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