@oxvo/ai-live-assist 7.5.26 → 7.5.28
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/cjs/AiLiveAssist.d.ts +3 -1
- package/cjs/AiLiveAssist.js +24 -0
- package/cjs/client.d.ts +12 -0
- package/cjs/client.js +18 -0
- package/cjs/commerce/cartRecovery.d.ts +26 -0
- package/cjs/commerce/cartRecovery.js +96 -0
- package/cjs/commerce/cartSession.d.ts +7 -1
- package/cjs/commerce/cartSession.js +61 -5
- package/cjs/commerce/realtimeCommerce.d.ts +1 -0
- package/cjs/commerce/realtimeCommerce.js +1 -0
- package/cjs/commerce/shopifyCart.d.ts +3 -0
- package/cjs/commerce/shopifyCart.js +26 -0
- package/cjs/guideAdmission.d.ts +1 -0
- package/cjs/guideAdmission.js +3 -0
- package/cjs/guideMeasurement.d.ts +1 -1
- package/cjs/guideMeasurement.js +1 -1
- package/cjs/liveControlChannel.d.ts +3 -1
- package/cjs/liveControlChannel.js +4 -1
- package/cjs/liveGuideWidget.d.ts +22 -2
- package/cjs/liveGuideWidget.js +45 -8
- package/cjs/merchantPreview.d.ts +5 -0
- package/cjs/merchantPreview.js +148 -0
- package/cjs/merchantPreviewAdmission.d.ts +33 -0
- package/cjs/merchantPreviewAdmission.js +186 -0
- package/cjs/merchantPreviewOrigins.d.ts +6 -0
- package/cjs/merchantPreviewOrigins.js +24 -0
- package/cjs/merchantPreviewStorage.d.ts +9 -0
- package/cjs/merchantPreviewStorage.js +68 -0
- package/cjs/merchantPreviewTypes.d.ts +57 -0
- package/cjs/merchantPreviewTypes.js +2 -0
- package/cjs/standalone.d.ts +2 -0
- package/cjs/standalone.js +3 -1
- package/cjs/ui.d.ts +4 -1
- package/cjs/ui.js +13 -4
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/lib/AiLiveAssist.d.ts +3 -1
- package/lib/AiLiveAssist.js +24 -0
- package/lib/client.d.ts +12 -0
- package/lib/client.js +18 -0
- package/lib/commerce/cartRecovery.d.ts +26 -0
- package/lib/commerce/cartRecovery.js +93 -0
- package/lib/commerce/cartSession.d.ts +7 -1
- package/lib/commerce/cartSession.js +61 -5
- package/lib/commerce/realtimeCommerce.d.ts +1 -0
- package/lib/commerce/realtimeCommerce.js +1 -0
- package/lib/commerce/shopifyCart.d.ts +3 -0
- package/lib/commerce/shopifyCart.js +26 -0
- package/lib/guideAdmission.d.ts +1 -0
- package/lib/guideAdmission.js +3 -0
- package/lib/guideMeasurement.d.ts +1 -1
- package/lib/guideMeasurement.js +1 -1
- package/lib/liveControlChannel.d.ts +3 -1
- package/lib/liveControlChannel.js +4 -1
- package/lib/liveGuideWidget.d.ts +22 -2
- package/lib/liveGuideWidget.js +45 -8
- package/lib/merchantPreview.d.ts +5 -0
- package/lib/merchantPreview.js +144 -0
- package/lib/merchantPreviewAdmission.d.ts +33 -0
- package/lib/merchantPreviewAdmission.js +181 -0
- package/lib/merchantPreviewOrigins.d.ts +6 -0
- package/lib/merchantPreviewOrigins.js +18 -0
- package/lib/merchantPreviewStorage.d.ts +9 -0
- package/lib/merchantPreviewStorage.js +62 -0
- package/lib/merchantPreviewTypes.d.ts +57 -0
- package/lib/merchantPreviewTypes.js +1 -0
- package/lib/standalone.d.ts +2 -0
- package/lib/standalone.js +1 -0
- package/lib/ui.d.ts +4 -1
- package/lib/ui.js +13 -4
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/cjs/liveGuideWidget.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveGuideWidget = void 0;
|
|
4
4
|
const ui_js_1 = require("./ui.js");
|
|
5
|
+
const client_js_1 = require("./client.js");
|
|
5
6
|
const liveGuideAdmission_js_1 = require("./liveGuideAdmission.js");
|
|
6
7
|
const liveControlChannel_js_1 = require("./liveControlChannel.js");
|
|
7
8
|
const liveBrowserDetector_js_1 = require("./liveBrowserDetector.js");
|
|
@@ -62,10 +63,22 @@ class LiveGuideWidget {
|
|
|
62
63
|
JSON.stringify(config.liveCapabilities) !== JSON.stringify(liveControlChannel_js_1.LIVE_CONTROL_CLIENT_CAPABILITIES))
|
|
63
64
|
throw new Error('AI Guide Live is unavailable.');
|
|
64
65
|
(0, liveBrowserDetector_js_1.validateLiveBrowserAssets)(config.liveAssets);
|
|
65
|
-
|
|
66
|
+
if (options.sessionAdmission)
|
|
67
|
+
this.admission = options.sessionAdmission;
|
|
68
|
+
else {
|
|
69
|
+
const publicAdmission = options.admission;
|
|
70
|
+
const live = new liveGuideAdmission_js_1.LiveGuideAdmission(publicAdmission.identity, publicAdmission.store, options.runtime, publicAdmission);
|
|
71
|
+
this.admission = {
|
|
72
|
+
cartRecovery: () => publicAdmission.cartRecovery(),
|
|
73
|
+
hasPendingLaunch: () => live.hasPendingLaunch(),
|
|
74
|
+
pendingLaunchId: () => live.pendingLaunchId(),
|
|
75
|
+
launch: (intent, signal) => live.launch({ ...intent, installKey: publicAdmission.identity.installKey }, signal),
|
|
76
|
+
end: (signal, expectedLaunchRequestId) => live.end(signal, expectedLaunchRequestId),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
66
79
|
const callbacks = {
|
|
67
80
|
onStart: (mode, scopes, question) => this.start(mode, scopes, question),
|
|
68
|
-
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch(),
|
|
81
|
+
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch() && this.admission.canStart?.() !== false,
|
|
69
82
|
onEnd: () => { void this.end().catch(() => undefined); },
|
|
70
83
|
onMute: muted => { if (muted)
|
|
71
84
|
this.privacy('mute');
|
|
@@ -106,6 +119,7 @@ class LiveGuideWidget {
|
|
|
106
119
|
this.commerceCart = this.commerce?.cartEnabled && config.capabilities?.commerceCart === true ? new cartSession_js_1.CartSession({
|
|
107
120
|
bootstrap: this.commerce, view: () => this.destroyed ? null : this.view,
|
|
108
121
|
current: () => this.currentCartSnapshot(),
|
|
122
|
+
...(this.admission.cartRecovery ? { recovery: this.admission.cartRecovery() } : {}),
|
|
109
123
|
transportSessionId: () => this.channel?.sessionId ?? null,
|
|
110
124
|
selection: (productRef, variantRef) => {
|
|
111
125
|
this.commerceContext?.refresh();
|
|
@@ -122,12 +136,17 @@ class LiveGuideWidget {
|
|
|
122
136
|
},
|
|
123
137
|
}) : null;
|
|
124
138
|
this.commerceContext?.start();
|
|
139
|
+
this.commerceCart?.refreshControls();
|
|
125
140
|
if (this.admission.hasPendingLaunch()) {
|
|
126
141
|
if (this.acquireLock()) {
|
|
127
142
|
this.ownedLaunchId = this.admission.pendingLaunchId();
|
|
128
143
|
void this.end().catch(() => undefined);
|
|
129
144
|
}
|
|
130
145
|
}
|
|
146
|
+
else if (this.admission.recoveryOnly) {
|
|
147
|
+
this.phase = 'ended';
|
|
148
|
+
this.view.showLaunchUnavailable(this.admission.endMessage ?? this.view.message('ended'));
|
|
149
|
+
}
|
|
131
150
|
// Capture runs before TabActivityLock releases cross-tab ownership.
|
|
132
151
|
window.addEventListener('pagehide', this.pagehide, true);
|
|
133
152
|
window.addEventListener('focus', this.refreshOwnership);
|
|
@@ -145,6 +164,7 @@ class LiveGuideWidget {
|
|
|
145
164
|
this.requestIds.delete(this.requestIds.values().next().value);
|
|
146
165
|
}
|
|
147
166
|
this.view.open(input.mode ?? this.mode);
|
|
167
|
+
this.commerceCart?.refreshControls();
|
|
148
168
|
if (input.question) {
|
|
149
169
|
if (this.active)
|
|
150
170
|
this.submitText(input.question, true);
|
|
@@ -160,7 +180,7 @@ class LiveGuideWidget {
|
|
|
160
180
|
companion: false, pendingQuestion: this.pendingQuestions.length > 0 };
|
|
161
181
|
}
|
|
162
182
|
start(mode, scopes, question) {
|
|
163
|
-
if (this.destroyed || this.starting || this.active || this.ending ||
|
|
183
|
+
if (this.destroyed || this.starting || this.active || this.ending || this.admission.canStart?.() === false ||
|
|
164
184
|
(question && (!question.trim() || question.length > 4000)) || !this.acquireLock())
|
|
165
185
|
return false;
|
|
166
186
|
// Recover abandoned intent only after acquiring the actual activity lock;
|
|
@@ -178,7 +198,7 @@ class LiveGuideWidget {
|
|
|
178
198
|
this.operation = operation;
|
|
179
199
|
const timeout = setTimeout(() => operation.abort(), 20000);
|
|
180
200
|
const config = this.options.bootstrap;
|
|
181
|
-
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
201
|
+
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
182
202
|
launchRequestId: crypto.randomUUID(), clientVersion: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_VERSION, liveCapabilities: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_CAPABILITIES,
|
|
183
203
|
configRevision: config.configRevision, path: location.pathname, tabId: this.options.tabId, mode, experienceMode: 'standard',
|
|
184
204
|
consent: { disclosureChecksum: config.consent.disclosureChecksum, scopes: [...scopes], locale: this.options.locale },
|
|
@@ -198,6 +218,7 @@ class LiveGuideWidget {
|
|
|
198
218
|
throw new Error('Cancelled.');
|
|
199
219
|
const audio = this.view.livePlaybackElement();
|
|
200
220
|
const channel = new liveControlChannel_js_1.LiveControlChannel({ authorization, trustedRuntimeOrigin: new URL(this.options.runtime.baseUrl).origin,
|
|
221
|
+
...(this.options.previewRuntimePolicy ? { previewRuntimePolicy: this.options.previewRuntimePolicy } : {}),
|
|
201
222
|
tabId: this.options.tabId, onState: state => this.onControlState(state),
|
|
202
223
|
onClose: reason => {
|
|
203
224
|
if (this.channel === channel && !this.ending && !this.destroyed) {
|
|
@@ -580,11 +601,26 @@ class LiveGuideWidget {
|
|
|
580
601
|
this.ownedLaunchId = null;
|
|
581
602
|
this.phase = 'ended';
|
|
582
603
|
this.releaseLock();
|
|
583
|
-
if (!this.destroyed)
|
|
584
|
-
this.
|
|
604
|
+
if (!this.destroyed) {
|
|
605
|
+
if (this.admission.endMessage)
|
|
606
|
+
this.view.showLaunchUnavailable(this.admission.endMessage);
|
|
607
|
+
else
|
|
608
|
+
this.view.showResumeStopped();
|
|
609
|
+
this.commerceCart?.refreshControls();
|
|
610
|
+
}
|
|
585
611
|
this.options.onState();
|
|
586
|
-
}).catch(error => {
|
|
587
|
-
this.
|
|
612
|
+
}).catch(error => {
|
|
613
|
+
this.phase = 'error';
|
|
614
|
+
if (!this.destroyed) {
|
|
615
|
+
if (this.admission.recoveryOnly && error instanceof client_js_1.RuntimeClientError && error.code === 'MERCHANT_PREVIEW_END_UNRESOLVED') {
|
|
616
|
+
this.view.showLaunchUnavailable(error.message);
|
|
617
|
+
}
|
|
618
|
+
else
|
|
619
|
+
this.view.showError(this.view.message('error'), true);
|
|
620
|
+
}
|
|
621
|
+
this.options.onState();
|
|
622
|
+
throw error;
|
|
623
|
+
})
|
|
588
624
|
.finally(() => { if (this.ending === pending)
|
|
589
625
|
this.ending = null; });
|
|
590
626
|
this.ending = pending;
|
|
@@ -639,6 +675,7 @@ class LiveGuideWidget {
|
|
|
639
675
|
channel?.end();
|
|
640
676
|
this.operation?.abort();
|
|
641
677
|
this.operation = null;
|
|
678
|
+
this.commerceCart?.refreshControls();
|
|
642
679
|
}
|
|
643
680
|
destroy() {
|
|
644
681
|
if (this.destroyed)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AiGuideController } from './guideTypes.js';
|
|
2
|
+
import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
3
|
+
export type { MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
4
|
+
export declare function validateMerchantPreviewBootstrap(value: MerchantPreviewBootstrap, preview: MerchantPreviewOptions): MerchantPreviewBootstrap;
|
|
5
|
+
export declare function installMerchantGuidePreview(input: MerchantPreviewOptions): Promise<AiGuideController>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateMerchantPreviewBootstrap = validateMerchantPreviewBootstrap;
|
|
4
|
+
exports.installMerchantGuidePreview = installMerchantGuidePreview;
|
|
5
|
+
const client_js_1 = require("./client.js");
|
|
6
|
+
const merchantPreviewOrigins_js_1 = require("./merchantPreviewOrigins.js");
|
|
7
|
+
const guideAdmission_js_1 = require("./guideAdmission.js");
|
|
8
|
+
const guideTypes_js_1 = require("./guideTypes.js");
|
|
9
|
+
const guideMount_js_1 = require("./guideMount.js");
|
|
10
|
+
const liveGuideWidget_js_1 = require("./liveGuideWidget.js");
|
|
11
|
+
const merchantPreviewAdmission_js_1 = require("./merchantPreviewAdmission.js");
|
|
12
|
+
const merchantPreviewStorage_js_1 = require("./merchantPreviewStorage.js");
|
|
13
|
+
const tabLock_js_1 = require("./tabLock.js");
|
|
14
|
+
const version_js_1 = require("./version.js");
|
|
15
|
+
const invalid = () => new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_INVALID', 'This preview could not be opened. Open it again from OXVO.', false, null, 409);
|
|
16
|
+
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
17
|
+
const timestamp = (value) => typeof value === 'string' ? Date.parse(value) : NaN;
|
|
18
|
+
function captureOptions(input) {
|
|
19
|
+
if (!input || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(input.previewId) || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(input.guideId) ||
|
|
20
|
+
!positive(input.projectId) || !positive(input.configurationVersionId) || !positive(input.configurationRevision) ||
|
|
21
|
+
!/^[a-f0-9]{64}$/.test(input.configurationChecksum) || input.targetOrigin !== location.origin ||
|
|
22
|
+
input.targetPath !== location.pathname || !/^\/(?!\/)[^\x00-\x20\\?#]*$/.test(input.targetPath) || input.targetPath.length > 2048 ||
|
|
23
|
+
input.widgetVersion !== version_js_1.VERSION || typeof input.previewGrant !== 'string' ||
|
|
24
|
+
input.previewGrant.length > 4096 || !/^[\x21-\x7e]*$/.test(input.previewGrant) ||
|
|
25
|
+
!Number.isFinite(timestamp(input.launchExpiresAt)) ||
|
|
26
|
+
!Number.isFinite(timestamp(input.expiresAt)) || timestamp(input.expiresAt) < timestamp(input.launchExpiresAt))
|
|
27
|
+
throw invalid();
|
|
28
|
+
if (input.developmentConsoleOrigin !== undefined && !(0, merchantPreviewOrigins_js_1.isLocalConsoleOrigin)(input.developmentConsoleOrigin))
|
|
29
|
+
throw invalid();
|
|
30
|
+
const runtime = new URL(input.runtimeUrl);
|
|
31
|
+
if (runtime.username || runtime.password || runtime.search || runtime.hash || runtime.pathname !== '/' ||
|
|
32
|
+
!(0, merchantPreviewOrigins_js_1.isPreviewRuntimeOrigin)(runtime, input))
|
|
33
|
+
throw invalid();
|
|
34
|
+
return { previewId: input.previewId, projectId: input.projectId, guideId: input.guideId,
|
|
35
|
+
configurationVersionId: input.configurationVersionId, configurationRevision: input.configurationRevision,
|
|
36
|
+
configurationChecksum: input.configurationChecksum, targetOrigin: input.targetOrigin, targetPath: input.targetPath,
|
|
37
|
+
launchExpiresAt: input.launchExpiresAt, expiresAt: input.expiresAt, runtimeUrl: runtime.href,
|
|
38
|
+
widgetVersion: input.widgetVersion, previewGrant: input.previewGrant,
|
|
39
|
+
...(input.developmentConsoleOrigin ? { developmentConsoleOrigin: input.developmentConsoleOrigin } : {}),
|
|
40
|
+
...(typeof input.onState === 'function' ? { onState: input.onState } : {}),
|
|
41
|
+
...(typeof input.onError === 'function' ? { onError: input.onError } : {}) };
|
|
42
|
+
}
|
|
43
|
+
function validateMerchantPreviewBootstrap(value, preview) {
|
|
44
|
+
const config = (0, guideAdmission_js_1.validateGuideBootstrap)(value, value?.installKey);
|
|
45
|
+
const metadata = value?.merchantPreview;
|
|
46
|
+
if (!guideTypes_js_1.GUIDE_INSTALL_KEY_PATTERN.test(config.installKey) || config.projectId !== preview.projectId || config.guideId !== preview.guideId ||
|
|
47
|
+
config.configRevision !== preview.configurationRevision || config.configChecksum !== `sha256:${preview.configurationChecksum}` ||
|
|
48
|
+
value.providerProtocol !== 'live' || value.widgetVersion !== preview.widgetVersion || value.experienceMode !== 'standard' ||
|
|
49
|
+
value.capabilities?.guideMeasurementV1 === true || value.replayRecordingEnabled === true ||
|
|
50
|
+
!metadata || metadata.previewId !== preview.previewId || metadata.configurationVersionId !== preview.configurationVersionId ||
|
|
51
|
+
metadata.targetOrigin !== preview.targetOrigin || metadata.targetPath !== preview.targetPath ||
|
|
52
|
+
timestamp(metadata.expiresAt) !== timestamp(preview.expiresAt))
|
|
53
|
+
throw invalid();
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function installMerchantGuidePreview(input) {
|
|
57
|
+
try {
|
|
58
|
+
if (window.self !== window.top || window.location.origin === 'null')
|
|
59
|
+
throw invalid();
|
|
60
|
+
const preview = captureOptions(input);
|
|
61
|
+
const recovery = (0, merchantPreviewStorage_js_1.readMerchantPreviewRecovery)(preview, sessionStorage);
|
|
62
|
+
if (!recovery && (!preview.previewGrant || timestamp(preview.launchExpiresAt) <= Date.now()))
|
|
63
|
+
throw invalid();
|
|
64
|
+
const namespace = (0, merchantPreviewAdmission_js_1.merchantPreviewNamespace)(preview.targetOrigin, preview.previewId);
|
|
65
|
+
const mountIdentity = `merchant-preview:${namespace}`;
|
|
66
|
+
const current = (0, guideMount_js_1.mountedGuide)(document, mountIdentity);
|
|
67
|
+
if (current)
|
|
68
|
+
return Promise.resolve(current);
|
|
69
|
+
const mount = new guideMount_js_1.PendingGuideMount(document, mountIdentity);
|
|
70
|
+
void (async () => {
|
|
71
|
+
let lock;
|
|
72
|
+
let widget;
|
|
73
|
+
let admission;
|
|
74
|
+
const operation = new AbortController();
|
|
75
|
+
const timeout = window.setTimeout(() => operation.abort(), 15000);
|
|
76
|
+
try {
|
|
77
|
+
const runtime = new client_js_1.RuntimeClient(preview.runtimeUrl, version_js_1.VERSION);
|
|
78
|
+
const locale = (navigator.language || 'en').slice(0, 32);
|
|
79
|
+
const bootstrap = validateMerchantPreviewBootstrap(recovery ?? await runtime.bootstrapMerchantPreview({ schemaVersion: 1,
|
|
80
|
+
previewId: preview.previewId, previewGrant: preview.previewGrant, path: preview.targetPath, requestedLocale: locale }, operation.signal), preview);
|
|
81
|
+
if (operation.signal.aborted || location.origin !== preview.targetOrigin || location.pathname !== preview.targetPath)
|
|
82
|
+
throw invalid();
|
|
83
|
+
admission = new merchantPreviewAdmission_js_1.MerchantPreviewAdmission(preview, bootstrap, runtime, sessionStorage, recovery !== null);
|
|
84
|
+
const ownerId = `preview:${crypto.randomUUID()}`;
|
|
85
|
+
const tabKey = `__oxvo_ai_guide_preview_tab_${namespace}`;
|
|
86
|
+
let tabId = sessionStorage.getItem(tabKey);
|
|
87
|
+
if (!tabId || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(tabId)) {
|
|
88
|
+
tabId = `preview:${crypto.randomUUID()}`;
|
|
89
|
+
sessionStorage.setItem(tabKey, tabId);
|
|
90
|
+
if (sessionStorage.getItem(tabKey) !== tabId)
|
|
91
|
+
throw invalid();
|
|
92
|
+
}
|
|
93
|
+
const reportState = () => {
|
|
94
|
+
if (!widget)
|
|
95
|
+
return;
|
|
96
|
+
const state = widget.getState();
|
|
97
|
+
try {
|
|
98
|
+
preview.onState?.(state);
|
|
99
|
+
}
|
|
100
|
+
catch { /* A host observer cannot interrupt session cleanup. */ }
|
|
101
|
+
window.dispatchEvent(new CustomEvent('oxvo-ai-guide:state', { detail: state }));
|
|
102
|
+
};
|
|
103
|
+
lock = new tabLock_js_1.TabActivityLock(namespace, ownerId, active => widget?.onTabActivityChange(active), undefined, undefined, {
|
|
104
|
+
onBeforePageHideRelease: () => { void widget?.end().catch(() => undefined); },
|
|
105
|
+
});
|
|
106
|
+
const activity = lock;
|
|
107
|
+
widget = new liveGuideWidget_js_1.LiveGuideWidget({ bootstrap, sessionAdmission: admission, runtime, tabId, locale, messages: {},
|
|
108
|
+
previewRuntimePolicy: preview.developmentConsoleOrigin ? { developmentConsoleOrigin: preview.developmentConsoleOrigin } : {},
|
|
109
|
+
viewOptions: { storageNamespace: namespace, initialPanelView: 'expanded',
|
|
110
|
+
contextNotice: recovery ? 'Finishing your previous preview. If it cannot finish here, check its status in the original Console tab or wait for it to expire.'
|
|
111
|
+
: `Saved draft · Revision ${preview.configurationRevision}. This preview uses OXVO Credits.` },
|
|
112
|
+
acquire: () => activity.acquire(), ownsActivity: () => activity.ownsActivity(), release: () => activity.release(), onState: reportState });
|
|
113
|
+
const live = widget;
|
|
114
|
+
const session = admission;
|
|
115
|
+
let destroyed = false;
|
|
116
|
+
const controller = {
|
|
117
|
+
version: version_js_1.VERSION,
|
|
118
|
+
open: value => live.open(value), close: () => live.close(), getState: () => live.getState(), end: () => live.end(),
|
|
119
|
+
destroy: () => {
|
|
120
|
+
if (destroyed)
|
|
121
|
+
return;
|
|
122
|
+
destroyed = true;
|
|
123
|
+
const ended = live.end();
|
|
124
|
+
live.destroy();
|
|
125
|
+
void ended.catch(() => undefined).finally(() => { session.destroy(); activity.destroy(); mount.release(); });
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
mount.promote(document, mountIdentity, controller);
|
|
129
|
+
mount.resolve(controller);
|
|
130
|
+
reportState();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
widget?.destroy();
|
|
134
|
+
admission?.destroy();
|
|
135
|
+
lock?.destroy();
|
|
136
|
+
mount.release();
|
|
137
|
+
mount.reject(error);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
window.clearTimeout(timeout);
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
143
|
+
return mount.promise;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
return Promise.reject(error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RuntimeClient } from './client.js';
|
|
2
|
+
import type { LiveControlAuthorization } from './liveControlChannel.js';
|
|
3
|
+
import type { LiveGuideSessionAdmission, LiveGuideStartIntent } from './liveGuideWidget.js';
|
|
4
|
+
import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
5
|
+
export { merchantPreviewNamespace } from './merchantPreviewStorage.js';
|
|
6
|
+
export declare class MerchantPreviewAdmission implements LiveGuideSessionAdmission {
|
|
7
|
+
private readonly preview;
|
|
8
|
+
private readonly bootstrap;
|
|
9
|
+
private readonly runtime;
|
|
10
|
+
private readonly storage;
|
|
11
|
+
readonly recoveryOnly: boolean;
|
|
12
|
+
cartRecovery(): import("./commerce/cartRecovery.js").CartRecovery;
|
|
13
|
+
readonly endMessage = "Preview ended. Return to Console to open another preview.";
|
|
14
|
+
private readonly store;
|
|
15
|
+
private readonly originalKey;
|
|
16
|
+
private admission;
|
|
17
|
+
private admitting;
|
|
18
|
+
private ending;
|
|
19
|
+
private grant;
|
|
20
|
+
constructor(preview: MerchantPreviewOptions, bootstrap: MerchantPreviewBootstrap, runtime: RuntimeClient, storage?: Storage, recoveryOnly?: boolean);
|
|
21
|
+
canStart(): boolean;
|
|
22
|
+
hasPendingLaunch(): boolean;
|
|
23
|
+
pendingLaunchId(): string | null;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
launch(input: LiveGuideStartIntent, signal: AbortSignal): Promise<LiveControlAuthorization>;
|
|
26
|
+
private reportError;
|
|
27
|
+
private start;
|
|
28
|
+
end(signal?: AbortSignal, expectedLaunchRequestId?: string): Promise<void>;
|
|
29
|
+
private finish;
|
|
30
|
+
private admit;
|
|
31
|
+
private original;
|
|
32
|
+
private writeOriginal;
|
|
33
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MerchantPreviewAdmission = exports.merchantPreviewNamespace = void 0;
|
|
4
|
+
const cartRecovery_js_1 = require("./commerce/cartRecovery.js");
|
|
5
|
+
const client_js_1 = require("./client.js");
|
|
6
|
+
const guideSubjectStore_js_1 = require("./guideSubjectStore.js");
|
|
7
|
+
const guideTypes_js_1 = require("./guideTypes.js");
|
|
8
|
+
const merchantPreviewStorage_js_1 = require("./merchantPreviewStorage.js");
|
|
9
|
+
var merchantPreviewStorage_js_2 = require("./merchantPreviewStorage.js");
|
|
10
|
+
Object.defineProperty(exports, "merchantPreviewNamespace", { enumerable: true, get: function () { return merchantPreviewStorage_js_2.merchantPreviewNamespace; } });
|
|
11
|
+
const unavailable = () => new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_UNAVAILABLE', 'This preview is no longer available. Open a new preview from OXVO.', false, null, 409);
|
|
12
|
+
class MerchantPreviewAdmission {
|
|
13
|
+
cartRecovery() { return (0, cartRecovery_js_1.createCartRecovery)(this.runtime, this.bootstrap.installKey, this.store); }
|
|
14
|
+
constructor(preview, bootstrap, runtime, storage = sessionStorage, recoveryOnly = false) {
|
|
15
|
+
this.preview = preview;
|
|
16
|
+
this.bootstrap = bootstrap;
|
|
17
|
+
this.runtime = runtime;
|
|
18
|
+
this.storage = storage;
|
|
19
|
+
this.recoveryOnly = recoveryOnly;
|
|
20
|
+
this.endMessage = 'Preview ended. Return to Console to open another preview.';
|
|
21
|
+
this.admission = null;
|
|
22
|
+
this.admitting = null;
|
|
23
|
+
this.ending = null;
|
|
24
|
+
const namespace = (0, merchantPreviewStorage_js_1.merchantPreviewNamespace)(preview.targetOrigin, preview.previewId);
|
|
25
|
+
this.store = new guideSubjectStore_js_1.GuideSubjectStore(bootstrap, preview.targetOrigin, namespace, storage);
|
|
26
|
+
this.originalKey = (0, merchantPreviewStorage_js_1.merchantPreviewStorageKeys)(preview).original;
|
|
27
|
+
this.grant = recoveryOnly ? '' : preview.previewGrant;
|
|
28
|
+
}
|
|
29
|
+
canStart() { return !this.recoveryOnly && !this.original() && Date.now() < Date.parse(this.preview.launchExpiresAt); }
|
|
30
|
+
hasPendingLaunch() { const original = this.original(); return original !== null && !original.completed; }
|
|
31
|
+
pendingLaunchId() { const original = this.original(); return original && !original.completed ? original.intent.launchRequestId : null; }
|
|
32
|
+
destroy() { this.grant = ''; }
|
|
33
|
+
async launch(input, signal) {
|
|
34
|
+
try {
|
|
35
|
+
return await this.start(input, signal);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.reportError(error);
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
reportError(error) {
|
|
43
|
+
const code = error instanceof client_js_1.RuntimeClientError && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
|
|
44
|
+
? error.code : 'MERCHANT_PREVIEW_UNAVAILABLE';
|
|
45
|
+
try {
|
|
46
|
+
this.preview.onError?.(code);
|
|
47
|
+
}
|
|
48
|
+
catch { /* Feedback cannot interrupt original-session cleanup. */ }
|
|
49
|
+
}
|
|
50
|
+
async start(input, signal) {
|
|
51
|
+
if (signal.aborted || !this.canStart() || location.origin !== this.preview.targetOrigin ||
|
|
52
|
+
location.pathname !== this.preview.targetPath || input.path !== this.preview.targetPath ||
|
|
53
|
+
input.configRevision !== this.preview.configurationRevision)
|
|
54
|
+
throw unavailable();
|
|
55
|
+
const intent = {
|
|
56
|
+
schemaVersion: 3, protocolVersion: 2, installKey: this.bootstrap.installKey,
|
|
57
|
+
previewId: this.preview.previewId, launchRequestId: input.launchRequestId,
|
|
58
|
+
clientVersion: input.clientVersion, liveCapabilities: [...input.liveCapabilities],
|
|
59
|
+
configRevision: input.configRevision, path: input.path, tabId: input.tabId, mode: input.mode,
|
|
60
|
+
experienceMode: 'standard', consent: { ...input.consent, scopes: [...input.consent.scopes] },
|
|
61
|
+
capabilitySummary: { ...input.capabilitySummary },
|
|
62
|
+
};
|
|
63
|
+
(0, merchantPreviewStorage_js_1.saveMerchantPreviewRecovery)(this.preview, this.bootstrap, this.storage);
|
|
64
|
+
this.writeOriginal({ v: 1, previewId: this.preview.previewId, intent, completed: false });
|
|
65
|
+
const admission = await this.admit(intent, signal);
|
|
66
|
+
if (signal.aborted || this.original()?.completed)
|
|
67
|
+
throw unavailable();
|
|
68
|
+
const result = await this.runtime.launchMerchantPreview(intent, admission.admissionGrant, signal);
|
|
69
|
+
if (result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
70
|
+
result.guideId !== this.preview.guideId || result.subjectId !== admission.subjectId ||
|
|
71
|
+
result.launchRequestId !== intent.launchRequestId)
|
|
72
|
+
throw unavailable();
|
|
73
|
+
// The existing control protocol validates its exact envelope, without preview metadata.
|
|
74
|
+
const authorization = { ...result };
|
|
75
|
+
delete authorization.previewId;
|
|
76
|
+
return authorization;
|
|
77
|
+
}
|
|
78
|
+
end(signal, expectedLaunchRequestId) {
|
|
79
|
+
if (this.ending)
|
|
80
|
+
return this.ending;
|
|
81
|
+
const original = this.original();
|
|
82
|
+
if (!original || original.completed || (expectedLaunchRequestId !== undefined &&
|
|
83
|
+
original.intent.launchRequestId !== expectedLaunchRequestId))
|
|
84
|
+
return Promise.resolve();
|
|
85
|
+
const operation = this.finish(original, signal).catch(error => { this.reportError(error); throw error; })
|
|
86
|
+
.finally(() => { if (this.ending === operation)
|
|
87
|
+
this.ending = null; });
|
|
88
|
+
this.ending = operation;
|
|
89
|
+
return operation;
|
|
90
|
+
}
|
|
91
|
+
async finish(original, signal) {
|
|
92
|
+
if (this.admitting)
|
|
93
|
+
await this.admitting.catch(() => undefined);
|
|
94
|
+
let subject = this.store.readSubject();
|
|
95
|
+
if (!subject) {
|
|
96
|
+
// An ambiguous admission can be recovered only with its original intent and in-memory grant.
|
|
97
|
+
if (!this.grant)
|
|
98
|
+
throw new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_END_UNRESOLVED', 'The previous preview could not be confirmed. Return to the original Console tab to check its status or wait for it to expire.', false, null, 409);
|
|
99
|
+
await this.admit(original.intent, signal);
|
|
100
|
+
subject = this.store.readSubject();
|
|
101
|
+
}
|
|
102
|
+
if (!subject || this.original()?.intent.launchRequestId !== original.intent.launchRequestId)
|
|
103
|
+
throw unavailable();
|
|
104
|
+
const result = await this.runtime.endMerchantPreview({ schemaVersion: 3, previewId: this.preview.previewId,
|
|
105
|
+
installKey: this.bootstrap.installKey, subjectCredential: subject.credential,
|
|
106
|
+
launchRequestId: original.intent.launchRequestId, tabId: original.intent.tabId, action: 'end' }, signal);
|
|
107
|
+
if (!result || Object.keys(result).length !== 6 || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
108
|
+
result.providerProtocol !== 'live' || result.status !== 'end_requested' || result.previewId !== this.preview.previewId ||
|
|
109
|
+
result.launchRequestId !== original.intent.launchRequestId)
|
|
110
|
+
throw unavailable();
|
|
111
|
+
this.writeOriginal({ ...original, completed: true });
|
|
112
|
+
this.store.clearLaunch(original.intent.launchRequestId);
|
|
113
|
+
this.admission = null;
|
|
114
|
+
this.grant = '';
|
|
115
|
+
}
|
|
116
|
+
async admit(intent, signal) {
|
|
117
|
+
if (this.admission)
|
|
118
|
+
return this.admission;
|
|
119
|
+
if (this.admitting)
|
|
120
|
+
return this.admitting;
|
|
121
|
+
if (!this.grant)
|
|
122
|
+
throw unavailable();
|
|
123
|
+
const subject = this.store.readSubject();
|
|
124
|
+
const operation = this.runtime.admitMerchantPreview(intent, this.grant, subject?.credential, signal).then(result => {
|
|
125
|
+
const required = ['schemaVersion', 'protocolVersion', 'providerProtocol', 'previewId', 'projectId', 'guideId', 'subjectId',
|
|
126
|
+
'subjectAuthorityRevision', 'tabId', 'launchRequestId', 'configRevision', 'configChecksum', 'admissionGrant',
|
|
127
|
+
'expiresAt', 'subjectCredentialExpiresAt'];
|
|
128
|
+
if (!result || Object.keys(result).some(key => ![...required, 'subjectCredential'].includes(key)) ||
|
|
129
|
+
required.some(key => !(key in result)) || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
130
|
+
result.providerProtocol !== 'live' || result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
131
|
+
result.guideId !== this.preview.guideId || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(result.subjectId) ||
|
|
132
|
+
result.tabId !== intent.tabId || result.launchRequestId !== intent.launchRequestId ||
|
|
133
|
+
result.configRevision !== this.preview.configurationRevision || result.configChecksum !== this.bootstrap.configChecksum ||
|
|
134
|
+
!Number.isSafeInteger(result.subjectAuthorityRevision) || result.subjectAuthorityRevision < 0 ||
|
|
135
|
+
typeof result.admissionGrant !== 'string' || result.admissionGrant.length < 1 || result.admissionGrant.length > 4096 ||
|
|
136
|
+
!Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now() ||
|
|
137
|
+
!Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) || Date.parse(result.subjectCredentialExpiresAt) <= Date.now() ||
|
|
138
|
+
(subject && (result.subjectId !== subject.subjectId || result.subjectAuthorityRevision !== subject.subjectAuthorityRevision)))
|
|
139
|
+
throw unavailable();
|
|
140
|
+
const credential = subject?.credential ?? result.subjectCredential;
|
|
141
|
+
if (!credential || !guideTypes_js_1.GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(credential))
|
|
142
|
+
throw unavailable();
|
|
143
|
+
this.store.saveSubject({ v: 1, origin: this.preview.targetOrigin, projectId: this.preview.projectId, guideId: this.preview.guideId,
|
|
144
|
+
subjectId: result.subjectId, subjectAuthorityRevision: result.subjectAuthorityRevision, credential, expiresAt: result.subjectCredentialExpiresAt });
|
|
145
|
+
this.store.saveLaunch({ v: 1, subjectId: result.subjectId, intent, recordingConsent: false });
|
|
146
|
+
this.admission = result;
|
|
147
|
+
return result;
|
|
148
|
+
}).finally(() => { if (this.admitting === operation)
|
|
149
|
+
this.admitting = null; });
|
|
150
|
+
this.admitting = operation;
|
|
151
|
+
return operation;
|
|
152
|
+
}
|
|
153
|
+
original() {
|
|
154
|
+
const raw = this.storage.getItem(this.originalKey);
|
|
155
|
+
if (raw === null)
|
|
156
|
+
return null;
|
|
157
|
+
if (raw.length > 16384)
|
|
158
|
+
throw unavailable();
|
|
159
|
+
let value;
|
|
160
|
+
try {
|
|
161
|
+
value = JSON.parse(raw);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
throw unavailable();
|
|
165
|
+
}
|
|
166
|
+
const intent = value?.intent;
|
|
167
|
+
if (value?.v !== 1 || value.previewId !== this.preview.previewId || typeof value.completed !== 'boolean' ||
|
|
168
|
+
!intent || intent.schemaVersion !== 3 || intent.protocolVersion !== 2 || intent.previewId !== this.preview.previewId ||
|
|
169
|
+
intent.installKey !== this.bootstrap.installKey || intent.configRevision !== this.preview.configurationRevision ||
|
|
170
|
+
intent.path !== this.preview.targetPath || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(intent.launchRequestId) ||
|
|
171
|
+
typeof intent.tabId !== 'string' || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(intent.tabId) ||
|
|
172
|
+
!['text', 'voice'].includes(intent.mode) || intent.experienceMode !== 'standard' ||
|
|
173
|
+
'guideMeasurement' in intent || 'previewGrant' in intent || 'admissionGrant' in intent)
|
|
174
|
+
throw unavailable();
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
writeOriginal(value) {
|
|
178
|
+
const raw = JSON.stringify(value);
|
|
179
|
+
if (raw.length > 16384)
|
|
180
|
+
throw unavailable();
|
|
181
|
+
this.storage.setItem(this.originalKey, raw);
|
|
182
|
+
if (this.storage.getItem(this.originalKey) !== raw)
|
|
183
|
+
throw unavailable();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.MerchantPreviewAdmission = MerchantPreviewAdmission;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type MerchantPreviewRuntimePolicy = {
|
|
2
|
+
developmentConsoleOrigin?: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const isLoopbackHostname: (hostname: string) => boolean;
|
|
5
|
+
export declare function isLocalConsoleOrigin(value: string): boolean;
|
|
6
|
+
export declare function isPreviewRuntimeOrigin(url: URL, policy?: MerchantPreviewRuntimePolicy): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoopbackHostname = void 0;
|
|
4
|
+
exports.isLocalConsoleOrigin = isLocalConsoleOrigin;
|
|
5
|
+
exports.isPreviewRuntimeOrigin = isPreviewRuntimeOrigin;
|
|
6
|
+
const isLoopbackHostname = (hostname) => hostname === 'localhost' ||
|
|
7
|
+
hostname.endsWith('.localhost') || /^127(?:\.\d{1,3}){3}$/.test(hostname) || hostname === '[::1]';
|
|
8
|
+
exports.isLoopbackHostname = isLoopbackHostname;
|
|
9
|
+
function isLocalConsoleOrigin(value) {
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(value);
|
|
12
|
+
return value === url.origin && ['http:', 'https:'].includes(url.protocol) &&
|
|
13
|
+
!url.username && !url.password && (0, exports.isLoopbackHostname)(url.hostname);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// The dev alias is accepted only for a preview whose installed loader pinned a local Console.
|
|
20
|
+
function isPreviewRuntimeOrigin(url, policy = {}) {
|
|
21
|
+
return url.protocol === 'https:' || (url.protocol === 'http:' && ((0, exports.isLoopbackHostname)(url.hostname) ||
|
|
22
|
+
(url.hostname === 'oxvosessions.local' && typeof policy.developmentConsoleOrigin === 'string' &&
|
|
23
|
+
isLocalConsoleOrigin(policy.developmentConsoleOrigin))));
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
2
|
+
export declare function merchantPreviewNamespace(origin: string, previewId: string): string;
|
|
3
|
+
export declare function merchantPreviewStorageKeys(preview: Pick<MerchantPreviewOptions, 'targetOrigin' | 'previewId'>): {
|
|
4
|
+
namespace: string;
|
|
5
|
+
original: string;
|
|
6
|
+
recovery: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function saveMerchantPreviewRecovery(preview: MerchantPreviewOptions, bootstrap: MerchantPreviewBootstrap, storage: Storage): void;
|
|
9
|
+
export declare function readMerchantPreviewRecovery(preview: MerchantPreviewOptions, storage: Storage): MerchantPreviewBootstrap | null;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.merchantPreviewNamespace = merchantPreviewNamespace;
|
|
4
|
+
exports.merchantPreviewStorageKeys = merchantPreviewStorageKeys;
|
|
5
|
+
exports.saveMerchantPreviewRecovery = saveMerchantPreviewRecovery;
|
|
6
|
+
exports.readMerchantPreviewRecovery = readMerchantPreviewRecovery;
|
|
7
|
+
const guideTypes_js_1 = require("./guideTypes.js");
|
|
8
|
+
const contracts_js_1 = require("./commerce/contracts.js");
|
|
9
|
+
const invalid = () => new Error('The previous preview could not be recovered. Return to the original Console tab to check its status or wait for it to expire.');
|
|
10
|
+
const PREVIEW_FIELDS = ['previewId', 'projectId', 'guideId', 'configurationVersionId', 'configurationRevision',
|
|
11
|
+
'configurationChecksum', 'targetOrigin', 'targetPath', 'launchExpiresAt', 'expiresAt', 'runtimeUrl', 'widgetVersion'];
|
|
12
|
+
const BOOTSTRAP_FIELDS = ['schemaVersion', 'projectId', 'guideId', 'installKey', 'protocol', 'available', 'configRevision',
|
|
13
|
+
'configChecksum', 'providerProtocol', 'providerModel', 'liveCapabilities', 'liveAssets', 'widgetVersion',
|
|
14
|
+
'experienceMode', 'replayRecordingEnabled', 'capabilities', 'consent', 'cache', 'merchantPreview'];
|
|
15
|
+
const APPEARANCE_FIELDS = ['brandName', 'launcherLabel', 'accent', 'position', 'panelWidth', 'glassEffect',
|
|
16
|
+
'hideLauncherWhenVisitorLimited', 'theme', 'welcomeMessage', 'compactEntryEnabled'];
|
|
17
|
+
function merchantPreviewNamespace(origin, previewId) {
|
|
18
|
+
if (new URL(origin).origin !== origin || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(previewId))
|
|
19
|
+
throw invalid();
|
|
20
|
+
return `merchant_preview_v1_${encodeURIComponent(origin)}_${previewId}`;
|
|
21
|
+
}
|
|
22
|
+
function merchantPreviewStorageKeys(preview) {
|
|
23
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
24
|
+
return { namespace, original: `__oxvo_ai_guide_preview_launch_${namespace}`, recovery: `__oxvo_ai_guide_preview_recovery_${namespace}` };
|
|
25
|
+
}
|
|
26
|
+
const pick = (value, fields) => Object.fromEntries(fields.filter(key => key in value)
|
|
27
|
+
.map(key => [key, value[key]]));
|
|
28
|
+
function saveMerchantPreviewRecovery(preview, bootstrap, storage) {
|
|
29
|
+
const commerce = bootstrap.commerce === undefined ? null
|
|
30
|
+
: (0, contracts_js_1.parseCommerceBootstrap)(bootstrap.commerce, preview.guideId, preview.targetOrigin);
|
|
31
|
+
if (bootstrap.commerce !== undefined && !commerce)
|
|
32
|
+
throw invalid();
|
|
33
|
+
const presentation = { ...pick(bootstrap, BOOTSTRAP_FIELDS),
|
|
34
|
+
...(commerce ? { commerce: { schemaVersion: commerce.schemaVersion, enabled: commerce.enabled,
|
|
35
|
+
guideId: commerce.guideId, cartEnabled: commerce.cartEnabled,
|
|
36
|
+
store: { provider: commerce.store.provider, storeRef: commerce.store.storeRef,
|
|
37
|
+
origin: commerce.store.origin, policyRevision: commerce.store.policyRevision } } } : {}),
|
|
38
|
+
...(bootstrap.appearance ? { appearance: pick(bootstrap.appearance, APPEARANCE_FIELDS) } : {}) };
|
|
39
|
+
const raw = JSON.stringify({ v: 1, preview: pick(preview, PREVIEW_FIELDS), bootstrap: presentation });
|
|
40
|
+
if (raw.length > 65536 || /"(?:previewGrant|admissionGrant|controlCredential|subjectCredential)"\s*:/.test(raw))
|
|
41
|
+
throw invalid();
|
|
42
|
+
const key = merchantPreviewStorageKeys(preview).recovery;
|
|
43
|
+
storage.setItem(key, raw);
|
|
44
|
+
if (storage.getItem(key) !== raw)
|
|
45
|
+
throw invalid();
|
|
46
|
+
}
|
|
47
|
+
function readMerchantPreviewRecovery(preview, storage) {
|
|
48
|
+
const keys = merchantPreviewStorageKeys(preview);
|
|
49
|
+
if (storage.getItem(keys.original) === null)
|
|
50
|
+
return null;
|
|
51
|
+
const raw = storage.getItem(keys.recovery);
|
|
52
|
+
if (!raw || raw.length > 65536)
|
|
53
|
+
throw invalid();
|
|
54
|
+
let value;
|
|
55
|
+
try {
|
|
56
|
+
value = JSON.parse(raw);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw invalid();
|
|
60
|
+
}
|
|
61
|
+
if (value?.v !== 1 || !value.preview || !value.bootstrap ||
|
|
62
|
+
JSON.stringify(value.preview) !== JSON.stringify(pick(preview, PREVIEW_FIELDS)))
|
|
63
|
+
throw invalid();
|
|
64
|
+
if (value.bootstrap.commerce !== undefined &&
|
|
65
|
+
!(0, contracts_js_1.parseCommerceBootstrap)(value.bootstrap.commerce, preview.guideId, preview.targetOrigin))
|
|
66
|
+
throw invalid();
|
|
67
|
+
return value.bootstrap;
|
|
68
|
+
}
|