@salla.sa/embedded-sdk 0.2.3 → 0.2.4
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 +142 -165
- 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 +7 -23
- 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
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
const o = "embedded::",
|
|
1
|
+
const o = "embedded::", $ = {
|
|
2
2
|
/** Initialize handshake - iframe signals it's ready to receive context */
|
|
3
3
|
INIT: `${o}iframe.ready`,
|
|
4
|
-
/** Request iframe resize */
|
|
5
|
-
RESIZE: `${o}iframe.resize`,
|
|
6
4
|
/** App signals it's fully loaded and ready */
|
|
7
5
|
READY: `${o}ready`,
|
|
8
6
|
/** App requests to be destroyed and navigate away */
|
|
@@ -24,21 +22,21 @@ const o = "embedded::", v = {
|
|
|
24
22
|
}, K = {}, U = {
|
|
25
23
|
/** Request token refresh (re-renders iframe with new token) */
|
|
26
24
|
REFRESH: `${o}auth.refresh`
|
|
27
|
-
},
|
|
25
|
+
}, p = {
|
|
28
26
|
/** Navigate using React Router (SPA navigation) */
|
|
29
27
|
NAVIGATE: `${o}page.navigate`,
|
|
30
28
|
/** Redirect using window.location (full page reload) */
|
|
31
29
|
REDIRECT: `${o}page.redirect`,
|
|
32
30
|
/** Set page title */
|
|
33
31
|
SET_TITLE: `${o}page.setTitle`
|
|
34
|
-
},
|
|
32
|
+
}, w = {
|
|
35
33
|
/** Set primary action button in navbar */
|
|
36
34
|
SET_ACTION: `${o}nav.setAction`,
|
|
37
35
|
/** Clear the primary action button */
|
|
38
36
|
CLEAR_ACTION: `${o}nav.clearAction`,
|
|
39
37
|
/** Notification when action button is clicked (host → iframe) */
|
|
40
38
|
ACTION_CLICK: `${o}nav.actionClick`
|
|
41
|
-
},
|
|
39
|
+
}, m = {
|
|
42
40
|
/** Create checkout flow */
|
|
43
41
|
CREATE: `${o}checkout.create`,
|
|
44
42
|
/** Checkout response from host */
|
|
@@ -47,19 +45,19 @@ const o = "embedded::", v = {
|
|
|
47
45
|
GET_ADDONS: `${o}checkout.getAddons`,
|
|
48
46
|
/** Get addons response from host */
|
|
49
47
|
GET_ADDONS_RESPONSE: `${o}checkout.getAddons.response`
|
|
50
|
-
},
|
|
48
|
+
}, I = K.version || "", X = 1e4, W = [
|
|
51
49
|
"localhost",
|
|
52
50
|
"merchants.workers.dev",
|
|
53
51
|
"s.salla.sa",
|
|
54
52
|
".salla.group",
|
|
55
53
|
".salla.sa"
|
|
56
54
|
];
|
|
57
|
-
let
|
|
55
|
+
let S = {
|
|
58
56
|
showVersion: !0,
|
|
59
57
|
debug: !1
|
|
60
58
|
};
|
|
61
59
|
function Y(t) {
|
|
62
|
-
|
|
60
|
+
S = { ...S, ...t };
|
|
63
61
|
}
|
|
64
62
|
function D(t) {
|
|
65
63
|
return `%c${t}`;
|
|
@@ -68,10 +66,10 @@ function L(t, e = "#fff") {
|
|
|
68
66
|
return `background-color: ${t}; color: ${e}; padding: 2px 6px; border-radius: 3px; font-weight: 500; font-size: 11px;`;
|
|
69
67
|
}
|
|
70
68
|
function b(t, ...e) {
|
|
71
|
-
if (t === "debug" && !
|
|
69
|
+
if (t === "debug" && !S.debug)
|
|
72
70
|
return;
|
|
73
71
|
const r = [], i = [];
|
|
74
|
-
r.push(D("EmbeddedSDK")), i.push(L("#10b981", "#fff")),
|
|
72
|
+
r.push(D("EmbeddedSDK")), i.push(L("#10b981", "#fff")), S.showVersion && (r.push(D(`v${I}`)), i.push(L("#6b7280", "#fff")));
|
|
75
73
|
const n = r.join("").trim();
|
|
76
74
|
(console[t] || console.log)(n, ...i, ...e);
|
|
77
75
|
}
|
|
@@ -100,29 +98,29 @@ function B(t) {
|
|
|
100
98
|
return !1;
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
|
-
function
|
|
101
|
+
function Q() {
|
|
104
102
|
return typeof window > "u" || window.parent === window ? null : window.parent;
|
|
105
103
|
}
|
|
106
|
-
function
|
|
107
|
-
const s =
|
|
104
|
+
function c(t, e, r = "*", i, n) {
|
|
105
|
+
const s = Q();
|
|
108
106
|
if (!s) {
|
|
109
107
|
a.warn("Not running in an iframe, cannot post to host");
|
|
110
108
|
return;
|
|
111
109
|
}
|
|
112
|
-
const
|
|
110
|
+
const u = {
|
|
113
111
|
event: t,
|
|
114
112
|
payload: e || {},
|
|
115
113
|
timestamp: Date.now(),
|
|
116
114
|
source: "embedded-app",
|
|
117
115
|
...i && { requestId: i },
|
|
118
116
|
metadata: {
|
|
119
|
-
version:
|
|
117
|
+
version: I
|
|
120
118
|
}
|
|
121
119
|
};
|
|
122
|
-
s.postMessage(
|
|
120
|
+
s.postMessage(u, r);
|
|
123
121
|
}
|
|
124
122
|
const l = /* @__PURE__ */ new Map();
|
|
125
|
-
let
|
|
123
|
+
let A = !1;
|
|
126
124
|
function V(t) {
|
|
127
125
|
if (process.env.NODE_ENV === "production" && !B(t.origin))
|
|
128
126
|
return;
|
|
@@ -148,27 +146,27 @@ function V(t) {
|
|
|
148
146
|
}
|
|
149
147
|
});
|
|
150
148
|
}
|
|
151
|
-
function
|
|
152
|
-
|
|
149
|
+
function J() {
|
|
150
|
+
A || typeof window > "u" || (window.addEventListener("message", V), A = !0);
|
|
153
151
|
}
|
|
154
152
|
function y(t, e) {
|
|
155
|
-
|
|
153
|
+
J(), l.has(t) || l.set(t, /* @__PURE__ */ new Set());
|
|
156
154
|
const r = l.get(t);
|
|
157
155
|
return r.add(e), () => {
|
|
158
156
|
r.delete(e), r.size === 0 && l.delete(t);
|
|
159
157
|
};
|
|
160
158
|
}
|
|
161
|
-
function
|
|
159
|
+
function Z(t, e = X) {
|
|
162
160
|
return new Promise((r, i) => {
|
|
163
161
|
const n = setTimeout(() => {
|
|
164
162
|
s(), i(new Error(`[EmbeddedSDK] Timeout waiting for "${t}" message`));
|
|
165
|
-
}, e), s = y(t, (
|
|
166
|
-
clearTimeout(n), s(), r(
|
|
163
|
+
}, e), s = y(t, (u) => {
|
|
164
|
+
clearTimeout(n), s(), r(u);
|
|
167
165
|
});
|
|
168
166
|
});
|
|
169
167
|
}
|
|
170
168
|
function ee() {
|
|
171
|
-
l.clear(),
|
|
169
|
+
l.clear(), A && typeof window < "u" && (window.removeEventListener("message", V), A = !1);
|
|
172
170
|
}
|
|
173
171
|
function te() {
|
|
174
172
|
return typeof window > "u" ? !1 : window.parent !== window;
|
|
@@ -180,55 +178,55 @@ function re(t, e, r) {
|
|
|
180
178
|
timestamp: Date.now(),
|
|
181
179
|
source: "merchant-dashboard",
|
|
182
180
|
...r,
|
|
183
|
-
metadata: { version:
|
|
181
|
+
metadata: { version: I, synthetic: !0 }
|
|
184
182
|
}, n = l.get(t);
|
|
185
183
|
n == null || n.forEach((s) => {
|
|
186
184
|
try {
|
|
187
185
|
s(i);
|
|
188
|
-
} catch (
|
|
189
|
-
a.error("Error in message handler:",
|
|
186
|
+
} catch (u) {
|
|
187
|
+
a.error("Error in message handler:", u);
|
|
190
188
|
}
|
|
191
189
|
});
|
|
192
190
|
}
|
|
193
|
-
const
|
|
194
|
-
function
|
|
191
|
+
const f = /* @__PURE__ */ new Map(), ie = 3e4;
|
|
192
|
+
function F() {
|
|
195
193
|
const t = Date.now(), e = Math.random().toString(36).slice(2, 9);
|
|
196
194
|
return `req_${t}_${e}`;
|
|
197
195
|
}
|
|
198
196
|
function j(t, e = {}, r = ie) {
|
|
199
|
-
const i =
|
|
197
|
+
const i = F();
|
|
200
198
|
return new Promise((n, s) => {
|
|
201
|
-
const
|
|
202
|
-
|
|
199
|
+
const u = setTimeout(() => {
|
|
200
|
+
f.get(i) && (f.delete(i), s(
|
|
203
201
|
new Error(
|
|
204
202
|
`[EmbeddedSDK] Request "${t}" timed out after ${r}ms`
|
|
205
203
|
)
|
|
206
204
|
));
|
|
207
205
|
}, r);
|
|
208
|
-
|
|
206
|
+
f.set(i, {
|
|
209
207
|
resolve: n,
|
|
210
208
|
reject: s,
|
|
211
|
-
timeout:
|
|
209
|
+
timeout: u,
|
|
212
210
|
event: t
|
|
213
|
-
}),
|
|
211
|
+
}), c(t, e, "*", i);
|
|
214
212
|
});
|
|
215
213
|
}
|
|
216
|
-
function
|
|
217
|
-
const i =
|
|
214
|
+
function H(t, e, r) {
|
|
215
|
+
const i = f.get(t);
|
|
218
216
|
if (!i) {
|
|
219
217
|
a.warn(`Received response for unknown request: ${t}`);
|
|
220
218
|
return;
|
|
221
219
|
}
|
|
222
|
-
clearTimeout(i.timeout),
|
|
220
|
+
clearTimeout(i.timeout), f.delete(t), i.resolve(e);
|
|
223
221
|
}
|
|
224
222
|
function ne(t = "SDK cleanup") {
|
|
225
|
-
|
|
223
|
+
f.forEach((e, r) => {
|
|
226
224
|
clearTimeout(e.timeout), e.reject(
|
|
227
225
|
new Error(`[EmbeddedSDK] Request ${r} cancelled: ${t}`)
|
|
228
226
|
);
|
|
229
|
-
}),
|
|
227
|
+
}), f.clear();
|
|
230
228
|
}
|
|
231
|
-
function
|
|
229
|
+
function R() {
|
|
232
230
|
const t = /* @__PURE__ */ new Set();
|
|
233
231
|
return {
|
|
234
232
|
subscribe(e) {
|
|
@@ -260,34 +258,34 @@ class T extends Error {
|
|
|
260
258
|
}
|
|
261
259
|
}
|
|
262
260
|
async function ae(t, e = {}) {
|
|
263
|
-
const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e,
|
|
264
|
-
|
|
261
|
+
const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, u = `${se}${t}`, N = new AbortController(), O = setTimeout(() => {
|
|
262
|
+
N.abort();
|
|
265
263
|
}, s);
|
|
266
264
|
try {
|
|
267
|
-
const d = await fetch(
|
|
265
|
+
const d = await fetch(u, {
|
|
268
266
|
method: r,
|
|
269
267
|
headers: {
|
|
270
268
|
"Content-Type": "application/json",
|
|
271
269
|
...i
|
|
272
270
|
},
|
|
273
271
|
body: n ? JSON.stringify(n) : void 0,
|
|
274
|
-
signal:
|
|
272
|
+
signal: N.signal
|
|
275
273
|
});
|
|
276
|
-
clearTimeout(
|
|
277
|
-
let
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
274
|
+
clearTimeout(O);
|
|
275
|
+
let v;
|
|
276
|
+
const C = d.headers.get("content-type");
|
|
277
|
+
if (C != null && C.includes("application/json") ? v = await d.json() : v = await d.text(), !d.ok)
|
|
280
278
|
throw new T(
|
|
281
279
|
`API request failed: ${d.statusText}`,
|
|
282
280
|
d.status,
|
|
283
|
-
|
|
281
|
+
v
|
|
284
282
|
);
|
|
285
|
-
return
|
|
283
|
+
return v;
|
|
286
284
|
} catch (d) {
|
|
287
|
-
throw clearTimeout(
|
|
285
|
+
throw clearTimeout(O), d instanceof T ? d : d instanceof Error ? d.name === "AbortError" ? new T(`Request timeout after ${s}ms`) : new T(`Request failed: ${d.message}`) : new T("Unknown error occurred");
|
|
288
286
|
}
|
|
289
287
|
}
|
|
290
|
-
function
|
|
288
|
+
function _(t) {
|
|
291
289
|
return {
|
|
292
290
|
isVerified: !1,
|
|
293
291
|
isError: !0,
|
|
@@ -299,11 +297,11 @@ async function oe(t) {
|
|
|
299
297
|
const { token: e, appId: r, refreshOnError: i = !0 } = t;
|
|
300
298
|
if (!e) {
|
|
301
299
|
const n = "Token is required. Provide it as a parameter or in URL as ?token=XXX";
|
|
302
|
-
return a.error("Error in introspect:", n),
|
|
300
|
+
return a.error("Error in introspect:", n), _(n);
|
|
303
301
|
}
|
|
304
302
|
if (!r) {
|
|
305
303
|
const n = "App ID is required. Provide it as a parameter or in URL as ?app_id=XXX";
|
|
306
|
-
return a.error("Error in introspect:", n),
|
|
304
|
+
return a.error("Error in introspect:", n), _(n);
|
|
307
305
|
}
|
|
308
306
|
try {
|
|
309
307
|
const n = await ae(
|
|
@@ -329,9 +327,9 @@ async function oe(t) {
|
|
|
329
327
|
data: s ? n.data : null
|
|
330
328
|
};
|
|
331
329
|
} catch (n) {
|
|
332
|
-
i && (G().ui.toast.error((n == null ? void 0 : n.toString()) ?? "Introspect error"),
|
|
330
|
+
i && (G().ui.toast.error((n == null ? void 0 : n.toString()) ?? "Introspect error"), c(U.REFRESH, {})), a.error("Error in introspect:", n);
|
|
333
331
|
const s = n instanceof Error ? n.message : n;
|
|
334
|
-
return
|
|
332
|
+
return _(s);
|
|
335
333
|
}
|
|
336
334
|
}
|
|
337
335
|
function ue(t) {
|
|
@@ -369,7 +367,7 @@ function ue(t) {
|
|
|
369
367
|
* ```
|
|
370
368
|
*/
|
|
371
369
|
refresh() {
|
|
372
|
-
|
|
370
|
+
c(U.REFRESH, {});
|
|
373
371
|
},
|
|
374
372
|
/**
|
|
375
373
|
* Introspect (verify) a short-lived token with Salla's API.
|
|
@@ -414,11 +412,11 @@ function de(t) {
|
|
|
414
412
|
return e.push(...n), { valid: e.length === 0, errors: e };
|
|
415
413
|
}
|
|
416
414
|
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) => {
|
|
417
|
-
const
|
|
415
|
+
const u = q(
|
|
418
416
|
n,
|
|
419
417
|
`Item at index ${s}`
|
|
420
418
|
);
|
|
421
|
-
e.push(...
|
|
419
|
+
e.push(...u);
|
|
422
420
|
}), { valid: e.length === 0, errors: e }) : (e.push("Checkout items must be an array"), { valid: !1, errors: e });
|
|
423
421
|
}
|
|
424
422
|
function le(t) {
|
|
@@ -462,104 +460,83 @@ function he(t) {
|
|
|
462
460
|
);
|
|
463
461
|
}) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
|
|
464
462
|
}
|
|
465
|
-
const
|
|
463
|
+
const z = ["danger", "warning", "info"];
|
|
466
464
|
function ge(t) {
|
|
467
465
|
const e = [];
|
|
468
|
-
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" || !
|
|
469
|
-
`Invalid confirm variant "${t.variant}". Expected: ${
|
|
466
|
+
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" || !z.includes(t.variant)) && e.push(
|
|
467
|
+
`Invalid confirm variant "${t.variant}". Expected: ${z.join(" | ")}`
|
|
470
468
|
), { valid: e.length === 0, errors: e };
|
|
471
469
|
}
|
|
472
|
-
function
|
|
470
|
+
function h(t, e) {
|
|
473
471
|
a.error(
|
|
474
472
|
`Validation failed for ${t}:
|
|
475
473
|
` + e.map((r) => ` • ${r}`).join(`
|
|
476
474
|
`)
|
|
477
475
|
);
|
|
478
476
|
}
|
|
477
|
+
function pe() {
|
|
478
|
+
return { resize: (i) => {
|
|
479
|
+
}, autoResize: () => {
|
|
480
|
+
}, stopAutoResize: () => {
|
|
481
|
+
} };
|
|
482
|
+
}
|
|
479
483
|
function me() {
|
|
484
|
+
const { resize: t, autoResize: e, stopAutoResize: r } = pe();
|
|
480
485
|
return {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const r = le({ path: t, ...e });
|
|
486
|
-
if (!r.valid) {
|
|
487
|
-
f(m.NAVIGATE, r.errors);
|
|
486
|
+
navigate(i, n) {
|
|
487
|
+
const s = le({ path: i, ...n });
|
|
488
|
+
if (!s.valid) {
|
|
489
|
+
h(p.NAVIGATE, s.errors);
|
|
488
490
|
return;
|
|
489
491
|
}
|
|
490
|
-
|
|
491
|
-
path:
|
|
492
|
-
state:
|
|
493
|
-
replace:
|
|
492
|
+
c(p.NAVIGATE, {
|
|
493
|
+
path: i,
|
|
494
|
+
state: n == null ? void 0 : n.state,
|
|
495
|
+
replace: n == null ? void 0 : n.replace
|
|
494
496
|
});
|
|
495
497
|
},
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const e = fe({ url: t });
|
|
501
|
-
if (!e.valid) {
|
|
502
|
-
f(m.REDIRECT, e.errors);
|
|
498
|
+
redirect(i) {
|
|
499
|
+
const n = fe({ url: i });
|
|
500
|
+
if (!n.valid) {
|
|
501
|
+
h(p.REDIRECT, n.errors);
|
|
503
502
|
return;
|
|
504
503
|
}
|
|
505
|
-
|
|
504
|
+
c(p.REDIRECT, { url: i });
|
|
506
505
|
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
navTo(t, e) {
|
|
511
|
-
if (t.startsWith("http://") || t.startsWith("https://")) {
|
|
512
|
-
this.redirect(t);
|
|
506
|
+
navTo(i, n) {
|
|
507
|
+
if (i.startsWith("http://") || i.startsWith("https://")) {
|
|
508
|
+
this.redirect(i);
|
|
513
509
|
return;
|
|
514
510
|
}
|
|
515
|
-
this.navigate(
|
|
511
|
+
this.navigate(i, n);
|
|
516
512
|
},
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
resize(t) {
|
|
521
|
-
if (typeof t != "number" || t < 0) {
|
|
522
|
-
f(v.RESIZE, [
|
|
523
|
-
"Height must be a non-negative number"
|
|
524
|
-
]);
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
527
|
-
u(v.RESIZE, { height: t });
|
|
528
|
-
},
|
|
529
|
-
/**
|
|
530
|
-
* Auto-resize iframe to content height.
|
|
531
|
-
*/
|
|
532
|
-
autoResize() {
|
|
533
|
-
const t = document.documentElement.scrollHeight;
|
|
534
|
-
this.resize(t);
|
|
535
|
-
},
|
|
536
|
-
/**
|
|
537
|
-
* Set the page title in the host document.
|
|
538
|
-
*/
|
|
539
|
-
setTitle(t) {
|
|
540
|
-
if (typeof t != "string" || !t.trim()) {
|
|
541
|
-
f(m.SET_TITLE, [
|
|
513
|
+
setTitle(i) {
|
|
514
|
+
if (typeof i != "string" || !i.trim()) {
|
|
515
|
+
h(p.SET_TITLE, [
|
|
542
516
|
"Title must be a non-empty string"
|
|
543
517
|
]);
|
|
544
518
|
return;
|
|
545
519
|
}
|
|
546
|
-
|
|
547
|
-
}
|
|
520
|
+
c(p.SET_TITLE, { title: i });
|
|
521
|
+
},
|
|
522
|
+
resize: t,
|
|
523
|
+
autoResize: e,
|
|
524
|
+
stopAutoResize: r
|
|
548
525
|
};
|
|
549
526
|
}
|
|
550
|
-
function
|
|
551
|
-
const t =
|
|
552
|
-
return y(
|
|
527
|
+
function Ee() {
|
|
528
|
+
const t = R();
|
|
529
|
+
return y(w.ACTION_CLICK, (e) => {
|
|
553
530
|
t.notify(e.payload.value);
|
|
554
531
|
}), {
|
|
555
532
|
setAction(e) {
|
|
556
533
|
var i;
|
|
557
534
|
const r = he(e);
|
|
558
535
|
if (!r.valid) {
|
|
559
|
-
|
|
536
|
+
h(w.SET_ACTION, r.errors);
|
|
560
537
|
return;
|
|
561
538
|
}
|
|
562
|
-
|
|
539
|
+
c(w.SET_ACTION, {
|
|
563
540
|
title: e.title,
|
|
564
541
|
value: e.value,
|
|
565
542
|
subTitle: e.subTitle,
|
|
@@ -575,37 +552,37 @@ function pe() {
|
|
|
575
552
|
});
|
|
576
553
|
},
|
|
577
554
|
clearAction() {
|
|
578
|
-
|
|
555
|
+
c(w.CLEAR_ACTION, {});
|
|
579
556
|
},
|
|
580
557
|
onActionClick(e) {
|
|
581
558
|
return t.subscribe(e);
|
|
582
559
|
}
|
|
583
560
|
};
|
|
584
561
|
}
|
|
585
|
-
function
|
|
562
|
+
function ye() {
|
|
586
563
|
return {
|
|
587
564
|
/**
|
|
588
565
|
* Show loading indicator.
|
|
589
566
|
*/
|
|
590
567
|
show() {
|
|
591
|
-
|
|
568
|
+
c(g.LOADING, { action: "show" });
|
|
592
569
|
},
|
|
593
570
|
/**
|
|
594
571
|
* Hide loading indicator.
|
|
595
572
|
*/
|
|
596
573
|
hide() {
|
|
597
|
-
|
|
574
|
+
c(g.LOADING, { action: "hide" });
|
|
598
575
|
}
|
|
599
576
|
};
|
|
600
577
|
}
|
|
601
|
-
function
|
|
578
|
+
function be() {
|
|
602
579
|
const t = (e) => {
|
|
603
580
|
const r = ce(e);
|
|
604
581
|
if (!r.valid) {
|
|
605
|
-
|
|
582
|
+
h(g.TOAST, r.errors);
|
|
606
583
|
return;
|
|
607
584
|
}
|
|
608
|
-
|
|
585
|
+
c(g.TOAST, {
|
|
609
586
|
type: e.type,
|
|
610
587
|
message: e.message,
|
|
611
588
|
duration: e.duration
|
|
@@ -642,7 +619,7 @@ function ye() {
|
|
|
642
619
|
}
|
|
643
620
|
};
|
|
644
621
|
}
|
|
645
|
-
function
|
|
622
|
+
function Te() {
|
|
646
623
|
return async (t) => {
|
|
647
624
|
const e = ge(t);
|
|
648
625
|
return e.valid ? j(g.CONFIRM, {
|
|
@@ -651,20 +628,20 @@ function be() {
|
|
|
651
628
|
confirmText: t.confirmText ?? "Confirm",
|
|
652
629
|
cancelText: t.cancelText ?? "Cancel",
|
|
653
630
|
variant: t.variant ?? "info"
|
|
654
|
-
}) : (
|
|
631
|
+
}) : (h(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
|
|
655
632
|
};
|
|
656
633
|
}
|
|
657
|
-
function
|
|
634
|
+
function ve() {
|
|
658
635
|
return {
|
|
659
|
-
loading:
|
|
660
|
-
toast:
|
|
661
|
-
confirm:
|
|
636
|
+
loading: ye(),
|
|
637
|
+
toast: be(),
|
|
638
|
+
confirm: Te()
|
|
662
639
|
};
|
|
663
640
|
}
|
|
664
|
-
function
|
|
665
|
-
const t =
|
|
641
|
+
function we() {
|
|
642
|
+
const t = R(), e = [];
|
|
666
643
|
return e.push(
|
|
667
|
-
y(
|
|
644
|
+
y(m.RESPONSE, (r) => {
|
|
668
645
|
t.notify({
|
|
669
646
|
success: r.payload.success,
|
|
670
647
|
order_id: r.payload.order_id,
|
|
@@ -675,9 +652,9 @@ function ve() {
|
|
|
675
652
|
})
|
|
676
653
|
), e.push(
|
|
677
654
|
y(
|
|
678
|
-
|
|
655
|
+
m.GET_ADDONS_RESPONSE,
|
|
679
656
|
(r) => {
|
|
680
|
-
r.requestId &&
|
|
657
|
+
r.requestId && H(r.requestId, {
|
|
681
658
|
success: r.payload.success,
|
|
682
659
|
addons: r.payload.addons,
|
|
683
660
|
error: r.payload.error
|
|
@@ -688,19 +665,19 @@ function ve() {
|
|
|
688
665
|
create(r, i) {
|
|
689
666
|
const n = Array.isArray(r) ? r : [r], s = de({ items: n });
|
|
690
667
|
if (!s.valid)
|
|
691
|
-
throw
|
|
692
|
-
|
|
693
|
-
|
|
668
|
+
throw h(m.CREATE, s.errors), new Error(s.errors[0]);
|
|
669
|
+
c(
|
|
670
|
+
m.CREATE,
|
|
694
671
|
{
|
|
695
|
-
items: n.map((
|
|
696
|
-
type:
|
|
697
|
-
slug:
|
|
698
|
-
quantity:
|
|
672
|
+
items: n.map((u) => ({
|
|
673
|
+
type: u.type,
|
|
674
|
+
slug: u.slug,
|
|
675
|
+
quantity: u.quantity ?? 1
|
|
699
676
|
})),
|
|
700
677
|
...(i == null ? void 0 : i.context) !== void 0 && { context: i.context }
|
|
701
678
|
},
|
|
702
679
|
"*",
|
|
703
|
-
|
|
680
|
+
F()
|
|
704
681
|
);
|
|
705
682
|
},
|
|
706
683
|
onResult(r) {
|
|
@@ -709,7 +686,7 @@ function ve() {
|
|
|
709
686
|
async getAddons() {
|
|
710
687
|
try {
|
|
711
688
|
return await j(
|
|
712
|
-
|
|
689
|
+
m.GET_ADDONS,
|
|
713
690
|
{},
|
|
714
691
|
3e4
|
|
715
692
|
);
|
|
@@ -728,18 +705,18 @@ function ve() {
|
|
|
728
705
|
}
|
|
729
706
|
};
|
|
730
707
|
}
|
|
731
|
-
const
|
|
708
|
+
const M = {
|
|
732
709
|
theme: "light",
|
|
733
710
|
width: 0,
|
|
734
711
|
locale: "ar",
|
|
735
712
|
currency: "SAR"
|
|
736
713
|
};
|
|
737
|
-
class
|
|
714
|
+
class Se {
|
|
738
715
|
constructor() {
|
|
739
|
-
this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...
|
|
716
|
+
this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...M }, this.postInitHooks = [], this.themeSubscription = R(), this.initSubscription = R(), this.auth = ue(), this.page = me(), this.nav = Ee(), this.ui = ve(), this.checkout = we(), this.registerPostInitHook((e) => {
|
|
740
717
|
const r = e.payload.pendingCheckoutResult;
|
|
741
718
|
r && (a.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
|
|
742
|
-
re(
|
|
719
|
+
re(m.RESPONSE, {
|
|
743
720
|
success: r.success,
|
|
744
721
|
status: r.status,
|
|
745
722
|
error: r.error,
|
|
@@ -762,7 +739,7 @@ class we {
|
|
|
762
739
|
y(x.THEME_CHANGE, (e) => {
|
|
763
740
|
this.layout.theme = e.payload.theme, a.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
|
|
764
741
|
}), y(g.CONFIRM_RESPONSE, (e) => {
|
|
765
|
-
a.debug("Received confirm response:", e), e.requestId &&
|
|
742
|
+
a.debug("Received confirm response:", e), e.requestId && H(e.requestId, { confirmed: e.payload.confirmed });
|
|
766
743
|
});
|
|
767
744
|
}
|
|
768
745
|
/**
|
|
@@ -811,7 +788,7 @@ class we {
|
|
|
811
788
|
a.warn("Cannot signal ready before init() is called");
|
|
812
789
|
return;
|
|
813
790
|
}
|
|
814
|
-
this.appReady = !0,
|
|
791
|
+
this.appReady = !0, c($.READY, {}), a.debug("Sent ready signal to host");
|
|
815
792
|
}
|
|
816
793
|
/**
|
|
817
794
|
* Initialize the SDK and establish connection with the host.
|
|
@@ -827,10 +804,10 @@ class we {
|
|
|
827
804
|
});
|
|
828
805
|
this.initializing = !0, this.debugMode = e.debug ?? !1, Y({ debug: this.debugMode }), te() || a.warn("Not running in an iframe. Some features may not work."), a.debug("Initializing SDK...");
|
|
829
806
|
try {
|
|
830
|
-
|
|
807
|
+
c($.INIT, {
|
|
831
808
|
height: document.documentElement.scrollHeight
|
|
832
809
|
}), a.debug("Sent iframe.ready message, waiting for context...");
|
|
833
|
-
const r = await
|
|
810
|
+
const r = await Z(
|
|
834
811
|
x.PROVIDE
|
|
835
812
|
);
|
|
836
813
|
a.debug("Received context from host:", r);
|
|
@@ -855,23 +832,23 @@ class we {
|
|
|
855
832
|
* Destroy the SDK instance and clean up resources.
|
|
856
833
|
*/
|
|
857
834
|
destroy() {
|
|
858
|
-
a.debug("Destroying SDK instance"), this.initialized && (
|
|
835
|
+
a.debug("Destroying SDK instance"), this.initialized && (c($.DESTROY, {}), a.debug("Sent destroy event to host")), this.checkout.destroy(), ne("SDK destroyed"), ee(), this.themeSubscription.clear(), this.initSubscription.clear(), this.postInitHooks = [], this.initialized = !1, this.initializing = !1, this.appReady = !1, this.layout = { ...M };
|
|
859
836
|
}
|
|
860
837
|
}
|
|
861
838
|
let E = null;
|
|
862
839
|
function G() {
|
|
863
|
-
return E || (E = new
|
|
840
|
+
return E || (E = new Se()), E;
|
|
864
841
|
}
|
|
865
|
-
function
|
|
842
|
+
function Ae() {
|
|
866
843
|
E && (E.destroy(), E = null);
|
|
867
844
|
}
|
|
868
|
-
const P = G(),
|
|
845
|
+
const P = G(), Re = I;
|
|
869
846
|
typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = P), window.Salla.embedded || (window.Salla.embedded = P));
|
|
870
847
|
export {
|
|
871
|
-
|
|
848
|
+
Se as EmbeddedApp,
|
|
872
849
|
P as embedded,
|
|
873
850
|
G as getEmbeddedApp,
|
|
874
|
-
|
|
875
|
-
|
|
851
|
+
Ae as resetEmbeddedApp,
|
|
852
|
+
Re as version
|
|
876
853
|
};
|
|
877
854
|
//# sourceMappingURL=index.js.map
|