@salla.sa/embedded-sdk 0.1.0-beta.2 → 0.1.0-beta.3

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,178 +1,176 @@
1
- const _ = "0.1.0-beta.2", M = {
2
- version: _
3
- }, n = "embedded::", y = {
1
+ const $ = "0.1.0-beta.3", k = {
2
+ version: $
3
+ }, s = "embedded::", g = {
4
4
  /** Initialize handshake - iframe signals it's ready to receive context */
5
- INIT: `${n}iframe.ready`,
5
+ INIT: `${s}iframe.ready`,
6
6
  /** Request iframe resize */
7
- RESIZE: `${n}iframe.resize`,
7
+ RESIZE: `${s}iframe.resize`,
8
8
  /** App signals it's fully loaded and ready */
9
- READY: `${n}ready`
10
- }, S = {
9
+ READY: `${s}ready`,
10
+ /** App requests to be destroyed and navigate away */
11
+ DESTROY: `${s}destroy`
12
+ }, w = {
11
13
  /** Context data provision */
12
- PROVIDE: `${n}context.provide`,
14
+ PROVIDE: `${s}context.provide`,
13
15
  /** Theme change notification */
14
- THEME_CHANGE: `${n}theme.change`
15
- }, k = {
16
+ THEME_CHANGE: `${s}theme.change`
17
+ }, _ = {
16
18
  /** Send log message to host */
17
- LOG: `${n}log`
18
- }, v = {
19
- /** Request logout and redirect to apps page */
20
- LOGOUT: `${n}auth.logout`,
19
+ LOG: `${s}log`
20
+ }, M = {
21
21
  /** Request token refresh (re-renders iframe with new token) */
22
- REFRESH: `${n}auth.refresh`,
23
- /** Signal auth error to host */
24
- ERROR: `${n}auth.error`
22
+ REFRESH: `${s}auth.refresh`
25
23
  }, h = {
26
24
  /** Navigate using React Router (SPA navigation) */
27
- NAVIGATE: `${n}page.navigate`,
25
+ NAVIGATE: `${s}page.navigate`,
28
26
  /** Redirect using window.location (full page reload) */
29
- REDIRECT: `${n}page.redirect`,
27
+ REDIRECT: `${s}page.redirect`,
30
28
  /** Set page title */
31
- SET_TITLE: `${n}page.setTitle`
32
- }, E = {
29
+ SET_TITLE: `${s}page.setTitle`
30
+ }, b = {
33
31
  /** Set primary action button in navbar */
34
- SET_ACTION: `${n}nav.setAction`,
32
+ SET_ACTION: `${s}nav.setAction`,
35
33
  /** Notification when action button is clicked (host → iframe) */
36
- ACTION_CLICK: `${n}nav.actionClick`
37
- }, l = {
34
+ ACTION_CLICK: `${s}nav.actionClick`
35
+ }, u = {
38
36
  /** Set loading state */
39
- LOADING: `${n}ui.loading`,
37
+ LOADING: `${s}ui.loading`,
40
38
  /** Control overlay state */
41
- OVERLAY: `${n}ui.overlay`,
39
+ OVERLAY: `${s}ui.overlay`,
42
40
  /** Show toast notification */
43
- TOAST: `${n}ui.toast`,
41
+ TOAST: `${s}ui.toast`,
44
42
  /** Control modal state */
45
- MODAL: `${n}ui.modal`,
43
+ MODAL: `${s}ui.modal`,
46
44
  /** Show confirm dialog (async request) */
47
- CONFIRM: `${n}ui.confirm`,
45
+ CONFIRM: `${s}ui.confirm`,
48
46
  /** Confirm dialog response (from host) */
49
- CONFIRM_RESPONSE: `${n}ui.confirm.response`,
47
+ CONFIRM_RESPONSE: `${s}ui.confirm.response`,
50
48
  /** Modal response (from host) */
51
- MODAL_RESPONSE: `${n}ui.modal.response`
49
+ MODAL_RESPONSE: `${s}ui.modal.response`
52
50
  }, p = {
53
51
  /** Initialize checkout flow */
54
- CREATE: `${n}checkout.create`
55
- }, b = M.version, x = 1e4, V = [
52
+ CREATE: `${s}checkout.create`
53
+ }, T = k.version, x = 1e4, V = [
56
54
  "localhost",
57
55
  "merchants.workers.dev",
58
56
  "s.salla.sa",
59
57
  ".salla.group",
60
58
  ".salla.sa"
61
59
  ];
62
- function U(t) {
60
+ function z(e) {
63
61
  try {
64
- const i = new URL(t).hostname;
65
- return V.some((r) => r.startsWith(".") ? i.endsWith(r) || i === r.slice(1) : i === r || i.startsWith(`${r}:`));
62
+ const n = new URL(e).hostname;
63
+ return V.some((i) => i.startsWith(".") ? n.endsWith(i) || n === i.slice(1) : n === i || n.startsWith(`${i}:`));
66
64
  } catch {
67
65
  return !1;
68
66
  }
69
67
  }
70
- function z() {
68
+ function K() {
71
69
  return typeof window > "u" || window.parent === window ? null : window.parent;
72
70
  }
73
- function s(t, e, i = "*") {
74
- const r = z();
75
- if (!r) {
71
+ function a(e, t, n = "*") {
72
+ const i = K();
73
+ if (!i) {
76
74
  console.warn("[EmbeddedSDK] Not running in an iframe, cannot post to host");
77
75
  return;
78
76
  }
79
- const a = {
80
- event: t,
81
- ...e
77
+ const r = {
78
+ event: e,
79
+ ...t
82
80
  };
83
- r.postMessage(a, i);
81
+ i.postMessage(r, n);
84
82
  }
85
83
  const d = /* @__PURE__ */ new Map();
86
- let T = !1;
87
- function O(t) {
88
- if (process.env.NODE_ENV === "production" && !U(t.origin))
84
+ let y = !1;
85
+ function N(e) {
86
+ if (process.env.NODE_ENV === "production" && !z(e.origin))
89
87
  return;
90
- const e = t.data;
91
- if (!e || typeof e.event != "string")
88
+ const t = e.data;
89
+ if (!t || typeof t.event != "string")
92
90
  return;
93
- const i = d.get(e.event);
94
- i && i.forEach((a) => {
91
+ const n = d.get(t.event);
92
+ n && n.forEach((r) => {
95
93
  try {
96
- a(e);
97
- } catch (o) {
98
- console.error("[EmbeddedSDK] Error in message handler:", o);
94
+ r(t);
95
+ } catch (l) {
96
+ console.error("[EmbeddedSDK] Error in message handler:", l);
99
97
  }
100
98
  });
101
- const r = d.get("*");
102
- r && r.forEach((a) => {
99
+ const i = d.get("*");
100
+ i && i.forEach((r) => {
103
101
  try {
104
- a(e);
105
- } catch (o) {
106
- console.error("[EmbeddedSDK] Error in wildcard handler:", o);
102
+ r(t);
103
+ } catch (l) {
104
+ console.error("[EmbeddedSDK] Error in wildcard handler:", l);
107
105
  }
108
106
  });
109
107
  }
110
- function K() {
111
- T || typeof window > "u" || (window.addEventListener("message", O), T = !0);
108
+ function U() {
109
+ y || typeof window > "u" || (window.addEventListener("message", N), y = !0);
112
110
  }
113
- function g(t, e) {
114
- K(), d.has(t) || d.set(t, /* @__PURE__ */ new Set());
115
- const i = d.get(t);
116
- return i.add(e), () => {
117
- i.delete(e), i.size === 0 && d.delete(t);
111
+ function E(e, t) {
112
+ U(), d.has(e) || d.set(e, /* @__PURE__ */ new Set());
113
+ const n = d.get(e);
114
+ return n.add(t), () => {
115
+ n.delete(t), n.size === 0 && d.delete(e);
118
116
  };
119
117
  }
120
- function F(t, e = x) {
121
- return new Promise((i, r) => {
122
- const a = setTimeout(() => {
123
- o(), r(new Error(`[EmbeddedSDK] Timeout waiting for "${t}" message`));
124
- }, e), o = g(t, (u) => {
125
- clearTimeout(a), o(), i(u);
118
+ function F(e, t = x) {
119
+ return new Promise((n, i) => {
120
+ const r = setTimeout(() => {
121
+ l(), i(new Error(`[EmbeddedSDK] Timeout waiting for "${e}" message`));
122
+ }, t), l = E(e, (o) => {
123
+ clearTimeout(r), l(), n(o);
126
124
  });
127
125
  });
128
126
  }
129
127
  function q() {
130
- d.clear(), T && typeof window < "u" && (window.removeEventListener("message", O), T = !1);
128
+ d.clear(), y && typeof window < "u" && (window.removeEventListener("message", N), y = !1);
131
129
  }
132
130
  function P() {
133
131
  return typeof window > "u" ? !1 : window.parent !== window;
134
132
  }
135
133
  const f = /* @__PURE__ */ new Map(), G = 3e4;
136
134
  function H() {
137
- const t = Date.now(), e = Math.random().toString(36).slice(2, 9);
138
- return `req_${t}_${e}`;
139
- }
140
- function j(t, e = {}, i = G) {
141
- const r = H();
142
- return new Promise((a, o) => {
143
- const u = setTimeout(() => {
144
- f.get(r) && (f.delete(r), o(
135
+ const e = Date.now(), t = Math.random().toString(36).slice(2, 9);
136
+ return `req_${e}_${t}`;
137
+ }
138
+ function j(e, t = {}, n = G) {
139
+ const i = H();
140
+ return new Promise((r, l) => {
141
+ const o = setTimeout(() => {
142
+ f.get(i) && (f.delete(i), l(
145
143
  new Error(
146
- `[EmbeddedSDK] Request "${t}" timed out after ${i}ms`
144
+ `[EmbeddedSDK] Request "${e}" timed out after ${n}ms`
147
145
  )
148
146
  ));
149
- }, i);
150
- f.set(r, {
151
- resolve: a,
152
- reject: o,
153
- timeout: u,
154
- event: t
155
- }), s(t, { ...e, requestId: r });
147
+ }, n);
148
+ f.set(i, {
149
+ resolve: r,
150
+ reject: l,
151
+ timeout: o,
152
+ event: e
153
+ }), a(e, { ...t, requestId: i });
156
154
  });
157
155
  }
158
- function A(t, e, i) {
159
- const r = f.get(t);
160
- if (!r) {
156
+ function S(e, t, n) {
157
+ const i = f.get(e);
158
+ if (!i) {
161
159
  console.warn(
162
- `[EmbeddedSDK] Received response for unknown request: ${t}`
160
+ `[EmbeddedSDK] Received response for unknown request: ${e}`
163
161
  );
164
162
  return;
165
163
  }
166
- clearTimeout(r.timeout), f.delete(t), i ? r.reject(new Error(i)) : r.resolve(e);
164
+ clearTimeout(i.timeout), f.delete(e), n ? i.reject(new Error(n)) : i.resolve(t);
167
165
  }
168
- function Y(t = "SDK cleanup") {
169
- f.forEach((e, i) => {
170
- clearTimeout(e.timeout), e.reject(
171
- new Error(`[EmbeddedSDK] Request ${i} cancelled: ${t}`)
166
+ function Y(e = "SDK cleanup") {
167
+ f.forEach((t, n) => {
168
+ clearTimeout(t.timeout), t.reject(
169
+ new Error(`[EmbeddedSDK] Request ${n} cancelled: ${e}`)
172
170
  );
173
171
  }), f.clear();
174
172
  }
175
- function W(t) {
173
+ function W(e) {
176
174
  return {
177
175
  /**
178
176
  * Get the token from the URL query parameter.
@@ -189,18 +187,6 @@ function W(t) {
189
187
  getToken() {
190
188
  return new URLSearchParams(window.location.search).get("token");
191
189
  },
192
- /**
193
- * Request logout from the host.
194
- * This will navigate to the installed apps page.
195
- *
196
- * @example
197
- * ```typescript
198
- * embedded.auth.logout();
199
- * ```
200
- */
201
- logout() {
202
- s(v.LOGOUT, {});
203
- },
204
190
  /**
205
191
  * Request a token refresh from the host.
206
192
  * This will re-render the iframe with a new token URL.
@@ -212,83 +198,75 @@ function W(t) {
212
198
  * ```
213
199
  */
214
200
  refresh() {
215
- s(v.REFRESH, {});
216
- },
217
- /**
218
- * Signal an authentication error to the host.
219
- * This will navigate away and show an error toast.
220
- *
221
- * @param message - Error message to display
222
- *
223
- * @example
224
- * ```typescript
225
- * try {
226
- * await verifyToken(token);
227
- * } catch (err) {
228
- * embedded.auth.error(err.message);
229
- * }
230
- * ```
231
- */
232
- error(e) {
233
- s(v.ERROR, { message: e });
201
+ a(M.REFRESH, {});
234
202
  }
235
203
  };
236
204
  }
237
- const R = ["success", "error", "warning", "info"];
238
- function Z(t) {
239
- const e = [];
240
- return t.type === void 0 || t.type === null ? e.push("Toast type is required") : (typeof t.type != "string" || !R.includes(t.type)) && e.push(
241
- `Invalid toast type "${t.type}". Expected: ${R.join(" | ")}`
242
- ), 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 };
243
- }
244
- function X(t) {
245
- const e = [];
246
- return typeof t != "object" || t === null ? (e.push("Checkout payload must be an object"), { valid: !1, errors: e }) : (t.amount !== void 0 && t.amount !== null && (typeof t.amount != "number" ? e.push("Checkout amount must be a number") : t.amount < 0 && e.push("Checkout amount cannot be negative")), t.currency !== void 0 && t.currency !== null && (typeof t.currency != "string" ? e.push("Checkout currency must be a string") : t.currency.trim() === "" && e.push("Checkout currency cannot be empty")), t.items !== void 0 && t.items !== null && (Array.isArray(t.items) || e.push("Checkout items must be an array")), { valid: e.length === 0, errors: e });
247
- }
248
- function Q(t) {
249
- const e = [];
250
- 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 };
251
- }
252
- function B(t) {
253
- const e = [];
254
- if (t.url === void 0 || t.url === null)
255
- e.push("Redirect URL is required");
256
- else if (typeof t.url != "string")
257
- e.push("Redirect URL must be a string");
258
- else if (t.url.trim() === "")
259
- e.push("Redirect URL cannot be empty");
205
+ const A = ["success", "error", "warning", "info"];
206
+ function Z(e) {
207
+ const t = [];
208
+ return e.type === void 0 || e.type === null ? t.push("Toast type is required") : (typeof e.type != "string" || !A.includes(e.type)) && t.push(
209
+ `Invalid toast type "${e.type}". Expected: ${A.join(" | ")}`
210
+ ), e.message === void 0 || e.message === null ? t.push("Toast message is required") : typeof e.message != "string" ? t.push("Toast message must be a string") : e.message.trim() === "" && t.push("Toast message cannot be empty"), e.duration !== void 0 && e.duration !== null && (typeof e.duration != "number" ? t.push("Toast duration must be a number") : e.duration < 0 && t.push("Toast duration cannot be negative")), { valid: t.length === 0, errors: t };
211
+ }
212
+ function X(e) {
213
+ const t = [];
214
+ return typeof e != "object" || e === null ? (t.push("Checkout payload must be an object"), { valid: !1, errors: t }) : (e.amount !== void 0 && e.amount !== null && (typeof e.amount != "number" ? t.push("Checkout amount must be a number") : e.amount < 0 && t.push("Checkout amount cannot be negative")), e.currency !== void 0 && e.currency !== null && (typeof e.currency != "string" ? t.push("Checkout currency must be a string") : e.currency.trim() === "" && t.push("Checkout currency cannot be empty")), e.items !== void 0 && e.items !== null && (Array.isArray(e.items) || t.push("Checkout items must be an array")), { valid: t.length === 0, errors: t });
215
+ }
216
+ function Q(e) {
217
+ const t = [];
218
+ return e.path === void 0 || e.path === null ? t.push("Navigation path is required") : typeof e.path != "string" ? t.push("Navigation path must be a string") : e.path.trim() === "" && t.push("Navigation path cannot be empty"), e.replace !== void 0 && typeof e.replace != "boolean" && t.push("Navigation replace option must be a boolean"), { valid: t.length === 0, errors: t };
219
+ }
220
+ function B(e) {
221
+ const t = [];
222
+ if (e.url === void 0 || e.url === null)
223
+ t.push("Redirect URL is required");
224
+ else if (typeof e.url != "string")
225
+ t.push("Redirect URL must be a string");
226
+ else if (e.url.trim() === "")
227
+ t.push("Redirect URL cannot be empty");
260
228
  else
261
229
  try {
262
- new URL(t.url);
230
+ new URL(e.url);
263
231
  } catch {
264
- e.push(`Invalid redirect URL: "${t.url}"`);
232
+ t.push(`Invalid redirect URL: "${e.url}"`);
265
233
  }
266
- return { valid: e.length === 0, errors: e };
234
+ return { valid: t.length === 0, errors: t };
267
235
  }
268
- function J(t) {
269
- const e = [];
270
- return t.title === void 0 || t.title === null ? e.push("Nav action title is required") : typeof t.title != "string" && e.push("Nav action title must be a string"), t.url !== void 0 && t.url !== null && typeof t.url != "string" && e.push("Nav action URL must be a string"), t.value !== void 0 && t.value !== null && typeof t.value != "string" && e.push("Nav action value must be a string"), t.extendedActions !== void 0 && t.extendedActions !== null && (Array.isArray(t.extendedActions) ? t.extendedActions.forEach((i, r) => {
271
- if (typeof i != "object" || i === null) {
272
- e.push(`Extended action at index ${r} must be an object`);
236
+ function J(e) {
237
+ const t = [];
238
+ 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((n, i) => {
239
+ if (typeof n != "object" || n === null) {
240
+ t.push(`Extended action at index ${i} must be an object`);
273
241
  return;
274
242
  }
275
- const a = i;
276
- (!a.title || typeof a.title != "string") && e.push(
277
- `Extended action at index ${r} is missing required "title" property`
243
+ const r = n;
244
+ (!r.title || typeof r.title != "string") && t.push(
245
+ `Extended action at index ${i} is missing required "title" property`
246
+ ), r.subTitle !== void 0 && typeof r.subTitle != "string" && t.push(
247
+ `Extended action at index ${i} subTitle must be a string`
248
+ ), r.url !== void 0 && typeof r.url != "string" && t.push(
249
+ `Extended action at index ${i} url must be a string`
250
+ ), r.value !== void 0 && typeof r.value != "string" && t.push(
251
+ `Extended action at index ${i} value must be a string`
252
+ ), r.icon !== void 0 && typeof r.icon != "string" && t.push(
253
+ `Extended action at index ${i} icon must be a string`
254
+ ), r.disabled !== void 0 && typeof r.disabled != "boolean" && t.push(
255
+ `Extended action at index ${i} disabled must be a boolean`
278
256
  );
279
- }) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
257
+ }) : t.push("Nav action extendedActions must be an array")), { valid: t.length === 0, errors: t };
280
258
  }
281
259
  const C = ["danger", "warning", "info"];
282
- function ee(t) {
283
- const e = [];
284
- 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" || !C.includes(t.variant)) && e.push(
285
- `Invalid confirm variant "${t.variant}". Expected: ${C.join(" | ")}`
286
- ), { valid: e.length === 0, errors: e };
260
+ function ee(e) {
261
+ const t = [];
262
+ 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" || !C.includes(e.variant)) && t.push(
263
+ `Invalid confirm variant "${e.variant}". Expected: ${C.join(" | ")}`
264
+ ), { valid: t.length === 0, errors: t };
287
265
  }
288
- function c(t, e) {
266
+ function c(e, t) {
289
267
  console.error(
290
- `[EmbeddedSDK] Validation failed for ${t}:
291
- ` + e.map((i) => ` • ${i}`).join(`
268
+ `[EmbeddedSDK] Validation failed for ${e}:
269
+ ` + t.map((n) => ` • ${n}`).join(`
292
270
  `)
293
271
  );
294
272
  }
@@ -297,198 +275,216 @@ function te() {
297
275
  /**
298
276
  * Navigate to a path using React Router (SPA navigation).
299
277
  */
300
- navigate(t, e) {
301
- const i = Q({ path: t, ...e });
302
- if (!i.valid) {
303
- c(h.NAVIGATE, i.errors);
278
+ navigate(e, t) {
279
+ const n = Q({ path: e, ...t });
280
+ if (!n.valid) {
281
+ c(h.NAVIGATE, n.errors);
304
282
  return;
305
283
  }
306
- s(h.NAVIGATE, {
307
- path: t,
308
- state: e == null ? void 0 : e.state,
309
- replace: e == null ? void 0 : e.replace
284
+ a(h.NAVIGATE, {
285
+ path: e,
286
+ state: t == null ? void 0 : t.state,
287
+ replace: t == null ? void 0 : t.replace
310
288
  });
311
289
  },
312
290
  /**
313
291
  * Redirect to a URL (full page reload).
314
292
  */
315
- redirect(t) {
316
- const e = B({ url: t });
317
- if (!e.valid) {
318
- c(h.REDIRECT, e.errors);
293
+ redirect(e) {
294
+ const t = B({ url: e });
295
+ if (!t.valid) {
296
+ c(h.REDIRECT, t.errors);
319
297
  return;
320
298
  }
321
- s(h.REDIRECT, { url: t });
299
+ a(h.REDIRECT, { url: e });
322
300
  },
323
301
  /**
324
302
  * Navigate to a path - auto-detects internal vs external.
325
303
  */
326
- navTo(t, e) {
327
- if (t.startsWith("http://") || t.startsWith("https://")) {
328
- this.redirect(t);
304
+ navTo(e, t) {
305
+ if (e.startsWith("http://") || e.startsWith("https://")) {
306
+ this.redirect(e);
329
307
  return;
330
308
  }
331
- this.navigate(t, e);
309
+ this.navigate(e, t);
332
310
  },
333
311
  /**
334
312
  * Update the iframe height.
335
313
  */
336
- resize(t) {
337
- if (typeof t != "number" || t < 0) {
338
- c(y.RESIZE, [
314
+ resize(e) {
315
+ if (typeof e != "number" || e < 0) {
316
+ c(g.RESIZE, [
339
317
  "Height must be a non-negative number"
340
318
  ]);
341
319
  return;
342
320
  }
343
- s(y.RESIZE, { height: t });
321
+ a(g.RESIZE, { height: e });
344
322
  },
345
323
  /**
346
324
  * Auto-resize iframe to content height.
347
325
  */
348
326
  autoResize() {
349
- const t = document.documentElement.scrollHeight;
350
- this.resize(t);
327
+ const e = document.documentElement.scrollHeight;
328
+ this.resize(e);
351
329
  },
352
330
  /**
353
331
  * Set the page title in the host document.
354
332
  */
355
- setTitle(t) {
356
- if (typeof t != "string" || !t.trim()) {
333
+ setTitle(e) {
334
+ if (typeof e != "string" || !e.trim()) {
357
335
  c(h.SET_TITLE, [
358
336
  "Title must be a non-empty string"
359
337
  ]);
360
338
  return;
361
339
  }
362
- s(h.SET_TITLE, { title: t });
340
+ a(h.SET_TITLE, { title: e });
363
341
  }
364
342
  };
365
343
  }
366
344
  function ie() {
367
- const t = /* @__PURE__ */ new Set();
368
- return g(E.ACTION_CLICK, (e) => {
369
- t.forEach((i) => {
345
+ const e = /* @__PURE__ */ new Set();
346
+ let t = null;
347
+ return E(b.ACTION_CLICK, (i) => {
348
+ if (t)
370
349
  try {
371
- i(e.url, e.value);
350
+ t();
372
351
  } catch (r) {
373
- console.error("[EmbeddedSDK] Error in action click callback:", r);
352
+ console.error("[EmbeddedSDK] Error in onClick callback:", r);
353
+ }
354
+ e.forEach((r) => {
355
+ try {
356
+ r(i.url, i.value);
357
+ } catch (l) {
358
+ console.error("[EmbeddedSDK] Error in action click callback:", l);
374
359
  }
375
360
  });
376
361
  }), {
377
362
  /**
378
363
  * Set the primary action button.
379
364
  */
380
- setAction(e) {
381
- const i = J(e);
382
- if (!i.valid) {
383
- c(E.SET_ACTION, i.errors);
365
+ setAction(i) {
366
+ var l;
367
+ const r = J(i);
368
+ if (!r.valid) {
369
+ c(b.SET_ACTION, r.errors);
384
370
  return;
385
371
  }
386
- s(E.SET_ACTION, {
387
- title: e.title,
388
- url: e.url,
389
- value: e.value,
390
- extendedActions: e.extendedActions
372
+ i.onClick ? t = i.onClick : t = null, a(b.SET_ACTION, {
373
+ title: i.title,
374
+ onClick: i.onClick ? !0 : void 0,
375
+ value: i.value,
376
+ subTitle: i.subTitle,
377
+ icon: i.icon,
378
+ disabled: i.disabled,
379
+ extendedActions: (l = i.extendedActions) == null ? void 0 : l.map((o) => ({
380
+ title: o.title,
381
+ subTitle: o.subTitle,
382
+ url: o.url,
383
+ value: o.value,
384
+ icon: o.icon,
385
+ disabled: o.disabled
386
+ }))
391
387
  });
392
388
  },
393
389
  /**
394
390
  * Clear the primary action button.
395
391
  */
396
392
  clearAction() {
397
- s(E.SET_ACTION, {
393
+ t = null, a(b.SET_ACTION, {
398
394
  title: ""
399
395
  });
400
396
  },
401
397
  /**
402
398
  * Subscribe to action button clicks.
403
399
  */
404
- onActionClick(e) {
405
- return t.add(e), () => {
406
- t.delete(e);
400
+ onActionClick(i) {
401
+ return e.add(i), () => {
402
+ e.delete(i);
407
403
  };
408
404
  },
409
405
  // Legacy aliases
410
- primaryAction(e) {
411
- this.setAction(e);
406
+ primaryAction(i) {
407
+ this.setAction(i);
412
408
  },
413
409
  clearPrimaryAction() {
414
410
  this.clearAction();
415
411
  }
416
412
  };
417
413
  }
418
- function re() {
414
+ function ne() {
419
415
  return {
420
416
  /**
421
417
  * Show loading indicator.
422
418
  * @param mode - Display mode ('full' for full page, 'component' for inline)
423
419
  */
424
- show(t = "full") {
425
- s(l.LOADING, { status: !1, mode: t });
420
+ show(e = "full") {
421
+ a(u.LOADING, { status: !1, mode: e });
426
422
  },
427
423
  /**
428
424
  * Hide loading indicator.
429
425
  */
430
426
  hide() {
431
- s(l.LOADING, { status: !0, mode: "full" });
427
+ a(u.LOADING, { status: !0, mode: "full" });
432
428
  }
433
429
  };
434
430
  }
435
- function ne() {
431
+ function re() {
436
432
  return {
437
433
  /**
438
434
  * Open overlay mode.
439
435
  */
440
436
  open() {
441
- s(l.OVERLAY, { action: "open" });
437
+ a(u.OVERLAY, { action: "open" });
442
438
  },
443
439
  /**
444
440
  * Close overlay mode.
445
441
  */
446
442
  close() {
447
- s(l.OVERLAY, { action: "close" });
443
+ a(u.OVERLAY, { action: "close" });
448
444
  }
449
445
  };
450
446
  }
451
447
  function se() {
452
- const t = (e) => {
453
- const i = Z(e);
454
- if (!i.valid) {
455
- c(l.TOAST, i.errors);
448
+ const e = (t) => {
449
+ const n = Z(t);
450
+ if (!n.valid) {
451
+ c(u.TOAST, n.errors);
456
452
  return;
457
453
  }
458
- s(l.TOAST, {
459
- type: e.type,
460
- message: e.message,
461
- duration: e.duration
454
+ a(u.TOAST, {
455
+ type: t.type,
456
+ message: t.message,
457
+ duration: t.duration
462
458
  });
463
459
  };
464
460
  return {
465
461
  /**
466
462
  * Show a toast notification.
467
463
  */
468
- show: t,
464
+ show: e,
469
465
  /**
470
466
  * Show success toast.
471
467
  */
472
- success(e, i) {
473
- t({ type: "success", message: e, duration: i });
468
+ success(t, n) {
469
+ e({ type: "success", message: t, duration: n });
474
470
  },
475
471
  /**
476
472
  * Show error toast.
477
473
  */
478
- error(e, i) {
479
- t({ type: "error", message: e, duration: i });
474
+ error(t, n) {
475
+ e({ type: "error", message: t, duration: n });
480
476
  },
481
477
  /**
482
478
  * Show warning toast.
483
479
  */
484
- warning(e, i) {
485
- t({ type: "warning", message: e, duration: i });
480
+ warning(t, n) {
481
+ e({ type: "warning", message: t, duration: n });
486
482
  },
487
483
  /**
488
484
  * Show info toast.
489
485
  */
490
- info(e, i) {
491
- t({ type: "info", message: e, duration: i });
486
+ info(t, n) {
487
+ e({ type: "info", message: t, duration: n });
492
488
  }
493
489
  };
494
490
  }
@@ -497,40 +493,40 @@ function ae() {
497
493
  /**
498
494
  * Open a modal.
499
495
  */
500
- open(t, e) {
501
- s(l.MODAL, {
496
+ open(e, t) {
497
+ a(u.MODAL, {
502
498
  action: "open",
503
- id: t,
504
- content: e
499
+ id: e,
500
+ content: t
505
501
  });
506
502
  },
507
503
  /**
508
504
  * Close a modal.
509
505
  */
510
- close(t) {
511
- s(l.MODAL, {
506
+ close(e) {
507
+ a(u.MODAL, {
512
508
  action: "close",
513
- id: t
509
+ id: e
514
510
  });
515
511
  }
516
512
  };
517
513
  }
518
514
  function oe() {
519
- return async (t) => {
520
- const e = ee(t);
521
- return e.valid ? j(l.CONFIRM, {
522
- title: t.title,
523
- message: t.message,
524
- confirmText: t.confirmText ?? "Confirm",
525
- cancelText: t.cancelText ?? "Cancel",
526
- variant: t.variant ?? "info"
527
- }) : (c(l.CONFIRM, e.errors), Promise.reject(new Error(e.errors.join(", "))));
515
+ return async (e) => {
516
+ const t = ee(e);
517
+ return t.valid ? j(u.CONFIRM, {
518
+ title: e.title,
519
+ message: e.message,
520
+ confirmText: e.confirmText ?? "Confirm",
521
+ cancelText: e.cancelText ?? "Cancel",
522
+ variant: e.variant ?? "info"
523
+ }) : (c(u.CONFIRM, t.errors), Promise.reject(new Error(t.errors.join(", "))));
528
524
  };
529
525
  }
530
526
  function le() {
531
527
  return {
532
- loading: re(),
533
- overlay: ne(),
528
+ loading: ne(),
529
+ overlay: re(),
534
530
  toast: se(),
535
531
  modal: ae(),
536
532
  confirm: oe()
@@ -541,17 +537,17 @@ function ue() {
541
537
  /**
542
538
  * Create/initiate a checkout.
543
539
  */
544
- create(t) {
545
- const e = X(t);
546
- if (!e.valid) {
547
- c(p.CREATE, e.errors);
540
+ create(e) {
541
+ const t = X(e);
542
+ if (!t.valid) {
543
+ c(p.CREATE, t.errors);
548
544
  return;
549
545
  }
550
- s(p.CREATE, { payload: t });
546
+ a(p.CREATE, { payload: e });
551
547
  }
552
548
  };
553
549
  }
554
- const L = {
550
+ const R = {
555
551
  debug: !1,
556
552
  initialized: !1
557
553
  }, ce = {
@@ -559,14 +555,14 @@ const L = {
559
555
  width: 0,
560
556
  locale: "ar",
561
557
  currency: "SAR"
562
- }, I = {
558
+ }, L = {
563
559
  ready: !1,
564
560
  initializing: !1,
565
561
  layout: { ...ce }
566
562
  };
567
563
  class de {
568
564
  constructor() {
569
- this.config = { ...L }, this.state = { ...I }, this.themeCallbacks = /* @__PURE__ */ new Set(), this.initCallbacks = /* @__PURE__ */ new Set(), this.appReady = !1, this.auth = W(), this.page = te(), this.nav = ie(), this.ui = le(), this.checkout = ue(), this.setupThemeListener(), this.setupResponseListeners();
565
+ this.config = { ...R }, this.state = { ...L }, this.themeCallbacks = /* @__PURE__ */ new Set(), this.initCallbacks = /* @__PURE__ */ new Set(), this.appReady = !1, this.auth = W(), this.page = te(), this.nav = ie(), this.ui = le(), this.checkout = ue(), this.setupThemeListener(), this.setupResponseListeners();
570
566
  }
571
567
  /**
572
568
  * Get current SDK state (layout info only, no token).
@@ -593,25 +589,25 @@ class de {
593
589
  /**
594
590
  * Log debug messages if debug mode is enabled.
595
591
  */
596
- debugLog(...e) {
597
- this.config.debug && console.log(`[EmbeddedSDK v${b}]`, ...e);
592
+ debugLog(...t) {
593
+ this.config.debug && console.log(`[EmbeddedSDK v${T}]`, ...t);
598
594
  }
599
595
  /**
600
596
  * Log warnings.
601
597
  */
602
- warn(...e) {
603
- console.warn(`[EmbeddedSDK v${b}]`, ...e);
598
+ warn(...t) {
599
+ console.warn(`[EmbeddedSDK v${T}]`, ...t);
604
600
  }
605
601
  /**
606
602
  * Set up listener for theme changes from host.
607
603
  */
608
604
  setupThemeListener() {
609
- g(S.THEME_CHANGE, (e) => {
610
- this.state.layout.theme = e.theme, this.debugLog("Theme changed:", e.theme), this.themeCallbacks.forEach((i) => {
605
+ E(w.THEME_CHANGE, (t) => {
606
+ this.state.layout.theme = t.theme, this.debugLog("Theme changed:", t.theme), this.themeCallbacks.forEach((n) => {
611
607
  try {
612
- i(e.theme);
613
- } catch (r) {
614
- console.error("[EmbeddedSDK] Error in theme callback:", r);
608
+ n(t.theme);
609
+ } catch (i) {
610
+ console.error("[EmbeddedSDK] Error in theme callback:", i);
615
611
  }
616
612
  });
617
613
  });
@@ -620,10 +616,10 @@ class de {
620
616
  * Set up listeners for async response events from host.
621
617
  */
622
618
  setupResponseListeners() {
623
- g(l.CONFIRM_RESPONSE, (e) => {
624
- this.debugLog("Received confirm response:", e), A(e.requestId, { confirmed: e.confirmed });
625
- }), g(l.MODAL_RESPONSE, (e) => {
626
- this.debugLog("Received modal response:", e), A(e.requestId, e.result, e.error);
619
+ E(u.CONFIRM_RESPONSE, (t) => {
620
+ this.debugLog("Received confirm response:", t), S(t.requestId, { confirmed: t.confirmed });
621
+ }), E(u.MODAL_RESPONSE, (t) => {
622
+ this.debugLog("Received modal response:", t), S(t.requestId, t.result, t.error);
627
623
  });
628
624
  }
629
625
  /**
@@ -639,9 +635,9 @@ class de {
639
635
  * });
640
636
  * ```
641
637
  */
642
- onThemeChange(e) {
643
- return this.themeCallbacks.add(e), () => {
644
- this.themeCallbacks.delete(e);
638
+ onThemeChange(t) {
639
+ return this.themeCallbacks.add(t), () => {
640
+ this.themeCallbacks.delete(t);
645
641
  };
646
642
  }
647
643
  /**
@@ -657,15 +653,15 @@ class de {
657
653
  * });
658
654
  * ```
659
655
  */
660
- onInit(e) {
656
+ onInit(t) {
661
657
  if (this.config.initialized)
662
658
  try {
663
- e(this.getState());
664
- } catch (i) {
665
- console.error("[EmbeddedSDK] Error in init callback:", i);
659
+ t(this.getState());
660
+ } catch (n) {
661
+ console.error("[EmbeddedSDK] Error in init callback:", n);
666
662
  }
667
- return this.initCallbacks.add(e), () => {
668
- this.initCallbacks.delete(e);
663
+ return this.initCallbacks.add(t), () => {
664
+ this.initCallbacks.delete(t);
669
665
  };
670
666
  }
671
667
  /**
@@ -680,11 +676,11 @@ class de {
680
676
  * embedded.log('error', 'Failed to load data', { endpoint: '/api/data' });
681
677
  * ```
682
678
  */
683
- log(e, i, r) {
684
- s(k.LOG, {
685
- level: e,
686
- message: i,
687
- context: r
679
+ log(t, n, i) {
680
+ a(_.LOG, {
681
+ level: t,
682
+ message: n,
683
+ context: i
688
684
  });
689
685
  }
690
686
  /**
@@ -706,7 +702,7 @@ class de {
706
702
  this.warn("Cannot signal ready before init() is called");
707
703
  return;
708
704
  }
709
- this.appReady = !0, s(y.READY, {}), this.debugLog("Sent ready signal to host");
705
+ this.appReady = !0, a(g.READY, {}), this.debugLog("Sent ready signal to host");
710
706
  }
711
707
  /**
712
708
  * Initialize the SDK and establish connection with the host.
@@ -721,43 +717,43 @@ class de {
721
717
  * console.log('Locale:', layout.locale);
722
718
  * ```
723
719
  */
724
- async init(e = {}) {
725
- var i, r, a, o;
720
+ async init(t = {}) {
721
+ var n, i, r, l;
726
722
  if (this.config.initialized)
727
723
  return this.debugLog("Already initialized, returning current layout"), { layout: { ...this.state.layout } };
728
724
  if (this.state.initializing)
729
725
  return this.warn("Initialization already in progress"), this.waitForInit();
730
726
  P() || this.warn("Not running in an iframe. Some features may not work."), this.config = {
731
- debug: e.debug ?? !1,
727
+ debug: t.debug ?? !1,
732
728
  initialized: !1
733
729
  }, this.state.initializing = !0, this.debugLog("Initializing SDK...");
734
730
  try {
735
- s(y.INIT, {
731
+ a(g.INIT, {
736
732
  height: document.documentElement.scrollHeight
737
733
  }), this.debugLog("Sent iframe.ready message, waiting for context...");
738
- const u = await F(
739
- S.PROVIDE
734
+ const o = await F(
735
+ w.PROVIDE
740
736
  );
741
- this.debugLog("Received context from host:", u), this.state = {
737
+ this.debugLog("Received context from host:", o), this.state = {
742
738
  ready: !0,
743
739
  initializing: !1,
744
740
  layout: {
745
- theme: ((i = u.layout) == null ? void 0 : i.theme) ?? "light",
746
- width: ((r = u.layout) == null ? void 0 : r.width) ?? 0,
747
- locale: ((a = u.layout) == null ? void 0 : a.locale) ?? "ar",
748
- currency: ((o = u.layout) == null ? void 0 : o.currency) ?? "SAR"
741
+ theme: ((n = o.layout) == null ? void 0 : n.theme) ?? "light",
742
+ width: ((i = o.layout) == null ? void 0 : i.width) ?? 0,
743
+ locale: ((r = o.layout) == null ? void 0 : r.locale) ?? "ar",
744
+ currency: ((l = o.layout) == null ? void 0 : l.currency) ?? "SAR"
749
745
  }
750
746
  }, this.config.initialized = !0, this.debugLog("Initialization complete. Layout:", this.state.layout);
751
- const w = this.getState();
752
- return this.initCallbacks.forEach((D) => {
747
+ const v = this.getState();
748
+ return this.initCallbacks.forEach((O) => {
753
749
  try {
754
- D(w);
755
- } catch ($) {
756
- console.error("[EmbeddedSDK] Error in init callback:", $);
750
+ O(v);
751
+ } catch (D) {
752
+ console.error("[EmbeddedSDK] Error in init callback:", D);
757
753
  }
758
754
  }), { layout: { ...this.state.layout } };
759
- } catch (u) {
760
- throw this.state.initializing = !1, this.state.ready = !1, u;
755
+ } catch (o) {
756
+ throw this.state.initializing = !1, this.state.ready = !1, o;
761
757
  }
762
758
  }
763
759
  /**
@@ -765,18 +761,25 @@ class de {
765
761
  * Useful when multiple calls to init() might happen.
766
762
  */
767
763
  waitForInit() {
768
- return new Promise((e) => {
769
- const i = () => {
770
- this.state.ready ? e({ layout: { ...this.state.layout } }) : setTimeout(i, 100);
764
+ return new Promise((t) => {
765
+ const n = () => {
766
+ this.state.ready ? t({ layout: { ...this.state.layout } }) : setTimeout(n, 100);
771
767
  };
772
- i();
768
+ n();
773
769
  });
774
770
  }
775
771
  /**
776
772
  * Destroy the SDK instance and clean up resources.
773
+ * Sends a destroy event to the host to navigate away from the embedded view.
774
+ *
775
+ * @example
776
+ * ```typescript
777
+ * // On auth failure or when app needs to exit
778
+ * embedded.destroy();
779
+ * ```
777
780
  */
778
781
  destroy() {
779
- this.debugLog("Destroying SDK instance"), Y("SDK destroyed"), q(), this.themeCallbacks.clear(), this.initCallbacks.clear(), this.config = { ...L }, this.state = { ...I }, this.appReady = !1;
782
+ this.debugLog("Destroying SDK instance"), this.config.initialized && (a(g.DESTROY, {}), this.debugLog("Sent destroy event to host")), Y("SDK destroyed"), q(), this.themeCallbacks.clear(), this.initCallbacks.clear(), this.config = { ...R }, this.state = { ...L }, this.appReady = !1;
780
783
  }
781
784
  }
782
785
  let m = null;
@@ -786,11 +789,11 @@ function fe() {
786
789
  function he() {
787
790
  m && (m.destroy(), m = null);
788
791
  }
789
- const N = fe(), me = b;
790
- typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = N), window.Salla.embedded || (window.Salla.embedded = N));
792
+ const I = fe(), me = T;
793
+ typeof window < "u" && (window.salla = window.salla || window.Salla || {}, window.Salla = window.salla, window.salla.embedded || (window.salla.embedded = I), window.Salla.embedded || (window.Salla.embedded = I));
791
794
  export {
792
795
  de as EmbeddedApp,
793
- N as embedded,
796
+ I as embedded,
794
797
  fe as getEmbeddedApp,
795
798
  he as resetEmbeddedApp,
796
799
  me as version