@salla.sa/embedded-sdk 0.1.0-beta.12 → 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 +379 -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 -557
- 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.12", 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,366 +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.
|
|
422
|
+
* @param mode - Display mode ('full' for full page, 'component' for inline)
|
|
561
423
|
*/
|
|
562
|
-
show() {
|
|
563
|
-
|
|
424
|
+
show(t = "full") {
|
|
425
|
+
s(l.LOADING, { status: !1, mode: t });
|
|
564
426
|
},
|
|
565
427
|
/**
|
|
566
428
|
* Hide loading indicator.
|
|
567
429
|
*/
|
|
568
430
|
hide() {
|
|
569
|
-
|
|
431
|
+
s(l.LOADING, { status: !0, mode: "full" });
|
|
570
432
|
}
|
|
571
433
|
};
|
|
572
434
|
}
|
|
573
|
-
function
|
|
574
|
-
|
|
575
|
-
|
|
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);
|
|
576
454
|
if (!i.valid) {
|
|
577
|
-
|
|
455
|
+
c(l.TOAST, i.errors);
|
|
578
456
|
return;
|
|
579
457
|
}
|
|
580
|
-
|
|
581
|
-
type:
|
|
582
|
-
message:
|
|
583
|
-
duration:
|
|
458
|
+
s(l.TOAST, {
|
|
459
|
+
type: e.type,
|
|
460
|
+
message: e.message,
|
|
461
|
+
duration: e.duration
|
|
584
462
|
});
|
|
585
463
|
};
|
|
586
464
|
return {
|
|
587
465
|
/**
|
|
588
466
|
* Show a toast notification.
|
|
589
467
|
*/
|
|
590
|
-
show:
|
|
468
|
+
show: t,
|
|
591
469
|
/**
|
|
592
470
|
* Show success toast.
|
|
593
471
|
*/
|
|
594
|
-
success(
|
|
595
|
-
|
|
472
|
+
success(e, i) {
|
|
473
|
+
t({ type: "success", message: e, duration: i });
|
|
596
474
|
},
|
|
597
475
|
/**
|
|
598
476
|
* Show error toast.
|
|
599
477
|
*/
|
|
600
|
-
error(
|
|
601
|
-
|
|
478
|
+
error(e, i) {
|
|
479
|
+
t({ type: "error", message: e, duration: i });
|
|
602
480
|
},
|
|
603
481
|
/**
|
|
604
482
|
* Show warning toast.
|
|
605
483
|
*/
|
|
606
|
-
warning(
|
|
607
|
-
|
|
484
|
+
warning(e, i) {
|
|
485
|
+
t({ type: "warning", message: e, duration: i });
|
|
608
486
|
},
|
|
609
487
|
/**
|
|
610
488
|
* Show info toast.
|
|
611
489
|
*/
|
|
612
|
-
info(
|
|
613
|
-
|
|
490
|
+
info(e, i) {
|
|
491
|
+
t({ type: "info", message: e, duration: i });
|
|
614
492
|
}
|
|
615
493
|
};
|
|
616
494
|
}
|
|
617
|
-
function
|
|
495
|
+
function ae() {
|
|
618
496
|
return {
|
|
619
497
|
/**
|
|
620
498
|
* Open a modal.
|
|
621
499
|
*/
|
|
622
|
-
open(
|
|
623
|
-
|
|
500
|
+
open(t, e) {
|
|
501
|
+
s(l.MODAL, {
|
|
624
502
|
action: "open",
|
|
625
|
-
id:
|
|
626
|
-
content:
|
|
503
|
+
id: t,
|
|
504
|
+
content: e
|
|
627
505
|
});
|
|
628
506
|
},
|
|
629
507
|
/**
|
|
630
508
|
* Close a modal.
|
|
631
509
|
*/
|
|
632
|
-
close(
|
|
633
|
-
|
|
510
|
+
close(t) {
|
|
511
|
+
s(l.MODAL, {
|
|
634
512
|
action: "close",
|
|
635
|
-
id:
|
|
513
|
+
id: t
|
|
636
514
|
});
|
|
637
515
|
}
|
|
638
516
|
};
|
|
639
517
|
}
|
|
640
|
-
function
|
|
641
|
-
return async (
|
|
642
|
-
const
|
|
643
|
-
return
|
|
644
|
-
title:
|
|
645
|
-
message:
|
|
646
|
-
confirmText:
|
|
647
|
-
cancelText:
|
|
648
|
-
variant:
|
|
649
|
-
}) : (
|
|
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(", "))));
|
|
650
528
|
};
|
|
651
529
|
}
|
|
652
|
-
function
|
|
530
|
+
function le() {
|
|
653
531
|
return {
|
|
654
|
-
loading:
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
532
|
+
loading: re(),
|
|
533
|
+
overlay: ne(),
|
|
534
|
+
toast: se(),
|
|
535
|
+
modal: ae(),
|
|
536
|
+
confirm: oe()
|
|
658
537
|
};
|
|
659
538
|
}
|
|
660
|
-
function
|
|
539
|
+
function ue() {
|
|
661
540
|
return {
|
|
662
541
|
/**
|
|
663
542
|
* Create/initiate a checkout.
|
|
664
543
|
*/
|
|
665
|
-
create(
|
|
666
|
-
const
|
|
667
|
-
if (!
|
|
668
|
-
|
|
544
|
+
create(t) {
|
|
545
|
+
const e = X(t);
|
|
546
|
+
if (!e.valid) {
|
|
547
|
+
c(p.CREATE, e.errors);
|
|
669
548
|
return;
|
|
670
549
|
}
|
|
671
|
-
|
|
550
|
+
s(p.CREATE, { payload: t });
|
|
672
551
|
}
|
|
673
552
|
};
|
|
674
553
|
}
|
|
675
|
-
const
|
|
554
|
+
const L = {
|
|
676
555
|
debug: !1,
|
|
677
556
|
initialized: !1
|
|
678
|
-
},
|
|
557
|
+
}, ce = {
|
|
679
558
|
theme: "light",
|
|
680
559
|
width: 0,
|
|
681
560
|
locale: "ar",
|
|
682
561
|
currency: "SAR"
|
|
683
|
-
},
|
|
562
|
+
}, I = {
|
|
684
563
|
ready: !1,
|
|
685
564
|
initializing: !1,
|
|
686
|
-
layout: { ...
|
|
565
|
+
layout: { ...ce }
|
|
687
566
|
};
|
|
688
|
-
class
|
|
567
|
+
class de {
|
|
689
568
|
constructor() {
|
|
690
|
-
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();
|
|
691
570
|
}
|
|
692
571
|
/**
|
|
693
572
|
* Get current SDK state (layout info only, no token).
|
|
@@ -712,40 +591,27 @@ class Se {
|
|
|
712
591
|
return this.state.ready;
|
|
713
592
|
}
|
|
714
593
|
/**
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
* @param type - Log type (log, warn, error, info, debug)
|
|
718
|
-
* @param args - Arguments to log
|
|
594
|
+
* Log debug messages if debug mode is enabled.
|
|
719
595
|
*/
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
case "error":
|
|
729
|
-
u.error(...i);
|
|
730
|
-
break;
|
|
731
|
-
case "info":
|
|
732
|
-
u.info(...i);
|
|
733
|
-
break;
|
|
734
|
-
case "debug":
|
|
735
|
-
u.debug(...i);
|
|
736
|
-
break;
|
|
737
|
-
}
|
|
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);
|
|
738
604
|
}
|
|
739
605
|
/**
|
|
740
606
|
* Set up listener for theme changes from host.
|
|
741
607
|
*/
|
|
742
608
|
setupThemeListener() {
|
|
743
|
-
|
|
744
|
-
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) => {
|
|
745
611
|
try {
|
|
746
|
-
i(
|
|
612
|
+
i(e.theme);
|
|
747
613
|
} catch (r) {
|
|
748
|
-
|
|
614
|
+
console.error("[EmbeddedSDK] Error in theme callback:", r);
|
|
749
615
|
}
|
|
750
616
|
});
|
|
751
617
|
});
|
|
@@ -754,10 +620,10 @@ class Se {
|
|
|
754
620
|
* Set up listeners for async response events from host.
|
|
755
621
|
*/
|
|
756
622
|
setupResponseListeners() {
|
|
757
|
-
|
|
758
|
-
this.
|
|
759
|
-
}),
|
|
760
|
-
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);
|
|
761
627
|
});
|
|
762
628
|
}
|
|
763
629
|
/**
|
|
@@ -773,9 +639,9 @@ class Se {
|
|
|
773
639
|
* });
|
|
774
640
|
* ```
|
|
775
641
|
*/
|
|
776
|
-
onThemeChange(
|
|
777
|
-
return this.themeCallbacks.add(
|
|
778
|
-
this.themeCallbacks.delete(
|
|
642
|
+
onThemeChange(e) {
|
|
643
|
+
return this.themeCallbacks.add(e), () => {
|
|
644
|
+
this.themeCallbacks.delete(e);
|
|
779
645
|
};
|
|
780
646
|
}
|
|
781
647
|
/**
|
|
@@ -791,15 +657,15 @@ class Se {
|
|
|
791
657
|
* });
|
|
792
658
|
* ```
|
|
793
659
|
*/
|
|
794
|
-
onInit(
|
|
660
|
+
onInit(e) {
|
|
795
661
|
if (this.config.initialized)
|
|
796
662
|
try {
|
|
797
|
-
|
|
663
|
+
e(this.getState());
|
|
798
664
|
} catch (i) {
|
|
799
|
-
|
|
665
|
+
console.error("[EmbeddedSDK] Error in init callback:", i);
|
|
800
666
|
}
|
|
801
|
-
return this.initCallbacks.add(
|
|
802
|
-
this.initCallbacks.delete(
|
|
667
|
+
return this.initCallbacks.add(e), () => {
|
|
668
|
+
this.initCallbacks.delete(e);
|
|
803
669
|
};
|
|
804
670
|
}
|
|
805
671
|
/**
|
|
@@ -814,9 +680,9 @@ class Se {
|
|
|
814
680
|
* embedded.log('error', 'Failed to load data', { endpoint: '/api/data' });
|
|
815
681
|
* ```
|
|
816
682
|
*/
|
|
817
|
-
log(
|
|
818
|
-
|
|
819
|
-
level:
|
|
683
|
+
log(e, i, r) {
|
|
684
|
+
s(k.LOG, {
|
|
685
|
+
level: e,
|
|
820
686
|
message: i,
|
|
821
687
|
context: r
|
|
822
688
|
});
|
|
@@ -833,14 +699,14 @@ class Se {
|
|
|
833
699
|
*/
|
|
834
700
|
ready() {
|
|
835
701
|
if (this.appReady) {
|
|
836
|
-
this.
|
|
702
|
+
this.debugLog("App already signaled as ready");
|
|
837
703
|
return;
|
|
838
704
|
}
|
|
839
705
|
if (!this.config.initialized) {
|
|
840
|
-
this.
|
|
706
|
+
this.warn("Cannot signal ready before init() is called");
|
|
841
707
|
return;
|
|
842
708
|
}
|
|
843
|
-
this.appReady = !0,
|
|
709
|
+
this.appReady = !0, s(y.READY, {}), this.debugLog("Sent ready signal to host");
|
|
844
710
|
}
|
|
845
711
|
/**
|
|
846
712
|
* Initialize the SDK and establish connection with the host.
|
|
@@ -855,59 +721,43 @@ class Se {
|
|
|
855
721
|
* console.log('Locale:', layout.locale);
|
|
856
722
|
* ```
|
|
857
723
|
*/
|
|
858
|
-
async init(
|
|
724
|
+
async init(e = {}) {
|
|
725
|
+
var i, r, a, o;
|
|
859
726
|
if (this.config.initialized)
|
|
860
|
-
return this.
|
|
861
|
-
"debug",
|
|
862
|
-
"Already initialized, returning current layout"
|
|
863
|
-
), { layout: { ...this.state.layout } };
|
|
727
|
+
return this.debugLog("Already initialized, returning current layout"), { layout: { ...this.state.layout } };
|
|
864
728
|
if (this.state.initializing)
|
|
865
|
-
return this.
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
"Not running in an iframe. Some features may not work."
|
|
869
|
-
), this.config = {
|
|
870
|
-
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,
|
|
871
732
|
initialized: !1
|
|
872
|
-
},
|
|
873
|
-
debug: this.config.debug
|
|
874
|
-
}), this.state.initializing = !0, this.internalLog("debug", "Initializing SDK...");
|
|
733
|
+
}, this.state.initializing = !0, this.debugLog("Initializing SDK...");
|
|
875
734
|
try {
|
|
876
|
-
|
|
735
|
+
s(y.INIT, {
|
|
877
736
|
height: document.documentElement.scrollHeight
|
|
878
|
-
}), this.
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
);
|
|
882
|
-
const i = await J(
|
|
883
|
-
k.PROVIDE
|
|
737
|
+
}), this.debugLog("Sent iframe.ready message, waiting for context...");
|
|
738
|
+
const u = await F(
|
|
739
|
+
S.PROVIDE
|
|
884
740
|
);
|
|
885
|
-
this.
|
|
886
|
-
const r = i.payload.layout;
|
|
887
|
-
this.state = {
|
|
741
|
+
this.debugLog("Received context from host:", u), this.state = {
|
|
888
742
|
ready: !0,
|
|
889
743
|
initializing: !1,
|
|
890
744
|
layout: {
|
|
891
|
-
theme: (
|
|
892
|
-
width: (r == null ? void 0 : r.width) ?? 0,
|
|
893
|
-
locale: (
|
|
894
|
-
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"
|
|
895
749
|
}
|
|
896
|
-
}, this.config.initialized = !0, this.
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
this.state.layout
|
|
900
|
-
);
|
|
901
|
-
const n = this.getState();
|
|
902
|
-
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) => {
|
|
903
753
|
try {
|
|
904
|
-
|
|
905
|
-
} catch (
|
|
906
|
-
|
|
754
|
+
D(w);
|
|
755
|
+
} catch ($) {
|
|
756
|
+
console.error("[EmbeddedSDK] Error in init callback:", $);
|
|
907
757
|
}
|
|
908
758
|
}), { layout: { ...this.state.layout } };
|
|
909
|
-
} catch (
|
|
910
|
-
throw this.state.initializing = !1, this.state.ready = !1,
|
|
759
|
+
} catch (u) {
|
|
760
|
+
throw this.state.initializing = !1, this.state.ready = !1, u;
|
|
911
761
|
}
|
|
912
762
|
}
|
|
913
763
|
/**
|
|
@@ -915,40 +765,34 @@ class Se {
|
|
|
915
765
|
* Useful when multiple calls to init() might happen.
|
|
916
766
|
*/
|
|
917
767
|
waitForInit() {
|
|
918
|
-
return new Promise((
|
|
919
|
-
const i =
|
|
920
|
-
|
|
921
|
-
}
|
|
768
|
+
return new Promise((e) => {
|
|
769
|
+
const i = () => {
|
|
770
|
+
this.state.ready ? e({ layout: { ...this.state.layout } }) : setTimeout(i, 100);
|
|
771
|
+
};
|
|
772
|
+
i();
|
|
922
773
|
});
|
|
923
774
|
}
|
|
924
775
|
/**
|
|
925
776
|
* Destroy the SDK instance and clean up resources.
|
|
926
|
-
* Sends a destroy event to the host to navigate away from the embedded view.
|
|
927
|
-
*
|
|
928
|
-
* @example
|
|
929
|
-
* ```typescript
|
|
930
|
-
* // On auth failure or when app needs to exit
|
|
931
|
-
* embedded.destroy();
|
|
932
|
-
* ```
|
|
933
777
|
*/
|
|
934
778
|
destroy() {
|
|
935
|
-
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;
|
|
936
780
|
}
|
|
937
781
|
}
|
|
938
|
-
let
|
|
939
|
-
function
|
|
940
|
-
return
|
|
782
|
+
let m = null;
|
|
783
|
+
function fe() {
|
|
784
|
+
return m || (m = new de()), m;
|
|
941
785
|
}
|
|
942
|
-
function
|
|
943
|
-
|
|
786
|
+
function he() {
|
|
787
|
+
m && (m.destroy(), m = null);
|
|
944
788
|
}
|
|
945
|
-
const
|
|
946
|
-
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));
|
|
947
791
|
export {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
792
|
+
de as EmbeddedApp,
|
|
793
|
+
N as embedded,
|
|
794
|
+
fe as getEmbeddedApp,
|
|
795
|
+
he as resetEmbeddedApp,
|
|
796
|
+
me as version
|
|
953
797
|
};
|
|
954
798
|
//# sourceMappingURL=index.js.map
|