@wssto2/vue-core 0.5.0 → 0.5.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 (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/{AccessGate.vue_vue_type_script_setup_true_lang-Nw1IsB8N.js → AccessGate.vue_vue_type_script_setup_true_lang-DZ9GcLC1.js} +1 -1
  3. package/dist/{Activity-CoGI2_GL.js → Activity-dpY2kIs2.js} +2 -2
  4. package/dist/{Changes-Cwfe6wbX.js → Changes-CL8F1w8q.js} +2 -2
  5. package/dist/{CollectionPage.vue_vue_type_script_setup_true_lang-CtvHtFLy.js → CollectionPage.vue_vue_type_script_setup_true_lang-l-e-6WeS.js} +1 -1
  6. package/dist/{DeadLetters-DyA5Dqn0.js → DeadLetters-BZLyL5lR.js} +4 -4
  7. package/dist/{General-DTEfxWls.js → General-mrVzi-5R.js} +2 -2
  8. package/dist/{NewRolePage-CRZoUajV.js → NewRolePage-B2DItwvf.js} +2 -2
  9. package/dist/{ProfilePage-DLY81mvN.js → ProfilePage-EiTIYzZ5.js} +2 -2
  10. package/dist/{RoleEditor.vue_vue_type_script_setup_true_lang-gXbxXG2R.js → RoleEditor.vue_vue_type_script_setup_true_lang-BqqilJGF.js} +2 -2
  11. package/dist/{RolePage-B9t586Q8.js → RolePage-jMHAt9y8.js} +3 -3
  12. package/dist/{RolesPage-BRdG-OSL.js → RolesPage-B9GaVQBx.js} +2 -2
  13. package/dist/{SectionNavigator.vue_vue_type_script_setup_true_lang-Cy9Oi0ts.js → SectionNavigator.vue_vue_type_script_setup_true_lang-Ci04hApd.js} +1 -1
  14. package/dist/{Sessions-vGyUOnPG.js → Sessions-CHLokZ9e.js} +2 -2
  15. package/dist/{SettingsPage-V8WeADZZ.js → SettingsPage-CudoKdXm.js} +2 -2
  16. package/dist/{SignIn-C-3i8RG6.js → SignIn-ypRvdmjg.js} +2 -2
  17. package/dist/{SignInPage-D2NA3VKU.js → SignInPage-CbPeKlAo.js} +2 -2
  18. package/dist/{SignIns-eoYPB6kB.js → SignIns-BApzbGq-.js} +2 -2
  19. package/dist/{UserRecord-BaQl2zzQ.js → UserRecord-BCTaBajE.js} +5 -5
  20. package/dist/{UsersList-BfXWgH5K.js → UsersList-CqSK3cQL.js} +4 -4
  21. package/dist/access/index.js +1 -1
  22. package/dist/app/index.js +117 -115
  23. package/dist/app/keepAlive.d.ts +4 -8
  24. package/dist/collection/index.js +3 -3
  25. package/dist/{contributions-DVQPcjJz.js → contributions-fx5q5n1u.js} +1 -1
  26. package/dist/{guards-DRh4zmxO.js → guards-D4mXf_2X.js} +1 -1
  27. package/dist/{http-D_pBg22D.js → http-CdQowFlW.js} +1 -1
  28. package/dist/identity/index.d.ts +1 -1
  29. package/dist/identity/index.js +6 -7
  30. package/dist/identity/session.d.ts +10 -7
  31. package/dist/{index-g-qbUeTk.js → index-BTRv8mcf.js} +3 -3
  32. package/dist/{index-WkbzC_ee.js → index-VPzJJN6Z.js} +5 -5
  33. package/dist/{index-kqk7Mclb.js → index-auJqVMWC.js} +90 -92
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/keepAlive-z3IRFkQq.js +46 -0
  37. package/dist/{navigation-DuQwti76.js → navigation-Bc5EQ_Si.js} +1 -1
  38. package/dist/{neighbors-IMRQ4rkm.js → neighbors-Bv6vnWlW.js} +1 -1
  39. package/dist/notifications/index.js +1 -1
  40. package/dist/page/index.js +1 -1
  41. package/dist/platform/index.js +3 -3
  42. package/dist/platform/platform.d.ts +7 -2
  43. package/dist/platform/session.d.ts +17 -0
  44. package/dist/platform-Dx6STiwY.js +283 -0
  45. package/dist/router/index.js +3 -3
  46. package/dist/{sections-D5rgQ4YB.js → sections-B0HxIOC2.js} +1 -1
  47. package/dist/shell/index.js +3 -3
  48. package/dist/{status-C2gHqkj6.js → status-BUFELJz2.js} +2 -2
  49. package/dist/testing/index.js +1 -1
  50. package/package.json +1 -1
  51. package/dist/keepAlive-CDvMQlcJ.js +0 -49
  52. package/dist/platform-Dl1fbScN.js +0 -268
@@ -0,0 +1,283 @@
1
+ import { c as U } from "./client-BHPFfBj3.js";
2
+ import { d as _ } from "./context-Ch1r4fdN.js";
3
+ import { i as A, A as z } from "./error-Bb_dr_Ay.js";
4
+ import { shallowRef as C } from "vue";
5
+ const I = (e, t) => e.level === t.level && e.id === t.id, T = (e, t) => Object.prototype.hasOwnProperty.call(e, t);
6
+ function N(e, t = {}) {
7
+ const n = t.covers ?? I;
8
+ function o(s) {
9
+ const r = e();
10
+ return !r || !T(r.permissions, s) || r.unavailable.includes(s) ? null : r.permissions[s] ?? null;
11
+ }
12
+ function i(s, r) {
13
+ const c = o(s);
14
+ return c ? r ? (c.clauses.length > 0 ? c.clauses.map((f) => f.scope) : [c.scope]).some((f) => n(f, r)) : !0 : !1;
15
+ }
16
+ return {
17
+ get root() {
18
+ return e()?.root ?? !1;
19
+ },
20
+ can: i,
21
+ canAny: (s) => s.some((r) => i(r)),
22
+ canAll: (s) => s.every((r) => i(r)),
23
+ held: o
24
+ };
25
+ }
26
+ const $ = ["own", "own_location", "all"], y = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
27
+ function S(e, t, n) {
28
+ return !y(e) || typeof e.level != "string" ? (n.push(`${t}: expected { level: string, id?: number }`), { level: "" }) : (e.id !== void 0 && typeof e.id != "number" && n.push(`${t}.id: expected number`), typeof e.id == "number" ? { level: e.level, id: e.id } : { level: e.level });
29
+ }
30
+ function O(e, t, n) {
31
+ return typeof e == "string" && $.includes(e) ? e : (n.push(`${t}: expected one of ${$.join(", ")}`), "own");
32
+ }
33
+ function B(e) {
34
+ const t = [], n = {}, o = { root: !1, permissions: {}, unavailable: [] };
35
+ if (!y(e)) return { snapshot: o, issues: ["access: expected an object"] };
36
+ if (!y(e.permissions)) t.push("access.permissions: expected an object");
37
+ else
38
+ for (const [s, r] of Object.entries(e.permissions)) {
39
+ const c = `access.permissions.${s}`;
40
+ if (!y(r)) {
41
+ t.push(`${c}: expected an object`);
42
+ continue;
43
+ }
44
+ const a = (Array.isArray(r.clauses) ? r.clauses : []).map((f, b) => {
45
+ const h = `${c}.clauses[${b}]`;
46
+ if (!y(f))
47
+ return t.push(`${h}: expected an object`), { scope: { level: "" }, qualifier: "own" };
48
+ const d = { scope: S(f.scope, `${h}.scope`, t), qualifier: O(f.qualifier, `${h}.qualifier`, t) };
49
+ return typeof f.role == "string" ? { ...d, role: f.role } : d;
50
+ });
51
+ n[s] = {
52
+ scope: S(r.scope, `${c}.scope`, t),
53
+ qualifier: O(r.qualifier, `${c}.qualifier`, t),
54
+ clauses: a
55
+ };
56
+ }
57
+ const i = e.unavailable ?? [];
58
+ return (!Array.isArray(i) || !i.every((s) => typeof s == "string")) && t.push("access.unavailable: expected an array of strings"), {
59
+ snapshot: {
60
+ root: e.root === !0,
61
+ permissions: n,
62
+ unavailable: Array.isArray(i) ? i.filter((s) => typeof s == "string") : []
63
+ },
64
+ issues: t
65
+ };
66
+ }
67
+ const F = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
68
+ function P(e, t, n = "navigation") {
69
+ return Array.isArray(e) ? e.flatMap((o, i) => {
70
+ const s = `${n}[${i}]`;
71
+ if (!F(o) || typeof o.i18n != "string")
72
+ return t.push(`${s}: expected an object with an i18n key`), [];
73
+ for (const c of ["icon", "route"])
74
+ o[c] != null && typeof o[c] != "string" && t.push(`${s}.${c}: expected a string`);
75
+ const r = o.children == null ? void 0 : P(o.children, t, `${s}.children`);
76
+ return [
77
+ {
78
+ i18n: o.i18n,
79
+ ...typeof o.icon == "string" && { icon: o.icon },
80
+ ...typeof o.route == "string" && { route: o.route },
81
+ ...r && { children: r }
82
+ }
83
+ ];
84
+ }) : (t.push(`${n}: expected an array`), []);
85
+ }
86
+ const w = (e) => typeof e == "object" && e !== null && !Array.isArray(e), H = (e) => {
87
+ if (w(e) && (typeof e.id == "number" || typeof e.id == "string")) return { id: e.id };
88
+ throw new TypeError("expected an object with a numeric or string id");
89
+ };
90
+ function Q(e, t = H) {
91
+ const n = [];
92
+ if (!w(e)) throw j(["expected an object"]);
93
+ let o = null;
94
+ try {
95
+ o = t(e.user);
96
+ } catch (a) {
97
+ n.push(`user: ${a instanceof Error ? a.message : "invalid"}`);
98
+ }
99
+ let i = null;
100
+ if (e.expires_at !== void 0 && e.expires_at !== null) {
101
+ const a = typeof e.expires_at == "string" ? new Date(e.expires_at) : null;
102
+ a === null || Number.isNaN(a.getTime()) ? n.push("expires_at: expected an ISO date-time string") : i = a;
103
+ }
104
+ let s;
105
+ if (e.impersonator !== void 0 && e.impersonator !== null) {
106
+ const a = e.impersonator;
107
+ w(a) && (typeof a.id == "number" || typeof a.id == "string") && typeof a.name == "string" ? s = { id: a.id, name: a.name } : n.push("impersonator: expected { id, name }");
108
+ }
109
+ const r = B(e.access);
110
+ n.push(...r.issues);
111
+ const c = e.navigation === void 0 || e.navigation === null ? void 0 : P(e.navigation, n);
112
+ if (o === null || n.length > 0) throw j(n);
113
+ return { user: o, expiresAt: i, access: r.snapshot, ...s && { impersonator: s }, ...c && { navigation: c } };
114
+ }
115
+ const j = (e) => new z({ kind: "malformed", message: `Unreadable session payload: ${e.join("; ")}` });
116
+ function R(e, t = {}) {
117
+ const { mePath: n = "/auth/me", signOutPath: o = "/auth/logout", parseUser: i } = t;
118
+ return {
119
+ async load(s) {
120
+ try {
121
+ const { data: r } = await e.get(n, { signal: s, handleUnauthorized: !1 });
122
+ return Q(r, i);
123
+ } catch (r) {
124
+ if (A(r) && r.kind === "unauthorized") return null;
125
+ throw r;
126
+ }
127
+ },
128
+ async signOut() {
129
+ try {
130
+ await e.post(o, void 0, { handleUnauthorized: !1 });
131
+ } catch (s) {
132
+ if (!(A(s) && s.kind === "unauthorized")) throw s;
133
+ }
134
+ }
135
+ };
136
+ }
137
+ function k(e) {
138
+ return e.status === "authenticated" ? e : e.status === "anonymous" && e.reason === "expired" ? e.previous ?? null : null;
139
+ }
140
+ const E = 3e3;
141
+ function D(e, t = {}) {
142
+ const n = C({ status: "unknown" });
143
+ let o = 0;
144
+ const i = new Set(t.beforeSignOut ? [t.beforeSignOut] : []);
145
+ let s = !1, r = null, c = null, a = null;
146
+ function f() {
147
+ o++, a?.controller.abort(), a = null;
148
+ }
149
+ async function b(u) {
150
+ const l = new AbortController();
151
+ let g;
152
+ const v = new Promise((m) => {
153
+ g = setTimeout(() => {
154
+ l.abort(), t.onError?.(new Error(`A before-sign-out hook did not finish within ${E} ms; signing out without it.`)), m();
155
+ }, E);
156
+ }), x = Promise.all(
157
+ [...i].map(async (m) => {
158
+ try {
159
+ await m(u, l.signal);
160
+ } catch (p) {
161
+ t.onError?.(p);
162
+ }
163
+ })
164
+ ).then(() => {
165
+ });
166
+ await Promise.race([x, v]), clearTimeout(g);
167
+ }
168
+ function h() {
169
+ if (a) return a.promise;
170
+ const u = o, l = new AbortController(), g = n.value, v = k(g) !== null;
171
+ v || (n.value = { status: "loading" });
172
+ const x = async () => {
173
+ try {
174
+ const p = await e.load(l.signal);
175
+ if (o !== u) return n.value;
176
+ n.value = p ? { status: "authenticated", ...p } : { status: "anonymous", reason: "none" };
177
+ } catch (p) {
178
+ if (o !== u) return n.value;
179
+ t.onError?.(p), n.value = v ? g : { status: "failed", error: p };
180
+ } finally {
181
+ o === u && (a = null);
182
+ }
183
+ return n.value;
184
+ }, m = Promise.resolve().then(x);
185
+ return a = { controller: l, promise: m }, m;
186
+ }
187
+ const d = {
188
+ state: n,
189
+ restore: () => n.value.status === "unknown" || n.value.status === "failed" ? h() : a?.promise ?? Promise.resolve(n.value),
190
+ refresh: h,
191
+ establish(u) {
192
+ f(), n.value = { status: "authenticated", ...u };
193
+ },
194
+ update(u) {
195
+ const l = n.value;
196
+ if (l.status === "authenticated") {
197
+ if (u.user && u.user.id !== l.user.id)
198
+ throw new Error(`session.update cannot change who is signed in (user ${String(l.user.id)} to ${String(u.user.id)}); use session.establish for a different person.`);
199
+ n.value = {
200
+ ...l,
201
+ user: u.user ?? l.user,
202
+ access: u.access ?? l.access,
203
+ ...(u.navigation ?? l.navigation) && { navigation: u.navigation ?? l.navigation }
204
+ };
205
+ }
206
+ },
207
+ expire() {
208
+ if (n.value.status !== "authenticated") return;
209
+ const { status: u, ...l } = n.value;
210
+ f(), n.value = s && !n.value.impersonator ? { status: "anonymous", reason: "expired", previous: l } : { status: "anonymous", reason: "expired" }, t.onExpired?.();
211
+ },
212
+ signOut() {
213
+ return r ?? (r = (async () => {
214
+ try {
215
+ const u = n.value;
216
+ u.status === "authenticated" && i.size > 0 && await b(u.user), f(), n.value = { status: "anonymous", reason: "signedOut" }, await e.signOut();
217
+ } finally {
218
+ r = null;
219
+ }
220
+ })()), r;
221
+ },
222
+ get renewable() {
223
+ return t.renew !== void 0 && (t.renewable?.() ?? !0);
224
+ },
225
+ renew() {
226
+ return n.value.status !== "authenticated" ? Promise.resolve(!1) : (c ?? (c = (async () => {
227
+ try {
228
+ if (d.renewable && await t.renew(d)) return !0;
229
+ } catch {
230
+ }
231
+ return d.expire(), !1;
232
+ })().finally(() => {
233
+ c = null;
234
+ })), c);
235
+ },
236
+ holdExpired(u) {
237
+ s = u;
238
+ },
239
+ onBeforeSignOut(u) {
240
+ return i.add(u), () => void i.delete(u);
241
+ }
242
+ };
243
+ return d;
244
+ }
245
+ function V(e) {
246
+ const t = U({
247
+ baseUrl: e.config.apiBase,
248
+ transport: e.transport,
249
+ headers: e.headers,
250
+ credentials: e.credentials,
251
+ requestId: e.requestId,
252
+ async onUnauthorized() {
253
+ return await i.renew() ? "retry" : "fail";
254
+ }
255
+ }), n = e.session ?? ((r) => R(r)), o = typeof n == "function" ? n(t) : n, i = D(o, {
256
+ onError: e.onSessionError,
257
+ onExpired: e.onSessionExpired,
258
+ beforeSignOut: e.beforeSignOut,
259
+ renew: e.renewSession && ((r) => e.renewSession(r, t)),
260
+ renewable: e.renewable
261
+ }), s = N(
262
+ () => k(i.state.value)?.access ?? null,
263
+ { covers: e.covers }
264
+ );
265
+ return { config: e.config, http: t, session: i, access: s };
266
+ }
267
+ const q = _("platform"), K = q[0], W = q[1];
268
+ function X(e, t) {
269
+ e.provide(K, t);
270
+ }
271
+ export {
272
+ V as a,
273
+ E as b,
274
+ N as c,
275
+ D as d,
276
+ R as e,
277
+ Q as f,
278
+ K as g,
279
+ k as h,
280
+ X as i,
281
+ P as p,
282
+ W as u
283
+ };
@@ -1,9 +1,9 @@
1
1
  import { _ as a, c as o, a as r, i as t } from "../NoAccess.vue_vue_type_script_setup_true_lang-DWxq-MTM.js";
2
2
  import { d as c } from "../defineRoutes-BGAdiIrt.js";
3
3
  import { A as u, f as p, i as f, r as A, u as m } from "../access-DmAceEo5.js";
4
- import { i as l, r as x } from "../guards-DRh4zmxO.js";
5
- import { u as y } from "../sections-D5rgQ4YB.js";
6
- import { b as v, c as N, n as H, u as b } from "../navigation-DuQwti76.js";
4
+ import { i as l, r as x } from "../guards-D4mXf_2X.js";
5
+ import { u as y } from "../sections-B0HxIOC2.js";
6
+ import { b as v, c as N, n as H, u as b } from "../navigation-Bc5EQ_Si.js";
7
7
  export {
8
8
  u as AppRouterView,
9
9
  a as NoAccess,
@@ -1,7 +1,7 @@
1
1
  import { computed as n, watch as h } from "vue";
2
2
  import { useI18n as b } from "vue-i18n";
3
3
  import { useRoute as g, useRouter as p } from "vue-router";
4
- import { u as y } from "./platform-Dl1fbScN.js";
4
+ import { u as y } from "./platform-Dx6STiwY.js";
5
5
  import { i as w } from "./access-DmAceEo5.js";
6
6
  function j() {
7
7
  const t = g(), u = p(), { access: c } = y(), { t: r } = b(), i = n(() => {
@@ -3,12 +3,12 @@ import { useI18n as B } from "vue-i18n";
3
3
  import { _ as we } from "../Avatar.vue_vue_type_script_setup_true_lang-BPj_fkJR.js";
4
4
  import { _ as P, u as Xe, c as Ue } from "../Icon.vue_vue_type_script_lang-D7oC-d-S.js";
5
5
  import { _ as We } from "../Popover.vue_vue_type_script_setup_true_lang-C70GrCP7.js";
6
- import { u as xe, S as X } from "../contributions-DVQPcjJz.js";
6
+ import { u as xe, S as X } from "../contributions-fx5q5n1u.js";
7
7
  import { u as Ye } from "../environment-Dva-SG8D.js";
8
8
  import { _ as He } from "../CountryFlag.vue_vue_type_script_setup_true_lang-Kry_vPPZ.js";
9
9
  import { l as pe } from "../languageName-CItV_SOv.js";
10
10
  import { t as _e } from "../toast-CqSDTWRX.js";
11
- import { u as J, h as ue } from "../platform-Dl1fbScN.js";
11
+ import { u as J, h as ue } from "../platform-Dx6STiwY.js";
12
12
  import { a as qe, _ as ve, h as ke } from "../AccountMenuItem.vue_vue_type_script_setup_true_lang-CPeNxh5K.js";
13
13
  import { _ as Ge } from "../Sheet.vue_vue_type_script_setup_true_lang-DgOFV4fa.js";
14
14
  import { _ as Qe } from "../LeaveGuardRoot.vue_vue_type_script_setup_true_lang-Cv7KlA5y.js";
@@ -17,7 +17,7 @@ import { _ as Ze } from "../BottomDock.vue_vue_type_script_setup_true_lang-CjN7x
17
17
  import { b as $e } from "../chrome-nUcmVu8G.js";
18
18
  import { p as Se, A as et } from "../access-DmAceEo5.js";
19
19
  import { RouterLink as Le, useRoute as tt, useRouter as de } from "vue-router";
20
- import { u as nt } from "../navigation-DuQwti76.js";
20
+ import { u as nt } from "../navigation-Bc5EQ_Si.js";
21
21
  import { u as at } from "../leaveGuard-Cc8yeLxM.js";
22
22
  import { u as ot, S as st } from "../dialogStack-DZZg55w0.js";
23
23
  import { a as H } from "../mediaQuery-CygcXmFW.js";
@@ -1,5 +1,5 @@
1
- import { a, r as o } from "./http-D_pBg22D.js";
2
- import { i as r } from "./index-kqk7Mclb.js";
1
+ import { a, r as o } from "./http-CdQowFlW.js";
2
+ import { i as r } from "./index-auJqVMWC.js";
3
3
  const n = ["active", "locked", "inactive", "all"];
4
4
  function l(i) {
5
5
  return a({
@@ -1,6 +1,6 @@
1
1
  import { nextTick as b, createApp as j, defineComponent as m, h as u } from "vue";
2
2
  import { createMemoryHistory as P, createRouter as E, RouterView as $ } from "vue-router";
3
- import { a as A, i as O } from "../platform-Dl1fbScN.js";
3
+ import { a as A, i as O } from "../platform-Dx6STiwY.js";
4
4
  import { createI18n as k } from "vue-i18n";
5
5
  import { coreMessages as M } from "../i18n/index.js";
6
6
  import { i as R, c as S } from "../format-D8X4zsx6.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wssto2/vue-core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "goCore": "v1.8.0",
5
5
  "description": "Shared Vue 3 library for go-core applications: app shell, list / record / form pages and their controls.",
6
6
  "keywords": [
@@ -1,49 +0,0 @@
1
- function w(a = {}) {
2
- const { margin: v = 6e4, retryAfter: h = 3e4 } = a;
3
- return {
4
- id: "vue-core.keep-session-alive",
5
- scope: "session",
6
- start({ signal: i, platform: t, report: f }) {
7
- let s, r = null;
8
- const o = () => {
9
- const e = t.session.state.value;
10
- return e.status === "authenticated" && e.expiresAt ? e.expiresAt.getTime() - Date.now() - v : null;
11
- }, m = () => (r ?? (r = (async () => {
12
- try {
13
- if (await a.renew?.(t), t.session.state.value.status !== "authenticated") return;
14
- await t.session.refresh();
15
- } catch (e) {
16
- f(e);
17
- } finally {
18
- r = null;
19
- }
20
- })()), r);
21
- function u(e = 0) {
22
- clearTimeout(s);
23
- const d = o();
24
- d !== null && !i.aborted && (s = setTimeout(() => void n(), Math.min(Math.max(d, e), 864e5)));
25
- }
26
- async function n() {
27
- if (i.aborted || !navigator.onLine) return;
28
- const e = o();
29
- if (e !== null) {
30
- if (e <= 0) {
31
- if (await m(), i.aborted) return;
32
- u((o() ?? 1) <= 0 ? h : 0);
33
- return;
34
- }
35
- u();
36
- }
37
- }
38
- const c = () => {
39
- document.visibilityState === "visible" && n();
40
- }, l = () => void n();
41
- return document.addEventListener("visibilitychange", c), window.addEventListener("online", l), n(), () => {
42
- clearTimeout(s), document.removeEventListener("visibilitychange", c), window.removeEventListener("online", l);
43
- };
44
- }
45
- };
46
- }
47
- export {
48
- w as k
49
- };
@@ -1,268 +0,0 @@
1
- import { c as k } from "./client-BHPFfBj3.js";
2
- import { d as q } from "./context-Ch1r4fdN.js";
3
- import { i as x, A as U } from "./error-Bb_dr_Ay.js";
4
- import { shallowRef as _ } from "vue";
5
- const z = (e, n) => e.level === n.level && e.id === n.id, C = (e, n) => Object.prototype.hasOwnProperty.call(e, n);
6
- function I(e, n = {}) {
7
- const t = n.covers ?? z;
8
- function o(s) {
9
- const r = e();
10
- return !r || !C(r.permissions, s) || r.unavailable.includes(s) ? null : r.permissions[s] ?? null;
11
- }
12
- function u(s, r) {
13
- const i = o(s);
14
- return i ? r ? (i.clauses.length > 0 ? i.clauses.map((f) => f.scope) : [i.scope]).some((f) => t(f, r)) : !0 : !1;
15
- }
16
- return {
17
- get root() {
18
- return e()?.root ?? !1;
19
- },
20
- can: u,
21
- canAny: (s) => s.some((r) => u(r)),
22
- canAll: (s) => s.every((r) => u(r)),
23
- held: o
24
- };
25
- }
26
- const A = ["own", "own_location", "all"], m = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
27
- function $(e, n, t) {
28
- return !m(e) || typeof e.level != "string" ? (t.push(`${n}: expected { level: string, id?: number }`), { level: "" }) : (e.id !== void 0 && typeof e.id != "number" && t.push(`${n}.id: expected number`), typeof e.id == "number" ? { level: e.level, id: e.id } : { level: e.level });
29
- }
30
- function S(e, n, t) {
31
- return typeof e == "string" && A.includes(e) ? e : (t.push(`${n}: expected one of ${A.join(", ")}`), "own");
32
- }
33
- function T(e) {
34
- const n = [], t = {}, o = { root: !1, permissions: {}, unavailable: [] };
35
- if (!m(e)) return { snapshot: o, issues: ["access: expected an object"] };
36
- if (!m(e.permissions)) n.push("access.permissions: expected an object");
37
- else
38
- for (const [s, r] of Object.entries(e.permissions)) {
39
- const i = `access.permissions.${s}`;
40
- if (!m(r)) {
41
- n.push(`${i}: expected an object`);
42
- continue;
43
- }
44
- const c = (Array.isArray(r.clauses) ? r.clauses : []).map((f, g) => {
45
- const a = `${i}.clauses[${g}]`;
46
- if (!m(f))
47
- return n.push(`${a}: expected an object`), { scope: { level: "" }, qualifier: "own" };
48
- const l = { scope: $(f.scope, `${a}.scope`, n), qualifier: S(f.qualifier, `${a}.qualifier`, n) };
49
- return typeof f.role == "string" ? { ...l, role: f.role } : l;
50
- });
51
- t[s] = {
52
- scope: $(r.scope, `${i}.scope`, n),
53
- qualifier: S(r.qualifier, `${i}.qualifier`, n),
54
- clauses: c
55
- };
56
- }
57
- const u = e.unavailable ?? [];
58
- return (!Array.isArray(u) || !u.every((s) => typeof s == "string")) && n.push("access.unavailable: expected an array of strings"), {
59
- snapshot: {
60
- root: e.root === !0,
61
- permissions: t,
62
- unavailable: Array.isArray(u) ? u.filter((s) => typeof s == "string") : []
63
- },
64
- issues: n
65
- };
66
- }
67
- const N = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
68
- function j(e, n, t = "navigation") {
69
- return Array.isArray(e) ? e.flatMap((o, u) => {
70
- const s = `${t}[${u}]`;
71
- if (!N(o) || typeof o.i18n != "string")
72
- return n.push(`${s}: expected an object with an i18n key`), [];
73
- for (const i of ["icon", "route"])
74
- o[i] != null && typeof o[i] != "string" && n.push(`${s}.${i}: expected a string`);
75
- const r = o.children == null ? void 0 : j(o.children, n, `${s}.children`);
76
- return [
77
- {
78
- i18n: o.i18n,
79
- ...typeof o.icon == "string" && { icon: o.icon },
80
- ...typeof o.route == "string" && { route: o.route },
81
- ...r && { children: r }
82
- }
83
- ];
84
- }) : (n.push(`${t}: expected an array`), []);
85
- }
86
- const b = (e) => typeof e == "object" && e !== null && !Array.isArray(e), B = (e) => {
87
- if (b(e) && (typeof e.id == "number" || typeof e.id == "string")) return { id: e.id };
88
- throw new TypeError("expected an object with a numeric or string id");
89
- };
90
- function F(e, n = B) {
91
- const t = [];
92
- if (!b(e)) throw w(["expected an object"]);
93
- let o = null;
94
- try {
95
- o = n(e.user);
96
- } catch (c) {
97
- t.push(`user: ${c instanceof Error ? c.message : "invalid"}`);
98
- }
99
- let u = null;
100
- if (e.expires_at !== void 0 && e.expires_at !== null) {
101
- const c = typeof e.expires_at == "string" ? new Date(e.expires_at) : null;
102
- c === null || Number.isNaN(c.getTime()) ? t.push("expires_at: expected an ISO date-time string") : u = c;
103
- }
104
- let s;
105
- if (e.impersonator !== void 0 && e.impersonator !== null) {
106
- const c = e.impersonator;
107
- b(c) && (typeof c.id == "number" || typeof c.id == "string") && typeof c.name == "string" ? s = { id: c.id, name: c.name } : t.push("impersonator: expected { id, name }");
108
- }
109
- const r = T(e.access);
110
- t.push(...r.issues);
111
- const i = e.navigation === void 0 || e.navigation === null ? void 0 : j(e.navigation, t);
112
- if (o === null || t.length > 0) throw w(t);
113
- return { user: o, expiresAt: u, access: r.snapshot, ...s && { impersonator: s }, ...i && { navigation: i } };
114
- }
115
- const w = (e) => new U({ kind: "malformed", message: `Unreadable session payload: ${e.join("; ")}` });
116
- function H(e, n = {}) {
117
- const { mePath: t = "/auth/me", signOutPath: o = "/auth/logout", parseUser: u } = n;
118
- return {
119
- async load(s) {
120
- try {
121
- const { data: r } = await e.get(t, { signal: s, handleUnauthorized: !1 });
122
- return F(r, u);
123
- } catch (r) {
124
- if (x(r) && r.kind === "unauthorized") return null;
125
- throw r;
126
- }
127
- },
128
- async signOut() {
129
- try {
130
- await e.post(o, void 0, { handleUnauthorized: !1 });
131
- } catch (s) {
132
- if (!(x(s) && s.kind === "unauthorized")) throw s;
133
- }
134
- }
135
- };
136
- }
137
- function E(e) {
138
- return e.status === "authenticated" ? e : e.status === "anonymous" && e.reason === "expired" ? e.previous ?? null : null;
139
- }
140
- const O = 3e3;
141
- function Q(e, n = {}) {
142
- const t = _({ status: "unknown" });
143
- let o = 0;
144
- const u = new Set(n.beforeSignOut ? [n.beforeSignOut] : []);
145
- let s = !1, r = null, i = null;
146
- function c() {
147
- o++, i?.controller.abort(), i = null;
148
- }
149
- async function f(a) {
150
- const l = new AbortController();
151
- let h;
152
- const y = new Promise((p) => {
153
- h = setTimeout(() => {
154
- l.abort(), n.onError?.(new Error(`A before-sign-out hook did not finish within ${O} ms; signing out without it.`)), p();
155
- }, O);
156
- }), v = Promise.all(
157
- [...u].map(async (p) => {
158
- try {
159
- await p(a, l.signal);
160
- } catch (d) {
161
- n.onError?.(d);
162
- }
163
- })
164
- ).then(() => {
165
- });
166
- await Promise.race([v, y]), clearTimeout(h);
167
- }
168
- function g() {
169
- if (i) return i.promise;
170
- const a = o, l = new AbortController(), h = t.value, y = E(h) !== null;
171
- y || (t.value = { status: "loading" });
172
- const v = async () => {
173
- try {
174
- const d = await e.load(l.signal);
175
- if (o !== a) return t.value;
176
- t.value = d ? { status: "authenticated", ...d } : { status: "anonymous", reason: "none" };
177
- } catch (d) {
178
- if (o !== a) return t.value;
179
- n.onError?.(d), t.value = y ? h : { status: "failed", error: d };
180
- } finally {
181
- o === a && (i = null);
182
- }
183
- return t.value;
184
- }, p = Promise.resolve().then(v);
185
- return i = { controller: l, promise: p }, p;
186
- }
187
- return {
188
- state: t,
189
- restore: () => t.value.status === "unknown" || t.value.status === "failed" ? g() : i?.promise ?? Promise.resolve(t.value),
190
- refresh: g,
191
- establish(a) {
192
- c(), t.value = { status: "authenticated", ...a };
193
- },
194
- update(a) {
195
- const l = t.value;
196
- if (l.status === "authenticated") {
197
- if (a.user && a.user.id !== l.user.id)
198
- throw new Error(`session.update cannot change who is signed in (user ${String(l.user.id)} to ${String(a.user.id)}); use session.establish for a different person.`);
199
- t.value = {
200
- ...l,
201
- user: a.user ?? l.user,
202
- access: a.access ?? l.access,
203
- ...(a.navigation ?? l.navigation) && { navigation: a.navigation ?? l.navigation }
204
- };
205
- }
206
- },
207
- expire() {
208
- if (t.value.status !== "authenticated") return;
209
- const { status: a, ...l } = t.value;
210
- c(), t.value = s && !t.value.impersonator ? { status: "anonymous", reason: "expired", previous: l } : { status: "anonymous", reason: "expired" }, n.onExpired?.();
211
- },
212
- signOut() {
213
- return r ?? (r = (async () => {
214
- try {
215
- const a = t.value;
216
- a.status === "authenticated" && u.size > 0 && await f(a.user), c(), t.value = { status: "anonymous", reason: "signedOut" }, await e.signOut();
217
- } finally {
218
- r = null;
219
- }
220
- })()), r;
221
- },
222
- holdExpired(a) {
223
- s = a;
224
- },
225
- onBeforeSignOut(a) {
226
- return u.add(a), () => void u.delete(a);
227
- }
228
- };
229
- }
230
- function G(e) {
231
- let n = null;
232
- const t = k({
233
- baseUrl: e.config.apiBase,
234
- transport: e.transport,
235
- headers: e.headers,
236
- credentials: e.credentials,
237
- requestId: e.requestId,
238
- async onUnauthorized() {
239
- return s.state.value.status !== "authenticated" ? "fail" : e.renewSession && (n ?? (n = e.renewSession(s, t).then(
240
- (i) => i,
241
- () => !1
242
- ).finally(() => {
243
- n = null;
244
- })), await n) ? "retry" : (s.expire(), "fail");
245
- }
246
- }), o = e.session ?? ((i) => H(i)), u = typeof o == "function" ? o(t) : o, s = Q(u, { onError: e.onSessionError, onExpired: e.onSessionExpired, beforeSignOut: e.beforeSignOut }), r = I(
247
- () => E(s.state.value)?.access ?? null,
248
- { covers: e.covers }
249
- );
250
- return { config: e.config, http: t, session: s, access: r };
251
- }
252
- const P = q("platform"), R = P[0], J = P[1];
253
- function V(e, n) {
254
- e.provide(R, n);
255
- }
256
- export {
257
- G as a,
258
- O as b,
259
- I as c,
260
- Q as d,
261
- H as e,
262
- F as f,
263
- R as g,
264
- E as h,
265
- V as i,
266
- j as p,
267
- J as u
268
- };