@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
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { createCartRecovery } from './commerce/cartRecovery.js';
|
|
2
|
+
import { RuntimeClientError } from './client.js';
|
|
3
|
+
import { GuideSubjectStore } from './guideSubjectStore.js';
|
|
4
|
+
import { GUIDE_SUBJECT_CREDENTIAL_PATTERN, GUIDE_UUID_PATTERN } from './guideTypes.js';
|
|
5
|
+
import { merchantPreviewNamespace, merchantPreviewStorageKeys, saveMerchantPreviewRecovery } from './merchantPreviewStorage.js';
|
|
6
|
+
export { merchantPreviewNamespace } from './merchantPreviewStorage.js';
|
|
7
|
+
const unavailable = () => new RuntimeClientError('MERCHANT_PREVIEW_UNAVAILABLE', 'This preview is no longer available. Open a new preview from OXVO.', false, null, 409);
|
|
8
|
+
export class MerchantPreviewAdmission {
|
|
9
|
+
cartRecovery() { return createCartRecovery(this.runtime, this.bootstrap.installKey, this.store); }
|
|
10
|
+
constructor(preview, bootstrap, runtime, storage = sessionStorage, recoveryOnly = false) {
|
|
11
|
+
this.preview = preview;
|
|
12
|
+
this.bootstrap = bootstrap;
|
|
13
|
+
this.runtime = runtime;
|
|
14
|
+
this.storage = storage;
|
|
15
|
+
this.recoveryOnly = recoveryOnly;
|
|
16
|
+
this.endMessage = 'Preview ended. Return to Console to open another preview.';
|
|
17
|
+
this.admission = null;
|
|
18
|
+
this.admitting = null;
|
|
19
|
+
this.ending = null;
|
|
20
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
21
|
+
this.store = new GuideSubjectStore(bootstrap, preview.targetOrigin, namespace, storage);
|
|
22
|
+
this.originalKey = merchantPreviewStorageKeys(preview).original;
|
|
23
|
+
this.grant = recoveryOnly ? '' : preview.previewGrant;
|
|
24
|
+
}
|
|
25
|
+
canStart() { return !this.recoveryOnly && !this.original() && Date.now() < Date.parse(this.preview.launchExpiresAt); }
|
|
26
|
+
hasPendingLaunch() { const original = this.original(); return original !== null && !original.completed; }
|
|
27
|
+
pendingLaunchId() { const original = this.original(); return original && !original.completed ? original.intent.launchRequestId : null; }
|
|
28
|
+
destroy() { this.grant = ''; }
|
|
29
|
+
async launch(input, signal) {
|
|
30
|
+
try {
|
|
31
|
+
return await this.start(input, signal);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.reportError(error);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
reportError(error) {
|
|
39
|
+
const code = error instanceof RuntimeClientError && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
|
|
40
|
+
? error.code : 'MERCHANT_PREVIEW_UNAVAILABLE';
|
|
41
|
+
try {
|
|
42
|
+
this.preview.onError?.(code);
|
|
43
|
+
}
|
|
44
|
+
catch { /* Feedback cannot interrupt original-session cleanup. */ }
|
|
45
|
+
}
|
|
46
|
+
async start(input, signal) {
|
|
47
|
+
if (signal.aborted || !this.canStart() || location.origin !== this.preview.targetOrigin ||
|
|
48
|
+
location.pathname !== this.preview.targetPath || input.path !== this.preview.targetPath ||
|
|
49
|
+
input.configRevision !== this.preview.configurationRevision)
|
|
50
|
+
throw unavailable();
|
|
51
|
+
const intent = {
|
|
52
|
+
schemaVersion: 3, protocolVersion: 2, installKey: this.bootstrap.installKey,
|
|
53
|
+
previewId: this.preview.previewId, launchRequestId: input.launchRequestId,
|
|
54
|
+
clientVersion: input.clientVersion, liveCapabilities: [...input.liveCapabilities],
|
|
55
|
+
configRevision: input.configRevision, path: input.path, tabId: input.tabId, mode: input.mode,
|
|
56
|
+
experienceMode: 'standard', consent: { ...input.consent, scopes: [...input.consent.scopes] },
|
|
57
|
+
capabilitySummary: { ...input.capabilitySummary },
|
|
58
|
+
};
|
|
59
|
+
saveMerchantPreviewRecovery(this.preview, this.bootstrap, this.storage);
|
|
60
|
+
this.writeOriginal({ v: 1, previewId: this.preview.previewId, intent, completed: false });
|
|
61
|
+
const admission = await this.admit(intent, signal);
|
|
62
|
+
if (signal.aborted || this.original()?.completed)
|
|
63
|
+
throw unavailable();
|
|
64
|
+
const result = await this.runtime.launchMerchantPreview(intent, admission.admissionGrant, signal);
|
|
65
|
+
if (result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
66
|
+
result.guideId !== this.preview.guideId || result.subjectId !== admission.subjectId ||
|
|
67
|
+
result.launchRequestId !== intent.launchRequestId)
|
|
68
|
+
throw unavailable();
|
|
69
|
+
// The existing control protocol validates its exact envelope, without preview metadata.
|
|
70
|
+
const authorization = { ...result };
|
|
71
|
+
delete authorization.previewId;
|
|
72
|
+
return authorization;
|
|
73
|
+
}
|
|
74
|
+
end(signal, expectedLaunchRequestId) {
|
|
75
|
+
if (this.ending)
|
|
76
|
+
return this.ending;
|
|
77
|
+
const original = this.original();
|
|
78
|
+
if (!original || original.completed || (expectedLaunchRequestId !== undefined &&
|
|
79
|
+
original.intent.launchRequestId !== expectedLaunchRequestId))
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
const operation = this.finish(original, signal).catch(error => { this.reportError(error); throw error; })
|
|
82
|
+
.finally(() => { if (this.ending === operation)
|
|
83
|
+
this.ending = null; });
|
|
84
|
+
this.ending = operation;
|
|
85
|
+
return operation;
|
|
86
|
+
}
|
|
87
|
+
async finish(original, signal) {
|
|
88
|
+
if (this.admitting)
|
|
89
|
+
await this.admitting.catch(() => undefined);
|
|
90
|
+
let subject = this.store.readSubject();
|
|
91
|
+
if (!subject) {
|
|
92
|
+
// An ambiguous admission can be recovered only with its original intent and in-memory grant.
|
|
93
|
+
if (!this.grant)
|
|
94
|
+
throw new 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);
|
|
95
|
+
await this.admit(original.intent, signal);
|
|
96
|
+
subject = this.store.readSubject();
|
|
97
|
+
}
|
|
98
|
+
if (!subject || this.original()?.intent.launchRequestId !== original.intent.launchRequestId)
|
|
99
|
+
throw unavailable();
|
|
100
|
+
const result = await this.runtime.endMerchantPreview({ schemaVersion: 3, previewId: this.preview.previewId,
|
|
101
|
+
installKey: this.bootstrap.installKey, subjectCredential: subject.credential,
|
|
102
|
+
launchRequestId: original.intent.launchRequestId, tabId: original.intent.tabId, action: 'end' }, signal);
|
|
103
|
+
if (!result || Object.keys(result).length !== 6 || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
104
|
+
result.providerProtocol !== 'live' || result.status !== 'end_requested' || result.previewId !== this.preview.previewId ||
|
|
105
|
+
result.launchRequestId !== original.intent.launchRequestId)
|
|
106
|
+
throw unavailable();
|
|
107
|
+
this.writeOriginal({ ...original, completed: true });
|
|
108
|
+
this.store.clearLaunch(original.intent.launchRequestId);
|
|
109
|
+
this.admission = null;
|
|
110
|
+
this.grant = '';
|
|
111
|
+
}
|
|
112
|
+
async admit(intent, signal) {
|
|
113
|
+
if (this.admission)
|
|
114
|
+
return this.admission;
|
|
115
|
+
if (this.admitting)
|
|
116
|
+
return this.admitting;
|
|
117
|
+
if (!this.grant)
|
|
118
|
+
throw unavailable();
|
|
119
|
+
const subject = this.store.readSubject();
|
|
120
|
+
const operation = this.runtime.admitMerchantPreview(intent, this.grant, subject?.credential, signal).then(result => {
|
|
121
|
+
const required = ['schemaVersion', 'protocolVersion', 'providerProtocol', 'previewId', 'projectId', 'guideId', 'subjectId',
|
|
122
|
+
'subjectAuthorityRevision', 'tabId', 'launchRequestId', 'configRevision', 'configChecksum', 'admissionGrant',
|
|
123
|
+
'expiresAt', 'subjectCredentialExpiresAt'];
|
|
124
|
+
if (!result || Object.keys(result).some(key => ![...required, 'subjectCredential'].includes(key)) ||
|
|
125
|
+
required.some(key => !(key in result)) || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
126
|
+
result.providerProtocol !== 'live' || result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
127
|
+
result.guideId !== this.preview.guideId || !GUIDE_UUID_PATTERN.test(result.subjectId) ||
|
|
128
|
+
result.tabId !== intent.tabId || result.launchRequestId !== intent.launchRequestId ||
|
|
129
|
+
result.configRevision !== this.preview.configurationRevision || result.configChecksum !== this.bootstrap.configChecksum ||
|
|
130
|
+
!Number.isSafeInteger(result.subjectAuthorityRevision) || result.subjectAuthorityRevision < 0 ||
|
|
131
|
+
typeof result.admissionGrant !== 'string' || result.admissionGrant.length < 1 || result.admissionGrant.length > 4096 ||
|
|
132
|
+
!Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now() ||
|
|
133
|
+
!Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) || Date.parse(result.subjectCredentialExpiresAt) <= Date.now() ||
|
|
134
|
+
(subject && (result.subjectId !== subject.subjectId || result.subjectAuthorityRevision !== subject.subjectAuthorityRevision)))
|
|
135
|
+
throw unavailable();
|
|
136
|
+
const credential = subject?.credential ?? result.subjectCredential;
|
|
137
|
+
if (!credential || !GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(credential))
|
|
138
|
+
throw unavailable();
|
|
139
|
+
this.store.saveSubject({ v: 1, origin: this.preview.targetOrigin, projectId: this.preview.projectId, guideId: this.preview.guideId,
|
|
140
|
+
subjectId: result.subjectId, subjectAuthorityRevision: result.subjectAuthorityRevision, credential, expiresAt: result.subjectCredentialExpiresAt });
|
|
141
|
+
this.store.saveLaunch({ v: 1, subjectId: result.subjectId, intent, recordingConsent: false });
|
|
142
|
+
this.admission = result;
|
|
143
|
+
return result;
|
|
144
|
+
}).finally(() => { if (this.admitting === operation)
|
|
145
|
+
this.admitting = null; });
|
|
146
|
+
this.admitting = operation;
|
|
147
|
+
return operation;
|
|
148
|
+
}
|
|
149
|
+
original() {
|
|
150
|
+
const raw = this.storage.getItem(this.originalKey);
|
|
151
|
+
if (raw === null)
|
|
152
|
+
return null;
|
|
153
|
+
if (raw.length > 16384)
|
|
154
|
+
throw unavailable();
|
|
155
|
+
let value;
|
|
156
|
+
try {
|
|
157
|
+
value = JSON.parse(raw);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
throw unavailable();
|
|
161
|
+
}
|
|
162
|
+
const intent = value?.intent;
|
|
163
|
+
if (value?.v !== 1 || value.previewId !== this.preview.previewId || typeof value.completed !== 'boolean' ||
|
|
164
|
+
!intent || intent.schemaVersion !== 3 || intent.protocolVersion !== 2 || intent.previewId !== this.preview.previewId ||
|
|
165
|
+
intent.installKey !== this.bootstrap.installKey || intent.configRevision !== this.preview.configurationRevision ||
|
|
166
|
+
intent.path !== this.preview.targetPath || !GUIDE_UUID_PATTERN.test(intent.launchRequestId) ||
|
|
167
|
+
typeof intent.tabId !== 'string' || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(intent.tabId) ||
|
|
168
|
+
!['text', 'voice'].includes(intent.mode) || intent.experienceMode !== 'standard' ||
|
|
169
|
+
'guideMeasurement' in intent || 'previewGrant' in intent || 'admissionGrant' in intent)
|
|
170
|
+
throw unavailable();
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
writeOriginal(value) {
|
|
174
|
+
const raw = JSON.stringify(value);
|
|
175
|
+
if (raw.length > 16384)
|
|
176
|
+
throw unavailable();
|
|
177
|
+
this.storage.setItem(this.originalKey, raw);
|
|
178
|
+
if (this.storage.getItem(this.originalKey) !== raw)
|
|
179
|
+
throw unavailable();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -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,18 @@
|
|
|
1
|
+
export const isLoopbackHostname = (hostname) => hostname === 'localhost' ||
|
|
2
|
+
hostname.endsWith('.localhost') || /^127(?:\.\d{1,3}){3}$/.test(hostname) || hostname === '[::1]';
|
|
3
|
+
export function isLocalConsoleOrigin(value) {
|
|
4
|
+
try {
|
|
5
|
+
const url = new URL(value);
|
|
6
|
+
return value === url.origin && ['http:', 'https:'].includes(url.protocol) &&
|
|
7
|
+
!url.username && !url.password && isLoopbackHostname(url.hostname);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// The dev alias is accepted only for a preview whose installed loader pinned a local Console.
|
|
14
|
+
export function isPreviewRuntimeOrigin(url, policy = {}) {
|
|
15
|
+
return url.protocol === 'https:' || (url.protocol === 'http:' && (isLoopbackHostname(url.hostname) ||
|
|
16
|
+
(url.hostname === 'oxvosessions.local' && typeof policy.developmentConsoleOrigin === 'string' &&
|
|
17
|
+
isLocalConsoleOrigin(policy.developmentConsoleOrigin))));
|
|
18
|
+
}
|
|
@@ -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,62 @@
|
|
|
1
|
+
import { GUIDE_UUID_PATTERN } from './guideTypes.js';
|
|
2
|
+
import { parseCommerceBootstrap } from './commerce/contracts.js';
|
|
3
|
+
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.');
|
|
4
|
+
const PREVIEW_FIELDS = ['previewId', 'projectId', 'guideId', 'configurationVersionId', 'configurationRevision',
|
|
5
|
+
'configurationChecksum', 'targetOrigin', 'targetPath', 'launchExpiresAt', 'expiresAt', 'runtimeUrl', 'widgetVersion'];
|
|
6
|
+
const BOOTSTRAP_FIELDS = ['schemaVersion', 'projectId', 'guideId', 'installKey', 'protocol', 'available', 'configRevision',
|
|
7
|
+
'configChecksum', 'providerProtocol', 'providerModel', 'liveCapabilities', 'liveAssets', 'widgetVersion',
|
|
8
|
+
'experienceMode', 'replayRecordingEnabled', 'capabilities', 'consent', 'cache', 'merchantPreview'];
|
|
9
|
+
const APPEARANCE_FIELDS = ['brandName', 'launcherLabel', 'accent', 'position', 'panelWidth', 'glassEffect',
|
|
10
|
+
'hideLauncherWhenVisitorLimited', 'theme', 'welcomeMessage', 'compactEntryEnabled'];
|
|
11
|
+
export function merchantPreviewNamespace(origin, previewId) {
|
|
12
|
+
if (new URL(origin).origin !== origin || !GUIDE_UUID_PATTERN.test(previewId))
|
|
13
|
+
throw invalid();
|
|
14
|
+
return `merchant_preview_v1_${encodeURIComponent(origin)}_${previewId}`;
|
|
15
|
+
}
|
|
16
|
+
export function merchantPreviewStorageKeys(preview) {
|
|
17
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
18
|
+
return { namespace, original: `__oxvo_ai_guide_preview_launch_${namespace}`, recovery: `__oxvo_ai_guide_preview_recovery_${namespace}` };
|
|
19
|
+
}
|
|
20
|
+
const pick = (value, fields) => Object.fromEntries(fields.filter(key => key in value)
|
|
21
|
+
.map(key => [key, value[key]]));
|
|
22
|
+
export function saveMerchantPreviewRecovery(preview, bootstrap, storage) {
|
|
23
|
+
const commerce = bootstrap.commerce === undefined ? null
|
|
24
|
+
: parseCommerceBootstrap(bootstrap.commerce, preview.guideId, preview.targetOrigin);
|
|
25
|
+
if (bootstrap.commerce !== undefined && !commerce)
|
|
26
|
+
throw invalid();
|
|
27
|
+
const presentation = { ...pick(bootstrap, BOOTSTRAP_FIELDS),
|
|
28
|
+
...(commerce ? { commerce: { schemaVersion: commerce.schemaVersion, enabled: commerce.enabled,
|
|
29
|
+
guideId: commerce.guideId, cartEnabled: commerce.cartEnabled,
|
|
30
|
+
store: { provider: commerce.store.provider, storeRef: commerce.store.storeRef,
|
|
31
|
+
origin: commerce.store.origin, policyRevision: commerce.store.policyRevision } } } : {}),
|
|
32
|
+
...(bootstrap.appearance ? { appearance: pick(bootstrap.appearance, APPEARANCE_FIELDS) } : {}) };
|
|
33
|
+
const raw = JSON.stringify({ v: 1, preview: pick(preview, PREVIEW_FIELDS), bootstrap: presentation });
|
|
34
|
+
if (raw.length > 65536 || /"(?:previewGrant|admissionGrant|controlCredential|subjectCredential)"\s*:/.test(raw))
|
|
35
|
+
throw invalid();
|
|
36
|
+
const key = merchantPreviewStorageKeys(preview).recovery;
|
|
37
|
+
storage.setItem(key, raw);
|
|
38
|
+
if (storage.getItem(key) !== raw)
|
|
39
|
+
throw invalid();
|
|
40
|
+
}
|
|
41
|
+
export function readMerchantPreviewRecovery(preview, storage) {
|
|
42
|
+
const keys = merchantPreviewStorageKeys(preview);
|
|
43
|
+
if (storage.getItem(keys.original) === null)
|
|
44
|
+
return null;
|
|
45
|
+
const raw = storage.getItem(keys.recovery);
|
|
46
|
+
if (!raw || raw.length > 65536)
|
|
47
|
+
throw invalid();
|
|
48
|
+
let value;
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(raw);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw invalid();
|
|
54
|
+
}
|
|
55
|
+
if (value?.v !== 1 || !value.preview || !value.bootstrap ||
|
|
56
|
+
JSON.stringify(value.preview) !== JSON.stringify(pick(preview, PREVIEW_FIELDS)))
|
|
57
|
+
throw invalid();
|
|
58
|
+
if (value.bootstrap.commerce !== undefined &&
|
|
59
|
+
!parseCommerceBootstrap(value.bootstrap.commerce, preview.guideId, preview.targetOrigin))
|
|
60
|
+
throw invalid();
|
|
61
|
+
return value.bootstrap;
|
|
62
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { GuideAdmissionResult, GuideBootstrapConfig, GuideLaunchRecoveryInput } from './guideTypes.js';
|
|
2
|
+
import type { LiveGuideLaunchIntent } from './liveGuideAdmission.js';
|
|
3
|
+
import type { AiGuideControllerState } from './types.js';
|
|
4
|
+
export type MerchantPreviewOptions = {
|
|
5
|
+
previewId: string;
|
|
6
|
+
projectId: number;
|
|
7
|
+
guideId: string;
|
|
8
|
+
configurationVersionId: number;
|
|
9
|
+
configurationRevision: number;
|
|
10
|
+
configurationChecksum: string;
|
|
11
|
+
targetOrigin: string;
|
|
12
|
+
targetPath: string;
|
|
13
|
+
launchExpiresAt: string;
|
|
14
|
+
expiresAt: string;
|
|
15
|
+
runtimeUrl: string;
|
|
16
|
+
widgetVersion: string;
|
|
17
|
+
previewGrant: string;
|
|
18
|
+
developmentConsoleOrigin?: string;
|
|
19
|
+
onState?(state: AiGuideControllerState): void;
|
|
20
|
+
onError?(code: string): void;
|
|
21
|
+
};
|
|
22
|
+
export type MerchantPreviewBootstrapInput = {
|
|
23
|
+
schemaVersion: 1;
|
|
24
|
+
previewId: string;
|
|
25
|
+
previewGrant: string;
|
|
26
|
+
path: string;
|
|
27
|
+
requestedLocale?: string;
|
|
28
|
+
};
|
|
29
|
+
export type MerchantPreviewBootstrap = GuideBootstrapConfig & {
|
|
30
|
+
providerProtocol: 'live';
|
|
31
|
+
merchantPreview: {
|
|
32
|
+
previewId: string;
|
|
33
|
+
configurationVersionId: number;
|
|
34
|
+
targetOrigin: string;
|
|
35
|
+
targetPath: string;
|
|
36
|
+
expiresAt: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type MerchantPreviewLaunchIntent = Omit<LiveGuideLaunchIntent, 'guideMeasurement'> & {
|
|
40
|
+
previewId: string;
|
|
41
|
+
};
|
|
42
|
+
export type MerchantPreviewAdmissionResult = GuideAdmissionResult & {
|
|
43
|
+
providerProtocol: 'live';
|
|
44
|
+
previewId: string;
|
|
45
|
+
};
|
|
46
|
+
export type MerchantPreviewEndInput = GuideLaunchRecoveryInput & {
|
|
47
|
+
previewId: string;
|
|
48
|
+
action: 'end';
|
|
49
|
+
};
|
|
50
|
+
export type MerchantPreviewEndResult = {
|
|
51
|
+
schemaVersion: 3;
|
|
52
|
+
protocolVersion: 2;
|
|
53
|
+
providerProtocol: 'live';
|
|
54
|
+
status: 'end_requested';
|
|
55
|
+
launchRequestId: string;
|
|
56
|
+
previewId: string;
|
|
57
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/standalone.d.ts
CHANGED
|
@@ -4,3 +4,5 @@ export { createGuideRecordingNetworkCapture, observeGuideRecording, } from "./gu
|
|
|
4
4
|
export type { GuideRecordingObserver, GuideRecordingSource, GuideRecordingLink, } from "./guideRecording.js";
|
|
5
5
|
/** Install a Guide without importing, initializing or consulting a recorder. */
|
|
6
6
|
export declare function installAiGuide(options: StandaloneGuideOptions): Promise<AiGuideController | undefined>;
|
|
7
|
+
export { installMerchantGuidePreview } from './merchantPreview.js';
|
|
8
|
+
export type { MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
package/lib/standalone.js
CHANGED
package/lib/ui.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export type WidgetCallbacks = {
|
|
|
60
60
|
onOpenChange?: (open: boolean) => void;
|
|
61
61
|
};
|
|
62
62
|
export type WidgetViewOptions = {
|
|
63
|
+
contextNotice?: string;
|
|
63
64
|
persistentState?: boolean;
|
|
64
65
|
storageNamespace?: string;
|
|
65
66
|
initialPanelView?: "compact" | "expanded";
|
|
@@ -283,7 +284,9 @@ export declare class WidgetView {
|
|
|
283
284
|
setCommerceCartActionHandler(handler: CommerceAddHandler | null, canAdd?: CommerceCanAdd): void;
|
|
284
285
|
showCommerceCartConfirmation(value: CommerceCartConfirmationView, onDecision: (approved: boolean) => void): void;
|
|
285
286
|
clearCommerceCartConfirmation(operationId?: string): void;
|
|
286
|
-
setCommerceCartStatus(outcome: ShopifyCartOutcome, cartUrl: string, onCheck?: () => void | Promise<void
|
|
287
|
+
setCommerceCartStatus(outcome: ShopifyCartOutcome, cartUrl: string, onCheck?: () => void | Promise<void>, options?: {
|
|
288
|
+
readOnlyRecovery?: boolean;
|
|
289
|
+
}): void;
|
|
287
290
|
clearCommerceCartStatus(): void;
|
|
288
291
|
setAdvancedSessionControlsVisible(visible: boolean): void;
|
|
289
292
|
open(mode?: AssistMode): void;
|
package/lib/ui.js
CHANGED
|
@@ -4865,6 +4865,14 @@ export class WidgetView {
|
|
|
4865
4865
|
this.shadow.append(this.build());
|
|
4866
4866
|
document.documentElement.append(this.host);
|
|
4867
4867
|
this.panel = this.require(".panel");
|
|
4868
|
+
if (options.contextNotice) {
|
|
4869
|
+
const notice = document.createElement("p");
|
|
4870
|
+
notice.dataset.role = "context-notice";
|
|
4871
|
+
notice.textContent = options.contextNotice.slice(0, 240);
|
|
4872
|
+
notice.style.cssText = "margin:0;padding:4px 0;font-size:12px;line-height:1.4;color:var(--assist-muted)";
|
|
4873
|
+
this.require(".header .identity").append(notice);
|
|
4874
|
+
this.require('[data-role="intro-entry"]').prepend(notice.cloneNode(true));
|
|
4875
|
+
}
|
|
4868
4876
|
this.body = this.require(".body");
|
|
4869
4877
|
this.status = this.require('[data-role="status"]');
|
|
4870
4878
|
this.duration = this.require('[data-role="duration"]');
|
|
@@ -5770,9 +5778,10 @@ export class WidgetView {
|
|
|
5770
5778
|
if (current?.onDecision && (!operationId || current.actionId === operationId))
|
|
5771
5779
|
this.resolveConfirmation(false);
|
|
5772
5780
|
}
|
|
5773
|
-
setCommerceCartStatus(outcome, cartUrl, onCheck) {
|
|
5781
|
+
setCommerceCartStatus(outcome, cartUrl, onCheck, options = {}) {
|
|
5774
5782
|
this.clearCommerceCartStatus();
|
|
5775
|
-
|
|
5783
|
+
const available = () => !this.destroyed && (this.active || options.readOnlyRecovery === true);
|
|
5784
|
+
if (!available())
|
|
5776
5785
|
return;
|
|
5777
5786
|
if (this.semanticStatus === this.messages.commerceCartChecking && !this.currentConfirmation &&
|
|
5778
5787
|
!this.currentVisualRequest && !this.currentHandoffContextRequest && !this.currentPageAssistanceRequest) {
|
|
@@ -5804,7 +5813,7 @@ export class WidgetView {
|
|
|
5804
5813
|
check.type = "button";
|
|
5805
5814
|
check.textContent = this.messages.commerceCartRecheck;
|
|
5806
5815
|
check.addEventListener("click", async () => {
|
|
5807
|
-
if (check.disabled ||
|
|
5816
|
+
if (check.disabled || !available() || this.commerceCartStatus !== status)
|
|
5808
5817
|
return;
|
|
5809
5818
|
check.disabled = true;
|
|
5810
5819
|
check.setAttribute("aria-busy", "true");
|
|
@@ -5813,7 +5822,7 @@ export class WidgetView {
|
|
|
5813
5822
|
}
|
|
5814
5823
|
catch { /* Keep the uncertain result available for another read-only check. */ }
|
|
5815
5824
|
finally {
|
|
5816
|
-
if (this.commerceCartStatus === status && check.isConnected &&
|
|
5825
|
+
if (this.commerceCartStatus === status && check.isConnected && available()) {
|
|
5817
5826
|
check.disabled = false;
|
|
5818
5827
|
check.removeAttribute("aria-busy");
|
|
5819
5828
|
}
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "7.5.
|
|
1
|
+
export declare const VERSION = "7.5.28";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '7.5.
|
|
1
|
+
export const VERSION = '7.5.28';
|