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