@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 +134 -101
- package/dist/ui/components/Stack.d.ts +1 -1
- package/package.json +1 -1
package/dist/oidc.es.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
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
|
|
5
|
-
import { jwtDecode as
|
|
6
|
-
const I =
|
|
4
|
+
import L from "use-local-storage-state";
|
|
5
|
+
import { jwtDecode as y } from "jwt-decode";
|
|
6
|
+
const I = x(
|
|
7
7
|
null
|
|
8
|
-
),
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
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
|
|
15
|
-
},
|
|
16
|
-
children:
|
|
14
|
+
return t;
|
|
15
|
+
}, z = ({
|
|
16
|
+
children: t
|
|
17
17
|
}) => {
|
|
18
|
-
const [
|
|
18
|
+
const [e, a] = L("impersonationState", {
|
|
19
19
|
defaultValue: {}
|
|
20
|
-
}), s =
|
|
21
|
-
accessToken:
|
|
22
|
-
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
|
+
a({ accessToken: n, userInfo: o });
|
|
25
25
|
}
|
|
26
26
|
}), []);
|
|
27
|
-
return /* @__PURE__ */
|
|
28
|
-
},
|
|
29
|
-
const { setImpersonation:
|
|
30
|
-
|
|
31
|
-
const { search:
|
|
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 &&
|
|
35
|
-
const n =
|
|
36
|
-
|
|
34
|
+
if (s && e) {
|
|
35
|
+
const n = y(s);
|
|
36
|
+
e(s, n), t();
|
|
37
37
|
}
|
|
38
38
|
}, []);
|
|
39
39
|
};
|
|
40
|
-
function
|
|
41
|
-
return JSON.parse(
|
|
40
|
+
function V(t) {
|
|
41
|
+
return JSON.parse(t).map((s) => {
|
|
42
42
|
const [
|
|
43
43
|
n,
|
|
44
44
|
o,
|
|
45
|
-
|
|
45
|
+
u,
|
|
46
46
|
i,
|
|
47
|
-
|
|
48
|
-
] = s.split("|"),
|
|
47
|
+
d
|
|
48
|
+
] = s.split("|"), m = i.split(",");
|
|
49
49
|
return {
|
|
50
50
|
CustomerExternalId: n,
|
|
51
51
|
CustomerFirmId: o,
|
|
52
|
-
CustomerFirmName:
|
|
53
|
-
CustomerUserRoles:
|
|
54
|
-
CustomerUserIsAdmin:
|
|
52
|
+
CustomerFirmName: u,
|
|
53
|
+
CustomerUserRoles: m,
|
|
54
|
+
CustomerUserIsAdmin: d === "True"
|
|
55
55
|
};
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const J = [
|
|
59
59
|
"97",
|
|
60
60
|
"131",
|
|
61
61
|
"132",
|
|
62
62
|
"141"
|
|
63
|
-
],
|
|
63
|
+
], K = [
|
|
64
64
|
"3"
|
|
65
|
-
],
|
|
65
|
+
], _ = [
|
|
66
66
|
"0"
|
|
67
|
-
],
|
|
68
|
-
userManager:
|
|
69
|
-
context:
|
|
70
|
-
children:
|
|
67
|
+
], g = ({
|
|
68
|
+
userManager: t,
|
|
69
|
+
context: e,
|
|
70
|
+
children: a
|
|
71
71
|
}) => {
|
|
72
|
-
const [s, n] =
|
|
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 =
|
|
79
|
-
|
|
78
|
+
}), o = U(!1);
|
|
79
|
+
h(() => {
|
|
80
80
|
o.current || (o.current = !0, (async () => {
|
|
81
81
|
try {
|
|
82
|
-
const r = await
|
|
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
|
-
}, [
|
|
101
|
-
const r = (
|
|
100
|
+
}, [t]), h(() => {
|
|
101
|
+
const r = (f) => {
|
|
102
102
|
n({
|
|
103
|
-
user:
|
|
103
|
+
user: f,
|
|
104
104
|
isLoading: !1,
|
|
105
|
-
isAuthenticated: !
|
|
105
|
+
isAuthenticated: !f.expired,
|
|
106
106
|
isError: !1,
|
|
107
107
|
error: null
|
|
108
108
|
});
|
|
109
109
|
};
|
|
110
|
-
|
|
111
|
-
const
|
|
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
|
-
|
|
119
|
-
const
|
|
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:
|
|
124
|
+
error: f
|
|
125
125
|
});
|
|
126
126
|
};
|
|
127
|
-
return
|
|
128
|
-
|
|
127
|
+
return t.events.addSilentRenewError(w), () => {
|
|
128
|
+
t.events.removeUserLoaded(r), t.events.removeUserUnloaded(c), t.events.removeSilentRenewError(w);
|
|
129
129
|
};
|
|
130
|
-
}, [
|
|
131
|
-
const
|
|
132
|
-
const r = await
|
|
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
|
-
}, [
|
|
140
|
+
}, [t]), i = l(
|
|
141
141
|
async (r) => {
|
|
142
142
|
try {
|
|
143
|
-
await
|
|
144
|
-
} catch (
|
|
145
|
-
console.error(
|
|
143
|
+
await t.signinRedirect(r);
|
|
144
|
+
} catch (c) {
|
|
145
|
+
console.error(c);
|
|
146
146
|
}
|
|
147
147
|
},
|
|
148
|
-
[
|
|
149
|
-
),
|
|
148
|
+
[t]
|
|
149
|
+
), d = l(
|
|
150
150
|
async (r) => {
|
|
151
151
|
try {
|
|
152
|
-
await
|
|
153
|
-
} catch (
|
|
154
|
-
console.error(
|
|
152
|
+
await t.signinPopup(r);
|
|
153
|
+
} catch (c) {
|
|
154
|
+
console.error(c);
|
|
155
155
|
}
|
|
156
156
|
},
|
|
157
|
-
[
|
|
158
|
-
),
|
|
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:
|
|
185
|
+
handleSigninCallback: u,
|
|
162
186
|
redirectToSignin: i,
|
|
163
|
-
|
|
187
|
+
signinSilent: m,
|
|
188
|
+
signinPopup: d,
|
|
189
|
+
logout: A
|
|
164
190
|
}),
|
|
165
|
-
[
|
|
191
|
+
[
|
|
192
|
+
s,
|
|
193
|
+
u,
|
|
194
|
+
i,
|
|
195
|
+
m,
|
|
196
|
+
d,
|
|
197
|
+
A
|
|
198
|
+
]
|
|
166
199
|
);
|
|
167
|
-
return /* @__PURE__ */
|
|
168
|
-
},
|
|
169
|
-
const
|
|
170
|
-
if (!
|
|
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
|
|
173
|
-
},
|
|
174
|
-
const { state:
|
|
175
|
-
return
|
|
176
|
-
}, b = (
|
|
177
|
-
const { state:
|
|
178
|
-
return
|
|
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
|
-
(
|
|
214
|
+
(u) => setTimeout(() => u(o), 0)
|
|
182
215
|
)
|
|
183
|
-
).then((o) =>
|
|
184
|
-
}, [s]),
|
|
185
|
-
},
|
|
186
|
-
const
|
|
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:
|
|
189
|
-
AuthProvider: ({ children: i }) => /* @__PURE__ */
|
|
190
|
-
useAuthContext: () =>
|
|
191
|
-
useAuthState: () =>
|
|
192
|
-
useSigninCallback: (i) => b(
|
|
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
|
|
227
|
+
const i = await t.getUser();
|
|
195
228
|
return i ? i.access_token : null;
|
|
196
229
|
}
|
|
197
230
|
};
|
|
198
231
|
};
|
|
199
232
|
export {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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 | "
|
|
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";
|