@salla.sa/embedded-sdk 0.1.0-beta.4 → 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/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +362 -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.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: `${
|
|
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
|
+
}, A = 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,141 @@ 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(() => 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
|
+
}
|
|
170
202
|
}
|
|
171
|
-
function
|
|
203
|
+
function Q(t) {
|
|
172
204
|
return {
|
|
173
205
|
/**
|
|
174
206
|
* Get the token from the URL query parameter.
|
|
@@ -185,6 +217,13 @@ function Y(e) {
|
|
|
185
217
|
getToken() {
|
|
186
218
|
return new URLSearchParams(window.location.search).get("token");
|
|
187
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
|
+
},
|
|
188
227
|
/**
|
|
189
228
|
* Request a token refresh from the host.
|
|
190
229
|
* This will re-render the iframe with a new token URL.
|
|
@@ -196,162 +235,199 @@ function Y(e) {
|
|
|
196
235
|
* ```
|
|
197
236
|
*/
|
|
198
237
|
refresh() {
|
|
199
|
-
|
|
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
|
+
);
|
|
200
276
|
}
|
|
201
277
|
};
|
|
202
278
|
}
|
|
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
|
-
|
|
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");
|
|
226
302
|
else
|
|
227
303
|
try {
|
|
228
|
-
new URL(
|
|
304
|
+
new URL(t.url);
|
|
229
305
|
} catch {
|
|
230
|
-
|
|
306
|
+
e.push(`Invalid redirect URL: "${t.url}"`);
|
|
231
307
|
}
|
|
232
|
-
return { valid:
|
|
308
|
+
return { valid: e.length === 0, errors: e };
|
|
233
309
|
}
|
|
234
|
-
function
|
|
235
|
-
const
|
|
236
|
-
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) => {
|
|
237
313
|
if (typeof n != "object" || n === null) {
|
|
238
|
-
|
|
314
|
+
e.push(`Extended action at index ${i} must be an object`);
|
|
239
315
|
return;
|
|
240
316
|
}
|
|
241
317
|
const r = n;
|
|
242
|
-
(!r.title || typeof r.title != "string") &&
|
|
318
|
+
(!r.title || typeof r.title != "string") && e.push(
|
|
243
319
|
`Extended action at index ${i} is missing required "title" property`
|
|
244
|
-
), r.subTitle !== void 0 && typeof r.subTitle != "string" &&
|
|
320
|
+
), r.subTitle !== void 0 && typeof r.subTitle != "string" && e.push(
|
|
245
321
|
`Extended action at index ${i} subTitle must be a string`
|
|
246
|
-
), r.url !== void 0 && typeof r.url != "string" &&
|
|
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(
|
|
247
323
|
`Extended action at index ${i} value must be a string`
|
|
248
|
-
), r.icon !== void 0 && typeof r.icon != "string" &&
|
|
324
|
+
), r.icon !== void 0 && typeof r.icon != "string" && e.push(
|
|
249
325
|
`Extended action at index ${i} icon must be a string`
|
|
250
|
-
), r.disabled !== void 0 && typeof r.disabled != "boolean" &&
|
|
326
|
+
), r.disabled !== void 0 && typeof r.disabled != "boolean" && e.push(
|
|
251
327
|
`Extended action at index ${i} disabled must be a boolean`
|
|
252
328
|
);
|
|
253
|
-
}) :
|
|
329
|
+
}) : e.push("Nav action extendedActions must be an array")), { valid: e.length === 0, errors: e };
|
|
254
330
|
}
|
|
255
|
-
const
|
|
256
|
-
function
|
|
257
|
-
const
|
|
258
|
-
return
|
|
259
|
-
`Invalid confirm variant "${
|
|
260
|
-
), { 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 };
|
|
261
337
|
}
|
|
262
|
-
function
|
|
338
|
+
function d(t, e) {
|
|
263
339
|
console.error(
|
|
264
|
-
`[EmbeddedSDK] Validation failed for ${
|
|
265
|
-
` +
|
|
340
|
+
`[EmbeddedSDK] Validation failed for ${t}:
|
|
341
|
+
` + e.map((n) => ` • ${n}`).join(`
|
|
266
342
|
`)
|
|
267
343
|
);
|
|
268
344
|
}
|
|
269
|
-
function
|
|
345
|
+
function ae() {
|
|
270
346
|
return {
|
|
271
347
|
/**
|
|
272
348
|
* Navigate to a path using React Router (SPA navigation).
|
|
273
349
|
*/
|
|
274
|
-
navigate(
|
|
275
|
-
const n =
|
|
350
|
+
navigate(t, e) {
|
|
351
|
+
const n = ie({ path: t, ...e });
|
|
276
352
|
if (!n.valid) {
|
|
277
|
-
|
|
353
|
+
d(m.NAVIGATE, n.errors);
|
|
278
354
|
return;
|
|
279
355
|
}
|
|
280
|
-
|
|
281
|
-
path:
|
|
282
|
-
state:
|
|
283
|
-
replace:
|
|
356
|
+
l(m.NAVIGATE, {
|
|
357
|
+
path: t,
|
|
358
|
+
state: e == null ? void 0 : e.state,
|
|
359
|
+
replace: e == null ? void 0 : e.replace
|
|
284
360
|
});
|
|
285
361
|
},
|
|
286
362
|
/**
|
|
287
363
|
* Redirect to a URL (full page reload).
|
|
288
364
|
*/
|
|
289
|
-
redirect(
|
|
290
|
-
const
|
|
291
|
-
if (!
|
|
292
|
-
|
|
365
|
+
redirect(t) {
|
|
366
|
+
const e = ne({ url: t });
|
|
367
|
+
if (!e.valid) {
|
|
368
|
+
d(m.REDIRECT, e.errors);
|
|
293
369
|
return;
|
|
294
370
|
}
|
|
295
|
-
|
|
371
|
+
l(m.REDIRECT, { url: t });
|
|
296
372
|
},
|
|
297
373
|
/**
|
|
298
374
|
* Navigate to a path - auto-detects internal vs external.
|
|
299
375
|
*/
|
|
300
|
-
navTo(
|
|
301
|
-
if (
|
|
302
|
-
this.redirect(
|
|
376
|
+
navTo(t, e) {
|
|
377
|
+
if (t.startsWith("http://") || t.startsWith("https://")) {
|
|
378
|
+
this.redirect(t);
|
|
303
379
|
return;
|
|
304
380
|
}
|
|
305
|
-
this.navigate(
|
|
381
|
+
this.navigate(t, e);
|
|
306
382
|
},
|
|
307
383
|
/**
|
|
308
384
|
* Update the iframe height.
|
|
309
385
|
*/
|
|
310
|
-
resize(
|
|
311
|
-
if (typeof
|
|
312
|
-
|
|
386
|
+
resize(t) {
|
|
387
|
+
if (typeof t != "number" || t < 0) {
|
|
388
|
+
d(T.RESIZE, [
|
|
313
389
|
"Height must be a non-negative number"
|
|
314
390
|
]);
|
|
315
391
|
return;
|
|
316
392
|
}
|
|
317
|
-
|
|
393
|
+
l(T.RESIZE, { height: t });
|
|
318
394
|
},
|
|
319
395
|
/**
|
|
320
396
|
* Auto-resize iframe to content height.
|
|
321
397
|
*/
|
|
322
398
|
autoResize() {
|
|
323
|
-
const
|
|
324
|
-
this.resize(
|
|
399
|
+
const t = document.documentElement.scrollHeight;
|
|
400
|
+
this.resize(t);
|
|
325
401
|
},
|
|
326
402
|
/**
|
|
327
403
|
* Set the page title in the host document.
|
|
328
404
|
*/
|
|
329
|
-
setTitle(
|
|
330
|
-
if (typeof
|
|
331
|
-
|
|
405
|
+
setTitle(t) {
|
|
406
|
+
if (typeof t != "string" || !t.trim()) {
|
|
407
|
+
d(m.SET_TITLE, [
|
|
332
408
|
"Title must be a non-empty string"
|
|
333
409
|
]);
|
|
334
410
|
return;
|
|
335
411
|
}
|
|
336
|
-
|
|
412
|
+
l(m.SET_TITLE, { title: t });
|
|
337
413
|
}
|
|
338
414
|
};
|
|
339
415
|
}
|
|
340
|
-
function
|
|
341
|
-
const
|
|
342
|
-
let
|
|
343
|
-
return
|
|
344
|
-
if (
|
|
416
|
+
function oe() {
|
|
417
|
+
const t = /* @__PURE__ */ new Set();
|
|
418
|
+
let e = null;
|
|
419
|
+
return y(w.ACTION_CLICK, (i) => {
|
|
420
|
+
if (e)
|
|
345
421
|
try {
|
|
346
|
-
|
|
422
|
+
e();
|
|
347
423
|
} catch (r) {
|
|
348
424
|
console.error("[EmbeddedSDK] Error in onClick callback:", r);
|
|
349
425
|
}
|
|
350
|
-
|
|
426
|
+
t.forEach((r) => {
|
|
351
427
|
try {
|
|
352
428
|
r(i.url, i.value);
|
|
353
|
-
} catch (
|
|
354
|
-
console.error("[EmbeddedSDK] Error in action click callback:",
|
|
429
|
+
} catch (s) {
|
|
430
|
+
console.error("[EmbeddedSDK] Error in action click callback:", s);
|
|
355
431
|
}
|
|
356
432
|
});
|
|
357
433
|
}), {
|
|
@@ -359,20 +435,20 @@ function ie() {
|
|
|
359
435
|
* Set the primary action button.
|
|
360
436
|
*/
|
|
361
437
|
setAction(i) {
|
|
362
|
-
var
|
|
363
|
-
const r =
|
|
438
|
+
var s;
|
|
439
|
+
const r = re(i);
|
|
364
440
|
if (!r.valid) {
|
|
365
|
-
|
|
441
|
+
d(w.SET_ACTION, r.errors);
|
|
366
442
|
return;
|
|
367
443
|
}
|
|
368
|
-
i.onClick ?
|
|
444
|
+
i.onClick ? e = i.onClick : e = null, l(w.SET_ACTION, {
|
|
369
445
|
title: i.title,
|
|
370
446
|
onClick: i.onClick ? !0 : void 0,
|
|
371
447
|
value: i.value,
|
|
372
448
|
subTitle: i.subTitle,
|
|
373
449
|
icon: i.icon,
|
|
374
450
|
disabled: i.disabled,
|
|
375
|
-
extendedActions: (
|
|
451
|
+
extendedActions: (s = i.extendedActions) == null ? void 0 : s.map((a) => ({
|
|
376
452
|
title: a.title,
|
|
377
453
|
subTitle: a.subTitle,
|
|
378
454
|
url: a.url,
|
|
@@ -386,7 +462,7 @@ function ie() {
|
|
|
386
462
|
* Clear the primary action button.
|
|
387
463
|
*/
|
|
388
464
|
clearAction() {
|
|
389
|
-
|
|
465
|
+
e = null, l(w.SET_ACTION, {
|
|
390
466
|
title: ""
|
|
391
467
|
});
|
|
392
468
|
},
|
|
@@ -394,8 +470,8 @@ function ie() {
|
|
|
394
470
|
* Subscribe to action button clicks.
|
|
395
471
|
*/
|
|
396
472
|
onActionClick(i) {
|
|
397
|
-
return
|
|
398
|
-
|
|
473
|
+
return t.add(i), () => {
|
|
474
|
+
t.delete(i);
|
|
399
475
|
};
|
|
400
476
|
},
|
|
401
477
|
// Legacy aliases
|
|
@@ -407,141 +483,141 @@ function ie() {
|
|
|
407
483
|
}
|
|
408
484
|
};
|
|
409
485
|
}
|
|
410
|
-
function
|
|
486
|
+
function le() {
|
|
411
487
|
return {
|
|
412
488
|
/**
|
|
413
489
|
* Show loading indicator.
|
|
414
490
|
* @param mode - Display mode ('full' for full page, 'component' for inline)
|
|
415
491
|
*/
|
|
416
|
-
show(
|
|
417
|
-
|
|
492
|
+
show(t = "full") {
|
|
493
|
+
l(c.LOADING, { status: !1, mode: t });
|
|
418
494
|
},
|
|
419
495
|
/**
|
|
420
496
|
* Hide loading indicator.
|
|
421
497
|
*/
|
|
422
498
|
hide() {
|
|
423
|
-
|
|
499
|
+
l(c.LOADING, { status: !0, mode: "full" });
|
|
424
500
|
}
|
|
425
501
|
};
|
|
426
502
|
}
|
|
427
|
-
function
|
|
428
|
-
const
|
|
429
|
-
const n =
|
|
503
|
+
function ue() {
|
|
504
|
+
const t = (e) => {
|
|
505
|
+
const n = ee(e);
|
|
430
506
|
if (!n.valid) {
|
|
431
|
-
c
|
|
507
|
+
d(c.TOAST, n.errors);
|
|
432
508
|
return;
|
|
433
509
|
}
|
|
434
|
-
|
|
435
|
-
type:
|
|
436
|
-
message:
|
|
437
|
-
duration:
|
|
510
|
+
l(c.TOAST, {
|
|
511
|
+
type: e.type,
|
|
512
|
+
message: e.message,
|
|
513
|
+
duration: e.duration
|
|
438
514
|
});
|
|
439
515
|
};
|
|
440
516
|
return {
|
|
441
517
|
/**
|
|
442
518
|
* Show a toast notification.
|
|
443
519
|
*/
|
|
444
|
-
show:
|
|
520
|
+
show: t,
|
|
445
521
|
/**
|
|
446
522
|
* Show success toast.
|
|
447
523
|
*/
|
|
448
|
-
success(
|
|
449
|
-
|
|
524
|
+
success(e, n) {
|
|
525
|
+
t({ type: "success", message: e, duration: n });
|
|
450
526
|
},
|
|
451
527
|
/**
|
|
452
528
|
* Show error toast.
|
|
453
529
|
*/
|
|
454
|
-
error(
|
|
455
|
-
|
|
530
|
+
error(e, n) {
|
|
531
|
+
t({ type: "error", message: e, duration: n });
|
|
456
532
|
},
|
|
457
533
|
/**
|
|
458
534
|
* Show warning toast.
|
|
459
535
|
*/
|
|
460
|
-
warning(
|
|
461
|
-
|
|
536
|
+
warning(e, n) {
|
|
537
|
+
t({ type: "warning", message: e, duration: n });
|
|
462
538
|
},
|
|
463
539
|
/**
|
|
464
540
|
* Show info toast.
|
|
465
541
|
*/
|
|
466
|
-
info(
|
|
467
|
-
|
|
542
|
+
info(e, n) {
|
|
543
|
+
t({ type: "info", message: e, duration: n });
|
|
468
544
|
}
|
|
469
545
|
};
|
|
470
546
|
}
|
|
471
|
-
function
|
|
547
|
+
function ce() {
|
|
472
548
|
return {
|
|
473
549
|
/**
|
|
474
550
|
* Open a modal.
|
|
475
551
|
*/
|
|
476
|
-
open(
|
|
477
|
-
|
|
552
|
+
open(t, e) {
|
|
553
|
+
l(c.MODAL, {
|
|
478
554
|
action: "open",
|
|
479
|
-
id:
|
|
480
|
-
content:
|
|
555
|
+
id: t,
|
|
556
|
+
content: e
|
|
481
557
|
});
|
|
482
558
|
},
|
|
483
559
|
/**
|
|
484
560
|
* Close a modal.
|
|
485
561
|
*/
|
|
486
|
-
close(
|
|
487
|
-
|
|
562
|
+
close(t) {
|
|
563
|
+
l(c.MODAL, {
|
|
488
564
|
action: "close",
|
|
489
|
-
id:
|
|
565
|
+
id: t
|
|
490
566
|
});
|
|
491
567
|
}
|
|
492
568
|
};
|
|
493
569
|
}
|
|
494
|
-
function
|
|
495
|
-
return async (
|
|
496
|
-
const
|
|
497
|
-
return
|
|
498
|
-
title:
|
|
499
|
-
message:
|
|
500
|
-
confirmText:
|
|
501
|
-
cancelText:
|
|
502
|
-
variant:
|
|
503
|
-
}) : (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(", "))));
|
|
504
580
|
};
|
|
505
581
|
}
|
|
506
|
-
function
|
|
582
|
+
function fe() {
|
|
507
583
|
return {
|
|
508
|
-
loading:
|
|
509
|
-
toast:
|
|
510
|
-
modal:
|
|
511
|
-
confirm:
|
|
584
|
+
loading: le(),
|
|
585
|
+
toast: ue(),
|
|
586
|
+
modal: ce(),
|
|
587
|
+
confirm: de()
|
|
512
588
|
};
|
|
513
589
|
}
|
|
514
|
-
function
|
|
590
|
+
function he() {
|
|
515
591
|
return {
|
|
516
592
|
/**
|
|
517
593
|
* Create/initiate a checkout.
|
|
518
594
|
*/
|
|
519
|
-
create(
|
|
520
|
-
const
|
|
521
|
-
if (!
|
|
522
|
-
|
|
595
|
+
create(t) {
|
|
596
|
+
const e = te(t);
|
|
597
|
+
if (!e.valid) {
|
|
598
|
+
d(I.CREATE, e.errors);
|
|
523
599
|
return;
|
|
524
600
|
}
|
|
525
|
-
|
|
601
|
+
l(I.CREATE, { payload: t });
|
|
526
602
|
}
|
|
527
603
|
};
|
|
528
604
|
}
|
|
529
|
-
const
|
|
605
|
+
const D = {
|
|
530
606
|
debug: !1,
|
|
531
607
|
initialized: !1
|
|
532
|
-
},
|
|
608
|
+
}, me = {
|
|
533
609
|
theme: "light",
|
|
534
610
|
width: 0,
|
|
535
611
|
locale: "ar",
|
|
536
612
|
currency: "SAR"
|
|
537
|
-
},
|
|
613
|
+
}, k = {
|
|
538
614
|
ready: !1,
|
|
539
615
|
initializing: !1,
|
|
540
|
-
layout: { ...
|
|
616
|
+
layout: { ...me }
|
|
541
617
|
};
|
|
542
|
-
class
|
|
618
|
+
class ge {
|
|
543
619
|
constructor() {
|
|
544
|
-
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();
|
|
545
621
|
}
|
|
546
622
|
/**
|
|
547
623
|
* Get current SDK state (layout info only, no token).
|
|
@@ -568,23 +644,23 @@ class ce {
|
|
|
568
644
|
/**
|
|
569
645
|
* Log debug messages if debug mode is enabled.
|
|
570
646
|
*/
|
|
571
|
-
debugLog(...
|
|
572
|
-
this.config.debug && console.log(`[EmbeddedSDK v${
|
|
647
|
+
debugLog(...e) {
|
|
648
|
+
this.config.debug && console.log(`[EmbeddedSDK v${A}]`, ...e);
|
|
573
649
|
}
|
|
574
650
|
/**
|
|
575
651
|
* Log warnings.
|
|
576
652
|
*/
|
|
577
|
-
warn(...
|
|
578
|
-
console.warn(`[EmbeddedSDK v${
|
|
653
|
+
warn(...e) {
|
|
654
|
+
console.warn(`[EmbeddedSDK v${A}]`, ...e);
|
|
579
655
|
}
|
|
580
656
|
/**
|
|
581
657
|
* Set up listener for theme changes from host.
|
|
582
658
|
*/
|
|
583
659
|
setupThemeListener() {
|
|
584
|
-
|
|
585
|
-
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) => {
|
|
586
662
|
try {
|
|
587
|
-
n(
|
|
663
|
+
n(e.theme);
|
|
588
664
|
} catch (i) {
|
|
589
665
|
console.error("[EmbeddedSDK] Error in theme callback:", i);
|
|
590
666
|
}
|
|
@@ -595,10 +671,10 @@ class ce {
|
|
|
595
671
|
* Set up listeners for async response events from host.
|
|
596
672
|
*/
|
|
597
673
|
setupResponseListeners() {
|
|
598
|
-
|
|
599
|
-
this.debugLog("Received confirm response:",
|
|
600
|
-
}),
|
|
601
|
-
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);
|
|
602
678
|
});
|
|
603
679
|
}
|
|
604
680
|
/**
|
|
@@ -614,9 +690,9 @@ class ce {
|
|
|
614
690
|
* });
|
|
615
691
|
* ```
|
|
616
692
|
*/
|
|
617
|
-
onThemeChange(
|
|
618
|
-
return this.themeCallbacks.add(
|
|
619
|
-
this.themeCallbacks.delete(
|
|
693
|
+
onThemeChange(e) {
|
|
694
|
+
return this.themeCallbacks.add(e), () => {
|
|
695
|
+
this.themeCallbacks.delete(e);
|
|
620
696
|
};
|
|
621
697
|
}
|
|
622
698
|
/**
|
|
@@ -632,15 +708,15 @@ class ce {
|
|
|
632
708
|
* });
|
|
633
709
|
* ```
|
|
634
710
|
*/
|
|
635
|
-
onInit(
|
|
711
|
+
onInit(e) {
|
|
636
712
|
if (this.config.initialized)
|
|
637
713
|
try {
|
|
638
|
-
|
|
714
|
+
e(this.getState());
|
|
639
715
|
} catch (n) {
|
|
640
716
|
console.error("[EmbeddedSDK] Error in init callback:", n);
|
|
641
717
|
}
|
|
642
|
-
return this.initCallbacks.add(
|
|
643
|
-
this.initCallbacks.delete(
|
|
718
|
+
return this.initCallbacks.add(e), () => {
|
|
719
|
+
this.initCallbacks.delete(e);
|
|
644
720
|
};
|
|
645
721
|
}
|
|
646
722
|
/**
|
|
@@ -655,9 +731,9 @@ class ce {
|
|
|
655
731
|
* embedded.log('error', 'Failed to load data', { endpoint: '/api/data' });
|
|
656
732
|
* ```
|
|
657
733
|
*/
|
|
658
|
-
log(
|
|
659
|
-
|
|
660
|
-
level:
|
|
734
|
+
log(e, n, i) {
|
|
735
|
+
l(U.LOG, {
|
|
736
|
+
level: e,
|
|
661
737
|
message: n,
|
|
662
738
|
context: i
|
|
663
739
|
});
|
|
@@ -681,7 +757,7 @@ class ce {
|
|
|
681
757
|
this.warn("Cannot signal ready before init() is called");
|
|
682
758
|
return;
|
|
683
759
|
}
|
|
684
|
-
this.appReady = !0,
|
|
760
|
+
this.appReady = !0, l(T.READY, {}), this.debugLog("Sent ready signal to host");
|
|
685
761
|
}
|
|
686
762
|
/**
|
|
687
763
|
* Initialize the SDK and establish connection with the host.
|
|
@@ -696,22 +772,22 @@ class ce {
|
|
|
696
772
|
* console.log('Locale:', layout.locale);
|
|
697
773
|
* ```
|
|
698
774
|
*/
|
|
699
|
-
async init(
|
|
700
|
-
var n, i, r,
|
|
775
|
+
async init(e = {}) {
|
|
776
|
+
var n, i, r, s;
|
|
701
777
|
if (this.config.initialized)
|
|
702
778
|
return this.debugLog("Already initialized, returning current layout"), { layout: { ...this.state.layout } };
|
|
703
779
|
if (this.state.initializing)
|
|
704
780
|
return this.warn("Initialization already in progress"), this.waitForInit();
|
|
705
|
-
|
|
706
|
-
debug:
|
|
781
|
+
H() || this.warn("Not running in an iframe. Some features may not work."), this.config = {
|
|
782
|
+
debug: e.debug ?? !1,
|
|
707
783
|
initialized: !1
|
|
708
784
|
}, this.state.initializing = !0, this.debugLog("Initializing SDK...");
|
|
709
785
|
try {
|
|
710
|
-
|
|
786
|
+
l(T.INIT, {
|
|
711
787
|
height: document.documentElement.scrollHeight
|
|
712
788
|
}), this.debugLog("Sent iframe.ready message, waiting for context...");
|
|
713
|
-
const a = await
|
|
714
|
-
|
|
789
|
+
const a = await j(
|
|
790
|
+
R.PROVIDE
|
|
715
791
|
);
|
|
716
792
|
this.debugLog("Received context from host:", a), this.state = {
|
|
717
793
|
ready: !0,
|
|
@@ -720,15 +796,15 @@ class ce {
|
|
|
720
796
|
theme: ((n = a.layout) == null ? void 0 : n.theme) ?? "light",
|
|
721
797
|
width: ((i = a.layout) == null ? void 0 : i.width) ?? 0,
|
|
722
798
|
locale: ((r = a.layout) == null ? void 0 : r.locale) ?? "ar",
|
|
723
|
-
currency: ((
|
|
799
|
+
currency: ((s = a.layout) == null ? void 0 : s.currency) ?? "SAR"
|
|
724
800
|
}
|
|
725
801
|
}, this.config.initialized = !0, this.debugLog("Initialization complete. Layout:", this.state.layout);
|
|
726
|
-
const
|
|
727
|
-
return this.initCallbacks.forEach((
|
|
802
|
+
const E = this.getState();
|
|
803
|
+
return this.initCallbacks.forEach((p) => {
|
|
728
804
|
try {
|
|
729
|
-
|
|
730
|
-
} catch (
|
|
731
|
-
console.error("[EmbeddedSDK] Error in init callback:",
|
|
805
|
+
p(E);
|
|
806
|
+
} catch (u) {
|
|
807
|
+
console.error("[EmbeddedSDK] Error in init callback:", u);
|
|
732
808
|
}
|
|
733
809
|
}), { layout: { ...this.state.layout } };
|
|
734
810
|
} catch (a) {
|
|
@@ -740,11 +816,10 @@ class ce {
|
|
|
740
816
|
* Useful when multiple calls to init() might happen.
|
|
741
817
|
*/
|
|
742
818
|
waitForInit() {
|
|
743
|
-
return new Promise((
|
|
744
|
-
const n = () => {
|
|
745
|
-
|
|
746
|
-
};
|
|
747
|
-
n();
|
|
819
|
+
return new Promise((e) => {
|
|
820
|
+
const n = this.onInit((i) => {
|
|
821
|
+
n(), e({ layout: { ...i.layout } });
|
|
822
|
+
});
|
|
748
823
|
});
|
|
749
824
|
}
|
|
750
825
|
/**
|
|
@@ -758,23 +833,23 @@ class ce {
|
|
|
758
833
|
* ```
|
|
759
834
|
*/
|
|
760
835
|
destroy() {
|
|
761
|
-
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;
|
|
762
837
|
}
|
|
763
838
|
}
|
|
764
|
-
let
|
|
765
|
-
function
|
|
766
|
-
return
|
|
839
|
+
let g = null;
|
|
840
|
+
function Ee() {
|
|
841
|
+
return g || (g = new ge()), g;
|
|
767
842
|
}
|
|
768
|
-
function
|
|
769
|
-
|
|
843
|
+
function be() {
|
|
844
|
+
g && (g.destroy(), g = null);
|
|
770
845
|
}
|
|
771
|
-
const
|
|
772
|
-
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));
|
|
773
848
|
export {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
849
|
+
ge as EmbeddedApp,
|
|
850
|
+
O as embedded,
|
|
851
|
+
Ee as getEmbeddedApp,
|
|
852
|
+
be as resetEmbeddedApp,
|
|
853
|
+
Te as version
|
|
779
854
|
};
|
|
780
855
|
//# sourceMappingURL=index.js.map
|