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