@salla.sa/embedded-sdk 0.1.0-beta.10 → 0.1.0-beta.11

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,102 +1,102 @@
1
- const o = "embedded::", T = {
1
+ const s = "embedded::", y = {
2
2
  /** Initialize handshake - iframe signals it's ready to receive context */
3
- INIT: `${o}iframe.ready`,
3
+ INIT: `${s}iframe.ready`,
4
4
  /** Request iframe resize */
5
- RESIZE: `${o}iframe.resize`,
5
+ RESIZE: `${s}iframe.resize`,
6
6
  /** App signals it's fully loaded and ready */
7
- READY: `${o}ready`,
7
+ READY: `${s}ready`,
8
8
  /** App requests to be destroyed and navigate away */
9
- DESTROY: `${o}destroy`
10
- }, N = {
9
+ DESTROY: `${s}destroy`
10
+ }, k = {
11
11
  /** Context data provision */
12
- PROVIDE: `${o}context.provide`,
12
+ PROVIDE: `${s}context.provide`,
13
13
  /** Theme change notification */
14
- THEME_CHANGE: `${o}theme.change`
14
+ THEME_CHANGE: `${s}theme.change`
15
15
  }, j = {
16
16
  /** Send log message to host */
17
- LOG: `${o}log`
17
+ LOG: `${s}log`
18
18
  }, d = {
19
19
  /** Set loading state */
20
- LOADING: `${o}ui.loading`,
20
+ LOADING: `${s}ui.loading`,
21
21
  /** Show toast notification */
22
- TOAST: `${o}ui.toast`,
22
+ TOAST: `${s}ui.toast`,
23
23
  /** Control modal state */
24
- MODAL: `${o}ui.modal`,
24
+ MODAL: `${s}ui.modal`,
25
25
  /** Show confirm dialog (async request) */
26
- CONFIRM: `${o}ui.confirm`,
26
+ CONFIRM: `${s}ui.confirm`,
27
27
  /** Confirm dialog response (from host) */
28
- CONFIRM_RESPONSE: `${o}ui.confirm.response`,
28
+ CONFIRM_RESPONSE: `${s}ui.confirm.response`,
29
29
  /** Modal response (from host) */
30
- MODAL_RESPONSE: `${o}ui.modal.response`
31
- }, G = "0.1.0-beta.10", H = {
30
+ MODAL_RESPONSE: `${s}ui.modal.response`
31
+ }, G = "0.1.0-beta.11", H = {
32
32
  version: G
33
- }, q = {
33
+ }, z = {
34
34
  /** Request token refresh (re-renders iframe with new token) */
35
- REFRESH: `${o}auth.refresh`
35
+ REFRESH: `${s}auth.refresh`
36
36
  }, m = {
37
37
  /** Navigate using React Router (SPA navigation) */
38
- NAVIGATE: `${o}page.navigate`,
38
+ NAVIGATE: `${s}page.navigate`,
39
39
  /** Redirect using window.location (full page reload) */
40
- REDIRECT: `${o}page.redirect`,
40
+ REDIRECT: `${s}page.redirect`,
41
41
  /** Set page title */
42
- SET_TITLE: `${o}page.setTitle`
43
- }, S = {
42
+ SET_TITLE: `${s}page.setTitle`
43
+ }, w = {
44
44
  /** Set primary action button in navbar */
45
- SET_ACTION: `${o}nav.setAction`,
45
+ SET_ACTION: `${s}nav.setAction`,
46
46
  /** Notification when action button is clicked (host → iframe) */
47
- ACTION_CLICK: `${o}nav.actionClick`
48
- }, k = {
47
+ ACTION_CLICK: `${s}nav.actionClick`
48
+ }, $ = {
49
49
  /** Initialize checkout flow */
50
- CREATE: `${o}checkout.create`
51
- }, z = H.version, K = 1e4, X = [
50
+ CREATE: `${s}checkout.create`
51
+ }, L = H.version, K = 1e4, X = [
52
52
  "localhost",
53
53
  "merchants.workers.dev",
54
54
  "s.salla.sa",
55
55
  ".salla.group",
56
56
  ".salla.sa"
57
57
  ];
58
- let R = {
58
+ let A = {
59
59
  showVersion: !0,
60
60
  debug: !1
61
61
  };
62
62
  function W(e) {
63
- R = { ...R, ...e };
63
+ A = { ...A, ...e };
64
64
  }
65
- function $(e) {
65
+ function O(e) {
66
66
  return `%c${e}`;
67
67
  }
68
- function O(e, t = "#fff") {
68
+ function _(e, t = "#fff") {
69
69
  return `background-color: ${e}; color: ${t}; padding: 2px 6px; border-radius: 3px; font-weight: 500; font-size: 11px;`;
70
70
  }
71
- function p(e, ...t) {
72
- if (e === "debug" && !R.debug)
71
+ function b(e, ...t) {
72
+ if (e === "debug" && !A.debug)
73
73
  return;
74
- const r = [], i = [];
75
- r.push($("EmbeddedSDK")), i.push(O("#10b981", "#fff")), R.showVersion && (r.push($(`v${z}`)), i.push(O("#6b7280", "#fff")));
76
- const n = r.join("").trim();
77
- (console[e] || console.log)(n, ...i, ...t);
74
+ const i = [], r = [];
75
+ i.push(O("EmbeddedSDK")), r.push(_("#10b981", "#fff")), A.showVersion && (i.push(O(`v${L}`)), r.push(_("#6b7280", "#fff")));
76
+ const n = i.join("").trim();
77
+ (console[e] || console.log)(n, ...r, ...t);
78
78
  }
79
79
  const u = {
80
80
  log: (...e) => {
81
- p("log", ...e);
81
+ b("log", ...e);
82
82
  },
83
83
  warn: (...e) => {
84
- p("warn", ...e);
84
+ b("warn", ...e);
85
85
  },
86
86
  error: (...e) => {
87
- p("error", ...e);
87
+ b("error", ...e);
88
88
  },
89
89
  info: (...e) => {
90
- p("info", ...e);
90
+ b("info", ...e);
91
91
  },
92
92
  debug: (...e) => {
93
- p("debug", ...e);
93
+ b("debug", ...e);
94
94
  }
95
95
  };
96
96
  function Y(e) {
97
97
  try {
98
- const r = new URL(e).hostname;
99
- return X.some((i) => i.startsWith(".") ? r.endsWith(i) || r === i.slice(1) : r === i || r.startsWith(`${i}:`));
98
+ const i = new URL(e).hostname;
99
+ return X.some((r) => r.startsWith(".") ? i.endsWith(r) || i === r.slice(1) : i === r || i.startsWith(`${r}:`));
100
100
  } catch {
101
101
  return !1;
102
102
  }
@@ -104,64 +104,72 @@ function Y(e) {
104
104
  function B() {
105
105
  return typeof window > "u" || window.parent === window ? null : window.parent;
106
106
  }
107
- function l(e, t, r = "*") {
108
- const i = B();
109
- if (!i) {
107
+ function o(e, t, i = "*", r, n) {
108
+ const a = B();
109
+ if (!a) {
110
110
  u.warn("Not running in an iframe, cannot post to host");
111
111
  return;
112
112
  }
113
- const n = {
113
+ const l = {
114
114
  event: e,
115
- ...t
115
+ payload: t || {},
116
+ timestamp: Date.now(),
117
+ source: "embedded-app",
118
+ ...r && { requestId: r },
119
+ metadata: {
120
+ version: L
121
+ }
116
122
  };
117
- i.postMessage(n, r);
123
+ a.postMessage(l, i);
118
124
  }
119
125
  const h = /* @__PURE__ */ new Map();
120
- let C = !1;
126
+ let S = !1;
121
127
  function P(e) {
122
128
  if (process.env.NODE_ENV === "production" && !Y(e.origin))
123
129
  return;
124
130
  const t = e.data;
125
- if (!t || typeof t.event != "string")
131
+ if (!t || typeof t.event != "string" || !t.payload || typeof t.timestamp != "number" || !t.source) {
132
+ u.warn("Invalid message structure received:", t);
126
133
  return;
127
- const r = h.get(t.event);
128
- r && r.forEach((n) => {
134
+ }
135
+ const i = h.get(t.event);
136
+ i && i.forEach((n) => {
129
137
  try {
130
138
  n(t);
131
- } catch (s) {
132
- u.error("Error in message handler:", s);
139
+ } catch (a) {
140
+ u.error("Error in message handler:", a);
133
141
  }
134
142
  });
135
- const i = h.get("*");
136
- i && i.forEach((n) => {
143
+ const r = h.get("*");
144
+ r && r.forEach((n) => {
137
145
  try {
138
146
  n(t);
139
- } catch (s) {
140
- u.error("Error in wildcard handler:", s);
147
+ } catch (a) {
148
+ u.error("Error in wildcard handler:", a);
141
149
  }
142
150
  });
143
151
  }
144
152
  function Z() {
145
- C || typeof window > "u" || (window.addEventListener("message", P), C = !0);
153
+ S || typeof window > "u" || (window.addEventListener("message", P), S = !0);
146
154
  }
147
- function v(e, t) {
155
+ function T(e, t) {
148
156
  Z(), h.has(e) || h.set(e, /* @__PURE__ */ new Set());
149
- const r = h.get(e);
150
- return r.add(t), () => {
151
- r.delete(t), r.size === 0 && h.delete(e);
157
+ const i = h.get(e);
158
+ return i.add(t), () => {
159
+ i.delete(t), i.size === 0 && h.delete(e);
152
160
  };
153
161
  }
154
162
  function J(e, t = K) {
155
- return new Promise((r, i) => {
163
+ return new Promise((i, r) => {
156
164
  const n = setTimeout(() => {
157
- s(), i(new Error(`[EmbeddedSDK] Timeout waiting for "${e}" message`));
158
- }, t), s = v(e, (a) => {
159
- clearTimeout(n), s(), r(a);
165
+ a(), r(new Error(`[EmbeddedSDK] Timeout waiting for "${e}" message`));
166
+ }, t), a = T(e, (l) => {
167
+ clearTimeout(n), a(), i(l);
160
168
  });
161
169
  });
162
170
  }
163
171
  function Q() {
164
- h.clear(), C && typeof window < "u" && (window.removeEventListener("message", P), C = !1);
172
+ h.clear(), S && typeof window < "u" && (window.removeEventListener("message", P), S = !1);
165
173
  }
166
174
  function ee() {
167
175
  return typeof window > "u" ? !1 : window.parent !== window;
@@ -171,74 +179,74 @@ function re() {
171
179
  const e = Date.now(), t = Math.random().toString(36).slice(2, 9);
172
180
  return `req_${e}_${t}`;
173
181
  }
174
- function ie(e, t = {}, r = te) {
175
- const i = re();
176
- return new Promise((n, s) => {
177
- const a = setTimeout(() => {
178
- g.get(i) && (g.delete(i), s(
182
+ function ie(e, t = {}, i = te) {
183
+ const r = re();
184
+ return new Promise((n, a) => {
185
+ const l = setTimeout(() => {
186
+ g.get(r) && (g.delete(r), a(
179
187
  new Error(
180
- `[EmbeddedSDK] Request "${e}" timed out after ${r}ms`
188
+ `[EmbeddedSDK] Request "${e}" timed out after ${i}ms`
181
189
  )
182
190
  ));
183
- }, r);
184
- g.set(i, {
191
+ }, i);
192
+ g.set(r, {
185
193
  resolve: n,
186
- reject: s,
187
- timeout: a,
194
+ reject: a,
195
+ timeout: l,
188
196
  event: e
189
- }), l(e, { ...t, requestId: i });
197
+ }), o(e, t, "*", r);
190
198
  });
191
199
  }
192
- function _(e, t, r) {
193
- const i = g.get(e);
194
- if (!i) {
200
+ function D(e, t, i) {
201
+ const r = g.get(e);
202
+ if (!r) {
195
203
  u.warn(`Received response for unknown request: ${e}`);
196
204
  return;
197
205
  }
198
- clearTimeout(i.timeout), g.delete(e), r ? i.reject(new Error(r)) : i.resolve(t);
206
+ clearTimeout(r.timeout), g.delete(e), i ? r.reject(new Error(i)) : r.resolve(t);
199
207
  }
200
208
  function ne(e = "SDK cleanup") {
201
- g.forEach((t, r) => {
209
+ g.forEach((t, i) => {
202
210
  clearTimeout(t.timeout), t.reject(
203
- new Error(`[EmbeddedSDK] Request ${r} cancelled: ${e}`)
211
+ new Error(`[EmbeddedSDK] Request ${i} cancelled: ${e}`)
204
212
  );
205
213
  }), g.clear();
206
214
  }
207
- const se = "https://api.salla.dev";
208
- class y extends Error {
209
- constructor(t, r, i) {
210
- super(t), this.status = r, this.response = i, this.name = "ApiError";
215
+ const ae = "https://api.salla.dev";
216
+ class E extends Error {
217
+ constructor(t, i, r) {
218
+ super(t), this.status = i, this.response = r, this.name = "ApiError";
211
219
  }
212
220
  }
213
- async function ae(e, t = {}) {
214
- const { method: r = "GET", headers: i = {}, body: n, timeout: s = 3e4 } = t, a = `${se}${e}`, E = new AbortController(), w = setTimeout(() => {
215
- E.abort();
216
- }, s);
221
+ async function se(e, t = {}) {
222
+ const { method: i = "GET", headers: r = {}, body: n, timeout: a = 3e4 } = t, l = `${ae}${e}`, R = new AbortController(), N = setTimeout(() => {
223
+ R.abort();
224
+ }, a);
217
225
  try {
218
- const c = await fetch(a, {
219
- method: r,
226
+ const c = await fetch(l, {
227
+ method: i,
220
228
  headers: {
221
229
  "Content-Type": "application/json",
222
- ...i
230
+ ...r
223
231
  },
224
232
  body: n ? JSON.stringify(n) : void 0,
225
- signal: E.signal
233
+ signal: R.signal
226
234
  });
227
- clearTimeout(w);
228
- let A;
229
- const I = c.headers.get("content-type");
230
- if (I != null && I.includes("application/json") ? A = await c.json() : A = await c.text(), !c.ok)
231
- throw new y(
235
+ clearTimeout(N);
236
+ let v;
237
+ const C = c.headers.get("content-type");
238
+ if (C != null && C.includes("application/json") ? v = await c.json() : v = await c.text(), !c.ok)
239
+ throw new E(
232
240
  `API request failed: ${c.statusText}`,
233
241
  c.status,
234
- A
242
+ v
235
243
  );
236
- return A;
244
+ return v;
237
245
  } catch (c) {
238
- throw clearTimeout(w), c instanceof y ? c : c instanceof Error ? c.name === "AbortError" ? new y(`Request timeout after ${s}ms`) : new y(`Request failed: ${c.message}`) : new y("Unknown error occurred");
246
+ throw clearTimeout(N), c instanceof E ? c : c instanceof Error ? c.name === "AbortError" ? new E(`Request timeout after ${a}ms`) : new E(`Request failed: ${c.message}`) : new E("Unknown error occurred");
239
247
  }
240
248
  }
241
- function L(e) {
249
+ function I(e) {
242
250
  return {
243
251
  isVerified: !1,
244
252
  isError: !0,
@@ -247,22 +255,22 @@ function L(e) {
247
255
  };
248
256
  }
249
257
  async function oe(e) {
250
- const { token: t, appId: r, refreshOnError: i = !0 } = e;
258
+ const { token: t, appId: i, refreshOnError: r = !0 } = e;
251
259
  if (!t) {
252
260
  const n = "Token is required. Provide it as a parameter or in URL as ?token=XXX";
253
- return u.error("Error in introspect:", n), L(n);
261
+ return u.error("Error in introspect:", n), I(n);
254
262
  }
255
- if (!r) {
263
+ if (!i) {
256
264
  const n = "App ID is required. Provide it as a parameter or in URL as ?app_id=XXX";
257
- return u.error("Error in introspect:", n), L(n);
265
+ return u.error("Error in introspect:", n), I(n);
258
266
  }
259
267
  try {
260
- const n = await ae(
268
+ const n = await se(
261
269
  "/exchange-authority/v1/introspect",
262
270
  {
263
271
  method: "POST",
264
272
  headers: {
265
- "S-Source": r,
273
+ "S-Source": i,
266
274
  "Content-Type": "application/json"
267
275
  },
268
276
  body: {
@@ -272,17 +280,17 @@ async function oe(e) {
272
280
  subject: "embedded-page"
273
281
  }
274
282
  }
275
- ), s = n.success;
283
+ ), a = n.success;
276
284
  return {
277
- isVerified: s,
278
- isError: !s,
279
- error: s ? void 0 : "API request failed",
280
- data: s ? n.data : null
285
+ isVerified: a,
286
+ isError: !a,
287
+ error: a ? void 0 : "API request failed",
288
+ data: a ? n.data : null
281
289
  };
282
290
  } catch (n) {
283
- i && (F().ui.toast.error((n == null ? void 0 : n.toString()) ?? "Introspect error"), l(q.REFRESH, {})), u.error("Error in introspect:", n);
284
- const s = n instanceof Error ? n.message : n;
285
- return L(s);
291
+ r && (F().ui.toast.error((n == null ? void 0 : n.toString()) ?? "Introspect error"), o(z.REFRESH, {})), u.error("Error in introspect:", n);
292
+ const a = n instanceof Error ? n.message : n;
293
+ return I(a);
286
294
  }
287
295
  }
288
296
  function le(e) {
@@ -320,7 +328,7 @@ function le(e) {
320
328
  * ```
321
329
  */
322
330
  refresh() {
323
- l(q.REFRESH, {});
331
+ o(z.REFRESH, {});
324
332
  },
325
333
  /**
326
334
  * Introspect (verify) a short-lived token with Salla's API.
@@ -330,10 +338,10 @@ function le(e) {
330
338
  * @returns Promise that resolves with the introspect response. On API error, resolves with isVerified: false, isError: true, and empty data.
331
339
  */
332
340
  async introspect(t = {}) {
333
- const r = t.token ?? this.getToken() ?? "", i = t.appId ?? this.getAppId() ?? "";
341
+ const i = t.token ?? this.getToken() ?? "", r = t.appId ?? this.getAppId() ?? "";
334
342
  return oe({
335
- token: r,
336
- appId: i,
343
+ token: i,
344
+ appId: r,
337
345
  refreshOnError: t.refreshOnError
338
346
  });
339
347
  }
@@ -372,36 +380,36 @@ function fe(e) {
372
380
  }
373
381
  function he(e) {
374
382
  const t = [];
375
- return e.title === void 0 || e.title === null ? t.push("Nav action title is required") : typeof e.title != "string" && t.push("Nav action title must be a string"), e.onClick !== void 0 && e.onClick !== null && typeof e.onClick != "function" && t.push("Nav action onClick must be a function"), e.value !== void 0 && e.value !== null && typeof e.value != "string" && t.push("Nav action value must be a string"), e.subTitle !== void 0 && e.subTitle !== null && typeof e.subTitle != "string" && t.push("Nav action subTitle must be a string"), e.icon !== void 0 && e.icon !== null && typeof e.icon != "string" && t.push("Nav action icon must be a string"), e.disabled !== void 0 && e.disabled !== null && typeof e.disabled != "boolean" && t.push("Nav action disabled must be a boolean"), e.extendedActions !== void 0 && e.extendedActions !== null && (Array.isArray(e.extendedActions) ? e.extendedActions.forEach((r, i) => {
376
- if (typeof r != "object" || r === null) {
377
- t.push(`Extended action at index ${i} must be an object`);
383
+ return e.title === void 0 || e.title === null ? t.push("Nav action title is required") : typeof e.title != "string" && t.push("Nav action title must be a string"), e.onClick !== void 0 && e.onClick !== null && typeof e.onClick != "function" && t.push("Nav action onClick must be a function"), e.value !== void 0 && e.value !== null && typeof e.value != "string" && t.push("Nav action value must be a string"), e.subTitle !== void 0 && e.subTitle !== null && typeof e.subTitle != "string" && t.push("Nav action subTitle must be a string"), e.icon !== void 0 && e.icon !== null && typeof e.icon != "string" && t.push("Nav action icon must be a string"), e.disabled !== void 0 && e.disabled !== null && typeof e.disabled != "boolean" && t.push("Nav action disabled must be a boolean"), e.extendedActions !== void 0 && e.extendedActions !== null && (Array.isArray(e.extendedActions) ? e.extendedActions.forEach((i, r) => {
384
+ if (typeof i != "object" || i === null) {
385
+ t.push(`Extended action at index ${r} must be an object`);
378
386
  return;
379
387
  }
380
- const n = r;
388
+ const n = i;
381
389
  (!n.title || typeof n.title != "string") && t.push(
382
- `Extended action at index ${i} is missing required "title" property`
390
+ `Extended action at index ${r} is missing required "title" property`
383
391
  ), n.subTitle !== void 0 && typeof n.subTitle != "string" && t.push(
384
- `Extended action at index ${i} subTitle must be a string`
385
- ), n.url !== void 0 && typeof n.url != "string" && t.push(`Extended action at index ${i} url must be a string`), n.value !== void 0 && typeof n.value != "string" && t.push(
386
- `Extended action at index ${i} value must be a string`
392
+ `Extended action at index ${r} subTitle must be a string`
393
+ ), n.url !== void 0 && typeof n.url != "string" && t.push(`Extended action at index ${r} url must be a string`), n.value !== void 0 && typeof n.value != "string" && t.push(
394
+ `Extended action at index ${r} value must be a string`
387
395
  ), n.icon !== void 0 && typeof n.icon != "string" && t.push(
388
- `Extended action at index ${i} icon must be a string`
396
+ `Extended action at index ${r} icon must be a string`
389
397
  ), n.disabled !== void 0 && typeof n.disabled != "boolean" && t.push(
390
- `Extended action at index ${i} disabled must be a boolean`
398
+ `Extended action at index ${r} disabled must be a boolean`
391
399
  );
392
400
  }) : t.push("Nav action extendedActions must be an array")), { valid: t.length === 0, errors: t };
393
401
  }
394
- const D = ["danger", "warning", "info"];
402
+ const x = ["danger", "warning", "info"];
395
403
  function ge(e) {
396
404
  const t = [];
397
- return e.title === void 0 || e.title === null ? t.push("Confirm dialog title is required") : typeof e.title != "string" ? t.push("Confirm dialog title must be a string") : e.title.trim() === "" && t.push("Confirm dialog title cannot be empty"), e.message === void 0 || e.message === null ? t.push("Confirm dialog message is required") : typeof e.message != "string" ? t.push("Confirm dialog message must be a string") : e.message.trim() === "" && t.push("Confirm dialog message cannot be empty"), e.confirmText !== void 0 && e.confirmText !== null && typeof e.confirmText != "string" && t.push("Confirm dialog confirmText must be a string"), e.cancelText !== void 0 && e.cancelText !== null && typeof e.cancelText != "string" && t.push("Confirm dialog cancelText must be a string"), e.variant !== void 0 && e.variant !== null && (typeof e.variant != "string" || !D.includes(e.variant)) && t.push(
398
- `Invalid confirm variant "${e.variant}". Expected: ${D.join(" | ")}`
405
+ return e.title === void 0 || e.title === null ? t.push("Confirm dialog title is required") : typeof e.title != "string" ? t.push("Confirm dialog title must be a string") : e.title.trim() === "" && t.push("Confirm dialog title cannot be empty"), e.message === void 0 || e.message === null ? t.push("Confirm dialog message is required") : typeof e.message != "string" ? t.push("Confirm dialog message must be a string") : e.message.trim() === "" && t.push("Confirm dialog message cannot be empty"), e.confirmText !== void 0 && e.confirmText !== null && typeof e.confirmText != "string" && t.push("Confirm dialog confirmText must be a string"), e.cancelText !== void 0 && e.cancelText !== null && typeof e.cancelText != "string" && t.push("Confirm dialog cancelText must be a string"), e.variant !== void 0 && e.variant !== null && (typeof e.variant != "string" || !x.includes(e.variant)) && t.push(
406
+ `Invalid confirm variant "${e.variant}". Expected: ${x.join(" | ")}`
399
407
  ), { valid: t.length === 0, errors: t };
400
408
  }
401
409
  function f(e, t) {
402
410
  u.error(
403
411
  `Validation failed for ${e}:
404
- ` + t.map((r) => ` • ${r}`).join(`
412
+ ` + t.map((i) => ` • ${i}`).join(`
405
413
  `)
406
414
  );
407
415
  }
@@ -411,12 +419,12 @@ function me() {
411
419
  * Navigate to a path using React Router (SPA navigation).
412
420
  */
413
421
  navigate(e, t) {
414
- const r = de({ path: e, ...t });
415
- if (!r.valid) {
416
- f(m.NAVIGATE, r.errors);
422
+ const i = de({ path: e, ...t });
423
+ if (!i.valid) {
424
+ f(m.NAVIGATE, i.errors);
417
425
  return;
418
426
  }
419
- l(m.NAVIGATE, {
427
+ o(m.NAVIGATE, {
420
428
  path: e,
421
429
  state: t == null ? void 0 : t.state,
422
430
  replace: t == null ? void 0 : t.replace
@@ -431,7 +439,7 @@ function me() {
431
439
  f(m.REDIRECT, t.errors);
432
440
  return;
433
441
  }
434
- l(m.REDIRECT, { url: e });
442
+ o(m.REDIRECT, { url: e });
435
443
  },
436
444
  /**
437
445
  * Navigate to a path - auto-detects internal vs external.
@@ -448,12 +456,12 @@ function me() {
448
456
  */
449
457
  resize(e) {
450
458
  if (typeof e != "number" || e < 0) {
451
- f(T.RESIZE, [
459
+ f(y.RESIZE, [
452
460
  "Height must be a non-negative number"
453
461
  ]);
454
462
  return;
455
463
  }
456
- l(T.RESIZE, { height: e });
464
+ o(y.RESIZE, { height: e });
457
465
  },
458
466
  /**
459
467
  * Auto-resize iframe to content height.
@@ -472,14 +480,14 @@ function me() {
472
480
  ]);
473
481
  return;
474
482
  }
475
- l(m.SET_TITLE, { title: e });
483
+ o(m.SET_TITLE, { title: e });
476
484
  }
477
485
  };
478
486
  }
479
- function be() {
487
+ function pe() {
480
488
  const e = /* @__PURE__ */ new Set();
481
489
  let t = null;
482
- return v(S.ACTION_CLICK, (i) => {
490
+ return T(w.ACTION_CLICK, (r) => {
483
491
  if (t)
484
492
  try {
485
493
  t();
@@ -488,36 +496,36 @@ function be() {
488
496
  }
489
497
  e.forEach((n) => {
490
498
  try {
491
- n(i.url, i.value);
492
- } catch (s) {
493
- u.error("Error in action click callback:", s);
499
+ n(r.payload.url, r.payload.value);
500
+ } catch (a) {
501
+ u.error("Error in action click callback:", a);
494
502
  }
495
503
  });
496
504
  }), {
497
505
  /**
498
506
  * Set the primary action button.
499
507
  */
500
- setAction(i) {
501
- var s;
502
- const n = he(i);
508
+ setAction(r) {
509
+ var a;
510
+ const n = he(r);
503
511
  if (!n.valid) {
504
- f(S.SET_ACTION, n.errors);
512
+ f(w.SET_ACTION, n.errors);
505
513
  return;
506
514
  }
507
- i.onClick ? t = i.onClick : t = null, l(S.SET_ACTION, {
508
- title: i.title,
509
- onClick: i.onClick ? !0 : void 0,
510
- value: i.value,
511
- subTitle: i.subTitle,
512
- icon: i.icon,
513
- disabled: i.disabled,
514
- extendedActions: (s = i.extendedActions) == null ? void 0 : s.map((a) => ({
515
- title: a.title,
516
- subTitle: a.subTitle,
517
- url: a.url,
518
- value: a.value,
519
- icon: a.icon,
520
- disabled: a.disabled
515
+ r.onClick ? t = r.onClick : t = null, o(w.SET_ACTION, {
516
+ title: r.title,
517
+ onClick: r.onClick ? !0 : void 0,
518
+ value: r.value,
519
+ subTitle: r.subTitle,
520
+ icon: r.icon,
521
+ disabled: r.disabled,
522
+ extendedActions: (a = r.extendedActions) == null ? void 0 : a.map((l) => ({
523
+ title: l.title,
524
+ subTitle: l.subTitle,
525
+ url: l.url,
526
+ value: l.value,
527
+ icon: l.icon,
528
+ disabled: l.disabled
521
529
  }))
522
530
  });
523
531
  },
@@ -525,52 +533,52 @@ function be() {
525
533
  * Clear the primary action button.
526
534
  */
527
535
  clearAction() {
528
- t = null, l(S.SET_ACTION, {
536
+ t = null, o(w.SET_ACTION, {
529
537
  title: ""
530
538
  });
531
539
  },
532
540
  /**
533
541
  * Subscribe to action button clicks.
534
542
  */
535
- onActionClick(i) {
536
- return e.add(i), () => {
537
- e.delete(i);
543
+ onActionClick(r) {
544
+ return e.add(r), () => {
545
+ e.delete(r);
538
546
  };
539
547
  },
540
548
  // Legacy aliases
541
- primaryAction(i) {
542
- this.setAction(i);
549
+ primaryAction(r) {
550
+ this.setAction(r);
543
551
  },
544
552
  clearPrimaryAction() {
545
553
  this.clearAction();
546
554
  }
547
555
  };
548
556
  }
549
- function Ee() {
557
+ function be() {
550
558
  return {
551
559
  /**
552
560
  * Show loading indicator.
553
561
  * @param mode - Display mode ('full' for full page, 'component' for inline)
554
562
  */
555
563
  show(e = "full") {
556
- l(d.LOADING, { status: !1, mode: e });
564
+ o(d.LOADING, { status: !1, mode: e });
557
565
  },
558
566
  /**
559
567
  * Hide loading indicator.
560
568
  */
561
569
  hide() {
562
- l(d.LOADING, { status: !0, mode: "full" });
570
+ o(d.LOADING, { status: !0, mode: "full" });
563
571
  }
564
572
  };
565
573
  }
566
- function pe() {
574
+ function Ee() {
567
575
  const e = (t) => {
568
- const r = ue(t);
569
- if (!r.valid) {
570
- f(d.TOAST, r.errors);
576
+ const i = ue(t);
577
+ if (!i.valid) {
578
+ f(d.TOAST, i.errors);
571
579
  return;
572
580
  }
573
- l(d.TOAST, {
581
+ o(d.TOAST, {
574
582
  type: t.type,
575
583
  message: t.message,
576
584
  duration: t.duration
@@ -584,26 +592,26 @@ function pe() {
584
592
  /**
585
593
  * Show success toast.
586
594
  */
587
- success(t, r) {
588
- e({ type: "success", message: t, duration: r });
595
+ success(t, i) {
596
+ e({ type: "success", message: t, duration: i });
589
597
  },
590
598
  /**
591
599
  * Show error toast.
592
600
  */
593
- error(t, r) {
594
- e({ type: "error", message: t, duration: r });
601
+ error(t, i) {
602
+ e({ type: "error", message: t, duration: i });
595
603
  },
596
604
  /**
597
605
  * Show warning toast.
598
606
  */
599
- warning(t, r) {
600
- e({ type: "warning", message: t, duration: r });
607
+ warning(t, i) {
608
+ e({ type: "warning", message: t, duration: i });
601
609
  },
602
610
  /**
603
611
  * Show info toast.
604
612
  */
605
- info(t, r) {
606
- e({ type: "info", message: t, duration: r });
613
+ info(t, i) {
614
+ e({ type: "info", message: t, duration: i });
607
615
  }
608
616
  };
609
617
  }
@@ -613,7 +621,7 @@ function ye() {
613
621
  * Open a modal.
614
622
  */
615
623
  open(e, t) {
616
- l(d.MODAL, {
624
+ o(d.MODAL, {
617
625
  action: "open",
618
626
  id: e,
619
627
  content: t
@@ -623,7 +631,7 @@ function ye() {
623
631
  * Close a modal.
624
632
  */
625
633
  close(e) {
626
- l(d.MODAL, {
634
+ o(d.MODAL, {
627
635
  action: "close",
628
636
  id: e
629
637
  });
@@ -644,8 +652,8 @@ function Te() {
644
652
  }
645
653
  function ve() {
646
654
  return {
647
- loading: Ee(),
648
- toast: pe(),
655
+ loading: be(),
656
+ toast: Ee(),
649
657
  modal: ye(),
650
658
  confirm: Te()
651
659
  };
@@ -658,14 +666,14 @@ function we() {
658
666
  create(e) {
659
667
  const t = ce(e);
660
668
  if (!t.valid) {
661
- f(k.CREATE, t.errors);
669
+ f($.CREATE, t.errors);
662
670
  return;
663
671
  }
664
- l(k.CREATE, { payload: e });
672
+ o($.CREATE, e);
665
673
  }
666
674
  };
667
675
  }
668
- const x = {
676
+ const U = {
669
677
  debug: !1,
670
678
  initialized: !1
671
679
  }, Ae = {
@@ -673,14 +681,14 @@ const x = {
673
681
  width: 0,
674
682
  locale: "ar",
675
683
  currency: "SAR"
676
- }, U = {
684
+ }, V = {
677
685
  ready: !1,
678
686
  initializing: !1,
679
687
  layout: { ...Ae }
680
688
  };
681
689
  class Se {
682
690
  constructor() {
683
- this.config = { ...x }, this.state = { ...U }, this.themeCallbacks = /* @__PURE__ */ new Set(), this.initCallbacks = /* @__PURE__ */ new Set(), this.appReady = !1, this.auth = le(), this.page = me(), this.nav = be(), this.ui = ve(), this.checkout = we(), this.setupThemeListener(), this.setupResponseListeners();
691
+ this.config = { ...U }, this.state = { ...V }, this.themeCallbacks = /* @__PURE__ */ new Set(), this.initCallbacks = /* @__PURE__ */ new Set(), this.appReady = !1, this.auth = le(), this.page = me(), this.nav = pe(), this.ui = ve(), this.checkout = we(), this.setupThemeListener(), this.setupResponseListeners();
684
692
  }
685
693
  /**
686
694
  * Get current SDK state (layout info only, no token).
@@ -710,22 +718,22 @@ class Se {
710
718
  * @param type - Log type (log, warn, error, info, debug)
711
719
  * @param args - Arguments to log
712
720
  */
713
- internalLog(t, ...r) {
721
+ internalLog(t, ...i) {
714
722
  switch (t) {
715
723
  case "log":
716
- u.log(...r);
724
+ u.log(...i);
717
725
  break;
718
726
  case "warn":
719
- u.warn(...r);
727
+ u.warn(...i);
720
728
  break;
721
729
  case "error":
722
- u.error(...r);
730
+ u.error(...i);
723
731
  break;
724
732
  case "info":
725
- u.info(...r);
733
+ u.info(...i);
726
734
  break;
727
735
  case "debug":
728
- u.debug(...r);
736
+ u.debug(...i);
729
737
  break;
730
738
  }
731
739
  }
@@ -733,12 +741,12 @@ class Se {
733
741
  * Set up listener for theme changes from host.
734
742
  */
735
743
  setupThemeListener() {
736
- v(N.THEME_CHANGE, (t) => {
737
- this.state.layout.theme = t.theme, this.internalLog("debug", "Theme changed:", t.theme), this.themeCallbacks.forEach((r) => {
744
+ T(k.THEME_CHANGE, (t) => {
745
+ this.state.layout.theme = t.payload.theme, this.internalLog("debug", "Theme changed:", t.payload.theme), this.themeCallbacks.forEach((i) => {
738
746
  try {
739
- r(t.theme);
740
- } catch (i) {
741
- this.internalLog("error", "Error in theme callback:", i);
747
+ i(t.payload.theme);
748
+ } catch (r) {
749
+ this.internalLog("error", "Error in theme callback:", r);
742
750
  }
743
751
  });
744
752
  });
@@ -747,10 +755,10 @@ class Se {
747
755
  * Set up listeners for async response events from host.
748
756
  */
749
757
  setupResponseListeners() {
750
- v(d.CONFIRM_RESPONSE, (t) => {
751
- this.internalLog("debug", "Received confirm response:", t), _(t.requestId, { confirmed: t.confirmed });
752
- }), v(d.MODAL_RESPONSE, (t) => {
753
- this.internalLog("debug", "Received modal response:", t), _(t.requestId, t.result, t.error);
758
+ T(d.CONFIRM_RESPONSE, (t) => {
759
+ this.internalLog("debug", "Received confirm response:", t), t.requestId && D(t.requestId, { confirmed: t.payload.confirmed });
760
+ }), T(d.MODAL_RESPONSE, (t) => {
761
+ this.internalLog("debug", "Received modal response:", t), t.requestId && D(t.requestId, t.payload.result, t.payload.error);
754
762
  });
755
763
  }
756
764
  /**
@@ -788,8 +796,8 @@ class Se {
788
796
  if (this.config.initialized)
789
797
  try {
790
798
  t(this.getState());
791
- } catch (r) {
792
- this.internalLog("error", "Error in init callback:", r);
799
+ } catch (i) {
800
+ this.internalLog("error", "Error in init callback:", i);
793
801
  }
794
802
  return this.initCallbacks.add(t), () => {
795
803
  this.initCallbacks.delete(t);
@@ -807,11 +815,11 @@ class Se {
807
815
  * embedded.log('error', 'Failed to load data', { endpoint: '/api/data' });
808
816
  * ```
809
817
  */
810
- log(t, r, i) {
811
- l(j.LOG, {
818
+ log(t, i, r) {
819
+ o(j.LOG, {
812
820
  level: t,
813
- message: r,
814
- context: i
821
+ message: i,
822
+ context: r
815
823
  });
816
824
  }
817
825
  /**
@@ -833,7 +841,7 @@ class Se {
833
841
  this.internalLog("warn", "Cannot signal ready before init() is called");
834
842
  return;
835
843
  }
836
- this.appReady = !0, l(T.READY, {}), this.internalLog("debug", "Sent ready signal to host");
844
+ this.appReady = !0, o(y.READY, {}), this.internalLog("debug", "Sent ready signal to host");
837
845
  }
838
846
  /**
839
847
  * Initialize the SDK and establish connection with the host.
@@ -849,7 +857,6 @@ class Se {
849
857
  * ```
850
858
  */
851
859
  async init(t = {}) {
852
- var r, i, n, s;
853
860
  if (this.config.initialized)
854
861
  return this.internalLog(
855
862
  "debug",
@@ -867,39 +874,41 @@ class Se {
867
874
  debug: this.config.debug
868
875
  }), this.state.initializing = !0, this.internalLog("debug", "Initializing SDK...");
869
876
  try {
870
- l(T.INIT, {
877
+ o(y.INIT, {
871
878
  height: document.documentElement.scrollHeight
872
879
  }), this.internalLog(
873
880
  "debug",
874
881
  "Sent iframe.ready message, waiting for context..."
875
882
  );
876
- const a = await J(
877
- N.PROVIDE
883
+ const i = await J(
884
+ k.PROVIDE
878
885
  );
879
- this.internalLog("debug", "Received context from host:", a), this.state = {
886
+ this.internalLog("debug", "Received context from host:", i);
887
+ const r = i.payload.layout;
888
+ this.state = {
880
889
  ready: !0,
881
890
  initializing: !1,
882
891
  layout: {
883
- theme: ((r = a.layout) == null ? void 0 : r.theme) ?? "light",
884
- width: ((i = a.layout) == null ? void 0 : i.width) ?? 0,
885
- locale: ((n = a.layout) == null ? void 0 : n.locale) ?? "ar",
886
- currency: ((s = a.layout) == null ? void 0 : s.currency) ?? "SAR"
892
+ theme: (r == null ? void 0 : r.theme) ?? "light",
893
+ width: (r == null ? void 0 : r.width) ?? 0,
894
+ locale: (r == null ? void 0 : r.locale) ?? "ar",
895
+ currency: (r == null ? void 0 : r.currency) ?? "SAR"
887
896
  }
888
897
  }, this.config.initialized = !0, this.internalLog(
889
898
  "debug",
890
899
  "Initialization complete. Layout:",
891
900
  this.state.layout
892
901
  );
893
- const E = this.getState();
894
- return this.initCallbacks.forEach((w) => {
902
+ const n = this.getState();
903
+ return this.initCallbacks.forEach((a) => {
895
904
  try {
896
- w(E);
897
- } catch (c) {
898
- this.internalLog("error", "Error in init callback:", c);
905
+ a(n);
906
+ } catch (l) {
907
+ this.internalLog("error", "Error in init callback:", l);
899
908
  }
900
909
  }), { layout: { ...this.state.layout } };
901
- } catch (a) {
902
- throw this.state.initializing = !1, this.state.ready = !1, a;
910
+ } catch (i) {
911
+ throw this.state.initializing = !1, this.state.ready = !1, i;
903
912
  }
904
913
  }
905
914
  /**
@@ -908,8 +917,8 @@ class Se {
908
917
  */
909
918
  waitForInit() {
910
919
  return new Promise((t) => {
911
- const r = this.onInit((i) => {
912
- r(), t({ layout: { ...i.layout } });
920
+ const i = this.onInit((r) => {
921
+ i(), t({ layout: { ...r.layout } });
913
922
  });
914
923
  });
915
924
  }
@@ -924,21 +933,21 @@ class Se {
924
933
  * ```
925
934
  */
926
935
  destroy() {
927
- this.internalLog("debug", "Destroying SDK instance"), this.config.initialized && (l(T.DESTROY, {}), this.internalLog("debug", "Sent destroy event to host")), ne("SDK destroyed"), Q(), this.themeCallbacks.clear(), this.initCallbacks.clear(), this.config = { ...x }, this.state = { ...U }, this.appReady = !1;
936
+ this.internalLog("debug", "Destroying SDK instance"), this.config.initialized && (o(y.DESTROY, {}), this.internalLog("debug", "Sent destroy event to host")), ne("SDK destroyed"), Q(), this.themeCallbacks.clear(), this.initCallbacks.clear(), this.config = { ...U }, this.state = { ...V }, this.appReady = !1;
928
937
  }
929
938
  }
930
- let b = null;
939
+ let p = null;
931
940
  function F() {
932
- return b || (b = new Se()), b;
941
+ return p || (p = new Se()), p;
933
942
  }
934
943
  function Re() {
935
- b && (b.destroy(), b = null);
944
+ p && (p.destroy(), p = null);
936
945
  }
937
- const V = F(), Ce = z;
938
- typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = V), window.Salla.embedded || (window.Salla.embedded = V));
946
+ const q = F(), Ce = L;
947
+ typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = q), window.Salla.embedded || (window.Salla.embedded = q));
939
948
  export {
940
949
  Se as EmbeddedApp,
941
- V as embedded,
950
+ q as embedded,
942
951
  F as getEmbeddedApp,
943
952
  Re as resetEmbeddedApp,
944
953
  Ce as version