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

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