@salla.sa/embedded-sdk 0.2.5 → 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,69 +1,69 @@
1
- const o = "embedded::", C = {
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
- }, O = {
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`
13
- }, h = {
12
+ THEME_CHANGE: `${u}theme.change`
13
+ }, g = {
14
14
  /** Set loading state */
15
- LOADING: `${o}ui.loading`,
15
+ LOADING: `${u}ui.loading`,
16
16
  /** Set breadcrumbs visibility state */
17
- BREADCRUMBS: `${o}ui.breadcrumbs`,
17
+ BREADCRUMBS: `${u}ui.breadcrumbs`,
18
18
  /** Show toast notification */
19
- TOAST: `${o}ui.toast`,
19
+ TOAST: `${u}ui.toast`,
20
20
  /** Show confirm dialog (async request) */
21
- CONFIRM: `${o}ui.confirm`,
21
+ CONFIRM: `${u}ui.confirm`,
22
22
  /** Confirm dialog response (from host) */
23
- CONFIRM_RESPONSE: `${o}ui.confirm.response`
24
- }, G = {}, V = {
23
+ CONFIRM_RESPONSE: `${u}ui.confirm.response`
24
+ }, Z = {}, X = {
25
25
  /** Request token refresh (re-renders iframe with new token) */
26
- REFRESH: `${o}auth.refresh`
27
- }, b = {
26
+ REFRESH: `${u}auth.refresh`
27
+ }, T = {
28
28
  /** Navigate using React Router (SPA navigation) */
29
- NAVIGATE: `${o}page.navigate`,
29
+ NAVIGATE: `${u}page.navigate`,
30
30
  /** Redirect using window.location (full page reload) */
31
- REDIRECT: `${o}page.redirect`,
31
+ REDIRECT: `${u}page.redirect`,
32
32
  /** Set page title */
33
- SET_TITLE: `${o}page.setTitle`
34
- }, l = {
33
+ SET_TITLE: `${u}page.setTitle`
34
+ }, h = {
35
35
  /** Set primary action button in navbar */
36
- SET_ACTION: `${o}nav.setAction`,
36
+ SET_ACTION: `${u}nav.setAction`,
37
37
  /** Clear the primary action button */
38
- CLEAR_ACTION: `${o}nav.clearAction`,
38
+ CLEAR_ACTION: `${u}nav.clearAction`,
39
39
  /** Notification when action button is clicked (host → iframe) */
40
- ACTION_CLICK: `${o}nav.actionClick`,
40
+ ACTION_CLICK: `${u}nav.actionClick`,
41
41
  /** Add one sub-navigation item (iframe → host) */
42
- ADD_ITEM: `${o}nav.addItem`,
43
- /** Ack with generated opaque id (host → iframe; request response) */
44
- ADD_ITEM_RESPONSE: `${o}nav.addItem.response`,
45
- UPDATE_ITEM: `${o}nav.updateItem`,
46
- REMOVE_ITEM: `${o}nav.removeItem`,
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: `${o}nav.itemClick`
49
- }, g = {
48
+ ITEM_CLICK: `${u}nav.itemClick`
49
+ }, y = {
50
50
  /** Create checkout flow */
51
- CREATE: `${o}checkout.create`,
51
+ CREATE: `${u}checkout.create`,
52
52
  /** Checkout response from host */
53
- RESPONSE: `${o}checkout.response`,
53
+ RESPONSE: `${u}checkout.response`,
54
54
  /** Get available addons for the app */
55
- GET_ADDONS: `${o}checkout.getAddons`,
55
+ GET_ADDONS: `${u}checkout.getAddons`,
56
56
  /** Get addons response from host */
57
- GET_ADDONS_RESPONSE: `${o}checkout.getAddons.response`,
57
+ GET_ADDONS_RESPONSE: `${u}checkout.getAddons.response`,
58
58
  /** Reset checkout cache on host */
59
- RESET_CACHE: `${o}checkout.resetCache`
60
- }, R = G.version || "", K = 1e4, B = [
59
+ RESET_CACHE: `${u}checkout.resetCache`
60
+ }, D = Z.version || "", ee = 1e4, te = [
61
61
  "localhost",
62
62
  "merchants.workers.dev",
63
63
  "s.salla.sa",
64
64
  ".salla.group",
65
65
  ".salla.sa"
66
- ], X = /* @__PURE__ */ new Set([
66
+ ], re = /* @__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 W(t) {
82
+ function ie(t) {
83
83
  const e = (t ?? "ar").toLowerCase().split(/[-_]/)[0];
84
- return X.has(e) ? "rtl" : "ltr";
84
+ return re.has(e) ? "rtl" : "ltr";
85
85
  }
86
- let S = {
86
+ let N = {
87
87
  showVersion: !0,
88
88
  debug: !1
89
89
  };
90
- function Y(t) {
91
- S = { ...S, ...t };
90
+ function ne(t) {
91
+ N = { ...N, ...t };
92
92
  }
93
- function L(t) {
93
+ function P(t) {
94
94
  return `%c${t}`;
95
95
  }
96
- function x(t, e = "#fff") {
96
+ function j(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 y(t, ...e) {
100
- if (t === "debug" && !S.debug)
99
+ function S(t, ...e) {
100
+ if (t === "debug" && !N.debug)
101
101
  return;
102
102
  const r = [], i = [];
103
- r.push(L("EmbeddedSDK")), i.push(x("#10b981", "#fff")), S.showVersion && (r.push(L(`v${R}`)), i.push(x("#6b7280", "#fff")));
103
+ r.push(P("EmbeddedSDK")), i.push(j("#10b981", "#fff")), N.showVersion && (r.push(P(`v${D}`)), i.push(j("#6b7280", "#fff")));
104
104
  const n = r.join("").trim();
105
105
  (console[t] || console.log)(n, ...i, ...e);
106
106
  }
107
- const a = {
107
+ const o = {
108
108
  log: (...t) => {
109
- y("log", ...t);
109
+ S("log", ...t);
110
110
  },
111
111
  warn: (...t) => {
112
- y("warn", ...t);
112
+ S("warn", ...t);
113
113
  },
114
114
  error: (...t) => {
115
- y("error", ...t);
115
+ S("error", ...t);
116
116
  },
117
117
  info: (...t) => {
118
- y("info", ...t);
118
+ S("info", ...t);
119
119
  },
120
120
  debug: (...t) => {
121
- y("debug", ...t);
121
+ S("debug", ...t);
122
122
  }
123
123
  };
124
- function Q(t) {
124
+ function se(t) {
125
125
  try {
126
126
  const r = new URL(t).hostname;
127
- return B.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}:`));
128
128
  } catch {
129
129
  return !1;
130
130
  }
