@salla.sa/embedded-sdk 0.2.5 → 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 +416 -270
- 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 +83 -22
- 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,69 +1,69 @@
|
|
|
1
|
-
const
|
|
1
|
+
const u = "embedded::", q = {
|
|
2
2
|
/** Initialize handshake - iframe signals it's ready to receive context */
|
|
3
|
-
INIT: `${
|
|
3
|
+
INIT: `${u}iframe.ready`,
|
|
4
4
|
/** App signals it's fully loaded and ready */
|
|
5
|
-
READY: `${
|
|
5
|
+
READY: `${u}ready`,
|
|
6
6
|
/** App requests to be destroyed and navigate away */
|
|
7
|
-
DESTROY: `${
|
|
8
|
-
},
|
|
7
|
+
DESTROY: `${u}destroy`
|
|
8
|
+
}, j = {
|
|
9
9
|
/** Context data provision */
|
|
10
|
-
PROVIDE: `${
|
|
10
|
+
PROVIDE: `${u}context.provide`,
|
|
11
11
|
/** Theme change notification */
|
|
12
|
-
THEME_CHANGE: `${
|
|
13
|
-
},
|
|
12
|
+
THEME_CHANGE: `${u}theme.change`
|
|
13
|
+
}, g = {
|
|
14
14
|
/** Set loading state */
|
|
15
|
-
LOADING: `${
|
|
15
|
+
LOADING: `${u}ui.loading`,
|
|
16
16
|
/** Set breadcrumbs visibility state */
|
|
17
|
-
BREADCRUMBS: `${
|
|
17
|
+
BREADCRUMBS: `${u}ui.breadcrumbs`,
|
|
18
18
|
/** Show toast notification */
|
|
19
|
-
TOAST: `${
|
|
19
|
+
TOAST: `${u}ui.toast`,
|
|
20
20
|
/** Show confirm dialog (async request) */
|
|
21
|
-
CONFIRM: `${
|
|
21
|
+
CONFIRM: `${u}ui.confirm`,
|
|
22
22
|
/** Confirm dialog response (from host) */
|
|
23
|
-
CONFIRM_RESPONSE: `${
|
|
24
|
-
},
|
|
23
|
+
CONFIRM_RESPONSE: `${u}ui.confirm.response`
|
|
24
|
+
}, ne = {}, Z = {
|
|
25
25
|
/** Request token refresh (re-renders iframe with new token) */
|
|
26
|
-
REFRESH: `${
|
|
27
|
-
},
|
|
26
|
+
REFRESH: `${u}auth.refresh`
|
|
27
|
+
}, T = {
|
|
28
28
|
/** Navigate using React Router (SPA navigation) */
|
|
29
|
-
NAVIGATE: `${
|
|
29
|
+
NAVIGATE: `${u}page.navigate`,
|
|
30
30
|
/** Redirect using window.location (full page reload) */
|
|
31
|
-
REDIRECT: `${
|
|
31
|
+
REDIRECT: `${u}page.redirect`,
|
|
32
32
|
/** Set page title */
|
|
33
|
-
SET_TITLE: `${
|
|
34
|
-
},
|
|
33
|
+
SET_TITLE: `${u}page.setTitle`
|
|
34
|
+
}, h = {
|
|
35
35
|
/** Set primary action button in navbar */
|
|
36
|
-
SET_ACTION: `${
|
|
36
|
+
SET_ACTION: `${u}nav.setAction`,
|
|
37
37
|
/** Clear the primary action button */
|
|
38
|
-
CLEAR_ACTION: `${
|
|
38
|
+
CLEAR_ACTION: `${u}nav.clearAction`,
|
|
39
39
|
/** Notification when action button is clicked (host → iframe) */
|
|
40
|
-
ACTION_CLICK: `${
|
|
40
|
+
ACTION_CLICK: `${u}nav.actionClick`,
|
|
41
41
|
/** Add one sub-navigation item (iframe → host) */
|
|
42
|
-
ADD_ITEM: `${
|
|
43
|
-
/** Ack with
|
|
44
|
-
ADD_ITEM_RESPONSE: `${
|
|
45
|
-
UPDATE_ITEM: `${
|
|
46
|
-
REMOVE_ITEM: `${
|
|
42
|
+
ADD_ITEM: `${u}nav.addItem`,
|
|
43
|
+
/** Ack with `value` and deprecated `id` (same string) (host → iframe; request response) */
|
|
44
|
+
ADD_ITEM_RESPONSE: `${u}nav.addItem.response`,
|
|
45
|
+
UPDATE_ITEM: `${u}nav.updateItem`,
|
|
46
|
+
REMOVE_ITEM: `${u}nav.removeItem`,
|
|
47
47
|
/** Injected sub-nav item clicked (host → iframe) */
|
|
48
|
-
ITEM_CLICK: `${
|
|
49
|
-
},
|
|
48
|
+
ITEM_CLICK: `${u}nav.itemClick`
|
|
49
|
+
}, v = {
|
|
50
50
|
/** Create checkout flow */
|
|
51
|
-
CREATE: `${
|
|
51
|
+
CREATE: `${u}checkout.create`,
|
|
52
52
|
/** Checkout response from host */
|
|
53
|
-
RESPONSE: `${
|
|
53
|
+
RESPONSE: `${u}checkout.response`,
|
|
54
54
|
/** Get available addons for the app */
|
|
55
|
-
GET_ADDONS: `${
|
|
55
|
+
GET_ADDONS: `${u}checkout.getAddons`,
|
|
56
56
|
/** Get addons response from host */
|
|
57
|
-
GET_ADDONS_RESPONSE: `${
|
|
57
|
+
GET_ADDONS_RESPONSE: `${u}checkout.getAddons.response`,
|
|
58
58
|
/** Reset checkout cache on host */
|
|
59
|
-
RESET_CACHE: `${
|
|
60
|
-
},
|
|
59
|
+
RESET_CACHE: `${u}checkout.resetCache`
|
|
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,155 +79,155 @@ const o = "embedded::", C = {
|
|
|
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
|
-
let
|
|
86
|
+
let N = {
|
|
87
87
|
showVersion: !0,
|
|
88
88
|
debug: !1
|
|
89
89
|
};
|
|
90
|
-
function
|
|
91
|
-
|
|
90
|
+
function ce(t) {
|
|
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
|
-
function
|
|
100
|
-
if (t === "debug" && !
|
|
99
|
+
function S(t, ...e) {
|
|
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
|
}
|
|
107
|
-
const
|
|
107
|
+
const o = {
|
|
108
108
|
log: (...t) => {
|
|
109
|
-
|
|
109
|
+
S("log", ...t);
|
|
110
110
|
},
|
|
111
111
|
warn: (...t) => {
|
|
112
|
-
|
|
112
|
+
S("warn", ...t);
|
|
113
113
|
},
|
|
114
114
|
error: (...t) => {
|
|
115
|
-
|
|
115
|
+
S("error", ...t);
|
|
116
116
|
},
|
|
117
117
|
info: (...t) => {
|
|
118
|
-
|
|
118
|
+
S("info", ...t);
|
|
119
119
|
},
|
|
120
120
|
debug: (...t) => {
|
|
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;
|
|
140
140
|
}
|
|
141
|
-
const
|
|
141
|
+
const a = {
|
|
142
142
|
event: t,
|
|
143
143
|
payload: e || {},
|
|
144
144
|
timestamp: Date.now(),
|
|
145
145
|
source: "embedded-app",
|
|
146
146
|
...i && { requestId: i },
|
|
147
147
|
metadata: {
|
|
148
|
-
version:
|
|
148
|
+
version: M
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
|
-
s.postMessage(
|
|
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);
|
|
167
167
|
} catch (s) {
|
|
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);
|
|
175
175
|
} catch (s) {
|
|
176
|
-
|
|
176
|
+
o.error("Error in wildcard handler:", s);
|
|
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 =
|
|
195
|
-
clearTimeout(n), s(), r(
|
|
194
|
+
}, e), s = y(t, (a) => {
|
|
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
|
-
} catch (
|
|
218
|
-
|
|
217
|
+
} catch (a) {
|
|
218
|
+
o.error("Error in message handler:", a);
|
|
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
|
-
const
|
|
230
|
+
const a = setTimeout(() => {
|
|
231
231
|
E.get(i) && (E.delete(i), s(
|
|
232
232
|
new Error(
|
|
233
233
|
`[EmbeddedSDK] Request "${t}" timed out after ${r}ms`
|
|
@@ -237,27 +237,27 @@ function $(t, e = {}, r = ne) {
|
|
|
237
237
|
E.set(i, {
|
|
238
238
|
resolve: n,
|
|
239
239
|
reject: s,
|
|
240
|
-
timeout:
|
|
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}`);
|
|
249
249
|
return;
|
|
250
250
|
}
|
|
251
|
-
clearTimeout(i.timeout), E.delete(t), i.resolve(e);
|
|
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) {
|
|
@@ -270,7 +270,7 @@ function w() {
|
|
|
270
270
|
try {
|
|
271
271
|
r(...e);
|
|
272
272
|
} catch (i) {
|
|
273
|
-
|
|
273
|
+
o.error("Error in subscription callback:", i);
|
|
274
274
|
}
|
|
275
275
|
});
|
|
276
276
|
},
|
|
@@ -282,40 +282,40 @@ function w() {
|
|
|
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,
|
|
293
|
-
|
|
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
|
+
l.abort();
|
|
294
294
|
}, s);
|
|
295
295
|
try {
|
|
296
|
-
const c = await fetch(
|
|
296
|
+
const c = await fetch(a, {
|
|
297
297
|
method: r,
|
|
298
298
|
headers: {
|
|
299
299
|
"Content-Type": "application/json",
|
|
300
300
|
...i
|
|
301
301
|
},
|
|
302
302
|
body: n ? JSON.stringify(n) : void 0,
|
|
303
|
-
signal:
|
|
303
|
+
signal: l.signal
|
|
304
304
|
});
|
|
305
|
-
clearTimeout(
|
|
306
|
-
let
|
|
307
|
-
if (c.headers.get("content-type")?.includes("application/json") ?
|
|
308
|
-
throw new
|
|
305
|
+
clearTimeout(f);
|
|
306
|
+
let m;
|
|
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
309
|
`API request failed: ${c.statusText}`,
|
|
310
310
|
c.status,
|
|
311
|
-
|
|
311
|
+
m
|
|
312
312
|
);
|
|
313
|
-
return
|
|
313
|
+
return m;
|
|
314
314
|
} catch (c) {
|
|
315
|
-
throw clearTimeout(
|
|
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 _(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
|
|
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
|
|
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 ue(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 de(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 de(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
|
|
@@ -416,44 +416,50 @@ function de(t) {
|
|
|
416
416
|
}
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
|
-
const
|
|
420
|
-
function
|
|
419
|
+
const F = ["success", "error", "warning", "info"];
|
|
420
|
+
function Se(t) {
|
|
421
421
|
const e = [];
|
|
422
|
-
return t.type === void 0 || t.type === null ? e.push("Toast type is required") : (typeof t.type != "string" || !
|
|
423
|
-
`Invalid toast type "${t.type}". Expected: ${
|
|
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
|
+
`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
|
|
451
|
+
const a = G(
|
|
446
452
|
n,
|
|
447
453
|
`Item at index ${s}`
|
|
448
454
|
);
|
|
449
|
-
e.push(...
|
|
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 he(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,75 +496,153 @@ function pe(t) {
|
|
|
490
496
|
);
|
|
491
497
|
}) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
|
|
492
498
|
}
|
|
493
|
-
|
|
494
|
-
|
|
499
|
+
const D = 50;
|
|
500
|
+
function _(t, e) {
|
|
501
|
+
return t ? `${t}.${e}` : e;
|
|
502
|
+
}
|
|
503
|
+
function Ce(t, e) {
|
|
504
|
+
const r = [];
|
|
505
|
+
["title", "value", "url"].forEach((s) => {
|
|
506
|
+
(typeof t[s] != "string" || !String(t[s]).trim()) && r.push(
|
|
507
|
+
`Sub-nav addItem "${_(e, s)}" must be non-empty string`
|
|
508
|
+
);
|
|
509
|
+
});
|
|
510
|
+
const i = _(e, "disabled"), n = _(e, "active");
|
|
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;
|
|
512
|
+
}
|
|
513
|
+
function z(t, e, r) {
|
|
514
|
+
if (typeof t != "object" || t === null)
|
|
515
|
+
return [`Sub-nav addItem "${e || "item"}" must be an object`];
|
|
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`
|
|
519
|
+
), n) : (i.children.forEach((a, l) => {
|
|
520
|
+
const f = e ? `${e}.children[${l}]` : `children[${l}]`;
|
|
521
|
+
n.push(...z(a, f, !1));
|
|
522
|
+
}), n) : (n.push(`Sub-nav addItem "${s}" must be an array`), n) : (Array.isArray(i.children) && i.children.length === 0 || n.push(
|
|
523
|
+
`Sub-nav addItem "${s}" is not supported on submenu rows (only one dropdown level)`
|
|
524
|
+
), n);
|
|
525
|
+
}
|
|
526
|
+
function re(t, e, r, i) {
|
|
495
527
|
if (typeof t != "object" || t === null)
|
|
496
|
-
return
|
|
497
|
-
const
|
|
498
|
-
return
|
|
499
|
-
|
|
500
|
-
|
|
528
|
+
return i;
|
|
529
|
+
const n = t;
|
|
530
|
+
return typeof n.value == "string" && n.value.trim() && i.push(n.value.trim()), !r || !Array.isArray(n.children) || n.children.forEach((s, a) => {
|
|
531
|
+
const l = e ? `${e}.children[${a}]` : `children[${a}]`;
|
|
532
|
+
re(s, l, !1, i);
|
|
533
|
+
}), i;
|
|
534
|
+
}
|
|
535
|
+
function $e(t) {
|
|
536
|
+
const e = re(t, "", !0, []), r = /* @__PURE__ */ new Set(), i = [];
|
|
537
|
+
for (const n of e)
|
|
538
|
+
r.has(n) && i.push(n), r.add(n);
|
|
539
|
+
return i.length === 0 ? [] : [
|
|
540
|
+
`Sub-nav addItem "value" must be globally unique within the item tree (duplicate: ${[...new Set(i)].join(", ")})`
|
|
541
|
+
];
|
|
501
542
|
}
|
|
502
|
-
function
|
|
543
|
+
function De(t) {
|
|
544
|
+
if (typeof t != "object" || t === null)
|
|
545
|
+
return {
|
|
546
|
+
valid: !1,
|
|
547
|
+
errors: ["Nav addItem expects an object item"]
|
|
548
|
+
};
|
|
549
|
+
const e = [
|
|
550
|
+
...z(t, "", !0),
|
|
551
|
+
...$e(t)
|
|
552
|
+
];
|
|
553
|
+
return { valid: e.length === 0, errors: e };
|
|
554
|
+
}
|
|
555
|
+
function Me(t) {
|
|
503
556
|
const e = [];
|
|
504
557
|
if (typeof t != "object" || t === null)
|
|
505
558
|
return e.push("Nav updateItem expects an object item"), { valid: !1, errors: e };
|
|
506
|
-
const r = t;
|
|
507
|
-
if (
|
|
508
|
-
return e.push('Sub-nav updateItem requires string "
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
559
|
+
const r = t, i = typeof r.value == "string" && String(r.value).trim().length > 0, n = typeof r.id == "string" && String(r.id).trim().length > 0, s = i ? String(r.value).trim() : "", a = n ? String(r.id).trim() : "";
|
|
560
|
+
if (!i && !n)
|
|
561
|
+
return e.push('Sub-nav updateItem requires non-empty string "value"'), { valid: !1, errors: e };
|
|
562
|
+
if (i && n && s !== a)
|
|
563
|
+
return e.push(
|
|
564
|
+
'Sub-nav updateItem must not specify different "id" and "value"; "value" is the immutable row key and cannot be renamed via patch'
|
|
565
|
+
), { valid: !1, errors: e };
|
|
566
|
+
const l = s || a;
|
|
567
|
+
let f = 0;
|
|
568
|
+
if (r.title !== void 0 && f++, r.url !== void 0 && f++, r.disabled !== void 0 && f++, r.active !== void 0 && f++, r.children !== void 0 && f++, f === 0)
|
|
569
|
+
return e.push(
|
|
570
|
+
"Sub-nav updateItem must include at least one of title, url, disabled, active, children"
|
|
571
|
+
), { valid: !1, errors: e };
|
|
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`);
|
|
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)
|
|
575
|
+
if (!Array.isArray(r.children))
|
|
576
|
+
e.push('Sub-nav updateItem "children" must be an array');
|
|
577
|
+
else if (r.children.length > D)
|
|
578
|
+
e.push(
|
|
579
|
+
`Sub-nav updateItem "children" must have at most ${D} items`
|
|
580
|
+
);
|
|
581
|
+
else {
|
|
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);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return { valid: e.length === 0, errors: e };
|
|
599
|
+
}
|
|
600
|
+
function Oe(t) {
|
|
517
601
|
const e = [];
|
|
518
|
-
return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem
|
|
602
|
+
return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem value must be non-empty string"), { valid: e.length === 0, errors: e };
|
|
519
603
|
}
|
|
520
|
-
const
|
|
521
|
-
function
|
|
604
|
+
const W = ["danger", "warning", "info"];
|
|
605
|
+
function Le(t) {
|
|
522
606
|
const e = [];
|
|
523
|
-
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" || !
|
|
524
|
-
`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(" | ")}`
|
|
525
609
|
), { valid: e.length === 0, errors: e };
|
|
526
610
|
}
|
|
527
|
-
function
|
|
528
|
-
|
|
611
|
+
function p(t, e) {
|
|
612
|
+
o.error(
|
|
529
613
|
`Validation failed for ${t}:
|
|
530
614
|
` + e.map((r) => ` • ${r}`).join(`
|
|
531
615
|
`)
|
|
532
616
|
);
|
|
533
617
|
}
|
|
534
|
-
function
|
|
618
|
+
function ke() {
|
|
535
619
|
return { resize: (i) => {
|
|
536
620
|
}, autoResize: () => {
|
|
537
621
|
}, stopAutoResize: () => {
|
|
538
622
|
} };
|
|
539
623
|
}
|
|
540
|
-
function
|
|
541
|
-
const { resize: t, autoResize: e, stopAutoResize: r } =
|
|
624
|
+
function qe() {
|
|
625
|
+
const { resize: t, autoResize: e, stopAutoResize: r } = ke();
|
|
542
626
|
return {
|
|
543
627
|
navigate(i, n) {
|
|
544
|
-
const s =
|
|
628
|
+
const s = Re({ path: i, ...n });
|
|
545
629
|
if (!s.valid) {
|
|
546
|
-
|
|
630
|
+
p(T.NAVIGATE, s.errors);
|
|
547
631
|
return;
|
|
548
632
|
}
|
|
549
|
-
|
|
633
|
+
d(T.NAVIGATE, {
|
|
550
634
|
path: i,
|
|
551
635
|
state: n?.state,
|
|
552
636
|
replace: n?.replace
|
|
553
637
|
});
|
|
554
638
|
},
|
|
555
639
|
redirect(i) {
|
|
556
|
-
const n =
|
|
640
|
+
const n = _e({ url: i });
|
|
557
641
|
if (!n.valid) {
|
|
558
|
-
|
|
642
|
+
p(T.REDIRECT, n.errors);
|
|
559
643
|
return;
|
|
560
644
|
}
|
|
561
|
-
|
|
645
|
+
d(T.REDIRECT, { url: i });
|
|
562
646
|
},
|
|
563
647
|
navTo(i, n) {
|
|
564
648
|
if (i.startsWith("http://") || i.startsWith("https://")) {
|
|
@@ -569,41 +653,67 @@ function ye() {
|
|
|
569
653
|
},
|
|
570
654
|
setTitle(i) {
|
|
571
655
|
if (typeof i != "string" || !i.trim()) {
|
|
572
|
-
|
|
656
|
+
p(T.SET_TITLE, [
|
|
573
657
|
"Title must be a non-empty string"
|
|
574
658
|
]);
|
|
575
659
|
return;
|
|
576
660
|
}
|
|
577
|
-
|
|
661
|
+
d(T.SET_TITLE, { title: i });
|
|
578
662
|
},
|
|
579
663
|
resize: t,
|
|
580
664
|
autoResize: e,
|
|
581
665
|
stopAutoResize: r
|
|
582
666
|
};
|
|
583
667
|
}
|
|
584
|
-
function
|
|
585
|
-
const t =
|
|
668
|
+
function xe() {
|
|
669
|
+
const t = R(), e = R(), r = [];
|
|
586
670
|
return r.push(
|
|
587
|
-
|
|
671
|
+
y(h.ACTION_CLICK, (i) => {
|
|
588
672
|
t.notify(i.payload.value);
|
|
589
673
|
})
|
|
590
674
|
), r.push(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
675
|
+
y(h.ADD_ITEM_RESPONSE, (i) => {
|
|
676
|
+
if (!i.requestId) return;
|
|
677
|
+
const n = i.payload;
|
|
678
|
+
if (typeof n.error == "string" && n.error.trim()) {
|
|
679
|
+
const a = n.error.trim();
|
|
680
|
+
o.warn(`embedded::nav.addItem failed: ${a}`), $(
|
|
681
|
+
i.requestId,
|
|
682
|
+
{},
|
|
683
|
+
a
|
|
684
|
+
);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
const s = n.item;
|
|
688
|
+
if (s && typeof s.value == "string" && s.value.trim()) {
|
|
689
|
+
const a = s.value.trim(), l = {
|
|
690
|
+
value: a,
|
|
691
|
+
id: a
|
|
692
|
+
};
|
|
693
|
+
$(i.requestId, l);
|
|
694
|
+
}
|
|
594
695
|
})
|
|
595
696
|
), r.push(
|
|
596
|
-
|
|
597
|
-
|
|
697
|
+
y(h.ITEM_CLICK, (i) => {
|
|
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() : "";
|
|
699
|
+
if (!s) {
|
|
700
|
+
e.notify(n);
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
e.notify({
|
|
704
|
+
...n,
|
|
705
|
+
value: s,
|
|
706
|
+
id: s
|
|
707
|
+
});
|
|
598
708
|
})
|
|
599
709
|
), {
|
|
600
710
|
setAction(i) {
|
|
601
|
-
const n =
|
|
711
|
+
const n = Ne(i);
|
|
602
712
|
if (!n.valid) {
|
|
603
|
-
|
|
713
|
+
p(h.SET_ACTION, n.errors);
|
|
604
714
|
return;
|
|
605
715
|
}
|
|
606
|
-
|
|
716
|
+
d(h.SET_ACTION, {
|
|
607
717
|
title: i.title,
|
|
608
718
|
value: i.value,
|
|
609
719
|
subTitle: i.subTitle,
|
|
@@ -619,30 +729,33 @@ function Te() {
|
|
|
619
729
|
});
|
|
620
730
|
},
|
|
621
731
|
clearAction() {
|
|
622
|
-
|
|
732
|
+
d(h.CLEAR_ACTION, {});
|
|
623
733
|
},
|
|
624
734
|
onActionClick(i) {
|
|
625
735
|
return t.subscribe(i);
|
|
626
736
|
},
|
|
627
737
|
addNavItem(i) {
|
|
628
|
-
const n =
|
|
629
|
-
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])));
|
|
630
740
|
},
|
|
631
741
|
updateNavItem(i) {
|
|
632
|
-
const n =
|
|
742
|
+
const n = Me(i);
|
|
633
743
|
if (!n.valid) {
|
|
634
|
-
|
|
744
|
+
p(h.UPDATE_ITEM, n.errors);
|
|
635
745
|
return;
|
|
636
746
|
}
|
|
637
|
-
|
|
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, {
|
|
749
|
+
item: { ...m, value: f }
|
|
750
|
+
});
|
|
638
751
|
},
|
|
639
752
|
removeNavItem(i) {
|
|
640
|
-
const n =
|
|
753
|
+
const n = Oe(i);
|
|
641
754
|
if (!n.valid) {
|
|
642
|
-
|
|
755
|
+
p(h.REMOVE_ITEM, n.errors);
|
|
643
756
|
return;
|
|
644
757
|
}
|
|
645
|
-
|
|
758
|
+
d(h.REMOVE_ITEM, { value: i });
|
|
646
759
|
},
|
|
647
760
|
onNavItemClick(i) {
|
|
648
761
|
return e.subscribe(i);
|
|
@@ -652,40 +765,40 @@ function Te() {
|
|
|
652
765
|
}
|
|
653
766
|
};
|
|
654
767
|
}
|
|
655
|
-
function
|
|
768
|
+
function Ue() {
|
|
656
769
|
return {
|
|
657
770
|
/**
|
|
658
771
|
* Show loading indicator.
|
|
659
772
|
*/
|
|
660
773
|
show() {
|
|
661
|
-
|
|
774
|
+
d(g.LOADING, { action: "show" });
|
|
662
775
|
},
|
|
663
776
|
/**
|
|
664
777
|
* Hide loading indicator.
|
|
665
778
|
*/
|
|
666
779
|
hide() {
|
|
667
|
-
|
|
780
|
+
d(g.LOADING, { action: "hide" });
|
|
668
781
|
}
|
|
669
782
|
};
|
|
670
783
|
}
|
|
671
|
-
function
|
|
784
|
+
function Ve() {
|
|
672
785
|
return {
|
|
673
786
|
hide() {
|
|
674
|
-
|
|
787
|
+
d(g.BREADCRUMBS, { action: "hide" });
|
|
675
788
|
},
|
|
676
789
|
show() {
|
|
677
|
-
|
|
790
|
+
d(g.BREADCRUMBS, { action: "show" });
|
|
678
791
|
}
|
|
679
792
|
};
|
|
680
793
|
}
|
|
681
|
-
function
|
|
794
|
+
function ze() {
|
|
682
795
|
const t = (e) => {
|
|
683
|
-
const r =
|
|
796
|
+
const r = Se(e);
|
|
684
797
|
if (!r.valid) {
|
|
685
|
-
|
|
798
|
+
p(g.TOAST, r.errors);
|
|
686
799
|
return;
|
|
687
800
|
}
|
|
688
|
-
|
|
801
|
+
d(g.TOAST, {
|
|
689
802
|
type: e.type,
|
|
690
803
|
message: e.message,
|
|
691
804
|
duration: e.duration
|
|
@@ -722,43 +835,53 @@ function Se() {
|
|
|
722
835
|
}
|
|
723
836
|
};
|
|
724
837
|
}
|
|
725
|
-
function
|
|
838
|
+
function Pe() {
|
|
726
839
|
return async (t) => {
|
|
727
|
-
const e =
|
|
728
|
-
return e.valid ?
|
|
840
|
+
const e = Le(t);
|
|
841
|
+
return e.valid ? V(g.CONFIRM, {
|
|
729
842
|
title: t.title,
|
|
730
843
|
message: t.message,
|
|
731
844
|
confirmText: t.confirmText ?? "Confirm",
|
|
732
845
|
cancelText: t.cancelText ?? "Cancel",
|
|
733
846
|
variant: t.variant ?? "info"
|
|
734
|
-
}) : (
|
|
847
|
+
}) : (p(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
|
|
735
848
|
};
|
|
736
849
|
}
|
|
737
|
-
function
|
|
850
|
+
function je() {
|
|
738
851
|
return {
|
|
739
|
-
loading:
|
|
740
|
-
breadcrumbs:
|
|
741
|
-
toast:
|
|
742
|
-
confirm:
|
|
852
|
+
loading: Ue(),
|
|
853
|
+
breadcrumbs: Ve(),
|
|
854
|
+
toast: ze(),
|
|
855
|
+
confirm: Pe()
|
|
743
856
|
};
|
|
744
857
|
}
|
|
745
|
-
|
|
746
|
-
|
|
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 = [];
|
|
747
869
|
return e.push(
|
|
748
|
-
|
|
870
|
+
y(v.RESPONSE, (r) => {
|
|
749
871
|
t.notify({
|
|
750
872
|
success: r.payload.success,
|
|
751
873
|
order_id: r.payload.order_id,
|
|
874
|
+
checkout_id: r.payload.checkout_id,
|
|
752
875
|
status: r.payload.status,
|
|
753
876
|
error: r.payload.error,
|
|
754
877
|
context: r.payload.context
|
|
755
878
|
});
|
|
756
879
|
})
|
|
757
880
|
), e.push(
|
|
758
|
-
|
|
759
|
-
|
|
881
|
+
y(
|
|
882
|
+
v.GET_ADDONS_RESPONSE,
|
|
760
883
|
(r) => {
|
|
761
|
-
r.requestId &&
|
|
884
|
+
r.requestId && $(r.requestId, {
|
|
762
885
|
success: r.payload.success,
|
|
763
886
|
addons: r.payload.addons,
|
|
764
887
|
error: r.payload.error
|
|
@@ -767,21 +890,42 @@ function Ne() {
|
|
|
767
890
|
)
|
|
768
891
|
), {
|
|
769
892
|
create(r, i) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
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,
|
|
775
923
|
{
|
|
776
|
-
|
|
777
|
-
type: d.type,
|
|
778
|
-
slug: d.slug,
|
|
779
|
-
quantity: d.quantity ?? 1
|
|
780
|
-
})),
|
|
924
|
+
...n,
|
|
781
925
|
...i?.context !== void 0 && { context: i.context }
|
|
782
926
|
},
|
|
783
927
|
"*",
|
|
784
|
-
|
|
928
|
+
te()
|
|
785
929
|
);
|
|
786
930
|
},
|
|
787
931
|
onResult(r) {
|
|
@@ -789,8 +933,8 @@ function Ne() {
|
|
|
789
933
|
},
|
|
790
934
|
async getAddons() {
|
|
791
935
|
try {
|
|
792
|
-
return await
|
|
793
|
-
|
|
936
|
+
return await V(
|
|
937
|
+
v.GET_ADDONS,
|
|
794
938
|
{},
|
|
795
939
|
3e4
|
|
796
940
|
);
|
|
@@ -805,28 +949,29 @@ function Ne() {
|
|
|
805
949
|
}
|
|
806
950
|
},
|
|
807
951
|
resetCache() {
|
|
808
|
-
|
|
952
|
+
d(v.RESET_CACHE, {}, "*");
|
|
809
953
|
},
|
|
810
954
|
destroy() {
|
|
811
955
|
e.forEach((r) => r()), e.length = 0, t.clear();
|
|
812
956
|
}
|
|
813
957
|
};
|
|
814
958
|
}
|
|
815
|
-
const
|
|
959
|
+
const Q = {
|
|
816
960
|
theme: "light",
|
|
817
961
|
dir: "rtl",
|
|
818
962
|
width: 0,
|
|
819
963
|
locale: "ar",
|
|
820
964
|
currency: "SAR"
|
|
821
965
|
};
|
|
822
|
-
class
|
|
966
|
+
class Ge {
|
|
823
967
|
constructor() {
|
|
824
|
-
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) => {
|
|
825
969
|
const r = e.payload.pendingCheckoutResult;
|
|
826
|
-
r && (
|
|
827
|
-
|
|
970
|
+
r && (o.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
|
|
971
|
+
ge(v.RESPONSE, {
|
|
828
972
|
success: r.success,
|
|
829
973
|
status: r.status,
|
|
974
|
+
checkout_id: r.checkout_id,
|
|
830
975
|
error: r.error,
|
|
831
976
|
context: r.context
|
|
832
977
|
});
|
|
@@ -844,10 +989,10 @@ class Ce {
|
|
|
844
989
|
* Set up core event listeners.
|
|
845
990
|
*/
|
|
846
991
|
setupListeners() {
|
|
847
|
-
|
|
848
|
-
this.layout.theme = e.payload.theme,
|
|
849
|
-
}),
|
|
850
|
-
|
|
992
|
+
y(j.THEME_CHANGE, (e) => {
|
|
993
|
+
this.layout.theme = e.payload.theme, o.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
|
|
994
|
+
}), y(g.CONFIRM_RESPONSE, (e) => {
|
|
995
|
+
o.debug("Received confirm response:", e), e.requestId && $(e.requestId, { confirmed: e.payload.confirmed });
|
|
851
996
|
});
|
|
852
997
|
}
|
|
853
998
|
/**
|
|
@@ -880,7 +1025,7 @@ class Ce {
|
|
|
880
1025
|
try {
|
|
881
1026
|
e(this.getState());
|
|
882
1027
|
} catch (r) {
|
|
883
|
-
|
|
1028
|
+
o.error("Error in init callback:", r);
|
|
884
1029
|
}
|
|
885
1030
|
return this.initSubscription.subscribe(e);
|
|
886
1031
|
}
|
|
@@ -889,40 +1034,40 @@ class Ce {
|
|
|
889
1034
|
*/
|
|
890
1035
|
ready() {
|
|
891
1036
|
if (this.appReady) {
|
|
892
|
-
|
|
1037
|
+
o.debug("App already signaled as ready");
|
|
893
1038
|
return;
|
|
894
1039
|
}
|
|
895
1040
|
if (!this.initialized) {
|
|
896
|
-
|
|
1041
|
+
o.warn("Cannot signal ready before init() is called");
|
|
897
1042
|
return;
|
|
898
1043
|
}
|
|
899
|
-
this.appReady = !0,
|
|
1044
|
+
this.appReady = !0, d(q.READY, {}), o.debug("Sent ready signal to host");
|
|
900
1045
|
}
|
|
901
1046
|
/**
|
|
902
1047
|
* Initialize the SDK and establish connection with the host.
|
|
903
1048
|
*/
|
|
904
1049
|
async init(e = {}) {
|
|
905
1050
|
if (this.initialized)
|
|
906
|
-
return
|
|
1051
|
+
return o.debug("Already initialized, returning current layout"), { layout: { ...this.layout } };
|
|
907
1052
|
if (this.initializing)
|
|
908
|
-
return
|
|
1053
|
+
return o.warn("Initialization already in progress"), new Promise((r) => {
|
|
909
1054
|
const i = this.onInit((n) => {
|
|
910
1055
|
i(), r({ layout: { ...n.layout } });
|
|
911
1056
|
});
|
|
912
1057
|
});
|
|
913
|
-
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...");
|
|
914
1059
|
try {
|
|
915
|
-
|
|
1060
|
+
d(q.INIT, {
|
|
916
1061
|
height: document.documentElement.scrollHeight
|
|
917
|
-
}),
|
|
918
|
-
const r = await
|
|
919
|
-
|
|
1062
|
+
}), o.debug("Sent iframe.ready message, waiting for context...");
|
|
1063
|
+
const r = await he(
|
|
1064
|
+
j.PROVIDE
|
|
920
1065
|
);
|
|
921
|
-
|
|
1066
|
+
o.debug("Received context from host:", r);
|
|
922
1067
|
const { layout: i } = r.payload;
|
|
923
1068
|
return this.layout = {
|
|
924
1069
|
theme: i?.theme ?? "light",
|
|
925
|
-
dir: i?.dir ??
|
|
1070
|
+
dir: i?.dir ?? ue(i?.locale),
|
|
926
1071
|
width: i?.width ?? 0,
|
|
927
1072
|
locale: i?.locale ?? "ar",
|
|
928
1073
|
currency: i?.currency ?? "SAR"
|
|
@@ -930,9 +1075,9 @@ class Ce {
|
|
|
930
1075
|
try {
|
|
931
1076
|
n(r);
|
|
932
1077
|
} catch (s) {
|
|
933
|
-
|
|
1078
|
+
o.error("Error in post-init hook:", s);
|
|
934
1079
|
}
|
|
935
|
-
}), this.initialized = !0, this.initializing = !1,
|
|
1080
|
+
}), this.initialized = !0, this.initializing = !1, o.debug("Initialization complete. Layout:", this.layout), this.initSubscription.notify(this.getState()), { layout: { ...this.layout } };
|
|
936
1081
|
} catch (r) {
|
|
937
1082
|
throw this.initializing = !1, r;
|
|
938
1083
|
}
|
|
@@ -941,23 +1086,24 @@ class Ce {
|
|
|
941
1086
|
* Destroy the SDK instance and clean up resources.
|
|
942
1087
|
*/
|
|
943
1088
|
destroy() {
|
|
944
|
-
|
|
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 };
|
|
945
1090
|
}
|
|
946
1091
|
}
|
|
947
|
-
let
|
|
948
|
-
function
|
|
949
|
-
return
|
|
1092
|
+
let I = null;
|
|
1093
|
+
function ie() {
|
|
1094
|
+
return I || (I = new Ge()), I;
|
|
950
1095
|
}
|
|
951
|
-
function
|
|
952
|
-
|
|
1096
|
+
function Be() {
|
|
1097
|
+
I && (I.destroy(), I = null);
|
|
953
1098
|
}
|
|
954
|
-
const
|
|
955
|
-
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));
|
|
956
1101
|
export {
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
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
|
|
962
1108
|
};
|
|
963
1109
|
//# sourceMappingURL=index.js.map
|