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