@active-reach/web-sdk 1.47.3 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-CxqFHlNB.mjs → analytics-DMY0Q0rI.mjs} +915 -318
- package/dist/analytics-DMY0Q0rI.mjs.map +1 -0
- package/dist/chat/AegisChat.d.ts +20 -0
- package/dist/chat/AegisChat.d.ts.map +1 -1
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.d.ts.map +1 -1
- package/dist/core/analytics.d.ts +16 -0
- package/dist/core/analytics.d.ts.map +1 -1
- package/dist/core/bootstrap.d.ts +2 -1
- package/dist/core/bootstrap.d.ts.map +1 -1
- package/dist/core/prefetch-bundle-client.d.ts +3 -0
- package/dist/core/prefetch-bundle-client.d.ts.map +1 -1
- package/dist/core/purchase-backlog.d.ts +141 -0
- package/dist/core/purchase-backlog.d.ts.map +1 -0
- package/dist/core/purchase-events.d.ts +25 -0
- package/dist/core/purchase-events.d.ts.map +1 -0
- package/dist/core/queue.d.ts +39 -0
- package/dist/core/queue.d.ts.map +1 -1
- package/dist/core/sdk-config-poller.d.ts.map +1 -1
- package/dist/core/transport.d.ts +74 -1
- package/dist/core/transport.d.ts.map +1 -1
- package/dist/ecommerce/index.d.ts +4 -4
- package/dist/ecommerce/index.d.ts.map +1 -1
- package/dist/ecommerce/types.d.ts +10 -0
- package/dist/ecommerce/types.d.ts.map +1 -1
- package/dist/governance/trait-governor.d.ts +13 -6
- package/dist/governance/trait-governor.d.ts.map +1 -1
- package/dist/inapp/AegisInAppManager.d.ts +114 -6
- package/dist/inapp/AegisInAppManager.d.ts.map +1 -1
- package/dist/inapp/anon-claim.d.ts +36 -0
- package/dist/inapp/anon-claim.d.ts.map +1 -0
- package/dist/inapp/index.d.ts +1 -1
- package/dist/inapp/index.d.ts.map +1 -1
- package/dist/inapp/prize-retry.d.ts +51 -0
- package/dist/inapp/prize-retry.d.ts.map +1 -0
- package/dist/inapp/rail-fallback.d.ts +83 -0
- package/dist/inapp/rail-fallback.d.ts.map +1 -0
- package/dist/inapp/renderers/games.d.ts.map +1 -1
- package/dist/inapp/renderers/types.d.ts +12 -0
- package/dist/inapp/renderers/types.d.ts.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1008 -146
- package/dist/index.js.map +1 -1
- package/dist/integrations/react.d.ts.map +1 -1
- package/dist/react.js +1 -1
- package/dist/runtime/AegisMessageRuntime.d.ts +17 -0
- package/dist/runtime/AegisMessageRuntime.d.ts.map +1 -1
- package/dist/snippet.min.js +1 -1
- package/dist/triggers/IntentRuleEvaluator.d.ts.map +1 -1
- package/dist/utils/fetch-abort.d.ts +23 -0
- package/dist/utils/fetch-abort.d.ts.map +1 -0
- package/dist/utils/preview-as-of.d.ts +21 -0
- package/dist/utils/preview-as-of.d.ts.map +1 -0
- package/dist/widgets/AegisWidgetManager.d.ts +2 -2
- package/package.json +1 -1
- package/dist/analytics-CxqFHlNB.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Storage, r as redactUrl, a as recordInAppItemTouch, e as ensureFbc, l as logger, A as Aegis } from "./analytics-
|
|
2
|
-
import { B, E, N, R, U, m } from "./analytics-
|
|
1
|
+
import { g as generateUUID, S as Storage, r as redactUrl, i as isPreviewPage, p as previewAsOfToken, a as recordInAppItemTouch, e as ensureFbc, l as logger, A as Aegis } from "./analytics-DMY0Q0rI.mjs";
|
|
2
|
+
import { B, E, N, R, U, m } from "./analytics-DMY0Q0rI.mjs";
|
|
3
3
|
import { a as assetIdOf } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
4
4
|
import { A } from "./AegisWebPush-BE9wJcx0.mjs";
|
|
5
5
|
function debounce(func, wait) {
|
|
@@ -121,6 +121,130 @@ function fallbackUrlForAction(a, productUrl = productPath) {
|
|
|
121
121
|
return void 0;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
const PRIZE_GRANT_RETRY = "PRIZE_GRANT_RETRY";
|
|
125
|
+
const ANON_CLAIM_REASON = "verify_phone_to_claim";
|
|
126
|
+
const SIGN_IN_TO_PLAY_REASON = "sign_in_to_play";
|
|
127
|
+
const PRIZE_GRANT_RETRY_MESSAGE = "We couldn't hand over this prize right now. Please try again in a moment.";
|
|
128
|
+
const SPIN_AGAIN_MESSAGE = "We couldn't finish this play. Please try again.";
|
|
129
|
+
const NON_REDEEMABLE_MESSAGE = "This prize can't be redeemed.";
|
|
130
|
+
const DRAW_ANSWER_TIMEOUT_MS = 8e3;
|
|
131
|
+
function prizeStateOf(resp, retryMessage) {
|
|
132
|
+
if (!resp) return { state: "spin_again", message: retryMessage || SPIN_AGAIN_MESSAGE };
|
|
133
|
+
const prize = resp.prize;
|
|
134
|
+
if (!prize || typeof prize !== "object") return { state: "loss" };
|
|
135
|
+
const outcome = prize.outcome;
|
|
136
|
+
if (outcome === "non_redeemable") {
|
|
137
|
+
const msg = typeof prize.message === "string" && prize.message ? prize.message : NON_REDEEMABLE_MESSAGE;
|
|
138
|
+
if (prize.claimable === true && prize.non_redeemable_reason === ANON_CLAIM_REASON) {
|
|
139
|
+
return { state: "non_redeemable", message: msg, claimable: true };
|
|
140
|
+
}
|
|
141
|
+
if (prize.non_redeemable_reason === SIGN_IN_TO_PLAY_REASON) {
|
|
142
|
+
return { state: "non_redeemable", message: msg, signIn: true };
|
|
143
|
+
}
|
|
144
|
+
return { state: "non_redeemable", message: msg };
|
|
145
|
+
}
|
|
146
|
+
if (outcome === "loss") return { state: "loss" };
|
|
147
|
+
if (prize.win === false || String(prize.prize_type || "").toLowerCase() === "no_prize") return { state: "loss" };
|
|
148
|
+
if (outcome === "credited_win") return { state: "credited_win" };
|
|
149
|
+
return prize.win === false ? { state: "loss" } : { state: "credited_win" };
|
|
150
|
+
}
|
|
151
|
+
const CLAIM_BUTTON_LABEL = "Log in or sign up to claim";
|
|
152
|
+
const SIGN_IN_BUTTON_LABEL = "Sign in to play";
|
|
153
|
+
const ANON_CLAIMS_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
154
|
+
const CLAIM_PATH = "/v1/in-app/responses/anon-claim";
|
|
155
|
+
const CLAIM_RETRY_MESSAGE = "We couldn't check this prize right now. Please try again.";
|
|
156
|
+
const CLAIM_EVENT = "aegis:anon-claim";
|
|
157
|
+
function claimAnswer(body) {
|
|
158
|
+
if (!body) return { claimed: false, text: CLAIM_RETRY_MESSAGE, code: "" };
|
|
159
|
+
const prize = body.prize && typeof body.prize === "object" ? body.prize : {};
|
|
160
|
+
const st = prizeStateOf(body);
|
|
161
|
+
const label = typeof prize.prize_label === "string" ? prize.prize_label : "";
|
|
162
|
+
if (body.status === "claimed" && st.state === "credited_win") {
|
|
163
|
+
const code = typeof prize.coupon_code === "string" ? prize.coupon_code : "";
|
|
164
|
+
return { claimed: true, text: label ? `You claimed: ${label}` : "Prize claimed", code };
|
|
165
|
+
}
|
|
166
|
+
if (st.state === "non_redeemable") return { claimed: false, text: st.message, code: "" };
|
|
167
|
+
const msg = typeof body.message === "string" && body.message ? body.message : CLAIM_RETRY_MESSAGE;
|
|
168
|
+
return { claimed: false, text: msg, code: "" };
|
|
169
|
+
}
|
|
170
|
+
const ANON_CLAIMS_STORAGE_KEY = "aegis_anon_claims";
|
|
171
|
+
function loadAnonClaims() {
|
|
172
|
+
try {
|
|
173
|
+
const raw = typeof localStorage !== "undefined" ? localStorage.getItem(ANON_CLAIMS_STORAGE_KEY) : null;
|
|
174
|
+
if (!raw) return { pending: [], tickets: {} };
|
|
175
|
+
const v = JSON.parse(raw);
|
|
176
|
+
if (typeof v.savedAt !== "number" || Date.now() - v.savedAt > ANON_CLAIMS_TTL_MS) {
|
|
177
|
+
return { pending: [], tickets: {} };
|
|
178
|
+
}
|
|
179
|
+
const pending = Array.isArray(v.pending) ? v.pending.filter((x) => typeof x === "string") : [];
|
|
180
|
+
const tickets = {};
|
|
181
|
+
if (v.tickets && typeof v.tickets === "object") {
|
|
182
|
+
for (const [k, t] of Object.entries(v.tickets)) if (typeof t === "string") tickets[k] = t;
|
|
183
|
+
}
|
|
184
|
+
return { pending, tickets };
|
|
185
|
+
} catch {
|
|
186
|
+
return { pending: [], tickets: {} };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function saveAnonClaims(state) {
|
|
190
|
+
try {
|
|
191
|
+
if (typeof localStorage !== "undefined") {
|
|
192
|
+
localStorage.setItem(ANON_CLAIMS_STORAGE_KEY, JSON.stringify({ ...state, savedAt: Date.now() }));
|
|
193
|
+
}
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function claimButton(onClick, label = CLAIM_BUTTON_LABEL) {
|
|
198
|
+
const btn = document.createElement("button");
|
|
199
|
+
btn.type = "button";
|
|
200
|
+
btn.setAttribute("data-aegis-anon-claim", "");
|
|
201
|
+
btn.textContent = label;
|
|
202
|
+
btn.style.cssText = "margin-top:8px;padding:8px 14px;border:0;border-radius:8px;font-weight:600;font-size:13px;cursor:pointer;background:#111827;color:#fff;";
|
|
203
|
+
btn.addEventListener("click", (e) => {
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
btn.disabled = true;
|
|
206
|
+
onClick();
|
|
207
|
+
});
|
|
208
|
+
return btn;
|
|
209
|
+
}
|
|
210
|
+
function showClaimNotice(answer, onRetry) {
|
|
211
|
+
var _a;
|
|
212
|
+
if (typeof document === "undefined" || !document.body) return;
|
|
213
|
+
(_a = document.querySelector("[data-aegis-anon-claim-notice]")) == null ? void 0 : _a.remove();
|
|
214
|
+
const box = document.createElement("div");
|
|
215
|
+
box.setAttribute("data-aegis-anon-claim-notice", "");
|
|
216
|
+
box.setAttribute("role", "status");
|
|
217
|
+
box.style.cssText = "position:fixed;left:16px;right:16px;bottom:16px;max-width:420px;margin:0 auto;z-index:2147483646;background:#fff;color:#111827;border-radius:12px;padding:14px 16px;box-shadow:0 8px 30px rgba(0,0,0,0.18);font:14px/1.4 system-ui,sans-serif;";
|
|
218
|
+
const text = document.createElement("div");
|
|
219
|
+
text.style.cssText = "font-weight:600;";
|
|
220
|
+
text.textContent = answer.text;
|
|
221
|
+
box.appendChild(text);
|
|
222
|
+
if (answer.code) {
|
|
223
|
+
const code = document.createElement("div");
|
|
224
|
+
code.style.cssText = "margin-top:6px;font-family:monospace;font-size:15px;letter-spacing:0.5px;";
|
|
225
|
+
code.textContent = answer.code;
|
|
226
|
+
box.appendChild(code);
|
|
227
|
+
}
|
|
228
|
+
if (onRetry) {
|
|
229
|
+
const retry = document.createElement("button");
|
|
230
|
+
retry.type = "button";
|
|
231
|
+
retry.setAttribute("data-aegis-anon-claim-retry", "");
|
|
232
|
+
retry.textContent = "Try again";
|
|
233
|
+
retry.style.cssText = "margin-top:10px;margin-right:16px;border:0;background:none;color:#111827;font-weight:600;cursor:pointer;padding:0;";
|
|
234
|
+
retry.addEventListener("click", () => {
|
|
235
|
+
box.remove();
|
|
236
|
+
onRetry();
|
|
237
|
+
});
|
|
238
|
+
box.appendChild(retry);
|
|
239
|
+
}
|
|
240
|
+
const close = document.createElement("button");
|
|
241
|
+
close.type = "button";
|
|
242
|
+
close.textContent = "Close";
|
|
243
|
+
close.style.cssText = "margin-top:10px;border:0;background:none;color:#4b5563;cursor:pointer;padding:0;";
|
|
244
|
+
close.addEventListener("click", () => box.remove());
|
|
245
|
+
box.appendChild(close);
|
|
246
|
+
document.body.appendChild(box);
|
|
247
|
+
}
|
|
124
248
|
const ICONS = {
|
|
125
249
|
x: [
|
|
126
250
|
["path", { d: "M18 6 6 18" }],
|
|
@@ -426,16 +550,16 @@ function readRootVar(name) {
|
|
|
426
550
|
return "";
|
|
427
551
|
}
|
|
428
552
|
}
|
|
429
|
-
function detectFontHost(
|
|
430
|
-
return
|
|
553
|
+
function detectFontHost(read2 = readRootVar) {
|
|
554
|
+
return read2(ACS_BODY_FONT_VAR) ? "acs" : "third_party";
|
|
431
555
|
}
|
|
432
|
-
function resolveRootFonts(brand,
|
|
433
|
-
const host = detectFontHost(
|
|
556
|
+
function resolveRootFonts(brand, read2 = readRootVar) {
|
|
557
|
+
const host = detectFontHost(read2);
|
|
434
558
|
if (host === "acs") {
|
|
435
559
|
return {
|
|
436
560
|
host,
|
|
437
561
|
body: `var(${ACS_BODY_FONT_VAR})`,
|
|
438
|
-
display:
|
|
562
|
+
display: read2(ACS_DISPLAY_FONT_VAR) ? `var(${ACS_DISPLAY_FONT_VAR})` : `var(${ACS_BODY_FONT_VAR})`,
|
|
439
563
|
load: []
|
|
440
564
|
};
|
|
441
565
|
}
|
|
@@ -476,9 +600,9 @@ function ensurePreconnect() {
|
|
|
476
600
|
document.head.appendChild(l);
|
|
477
601
|
}
|
|
478
602
|
}
|
|
479
|
-
function loadFonts(loads,
|
|
603
|
+
function loadFonts(loads, read2 = readRootVar) {
|
|
480
604
|
if (typeof document === "undefined" || loads.length === 0) return;
|
|
481
|
-
if (detectFontHost(
|
|
605
|
+
if (detectFontHost(read2) === "acs") return;
|
|
482
606
|
let grew = false;
|
|
483
607
|
for (const { font, role } of loads) {
|
|
484
608
|
const known = findGoogleFont(font.name);
|
|
@@ -512,15 +636,15 @@ function loadFonts(loads, read = readRootVar) {
|
|
|
512
636
|
}
|
|
513
637
|
link.href = googleFontsHref(requested);
|
|
514
638
|
}
|
|
515
|
-
function applyRootFonts(brand,
|
|
516
|
-
const r = resolveRootFonts(brand,
|
|
639
|
+
function applyRootFonts(brand, read2 = readRootVar) {
|
|
640
|
+
const r = resolveRootFonts(brand, read2);
|
|
517
641
|
if (typeof document === "undefined") return r;
|
|
518
642
|
const root = document.documentElement.style;
|
|
519
643
|
if (r.body) root.setProperty(AEGIS_BODY_FONT_VAR, r.body);
|
|
520
644
|
else root.removeProperty(AEGIS_BODY_FONT_VAR);
|
|
521
645
|
if (r.display) root.setProperty(AEGIS_DISPLAY_FONT_VAR, r.display);
|
|
522
646
|
else root.removeProperty(AEGIS_DISPLAY_FONT_VAR);
|
|
523
|
-
loadFonts(r.load,
|
|
647
|
+
loadFonts(r.load, read2);
|
|
524
648
|
return r;
|
|
525
649
|
}
|
|
526
650
|
function campaignFontFamily(campaign) {
|
|
@@ -532,8 +656,8 @@ function campaignFontFamily(campaign) {
|
|
|
532
656
|
}
|
|
533
657
|
return void 0;
|
|
534
658
|
}
|
|
535
|
-
function campaignFontVarsCss(value,
|
|
536
|
-
const served = fontValueToCss(value, detectFontHost(
|
|
659
|
+
function campaignFontVarsCss(value, read2 = readRootVar) {
|
|
660
|
+
const served = fontValueToCss(value, detectFontHost(read2));
|
|
537
661
|
if (!served) return "";
|
|
538
662
|
if (served.font) {
|
|
539
663
|
loadFonts(
|
|
@@ -541,19 +665,19 @@ function campaignFontVarsCss(value, read = readRootVar) {
|
|
|
541
665
|
{ font: served.font, role: "body" },
|
|
542
666
|
{ font: served.font, role: "display" }
|
|
543
667
|
],
|
|
544
|
-
|
|
668
|
+
read2
|
|
545
669
|
);
|
|
546
670
|
}
|
|
547
671
|
return `${AEGIS_BODY_FONT_VAR}:${served.css};${AEGIS_DISPLAY_FONT_VAR}:${served.css};`;
|
|
548
672
|
}
|
|
549
673
|
const CAMPAIGN_SHEET_ID = "aegis-campaign-fonts";
|
|
550
674
|
const SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
551
|
-
function registerCampaignFonts(campaigns,
|
|
675
|
+
function registerCampaignFonts(campaigns, read2 = readRootVar) {
|
|
552
676
|
const rules = [];
|
|
553
677
|
for (const c of campaigns) {
|
|
554
678
|
const id = typeof c.id === "string" ? c.id : "";
|
|
555
679
|
if (!SAFE_ID.test(id)) continue;
|
|
556
|
-
const decl = campaignFontVarsCss(campaignFontFamily(c),
|
|
680
|
+
const decl = campaignFontVarsCss(campaignFontFamily(c), read2);
|
|
557
681
|
if (decl) rules.push(`[data-campaign-id="${id}"]{${decl}}`);
|
|
558
682
|
}
|
|
559
683
|
const css = rules.join("\n");
|
|
@@ -571,11 +695,11 @@ function registerCampaignFonts(campaigns, read = readRootVar) {
|
|
|
571
695
|
sheet.textContent = css;
|
|
572
696
|
return css;
|
|
573
697
|
}
|
|
574
|
-
function applyCampaignFonts(campaigns,
|
|
698
|
+
function applyCampaignFonts(campaigns, read2 = readRootVar) {
|
|
575
699
|
var _a;
|
|
576
700
|
const brand = ((_a = campaigns.find((c) => c.brand_typography)) == null ? void 0 : _a.brand_typography) ?? null;
|
|
577
|
-
applyRootFonts(brand,
|
|
578
|
-
registerCampaignFonts(campaigns,
|
|
701
|
+
applyRootFonts(brand, read2);
|
|
702
|
+
registerCampaignFonts(campaigns, read2);
|
|
579
703
|
}
|
|
580
704
|
const HERO_IMAGE_SIZES = "100vw";
|
|
581
705
|
function cardImageSizes(kind, widthPx) {
|
|
@@ -3602,6 +3726,21 @@ function injectStoryStyles() {
|
|
|
3602
3726
|
`;
|
|
3603
3727
|
document.head.appendChild(style);
|
|
3604
3728
|
}
|
|
3729
|
+
async function drawAnswer(ctx, submitP) {
|
|
3730
|
+
var _a;
|
|
3731
|
+
let res = null;
|
|
3732
|
+
try {
|
|
3733
|
+
res = await Promise.race([
|
|
3734
|
+
submitP ?? Promise.resolve(null),
|
|
3735
|
+
new Promise((resolve) => window.setTimeout(() => resolve(null), DRAW_ANSWER_TIMEOUT_MS))
|
|
3736
|
+
]);
|
|
3737
|
+
} catch {
|
|
3738
|
+
res = null;
|
|
3739
|
+
}
|
|
3740
|
+
const st = prizeStateOf(res, ((_a = ctx.takeRetryAnswer) == null ? void 0 : _a.call(ctx)) ?? null);
|
|
3741
|
+
const prize = res && res.prize && typeof res.prize === "object" ? res.prize : null;
|
|
3742
|
+
return { st, prize };
|
|
3743
|
+
}
|
|
3605
3744
|
function earnPct(current, threshold) {
|
|
3606
3745
|
return computeProgress({ threshold, current }).pct;
|
|
3607
3746
|
}
|
|
@@ -4014,6 +4153,8 @@ function renderMysteryBox(ctx) {
|
|
|
4014
4153
|
const row = document.createElement("div");
|
|
4015
4154
|
row.style.cssText = "display:flex;gap:12px;justify-content:center;margin:8px 0 4px";
|
|
4016
4155
|
let opened = false;
|
|
4156
|
+
const note = document.createElement("div");
|
|
4157
|
+
note.style.cssText = "font-size:12.5px;font-weight:600;min-height:16px;margin-top:6px;opacity:0.8";
|
|
4017
4158
|
list.forEach((b, i) => {
|
|
4018
4159
|
const box = document.createElement("button");
|
|
4019
4160
|
box.type = "button";
|
|
@@ -4038,19 +4179,43 @@ function renderMysteryBox(ctx) {
|
|
|
4038
4179
|
box.style.animation = "";
|
|
4039
4180
|
let won = true;
|
|
4040
4181
|
let prizeLabel = str$1(b.prize, "You won!");
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4182
|
+
let nonRedeemable = null;
|
|
4183
|
+
let claimable = false;
|
|
4184
|
+
let signIn = false;
|
|
4185
|
+
if (ctx.submitResponse) {
|
|
4186
|
+
const { st, prize } = await drawAnswer(ctx, submitP);
|
|
4187
|
+
if (st.state === "spin_again") {
|
|
4188
|
+
opened = false;
|
|
4189
|
+
Array.from(row.children).forEach((c) => {
|
|
4190
|
+
c.style.opacity = "";
|
|
4191
|
+
c.style.transform = "";
|
|
4192
|
+
});
|
|
4193
|
+
note.textContent = st.message;
|
|
4194
|
+
return;
|
|
4195
|
+
}
|
|
4196
|
+
note.textContent = "";
|
|
4197
|
+
if (prize && prize.prize_label) prizeLabel = String(prize.prize_label);
|
|
4198
|
+
won = st.state === "credited_win";
|
|
4199
|
+
if (st.state === "non_redeemable") {
|
|
4200
|
+
nonRedeemable = st.message;
|
|
4201
|
+
claimable = st.claimable === true;
|
|
4202
|
+
signIn = st.signIn === true;
|
|
4047
4203
|
}
|
|
4048
|
-
} catch {
|
|
4049
4204
|
}
|
|
4050
4205
|
box.style.background = won ? `${s.accent}` : "rgba(148,163,184,0.22)";
|
|
4051
4206
|
box.style.color = won ? "#fff" : "#475569";
|
|
4052
4207
|
box.style.transform = "scale(1.08)";
|
|
4053
4208
|
box.replaceChildren();
|
|
4209
|
+
if (nonRedeemable !== null) {
|
|
4210
|
+
box.appendChild(gEl("span", "", prizeLabel));
|
|
4211
|
+
note.textContent = nonRedeemable;
|
|
4212
|
+
if (claimable && ctx.claimAnonWin) note.appendChild(claimButton(ctx.claimAnonWin));
|
|
4213
|
+
else if (signIn && ctx.dispatchAction) {
|
|
4214
|
+
const open = ctx.dispatchAction;
|
|
4215
|
+
note.appendChild(claimButton(() => open({ type: "open_login" }), SIGN_IN_BUTTON_LABEL));
|
|
4216
|
+
}
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4054
4219
|
box.appendChild(gEl("span", "font-size:28px", won ? "🎉" : "🙈"));
|
|
4055
4220
|
box.appendChild(gEl("span", "", won ? prizeLabel : "Not this time"));
|
|
4056
4221
|
if (won) {
|
|
@@ -4068,6 +4233,7 @@ function renderMysteryBox(ctx) {
|
|
|
4068
4233
|
row.appendChild(box);
|
|
4069
4234
|
});
|
|
4070
4235
|
s.content.appendChild(row);
|
|
4236
|
+
s.content.appendChild(note);
|
|
4071
4237
|
s.ctaButton(str$1(ic.mystery_cta_text, ""));
|
|
4072
4238
|
}
|
|
4073
4239
|
function renderTierLadder(ctx) {
|
|
@@ -4258,19 +4424,27 @@ function renderSlotMachine(ctx) {
|
|
|
4258
4424
|
const prov = [pool[rnd(pool.length)], pool[rnd(pool.length)], pool[rnd(pool.length)]];
|
|
4259
4425
|
const provWin = prov[0] === prov[1] && prov[1] === prov[2];
|
|
4260
4426
|
const submitP = (_b = ctx.submitResponse) == null ? void 0 : _b.call(ctx, "slot_machine", { win: provWin, symbols: prov });
|
|
4261
|
-
let
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4427
|
+
let win = provWin;
|
|
4428
|
+
let label = str$1(ic.slot_win_text, "You win!");
|
|
4429
|
+
let nonRedeemable = null;
|
|
4430
|
+
let claimable = false;
|
|
4431
|
+
let signIn = false;
|
|
4432
|
+
let spinAgain = null;
|
|
4433
|
+
let claimInStore = false;
|
|
4434
|
+
if (ctx.submitResponse) {
|
|
4435
|
+
const { st, prize } = await drawAnswer(ctx, submitP);
|
|
4436
|
+
if (prize && prize.prize_label) label = String(prize.prize_label);
|
|
4437
|
+
win = st.state === "credited_win";
|
|
4438
|
+
claimInStore = win && !!prize && String(prize.prize_type || "").toLowerCase() === "freebie" && !prize.coupon_code;
|
|
4439
|
+
if (st.state === "non_redeemable") {
|
|
4440
|
+
nonRedeemable = st.message;
|
|
4441
|
+
claimable = st.claimable === true;
|
|
4442
|
+
signIn = st.signIn === true;
|
|
4443
|
+
}
|
|
4444
|
+
if (st.state === "spin_again") spinAgain = st.message;
|
|
4269
4445
|
}
|
|
4270
|
-
const win = serverPrize ? serverPrize.win !== false : provWin;
|
|
4271
|
-
const label = serverPrize && serverPrize.prize_label ? String(serverPrize.prize_label) : str$1(ic.slot_win_text, "You win!");
|
|
4272
4446
|
let target;
|
|
4273
|
-
if (
|
|
4447
|
+
if (ctx.submitResponse) {
|
|
4274
4448
|
if (win) {
|
|
4275
4449
|
const sym = pool[rnd(pool.length)];
|
|
4276
4450
|
target = [sym, sym, sym];
|
|
@@ -4283,8 +4457,29 @@ function renderSlotMachine(ctx) {
|
|
|
4283
4457
|
}
|
|
4284
4458
|
const finish = () => {
|
|
4285
4459
|
var _a2, _b2, _c, _d;
|
|
4460
|
+
if (spinAgain !== null || nonRedeemable !== null) {
|
|
4461
|
+
result.textContent = spinAgain ?? `${label}: ${nonRedeemable}`;
|
|
4462
|
+
result.style.color = "#64748b";
|
|
4463
|
+
if (spinAgain === null && claimable && ctx.claimAnonWin) {
|
|
4464
|
+
const claimRow = document.createElement("div");
|
|
4465
|
+
claimRow.appendChild(claimButton(ctx.claimAnonWin));
|
|
4466
|
+
result.appendChild(claimRow);
|
|
4467
|
+
} else if (spinAgain === null && signIn && ctx.dispatchAction) {
|
|
4468
|
+
const open = ctx.dispatchAction;
|
|
4469
|
+
const signInRow = document.createElement("div");
|
|
4470
|
+
signInRow.appendChild(claimButton(() => open({ type: "open_login" }), SIGN_IN_BUTTON_LABEL));
|
|
4471
|
+
result.appendChild(signInRow);
|
|
4472
|
+
}
|
|
4473
|
+
if (spinAgain !== null && fresh) fresh.disabled = false;
|
|
4474
|
+
ctx.trackEvent(ctx.campaign.id, "clicked", { stepId: spinAgain !== null ? "retry" : "non_redeemable" });
|
|
4475
|
+
spinning = false;
|
|
4476
|
+
return;
|
|
4477
|
+
}
|
|
4286
4478
|
result.textContent = win ? `🎉 ${label}` : "So close — try again next time!";
|
|
4287
4479
|
result.style.color = win ? s.accent : "#94a3b8";
|
|
4480
|
+
if (win && claimInStore) {
|
|
4481
|
+
result.appendChild(gEl("div", "font-size:12px;font-weight:600;opacity:0.85;margin-top:2px", "🎟️ Show this screen to claim"));
|
|
4482
|
+
}
|
|
4288
4483
|
if (win) {
|
|
4289
4484
|
winLine.style.borderColor = s.accent;
|
|
4290
4485
|
winLine.style.boxShadow = `0 0 14px ${s.accent}aa, inset 0 0 14px ${s.accent}55`;
|
|
@@ -5230,9 +5425,26 @@ function interactiveSig(msg) {
|
|
|
5230
5425
|
}
|
|
5231
5426
|
}
|
|
5232
5427
|
let currentLauncher = null;
|
|
5428
|
+
const launcherListeners = /* @__PURE__ */ new Set();
|
|
5429
|
+
function setCurrentLauncher(next) {
|
|
5430
|
+
if (currentLauncher === next) return;
|
|
5431
|
+
currentLauncher = next;
|
|
5432
|
+
for (const listener of launcherListeners) {
|
|
5433
|
+
try {
|
|
5434
|
+
listener(next);
|
|
5435
|
+
} catch {
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5233
5439
|
function getCurrentLauncher() {
|
|
5234
5440
|
return currentLauncher;
|
|
5235
5441
|
}
|
|
5442
|
+
function onLauncherChange(listener) {
|
|
5443
|
+
launcherListeners.add(listener);
|
|
5444
|
+
return () => {
|
|
5445
|
+
launcherListeners.delete(listener);
|
|
5446
|
+
};
|
|
5447
|
+
}
|
|
5236
5448
|
function openChat(prefill) {
|
|
5237
5449
|
currentLauncher == null ? void 0 : currentLauncher.openPanel(prefill);
|
|
5238
5450
|
}
|
|
@@ -5240,7 +5452,7 @@ function closeChat() {
|
|
|
5240
5452
|
currentLauncher == null ? void 0 : currentLauncher.closePanel();
|
|
5241
5453
|
}
|
|
5242
5454
|
const ATTENTION_DELAY_MS = 4500;
|
|
5243
|
-
class
|
|
5455
|
+
const _AegisChat = class _AegisChat {
|
|
5244
5456
|
constructor(config) {
|
|
5245
5457
|
this.workspaceRejected = false;
|
|
5246
5458
|
this.lastRemintAt = 0;
|
|
@@ -5249,6 +5461,8 @@ class AegisChat {
|
|
|
5249
5461
|
this.renderedRows = /* @__PURE__ */ new Map();
|
|
5250
5462
|
this.sessionResumed = false;
|
|
5251
5463
|
this.open = false;
|
|
5464
|
+
this.destroyed = false;
|
|
5465
|
+
this.retryWaits = /* @__PURE__ */ new Set();
|
|
5252
5466
|
this.initialized = false;
|
|
5253
5467
|
this.unread = 0;
|
|
5254
5468
|
this.renderedIds = /* @__PURE__ */ new Set();
|
|
@@ -5292,11 +5506,11 @@ class AegisChat {
|
|
|
5292
5506
|
}
|
|
5293
5507
|
if (this.whatsapp) {
|
|
5294
5508
|
this.mountWhatsapp();
|
|
5295
|
-
|
|
5509
|
+
setCurrentLauncher(this);
|
|
5296
5510
|
return;
|
|
5297
5511
|
}
|
|
5298
5512
|
this.mount();
|
|
5299
|
-
|
|
5513
|
+
setCurrentLauncher(this);
|
|
5300
5514
|
if (this.displayMode !== "nav") this.scheduleAttention();
|
|
5301
5515
|
}
|
|
5302
5516
|
/** Called by the runtime when the visitor identifies. */
|
|
@@ -5358,6 +5572,13 @@ class AegisChat {
|
|
|
5358
5572
|
}
|
|
5359
5573
|
destroy() {
|
|
5360
5574
|
var _a, _b;
|
|
5575
|
+
this.destroyed = true;
|
|
5576
|
+
this.open = false;
|
|
5577
|
+
for (const w of this.retryWaits) {
|
|
5578
|
+
clearTimeout(w.timer);
|
|
5579
|
+
w.wake();
|
|
5580
|
+
}
|
|
5581
|
+
this.retryWaits.clear();
|
|
5361
5582
|
this.unbindViewport();
|
|
5362
5583
|
this.disconnectSSE();
|
|
5363
5584
|
this.stopPolling();
|
|
@@ -5365,11 +5586,10 @@ class AegisChat {
|
|
|
5365
5586
|
this.waDismiss = void 0;
|
|
5366
5587
|
(_b = this.root) == null ? void 0 : _b.remove();
|
|
5367
5588
|
this.initialized = false;
|
|
5368
|
-
if (currentLauncher === this)
|
|
5589
|
+
if (currentLauncher === this) setCurrentLauncher(null);
|
|
5369
5590
|
}
|
|
5370
5591
|
// ── Send ─────────────────────────────────────────────────────────────────
|
|
5371
5592
|
async send(text, media) {
|
|
5372
|
-
var _a;
|
|
5373
5593
|
const caption2 = text.trim();
|
|
5374
5594
|
if (!caption2 && !media) return;
|
|
5375
5595
|
const message = caption2 || (media ? media.type === "image" ? "Sent a photo 📷" : "Sent a file 📎" : "");
|
|
@@ -5387,33 +5607,72 @@ class AegisChat {
|
|
|
5387
5607
|
this.input.style.height = "auto";
|
|
5388
5608
|
}
|
|
5389
5609
|
this.showTyping();
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5406
|
-
|
|
5407
|
-
|
|
5610
|
+
await this.deliver({ message, media, clientMessageId: generateUUID() });
|
|
5611
|
+
}
|
|
5612
|
+
static retryAfterMs(res) {
|
|
5613
|
+
var _a, _b;
|
|
5614
|
+
const raw = (_b = (_a = res.headers) == null ? void 0 : _a.get) == null ? void 0 : _b.call(_a, "Retry-After");
|
|
5615
|
+
const secs = raw ? Number(raw) : NaN;
|
|
5616
|
+
return Number.isFinite(secs) && secs >= 0 ? Math.min(secs * 1e3, _AegisChat.RETRY_AFTER_CAP_MS) : null;
|
|
5617
|
+
}
|
|
5618
|
+
/** POST one message with bounded automatic retries on the SAME id. On a final
|
|
5619
|
+
* failure, leave a Retry action that re-sends the stored id and text. */
|
|
5620
|
+
async deliver(pending) {
|
|
5621
|
+
var _a;
|
|
5622
|
+
const { message, media, clientMessageId } = pending;
|
|
5623
|
+
const post = () => fetch(`${this.apiHost}/v1/chat/message`, {
|
|
5624
|
+
method: "POST",
|
|
5625
|
+
headers: { "Content-Type": "application/json", "X-Aegis-Write-Key": this.writeKey },
|
|
5626
|
+
body: JSON.stringify({
|
|
5627
|
+
workspace_id: this.sentWorkspaceId(),
|
|
5628
|
+
message_text: message,
|
|
5629
|
+
client_message_id: clientMessageId,
|
|
5630
|
+
channel: this.channel,
|
|
5631
|
+
anonymous_id: this.anonymousId,
|
|
5632
|
+
contact_id: this.contactId,
|
|
5633
|
+
media_url: media == null ? void 0 : media.url,
|
|
5634
|
+
media_type: media == null ? void 0 : media.type,
|
|
5635
|
+
// Active Web Chat — binds the campaign-configured persona. Optional;
|
|
5636
|
+
// the backend falls back to the tenant default if unknown/absent
|
|
5637
|
+
// (honored server-side in Phase E). JSON.stringify drops it if absent.
|
|
5638
|
+
agent_persona: this.agentPersona
|
|
5639
|
+
}),
|
|
5640
|
+
keepalive: true
|
|
5641
|
+
});
|
|
5642
|
+
const delays = _AegisChat.RETRY_DELAYS_MS;
|
|
5643
|
+
let res = null;
|
|
5644
|
+
for (let attempt = 0; attempt <= delays.length; attempt++) {
|
|
5645
|
+
if (this.destroyed) return;
|
|
5646
|
+
let waitMs = null;
|
|
5647
|
+
try {
|
|
5648
|
+
res = await post();
|
|
5649
|
+
if (await this.isWorkspaceMismatch(res)) res = await post();
|
|
5650
|
+
if (res.ok || !_AegisChat.RETRYABLE_STATUS.has(res.status)) break;
|
|
5651
|
+
this.log("send failed (retryable)", res.status);
|
|
5652
|
+
waitMs = _AegisChat.retryAfterMs(res);
|
|
5653
|
+
} catch (err) {
|
|
5654
|
+
this.log("send error", err);
|
|
5655
|
+
res = null;
|
|
5656
|
+
}
|
|
5657
|
+
if (attempt === delays.length) break;
|
|
5658
|
+
if (this.destroyed) return;
|
|
5659
|
+
await new Promise((resolve) => {
|
|
5660
|
+
const w = { timer: setTimeout(() => {
|
|
5661
|
+
this.retryWaits.delete(w);
|
|
5662
|
+
resolve();
|
|
5663
|
+
}, waitMs ?? delays[attempt]), wake: resolve };
|
|
5664
|
+
this.retryWaits.add(w);
|
|
5408
5665
|
});
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5415
|
-
|
|
5666
|
+
}
|
|
5667
|
+
if (this.destroyed) return;
|
|
5668
|
+
if (!res || !res.ok) {
|
|
5669
|
+
if (res) this.log("send failed", res.status);
|
|
5670
|
+
this.appendDeliveryFailed(pending);
|
|
5671
|
+
return;
|
|
5672
|
+
}
|
|
5673
|
+
try {
|
|
5416
5674
|
const data = await res.json();
|
|
5675
|
+
if (this.destroyed) return;
|
|
5417
5676
|
try {
|
|
5418
5677
|
(_a = this.onMessageSent) == null ? void 0 : _a.call(this);
|
|
5419
5678
|
} catch {
|
|
@@ -5426,9 +5685,30 @@ class AegisChat {
|
|
|
5426
5685
|
void this.refreshHistory();
|
|
5427
5686
|
} catch (err) {
|
|
5428
5687
|
this.log("send error", err);
|
|
5429
|
-
this.
|
|
5688
|
+
this.appendDeliveryFailed(pending);
|
|
5430
5689
|
}
|
|
5431
5690
|
}
|
|
5691
|
+
/** The failed-message notice with a Retry button. Retry re-sends the stored
|
|
5692
|
+
* client id + text, so a message the server did accept is absorbed, not
|
|
5693
|
+
* answered twice, and the customer never has to retype. */
|
|
5694
|
+
appendDeliveryFailed(pending) {
|
|
5695
|
+
var _a;
|
|
5696
|
+
this.hideTyping();
|
|
5697
|
+
this.appendSystem("Sorry — your message could not be delivered.");
|
|
5698
|
+
const row = (_a = this.thread) == null ? void 0 : _a.lastElementChild;
|
|
5699
|
+
if (!row) return;
|
|
5700
|
+
const btn = document.createElement("button");
|
|
5701
|
+
btn.type = "button";
|
|
5702
|
+
btn.className = "aegis-chat-chip aegis-chat-retry";
|
|
5703
|
+
btn.textContent = "Retry";
|
|
5704
|
+
btn.addEventListener("click", () => {
|
|
5705
|
+
btn.disabled = true;
|
|
5706
|
+
row.remove();
|
|
5707
|
+
this.showTyping();
|
|
5708
|
+
void this.deliver(pending);
|
|
5709
|
+
});
|
|
5710
|
+
row.appendChild(btn);
|
|
5711
|
+
}
|
|
5432
5712
|
// ── Media attachments ─────────────────────────────────────────────────────
|
|
5433
5713
|
/** Validate + upload a picked file, then send it as a media message. */
|
|
5434
5714
|
async handleFile(file) {
|
|
@@ -6309,7 +6589,11 @@ class AegisChat {
|
|
|
6309
6589
|
style.textContent = CHAT_CSS;
|
|
6310
6590
|
document.head.appendChild(style);
|
|
6311
6591
|
}
|
|
6312
|
-
}
|
|
6592
|
+
};
|
|
6593
|
+
_AegisChat.RETRYABLE_STATUS = /* @__PURE__ */ new Set([429, 502, 503, 504]);
|
|
6594
|
+
_AegisChat.RETRY_DELAYS_MS = [1e3, 3e3, 7e3];
|
|
6595
|
+
_AegisChat.RETRY_AFTER_CAP_MS = 3e4;
|
|
6596
|
+
let AegisChat = _AegisChat;
|
|
6313
6597
|
const CHAT_CSS = `
|
|
6314
6598
|
${launcherRootCss("aegis-chat-root")}
|
|
6315
6599
|
.aegis-chat-root{${fontFamilyCss("body")}}
|
|
@@ -8251,6 +8535,165 @@ function armBehaviouralTriggers(engine, triggers, armed, fire, isMobile) {
|
|
|
8251
8535
|
}
|
|
8252
8536
|
return newlyArmed;
|
|
8253
8537
|
}
|
|
8538
|
+
const SDK_FETCH_ABORT_MS = 800;
|
|
8539
|
+
function fetchWithAbort(input, init = {}, timeoutMs = SDK_FETCH_ABORT_MS) {
|
|
8540
|
+
const budget = Math.min(timeoutMs, SDK_FETCH_ABORT_MS);
|
|
8541
|
+
if (typeof AbortController === "undefined") {
|
|
8542
|
+
return fetch(input, init);
|
|
8543
|
+
}
|
|
8544
|
+
const controller = new AbortController();
|
|
8545
|
+
const outer = init.signal;
|
|
8546
|
+
if (outer) {
|
|
8547
|
+
if (outer.aborted) controller.abort();
|
|
8548
|
+
else outer.addEventListener("abort", () => controller.abort(), { once: true });
|
|
8549
|
+
}
|
|
8550
|
+
const timer = setTimeout(() => controller.abort(), budget);
|
|
8551
|
+
return fetch(input, { ...init, signal: controller.signal }).catch((err) => {
|
|
8552
|
+
clearTimeout(timer);
|
|
8553
|
+
throw err;
|
|
8554
|
+
});
|
|
8555
|
+
}
|
|
8556
|
+
function isAbortError(err) {
|
|
8557
|
+
return !!err && typeof err === "object" && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
8558
|
+
}
|
|
8559
|
+
const LAST_GOOD_PREFIX = "aegis_rail_lastgood:v1:";
|
|
8560
|
+
const LAST_GOOD_SPECIFIC_PREFIX = "aegis_rail_lastgood_specific:v1:";
|
|
8561
|
+
const POPULAR_PREFIX = "aegis_rail_popular:v1:";
|
|
8562
|
+
const RAIL_FALLBACK_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
8563
|
+
const RAIL_FALLBACK_MAX_BYTES = 15e4;
|
|
8564
|
+
const RAIL_FALLBACK_MAX_RAILS = 8;
|
|
8565
|
+
function lastGoodKey(ctx) {
|
|
8566
|
+
return `${LAST_GOOD_PREFIX}${ctx.propertyId || "-"}:${ctx.surface || "-"}:${ctx.screen || "-"}:${ctx.locationId || "-"}`;
|
|
8567
|
+
}
|
|
8568
|
+
function specificKey(ctx) {
|
|
8569
|
+
return `${LAST_GOOD_SPECIFIC_PREFIX}${ctx.propertyId || "-"}:${ctx.surface || "-"}:${ctx.screen || "-"}:${ctx.locationId || "-"}`;
|
|
8570
|
+
}
|
|
8571
|
+
const GENERIC_REC_SOURCES = /* @__PURE__ */ new Set(["trending", "top_rated", "manual"]);
|
|
8572
|
+
const ANCHORED_REASONS = /* @__PURE__ */ new Set(["similar", "same_category"]);
|
|
8573
|
+
const LIVE_CARD_KEYS = [
|
|
8574
|
+
"price",
|
|
8575
|
+
"compare_at_price",
|
|
8576
|
+
"original_price",
|
|
8577
|
+
"sale_price",
|
|
8578
|
+
"discount_pct",
|
|
8579
|
+
"stock",
|
|
8580
|
+
"in_stock",
|
|
8581
|
+
"stock_status",
|
|
8582
|
+
"stock_qty",
|
|
8583
|
+
"available",
|
|
8584
|
+
"availability",
|
|
8585
|
+
"sold_out"
|
|
8586
|
+
];
|
|
8587
|
+
function isAnchoredOrPersonal(c) {
|
|
8588
|
+
const ic = c.interactive_config || {};
|
|
8589
|
+
if (ic.rec_source !== void 0 && ic.rec_source !== null && ic.rec_source !== "") {
|
|
8590
|
+
if (typeof ic.rec_source !== "string" || !GENERIC_REC_SOURCES.has(ic.rec_source)) return true;
|
|
8591
|
+
} else if (c.type === "product_recommendation") {
|
|
8592
|
+
return true;
|
|
8593
|
+
}
|
|
8594
|
+
if (ic.already_won && typeof ic.already_won === "object") return true;
|
|
8595
|
+
const cards = Array.isArray(ic.cards) ? ic.cards : [];
|
|
8596
|
+
return cards.some((card) => {
|
|
8597
|
+
var _a;
|
|
8598
|
+
return typeof ((_a = card == null ? void 0 : card.metadata) == null ? void 0 : _a.reason) === "string" && ANCHORED_REASONS.has(card.metadata.reason);
|
|
8599
|
+
});
|
|
8600
|
+
}
|
|
8601
|
+
function stripLiveFacts(c) {
|
|
8602
|
+
const ic = c.interactive_config || {};
|
|
8603
|
+
if (!Array.isArray(ic.cards)) return c;
|
|
8604
|
+
const cards = ic.cards.map((card) => {
|
|
8605
|
+
const meta = { ...card.metadata || {} };
|
|
8606
|
+
for (const k of LIVE_CARD_KEYS) delete meta[k];
|
|
8607
|
+
const style = { ...card.style || {}, hide_price: true };
|
|
8608
|
+
delete style.badge;
|
|
8609
|
+
return { ...card, metadata: meta, style };
|
|
8610
|
+
});
|
|
8611
|
+
return { ...c, interactive_config: { ...ic, cards } };
|
|
8612
|
+
}
|
|
8613
|
+
function popularKey(ctx) {
|
|
8614
|
+
return `${POPULAR_PREFIX}${ctx.propertyId || "-"}:${ctx.locationId || "-"}`;
|
|
8615
|
+
}
|
|
8616
|
+
function isEmbeddedRail(c) {
|
|
8617
|
+
return Array.isArray(c.delivery_modes) && c.delivery_modes.includes("embedded_card");
|
|
8618
|
+
}
|
|
8619
|
+
function isPopularRail(c) {
|
|
8620
|
+
if (!isEmbeddedRail(c)) return false;
|
|
8621
|
+
const ic = c.interactive_config || {};
|
|
8622
|
+
if (ic.rec_source === "trending") return true;
|
|
8623
|
+
const cards = Array.isArray(ic.cards) ? ic.cards : [];
|
|
8624
|
+
return cards.length > 0 && cards.every((card) => {
|
|
8625
|
+
var _a;
|
|
8626
|
+
return ((_a = card == null ? void 0 : card.metadata) == null ? void 0 : _a.reason) === "popular_here";
|
|
8627
|
+
});
|
|
8628
|
+
}
|
|
8629
|
+
function embeddedOnly(c) {
|
|
8630
|
+
return { ...stripLiveFacts(c), delivery_modes: ["embedded_card"] };
|
|
8631
|
+
}
|
|
8632
|
+
function write(key, rails, now, audience) {
|
|
8633
|
+
try {
|
|
8634
|
+
if (typeof localStorage === "undefined") return;
|
|
8635
|
+
const raw = JSON.stringify({
|
|
8636
|
+
t: now,
|
|
8637
|
+
...audience ? { path: audience.path || null, contact: audience.contactId || null } : {},
|
|
8638
|
+
rails: rails.slice(0, RAIL_FALLBACK_MAX_RAILS).map(embeddedOnly)
|
|
8639
|
+
});
|
|
8640
|
+
if (raw.length > RAIL_FALLBACK_MAX_BYTES) return;
|
|
8641
|
+
localStorage.setItem(key, raw);
|
|
8642
|
+
} catch {
|
|
8643
|
+
}
|
|
8644
|
+
}
|
|
8645
|
+
function read(key, now, audience) {
|
|
8646
|
+
try {
|
|
8647
|
+
if (typeof localStorage === "undefined") return [];
|
|
8648
|
+
const raw = localStorage.getItem(key);
|
|
8649
|
+
if (!raw) return [];
|
|
8650
|
+
const parsed = JSON.parse(raw);
|
|
8651
|
+
if (typeof (parsed == null ? void 0 : parsed.t) !== "number" || now - parsed.t > RAIL_FALLBACK_TTL_MS || parsed.t > now + 6e4) {
|
|
8652
|
+
return [];
|
|
8653
|
+
}
|
|
8654
|
+
if (audience) {
|
|
8655
|
+
if ((parsed.path ?? null) !== (audience.path || null)) return [];
|
|
8656
|
+
if ((parsed.contact ?? null) !== (audience.contactId || null)) return [];
|
|
8657
|
+
}
|
|
8658
|
+
if (!Array.isArray(parsed.rails)) return [];
|
|
8659
|
+
return parsed.rails.filter(
|
|
8660
|
+
(c) => !!c && typeof c === "object" && typeof c.id === "string" && isEmbeddedRail(c)
|
|
8661
|
+
);
|
|
8662
|
+
} catch {
|
|
8663
|
+
return [];
|
|
8664
|
+
}
|
|
8665
|
+
}
|
|
8666
|
+
function saveGoodRails(ctx, campaigns, now = Date.now(), audience = {}) {
|
|
8667
|
+
const rails = campaigns.filter(isEmbeddedRail);
|
|
8668
|
+
const generic = rails.filter((c) => !isAnchoredOrPersonal(c));
|
|
8669
|
+
const specific = rails.filter(isAnchoredOrPersonal);
|
|
8670
|
+
const save = (key, list, aud) => {
|
|
8671
|
+
if (list.length === 0) {
|
|
8672
|
+
try {
|
|
8673
|
+
if (typeof localStorage !== "undefined") localStorage.removeItem(key);
|
|
8674
|
+
} catch {
|
|
8675
|
+
}
|
|
8676
|
+
} else {
|
|
8677
|
+
write(key, list, now, aud);
|
|
8678
|
+
}
|
|
8679
|
+
};
|
|
8680
|
+
save(lastGoodKey(ctx), generic);
|
|
8681
|
+
save(specificKey(ctx), specific, audience);
|
|
8682
|
+
const popular = rails.filter((c) => isPopularRail(c) && !isAnchoredOrPersonal(c));
|
|
8683
|
+
if (popular.length > 0) write(popularKey(ctx), popular, now);
|
|
8684
|
+
}
|
|
8685
|
+
function readRailFallback(ctx, now = Date.now(), audience = {}) {
|
|
8686
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8687
|
+
const lastGood = [...read(specificKey(ctx), now, audience), ...read(lastGoodKey(ctx), now)].filter((c) => {
|
|
8688
|
+
if (seen.has(c.id)) return false;
|
|
8689
|
+
seen.add(c.id);
|
|
8690
|
+
return true;
|
|
8691
|
+
});
|
|
8692
|
+
if (lastGood.length > 0) return { tier: "last_good", campaigns: lastGood };
|
|
8693
|
+
const popular = read(popularKey(ctx), now);
|
|
8694
|
+
if (popular.length > 0) return { tier: "popular", campaigns: popular };
|
|
8695
|
+
return { tier: "hidden", campaigns: [] };
|
|
8696
|
+
}
|
|
8254
8697
|
function readAnonIdFromStorage$1() {
|
|
8255
8698
|
if (typeof document === "undefined") return void 0;
|
|
8256
8699
|
try {
|
|
@@ -8341,6 +8784,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8341
8784
|
this.displayedCampaigns = /* @__PURE__ */ new Set();
|
|
8342
8785
|
this._displaySizeMul = 1;
|
|
8343
8786
|
this.suppressedUntil = /* @__PURE__ */ new Map();
|
|
8787
|
+
this.overlaysHeld = false;
|
|
8344
8788
|
this.isInitialized = false;
|
|
8345
8789
|
this.reconnectAttempts = 0;
|
|
8346
8790
|
this.maxReconnectAttempts = 5;
|
|
@@ -8353,6 +8797,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8353
8797
|
this.currentSurface = null;
|
|
8354
8798
|
this.currentScreen = null;
|
|
8355
8799
|
this.currentLocationId = null;
|
|
8800
|
+
this.currentCartProductIds = null;
|
|
8356
8801
|
this._lastDispatch = null;
|
|
8357
8802
|
this.filledSlots = /* @__PURE__ */ new WeakSet();
|
|
8358
8803
|
this.slotSignatures = /* @__PURE__ */ new WeakMap();
|
|
@@ -8360,18 +8805,25 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8360
8805
|
this.slotTimers = /* @__PURE__ */ new WeakMap();
|
|
8361
8806
|
this.renderedSlots = /* @__PURE__ */ new Set();
|
|
8362
8807
|
this.slotObserver = null;
|
|
8808
|
+
this.anchorWrappers = /* @__PURE__ */ new WeakMap();
|
|
8809
|
+
this.ownAnchorWrappers = /* @__PURE__ */ new Set();
|
|
8363
8810
|
this.phoneVariantMedia = null;
|
|
8364
8811
|
this.onPhoneVariantChange = () => {
|
|
8365
8812
|
if (this.slotsTornDown || typeof document === "undefined") return;
|
|
8366
8813
|
if (document.querySelector(`[data-aegis-slot][${SLOT_VARIANT_PHONE_ATTR}]`)) this.renderIntoSlots();
|
|
8367
8814
|
};
|
|
8368
8815
|
this.slotRenderScheduled = false;
|
|
8816
|
+
this.pendingSlotRender = false;
|
|
8817
|
+
this.pendingAnchorRender = false;
|
|
8369
8818
|
this.slotsTornDown = false;
|
|
8370
8819
|
this.campaignsLoaded = false;
|
|
8371
8820
|
this.shellTimeout = null;
|
|
8372
8821
|
this.lifecycleGen = 0;
|
|
8373
8822
|
this.slotUnfilledBeaconed = /* @__PURE__ */ new Set();
|
|
8374
8823
|
this.slotUnfilledSweepTimer = null;
|
|
8824
|
+
this.railFallbackTier = null;
|
|
8825
|
+
this.retryAnswers = /* @__PURE__ */ new Map();
|
|
8826
|
+
this.anonClaims = loadAnonClaims();
|
|
8375
8827
|
this._pushOptInLoading = false;
|
|
8376
8828
|
this.journeyStepByCampaign = /* @__PURE__ */ new Map();
|
|
8377
8829
|
this.journeyAcks = /* @__PURE__ */ new Set();
|
|
@@ -8383,7 +8835,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8383
8835
|
this.organizationId = config.organizationId;
|
|
8384
8836
|
this.propertyId = config.propertyId;
|
|
8385
8837
|
this.debugMode = config.debugMode || false;
|
|
8386
|
-
this.
|
|
8838
|
+
this.previewOnly = config.previewOnly === true || isPreviewPage();
|
|
8839
|
+
this.enableSSE = config.enableSSE === true && !this.previewOnly;
|
|
8387
8840
|
this.onActionHandler = config.onAction;
|
|
8388
8841
|
if (config.productUrl) this.productUrl = config.productUrl;
|
|
8389
8842
|
this.getWorkspaceId = config.getWorkspaceId;
|
|
@@ -8395,13 +8848,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8395
8848
|
if (screen && screen !== "page_view") this.currentScreen = screen;
|
|
8396
8849
|
if (config.locationId) this.currentLocationId = config.locationId;
|
|
8397
8850
|
}
|
|
8398
|
-
emit(eventName, payload) {
|
|
8851
|
+
emit(eventName, payload, info) {
|
|
8399
8852
|
const handlers = this.hooks.get(eventName);
|
|
8400
8853
|
if (!handlers || handlers.size === 0) return true;
|
|
8401
8854
|
let proceed = true;
|
|
8402
8855
|
for (const handler of handlers) {
|
|
8403
8856
|
try {
|
|
8404
|
-
const result = handler(payload);
|
|
8857
|
+
const result = handler(payload, info);
|
|
8405
8858
|
if (result === false) proceed = false;
|
|
8406
8859
|
} catch (err) {
|
|
8407
8860
|
this.emitError(err, { event: eventName });
|
|
@@ -8426,6 +8879,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8426
8879
|
}
|
|
8427
8880
|
}
|
|
8428
8881
|
}
|
|
8882
|
+
// `info` is the optional second argument some events carry
|
|
8883
|
+
// (`campaign-will-show` -> CampaignWillShowInfo); `never` lets both one- and
|
|
8884
|
+
// two-argument handlers register.
|
|
8429
8885
|
register(eventName, handler) {
|
|
8430
8886
|
if (!this.hooks.has(eventName)) this.hooks.set(eventName, /* @__PURE__ */ new Set());
|
|
8431
8887
|
this.hooks.get(eventName).add(handler);
|
|
@@ -8455,7 +8911,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8455
8911
|
}
|
|
8456
8912
|
/** Sugar: subscribe to `campaign-will-show`. CANCELLABLE — return `false`
|
|
8457
8913
|
* to suppress rendering this campaign (host-side suppression rules,
|
|
8458
|
-
* route-aware blocking, etc.).
|
|
8914
|
+
* route-aware blocking, etc.). The second argument says where it renders
|
|
8915
|
+
* (`{ target: 'slot' | 'overlay' }`). */
|
|
8459
8916
|
onCampaignWillShow(handler) {
|
|
8460
8917
|
return this.register("campaign-will-show", handler);
|
|
8461
8918
|
}
|
|
@@ -8487,9 +8944,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8487
8944
|
this.log("AegisInApp already initialized");
|
|
8488
8945
|
return;
|
|
8489
8946
|
}
|
|
8490
|
-
markReturningVisitor();
|
|
8947
|
+
if (!this.previewOnly) markReturningVisitor();
|
|
8491
8948
|
try {
|
|
8492
|
-
if (typeof localStorage !== "undefined") {
|
|
8949
|
+
if (!this.previewOnly && typeof localStorage !== "undefined") {
|
|
8493
8950
|
const pv = parseInt(localStorage.getItem("aegis_pv_count") || "0", 10);
|
|
8494
8951
|
localStorage.setItem("aegis_pv_count", String(pv + 1));
|
|
8495
8952
|
}
|
|
@@ -8537,6 +8994,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8537
8994
|
this.log("AegisInApp initialized successfully");
|
|
8538
8995
|
}
|
|
8539
8996
|
async _sendPushBootBeacon() {
|
|
8997
|
+
if (this.previewOnly) return;
|
|
8540
8998
|
try {
|
|
8541
8999
|
if (sessionStorage.getItem("aegis_push_boot_beacon") === "1") return;
|
|
8542
9000
|
} catch {
|
|
@@ -8607,6 +9065,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8607
9065
|
var _a;
|
|
8608
9066
|
this.contactId = contactId;
|
|
8609
9067
|
this.contactToken = contactToken;
|
|
9068
|
+
if (contactToken && (this.anonClaims.pending.length || loadAnonClaims().pending.length)) {
|
|
9069
|
+
void this.claimPendingAnonWins();
|
|
9070
|
+
}
|
|
8610
9071
|
(_a = this.activeWebChat) == null ? void 0 : _a.updateContactId(contactId);
|
|
8611
9072
|
this.disconnectSSE();
|
|
8612
9073
|
if (this.enableSSE && this.organizationId) {
|
|
@@ -8617,7 +9078,30 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8617
9078
|
/** The page context a `/v1/in-app/active` request is built from now. */
|
|
8618
9079
|
activeRequestKey() {
|
|
8619
9080
|
const url = this.currentPageUrl() ?? "/";
|
|
8620
|
-
return [url, this.currentSurface ?? "", this.currentScreen ?? "", this.currentLocationId ?? ""].join("|");
|
|
9081
|
+
return [url, this.currentSurface ?? "", this.currentScreen ?? "", this.currentLocationId ?? "", this.cartKeyPart()].join("|");
|
|
9082
|
+
}
|
|
9083
|
+
/** The cart ids as a request-key part: sorted + deduped so a reorder is not a
|
|
9084
|
+
* change; `-` = no cart known, distinct from `` = an empty cart. */
|
|
9085
|
+
cartKeyPart() {
|
|
9086
|
+
return this.cartKeyPartOf(this.currentCartProductIds);
|
|
9087
|
+
}
|
|
9088
|
+
/** Host order, trimmed + deduped. An id with a comma is dropped: the server
|
|
9089
|
+
* splits the param on commas, so it could not round-trip. */
|
|
9090
|
+
normalizeCartIds(ids) {
|
|
9091
|
+
const out = [];
|
|
9092
|
+
for (const raw of ids) {
|
|
9093
|
+
const id = String(raw).trim();
|
|
9094
|
+
if (!id) continue;
|
|
9095
|
+
if (id.includes(",")) {
|
|
9096
|
+
this.log(`setPageContext: dropping cart_product_id containing a comma: ${id}`, "warn");
|
|
9097
|
+
continue;
|
|
9098
|
+
}
|
|
9099
|
+
if (!out.includes(id)) out.push(id);
|
|
9100
|
+
}
|
|
9101
|
+
return out;
|
|
9102
|
+
}
|
|
9103
|
+
cartKeyPartOf(ids) {
|
|
9104
|
+
return ids === null ? "-" : [...ids].sort().join(",");
|
|
8621
9105
|
}
|
|
8622
9106
|
/**
|
|
8623
9107
|
* Qualifying-event refresh — schedule a debounced `refreshCampaigns()`
|
|
@@ -8692,7 +9176,10 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8692
9176
|
const next = locationId || null;
|
|
8693
9177
|
if (next === this.currentLocationId) return;
|
|
8694
9178
|
this.currentLocationId = next;
|
|
8695
|
-
if (!this.isInitialized)
|
|
9179
|
+
if (!this.isInitialized) {
|
|
9180
|
+
this.pendingPreInitRefresh = true;
|
|
9181
|
+
return;
|
|
9182
|
+
}
|
|
8696
9183
|
if (this.refreshDebounceTimer) {
|
|
8697
9184
|
clearTimeout(this.refreshDebounceTimer);
|
|
8698
9185
|
}
|
|
@@ -8702,6 +9189,33 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8702
9189
|
void this.refreshCampaigns();
|
|
8703
9190
|
}, _AegisInAppManager.REFRESH_DEBOUNCE_MS);
|
|
8704
9191
|
}
|
|
9192
|
+
/**
|
|
9193
|
+
* Page context beyond surface / screen / outlet. `cart_product_ids` is the
|
|
9194
|
+
* catalogue product ids in the shopper's cart: `undefined` leaves it as is,
|
|
9195
|
+
* `null` clears it (no cart known, param omitted), `[]` declares an EMPTY
|
|
9196
|
+
* cart (param sent empty). Threaded to `/v1/in-app/active?cart_product_ids=`
|
|
9197
|
+
* so cart rails can anchor on the cart.
|
|
9198
|
+
*
|
|
9199
|
+
* No-ops when the normalized ids are unchanged; otherwise debounce-refreshes.
|
|
9200
|
+
*/
|
|
9201
|
+
setPageContext(ctx) {
|
|
9202
|
+
if (ctx.cart_product_ids === void 0) return;
|
|
9203
|
+
const next = ctx.cart_product_ids === null ? null : this.normalizeCartIds(ctx.cart_product_ids);
|
|
9204
|
+
if (this.cartKeyPartOf(next) === this.cartKeyPart()) return;
|
|
9205
|
+
this.currentCartProductIds = next;
|
|
9206
|
+
if (!this.isInitialized) {
|
|
9207
|
+
this.pendingPreInitRefresh = true;
|
|
9208
|
+
return;
|
|
9209
|
+
}
|
|
9210
|
+
if (this.refreshDebounceTimer) {
|
|
9211
|
+
clearTimeout(this.refreshDebounceTimer);
|
|
9212
|
+
}
|
|
9213
|
+
this.refreshDebounceTimer = setTimeout(() => {
|
|
9214
|
+
this.refreshDebounceTimer = void 0;
|
|
9215
|
+
this.log("setPageContext(cart_product_ids) — firing refreshCampaigns()");
|
|
9216
|
+
void this.refreshCampaigns();
|
|
9217
|
+
}, _AegisInAppManager.REFRESH_DEBOUNCE_MS);
|
|
9218
|
+
}
|
|
8705
9219
|
/**
|
|
8706
9220
|
* Conversion-aware suppression. Call this when the host app observes a
|
|
8707
9221
|
* goal event (purchase, order_placed, checkout_completed, or any custom
|
|
@@ -8930,10 +9444,21 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8930
9444
|
if (this.currentLocationId) {
|
|
8931
9445
|
context.set("location_id", this.currentLocationId);
|
|
8932
9446
|
}
|
|
9447
|
+
if (this.currentCartProductIds !== null) {
|
|
9448
|
+
context.set("cart_product_ids", this.currentCartProductIds.join(","));
|
|
9449
|
+
}
|
|
9450
|
+
const previewAsOf = previewAsOfToken();
|
|
9451
|
+
if (previewAsOf) {
|
|
9452
|
+
context.set("preview_as_of", previewAsOf);
|
|
9453
|
+
}
|
|
9454
|
+
if (this.previewOnly) {
|
|
9455
|
+
context.set("preview", "1");
|
|
9456
|
+
}
|
|
8933
9457
|
const url = `${this.apiHost}/v1/in-app/active?${context.toString()}`;
|
|
8934
9458
|
requestKey = this.activeRequestKey();
|
|
8935
9459
|
this.lastActiveRequestKey = requestKey;
|
|
8936
9460
|
const shellCtx = this.shellContext();
|
|
9461
|
+
const railAudience = this.railAudience();
|
|
8937
9462
|
const headers = {
|
|
8938
9463
|
"X-Aegis-Write-Key": this.writeKey,
|
|
8939
9464
|
"Content-Type": "application/json"
|
|
@@ -8957,7 +9482,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8957
9482
|
if (Object.keys(abAssignments).length > 0) {
|
|
8958
9483
|
headers["X-AB-Assignments"] = btoa(JSON.stringify(abAssignments));
|
|
8959
9484
|
}
|
|
8960
|
-
const response = await
|
|
9485
|
+
const response = await fetchWithAbort(url, {
|
|
8961
9486
|
method: "GET",
|
|
8962
9487
|
headers,
|
|
8963
9488
|
credentials: "include"
|
|
@@ -8970,6 +9495,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8970
9495
|
if (gen !== this.lifecycleGen) return;
|
|
8971
9496
|
this.campaigns = Array.isArray(payload) ? payload : [];
|
|
8972
9497
|
this.campaignsLoaded = true;
|
|
9498
|
+
this.railFallbackTier = null;
|
|
8973
9499
|
this.campaignsRequestKey = requestKey;
|
|
8974
9500
|
this.clearShellTimeout();
|
|
8975
9501
|
applyCampaignFonts(this.campaigns);
|
|
@@ -8982,7 +9508,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8982
9508
|
this.mountPersistentLaunchers();
|
|
8983
9509
|
this.tryDisplayNextCampaign();
|
|
8984
9510
|
this.renderIntoSlots();
|
|
8985
|
-
this.saveSlotShapes(shellCtx);
|
|
9511
|
+
if (!this.previewOnly) this.saveSlotShapes(shellCtx);
|
|
9512
|
+
if (!this.previewOnly) saveGoodRails(shellCtx, this.campaigns, Date.now(), railAudience);
|
|
8986
9513
|
this.renderIntoAnchors();
|
|
8987
9514
|
this.renderTokenAnchors();
|
|
8988
9515
|
} catch (error) {
|
|
@@ -8990,12 +9517,16 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8990
9517
|
this.lastActiveRequestKey = void 0;
|
|
8991
9518
|
}
|
|
8992
9519
|
if (gen !== this.lifecycleGen) return;
|
|
8993
|
-
if (!this.campaignsLoaded)
|
|
9520
|
+
if (!this.campaignsLoaded) {
|
|
9521
|
+
this.applyRailFallback();
|
|
9522
|
+
this.removeShells();
|
|
9523
|
+
}
|
|
8994
9524
|
this.emitError(error, { stage: "refresh-campaigns" });
|
|
8995
9525
|
this.log(`Error refreshing campaigns: ${error}`, "error");
|
|
8996
9526
|
}
|
|
8997
9527
|
}
|
|
8998
9528
|
emitServedEvents(campaigns) {
|
|
9529
|
+
if (this.previewOnly) return;
|
|
8999
9530
|
if (typeof sessionStorage === "undefined") {
|
|
9000
9531
|
for (const c of campaigns) {
|
|
9001
9532
|
void this.trackEvent(c.id, "served");
|
|
@@ -9048,7 +9579,34 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9048
9579
|
const assignments = this.getABAssignments();
|
|
9049
9580
|
return assignments[campaignId] ?? void 0;
|
|
9050
9581
|
}
|
|
9582
|
+
/**
|
|
9583
|
+
* Hold every automatic overlay (pop-up, half sheet, full screen …) until
|
|
9584
|
+
* `releaseOverlays()`. A host whose page must not be interrupted yet (the bill
|
|
9585
|
+
* before it is paid, Active Bill Q15) calls this BEFORE `initialize()`; the
|
|
9586
|
+
* campaigns still load and fill their slots, only the overlay pick waits.
|
|
9587
|
+
*/
|
|
9588
|
+
holdOverlays() {
|
|
9589
|
+
this.overlaysHeld = true;
|
|
9590
|
+
}
|
|
9591
|
+
/**
|
|
9592
|
+
* Lift `holdOverlays()` and run the overlay pick once, so the page gets at
|
|
9593
|
+
* most the one overlay the pick would have shown on load, with the same
|
|
9594
|
+
* pacing (`displayedCampaigns`, caps, suppression). No-op when not held.
|
|
9595
|
+
*/
|
|
9596
|
+
releaseOverlays() {
|
|
9597
|
+
if (!this.overlaysHeld) return;
|
|
9598
|
+
this.overlaysHeld = false;
|
|
9599
|
+
if (this.campaigns.length > 0) this.tryDisplayNextCampaign();
|
|
9600
|
+
}
|
|
9601
|
+
/** True while `holdOverlays()` is in force. */
|
|
9602
|
+
overlaysAreHeld() {
|
|
9603
|
+
return this.overlaysHeld;
|
|
9604
|
+
}
|
|
9051
9605
|
tryDisplayNextCampaign() {
|
|
9606
|
+
if (this.overlaysHeld) {
|
|
9607
|
+
this.log("overlay pick skipped: overlays held by the host");
|
|
9608
|
+
return;
|
|
9609
|
+
}
|
|
9052
9610
|
const campaign = this.campaigns.find(
|
|
9053
9611
|
(c) => !this.displayedCampaigns.has(c.id) && !c.client_trigger && !this.isSuppressed(c.id) && c.type !== "active_web_chat" && (c.sub_type !== "push_primer" || this._primerEligibleNow()) && !(Array.isArray(c.delivery_modes) && c.delivery_modes.length > 0 && !c.delivery_modes.includes("in_app_overlay"))
|
|
9054
9612
|
);
|
|
@@ -9174,6 +9732,35 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9174
9732
|
this.log(`slot shells skipped: ${err}`, "warn");
|
|
9175
9733
|
}
|
|
9176
9734
|
}
|
|
9735
|
+
/**
|
|
9736
|
+
* WP17 rail fallback: last good rails for this page → the brand's popular
|
|
9737
|
+
* rails → hidden. Rails only (stored embedded-only), never an overlay, never
|
|
9738
|
+
* `served`/`campaigns-loaded`: a real /active answer replaces them. Fail-soft:
|
|
9739
|
+
* a fallback error just leaves the slots empty.
|
|
9740
|
+
*/
|
|
9741
|
+
applyRailFallback() {
|
|
9742
|
+
if (typeof document === "undefined" || this.slotsTornDown) return;
|
|
9743
|
+
try {
|
|
9744
|
+
const fb = readRailFallback(this.shellContext(), Date.now(), this.railAudience());
|
|
9745
|
+
this.railFallbackTier = fb.tier;
|
|
9746
|
+
if (fb.tier === "hidden") return;
|
|
9747
|
+
const held = new Set(this.campaigns.map((c) => c.id));
|
|
9748
|
+
this.campaigns = [...this.campaigns, ...fb.campaigns.filter((c) => !held.has(c.id))];
|
|
9749
|
+
this.log(`/active did not answer: painting ${fb.campaigns.length} ${fb.tier} rail(s)`, "warn");
|
|
9750
|
+
this.renderIntoSlots();
|
|
9751
|
+
} catch (err) {
|
|
9752
|
+
this.log(`rail fallback skipped: ${err}`, "warn");
|
|
9753
|
+
}
|
|
9754
|
+
}
|
|
9755
|
+
/** Who / where anchored or personal rails answer (rail-fallback.ts). */
|
|
9756
|
+
railAudience() {
|
|
9757
|
+
const path = typeof window !== "undefined" && window.location ? window.location.pathname || "/" : null;
|
|
9758
|
+
return { path, contactId: this.contactId ?? null };
|
|
9759
|
+
}
|
|
9760
|
+
/** The fallback tier in use after a failed first /active (null when none). */
|
|
9761
|
+
getRailFallbackTier() {
|
|
9762
|
+
return this.railFallbackTier;
|
|
9763
|
+
}
|
|
9177
9764
|
clearShellTimeout() {
|
|
9178
9765
|
if (this.shellTimeout) {
|
|
9179
9766
|
clearTimeout(this.shellTimeout);
|
|
@@ -9217,34 +9804,52 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9217
9804
|
":scope > [data-aegis-rotate-stack], :scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
|
|
9218
9805
|
).forEach((n) => n.remove());
|
|
9219
9806
|
}
|
|
9220
|
-
// Re-fill
|
|
9221
|
-
//
|
|
9222
|
-
//
|
|
9223
|
-
//
|
|
9224
|
-
//
|
|
9807
|
+
// Re-fill spots that mount after a poll (SPA route changes, a section drawn
|
|
9808
|
+
// after a client-side step). Observes the DOM once; when a new
|
|
9809
|
+
// [data-aegis-slot] appears it re-runs renderIntoSlots, and when an element
|
|
9810
|
+
// a cached campaign is anchored to appears (a Promo spot section's
|
|
9811
|
+
// [data-aegis-section-spot] box, or any operator element anchor) it re-runs
|
|
9812
|
+
// renderIntoAnchors, both from the cached campaigns (idempotent: filled
|
|
9813
|
+
// spots are skipped, a before/after wrapper is reused). Does NOT loop on
|
|
9814
|
+
// the SDK's own injections: a re-run adds nothing to a filled spot.
|
|
9225
9815
|
ensureSlotObserver() {
|
|
9226
9816
|
if (this.slotObserver || typeof MutationObserver === "undefined" || typeof document === "undefined") {
|
|
9227
9817
|
return;
|
|
9228
9818
|
}
|
|
9229
9819
|
this.slotObserver = new MutationObserver((mutations) => {
|
|
9230
9820
|
let sawSlot = false;
|
|
9821
|
+
let sawAnchor = false;
|
|
9822
|
+
const anchorSelectors = this.cachedAnchorSelectors();
|
|
9823
|
+
const hits = (el2, sel) => {
|
|
9824
|
+
var _a, _b;
|
|
9825
|
+
try {
|
|
9826
|
+
return !!(((_a = el2.matches) == null ? void 0 : _a.call(el2, sel)) || ((_b = el2.querySelector) == null ? void 0 : _b.call(el2, sel)));
|
|
9827
|
+
} catch {
|
|
9828
|
+
return false;
|
|
9829
|
+
}
|
|
9830
|
+
};
|
|
9231
9831
|
for (const m2 of mutations) {
|
|
9232
9832
|
m2.addedNodes.forEach((n) => {
|
|
9233
|
-
|
|
9234
|
-
if (sawSlot || n.nodeType !== 1) return;
|
|
9833
|
+
if (n.nodeType !== 1) return;
|
|
9235
9834
|
const el2 = n;
|
|
9236
|
-
if (
|
|
9237
|
-
|
|
9238
|
-
}
|
|
9835
|
+
if (!sawSlot && hits(el2, "[data-aegis-slot]")) sawSlot = true;
|
|
9836
|
+
if (!sawAnchor && anchorSelectors.some((sel) => hits(el2, sel))) sawAnchor = true;
|
|
9239
9837
|
});
|
|
9240
|
-
if (sawSlot) break;
|
|
9838
|
+
if (sawSlot && sawAnchor) break;
|
|
9241
9839
|
}
|
|
9242
|
-
if (
|
|
9840
|
+
if (sawSlot) this.pendingSlotRender = true;
|
|
9841
|
+
if (sawAnchor) this.pendingAnchorRender = true;
|
|
9842
|
+
if (!sawSlot && !sawAnchor || this.slotRenderScheduled) return;
|
|
9243
9843
|
this.slotRenderScheduled = true;
|
|
9244
9844
|
const run = () => {
|
|
9245
9845
|
this.slotRenderScheduled = false;
|
|
9846
|
+
const slots = this.pendingSlotRender;
|
|
9847
|
+
const anchors = this.pendingAnchorRender;
|
|
9848
|
+
this.pendingSlotRender = false;
|
|
9849
|
+
this.pendingAnchorRender = false;
|
|
9246
9850
|
if (this.slotsTornDown) return;
|
|
9247
|
-
this.renderIntoSlots();
|
|
9851
|
+
if (slots) this.renderIntoSlots();
|
|
9852
|
+
if (anchors) this.renderIntoAnchors({ reportUnresolved: false });
|
|
9248
9853
|
};
|
|
9249
9854
|
if (typeof requestAnimationFrame === "function") requestAnimationFrame(run);
|
|
9250
9855
|
else setTimeout(run, 0);
|
|
@@ -9502,6 +10107,20 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9502
10107
|
window.addEventListener("beforeunload", () => timer && clearInterval(timer), { once: true });
|
|
9503
10108
|
}
|
|
9504
10109
|
}
|
|
10110
|
+
/** Element-anchor selectors of the cached inline campaigns placeable here:
|
|
10111
|
+
* what the slot observer watches for (a Promo spot section mounted after
|
|
10112
|
+
* /active answered). */
|
|
10113
|
+
cachedAnchorSelectors() {
|
|
10114
|
+
var _a;
|
|
10115
|
+
const out = [];
|
|
10116
|
+
for (const c of this.campaigns) {
|
|
10117
|
+
if (!c.delivery_modes || !c.delivery_modes.includes("embedded_card")) continue;
|
|
10118
|
+
const ic = c.interactive_config;
|
|
10119
|
+
const sel = (_a = ic == null ? void 0 : ic.anchor) == null ? void 0 : _a.element_selector;
|
|
10120
|
+
if (typeof sel === "string" && sel && !out.includes(sel)) out.push(sel);
|
|
10121
|
+
}
|
|
10122
|
+
return out;
|
|
10123
|
+
}
|
|
9505
10124
|
/**
|
|
9506
10125
|
* Surface-Canvas inline element anchoring (Plotline / WebEngage model).
|
|
9507
10126
|
*
|
|
@@ -9515,12 +10134,19 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9515
10134
|
* Reuses `renderCampaignIntoSlot` (same sub_type dispatch → `renderProgressBarInline`
|
|
9516
10135
|
* etc.) so inline render code is single-sourced with the slot path. Embedded-card
|
|
9517
10136
|
* gated (so an anchored campaign never ALSO renders as an overlay), surface-gated,
|
|
9518
|
-
* and idempotent via `filledSlots` keyed on the resolved element.
|
|
9519
|
-
*
|
|
10137
|
+
* and idempotent via `filledSlots` keyed on the resolved element.
|
|
10138
|
+
*
|
|
10139
|
+
* A selector that doesn't resolve emits `anchor_unresolved` (parity with tooltip
|
|
10140
|
+
* anchoring) only on the /active pass (`reportUnresolved` unset or true). The slot
|
|
10141
|
+
* observer's re-runs pass `reportUnresolved: false` and stay silent: an anchor
|
|
10142
|
+
* that mounts later (a Promo spot section) is not missing, and a DOM change must
|
|
10143
|
+
* never emit one event per campaign per mutation.
|
|
9520
10144
|
*/
|
|
9521
|
-
renderIntoAnchors() {
|
|
10145
|
+
renderIntoAnchors(opts = {}) {
|
|
9522
10146
|
var _a;
|
|
9523
|
-
if (typeof document === "undefined") return;
|
|
10147
|
+
if (typeof document === "undefined" || this.slotsTornDown) return;
|
|
10148
|
+
this.ensureSlotObserver();
|
|
10149
|
+
const reportUnresolved = opts.reportUnresolved !== false;
|
|
9524
10150
|
for (const c of this.campaigns) {
|
|
9525
10151
|
if (!this.isPlaceableHere(c)) continue;
|
|
9526
10152
|
const modes = c.delivery_modes;
|
|
@@ -9536,17 +10162,31 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9536
10162
|
el2 = null;
|
|
9537
10163
|
}
|
|
9538
10164
|
if (!el2) {
|
|
9539
|
-
|
|
9540
|
-
|
|
9541
|
-
|
|
10165
|
+
if (reportUnresolved) {
|
|
10166
|
+
void this.trackEvent(c.id, "anchor_unresolved", {
|
|
10167
|
+
meta: { anchor_resolved: false, anchor_selector: selector, widget_type: c.sub_type }
|
|
10168
|
+
});
|
|
10169
|
+
}
|
|
9542
10170
|
continue;
|
|
9543
10171
|
}
|
|
9544
10172
|
const position = (anchor == null ? void 0 : anchor.position) || "inside";
|
|
9545
10173
|
let target;
|
|
9546
10174
|
if (position === "before" || position === "after") {
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
10175
|
+
let byCampaign = this.anchorWrappers.get(el2);
|
|
10176
|
+
if (!byCampaign) {
|
|
10177
|
+
byCampaign = /* @__PURE__ */ new Map();
|
|
10178
|
+
this.anchorWrappers.set(el2, byCampaign);
|
|
10179
|
+
}
|
|
10180
|
+
const kept = byCampaign.get(c.id);
|
|
10181
|
+
if (kept && kept.isConnected) {
|
|
10182
|
+
target = kept;
|
|
10183
|
+
} else {
|
|
10184
|
+
target = document.createElement("div");
|
|
10185
|
+
target.setAttribute("data-aegis-anchor-wrapper", c.id);
|
|
10186
|
+
(_a = el2.parentNode) == null ? void 0 : _a.insertBefore(target, position === "before" ? el2 : el2.nextSibling);
|
|
10187
|
+
byCampaign.set(c.id, target);
|
|
10188
|
+
this.ownAnchorWrappers.add(target);
|
|
10189
|
+
}
|
|
9550
10190
|
} else {
|
|
9551
10191
|
target = el2;
|
|
9552
10192
|
if (position === "replace") {
|
|
@@ -9562,8 +10202,17 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9562
10202
|
}
|
|
9563
10203
|
}
|
|
9564
10204
|
if (this.filledSlots.has(target)) continue;
|
|
9565
|
-
this.
|
|
10205
|
+
this.clearSlotContent(target);
|
|
10206
|
+
const host = document.createElement("div");
|
|
10207
|
+
host.setAttribute("data-aegis-slot-rendered", c.id);
|
|
10208
|
+
target.appendChild(host);
|
|
10209
|
+
this.renderCampaignIntoSlot(c, host);
|
|
10210
|
+
if (host.childElementCount === 0) {
|
|
10211
|
+
host.remove();
|
|
10212
|
+
continue;
|
|
10213
|
+
}
|
|
9566
10214
|
this.filledSlots.add(target);
|
|
10215
|
+
this.renderedSlots.add(target);
|
|
9567
10216
|
}
|
|
9568
10217
|
}
|
|
9569
10218
|
/**
|
|
@@ -9633,7 +10282,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9633
10282
|
* skip — those types only make sense as fullscreen overlays.
|
|
9634
10283
|
*/
|
|
9635
10284
|
renderCampaignIntoSlot(campaign, target, options) {
|
|
9636
|
-
const
|
|
10285
|
+
const willShow = { target: "slot" };
|
|
10286
|
+
const proceed = this.emit("campaign-will-show", campaign, willShow);
|
|
9637
10287
|
if (!proceed) {
|
|
9638
10288
|
this.log(
|
|
9639
10289
|
`slot campaign ${campaign.id} suppressed by campaign-will-show handler`
|
|
@@ -10132,6 +10782,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10132
10782
|
/** POST a form response to /in-app/responses (gateway → cell-plane). The
|
|
10133
10783
|
* cell-plane enriches the contact from the campaign's field-map. Best-effort. */
|
|
10134
10784
|
async submitFormResponse(campaign, fields) {
|
|
10785
|
+
if (this.previewOnly) return;
|
|
10135
10786
|
if (!this.organizationId) {
|
|
10136
10787
|
this.log("submitFormResponse: no organizationId — cannot submit", "warn");
|
|
10137
10788
|
return;
|
|
@@ -10168,14 +10819,88 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10168
10819
|
this.log(`submitFormResponse error: ${e}`, "warn");
|
|
10169
10820
|
}
|
|
10170
10821
|
}
|
|
10171
|
-
/**
|
|
10172
|
-
*
|
|
10173
|
-
*
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10822
|
+
/** The claim button's action: claim now when signed in, else ask the host to
|
|
10823
|
+
* open its sign-in (the existing OTP sign-in) and claim once it hands us a
|
|
10824
|
+
* contact token (`updateContactId`). */
|
|
10825
|
+
startAnonClaim(campaignId) {
|
|
10826
|
+
if (!this.anonClaims.pending.includes(campaignId)) this.anonClaims.pending.push(campaignId);
|
|
10827
|
+
saveAnonClaims(this.anonClaims);
|
|
10828
|
+
if (this.contactId && this.contactToken) {
|
|
10829
|
+
void this.claimPendingAnonWins();
|
|
10830
|
+
return;
|
|
10831
|
+
}
|
|
10832
|
+
this.dispatchAction({ type: "open_login" }, campaignId);
|
|
10833
|
+
}
|
|
10834
|
+
async claimPendingAnonWins() {
|
|
10835
|
+
const saved = loadAnonClaims();
|
|
10836
|
+
this.anonClaims = {
|
|
10837
|
+
pending: Array.from(/* @__PURE__ */ new Set([...saved.pending, ...this.anonClaims.pending])),
|
|
10838
|
+
tickets: { ...saved.tickets, ...this.anonClaims.tickets }
|
|
10839
|
+
};
|
|
10840
|
+
const ids = this.anonClaims.pending.slice();
|
|
10841
|
+
this.anonClaims.pending = [];
|
|
10842
|
+
saveAnonClaims(this.anonClaims);
|
|
10843
|
+
for (const id of ids) {
|
|
10844
|
+
const body = await this.claimAnonWin(id);
|
|
10845
|
+
const answer = claimAnswer(body);
|
|
10846
|
+
if (body) {
|
|
10847
|
+
delete this.anonClaims.tickets[id];
|
|
10848
|
+
saveAnonClaims(this.anonClaims);
|
|
10849
|
+
showClaimNotice(answer);
|
|
10850
|
+
} else {
|
|
10851
|
+
showClaimNotice(answer, () => this.startAnonClaim(id));
|
|
10852
|
+
}
|
|
10853
|
+
try {
|
|
10854
|
+
window.dispatchEvent(new CustomEvent(CLAIM_EVENT, { detail: { campaignId: id, ...answer, body } }));
|
|
10855
|
+
} catch {
|
|
10856
|
+
}
|
|
10857
|
+
void this.trackEvent(id, "clicked", { stepId: answer.claimed ? "anon_claim_claimed" : "anon_claim_not_eligible" });
|
|
10858
|
+
}
|
|
10859
|
+
}
|
|
10860
|
+
/** POST the claim. The cell decides from the device's stored play; this sends
|
|
10861
|
+
* only the campaign, the device id and the contact token. null = no answer. */
|
|
10862
|
+
async claimAnonWin(campaignId) {
|
|
10863
|
+
if (this.previewOnly) return null;
|
|
10864
|
+
if (!this.organizationId || !this.contactId || !this.contactToken) return null;
|
|
10865
|
+
try {
|
|
10866
|
+
const res = await fetch(`${this.apiHost}${CLAIM_PATH}`, {
|
|
10867
|
+
method: "POST",
|
|
10868
|
+
headers: {
|
|
10869
|
+
"Content-Type": "application/json",
|
|
10870
|
+
"X-Aegis-Write-Key": this.writeKey,
|
|
10871
|
+
"X-Organization-ID": this.organizationId,
|
|
10872
|
+
"X-Contact-ID": this.contactId,
|
|
10873
|
+
"X-Contact-Token": this.contactToken
|
|
10874
|
+
},
|
|
10875
|
+
body: JSON.stringify({
|
|
10876
|
+
campaign_id: campaignId,
|
|
10877
|
+
contact_id: this.contactId,
|
|
10878
|
+
anonymous_id: readAnonIdFromStorage$1(),
|
|
10879
|
+
claim_ticket: this.anonClaims.tickets[campaignId]
|
|
10880
|
+
})
|
|
10881
|
+
});
|
|
10882
|
+
if (!res.ok) {
|
|
10883
|
+
this.log(`anon win claim failed (${res.status})`, "warn");
|
|
10884
|
+
return null;
|
|
10885
|
+
}
|
|
10886
|
+
return await res.json().catch(() => null);
|
|
10887
|
+
} catch (e) {
|
|
10888
|
+
this.log(`anon win claim error: ${e}`, "warn");
|
|
10889
|
+
return null;
|
|
10890
|
+
}
|
|
10891
|
+
}
|
|
10892
|
+
/** The server's "try again" answer for this campaign's last submit, once. */
|
|
10893
|
+
takeRetryAnswer(campaignId) {
|
|
10894
|
+
const msg = this.retryAnswers.get(campaignId);
|
|
10895
|
+
if (msg === void 0) return null;
|
|
10896
|
+
this.retryAnswers.delete(campaignId);
|
|
10897
|
+
return msg;
|
|
10898
|
+
}
|
|
10177
10899
|
async submitWidgetResponse(campaign, responseType, payload) {
|
|
10900
|
+
var _a, _b;
|
|
10901
|
+
if (this.previewOnly) return null;
|
|
10178
10902
|
if (!this.organizationId) return null;
|
|
10903
|
+
this.retryAnswers.delete(campaign.id);
|
|
10179
10904
|
try {
|
|
10180
10905
|
const headers = {
|
|
10181
10906
|
"Content-Type": "application/json",
|
|
@@ -10204,9 +10929,25 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10204
10929
|
});
|
|
10205
10930
|
if (!res.ok) {
|
|
10206
10931
|
this.log(`submitWidgetResponse ${responseType} failed (${res.status})`, "warn");
|
|
10932
|
+
if (res.status === 503) {
|
|
10933
|
+
const body = await res.json().catch(() => null);
|
|
10934
|
+
const code = (_a = body == null ? void 0 : body.detail) == null ? void 0 : _a.reason_code;
|
|
10935
|
+
if (code === PRIZE_GRANT_RETRY || code === "DIET_UNREAD") {
|
|
10936
|
+
const msg = (_b = body == null ? void 0 : body.detail) == null ? void 0 : _b.message;
|
|
10937
|
+
this.retryAnswers.set(
|
|
10938
|
+
campaign.id,
|
|
10939
|
+
typeof msg === "string" && msg ? msg : PRIZE_GRANT_RETRY_MESSAGE
|
|
10940
|
+
);
|
|
10941
|
+
}
|
|
10942
|
+
}
|
|
10207
10943
|
return null;
|
|
10208
10944
|
}
|
|
10209
|
-
|
|
10945
|
+
const answer = await res.json().catch(() => null);
|
|
10946
|
+
if (answer && typeof answer.claim_ticket === "string" && answer.claim_ticket) {
|
|
10947
|
+
this.anonClaims.tickets[campaign.id] = answer.claim_ticket;
|
|
10948
|
+
saveAnonClaims(this.anonClaims);
|
|
10949
|
+
}
|
|
10950
|
+
return answer;
|
|
10210
10951
|
} catch (e) {
|
|
10211
10952
|
this.log(`submitWidgetResponse ${responseType} error: ${e}`, "warn");
|
|
10212
10953
|
return null;
|
|
@@ -10625,7 +11366,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10625
11366
|
loseFx();
|
|
10626
11367
|
this._playReaction(card, "empathize", void 0, ic);
|
|
10627
11368
|
}
|
|
10628
|
-
if (
|
|
11369
|
+
if (r.nonRedeemable !== void 0) {
|
|
11370
|
+
result.textContent = r.label ? `${r.label}: ${r.nonRedeemable}` : r.nonRedeemable;
|
|
11371
|
+
if (r.claimable) result.appendChild(claimButton(() => this.startAnonClaim(campaign.id)));
|
|
11372
|
+
else if (r.signIn) {
|
|
11373
|
+
result.appendChild(claimButton(() => this.dispatchAction({ type: "open_login" }, campaign.id), SIGN_IN_BUTTON_LABEL));
|
|
11374
|
+
}
|
|
11375
|
+
} else if (winReveal === "takeover" && r.won) renderTakeover(r);
|
|
10629
11376
|
else if (r.label && r.code) {
|
|
10630
11377
|
result.textContent = "";
|
|
10631
11378
|
const tag = document.createElement("span");
|
|
@@ -10646,7 +11393,15 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10646
11393
|
result.appendChild(chip);
|
|
10647
11394
|
const validTill = this._validTillLine(r.expiresAt, text);
|
|
10648
11395
|
if (validTill) result.appendChild(validTill);
|
|
10649
|
-
} else
|
|
11396
|
+
} else {
|
|
11397
|
+
result.textContent = r.label || "Thanks for playing!";
|
|
11398
|
+
if (r.won && !r.code && r.kind === "freebie") {
|
|
11399
|
+
const hint = document.createElement("div");
|
|
11400
|
+
hint.textContent = "🎟️ Show this screen to claim";
|
|
11401
|
+
hint.style.cssText = "margin-top: 4px; font-size: 12px; font-weight: 600; opacity: 0.85;";
|
|
11402
|
+
result.appendChild(hint);
|
|
11403
|
+
}
|
|
11404
|
+
}
|
|
10650
11405
|
retireCta();
|
|
10651
11406
|
};
|
|
10652
11407
|
const beginSpin = (velocityDegPerMs) => {
|
|
@@ -10665,6 +11420,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10665
11420
|
const loopSpeed = 0.5 + v * 0.35;
|
|
10666
11421
|
let looping = true;
|
|
10667
11422
|
let done = false;
|
|
11423
|
+
let timedOut = false;
|
|
10668
11424
|
let lastTs = now();
|
|
10669
11425
|
const loopFrame = () => {
|
|
10670
11426
|
if (!looping) return;
|
|
@@ -10684,6 +11440,16 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10684
11440
|
}
|
|
10685
11441
|
return provisional;
|
|
10686
11442
|
};
|
|
11443
|
+
const pauseForRetry = (message) => {
|
|
11444
|
+
if (done) return;
|
|
11445
|
+
done = true;
|
|
11446
|
+
looping = false;
|
|
11447
|
+
spinning = false;
|
|
11448
|
+
btn.disabled = false;
|
|
11449
|
+
btn.style.opacity = "";
|
|
11450
|
+
btn.style.transform = "";
|
|
11451
|
+
result.textContent = message;
|
|
11452
|
+
};
|
|
10687
11453
|
const launch = (idx, r) => {
|
|
10688
11454
|
if (done) return;
|
|
10689
11455
|
done = true;
|
|
@@ -10701,27 +11467,48 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10701
11467
|
});
|
|
10702
11468
|
};
|
|
10703
11469
|
void this.submitWidgetResponse(campaign, "spin", { segment_index: provisional }).then((resp) => {
|
|
10704
|
-
|
|
11470
|
+
if (done) {
|
|
11471
|
+
if (!timedOut || spinning || resolved) return;
|
|
11472
|
+
done = false;
|
|
11473
|
+
spinning = true;
|
|
11474
|
+
btn.disabled = true;
|
|
11475
|
+
btn.style.opacity = "0.6";
|
|
11476
|
+
}
|
|
11477
|
+
const st2 = prizeStateOf(resp, this.takeRetryAnswer(campaign.id));
|
|
11478
|
+
if (st2.state === "spin_again") {
|
|
11479
|
+
pauseForRetry(st2.message);
|
|
11480
|
+
return;
|
|
11481
|
+
}
|
|
11482
|
+
const prize = resp.prize || null;
|
|
11483
|
+
if (!prize) {
|
|
11484
|
+
const li = lossIndex();
|
|
11485
|
+
launch(li, {
|
|
11486
|
+
label: labels[li] || "",
|
|
11487
|
+
code: "",
|
|
11488
|
+
won: false,
|
|
11489
|
+
kind: shown[li] && typeof shown[li].prize_type === "string" ? String(shown[li].prize_type).toLowerCase() : "no_prize"
|
|
11490
|
+
});
|
|
11491
|
+
return;
|
|
11492
|
+
}
|
|
10705
11493
|
let idx = provisional;
|
|
10706
|
-
if (
|
|
10707
|
-
const label =
|
|
10708
|
-
const
|
|
10709
|
-
|
|
10710
|
-
|
|
10711
|
-
|
|
10712
|
-
|
|
11494
|
+
if (typeof prize.segment_index === "number") idx = prize.segment_index % n;
|
|
11495
|
+
const label = typeof prize.prize_label === "string" ? prize.prize_label : labels[idx] || "";
|
|
11496
|
+
const kind = typeof prize.prize_type === "string" ? prize.prize_type.toLowerCase() : shown[idx] && typeof shown[idx].prize_type === "string" ? String(shown[idx].prize_type).toLowerCase() : "";
|
|
11497
|
+
if (st2.state === "non_redeemable") {
|
|
11498
|
+
launch(idx, { label, code: "", won: false, kind, nonRedeemable: st2.message, claimable: st2.claimable === true, signIn: st2.signIn === true });
|
|
11499
|
+
return;
|
|
11500
|
+
}
|
|
11501
|
+
const won = st2.state === "credited_win" && !!label;
|
|
11502
|
+
const code = won && typeof prize.coupon_code === "string" ? prize.coupon_code : "";
|
|
11503
|
+
const expiresAt = won && typeof prize.expires_at === "string" ? prize.expires_at : null;
|
|
11504
|
+
launch(idx, { label, code, won, kind, expiresAt });
|
|
10713
11505
|
}).catch(() => {
|
|
10714
11506
|
});
|
|
10715
11507
|
window.setTimeout(() => {
|
|
10716
11508
|
if (done) return;
|
|
10717
|
-
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
code: "",
|
|
10721
|
-
won: false,
|
|
10722
|
-
kind: shown[li] && typeof shown[li].prize_type === "string" ? String(shown[li].prize_type).toLowerCase() : "no_prize"
|
|
10723
|
-
});
|
|
10724
|
-
}, 8e3);
|
|
11509
|
+
timedOut = true;
|
|
11510
|
+
pauseForRetry(SPIN_AGAIN_MESSAGE);
|
|
11511
|
+
}, DRAW_ANSWER_TIMEOUT_MS);
|
|
10725
11512
|
};
|
|
10726
11513
|
if (spinMode === "button" || spinMode === "both") {
|
|
10727
11514
|
btn.addEventListener("click", () => beginSpin(0.7));
|
|
@@ -11204,12 +11991,38 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11204
11991
|
revealed = true;
|
|
11205
11992
|
this.addAnimationStyles();
|
|
11206
11993
|
void this.trackEvent(campaign.id, "clicked");
|
|
11207
|
-
|
|
11994
|
+
const answered = Promise.resolve(dealOnce()).then(() => this.submitWidgetResponse(campaign, "scratch", { state: "revealed" }));
|
|
11995
|
+
const bounded = Promise.race([
|
|
11996
|
+
answered,
|
|
11997
|
+
new Promise((resolve) => window.setTimeout(() => resolve(null), DRAW_ANSWER_TIMEOUT_MS))
|
|
11998
|
+
]);
|
|
11999
|
+
return bounded.then((resp) => {
|
|
12000
|
+
var _a;
|
|
11208
12001
|
if (!resp) {
|
|
11209
12002
|
revealed = false;
|
|
12003
|
+
const again = prizeStateOf(null, this.takeRetryAnswer(campaign.id));
|
|
12004
|
+
let note = body.querySelector("[data-aegis-scratch-retry]");
|
|
12005
|
+
if (!note) {
|
|
12006
|
+
note = document.createElement("div");
|
|
12007
|
+
note.setAttribute("data-aegis-scratch-retry", "");
|
|
12008
|
+
note.style.cssText = "margin-top: 6px; font-size: 12px; font-weight: 600; opacity: 0.8;";
|
|
12009
|
+
body.appendChild(note);
|
|
12010
|
+
}
|
|
12011
|
+
note.textContent = again.state === "spin_again" ? again.message : "";
|
|
11210
12012
|
return false;
|
|
11211
12013
|
}
|
|
11212
|
-
|
|
12014
|
+
(_a = body.querySelector("[data-aegis-scratch-retry]")) == null ? void 0 : _a.remove();
|
|
12015
|
+
const st2 = prizeStateOf(resp);
|
|
12016
|
+
if (st2.state === "non_redeemable") {
|
|
12017
|
+
const nrLabel = this._extractPrizeLabel(resp) || "";
|
|
12018
|
+
prizeText.textContent = nrLabel ? `${nrLabel}: ${st2.message}` : st2.message;
|
|
12019
|
+
if (st2.claimable) body.appendChild(claimButton(() => this.startAnonClaim(campaign.id)));
|
|
12020
|
+
else if (st2.signIn) {
|
|
12021
|
+
body.appendChild(claimButton(() => this.dispatchAction({ type: "open_login" }, campaign.id), SIGN_IN_BUTTON_LABEL));
|
|
12022
|
+
}
|
|
12023
|
+
return true;
|
|
12024
|
+
}
|
|
12025
|
+
const won = scratchOutcome(resp) === true && (st2.state === "credited_win" || !resp.prize);
|
|
11213
12026
|
const sampleLabel = sampleWin && typeof sampleWin.label === "string" ? sampleWin.label : "";
|
|
11214
12027
|
const label = this._extractPrizeLabel(resp) || sampleLabel || ic.scratch_prize_label || "You won!";
|
|
11215
12028
|
const code = this._extractCouponCode(resp) || "";
|
|
@@ -11410,7 +12223,12 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11410
12223
|
if (Array.isArray(campaign.delivery_modes) && campaign.delivery_modes.length > 0 && !campaign.delivery_modes.includes("in_app_overlay")) {
|
|
11411
12224
|
return;
|
|
11412
12225
|
}
|
|
11413
|
-
|
|
12226
|
+
if (this.overlaysHeld && campaign.type !== "active_web_chat") {
|
|
12227
|
+
this.log(`campaign ${campaign.id} not drawn: overlays held by the host`);
|
|
12228
|
+
return;
|
|
12229
|
+
}
|
|
12230
|
+
const willShow = { target: "overlay" };
|
|
12231
|
+
const proceed = this.emit("campaign-will-show", campaign, willShow);
|
|
11414
12232
|
if (!proceed) {
|
|
11415
12233
|
this.log(`campaign ${campaign.id} suppressed by campaign-will-show handler`);
|
|
11416
12234
|
return;
|
|
@@ -11587,7 +12405,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11587
12405
|
sanitizeUrl: (url) => this.sanitizeUrl(url),
|
|
11588
12406
|
navigate: (url, buttonId) => this.navigateToCampaignAction(campaign, url, buttonId),
|
|
11589
12407
|
dispatchAction: (action) => this.dispatchAction(action, campaign.id),
|
|
12408
|
+
claimAnonWin: () => this.startAnonClaim(campaign.id),
|
|
11590
12409
|
submitResponse: (responseType, payload) => this.submitWidgetResponse(campaign, responseType, payload),
|
|
12410
|
+
takeRetryAnswer: () => this.takeRetryAnswer(campaign.id),
|
|
11591
12411
|
playReaction: (el2, intent, lottieFile, scope) => this._playReaction(el2, intent, lottieFile, campaign.interactive_config, scope),
|
|
11592
12412
|
haptic: (pattern) => {
|
|
11593
12413
|
try {
|
|
@@ -12161,6 +12981,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
12161
12981
|
*/
|
|
12162
12982
|
async _subscribeFromPushPrimer() {
|
|
12163
12983
|
var _a, _b, _c, _d, _e;
|
|
12984
|
+
if (this.previewOnly) return "default";
|
|
12164
12985
|
if (!this.propertyId) {
|
|
12165
12986
|
return Notification.requestPermission();
|
|
12166
12987
|
}
|
|
@@ -14274,6 +15095,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14274
15095
|
});
|
|
14275
15096
|
}
|
|
14276
15097
|
}
|
|
15098
|
+
if (this.previewOnly) return;
|
|
14277
15099
|
try {
|
|
14278
15100
|
const url = `${this.apiHost}/v1/in-app/events`;
|
|
14279
15101
|
const externalEventId = `inapp_${campaignId}_${eventType}_${Date.now()}`;
|
|
@@ -14378,6 +15200,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14378
15200
|
* nothing — so a duplicate ack is harmless.
|
|
14379
15201
|
*/
|
|
14380
15202
|
async ackJourneyQueueItem(step, action, attempt = 0) {
|
|
15203
|
+
if (this.previewOnly) return;
|
|
14381
15204
|
const key = `${step}:${action}`;
|
|
14382
15205
|
if (attempt === 0) {
|
|
14383
15206
|
if (this.journeyAcks.has(key)) return;
|
|
@@ -14453,6 +15276,11 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14453
15276
|
}
|
|
14454
15277
|
this.renderedSlots.forEach((slot) => this.clearSlotContent(slot));
|
|
14455
15278
|
this.renderedSlots.clear();
|
|
15279
|
+
this.ownAnchorWrappers.forEach((w) => w.remove());
|
|
15280
|
+
this.ownAnchorWrappers.clear();
|
|
15281
|
+
this.anchorWrappers = /* @__PURE__ */ new WeakMap();
|
|
15282
|
+
this.pendingSlotRender = false;
|
|
15283
|
+
this.pendingAnchorRender = false;
|
|
14456
15284
|
this.filledSlots = /* @__PURE__ */ new WeakSet();
|
|
14457
15285
|
this.slotSignatures = /* @__PURE__ */ new WeakMap();
|
|
14458
15286
|
this.slotTimers = /* @__PURE__ */ new WeakMap();
|
|
@@ -15048,7 +15876,7 @@ class SdkConfigPoller {
|
|
|
15048
15876
|
if (this.currentETag) {
|
|
15049
15877
|
headers["If-None-Match"] = this.currentETag;
|
|
15050
15878
|
}
|
|
15051
|
-
const response = await
|
|
15879
|
+
const response = await fetchWithAbort(`${this.options.apiHost}/v1/sdk/config`, {
|
|
15052
15880
|
method: "GET",
|
|
15053
15881
|
headers
|
|
15054
15882
|
});
|
|
@@ -15228,6 +16056,19 @@ class PrefetchBundleClient {
|
|
|
15228
16056
|
if (ctx.geo) qs.set("geo", ctx.geo);
|
|
15229
16057
|
const isNewUser = ctx.is_new_user ?? isNewVisitor();
|
|
15230
16058
|
qs.set("is_new_user", isNewUser ? "true" : "false");
|
|
16059
|
+
if (ctx.cart_product_ids != null) {
|
|
16060
|
+
const ids = [];
|
|
16061
|
+
for (const raw of ctx.cart_product_ids) {
|
|
16062
|
+
const id = String(raw).trim();
|
|
16063
|
+
if (!id) continue;
|
|
16064
|
+
if (id.includes(",")) {
|
|
16065
|
+
logger.warn("prefetch-bundle: dropping cart_product_id containing a comma:", id);
|
|
16066
|
+
continue;
|
|
16067
|
+
}
|
|
16068
|
+
if (!ids.includes(id)) ids.push(id);
|
|
16069
|
+
}
|
|
16070
|
+
qs.set("cart_product_ids", ids.join(","));
|
|
16071
|
+
}
|
|
15231
16072
|
const url = `${this.apiHost}/v1/sdk/prefetch-bundle?${qs.toString()}`;
|
|
15232
16073
|
const headers = {
|
|
15233
16074
|
"X-Aegis-Write-Key": this.writeKey,
|
|
@@ -15247,7 +16088,7 @@ class PrefetchBundleClient {
|
|
|
15247
16088
|
}
|
|
15248
16089
|
let response;
|
|
15249
16090
|
try {
|
|
15250
|
-
response = await
|
|
16091
|
+
response = await fetchWithAbort(url, { method: "GET", headers, cache: "no-cache" });
|
|
15251
16092
|
} catch (err) {
|
|
15252
16093
|
logger.warn("prefetch-bundle fetch network error:", err);
|
|
15253
16094
|
return this.currentBundle;
|
|
@@ -17105,7 +17946,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17105
17946
|
this.initialized = false;
|
|
17106
17947
|
this.armedInAppTriggers = /* @__PURE__ */ new Set();
|
|
17107
17948
|
{
|
|
17108
|
-
const v = "1.
|
|
17949
|
+
const v = "1.49.0";
|
|
17109
17950
|
try {
|
|
17110
17951
|
globalThis.__AEGIS_SDK_VERSION__ = v;
|
|
17111
17952
|
} catch {
|
|
@@ -17126,6 +17967,8 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17126
17967
|
const ownsTriggerEngine = !config.triggerEngine;
|
|
17127
17968
|
this.triggerEngine = triggerEngine;
|
|
17128
17969
|
this.ownsTriggerEngine = ownsTriggerEngine;
|
|
17970
|
+
const previewOnly = config.previewOnly === true || isPreviewPage();
|
|
17971
|
+
this.spotsOnly = config.spotsOnly === true || previewOnly;
|
|
17129
17972
|
this.contactId = config.contactId;
|
|
17130
17973
|
this.contactToken = config.contactToken;
|
|
17131
17974
|
this.pairingApiHost = config.apiHost ?? "";
|
|
@@ -17162,6 +18005,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17162
18005
|
propertyId: config.propertyId,
|
|
17163
18006
|
debugMode: config.debugMode,
|
|
17164
18007
|
enableSSE: config.enableSSE,
|
|
18008
|
+
previewOnly,
|
|
17165
18009
|
getWorkspaceId: config.getWorkspaceId,
|
|
17166
18010
|
// First-party cart reader — renderers (progress-bar) read live cart
|
|
17167
18011
|
// state from here instead of `window.*` cart globals. See setCartState().
|
|
@@ -17196,7 +18040,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17196
18040
|
apiHost: config.apiHost,
|
|
17197
18041
|
debugMode: config.debugMode
|
|
17198
18042
|
});
|
|
17199
|
-
if (config.enableChat) {
|
|
18043
|
+
if (config.enableChat && !previewOnly) {
|
|
17200
18044
|
this.chat = new AegisChat({
|
|
17201
18045
|
writeKey: config.writeKey,
|
|
17202
18046
|
apiHost: config.apiHost,
|
|
@@ -17265,7 +18109,8 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17265
18109
|
maybeStartPairing(this.pairingApiHost);
|
|
17266
18110
|
await Promise.all([
|
|
17267
18111
|
this.inApp.initialize(),
|
|
17268
|
-
|
|
18112
|
+
// A spot-only page never starts the pop-up widget layer.
|
|
18113
|
+
this.spotsOnly ? Promise.resolve() : this.widgets.initialize()
|
|
17269
18114
|
]);
|
|
17270
18115
|
(_a = this.chat) == null ? void 0 : _a.initialize();
|
|
17271
18116
|
if (this.ownsTriggerEngine) {
|
|
@@ -17531,13 +18376,28 @@ async function bootstrap(apiHost, req) {
|
|
|
17531
18376
|
if (req.attestationToken) body.attestationToken = req.attestationToken;
|
|
17532
18377
|
if (req.userAgent) body.userAgent = req.userAgent;
|
|
17533
18378
|
const url = `${apiHost.replace(/\/$/, "")}/v1/sdk/bootstrap`;
|
|
17534
|
-
const doFetch = async () =>
|
|
17535
|
-
|
|
17536
|
-
|
|
17537
|
-
|
|
17538
|
-
|
|
17539
|
-
|
|
17540
|
-
|
|
18379
|
+
const doFetch = async () => {
|
|
18380
|
+
try {
|
|
18381
|
+
return await fetchWithAbort(url, {
|
|
18382
|
+
method: "POST",
|
|
18383
|
+
headers: { "Content-Type": "application/json" },
|
|
18384
|
+
body: JSON.stringify(body),
|
|
18385
|
+
credentials: "omit"
|
|
18386
|
+
});
|
|
18387
|
+
} catch (err) {
|
|
18388
|
+
if (isAbortError(err)) {
|
|
18389
|
+
throw new BootstrapError(0, `Bootstrap timed out after ${SDK_FETCH_ABORT_MS} ms`);
|
|
18390
|
+
}
|
|
18391
|
+
throw err;
|
|
18392
|
+
}
|
|
18393
|
+
};
|
|
18394
|
+
let resp;
|
|
18395
|
+
try {
|
|
18396
|
+
resp = await doFetch();
|
|
18397
|
+
} catch (err) {
|
|
18398
|
+
if (!(err instanceof BootstrapError) || err.status !== 0) throw err;
|
|
18399
|
+
resp = await doFetch();
|
|
18400
|
+
}
|
|
17541
18401
|
if (resp.status >= 500) {
|
|
17542
18402
|
await new Promise((r) => setTimeout(r, 750));
|
|
17543
18403
|
resp = await doFetch();
|
|
@@ -17602,9 +18462,11 @@ export {
|
|
|
17602
18462
|
fallbackUrlForAction,
|
|
17603
18463
|
getChatContext,
|
|
17604
18464
|
getCurrentLauncher,
|
|
18465
|
+
isPreviewPage,
|
|
17605
18466
|
isReplaceableRailTitle,
|
|
17606
18467
|
mountScratchSurface,
|
|
17607
18468
|
m as murmurhash3_x86_32,
|
|
18469
|
+
onLauncherChange,
|
|
17608
18470
|
openChat,
|
|
17609
18471
|
parseAction,
|
|
17610
18472
|
readFirstPartyCookie,
|