131
131
  }
132
- function J() {
132
+ function ae() {
133
133
  return typeof window > "u" || window.parent === window ? null : window.parent;
134
134
  }
135
- function u(t, e, r = "*", i, n) {
136
- const s = J();
135
+ function c(t, e, r = "*", i, n) {
136
+ const s = ae();
137
137
  if (!s) {
138
- a.warn("Not running in an iframe, cannot post to host");
138
+ o.warn("Not running in an iframe, cannot post to host");
139
139
  return;
140
140
  }
141
- const d = {
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: R
148
+ version: D
149
149
  }
150
150
  };
151
- s.postMessage(d, r);
151
+ s.postMessage(a, r);
152
152
  }
153
- const p = /* @__PURE__ */ new Map();
154
- let A = !1;
155
- function j(t) {
156
- if (process.env.NODE_ENV === "production" && !Q(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))
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
- a.warn("Invalid message structure received:", e);
160
+ o.warn("Invalid message structure received:", e);
161
161
  return;
162
162
  }
163
- const r = p.get(e.event);
163
+ const r = v.get(e.event);
164
164
  r && r.forEach((n) => {
165
165
  try {
166
166
  n(e);
167
167
  } catch (s) {
168
- a.error("Error in message handler:", s);
168
+ o.error("Error in message handler:", s);
169
169
  }
170
170
  });
171
- const i = p.get("*");
171
+ const i = v.get("*");
172
172
  i && i.forEach((n) => {
173
173
  try {
174
174
  n(e);
175
175
  } catch (s) {
176
- a.error("Error in wildcard handler:", s);
176
+ o.error("Error in wildcard handler:", s);
177
177
  }
178
178
  });
179
179
  }
