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