@arkitektbedriftene/fe-lib 1.1.2 → 1.2.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.
@@ -14,6 +14,8 @@ export type AuthContextData = {
14
14
  state: AuthState;
15
15
  handleSigninCallback: () => Promise<User | undefined>;
16
16
  redirectToSignin: UserManager["signinRedirect"];
17
+ signinSilent: UserManager["signinSilent"];
18
+ signinPopup: UserManager["signinPopup"];
17
19
  logout: UserManager["signoutRedirect"];
18
20
  };
19
21
  export type AuthProviderConfig = {
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 P } from "jwt-decode";
6
+ const I = x(
7
7
  null
8
- ), L = () => {
9
- const e = x(I);
10
- if (!e)
8
+ ), g = () => {
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, c] = 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
24
  c({ 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(() => {
27
+ return /* @__PURE__ */ C(I.Provider, { value: s, children: t });
28
+ }, N = (t) => {
29
+ const { setImpersonation: e } = g();
30
+ h(() => {
31
31
  const { search: c } = window.location, s = new URLSearchParams(c).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 = P(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,
67
+ ], y = ({
68
+ userManager: t,
69
+ context: e,
70
70
  children: c
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 a = () => {
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(a);
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(a), 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,99 @@ 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 (a) {
145
+ console.error(a);
146
146
  }
147
147
  },
148
- [e]
149
- ), l = C(
148
+ [t]
149
+ ), d = l(
150
+ async (r) => await t.signinPopup(r),
151
+ [t]
152
+ ), m = l(
150
153
  async (r) => {
151
154
  try {
152
- await e.signoutRedirect(r);
153
- } catch (u) {
154
- console.error(u);
155
+ return await t.signinSilent(r);
156
+ } catch (a) {
157
+ return n({
158
+ user: null,
159
+ isLoading: !1,
160
+ isAuthenticated: !1,
161
+ isError: !0,
162
+ error: a instanceof Error ? a : new Error("Unknown error during silent signin")
163
+ }), null;
155
164
  }
156
165
  },
157
- [e]
158
- ), f = v(
166
+ [t]
167
+ ), A = l(
168
+ async (r) => {
169
+ try {
170
+ await t.signoutRedirect(r);
171
+ } catch (a) {
172
+ console.error(a);
173
+ }
174
+ },
175
+ [t]
176
+ ), S = E(
159
177
  () => ({
160
178
  state: s,
161
- handleSigninCallback: a,
179
+ handleSigninCallback: u,
162
180
  redirectToSignin: i,
163
- logout: l
181
+ signinSilent: m,
182
+ signinPopup: d,
183
+ logout: A
164
184
  }),
165
- [s, a, i, l]
185
+ [
186
+ s,
187
+ u,
188
+ i,
189
+ m,
190
+ d,
191
+ A
192
+ ]
166
193
  );
167
- return /* @__PURE__ */ A(t.Provider, { value: f, children: c });
168
- }, h = (e) => {
169
- const t = x(e);
170
- if (!t)
194
+ return /* @__PURE__ */ C(e.Provider, { value: S, children: c });
195
+ }, p = (t) => {
196
+ const e = v(t);
197
+ if (!e)
171
198
  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(() => {
199
+ return e;
200
+ }, R = (t) => {
201
+ const { state: e } = p(t);
202
+ return e;
203
+ }, b = (t, e) => {
204
+ const { state: c, handleSigninCallback: s } = p(t), n = U(!1);
205
+ return h(() => {
179
206
  n.current || (n.current = !0, s().then(
180
207
  (o) => new Promise(
181
- (a) => setTimeout(() => a(o), 0)
208
+ (u) => setTimeout(() => u(o), 0)
182
209
  )
183
- ).then((o) => t == null ? void 0 : t(o)));
210
+ ).then((o) => e == null ? void 0 : e(o)));
184
211
  }, [s]), c;
185
- }, K = (e) => {
186
- const t = p(null);
212
+ }, q = (t) => {
213
+ const e = x(null);
187
214
  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),
215
+ AuthContext: e,
216
+ AuthProvider: ({ children: i }) => /* @__PURE__ */ C(y, { userManager: t, context: e, children: i }),
217
+ useAuthContext: () => p(e),
218
+ useAuthState: () => R(e),
219
+ useSigninCallback: (i) => b(e, i),
193
220
  getAccessToken: async () => {
194
- const i = await e.getUser();
221
+ const i = await t.getUser();
195
222
  return i ? i.access_token : null;
196
223
  }
197
224
  };
198
225
  };
199
226
  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
227
+ z as ImpersonationContextProvider,
228
+ J as ROLESAdminInCompany,
229
+ _ as ROLESAnsatt,
230
+ K as ROLESMAKSAdministrator,
231
+ q as createAuthContext,
232
+ V as parseUserProfileFCString,
233
+ N as useImpersonationCallback,
234
+ g as useImpersonationContext
208
235
  };
@@ -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.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {