@arkitektbedriftene/fe-lib 1.0.0 → 1.1.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.
- package/dist/oidc/oidc.d.ts +1 -0
- package/dist/oidc.es.js +70 -60
- package/package.json +1 -1
package/dist/oidc/oidc.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type AuthContextData = {
|
|
|
14
14
|
state: AuthState;
|
|
15
15
|
handleSigninCallback: () => Promise<User | undefined>;
|
|
16
16
|
redirectToSignin: UserManager["signinRedirect"];
|
|
17
|
+
logout: UserManager["signoutRedirect"];
|
|
17
18
|
};
|
|
18
19
|
export type AuthProviderConfig = {
|
|
19
20
|
onSigninComplete: (user: User | null) => void;
|
package/dist/oidc.es.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as S, useContext as
|
|
1
|
+
import { jsx as A } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as S, useContext as w, useMemo as x, useEffect as m, useState as U, useRef as v, useCallback as C } from "react";
|
|
3
3
|
export * from "oidc-client-ts";
|
|
4
|
-
import
|
|
5
|
-
import { jwtDecode as
|
|
6
|
-
const
|
|
4
|
+
import E from "use-local-storage-state";
|
|
5
|
+
import { jwtDecode as k } from "jwt-decode";
|
|
6
|
+
const I = S(
|
|
7
7
|
null
|
|
8
|
-
),
|
|
9
|
-
const e =
|
|
8
|
+
), L = () => {
|
|
9
|
+
const e = w(I);
|
|
10
10
|
if (!e)
|
|
11
11
|
throw new Error(
|
|
12
12
|
"useImpersonationContext must be used within a ImpersonationContextProvider"
|
|
13
13
|
);
|
|
14
14
|
return e;
|
|
15
|
-
},
|
|
15
|
+
}, F = ({
|
|
16
16
|
children: e
|
|
17
17
|
}) => {
|
|
18
|
-
const [t, c] =
|
|
18
|
+
const [t, c] = E("impersonationState", {
|
|
19
19
|
defaultValue: {}
|
|
20
20
|
}), s = x(() => ({
|
|
21
21
|
accessToken: t == null ? void 0 : t.accessToken,
|
|
@@ -24,59 +24,59 @@ const w = S(
|
|
|
24
24
|
c({ accessToken: n, userInfo: o });
|
|
25
25
|
}
|
|
26
26
|
}), []);
|
|
27
|
-
return /* @__PURE__ */
|
|
28
|
-
},
|
|
29
|
-
const { setImpersonation: t } =
|
|
30
|
-
|
|
27
|
+
return /* @__PURE__ */ A(I.Provider, { value: s, children: e });
|
|
28
|
+
}, j = (e) => {
|
|
29
|
+
const { setImpersonation: t } = L();
|
|
30
|
+
m(() => {
|
|
31
31
|
const { search: c } = window.location, s = new URLSearchParams(c).get(
|
|
32
32
|
"impersonateAccessToken"
|
|
33
33
|
);
|
|
34
34
|
if (s && t) {
|
|
35
|
-
const n =
|
|
35
|
+
const n = k(s);
|
|
36
36
|
t(s, n), e();
|
|
37
37
|
}
|
|
38
38
|
}, []);
|
|
39
39
|
};
|
|
40
|
-
function
|
|
40
|
+
function z(e) {
|
|
41
41
|
return JSON.parse(e).map((s) => {
|
|
42
42
|
const [
|
|
43
43
|
n,
|
|
44
44
|
o,
|
|
45
45
|
a,
|
|
46
46
|
i,
|
|
47
|
-
|
|
48
|
-
] = s.split("|"),
|
|
47
|
+
l
|
|
48
|
+
] = s.split("|"), f = i.split(",");
|
|
49
49
|
return {
|
|
50
50
|
CustomerExternalId: n,
|
|
51
51
|
CustomerFirmId: o,
|
|
52
52
|
CustomerFirmName: a,
|
|
53
|
-
CustomerUserRoles:
|
|
54
|
-
CustomerUserIsAdmin:
|
|
53
|
+
CustomerUserRoles: f,
|
|
54
|
+
CustomerUserIsAdmin: l === "True"
|
|
55
55
|
};
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const N = [
|
|
59
59
|
"97",
|
|
60
60
|
"131",
|
|
61
61
|
"132",
|
|
62
62
|
"141"
|
|
63
|
-
], N = [
|
|
64
|
-
"3"
|
|
65
63
|
], V = [
|
|
64
|
+
"3"
|
|
65
|
+
], J = [
|
|
66
66
|
"0"
|
|
67
|
-
],
|
|
67
|
+
], P = ({
|
|
68
68
|
userManager: e,
|
|
69
69
|
context: t,
|
|
70
70
|
children: c
|
|
71
71
|
}) => {
|
|
72
|
-
const [s, n] =
|
|
72
|
+
const [s, n] = U({
|
|
73
73
|
user: null,
|
|
74
74
|
isLoading: !0,
|
|
75
75
|
isAuthenticated: !1,
|
|
76
76
|
isError: !1,
|
|
77
77
|
error: null
|
|
78
78
|
}), o = v(!1);
|
|
79
|
-
|
|
79
|
+
m(() => {
|
|
80
80
|
o.current || (o.current = !0, (async () => {
|
|
81
81
|
try {
|
|
82
82
|
const r = await e.getUser();
|
|
@@ -97,12 +97,12 @@ const z = [
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
})());
|
|
100
|
-
}, [e]),
|
|
101
|
-
const r = (
|
|
100
|
+
}, [e]), m(() => {
|
|
101
|
+
const r = (d) => {
|
|
102
102
|
n({
|
|
103
|
-
user:
|
|
103
|
+
user: d,
|
|
104
104
|
isLoading: !1,
|
|
105
|
-
isAuthenticated: !
|
|
105
|
+
isAuthenticated: !d.expired,
|
|
106
106
|
isError: !1,
|
|
107
107
|
error: null
|
|
108
108
|
});
|
|
@@ -116,19 +116,19 @@ const z = [
|
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
e.events.addUserUnloaded(u);
|
|
119
|
-
const
|
|
119
|
+
const p = (d) => {
|
|
120
120
|
n({
|
|
121
121
|
...s,
|
|
122
122
|
isLoading: !1,
|
|
123
123
|
isError: !0,
|
|
124
|
-
error:
|
|
124
|
+
error: d
|
|
125
125
|
});
|
|
126
126
|
};
|
|
127
|
-
return e.events.addSilentRenewError(
|
|
128
|
-
e.events.removeUserLoaded(r), e.events.removeUserUnloaded(u), e.events.removeSilentRenewError(
|
|
127
|
+
return e.events.addSilentRenewError(p), () => {
|
|
128
|
+
e.events.removeUserLoaded(r), e.events.removeUserUnloaded(u), e.events.removeSilentRenewError(p);
|
|
129
129
|
};
|
|
130
130
|
}, [e]);
|
|
131
|
-
const a =
|
|
131
|
+
const a = C(async () => {
|
|
132
132
|
const r = await e.signinCallback();
|
|
133
133
|
return n({
|
|
134
134
|
user: r ?? null,
|
|
@@ -137,49 +137,59 @@ const z = [
|
|
|
137
137
|
isError: !1,
|
|
138
138
|
error: null
|
|
139
139
|
}), r ?? void 0;
|
|
140
|
-
}, [e]), i =
|
|
140
|
+
}, [e]), i = C(
|
|
141
|
+
async (r) => {
|
|
142
|
+
try {
|
|
143
|
+
window.self !== window.top ? await e.signinPopup(r) : await e.signinRedirect(r);
|
|
144
|
+
} catch (u) {
|
|
145
|
+
console.error(u);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
[e]
|
|
149
|
+
), l = C(
|
|
141
150
|
async (r) => {
|
|
142
151
|
try {
|
|
143
|
-
await e.
|
|
152
|
+
await e.signoutRedirect(r);
|
|
144
153
|
} catch (u) {
|
|
145
154
|
console.error(u);
|
|
146
155
|
}
|
|
147
156
|
},
|
|
148
157
|
[e]
|
|
149
|
-
),
|
|
158
|
+
), f = x(
|
|
150
159
|
() => ({
|
|
151
160
|
state: s,
|
|
152
161
|
handleSigninCallback: a,
|
|
153
|
-
redirectToSignin: i
|
|
162
|
+
redirectToSignin: i,
|
|
163
|
+
logout: l
|
|
154
164
|
}),
|
|
155
|
-
[s, a, i]
|
|
165
|
+
[s, a, i, l]
|
|
156
166
|
);
|
|
157
|
-
return /* @__PURE__ */
|
|
158
|
-
},
|
|
159
|
-
const t =
|
|
167
|
+
return /* @__PURE__ */ A(t.Provider, { value: f, children: c });
|
|
168
|
+
}, h = (e) => {
|
|
169
|
+
const t = w(e);
|
|
160
170
|
if (!t)
|
|
161
171
|
throw new Error("useAuthContext must be used within an AuthProvider");
|
|
162
172
|
return t;
|
|
163
|
-
},
|
|
164
|
-
const { state: t } =
|
|
173
|
+
}, R = (e) => {
|
|
174
|
+
const { state: t } = h(e);
|
|
165
175
|
return t;
|
|
166
|
-
},
|
|
167
|
-
const { state: c, handleSigninCallback: s } =
|
|
168
|
-
return
|
|
176
|
+
}, b = (e, t) => {
|
|
177
|
+
const { state: c, handleSigninCallback: s } = h(e), n = v(!1);
|
|
178
|
+
return m(() => {
|
|
169
179
|
n.current || (n.current = !0, s().then(
|
|
170
180
|
(o) => new Promise(
|
|
171
181
|
(a) => setTimeout(() => a(o), 0)
|
|
172
182
|
)
|
|
173
183
|
).then((o) => t == null ? void 0 : t(o)));
|
|
174
184
|
}, [s]), c;
|
|
175
|
-
},
|
|
185
|
+
}, K = (e) => {
|
|
176
186
|
const t = S(null);
|
|
177
187
|
return {
|
|
178
188
|
AuthContext: t,
|
|
179
|
-
AuthProvider: ({ children: i }) => /* @__PURE__ */
|
|
180
|
-
useAuthContext: () =>
|
|
181
|
-
useAuthState: () =>
|
|
182
|
-
useSigninCallback: (i) =>
|
|
189
|
+
AuthProvider: ({ children: i }) => /* @__PURE__ */ A(P, { userManager: e, context: t, children: i }),
|
|
190
|
+
useAuthContext: () => h(t),
|
|
191
|
+
useAuthState: () => R(t),
|
|
192
|
+
useSigninCallback: (i) => b(t, i),
|
|
183
193
|
getAccessToken: async () => {
|
|
184
194
|
const i = await e.getUser();
|
|
185
195
|
return i ? i.access_token : null;
|
|
@@ -187,12 +197,12 @@ const z = [
|
|
|
187
197
|
};
|
|
188
198
|
};
|
|
189
199
|
export {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
|
198
208
|
};
|