@oxvo/ai-live-assist 7.5.25 → 7.5.27
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 +1 -1
- package/cjs/client.d.ts +7 -0
- package/cjs/client.js +12 -0
- package/cjs/commerce/cartSession.d.ts +6 -0
- package/cjs/commerce/cartSession.js +124 -21
- package/cjs/commerce/shopifyCart.d.ts +3 -1
- package/cjs/commerce/shopifyCart.js +24 -9
- 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 +20 -2
- package/cjs/liveGuideWidget.js +39 -8
- package/cjs/merchantPreview.d.ts +5 -0
- package/cjs/merchantPreview.js +148 -0
- package/cjs/merchantPreviewAdmission.d.ts +32 -0
- package/cjs/merchantPreviewAdmission.js +184 -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 +56 -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 +1 -0
- package/cjs/ui.js +8 -0
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/lib/AiLiveAssist.d.ts +1 -1
- package/lib/client.d.ts +7 -0
- package/lib/client.js +12 -0
- package/lib/commerce/cartSession.d.ts +6 -0
- package/lib/commerce/cartSession.js +124 -21
- package/lib/commerce/shopifyCart.d.ts +3 -1
- package/lib/commerce/shopifyCart.js +24 -9
- 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 +20 -2
- package/lib/liveGuideWidget.js +39 -8
- package/lib/merchantPreview.d.ts +5 -0
- package/lib/merchantPreview.js +144 -0
- package/lib/merchantPreviewAdmission.d.ts +32 -0
- package/lib/merchantPreviewAdmission.js +179 -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 +50 -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 +1 -0
- package/lib/ui.js +8 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { RuntimeClient, RuntimeClientError } from './client.js';
|
|
2
|
+
import { isLocalConsoleOrigin, isPreviewRuntimeOrigin } from './merchantPreviewOrigins.js';
|
|
3
|
+
import { validateGuideBootstrap } from './guideAdmission.js';
|
|
4
|
+
import { GUIDE_INSTALL_KEY_PATTERN, GUIDE_UUID_PATTERN } from './guideTypes.js';
|
|
5
|
+
import { mountedGuide, PendingGuideMount } from './guideMount.js';
|
|
6
|
+
import { LiveGuideWidget } from './liveGuideWidget.js';
|
|
7
|
+
import { MerchantPreviewAdmission, merchantPreviewNamespace } from './merchantPreviewAdmission.js';
|
|
8
|
+
import { readMerchantPreviewRecovery } from './merchantPreviewStorage.js';
|
|
9
|
+
import { TabActivityLock } from './tabLock.js';
|
|
10
|
+
import { VERSION } from './version.js';
|
|
11
|
+
const invalid = () => new RuntimeClientError('MERCHANT_PREVIEW_INVALID', 'This preview could not be opened. Open it again from OXVO.', false, null, 409);
|
|
12
|
+
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
13
|
+
const timestamp = (value) => typeof value === 'string' ? Date.parse(value) : NaN;
|
|
14
|
+
function captureOptions(input) {
|
|
15
|
+
if (!input || !GUIDE_UUID_PATTERN.test(input.previewId) || !GUIDE_UUID_PATTERN.test(input.guideId) ||
|
|
16
|
+
!positive(input.projectId) || !positive(input.configurationVersionId) || !positive(input.configurationRevision) ||
|
|
17
|
+
!/^[a-f0-9]{64}$/.test(input.configurationChecksum) || input.targetOrigin !== location.origin ||
|
|
18
|
+
input.targetPath !== location.pathname || !/^\/(?!\/)[^\x00-\x20\\?#]*$/.test(input.targetPath) || input.targetPath.length > 2048 ||
|
|
19
|
+
input.widgetVersion !== VERSION || typeof input.previewGrant !== 'string' ||
|
|
20
|
+
input.previewGrant.length > 4096 || !/^[\x21-\x7e]*$/.test(input.previewGrant) ||
|
|
21
|
+
!Number.isFinite(timestamp(input.launchExpiresAt)) ||
|
|
22
|
+
!Number.isFinite(timestamp(input.expiresAt)) || timestamp(input.expiresAt) < timestamp(input.launchExpiresAt))
|
|
23
|
+
throw invalid();
|
|
24
|
+
if (input.developmentConsoleOrigin !== undefined && !isLocalConsoleOrigin(input.developmentConsoleOrigin))
|
|
25
|
+
throw invalid();
|
|
26
|
+
const runtime = new URL(input.runtimeUrl);
|
|
27
|
+
if (runtime.username || runtime.password || runtime.search || runtime.hash || runtime.pathname !== '/' ||
|
|
28
|
+
!isPreviewRuntimeOrigin(runtime, input))
|
|
29
|
+
throw invalid();
|
|
30
|
+
return { previewId: input.previewId, projectId: input.projectId, guideId: input.guideId,
|
|
31
|
+
configurationVersionId: input.configurationVersionId, configurationRevision: input.configurationRevision,
|
|
32
|
+
configurationChecksum: input.configurationChecksum, targetOrigin: input.targetOrigin, targetPath: input.targetPath,
|
|
33
|
+
launchExpiresAt: input.launchExpiresAt, expiresAt: input.expiresAt, runtimeUrl: runtime.href,
|
|
34
|
+
widgetVersion: input.widgetVersion, previewGrant: input.previewGrant,
|
|
35
|
+
...(input.developmentConsoleOrigin ? { developmentConsoleOrigin: input.developmentConsoleOrigin } : {}),
|
|
36
|
+
...(typeof input.onState === 'function' ? { onState: input.onState } : {}),
|
|
37
|
+
...(typeof input.onError === 'function' ? { onError: input.onError } : {}) };
|
|
38
|
+
}
|
|
39
|
+
export function validateMerchantPreviewBootstrap(value, preview) {
|
|
40
|
+
const config = validateGuideBootstrap(value, value?.installKey);
|
|
41
|
+
const metadata = value?.merchantPreview;
|
|
42
|
+
if (!GUIDE_INSTALL_KEY_PATTERN.test(config.installKey) || config.projectId !== preview.projectId || config.guideId !== preview.guideId ||
|
|
43
|
+
config.configRevision !== preview.configurationRevision || config.configChecksum !== `sha256:${preview.configurationChecksum}` ||
|
|
44
|
+
value.providerProtocol !== 'live' || value.widgetVersion !== preview.widgetVersion || value.experienceMode !== 'standard' ||
|
|
45
|
+
value.capabilities?.guideMeasurementV1 === true || value.replayRecordingEnabled === true ||
|
|
46
|
+
!metadata || metadata.previewId !== preview.previewId || metadata.configurationVersionId !== preview.configurationVersionId ||
|
|
47
|
+
metadata.targetOrigin !== preview.targetOrigin || metadata.targetPath !== preview.targetPath ||
|
|
48
|
+
timestamp(metadata.expiresAt) !== timestamp(preview.expiresAt))
|
|
49
|
+
throw invalid();
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
export function installMerchantGuidePreview(input) {
|
|
53
|
+
try {
|
|
54
|
+
if (window.self !== window.top || window.location.origin === 'null')
|
|
55
|
+
throw invalid();
|
|
56
|
+
const preview = captureOptions(input);
|
|
57
|
+
const recovery = readMerchantPreviewRecovery(preview, sessionStorage);
|
|
58
|
+
if (!recovery && (!preview.previewGrant || timestamp(preview.launchExpiresAt) <= Date.now()))
|
|
59
|
+
throw invalid();
|
|
60
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
61
|
+
const mountIdentity = `merchant-preview:${namespace}`;
|
|
62
|
+
const current = mountedGuide(document, mountIdentity);
|
|
63
|
+
if (current)
|
|
64
|
+
return Promise.resolve(current);
|
|
65
|
+
const mount = new PendingGuideMount(document, mountIdentity);
|
|
66
|
+
void (async () => {
|
|
67
|
+
let lock;
|
|
68
|
+
let widget;
|
|
69
|
+
let admission;
|
|
70
|
+
const operation = new AbortController();
|
|
71
|
+
const timeout = window.setTimeout(() => operation.abort(), 15000);
|
|
72
|
+
try {
|
|
73
|
+
const runtime = new RuntimeClient(preview.runtimeUrl, VERSION);
|
|
74
|
+
const locale = (navigator.language || 'en').slice(0, 32);
|
|
75
|
+
const bootstrap = validateMerchantPreviewBootstrap(recovery ?? await runtime.bootstrapMerchantPreview({ schemaVersion: 1,
|
|
76
|
+
previewId: preview.previewId, previewGrant: preview.previewGrant, path: preview.targetPath, requestedLocale: locale }, operation.signal), preview);
|
|
77
|
+
if (operation.signal.aborted || location.origin !== preview.targetOrigin || location.pathname !== preview.targetPath)
|
|
78
|
+
throw invalid();
|
|
79
|
+
admission = new MerchantPreviewAdmission(preview, bootstrap, runtime, sessionStorage, recovery !== null);
|
|
80
|
+
const ownerId = `preview:${crypto.randomUUID()}`;
|
|
81
|
+
const tabKey = `__oxvo_ai_guide_preview_tab_${namespace}`;
|
|
82
|
+
let tabId = sessionStorage.getItem(tabKey);
|
|
83
|
+
if (!tabId || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(tabId)) {
|
|
84
|
+
tabId = `preview:${crypto.randomUUID()}`;
|
|
85
|
+
sessionStorage.setItem(tabKey, tabId);
|
|
86
|
+
if (sessionStorage.getItem(tabKey) !== tabId)
|
|
87
|
+
throw invalid();
|
|
88
|
+
}
|
|
89
|
+
const reportState = () => {
|
|
90
|
+
if (!widget)
|
|
91
|
+
return;
|
|
92
|
+
const state = widget.getState();
|
|
93
|
+
try {
|
|
94
|
+
preview.onState?.(state);
|
|
95
|
+
}
|
|
96
|
+
catch { /* A host observer cannot interrupt session cleanup. */ }
|
|
97
|
+
window.dispatchEvent(new CustomEvent('oxvo-ai-guide:state', { detail: state }));
|
|
98
|
+
};
|
|
99
|
+
lock = new TabActivityLock(namespace, ownerId, active => widget?.onTabActivityChange(active), undefined, undefined, {
|
|
100
|
+
onBeforePageHideRelease: () => { void widget?.end().catch(() => undefined); },
|
|
101
|
+
});
|
|
102
|
+
const activity = lock;
|
|
103
|
+
widget = new LiveGuideWidget({ bootstrap, sessionAdmission: admission, runtime, tabId, locale, messages: {},
|
|
104
|
+
previewRuntimePolicy: preview.developmentConsoleOrigin ? { developmentConsoleOrigin: preview.developmentConsoleOrigin } : {},
|
|
105
|
+
viewOptions: { storageNamespace: namespace, initialPanelView: 'expanded',
|
|
106
|
+
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.'
|
|
107
|
+
: `Saved draft · Revision ${preview.configurationRevision}. This preview uses OXVO Credits.` },
|
|
108
|
+
acquire: () => activity.acquire(), ownsActivity: () => activity.ownsActivity(), release: () => activity.release(), onState: reportState });
|
|
109
|
+
const live = widget;
|
|
110
|
+
const session = admission;
|
|
111
|
+
let destroyed = false;
|
|
112
|
+
const controller = {
|
|
113
|
+
version: VERSION,
|
|
114
|
+
open: value => live.open(value), close: () => live.close(), getState: () => live.getState(), end: () => live.end(),
|
|
115
|
+
destroy: () => {
|
|
116
|
+
if (destroyed)
|
|
117
|
+
return;
|
|
118
|
+
destroyed = true;
|
|
119
|
+
const ended = live.end();
|
|
120
|
+
live.destroy();
|
|
121
|
+
void ended.catch(() => undefined).finally(() => { session.destroy(); activity.destroy(); mount.release(); });
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
mount.promote(document, mountIdentity, controller);
|
|
125
|
+
mount.resolve(controller);
|
|
126
|
+
reportState();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
widget?.destroy();
|
|
130
|
+
admission?.destroy();
|
|
131
|
+
lock?.destroy();
|
|
132
|
+
mount.release();
|
|
133
|
+
mount.reject(error);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
window.clearTimeout(timeout);
|
|
137
|
+
}
|
|
138
|
+
})();
|
|
139
|
+
return mount.promise;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return Promise.reject(error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
readonly endMessage = "Preview ended. Return to Console to open another preview.";
|
|
13
|
+
private readonly store;
|
|
14
|
+
private readonly originalKey;
|
|
15
|
+
private admission;
|
|
16
|
+
private admitting;
|
|
17
|
+
private ending;
|
|
18
|
+
private grant;
|
|
19
|
+
constructor(preview: MerchantPreviewOptions, bootstrap: MerchantPreviewBootstrap, runtime: RuntimeClient, storage?: Storage, recoveryOnly?: boolean);
|
|
20
|
+
canStart(): boolean;
|
|
21
|
+
hasPendingLaunch(): boolean;
|
|
22
|
+
pendingLaunchId(): string | null;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
launch(input: LiveGuideStartIntent, signal: AbortSignal): Promise<LiveControlAuthorization>;
|
|
25
|
+
private reportError;
|
|
26
|
+
private start;
|
|
27
|
+
end(signal?: AbortSignal, expectedLaunchRequestId?: string): Promise<void>;
|
|
28
|
+
private finish;
|
|
29
|
+
private admit;
|
|
30
|
+
private original;
|
|
31
|
+
private writeOriginal;
|
|
32
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { RuntimeClientError } from './client.js';
|
|
2
|
+
import { GuideSubjectStore } from './guideSubjectStore.js';
|
|
3
|
+
import { GUIDE_SUBJECT_CREDENTIAL_PATTERN, GUIDE_UUID_PATTERN } from './guideTypes.js';
|
|
4
|
+
import { merchantPreviewNamespace, merchantPreviewStorageKeys, saveMerchantPreviewRecovery } from './merchantPreviewStorage.js';
|
|
5
|
+
export { merchantPreviewNamespace } from './merchantPreviewStorage.js';
|
|
6
|
+
const unavailable = () => new RuntimeClientError('MERCHANT_PREVIEW_UNAVAILABLE', 'This preview is no longer available. Open a new preview from OXVO.', false, null, 409);
|
|
7
|
+
export class MerchantPreviewAdmission {
|
|
8
|
+
constructor(preview, bootstrap, runtime, storage = sessionStorage, recoveryOnly = false) {
|
|
9
|
+
this.preview = preview;
|
|
10
|
+
this.bootstrap = bootstrap;
|
|
11
|
+
this.runtime = runtime;
|
|
12
|
+
this.storage = storage;
|
|
13
|
+
this.recoveryOnly = recoveryOnly;
|
|
14
|
+
this.endMessage = 'Preview ended. Return to Console to open another preview.';
|
|
15
|
+
this.admission = null;
|
|
16
|
+
this.admitting = null;
|
|
17
|
+
this.ending = null;
|
|
18
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
19
|
+
this.store = new GuideSubjectStore(bootstrap, preview.targetOrigin, namespace, storage);
|
|
20
|
+
this.originalKey = merchantPreviewStorageKeys(preview).original;
|
|
21
|
+
this.grant = recoveryOnly ? '' : preview.previewGrant;
|
|
22
|
+
}
|
|
23
|
+
canStart() { return !this.recoveryOnly && !this.original() && Date.now() < Date.parse(this.preview.launchExpiresAt); }
|
|
24
|
+
hasPendingLaunch() { const original = this.original(); return original !== null && !original.completed; }
|
|
25
|
+
pendingLaunchId() { const original = this.original(); return original && !original.completed ? original.intent.launchRequestId : null; }
|
|
26
|
+
destroy() { this.grant = ''; }
|
|
27
|
+
async launch(input, signal) {
|
|
28
|
+
try {
|
|
29
|
+
return await this.start(input, signal);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.reportError(error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
reportError(error) {
|
|
37
|
+
const code = error instanceof RuntimeClientError && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
|
|
38
|
+
? error.code : 'MERCHANT_PREVIEW_UNAVAILABLE';
|
|
39
|
+
try {
|
|
40
|
+
this.preview.onError?.(code);
|
|
41
|
+
}
|
|
42
|
+
catch { /* Feedback cannot interrupt original-session cleanup. */ }
|
|
43
|
+
}
|
|
44
|
+
async start(input, signal) {
|
|
45
|
+
if (signal.aborted || !this.canStart() || location.origin !== this.preview.targetOrigin ||
|
|
46
|
+
location.pathname !== this.preview.targetPath || input.path !== this.preview.targetPath ||
|
|
47
|
+
input.configRevision !== this.preview.configurationRevision)
|
|
48
|
+
throw unavailable();
|
|
49
|
+
const intent = {
|
|
50
|
+
schemaVersion: 3, protocolVersion: 2, installKey: this.bootstrap.installKey,
|
|
51
|
+
previewId: this.preview.previewId, launchRequestId: input.launchRequestId,
|
|
52
|
+
clientVersion: input.clientVersion, liveCapabilities: [...input.liveCapabilities],
|
|
53
|
+
configRevision: input.configRevision, path: input.path, tabId: input.tabId, mode: input.mode,
|
|
54
|
+
experienceMode: 'standard', consent: { ...input.consent, scopes: [...input.consent.scopes] },
|
|
55
|
+
capabilitySummary: { ...input.capabilitySummary },
|
|
56
|
+
};
|
|
57
|
+
saveMerchantPreviewRecovery(this.preview, this.bootstrap, this.storage);
|
|
58
|
+
this.writeOriginal({ v: 1, previewId: this.preview.previewId, intent, completed: false });
|
|
59
|
+
const admission = await this.admit(intent, signal);
|
|
60
|
+
if (signal.aborted || this.original()?.completed)
|
|
61
|
+
throw unavailable();
|
|
62
|
+
const result = await this.runtime.launchMerchantPreview(intent, admission.admissionGrant, signal);
|
|
63
|
+
if (result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
64
|
+
result.guideId !== this.preview.guideId || result.subjectId !== admission.subjectId ||
|
|
65
|
+
result.launchRequestId !== intent.launchRequestId)
|
|
66
|
+
throw unavailable();
|
|
67
|
+
// The existing control protocol validates its exact envelope, without preview metadata.
|
|
68
|
+
const authorization = { ...result };
|
|
69
|
+
delete authorization.previewId;
|
|
70
|
+
return authorization;
|
|
71
|
+
}
|
|
72
|
+
end(signal, expectedLaunchRequestId) {
|
|
73
|
+
if (this.ending)
|
|
74
|
+
return this.ending;
|
|
75
|
+
const original = this.original();
|
|
76
|
+
if (!original || original.completed || (expectedLaunchRequestId !== undefined &&
|
|
77
|
+
original.intent.launchRequestId !== expectedLaunchRequestId))
|
|
78
|
+
return Promise.resolve();
|
|
79
|
+
const operation = this.finish(original, signal).catch(error => { this.reportError(error); throw error; })
|
|
80
|
+
.finally(() => { if (this.ending === operation)
|
|
81
|
+
this.ending = null; });
|
|
82
|
+
this.ending = operation;
|
|
83
|
+
return operation;
|
|
84
|
+
}
|
|
85
|
+
async finish(original, signal) {
|
|
86
|
+
if (this.admitting)
|
|
87
|
+
await this.admitting.catch(() => undefined);
|
|
88
|
+
let subject = this.store.readSubject();
|
|
89
|
+
if (!subject) {
|
|
90
|
+
// An ambiguous admission can be recovered only with its original intent and in-memory grant.
|
|
91
|
+
if (!this.grant)
|
|
92
|
+
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);
|
|
93
|
+
await this.admit(original.intent, signal);
|
|
94
|
+
subject = this.store.readSubject();
|
|
95
|
+
}
|
|
96
|
+
if (!subject || this.original()?.intent.launchRequestId !== original.intent.launchRequestId)
|
|
97
|
+
throw unavailable();
|
|
98
|
+
const result = await this.runtime.endMerchantPreview({ schemaVersion: 3, previewId: this.preview.previewId,
|
|
99
|
+
installKey: this.bootstrap.installKey, subjectCredential: subject.credential,
|
|
100
|
+
launchRequestId: original.intent.launchRequestId, tabId: original.intent.tabId, action: 'end' }, signal);
|
|
101
|
+
if (!result || Object.keys(result).length !== 6 || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
102
|
+
result.providerProtocol !== 'live' || result.status !== 'end_requested' || result.previewId !== this.preview.previewId ||
|
|
103
|
+
result.launchRequestId !== original.intent.launchRequestId)
|
|
104
|
+
throw unavailable();
|
|
105
|
+
this.writeOriginal({ ...original, completed: true });
|
|
106
|
+
this.store.clearLaunch(original.intent.launchRequestId);
|
|
107
|
+
this.admission = null;
|
|
108
|
+
this.grant = '';
|
|
109
|
+
}
|
|
110
|
+
async admit(intent, signal) {
|
|
111
|
+
if (this.admission)
|
|
112
|
+
return this.admission;
|
|
113
|
+
if (this.admitting)
|
|
114
|
+
return this.admitting;
|
|
115
|
+
if (!this.grant)
|
|
116
|
+
throw unavailable();
|
|
117
|
+
const subject = this.store.readSubject();
|
|
118
|
+
const operation = this.runtime.admitMerchantPreview(intent, this.grant, subject?.credential, signal).then(result => {
|
|
119
|
+
const required = ['schemaVersion', 'protocolVersion', 'providerProtocol', 'previewId', 'projectId', 'guideId', 'subjectId',
|
|
120
|
+
'subjectAuthorityRevision', 'tabId', 'launchRequestId', 'configRevision', 'configChecksum', 'admissionGrant',
|
|
121
|
+
'expiresAt', 'subjectCredentialExpiresAt'];
|
|
122
|
+
if (!result || Object.keys(result).some(key => ![...required, 'subjectCredential'].includes(key)) ||
|
|
123
|
+
required.some(key => !(key in result)) || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
124
|
+
result.providerProtocol !== 'live' || result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
125
|
+
result.guideId !== this.preview.guideId || !GUIDE_UUID_PATTERN.test(result.subjectId) ||
|
|
126
|
+
result.tabId !== intent.tabId || result.launchRequestId !== intent.launchRequestId ||
|
|
127
|
+
result.configRevision !== this.preview.configurationRevision || result.configChecksum !== this.bootstrap.configChecksum ||
|
|
128
|
+
!Number.isSafeInteger(result.subjectAuthorityRevision) || result.subjectAuthorityRevision < 0 ||
|
|
129
|
+
typeof result.admissionGrant !== 'string' || result.admissionGrant.length < 1 || result.admissionGrant.length > 4096 ||
|
|
130
|
+
!Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now() ||
|
|
131
|
+
!Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) || Date.parse(result.subjectCredentialExpiresAt) <= Date.now() ||
|
|
132
|
+
(subject && (result.subjectId !== subject.subjectId || result.subjectAuthorityRevision !== subject.subjectAuthorityRevision)))
|
|
133
|
+
throw unavailable();
|
|
134
|
+
const credential = subject?.credential ?? result.subjectCredential;
|
|
135
|
+
if (!credential || !GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(credential))
|
|
136
|
+
throw unavailable();
|
|
137
|
+
this.store.saveSubject({ v: 1, origin: this.preview.targetOrigin, projectId: this.preview.projectId, guideId: this.preview.guideId,
|
|
138
|
+
subjectId: result.subjectId, subjectAuthorityRevision: result.subjectAuthorityRevision, credential, expiresAt: result.subjectCredentialExpiresAt });
|
|
139
|
+
this.store.saveLaunch({ v: 1, subjectId: result.subjectId, intent, recordingConsent: false });
|
|
140
|
+
this.admission = result;
|
|
141
|
+
return result;
|
|
142
|
+
}).finally(() => { if (this.admitting === operation)
|
|
143
|
+
this.admitting = null; });
|
|
144
|
+
this.admitting = operation;
|
|
145
|
+
return operation;
|
|
146
|
+
}
|
|
147
|
+
original() {
|
|
148
|
+
const raw = this.storage.getItem(this.originalKey);
|
|
149
|
+
if (raw === null)
|
|
150
|
+
return null;
|
|
151
|
+
if (raw.length > 16384)
|
|
152
|
+
throw unavailable();
|
|
153
|
+
let value;
|
|
154
|
+
try {
|
|
155
|
+
value = JSON.parse(raw);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
throw unavailable();
|
|
159
|
+
}
|
|
160
|
+
const intent = value?.intent;
|
|
161
|
+
if (value?.v !== 1 || value.previewId !== this.preview.previewId || typeof value.completed !== 'boolean' ||
|
|
162
|
+
!intent || intent.schemaVersion !== 3 || intent.protocolVersion !== 2 || intent.previewId !== this.preview.previewId ||
|
|
163
|
+
intent.installKey !== this.bootstrap.installKey || intent.configRevision !== this.preview.configurationRevision ||
|
|
164
|
+
intent.path !== this.preview.targetPath || !GUIDE_UUID_PATTERN.test(intent.launchRequestId) ||
|
|
165
|
+
typeof intent.tabId !== 'string' || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(intent.tabId) ||
|
|
166
|
+
!['text', 'voice'].includes(intent.mode) || intent.experienceMode !== 'standard' ||
|
|
167
|
+
'guideMeasurement' in intent || 'previewGrant' in intent || 'admissionGrant' in intent)
|
|
168
|
+
throw unavailable();
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
writeOriginal(value) {
|
|
172
|
+
const raw = JSON.stringify(value);
|
|
173
|
+
if (raw.length > 16384)
|
|
174
|
+
throw unavailable();
|
|
175
|
+
this.storage.setItem(this.originalKey, raw);
|
|
176
|
+
if (this.storage.getItem(this.originalKey) !== raw)
|
|
177
|
+
throw unavailable();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -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,50 @@
|
|
|
1
|
+
import { GUIDE_UUID_PATTERN } from './guideTypes.js';
|
|
2
|
+
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.');
|
|
3
|
+
const PREVIEW_FIELDS = ['previewId', 'projectId', 'guideId', 'configurationVersionId', 'configurationRevision',
|
|
4
|
+
'configurationChecksum', 'targetOrigin', 'targetPath', 'launchExpiresAt', 'expiresAt', 'runtimeUrl', 'widgetVersion'];
|
|
5
|
+
const BOOTSTRAP_FIELDS = ['schemaVersion', 'projectId', 'guideId', 'installKey', 'protocol', 'available', 'configRevision',
|
|
6
|
+
'configChecksum', 'providerProtocol', 'providerModel', 'liveCapabilities', 'liveAssets', 'widgetVersion',
|
|
7
|
+
'experienceMode', 'replayRecordingEnabled', 'capabilities', 'consent', 'cache', 'merchantPreview'];
|
|
8
|
+
const APPEARANCE_FIELDS = ['brandName', 'launcherLabel', 'accent', 'position', 'panelWidth', 'glassEffect',
|
|
9
|
+
'hideLauncherWhenVisitorLimited', 'theme', 'welcomeMessage', 'compactEntryEnabled'];
|
|
10
|
+
export function merchantPreviewNamespace(origin, previewId) {
|
|
11
|
+
if (new URL(origin).origin !== origin || !GUIDE_UUID_PATTERN.test(previewId))
|
|
12
|
+
throw invalid();
|
|
13
|
+
return `merchant_preview_v1_${encodeURIComponent(origin)}_${previewId}`;
|
|
14
|
+
}
|
|
15
|
+
export function merchantPreviewStorageKeys(preview) {
|
|
16
|
+
const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
|
|
17
|
+
return { namespace, original: `__oxvo_ai_guide_preview_launch_${namespace}`, recovery: `__oxvo_ai_guide_preview_recovery_${namespace}` };
|
|
18
|
+
}
|
|
19
|
+
const pick = (value, fields) => Object.fromEntries(fields.filter(key => key in value)
|
|
20
|
+
.map(key => [key, value[key]]));
|
|
21
|
+
export function saveMerchantPreviewRecovery(preview, bootstrap, storage) {
|
|
22
|
+
const presentation = { ...pick(bootstrap, BOOTSTRAP_FIELDS),
|
|
23
|
+
...(bootstrap.appearance ? { appearance: pick(bootstrap.appearance, APPEARANCE_FIELDS) } : {}) };
|
|
24
|
+
const raw = JSON.stringify({ v: 1, preview: pick(preview, PREVIEW_FIELDS), bootstrap: presentation });
|
|
25
|
+
if (raw.length > 65536 || /"(?:previewGrant|admissionGrant|controlCredential|subjectCredential)"\s*:/.test(raw))
|
|
26
|
+
throw invalid();
|
|
27
|
+
const key = merchantPreviewStorageKeys(preview).recovery;
|
|
28
|
+
storage.setItem(key, raw);
|
|
29
|
+
if (storage.getItem(key) !== raw)
|
|
30
|
+
throw invalid();
|
|
31
|
+
}
|
|
32
|
+
export function readMerchantPreviewRecovery(preview, storage) {
|
|
33
|
+
const keys = merchantPreviewStorageKeys(preview);
|
|
34
|
+
if (storage.getItem(keys.original) === null)
|
|
35
|
+
return null;
|
|
36
|
+
const raw = storage.getItem(keys.recovery);
|
|
37
|
+
if (!raw || raw.length > 65536)
|
|
38
|
+
throw invalid();
|
|
39
|
+
let value;
|
|
40
|
+
try {
|
|
41
|
+
value = JSON.parse(raw);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
throw invalid();
|
|
45
|
+
}
|
|
46
|
+
if (value?.v !== 1 || !value.preview || !value.bootstrap ||
|
|
47
|
+
JSON.stringify(value.preview) !== JSON.stringify(pick(preview, PREVIEW_FIELDS)))
|
|
48
|
+
throw invalid();
|
|
49
|
+
return value.bootstrap;
|
|
50
|
+
}
|
|
@@ -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
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"]');
|
package/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "7.5.
|
|
1
|
+
export declare const VERSION = "7.5.27";
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '7.5.
|
|
1
|
+
export const VERSION = '7.5.27';
|