-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (37 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const functions = require("@google-cloud/functions-framework")
const { initializeDevCycle } = require("@devcycle/nodejs-server-sdk")
functions.http("helloHttp", async (req, res) => {
const serverKey = process.env.DEVCYCLE_SERVER_SDK_KEY
const dvcClient = initializeDevCycle(serverKey, {
enableCloudBucketing: true,
enableEdgeDB: true,
})
const userWithAllData = {
user_id: "testuser_1234333",
email: "[email protected]",
}
const { value: hasCampaign } = await dvcClient.variable(
userWithAllData,
"campaign-switch",
false
)
const { value: campaignData } = await dvcClient.variable(
{ user_id: "testuser_1234333" },
"campaign-details",
{}
)
const { value: proposedCampaignTitle } = await dvcClient.variable(
{ user_id: "testuser_1234333" },
"dec-campaign-proposed-name",
""
)
if (hasCampaign) {
const finalizedCampaignData = campaignData
if (campaignData.campaignId === "20221223") {
finalizedCampaignData.title = proposedCampaignTitle
}
res.send(`Current Campaign Data: ${JSON.stringify(finalizedCampaignData)}`)
} else {
res.send("No campaign at the moment!")
}
})