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