180
- function Z() {
181
- A || typeof window > "u" || (window.addEventListener("message", j), A = !0);
180
+ function oe() {
181
+ $ || typeof window > "u" || (window.addEventListener("message", W), $ = !0);
182
182
  }
183
- function m(t, e) {
184
- Z(), p.has(t) || p.set(t, /* @__PURE__ */ new Set());
185
- const r = p.get(t);
183
+ function b(t, e) {
184
+ oe(), v.has(t) || v.set(t, /* @__PURE__ */ new Set());
185
+ const r = v.get(t);
186
186
  return r.add(e), () => {
187
- r.delete(e), r.size === 0 && p.delete(t);
187
+ r.delete(e), r.size === 0 && v.delete(t);
188
188
  };
189
189
  }
190
- function ee(t, e = K) {
190
+ function ue(t, e = ee) {
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 = m(t, (d) => {
195
- clearTimeout(n), s(), r(d);
194
+ }, e), s = b(t, (a) => {
195
+ clearTimeout(n), s(), r(a);
196
196
  });
197
197
  });
198
198
  }
199
- function te() {
200
- p.clear(), A && typeof window < "u" && (window.removeEventListener("message", j), A = !1);
199
+ function de() {
200
+ v.clear(), $ && typeof window < "u" && (window.removeEventListener("message", W), $ = !1);
201
201
  }
202
- function re() {
202
+ function ce() {
203
203
  return typeof window > "u" ? !1 : window.parent !== window;
204
204
  }
205
- function ie(t, e, r) {
205
+ function le(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: R, synthetic: !0 }
212
+ metadata: { version: D, synthetic: !0 }
213
213
  };
214
- p.get(t)?.forEach((s) => {
214
+ v.get(t)?.forEach((s) => {
215
215
  try {
216
216
  s(i);
217
- } catch (d) {
218
- a.error("Error in message handler:", d);
217
+ } catch (a) {
218
+ o.error("Error in message handler:", a);
219
219
  }
220
220
  });
221
221
  }
222
- const E = /* @__PURE__ */ new Map(), ne = 3e4;
223
- function F() {
222
+ const E = /* @__PURE__ */ new Map(), fe = 3e4;
223
+ function Y() {
224
224
  const t = Date.now(), e = Math.random().toString(36).slice(2, 9);
225
225
  return `req_${t}_${e}`;
226
226
  }
227
- function $(t, e = {}, r = ne) {
228
- const i = F();
227
+ function x(t, e = {}, r = fe) {
228
+ const i = Y();
229
229
  return new Promise((n, s) => {
230
- const d = setTimeout(() => {
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: d,
240
+ timeout: a,
241
241
  event: t
242
- }), u(t, e, "*", i);
242
+ }), c(t, e, "*", i);
243
243
  });
244
244
  }
245
- function D(t, e, r) {
245
+ function C(t, e, r) {
246
246
  const i = E.get(t);
247
247
  if (!i) {
248
- a.warn(`Received response for unknown request: ${t}`);
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 se(t = "SDK cleanup") {
253
+ function he(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 w() {
260
+ function A() {
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
- a.error("Error in subscription callback:", i);
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 ae = "https://api.salla.dev";
286
- class T extends Error {
285
+ const me = "https://api.salla.dev";
286
+ class w 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 oe(t, e = {}) {
292
- const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = e, d = `${ae}${t}`, N = new AbortController(), M = setTimeout(() => {
293
- 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();
294
294
  }, s);
295
295
  try {
296
- const c = await fetch(d, {
296
+ const d = 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: N.signal
303
+ signal: l.signal
304
304
  });
305
- clearTimeout(M);
306
- let I;
307
- if (c.headers.get("content-type")?.includes("application/json") ? I = await c.json() : I = await c.text(), !c.ok)
308
- throw new T(
309
- `API request failed: ${c.statusText}`,
310
- c.status,
311
- I
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(
309
+ `API request failed: ${d.statusText}`,
310
+ d.status,
311
+ m
312
312
  );
313
- return I;
314
- } catch (c) {
315
- throw clearTimeout(M), c instanceof T ? c : c instanceof Error ? c.name === "AbortError" ? new T(`Request timeout after ${s}ms`) : new T(`Request failed: ${c.message}`) : new T("Unknown error occurred");
313
+ return m;
314
+ } catch (d) {
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");
316
316
  }
317
317
  }
318
- function _(t) {
318
+ function k(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 ue(t) {
326
+ async function ge(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 a.error("Error in introspect:", n), _(n);
330
+ return o.error("Error in introspect:", n), k(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 a.error("Error in introspect:", n), _(n);
334
+ return o.error("Error in introspect:", n), k(n);
335
335
  }
336
336
  try {
337
- const n = await oe(
337
+ const n = await pe(
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 && (H().ui.toast.error(n?.toString() ?? "Introspect error"), u(V.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);
361
361
  const s = n instanceof Error ? n.message : n;
362
- return _(s);
362
+ return k(s);
363
363
  }
364
364
  }
365
- function de(t) {
365
+ function ve(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
- u(V.REFRESH, {});
400
+ c(X.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 ue({
411
+ return ge({
412
412
  token: r,
413
413
  appId: i,
414
414
  refreshOnError: e.refreshOnError
@@ -416,18 +416,18 @@ function de(t) {
416
416
  }
417
417
  };
418
418
  }
419
- const k = ["success", "error", "warning", "info"];
420
- function ce(t) {
419
+ const F = ["success", "error", "warning", "info"];
420
+ function be(t) {
421
421
  const e = [];
422
- return t.type === void 0 || t.type === null ? e.push("Toast type is required") : (typeof t.type != "string" || !k.includes(t.type)) && e.push(
423
- `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(" | ")}`
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 q(t, e) {
426
+ function H(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
- function le(t) {
430
+ function ye(t) {
431
431
  const e = [];
432
432
  if (typeof t != "object" || t === null)
433
433
  return e.push("Checkout options must be an object"), { valid: !1, errors: e };
@@ -435,25 +435,25 @@ function le(t) {
435
435
  if (!r && !i)
436
436
  return e.push("Checkout requires either 'item' or 'items'"), { valid: !1, errors: e };
437
437
  if (r) {
438
- const n = q(
438
+ const n = H(
439
439
  t.item,
440
440
  "Item"
441
441
  );
442
442
  return e.push(...n), { valid: e.length === 0, errors: e };
443
443
  }
444
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) => {
445
- const d = q(
445
+ const a = H(
446
446
  n,
447
447
  `Item at index ${s}`
448
448
  );
449
- e.push(...d);
449
+ e.push(...a);
450
450
  }), { valid: e.length === 0, errors: e }) : (e.push("Checkout items must be an array"), { valid: !1, errors: e });
451
451
  }
452
- function fe(t) {
452
+ function Ee(t) {
453
453
  const e = [];
454
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 };
455
455
  }
456
- function he(t) {
456
+ function Te(t) {
457
457
  const e = [];
458
458
  if (t.url === void 0 || t.url === null)
459
459
  e.push("Redirect URL is required");
@@ -469,7 +469,7 @@ function he(t) {
469
469
  }
470
470
  return { valid: e.length === 0, errors: e };
471
471
  }
472
- function pe(t) {
472
+ function Ie(t) {
473
473
  const e = [];
474
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) => {
475
475
  if (typeof r != "object" || r === null) {
@@ -490,75 +490,153 @@ function pe(t) {
490
490
  );
491
491
  }) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
492
492
  }
493
- function me(t) {
494
- const e = [];
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) {
495
521
  if (typeof t != "object" || t === null)
496
- return e.push("Nav addItem expects an object item"), { valid: !1, errors: e };
497
- const r = t;
498
- return ["title", "value", "url"].forEach((i) => {
499
- (typeof r[i] != "string" || !String(r[i]).trim()) && e.push(`Sub-nav addItem "${i}" must be non-empty string`);
500
- }), r.disabled !== void 0 && typeof r.disabled != "boolean" && e.push('Sub-nav addItem "disabled" must be boolean'), r.active !== void 0 && typeof r.active != "boolean" && e.push('Sub-nav addItem "active" must be boolean'), { valid: e.length === 0, errors: e };
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 };
501
548
  }
502
- function ge(t) {
549
+ function Re(t) {
503
550
  const e = [];
504
551
  if (typeof t != "object" || t === null)
505
552
  return e.push("Nav updateItem expects an object item"), { valid: !1, errors: e };
506
- const r = t;
507
- if (typeof r.id != "string" || !r.id.trim())
508
- return e.push('Sub-nav updateItem requires string "id"'), { valid: !1, errors: e };
509
- let i = 0;
510
- return r.title !== void 0 && i++, r.value !== void 0 && i++, r.url !== void 0 && i++, r.disabled !== void 0 && i++, r.active !== void 0 && i++, i === 0 ? (e.push(
511
- "Sub-nav updateItem must include at least one of title, value, url, disabled, active"
512
- ), { valid: !1, errors: e }) : (["title", "value", "url"].forEach((n) => {
513
- r[n] !== void 0 && (typeof r[n] != "string" || !r[n].trim()) && e.push(`Sub-nav updateItem "${n}" must be non-empty`);
514
- }), 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'), { valid: e.length === 0, 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 };
515
593
  }
516
- function Ee(t) {
594
+ function Ne(t) {
517
595
  const e = [];
518
- return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem id must be non-empty string"), { valid: e.length === 0, errors: e };
596
+ return (typeof t != "string" || !t.trim()) && e.push("Nav removeItem value must be non-empty string"), { valid: e.length === 0, errors: e };
519
597
  }
520
- const z = ["danger", "warning", "info"];
521
- function be(t) {
598
+ const K = ["danger", "warning", "info"];
599
+ function $e(t) {
522
600
  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" || !z.includes(t.variant)) && e.push(
524
- `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(" | ")}`
525
603
  ), { valid: e.length === 0, errors: e };
526
604
  }
527
- function f(t, e) {
528
- a.error(
605
+ function p(t, e) {
606
+ o.error(
529
607
  `Validation failed for ${t}:
530
608
  ` + e.map((r) => ` • ${r}`).join(`
531
609
  `)
532
610
  );
533
611
  }
534
- function ve() {
612
+ function Ce() {
535
613
  return { resize: (i) => {
536
614
  }, autoResize: () => {
537
615
  }, stopAutoResize: () => {
538
616
  } };
539
617
  }
540
- function ye() {
541
- const { resize: t, autoResize: e, stopAutoResize: r } = ve();
618
+ function _e() {
619
+ const { resize: t, autoResize: e, stopAutoResize: r } = Ce();
542
620
  return {
543
621
  navigate(i, n) {
544
- const s = fe({ path: i, ...n });
622
+ const s = Ee({ path: i, ...n });
545
623
  if (!s.valid) {
546
- f(b.NAVIGATE, s.errors);
624
+ p(T.NAVIGATE, s.errors);
547
625
  return;
548
626
  }
549
- u(b.NAVIGATE, {
627
+ c(T.NAVIGATE, {
550
628
  path: i,
551
629
  state: n?.state,
552
630
  replace: n?.replace
553
631
  });
554
632
  },
555
633
  redirect(i) {
556
- const n = he({ url: i });
634
+ const n = Te({ url: i });
557
635
  if (!n.valid) {
558
- f(b.REDIRECT, n.errors);
636
+ p(T.REDIRECT, n.errors);
559
637
  return;
560
638
  }
561
- u(b.REDIRECT, { url: i });
639
+ c(T.REDIRECT, { url: i });
562
640
  },
563
641
  navTo(i, n) {
564
642
  if (i.startsWith("http://") || i.startsWith("https://")) {
@@ -569,41 +647,67 @@ function ye() {
569
647
  },
570
648
  setTitle(i) {
571
649
  if (typeof i != "string" || !i.trim()) {
572
- f(b.SET_TITLE, [
650
+ p(T.SET_TITLE, [
573
651
  "Title must be a non-empty string"
574
652
  ]);
575
653
  return;
576
654
  }
577
- u(b.SET_TITLE, { title: i });
655
+ c(T.SET_TITLE, { title: i });
578
656
  },
579
657
  resize: t,
580
658
  autoResize: e,
581
659
  stopAutoResize: r
582
660
  };
583
661
  }
584
- function Te() {
585
- const t = w(), e = w(), r = [];
662
+ function De() {
663
+ const t = A(), e = A(), r = [];
586
664
  return r.push(
587
- m(l.ACTION_CLICK, (i) => {
665
+ b(h.ACTION_CLICK, (i) => {
588
666
  t.notify(i.payload.value);
589
667
  })
590
668
  ), r.push(
591
- m(l.ADD_ITEM_RESPONSE, (i) => {
592
- const n = i.payload.item;
593
- i.requestId && n && typeof n.id == "string" && typeof n.value == "string" && D(i.requestId, n);
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
+ );
679
+ return;
680
+ }
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
+ }
594
689
  })
595
690
  ), r.push(
596
- m(l.ITEM_CLICK, (i) => {
597
- e.notify(i.payload);
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
+ });
598
702
  })
599
703
  ), {
600
704
  setAction(i) {
601
- const n = pe(i);
705
+ const n = Ie(i);
602
706
  if (!n.valid) {
603
- f(l.SET_ACTION, n.errors);
707
+ p(h.SET_ACTION, n.errors);
604
708
  return;
605
709
  }
606
- u(l.SET_ACTION, {
710
+ c(h.SET_ACTION, {
607
711
  title: i.title,
608
712
  value: i.value,
609
713
  subTitle: i.subTitle,
@@ -619,30 +723,33 @@ function Te() {
619
723
  });
620
724
  },
621
725
  clearAction() {
622
- u(l.CLEAR_ACTION, {});
726
+ c(h.CLEAR_ACTION, {});
623
727
  },
624
728
  onActionClick(i) {
625
729
  return t.subscribe(i);
626
730
  },
627
731
  addNavItem(i) {
628
- const n = me(i);
629
- return n.valid ? $(l.ADD_ITEM, { item: i }, 2e3) : (f(l.ADD_ITEM, n.errors), Promise.reject(new Error(n.errors[0])));
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])));
630
734
  },
631
735
  updateNavItem(i) {
632
- const n = ge(i);
736
+ const n = Re(i);
633
737
  if (!n.valid) {
634
- f(l.UPDATE_ITEM, n.errors);
738
+ p(h.UPDATE_ITEM, n.errors);
635
739
  return;
636
740
  }
637
- u(l.UPDATE_ITEM, { item: i });
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
+ });
638
745
  },
639
746
  removeNavItem(i) {
640
- const n = Ee(i);
747
+ const n = Ne(i);
641
748
  if (!n.valid) {
642
- f(l.REMOVE_ITEM, n.errors);
749
+ p(h.REMOVE_ITEM, n.errors);
643
750
  return;
644
751
  }
645
- u(l.REMOVE_ITEM, { id: i });
752
+ c(h.REMOVE_ITEM, { value: i });
646
753
  },
647
754
  onNavItemClick(i) {
648
755
  return e.subscribe(i);
@@ -652,40 +759,40 @@ function Te() {
652
759
  }
653
760
  };
654
761
  }
655
- function we() {
762
+ function Me() {
656
763
  return {
657
764
  /**
658
765
  * Show loading indicator.
659
766
  */
660
767
  show() {
661
- u(h.LOADING, { action: "show" });
768
+ c(g.LOADING, { action: "show" });
662
769
  },
663
770
  /**
664
771
  * Hide loading indicator.
665
772
  */
666
773
  hide() {
667
- u(h.LOADING, { action: "hide" });
774
+ c(g.LOADING, { action: "hide" });
668
775
  }
669
776
  };
670
777
  }
671
- function Ie() {
778
+ function Oe() {
672
779
  return {
673
780
  hide() {
674
- u(h.BREADCRUMBS, { action: "hide" });
781
+ c(g.BREADCRUMBS, { action: "hide" });
675
782
  },
676
783
  show() {
677
- u(h.BREADCRUMBS, { action: "show" });
784
+ c(g.BREADCRUMBS, { action: "show" });
678
785
  }
679
786
  };
680
787
  }
681
- function Se() {
788
+ function Le() {
682
789
  const t = (e) => {
683
- const r = ce(e);
790
+ const r = be(e);
684
791
  if (!r.valid) {
685
- f(h.TOAST, r.errors);
792
+ p(g.TOAST, r.errors);
686
793
  return;
687
794
  }
688
- u(h.TOAST, {
795
+ c(g.TOAST, {
689
796
  type: e.type,
690
797
  message: e.message,
691
798
  duration: e.duration
@@ -722,30 +829,30 @@ function Se() {
722
829
  }
723
830
  };
724
831
  }
725
- function Ae() {
832
+ function qe() {
726
833
  return async (t) => {
727
- const e = be(t);
728
- return e.valid ? $(h.CONFIRM, {
834
+ const e = $e(t);
835
+ return e.valid ? x(g.CONFIRM, {
729
836
  title: t.title,
730
837
  message: t.message,
731
838
  confirmText: t.confirmText ?? "Confirm",
732
839
  cancelText: t.cancelText ?? "Cancel",
733
840
  variant: t.variant ?? "info"
734
- }) : (f(h.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
841
+ }) : (p(g.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
735
842
  };
736
843
  }
737
- function Re() {
844
+ function ke() {
738
845
  return {
739
- loading: we(),
740
- breadcrumbs: Ie(),
741
- toast: Se(),
742
- confirm: Ae()
846
+ loading: Me(),
847
+ breadcrumbs: Oe(),
848
+ toast: Le(),
849
+ confirm: qe()
743
850
  };
744
851
  }
745
- function Ne() {
746
- const t = w(), e = [];
852
+ function xe() {
853
+ const t = A(), e = [];
747
854
  return e.push(
748
- m(g.RESPONSE, (r) => {
855
+ b(y.RESPONSE, (r) => {
749
856
  t.notify({
750
857
  success: r.payload.success,
751
858
  order_id: r.payload.order_id,
@@ -755,10 +862,10 @@ function Ne() {
755
862
  });
756
863
  })
757
864
  ), e.push(
758
- m(
759
- g.GET_ADDONS_RESPONSE,
865
+ b(
866
+ y.GET_ADDONS_RESPONSE,
760
867
  (r) => {
761
- r.requestId && D(r.requestId, {
868
+ r.requestId && C(r.requestId, {
762
869
  success: r.payload.success,
763
870
  addons: r.payload.addons,
764
871
  error: r.payload.error
@@ -767,21 +874,21 @@ function Ne() {
767
874
  )
768
875
  ), {
769
876
  create(r, i) {
770
- const n = Array.isArray(r) ? r : [r], s = le({ items: n });
877
+ const n = Array.isArray(r) ? r : [r], s = ye({ items: n });
771
878
  if (!s.valid)
772
- throw f(g.CREATE, s.errors), new Error(s.errors[0]);
773
- u(
774
- g.CREATE,
879
+ throw p(y.CREATE, s.errors), new Error(s.errors[0]);
880
+ c(
881
+ y.CREATE,
775
882
  {
776
- items: n.map((d) => ({
777
- type: d.type,
778
- slug: d.slug,
779
- quantity: d.quantity ?? 1
883
+ items: n.map((a) => ({
884
+ type: a.type,
885
+ slug: a.slug,
886
+ quantity: a.quantity ?? 1
780
887
  })),
781
888
  ...i?.context !== void 0 && { context: i.context }
782
889
  },
783
890
  "*",
784
- F()
891
+ Y()
785
892
  );
786
893
  },
787
894
  onResult(r) {
@@ -789,8 +896,8 @@ function Ne() {
789
896
  },
790
897
  async getAddons() {
791
898
  try {
792
- return await $(
793
- g.GET_ADDONS,
899
+ return await x(
900
+ y.GET_ADDONS,
794
901
  {},
795
902
  3e4
796
903
  );
@@ -805,26 +912,26 @@ function Ne() {
805
912
  }
806
913
  },
807
914
  resetCache() {
808
- u(g.RESET_CACHE, {}, "*");
915
+ c(y.RESET_CACHE, {}, "*");
809
916
  },
810
917
  destroy() {
811
918
  e.forEach((r) => r()), e.length = 0, t.clear();
812
919
  }
813
920
  };
814
921
  }
815
- const P = {
922
+ const G = {
816
923
  theme: "light",
817
924
  dir: "rtl",
818
925
  width: 0,
819
926
  locale: "ar",
820
927
  currency: "SAR"
821
928
  };
822
- class Ce {
929
+ class ze {
823
930
  constructor() {
824
- this.initialized = !1, this.initializing = !1, this.debugMode = !1, this.appReady = !1, this.layout = { ...P }, this.postInitHooks = [], this.themeSubscription = w(), this.initSubscription = w(), this.auth = de(), this.page = ye(), this.nav = Te(), this.ui = Re(), this.checkout = Ne(), 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) => {
825
932
  const r = e.payload.pendingCheckoutResult;
826
- r && (a.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
827
- ie(g.RESPONSE, {
933
+ r && (o.debug("Dispatching pending checkout result:", r), queueMicrotask(() => {
934
+ le(y.RESPONSE, {
828
935
  success: r.success,
829
936
  status: r.status,
830
937
  error: r.error,
@@ -844,10 +951,10 @@ class Ce {
844
951
  * Set up core event listeners.
845
952
  */
846
953
  setupListeners() {
847
- m(O.THEME_CHANGE, (e) => {
848
- this.layout.theme = e.payload.theme, a.debug("Theme changed:", e.payload.theme), this.themeSubscription.notify(e.payload.theme);
849
- }), m(h.CONFIRM_RESPONSE, (e) => {
850
- a.debug("Received confirm response:", e), e.requestId && D(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 });
851
958
  });
852
959
  }
853
960
  /**
@@ -880,7 +987,7 @@ class Ce {
880
987
  try {
881
988
  e(this.getState());
882
989
  } catch (r) {
883
- a.error("Error in init callback:", r);
990
+ o.error("Error in init callback:", r);
884
991
  }
885
992
  return this.initSubscription.subscribe(e);
886
993
  }
@@ -889,40 +996,40 @@ class Ce {
889
996
  */
890
997
  ready() {
891
998
  if (this.appReady) {
892
- a.debug("App already signaled as ready");
999
+ o.debug("App already signaled as ready");
893
1000
  return;
894
1001
  }
895
1002
  if (!this.initialized) {
896
- a.warn("Cannot signal ready before init() is called");
1003
+ o.warn("Cannot signal ready before init() is called");
897
1004
  return;
898
1005
  }
899
- this.appReady = !0, u(C.READY, {}), a.debug("Sent ready signal to host");
1006
+ this.appReady = !0, c(q.READY, {}), o.debug("Sent ready signal to host");
900
1007
  }
901
1008
  /**
902
1009
  * Initialize the SDK and establish connection with the host.
903
1010
  */
904
1011
  async init(e = {}) {
905
1012
  if (this.initialized)
906
- return a.debug("Already initialized, returning current layout"), { layout: { ...this.layout } };
1013
+ return o.debug("Already initialized, returning current layout"), { layout: { ...this.layout } };
907
1014
  if (this.initializing)
908
- return a.warn("Initialization already in progress"), new Promise((r) => {
1015
+ return o.warn("Initialization already in progress"), new Promise((r) => {
909
1016
  const i = this.onInit((n) => {
910
1017
  i(), r({ layout: { ...n.layout } });
911
1018
  });
912
1019
  });
913
- this.initializing = !0, this.debugMode = e.debug ?? !1, Y({ debug: this.debugMode }), re() || 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...");
914
1021
  try {
915
- u(C.INIT, {
1022
+ c(q.INIT, {
916
1023
  height: document.documentElement.scrollHeight
917
- }), a.debug("Sent iframe.ready message, waiting for context...");
918
- const r = await ee(
919
- O.PROVIDE
1024
+ }), o.debug("Sent iframe.ready message, waiting for context...");
1025
+ const r = await ue(
1026
+ U.PROVIDE
920
1027
  );
921
- a.debug("Received context from host:", r);
1028
+ o.debug("Received context from host:", r);
922
1029
  const { layout: i } = r.payload;
923
1030
  return this.layout = {
924
1031
  theme: i?.theme ?? "light",
925
- dir: i?.dir ?? W(i?.locale),
1032
+ dir: i?.dir ?? ie(i?.locale),
926
1033
  width: i?.width ?? 0,
927
1034
  locale: i?.locale ?? "ar",
928
1035
  currency: i?.currency ?? "SAR"
@@ -930,9 +1037,9 @@ class Ce {
930
1037
  try {
931
1038
  n(r);
932
1039
  } catch (s) {
933
- a.error("Error in post-init hook:", s);
1040
+ o.error("Error in post-init hook:", s);
934
1041
  }
935
- }), 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 } };
936
1043
  } catch (r) {
937
1044
  throw this.initializing = !1, r;
938
1045
  }
@@ -941,23 +1048,23 @@ class Ce {
941
1048
  * Destroy the SDK instance and clean up resources.
942
1049
  */
943
1050
  destroy() {
944
- a.debug("Destroying SDK instance"), this.initialized && (u(C.DESTROY, {}), a.debug("Sent destroy event to host")), this.checkout.destroy(), this.nav.destroy(), se("SDK destroyed"), te(), this.themeSubscription.clear(), this.initSubscription.clear(), this.postInitHooks = [], this.initialized = !1, this.initializing = !1, this.appReady = !1, this.layout = { ...P };
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 };
945
1052
  }
946
1053
  }
947
- let v = null;
948
- function H() {
949
- return v || (v = new Ce()), v;
1054
+ let I = null;
1055
+ function J() {
1056
+ return I || (I = new ze()), I;
950
1057
  }
951
- function $e() {
952
- v && (v.destroy(), v = null);
1058
+ function Ve() {
1059
+ I && (I.destroy(), I = null);
953
1060
  }
954
- const U = H(), De = R;
955
- typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = U), window.Salla.embedded || (window.Salla.embedded = U));
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));
956
1063
  export {
957
- Ce as EmbeddedApp,
958
- U as embedded,
959
- H as getEmbeddedApp,
960
- $e as resetEmbeddedApp,
961
- De as version
1064
+ ze as EmbeddedApp,
1065
+ B as embedded,
1066
+ J as getEmbeddedApp,
1067
+ Ve as resetEmbeddedApp,
1068
+ Ue as version
962
1069
  };
963
1070
  //# sourceMappingURL=index.js.map