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