@abraca/junis 2.100.0 → 2.101.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/README.md +25 -0
- package/dist/module.d.mts +14 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +32 -0
- package/dist/runtime/components/JunAccessGate.d.vue.ts +3 -0
- package/dist/runtime/components/JunAccessGate.vue +146 -0
- package/dist/runtime/components/JunAccessGate.vue.d.ts +3 -0
- package/dist/runtime/components/JunServiceCard.vue +2 -0
- package/dist/runtime/components/JunShell.vue +2 -0
- package/dist/runtime/components/renderers/JunConfigRenderer.vue +422 -0
- package/dist/runtime/components/renderers/JunStatsRenderer.vue +5 -1
- package/dist/runtime/composables/useJunAccess.d.ts +9 -0
- package/dist/runtime/composables/useJunAccess.js +25 -0
- package/dist/runtime/composables/useJunAccessAdmin.d.ts +90 -0
- package/dist/runtime/composables/useJunAccessAdmin.js +129 -0
- package/dist/runtime/composables/useJunApiFetch.d.ts +12 -0
- package/dist/runtime/composables/useJunApiFetch.js +4 -0
- package/dist/runtime/composables/useJunGarden.js +4 -2
- package/dist/runtime/composables/useJunSettings.d.ts +1 -1
- package/dist/runtime/composables/useJunSettings.js +6 -0
- package/dist/runtime/composables/useJunSiteConfigValues.js +2 -0
- package/dist/runtime/layouts/jun.d.vue.ts +2 -2
- package/dist/runtime/layouts/jun.vue +18 -1
- package/dist/runtime/layouts/jun.vue.d.ts +2 -2
- package/dist/runtime/pages/doc.vue +6 -1
- package/dist/runtime/pages/index.vue +7 -1
- package/dist/runtime/plugins/jun-session.client.d.ts +2 -0
- package/dist/runtime/plugins/jun-session.client.js +40 -0
- package/dist/runtime/server/api/links.get.js +2 -2
- package/dist/runtime/server/api/resolve/[...slug].get.js +4 -4
- package/dist/runtime/server/api/search.get.js +2 -2
- package/dist/runtime/server/api/tree.get.js +2 -2
- package/dist/runtime/server/middleware/jun-access.d.ts +2 -0
- package/dist/runtime/server/middleware/jun-access.js +34 -0
- package/dist/runtime/server/routes/jun-card.png.get.js +2 -2
- package/dist/runtime/server/routes/manifest.webmanifest.get.js +2 -2
- package/dist/runtime/server/routes/robots.txt.get.d.ts +2 -0
- package/dist/runtime/server/routes/robots.txt.get.js +16 -0
- package/dist/runtime/server/utils/junAccessGate.d.ts +36 -0
- package/dist/runtime/server/utils/junAccessGate.js +57 -0
- package/dist/runtime/server/utils/junFeed.js +2 -2
- package/dist/runtime/server/utils/junPages.js +2 -2
- package/dist/runtime/server/utils/junVisibility.d.ts +40 -0
- package/dist/runtime/server/utils/junVisibility.js +6 -0
- package/dist/runtime/types.d.ts +9 -0
- package/dist/runtime/utils/junAccess.d.ts +160 -0
- package/dist/runtime/utils/junAccess.js +62 -0
- package/dist/runtime/utils/junVisibility.d.ts +40 -0
- package/dist/runtime/utils/junVisibility.js +6 -0
- package/dist/types.d.mts +1 -1
- package/package.json +8 -3
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { computed, ref } from "vue";
|
|
2
|
+
import { useAbracadabra, useChildTree, useToast } from "#imports";
|
|
3
|
+
import { useJunStudio } from "./useJunStudio.js";
|
|
4
|
+
export const JUN_DOC_ACCESS_CHOICES = [
|
|
5
|
+
{ value: "inherit", label: "Inherit", hint: "Whatever the page above it says" },
|
|
6
|
+
{ value: "private", label: "Private", hint: "Sealed \u2014 only explicit grants, owners and admins" },
|
|
7
|
+
{ value: "none", label: "No floor", hint: "Blocks anonymous; authenticated still get the server default" },
|
|
8
|
+
{ value: "observer", label: "Observer", hint: "Readable, with no presence" },
|
|
9
|
+
{ value: "viewer", label: "Viewer", hint: "Readable, and readers are visible to each other" },
|
|
10
|
+
{ value: "editor", label: "Editor", hint: "Anyone signed in may write here" }
|
|
11
|
+
];
|
|
12
|
+
export function useJunAccessAdmin() {
|
|
13
|
+
const abra = useAbracadabra();
|
|
14
|
+
const { canEdit } = useJunStudio();
|
|
15
|
+
const toast = useToast();
|
|
16
|
+
const server = ref(null);
|
|
17
|
+
const invites = ref([]);
|
|
18
|
+
const invitesLoaded = ref(false);
|
|
19
|
+
const error = ref("");
|
|
20
|
+
const busy = ref("");
|
|
21
|
+
const canAdmin = computed(() => canEdit.value === true && !!abra.spaceDocId.value);
|
|
22
|
+
function client() {
|
|
23
|
+
return abra.client.value ?? null;
|
|
24
|
+
}
|
|
25
|
+
async function refreshServer() {
|
|
26
|
+
const c = client();
|
|
27
|
+
if (!c?.serverInfo) return;
|
|
28
|
+
try {
|
|
29
|
+
const info = await c.serverInfo();
|
|
30
|
+
server.value = {
|
|
31
|
+
anonymous: info.access?.anonymous ?? "none",
|
|
32
|
+
authenticated: info.access?.authenticated ?? "viewer",
|
|
33
|
+
// Older servers do not report it. `null` is "the server did not say",
|
|
34
|
+
// which the panel renders as such rather than as a confident "closed".
|
|
35
|
+
registrationOpen: typeof info.registration_allowed === "boolean" ? info.registration_allowed : null,
|
|
36
|
+
inviteOnly: typeof info.invite_only === "boolean" ? info.invite_only : null,
|
|
37
|
+
serverName: info.name ?? "",
|
|
38
|
+
serverVersion: info.version ?? ""
|
|
39
|
+
};
|
|
40
|
+
} catch {
|
|
41
|
+
server.value = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function refreshInvites() {
|
|
45
|
+
const c = client();
|
|
46
|
+
if (!canAdmin.value || !c?.listInvites) return;
|
|
47
|
+
try {
|
|
48
|
+
invites.value = await c.listInvites();
|
|
49
|
+
invitesLoaded.value = true;
|
|
50
|
+
error.value = "";
|
|
51
|
+
} catch (e) {
|
|
52
|
+
invites.value = [];
|
|
53
|
+
invitesLoaded.value = true;
|
|
54
|
+
error.value = /403|forbidden|permission/i.test(String(e)) ? "This server does not let you manage invites \u2014 see `[users].who_can_invite`." : "Could not read the invites.";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function createInvite(opts) {
|
|
58
|
+
const c = client();
|
|
59
|
+
if (!canAdmin.value || !c?.createInvite) return "";
|
|
60
|
+
busy.value = "create";
|
|
61
|
+
try {
|
|
62
|
+
const row = await c.createInvite(opts);
|
|
63
|
+
await refreshInvites();
|
|
64
|
+
toast.add({ title: "Invite created", description: row.code, icon: "i-lucide-ticket", color: "neutral" });
|
|
65
|
+
return row.code;
|
|
66
|
+
} catch {
|
|
67
|
+
error.value = "Could not create an invite.";
|
|
68
|
+
return "";
|
|
69
|
+
} finally {
|
|
70
|
+
busy.value = "";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function revokeInvite(code) {
|
|
74
|
+
const c = client();
|
|
75
|
+
if (!canAdmin.value || !c?.revokeInvite) return;
|
|
76
|
+
busy.value = code;
|
|
77
|
+
try {
|
|
78
|
+
await c.revokeInvite(code);
|
|
79
|
+
await refreshInvites();
|
|
80
|
+
} catch {
|
|
81
|
+
error.value = "Could not revoke that invite.";
|
|
82
|
+
} finally {
|
|
83
|
+
busy.value = "";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function docAccess(docId) {
|
|
87
|
+
const c = client();
|
|
88
|
+
if (!c?.getDocumentAccess || !docId) return { own: null, effective: null };
|
|
89
|
+
try {
|
|
90
|
+
const row = await c.getDocumentAccess(docId);
|
|
91
|
+
return {
|
|
92
|
+
own: row.public_access ?? null,
|
|
93
|
+
effective: row.effective_public_access ?? null
|
|
94
|
+
};
|
|
95
|
+
} catch {
|
|
96
|
+
return { own: null, effective: null };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function setDocAccess(docId, value) {
|
|
100
|
+
const c = client();
|
|
101
|
+
if (!canAdmin.value || !c?.setDocumentAccess || !docId) return;
|
|
102
|
+
busy.value = docId;
|
|
103
|
+
try {
|
|
104
|
+
await c.setDocumentAccess(docId, value);
|
|
105
|
+
error.value = "";
|
|
106
|
+
const stored = await docAccess(docId);
|
|
107
|
+
const sealed = stored.own === "private" || stored.effective === "private";
|
|
108
|
+
useChildTree(abra.doc, docId).updateMeta(docId, { junPrivate: sealed || void 0 });
|
|
109
|
+
} catch (e) {
|
|
110
|
+
error.value = /400|bad request/i.test(String(e)) ? "This server is too old for that setting \u2014 `private` needs a newer Abracadabra." : "The server refused that change.";
|
|
111
|
+
} finally {
|
|
112
|
+
busy.value = "";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
canAdmin,
|
|
117
|
+
server,
|
|
118
|
+
invites,
|
|
119
|
+
invitesLoaded,
|
|
120
|
+
error,
|
|
121
|
+
busy,
|
|
122
|
+
refreshServer,
|
|
123
|
+
refreshInvites,
|
|
124
|
+
createInvite,
|
|
125
|
+
revokeInvite,
|
|
126
|
+
docAccess,
|
|
127
|
+
setDocAccess
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cast is deliberate, and it is Nuxt's own type gap rather than a lie.
|
|
3
|
+
*
|
|
4
|
+
* `useRequestFetch()` is typed as `H3Event$Fetch`, which is the same callable
|
|
5
|
+
* minus the `.raw` and `.create` helpers `$Fetch` carries — and `useFetch`'s
|
|
6
|
+
* `$fetch` option asks for the full `$Fetch`. It never calls either helper, so
|
|
7
|
+
* the difference is structural only; without the cast every `useFetch` that
|
|
8
|
+
* passes this reports "no overload matches" and, worse, falls back to the
|
|
9
|
+
* generic overload, which un-types `data` and takes six real assertions down
|
|
10
|
+
* with it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function junApiFetch(): typeof globalThis.$fetch;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import { useDocSlugs, useDocTree, useJunOptions } from "#imports";
|
|
3
3
|
import { useFetch } from "#app";
|
|
4
|
+
import { junApiFetch } from "./useJunApiFetch.js";
|
|
4
5
|
import {
|
|
5
6
|
junGardenCounts,
|
|
6
7
|
junGardenNotes,
|
|
7
8
|
junGardenOrphans,
|
|
8
9
|
junGardenSort
|
|
9
10
|
} from "../utils/junGarden.js";
|
|
10
|
-
import {
|
|
11
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
11
12
|
const EMPTY = { nodes: [], edges: [], scanned: 0, generatedAt: 0 };
|
|
12
13
|
export function useJunLinkGraph(docId) {
|
|
13
14
|
const opts = useJunOptions();
|
|
14
15
|
const { data, refresh } = useFetch(`${opts.apiBase}/links`, {
|
|
16
|
+
$fetch: junApiFetch(),
|
|
15
17
|
key: docId ? `jun-links-${docId}` : "jun-links",
|
|
16
18
|
query: docId ? { doc: docId } : void 0,
|
|
17
19
|
default: () => EMPTY
|
|
@@ -37,7 +39,7 @@ export function useJunGarden(docId, sort) {
|
|
|
37
39
|
const allEntries = computed(() => {
|
|
38
40
|
const live = entries.value ?? [];
|
|
39
41
|
if (live.length) {
|
|
40
|
-
return live.filter((e) => !e.trashed && !
|
|
42
|
+
return live.filter((e) => !e.trashed && !isJunWithheldDoc(e)).map((e) => ({
|
|
41
43
|
id: e.id,
|
|
42
44
|
label: e.label,
|
|
43
45
|
href: getDocUrl(e.id),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type JunSettingsSection = 'identity' | 'navigation' | 'mark' | 'theme' | 'announcement' | 'campfire' | 'footer' | 'mobile' | 'visitors' | 'offline' | 'renderers';
|
|
1
|
+
export type JunSettingsSection = 'identity' | 'navigation' | 'mark' | 'theme' | 'announcement' | 'campfire' | 'footer' | 'mobile' | 'visitors' | 'access' | 'offline' | 'renderers';
|
|
2
2
|
export interface JunSettingsSectionDef {
|
|
3
3
|
id: JunSettingsSection;
|
|
4
4
|
label: string;
|
|
@@ -12,6 +12,12 @@ export const JUN_SETTINGS_SECTIONS = [
|
|
|
12
12
|
// effects most owners will never see on the machine they configure them from.
|
|
13
13
|
{ id: "mobile", label: "Mobile", icon: "i-lucide-smartphone", hint: "Phones, and the installed app" },
|
|
14
14
|
{ id: "visitors", label: "Visitors", icon: "i-lucide-users", hint: "Guestbook, feeds, people" },
|
|
15
|
+
// Directly after Visitors, because it is the same subject seen from the other
|
|
16
|
+
// side: that section is what a passer-by may DO, this one is who a passer-by
|
|
17
|
+
// is allowed to BE. It is also the section that did not exist for the first
|
|
18
|
+
// twelve rounds — every permission in the system was real, enforced, and
|
|
19
|
+
// invisible unless you were reading a config file on the server.
|
|
20
|
+
{ id: "access", label: "Access", icon: "i-lucide-shield", hint: "Who may read, write and join" },
|
|
15
21
|
// After Visitors, because it is about what a visitor may take away with them.
|
|
16
22
|
{ id: "offline", label: "Offline", icon: "i-lucide-cloud-download", hint: "What a reader may keep on their device" },
|
|
17
23
|
// Last, because it is the only section that configures CONTENT rather than
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { computed } from "vue";
|
|
2
2
|
import { useFetch } from "#app";
|
|
3
|
+
import { junApiFetch } from "./useJunApiFetch.js";
|
|
3
4
|
import { useJunOptions } from "./useJunOptions.js";
|
|
4
5
|
export function junConfigStr(v) {
|
|
5
6
|
return typeof v === "string" && v.trim() ? v : void 0;
|
|
@@ -10,6 +11,7 @@ export function junConfigOn(v) {
|
|
|
10
11
|
export async function useJunSiteConfigValues(live) {
|
|
11
12
|
const { apiBase } = useJunOptions();
|
|
12
13
|
const { data: ssr } = await useFetch(`${apiBase}/site-config`, {
|
|
14
|
+
$fetch: junApiFetch(),
|
|
13
15
|
key: "jun-site-config",
|
|
14
16
|
default: () => ({})
|
|
15
17
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare var
|
|
1
|
+
declare var __VLS_42: {};
|
|
2
2
|
type __VLS_Slots = {} & {
|
|
3
|
-
default?: (props: typeof
|
|
3
|
+
default?: (props: typeof __VLS_42) => any;
|
|
4
4
|
};
|
|
5
5
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
6
6
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -3,6 +3,7 @@ import { computed, resolveComponent } from "vue";
|
|
|
3
3
|
import { useEventListener } from "@vueuse/core";
|
|
4
4
|
import {
|
|
5
5
|
useAAFocus,
|
|
6
|
+
useJunAccess,
|
|
6
7
|
useJunBackdrop,
|
|
7
8
|
useJunCampfireSettings,
|
|
8
9
|
useJunEffectiveConfig,
|
|
@@ -17,6 +18,7 @@ import {
|
|
|
17
18
|
useJunThemeApply
|
|
18
19
|
} from "#imports";
|
|
19
20
|
const { features, contextMenu, offline, pwa } = useJunOptions();
|
|
21
|
+
const { gated } = useJunAccess();
|
|
20
22
|
const { kind: backdropKind } = useJunBackdrop();
|
|
21
23
|
const backdropComponent = computed(() => {
|
|
22
24
|
if (backdropKind.value === "shader") return resolveComponent("JunShaderBackdrop");
|
|
@@ -59,7 +61,22 @@ if (import.meta.client && contextMenu.suppressNative) {
|
|
|
59
61
|
</script>
|
|
60
62
|
|
|
61
63
|
<template>
|
|
62
|
-
|
|
64
|
+
<!-- ── The private gate ──────────────────────────────────────────────────
|
|
65
|
+
A private site shows the sign-in screen INSTEAD of the site, not on top
|
|
66
|
+
of it. Everything below this line — the shell, the navbar, the presence
|
|
67
|
+
layers, the studio — is a site, and drawing a site behind a door is a
|
|
68
|
+
site pretending to have content it is refusing to show.
|
|
69
|
+
|
|
70
|
+
`gated` is only ever true when `access.mode === 'private'` AND the
|
|
71
|
+
server could not verify a session AND the visitor's own socket has not
|
|
72
|
+
synced. It server-renders, so a stranger's first byte is this and not a
|
|
73
|
+
skeleton that becomes this. See `useJunAccess`. -->
|
|
74
|
+
<JunAccessGate v-if="gated" />
|
|
75
|
+
|
|
76
|
+
<div
|
|
77
|
+
v-else
|
|
78
|
+
class="jun-app-floor relative"
|
|
79
|
+
>
|
|
63
80
|
<!-- Bypass the navbar. THE FIRST FOCUSABLE THING ON THE PAGE, and that is
|
|
64
81
|
the whole feature: put it inside `<JunShell>` and the navbar renders
|
|
65
82
|
first, so the link is stop twenty-six rather than stop one. (It was,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare var
|
|
1
|
+
declare var __VLS_42: {};
|
|
2
2
|
type __VLS_Slots = {} & {
|
|
3
|
-
default?: (props: typeof
|
|
3
|
+
default?: (props: typeof __VLS_42) => any;
|
|
4
4
|
};
|
|
5
5
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
6
6
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
useJunRename,
|
|
13
13
|
useSlugRoute
|
|
14
14
|
} from "#imports";
|
|
15
|
+
import { junApiFetch } from "../composables/useJunApiFetch";
|
|
15
16
|
definePageMeta({ layout: "jun" });
|
|
16
17
|
const route = useRoute();
|
|
17
18
|
const router = useRouter();
|
|
@@ -35,7 +36,11 @@ const request = useFetch(
|
|
|
35
36
|
// Nuxt derives a correct per-URL key from the reactive URL above.
|
|
36
37
|
// A 404 here only means the SERVER cache doesn't know the slug — the
|
|
37
38
|
// client map may still resolve it, so this must not throw.
|
|
38
|
-
ignoreResponseError: true
|
|
39
|
+
ignoreResponseError: true,
|
|
40
|
+
// Forward the visitor's own headers on the server. On a PRIVATE site this
|
|
41
|
+
// subrequest meets the gate, and without the forward it arrives anonymous
|
|
42
|
+
// — a member would get an empty payload on a page they are entitled to.
|
|
43
|
+
$fetch: junApiFetch()
|
|
39
44
|
}
|
|
40
45
|
);
|
|
41
46
|
const resolved = request.data;
|
|
@@ -10,10 +10,16 @@ import {
|
|
|
10
10
|
useJunDocPage,
|
|
11
11
|
useJunOptions
|
|
12
12
|
} from "#imports";
|
|
13
|
+
import { junApiFetch } from "../composables/useJunApiFetch";
|
|
13
14
|
definePageMeta({ layout: "jun" });
|
|
14
15
|
const { apiBase } = useJunOptions();
|
|
15
16
|
const request = useFetch(() => `${apiBase}/resolve`, {
|
|
16
|
-
ignoreResponseError: true
|
|
17
|
+
ignoreResponseError: true,
|
|
18
|
+
// Forward the visitor's own headers on the server. On a PRIVATE site this
|
|
19
|
+
// subrequest meets the gate, and without the forward it arrives anonymous —
|
|
20
|
+
// a member would get an empty payload on a page they are entitled to. See
|
|
21
|
+
// `junApiFetch`.
|
|
22
|
+
$fetch: junApiFetch()
|
|
17
23
|
});
|
|
18
24
|
const resolved = request.data;
|
|
19
25
|
if (import.meta.server) await request;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineNuxtPlugin, useCookie, useRuntimeConfig } from "#app";
|
|
2
|
+
import { useAbracadabra } from "#imports";
|
|
3
|
+
import { watch } from "vue";
|
|
4
|
+
import { JUN_SESSION_COOKIE } from "../utils/junAccess.js";
|
|
5
|
+
export default defineNuxtPlugin(() => {
|
|
6
|
+
const jun = useRuntimeConfig().public.jun;
|
|
7
|
+
if (jun?.access?.mode !== "private") return;
|
|
8
|
+
const abra = useAbracadabra();
|
|
9
|
+
const cookie = useCookie(JUN_SESSION_COOKIE, {
|
|
10
|
+
// The gate is a GET on this origin; nothing cross-site ever needs to send
|
|
11
|
+
// it, and `strict` would drop it when a member arrives from a link in
|
|
12
|
+
// their mail — which is precisely how somebody arrives at a private site.
|
|
13
|
+
sameSite: "lax",
|
|
14
|
+
secure: window.location.protocol === "https:",
|
|
15
|
+
path: "/",
|
|
16
|
+
// A session cookie, deliberately: the token has its own expiry and the
|
|
17
|
+
// authority on it is the backend. Persisting it past the browser session
|
|
18
|
+
// would be this module deciding how long a sign-in lasts.
|
|
19
|
+
maxAge: void 0
|
|
20
|
+
});
|
|
21
|
+
function publish(token) {
|
|
22
|
+
cookie.value = token && token.length > 0 ? token : null;
|
|
23
|
+
}
|
|
24
|
+
let unsubscribe = null;
|
|
25
|
+
watch(
|
|
26
|
+
abra.client,
|
|
27
|
+
(client) => {
|
|
28
|
+
unsubscribe?.();
|
|
29
|
+
unsubscribe = null;
|
|
30
|
+
if (!client) {
|
|
31
|
+
publish(null);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
publish(client.token);
|
|
35
|
+
unsubscribe = client.onTokenChanged?.((token) => publish(token)) ?? null;
|
|
36
|
+
},
|
|
37
|
+
{ immediate: true }
|
|
38
|
+
);
|
|
39
|
+
watch(abra.identityState, () => publish(abra.client.value?.token ?? null));
|
|
40
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getQuery } from "h3";
|
|
2
2
|
import { defineCachedEventHandler } from "nitropack/runtime";
|
|
3
3
|
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
5
5
|
import { junGardenEdges, junMaturityOf } from "../../utils/junGarden.js";
|
|
6
6
|
export default defineCachedEventHandler(async (event) => {
|
|
7
7
|
const rootDocId = junRootDocId();
|
|
@@ -12,7 +12,7 @@ export default defineCachedEventHandler(async (event) => {
|
|
|
12
12
|
const knownIds = /* @__PURE__ */ new Set();
|
|
13
13
|
for (const [id, entry] of Object.entries(tree)) {
|
|
14
14
|
if (!entry || entry.trashed) continue;
|
|
15
|
-
if (id === rootDocId ||
|
|
15
|
+
if (id === rootDocId || isJunWithheldDoc(entry)) continue;
|
|
16
16
|
const slug = idToSlug[id];
|
|
17
17
|
knownIds.add(id);
|
|
18
18
|
if (slug) slugToId[slug.toLowerCase()] = id;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, getRouterParam } from "h3";
|
|
2
2
|
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../../utils/junCache.js";
|
|
3
3
|
import { junDocIdForAlias } from "../../utils/junSlugAlias.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isJunWithheldDoc } from "../../utils/junVisibility.js";
|
|
5
5
|
export default defineEventHandler(async (event) => {
|
|
6
6
|
const raw = getRouterParam(event, "slug") ?? getRouterParam(event, "_") ?? "";
|
|
7
7
|
const slug = raw.replace(/^\/+|\/+$/g, "");
|
|
@@ -16,7 +16,7 @@ export default defineEventHandler(async (event) => {
|
|
|
16
16
|
canonical = idToSlug[aliasId] ?? null;
|
|
17
17
|
}
|
|
18
18
|
const entry = tree[docId];
|
|
19
|
-
if (
|
|
19
|
+
if (isJunWithheldDoc(entry)) {
|
|
20
20
|
return {
|
|
21
21
|
found: true,
|
|
22
22
|
cacheReady,
|
|
@@ -38,7 +38,7 @@ export default defineEventHandler(async (event) => {
|
|
|
38
38
|
while (cursor && trail.length < 12 && !seen.has(cursor)) {
|
|
39
39
|
seen.add(cursor);
|
|
40
40
|
const node = tree[cursor];
|
|
41
|
-
if (!node || node.trashed ||
|
|
41
|
+
if (!node || node.trashed || isJunWithheldDoc(node)) break;
|
|
42
42
|
trail.unshift({ id: cursor, title: node.label ?? "", slug: idToSlug[cursor] ?? null });
|
|
43
43
|
cursor = node.parentId ?? null;
|
|
44
44
|
}
|
|
@@ -52,7 +52,7 @@ export default defineEventHandler(async (event) => {
|
|
|
52
52
|
parentTitle: sectionParent.label ?? "",
|
|
53
53
|
parentSlug: idToSlug[sectionParentId] ?? null,
|
|
54
54
|
items: Object.entries(tree).filter(
|
|
55
|
-
([id, e]) => !!e && e.parentId === sectionParentId && id !== sectionParentId && !e.trashed && e.meta?.hidden !== true && e.meta?.draft !== true && !
|
|
55
|
+
([id, e]) => !!e && e.parentId === sectionParentId && id !== sectionParentId && !e.trashed && e.meta?.hidden !== true && e.meta?.draft !== true && !isJunWithheldDoc(e) && !e.meta?.signerId && e.meta?.replyTo == null && e.meta?.t == null
|
|
56
56
|
).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0)).map(([id, e]) => ({
|
|
57
57
|
id,
|
|
58
58
|
title: e.label ?? "",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler, getQuery } from "h3";
|
|
2
2
|
import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
4
4
|
import { junSearchScore, junSearchSnippet, junSearchTerms } from "../../utils/junSearchRank.js";
|
|
5
5
|
const escapeHtml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
6
6
|
function toText(html) {
|
|
@@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => {
|
|
|
37
37
|
for (const [id, entry] of Object.entries(tree)) {
|
|
38
38
|
if (!entry || entry.trashed) continue;
|
|
39
39
|
if (id === rootId) continue;
|
|
40
|
-
if (
|
|
40
|
+
if (isJunWithheldDoc(entry)) continue;
|
|
41
41
|
if (types && !types.has(entry.type ?? "doc")) continue;
|
|
42
42
|
const label = entry.label ?? "";
|
|
43
43
|
const meta = entry.meta ?? {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineEventHandler } from "h3";
|
|
2
2
|
import { junDocTree, junRootDocId } from "../utils/junCache.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
4
4
|
const META_OMIT = /* @__PURE__ */ new Set(["routeGeo", "junSite"]);
|
|
5
5
|
export default defineEventHandler(async () => {
|
|
6
6
|
const rootId = junRootDocId();
|
|
@@ -8,7 +8,7 @@ export default defineEventHandler(async () => {
|
|
|
8
8
|
const entries = {};
|
|
9
9
|
for (const [id, entry] of Object.entries(tree)) {
|
|
10
10
|
if (!entry) continue;
|
|
11
|
-
if (
|
|
11
|
+
if (isJunWithheldDoc(entry)) continue;
|
|
12
12
|
let meta = entry.meta;
|
|
13
13
|
if (meta) {
|
|
14
14
|
const kept = {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineEventHandler, createError, getRequestHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { junPathIsPublic, junRefusalFor } from "../../utils/junAccess.js";
|
|
4
|
+
import { junRequestToken, junVerifySession } from "../utils/junAccessGate.js";
|
|
5
|
+
import { junRootDocId } from "../utils/junCache.js";
|
|
6
|
+
export default defineEventHandler(async (event) => {
|
|
7
|
+
const pub = useRuntimeConfig().public;
|
|
8
|
+
const access = pub.jun?.access;
|
|
9
|
+
if (!access || access.mode !== "private") return;
|
|
10
|
+
const apiBase = pub.jun?.apiBase ?? "/api/_jun";
|
|
11
|
+
const path = event.path ?? "/";
|
|
12
|
+
if (path === `${apiBase}/health` || junPathIsPublic(path, access.publicPaths)) return;
|
|
13
|
+
const token = junRequestToken(event);
|
|
14
|
+
const verdict = await junVerifySession(token, {
|
|
15
|
+
rootDocId: junRootDocId(),
|
|
16
|
+
ttlS: access.sessionTtlS
|
|
17
|
+
});
|
|
18
|
+
if (verdict.ok) {
|
|
19
|
+
event.context.junSession = { userId: verdict.userId };
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (junRefusalFor(path, getRequestHeader(event, "accept"), apiBase) === "unauthorized") {
|
|
23
|
+
throw createError({
|
|
24
|
+
statusCode: 401,
|
|
25
|
+
statusMessage: "Unauthorized",
|
|
26
|
+
// Named, so a client that gets this back can tell "you are not a member
|
|
27
|
+
// of this site" from "that endpoint is broken" without parsing prose.
|
|
28
|
+
data: { junGate: true, reason: "private-site" }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
event.context.junGated = true;
|
|
32
|
+
event.node.res.setHeader("x-jun-gate", "private");
|
|
33
|
+
event.node.res.setHeader("cache-control", "private, no-store");
|
|
34
|
+
});
|
|
@@ -2,7 +2,7 @@ import { defineEventHandler, getQuery, setResponseHeader } from "h3";
|
|
|
2
2
|
import { junBrandIdentity } from "../utils/junBrand.js";
|
|
3
3
|
import { junRenderCard } from "../utils/junCard.js";
|
|
4
4
|
import { junDocTree } from "../utils/junCache.js";
|
|
5
|
-
import {
|
|
5
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
6
6
|
import { useRuntimeConfig } from "nitropack/runtime";
|
|
7
7
|
function kindOf(type, opts) {
|
|
8
8
|
if (!type) return void 0;
|
|
@@ -20,7 +20,7 @@ export default defineEventHandler(async (event) => {
|
|
|
20
20
|
if (docId) {
|
|
21
21
|
const tree = await junDocTree().catch(() => ({}));
|
|
22
22
|
const entry = tree[docId];
|
|
23
|
-
if (entry && !entry.trashed && !
|
|
23
|
+
if (entry && !entry.trashed && !isJunWithheldDoc(entry)) {
|
|
24
24
|
title = entry.label ?? "";
|
|
25
25
|
kind = kindOf(entry.type, opts);
|
|
26
26
|
const meta = entry.meta ?? {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineEventHandler, setResponseHeader } from "h3";
|
|
2
2
|
import { junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
|
|
3
3
|
import { junBrandIdentity } from "../utils/junBrand.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isJunWithheldDoc } from "../utils/junVisibility.js";
|
|
5
5
|
const MAX_SHORTCUTS = 4;
|
|
6
6
|
export default defineEventHandler(async (event) => {
|
|
7
7
|
const brand = await junBrandIdentity();
|
|
@@ -17,7 +17,7 @@ export default defineEventHandler(async (event) => {
|
|
|
17
17
|
const rootDocId = junRootDocId();
|
|
18
18
|
const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
|
|
19
19
|
shortcuts = Object.entries(tree).filter(
|
|
20
|
-
([id, e]) => !!e && !e.trashed && id !== rootDocId && (!e.parentId || e.parentId === rootDocId) && e.meta?.hidden !== true && e.meta?.draft !== true && !
|
|
20
|
+
([id, e]) => !!e && !e.trashed && id !== rootDocId && (!e.parentId || e.parentId === rootDocId) && e.meta?.hidden !== true && e.meta?.draft !== true && !isJunWithheldDoc(e) && !!idToSlug[id]
|
|
21
21
|
).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0)).slice(0, MAX_SHORTCUTS).map(([id, e]) => ({ name: e.label || "Untitled", url: `/${idToSlug[id]}` }));
|
|
22
22
|
} catch {
|
|
23
23
|
shortcuts = [];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineEventHandler, setHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
+
import { junSiteUrl } from "../utils/junFeed.js";
|
|
4
|
+
export default defineEventHandler((event) => {
|
|
5
|
+
const pub = useRuntimeConfig().public;
|
|
6
|
+
setHeader(event, "content-type", "text/plain; charset=utf-8");
|
|
7
|
+
if (pub.jun?.access?.discovery === false) {
|
|
8
|
+
return "User-agent: *\nDisallow: /\n";
|
|
9
|
+
}
|
|
10
|
+
const lines = ["User-agent: *", "Allow: /"];
|
|
11
|
+
if (pub.jun?.features?.sitemap !== false) {
|
|
12
|
+
lines.push("", `Sitemap: ${junSiteUrl()}/sitemap.xml`);
|
|
13
|
+
}
|
|
14
|
+
return `${lines.join("\n")}
|
|
15
|
+
`;
|
|
16
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
2
|
+
/** One verified token. `userId` is informational — nothing branches on it. */
|
|
3
|
+
export interface JunSessionVerdict {
|
|
4
|
+
ok: boolean;
|
|
5
|
+
userId?: string;
|
|
6
|
+
/** Epoch ms this verdict stops being reusable. */
|
|
7
|
+
expires: number;
|
|
8
|
+
}
|
|
9
|
+
/** Drop everything remembered. Used by the tests and by a TTL of 0. */
|
|
10
|
+
export declare function junClearSessionCache(): void;
|
|
11
|
+
/**
|
|
12
|
+
* The caller's token, from wherever this kind of request carries one.
|
|
13
|
+
*
|
|
14
|
+
* A `fetch` sends `Authorization`, because the SDK holds the token in
|
|
15
|
+
* `localStorage` and can attach it. A NAVIGATION sends cookies and nothing
|
|
16
|
+
* else, which is why the client mirrors the same token into
|
|
17
|
+
* `JUN_SESSION_COOKIE` — without that mirror, SSR could never tell a member
|
|
18
|
+
* from a stranger and a private site could only ever be client-rendered.
|
|
19
|
+
*/
|
|
20
|
+
export declare function junRequestToken(event: H3Event): string | null;
|
|
21
|
+
/** The origin the RUNNER uses — internal container DNS, never the browser's. */
|
|
22
|
+
export declare function junBackendOrigin(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Ask the backend whether this token may read the site root.
|
|
25
|
+
*
|
|
26
|
+
* Cached for `ttlS` seconds per token. The cost of the cache is that a member
|
|
27
|
+
* whose grant was revoked keeps the CACHED site for up to that long — their
|
|
28
|
+
* live socket drops the moment the server says so, so what they keep is
|
|
29
|
+
* yesterday's HTML rather than today's content. 60s is the default; `0` turns
|
|
30
|
+
* the cache off entirely for a deployment that would rather pay the round trip.
|
|
31
|
+
*/
|
|
32
|
+
export declare function junVerifySession(token: string | null, opts: {
|
|
33
|
+
rootDocId: string;
|
|
34
|
+
ttlS: number;
|
|
35
|
+
origin?: string;
|
|
36
|
+
}): Promise<JunSessionVerdict>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { getCookie, getRequestHeader } from "h3";
|
|
3
|
+
import { useRuntimeConfig } from "nitropack/runtime";
|
|
4
|
+
import { JUN_SESSION_COOKIE } from "../../utils/junAccess.js";
|
|
5
|
+
const verdicts = /* @__PURE__ */ new Map();
|
|
6
|
+
const VERDICT_CAP = 2048;
|
|
7
|
+
function hash(token) {
|
|
8
|
+
return createHash("sha256").update(token).digest("base64url").slice(0, 32);
|
|
9
|
+
}
|
|
10
|
+
export function junClearSessionCache() {
|
|
11
|
+
verdicts.clear();
|
|
12
|
+
}
|
|
13
|
+
export function junRequestToken(event) {
|
|
14
|
+
const header = getRequestHeader(event, "authorization");
|
|
15
|
+
if (header) {
|
|
16
|
+
const [scheme, ...rest] = header.trim().split(/\s+/);
|
|
17
|
+
if (scheme?.toLowerCase() === "bearer" && rest.length) return rest.join(" ").trim();
|
|
18
|
+
}
|
|
19
|
+
const cookie = getCookie(event, JUN_SESSION_COOKIE);
|
|
20
|
+
return cookie ? cookie.trim() : null;
|
|
21
|
+
}
|
|
22
|
+
export function junBackendOrigin() {
|
|
23
|
+
const runtime = useRuntimeConfig();
|
|
24
|
+
const priv = runtime.abracadabra ?? {};
|
|
25
|
+
const pub = runtime.public.abracadabra ?? {};
|
|
26
|
+
return (priv.serviceServerUrl || pub.url || "http://localhost:3011").replace(/\/+$/, "");
|
|
27
|
+
}
|
|
28
|
+
export async function junVerifySession(token, opts) {
|
|
29
|
+
if (!token || !opts.rootDocId) return { ok: false, expires: 0 };
|
|
30
|
+
const key = hash(token);
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const cached = verdicts.get(key);
|
|
33
|
+
if (cached && cached.expires > now) return cached;
|
|
34
|
+
const origin = opts.origin ?? junBackendOrigin();
|
|
35
|
+
let verdict = { ok: false, expires: now + Math.min(opts.ttlS, 10) * 1e3 };
|
|
36
|
+
try {
|
|
37
|
+
const res = await fetch(`${origin}/docs/${encodeURIComponent(opts.rootDocId)}`, {
|
|
38
|
+
headers: { authorization: `Bearer ${token}` },
|
|
39
|
+
signal: AbortSignal.timeout(5e3)
|
|
40
|
+
});
|
|
41
|
+
if (res.ok) {
|
|
42
|
+
const body = await res.json().catch(() => null);
|
|
43
|
+
verdict = { ok: true, userId: body?.owner_id, expires: now + opts.ttlS * 1e3 };
|
|
44
|
+
} else if (res.status === 401 || res.status === 403) {
|
|
45
|
+
verdict = { ok: false, expires: now + opts.ttlS * 1e3 };
|
|
46
|
+
}
|
|
47
|
+
} catch {
|
|
48
|
+
}
|
|
49
|
+
if (opts.ttlS > 0) {
|
|
50
|
+
if (verdicts.size >= VERDICT_CAP) {
|
|
51
|
+
const oldest = verdicts.keys().next();
|
|
52
|
+
if (!oldest.done) verdicts.delete(oldest.value);
|
|
53
|
+
}
|
|
54
|
+
verdicts.set(key, verdict);
|
|
55
|
+
}
|
|
56
|
+
return verdict;
|
|
57
|
+
}
|