@salla.sa/embedded-sdk 0.1.0-beta.8 → 0.1.0

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