@kadanza/extension-sdk 0.1.0 → 0.2.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/extension-sdk.cjs +1 -1
- package/dist/extension-sdk.cjs.map +1 -1
- package/dist/extension-sdk.js +199 -132
- package/dist/extension-sdk.js.map +1 -1
- package/dist/index.d.cts +96 -4
- package/dist/index.d.ts +96 -4
- package/package.json +1 -1
package/dist/extension-sdk.js
CHANGED
|
@@ -31,6 +31,7 @@ var r = {
|
|
|
31
31
|
loadPageSettings: "LOAD_PAGE_SETTINGS",
|
|
32
32
|
updatePageSettings: "UPDATE_PAGE_SETTINGS",
|
|
33
33
|
pageSettingsUpdated: "PAGE_SETTINGS_UPDATED",
|
|
34
|
+
requestNavigationChange: "REQUEST_NAVIGATION_CHANGE",
|
|
34
35
|
navigationChange: "NAVIGATION_CHANGE"
|
|
35
36
|
};
|
|
36
37
|
//#endregion
|
|
@@ -76,11 +77,56 @@ function l(e = window.location.search) {
|
|
|
76
77
|
return new URLSearchParams(e).get("tenantUrl");
|
|
77
78
|
}
|
|
78
79
|
//#endregion
|
|
80
|
+
//#region src/PendingRequest.ts
|
|
81
|
+
var u = class e {
|
|
82
|
+
promise;
|
|
83
|
+
context;
|
|
84
|
+
#e;
|
|
85
|
+
#t;
|
|
86
|
+
#n;
|
|
87
|
+
#r = !1;
|
|
88
|
+
#i;
|
|
89
|
+
constructor(e) {
|
|
90
|
+
this.context = e.context, this.#i = e.onSettle, this.promise = new Promise((e, t) => {
|
|
91
|
+
this.#e = e, this.#t = t;
|
|
92
|
+
}), this.#n = setTimeout(() => {
|
|
93
|
+
this.reject(Error(e.timeoutMessage));
|
|
94
|
+
}, e.timeoutMs);
|
|
95
|
+
}
|
|
96
|
+
static create(t) {
|
|
97
|
+
return new e(t);
|
|
98
|
+
}
|
|
99
|
+
get isPending() {
|
|
100
|
+
return !this.#r;
|
|
101
|
+
}
|
|
102
|
+
matches(e) {
|
|
103
|
+
return this.isPending && e(this.context);
|
|
104
|
+
}
|
|
105
|
+
resolve(e) {
|
|
106
|
+
return this.#r ? !1 : (this.#a(), this.#e(e), !0);
|
|
107
|
+
}
|
|
108
|
+
reject(e) {
|
|
109
|
+
return this.#r ? !1 : (this.#a(), this.#t(e), !0);
|
|
110
|
+
}
|
|
111
|
+
abandon() {
|
|
112
|
+
return this.#r ? !1 : (this.#a(), !0);
|
|
113
|
+
}
|
|
114
|
+
#a() {
|
|
115
|
+
this.#r = !0, clearTimeout(this.#n), this.#i?.(), this.#i = void 0;
|
|
116
|
+
}
|
|
117
|
+
}, d = "server";
|
|
118
|
+
function f(e) {
|
|
119
|
+
return e === "client-hash" ? "client-hash" : d;
|
|
120
|
+
}
|
|
121
|
+
function p(e) {
|
|
122
|
+
return typeof e != "string" || e === "" || e === "?" ? "" : e.startsWith("?") ? e : `?${e}`;
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
79
125
|
//#region src/ExtensionSDK.ts
|
|
80
|
-
function
|
|
126
|
+
function m(e) {
|
|
81
127
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
82
128
|
}
|
|
83
|
-
var
|
|
129
|
+
var h = 1e4, g = 12e4, _ = 3e4, v = 2147483647, y = class {
|
|
84
130
|
#e = null;
|
|
85
131
|
#t = null;
|
|
86
132
|
#n = null;
|
|
@@ -91,7 +137,7 @@ var d = 1e4, f = 12e4, p = 3e4, m = 2147483647, h = class {
|
|
|
91
137
|
#s = null;
|
|
92
138
|
#c = null;
|
|
93
139
|
#l = !1;
|
|
94
|
-
#u =
|
|
140
|
+
#u = g;
|
|
95
141
|
#d = null;
|
|
96
142
|
#f = !1;
|
|
97
143
|
#p = null;
|
|
@@ -100,35 +146,34 @@ var d = 1e4, f = 12e4, p = 3e4, m = 2147483647, h = class {
|
|
|
100
146
|
#g = null;
|
|
101
147
|
#_ = /* @__PURE__ */ new Set();
|
|
102
148
|
#v = /* @__PURE__ */ new Set();
|
|
149
|
+
#y = /* @__PURE__ */ new Set();
|
|
103
150
|
get isConnected() {
|
|
104
151
|
return this.#r;
|
|
105
152
|
}
|
|
106
153
|
async connect(e = {}) {
|
|
107
|
-
if (this.#
|
|
154
|
+
if (this.#D(), this.#r) return this.#k(e), this.#N(), this.#x();
|
|
108
155
|
if (this.#m) return this.#m;
|
|
109
|
-
this.#
|
|
156
|
+
this.#k(e);
|
|
110
157
|
let t = l();
|
|
111
|
-
this.#e = c(t), this.#t = t, this.#n?.(), this.#n = a(this.#e, (e) => this.#
|
|
112
|
-
let n = e.timeoutMs ??
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
reject: t,
|
|
119
|
-
timer: r
|
|
120
|
-
};
|
|
158
|
+
this.#e = c(t), this.#t = t, this.#n?.(), this.#n = a(this.#e, (e) => this.#b(e));
|
|
159
|
+
let n = e.timeoutMs ?? h, o = u.create({
|
|
160
|
+
timeoutMs: n,
|
|
161
|
+
timeoutMessage: `Handshake timed out after ${n}ms.`,
|
|
162
|
+
onSettle: () => {
|
|
163
|
+
this.#p === o && (this.#p = null), this.#m = null;
|
|
164
|
+
}
|
|
121
165
|
});
|
|
122
|
-
this.#m = o;
|
|
166
|
+
this.#p = o, this.#m = o.promise;
|
|
167
|
+
let s = { routingType: f(e.routingType) };
|
|
123
168
|
try {
|
|
124
|
-
i(r.handshakeInit, this.#e);
|
|
169
|
+
i(r.handshakeInit, this.#e, s);
|
|
125
170
|
} catch (e) {
|
|
126
|
-
throw
|
|
171
|
+
throw o.abandon(), this.#n?.(), this.#n = null, this.#e = null, this.#t = null, this.#M(), e;
|
|
127
172
|
}
|
|
128
|
-
return o;
|
|
173
|
+
return o.promise;
|
|
129
174
|
}
|
|
130
175
|
destroy() {
|
|
131
|
-
this.#i = !0, this.#r = !1, this.#
|
|
176
|
+
this.#i = !0, this.#r = !1, this.#M(), this.#l = !1, this.#f = !1, this.#n?.(), this.#n = null, this.#e = null, this.#t = null, this.#p?.reject(/* @__PURE__ */ Error("SDK destroyed.")), this.#h?.reject(/* @__PURE__ */ Error("SDK destroyed.")), this.#g?.reject(/* @__PURE__ */ Error("SDK destroyed.")), this.#p = null, this.#m = null, this.#h = null, this.#g = null, this.#_.clear(), this.#v.clear(), this.#y.clear(), this.#a = null, this.#o = null, this.#s = null, this.#c = null;
|
|
132
177
|
}
|
|
133
178
|
getAuthToken() {
|
|
134
179
|
return this.#a;
|
|
@@ -158,7 +203,7 @@ var d = 1e4, f = 12e4, p = 3e4, m = 2147483647, h = class {
|
|
|
158
203
|
}
|
|
159
204
|
}
|
|
160
205
|
async apiCall(e, t = {}) {
|
|
161
|
-
this.#
|
|
206
|
+
this.#O();
|
|
162
207
|
let r = this.#o?.baseUrl, i = this.#o?.tenantDomain, a = this.#a?.jwt;
|
|
163
208
|
if (!r || !i || !a) throw Error("API calls require handshake authToken and extensionDetails (baseUrl, tenantDomain).");
|
|
164
209
|
return n(e, {
|
|
@@ -168,65 +213,67 @@ var d = 1e4, f = 12e4, p = 3e4, m = 2147483647, h = class {
|
|
|
168
213
|
}, t);
|
|
169
214
|
}
|
|
170
215
|
async emitRequestAuthTokenRefresh(e = {}) {
|
|
171
|
-
if (this.#
|
|
172
|
-
let t = e.timeoutMs ??
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
reject: n,
|
|
179
|
-
timer: r
|
|
180
|
-
};
|
|
216
|
+
if (this.#O(), this.#h) throw Error("Auth token refresh already in progress.");
|
|
217
|
+
let t = e.timeoutMs ?? h, n = this.#e, a = u.create({
|
|
218
|
+
timeoutMs: t,
|
|
219
|
+
timeoutMessage: `Auth token refresh timed out after ${t}ms.`,
|
|
220
|
+
onSettle: () => {
|
|
221
|
+
this.#h === a && (this.#h = null);
|
|
222
|
+
}
|
|
181
223
|
});
|
|
182
|
-
return i(r.requestAuthTokenRefresh, n), a;
|
|
224
|
+
return this.#h = a, i(r.requestAuthTokenRefresh, n), a.promise;
|
|
183
225
|
}
|
|
184
226
|
async emitUpdatePageSettings(e, t = {}) {
|
|
185
|
-
if (this.#
|
|
186
|
-
let n = t.timeoutMs ??
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
reject: t,
|
|
193
|
-
timer: r
|
|
194
|
-
};
|
|
227
|
+
if (this.#O(), this.#g) throw Error("Page settings update already in progress.");
|
|
228
|
+
let n = t.timeoutMs ?? h, a = this.#e, o = u.create({
|
|
229
|
+
timeoutMs: n,
|
|
230
|
+
timeoutMessage: `Page settings update timed out after ${n}ms.`,
|
|
231
|
+
onSettle: () => {
|
|
232
|
+
this.#g === o && (this.#g = null);
|
|
233
|
+
}
|
|
195
234
|
});
|
|
196
|
-
return i(r.updatePageSettings, a, e), o;
|
|
235
|
+
return this.#g = o, i(r.updatePageSettings, a, e), o.promise;
|
|
197
236
|
}
|
|
198
237
|
onLoadPageSettings(e) {
|
|
199
238
|
return this.#_.add(e), () => {
|
|
200
239
|
this.#_.delete(e);
|
|
201
240
|
};
|
|
202
241
|
}
|
|
203
|
-
|
|
242
|
+
onNavigate(e) {
|
|
204
243
|
return this.#v.add(e), () => {
|
|
205
244
|
this.#v.delete(e);
|
|
206
245
|
};
|
|
207
246
|
}
|
|
247
|
+
onAuthTokenRefresh(e) {
|
|
248
|
+
return this.#y.add(e), () => {
|
|
249
|
+
this.#y.delete(e);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
208
252
|
emitNavigationChange(e) {
|
|
209
|
-
this.#
|
|
253
|
+
this.#O(), i(r.navigationChange, this.#e, e);
|
|
210
254
|
}
|
|
211
|
-
#
|
|
255
|
+
#b(e) {
|
|
212
256
|
let { type: t, payload: n } = e.data;
|
|
213
257
|
switch (t) {
|
|
214
258
|
case r.handshakeAck:
|
|
215
|
-
this.#
|
|
259
|
+
this.#S(n);
|
|
216
260
|
break;
|
|
217
261
|
case r.authTokenRefresh:
|
|
218
|
-
this.#
|
|
262
|
+
this.#C(n);
|
|
219
263
|
break;
|
|
220
264
|
case r.loadPageSettings:
|
|
221
|
-
this.#
|
|
265
|
+
this.#w(n);
|
|
266
|
+
break;
|
|
267
|
+
case r.requestNavigationChange:
|
|
268
|
+
this.#T(n);
|
|
222
269
|
break;
|
|
223
270
|
case r.pageSettingsUpdated:
|
|
224
|
-
this.#
|
|
271
|
+
this.#E(n);
|
|
225
272
|
break;
|
|
226
273
|
default: break;
|
|
227
274
|
}
|
|
228
275
|
}
|
|
229
|
-
#
|
|
276
|
+
#x() {
|
|
230
277
|
return {
|
|
231
278
|
authToken: this.#a,
|
|
232
279
|
extensionDetails: this.#o,
|
|
@@ -234,116 +281,105 @@ var d = 1e4, f = 12e4, p = 3e4, m = 2147483647, h = class {
|
|
|
234
281
|
pageSettings: this.#c
|
|
235
282
|
};
|
|
236
283
|
}
|
|
237
|
-
#x(e) {
|
|
238
|
-
this.#a = u(e?.authToken) ? e?.authToken : null, this.#o = u(e?.extensionDetails) ? e?.extensionDetails : null, this.#s = u(e?.designTokens) ? e?.designTokens : null, this.#c = u(e?.pageSettings) ? e?.pageSettings : null, this.#r = !0;
|
|
239
|
-
let t = this.#p;
|
|
240
|
-
this.#p = null, this.#m = null, this.#F(t, this.#b()), this.#f = !1, this.#j();
|
|
241
|
-
}
|
|
242
284
|
#S(e) {
|
|
285
|
+
this.#a = m(e?.authToken) ? e?.authToken : null, this.#o = m(e?.extensionDetails) ? e?.extensionDetails : null, this.#s = m(e?.designTokens) ? e?.designTokens : null, this.#c = m(e?.pageSettings) ? e?.pageSettings : null, this.#r = !0, this.#p?.resolve(this.#x()), this.#f = !1, this.#N();
|
|
286
|
+
}
|
|
287
|
+
#C(e) {
|
|
243
288
|
if (!e?.authToken) {
|
|
244
|
-
this.#
|
|
289
|
+
this.#h?.reject(/* @__PURE__ */ Error("Invalid TOKEN_REFRESH payload."));
|
|
245
290
|
return;
|
|
246
291
|
}
|
|
247
|
-
this.#a = e.authToken;
|
|
248
|
-
let
|
|
249
|
-
this.#
|
|
250
|
-
for (let e of this.#v) e(this.#a);
|
|
251
|
-
this.#f = !1, this.#j();
|
|
292
|
+
this.#a = e.authToken, this.#h?.resolve(this.#a);
|
|
293
|
+
for (let e of this.#y) e(this.#a);
|
|
294
|
+
this.#f = !1, this.#N();
|
|
252
295
|
}
|
|
253
|
-
#
|
|
296
|
+
#w(e) {
|
|
254
297
|
let t = e ?? {};
|
|
255
298
|
this.#c = t;
|
|
256
299
|
for (let e of this.#_) e(t);
|
|
257
300
|
}
|
|
258
|
-
#
|
|
301
|
+
#T(e) {
|
|
302
|
+
if (!(!e || typeof e.path != "string")) for (let t of this.#v) t(e);
|
|
303
|
+
}
|
|
304
|
+
#E(e) {
|
|
259
305
|
if (!e || typeof e.success != "boolean") {
|
|
260
|
-
this.#
|
|
306
|
+
this.#g?.reject(/* @__PURE__ */ Error("Invalid PAGE_SETTINGS_UPDATED payload."));
|
|
261
307
|
return;
|
|
262
308
|
}
|
|
263
|
-
|
|
264
|
-
this.#g = null, this.#F(t, e);
|
|
309
|
+
this.#g?.resolve(e);
|
|
265
310
|
}
|
|
266
|
-
#
|
|
311
|
+
#D() {
|
|
267
312
|
if (this.#i) throw Error("SDK has been destroyed.");
|
|
268
313
|
}
|
|
269
|
-
#
|
|
270
|
-
if (this.#
|
|
314
|
+
#O() {
|
|
315
|
+
if (this.#D(), !this.#r || !this.#e) throw Error("SDK is not connected. Call connect() first.");
|
|
271
316
|
}
|
|
272
|
-
#
|
|
317
|
+
#k(e) {
|
|
273
318
|
if (e.authTokenBufferMs !== void 0 && (!Number.isFinite(e.authTokenBufferMs) || e.authTokenBufferMs < 0)) throw Error("authTokenBufferMs must be a finite non-negative number.");
|
|
274
|
-
this.#l = e.authTokenAutoRefresh === !0, this.#u = e.authTokenBufferMs ??
|
|
319
|
+
this.#l = e.authTokenAutoRefresh === !0, this.#u = e.authTokenBufferMs ?? g, this.#f = !1, this.#M();
|
|
275
320
|
}
|
|
276
|
-
#
|
|
321
|
+
#A(e) {
|
|
277
322
|
let t = Number(e.expires);
|
|
278
323
|
return Number.isFinite(t) ? t * 1e3 : null;
|
|
279
324
|
}
|
|
280
|
-
#
|
|
281
|
-
let t = this.#
|
|
325
|
+
#j(e) {
|
|
326
|
+
let t = this.#A(e);
|
|
282
327
|
return t === null ? null : Math.max(0, t - this.#u - Date.now());
|
|
283
328
|
}
|
|
284
|
-
#
|
|
329
|
+
#M() {
|
|
285
330
|
this.#d !== null && (clearTimeout(this.#d), this.#d = null);
|
|
286
331
|
}
|
|
287
|
-
#
|
|
288
|
-
if (this.#
|
|
289
|
-
let e = this.#
|
|
332
|
+
#N() {
|
|
333
|
+
if (this.#M(), !this.#l || !this.#r || this.#i || !this.#a) return;
|
|
334
|
+
let e = this.#j(this.#a);
|
|
290
335
|
if (e === null) return;
|
|
291
|
-
let t = Math.min(e,
|
|
336
|
+
let t = Math.min(e, v);
|
|
292
337
|
this.#d = setTimeout(() => {
|
|
293
|
-
this.#d = null, this.#
|
|
338
|
+
this.#d = null, this.#P();
|
|
294
339
|
}, t);
|
|
295
340
|
}
|
|
296
|
-
async #
|
|
341
|
+
async #P() {
|
|
297
342
|
if (!this.#l || !this.#r || this.#i || !this.#a) return;
|
|
298
|
-
let e = this.#a, t = this.#
|
|
343
|
+
let e = this.#a, t = this.#j(e);
|
|
299
344
|
if (t !== null) {
|
|
300
345
|
if (t > 0) {
|
|
301
|
-
this.#
|
|
346
|
+
this.#N();
|
|
302
347
|
return;
|
|
303
348
|
}
|
|
304
349
|
if (this.#h) {
|
|
305
|
-
this.#
|
|
350
|
+
this.#F(e);
|
|
306
351
|
return;
|
|
307
352
|
}
|
|
308
353
|
try {
|
|
309
354
|
await this.emitRequestAuthTokenRefresh();
|
|
310
355
|
} catch {
|
|
311
|
-
this.#
|
|
356
|
+
this.#F(e);
|
|
312
357
|
}
|
|
313
358
|
}
|
|
314
359
|
}
|
|
315
|
-
#
|
|
360
|
+
#F(e) {
|
|
316
361
|
if (!this.#l || !this.#r || this.#i || this.#a?.jwt !== e.jwt || this.#f) return;
|
|
317
|
-
let t = this.#
|
|
362
|
+
let t = this.#A(e);
|
|
318
363
|
if (t === null) return;
|
|
319
364
|
let n = t - Date.now();
|
|
320
365
|
if (n <= 0) return;
|
|
321
|
-
this.#f = !0, this.#
|
|
322
|
-
let r = Math.min(
|
|
366
|
+
this.#f = !0, this.#M();
|
|
367
|
+
let r = Math.min(_, n);
|
|
323
368
|
this.#d = setTimeout(() => {
|
|
324
|
-
this.#d = null, this.#
|
|
369
|
+
this.#d = null, this.#P();
|
|
325
370
|
}, r);
|
|
326
371
|
}
|
|
327
|
-
#P(e) {
|
|
328
|
-
e && clearTimeout(e.timer);
|
|
329
|
-
}
|
|
330
|
-
#F(e, t) {
|
|
331
|
-
e && (clearTimeout(e.timer), e.resolve(t));
|
|
332
|
-
}
|
|
333
|
-
#I(e, t) {
|
|
334
|
-
e && (clearTimeout(e.timer), e.reject(t));
|
|
335
|
-
}
|
|
336
372
|
};
|
|
337
373
|
//#endregion
|
|
338
374
|
//#region src/hostMessaging.ts
|
|
339
|
-
function
|
|
375
|
+
function b(e, t, n, r) {
|
|
340
376
|
let i = r === void 0 ? { type: n } : {
|
|
341
377
|
type: n,
|
|
342
378
|
payload: r
|
|
343
379
|
};
|
|
344
380
|
e.postMessage(i, t);
|
|
345
381
|
}
|
|
346
|
-
function
|
|
382
|
+
function x(e, t) {
|
|
347
383
|
let n = (n) => {
|
|
348
384
|
n.origin === e && (!n.data || typeof n.data != "object" || !("type" in n.data) || t(n));
|
|
349
385
|
};
|
|
@@ -351,90 +387,121 @@ function _(e, t) {
|
|
|
351
387
|
}
|
|
352
388
|
//#endregion
|
|
353
389
|
//#region src/ExtensionSDKHost.ts
|
|
354
|
-
var
|
|
390
|
+
var S = 1e4;
|
|
391
|
+
function C(e, t) {
|
|
392
|
+
return `${e}\u0000${p(t)}`;
|
|
393
|
+
}
|
|
394
|
+
var w = class {
|
|
355
395
|
#e;
|
|
356
396
|
#t = null;
|
|
357
397
|
#n = !1;
|
|
358
398
|
#r = !1;
|
|
399
|
+
#i = d;
|
|
400
|
+
#a = null;
|
|
359
401
|
constructor(e) {
|
|
360
402
|
this.#e = e;
|
|
361
403
|
}
|
|
362
404
|
start() {
|
|
363
|
-
this.#r || this.#n || (this.#t =
|
|
364
|
-
this.#
|
|
405
|
+
this.#r || this.#n || (this.#t = x(this.#e.origin, (e) => {
|
|
406
|
+
this.#o(e);
|
|
365
407
|
}), this.#n = !0);
|
|
366
408
|
}
|
|
367
409
|
destroy() {
|
|
368
|
-
this.#r = !0, this.#n = !1, this.#t?.(), this.#t = null;
|
|
410
|
+
this.#r = !0, this.#n = !1, this.#t?.(), this.#t = null, this.#i = d, this.#a?.reject(/* @__PURE__ */ Error("ExtensionSDKHost has been destroyed.")), this.#a = null;
|
|
411
|
+
}
|
|
412
|
+
getRoutingType() {
|
|
413
|
+
return this.#i;
|
|
369
414
|
}
|
|
370
415
|
emitLoadPageSettings(e) {
|
|
371
|
-
this.#
|
|
416
|
+
this.#p(), this.#f(r.loadPageSettings, e);
|
|
417
|
+
}
|
|
418
|
+
async requestNavigationChange(e, t = {}) {
|
|
419
|
+
if (this.#p(), !e || typeof e.path != "string") throw Error("Invalid REQUEST_NAVIGATION_CHANGE payload.");
|
|
420
|
+
if (this.#a) throw Error("Navigation change request already in progress.");
|
|
421
|
+
let n = t.timeoutMs ?? S, i = u.create({
|
|
422
|
+
timeoutMs: n,
|
|
423
|
+
timeoutMessage: `Navigation change timed out after ${n}ms.`,
|
|
424
|
+
context: C(e.path, e.search),
|
|
425
|
+
onSettle: () => {
|
|
426
|
+
this.#a === i && (this.#a = null);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
return this.#a = i, this.#f(r.requestNavigationChange, e), i.promise;
|
|
372
430
|
}
|
|
373
|
-
async #
|
|
431
|
+
async #o(e) {
|
|
374
432
|
if (this.#r) return;
|
|
375
433
|
let { type: t, payload: n } = e.data;
|
|
376
434
|
switch (t) {
|
|
377
435
|
case r.handshakeInit:
|
|
378
|
-
await this.#
|
|
436
|
+
await this.#s(n);
|
|
379
437
|
break;
|
|
380
438
|
case r.requestAuthTokenRefresh:
|
|
381
|
-
await this.#
|
|
439
|
+
await this.#c();
|
|
382
440
|
break;
|
|
383
441
|
case r.updatePageSettings:
|
|
384
|
-
await this.#
|
|
442
|
+
await this.#l(n);
|
|
443
|
+
break;
|
|
444
|
+
case r.navigationChange:
|
|
445
|
+
this.#u(n);
|
|
385
446
|
break;
|
|
386
447
|
default: break;
|
|
387
448
|
}
|
|
388
449
|
}
|
|
389
|
-
async #
|
|
450
|
+
async #s(e) {
|
|
451
|
+
this.#i = f(e?.routingType);
|
|
390
452
|
try {
|
|
391
|
-
let e = await this.#e.resolveHandshakePayload();
|
|
453
|
+
let e = await this.#e.resolveHandshakePayload(this);
|
|
392
454
|
if (this.#r) return;
|
|
393
|
-
this.#
|
|
455
|
+
this.#f(r.handshakeAck, e);
|
|
394
456
|
} catch {}
|
|
395
457
|
}
|
|
396
|
-
async #
|
|
458
|
+
async #c() {
|
|
397
459
|
try {
|
|
398
460
|
let e = await this.#e.resolveAuthToken();
|
|
399
461
|
if (this.#r) return;
|
|
400
|
-
this.#
|
|
462
|
+
this.#f(r.authTokenRefresh, { authToken: e });
|
|
401
463
|
} catch {}
|
|
402
464
|
}
|
|
403
|
-
async #
|
|
465
|
+
async #l(e) {
|
|
404
466
|
let t = e?.settings;
|
|
405
467
|
if (!t || typeof t != "object") {
|
|
406
|
-
this.#
|
|
468
|
+
this.#d(!1);
|
|
407
469
|
return;
|
|
408
470
|
}
|
|
409
471
|
let n = this.#e.onUpdatePageSettings;
|
|
410
472
|
if (!n) {
|
|
411
|
-
this.#
|
|
473
|
+
this.#d(!1);
|
|
412
474
|
return;
|
|
413
475
|
}
|
|
414
476
|
try {
|
|
415
477
|
let e = await n(t);
|
|
416
478
|
if (this.#r) return;
|
|
417
|
-
this.#
|
|
479
|
+
this.#d(!!e);
|
|
418
480
|
} catch {
|
|
419
481
|
if (this.#r) return;
|
|
420
|
-
this.#
|
|
482
|
+
this.#d(!1);
|
|
421
483
|
}
|
|
422
484
|
}
|
|
423
|
-
#
|
|
485
|
+
#u(e) {
|
|
486
|
+
if (!e || typeof e.path != "string") return;
|
|
487
|
+
let t = C(e.path, e.search);
|
|
488
|
+
this.#a?.matches((e) => e === t) && this.#a.resolve(e), this.#e.onNavigationChange?.(e);
|
|
489
|
+
}
|
|
490
|
+
#d(e) {
|
|
424
491
|
let t = { success: e };
|
|
425
|
-
this.#
|
|
492
|
+
this.#f(r.pageSettingsUpdated, t);
|
|
426
493
|
}
|
|
427
|
-
#
|
|
494
|
+
#f(e, t) {
|
|
428
495
|
let n = this.#e.getContentWindow();
|
|
429
|
-
n &&
|
|
496
|
+
n && b(n, this.#e.origin, e, t);
|
|
430
497
|
}
|
|
431
|
-
#
|
|
498
|
+
#p() {
|
|
432
499
|
if (this.#r) throw Error("ExtensionSDKHost has been destroyed.");
|
|
433
500
|
}
|
|
434
501
|
};
|
|
435
502
|
//#endregion
|
|
436
503
|
//#region src/hostUrl.ts
|
|
437
|
-
function
|
|
504
|
+
function T(e, t) {
|
|
438
505
|
if (typeof e != "string") return !1;
|
|
439
506
|
try {
|
|
440
507
|
let n = new URL(e), r = n.protocol === "https:", i = !t || t(n.origin);
|
|
@@ -443,7 +510,7 @@ function y(e, t) {
|
|
|
443
510
|
return !1;
|
|
444
511
|
}
|
|
445
512
|
}
|
|
446
|
-
function
|
|
513
|
+
function E(e, t = window.location.origin) {
|
|
447
514
|
if (typeof e != "string") return null;
|
|
448
515
|
try {
|
|
449
516
|
let n = new URL(e);
|
|
@@ -454,12 +521,12 @@ function b(e, t = window.location.origin) {
|
|
|
454
521
|
}
|
|
455
522
|
//#endregion
|
|
456
523
|
//#region src/index.ts
|
|
457
|
-
var
|
|
524
|
+
var D = null, O = !1, k = class extends y {
|
|
458
525
|
destroy() {
|
|
459
|
-
super.destroy(),
|
|
526
|
+
super.destroy(), D === this && (D = null, O = !1);
|
|
460
527
|
}
|
|
461
|
-
},
|
|
528
|
+
}, A = () => D ? (O ||= (console.warn("[@kadanza/extension-sdk] createExtensionSDK() was called more than once. The SDK is a singleton — reuse the same instance for the whole app."), !0), D) : (D = new k(), D);
|
|
462
529
|
//#endregion
|
|
463
|
-
export { r as CONNECTION_EVENTS,
|
|
530
|
+
export { r as CONNECTION_EVENTS, d as DEFAULT_ROUTING_TYPE, y as ExtensionSDK, w as ExtensionSDKHost, s as InvalidOriginError, A as createExtensionSDK, E as enrichExtensionUrl, T as isValidExtensionUrl, f as normalizeRoutingType, b as postToChild, l as readTenantUrlFromLocation, c as resolveAllowedOrigin, x as subscribeToChildMessages };
|
|
464
531
|
|
|
465
532
|
//# sourceMappingURL=extension-sdk.js.map
|