@moh-sso/auth 1.3.2 → 1.4.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.
Files changed (2) hide show
  1. package/dist/index.js +188 -447
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -1,17 +1,18 @@
1
- import Ee, { useEffect as U, useMemo as D, createContext as Te, useState as Se, useRef as be, useCallback as ge, useContext as Ae } from "react";
2
- import { useDispatch as ne, useSelector as F } from "react-redux";
3
- import { API as g } from "@moh-sso/config";
4
- import { createSlice as ke, createSelector as p } from "@reduxjs/toolkit";
5
- import { baseApi as A } from "@moh-sso/api";
6
- const xe = {
1
+ import { useEffect as S, useMemo as C, createContext as D, useState as j, useRef as G, useCallback as O, useContext as V } from "react";
2
+ import { useDispatch as H, useSelector as v } from "react-redux";
3
+ import { API as p } from "@moh-sso/config";
4
+ import { createSlice as z, createSelector as i } from "@reduxjs/toolkit";
5
+ import { baseApi as f } from "@moh-sso/api";
6
+ import { jsx as N } from "react/jsx-runtime";
7
+ const K = {
7
8
  accessToken: null,
8
9
  user: null,
9
10
  loading: !0,
10
11
  loaded: !1,
11
12
  isAuthenticated: !1
12
- }, se = ke({
13
+ }, E = z({
13
14
  name: "auth",
14
- initialState: xe,
15
+ initialState: K,
15
16
  reducers: {
16
17
  /* ---------------------------
17
18
  * Bootstrap finished
@@ -25,8 +26,8 @@ const xe = {
25
26
  * Access token is optional because backend stores it
26
27
  * in an HttpOnly cookie.
27
28
  * --------------------------- */
28
- loginSuccess(e, r) {
29
- e.user = r.payload.user, e.accessToken = r.payload.accessToken ?? null, e.isAuthenticated = !0, e.loading = !1, e.loaded = !0;
29
+ loginSuccess(e, t) {
30
+ e.user = t.payload.user, e.accessToken = t.payload.accessToken ?? null, e.isAuthenticated = !0, e.loading = !1, e.loaded = !0;
30
31
  },
31
32
  /* ---------------------------
32
33
  * Token refresh only
@@ -34,8 +35,8 @@ const xe = {
34
35
  * Kept for backward compatibility.
35
36
  * Prefer not using this with HttpOnly cookies.
36
37
  * --------------------------- */
37
- setAccessToken(e, r) {
38
- e.accessToken = r.payload;
38
+ setAccessToken(e, t) {
39
+ e.accessToken = t.payload;
39
40
  },
40
41
  /* ---------------------------
41
42
  * Logout
@@ -44,31 +45,31 @@ const xe = {
44
45
  e.accessToken = null, e.user = null, e.loading = !1, e.loaded = !0, e.isAuthenticated = !1;
45
46
  }
46
47
  }
47
- }), { loginSuccess: Ce, logout: ae, setAccessToken: et, authLoaded: oe } = se.actions, tt = se.reducer, ce = A.injectEndpoints({
48
+ }), { loginSuccess: X, logout: U, setAccessToken: ye, authLoaded: W } = E.actions, ge = E.reducer, M = f.injectEndpoints({
48
49
  endpoints: (e) => ({
49
50
  /* -----------------------------
50
51
  * Get current user
51
52
  * ----------------------------- */
52
53
  me: e.query({
53
54
  query: () => ({
54
- url: g.auth.me(),
55
+ url: p.auth.me(),
55
56
  method: "GET",
56
57
  credentials: "include"
57
58
  }),
58
- transformResponse: (r) => r.data.user,
59
- async onQueryStarted(r, { dispatch: a, queryFulfilled: n }) {
59
+ transformResponse: (t) => t.data.user,
60
+ async onQueryStarted(t, { dispatch: n, queryFulfilled: s }) {
60
61
  try {
61
- const { data: o } = await n;
62
- a(
63
- Ce({
62
+ const { data: o } = await s;
63
+ n(
64
+ X({
64
65
  accessToken: null,
65
66
  user: o
66
67
  })
67
68
  );
68
69
  } catch {
69
- a(ae());
70
+ n(U());
70
71
  } finally {
71
- a(oe());
72
+ n(W());
72
73
  }
73
74
  }
74
75
  }),
@@ -76,13 +77,13 @@ const xe = {
76
77
  * Update profile
77
78
  * ----------------------------- */
78
79
  updateProfile: e.mutation({
79
- query: (r) => ({
80
- url: g.auth.me(),
80
+ query: (t) => ({
81
+ url: p.auth.me(),
81
82
  method: "PUT",
82
- body: r,
83
+ body: t,
83
84
  credentials: "include"
84
85
  }),
85
- transformResponse: (r) => r.data.user
86
+ transformResponse: (t) => t.data.user
86
87
  }),
87
88
  /* -----------------------------
88
89
  * Refresh session
@@ -93,53 +94,53 @@ const xe = {
93
94
  * ----------------------------- */
94
95
  refresh: e.mutation({
95
96
  query: () => ({
96
- url: g.auth.refresh(),
97
+ url: p.auth.refresh(),
97
98
  method: "POST",
98
99
  credentials: "include"
99
100
  })
100
101
  })
101
102
  })
102
- }), { useMeQuery: rt, useUpdateProfileMutation: nt, useRefreshMutation: st } = ce;
103
- let Z = !1;
104
- function at() {
105
- const e = ne();
106
- return U(() => {
107
- Z || (Z = !0, e(
108
- ce.endpoints.me.initiate(void 0, {
103
+ }), { useMeQuery: Se, useUpdateProfileMutation: Re, useRefreshMutation: Ce } = M;
104
+ let b = !1;
105
+ function ve() {
106
+ const e = H();
107
+ return S(() => {
108
+ b || (b = !0, e(
109
+ M.endpoints.me.initiate(void 0, {
109
110
  forceRefetch: !0
110
111
  })
111
112
  ).unwrap().catch(() => {
112
- e(ae());
113
+ e(U());
113
114
  }).finally(() => {
114
- e(oe());
115
+ e(W());
115
116
  }));
116
117
  }, [e]), null;
117
118
  }
118
- const Pe = A.injectEndpoints({
119
+ const Y = f.injectEndpoints({
119
120
  endpoints: (e) => ({
120
121
  myHealthContexts: e.query({
121
122
  query: () => ({
122
- url: g.healthContexts.mine(),
123
+ url: p.healthContexts.mine(),
123
124
  credentials: "include"
124
125
  }),
125
- transformResponse: (r) => r.data.healthContexts ?? [],
126
+ transformResponse: (t) => t.data.healthContexts ?? [],
126
127
  providesTags: ["HealthContext"]
127
128
  }),
128
129
  selectHealthContext: e.mutation({
129
- query: (r) => ({
130
- url: g.healthContexts.select(),
130
+ query: (t) => ({
131
+ url: p.healthContexts.select(),
131
132
  method: "POST",
132
133
  credentials: "include",
133
- body: { contextId: r }
134
+ body: { contextId: t }
134
135
  }),
135
- transformResponse: (r) => r.data,
136
+ transformResponse: (t) => t.data,
136
137
  invalidatesTags: ["HealthContext"]
137
138
  })
138
139
  })
139
- }), { useMyHealthContextsQuery: Oe, useSelectHealthContextMutation: Le } = Pe, x = (e) => e.auth, ot = p(x, (e) => e.accessToken), C = p(x, (e) => e.user), je = p(x, (e) => e.isAuthenticated), ct = p(C, (e) => e?.isAdmin === !0), it = p(C, (e) => e?.isUser === !0), ie = p(C, (e) => e?.permissions ?? []), Ne = p(C, (e) => e?.systems ?? []), ut = (e) => p(ie, (r) => r.includes(e)), lt = (e) => p(
140
- ie,
141
- (r) => e.some((a) => r.includes(a))
142
- ), dt = (e) => p(Ne, (r) => r.includes(e)), mt = p(x, (e) => e.loading), Ue = p(x, (e) => e.loaded), Ie = {
140
+ }), { useMyHealthContextsQuery: F, useSelectHealthContextMutation: J } = Y, y = (e) => e.auth, Ae = i(y, (e) => e.accessToken), g = i(y, (e) => e.user), Z = i(y, (e) => e.isAuthenticated), xe = i(g, (e) => e?.isAdmin === !0), ke = i(g, (e) => e?.isUser === !0), I = i(g, (e) => e?.permissions ?? []), ee = i(g, (e) => e?.systems ?? []), Te = (e) => i(I, (t) => t.includes(e)), Le = (e) => i(
141
+ I,
142
+ (t) => e.some((n) => t.includes(n))
143
+ ), _e = (e) => i(ee, (t) => t.includes(e)), be = i(y, (e) => e.loading), te = i(y, (e) => e.loaded), se = {
143
144
  portalAccess: "portal:access",
144
145
  systemsRead: "systems:read",
145
146
  systemsLaunch: "systems:launch",
@@ -197,460 +198,200 @@ const Pe = A.injectEndpoints({
197
198
  issueTrackerReopen: "issue_tracker:reopen",
198
199
  issueTrackerComment: "issue_tracker:comment"
199
200
  };
200
- function k(e) {
201
+ function w(e) {
201
202
  return e.trim().toLowerCase();
202
203
  }
203
- function I(e, r) {
204
- return e?.permissions?.includes(r) ?? !1;
204
+ function R(e, t) {
205
+ return e?.permissions?.includes(t) ?? !1;
205
206
  }
206
- function We(e, r) {
207
- return r.some((a) => I(e, a));
207
+ function ne(e, t) {
208
+ return t.some((n) => R(e, n));
208
209
  }
209
- function He(e, r) {
210
- return r.every((a) => I(e, a));
210
+ function re(e, t) {
211
+ return t.every((n) => R(e, n));
211
212
  }
212
- function ue(e, r) {
213
- const a = k(r);
214
- return e?.systems?.some((n) => k(n) === a) || e?.accessibleSystems?.some((n) => k(n.clientId) === a) || !1;
213
+ function q(e, t) {
214
+ const n = w(t);
215
+ return e?.systems?.some((s) => w(s) === n) || e?.accessibleSystems?.some((s) => w(s.clientId) === n) || !1;
215
216
  }
216
- function Me(e, r, a) {
217
- const n = k(a);
218
- return (e?.clientRoles?.[r] ?? []).some(
219
- (o) => k(o) === n
217
+ function oe(e, t, n) {
218
+ const s = w(n);
219
+ return (e?.clientRoles?.[t] ?? []).some(
220
+ (o) => w(o) === s
220
221
  );
221
222
  }
222
- function $e(e, r) {
223
- return I(e, Ie.systemsLaunch) && ue(e, r);
223
+ function ae(e, t) {
224
+ return R(e, se.systemsLaunch) && q(e, t);
224
225
  }
225
- function Ye(e) {
226
+ function ie(e) {
226
227
  return e?.accessibleSystems ?? [];
227
228
  }
228
- function qe() {
229
- const e = F(C);
230
- return D(() => {
231
- const r = new Set((e?.realmRoles ?? []).map((n) => n.toLowerCase())), a = e?.clientRoles ?? {};
229
+ function ce() {
230
+ const e = v(g);
231
+ return C(() => {
232
+ const t = new Set((e?.realmRoles ?? []).map((s) => s.toLowerCase())), n = e?.clientRoles ?? {};
232
233
  return {
233
- can: (n) => I(e, n),
234
- canAny: (n) => We(e, n),
235
- canAll: (n) => He(e, n),
236
- hasRealmRole: (n) => r.has(n.trim().toLowerCase()),
237
- hasClientRole: (n, o) => (a[n] ?? []).some(
238
- (i) => i.trim().toLowerCase() === o.trim().toLowerCase()
234
+ can: (s) => R(e, s),
235
+ canAny: (s) => ne(e, s),
236
+ canAll: (s) => re(e, s),
237
+ hasRealmRole: (s) => t.has(s.trim().toLowerCase()),
238
+ hasClientRole: (s, o) => (n[s] ?? []).some(
239
+ (c) => c.trim().toLowerCase() === o.trim().toLowerCase()
239
240
  ),
240
- hasSystem: (n) => ue(e, n),
241
- hasSystemRole: (n, o) => Me(e, n, o),
242
- canLaunchSystem: (n) => $e(e, n),
241
+ hasSystem: (s) => q(e, s),
242
+ hasSystemRole: (s, o) => oe(e, s, o),
243
+ canLaunchSystem: (s) => ae(e, s),
243
244
  permissions: e?.permissions ?? [],
244
245
  systems: e?.systems ?? [],
245
- accessibleSystems: Ye(e)
246
+ accessibleSystems: ie(e)
246
247
  };
247
248
  }, [e]);
248
249
  }
249
- function ft({
250
+ function Pe({
250
251
  permission: e,
251
- anyOf: r,
252
- fallback: a = null,
253
- children: n
252
+ anyOf: t,
253
+ fallback: n = null,
254
+ children: s
254
255
  }) {
255
- const { can: o, canAny: i } = qe();
256
- return (e ? o(e) : !0) && (r && r.length > 0 ? i(r) : !0) ? n : a;
256
+ const { can: o, canAny: c } = ce();
257
+ return (e ? o(e) : !0) && (t && t.length > 0 ? c(t) : !0) ? s : n;
257
258
  }
258
- function De() {
259
+ function le() {
259
260
  return typeof window > "u" ? "/portal" : `${window.location.pathname}${window.location.search}${window.location.hash}`;
260
261
  }
261
- function ht(e, r = De()) {
262
- const a = new URL(
262
+ function He(e, t = le()) {
263
+ const n = new URL(
263
264
  e,
264
265
  typeof window > "u" ? "http://localhost" : window.location.origin
265
266
  );
266
- return a.searchParams.set("returnTo", r), a.toString();
267
+ return n.searchParams.set("returnTo", t), n.toString();
267
268
  }
268
- function Fe(e) {
269
+ function ue(e) {
269
270
  try {
270
- const r = new URL(e);
271
- return ["http:", "https:"].includes(r.protocol) && !r.username && !r.password;
271
+ const t = new URL(e);
272
+ return ["http:", "https:"].includes(t.protocol) && !t.username && !t.password;
272
273
  } catch {
273
274
  return !1;
274
275
  }
275
276
  }
276
- function K(e, r) {
277
- const a = r.trim().replace(/\/$/, "");
278
- return !a || Fe(e) ? e : `${a}${e.startsWith("/") ? e : `/${e}`}`;
277
+ function P(e, t) {
278
+ const n = t.trim().replace(/\/$/, "");
279
+ return !n || ue(e) ? e : `${n}${e.startsWith("/") ? e : `/${e}`}`;
279
280
  }
280
- function pt(e, r) {
281
- const a = e.launchUrl?.trim() ?? "", n = e.authenticatedLaunchUrl?.trim() ?? "";
282
- return !r.hasPortalSession && n ? K(n, r.apiBaseUrl) : a || K(n, r.apiBaseUrl);
281
+ function Ee(e, t) {
282
+ const n = e.launchUrl?.trim() ?? "", s = e.authenticatedLaunchUrl?.trim() ?? "";
283
+ return !t.hasPortalSession && s ? P(s, t.apiBaseUrl) : n || P(s, t.apiBaseUrl);
283
284
  }
284
- var N = { exports: {} }, S = {};
285
- var ee;
286
- function Ve() {
287
- if (ee) return S;
288
- ee = 1;
289
- var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), r = /* @__PURE__ */ Symbol.for("react.fragment");
290
- function a(n, o, i) {
291
- var f = null;
292
- if (i !== void 0 && (f = "" + i), o.key !== void 0 && (f = "" + o.key), "key" in o) {
293
- i = {};
294
- for (var u in o)
295
- u !== "key" && (i[u] = o[u]);
296
- } else i = o;
297
- return o = i.ref, {
298
- $$typeof: e,
299
- type: n,
300
- key: f,
301
- ref: o !== void 0 ? o : null,
302
- props: i
303
- };
304
- }
305
- return S.Fragment = r, S.jsx = a, S.jsxs = a, S;
306
- }
307
- var b = {};
308
- var te;
309
- function ze() {
310
- return te || (te = 1, process.env.NODE_ENV !== "production" && (function() {
311
- function e(t) {
312
- if (t == null) return null;
313
- if (typeof t == "function")
314
- return t.$$typeof === _e ? null : t.displayName || t.name || null;
315
- if (typeof t == "string") return t;
316
- switch (t) {
317
- case R:
318
- return "Fragment";
319
- case W:
320
- return "Profiler";
321
- case w:
322
- return "StrictMode";
323
- case he:
324
- return "Suspense";
325
- case pe:
326
- return "SuspenseList";
327
- case we:
328
- return "Activity";
329
- }
330
- if (typeof t == "object")
331
- switch (typeof t.tag == "number" && console.error(
332
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
333
- ), t.$$typeof) {
334
- case l:
335
- return "Portal";
336
- case me:
337
- return t.displayName || "Context";
338
- case de:
339
- return (t._context.displayName || "Context") + ".Consumer";
340
- case fe:
341
- var s = t.render;
342
- return t = t.displayName, t || (t = s.displayName || s.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
343
- case Re:
344
- return s = t.displayName || null, s !== null ? s : e(t.type) || "Memo";
345
- case H:
346
- s = t._payload, t = t._init;
347
- try {
348
- return e(t(s));
349
- } catch {
350
- }
351
- }
352
- return null;
353
- }
354
- function r(t) {
355
- return "" + t;
356
- }
357
- function a(t) {
358
- try {
359
- r(t);
360
- var s = !1;
361
- } catch {
362
- s = !0;
363
- }
364
- if (s) {
365
- s = console;
366
- var c = s.error, d = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
367
- return c.call(
368
- s,
369
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
370
- d
371
- ), r(t);
372
- }
373
- }
374
- function n(t) {
375
- if (t === R) return "<>";
376
- if (typeof t == "object" && t !== null && t.$$typeof === H)
377
- return "<...>";
378
- try {
379
- var s = e(t);
380
- return s ? "<" + s + ">" : "<...>";
381
- } catch {
382
- return "<...>";
383
- }
384
- }
385
- function o() {
386
- var t = M.A;
387
- return t === null ? null : t.getOwner();
388
- }
389
- function i() {
390
- return Error("react-stack-top-frame");
391
- }
392
- function f(t) {
393
- if (z.call(t, "key")) {
394
- var s = Object.getOwnPropertyDescriptor(t, "key").get;
395
- if (s && s.isReactWarning) return !1;
396
- }
397
- return t.key !== void 0;
398
- }
399
- function u(t, s) {
400
- function c() {
401
- B || (B = !0, console.error(
402
- "%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://react.dev/link/special-props)",
403
- s
404
- ));
405
- }
406
- c.isReactWarning = !0, Object.defineProperty(t, "key", {
407
- get: c,
408
- configurable: !0
409
- });
410
- }
411
- function P() {
412
- var t = e(this.type);
413
- return G[t] || (G[t] = !0, console.error(
414
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
415
- )), t = this.props.ref, t !== void 0 ? t : null;
416
- }
417
- function O(t, s, c, d, j, Y) {
418
- var m = c.ref;
419
- return t = {
420
- $$typeof: L,
421
- type: t,
422
- key: s,
423
- props: c,
424
- _owner: d
425
- }, (m !== void 0 ? m : null) !== null ? Object.defineProperty(t, "ref", {
426
- enumerable: !1,
427
- get: P
428
- }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
429
- configurable: !1,
430
- enumerable: !1,
431
- writable: !0,
432
- value: 0
433
- }), Object.defineProperty(t, "_debugInfo", {
434
- configurable: !1,
435
- enumerable: !1,
436
- writable: !0,
437
- value: null
438
- }), Object.defineProperty(t, "_debugStack", {
439
- configurable: !1,
440
- enumerable: !1,
441
- writable: !0,
442
- value: j
443
- }), Object.defineProperty(t, "_debugTask", {
444
- configurable: !1,
445
- enumerable: !1,
446
- writable: !0,
447
- value: Y
448
- }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
449
- }
450
- function E(t, s, c, d, j, Y) {
451
- var m = s.children;
452
- if (m !== void 0)
453
- if (d)
454
- if (ve(m)) {
455
- for (d = 0; d < m.length; d++)
456
- T(m[d]);
457
- Object.freeze && Object.freeze(m);
458
- } else
459
- console.error(
460
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
461
- );
462
- else T(m);
463
- if (z.call(s, "key")) {
464
- m = e(t);
465
- var v = Object.keys(s).filter(function(ye) {
466
- return ye !== "key";
467
- });
468
- d = 0 < v.length ? "{key: someKey, " + v.join(": ..., ") + ": ...}" : "{key: someKey}", X[m + d] || (v = 0 < v.length ? "{" + v.join(": ..., ") + ": ...}" : "{}", console.error(
469
- `A props object containing a "key" prop is being spread into JSX:
470
- let props = %s;
471
- <%s {...props} />
472
- React keys must be passed directly to JSX without using spread:
473
- let props = %s;
474
- <%s key={someKey} {...props} />`,
475
- d,
476
- m,
477
- v,
478
- m
479
- ), X[m + d] = !0);
480
- }
481
- if (m = null, c !== void 0 && (a(c), m = "" + c), f(s) && (a(s.key), m = "" + s.key), "key" in s) {
482
- c = {};
483
- for (var q in s)
484
- q !== "key" && (c[q] = s[q]);
485
- } else c = s;
486
- return m && u(
487
- c,
488
- typeof t == "function" ? t.displayName || t.name || "Unknown" : t
489
- ), O(
490
- t,
491
- m,
492
- c,
493
- o(),
494
- j,
495
- Y
496
- );
497
- }
498
- function T(t) {
499
- h(t) ? t._store && (t._store.validated = 1) : typeof t == "object" && t !== null && t.$$typeof === H && (t._payload.status === "fulfilled" ? h(t._payload.value) && t._payload.value._store && (t._payload.value._store.validated = 1) : t._store && (t._store.validated = 1));
500
- }
501
- function h(t) {
502
- return typeof t == "object" && t !== null && t.$$typeof === L;
503
- }
504
- var _ = Ee, L = /* @__PURE__ */ Symbol.for("react.transitional.element"), l = /* @__PURE__ */ Symbol.for("react.portal"), R = /* @__PURE__ */ Symbol.for("react.fragment"), w = /* @__PURE__ */ Symbol.for("react.strict_mode"), W = /* @__PURE__ */ Symbol.for("react.profiler"), de = /* @__PURE__ */ Symbol.for("react.consumer"), me = /* @__PURE__ */ Symbol.for("react.context"), fe = /* @__PURE__ */ Symbol.for("react.forward_ref"), he = /* @__PURE__ */ Symbol.for("react.suspense"), pe = /* @__PURE__ */ Symbol.for("react.suspense_list"), Re = /* @__PURE__ */ Symbol.for("react.memo"), H = /* @__PURE__ */ Symbol.for("react.lazy"), we = /* @__PURE__ */ Symbol.for("react.activity"), _e = /* @__PURE__ */ Symbol.for("react.client.reference"), M = _.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, z = Object.prototype.hasOwnProperty, ve = Array.isArray, $ = console.createTask ? console.createTask : function() {
505
- return null;
506
- };
507
- _ = {
508
- react_stack_bottom_frame: function(t) {
509
- return t();
510
- }
511
- };
512
- var B, G = {}, J = _.react_stack_bottom_frame.bind(
513
- _,
514
- i
515
- )(), Q = $(n(i)), X = {};
516
- b.Fragment = R, b.jsx = function(t, s, c) {
517
- var d = 1e4 > M.recentlyCreatedOwnerStacks++;
518
- return E(
519
- t,
520
- s,
521
- c,
522
- !1,
523
- d ? Error("react-stack-top-frame") : J,
524
- d ? $(n(t)) : Q
525
- );
526
- }, b.jsxs = function(t, s, c) {
527
- var d = 1e4 > M.recentlyCreatedOwnerStacks++;
528
- return E(
529
- t,
530
- s,
531
- c,
532
- !0,
533
- d ? Error("react-stack-top-frame") : J,
534
- d ? $(n(t)) : Q
535
- );
536
- };
537
- })()), b;
538
- }
539
- var re;
540
- function Be() {
541
- return re || (re = 1, process.env.NODE_ENV === "production" ? N.exports = Ve() : N.exports = ze()), N.exports;
542
- }
543
- var Ge = Be();
544
- const y = "moh.activeHealthContextId", le = Te(void 0);
545
- function Rt({ children: e }) {
546
- const r = ne(), a = F(je), n = F(Ue), [o, i] = Se(
547
- () => typeof window > "u" ? null : window.localStorage.getItem(y)
548
- ), f = be(o), {
549
- data: u = [],
550
- isLoading: P,
551
- isSuccess: O
552
- } = Oe(void 0, {
553
- skip: !a
554
- }), [E, { isLoading: T }] = Le(), h = D(() => u.find((l) => l.id === o) ?? u.find((l) => l.isActive) ?? u.find((l) => l.isDefault) ?? u[0], [u, o]);
555
- U(() => {
285
+ const h = "moh.activeHealthContextId", B = D(void 0);
286
+ function Ue({ children: e }) {
287
+ const t = H(), n = v(Z), s = v(te), [o, c] = j(
288
+ () => typeof window > "u" ? null : window.localStorage.getItem(h)
289
+ ), u = G(o), {
290
+ data: a = [],
291
+ isLoading: x,
292
+ isSuccess: k
293
+ } = F(void 0, {
294
+ skip: !n
295
+ }), [T, { isLoading: L }] = J(), l = C(() => a.find((r) => r.id === o) ?? a.find((r) => r.isActive) ?? a.find((r) => r.isDefault) ?? a[0], [a, o]);
296
+ S(() => {
556
297
  if (!(typeof window > "u")) {
557
- if (n && !a) {
558
- window.localStorage.removeItem(y), f.current = null, i(null);
298
+ if (s && !n) {
299
+ window.localStorage.removeItem(h), u.current = null, c(null);
559
300
  return;
560
301
  }
561
- if (a && O && u.length === 0) {
562
- window.localStorage.removeItem(y), f.current = null, i(null);
302
+ if (n && k && a.length === 0) {
303
+ window.localStorage.removeItem(h), u.current = null, c(null);
563
304
  return;
564
305
  }
565
- h && (f.current = h.id, window.localStorage.setItem(y, h.id), o !== h.id && i(h.id), window.dispatchEvent(
566
- new CustomEvent("moh:health-context-changed", { detail: h })
306
+ l && (u.current = l.id, window.localStorage.setItem(h, l.id), o !== l.id && c(l.id), window.dispatchEvent(
307
+ new CustomEvent("moh:health-context-changed", { detail: l })
567
308
  ));
568
309
  }
569
- }, [h, a, n, u.length, O, o]), U(() => {
570
- const l = (R) => {
571
- R.key === y && (f.current = R.newValue, i(R.newValue), r(A.util.resetApiState()));
310
+ }, [l, n, s, a.length, k, o]), S(() => {
311
+ const r = (d) => {
312
+ d.key === h && (u.current = d.newValue, c(d.newValue), t(f.util.resetApiState()));
572
313
  };
573
- return window.addEventListener("storage", l), () => window.removeEventListener("storage", l);
574
- }, [r]), U(() => {
575
- const l = (R) => {
576
- const w = R.detail;
577
- !w?.id || !u.some((W) => W.id === w.id) || f.current !== w.id && (f.current = w.id, i(w.id), r(A.util.resetApiState()));
314
+ return window.addEventListener("storage", r), () => window.removeEventListener("storage", r);
315
+ }, [t]), S(() => {
316
+ const r = (d) => {
317
+ const m = d.detail;
318
+ !m?.id || !a.some((Q) => Q.id === m.id) || u.current !== m.id && (u.current = m.id, c(m.id), t(f.util.resetApiState()));
578
319
  };
579
- return window.addEventListener("moh:health-context-changed", l), () => window.removeEventListener("moh:health-context-changed", l);
580
- }, [u, r]);
581
- const _ = ge(
582
- async (l) => {
583
- await E(l).unwrap(), f.current = l, window.localStorage.setItem(y, l), i(l), r(A.util.resetApiState());
584
- const R = u.find((w) => w.id === l);
585
- window.dispatchEvent(new CustomEvent("moh:health-context-changed", { detail: R }));
320
+ return window.addEventListener("moh:health-context-changed", r), () => window.removeEventListener("moh:health-context-changed", r);
321
+ }, [a, t]);
322
+ const _ = O(
323
+ async (r) => {
324
+ await T(r).unwrap(), u.current = r, window.localStorage.setItem(h, r), c(r), t(f.util.resetApiState());
325
+ const d = a.find((m) => m.id === r);
326
+ window.dispatchEvent(new CustomEvent("moh:health-context-changed", { detail: d }));
586
327
  },
587
- [u, r, E]
588
- ), L = D(
589
- () => ({ contexts: u, activeContext: h, isLoading: P, isUpdating: T, selectContext: _ }),
590
- [h, u, P, T, _]
328
+ [a, t, T]
329
+ ), $ = C(
330
+ () => ({ contexts: a, activeContext: l, isLoading: x, isUpdating: L, selectContext: _ }),
331
+ [l, a, x, L, _]
591
332
  );
592
- return /* @__PURE__ */ Ge.jsx(le.Provider, { value: L, children: e });
333
+ return /* @__PURE__ */ N(B.Provider, { value: $, children: e });
593
334
  }
594
- function V() {
595
- const e = Ae(le);
335
+ function A() {
336
+ const e = V(B);
596
337
  if (!e)
597
338
  throw new Error("useHealthContext must be used inside HealthContextProvider");
598
339
  return e;
599
340
  }
600
- function wt() {
601
- return V().contexts;
341
+ function We() {
342
+ return A().contexts;
602
343
  }
603
- function _t() {
604
- return V().activeContext;
344
+ function Me() {
345
+ return A().activeContext;
605
346
  }
606
- function vt() {
607
- const e = V();
347
+ function Ie() {
348
+ const e = A();
608
349
  return { ...e, hasContext: !!e.activeContext };
609
350
  }
610
351
  export {
611
- y as ACTIVE_HEALTH_CONTEXT_STORAGE_KEY,
612
- at as AuthBootstrap,
613
- Rt as HealthContextProvider,
614
- Ie as PERMISSIONS,
615
- ft as PermissionGuard,
616
- ce as authApi,
617
- oe as authLoaded,
618
- tt as authReducer,
619
- ht as buildLoginURL,
620
- $e as canLaunchSystem,
621
- De as currentPortalReturnTo,
622
- Ye as getAccessibleSystems,
623
- He as hasAllPermissions,
624
- We as hasAnyPermission,
625
- I as hasPermission,
626
- ue as hasSystem,
627
- Me as hasSystemRole,
628
- Pe as healthContextApi,
629
- Ce as loginSuccess,
630
- ae as logout,
631
- pt as resolveSystemLaunchUrl,
632
- ot as selectAccessToken,
633
- x as selectAuth,
634
- Ue as selectAuthLoaded,
635
- mt as selectAuthLoading,
636
- je as selectAuthenticated,
637
- lt as selectHasAnyPermission,
638
- ut as selectHasPermission,
639
- dt as selectHasSystem,
640
- ct as selectIsAdmin,
641
- it as selectIsUser,
642
- ie as selectPermissions,
643
- Ne as selectSystems,
644
- C as selectUser,
645
- et as setAccessToken,
646
- _t as useActiveHealthContext,
647
- qe as useAuthorization,
648
- wt as useAvailableHealthContexts,
649
- V as useHealthContext,
650
- rt as useMeQuery,
651
- Oe as useMyHealthContextsQuery,
652
- st as useRefreshMutation,
653
- vt as useRequireHealthContext,
654
- Le as useSelectHealthContextMutation,
655
- nt as useUpdateProfileMutation
352
+ h as ACTIVE_HEALTH_CONTEXT_STORAGE_KEY,
353
+ ve as AuthBootstrap,
354
+ Ue as HealthContextProvider,
355
+ se as PERMISSIONS,
356
+ Pe as PermissionGuard,
357
+ M as authApi,
358
+ W as authLoaded,
359
+ ge as authReducer,
360
+ He as buildLoginURL,
361
+ ae as canLaunchSystem,
362
+ le as currentPortalReturnTo,
363
+ ie as getAccessibleSystems,
364
+ re as hasAllPermissions,
365
+ ne as hasAnyPermission,
366
+ R as hasPermission,
367
+ q as hasSystem,
368
+ oe as hasSystemRole,
369
+ Y as healthContextApi,
370
+ X as loginSuccess,
371
+ U as logout,
372
+ Ee as resolveSystemLaunchUrl,
373
+ Ae as selectAccessToken,
374
+ y as selectAuth,
375
+ te as selectAuthLoaded,
376
+ be as selectAuthLoading,
377
+ Z as selectAuthenticated,
378
+ Le as selectHasAnyPermission,
379
+ Te as selectHasPermission,
380
+ _e as selectHasSystem,
381
+ xe as selectIsAdmin,
382
+ ke as selectIsUser,
383
+ I as selectPermissions,
384
+ ee as selectSystems,
385
+ g as selectUser,
386
+ ye as setAccessToken,
387
+ Me as useActiveHealthContext,
388
+ ce as useAuthorization,
389
+ We as useAvailableHealthContexts,
390
+ A as useHealthContext,
391
+ Se as useMeQuery,
392
+ F as useMyHealthContextsQuery,
393
+ Ce as useRefreshMutation,
394
+ Ie as useRequireHealthContext,
395
+ J as useSelectHealthContextMutation,
396
+ Re as useUpdateProfileMutation
656
397
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
- "version": "1.3.2",
6
+ "version": "1.4.1",
7
7
  "license": "UNLICENSED",
8
8
  "module": "./dist/index.js",
9
9
  "files": [
@@ -24,9 +24,9 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@moh-sso/api": "^1.3.2",
28
- "@moh-sso/state": "^1.3.2",
29
- "@moh-sso/config": "^1.3.2"
27
+ "@moh-sso/api": "^1.4.1",
28
+ "@moh-sso/state": "^1.4.1",
29
+ "@moh-sso/config": "^1.4.1"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@reduxjs/toolkit": "^2.11.2",