@trimble-oss/trimble-id-react 0.0.1-rc.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.
@@ -0,0 +1,1457 @@
1
+ var kt = Object.defineProperty;
2
+ var Rt = (a, t, n) => t in a ? kt(a, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : a[t] = n;
3
+ var p = (a, t, n) => (Rt(a, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { OpenIdEndpointProvider as Tt, AuthorizationCodeGrantTokenProvider as Fe, AnalyticsHttpClient as wt, BearerTokenHttpClientProvider as bt } from "@trimble-oss/trimble-id";
5
+ import * as le from "es-cookie";
6
+ import Ct from "jwt-decode";
7
+ import Ye, { createContext as Pt, useContext as Je, useState as Ot, useReducer as It, useRef as xt, useMemo as Le, useEffect as Ge, useCallback as X } from "react";
8
+ class At {
9
+ constructor() {
10
+ /**
11
+ * This function generate a encapsulation function to store
12
+ * the user and token information in a secure way disabled the
13
+ * access from the outside
14
+ * @see {https://medium.com/javascript-scene/encapsulation-in-javascript-26be60e325b4} Encapsulation
15
+ * @return {CacheStorage} Key for the token
16
+ */
17
+ p(this, "generateCache", function() {
18
+ const t = {
19
+ token: void 0,
20
+ user: void 0
21
+ };
22
+ return {
23
+ /**
24
+ * Get token store in cache
25
+ * @return {Promise<TIDAuthToken | undefined>} Token store in memory
26
+ */
27
+ async getToken() {
28
+ return t.token;
29
+ },
30
+ /**
31
+ * Get user store in cache
32
+ * @return {Promise<TIDUser | undefined>} User store in memory
33
+ */
34
+ async getUser() {
35
+ return t.user;
36
+ },
37
+ /**
38
+ * Store token in cache
39
+ * @param {TIDAuthToken} token - Token that you want to store in cache
40
+ * @return {Promise<void>} Empty promise
41
+ */
42
+ async storeToken(n) {
43
+ t.token = n;
44
+ },
45
+ /**
46
+ * Store user in cache
47
+ * @param {TIDUser} user - User that you want to store in cache
48
+ * @return {Promise<void>} Empty promise
49
+ */
50
+ async storeUser(n) {
51
+ t.user = n;
52
+ },
53
+ /**
54
+ * The clear the cache from the storage
55
+ * @return {Promise<void>} Empty promise
56
+ */
57
+ clear() {
58
+ return t.token = void 0, t.user = void 0, Promise.resolve(void 0);
59
+ }
60
+ };
61
+ }());
62
+ }
63
+ }
64
+ class Kt {
65
+ /**
66
+ * Initialized configuration to store information into local storage
67
+ * @param {LocalStorageCacheOptions} options - Configuration for caching in localstorage
68
+ */
69
+ constructor(t) {
70
+ /**
71
+ * Local storage from the browser
72
+ * @type {Storage}
73
+ */
74
+ p(this, "localStorage");
75
+ /**
76
+ * The cache key represents the keys for storing and retrieving user and token from auth
77
+ * @type {CacheKey}
78
+ */
79
+ p(this, "cacheKey");
80
+ this.localStorage = window.localStorage, this.cacheKey = t.cacheKey;
81
+ }
82
+ /**
83
+ * Get token store in localstorage
84
+ * @return {Promise<TIDAuthToken | undefined>} - Token store in localstorage
85
+ */
86
+ async getToken() {
87
+ const t = this.getAuthKey(), n = localStorage.getItem(t);
88
+ return n ? JSON.parse(n) : void 0;
89
+ }
90
+ /**
91
+ * Get user store in localstorage
92
+ * @return {Promise<TIDUser | undefined>} - User store in localstorage
93
+ */
94
+ async getUser() {
95
+ const t = this.getUserKey(), n = localStorage.getItem(t);
96
+ return n ? JSON.parse(n) : void 0;
97
+ }
98
+ /**
99
+ * Store token in localstorage
100
+ * @param {TIDAuthToken} token - Token that you want to store in localstorage
101
+ * @return {Promise<void>} Empty promise
102
+ */
103
+ async storeToken(t) {
104
+ const n = this.getAuthKey(), o = JSON.stringify(t);
105
+ localStorage.setItem(n, o);
106
+ }
107
+ /**
108
+ * Store user in cache
109
+ * @param {TIDUser} user - User that you want to store in localstorage
110
+ * @return {Promise<void>} Empty promise
111
+ */
112
+ async storeUser(t) {
113
+ const n = this.getUserKey(), o = JSON.stringify(t);
114
+ localStorage.setItem(n, o);
115
+ }
116
+ /**
117
+ * Get the full key from the cachekey for the user
118
+ * @return {string} - Full key to get the token from the localstorage
119
+ */
120
+ getUserKey() {
121
+ return this.cacheKey.getUserKey();
122
+ }
123
+ /**
124
+ * Get the full key from the cachekey for the token
125
+ * @return {string} - Full key to get the token from the localstorage
126
+ */
127
+ getAuthKey() {
128
+ return this.cacheKey.getAuthKey();
129
+ }
130
+ /**
131
+ * The clear the cache from the localstorage
132
+ * @return {Promise<void>} Empty promise
133
+ */
134
+ clear() {
135
+ return this.localStorage.removeItem(this.getAuthKey()), this.localStorage.removeItem(this.getUserKey()), Promise.resolve(void 0);
136
+ }
137
+ }
138
+ const he = "@TID", Ut = `${he}_AUTH_KEY`, Dt = `${he}_USER_KEY`;
139
+ class Mt {
140
+ /**
141
+ * Initialized the cache key
142
+ * @param {CacheKeyOptions} cacheKeyOptions - Cache key options to edit the default values
143
+ */
144
+ constructor(t) {
145
+ /**
146
+ * Client id of the application created in trimble developer console
147
+ * @type {string}
148
+ */
149
+ p(this, "clientId");
150
+ /**
151
+ * Prefix value of the key, by default the prefix is based on the constant PREFIX_KEY
152
+ * @type {string}
153
+ */
154
+ p(this, "prefix", he);
155
+ /**
156
+ * Suffix value use it to generate the key to store and retrieve the token, by default the prefix is based on the constant AUTH_KEY
157
+ * @type {string}
158
+ */
159
+ p(this, "authSuffix", Ut);
160
+ /**
161
+ * Suffix value use it to generate the key to store and retrieve the user, by default the prefix is based on the constant USER_KEY
162
+ * @type {string}
163
+ */
164
+ p(this, "userSuffix", Dt);
165
+ this.clientId = t.client_id;
166
+ }
167
+ /**
168
+ * Get key to store/retrieve user
169
+ * @return {string} Key for the user
170
+ */
171
+ getUserKey() {
172
+ return `${this.prefix}_${this.userSuffix}_${this.clientId}`;
173
+ }
174
+ /**
175
+ * Get key to store/retrieve token
176
+ * @return {string} Key for the token
177
+ */
178
+ getAuthKey() {
179
+ return `${this.prefix}_${this.authSuffix}_${this.clientId}`;
180
+ }
181
+ }
182
+ class jt {
183
+ /**
184
+ * Initialized configuration to store information into session storage
185
+ * @param {SessionStorageCacheOptions} options - Configuration for caching in session storage
186
+ */
187
+ constructor(t) {
188
+ /**
189
+ * Session storage from the browser
190
+ * @type {Storage}
191
+ */
192
+ p(this, "sessionStorage");
193
+ /**
194
+ * The cache key represents the keys for storing and retrieving user and token from auth
195
+ * @type {CacheKey}
196
+ */
197
+ p(this, "cacheKey");
198
+ this.sessionStorage = window.sessionStorage, this.cacheKey = t.cacheKey;
199
+ }
200
+ /**
201
+ * Get token store in session storage
202
+ * @return {Promise<TIDAuthToken | undefined>} - Token store in session storage
203
+ */
204
+ async getToken() {
205
+ const t = this.getAuthKey(), n = sessionStorage.getItem(t);
206
+ return n ? JSON.parse(n) : void 0;
207
+ }
208
+ /**
209
+ * Get user store in session storage
210
+ * @return {Promise<TIDUser | undefined>} - User store in session storage
211
+ */
212
+ async getUser() {
213
+ const t = this.getUserKey(), n = sessionStorage.getItem(t);
214
+ return n ? JSON.parse(n) : void 0;
215
+ }
216
+ /**
217
+ * Store token in session storage
218
+ * @param {TIDAuthToken} authToken - Token that you want to store in session storage
219
+ * @return {Promise<void>} Empty promise
220
+ */
221
+ async storeToken(t) {
222
+ const n = this.getAuthKey(), o = JSON.stringify(t);
223
+ sessionStorage.setItem(n, o);
224
+ }
225
+ /**
226
+ * Store user in cache
227
+ * @param {TIDUser} user - User that you want to store in session storage
228
+ * @return {Promise<void>} Empty promise
229
+ */
230
+ async storeUser(t) {
231
+ const n = this.getUserKey(), o = JSON.stringify(t);
232
+ sessionStorage.setItem(n, o);
233
+ }
234
+ /**
235
+ * Get the full key from the cachekey for the user
236
+ * @return {string} - Full key to get the token from the session storage
237
+ */
238
+ getUserKey() {
239
+ return this.cacheKey.getUserKey();
240
+ }
241
+ /**
242
+ * Get the full key from the cachekey for the token
243
+ * @return {string} - Full key to get the token from the session storage
244
+ */
245
+ getAuthKey() {
246
+ return this.cacheKey.getAuthKey();
247
+ }
248
+ /**
249
+ * The clear the cache from the session storage
250
+ * @return {Promise<void>} Empty promise
251
+ */
252
+ clear() {
253
+ return this.sessionStorage.removeItem(this.getAuthKey()), this.sessionStorage.removeItem(this.getUserKey()), Promise.resolve(void 0);
254
+ }
255
+ }
256
+ class Ft {
257
+ /**
258
+ * Create a cache manager to extract or save the user, and token
259
+ * @param {CacheManagerOptions} options - Configuration for the managing the caching
260
+ */
261
+ constructor(t) {
262
+ /**
263
+ * Type persistent you want the user and token to be store
264
+ * in-memory - This one will only persist will the user stays in the page
265
+ * localStorage - This persistent doesn't have expiration date
266
+ * sessionStorage - This one is cleared when the page session ends
267
+ * @type {PersistentStore}
268
+ */
269
+ p(this, "persistentStore");
270
+ /**
271
+ * Cache option selected
272
+ * @type {CacheStorage}
273
+ */
274
+ p(this, "cacheStorage");
275
+ /**
276
+ * The cache key represents the keys for storing and retrieving user and token from auth
277
+ * @type {CacheKey}
278
+ */
279
+ p(this, "cacheKey");
280
+ this.persistentStore = t.persistentStore, this.cacheKey = new Mt({
281
+ client_id: t.clientId
282
+ }), this.persistentStore === "localStorage" ? this.cacheStorage = new Kt({
283
+ cacheKey: this.cacheKey
284
+ }) : this.persistentStore === "sessionStorage" ? this.cacheStorage = new jt({
285
+ cacheKey: this.cacheKey
286
+ }) : this.cacheStorage = new At().generateCache;
287
+ }
288
+ /**
289
+ * Store token in cache
290
+ * @param {TIDAuthToken} token - Token that you want to store in cache
291
+ * @return {Promise<void>} Empty promise
292
+ */
293
+ async setToken(t) {
294
+ await this.cacheStorage.storeToken(t);
295
+ }
296
+ /**
297
+ * Store user in cache
298
+ * @param {TIDUser} user - User that you want to store in cache
299
+ * @return {Promise<void>} Empty promise
300
+ */
301
+ async setUser(t) {
302
+ await this.cacheStorage.storeUser(t);
303
+ }
304
+ /**
305
+ * Get user store in cache
306
+ * @return {Promise<TIDUser | undefined>} Key for the user
307
+ */
308
+ async getUser() {
309
+ return this.cacheStorage.getUser();
310
+ }
311
+ /**
312
+ * Get token store in cache
313
+ * @return {Promise<TIDAuthToken | undefined>} Key for the user
314
+ */
315
+ async getToken() {
316
+ return this.cacheStorage.getToken();
317
+ }
318
+ /**
319
+ * The clear the cache from the storage
320
+ * @return {Promise<void>} Empty promise
321
+ */
322
+ async clear() {
323
+ await this.cacheStorage.clear();
324
+ }
325
+ }
326
+ const Lt = 5 * 6e4, Wt = ["code", "state"], We = (a) => a.split("?")[0], Nt = (a) => a.split("?")[1], Be = (a) => {
327
+ let t = a;
328
+ if (!a.startsWith("?"))
329
+ try {
330
+ t = new URL(a).search;
331
+ } catch {
332
+ }
333
+ return new URLSearchParams(t);
334
+ }, $t = (a = window.location.href, t) => {
335
+ if (t != null) {
336
+ const o = We(t), c = We(a ?? "");
337
+ if (o !== c)
338
+ return !1;
339
+ }
340
+ const n = Be(a);
341
+ for (const o of Wt)
342
+ if (!n.has(o))
343
+ return !1;
344
+ return !0;
345
+ }, Vt = (a) => ({
346
+ name: `${a.given_name} ${a.family_name}`,
347
+ given_name: a.given_name,
348
+ family_name: a.family_name,
349
+ picture: a.picture,
350
+ email: a.email,
351
+ email_verified: a.email_verified,
352
+ phone_number_verified: !1
353
+ }), Yt = "@TID_COOKIE";
354
+ class Jt {
355
+ /**
356
+ * Retrieve a cookie from the browser
357
+ * @param {string} key - Key to retrieve the cookies
358
+ */
359
+ get(t) {
360
+ const n = le.get(t);
361
+ if (n == null)
362
+ throw new Error("Cookie not found");
363
+ return JSON.parse(n);
364
+ }
365
+ /**
366
+ * Store cookies in the browser
367
+ * @param {string} key - Key to save and retrieve the cookies
368
+ * @param {any} value - Information you want to store in cookies
369
+ * @param {CookiesOptions} options - Additional options you want to add to the cookies.
370
+ * @example Save cookies with one day of expiration
371
+ * cookiesStorage.set('key',{data:{...}},{expires:1})
372
+ * @example Save cookies with a custom domain
373
+ * cookiesStorage.set('key',{data:{...}},{domain:'https://example.com/subpath'})
374
+ */
375
+ set(t, n, o) {
376
+ let c = {};
377
+ window.location.protocol === "https:" && (c = {
378
+ secure: !0,
379
+ sameSite: "none"
380
+ }), o != null && o.expires && (c.expires = o.expires), o != null && o.domain && (c.domain = o.domain), le.set(t, JSON.stringify(n), c);
381
+ }
382
+ /**
383
+ * Remove a cookie from the browser
384
+ * @param {string} key - Key to remove the cookies from the browser
385
+ * @param {CookiesOptions} options - Additional options used when the cookie was declared
386
+ * @example Remove cookies without additional information
387
+ * cookiesStorage.remove('key')
388
+ * @example Remove cookies with custom domain
389
+ * cookiesStorage.remove('key',{domain:'https://example.com/subpath'})
390
+ */
391
+ remove(t, n) {
392
+ const o = {};
393
+ n != null && n.domain && (o.domain = n.domain), le.remove(t, o);
394
+ }
395
+ }
396
+ class Gt {
397
+ /**
398
+ * Create a cookies manager to extract or save cookies in the browser
399
+ * @param {CookiesManagerOptions} options - Configuration for the managing the cookies
400
+ */
401
+ constructor(t) {
402
+ /**
403
+ * Cookie full key to store and retrieve the information from cookies
404
+ * @type {string}
405
+ */
406
+ p(this, "cookieKey");
407
+ /**
408
+ * Cookie storage. This object contain all functions necessary to retrieve and store tokens using cookies
409
+ * @type {CookiesStorage}
410
+ */
411
+ p(this, "cookiesStorage");
412
+ this.cookieKey = `${Yt}.${t.clientId}`, this.cookiesStorage = new Jt();
413
+ }
414
+ /**
415
+ * Store cookies in the browser
416
+ * @param {CookieValue} value - information to store
417
+ */
418
+ save(t) {
419
+ this.cookiesStorage.set(this.cookieKey, t, {
420
+ expires: 1
421
+ });
422
+ }
423
+ /**
424
+ * Retrieve cookies in the browser
425
+ * @return {CookieValue | undefined} - Cookies from the browser
426
+ */
427
+ get() {
428
+ try {
429
+ return this.cookiesStorage.get(this.cookieKey);
430
+ } catch {
431
+ return;
432
+ }
433
+ }
434
+ /**
435
+ * Clear information about the cookies stored in the browser
436
+ */
437
+ clear() {
438
+ this.cookiesStorage.remove(this.cookieKey);
439
+ }
440
+ }
441
+ class Bt extends Error {
442
+ }
443
+ class zt extends Error {
444
+ }
445
+ class Ht extends Error {
446
+ }
447
+ const D = "@trimble-oss/trimble-id-react", M = "0.0.1-rc.1", qt = {
448
+ configurationEndpoint: "",
449
+ clientId: "",
450
+ redirectUrl: "",
451
+ logoutRedirectUrl: "",
452
+ scopes: []
453
+ }, Xt = {
454
+ persistentStore: "in-memory"
455
+ };
456
+ class Qt {
457
+ /**
458
+ * Create a TID client to handle manage all user authentication functions and information
459
+ * @param {CacheManagerOptions} props - TID client configuration
460
+ */
461
+ constructor(t) {
462
+ /**
463
+ * Token provider SDK. This object handles all necessary communication with TID
464
+ * @type {AuthorizationCodeGrantTokenProvider}
465
+ */
466
+ p(this, "tokenProvider");
467
+ /**
468
+ * This object manage all caching, and all configurations necessary
469
+ * @type {CacheManager}
470
+ */
471
+ p(this, "cacheManager");
472
+ /**
473
+ * This object manage all cookies administration, and all configurations necessary
474
+ * @type {CookiesManager}
475
+ */
476
+ p(this, "cookiesManager");
477
+ /**
478
+ * Client id of the application created in trimble developer console
479
+ * @type {string}
480
+ */
481
+ p(this, "clientId");
482
+ /**
483
+ * Callback url to redirect the user after the authentication is successful
484
+ * @type {string}
485
+ */
486
+ p(this, "redirectUrl");
487
+ /**
488
+ * AnalyticsHttpClient for sending events
489
+ * @type {AnalyticsHttpClient}
490
+ */
491
+ p(this, "analyticshttpclient");
492
+ const { config: n = qt, persistentOptions: o = Xt } = t;
493
+ if (this.redirectUrl = n.redirectUrl, n.configurationEndpoint == null || n.configurationEndpoint == "")
494
+ throw new Error("Configuration endpoint not defined");
495
+ if (n.clientId == null || n.clientId == "")
496
+ throw new Error("Consumer key is not defined");
497
+ this.cookiesManager = new Gt({
498
+ clientId: n.clientId
499
+ });
500
+ const c = this.cookiesManager.get(), k = new Tt(n.configurationEndpoint);
501
+ let _ = new Fe(
502
+ k,
503
+ n.clientId,
504
+ n.redirectUrl
505
+ ).WithScopes(n.scopes);
506
+ n.logoutRedirectUrl && (_ = _.WithLogoutRedirect(n.logoutRedirectUrl)), (c == null ? void 0 : c.code_verifier) != null && (_ = _.WithProofKeyForCodeExchange(c.code_verifier)), this.tokenProvider = _, this.cacheManager = new Ft({
507
+ clientId: n.clientId,
508
+ persistentStore: o.persistentStore
509
+ }), this.clientId = n.clientId, this.analyticshttpclient = new wt(), this.analyticshttpclient.sendInitEvent("TIDClient", D, M, this.clientId);
510
+ }
511
+ /**
512
+ * Redirect the user to TID using the browser
513
+ * @param {LoginWithRedirectOptions} options - Custom configuration for the redirection
514
+ * @return {Promise<void>} Empty promise
515
+ * @example No configuration
516
+ * loginWithRedirect()
517
+ * // Automatically redirects the user to TID with all necessary parameters
518
+ * @example Custom redirect
519
+ * loginWithRedirect({onRedirect: (url) => router.navigate(url)})
520
+ * // Redirect calls onRedirect with the log-out url for TID
521
+ * // So it can be handled by the developer
522
+ */
523
+ async loginWithRedirect(t) {
524
+ this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name, D, M, this.clientId);
525
+ const { onRedirect: n } = t || {}, o = Fe.GenerateCodeVerifier();
526
+ this.cookiesManager.save({ code_verifier: o }), this.tokenProvider = this.tokenProvider.WithProofKeyForCodeExchange(o);
527
+ const c = await this.tokenProvider.GetOAuthRedirect("state");
528
+ n != null ? n(c) : window.location.assign(c);
529
+ }
530
+ /**
531
+ * Authenticated the user using the url callback params
532
+ * @param {string} url - Custom configuration for the redirection
533
+ * @return {Promise<AuthState>} Object contain the state returned from TID
534
+ * @throws {CodeVerifierNotFoundException} Will throw an exception if the session doesn't contain the code verifier
535
+ * @example No configuration
536
+ * handleCallback()
537
+ * // Will automatically take the url from the browser and try to log in the user
538
+ * @example Custom url
539
+ * handleCallback('https://example.com?code=code....')
540
+ * // Will try to log in the user with the url assign by the developer
541
+ */
542
+ async handleCallback(t = window.location.href) {
543
+ const n = this.cookiesManager.get();
544
+ if (n == null || (n == null ? void 0 : n.code_verifier) == null)
545
+ throw new Ht("Code verifier not available");
546
+ const o = Nt(t), c = Be(t), k = c.get("identity_provider") ?? "", _ = c.get("state") ?? "";
547
+ return await this.tokenProvider.ValidateQuery(o), await this.generateToken(k), {
548
+ authState: _
549
+ };
550
+ }
551
+ /**
552
+ * Function to generate and store the access token
553
+ * @param {string} identityProvider - Type of identity provider used
554
+ * @return {Promise<void>} Empty promise
555
+ */
556
+ async generateToken(t) {
557
+ var T, d;
558
+ const n = await this.tokenProvider.RetrieveToken(), o = await this.tokenProvider.RetrieveRefreshToken(), c = await this.tokenProvider.RetrieveIdToken(), k = await this.tokenProvider.RetrieveTokenExpiry(), w = new Date(k).getTime(), g = (d = (T = this.tokenProvider) == null ? void 0 : T._scopes) == null ? void 0 : d.join(" ");
559
+ await this.cacheManager.setToken({
560
+ scope: g,
561
+ state: "",
562
+ session_state: "",
563
+ identity_provider: t,
564
+ token_type: "bearer",
565
+ access_token: n,
566
+ refresh_token: o,
567
+ id_token: c,
568
+ expires_at: w
569
+ });
570
+ const C = Ct(c), S = Vt(C);
571
+ await this.cacheManager.setUser(S), await this.reloadCodeVerifier();
572
+ }
573
+ async reloadCodeVerifier() {
574
+ const t = await this.tokenProvider.RetrieveCodeVerifier();
575
+ this.cookiesManager.save({ code_verifier: t }), this.tokenProvider = this.tokenProvider.WithProofKeyForCodeExchange(t);
576
+ }
577
+ /**
578
+ * Return the user stored in cache
579
+ * @return {Promise<TIDUser | undefined>} User in cache
580
+ */
581
+ async getUser() {
582
+ return this.analyticshttpclient.sendMethodEvent(this.getUser.name, D, M, this.clientId), await this.cacheManager.getUser();
583
+ }
584
+ /**
585
+ * Gets the access token from cache. If the token already expired,
586
+ * will try to refresh it using the refresh token
587
+ * @return {Promise<string>} Access token
588
+ * @throws {TokenNotFoundException} Will throw an exception if the access token is not in cache
589
+ * @throws {TokenExpiredException} Will throw an exception if the user token expired
590
+ */
591
+ async getAccessTokenSilently() {
592
+ this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name, D, M, this.clientId);
593
+ let t = await this.cacheManager.getToken();
594
+ if (t == null)
595
+ throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name, D, M, "No token available", this.clientId), new zt("No token available");
596
+ const n = new Date((/* @__PURE__ */ new Date()).getTime() + Lt);
597
+ if ((t == null ? void 0 : t.expires_at) == null || (t == null ? void 0 : t.expires_at) < n.getTime()) {
598
+ try {
599
+ await this.tokenProvider.RetrieveToken();
600
+ } catch (o) {
601
+ throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name, D, M, o.message, this.clientId), new Bt(o.message);
602
+ }
603
+ await this.generateToken((t == null ? void 0 : t.identity_provider) ?? ""), t = await this.cacheManager.getToken();
604
+ }
605
+ return (t == null ? void 0 : t.access_token) || "";
606
+ }
607
+ /**
608
+ * Redirect the user to TID using the browser
609
+ * @param {LogoutOptions} options - Custom configuration for teh redirection
610
+ * @return {Promise<void>} Empty promise
611
+ * @example No configuration
612
+ * logout()
613
+ * // Automatically redirects the user to TID to log out
614
+ * @example Custom redirect
615
+ * logout({onRedirect: (url) => router.navigate(url)})
616
+ * // Redirect calls onRedirect with the log-out url for TID
617
+ * // So it can be handled by the developer
618
+ */
619
+ async logout(t) {
620
+ this.analyticshttpclient.sendMethodEvent(this.logout.name, D, M, this.clientId);
621
+ const { onRedirect: n, disabledAutoRedirect: o } = t || {};
622
+ this.cacheManager && await this.cacheManager.clear(), this.cookiesManager && this.cookiesManager.clear();
623
+ const c = await this.tokenProvider.GetOAuthLogoutRedirect("state");
624
+ if (n != null)
625
+ return n(c);
626
+ o || window.location.assign(c);
627
+ }
628
+ /**
629
+ * Check if the user still has a valid session
630
+ * @return {Promise<boolean>} True or false depending on if the user is session is valid or not
631
+ */
632
+ async checkSession() {
633
+ try {
634
+ await this.getAccessTokenSilently();
635
+ } catch {
636
+ return !1;
637
+ }
638
+ return !0;
639
+ }
640
+ /**
641
+ * Check if the user has a session valid after a refresh
642
+ * @return {Promise<void>} Empty promise
643
+ */
644
+ async loadUserSession() {
645
+ await this.loadCacheSessionIntoSDK(), await this.checkSession() || await this.cacheManager.clear();
646
+ }
647
+ /**
648
+ * Load the user session from cache into the SDK
649
+ * @return {Promise<void>} Empty promise
650
+ */
651
+ async loadCacheSessionIntoSDK() {
652
+ const t = await this.cacheManager.getToken();
653
+ if (t == null)
654
+ return;
655
+ const n = t.access_token, o = t.refresh_token || "", c = t.id_token, k = t.expires_at;
656
+ this.tokenProvider = this.tokenProvider.WithAccessToken(n, k).WithRefreshToken(o).WithIdToken(c);
657
+ }
658
+ /**
659
+ * Get a http bearer token client to use it for another SDK (Ex: Processing framework)
660
+ * @return {any} - BearerTokenHttpClientProvider
661
+ */
662
+ getBearerTokenHttpClient(t) {
663
+ return new bt(this.tokenProvider, t);
664
+ }
665
+ /**
666
+ * Get the redirect url to TID
667
+ * @return {string} - Callback redirect url
668
+ */
669
+ getRedirectUrl() {
670
+ return this.redirectUrl;
671
+ }
672
+ }
673
+ const ue = Pt(null), ze = () => Je(ue) ?? {};
674
+ var fe = { exports: {} }, N = {};
675
+ /**
676
+ * @license React
677
+ * react-jsx-runtime.production.min.js
678
+ *
679
+ * Copyright (c) Facebook, Inc. and its affiliates.
680
+ *
681
+ * This source code is licensed under the MIT license found in the
682
+ * LICENSE file in the root directory of this source tree.
683
+ */
684
+ var Ne;
685
+ function Zt() {
686
+ if (Ne)
687
+ return N;
688
+ Ne = 1;
689
+ var a = Ye, t = Symbol.for("react.element"), n = Symbol.for("react.fragment"), o = Object.prototype.hasOwnProperty, c = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, k = { key: !0, ref: !0, __self: !0, __source: !0 };
690
+ function _(w, g, C) {
691
+ var S, T = {}, d = null, K = null;
692
+ C !== void 0 && (d = "" + C), g.key !== void 0 && (d = "" + g.key), g.ref !== void 0 && (K = g.ref);
693
+ for (S in g)
694
+ o.call(g, S) && !k.hasOwnProperty(S) && (T[S] = g[S]);
695
+ if (w && w.defaultProps)
696
+ for (S in g = w.defaultProps, g)
697
+ T[S] === void 0 && (T[S] = g[S]);
698
+ return { $$typeof: t, type: w, key: d, ref: K, props: T, _owner: c.current };
699
+ }
700
+ return N.Fragment = n, N.jsx = _, N.jsxs = _, N;
701
+ }
702
+ var $ = {};
703
+ /**
704
+ * @license React
705
+ * react-jsx-runtime.development.js
706
+ *
707
+ * Copyright (c) Facebook, Inc. and its affiliates.
708
+ *
709
+ * This source code is licensed under the MIT license found in the
710
+ * LICENSE file in the root directory of this source tree.
711
+ */
712
+ var $e;
713
+ function er() {
714
+ return $e || ($e = 1, process.env.NODE_ENV !== "production" && function() {
715
+ var a = Ye, t = Symbol.for("react.element"), n = Symbol.for("react.portal"), o = Symbol.for("react.fragment"), c = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), _ = Symbol.for("react.provider"), w = Symbol.for("react.context"), g = Symbol.for("react.forward_ref"), C = Symbol.for("react.suspense"), S = Symbol.for("react.suspense_list"), T = Symbol.for("react.memo"), d = Symbol.for("react.lazy"), K = Symbol.for("react.offscreen"), A = Symbol.iterator, V = "@@iterator";
716
+ function Q(e) {
717
+ if (e === null || typeof e != "object")
718
+ return null;
719
+ var r = A && e[A] || e[V];
720
+ return typeof r == "function" ? r : null;
721
+ }
722
+ var O = a.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
723
+ function E(e) {
724
+ {
725
+ for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), s = 1; s < r; s++)
726
+ i[s - 1] = arguments[s];
727
+ Y("error", e, i);
728
+ }
729
+ }
730
+ function Y(e, r, i) {
731
+ {
732
+ var s = O.ReactDebugCurrentFrame, f = s.getStackAddendum();
733
+ f !== "" && (r += "%s", i = i.concat([f]));
734
+ var h = i.map(function(u) {
735
+ return String(u);
736
+ });
737
+ h.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, h);
738
+ }
739
+ }
740
+ var J = !1, Z = !1, v = !1, P = !1, ee = !1, ge;
741
+ ge = Symbol.for("react.module.reference");
742
+ function He(e) {
743
+ return !!(typeof e == "string" || typeof e == "function" || e === o || e === k || ee || e === c || e === C || e === S || P || e === K || J || Z || v || typeof e == "object" && e !== null && (e.$$typeof === d || e.$$typeof === T || e.$$typeof === _ || e.$$typeof === w || e.$$typeof === g || // This needs to include all possible module reference object
744
+ // types supported by any Flight configuration anywhere since
745
+ // we don't know which Flight build this will end up being used
746
+ // with.
747
+ e.$$typeof === ge || e.getModuleId !== void 0));
748
+ }
749
+ function qe(e, r, i) {
750
+ var s = e.displayName;
751
+ if (s)
752
+ return s;
753
+ var f = r.displayName || r.name || "";
754
+ return f !== "" ? i + "(" + f + ")" : i;
755
+ }
756
+ function ve(e) {
757
+ return e.displayName || "Context";
758
+ }
759
+ function I(e) {
760
+ if (e == null)
761
+ return null;
762
+ if (typeof e.tag == "number" && E("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
763
+ return e.displayName || e.name || null;
764
+ if (typeof e == "string")
765
+ return e;
766
+ switch (e) {
767
+ case o:
768
+ return "Fragment";
769
+ case n:
770
+ return "Portal";
771
+ case k:
772
+ return "Profiler";
773
+ case c:
774
+ return "StrictMode";
775
+ case C:
776
+ return "Suspense";
777
+ case S:
778
+ return "SuspenseList";
779
+ }
780
+ if (typeof e == "object")
781
+ switch (e.$$typeof) {
782
+ case w:
783
+ var r = e;
784
+ return ve(r) + ".Consumer";
785
+ case _:
786
+ var i = e;
787
+ return ve(i._context) + ".Provider";
788
+ case g:
789
+ return qe(e, e.render, "ForwardRef");
790
+ case T:
791
+ var s = e.displayName || null;
792
+ return s !== null ? s : I(e.type) || "Memo";
793
+ case d: {
794
+ var f = e, h = f._payload, u = f._init;
795
+ try {
796
+ return I(u(h));
797
+ } catch {
798
+ return null;
799
+ }
800
+ }
801
+ }
802
+ return null;
803
+ }
804
+ var U = Object.assign, L = 0, ye, pe, me, Ee, _e, Se, ke;
805
+ function Re() {
806
+ }
807
+ Re.__reactDisabledLog = !0;
808
+ function Xe() {
809
+ {
810
+ if (L === 0) {
811
+ ye = console.log, pe = console.info, me = console.warn, Ee = console.error, _e = console.group, Se = console.groupCollapsed, ke = console.groupEnd;
812
+ var e = {
813
+ configurable: !0,
814
+ enumerable: !0,
815
+ value: Re,
816
+ writable: !0
817
+ };
818
+ Object.defineProperties(console, {
819
+ info: e,
820
+ log: e,
821
+ warn: e,
822
+ error: e,
823
+ group: e,
824
+ groupCollapsed: e,
825
+ groupEnd: e
826
+ });
827
+ }
828
+ L++;
829
+ }
830
+ }
831
+ function Qe() {
832
+ {
833
+ if (L--, L === 0) {
834
+ var e = {
835
+ configurable: !0,
836
+ enumerable: !0,
837
+ writable: !0
838
+ };
839
+ Object.defineProperties(console, {
840
+ log: U({}, e, {
841
+ value: ye
842
+ }),
843
+ info: U({}, e, {
844
+ value: pe
845
+ }),
846
+ warn: U({}, e, {
847
+ value: me
848
+ }),
849
+ error: U({}, e, {
850
+ value: Ee
851
+ }),
852
+ group: U({}, e, {
853
+ value: _e
854
+ }),
855
+ groupCollapsed: U({}, e, {
856
+ value: Se
857
+ }),
858
+ groupEnd: U({}, e, {
859
+ value: ke
860
+ })
861
+ });
862
+ }
863
+ L < 0 && E("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
864
+ }
865
+ }
866
+ var te = O.ReactCurrentDispatcher, re;
867
+ function G(e, r, i) {
868
+ {
869
+ if (re === void 0)
870
+ try {
871
+ throw Error();
872
+ } catch (f) {
873
+ var s = f.stack.trim().match(/\n( *(at )?)/);
874
+ re = s && s[1] || "";
875
+ }
876
+ return `
877
+ ` + re + e;
878
+ }
879
+ }
880
+ var ne = !1, B;
881
+ {
882
+ var Ze = typeof WeakMap == "function" ? WeakMap : Map;
883
+ B = new Ze();
884
+ }
885
+ function Te(e, r) {
886
+ if (!e || ne)
887
+ return "";
888
+ {
889
+ var i = B.get(e);
890
+ if (i !== void 0)
891
+ return i;
892
+ }
893
+ var s;
894
+ ne = !0;
895
+ var f = Error.prepareStackTrace;
896
+ Error.prepareStackTrace = void 0;
897
+ var h;
898
+ h = te.current, te.current = null, Xe();
899
+ try {
900
+ if (r) {
901
+ var u = function() {
902
+ throw Error();
903
+ };
904
+ if (Object.defineProperty(u.prototype, "props", {
905
+ set: function() {
906
+ throw Error();
907
+ }
908
+ }), typeof Reflect == "object" && Reflect.construct) {
909
+ try {
910
+ Reflect.construct(u, []);
911
+ } catch (x) {
912
+ s = x;
913
+ }
914
+ Reflect.construct(e, [], u);
915
+ } else {
916
+ try {
917
+ u.call();
918
+ } catch (x) {
919
+ s = x;
920
+ }
921
+ e.call(u.prototype);
922
+ }
923
+ } else {
924
+ try {
925
+ throw Error();
926
+ } catch (x) {
927
+ s = x;
928
+ }
929
+ e();
930
+ }
931
+ } catch (x) {
932
+ if (x && s && typeof x.stack == "string") {
933
+ for (var l = x.stack.split(`
934
+ `), R = s.stack.split(`
935
+ `), y = l.length - 1, m = R.length - 1; y >= 1 && m >= 0 && l[y] !== R[m]; )
936
+ m--;
937
+ for (; y >= 1 && m >= 0; y--, m--)
938
+ if (l[y] !== R[m]) {
939
+ if (y !== 1 || m !== 1)
940
+ do
941
+ if (y--, m--, m < 0 || l[y] !== R[m]) {
942
+ var b = `
943
+ ` + l[y].replace(" at new ", " at ");
944
+ return e.displayName && b.includes("<anonymous>") && (b = b.replace("<anonymous>", e.displayName)), typeof e == "function" && B.set(e, b), b;
945
+ }
946
+ while (y >= 1 && m >= 0);
947
+ break;
948
+ }
949
+ }
950
+ } finally {
951
+ ne = !1, te.current = h, Qe(), Error.prepareStackTrace = f;
952
+ }
953
+ var F = e ? e.displayName || e.name : "", je = F ? G(F) : "";
954
+ return typeof e == "function" && B.set(e, je), je;
955
+ }
956
+ function et(e, r, i) {
957
+ return Te(e, !1);
958
+ }
959
+ function tt(e) {
960
+ var r = e.prototype;
961
+ return !!(r && r.isReactComponent);
962
+ }
963
+ function z(e, r, i) {
964
+ if (e == null)
965
+ return "";
966
+ if (typeof e == "function")
967
+ return Te(e, tt(e));
968
+ if (typeof e == "string")
969
+ return G(e);
970
+ switch (e) {
971
+ case C:
972
+ return G("Suspense");
973
+ case S:
974
+ return G("SuspenseList");
975
+ }
976
+ if (typeof e == "object")
977
+ switch (e.$$typeof) {
978
+ case g:
979
+ return et(e.render);
980
+ case T:
981
+ return z(e.type, r, i);
982
+ case d: {
983
+ var s = e, f = s._payload, h = s._init;
984
+ try {
985
+ return z(h(f), r, i);
986
+ } catch {
987
+ }
988
+ }
989
+ }
990
+ return "";
991
+ }
992
+ var H = Object.prototype.hasOwnProperty, we = {}, be = O.ReactDebugCurrentFrame;
993
+ function q(e) {
994
+ if (e) {
995
+ var r = e._owner, i = z(e.type, e._source, r ? r.type : null);
996
+ be.setExtraStackFrame(i);
997
+ } else
998
+ be.setExtraStackFrame(null);
999
+ }
1000
+ function rt(e, r, i, s, f) {
1001
+ {
1002
+ var h = Function.call.bind(H);
1003
+ for (var u in e)
1004
+ if (h(e, u)) {
1005
+ var l = void 0;
1006
+ try {
1007
+ if (typeof e[u] != "function") {
1008
+ var R = Error((s || "React class") + ": " + i + " type `" + u + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[u] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
1009
+ throw R.name = "Invariant Violation", R;
1010
+ }
1011
+ l = e[u](r, u, s, i, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
1012
+ } catch (y) {
1013
+ l = y;
1014
+ }
1015
+ l && !(l instanceof Error) && (q(f), E("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", s || "React class", i, u, typeof l), q(null)), l instanceof Error && !(l.message in we) && (we[l.message] = !0, q(f), E("Failed %s type: %s", i, l.message), q(null));
1016
+ }
1017
+ }
1018
+ }
1019
+ var nt = Array.isArray;
1020
+ function ie(e) {
1021
+ return nt(e);
1022
+ }
1023
+ function it(e) {
1024
+ {
1025
+ var r = typeof Symbol == "function" && Symbol.toStringTag, i = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
1026
+ return i;
1027
+ }
1028
+ }
1029
+ function at(e) {
1030
+ try {
1031
+ return Ce(e), !1;
1032
+ } catch {
1033
+ return !0;
1034
+ }
1035
+ }
1036
+ function Ce(e) {
1037
+ return "" + e;
1038
+ }
1039
+ function Pe(e) {
1040
+ if (at(e))
1041
+ return E("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", it(e)), Ce(e);
1042
+ }
1043
+ var W = O.ReactCurrentOwner, ot = {
1044
+ key: !0,
1045
+ ref: !0,
1046
+ __self: !0,
1047
+ __source: !0
1048
+ }, Oe, Ie, ae;
1049
+ ae = {};
1050
+ function st(e) {
1051
+ if (H.call(e, "ref")) {
1052
+ var r = Object.getOwnPropertyDescriptor(e, "ref").get;
1053
+ if (r && r.isReactWarning)
1054
+ return !1;
1055
+ }
1056
+ return e.ref !== void 0;
1057
+ }
1058
+ function ct(e) {
1059
+ if (H.call(e, "key")) {
1060
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
1061
+ if (r && r.isReactWarning)
1062
+ return !1;
1063
+ }
1064
+ return e.key !== void 0;
1065
+ }
1066
+ function lt(e, r) {
1067
+ if (typeof e.ref == "string" && W.current && r && W.current.stateNode !== r) {
1068
+ var i = I(W.current.type);
1069
+ ae[i] || (E('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', I(W.current.type), e.ref), ae[i] = !0);
1070
+ }
1071
+ }
1072
+ function ut(e, r) {
1073
+ {
1074
+ var i = function() {
1075
+ Oe || (Oe = !0, E("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
1076
+ };
1077
+ i.isReactWarning = !0, Object.defineProperty(e, "key", {
1078
+ get: i,
1079
+ configurable: !0
1080
+ });
1081
+ }
1082
+ }
1083
+ function ft(e, r) {
1084
+ {
1085
+ var i = function() {
1086
+ Ie || (Ie = !0, E("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
1087
+ };
1088
+ i.isReactWarning = !0, Object.defineProperty(e, "ref", {
1089
+ get: i,
1090
+ configurable: !0
1091
+ });
1092
+ }
1093
+ }
1094
+ var dt = function(e, r, i, s, f, h, u) {
1095
+ var l = {
1096
+ // This tag allows us to uniquely identify this as a React Element
1097
+ $$typeof: t,
1098
+ // Built-in properties that belong on the element
1099
+ type: e,
1100
+ key: r,
1101
+ ref: i,
1102
+ props: u,
1103
+ // Record the component responsible for creating this element.
1104
+ _owner: h
1105
+ };
1106
+ return l._store = {}, Object.defineProperty(l._store, "validated", {
1107
+ configurable: !1,
1108
+ enumerable: !1,
1109
+ writable: !0,
1110
+ value: !1
1111
+ }), Object.defineProperty(l, "_self", {
1112
+ configurable: !1,
1113
+ enumerable: !1,
1114
+ writable: !1,
1115
+ value: s
1116
+ }), Object.defineProperty(l, "_source", {
1117
+ configurable: !1,
1118
+ enumerable: !1,
1119
+ writable: !1,
1120
+ value: f
1121
+ }), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l;
1122
+ };
1123
+ function ht(e, r, i, s, f) {
1124
+ {
1125
+ var h, u = {}, l = null, R = null;
1126
+ i !== void 0 && (Pe(i), l = "" + i), ct(r) && (Pe(r.key), l = "" + r.key), st(r) && (R = r.ref, lt(r, f));
1127
+ for (h in r)
1128
+ H.call(r, h) && !ot.hasOwnProperty(h) && (u[h] = r[h]);
1129
+ if (e && e.defaultProps) {
1130
+ var y = e.defaultProps;
1131
+ for (h in y)
1132
+ u[h] === void 0 && (u[h] = y[h]);
1133
+ }
1134
+ if (l || R) {
1135
+ var m = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
1136
+ l && ut(u, m), R && ft(u, m);
1137
+ }
1138
+ return dt(e, l, R, f, s, W.current, u);
1139
+ }
1140
+ }
1141
+ var oe = O.ReactCurrentOwner, xe = O.ReactDebugCurrentFrame;
1142
+ function j(e) {
1143
+ if (e) {
1144
+ var r = e._owner, i = z(e.type, e._source, r ? r.type : null);
1145
+ xe.setExtraStackFrame(i);
1146
+ } else
1147
+ xe.setExtraStackFrame(null);
1148
+ }
1149
+ var se;
1150
+ se = !1;
1151
+ function ce(e) {
1152
+ return typeof e == "object" && e !== null && e.$$typeof === t;
1153
+ }
1154
+ function Ae() {
1155
+ {
1156
+ if (oe.current) {
1157
+ var e = I(oe.current.type);
1158
+ if (e)
1159
+ return `
1160
+
1161
+ Check the render method of \`` + e + "`.";
1162
+ }
1163
+ return "";
1164
+ }
1165
+ }
1166
+ function gt(e) {
1167
+ {
1168
+ if (e !== void 0) {
1169
+ var r = e.fileName.replace(/^.*[\\\/]/, ""), i = e.lineNumber;
1170
+ return `
1171
+
1172
+ Check your code at ` + r + ":" + i + ".";
1173
+ }
1174
+ return "";
1175
+ }
1176
+ }
1177
+ var Ke = {};
1178
+ function vt(e) {
1179
+ {
1180
+ var r = Ae();
1181
+ if (!r) {
1182
+ var i = typeof e == "string" ? e : e.displayName || e.name;
1183
+ i && (r = `
1184
+
1185
+ Check the top-level render call using <` + i + ">.");
1186
+ }
1187
+ return r;
1188
+ }
1189
+ }
1190
+ function Ue(e, r) {
1191
+ {
1192
+ if (!e._store || e._store.validated || e.key != null)
1193
+ return;
1194
+ e._store.validated = !0;
1195
+ var i = vt(r);
1196
+ if (Ke[i])
1197
+ return;
1198
+ Ke[i] = !0;
1199
+ var s = "";
1200
+ e && e._owner && e._owner !== oe.current && (s = " It was passed a child from " + I(e._owner.type) + "."), j(e), E('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', i, s), j(null);
1201
+ }
1202
+ }
1203
+ function De(e, r) {
1204
+ {
1205
+ if (typeof e != "object")
1206
+ return;
1207
+ if (ie(e))
1208
+ for (var i = 0; i < e.length; i++) {
1209
+ var s = e[i];
1210
+ ce(s) && Ue(s, r);
1211
+ }
1212
+ else if (ce(e))
1213
+ e._store && (e._store.validated = !0);
1214
+ else if (e) {
1215
+ var f = Q(e);
1216
+ if (typeof f == "function" && f !== e.entries)
1217
+ for (var h = f.call(e), u; !(u = h.next()).done; )
1218
+ ce(u.value) && Ue(u.value, r);
1219
+ }
1220
+ }
1221
+ }
1222
+ function yt(e) {
1223
+ {
1224
+ var r = e.type;
1225
+ if (r == null || typeof r == "string")
1226
+ return;
1227
+ var i;
1228
+ if (typeof r == "function")
1229
+ i = r.propTypes;
1230
+ else if (typeof r == "object" && (r.$$typeof === g || // Note: Memo only checks outer props here.
1231
+ // Inner props are checked in the reconciler.
1232
+ r.$$typeof === T))
1233
+ i = r.propTypes;
1234
+ else
1235
+ return;
1236
+ if (i) {
1237
+ var s = I(r);
1238
+ rt(i, e.props, "prop", s, e);
1239
+ } else if (r.PropTypes !== void 0 && !se) {
1240
+ se = !0;
1241
+ var f = I(r);
1242
+ E("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", f || "Unknown");
1243
+ }
1244
+ typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && E("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
1245
+ }
1246
+ }
1247
+ function pt(e) {
1248
+ {
1249
+ for (var r = Object.keys(e.props), i = 0; i < r.length; i++) {
1250
+ var s = r[i];
1251
+ if (s !== "children" && s !== "key") {
1252
+ j(e), E("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", s), j(null);
1253
+ break;
1254
+ }
1255
+ }
1256
+ e.ref !== null && (j(e), E("Invalid attribute `ref` supplied to `React.Fragment`."), j(null));
1257
+ }
1258
+ }
1259
+ function Me(e, r, i, s, f, h) {
1260
+ {
1261
+ var u = He(e);
1262
+ if (!u) {
1263
+ var l = "";
1264
+ (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (l += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
1265
+ var R = gt(f);
1266
+ R ? l += R : l += Ae();
1267
+ var y;
1268
+ e === null ? y = "null" : ie(e) ? y = "array" : e !== void 0 && e.$$typeof === t ? (y = "<" + (I(e.type) || "Unknown") + " />", l = " Did you accidentally export a JSX literal instead of a component?") : y = typeof e, E("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", y, l);
1269
+ }
1270
+ var m = ht(e, r, i, f, h);
1271
+ if (m == null)
1272
+ return m;
1273
+ if (u) {
1274
+ var b = r.children;
1275
+ if (b !== void 0)
1276
+ if (s)
1277
+ if (ie(b)) {
1278
+ for (var F = 0; F < b.length; F++)
1279
+ De(b[F], e);
1280
+ Object.freeze && Object.freeze(b);
1281
+ } else
1282
+ E("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
1283
+ else
1284
+ De(b, e);
1285
+ }
1286
+ return e === o ? pt(m) : yt(m), m;
1287
+ }
1288
+ }
1289
+ function mt(e, r, i) {
1290
+ return Me(e, r, i, !0);
1291
+ }
1292
+ function Et(e, r, i) {
1293
+ return Me(e, r, i, !1);
1294
+ }
1295
+ var _t = Et, St = mt;
1296
+ $.Fragment = o, $.jsx = _t, $.jsxs = St;
1297
+ }()), $;
1298
+ }
1299
+ process.env.NODE_ENV === "production" ? fe.exports = Zt() : fe.exports = er();
1300
+ var de = fe.exports;
1301
+ const tr = (a, t) => {
1302
+ switch (t.type) {
1303
+ case "INIT":
1304
+ return {
1305
+ ...a,
1306
+ isLoading: !1,
1307
+ isAuthenticated: t.user != null,
1308
+ user: t.user,
1309
+ error: void 0
1310
+ };
1311
+ case "HANDLE_CALLBACK_COMPLETE":
1312
+ case "GET_ACCESS_TOKEN_COMPLETE":
1313
+ return {
1314
+ ...a,
1315
+ isLoading: !1,
1316
+ isAuthenticated: t.user != null,
1317
+ user: t.user,
1318
+ error: void 0
1319
+ };
1320
+ case "LOGOUT":
1321
+ return {
1322
+ ...a,
1323
+ isAuthenticated: !1,
1324
+ user: void 0
1325
+ };
1326
+ case "ERROR":
1327
+ return {
1328
+ ...a,
1329
+ isLoading: !1,
1330
+ error: t.error
1331
+ };
1332
+ }
1333
+ }, rr = {
1334
+ isLoading: !0,
1335
+ isAuthenticated: !1
1336
+ }, Ve = (a) => {
1337
+ if (a == null || Object.keys(a).length <= 0)
1338
+ return !0;
1339
+ const t = Object.keys(a);
1340
+ for (const n of t)
1341
+ if (a[n] != null && a[n] !== "")
1342
+ return !1;
1343
+ return !0;
1344
+ }, nr = (a) => {
1345
+ const t = Ve(a.config), n = Ve(a.persistentOptions);
1346
+ return !t || !n;
1347
+ }, ir = (a) => {
1348
+ const {
1349
+ children: t,
1350
+ configurationEndpoint: n,
1351
+ clientId: o,
1352
+ redirectUrl: c,
1353
+ logoutRedirectUrl: k,
1354
+ scopes: _,
1355
+ persistentStore: w,
1356
+ onRedirectCallback: g,
1357
+ checkRedirectUrlMatch: C
1358
+ } = a;
1359
+ if (Je(ue) != null)
1360
+ throw new Error("TID Provider already defined");
1361
+ const T = {
1362
+ config: {
1363
+ configurationEndpoint: n ?? "",
1364
+ clientId: o ?? "",
1365
+ redirectUrl: c ?? "",
1366
+ logoutRedirectUrl: k ?? "",
1367
+ scopes: _ ?? [""]
1368
+ },
1369
+ persistentOptions: {
1370
+ persistentStore: w ?? "in-memory"
1371
+ }
1372
+ }, [d] = Ot(a.tidClient ?? new Qt(T)), [K, A] = It(tr, rr), V = xt(!1), Q = Le(
1373
+ () => C ? d.getRedirectUrl() : void 0,
1374
+ [C, d]
1375
+ );
1376
+ Ge(() => {
1377
+ V.current || (a.tidClient != null && nr({
1378
+ config: {
1379
+ configurationEndpoint: n,
1380
+ clientId: o,
1381
+ redirectUrl: c,
1382
+ logoutRedirectUrl: k,
1383
+ scopes: _
1384
+ },
1385
+ persistentOptions: {
1386
+ persistentStore: w
1387
+ }
1388
+ }) && console.warn(
1389
+ "When TID client is pass as prop, any client configuration property sent directly to the TID Provider component will be ignored"
1390
+ ), V.current = !0, (async () => {
1391
+ try {
1392
+ let v;
1393
+ if ($t(void 0, Q)) {
1394
+ const { authState: P } = await d.handleCallback();
1395
+ v = await d.getUser(), g != null && g(P);
1396
+ } else
1397
+ await d.loadUserSession(), v = await d.getUser();
1398
+ A({ type: "INIT", user: v });
1399
+ } catch (v) {
1400
+ let P = v;
1401
+ typeof v == "string" && (P = new Error(v)), A({ type: "ERROR", error: P });
1402
+ }
1403
+ })());
1404
+ }, [d, g]);
1405
+ const O = X(async () => {
1406
+ const v = await d.getAccessTokenSilently(), P = await d.getUser();
1407
+ return A({
1408
+ type: "GET_ACCESS_TOKEN_COMPLETE",
1409
+ user: P
1410
+ }), v;
1411
+ }, [d]), E = X(
1412
+ async (v) => {
1413
+ await d.loginWithRedirect(v);
1414
+ },
1415
+ [d]
1416
+ ), Y = X(
1417
+ async (v) => {
1418
+ await d.logout(v), (v == null ? void 0 : v.disabledAutoRedirect) != null && v.disabledAutoRedirect && A({
1419
+ type: "LOGOUT"
1420
+ });
1421
+ },
1422
+ [d]
1423
+ ), J = X(
1424
+ async (v) => {
1425
+ const { authState: P } = await d.handleCallback(v), ee = await d.getUser();
1426
+ return A({
1427
+ type: "HANDLE_CALLBACK_COMPLETE",
1428
+ user: ee
1429
+ }), {
1430
+ authState: P
1431
+ };
1432
+ },
1433
+ [d]
1434
+ ), Z = Le(
1435
+ () => ({
1436
+ ...K,
1437
+ getAccessTokenSilently: O,
1438
+ loginWithRedirect: E,
1439
+ handleCallback: J,
1440
+ logout: Y
1441
+ }),
1442
+ [K, O, E, J, Y]
1443
+ );
1444
+ return /* @__PURE__ */ de.jsx(ue.Provider, { value: Z, children: t });
1445
+ }, lr = ze, ur = ir, fr = ({ renderComponent: a, loader: t }) => {
1446
+ const { isAuthenticated: n, isLoading: o, loginWithRedirect: c } = ze();
1447
+ return Ge(() => {
1448
+ !o && !n && (async () => await c())();
1449
+ }, [o, n, c]), n ? a : t || /* @__PURE__ */ de.jsx(de.Fragment, {});
1450
+ };
1451
+ export {
1452
+ fr as AuthenticationGuard,
1453
+ Qt as TIDClient,
1454
+ ue as TIDContext,
1455
+ ur as TIDProvider,
1456
+ lr as useAuth
1457
+ };