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