@salla.sa/embedded-sdk 0.2.6 → 0.2.7
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/README.md +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +235 -196
- package/dist/esm/index.js.map +1 -1
- package/dist/system/index.js +2 -2
- package/dist/system/index.js.map +1 -1
- package/dist/types/index.d.ts +33 -4
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const u = "embedded::", q = {
|
|
|
5
5
|
READY: `${u}ready`,
|
|
6
6
|
/** App requests to be destroyed and navigate away */
|
|
7
7
|
DESTROY: `${u}destroy`
|
|
8
|
-
},
|
|
8
|
+
}, j = {
|
|
9
9
|
/** Context data provision */
|
|
10
10
|
PROVIDE: `${u}context.provide`,
|
|
11
11
|
/** Theme change notification */
|
|
@@ -21,7 +21,7 @@ const u = "embedded::", q = {
|
|
|
21
21
|
CONFIRM: `${u}ui.confirm`,
|
|
22
22
|
/** Confirm dialog response (from host) */
|
|
23
23
|
CONFIRM_RESPONSE: `${u}ui.confirm.response`
|
|
24
|
-
},
|
|
24
|
+
}, ne = {}, Z = {
|
|
25
25
|
/** Request token refresh (re-renders iframe with new token) */
|
|
26
26
|
REFRESH: `${u}auth.refresh`
|
|
27
27
|
}, T = {
|
|
@@ -46,7 +46,7 @@ const u = "embedded::", q = {
|
|
|
46
46
|
REMOVE_ITEM: `${u}nav.removeItem`,
|
|
47
47
|
/** Injected sub-nav item clicked (host → iframe) */
|
|
48
48
|
ITEM_CLICK: `${u}nav.itemClick`
|
|
49
|
-
},
|
|
49
|
+
}, v = {
|
|
50
50
|
/** Create checkout flow */
|
|
51
51
|
CREATE: `${u}checkout.create`,
|
|
52
52
|
/** Checkout response from host */
|
|
@@ -57,13 +57,13 @@ const u = "embedded::", q = {
|
|
|
57
57
|
GET_ADDONS_RESPONSE: `${u}checkout.getAddons.response`,
|
|
58
58
|
/** Reset checkout cache on host */
|
|
59
59
|
RESET_CACHE: `${u}checkout.resetCache`
|
|
60
|
-
},
|
|
60
|
+
}, M = ne.version || "", se = 1e4, ae = [
|
|
61
61
|
"localhost",
|
|
62
62
|
"merchants.workers.dev",
|
|
63
63
|
"s.salla.sa",
|
|
64
64
|
".salla.group",
|
|
65
65
|
".salla.sa"
|
|
66
|
-
],
|
|
66
|
+
], oe = /* @__PURE__ */ new Set([
|
|
67
67
|
"ar",
|
|
68
68
|
// Arabic
|
|
69
69
|
"he",
|
|
@@ -79,28 +79,28 @@ const u = "embedded::", q = {
|
|
|
79
79
|
"yi"
|
|
80
80
|
// Yiddish
|
|
81
81
|
]);
|
|
82
|
-
function
|
|
82
|
+
function ue(t) {
|
|
83
83
|
const e = (t ?? "ar").toLowerCase().split(/[-_]/)[0];
|
|
84
|
-
return
|
|
84
|
+
return oe.has(e) ? "rtl" : "ltr";
|
|
85
85
|
}
|
|
86
86
|
let N = {
|
|
87
87
|
showVersion: !0,
|
|
88
88
|
debug: !1
|
|
89
89
|
};
|
|
90
|
-
function
|
|
90
|
+
function ce(t) {
|
|
91
91
|
N = { ...N, ...t };
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function H(t) {
|
|
94
94
|
return `%c${t}`;
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function K(t, e = "#fff") {
|
|
97
97
|
return `background-color: ${t}; color: ${e}; padding: 2px 6px; border-radius: 3px; font-weight: 500; font-size: 11px;`;
|
|
98
98
|
}
|
|
99
99
|
function S(t, ...e) {
|
|
100
100
|
if (t === "debug" && !N.debug)
|
|
101
101
|
return;
|
|
102
102
|
const r = [], i = [];
|
|
103
|
-
r.push(
|
|
103
|
+
r.push(H("EmbeddedSDK")), i.push(K("#10b981", "#fff")), N.showVersion && (r.push(H(`v${M}`)), i.push(K("#6b7280", "#fff")));
|
|
104
104
|
const n = r.join("").trim();
|
|
105
105
|
(console[t] || console.log)(n, ...i, ...e);
|
|
106
106
|
}
|
|
@@ -121,19 +121,19 @@ const o = {
|
|
|
121
121
|
S("debug", ...t);
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
-
function
|
|
124
|
+
function de(t) {
|
|
125
125
|
try {
|
|
126
126
|
const r = new URL(t).hostname;
|
|
127
|
-
return
|
|
127
|
+
return ae.some((i) => i.startsWith(".") ? r.endsWith(i) || r === i.slice(1) : r === i || r.startsWith(`${i}:`));
|
|
128
128
|
} catch {
|
|
129
129
|
return !1;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function le() {
|
|
133
133
|
return typeof window > "u" || window.parent === window ? null : window.parent;
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
const s =
|
|
135
|
+
function d(t, e, r = "*", i, n) {
|
|
136
|
+
const s = le();
|
|
137
137
|
if (!s) {
|
|
138
138
|
o.warn("Not running in an iframe, cannot post to host");
|
|
139
139
|
return;
|
|
@@ -145,22 +145,22 @@ function c(t, e, r = "*", i, n) {
|
|
|
145
145
|
source: "embedded-app",
|
|
146
146
|
...i && { requestId: i },
|
|
147
147
|
metadata: {
|
|
148
|
-
version:
|
|
148
|
+
version: M
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
151
|
s.postMessage(a, r);
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
let
|
|
155
|
-
function
|
|
156
|
-
if (process.env.NODE_ENV === "production" && !
|
|
153
|
+
const b = /* @__PURE__ */ new Map();
|
|
154
|
+
let C = !1;
|
|
155
|
+
function ee(t) {
|
|
156
|
+
if (process.env.NODE_ENV === "production" && !de(t.origin))
|
|
157
157
|
return;
|
|
158
158
|
const e = t.data;
|
|
159
159
|
if (!e || typeof e.event != "string" || !e.payload || typeof e.timestamp != "number" || !e.source) {
|
|
160
160
|
o.warn("Invalid message structure received:", e);
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
|
-
const r =
|
|
163
|
+
const r = b.get(e.event);
|
|
164
164
|
r && r.forEach((n) => {
|
|
165
165
|
try {
|
|
166
166
|
n(e);
|
|
@@ -168,7 +168,7 @@ function W(t) {
|
|
|
168
168
|
o.error("Error in message handler:", s);
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
-
const i =
|
|
171
|
+
const i = b.get("*");
|
|
172
172
|
i && i.forEach((n) => {
|
|
173
173
|
try {
|
|
174
174
|
n(e);
|
|
@@ -177,41 +177,41 @@ function W(t) {
|
|
|
177
177
|
}
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
180
|
+
function fe() {
|
|
181
|
+
C || typeof window > "u" || (window.addEventListener("message", ee), C = !0);
|
|
182
182
|
}
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
const r =
|
|
183
|
+
function y(t, e) {
|
|
184
|
+
fe(), b.has(t) || b.set(t, /* @__PURE__ */ new Set());
|
|
185
|
+
const r = b.get(t);
|
|
186
186
|
return r.add(e), () => {
|
|
187
|
-
r.delete(e), r.size === 0 &&
|
|
187
|
+
r.delete(e), r.size === 0 && b.delete(t);
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function he(t, e = se) {
|
|
191
191
|
return new Promise((r, i) => {
|
|
192
192
|
const n = setTimeout(() => {
|
|
193
193
|
s(), i(new Error(`[EmbeddedSDK] Timeout waiting for "${t}" message`));
|
|
194
|
-
}, e), s =
|
|
194
|
+
}, e), s = y(t, (a) => {
|
|
195
195
|
clearTimeout(n), s(), r(a);
|
|
196
196
|
});
|
|
197
197
|
});
|
|
198
198
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
199
|
+
function me() {
|
|
200
|
+
b.clear(), C && typeof window < "u" && (window.removeEventListener("message", ee), C = !1);
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function pe() {
|
|
203
203
|
return typeof window > "u" ? !1 : window.parent !== window;
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function ge(t, e, r) {
|
|
206
206
|
const i = {
|
|
207
207
|
event: t,
|
|
208
208
|
payload: e,
|
|
209
209
|
timestamp: Date.now(),
|
|
210
210
|
source: "merchant-dashboard",
|
|
211
211
|
...r,
|
|
212
|
-
metadata: { version:
|
|
212
|
+
metadata: { version: M, synthetic: !0 }
|
|
213
213
|
};
|
|
214
|
-
|
|
214
|
+
b.get(t)?.forEach((s) => {
|
|
215
215
|
try {
|
|
216
216
|
s(i);
|
|
217
217
|
} catch (a) {
|
|
@@ -219,13 +219,13 @@ function le(t, e, r) {
|
|
|
219
219
|
}
|
|
220
220
|
});
|
|
221
221
|
}
|
|
222
|
-
const E = /* @__PURE__ */ new Map(),
|
|
223
|
-
function
|
|
222
|
+
const E = /* @__PURE__ */ new Map(), ve = 3e4;
|
|
223
|
+
function te() {
|
|
224
224
|
const t = Date.now(), e = Math.random().toString(36).slice(2, 9);
|
|
225
225
|
return `req_${t}_${e}`;
|
|
226
226
|
}
|
|
227
|
-
function
|
|
228
|
-
const i =
|
|
227
|
+
function V(t, e = {}, r = ve) {
|
|
228
|
+
const i = te();
|
|
229
229
|
return new Promise((n, s) => {
|
|
230
230
|
const a = setTimeout(() => {
|
|
231
231
|
E.get(i) && (E.delete(i), s(
|
|
@@ -239,10 +239,10 @@ function x(t, e = {}, r = fe) {
|
|
|
239
239
|
reject: s,
|
|
240
240
|
timeout: a,
|
|
241
241
|
event: t
|
|
242
|
-
}),
|
|
242
|
+
}), d(t, e, "*", i);
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function $(t, e, r) {
|
|
246
246
|
const i = E.get(t);
|
|
247
247
|
if (!i) {
|
|
248
248
|
o.warn(`Received response for unknown request: ${t}`);
|
|
@@ -250,14 +250,14 @@ function C(t, e, r) {
|
|
|
250
250
|
}
|
|
251
251
|
clearTimeout(i.timeout), E.delete(t), r ? i.reject(new Error(r)) : i.resolve(e);
|
|
252
252
|
}
|
|
253
|
-
function
|
|
253
|
+
function be(t = "SDK cleanup") {
|
|
254
254
|
E.forEach((e, r) => {
|
|
255
255
|
clearTimeout(e.timeout), e.reject(
|
|
256
256
|
new Error(`[EmbeddedSDK] Request ${r} cancelled: ${t}`)
|
|
257
257
|
);
|
|
258
258
|
}), E.clear();
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function R() {
|
|
261
261
|
const t = /* @__PURE__ */ new Set();
|
|
262
262
|
return {
|
|
263
263
|
subscribe(e) {
|
|
@@ -282,18 +282,18 @@ function A() {
|
|
|
282
282
|
}
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
|
-
const
|
|
286
|
-
class
|
|
285
|
+
const ye = "https://api.salla.dev";
|
|
286
|
+
class A extends Error {
|
|
287
287
|
constructor(e, r, i) {
|
|
288
288
|
super(e), this.status = r, this.response = i, this.name = "ApiError";
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
async function
|
|
292
|
-
const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, a = `${
|
|
291
|
+
async function Ee(t, e = {}) {
|
|
292
|
+
const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, a = `${ye}${t}`, l = new AbortController(), f = setTimeout(() => {
|
|
293
293
|
l.abort();
|
|
294
294
|
}, s);
|
|
295
295
|
try {
|
|
296
|
-
const
|
|
296
|
+
const c = await fetch(a, {
|
|
297
297
|
method: r,
|
|
298
298
|
headers: {
|
|
299
299
|
"Content-Type": "application/json",
|
|
@@ -304,18 +304,18 @@ async function pe(t, e = {}) {
|
|
|
304
304
|
});
|
|
305
305
|
clearTimeout(f);
|
|
306
306
|
let m;
|
|
307
|
-
if (
|
|
308
|
-
throw new
|
|
309
|
-
`API request failed: ${
|
|
310
|
-
|
|
307
|
+
if (c.headers.get("content-type")?.includes("application/json") ? m = await c.json() : m = await c.text(), !c.ok)
|
|
308
|
+
throw new A(
|
|
309
|
+
`API request failed: ${c.statusText}`,
|
|
310
|
+
c.status,
|
|
311
311
|
m
|
|
312
312
|
);
|
|
313
313
|
return m;
|
|
314
|
-
} catch (
|
|
315
|
-
throw clearTimeout(f),
|
|
314
|
+
} catch (c) {
|
|
315
|
+
throw clearTimeout(f), c instanceof A ? c : c instanceof Error ? c.name === "AbortError" ? new A(`Request timeout after ${s}ms`) : new A(`Request failed: ${c.message}`) : new A("Unknown error occurred");
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function x(t) {
|
|
319
319
|
return {
|
|
320
320
|
isVerified: !1,
|
|
321
321
|
isError: !0,
|
|
@@ -323,18 +323,18 @@ function k(t) {
|
|
|
323
323
|
data: null
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
|
-
async function
|
|
326
|
+
async function Te(t) {
|
|
327
327
|
const { token: e, appId: r, refreshOnError: i = !0 } = t;
|
|
328
328
|
if (!e) {
|
|
329
329
|
const n = "Token is required. Provide it as a parameter or in URL as ?token=XXX";
|
|
330
|
-
return o.error("Error in introspect:", n),
|
|
330
|
+
return o.error("Error in introspect:", n), x(n);
|
|
331
331
|
}
|
|
332
332
|
if (!r) {
|
|
333
333
|
const n = "App ID is required. Provide it as a parameter or in URL as ?app_id=XXX";
|
|
334
|
-
return o.error("Error in introspect:", n),
|
|
334
|
+
return o.error("Error in introspect:", n), x(n);
|
|
335
335
|
}
|
|
336
336
|
try {
|
|
337
|
-
const n = await
|
|
337
|
+
const n = await Ee(
|
|
338
338
|
"/exchange-authority/v1/introspect",
|
|
339
339
|
{
|
|
340
340
|
method: "POST",
|
|
@@ -357,12 +357,12 @@ async function ge(t) {
|
|
|
357
357
|
data: s ? n.data : null
|
|
358
358
|
};
|
|
359
359
|
} catch (n) {
|
|
360
|
-
i && (
|
|
360
|
+
i && (ie().ui.toast.error(n?.toString() ?? "Introspect error"), d(Z.REFRESH, {})), o.error("Error in introspect:", n);
|
|
361
361
|
const s = n instanceof Error ? n.message : n;
|
|
362
|
-
return
|
|
362
|
+
return x(s);
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
|
-
function
|
|
365
|
+
function Ie(t) {
|
|
366
366
|
return {
|
|
367
367
|
/**
|
|
368
368
|
* Get the token from the URL query parameter.
|
|
@@ -397,7 +397,7 @@ function ve(t) {
|
|
|
397
397
|
* ```
|
|
398
398
|
*/
|
|
399
399
|
refresh() {
|
|
400
|
-
|
|
400
|
+
d(Z.REFRESH, {});
|
|
401
401
|
},
|
|
402
402
|
/**
|
|
403
403
|
* Introspect (verify) a short-lived token with Salla's API.
|
|
@@ -408,7 +408,7 @@ function ve(t) {
|
|
|
408
408
|
*/
|
|
409
409
|
async introspect(e = {}) {
|
|
410
410
|
const r = e.token ?? this.getToken() ?? "", i = e.appId ?? this.getAppId() ?? "";
|
|
411
|
-
return
|
|
411
|
+
return Te({
|
|
412
412
|
token: r,
|
|
413
413
|
appId: i,
|
|
414
414
|
refreshOnError: e.refreshOnError
|
|
@@ -417,43 +417,49 @@ function ve(t) {
|
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
419
|
const F = ["success", "error", "warning", "info"];
|
|
420
|
-
function
|
|
420
|
+
function Se(t) {
|
|
421
421
|
const e = [];
|
|
422
422
|
return t.type === void 0 || t.type === null ? e.push("Toast type is required") : (typeof t.type != "string" || !F.includes(t.type)) && e.push(
|
|
423
423
|
`Invalid toast type "${t.type}". Expected: ${F.join(" | ")}`
|
|
424
424
|
), t.message === void 0 || t.message === null ? e.push("Toast message is required") : typeof t.message != "string" ? e.push("Toast message must be a string") : t.message.trim() === "" && e.push("Toast message cannot be empty"), t.duration !== void 0 && t.duration !== null && (typeof t.duration != "number" ? e.push("Toast duration must be a number") : t.duration < 0 && e.push("Toast duration cannot be negative")), { valid: e.length === 0, errors: e };
|
|
425
425
|
}
|
|
426
|
-
function
|
|
426
|
+
function G(t, e) {
|
|
427
427
|
const r = [];
|
|
428
428
|
return typeof t != "object" || t === null ? (r.push(`${e} must be an object`), r) : ((typeof t.type != "string" || t.type.trim() === "") && r.push(`${e} must have a valid type`), (typeof t.slug != "string" || t.slug.trim() === "") && r.push(`${e} must have a valid slug`), t.quantity !== void 0 && (typeof t.quantity != "number" || t.quantity < 1) && r.push(`${e} must have a quantity >= 1`), r);
|
|
429
429
|
}
|
|
430
|
-
|
|
430
|
+
const Ae = /^[A-Za-z0-9_-]+$/, B = 64, U = "checkout_id cannot be combined with item or items";
|
|
431
|
+
function we(t) {
|
|
432
|
+
return typeof t != "string" || t === "" ? ["checkout_id must be a non-empty string"] : t.length > B ? [`checkout_id must be at most ${B} characters`] : Ae.test(t) ? [] : ["checkout_id may only contain letters, numbers, '_' and '-'"];
|
|
433
|
+
}
|
|
434
|
+
function X(t) {
|
|
431
435
|
const e = [];
|
|
432
436
|
if (typeof t != "object" || t === null)
|
|
433
437
|
return e.push("Checkout options must be an object"), { valid: !1, errors: e };
|
|
434
438
|
const r = "item" in t, i = "items" in t;
|
|
439
|
+
if ("checkout_id" in t)
|
|
440
|
+
return r || i ? (e.push(U), { valid: !1, errors: e }) : (e.push(...we(t.checkout_id)), { valid: e.length === 0, errors: e });
|
|
435
441
|
if (!r && !i)
|
|
436
442
|
return e.push("Checkout requires either 'item' or 'items'"), { valid: !1, errors: e };
|
|
437
443
|
if (r) {
|
|
438
|
-
const n =
|
|
444
|
+
const n = G(
|
|
439
445
|
t.item,
|
|
440
446
|
"Item"
|
|
441
447
|
);
|
|
442
448
|
return e.push(...n), { valid: e.length === 0, errors: e };
|
|
443
449
|
}
|
|
444
450
|
return Array.isArray(t.items) ? t.items.length === 0 ? (e.push("At least one item is required"), { valid: !1, errors: e }) : (t.items.forEach((n, s) => {
|
|
445
|
-
const a =
|
|
451
|
+
const a = G(
|
|
446
452
|
n,
|
|
447
453
|
`Item at index ${s}`
|
|
448
454
|
);
|
|
449
455
|
e.push(...a);
|
|
450
456
|
}), { valid: e.length === 0, errors: e }) : (e.push("Checkout items must be an array"), { valid: !1, errors: e });
|
|
451
457
|
}
|
|
452
|
-
function
|
|
458
|
+
function Re(t) {
|
|
453
459
|
const e = [];
|
|
454
460
|
return t.path === void 0 || t.path === null ? e.push("Navigation path is required") : typeof t.path != "string" ? e.push("Navigation path must be a string") : t.path.trim() === "" && e.push("Navigation path cannot be empty"), t.replace !== void 0 && typeof t.replace != "boolean" && e.push("Navigation replace option must be a boolean"), { valid: e.length === 0, errors: e };
|
|
455
461
|
}
|
|
456
|
-
function
|
|
462
|
+
function _e(t) {
|
|
457
463
|
const e = [];
|
|
458
464
|
if (t.url === void 0 || t.url === null)
|
|
459
465
|
e.push("Redirect URL is required");
|
|
@@ -469,7 +475,7 @@ function Te(t) {
|
|
|
469
475
|
}
|
|
470
476
|
return { valid: e.length === 0, errors: e };
|
|
471
477
|
}
|
|
472
|
-
function
|
|
478
|
+
function Ne(t) {
|
|
473
479
|
const e = [];
|
|
474
480
|
return t.title ? typeof t.title != "string" && e.push("Nav action title must be a string") : e.push("Nav action title is required"), t.value ? typeof t.value != "string" && e.push("Nav action value must be a string") : e.push("Nav action value is required"), t.subTitle !== void 0 && t.subTitle !== null && typeof t.subTitle != "string" && e.push("Nav action subTitle must be a string"), t.icon !== void 0 && t.icon !== null && typeof t.icon != "string" && e.push("Nav action icon must be a string"), t.disabled !== void 0 && t.disabled !== null && typeof t.disabled != "boolean" && e.push("Nav action disabled must be a boolean"), t.extendedActions !== void 0 && t.extendedActions !== null && (Array.isArray(t.extendedActions) ? t.extendedActions.forEach((r, i) => {
|
|
475
481
|
if (typeof r != "object" || r === null) {
|
|
@@ -490,26 +496,26 @@ function Ie(t) {
|
|
|
490
496
|
);
|
|
491
497
|
}) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
|
|
492
498
|
}
|
|
493
|
-
const
|
|
494
|
-
function
|
|
499
|
+
const D = 50;
|
|
500
|
+
function _(t, e) {
|
|
495
501
|
return t ? `${t}.${e}` : e;
|
|
496
502
|
}
|
|
497
|
-
function
|
|
503
|
+
function Ce(t, e) {
|
|
498
504
|
const r = [];
|
|
499
505
|
["title", "value", "url"].forEach((s) => {
|
|
500
506
|
(typeof t[s] != "string" || !String(t[s]).trim()) && r.push(
|
|
501
|
-
`Sub-nav addItem "${
|
|
507
|
+
`Sub-nav addItem "${_(e, s)}" must be non-empty string`
|
|
502
508
|
);
|
|
503
509
|
});
|
|
504
|
-
const i =
|
|
510
|
+
const i = _(e, "disabled"), n = _(e, "active");
|
|
505
511
|
return t.disabled !== void 0 && typeof t.disabled != "boolean" && r.push(`Sub-nav addItem "${i}" must be boolean`), t.active !== void 0 && typeof t.active != "boolean" && r.push(`Sub-nav addItem "${n}" must be boolean`), r;
|
|
506
512
|
}
|
|
507
513
|
function z(t, e, r) {
|
|
508
514
|
if (typeof t != "object" || t === null)
|
|
509
515
|
return [`Sub-nav addItem "${e || "item"}" must be an object`];
|
|
510
|
-
const i = t, n =
|
|
511
|
-
return i.children === void 0 ? n : r ? Array.isArray(i.children) ? i.children.length >
|
|
512
|
-
`Sub-nav addItem "${s}" must have at most ${
|
|
516
|
+
const i = t, n = Ce(i, e), s = _(e, "children");
|
|
517
|
+
return i.children === void 0 ? n : r ? Array.isArray(i.children) ? i.children.length > D ? (n.push(
|
|
518
|
+
`Sub-nav addItem "${s}" must have at most ${D} items`
|
|
513
519
|
), n) : (i.children.forEach((a, l) => {
|
|
514
520
|
const f = e ? `${e}.children[${l}]` : `children[${l}]`;
|
|
515
521
|
n.push(...z(a, f, !1));
|
|
@@ -517,24 +523,24 @@ function z(t, e, r) {
|
|
|
517
523
|
`Sub-nav addItem "${s}" is not supported on submenu rows (only one dropdown level)`
|
|
518
524
|
), n);
|
|
519
525
|
}
|
|
520
|
-
function
|
|
526
|
+
function re(t, e, r, i) {
|
|
521
527
|
if (typeof t != "object" || t === null)
|
|
522
528
|
return i;
|
|
523
529
|
const n = t;
|
|
524
530
|
return typeof n.value == "string" && n.value.trim() && i.push(n.value.trim()), !r || !Array.isArray(n.children) || n.children.forEach((s, a) => {
|
|
525
531
|
const l = e ? `${e}.children[${a}]` : `children[${a}]`;
|
|
526
|
-
|
|
532
|
+
re(s, l, !1, i);
|
|
527
533
|
}), i;
|
|
528
534
|
}
|
|
529
|
-
function
|
|
530
|
-
const e =
|
|
535
|
+
function $e(t) {
|
|
536
|
+
const e = re(t, "", !0, []), r = /* @__PURE__ */ new Set(), i = [];
|
|
531
537
|
for (const n of e)
|
|
532
538
|
r.has(n) && i.push(n), r.add(n);
|
|
533
539
|
return i.length === 0 ? [] : [
|
|
534
540
|
`Sub-nav addItem "value" must be globally unique within the item tree (duplicate: ${[...new Set(i)].join(", ")})`
|
|
535
541
|
];
|
|
536
542
|
}
|
|
537
|
-
function
|
|
543
|
+
function De(t) {
|
|
538
544
|
if (typeof t != "object" || t === null)
|
|
539
545
|
return {
|
|
540
546
|
valid: !1,
|
|
@@ -542,11 +548,11 @@ function Ae(t) {
|
|
|
542
548
|
};
|
|
543
549
|
const e = [
|
|
544
550
|
...z(t, "", !0),
|
|
545
|
-
|
|
551
|
+
...$e(t)
|
|
546
552
|
];
|
|
547
553
|
return { valid: e.length === 0, errors: e };
|
|
548
554
|
}
|
|
549
|
-
function
|
|
555
|
+
function Me(t) {
|
|
550
556
|
const e = [];
|
|
551
557
|
if (typeof t != "object" || t === null)
|
|
552
558
|
return e.push("Nav updateItem expects an object item"), { valid: !1, errors: e };
|
|
@@ -563,43 +569,43 @@ function Re(t) {
|
|
|
563
569
|
return e.push(
|
|
564
570
|
"Sub-nav updateItem must include at least one of title, url, disabled, active, children"
|
|
565
571
|
), { valid: !1, errors: e };
|
|
566
|
-
if (["title", "url"].forEach((
|
|
567
|
-
r[
|
|
572
|
+
if (["title", "url"].forEach((c) => {
|
|
573
|
+
r[c] !== void 0 && (typeof r[c] != "string" || !r[c].trim()) && e.push(`Sub-nav updateItem "${c}" must be non-empty`);
|
|
568
574
|
}), r.disabled !== void 0 && typeof r.disabled != "boolean" && e.push('Sub-nav updateItem "disabled" must be boolean'), r.active !== void 0 && typeof r.active != "boolean" && e.push('Sub-nav updateItem "active" must be boolean'), r.children !== void 0)
|
|
569
575
|
if (!Array.isArray(r.children))
|
|
570
576
|
e.push('Sub-nav updateItem "children" must be an array');
|
|
571
|
-
else if (r.children.length >
|
|
577
|
+
else if (r.children.length > D)
|
|
572
578
|
e.push(
|
|
573
|
-
`Sub-nav updateItem "children" must have at most ${
|
|
579
|
+
`Sub-nav updateItem "children" must have at most ${D} items`
|
|
574
580
|
);
|
|
575
581
|
else {
|
|
576
|
-
const
|
|
577
|
-
r.children.forEach((m,
|
|
578
|
-
const
|
|
579
|
-
if (e.push(...z(m,
|
|
580
|
-
const
|
|
581
|
-
if (typeof
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
`Sub-nav updateItem "${
|
|
585
|
-
),
|
|
586
|
-
`Sub-nav updateItem "${
|
|
587
|
-
),
|
|
582
|
+
const c = /* @__PURE__ */ new Set();
|
|
583
|
+
r.children.forEach((m, P) => {
|
|
584
|
+
const O = `children[${P}]`;
|
|
585
|
+
if (e.push(...z(m, O, !1)), typeof m == "object" && m !== null) {
|
|
586
|
+
const L = m.value;
|
|
587
|
+
if (typeof L == "string" && L.trim()) {
|
|
588
|
+
const k = L.trim();
|
|
589
|
+
k === l && e.push(
|
|
590
|
+
`Sub-nav updateItem "${O}.value" must not equal the parent row identifier`
|
|
591
|
+
), c.has(k) && e.push(
|
|
592
|
+
`Sub-nav updateItem "${O}.value" must be unique within children`
|
|
593
|
+
), c.add(k);
|
|
588
594
|
}
|
|
589
595
|
}
|
|
590
596
|
});
|
|
591
597
|
}
|
|
592
598
|
return { valid: e.length === 0, errors: e };
|
|
593
599
|
}
|
|
594
|
-
function
|
|
600
|
+
function Oe(t) {
|
|
595
601
|
const e = [];
|
|
596
602
|
return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem value must be non-empty string"), { valid: e.length === 0, errors: e };
|
|
597
603
|
}
|
|
598
|
-
const
|
|
599
|
-
function
|
|
604
|
+
const W = ["danger", "warning", "info"];
|
|
605
|
+
function Le(t) {
|
|
600
606
|
const e = [];
|
|
601
|
-
return t.title === void 0 || t.title === null ? e.push("Confirm dialog title is required") : typeof t.title != "string" ? e.push("Confirm dialog title must be a string") : t.title.trim() === "" && e.push("Confirm dialog title cannot be empty"), t.message === void 0 || t.message === null ? e.push("Confirm dialog message is required") : typeof t.message != "string" ? e.push("Confirm dialog message must be a string") : t.message.trim() === "" && e.push("Confirm dialog message cannot be empty"), t.confirmText !== void 0 && t.confirmText !== null && typeof t.confirmText != "string" && e.push("Confirm dialog confirmText must be a string"), t.cancelText !== void 0 && t.cancelText !== null && typeof t.cancelText != "string" && e.push("Confirm dialog cancelText must be a string"), t.variant !== void 0 && t.variant !== null && (typeof t.variant != "string" || !
|
|
602
|
-
`Invalid confirm variant "${t.variant}". Expected: ${
|
|
607
|
+
return t.title === void 0 || t.title === null ? e.push("Confirm dialog title is required") : typeof t.title != "string" ? e.push("Confirm dialog title must be a string") : t.title.trim() === "" && e.push("Confirm dialog title cannot be empty"), t.message === void 0 || t.message === null ? e.push("Confirm dialog message is required") : typeof t.message != "string" ? e.push("Confirm dialog message must be a string") : t.message.trim() === "" && e.push("Confirm dialog message cannot be empty"), t.confirmText !== void 0 && t.confirmText !== null && typeof t.confirmText != "string" && e.push("Confirm dialog confirmText must be a string"), t.cancelText !== void 0 && t.cancelText !== null && typeof t.cancelText != "string" && e.push("Confirm dialog cancelText must be a string"), t.variant !== void 0 && t.variant !== null && (typeof t.variant != "string" || !W.includes(t.variant)) && e.push(
|
|
608
|
+
`Invalid confirm variant "${t.variant}". Expected: ${W.join(" | ")}`
|
|
603
609
|
), { valid: e.length === 0, errors: e };
|
|
604
610
|
}
|
|
605
611
|
function p(t, e) {
|
|
@@ -609,34 +615,34 @@ function p(t, e) {
|
|
|
609
615
|
`)
|
|
610
616
|
);
|
|
611
617
|
}
|
|
612
|
-
function
|
|
618
|
+
function ke() {
|
|
613
619
|
return { resize: (i) => {
|
|
614
620
|
}, autoResize: () => {
|
|
615
621
|
}, stopAutoResize: () => {
|
|
616
622
|
} };
|
|
617
623
|
}
|
|
618
|
-
function
|
|
619
|
-
const { resize: t, autoResize: e, stopAutoResize: r } =
|
|
624
|
+
function qe() {
|
|
625
|
+
const { resize: t, autoResize: e, stopAutoResize: r } = ke();
|
|
620
626
|
return {
|
|
621
627
|
navigate(i, n) {
|
|
622
|
-
const s =
|
|
628
|
+
const s = Re({ path: i, ...n });
|
|
623
629
|
if (!s.valid) {
|
|
624
630
|
p(T.NAVIGATE, s.errors);
|
|
625
631
|
return;
|
|
626
632
|
}
|
|
627
|
-
|
|
633
|
+
d(T.NAVIGATE, {
|
|
628
634
|
path: i,
|
|
629
635
|
state: n?.state,
|
|
630
636
|
replace: n?.replace
|
|
631
637
|
});
|
|
632
638
|
},
|
|
633
639
|
redirect(i) {
|
|
634
|
-
const n =
|
|
640
|
+
const n = _e({ url: i });
|
|
635
641
|
if (!n.valid) {
|
|
636
642
|
p(T.REDIRECT, n.errors);
|
|
637
643
|
return;
|
|
638
644
|
}
|
|
639
|
-
|
|
645
|
+
d(T.REDIRECT, { url: i });
|
|
640
646
|
},
|
|
641
647
|
navTo(i, n) {
|
|
642
648
|
if (i.startsWith("http://") || i.startsWith("https://")) {
|
|
@@ -652,26 +658,26 @@ function _e() {
|
|
|
652
658
|
]);
|
|
653
659
|
return;
|
|
654
660
|
}
|
|
655
|
-
|
|
661
|
+
d(T.SET_TITLE, { title: i });
|
|
656
662
|
},
|
|
657
663
|
resize: t,
|
|
658
664
|
autoResize: e,
|
|
659
665
|
stopAutoResize: r
|
|
660
666
|
};
|
|
661
667
|
}
|
|
662
|
-
function
|
|
663
|
-
const t =
|
|
668
|
+
function xe() {
|
|
669
|
+
const t = R(), e = R(), r = [];
|
|
664
670
|
return r.push(
|
|
665
|
-
|
|
671
|
+
y(h.ACTION_CLICK, (i) => {
|
|
666
672
|
t.notify(i.payload.value);
|
|
667
673
|
})
|
|
668
674
|
), r.push(
|
|
669
|
-
|
|
675
|
+
y(h.ADD_ITEM_RESPONSE, (i) => {
|
|
670
676
|
if (!i.requestId) return;
|
|
671
677
|
const n = i.payload;
|
|
672
678
|
if (typeof n.error == "string" && n.error.trim()) {
|
|
673
679
|
const a = n.error.trim();
|
|
674
|
-
o.warn(`embedded::nav.addItem failed: ${a}`),
|
|
680
|
+
o.warn(`embedded::nav.addItem failed: ${a}`), $(
|
|
675
681
|
i.requestId,
|
|
676
682
|
{},
|
|
677
683
|
a
|
|
@@ -684,11 +690,11 @@ function De() {
|
|
|
684
690
|
value: a,
|
|
685
691
|
id: a
|
|
686
692
|
};
|
|
687
|
-
|
|
693
|
+
$(i.requestId, l);
|
|
688
694
|
}
|
|
689
695
|
})
|
|
690
696
|
), r.push(
|
|
691
|
-
|
|
697
|
+
y(h.ITEM_CLICK, (i) => {
|
|
692
698
|
const n = i.payload, s = typeof n.value == "string" && n.value.trim() ? n.value.trim() : typeof n.id == "string" && n.id.trim() ? n.id.trim() : "";
|
|
693
699
|
if (!s) {
|
|
694
700
|
e.notify(n);
|
|
@@ -702,12 +708,12 @@ function De() {
|
|
|
702
708
|
})
|
|
703
709
|
), {
|
|
704
710
|
setAction(i) {
|
|
705
|
-
const n =
|
|
711
|
+
const n = Ne(i);
|
|
706
712
|
if (!n.valid) {
|
|
707
713
|
p(h.SET_ACTION, n.errors);
|
|
708
714
|
return;
|
|
709
715
|
}
|
|
710
|
-
|
|
716
|
+
d(h.SET_ACTION, {
|
|
711
717
|
title: i.title,
|
|
712
718
|
value: i.value,
|
|
713
719
|
subTitle: i.subTitle,
|
|
@@ -723,33 +729,33 @@ function De() {
|
|
|
723
729
|
});
|
|
724
730
|
},
|
|
725
731
|
clearAction() {
|
|
726
|
-
|
|
732
|
+
d(h.CLEAR_ACTION, {});
|
|
727
733
|
},
|
|
728
734
|
onActionClick(i) {
|
|
729
735
|
return t.subscribe(i);
|
|
730
736
|
},
|
|
731
737
|
addNavItem(i) {
|
|
732
|
-
const n =
|
|
733
|
-
return n.valid ?
|
|
738
|
+
const n = De(i);
|
|
739
|
+
return n.valid ? V(h.ADD_ITEM, { item: i }, 2e3) : (p(h.ADD_ITEM, n.errors), Promise.reject(new Error(n.errors[0])));
|
|
734
740
|
},
|
|
735
741
|
updateNavItem(i) {
|
|
736
|
-
const n =
|
|
742
|
+
const n = Me(i);
|
|
737
743
|
if (!n.valid) {
|
|
738
744
|
p(h.UPDATE_ITEM, n.errors);
|
|
739
745
|
return;
|
|
740
746
|
}
|
|
741
|
-
const s = i, a = typeof s.value == "string" ? s.value.trim() : "", l = typeof s.id == "string" ? s.id.trim() : "", f = a || l, { id:
|
|
742
|
-
|
|
747
|
+
const s = i, a = typeof s.value == "string" ? s.value.trim() : "", l = typeof s.id == "string" ? s.id.trim() : "", f = a || l, { id: c, ...m } = s;
|
|
748
|
+
d(h.UPDATE_ITEM, {
|
|
743
749
|
item: { ...m, value: f }
|
|
744
750
|
});
|
|
745
751
|
},
|
|
746
752
|
removeNavItem(i) {
|
|
747
|
-
const n =
|
|
753
|
+
const n = Oe(i);
|
|
748
754
|
if (!n.valid) {
|
|
749
755
|
p(h.REMOVE_ITEM, n.errors);
|
|
750
756
|
return;
|
|
751
757
|
}
|
|
752
|
-
|
|
758
|
+
d(h.REMOVE_ITEM, { value: i });
|
|
753
759
|
},
|
|
754
760
|
onNavItemClick(i) {
|
|
755
761
|
return e.subscribe(i);
|
|
@@ -759,40 +765,40 @@ function De() {
|
|
|
759
765
|
}
|
|
760
766
|
};
|
|
761
767
|
}
|
|
762
|
-
function
|
|
768
|
+
function Ue() {
|
|
763
769
|
return {
|
|
764
770
|
/**
|
|
765
771
|
* Show loading indicator.
|
|
766
772
|
*/
|
|
767
773
|
show() {
|
|
768
|
-
|
|
774
|
+
d(g.LOADING, { action: "show" });
|
|
769
775
|
},
|
|
770
776
|
/**
|
|
771
777
|
* Hide loading indicator.
|
|
772
778
|
*/
|
|
773
779
|
hide() {
|
|
774
|
-
|
|
780
|
+
d(g.LOADING, { action: "hide" });
|
|
775
781
|
}
|
|
776
782
|
};
|
|
777
783
|
}
|
|
778
|
-
function
|
|
784
|
+
function Ve() {
|
|
779
785
|
return {
|
|
780
786
|
hide() {
|
|
781
|
-
|
|
787
|
+
d(g.BREADCRUMBS, { action: "hide" });
|
|
782
788
|
},
|
|
783
789
|
show() {
|
|
784
|
-
|
|
790
|
+
d(g.BREADCRUMBS, { action: "show" });
|
|
785
791
|
}
|
|
786
792
|
};
|
|
787
793
|
}
|
|
788
|
-
function
|
|
794
|
+
function ze() {
|
|
789
795
|
const t = (e) => {
|
|
790
|
-
const r =
|
|
796
|
+
const r = Se(e);
|
|
791
797
|
if (!r.valid) {
|
|
792
798
|
p(g.TOAST, r.errors);
|
|
793
799
|
return;
|
|
794
800
|
}
|
|
795
|
-
|
|
801
|
+
d(g.TOAST, {
|
|
796
802
|
type: e.type,
|
|
797
803
|
message: e.message,
|
|
798
804
|
duration: e.duration
|
|
@@ -829,10 +835,10 @@ function Le() {
|
|
|
829
835
|
}
|
|
830
836
|
};
|
|
831
837
|
}
|
|
832
|
-
function
|
|
838
|
+
function Pe() {
|
|
833
839
|
return async (t) => {
|
|
834
|
-
const e =
|
|
835
|
-
return e.valid ?
|
|
840
|
+
const e = Le(t);
|
|
841
|
+
return e.valid ? V(g.CONFIRM, {
|
|
836
842
|
title: t.title,
|
|
837
843
|
message: t.message,
|
|
838
844
|
confirmText: t.confirmText ?? "Confirm",
|
|
@@ -841,31 +847,41 @@ function qe() {
|
|
|
841
847
|
}) : (p(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
|
|
842
848
|
};
|
|
843
849
|
}
|
|
844
|
-
function
|
|
850
|
+
function je() {
|
|
845
851
|
return {
|
|
846
|
-
loading:
|
|
847
|
-
breadcrumbs:
|
|
848
|
-
toast:
|
|
849
|
-
confirm:
|
|
852
|
+
loading: Ue(),
|
|
853
|
+
breadcrumbs: Ve(),
|
|
854
|
+
toast: ze(),
|
|
855
|
+
confirm: Pe()
|
|
850
856
|
};
|
|
851
857
|
}
|
|
852
|
-
|
|
853
|
-
|
|
858
|
+
const He = "INVALID_CHECKOUT_INPUT";
|
|
859
|
+
function w(t) {
|
|
860
|
+
const e = new Error(t);
|
|
861
|
+
return e.code = He, e;
|
|
862
|
+
}
|
|
863
|
+
const Ke = ["type", "slug", "quantity"];
|
|
864
|
+
function Y(t) {
|
|
865
|
+
return typeof t == "object" && t !== null && !Array.isArray(t) && "checkout_id" in t && t.checkout_id !== void 0;
|
|
866
|
+
}
|
|
867
|
+
function Fe() {
|
|
868
|
+
const t = R(), e = [];
|
|
854
869
|
return e.push(
|
|
855
|
-
|
|
870
|
+
y(v.RESPONSE, (r) => {
|
|
856
871
|
t.notify({
|
|
857
872
|
success: r.payload.success,
|
|
858
873
|
order_id: r.payload.order_id,
|
|
874
|
+
checkout_id: r.payload.checkout_id,
|
|
859
875
|
status: r.payload.status,
|
|
860
876
|
error: r.payload.error,
|
|
861
877
|
context: r.payload.context
|
|
862
878
|
});
|
|
863
879
|
})
|
|
864
880
|
), e.push(
|
|
865
|
-
|
|
866
|
-
|
|
881
|
+
y(
|
|
882
|
+
v.GET_ADDONS_RESPONSE,
|
|
867
883
|
(r) => {
|
|
868
|
-
r.requestId &&
|
|
884
|
+
r.requestId && $(r.requestId, {
|
|
869
885
|
success: r.payload.success,
|
|
870
886
|
addons: r.payload.addons,
|
|
871
887
|
error: r.payload.error
|
|
@@ -874,21 +890,42 @@ function xe() {
|
|
|
874
890
|
)
|
|
875
891
|
), {
|
|
876
892
|
create(r, i) {
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
893
|
+
if (Array.isArray(r) && r.some((s) => Y(s)))
|
|
894
|
+
throw w(U);
|
|
895
|
+
let n;
|
|
896
|
+
if (Y(r)) {
|
|
897
|
+
if ("context" in r)
|
|
898
|
+
throw w(
|
|
899
|
+
"context must be passed as the second argument (config.context)"
|
|
900
|
+
);
|
|
901
|
+
if (Ke.some((a) => a in r))
|
|
902
|
+
throw w(U);
|
|
903
|
+
const s = X(
|
|
904
|
+
r
|
|
905
|
+
);
|
|
906
|
+
if (!s.valid)
|
|
907
|
+
throw p(v.CREATE, s.errors), w(s.errors[0]);
|
|
908
|
+
n = { checkout_id: r.checkout_id };
|
|
909
|
+
} else {
|
|
910
|
+
const s = Array.isArray(r) ? r : [r], a = X({ items: s });
|
|
911
|
+
if (!a.valid)
|
|
912
|
+
throw p(v.CREATE, a.errors), w(a.errors[0]);
|
|
913
|
+
n = {
|
|
914
|
+
items: s.map((l) => ({
|
|
915
|
+
type: l.type,
|
|
916
|
+
slug: l.slug,
|
|
917
|
+
quantity: l.quantity ?? 1
|
|
918
|
+
}))
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
d(
|
|
922
|
+
v.CREATE,
|
|
882
923
|
{
|
|
883
|
-
|
|
884
|
-
type: a.type,
|
|
885
|
-
slug: a.slug,
|
|
886
|
-
quantity: a.quantity ?? 1
|
|
887
|
-
})),
|
|
924
|
+
...n,
|
|
888
925
|
...i?.context !== void 0 && { context: i.context }
|
|
889
926
|
},
|
|
890
927
|
"*",
|
|
891
|
-
|
|
928
|
+
te()
|
|
892
929
|
);
|
|
893
930
|
},
|
|
894
931
|
onResult(r) {
|
|
@@ -896,8 +933,8 @@ function xe() {
|
|
|
896
933
|
},
|
|
897
934
|
async getAddons() {
|
|
898
935
|
try {
|
|
899
|
-
return await
|
|
900
|
-
|
|
936
|
+
return await V(
|
|
937
|
+
v.GET_ADDONS,
|
|
901
938
|
{},
|
|
902
939
|
3e4
|
|
903
940
|
);
|
|
@@ -912,28 +949,29 @@ function xe() {
|
|
|
912
949
|
}
|
|
913
950
|
},
|
|
914
951
|
resetCache() {
|
|
915
|
-
|
|
952
|
+
d(v.RESET_CACHE, {}, "*");
|
|
916
953
|
},
|
|
917
954
|
destroy() {
|
|
918
955
|
e.forEach((r) => r()), e.length = 0, t.clear();
|
|
919
956
|
}
|
|
920
957
|
};
|
|
921
958
|
}
|
|
922
|
-
const
|
|
959
|
+
const Q = {
|
|
923
960
|
theme: "light",
|
|
924
961
|
dir: "rtl",
|
|
925
962
|
width: 0,
|
|
926
963
|
locale: "ar",
|
|
927
964
|
currency: "SAR"
|
|
928
965
|
};
|
|
929
|
-
class
|
|
966
|
+
class Ge {
|
|
930
967
|
constructor() {
|
|
931
|
-
this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...
|
|
968
|
+
this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...Q }, this.postInitHooks = [], this.themeSubscription = R(), this.initSubscription = R(), this.auth = Ie(), this.page = qe(), this.nav = xe(), this.ui = je(), this.checkout = Fe(), this.registerPostInitHook((e) => {
|
|
932
969
|
const r = e.payload.pendingCheckoutResult;
|
|
933
970
|
r && (o.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
|
|
934
|
-
|
|
971
|
+
ge(v.RESPONSE, {
|
|
935
972
|
success: r.success,
|
|
936
973
|
status: r.status,
|
|
974
|
+
checkout_id: r.checkout_id,
|
|
937
975
|
error: r.error,
|
|
938
976
|
context: r.context
|
|
939
977
|
});
|
|
@@ -951,10 +989,10 @@ class ze {
|
|
|
951
989
|
* Set up core event listeners.
|
|
952
990
|
*/
|
|
953
991
|
setupListeners() {
|
|
954
|
-
|
|
992
|
+
y(j.THEME_CHANGE, (e) => {
|
|
955
993
|
this.layout.theme = e.payload.theme, o.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
|
|
956
|
-
}),
|
|
957
|
-
o.debug("Received confirm response:", e), e.requestId &&
|
|
994
|
+
}), y(g.CONFIRM_RESPONSE, (e) => {
|
|
995
|
+
o.debug("Received confirm response:", e), e.requestId && $(e.requestId, { confirmed: e.payload.confirmed });
|
|
958
996
|
});
|
|
959
997
|
}
|
|
960
998
|
/**
|
|
@@ -1003,7 +1041,7 @@ class ze {
|
|
|
1003
1041
|
o.warn("Cannot signal ready before init() is called");
|
|
1004
1042
|
return;
|
|
1005
1043
|
}
|
|
1006
|
-
this.appReady = !0,
|
|
1044
|
+
this.appReady = !0, d(q.READY, {}), o.debug("Sent ready signal to host");
|
|
1007
1045
|
}
|
|
1008
1046
|
/**
|
|
1009
1047
|
* Initialize the SDK and establish connection with the host.
|
|
@@ -1017,19 +1055,19 @@ class ze {
|
|
|
1017
1055
|
i(), r({ layout: { ...n.layout } });
|
|
1018
1056
|
});
|
|
1019
1057
|
});
|
|
1020
|
-
this.initializing = !0, this.debugMode = e.debug ?? !1,
|
|
1058
|
+
this.initializing = !0, this.debugMode = e.debug ?? !1, ce({ debug: this.debugMode }), pe() || o.warn("Not running in an iframe. Some features may not work."), o.debug("Initializing SDK...");
|
|
1021
1059
|
try {
|
|
1022
|
-
|
|
1060
|
+
d(q.INIT, {
|
|
1023
1061
|
height: document.documentElement.scrollHeight
|
|
1024
1062
|
}), o.debug("Sent iframe.ready message, waiting for context...");
|
|
1025
|
-
const r = await
|
|
1026
|
-
|
|
1063
|
+
const r = await he(
|
|
1064
|
+
j.PROVIDE
|
|
1027
1065
|
);
|
|
1028
1066
|
o.debug("Received context from host:", r);
|
|
1029
1067
|
const { layout: i } = r.payload;
|
|
1030
1068
|
return this.layout = {
|
|
1031
1069
|
theme: i?.theme ?? "light",
|
|
1032
|
-
dir: i?.dir ??
|
|
1070
|
+
dir: i?.dir ?? ue(i?.locale),
|
|
1033
1071
|
width: i?.width ?? 0,
|
|
1034
1072
|
locale: i?.locale ?? "ar",
|
|
1035
1073
|
currency: i?.currency ?? "SAR"
|
|
@@ -1048,23 +1086,24 @@ class ze {
|
|
|
1048
1086
|
* Destroy the SDK instance and clean up resources.
|
|
1049
1087
|
*/
|
|
1050
1088
|
destroy() {
|
|
1051
|
-
o.debug("Destroying SDK instance"), this.initialized && (
|
|
1089
|
+
o.debug("Destroying SDK instance"), this.initialized && (d(q.DESTROY, {}), o.debug("Sent destroy event to host")), this.checkout.destroy(), this.nav.destroy(), be("SDK destroyed"), me(), this.themeSubscription.clear(), this.initSubscription.clear(), this.postInitHooks = [], this.initialized = !1, this.initializing = !1, this.appReady = !1, this.layout = { ...Q };
|
|
1052
1090
|
}
|
|
1053
1091
|
}
|
|
1054
1092
|
let I = null;
|
|
1055
|
-
function
|
|
1056
|
-
return I || (I = new
|
|
1093
|
+
function ie() {
|
|
1094
|
+
return I || (I = new Ge()), I;
|
|
1057
1095
|
}
|
|
1058
|
-
function
|
|
1096
|
+
function Be() {
|
|
1059
1097
|
I && (I.destroy(), I = null);
|
|
1060
1098
|
}
|
|
1061
|
-
const
|
|
1062
|
-
typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded =
|
|
1099
|
+
const J = ie(), Xe = M;
|
|
1100
|
+
typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = J), window.Salla.embedded || (window.Salla.embedded = J));
|
|
1063
1101
|
export {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
J as
|
|
1067
|
-
|
|
1068
|
-
|
|
1102
|
+
Ge as EmbeddedApp,
|
|
1103
|
+
He as INVALID_CHECKOUT_INPUT,
|
|
1104
|
+
J as embedded,
|
|
1105
|
+
ie as getEmbeddedApp,
|
|
1106
|
+
Be as resetEmbeddedApp,
|
|
1107
|
+
Xe as version
|
|
1069
1108
|
};
|
|
1070
1109
|
//# sourceMappingURL=index.js.map
|