@arkitektbedriftene/fe-lib 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/oidc.es.js CHANGED
@@ -1,85 +1,85 @@
1
- import { jsx as A } from "react/jsx-runtime";
2
- import { createContext as p, useContext as x, useMemo as v, useEffect as m, useState as U, useRef as w, useCallback as C } from "react";
1
+ import { jsx as C } from "react/jsx-runtime";
2
+ import { createContext as x, useContext as v, useMemo as E, useEffect as h, useState as k, useRef as U, useCallback as l } from "react";
3
3
  export * from "oidc-client-ts";
4
- import E from "use-local-storage-state";
5
- import { jwtDecode as k } from "jwt-decode";
6
- const I = p(
4
+ import L from "use-local-storage-state";
5
+ import { jwtDecode as y } from "jwt-decode";
6
+ const I = x(
7
7
  null
8
- ), L = () => {
9
- const e = x(I);
10
- if (!e)
8
+ ), P = () => {
9
+ const t = v(I);
10
+ if (!t)
11
11
  throw new Error(
12
12
  "useImpersonationContext must be used within a ImpersonationContextProvider"
13
13
  );
14
- return e;
15
- }, F = ({
16
- children: e
14
+ return t;
15
+ }, z = ({
16
+ children: t
17
17
  }) => {
18
- const [t, c] = E("impersonationState", {
18
+ const [e, a] = L("impersonationState", {
19
19
  defaultValue: {}
20
- }), s = v(() => ({
21
- accessToken: t == null ? void 0 : t.accessToken,
22
- userInfo: t == null ? void 0 : t.userInfo,
20
+ }), s = E(() => ({
21
+ accessToken: e == null ? void 0 : e.accessToken,
22
+ userInfo: e == null ? void 0 : e.userInfo,
23
23
  setImpersonation: (n, o) => {
24
- c({ accessToken: n, userInfo: o });
24
+ a({ accessToken: n, userInfo: o });
25
25
  }
26
26
  }), []);
27
- return /* @__PURE__ */ A(I.Provider, { value: s, children: e });
28
- }, j = (e) => {
29
- const { setImpersonation: t } = L();
30
- m(() => {
31
- const { search: c } = window.location, s = new URLSearchParams(c).get(
27
+ return /* @__PURE__ */ C(I.Provider, { value: s, children: t });
28
+ }, N = (t) => {
29
+ const { setImpersonation: e } = P();
30
+ h(() => {
31
+ const { search: a } = window.location, s = new URLSearchParams(a).get(
32
32
  "impersonateAccessToken"
33
33
  );
34
- if (s && t) {
35
- const n = k(s);
36
- t(s, n), e();
34
+ if (s && e) {
35
+ const n = y(s);
36
+ e(s, n), t();
37
37
  }
38
38
  }, []);
39
39
  };
40
- function z(e) {
41
- return JSON.parse(e).map((s) => {
40
+ function V(t) {
41
+ return JSON.parse(t).map((s) => {
42
42
  const [
43
43
  n,
44
44
  o,
45
- a,
45
+ u,
46
46
  i,
47
- l
48
- ] = s.split("|"), f = i.split(",");
47
+ d
48
+ ] = s.split("|"), m = i.split(",");
49
49
  return {
50
50
  CustomerExternalId: n,
51
51
  CustomerFirmId: o,
52
- CustomerFirmName: a,
53
- CustomerUserRoles: f,
54
- CustomerUserIsAdmin: l === "True"
52
+ CustomerFirmName: u,
53
+ CustomerUserRoles: m,
54
+ CustomerUserIsAdmin: d === "True"
55
55
  };
56
56
  });
57
57
  }
58
- const N = [
58
+ const J = [
59
59
  "97",
60
60
  "131",
61
61
  "132",
62
62
  "141"
63
- ], V = [
63
+ ], K = [
64
64
  "3"
65
- ], J = [
65
+ ], _ = [
66
66
  "0"
67
- ], R = ({
68
- userManager: e,
69
- context: t,
70
- children: c
67
+ ], g = ({
68
+ userManager: t,
69
+ context: e,
70
+ children: a
71
71
  }) => {
72
- const [s, n] = U({
72
+ const [s, n] = k({
73
73
  user: null,
74
74
  isLoading: !0,
75
75
  isAuthenticated: !1,
76
76
  isError: !1,
77
77
  error: null
78
- }), o = w(!1);
79
- m(() => {
78
+ }), o = U(!1);
79
+ h(() => {
80
80
  o.current || (o.current = !0, (async () => {
81
81
  try {
82
- const r = await e.getUser();
82
+ const r = await t.getUser();
83
83
  n({
84
84
  user: r,
85
85
  isLoading: !1,
@@ -97,39 +97,39 @@ const N = [
97
97
  });
98
98
  }
99
99
  })());
100
- }, [e]), m(() => {
101
- const r = (d) => {
100
+ }, [t]), h(() => {
101
+ const r = (f) => {
102
102
  n({
103
- user: d,
103
+ user: f,
104
104
  isLoading: !1,
105
- isAuthenticated: !d.expired,
105
+ isAuthenticated: !f.expired,
106
106
  isError: !1,
107
107
  error: null
108
108
  });
109
109
  };
110
- e.events.addUserLoaded(r);
111
- const u = () => {
110
+ t.events.addUserLoaded(r);
111
+ const c = () => {
112
112
  n({
113
113
  ...s,
114
114
  user: null,
115
115
  isAuthenticated: !1
116
116
  });
117
117
  };
118
- e.events.addUserUnloaded(u);
119
- const S = (d) => {
118
+ t.events.addUserUnloaded(c);
119
+ const w = (f) => {
120
120
  n({
121
121
  ...s,
122
122
  isLoading: !1,
123
123
  isError: !0,
124
- error: d
124
+ error: f
125
125
  });
126
126
  };
127
- return e.events.addSilentRenewError(S), () => {
128
- e.events.removeUserLoaded(r), e.events.removeUserUnloaded(u), e.events.removeSilentRenewError(S);
127
+ return t.events.addSilentRenewError(w), () => {
128
+ t.events.removeUserLoaded(r), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(w);
129
129
  };
130
- }, [e]);
131
- const a = C(async () => {
132
- const r = await e.signinCallback();
130
+ }, [t]);
131
+ const u = l(async () => {
132
+ const r = await t.signinCallback();
133
133
  return n({
134
134
  user: r ?? null,
135
135
  isLoading: !1,
@@ -137,72 +137,105 @@ const N = [
137
137
  isError: !1,
138
138
  error: null
139
139
  }), r ?? void 0;
140
- }, [e]), i = C(
140
+ }, [t]), i = l(
141
141
  async (r) => {
142
142
  try {
143
- await e.signinRedirect(r);
144
- } catch (u) {
145
- console.error(u);
143
+ await t.signinRedirect(r);
144
+ } catch (c) {
145
+ console.error(c);
146
146
  }
147
147
  },
148
- [e]
149
- ), l = C(
148
+ [t]
149
+ ), d = l(
150
150
  async (r) => {
151
151
  try {
152
- await e.signoutRedirect(r);
153
- } catch (u) {
154
- console.error(u);
152
+ await t.signinPopup(r);
153
+ } catch (c) {
154
+ console.error(c);
155
155
  }
156
156
  },
157
- [e]
158
- ), f = v(
157
+ [t]
158
+ ), m = l(
159
+ async (r) => {
160
+ try {
161
+ return await t.signinSilent(r);
162
+ } catch (c) {
163
+ n({
164
+ user: null,
165
+ isLoading: !1,
166
+ isAuthenticated: !1,
167
+ isError: !0,
168
+ error: c instanceof Error ? c : new Error("Unknown error during silent signin")
169
+ });
170
+ }
171
+ },
172
+ [t]
173
+ ), A = l(
174
+ async (r) => {
175
+ try {
176
+ await t.signoutRedirect(r);
177
+ } catch (c) {
178
+ console.error(c);
179
+ }
180
+ },
181
+ [t]
182
+ ), S = E(
159
183
  () => ({
160
184
  state: s,
161
- handleSigninCallback: a,
185
+ handleSigninCallback: u,
162
186
  redirectToSignin: i,
163
- logout: l
187
+ signinSilent: m,
188
+ signinPopup: d,
189
+ logout: A
164
190
  }),
165
- [s, a, i, l]
191
+ [
192
+ s,
193
+ u,
194
+ i,
195
+ m,
196
+ d,
197
+ A
198
+ ]
166
199
  );
167
- return /* @__PURE__ */ A(t.Provider, { value: f, children: c });
168
- }, h = (e) => {
169
- const t = x(e);
170
- if (!t)
200
+ return /* @__PURE__ */ C(e.Provider, { value: S, children: a });
201
+ }, p = (t) => {
202
+ const e = v(t);
203
+ if (!e)
171
204
  throw new Error("useAuthContext must be used within an AuthProvider");
172
- return t;
173
- }, P = (e) => {
174
- const { state: t } = h(e);
175
- return t;
176
- }, b = (e, t) => {
177
- const { state: c, handleSigninCallback: s } = h(e), n = w(!1);
178
- return m(() => {
205
+ return e;
206
+ }, R = (t) => {
207
+ const { state: e } = p(t);
208
+ return e;
209
+ }, b = (t, e) => {
210
+ const { state: a, handleSigninCallback: s } = p(t), n = U(!1);
211
+ return h(() => {
179
212
  n.current || (n.current = !0, s().then(
180
213
  (o) => new Promise(
181
- (a) => setTimeout(() => a(o), 0)
214
+ (u) => setTimeout(() => u(o), 0)
182
215
  )
183
- ).then((o) => t == null ? void 0 : t(o)));
184
- }, [s]), c;
185
- }, K = (e) => {
186
- const t = p(null);
216
+ ).then((o) => e == null ? void 0 : e(o)));
217
+ }, [s]), a;
218
+ }, q = (t) => {
219
+ const e = x(null);
187
220
  return {
188
- AuthContext: t,
189
- AuthProvider: ({ children: i }) => /* @__PURE__ */ A(R, { userManager: e, context: t, children: i }),
190
- useAuthContext: () => h(t),
191
- useAuthState: () => P(t),
192
- useSigninCallback: (i) => b(t, i),
221
+ AuthContext: e,
222
+ AuthProvider: ({ children: i }) => /* @__PURE__ */ C(g, { userManager: t, context: e, children: i }),
223
+ useAuthContext: () => p(e),
224
+ useAuthState: () => R(e),
225
+ useSigninCallback: (i) => b(e, i),
193
226
  getAccessToken: async () => {
194
- const i = await e.getUser();
227
+ const i = await t.getUser();
195
228
  return i ? i.access_token : null;
196
229
  }
197
230
  };
198
231
  };
199
232
  export {
200
- F as ImpersonationContextProvider,
201
- N as ROLESAdminInCompany,
202
- J as ROLESAnsatt,
203
- V as ROLESMAKSAdministrator,
204
- K as createAuthContext,
205
- z as parseUserProfileFCString,
206
- j as useImpersonationCallback,
207
- L as useImpersonationContext
233
+ z as ImpersonationContextProvider,
234
+ J as ROLESAdminInCompany,
235
+ _ as ROLESAnsatt,
236
+ K as ROLESMAKSAdministrator,
237
+ q as createAuthContext,
238
+ V as parseUserProfileFCString,
239
+ N as useImpersonationCallback,
240
+ P as useImpersonationContext
208
241
  };
@@ -1,7 +1,7 @@
1
1
  export declare const Stack: import("@stitches/react/types/styled-component").StyledComponent<"div", {
2
2
  direction?: "column" | "row" | undefined;
3
3
  align?: "center" | "start" | undefined;
4
- gap?: 0 | 1 | "0" | "1" | "2" | "3" | 2 | 3 | 4 | "4" | "6" | "8" | 6 | 8 | 5 | 7 | "5" | "7" | undefined;
4
+ gap?: 0 | 1 | "0" | "1" | "2" | "3" | 2 | 3 | 4 | "4" | "5" | "6" | "8" | 6 | 8 | 5 | 7 | "7" | undefined;
5
5
  }, {
6
6
  lg: "(min-width: 1200px)";
7
7
  print: "print";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkitektbedriftene/fe-lib",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {