Skip to content

Commit 93c312f

Browse files
jasonwaterscromulentlabs5amfungSam Fung
authored
bug fixes in samples (#52)
* local execution sample * target local execution sample update * updated local-execution sample * get attributes sample * added feature-flag link * formatting * updated samples and docs * updated local-exeecution and feature-flag samples * updated local-exeecution and feature-flag samples * new swapi for feature-flag sample * alpha.4 * alpha.5 * Fix typo * updated local decisioning samples to support 2.0.0-alpha.9 * 2.0.0-alpha.12 * update to use events option (#2) * 2.0.0-alpha.14 * Rename to on-device decisioning (#3) Co-authored-by: Sam Fung <[email protected]> * fix next-server-side-rendering-demo * bug fixes Co-authored-by: Greg <[email protected]> Co-authored-by: Sam Fung <[email protected]> Co-authored-by: Sam Fung <[email protected]>
1 parent 5eef043 commit 93c312f

File tree

23 files changed

+377
-130
lines changed

23 files changed

+377
-130
lines changed

advanced-atjs-integration-serverstate/server.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ function saveCookie(res, cookie) {
3232
return;
3333
}
3434

35-
res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
35+
res.cookie(cookie.name, cookie.value, { maxAge: cookie.maxAge * 1000 });
3636
}
3737

3838
const getResponseHeaders = () => ({
3939
"Content-Type": "text/html",
40-
"Expires": new Date().toUTCString()
40+
Expires: new Date().toUTCString()
4141
});
4242

4343
function sendHtml(res, targetResponse) {
4444
const serverState = {
4545
request: targetResponse.request,
4646
response: targetResponse.response
4747
};
48-
const htmlResponse = TEMPLATE
49-
.replace("${organizationId}", CONFIG.organizationId)
48+
const htmlResponse = TEMPLATE.replace(
49+
"${organizationId}",
50+
CONFIG.organizationId
51+
)
5052
.replace("${visitorState}", JSON.stringify(targetResponse.visitorState))
51-
.replace("${serverState}", JSON.stringify(serverState, null, ' '))
52-
.replace("${content}", JSON.stringify(targetResponse, null, ' '));
53+
.replace("${serverState}", JSON.stringify(serverState, null, " "))
54+
.replace("${content}", JSON.stringify(targetResponse, null, " "));
5355

5456
res.status(200).send(htmlResponse);
5557
}
@@ -67,30 +69,44 @@ function sendErrorResponse(res, error) {
6769
}
6870

6971
function getAddress(req) {
70-
return { url: req.headers.host + req.originalUrl }
72+
return { url: req.headers.host + req.originalUrl };
7173
}
7274

7375
app.get("/", async (req, res) => {
74-
const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
76+
const visitorCookie =
77+
req.cookies[
78+
encodeURIComponent(
79+
TargetClient.getVisitorCookieName(CONFIG.organizationId)
80+
)
81+
];
7582
const targetCookie = req.cookies[TargetClient.TargetCookieName];
76-
const targetLocationHintCookie = req.cookies[TargetClient.TargetLocationHintCookieName];
83+
const targetLocationHintCookie =
84+
req.cookies[TargetClient.TargetLocationHintCookieName];
7785
const request = {
7886
execute: {
79-
mboxes: [{
80-
address: getAddress(req),
81-
name: "a1-serverside-ab"
82-
}]
83-
}};
87+
mboxes: [
88+
{
89+
address: getAddress(req),
90+
name: "a1-serverside-ab"
91+
}
92+
]
93+
}
94+
};
8495

8596
try {
86-
const response = await targetClient.getOffers({ request, visitorCookie, targetCookie, targetLocationHintCookie });
97+
const response = await targetClient.getOffers({
98+
request,
99+
visitorCookie,
100+
targetCookie,
101+
targetLocationHintCookie
102+
});
87103
sendSuccessResponse(res, response);
88104
} catch (error) {
89105
console.error("Target:", error);
90106
sendErrorResponse(res, error);
91107
}
92108
});
93109

94-
app.listen(3000, function () {
110+
app.listen(3000, function() {
95111
console.log("Listening on port 3000 and watching!");
96112
});

ecid-analytics-atjs-integration/server.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ function saveCookie(res, cookie) {
3232
return;
3333
}
3434

35-
res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
35+
res.cookie(cookie.name, cookie.value, { maxAge: cookie.maxAge * 1000 });
3636
}
3737

3838
const getResponseHeaders = () => ({
3939
"Content-Type": "text/html",
40-
"Expires": new Date().toUTCString()
40+
Expires: new Date().toUTCString()
4141
});
4242

4343
function sendHtml(res, offer) {
44-
const htmlResponse = TEMPLATE
45-
.replace("${organizationId}", CONFIG.organizationId)
44+
const htmlResponse = TEMPLATE.replace(
45+
"${organizationId}",
46+
CONFIG.organizationId
47+
)
4648
.replace("${visitorState}", JSON.stringify(offer.visitorState))
47-
.replace("${content}", JSON.stringify(offer, null, ' '));
49+
.replace("${content}", JSON.stringify(offer, null, " "));
4850

4951
res.status(200).send(htmlResponse);
5052
}
@@ -62,30 +64,44 @@ function sendErrorResponse(res, error) {
6264
}
6365

6466
function getAddress(req) {
65-
return { url: req.headers.host + req.originalUrl }
67+
return { url: req.headers.host + req.originalUrl };
6668
}
6769

6870
app.get("/", async (req, res) => {
69-
const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
71+
const visitorCookie =
72+
req.cookies[
73+
encodeURIComponent(
74+
TargetClient.getVisitorCookieName(CONFIG.organizationId)
75+
)
76+
];
7077
const targetCookie = req.cookies[TargetClient.TargetCookieName];
71-
const targetLocationHintCookie = req.cookies[TargetClient.TargetLocationHintCookieName];
78+
const targetLocationHintCookie =
79+
req.cookies[TargetClient.TargetLocationHintCookieName];
7280
const request = {
7381
execute: {
74-
mboxes: [{
75-
address: getAddress(req),
76-
name: "a1-serverside-ab"
77-
}]
78-
}};
82+
mboxes: [
83+
{
84+
address: getAddress(req),
85+
name: "a1-serverside-ab"
86+
}
87+
]
88+
}
89+
};
7990

8091
try {
81-
const response = await targetClient.getOffers({ request, visitorCookie, targetCookie, targetLocationHintCookie });
92+
const response = await targetClient.getOffers({
93+
request,
94+
visitorCookie,
95+
targetCookie,
96+
targetLocationHintCookie
97+
});
8298
sendSuccessResponse(res, response);
8399
} catch (error) {
84100
console.error("Target:", error);
85101
sendErrorResponse(res, error);
86102
}
87103
});
88104

89-
app.listen(3000, function () {
105+
app.listen(3000, function() {
90106
console.log("Listening on port 3000 and watching!");
91107
});

ecid-analytics-integration/server.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ function saveCookie(res, cookie) {
3232
return;
3333
}
3434

35-
res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
35+
res.cookie(cookie.name, cookie.value, { maxAge: cookie.maxAge * 1000 });
3636
}
3737

3838
const getResponseHeaders = () => ({
3939
"Content-Type": "text/html",
40-
"Expires": new Date().toUTCString()
40+
Expires: new Date().toUTCString()
4141
});
4242

4343
function sendHtml(res, offer) {
44-
const htmlResponse = TEMPLATE
45-
.replace("${organizationId}", CONFIG.organizationId)
44+
const htmlResponse = TEMPLATE.replace(
45+
"${organizationId}",
46+
CONFIG.organizationId
47+
)
4648
.replace("${visitorState}", JSON.stringify(offer.visitorState))
47-
.replace("${content}", JSON.stringify(offer, null, ' '));
49+
.replace("${content}", JSON.stringify(offer, null, " "));
4850

4951
res.status(200).send(htmlResponse);
5052
}
@@ -61,29 +63,41 @@ function sendErrorResponse(res, error) {
6163
}
6264

6365
function getAddress(req) {
64-
return { url: req.headers.host + req.originalUrl }
66+
return { url: req.headers.host + req.originalUrl };
6567
}
6668

6769
app.get("/", async (req, res) => {
68-
const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
70+
const visitorCookie =
71+
req.cookies[
72+
encodeURIComponent(
73+
TargetClient.getVisitorCookieName(CONFIG.organizationId)
74+
)
75+
];
6976
const targetCookie = req.cookies[TargetClient.TargetCookieName];
7077
const request = {
7178
execute: {
72-
mboxes: [{
73-
address: getAddress(req),
74-
name: "a1-serverside-ab"
75-
}]
76-
}};
79+
mboxes: [
80+
{
81+
address: getAddress(req),
82+
name: "a1-serverside-ab"
83+
}
84+
]
85+
}
86+
};
7787

7888
try {
79-
const response = await targetClient.getOffers({ request, visitorCookie, targetCookie });
89+
const response = await targetClient.getOffers({
90+
request,
91+
visitorCookie,
92+
targetCookie
93+
});
8094
sendSuccessResponse(res, response);
8195
} catch (error) {
8296
console.error("Target:", error);
8397
sendErrorResponse(res, error);
8498
}
8599
});
86100

87-
app.listen(3000, function () {
101+
app.listen(3000, function() {
88102
console.log("Listening on port 3000 and watching!");
89103
});

ecid-customer-ids-integration/server.js

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@ function saveCookie(res, cookie) {
3232
return;
3333
}
3434

35-
res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
35+
res.cookie(cookie.name, cookie.value, { maxAge: cookie.maxAge * 1000 });
3636
}
3737

3838
const getResponseHeaders = () => ({
3939
"Content-Type": "text/html",
40-
"Expires": new Date().toUTCString()
40+
Expires: new Date().toUTCString()
4141
});
4242

4343
function sendHtml(res, offer) {
44-
const htmlResponse = TEMPLATE
45-
.replace("${organizationId}", CONFIG.organizationId)
44+
const htmlResponse = TEMPLATE.replace(
45+
"${organizationId}",
46+
CONFIG.organizationId
47+
)
4648
.replace("${visitorState}", JSON.stringify(offer.visitorState))
47-
.replace("${content}", JSON.stringify(offer, null, ' '));
49+
.replace("${content}", JSON.stringify(offer, null, " "));
4850

4951
res.status(200).send(htmlResponse);
5052
}
@@ -61,35 +63,48 @@ function sendErrorResponse(res, error) {
6163
}
6264

6365
function getAddress(req) {
64-
return { url: req.headers.host + req.originalUrl }
66+
return { url: req.headers.host + req.originalUrl };
6567
}
6668

6769
app.get("/", async (req, res) => {
68-
const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
70+
const visitorCookie =
71+
req.cookies[
72+
encodeURIComponent(
73+
TargetClient.getVisitorCookieName(CONFIG.organizationId)
74+
)
75+
];
6976
const targetCookie = req.cookies[TargetClient.TargetCookieName];
7077
const customerIds = {
71-
"userid": {
72-
"id": "67312378756723456",
73-
"authState": TargetClient.AuthState.AUTHENTICATED
78+
userid: {
79+
id: "67312378756723456",
80+
authState: TargetClient.AuthState.AUTHENTICATED
7481
}
7582
};
7683
const request = {
7784
execute: {
78-
mboxes: [{
79-
address: getAddress(req),
80-
name: "a1-serverside-ab"
81-
}]
82-
}};
85+
mboxes: [
86+
{
87+
address: getAddress(req),
88+
name: "a1-serverside-ab"
89+
}
90+
]
91+
}
92+
};
8393

8494
try {
85-
const response = await targetClient.getOffers({ request, visitorCookie, targetCookie, customerIds });
95+
const response = await targetClient.getOffers({
96+
request,
97+
visitorCookie,
98+
targetCookie,
99+
customerIds
100+
});
86101
sendSuccessResponse(res, response);
87102
} catch (error) {
88103
console.error("Target:", error);
89104
sendErrorResponse(res, error);
90105
}
91106
});
92107

93-
app.listen(3000, function () {
108+
app.listen(3000, function() {
94109
console.log("Listening on port 3000 and watching!");
95110
});

0 commit comments

Comments
 (0)