@active-reach/web-sdk 1.48.0 → 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/dist/aegis.min.js +1 -1
- package/dist/aegis.min.js.map +1 -1
- package/dist/{analytics-zA6ckfKP.mjs → analytics-DMY0Q0rI.mjs} +911 -312
- 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.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.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 +1 -1
- 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 +94 -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 +936 -144
- 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/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/package.json +1 -1
- package/dist/analytics-zA6ckfKP.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;
|
|
@@ -8361,18 +8805,25 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8361
8805
|
this.slotTimers = /* @__PURE__ */ new WeakMap();
|
|
8362
8806
|
this.renderedSlots = /* @__PURE__ */ new Set();
|
|
8363
8807
|
this.slotObserver = null;
|
|
8808
|
+
this.anchorWrappers = /* @__PURE__ */ new WeakMap();
|
|
8809
|
+
this.ownAnchorWrappers = /* @__PURE__ */ new Set();
|
|
8364
8810
|
this.phoneVariantMedia = null;
|
|
8365
8811
|
this.onPhoneVariantChange = () => {
|
|
8366
8812
|
if (this.slotsTornDown || typeof document === "undefined") return;
|
|
8367
8813
|
if (document.querySelector(`[data-aegis-slot][${SLOT_VARIANT_PHONE_ATTR}]`)) this.renderIntoSlots();
|
|
8368
8814
|
};
|
|
8369
8815
|
this.slotRenderScheduled = false;
|
|
8816
|
+
this.pendingSlotRender = false;
|
|
8817
|
+
this.pendingAnchorRender = false;
|
|
8370
8818
|
this.slotsTornDown = false;
|
|
8371
8819
|
this.campaignsLoaded = false;
|
|
8372
8820
|
this.shellTimeout = null;
|
|
8373
8821
|
this.lifecycleGen = 0;
|
|
8374
8822
|
this.slotUnfilledBeaconed = /* @__PURE__ */ new Set();
|
|
8375
8823
|
this.slotUnfilledSweepTimer = null;
|
|
8824
|
+
this.railFallbackTier = null;
|
|
8825
|
+
this.retryAnswers = /* @__PURE__ */ new Map();
|
|
8826
|
+
this.anonClaims = loadAnonClaims();
|
|
8376
8827
|
this._pushOptInLoading = false;
|
|
8377
8828
|
this.journeyStepByCampaign = /* @__PURE__ */ new Map();
|
|
8378
8829
|
this.journeyAcks = /* @__PURE__ */ new Set();
|
|
@@ -8384,7 +8835,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8384
8835
|
this.organizationId = config.organizationId;
|
|
8385
8836
|
this.propertyId = config.propertyId;
|
|
8386
8837
|
this.debugMode = config.debugMode || false;
|
|
8387
|
-
this.
|
|
8838
|
+
this.previewOnly = config.previewOnly === true || isPreviewPage();
|
|
8839
|
+
this.enableSSE = config.enableSSE === true && !this.previewOnly;
|
|
8388
8840
|
this.onActionHandler = config.onAction;
|
|
8389
8841
|
if (config.productUrl) this.productUrl = config.productUrl;
|
|
8390
8842
|
this.getWorkspaceId = config.getWorkspaceId;
|
|
@@ -8396,13 +8848,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8396
8848
|
if (screen && screen !== "page_view") this.currentScreen = screen;
|
|
8397
8849
|
if (config.locationId) this.currentLocationId = config.locationId;
|
|
8398
8850
|
}
|
|
8399
|
-
emit(eventName, payload) {
|
|
8851
|
+
emit(eventName, payload, info) {
|
|
8400
8852
|
const handlers = this.hooks.get(eventName);
|
|
8401
8853
|
if (!handlers || handlers.size === 0) return true;
|
|
8402
8854
|
let proceed = true;
|
|
8403
8855
|
for (const handler of handlers) {
|
|
8404
8856
|
try {
|
|
8405
|
-
const result = handler(payload);
|
|
8857
|
+
const result = handler(payload, info);
|
|
8406
8858
|
if (result === false) proceed = false;
|
|
8407
8859
|
} catch (err) {
|
|
8408
8860
|
this.emitError(err, { event: eventName });
|
|
@@ -8427,6 +8879,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8427
8879
|
}
|
|
8428
8880
|
}
|
|
8429
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.
|
|
8430
8885
|
register(eventName, handler) {
|
|
8431
8886
|
if (!this.hooks.has(eventName)) this.hooks.set(eventName, /* @__PURE__ */ new Set());
|
|
8432
8887
|
this.hooks.get(eventName).add(handler);
|
|
@@ -8456,7 +8911,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8456
8911
|
}
|
|
8457
8912
|
/** Sugar: subscribe to `campaign-will-show`. CANCELLABLE — return `false`
|
|
8458
8913
|
* to suppress rendering this campaign (host-side suppression rules,
|
|
8459
|
-
* route-aware blocking, etc.).
|
|
8914
|
+
* route-aware blocking, etc.). The second argument says where it renders
|
|
8915
|
+
* (`{ target: 'slot' | 'overlay' }`). */
|
|
8460
8916
|
onCampaignWillShow(handler) {
|
|
8461
8917
|
return this.register("campaign-will-show", handler);
|
|
8462
8918
|
}
|
|
@@ -8488,9 +8944,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8488
8944
|
this.log("AegisInApp already initialized");
|
|
8489
8945
|
return;
|
|
8490
8946
|
}
|
|
8491
|
-
markReturningVisitor();
|
|
8947
|
+
if (!this.previewOnly) markReturningVisitor();
|
|
8492
8948
|
try {
|
|
8493
|
-
if (typeof localStorage !== "undefined") {
|
|
8949
|
+
if (!this.previewOnly && typeof localStorage !== "undefined") {
|
|
8494
8950
|
const pv = parseInt(localStorage.getItem("aegis_pv_count") || "0", 10);
|
|
8495
8951
|
localStorage.setItem("aegis_pv_count", String(pv + 1));
|
|
8496
8952
|
}
|
|
@@ -8538,6 +8994,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8538
8994
|
this.log("AegisInApp initialized successfully");
|
|
8539
8995
|
}
|
|
8540
8996
|
async _sendPushBootBeacon() {
|
|
8997
|
+
if (this.previewOnly) return;
|
|
8541
8998
|
try {
|
|
8542
8999
|
if (sessionStorage.getItem("aegis_push_boot_beacon") === "1") return;
|
|
8543
9000
|
} catch {
|
|
@@ -8608,6 +9065,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8608
9065
|
var _a;
|
|
8609
9066
|
this.contactId = contactId;
|
|
8610
9067
|
this.contactToken = contactToken;
|
|
9068
|
+
if (contactToken && (this.anonClaims.pending.length || loadAnonClaims().pending.length)) {
|
|
9069
|
+
void this.claimPendingAnonWins();
|
|
9070
|
+
}
|
|
8611
9071
|
(_a = this.activeWebChat) == null ? void 0 : _a.updateContactId(contactId);
|
|
8612
9072
|
this.disconnectSSE();
|
|
8613
9073
|
if (this.enableSSE && this.organizationId) {
|
|
@@ -8987,10 +9447,18 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
8987
9447
|
if (this.currentCartProductIds !== null) {
|
|
8988
9448
|
context.set("cart_product_ids", this.currentCartProductIds.join(","));
|
|
8989
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
|
+
}
|
|
8990
9457
|
const url = `${this.apiHost}/v1/in-app/active?${context.toString()}`;
|
|
8991
9458
|
requestKey = this.activeRequestKey();
|
|
8992
9459
|
this.lastActiveRequestKey = requestKey;
|
|
8993
9460
|
const shellCtx = this.shellContext();
|
|
9461
|
+
const railAudience = this.railAudience();
|
|
8994
9462
|
const headers = {
|
|
8995
9463
|
"X-Aegis-Write-Key": this.writeKey,
|
|
8996
9464
|
"Content-Type": "application/json"
|
|
@@ -9014,7 +9482,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9014
9482
|
if (Object.keys(abAssignments).length > 0) {
|
|
9015
9483
|
headers["X-AB-Assignments"] = btoa(JSON.stringify(abAssignments));
|
|
9016
9484
|
}
|
|
9017
|
-
const response = await
|
|
9485
|
+
const response = await fetchWithAbort(url, {
|
|
9018
9486
|
method: "GET",
|
|
9019
9487
|
headers,
|
|
9020
9488
|
credentials: "include"
|
|
@@ -9027,6 +9495,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9027
9495
|
if (gen !== this.lifecycleGen) return;
|
|
9028
9496
|
this.campaigns = Array.isArray(payload) ? payload : [];
|
|
9029
9497
|
this.campaignsLoaded = true;
|
|
9498
|
+
this.railFallbackTier = null;
|
|
9030
9499
|
this.campaignsRequestKey = requestKey;
|
|
9031
9500
|
this.clearShellTimeout();
|
|
9032
9501
|
applyCampaignFonts(this.campaigns);
|
|
@@ -9039,7 +9508,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9039
9508
|
this.mountPersistentLaunchers();
|
|
9040
9509
|
this.tryDisplayNextCampaign();
|
|
9041
9510
|
this.renderIntoSlots();
|
|
9042
|
-
this.saveSlotShapes(shellCtx);
|
|
9511
|
+
if (!this.previewOnly) this.saveSlotShapes(shellCtx);
|
|
9512
|
+
if (!this.previewOnly) saveGoodRails(shellCtx, this.campaigns, Date.now(), railAudience);
|
|
9043
9513
|
this.renderIntoAnchors();
|
|
9044
9514
|
this.renderTokenAnchors();
|
|
9045
9515
|
} catch (error) {
|
|
@@ -9047,12 +9517,16 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9047
9517
|
this.lastActiveRequestKey = void 0;
|
|
9048
9518
|
}
|
|
9049
9519
|
if (gen !== this.lifecycleGen) return;
|
|
9050
|
-
if (!this.campaignsLoaded)
|
|
9520
|
+
if (!this.campaignsLoaded) {
|
|
9521
|
+
this.applyRailFallback();
|
|
9522
|
+
this.removeShells();
|
|
9523
|
+
}
|
|
9051
9524
|
this.emitError(error, { stage: "refresh-campaigns" });
|
|
9052
9525
|
this.log(`Error refreshing campaigns: ${error}`, "error");
|
|
9053
9526
|
}
|
|
9054
9527
|
}
|
|
9055
9528
|
emitServedEvents(campaigns) {
|
|
9529
|
+
if (this.previewOnly) return;
|
|
9056
9530
|
if (typeof sessionStorage === "undefined") {
|
|
9057
9531
|
for (const c of campaigns) {
|
|
9058
9532
|
void this.trackEvent(c.id, "served");
|
|
@@ -9105,7 +9579,34 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9105
9579
|
const assignments = this.getABAssignments();
|
|
9106
9580
|
return assignments[campaignId] ?? void 0;
|
|
9107
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
|
+
}
|
|
9108
9605
|
tryDisplayNextCampaign() {
|
|
9606
|
+
if (this.overlaysHeld) {
|
|
9607
|
+
this.log("overlay pick skipped: overlays held by the host");
|
|
9608
|
+
return;
|
|
9609
|
+
}
|
|
9109
9610
|
const campaign = this.campaigns.find(
|
|
9110
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"))
|
|
9111
9612
|
);
|
|
@@ -9231,6 +9732,35 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9231
9732
|
this.log(`slot shells skipped: ${err}`, "warn");
|
|
9232
9733
|
}
|
|
9233
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
|
+
}
|
|
9234
9764
|
clearShellTimeout() {
|
|
9235
9765
|
if (this.shellTimeout) {
|
|
9236
9766
|
clearTimeout(this.shellTimeout);
|
|
@@ -9274,34 +9804,52 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9274
9804
|
":scope > [data-aegis-rotate-stack], :scope > [data-aegis-rotate-pane], :scope > [data-aegis-slot-rendered], :scope > [data-aegis-rotate-dots]"
|
|
9275
9805
|
).forEach((n) => n.remove());
|
|
9276
9806
|
}
|
|
9277
|
-
// Re-fill
|
|
9278
|
-
//
|
|
9279
|
-
//
|
|
9280
|
-
//
|
|
9281
|
-
//
|
|
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.
|
|
9282
9815
|
ensureSlotObserver() {
|
|
9283
9816
|
if (this.slotObserver || typeof MutationObserver === "undefined" || typeof document === "undefined") {
|
|
9284
9817
|
return;
|
|
9285
9818
|
}
|
|
9286
9819
|
this.slotObserver = new MutationObserver((mutations) => {
|
|
9287
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
|
+
};
|
|
9288
9831
|
for (const m2 of mutations) {
|
|
9289
9832
|
m2.addedNodes.forEach((n) => {
|
|
9290
|
-
|
|
9291
|
-
if (sawSlot || n.nodeType !== 1) return;
|
|
9833
|
+
if (n.nodeType !== 1) return;
|
|
9292
9834
|
const el2 = n;
|
|
9293
|
-
if (
|
|
9294
|
-
|
|
9295
|
-
}
|
|
9835
|
+
if (!sawSlot && hits(el2, "[data-aegis-slot]")) sawSlot = true;
|
|
9836
|
+
if (!sawAnchor && anchorSelectors.some((sel) => hits(el2, sel))) sawAnchor = true;
|
|
9296
9837
|
});
|
|
9297
|
-
if (sawSlot) break;
|
|
9838
|
+
if (sawSlot && sawAnchor) break;
|
|
9298
9839
|
}
|
|
9299
|
-
if (
|
|
9840
|
+
if (sawSlot) this.pendingSlotRender = true;
|
|
9841
|
+
if (sawAnchor) this.pendingAnchorRender = true;
|
|
9842
|
+
if (!sawSlot && !sawAnchor || this.slotRenderScheduled) return;
|
|
9300
9843
|
this.slotRenderScheduled = true;
|
|
9301
9844
|
const run = () => {
|
|
9302
9845
|
this.slotRenderScheduled = false;
|
|
9846
|
+
const slots = this.pendingSlotRender;
|
|
9847
|
+
const anchors = this.pendingAnchorRender;
|
|
9848
|
+
this.pendingSlotRender = false;
|
|
9849
|
+
this.pendingAnchorRender = false;
|
|
9303
9850
|
if (this.slotsTornDown) return;
|
|
9304
|
-
this.renderIntoSlots();
|
|
9851
|
+
if (slots) this.renderIntoSlots();
|
|
9852
|
+
if (anchors) this.renderIntoAnchors({ reportUnresolved: false });
|
|
9305
9853
|
};
|
|
9306
9854
|
if (typeof requestAnimationFrame === "function") requestAnimationFrame(run);
|
|
9307
9855
|
else setTimeout(run, 0);
|
|
@@ -9559,6 +10107,20 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9559
10107
|
window.addEventListener("beforeunload", () => timer && clearInterval(timer), { once: true });
|
|
9560
10108
|
}
|
|
9561
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
|
+
}
|
|
9562
10124
|
/**
|
|
9563
10125
|
* Surface-Canvas inline element anchoring (Plotline / WebEngage model).
|
|
9564
10126
|
*
|
|
@@ -9572,12 +10134,19 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9572
10134
|
* Reuses `renderCampaignIntoSlot` (same sub_type dispatch → `renderProgressBarInline`
|
|
9573
10135
|
* etc.) so inline render code is single-sourced with the slot path. Embedded-card
|
|
9574
10136
|
* gated (so an anchored campaign never ALSO renders as an overlay), surface-gated,
|
|
9575
|
-
* and idempotent via `filledSlots` keyed on the resolved element.
|
|
9576
|
-
*
|
|
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.
|
|
9577
10144
|
*/
|
|
9578
|
-
renderIntoAnchors() {
|
|
10145
|
+
renderIntoAnchors(opts = {}) {
|
|
9579
10146
|
var _a;
|
|
9580
|
-
if (typeof document === "undefined") return;
|
|
10147
|
+
if (typeof document === "undefined" || this.slotsTornDown) return;
|
|
10148
|
+
this.ensureSlotObserver();
|
|
10149
|
+
const reportUnresolved = opts.reportUnresolved !== false;
|
|
9581
10150
|
for (const c of this.campaigns) {
|
|
9582
10151
|
if (!this.isPlaceableHere(c)) continue;
|
|
9583
10152
|
const modes = c.delivery_modes;
|
|
@@ -9593,17 +10162,31 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9593
10162
|
el2 = null;
|
|
9594
10163
|
}
|
|
9595
10164
|
if (!el2) {
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
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
|
+
}
|
|
9599
10170
|
continue;
|
|
9600
10171
|
}
|
|
9601
10172
|
const position = (anchor == null ? void 0 : anchor.position) || "inside";
|
|
9602
10173
|
let target;
|
|
9603
10174
|
if (position === "before" || position === "after") {
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
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
|
+
}
|
|
9607
10190
|
} else {
|
|
9608
10191
|
target = el2;
|
|
9609
10192
|
if (position === "replace") {
|
|
@@ -9619,8 +10202,17 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9619
10202
|
}
|
|
9620
10203
|
}
|
|
9621
10204
|
if (this.filledSlots.has(target)) continue;
|
|
9622
|
-
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
|
+
}
|
|
9623
10214
|
this.filledSlots.add(target);
|
|
10215
|
+
this.renderedSlots.add(target);
|
|
9624
10216
|
}
|
|
9625
10217
|
}
|
|
9626
10218
|
/**
|
|
@@ -9690,7 +10282,8 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
9690
10282
|
* skip — those types only make sense as fullscreen overlays.
|
|
9691
10283
|
*/
|
|
9692
10284
|
renderCampaignIntoSlot(campaign, target, options) {
|
|
9693
|
-
const
|
|
10285
|
+
const willShow = { target: "slot" };
|
|
10286
|
+
const proceed = this.emit("campaign-will-show", campaign, willShow);
|
|
9694
10287
|
if (!proceed) {
|
|
9695
10288
|
this.log(
|
|
9696
10289
|
`slot campaign ${campaign.id} suppressed by campaign-will-show handler`
|
|
@@ -10189,6 +10782,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10189
10782
|
/** POST a form response to /in-app/responses (gateway → cell-plane). The
|
|
10190
10783
|
* cell-plane enriches the contact from the campaign's field-map. Best-effort. */
|
|
10191
10784
|
async submitFormResponse(campaign, fields) {
|
|
10785
|
+
if (this.previewOnly) return;
|
|
10192
10786
|
if (!this.organizationId) {
|
|
10193
10787
|
this.log("submitFormResponse: no organizationId — cannot submit", "warn");
|
|
10194
10788
|
return;
|
|
@@ -10225,14 +10819,88 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10225
10819
|
this.log(`submitFormResponse error: ${e}`, "warn");
|
|
10226
10820
|
}
|
|
10227
10821
|
}
|
|
10228
|
-
/**
|
|
10229
|
-
*
|
|
10230
|
-
*
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
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
|
+
}
|
|
10234
10899
|
async submitWidgetResponse(campaign, responseType, payload) {
|
|
10900
|
+
var _a, _b;
|
|
10901
|
+
if (this.previewOnly) return null;
|
|
10235
10902
|
if (!this.organizationId) return null;
|
|
10903
|
+
this.retryAnswers.delete(campaign.id);
|
|
10236
10904
|
try {
|
|
10237
10905
|
const headers = {
|
|
10238
10906
|
"Content-Type": "application/json",
|
|
@@ -10261,9 +10929,25 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10261
10929
|
});
|
|
10262
10930
|
if (!res.ok) {
|
|
10263
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
|
+
}
|
|
10264
10943
|
return null;
|
|
10265
10944
|
}
|
|
10266
|
-
|
|
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;
|
|
10267
10951
|
} catch (e) {
|
|
10268
10952
|
this.log(`submitWidgetResponse ${responseType} error: ${e}`, "warn");
|
|
10269
10953
|
return null;
|
|
@@ -10682,7 +11366,13 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10682
11366
|
loseFx();
|
|
10683
11367
|
this._playReaction(card, "empathize", void 0, ic);
|
|
10684
11368
|
}
|
|
10685
|
-
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);
|
|
10686
11376
|
else if (r.label && r.code) {
|
|
10687
11377
|
result.textContent = "";
|
|
10688
11378
|
const tag = document.createElement("span");
|
|
@@ -10703,7 +11393,15 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10703
11393
|
result.appendChild(chip);
|
|
10704
11394
|
const validTill = this._validTillLine(r.expiresAt, text);
|
|
10705
11395
|
if (validTill) result.appendChild(validTill);
|
|
10706
|
-
} 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
|
+
}
|
|
10707
11405
|
retireCta();
|
|
10708
11406
|
};
|
|
10709
11407
|
const beginSpin = (velocityDegPerMs) => {
|
|
@@ -10722,6 +11420,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10722
11420
|
const loopSpeed = 0.5 + v * 0.35;
|
|
10723
11421
|
let looping = true;
|
|
10724
11422
|
let done = false;
|
|
11423
|
+
let timedOut = false;
|
|
10725
11424
|
let lastTs = now();
|
|
10726
11425
|
const loopFrame = () => {
|
|
10727
11426
|
if (!looping) return;
|
|
@@ -10741,6 +11440,16 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10741
11440
|
}
|
|
10742
11441
|
return provisional;
|
|
10743
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
|
+
};
|
|
10744
11453
|
const launch = (idx, r) => {
|
|
10745
11454
|
if (done) return;
|
|
10746
11455
|
done = true;
|
|
@@ -10758,27 +11467,48 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
10758
11467
|
});
|
|
10759
11468
|
};
|
|
10760
11469
|
void this.submitWidgetResponse(campaign, "spin", { segment_index: provisional }).then((resp) => {
|
|
10761
|
-
|
|
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
|
+
}
|
|
10762
11493
|
let idx = provisional;
|
|
10763
|
-
if (
|
|
10764
|
-
const label =
|
|
10765
|
-
const
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
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 });
|
|
10770
11505
|
}).catch(() => {
|
|
10771
11506
|
});
|
|
10772
11507
|
window.setTimeout(() => {
|
|
10773
11508
|
if (done) return;
|
|
10774
|
-
|
|
10775
|
-
|
|
10776
|
-
|
|
10777
|
-
code: "",
|
|
10778
|
-
won: false,
|
|
10779
|
-
kind: shown[li] && typeof shown[li].prize_type === "string" ? String(shown[li].prize_type).toLowerCase() : "no_prize"
|
|
10780
|
-
});
|
|
10781
|
-
}, 8e3);
|
|
11509
|
+
timedOut = true;
|
|
11510
|
+
pauseForRetry(SPIN_AGAIN_MESSAGE);
|
|
11511
|
+
}, DRAW_ANSWER_TIMEOUT_MS);
|
|
10782
11512
|
};
|
|
10783
11513
|
if (spinMode === "button" || spinMode === "both") {
|
|
10784
11514
|
btn.addEventListener("click", () => beginSpin(0.7));
|
|
@@ -11261,12 +11991,38 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11261
11991
|
revealed = true;
|
|
11262
11992
|
this.addAnimationStyles();
|
|
11263
11993
|
void this.trackEvent(campaign.id, "clicked");
|
|
11264
|
-
|
|
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;
|
|
11265
12001
|
if (!resp) {
|
|
11266
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 : "";
|
|
11267
12012
|
return false;
|
|
11268
12013
|
}
|
|
11269
|
-
|
|
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);
|
|
11270
12026
|
const sampleLabel = sampleWin && typeof sampleWin.label === "string" ? sampleWin.label : "";
|
|
11271
12027
|
const label = this._extractPrizeLabel(resp) || sampleLabel || ic.scratch_prize_label || "You won!";
|
|
11272
12028
|
const code = this._extractCouponCode(resp) || "";
|
|
@@ -11467,7 +12223,12 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11467
12223
|
if (Array.isArray(campaign.delivery_modes) && campaign.delivery_modes.length > 0 && !campaign.delivery_modes.includes("in_app_overlay")) {
|
|
11468
12224
|
return;
|
|
11469
12225
|
}
|
|
11470
|
-
|
|
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);
|
|
11471
12232
|
if (!proceed) {
|
|
11472
12233
|
this.log(`campaign ${campaign.id} suppressed by campaign-will-show handler`);
|
|
11473
12234
|
return;
|
|
@@ -11644,7 +12405,9 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
11644
12405
|
sanitizeUrl: (url) => this.sanitizeUrl(url),
|
|
11645
12406
|
navigate: (url, buttonId) => this.navigateToCampaignAction(campaign, url, buttonId),
|
|
11646
12407
|
dispatchAction: (action) => this.dispatchAction(action, campaign.id),
|
|
12408
|
+
claimAnonWin: () => this.startAnonClaim(campaign.id),
|
|
11647
12409
|
submitResponse: (responseType, payload) => this.submitWidgetResponse(campaign, responseType, payload),
|
|
12410
|
+
takeRetryAnswer: () => this.takeRetryAnswer(campaign.id),
|
|
11648
12411
|
playReaction: (el2, intent, lottieFile, scope) => this._playReaction(el2, intent, lottieFile, campaign.interactive_config, scope),
|
|
11649
12412
|
haptic: (pattern) => {
|
|
11650
12413
|
try {
|
|
@@ -12218,6 +12981,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
12218
12981
|
*/
|
|
12219
12982
|
async _subscribeFromPushPrimer() {
|
|
12220
12983
|
var _a, _b, _c, _d, _e;
|
|
12984
|
+
if (this.previewOnly) return "default";
|
|
12221
12985
|
if (!this.propertyId) {
|
|
12222
12986
|
return Notification.requestPermission();
|
|
12223
12987
|
}
|
|
@@ -14331,6 +15095,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14331
15095
|
});
|
|
14332
15096
|
}
|
|
14333
15097
|
}
|
|
15098
|
+
if (this.previewOnly) return;
|
|
14334
15099
|
try {
|
|
14335
15100
|
const url = `${this.apiHost}/v1/in-app/events`;
|
|
14336
15101
|
const externalEventId = `inapp_${campaignId}_${eventType}_${Date.now()}`;
|
|
@@ -14435,6 +15200,7 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14435
15200
|
* nothing — so a duplicate ack is harmless.
|
|
14436
15201
|
*/
|
|
14437
15202
|
async ackJourneyQueueItem(step, action, attempt = 0) {
|
|
15203
|
+
if (this.previewOnly) return;
|
|
14438
15204
|
const key = `${step}:${action}`;
|
|
14439
15205
|
if (attempt === 0) {
|
|
14440
15206
|
if (this.journeyAcks.has(key)) return;
|
|
@@ -14510,6 +15276,11 @@ const _AegisInAppManager = class _AegisInAppManager {
|
|
|
14510
15276
|
}
|
|
14511
15277
|
this.renderedSlots.forEach((slot) => this.clearSlotContent(slot));
|
|
14512
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;
|
|
14513
15284
|
this.filledSlots = /* @__PURE__ */ new WeakSet();
|
|
14514
15285
|
this.slotSignatures = /* @__PURE__ */ new WeakMap();
|
|
14515
15286
|
this.slotTimers = /* @__PURE__ */ new WeakMap();
|
|
@@ -15105,7 +15876,7 @@ class SdkConfigPoller {
|
|
|
15105
15876
|
if (this.currentETag) {
|
|
15106
15877
|
headers["If-None-Match"] = this.currentETag;
|
|
15107
15878
|
}
|
|
15108
|
-
const response = await
|
|
15879
|
+
const response = await fetchWithAbort(`${this.options.apiHost}/v1/sdk/config`, {
|
|
15109
15880
|
method: "GET",
|
|
15110
15881
|
headers
|
|
15111
15882
|
});
|
|
@@ -15317,7 +16088,7 @@ class PrefetchBundleClient {
|
|
|
15317
16088
|
}
|
|
15318
16089
|
let response;
|
|
15319
16090
|
try {
|
|
15320
|
-
response = await
|
|
16091
|
+
response = await fetchWithAbort(url, { method: "GET", headers, cache: "no-cache" });
|
|
15321
16092
|
} catch (err) {
|
|
15322
16093
|
logger.warn("prefetch-bundle fetch network error:", err);
|
|
15323
16094
|
return this.currentBundle;
|
|
@@ -17175,7 +17946,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17175
17946
|
this.initialized = false;
|
|
17176
17947
|
this.armedInAppTriggers = /* @__PURE__ */ new Set();
|
|
17177
17948
|
{
|
|
17178
|
-
const v = "1.
|
|
17949
|
+
const v = "1.49.0";
|
|
17179
17950
|
try {
|
|
17180
17951
|
globalThis.__AEGIS_SDK_VERSION__ = v;
|
|
17181
17952
|
} catch {
|
|
@@ -17196,6 +17967,8 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17196
17967
|
const ownsTriggerEngine = !config.triggerEngine;
|
|
17197
17968
|
this.triggerEngine = triggerEngine;
|
|
17198
17969
|
this.ownsTriggerEngine = ownsTriggerEngine;
|
|
17970
|
+
const previewOnly = config.previewOnly === true || isPreviewPage();
|
|
17971
|
+
this.spotsOnly = config.spotsOnly === true || previewOnly;
|
|
17199
17972
|
this.contactId = config.contactId;
|
|
17200
17973
|
this.contactToken = config.contactToken;
|
|
17201
17974
|
this.pairingApiHost = config.apiHost ?? "";
|
|
@@ -17232,6 +18005,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17232
18005
|
propertyId: config.propertyId,
|
|
17233
18006
|
debugMode: config.debugMode,
|
|
17234
18007
|
enableSSE: config.enableSSE,
|
|
18008
|
+
previewOnly,
|
|
17235
18009
|
getWorkspaceId: config.getWorkspaceId,
|
|
17236
18010
|
// First-party cart reader — renderers (progress-bar) read live cart
|
|
17237
18011
|
// state from here instead of `window.*` cart globals. See setCartState().
|
|
@@ -17266,7 +18040,7 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17266
18040
|
apiHost: config.apiHost,
|
|
17267
18041
|
debugMode: config.debugMode
|
|
17268
18042
|
});
|
|
17269
|
-
if (config.enableChat) {
|
|
18043
|
+
if (config.enableChat && !previewOnly) {
|
|
17270
18044
|
this.chat = new AegisChat({
|
|
17271
18045
|
writeKey: config.writeKey,
|
|
17272
18046
|
apiHost: config.apiHost,
|
|
@@ -17335,7 +18109,8 @@ const _AegisMessageRuntime = class _AegisMessageRuntime {
|
|
|
17335
18109
|
maybeStartPairing(this.pairingApiHost);
|
|
17336
18110
|
await Promise.all([
|
|
17337
18111
|
this.inApp.initialize(),
|
|
17338
|
-
|
|
18112
|
+
// A spot-only page never starts the pop-up widget layer.
|
|
18113
|
+
this.spotsOnly ? Promise.resolve() : this.widgets.initialize()
|
|
17339
18114
|
]);
|
|
17340
18115
|
(_a = this.chat) == null ? void 0 : _a.initialize();
|
|
17341
18116
|
if (this.ownsTriggerEngine) {
|
|
@@ -17601,13 +18376,28 @@ async function bootstrap(apiHost, req) {
|
|
|
17601
18376
|
if (req.attestationToken) body.attestationToken = req.attestationToken;
|
|
17602
18377
|
if (req.userAgent) body.userAgent = req.userAgent;
|
|
17603
18378
|
const url = `${apiHost.replace(/\/$/, "")}/v1/sdk/bootstrap`;
|
|
17604
|
-
const doFetch = async () =>
|
|
17605
|
-
|
|
17606
|
-
|
|
17607
|
-
|
|
17608
|
-
|
|
17609
|
-
|
|
17610
|
-
|
|
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
|
+
}
|
|
17611
18401
|
if (resp.status >= 500) {
|
|
17612
18402
|
await new Promise((r) => setTimeout(r, 750));
|
|
17613
18403
|
resp = await doFetch();
|
|
@@ -17672,9 +18462,11 @@ export {
|
|
|
17672
18462
|
fallbackUrlForAction,
|
|
17673
18463
|
getChatContext,
|
|
17674
18464
|
getCurrentLauncher,
|
|
18465
|
+
isPreviewPage,
|
|
17675
18466
|
isReplaceableRailTitle,
|
|
17676
18467
|
mountScratchSurface,
|
|
17677
18468
|
m as murmurhash3_x86_32,
|
|
18469
|
+
onLauncherChange,
|
|
17678
18470
|
openChat,
|
|
17679
18471
|
parseAction,
|
|
17680
18472
|
readFirstPartyCookie,
|