@oxvo/ai-live-assist 7.5.19 → 7.5.21
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 +8 -1
- package/cjs/AiLiveAssist.js +113 -8
- package/cjs/client.d.ts +5 -3
- package/cjs/client.js +44 -5
- package/cjs/commerce/cartContracts.d.ts +158 -0
- package/cjs/commerce/cartContracts.js +228 -0
- package/cjs/commerce/cartSession.d.ts +86 -0
- package/cjs/commerce/cartSession.js +475 -0
- package/cjs/commerce/contracts.d.ts +152 -0
- package/cjs/commerce/contracts.js +322 -0
- package/cjs/commerce/pageContext.d.ts +50 -0
- package/cjs/commerce/pageContext.js +173 -0
- package/cjs/commerce/productPanel.d.ts +65 -0
- package/cjs/commerce/productPanel.js +662 -0
- package/cjs/commerce/realtimeCommerce.d.ts +73 -0
- package/cjs/commerce/realtimeCommerce.js +342 -0
- package/cjs/commerce/shopifyCart.d.ts +130 -0
- package/cjs/commerce/shopifyCart.js +1135 -0
- package/cjs/commerce/shopifyCartPresentation.d.ts +12 -0
- package/cjs/commerce/shopifyCartPresentation.js +379 -0
- package/cjs/commerce/shoppingNotes.d.ts +61 -0
- package/cjs/commerce/shoppingNotes.js +313 -0
- package/cjs/commerce/shoppingNotesView.d.ts +46 -0
- package/cjs/commerce/shoppingNotesView.js +269 -0
- package/cjs/control.d.ts +9 -1
- package/cjs/control.js +51 -1
- package/cjs/guideAdmission.d.ts +5 -2
- package/cjs/guideAdmission.js +21 -2
- package/cjs/guideInstaller.js +1 -1
- package/cjs/guideMeasurement.d.ts +5 -0
- package/cjs/guideMeasurement.js +29 -0
- package/cjs/guideSubjectStore.js +2 -0
- package/cjs/guideTypes.d.ts +18 -0
- package/cjs/liveControlChannel.d.ts +43 -1
- package/cjs/liveControlChannel.js +166 -14
- package/cjs/liveGuideAdmission.d.ts +3 -2
- package/cjs/liveGuideAdmission.js +10 -2
- package/cjs/liveGuideWidget.d.ts +18 -0
- package/cjs/liveGuideWidget.js +228 -23
- package/cjs/locales/resources.js +2240 -0
- package/cjs/messages.js +56 -0
- package/cjs/tabLock.d.ts +2 -0
- package/cjs/tabLock.js +11 -1
- package/cjs/types.d.ts +6 -2
- package/cjs/types.js +56 -0
- package/cjs/ui.d.ts +37 -0
- package/cjs/ui.js +261 -9
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/lib/AiLiveAssist.d.ts +8 -1
- package/lib/AiLiveAssist.js +113 -8
- package/lib/client.d.ts +5 -3
- package/lib/client.js +44 -5
- package/lib/commerce/cartContracts.d.ts +158 -0
- package/lib/commerce/cartContracts.js +221 -0
- package/lib/commerce/cartSession.d.ts +86 -0
- package/lib/commerce/cartSession.js +471 -0
- package/lib/commerce/contracts.d.ts +152 -0
- package/lib/commerce/contracts.js +300 -0
- package/lib/commerce/pageContext.d.ts +50 -0
- package/lib/commerce/pageContext.js +168 -0
- package/lib/commerce/productPanel.d.ts +65 -0
- package/lib/commerce/productPanel.js +657 -0
- package/lib/commerce/realtimeCommerce.d.ts +73 -0
- package/lib/commerce/realtimeCommerce.js +337 -0
- package/lib/commerce/shopifyCart.d.ts +130 -0
- package/lib/commerce/shopifyCart.js +1130 -0
- package/lib/commerce/shopifyCartPresentation.d.ts +12 -0
- package/lib/commerce/shopifyCartPresentation.js +376 -0
- package/lib/commerce/shoppingNotes.d.ts +61 -0
- package/lib/commerce/shoppingNotes.js +307 -0
- package/lib/commerce/shoppingNotesView.d.ts +46 -0
- package/lib/commerce/shoppingNotesView.js +265 -0
- package/lib/control.d.ts +9 -1
- package/lib/control.js +51 -1
- package/lib/guideAdmission.d.ts +5 -2
- package/lib/guideAdmission.js +21 -2
- package/lib/guideInstaller.js +1 -1
- package/lib/guideMeasurement.d.ts +5 -0
- package/lib/guideMeasurement.js +24 -0
- package/lib/guideSubjectStore.js +2 -0
- package/lib/guideTypes.d.ts +18 -0
- package/lib/liveControlChannel.d.ts +43 -1
- package/lib/liveControlChannel.js +166 -14
- package/lib/liveGuideAdmission.d.ts +3 -2
- package/lib/liveGuideAdmission.js +10 -2
- package/lib/liveGuideWidget.d.ts +18 -0
- package/lib/liveGuideWidget.js +228 -23
- package/lib/locales/resources.js +2240 -0
- package/lib/messages.js +56 -0
- package/lib/tabLock.d.ts +2 -0
- package/lib/tabLock.js +11 -1
- package/lib/types.d.ts +6 -2
- package/lib/types.js +56 -0
- package/lib/ui.d.ts +37 -0
- package/lib/ui.js +261 -9
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMMERCE_CART_GRANT_MAX_AGE_MS = exports.COMMERCE_CART_CONFIRMATION_MAX_AGE_MS = exports.COMMERCE_CART_MESSAGE_MAX_BYTES = exports.COMMERCE_CART_SMALL_MESSAGE_MAX_BYTES = void 0;
|
|
4
|
+
exports.parseCommerceCartConfirmation = parseCommerceCartConfirmation;
|
|
5
|
+
exports.parseCommerceCartGrant = parseCommerceCartGrant;
|
|
6
|
+
exports.parseCommerceCartExecutionReady = parseCommerceCartExecutionReady;
|
|
7
|
+
exports.parseCommerceCartResult = parseCommerceCartResult;
|
|
8
|
+
const contracts_js_1 = require("./contracts.js");
|
|
9
|
+
exports.COMMERCE_CART_SMALL_MESSAGE_MAX_BYTES = 4096;
|
|
10
|
+
exports.COMMERCE_CART_MESSAGE_MAX_BYTES = 12000;
|
|
11
|
+
exports.COMMERCE_CART_CONFIRMATION_MAX_AGE_MS = 30000;
|
|
12
|
+
exports.COMMERCE_CART_GRANT_MAX_AGE_MS = 8000;
|
|
13
|
+
const scopeKeys = ['schemaVersion', 'requestId', 'operationId', 'proposalChecksum', 'contextDigest', 'contextRevision', 'pageId', 'provider'];
|
|
14
|
+
const itemKeys = ['productRef', 'variantRef', 'shopifyVariantId', 'title', 'productUrl', 'selectedOptions', 'quantity', 'unitPrice', 'quantityRule', 'requiresSellingPlan', 'requiresComponents'];
|
|
15
|
+
const controls = /[\u0000-\u001f\u007f]/u;
|
|
16
|
+
const label = (value, maximum) => typeof value === 'string' && value.length >= 1 &&
|
|
17
|
+
value.length <= maximum && value.trim() === value && !controls.test(value);
|
|
18
|
+
const ref = (value) => label(value, 256) && !/\s/u.test(value);
|
|
19
|
+
const digest = (value) => typeof value === 'string' && /^[a-f0-9]{64}$/u.test(value);
|
|
20
|
+
const positive = (value) => (0, contracts_js_1.commerceCount)(value) && value > 0;
|
|
21
|
+
const currency = (value) => typeof value === 'string' && /^[A-Z]{3}$/u.test(value);
|
|
22
|
+
const uint64 = (value) => typeof value === 'string' && /^[1-9]\d{0,19}$/u.test(value) &&
|
|
23
|
+
(value.length < 20 || value <= '18446744073709551615');
|
|
24
|
+
const grantToken = (value) => typeof value === 'string' && /^[A-Za-z0-9_-]{32,256}$/u.test(value);
|
|
25
|
+
const requestMessageId = (value) => typeof value === 'string' && /^[A-Za-z0-9_.:-]{8,128}$/u.test(value);
|
|
26
|
+
/** Walk plain JSON descriptors before reading values. This neither executes
|
|
27
|
+
* getters/toJSON nor serializes an unbounded object received from the wire. */
|
|
28
|
+
function bounded(value, limit) {
|
|
29
|
+
try {
|
|
30
|
+
let remaining = limit;
|
|
31
|
+
const ancestors = new Set();
|
|
32
|
+
const encoder = new TextEncoder();
|
|
33
|
+
const spend = (length) => { remaining -= length; if (remaining < 0)
|
|
34
|
+
throw new Error('Cart message is too large.'); };
|
|
35
|
+
const string = (item) => {
|
|
36
|
+
if (item.length > remaining)
|
|
37
|
+
throw new Error('Cart string is too large.');
|
|
38
|
+
spend(encoder.encode(JSON.stringify(item)).length);
|
|
39
|
+
};
|
|
40
|
+
const visit = (item, depth) => {
|
|
41
|
+
if (depth > 10)
|
|
42
|
+
throw new Error('Cart message is too deeply nested.');
|
|
43
|
+
if (typeof item === 'string') {
|
|
44
|
+
string(item);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (item === null) {
|
|
48
|
+
spend(4);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (typeof item === 'boolean') {
|
|
52
|
+
spend(item ? 4 : 5);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (typeof item === 'number' && Number.isFinite(item)) {
|
|
56
|
+
spend(String(item).length);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!item || typeof item !== 'object' || ancestors.has(item))
|
|
60
|
+
throw new Error('Cart message is not JSON.');
|
|
61
|
+
const array = Array.isArray(item);
|
|
62
|
+
if (!array && Object.getPrototypeOf(item) !== Object.prototype && Object.getPrototypeOf(item) !== null)
|
|
63
|
+
throw new Error('Cart message is not plain JSON.');
|
|
64
|
+
ancestors.add(item);
|
|
65
|
+
spend(2);
|
|
66
|
+
if (array && item.length > (remaining + 1) / 2)
|
|
67
|
+
throw new Error('Cart array is too large.');
|
|
68
|
+
const keys = Object.keys(item);
|
|
69
|
+
if (array && keys.length !== item.length)
|
|
70
|
+
throw new Error('Invalid cart array.');
|
|
71
|
+
for (const [index, key] of keys.entries()) {
|
|
72
|
+
if (array && key !== String(index))
|
|
73
|
+
throw new Error('Invalid cart array.');
|
|
74
|
+
if (index)
|
|
75
|
+
spend(1);
|
|
76
|
+
if (!array) {
|
|
77
|
+
string(key);
|
|
78
|
+
spend(1);
|
|
79
|
+
}
|
|
80
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, key);
|
|
81
|
+
if (!descriptor || !('value' in descriptor))
|
|
82
|
+
throw new Error('Cart accessors are not JSON.');
|
|
83
|
+
visit(descriptor.value, depth + 1);
|
|
84
|
+
}
|
|
85
|
+
ancestors.delete(item);
|
|
86
|
+
};
|
|
87
|
+
visit(value, 0);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function timestamp(value) {
|
|
95
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/u.test(value))
|
|
96
|
+
return null;
|
|
97
|
+
const parsed = Date.parse(value);
|
|
98
|
+
if (!Number.isFinite(parsed))
|
|
99
|
+
return null;
|
|
100
|
+
const canonical = value.replace(/(?:\.(\d{1,3}))?Z$/u, (_, fraction) => `.${(fraction ?? '').padEnd(3, '0')}Z`);
|
|
101
|
+
return new Date(parsed).toISOString() === canonical ? parsed : null;
|
|
102
|
+
}
|
|
103
|
+
function expires(value, now, maximum) {
|
|
104
|
+
const parsed = timestamp(value);
|
|
105
|
+
return Number.isSafeInteger(now) && now >= 0 && parsed !== null && parsed > now && parsed - now <= maximum;
|
|
106
|
+
}
|
|
107
|
+
function provider(value) {
|
|
108
|
+
return (0, contracts_js_1.commerceObject)(value, ['kind', 'generationDigest']) && value.kind === 'realtime' && digest(value.generationDigest) ||
|
|
109
|
+
(0, contracts_js_1.commerceObject)(value, ['kind', 'taskId', 'inputEpoch']) && value.kind === 'live' && (0, contracts_js_1.commerceUuid)(value.taskId) && (0, contracts_js_1.commerceCount)(value.inputEpoch);
|
|
110
|
+
}
|
|
111
|
+
function sameProvider(left, right) {
|
|
112
|
+
return left.kind === 'live' ? right.kind === 'live' && left.taskId === right.taskId && left.inputEpoch === right.inputEpoch :
|
|
113
|
+
right.kind === 'realtime' && left.generationDigest === right.generationDigest;
|
|
114
|
+
}
|
|
115
|
+
function scope(value) {
|
|
116
|
+
return value.schemaVersion === 1 && (0, contracts_js_1.commerceUuid)(value.requestId) && (0, contracts_js_1.commerceUuid)(value.operationId) && digest(value.proposalChecksum) &&
|
|
117
|
+
digest(value.contextDigest) && (0, contracts_js_1.commerceCount)(value.contextRevision) && label(value.pageId, 128) && !/\s/u.test(value.pageId) && provider(value.provider);
|
|
118
|
+
}
|
|
119
|
+
function expectedScope(value, expected) {
|
|
120
|
+
if (!expected)
|
|
121
|
+
return true;
|
|
122
|
+
return scopeKeys.every(key => !Object.prototype.hasOwnProperty.call(expected, key) || (key === 'provider'
|
|
123
|
+
? provider(expected.provider) && sameProvider(value.provider, expected.provider)
|
|
124
|
+
: value[key] === expected[key]));
|
|
125
|
+
}
|
|
126
|
+
function item(value) {
|
|
127
|
+
if (!(0, contracts_js_1.commerceObject)(value, itemKeys) || !ref(value.productRef) || !ref(value.variantRef) || !uint64(value.shopifyVariantId) ||
|
|
128
|
+
!label(value.title, 256) || !label(value.productUrl, 2048) || /[\s\\]/u.test(value.productUrl) || !(0, contracts_js_1.isCommerceOptions)(value.selectedOptions) ||
|
|
129
|
+
!positive(value.quantity) || !(0, contracts_js_1.commerceObject)(value.unitPrice, ['amount', 'currency']) || !currency(value.unitPrice.currency) ||
|
|
130
|
+
typeof value.unitPrice.amount !== 'string' || !/^(?:0|[1-9]\d{0,9})(?:\.\d{1,6})?$/u.test(value.unitPrice.amount) ||
|
|
131
|
+
!(0, contracts_js_1.commerceObject)(value.quantityRule, ['minimum', 'maximum', 'increment']) || value.requiresSellingPlan !== false || value.requiresComponents !== false)
|
|
132
|
+
return false;
|
|
133
|
+
const url = new URL(value.productUrl);
|
|
134
|
+
if (url.protocol !== 'https:' || url.username || url.password || !url.hostname)
|
|
135
|
+
return false;
|
|
136
|
+
const rule = value.quantityRule;
|
|
137
|
+
if (!positive(rule.minimum) || !positive(rule.increment) || (rule.maximum !== null && (!positive(rule.maximum) || rule.maximum < rule.minimum)))
|
|
138
|
+
return false;
|
|
139
|
+
const quantity = BigInt(value.quantity);
|
|
140
|
+
const increment = BigInt(rule.increment);
|
|
141
|
+
return quantity >= BigInt(rule.minimum) && (rule.maximum === null || quantity <= BigInt(rule.maximum)) && quantity % increment === 0n &&
|
|
142
|
+
BigInt(rule.minimum) % increment === 0n && (rule.maximum === null || BigInt(rule.maximum) % increment === 0n);
|
|
143
|
+
}
|
|
144
|
+
function quotedScope(value, bootstrap, context) {
|
|
145
|
+
return context !== null && (0, contracts_js_1.isCommerceContext)(context) && (0, contracts_js_1.parseCommerceBootstrap)(bootstrap, bootstrap.guideId, context.origin) !== null &&
|
|
146
|
+
bootstrap.cartEnabled === true && value.contextRevision === context.contextRevision && value.pageId === context.pageId &&
|
|
147
|
+
(0, contracts_js_1.isCommerceStore)(value.store) && (0, contracts_js_1.sameCommerceStore)(value.store, bootstrap.store) && (0, contracts_js_1.isCommerceMarket)(value.market) &&
|
|
148
|
+
(0, contracts_js_1.sameCommerceMarket)(value.market, context.market) && item(value.item) && new URL(value.item.productUrl).origin === value.store.origin &&
|
|
149
|
+
value.item.unitPrice.currency === value.market.currency;
|
|
150
|
+
}
|
|
151
|
+
/** A confirmation is a bounded quote, never permission to mutate the cart. */
|
|
152
|
+
function parseCommerceCartConfirmation(value, bootstrap, context, expected, now = Date.now()) {
|
|
153
|
+
try {
|
|
154
|
+
if (!bounded(value, exports.COMMERCE_CART_MESSAGE_MAX_BYTES) ||
|
|
155
|
+
!(0, contracts_js_1.commerceObject)(value, [...scopeKeys, 'guideId', 'store', 'market', 'item', 'expiresAt']) || !scope(value) ||
|
|
156
|
+
value.guideId !== bootstrap.guideId || !(0, contracts_js_1.commerceUuid)(value.guideId) || !quotedScope(value, bootstrap, context) ||
|
|
157
|
+
!expectedScope(value, expected) || !expires(value.expiresAt, now, exports.COMMERCE_CART_CONFIRMATION_MAX_AGE_MS))
|
|
158
|
+
return null;
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/** The session must additionally bind this grant to its approved quote and
|
|
166
|
+
* current control lease. operationMarker is an independent server-issued UUID. */
|
|
167
|
+
function parseCommerceCartGrant(value, bootstrap, context, expected, now = Date.now()) {
|
|
168
|
+
try {
|
|
169
|
+
if (!bounded(value, exports.COMMERCE_CART_MESSAGE_MAX_BYTES) ||
|
|
170
|
+
!(0, contracts_js_1.commerceObject)(value, [...scopeKeys, 'grant', 'action', 'store', 'market', 'item', 'operationMarker', 'expiresAt']) ||
|
|
171
|
+
!scope(value) || !grantToken(value.grant) || value.action !== 'add' || !(0, contracts_js_1.commerceUuid)(value.operationMarker) ||
|
|
172
|
+
!quotedScope(value, bootstrap, context) || !expectedScope(value, expected) || !expires(value.expiresAt, now, exports.COMMERCE_CART_GRANT_MAX_AGE_MS))
|
|
173
|
+
return null;
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** already_started retains the original executionId/cartDigest exactly. The
|
|
181
|
+
* caller must correlate operation/requestMessageId and must never replay POST. */
|
|
182
|
+
function parseCommerceCartExecutionReady(value, expected, now = Date.now()) {
|
|
183
|
+
try {
|
|
184
|
+
if (!bounded(value, exports.COMMERCE_CART_SMALL_MESSAGE_MAX_BYTES) ||
|
|
185
|
+
!(0, contracts_js_1.commerceObject)(value, ['schemaVersion', 'operationId', 'executionId', 'cartDigest', 'requestMessageId', 'state', 'expiresAt']) ||
|
|
186
|
+
value.schemaVersion !== 1 || !(0, contracts_js_1.commerceUuid)(value.operationId) || !(0, contracts_js_1.commerceUuid)(value.executionId) || !digest(value.cartDigest) ||
|
|
187
|
+
!requestMessageId(value.requestMessageId) || (value.state !== 'prepared' && value.state !== 'already_started') ||
|
|
188
|
+
!expires(value.expiresAt, now, exports.COMMERCE_CART_GRANT_MAX_AGE_MS) ||
|
|
189
|
+
(expected && !['operationId', 'executionId', 'cartDigest', 'requestMessageId'].every(key => !Object.prototype.hasOwnProperty.call(expected, key) || value[key] === expected[key])))
|
|
190
|
+
return null;
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function observation(value) {
|
|
198
|
+
return (0, contracts_js_1.commerceObject)(value, ['source', 'observedAt', 'currency', 'shopifyVariantId', 'operationMarker', 'quantity', 'lineKeyDigest']) &&
|
|
199
|
+
value.source === 'browser_cart' && timestamp(value.observedAt) !== null && currency(value.currency) && uint64(value.shopifyVariantId) &&
|
|
200
|
+
(0, contracts_js_1.commerceUuid)(value.operationMarker) && (0, contracts_js_1.commerceCount)(value.quantity) && (value.lineKeyDigest === null || digest(value.lineKeyDigest)) &&
|
|
201
|
+
(value.quantity === 0) === (value.lineKeyDigest === null);
|
|
202
|
+
}
|
|
203
|
+
const resultCodes = {
|
|
204
|
+
rejected: ['quote_unavailable', 'quote_changed', 'policy_denied', 'unsupported_selection', 'busy', 'context_changed', 'conflict'],
|
|
205
|
+
cancelled: ['declined', 'context_changed'], expired: ['expired'], unconfirmed: ['unconfirmed'], observed: ['observed'], partial: ['partial'],
|
|
206
|
+
};
|
|
207
|
+
/** observed/partial are correlated browser reports, not server-verified facts.
|
|
208
|
+
* observedAt remains the reported timestamp; no invented recency restriction. */
|
|
209
|
+
function parseCommerceCartResult(value, expected, now = Date.now()) {
|
|
210
|
+
try {
|
|
211
|
+
const keys = ['schemaVersion', 'requestId', 'operationId', 'executionId', 'status', 'code'];
|
|
212
|
+
if (!Number.isSafeInteger(now) || now < 0 || !bounded(value, exports.COMMERCE_CART_SMALL_MESSAGE_MAX_BYTES) ||
|
|
213
|
+
!((0, contracts_js_1.commerceObject)(value, keys) || (0, contracts_js_1.commerceObject)(value, [...keys, 'observation'])) || value.schemaVersion !== 1 ||
|
|
214
|
+
!(0, contracts_js_1.commerceUuid)(value.requestId) || (value.operationId !== null && !(0, contracts_js_1.commerceUuid)(value.operationId)) ||
|
|
215
|
+
(value.executionId !== null && !(0, contracts_js_1.commerceUuid)(value.executionId)) || (value.executionId !== null && value.operationId === null) ||
|
|
216
|
+
typeof value.status !== 'string' || typeof value.code !== 'string' || !Object.prototype.hasOwnProperty.call(resultCodes, value.status) ||
|
|
217
|
+
!resultCodes[value.status].includes(value.code) ||
|
|
218
|
+
(Object.prototype.hasOwnProperty.call(value, 'observation') && !observation(value.observation)) ||
|
|
219
|
+
(['observed', 'partial'].includes(value.status) && (!(0, contracts_js_1.commerceUuid)(value.operationId) || !(0, contracts_js_1.commerceUuid)(value.executionId) ||
|
|
220
|
+
!observation(value.observation) || value.observation.quantity === 0)) ||
|
|
221
|
+
(expected && !['requestId', 'operationId', 'executionId'].every(key => !Object.prototype.hasOwnProperty.call(expected, key) || value[key] === expected[key])))
|
|
222
|
+
return null;
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CommerceCartConfirmationView } from '../ui.js';
|
|
2
|
+
import type { CommerceAddHandler, CommerceCanAdd } from './productPanel.js';
|
|
3
|
+
import type { CommerceBootstrap, CommerceCartSelection, CommerceContext, CommerceProduct, LiveCommerceDisplayed, RealtimeCommerceDisplayed } from './contracts.js';
|
|
4
|
+
import { type CommerceCartProvider } from './cartContracts.js';
|
|
5
|
+
import { type ShopifyCartOutcome } from './shopifyCart.js';
|
|
6
|
+
export type CartSessionSnapshot = {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
context: CommerceContext;
|
|
9
|
+
provider: CommerceCartProvider;
|
|
10
|
+
fencingToken: number;
|
|
11
|
+
/** Local current-consent generation, never inferred server authorization. */
|
|
12
|
+
consentEpoch: number;
|
|
13
|
+
};
|
|
14
|
+
export type DisplayedCartSelection = {
|
|
15
|
+
selection: CommerceCartSelection;
|
|
16
|
+
displayReceipt: LiveCommerceDisplayed | RealtimeCommerceDisplayed;
|
|
17
|
+
product: CommerceProduct;
|
|
18
|
+
expiresAt: string;
|
|
19
|
+
};
|
|
20
|
+
export type CommerceCartView = {
|
|
21
|
+
setCommerceBusy(busy: boolean): void;
|
|
22
|
+
setCommerceError(): void;
|
|
23
|
+
setCommerceCartActionHandler(handler: CommerceAddHandler | null, canAdd?: CommerceCanAdd): void;
|
|
24
|
+
showCommerceCartConfirmation(value: CommerceCartConfirmationView, onDecision: (approved: boolean) => void): void;
|
|
25
|
+
clearCommerceCartConfirmation(operationId?: string): void;
|
|
26
|
+
setCommerceCartStatus(outcome: ShopifyCartOutcome, cartUrl: string, onCheck?: () => void | Promise<void>): void;
|
|
27
|
+
clearCommerceCartStatus(): void;
|
|
28
|
+
};
|
|
29
|
+
export type CartSessionOptions = {
|
|
30
|
+
bootstrap: CommerceBootstrap;
|
|
31
|
+
view: () => CommerceCartView | null;
|
|
32
|
+
/** Null unless disclosure, dedicated cart consent, cart negotiation and the
|
|
33
|
+
* current session/provider fence are all effective. */
|
|
34
|
+
current: () => CartSessionSnapshot | null;
|
|
35
|
+
/** Current authenticated transport identity even while cart consent is cut. */
|
|
36
|
+
transportSessionId?: () => string | null;
|
|
37
|
+
selection: (productRef: string, variantRef: string) => DisplayedCartSelection | null;
|
|
38
|
+
send: (type: string, payload: Record<string, unknown>) => {
|
|
39
|
+
messageId: string;
|
|
40
|
+
accepted: Promise<boolean>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/** One explicit shopper operation at a time. Catalog evidence can request a
|
|
44
|
+
* quote; only a separately approved, current grant can reach the Ajax executor. */
|
|
45
|
+
export declare class CartSession {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private pending;
|
|
48
|
+
private destroyed;
|
|
49
|
+
private readonly retired;
|
|
50
|
+
private readonly retiredRequests;
|
|
51
|
+
private recoveryOutcome;
|
|
52
|
+
private recoveryInFlight;
|
|
53
|
+
constructor(options: CartSessionOptions);
|
|
54
|
+
/** A catalog replaces the panel; install again after its visible receipt. */
|
|
55
|
+
refreshControls(): void;
|
|
56
|
+
canAdd: (productRef: string, variantRef: string, quantity: number) => boolean;
|
|
57
|
+
add: (productRef: string, variantRef: string, quantity: number) => void;
|
|
58
|
+
/** execution.ready must be delivered at authenticated ingress, before any
|
|
59
|
+
* queued handler waits for the executor's ACK-plus-ready barrier. */
|
|
60
|
+
onEvent(type: string, payload: unknown): void;
|
|
61
|
+
cut(): void;
|
|
62
|
+
destroy(): void;
|
|
63
|
+
private createPending;
|
|
64
|
+
private current;
|
|
65
|
+
private confirmation;
|
|
66
|
+
private quoteMatchesDisplayed;
|
|
67
|
+
private decide;
|
|
68
|
+
private grant;
|
|
69
|
+
private execute;
|
|
70
|
+
private recoveryExecutor;
|
|
71
|
+
private hasUnresolved;
|
|
72
|
+
private recoveryScope;
|
|
73
|
+
private report;
|
|
74
|
+
private showRecovery;
|
|
75
|
+
private checkCart;
|
|
76
|
+
private begin;
|
|
77
|
+
private ready;
|
|
78
|
+
private result;
|
|
79
|
+
private decline;
|
|
80
|
+
private arm;
|
|
81
|
+
private fail;
|
|
82
|
+
private finish;
|
|
83
|
+
private cartUrl;
|
|
84
|
+
private send;
|
|
85
|
+
private boundedAccepted;
|
|
86
|
+
}
|