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