@oxvo/ai-live-assist 7.5.26 → 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/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/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
package/cjs/AiLiveAssist.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const normalizeAiGuideOpenInput: (input?: AiGuideOpenInput) => Re
|
|
|
34
34
|
export declare const resolveAiGuideProtocolVersion: (bootstrap: Pick<BootstrapConfig, "experienceMode" | "minimumProtocolVersion" | "protocol">) => 1 | 2;
|
|
35
35
|
export default class AiLiveAssist {
|
|
36
36
|
private readonly options;
|
|
37
|
-
readonly version = "7.5.
|
|
37
|
+
readonly version = "7.5.27";
|
|
38
38
|
private readonly host;
|
|
39
39
|
private readonly guideAdmission;
|
|
40
40
|
private readonly standaloneAdmissionPending;
|
package/cjs/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AssistMode, AiGuideCompanionState, BootstrapConfig, ConsentScope,
|
|
|
2
2
|
import { type GuideAdmissionResult, type GuideLaunchIntent, type GuideLaunchRecoveryInput, type GuideLaunchRecoveryResult, type GuideLaunchResult, type GuideRecordingLinkInput, type GuideRecordingLinkResult, type GuideMeasurementBridge } from "./guideTypes.js";
|
|
3
3
|
import type { LiveControlAuthorization } from "./liveControlChannel.js";
|
|
4
4
|
import type { LiveGuideLaunchIntent } from "./liveGuideAdmission.js";
|
|
5
|
+
import type { MerchantPreviewBootstrapInput, MerchantPreviewBootstrap, MerchantPreviewLaunchIntent, MerchantPreviewAdmissionResult, MerchantPreviewEndInput, MerchantPreviewEndResult } from './merchantPreviewTypes.js';
|
|
5
6
|
export declare class RuntimeClientError extends Error {
|
|
6
7
|
readonly code: string;
|
|
7
8
|
readonly retryable: boolean;
|
|
@@ -104,6 +105,12 @@ export declare class RuntimeClient {
|
|
|
104
105
|
status: "end_requested";
|
|
105
106
|
launchRequestId: string;
|
|
106
107
|
}>;
|
|
108
|
+
bootstrapMerchantPreview(input: MerchantPreviewBootstrapInput, signal: AbortSignal): Promise<MerchantPreviewBootstrap>;
|
|
109
|
+
admitMerchantPreview(intent: MerchantPreviewLaunchIntent, previewGrant: string, subjectCredential: string | undefined, signal?: AbortSignal): Promise<MerchantPreviewAdmissionResult>;
|
|
110
|
+
launchMerchantPreview(intent: MerchantPreviewLaunchIntent, admissionGrant: string, signal: AbortSignal): Promise<LiveControlAuthorization & {
|
|
111
|
+
previewId: string;
|
|
112
|
+
}>;
|
|
113
|
+
endMerchantPreview(input: MerchantPreviewEndInput, signal?: AbortSignal): Promise<MerchantPreviewEndResult>;
|
|
107
114
|
launchGuide(intent: GuideLaunchIntent, admissionGrant: string, signal: AbortSignal, measurementBridge?: GuideMeasurementBridge): Promise<GuideLaunchResult>;
|
|
108
115
|
recoverGuideLaunch(input: GuideLaunchRecoveryInput, signal?: AbortSignal, keepalive?: boolean): Promise<GuideLaunchRecoveryResult>;
|
|
109
116
|
linkGuideRecording(sessionId: string, input: GuideRecordingLinkInput, signal: AbortSignal): Promise<GuideRecordingLinkResult>;
|
package/cjs/client.js
CHANGED
|
@@ -196,6 +196,18 @@ class RuntimeClient {
|
|
|
196
196
|
async endLiveGuide(input, signal) {
|
|
197
197
|
return this.postJson("/ai-live-assist/v1/public/live/launches/end", input, {}, signal, true);
|
|
198
198
|
}
|
|
199
|
+
async bootstrapMerchantPreview(input, signal) {
|
|
200
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/bootstrap', JSON.stringify(input), {}, signal, false, false, true);
|
|
201
|
+
}
|
|
202
|
+
async admitMerchantPreview(intent, previewGrant, subjectCredential, signal) {
|
|
203
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/admissions', JSON.stringify({ ...intent, previewGrant, ...(subjectCredential ? { subjectCredential } : {}) }), {}, signal, false, false, true);
|
|
204
|
+
}
|
|
205
|
+
async launchMerchantPreview(intent, admissionGrant, signal) {
|
|
206
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launch', JSON.stringify({ ...intent, admissionGrant }), { 'Idempotency-Key': intent.launchRequestId }, signal, false, false, true);
|
|
207
|
+
}
|
|
208
|
+
async endMerchantPreview(input, signal) {
|
|
209
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launches/end', JSON.stringify(input), {}, signal, true, false, true);
|
|
210
|
+
}
|
|
199
211
|
async launchGuide(intent, admissionGrant, signal, measurementBridge) {
|
|
200
212
|
return this.postGuideLaunch("/ai-live-assist/v1/public/launch", intent, admissionGrant, signal, measurementBridge);
|
|
201
213
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
|
|
2
|
-
export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.
|
|
2
|
+
export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.27";
|
|
3
3
|
export declare function isGuideMeasurementIntent(value: unknown): value is GuideMeasurementIntent;
|
|
4
4
|
/** The managed analytics owner supplies possession; this check grants no authority. */
|
|
5
5
|
export declare function currentGuideMeasurementBridge(value: unknown): value is GuideMeasurementBridge;
|
package/cjs/guideMeasurement.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.GUIDE_MEASUREMENT_CLIENT_VERSION = void 0;
|
|
|
4
4
|
exports.isGuideMeasurementIntent = isGuideMeasurementIntent;
|
|
5
5
|
exports.currentGuideMeasurementBridge = currentGuideMeasurementBridge;
|
|
6
6
|
exports.prepareGuideMeasurementBridge = prepareGuideMeasurementBridge;
|
|
7
|
-
exports.GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.
|
|
7
|
+
exports.GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.27';
|
|
8
8
|
function isGuideMeasurementIntent(value) {
|
|
9
9
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
10
|
return false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type MerchantPreviewRuntimePolicy } from './merchantPreviewOrigins.js';
|
|
1
2
|
import { type LiveDuplexMediaOptions, type LiveDuplexMediaDependencies } from './liveDuplexMedia.js';
|
|
2
3
|
import { type CommerceBootstrap, type CommerceContext, type CommerceCartSelection, type CommerceProduct, type CommerceContextClear, type LiveCommerceCatalog, type LiveCommerceDisplayed } from './commerce/contracts.js';
|
|
3
|
-
export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.
|
|
4
|
+
export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.27";
|
|
4
5
|
export declare const LIVE_CONTROL_CLIENT_CAPABILITIES: readonly ["live_duplex_v1", "live_local_wake_v1", "live_fragment_captions_v1"];
|
|
5
6
|
declare const phases: readonly ["voice_off", "local_listening", "wake_buffering", "starting", "active", "tentative_idle", "closing", "uncertain", "muted", "suspended", "budget_blocked", "ended"];
|
|
6
7
|
export type LiveControlState = {
|
|
@@ -41,6 +42,7 @@ export interface LiveControlChannelOptions {
|
|
|
41
42
|
tabId: string;
|
|
42
43
|
media: MediaOptions;
|
|
43
44
|
clock?: LiveControlClock;
|
|
45
|
+
previewRuntimePolicy?: MerchantPreviewRuntimePolicy;
|
|
44
46
|
createWebSocket?: (url: string, protocols: string[]) => WebSocket;
|
|
45
47
|
randomUUID?: () => string;
|
|
46
48
|
onState(state: LiveControlState): void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveControlChannel = exports.LIVE_CONTROL_CLIENT_CAPABILITIES = exports.LIVE_CONTROL_CLIENT_VERSION = void 0;
|
|
4
|
+
const merchantPreviewOrigins_js_1 = require("./merchantPreviewOrigins.js");
|
|
4
5
|
const liveDuplexMedia_js_1 = require("./liveDuplexMedia.js");
|
|
5
6
|
const version_js_1 = require("./version.js");
|
|
6
7
|
const contracts_js_1 = require("./commerce/contracts.js");
|
|
@@ -94,7 +95,9 @@ class LiveControlChannel {
|
|
|
94
95
|
if (!['https:', 'http:'].includes(trusted.protocol) || trusted.origin !== options.trustedRuntimeOrigin ||
|
|
95
96
|
trusted.username || trusted.password || target.username || target.password || target.search || target.hash || target.pathname !== path ||
|
|
96
97
|
target.protocol !== (trusted.protocol === 'https:' ? 'wss:' : 'ws:') || target.host !== trusted.host ||
|
|
97
|
-
(trusted.protocol === 'http:' && !
|
|
98
|
+
(trusted.protocol === 'http:' && !(options.previewRuntimePolicy
|
|
99
|
+
? (0, merchantPreviewOrigins_js_1.isPreviewRuntimeOrigin)(trusted, options.previewRuntimePolicy)
|
|
100
|
+
: ['localhost', '127.0.0.1', '[::1]'].includes(trusted.hostname))))
|
|
98
101
|
throw unavailable();
|
|
99
102
|
target.searchParams.set('session', String(value.sessionId));
|
|
100
103
|
this.url = target.href;
|
package/cjs/liveGuideWidget.d.ts
CHANGED
|
@@ -2,19 +2,37 @@ import { WidgetView, type WidgetViewOptions } from './ui.js';
|
|
|
2
2
|
import type { AiGuideControllerState, AiGuideOpenInput, BootstrapConfig, PluginOptions } from './types.js';
|
|
3
3
|
import type { GuideAdmission } from './guideAdmission.js';
|
|
4
4
|
import { RuntimeClient } from './client.js';
|
|
5
|
+
import { type LiveGuideLaunchIntent } from './liveGuideAdmission.js';
|
|
6
|
+
import { type LiveControlChannelOptions, type LiveControlAuthorization } from './liveControlChannel.js';
|
|
7
|
+
export type LiveGuideStartIntent = Omit<LiveGuideLaunchIntent, 'installKey' | 'guideMeasurement'>;
|
|
8
|
+
export type LiveGuideSessionAdmission = {
|
|
9
|
+
readonly recoveryOnly?: boolean;
|
|
10
|
+
readonly endMessage?: string;
|
|
11
|
+
canStart?(): boolean;
|
|
12
|
+
hasPendingLaunch(): boolean;
|
|
13
|
+
pendingLaunchId(): string | null;
|
|
14
|
+
launch(intent: LiveGuideStartIntent, signal: AbortSignal): Promise<LiveControlAuthorization>;
|
|
15
|
+
end(signal?: AbortSignal, expectedLaunchRequestId?: string): Promise<void>;
|
|
16
|
+
};
|
|
5
17
|
type Options = {
|
|
6
18
|
bootstrap: BootstrapConfig;
|
|
7
|
-
admission: GuideAdmission;
|
|
8
19
|
runtime: RuntimeClient;
|
|
9
20
|
tabId: string;
|
|
10
21
|
locale: string;
|
|
22
|
+
previewRuntimePolicy?: LiveControlChannelOptions['previewRuntimePolicy'];
|
|
11
23
|
messages: PluginOptions['messages'];
|
|
12
24
|
viewOptions: WidgetViewOptions;
|
|
13
25
|
acquire(): boolean;
|
|
14
26
|
ownsActivity?(): boolean;
|
|
15
27
|
release(): void;
|
|
16
28
|
onState(): void;
|
|
17
|
-
}
|
|
29
|
+
} & ({
|
|
30
|
+
admission: GuideAdmission;
|
|
31
|
+
sessionAdmission?: never;
|
|
32
|
+
} | {
|
|
33
|
+
sessionAdmission: LiveGuideSessionAdmission;
|
|
34
|
+
admission?: never;
|
|
35
|
+
});
|
|
18
36
|
/** Actual widget protocol branch. Reuses WidgetView, visitor possession storage,
|
|
19
37
|
* local detector/media and authenticated runtime; never constructs a Realtime
|
|
20
38
|
* transport or grants model/provider authority on the browser's behalf. */
|
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,21 @@ 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
|
+
hasPendingLaunch: () => live.hasPendingLaunch(),
|
|
73
|
+
pendingLaunchId: () => live.pendingLaunchId(),
|
|
74
|
+
launch: (intent, signal) => live.launch({ ...intent, installKey: publicAdmission.identity.installKey }, signal),
|
|
75
|
+
end: (signal, expectedLaunchRequestId) => live.end(signal, expectedLaunchRequestId),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
66
78
|
const callbacks = {
|
|
67
79
|
onStart: (mode, scopes, question) => this.start(mode, scopes, question),
|
|
68
|
-
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch(),
|
|
80
|
+
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch() && this.admission.canStart?.() !== false,
|
|
69
81
|
onEnd: () => { void this.end().catch(() => undefined); },
|
|
70
82
|
onMute: muted => { if (muted)
|
|
71
83
|
this.privacy('mute');
|
|
@@ -128,6 +140,10 @@ class LiveGuideWidget {
|
|
|
128
140
|
void this.end().catch(() => undefined);
|
|
129
141
|
}
|
|
130
142
|
}
|
|
143
|
+
else if (this.admission.recoveryOnly) {
|
|
144
|
+
this.phase = 'ended';
|
|
145
|
+
this.view.showLaunchUnavailable(this.admission.endMessage ?? this.view.message('ended'));
|
|
146
|
+
}
|
|
131
147
|
// Capture runs before TabActivityLock releases cross-tab ownership.
|
|
132
148
|
window.addEventListener('pagehide', this.pagehide, true);
|
|
133
149
|
window.addEventListener('focus', this.refreshOwnership);
|
|
@@ -160,7 +176,7 @@ class LiveGuideWidget {
|
|
|
160
176
|
companion: false, pendingQuestion: this.pendingQuestions.length > 0 };
|
|
161
177
|
}
|
|
162
178
|
start(mode, scopes, question) {
|
|
163
|
-
if (this.destroyed || this.starting || this.active || this.ending ||
|
|
179
|
+
if (this.destroyed || this.starting || this.active || this.ending || this.admission.canStart?.() === false ||
|
|
164
180
|
(question && (!question.trim() || question.length > 4000)) || !this.acquireLock())
|
|
165
181
|
return false;
|
|
166
182
|
// Recover abandoned intent only after acquiring the actual activity lock;
|
|
@@ -178,7 +194,7 @@ class LiveGuideWidget {
|
|
|
178
194
|
this.operation = operation;
|
|
179
195
|
const timeout = setTimeout(() => operation.abort(), 20000);
|
|
180
196
|
const config = this.options.bootstrap;
|
|
181
|
-
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
197
|
+
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
182
198
|
launchRequestId: crypto.randomUUID(), clientVersion: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_VERSION, liveCapabilities: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_CAPABILITIES,
|
|
183
199
|
configRevision: config.configRevision, path: location.pathname, tabId: this.options.tabId, mode, experienceMode: 'standard',
|
|
184
200
|
consent: { disclosureChecksum: config.consent.disclosureChecksum, scopes: [...scopes], locale: this.options.locale },
|
|
@@ -198,6 +214,7 @@ class LiveGuideWidget {
|
|
|
198
214
|
throw new Error('Cancelled.');
|
|
199
215
|
const audio = this.view.livePlaybackElement();
|
|
200
216
|
const channel = new liveControlChannel_js_1.LiveControlChannel({ authorization, trustedRuntimeOrigin: new URL(this.options.runtime.baseUrl).origin,
|
|
217
|
+
...(this.options.previewRuntimePolicy ? { previewRuntimePolicy: this.options.previewRuntimePolicy } : {}),
|
|
201
218
|
tabId: this.options.tabId, onState: state => this.onControlState(state),
|
|
202
219
|
onClose: reason => {
|
|
203
220
|
if (this.channel === channel && !this.ending && !this.destroyed) {
|
|
@@ -580,11 +597,25 @@ class LiveGuideWidget {
|
|
|
580
597
|
this.ownedLaunchId = null;
|
|
581
598
|
this.phase = 'ended';
|
|
582
599
|
this.releaseLock();
|
|
583
|
-
if (!this.destroyed)
|
|
584
|
-
this.
|
|
600
|
+
if (!this.destroyed) {
|
|
601
|
+
if (this.admission.endMessage)
|
|
602
|
+
this.view.showLaunchUnavailable(this.admission.endMessage);
|
|
603
|
+
else
|
|
604
|
+
this.view.showResumeStopped();
|
|
605
|
+
}
|
|
606
|
+
this.options.onState();
|
|
607
|
+
}).catch(error => {
|
|
608
|
+
this.phase = 'error';
|
|
609
|
+
if (!this.destroyed) {
|
|
610
|
+
if (this.admission.recoveryOnly && error instanceof client_js_1.RuntimeClientError && error.code === 'MERCHANT_PREVIEW_END_UNRESOLVED') {
|
|
611
|
+
this.view.showLaunchUnavailable(error.message);
|
|
612
|
+
}
|
|
613
|
+
else
|
|
614
|
+
this.view.showError(this.view.message('error'), true);
|
|
615
|
+
}
|
|
585
616
|
this.options.onState();
|
|
586
|
-
|
|
587
|
-
|
|
617
|
+
throw error;
|
|
618
|
+
})
|
|
588
619
|
.finally(() => { if (this.ending === pending)
|
|
589
620
|
this.ending = null; });
|
|
590
621
|
this.ending = pending;
|
|
@@ -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,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,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MerchantPreviewAdmission = exports.merchantPreviewNamespace = void 0;
|
|
4
|
+
const client_js_1 = require("./client.js");
|
|
5
|
+
const guideSubjectStore_js_1 = require("./guideSubjectStore.js");
|
|
6
|
+
const guideTypes_js_1 = require("./guideTypes.js");
|
|
7
|
+
const merchantPreviewStorage_js_1 = require("./merchantPreviewStorage.js");
|
|
8
|
+
var merchantPreviewStorage_js_2 = require("./merchantPreviewStorage.js");
|
|
9
|
+
Object.defineProperty(exports, "merchantPreviewNamespace", { enumerable: true, get: function () { return merchantPreviewStorage_js_2.merchantPreviewNamespace; } });
|
|
10
|
+
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);
|
|
11
|
+
class MerchantPreviewAdmission {
|
|
12
|
+
constructor(preview, bootstrap, runtime, storage = sessionStorage, recoveryOnly = false) {
|
|
13
|
+
this.preview = preview;
|
|
14
|
+
this.bootstrap = bootstrap;
|
|
15
|
+
this.runtime = runtime;
|
|
16
|
+
this.storage = storage;
|
|
17
|
+
this.recoveryOnly = recoveryOnly;
|
|
18
|
+
this.endMessage = 'Preview ended. Return to Console to open another preview.';
|
|
19
|
+
this.admission = null;
|
|
20
|
+
this.admitting = null;
|
|
21
|
+
this.ending = null;
|
|
22
|
+
const namespace = (0, merchantPreviewStorage_js_1.merchantPreviewNamespace)(preview.targetOrigin, preview.previewId);
|
|
23
|
+
this.store = new guideSubjectStore_js_1.GuideSubjectStore(bootstrap, preview.targetOrigin, namespace, storage);
|
|
24
|
+
this.originalKey = (0, merchantPreviewStorage_js_1.merchantPreviewStorageKeys)(preview).original;
|
|
25
|
+
this.grant = recoveryOnly ? '' : preview.previewGrant;
|
|
26
|
+
}
|
|
27
|
+
canStart() { return !this.recoveryOnly && !this.original() && Date.now() < Date.parse(this.preview.launchExpiresAt); }
|
|
28
|
+
hasPendingLaunch() { const original = this.original(); return original !== null && !original.completed; }
|
|
29
|
+
pendingLaunchId() { const original = this.original(); return original && !original.completed ? original.intent.launchRequestId : null; }
|
|
30
|
+
destroy() { this.grant = ''; }
|
|
31
|
+
async launch(input, signal) {
|
|
32
|
+
try {
|
|
33
|
+
return await this.start(input, signal);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
this.reportError(error);
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
reportError(error) {
|
|
41
|
+
const code = error instanceof client_js_1.RuntimeClientError && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
|
|
42
|
+
? error.code : 'MERCHANT_PREVIEW_UNAVAILABLE';
|
|
43
|
+
try {
|
|
44
|
+
this.preview.onError?.(code);
|
|
45
|
+
}
|
|
46
|
+
catch { /* Feedback cannot interrupt original-session cleanup. */ }
|
|
47
|
+
}
|
|
48
|
+
async start(input, signal) {
|
|
49
|
+
if (signal.aborted || !this.canStart() || location.origin !== this.preview.targetOrigin ||
|
|
50
|
+
location.pathname !== this.preview.targetPath || input.path !== this.preview.targetPath ||
|
|
51
|
+
input.configRevision !== this.preview.configurationRevision)
|
|
52
|
+
throw unavailable();
|
|
53
|
+
const intent = {
|
|
54
|
+
schemaVersion: 3, protocolVersion: 2, installKey: this.bootstrap.installKey,
|
|
55
|
+
previewId: this.preview.previewId, launchRequestId: input.launchRequestId,
|
|
56
|
+
clientVersion: input.clientVersion, liveCapabilities: [...input.liveCapabilities],
|
|
57
|
+
configRevision: input.configRevision, path: input.path, tabId: input.tabId, mode: input.mode,
|
|
58
|
+
experienceMode: 'standard', consent: { ...input.consent, scopes: [...input.consent.scopes] },
|
|
59
|
+
capabilitySummary: { ...input.capabilitySummary },
|
|
60
|
+
};
|
|
61
|
+
(0, merchantPreviewStorage_js_1.saveMerchantPreviewRecovery)(this.preview, this.bootstrap, this.storage);
|
|
62
|
+
this.writeOriginal({ v: 1, previewId: this.preview.previewId, intent, completed: false });
|
|
63
|
+
const admission = await this.admit(intent, signal);
|
|
64
|
+
if (signal.aborted || this.original()?.completed)
|
|
65
|
+
throw unavailable();
|
|
66
|
+
const result = await this.runtime.launchMerchantPreview(intent, admission.admissionGrant, signal);
|
|
67
|
+
if (result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
68
|
+
result.guideId !== this.preview.guideId || result.subjectId !== admission.subjectId ||
|
|
69
|
+
result.launchRequestId !== intent.launchRequestId)
|
|
70
|
+
throw unavailable();
|
|
71
|
+
// The existing control protocol validates its exact envelope, without preview metadata.
|
|
72
|
+
const authorization = { ...result };
|
|
73
|
+
delete authorization.previewId;
|
|
74
|
+
return authorization;
|
|
75
|
+
}
|
|
76
|
+
end(signal, expectedLaunchRequestId) {
|
|
77
|
+
if (this.ending)
|
|
78
|
+
return this.ending;
|
|
79
|
+
const original = this.original();
|
|
80
|
+
if (!original || original.completed || (expectedLaunchRequestId !== undefined &&
|
|
81
|
+
original.intent.launchRequestId !== expectedLaunchRequestId))
|
|
82
|
+
return Promise.resolve();
|
|
83
|
+
const operation = this.finish(original, signal).catch(error => { this.reportError(error); throw error; })
|
|
84
|
+
.finally(() => { if (this.ending === operation)
|
|
85
|
+
this.ending = null; });
|
|
86
|
+
this.ending = operation;
|
|
87
|
+
return operation;
|
|
88
|
+
}
|
|
89
|
+
async finish(original, signal) {
|
|
90
|
+
if (this.admitting)
|
|
91
|
+
await this.admitting.catch(() => undefined);
|
|
92
|
+
let subject = this.store.readSubject();
|
|
93
|
+
if (!subject) {
|
|
94
|
+
// An ambiguous admission can be recovered only with its original intent and in-memory grant.
|
|
95
|
+
if (!this.grant)
|
|
96
|
+
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);
|
|
97
|
+
await this.admit(original.intent, signal);
|
|
98
|
+
subject = this.store.readSubject();
|
|
99
|
+
}
|
|
100
|
+
if (!subject || this.original()?.intent.launchRequestId !== original.intent.launchRequestId)
|
|
101
|
+
throw unavailable();
|
|
102
|
+
const result = await this.runtime.endMerchantPreview({ schemaVersion: 3, previewId: this.preview.previewId,
|
|
103
|
+
installKey: this.bootstrap.installKey, subjectCredential: subject.credential,
|
|
104
|
+
launchRequestId: original.intent.launchRequestId, tabId: original.intent.tabId, action: 'end' }, signal);
|
|
105
|
+
if (!result || Object.keys(result).length !== 6 || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
106
|
+
result.providerProtocol !== 'live' || result.status !== 'end_requested' || result.previewId !== this.preview.previewId ||
|
|
107
|
+
result.launchRequestId !== original.intent.launchRequestId)
|
|
108
|
+
throw unavailable();
|
|
109
|
+
this.writeOriginal({ ...original, completed: true });
|
|
110
|
+
this.store.clearLaunch(original.intent.launchRequestId);
|
|
111
|
+
this.admission = null;
|
|
112
|
+
this.grant = '';
|
|
113
|
+
}
|
|
114
|
+
async admit(intent, signal) {
|
|
115
|
+
if (this.admission)
|
|
116
|
+
return this.admission;
|
|
117
|
+
if (this.admitting)
|
|
118
|
+
return this.admitting;
|
|
119
|
+
if (!this.grant)
|
|
120
|
+
throw unavailable();
|
|
121
|
+
const subject = this.store.readSubject();
|
|
122
|
+
const operation = this.runtime.admitMerchantPreview(intent, this.grant, subject?.credential, signal).then(result => {
|
|
123
|
+
const required = ['schemaVersion', 'protocolVersion', 'providerProtocol', 'previewId', 'projectId', 'guideId', 'subjectId',
|
|
124
|
+
'subjectAuthorityRevision', 'tabId', 'launchRequestId', 'configRevision', 'configChecksum', 'admissionGrant',
|
|
125
|
+
'expiresAt', 'subjectCredentialExpiresAt'];
|
|
126
|
+
if (!result || Object.keys(result).some(key => ![...required, 'subjectCredential'].includes(key)) ||
|
|
127
|
+
required.some(key => !(key in result)) || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
|
|
128
|
+
result.providerProtocol !== 'live' || result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
|
|
129
|
+
result.guideId !== this.preview.guideId || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(result.subjectId) ||
|
|
130
|
+
result.tabId !== intent.tabId || result.launchRequestId !== intent.launchRequestId ||
|
|
131
|
+
result.configRevision !== this.preview.configurationRevision || result.configChecksum !== this.bootstrap.configChecksum ||
|
|
132
|
+
!Number.isSafeInteger(result.subjectAuthorityRevision) || result.subjectAuthorityRevision < 0 ||
|
|
133
|
+
typeof result.admissionGrant !== 'string' || result.admissionGrant.length < 1 || result.admissionGrant.length > 4096 ||
|
|
134
|
+
!Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now() ||
|
|
135
|
+
!Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) || Date.parse(result.subjectCredentialExpiresAt) <= Date.now() ||
|
|
136
|
+
(subject && (result.subjectId !== subject.subjectId || result.subjectAuthorityRevision !== subject.subjectAuthorityRevision)))
|
|
137
|
+
throw unavailable();
|
|
138
|
+
const credential = subject?.credential ?? result.subjectCredential;
|
|
139
|
+
if (!credential || !guideTypes_js_1.GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(credential))
|
|
140
|
+
throw unavailable();
|
|
141
|
+
this.store.saveSubject({ v: 1, origin: this.preview.targetOrigin, projectId: this.preview.projectId, guideId: this.preview.guideId,
|
|
142
|
+
subjectId: result.subjectId, subjectAuthorityRevision: result.subjectAuthorityRevision, credential, expiresAt: result.subjectCredentialExpiresAt });
|
|
143
|
+
this.store.saveLaunch({ v: 1, subjectId: result.subjectId, intent, recordingConsent: false });
|
|
144
|
+
this.admission = result;
|
|
145
|
+
return result;
|
|
146
|
+
}).finally(() => { if (this.admitting === operation)
|
|
147
|
+
this.admitting = null; });
|
|
148
|
+
this.admitting = operation;
|
|
149
|
+
return operation;
|
|
150
|
+
}
|
|
151
|
+
original() {
|
|
152
|
+
const raw = this.storage.getItem(this.originalKey);
|
|
153
|
+
if (raw === null)
|
|
154
|
+
return null;
|
|
155
|
+
if (raw.length > 16384)
|
|
156
|
+
throw unavailable();
|
|
157
|
+
let value;
|
|
158
|
+
try {
|
|
159
|
+
value = JSON.parse(raw);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
throw unavailable();
|
|
163
|
+
}
|
|
164
|
+
const intent = value?.intent;
|
|
165
|
+
if (value?.v !== 1 || value.previewId !== this.preview.previewId || typeof value.completed !== 'boolean' ||
|
|
166
|
+
!intent || intent.schemaVersion !== 3 || intent.protocolVersion !== 2 || intent.previewId !== this.preview.previewId ||
|
|
167
|
+
intent.installKey !== this.bootstrap.installKey || intent.configRevision !== this.preview.configurationRevision ||
|
|
168
|
+
intent.path !== this.preview.targetPath || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(intent.launchRequestId) ||
|
|
169
|
+
typeof intent.tabId !== 'string' || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(intent.tabId) ||
|
|
170
|
+
!['text', 'voice'].includes(intent.mode) || intent.experienceMode !== 'standard' ||
|
|
171
|
+
'guideMeasurement' in intent || 'previewGrant' in intent || 'admissionGrant' in intent)
|
|
172
|
+
throw unavailable();
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
writeOriginal(value) {
|
|
176
|
+
const raw = JSON.stringify(value);
|
|
177
|
+
if (raw.length > 16384)
|
|
178
|
+
throw unavailable();
|
|
179
|
+
this.storage.setItem(this.originalKey, raw);
|
|
180
|
+
if (this.storage.getItem(this.originalKey) !== raw)
|
|
181
|
+
throw unavailable();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
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;
|