@salla.sa/embedded-sdk 0.2.4 → 0.2.6

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/dist/esm/index.js CHANGED
@@ -1,232 +1,263 @@
1
- const o = "embedded::", $ = {
1
+ const u = "embedded::", q = {
2
2
  /** Initialize handshake - iframe signals it's ready to receive context */
3
- INIT: `${o}iframe.ready`,
3
+ INIT: `${u}iframe.ready`,
4
4
  /** App signals it's fully loaded and ready */
5
- READY: `${o}ready`,
5
+ READY: `${u}ready`,
6
6
  /** App requests to be destroyed and navigate away */
7
- DESTROY: `${o}destroy`
8
- }, x = {
7
+ DESTROY: `${u}destroy`
8
+ }, U = {
9
9
  /** Context data provision */
10
- PROVIDE: `${o}context.provide`,
10
+ PROVIDE: `${u}context.provide`,
11
11
  /** Theme change notification */
12
- THEME_CHANGE: `${o}theme.change`
12
+ THEME_CHANGE: `${u}theme.change`
13
13
  }, g = {
14
14
  /** Set loading state */
15
- LOADING: `${o}ui.loading`,
15
+ LOADING: `${u}ui.loading`,
16
+ /** Set breadcrumbs visibility state */
17
+ BREADCRUMBS: `${u}ui.breadcrumbs`,
16
18
  /** Show toast notification */
17
- TOAST: `${o}ui.toast`,
19
+ TOAST: `${u}ui.toast`,
18
20
  /** Show confirm dialog (async request) */
19
- CONFIRM: `${o}ui.confirm`,
21
+ CONFIRM: `${u}ui.confirm`,
20
22
  /** Confirm dialog response (from host) */
21
- CONFIRM_RESPONSE: `${o}ui.confirm.response`
22
- }, K = {}, U = {
23
+ CONFIRM_RESPONSE: `${u}ui.confirm.response`
24
+ }, Z = {}, X = {
23
25
  /** Request token refresh (re-renders iframe with new token) */
24
- REFRESH: `${o}auth.refresh`
25
- }, p = {
26
+ REFRESH: `${u}auth.refresh`
27
+ }, T = {
26
28
  /** Navigate using React Router (SPA navigation) */
27
- NAVIGATE: `${o}page.navigate`,
29
+ NAVIGATE: `${u}page.navigate`,
28
30
  /** Redirect using window.location (full page reload) */
29
- REDIRECT: `${o}page.redirect`,
31
+ REDIRECT: `${u}page.redirect`,
30
32
  /** Set page title */
31
- SET_TITLE: `${o}page.setTitle`
32
- }, w = {
33
+ SET_TITLE: `${u}page.setTitle`
34
+ }, h = {
33
35
  /** Set primary action button in navbar */
34
- SET_ACTION: `${o}nav.setAction`,
36
+ SET_ACTION: `${u}nav.setAction`,
35
37
  /** Clear the primary action button */
36
- CLEAR_ACTION: `${o}nav.clearAction`,
38
+ CLEAR_ACTION: `${u}nav.clearAction`,
37
39
  /** Notification when action button is clicked (host → iframe) */
38
- ACTION_CLICK: `${o}nav.actionClick`
39
- }, m = {
40
+ ACTION_CLICK: `${u}nav.actionClick`,
41
+ /** Add one sub-navigation item (iframe → host) */
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
+ /** Injected sub-nav item clicked (host → iframe) */
48
+ ITEM_CLICK: `${u}nav.itemClick`
49
+ }, y = {
40
50
  /** Create checkout flow */
41
- CREATE: `${o}checkout.create`,
51
+ CREATE: `${u}checkout.create`,
42
52
  /** Checkout response from host */
43
- RESPONSE: `${o}checkout.response`,
53
+ RESPONSE: `${u}checkout.response`,
44
54
  /** Get available addons for the app */
45
- GET_ADDONS: `${o}checkout.getAddons`,
55
+ GET_ADDONS: `${u}checkout.getAddons`,
46
56
  /** Get addons response from host */
47
- GET_ADDONS_RESPONSE: `${o}checkout.getAddons.response`
48
- }, I = K.version || "", X = 1e4, W = [
57
+ GET_ADDONS_RESPONSE: `${u}checkout.getAddons.response`,
58
+ /** Reset checkout cache on host */
59
+ RESET_CACHE: `${u}checkout.resetCache`
60
+ }, D = Z.version || "", ee = 1e4, te = [
49
61
  "localhost",
50
62
  "merchants.workers.dev",
51
63
  "s.salla.sa",
52
64
  ".salla.group",
53
65
  ".salla.sa"
54
- ];
55
- let S = {
66
+ ], re = /* @__PURE__ */ new Set([
67
+ "ar",
68
+ // Arabic
69
+ "he",
70
+ // Hebrew
71
+ "fa",
72
+ // Persian / Farsi
73
+ "ur",
74
+ // Urdu
75
+ "ps",
76
+ // Pashto
77
+ "sd",
78
+ // Sindhi
79
+ "yi"
80
+ // Yiddish
81
+ ]);
82
+ function ie(t) {
83
+ const e = (t ?? "ar").toLowerCase().split(/[-_]/)[0];
84
+ return re.has(e) ? "rtl" : "ltr";
85
+ }
86
+ let N = {
56
87
  showVersion: !0,
57
88
  debug: !1
58
89
  };
59
- function Y(t) {
60
- S = { ...S, ...t };
90
+ function ne(t) {
91
+ N = { ...N, ...t };
61
92
  }
62
- function D(t) {
93
+ function P(t) {
63
94
  return `%c${t}`;
64
95
  }
65
- function L(t, e = "#fff") {
96
+ function j(t, e = "#fff") {
66
97
  return `background-color: ${t}; color: ${e}; padding: 2px 6px; border-radius: 3px; font-weight: 500; font-size: 11px;`;
67
98
  }
68
- function b(t, ...e) {
69
- if (t === "debug" && !S.debug)
99
+ function S(t, ...e) {
100
+ if (t === "debug" && !N.debug)
70
101
  return;
71
102
  const r = [], i = [];
72
- r.push(D("EmbeddedSDK")), i.push(L("#10b981", "#fff")), S.showVersion && (r.push(D(`v${I}`)), i.push(L("#6b7280", "#fff")));
103
+ r.push(P("EmbeddedSDK")), i.push(j("#10b981", "#fff")), N.showVersion && (r.push(P(`v${D}`)), i.push(j("#6b7280", "#fff")));
73
104
  const n = r.join("").trim();
74
105
  (console[t] || console.log)(n, ...i, ...e);
75
106
  }
76
- const a = {
107
+ const o = {
77
108
  log: (...t) => {
78
- b("log", ...t);
109
+ S("log", ...t);
79
110
  },
80
111
  warn: (...t) => {
81
- b("warn", ...t);
112
+ S("warn", ...t);
82
113
  },
83
114
  error: (...t) => {
84
- b("error", ...t);
115
+ S("error", ...t);
85
116
  },
86
117
  info: (...t) => {
87
- b("info", ...t);
118
+ S("info", ...t);
88
119
  },
89
120
  debug: (...t) => {
90
- b("debug", ...t);
121
+ S("debug", ...t);
91
122
  }
92
123
  };
93
- function B(t) {
124
+ function se(t) {
94
125
  try {
95
126
  const r = new URL(t).hostname;
96
- return W.some((i) => i.startsWith(".") ? r.endsWith(i) || r === i.slice(1) : r === i || r.startsWith(`${i}:`));
127
+ return te.some((i) => i.startsWith(".") ? r.endsWith(i) || r === i.slice(1) : r === i || r.startsWith(`${i}:`));
97
128
  } catch {
98
129
  return !1;
99
130
  }
100
131
  }
101
- function Q() {
132
+ function ae() {
102
133
  return typeof window > "u" || window.parent === window ? null : window.parent;
103
134
  }
104
135
  function c(t, e, r = "*", i, n) {
105
- const s = Q();
136
+ const s = ae();
106
137
  if (!s) {
107
- a.warn("Not running in an iframe, cannot post to host");
138
+ o.warn("Not running in an iframe, cannot post to host");
108
139
  return;
109
140
  }
110
- const u = {
141
+ const a = {
111
142
  event: t,
112
143
  payload: e || {},
113
144
  timestamp: Date.now(),
114
145
  source: "embedded-app",
115
146
  ...i && { requestId: i },
116
147
  metadata: {
117
- version: I
148
+ version: D
118
149
  }
119
150
  };
120
- s.postMessage(u, r);
151
+ s.postMessage(a, r);
121
152
  }
122
- const l = /* @__PURE__ */ new Map();
123
- let A = !1;
124
- function V(t) {
125
- if (process.env.NODE_ENV === "production" && !B(t.origin))
153
+ const v = /* @__PURE__ */ new Map();
154
+ let $ = !1;
155
+ function W(t) {
156
+ if (process.env.NODE_ENV === "production" && !se(t.origin))
126
157
  return;
127
158
  const e = t.data;
128
159
  if (!e || typeof e.event != "string" || !e.payload || typeof e.timestamp != "number" || !e.source) {
129
- a.warn("Invalid message structure received:", e);
160
+ o.warn("Invalid message structure received:", e);
130
161
  return;
131
162
  }
132
- const r = l.get(e.event);
163
+ const r = v.get(e.event);
133
164
  r && r.forEach((n) => {
134
165
  try {
135
166
  n(e);
136
167
  } catch (s) {
137
- a.error("Error in message handler:", s);
168
+ o.error("Error in message handler:", s);
138
169
  }
139
170
  });
140
- const i = l.get("*");
171
+ const i = v.get("*");
141
172
  i && i.forEach((n) => {
142
173
  try {
143
174
  n(e);
144
175
  } catch (s) {
145
- a.error("Error in wildcard handler:", s);
176
+ o.error("Error in wildcard handler:", s);
146
177
  }
147
178
  });
148
179
  }
149
- function J() {
150
- A || typeof window > "u" || (window.addEventListener("message", V), A = !0);
180
+ function oe() {
181
+ $ || typeof window > "u" || (window.addEventListener("message", W), $ = !0);
151
182
  }
152
- function y(t, e) {
153
- J(), l.has(t) || l.set(t, /* @__PURE__ */ new Set());
154
- const r = l.get(t);
183
+ function b(t, e) {
184
+ oe(), v.has(t) || v.set(t, /* @__PURE__ */ new Set());
185
+ const r = v.get(t);
155
186
  return r.add(e), () => {
156
- r.delete(e), r.size === 0 && l.delete(t);
187
+ r.delete(e), r.size === 0 && v.delete(t);
157
188
  };
158
189
  }
159
- function Z(t, e = X) {
190
+ function ue(t, e = ee) {
160
191
  return new Promise((r, i) => {
161
192
  const n = setTimeout(() => {
162
193
  s(), i(new Error(`[EmbeddedSDK] Timeout waiting for "${t}" message`));
163
- }, e), s = y(t, (u) => {
164
- clearTimeout(n), s(), r(u);
194
+ }, e), s = b(t, (a) => {
195
+ clearTimeout(n), s(), r(a);
165
196
  });
166
197
  });
167
198
  }
168
- function ee() {
169
- l.clear(), A && typeof window < "u" && (window.removeEventListener("message", V), A = !1);
199
+ function de() {
200
+ v.clear(), $ && typeof window < "u" && (window.removeEventListener("message", W), $ = !1);
170
201
  }
171
- function te() {
202
+ function ce() {
172
203
  return typeof window > "u" ? !1 : window.parent !== window;
173
204
  }
174
- function re(t, e, r) {
205
+ function le(t, e, r) {
175
206
  const i = {
176
207
  event: t,
177
208
  payload: e,
178
209
  timestamp: Date.now(),
179
210
  source: "merchant-dashboard",
180
211
  ...r,
181
- metadata: { version: I, synthetic: !0 }
182
- }, n = l.get(t);
183
- n == null || n.forEach((s) => {
212
+ metadata: { version: D, synthetic: !0 }
213
+ };
214
+ v.get(t)?.forEach((s) => {
184
215
  try {
185
216
  s(i);
186
- } catch (u) {
187
- a.error("Error in message handler:", u);
217
+ } catch (a) {
218
+ o.error("Error in message handler:", a);
188
219
  }
189
220
  });
190
221
  }
191
- const f = /* @__PURE__ */ new Map(), ie = 3e4;
192
- function F() {
222
+ const E = /* @__PURE__ */ new Map(), fe = 3e4;
223
+ function Y() {
193
224
  const t = Date.now(), e = Math.random().toString(36).slice(2, 9);
194
225
  return `req_${t}_${e}`;
195
226
  }
196
- function j(t, e = {}, r = ie) {
197
- const i = F();
227
+ function x(t, e = {}, r = fe) {
228
+ const i = Y();
198
229
  return new Promise((n, s) => {
199
- const u = setTimeout(() => {
200
- f.get(i) && (f.delete(i), s(
230
+ const a = setTimeout(() => {
231
+ E.get(i) && (E.delete(i), s(
201
232
  new Error(
202
233
  `[EmbeddedSDK] Request "${t}" timed out after ${r}ms`
203
234
  )
204
235
  ));
205
236
  }, r);
206
- f.set(i, {
237
+ E.set(i, {
207
238
  resolve: n,
208
239
  reject: s,
209
- timeout: u,
240
+ timeout: a,
210
241
  event: t
211
242
  }), c(t, e, "*", i);
212
243
  });
213
244
  }
214
- function H(t, e, r) {
215
- const i = f.get(t);
245
+ function C(t, e, r) {
246
+ const i = E.get(t);
216
247
  if (!i) {
217
- a.warn(`Received response for unknown request: ${t}`);
248
+ o.warn(`Received response for unknown request: ${t}`);
218
249
  return;
219
250
  }
220
- clearTimeout(i.timeout), f.delete(t), i.resolve(e);
251
+ clearTimeout(i.timeout), E.delete(t), r ? i.reject(new Error(r)) : i.resolve(e);
221
252
  }
222
- function ne(t = "SDK cleanup") {
223
- f.forEach((e, r) => {
253
+ function he(t = "SDK cleanup") {
254
+ E.forEach((e, r) => {
224
255
  clearTimeout(e.timeout), e.reject(
225
256
  new Error(`[EmbeddedSDK] Request ${r} cancelled: ${t}`)
226
257
  );
227
- }), f.clear();
258
+ }), E.clear();
228
259
  }
229
- function R() {
260
+ function A() {
230
261
  const t = /* @__PURE__ */ new Set();
231
262
  return {
232
263
  subscribe(e) {
@@ -239,7 +270,7 @@ function R() {
239
270
  try {
240
271
  r(...e);
241
272
  } catch (i) {
242
- a.error("Error in subscription callback:", i);
273
+ o.error("Error in subscription callback:", i);
243
274
  }
244
275
  });
245
276
  },
@@ -251,41 +282,40 @@ function R() {
251
282
  }
252
283
  };
253
284
  }
254
- const se = "https://api.salla.dev";
255
- class T extends Error {
285
+ const me = "https://api.salla.dev";
286
+ class w extends Error {
256
287
  constructor(e, r, i) {
257
288
  super(e), this.status = r, this.response = i, this.name = "ApiError";
258
289
  }
259
290
  }
260
- async function ae(t, e = {}) {
261
- const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, u = `${se}${t}`, N = new AbortController(), O = setTimeout(() => {
262
- N.abort();
291
+ async function pe(t, e = {}) {
292
+ const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, a = `${me}${t}`, l = new AbortController(), f = setTimeout(() => {
293
+ l.abort();
263
294
  }, s);
264
295
  try {
265
- const d = await fetch(u, {
296
+ const d = await fetch(a, {
266
297
  method: r,
267
298
  headers: {
268
299
  "Content-Type": "application/json",
269
300
  ...i
270
301
  },
271
302
  body: n ? JSON.stringify(n) : void 0,
272
- signal: N.signal
303
+ signal: l.signal
273
304
  });
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)
278
- throw new T(
305
+ clearTimeout(f);
306
+ let m;
307
+ if (d.headers.get("content-type")?.includes("application/json") ? m = await d.json() : m = await d.text(), !d.ok)
308
+ throw new w(
279
309
  `API request failed: ${d.statusText}`,
280
310
  d.status,
281
- v
311
+ m
282
312
  );
283
- return v;
313
+ return m;
284
314
  } catch (d) {
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");
315
+ throw clearTimeout(f), d instanceof w ? d : d instanceof Error ? d.name === "AbortError" ? new w(`Request timeout after ${s}ms`) : new w(`Request failed: ${d.message}`) : new w("Unknown error occurred");
286
316
  }
287
317
  }
288
- function _(t) {
318
+ function k(t) {
289
319
  return {
290
320
  isVerified: !1,
291
321
  isError: !0,
@@ -293,18 +323,18 @@ function _(t) {
293
323
  data: null
294
324
  };
295
325
  }
296
- async function oe(t) {
326
+ async function ge(t) {
297
327
  const { token: e, appId: r, refreshOnError: i = !0 } = t;
298
328
  if (!e) {
299
329
  const n = "Token is required. Provide it as a parameter or in URL as ?token=XXX";
300
- return a.error("Error in introspect:", n), _(n);
330
+ return o.error("Error in introspect:", n), k(n);
301
331
  }
302
332
  if (!r) {
303
333
  const n = "App ID is required. Provide it as a parameter or in URL as ?app_id=XXX";
304
- return a.error("Error in introspect:", n), _(n);
334
+ return o.error("Error in introspect:", n), k(n);
305
335
  }
306
336
  try {
307
- const n = await ae(
337
+ const n = await pe(
308
338
  "/exchange-authority/v1/introspect",
309
339
  {
310
340
  method: "POST",
@@ -327,12 +357,12 @@ async function oe(t) {
327
357
  data: s ? n.data : null
328
358
  };
329
359
  } catch (n) {
330
- i && (G().ui.toast.error((n == null ? void 0 : n.toString()) ?? "Introspect error"), c(U.REFRESH, {})), a.error("Error in introspect:", n);
360
+ i && (J().ui.toast.error(n?.toString() ?? "Introspect error"), c(X.REFRESH, {})), o.error("Error in introspect:", n);
331
361
  const s = n instanceof Error ? n.message : n;
332
- return _(s);
362
+ return k(s);
333
363
  }
334
364
  }
335
- function ue(t) {
365
+ function ve(t) {
336
366
  return {
337
367
  /**
338
368
  * Get the token from the URL query parameter.
@@ -367,7 +397,7 @@ function ue(t) {
367
397
  * ```
368
398
  */
369
399
  refresh() {
370
- c(U.REFRESH, {});
400
+ c(X.REFRESH, {});
371
401
  },
372
402
  /**
373
403
  * Introspect (verify) a short-lived token with Salla's API.
@@ -378,7 +408,7 @@ function ue(t) {
378
408
  */
379
409
  async introspect(e = {}) {
380
410
  const r = e.token ?? this.getToken() ?? "", i = e.appId ?? this.getAppId() ?? "";
381
- return oe({
411
+ return ge({
382
412
  token: r,
383
413
  appId: i,
384
414
  refreshOnError: e.refreshOnError
@@ -386,18 +416,18 @@ function ue(t) {
386
416
  }
387
417
  };
388
418
  }
389
- const k = ["success", "error", "warning", "info"];
390
- function ce(t) {
419
+ const F = ["success", "error", "warning", "info"];
420
+ function be(t) {
391
421
  const e = [];
392
- return t.type === void 0 || t.type === null ? e.push("Toast type is required") : (typeof t.type != "string" || !k.includes(t.type)) && e.push(
393
- `Invalid toast type "${t.type}". Expected: ${k.join(" | ")}`
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(" | ")}`
394
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 };
395
425
  }
396
- function q(t, e) {
426
+ function H(t, e) {
397
427
  const r = [];
398
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);
399
429
  }
400
- function de(t) {
430
+ function ye(t) {
401
431
  const e = [];
402
432
  if (typeof t != "object" || t === null)
403
433
  return e.push("Checkout options must be an object"), { valid: !1, errors: e };
@@ -405,25 +435,25 @@ function de(t) {
405
435
  if (!r && !i)
406
436
  return e.push("Checkout requires either 'item' or 'items'"), { valid: !1, errors: e };
407
437
  if (r) {
408
- const n = q(
438
+ const n = H(
409
439
  t.item,
410
440
  "Item"
411
441
  );
412
442
  return e.push(...n), { valid: e.length === 0, errors: e };
413
443
  }
414
444
  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) => {
415
- const u = q(
445
+ const a = H(
416
446
  n,
417
447
  `Item at index ${s}`
418
448
  );
419
- e.push(...u);
449
+ e.push(...a);
420
450
  }), { valid: e.length === 0, errors: e }) : (e.push("Checkout items must be an array"), { valid: !1, errors: e });
421
451
  }
422
- function le(t) {
452
+ function Ee(t) {
423
453
  const e = [];
424
454
  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 };
425
455
  }
426
- function fe(t) {
456
+ function Te(t) {
427
457
  const e = [];
428
458
  if (t.url === void 0 || t.url === null)
429
459
  e.push("Redirect URL is required");
@@ -439,7 +469,7 @@ function fe(t) {
439
469
  }
440
470
  return { valid: e.length === 0, errors: e };
441
471
  }
442
- function he(t) {
472
+ function Ie(t) {
443
473
  const e = [];
444
474
  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) => {
445
475
  if (typeof r != "object" || r === null) {
@@ -460,48 +490,153 @@ function he(t) {
460
490
  );
461
491
  }) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
462
492
  }
463
- const z = ["danger", "warning", "info"];
464
- function ge(t) {
493
+ const _ = 50;
494
+ function R(t, e) {
495
+ return t ? `${t}.${e}` : e;
496
+ }
497
+ function Se(t, e) {
498
+ const r = [];
499
+ ["title", "value", "url"].forEach((s) => {
500
+ (typeof t[s] != "string" || !String(t[s]).trim()) && r.push(
501
+ `Sub-nav addItem "${R(e, s)}" must be non-empty string`
502
+ );
503
+ });
504
+ const i = R(e, "disabled"), n = R(e, "active");
505
+ 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
+ }
507
+ function z(t, e, r) {
508
+ if (typeof t != "object" || t === null)
509
+ return [`Sub-nav addItem "${e || "item"}" must be an object`];
510
+ const i = t, n = Se(i, e), s = R(e, "children");
511
+ return i.children === void 0 ? n : r ? Array.isArray(i.children) ? i.children.length > _ ? (n.push(
512
+ `Sub-nav addItem "${s}" must have at most ${_} items`
513
+ ), n) : (i.children.forEach((a, l) => {
514
+ const f = e ? `${e}.children[${l}]` : `children[${l}]`;
515
+ n.push(...z(a, f, !1));
516
+ }), n) : (n.push(`Sub-nav addItem "${s}" must be an array`), n) : (Array.isArray(i.children) && i.children.length === 0 || n.push(
517
+ `Sub-nav addItem "${s}" is not supported on submenu rows (only one dropdown level)`
518
+ ), n);
519
+ }
520
+ function Q(t, e, r, i) {
521
+ if (typeof t != "object" || t === null)
522
+ return i;
523
+ const n = t;
524
+ return typeof n.value == "string" && n.value.trim() && i.push(n.value.trim()), !r || !Array.isArray(n.children) || n.children.forEach((s, a) => {
525
+ const l = e ? `${e}.children[${a}]` : `children[${a}]`;
526
+ Q(s, l, !1, i);
527
+ }), i;
528
+ }
529
+ function we(t) {
530
+ const e = Q(t, "", !0, []), r = /* @__PURE__ */ new Set(), i = [];
531
+ for (const n of e)
532
+ r.has(n) && i.push(n), r.add(n);
533
+ return i.length === 0 ? [] : [
534
+ `Sub-nav addItem "value" must be globally unique within the item tree (duplicate: ${[...new Set(i)].join(", ")})`
535
+ ];
536
+ }
537
+ function Ae(t) {
538
+ if (typeof t != "object" || t === null)
539
+ return {
540
+ valid: !1,
541
+ errors: ["Nav addItem expects an object item"]
542
+ };
543
+ const e = [
544
+ ...z(t, "", !0),
545
+ ...we(t)
546
+ ];
547
+ return { valid: e.length === 0, errors: e };
548
+ }
549
+ function Re(t) {
550
+ const e = [];
551
+ if (typeof t != "object" || t === null)
552
+ return e.push("Nav updateItem expects an object item"), { valid: !1, errors: e };
553
+ 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() : "";
554
+ if (!i && !n)
555
+ return e.push('Sub-nav updateItem requires non-empty string "value"'), { valid: !1, errors: e };
556
+ if (i && n && s !== a)
557
+ return e.push(
558
+ 'Sub-nav updateItem must not specify different "id" and "value"; "value" is the immutable row key and cannot be renamed via patch'
559
+ ), { valid: !1, errors: e };
560
+ const l = s || a;
561
+ let f = 0;
562
+ 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)
563
+ return e.push(
564
+ "Sub-nav updateItem must include at least one of title, url, disabled, active, children"
565
+ ), { valid: !1, errors: e };
566
+ if (["title", "url"].forEach((d) => {
567
+ r[d] !== void 0 && (typeof r[d] != "string" || !r[d].trim()) && e.push(`Sub-nav updateItem "${d}" must be non-empty`);
568
+ }), 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
+ if (!Array.isArray(r.children))
570
+ e.push('Sub-nav updateItem "children" must be an array');
571
+ else if (r.children.length > _)
572
+ e.push(
573
+ `Sub-nav updateItem "children" must have at most ${_} items`
574
+ );
575
+ else {
576
+ const d = /* @__PURE__ */ new Set();
577
+ r.children.forEach((m, V) => {
578
+ const M = `children[${V}]`;
579
+ if (e.push(...z(m, M, !1)), typeof m == "object" && m !== null) {
580
+ const O = m.value;
581
+ if (typeof O == "string" && O.trim()) {
582
+ const L = O.trim();
583
+ L === l && e.push(
584
+ `Sub-nav updateItem "${M}.value" must not equal the parent row identifier`
585
+ ), d.has(L) && e.push(
586
+ `Sub-nav updateItem "${M}.value" must be unique within children`
587
+ ), d.add(L);
588
+ }
589
+ }
590
+ });
591
+ }
592
+ return { valid: e.length === 0, errors: e };
593
+ }
594
+ function Ne(t) {
595
+ const e = [];
596
+ return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem value must be non-empty string"), { valid: e.length === 0, errors: e };
597
+ }
598
+ const K = ["danger", "warning", "info"];
599
+ function $e(t) {
465
600
  const e = [];
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(" | ")}`
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" || !K.includes(t.variant)) && e.push(
602
+ `Invalid confirm variant "${t.variant}". Expected: ${K.join(" | ")}`
468
603
  ), { valid: e.length === 0, errors: e };
469
604
  }
470
- function h(t, e) {
471
- a.error(
605
+ function p(t, e) {
606
+ o.error(
472
607
  `Validation failed for ${t}:
473
608
  ` + e.map((r) => ` • ${r}`).join(`
474
609
  `)
475
610
  );
476
611
  }
477
- function pe() {
612
+ function Ce() {
478
613
  return { resize: (i) => {
479
614
  }, autoResize: () => {
480
615
  }, stopAutoResize: () => {
481
616
  } };
482
617
  }
483
- function me() {
484
- const { resize: t, autoResize: e, stopAutoResize: r } = pe();
618
+ function _e() {
619
+ const { resize: t, autoResize: e, stopAutoResize: r } = Ce();
485
620
  return {
486
621
  navigate(i, n) {
487
- const s = le({ path: i, ...n });
622
+ const s = Ee({ path: i, ...n });
488
623
  if (!s.valid) {
489
- h(p.NAVIGATE, s.errors);
624
+ p(T.NAVIGATE, s.errors);
490
625
  return;
491
626
  }
492
- c(p.NAVIGATE, {
627
+ c(T.NAVIGATE, {
493
628
  path: i,
494
- state: n == null ? void 0 : n.state,
495
- replace: n == null ? void 0 : n.replace
629
+ state: n?.state,
630
+ replace: n?.replace
496
631
  });
497
632
  },
498
633
  redirect(i) {
499
- const n = fe({ url: i });
634
+ const n = Te({ url: i });
500
635
  if (!n.valid) {
501
- h(p.REDIRECT, n.errors);
636
+ p(T.REDIRECT, n.errors);
502
637
  return;
503
638
  }
504
- c(p.REDIRECT, { url: i });
639
+ c(T.REDIRECT, { url: i });
505
640
  },
506
641
  navTo(i, n) {
507
642
  if (i.startsWith("http://") || i.startsWith("https://")) {
@@ -512,54 +647,119 @@ function me() {
512
647
  },
513
648
  setTitle(i) {
514
649
  if (typeof i != "string" || !i.trim()) {
515
- h(p.SET_TITLE, [
650
+ p(T.SET_TITLE, [
516
651
  "Title must be a non-empty string"
517
652
  ]);
518
653
  return;
519
654
  }
520
- c(p.SET_TITLE, { title: i });
655
+ c(T.SET_TITLE, { title: i });
521
656
  },
522
657
  resize: t,
523
658
  autoResize: e,
524
659
  stopAutoResize: r
525
660
  };
526
661
  }
527
- function Ee() {
528
- const t = R();
529
- return y(w.ACTION_CLICK, (e) => {
530
- t.notify(e.payload.value);
531
- }), {
532
- setAction(e) {
533
- var i;
534
- const r = he(e);
535
- if (!r.valid) {
536
- h(w.SET_ACTION, r.errors);
662
+ function De() {
663
+ const t = A(), e = A(), r = [];
664
+ return r.push(
665
+ b(h.ACTION_CLICK, (i) => {
666
+ t.notify(i.payload.value);
667
+ })
668
+ ), r.push(
669
+ b(h.ADD_ITEM_RESPONSE, (i) => {
670
+ if (!i.requestId) return;
671
+ const n = i.payload;
672
+ if (typeof n.error == "string" && n.error.trim()) {
673
+ const a = n.error.trim();
674
+ o.warn(`embedded::nav.addItem failed: ${a}`), C(
675
+ i.requestId,
676
+ {},
677
+ a
678
+ );
537
679
  return;
538
680
  }
539
- c(w.SET_ACTION, {
540
- title: e.title,
541
- value: e.value,
542
- subTitle: e.subTitle,
543
- icon: e.icon,
544
- disabled: e.disabled,
545
- extendedActions: (i = e.extendedActions) == null ? void 0 : i.map((n) => ({
546
- title: n.title,
547
- value: n.value,
548
- subTitle: n.subTitle,
549
- icon: n.icon,
550
- disabled: n.disabled
681
+ const s = n.item;
682
+ if (s && typeof s.value == "string" && s.value.trim()) {
683
+ const a = s.value.trim(), l = {
684
+ value: a,
685
+ id: a
686
+ };
687
+ C(i.requestId, l);
688
+ }
689
+ })
690
+ ), r.push(
691
+ b(h.ITEM_CLICK, (i) => {
692
+ 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
+ if (!s) {
694
+ e.notify(n);
695
+ return;
696
+ }
697
+ e.notify({
698
+ ...n,
699
+ value: s,
700
+ id: s
701
+ });
702
+ })
703
+ ), {
704
+ setAction(i) {
705
+ const n = Ie(i);
706
+ if (!n.valid) {
707
+ p(h.SET_ACTION, n.errors);
708
+ return;
709
+ }
710
+ c(h.SET_ACTION, {
711
+ title: i.title,
712
+ value: i.value,
713
+ subTitle: i.subTitle,
714
+ icon: i.icon,
715
+ disabled: i.disabled,
716
+ extendedActions: i.extendedActions?.map((s) => ({
717
+ title: s.title,
718
+ value: s.value,
719
+ subTitle: s.subTitle,
720
+ icon: s.icon,
721
+ disabled: s.disabled
551
722
  }))
552
723
  });
553
724
  },
554
725
  clearAction() {
555
- c(w.CLEAR_ACTION, {});
726
+ c(h.CLEAR_ACTION, {});
727
+ },
728
+ onActionClick(i) {
729
+ return t.subscribe(i);
730
+ },
731
+ addNavItem(i) {
732
+ const n = Ae(i);
733
+ return n.valid ? x(h.ADD_ITEM, { item: i }, 2e3) : (p(h.ADD_ITEM, n.errors), Promise.reject(new Error(n.errors[0])));
734
+ },
735
+ updateNavItem(i) {
736
+ const n = Re(i);
737
+ if (!n.valid) {
738
+ p(h.UPDATE_ITEM, n.errors);
739
+ return;
740
+ }
741
+ const s = i, a = typeof s.value == "string" ? s.value.trim() : "", l = typeof s.id == "string" ? s.id.trim() : "", f = a || l, { id: d, ...m } = s;
742
+ c(h.UPDATE_ITEM, {
743
+ item: { ...m, value: f }
744
+ });
745
+ },
746
+ removeNavItem(i) {
747
+ const n = Ne(i);
748
+ if (!n.valid) {
749
+ p(h.REMOVE_ITEM, n.errors);
750
+ return;
751
+ }
752
+ c(h.REMOVE_ITEM, { value: i });
753
+ },
754
+ onNavItemClick(i) {
755
+ return e.subscribe(i);
556
756
  },
557
- onActionClick(e) {
558
- return t.subscribe(e);
757
+ destroy() {
758
+ r.forEach((i) => i()), r.length = 0, t.clear(), e.clear();
559
759
  }
560
760
  };
561
761
  }
562
- function ye() {
762
+ function Me() {
563
763
  return {
564
764
  /**
565
765
  * Show loading indicator.
@@ -575,11 +775,21 @@ function ye() {
575
775
  }
576
776
  };
577
777
  }
578
- function be() {
778
+ function Oe() {
779
+ return {
780
+ hide() {
781
+ c(g.BREADCRUMBS, { action: "hide" });
782
+ },
783
+ show() {
784
+ c(g.BREADCRUMBS, { action: "show" });
785
+ }
786
+ };
787
+ }
788
+ function Le() {
579
789
  const t = (e) => {
580
- const r = ce(e);
790
+ const r = be(e);
581
791
  if (!r.valid) {
582
- h(g.TOAST, r.errors);
792
+ p(g.TOAST, r.errors);
583
793
  return;
584
794
  }
585
795
  c(g.TOAST, {
@@ -619,29 +829,30 @@ function be() {
619
829
  }
620
830
  };
621
831
  }
622
- function Te() {
832
+ function qe() {
623
833
  return async (t) => {
624
- const e = ge(t);
625
- return e.valid ? j(g.CONFIRM, {
834
+ const e = $e(t);
835
+ return e.valid ? x(g.CONFIRM, {
626
836
  title: t.title,
627
837
  message: t.message,
628
838
  confirmText: t.confirmText ?? "Confirm",
629
839
  cancelText: t.cancelText ?? "Cancel",
630
840
  variant: t.variant ?? "info"
631
- }) : (h(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
841
+ }) : (p(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
632
842
  };
633
843
  }
634
- function ve() {
844
+ function ke() {
635
845
  return {
636
- loading: ye(),
637
- toast: be(),
638
- confirm: Te()
846
+ loading: Me(),
847
+ breadcrumbs: Oe(),
848
+ toast: Le(),
849
+ confirm: qe()
639
850
  };
640
851
  }
641
- function we() {
642
- const t = R(), e = [];
852
+ function xe() {
853
+ const t = A(), e = [];
643
854
  return e.push(
644
- y(m.RESPONSE, (r) => {
855
+ b(y.RESPONSE, (r) => {
645
856
  t.notify({
646
857
  success: r.payload.success,
647
858
  order_id: r.payload.order_id,
@@ -651,10 +862,10 @@ function we() {
651
862
  });
652
863
  })
653
864
  ), e.push(
654
- y(
655
- m.GET_ADDONS_RESPONSE,
865
+ b(
866
+ y.GET_ADDONS_RESPONSE,
656
867
  (r) => {
657
- r.requestId && H(r.requestId, {
868
+ r.requestId && C(r.requestId, {
658
869
  success: r.payload.success,
659
870
  addons: r.payload.addons,
660
871
  error: r.payload.error
@@ -663,21 +874,21 @@ function we() {
663
874
  )
664
875
  ), {
665
876
  create(r, i) {
666
- const n = Array.isArray(r) ? r : [r], s = de({ items: n });
877
+ const n = Array.isArray(r) ? r : [r], s = ye({ items: n });
667
878
  if (!s.valid)
668
- throw h(m.CREATE, s.errors), new Error(s.errors[0]);
879
+ throw p(y.CREATE, s.errors), new Error(s.errors[0]);
669
880
  c(
670
- m.CREATE,
881
+ y.CREATE,
671
882
  {
672
- items: n.map((u) => ({
673
- type: u.type,
674
- slug: u.slug,
675
- quantity: u.quantity ?? 1
883
+ items: n.map((a) => ({
884
+ type: a.type,
885
+ slug: a.slug,
886
+ quantity: a.quantity ?? 1
676
887
  })),
677
- ...(i == null ? void 0 : i.context) !== void 0 && { context: i.context }
888
+ ...i?.context !== void 0 && { context: i.context }
678
889
  },
679
890
  "*",
680
- F()
891
+ Y()
681
892
  );
682
893
  },
683
894
  onResult(r) {
@@ -685,8 +896,8 @@ function we() {
685
896
  },
686
897
  async getAddons() {
687
898
  try {
688
- return await j(
689
- m.GET_ADDONS,
899
+ return await x(
900
+ y.GET_ADDONS,
690
901
  {},
691
902
  3e4
692
903
  );
@@ -700,23 +911,27 @@ function we() {
700
911
  };
701
912
  }
702
913
  },
914
+ resetCache() {
915
+ c(y.RESET_CACHE, {}, "*");
916
+ },
703
917
  destroy() {
704
918
  e.forEach((r) => r()), e.length = 0, t.clear();
705
919
  }
706
920
  };
707
921
  }
708
- const M = {
922
+ const G = {
709
923
  theme: "light",
924
+ dir: "rtl",
710
925
  width: 0,
711
926
  locale: "ar",
712
927
  currency: "SAR"
713
928
  };
714
- class Se {
929
+ class ze {
715
930
  constructor() {
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) => {
931
+ this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...G }, this.postInitHooks = [], this.themeSubscription = A(), this.initSubscription = A(), this.auth = ve(), this.page = _e(), this.nav = De(), this.ui = ke(), this.checkout = xe(), this.registerPostInitHook((e) => {
717
932
  const r = e.payload.pendingCheckoutResult;
718
- r && (a.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
719
- re(m.RESPONSE, {
933
+ r && (o.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
934
+ le(y.RESPONSE, {
720
935
  success: r.success,
721
936
  status: r.status,
722
937
  error: r.error,
@@ -736,10 +951,10 @@ class Se {
736
951
  * Set up core event listeners.
737
952
  */
738
953
  setupListeners() {
739
- y(x.THEME_CHANGE, (e) => {
740
- this.layout.theme = e.payload.theme, a.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
741
- }), y(g.CONFIRM_RESPONSE, (e) => {
742
- a.debug("Received confirm response:", e), e.requestId && H(e.requestId, { confirmed: e.payload.confirmed });
954
+ b(U.THEME_CHANGE, (e) => {
955
+ this.layout.theme = e.payload.theme, o.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
956
+ }), b(g.CONFIRM_RESPONSE, (e) => {
957
+ o.debug("Received confirm response:", e), e.requestId && C(e.requestId, { confirmed: e.payload.confirmed });
743
958
  });
744
959
  }
745
960
  /**
@@ -772,7 +987,7 @@ class Se {
772
987
  try {
773
988
  e(this.getState());
774
989
  } catch (r) {
775
- a.error("Error in init callback:", r);
990
+ o.error("Error in init callback:", r);
776
991
  }
777
992
  return this.initSubscription.subscribe(e);
778
993
  }
@@ -781,49 +996,50 @@ class Se {
781
996
  */
782
997
  ready() {
783
998
  if (this.appReady) {
784
- a.debug("App already signaled as ready");
999
+ o.debug("App already signaled as ready");
785
1000
  return;
786
1001
  }
787
1002
  if (!this.initialized) {
788
- a.warn("Cannot signal ready before init() is called");
1003
+ o.warn("Cannot signal ready before init() is called");
789
1004
  return;
790
1005
  }
791
- this.appReady = !0, c($.READY, {}), a.debug("Sent ready signal to host");
1006
+ this.appReady = !0, c(q.READY, {}), o.debug("Sent ready signal to host");
792
1007
  }
793
1008
  /**
794
1009
  * Initialize the SDK and establish connection with the host.
795
1010
  */
796
1011
  async init(e = {}) {
797
1012
  if (this.initialized)
798
- return a.debug("Already initialized, returning current layout"), { layout: { ...this.layout } };
1013
+ return o.debug("Already initialized, returning current layout"), { layout: { ...this.layout } };
799
1014
  if (this.initializing)
800
- return a.warn("Initialization already in progress"), new Promise((r) => {
1015
+ return o.warn("Initialization already in progress"), new Promise((r) => {
801
1016
  const i = this.onInit((n) => {
802
1017
  i(), r({ layout: { ...n.layout } });
803
1018
  });
804
1019
  });
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...");
1020
+ this.initializing = !0, this.debugMode = e.debug ?? !1, ne({ debug: this.debugMode }), ce() || o.warn("Not running in an iframe. Some features may not work."), o.debug("Initializing SDK...");
806
1021
  try {
807
- c($.INIT, {
1022
+ c(q.INIT, {
808
1023
  height: document.documentElement.scrollHeight
809
- }), a.debug("Sent iframe.ready message, waiting for context...");
810
- const r = await Z(
811
- x.PROVIDE
1024
+ }), o.debug("Sent iframe.ready message, waiting for context...");
1025
+ const r = await ue(
1026
+ U.PROVIDE
812
1027
  );
813
- a.debug("Received context from host:", r);
1028
+ o.debug("Received context from host:", r);
814
1029
  const { layout: i } = r.payload;
815
1030
  return this.layout = {
816
- theme: (i == null ? void 0 : i.theme) ?? "light",
817
- width: (i == null ? void 0 : i.width) ?? 0,
818
- locale: (i == null ? void 0 : i.locale) ?? "ar",
819
- currency: (i == null ? void 0 : i.currency) ?? "SAR"
1031
+ theme: i?.theme ?? "light",
1032
+ dir: i?.dir ?? ie(i?.locale),
1033
+ width: i?.width ?? 0,
1034
+ locale: i?.locale ?? "ar",
1035
+ currency: i?.currency ?? "SAR"
820
1036
  }, this.postInitHooks.forEach((n) => {
821
1037
  try {
822
1038
  n(r);
823
1039
  } catch (s) {
824
- a.error("Error in post-init hook:", s);
1040
+ o.error("Error in post-init hook:", s);
825
1041
  }
826
- }), this.initialized = !0, this.initializing = !1, a.debug("Initialization complete. Layout:", this.layout), this.initSubscription.notify(this.getState()), { layout: { ...this.layout } };
1042
+ }), this.initialized = !0, this.initializing = !1, o.debug("Initialization complete. Layout:", this.layout), this.initSubscription.notify(this.getState()), { layout: { ...this.layout } };
827
1043
  } catch (r) {
828
1044
  throw this.initializing = !1, r;
829
1045
  }
@@ -832,23 +1048,23 @@ class Se {
832
1048
  * Destroy the SDK instance and clean up resources.
833
1049
  */
834
1050
  destroy() {
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 };
1051
+ o.debug("Destroying SDK instance"), this.initialized && (c(q.DESTROY, {}), o.debug("Sent destroy event to host")), this.checkout.destroy(), this.nav.destroy(), he("SDK destroyed"), de(), this.themeSubscription.clear(), this.initSubscription.clear(), this.postInitHooks = [], this.initialized = !1, this.initializing = !1, this.appReady = !1, this.layout = { ...G };
836
1052
  }
837
1053
  }
838
- let E = null;
839
- function G() {
840
- return E || (E = new Se()), E;
1054
+ let I = null;
1055
+ function J() {
1056
+ return I || (I = new ze()), I;
841
1057
  }
842
- function Ae() {
843
- E && (E.destroy(), E = null);
1058
+ function Ve() {
1059
+ I && (I.destroy(), I = null);
844
1060
  }
845
- const P = G(), Re = I;
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));
1061
+ const B = J(), Ue = D;
1062
+ typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = B), window.Salla.embedded || (window.Salla.embedded = B));
847
1063
  export {
848
- Se as EmbeddedApp,
849
- P as embedded,
850
- G as getEmbeddedApp,
851
- Ae as resetEmbeddedApp,
852
- Re as version
1064
+ ze as EmbeddedApp,
1065
+ B as embedded,
1066
+ J as getEmbeddedApp,
1067
+ Ve as resetEmbeddedApp,
1068
+ Ue as version
853
1069
  };
854
1070
  //# sourceMappingURL=index.js.map