@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.
Files changed (51) hide show
  1. package/README.md +25 -0
  2. package/dist/module.d.mts +14 -2
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +32 -0
  5. package/dist/runtime/components/JunAccessGate.d.vue.ts +3 -0
  6. package/dist/runtime/components/JunAccessGate.vue +146 -0
  7. package/dist/runtime/components/JunAccessGate.vue.d.ts +3 -0
  8. package/dist/runtime/components/JunServiceCard.vue +2 -0
  9. package/dist/runtime/components/JunShell.vue +2 -0
  10. package/dist/runtime/components/renderers/JunConfigRenderer.vue +422 -0
  11. package/dist/runtime/components/renderers/JunStatsRenderer.vue +5 -1
  12. package/dist/runtime/composables/useJunAccess.d.ts +9 -0
  13. package/dist/runtime/composables/useJunAccess.js +25 -0
  14. package/dist/runtime/composables/useJunAccessAdmin.d.ts +90 -0
  15. package/dist/runtime/composables/useJunAccessAdmin.js +129 -0
  16. package/dist/runtime/composables/useJunApiFetch.d.ts +12 -0
  17. package/dist/runtime/composables/useJunApiFetch.js +4 -0
  18. package/dist/runtime/composables/useJunGarden.js +4 -2
  19. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  20. package/dist/runtime/composables/useJunSettings.js +6 -0
  21. package/dist/runtime/composables/useJunSiteConfigValues.js +2 -0
  22. package/dist/runtime/layouts/jun.d.vue.ts +2 -2
  23. package/dist/runtime/layouts/jun.vue +18 -1
  24. package/dist/runtime/layouts/jun.vue.d.ts +2 -2
  25. package/dist/runtime/pages/doc.vue +6 -1
  26. package/dist/runtime/pages/index.vue +7 -1
  27. package/dist/runtime/plugins/jun-session.client.d.ts +2 -0
  28. package/dist/runtime/plugins/jun-session.client.js +40 -0
  29. package/dist/runtime/server/api/links.get.js +2 -2
  30. package/dist/runtime/server/api/resolve/[...slug].get.js +4 -4
  31. package/dist/runtime/server/api/search.get.js +2 -2
  32. package/dist/runtime/server/api/tree.get.js +2 -2
  33. package/dist/runtime/server/middleware/jun-access.d.ts +2 -0
  34. package/dist/runtime/server/middleware/jun-access.js +34 -0
  35. package/dist/runtime/server/routes/jun-card.png.get.js +2 -2
  36. package/dist/runtime/server/routes/manifest.webmanifest.get.js +2 -2
  37. package/dist/runtime/server/routes/robots.txt.get.d.ts +2 -0
  38. package/dist/runtime/server/routes/robots.txt.get.js +16 -0
  39. package/dist/runtime/server/utils/junAccessGate.d.ts +36 -0
  40. package/dist/runtime/server/utils/junAccessGate.js +57 -0
  41. package/dist/runtime/server/utils/junFeed.js +2 -2
  42. package/dist/runtime/server/utils/junPages.js +2 -2
  43. package/dist/runtime/server/utils/junVisibility.d.ts +40 -0
  44. package/dist/runtime/server/utils/junVisibility.js +6 -0
  45. package/dist/runtime/types.d.ts +9 -0
  46. package/dist/runtime/utils/junAccess.d.ts +160 -0
  47. package/dist/runtime/utils/junAccess.js +62 -0
  48. package/dist/runtime/utils/junVisibility.d.ts +40 -0
  49. package/dist/runtime/utils/junVisibility.js +6 -0
  50. package/dist/types.d.mts +1 -1
  51. package/package.json +8 -3
package/README.md CHANGED
@@ -32,6 +32,31 @@ visitor interaction — all driven by documents rather than code.
32
32
  pnpm add @abraca/junis @abraca/nuxt @abraca/dabra @abraca/convert
33
33
  ```
34
34
 
35
+ ## Three shapes, and you have to pick one
36
+
37
+ ```ts
38
+ jun: { access: { mode: 'public' } } // 'open' | 'public' | 'private'
39
+ ```
40
+
41
+ | | Reads | Writes | Runnable example |
42
+ |---|---|---|---|
43
+ | `open` | everyone | **everyone** | `playground/` · [jun.is](https://jun.is) |
44
+ | `public` *(default)* | everyone | the owner, plus guestbook/poll/thread over RPC | [`examples/atelier`](examples/atelier) |
45
+ | `private` | **members only** | members, per their grant | [`examples/kammer`](examples/kammer) |
46
+
47
+ `private` is not a login screen bolted on the front. Everything public about a
48
+ jun-is site is served from a doc cache that a **service-role** runner fills, so
49
+ without a gate a "private" deployment refuses a stranger's CRDT socket and then
50
+ hands them the whole tree over its own endpoints. `mode: 'private'` closes that:
51
+ `/api/**` answers 401, a navigation renders a sign-in screen with **no document
52
+ payload**, and the feeds, the sitemap and the link-preview cards are gone.
53
+
54
+ Every shape has a server half too — the backend is the authority, and nothing in
55
+ this module grants or withholds access on its own. **[`ACCESS.md`](ACCESS.md)**
56
+ has both halves for all three, plus the owner's new **Access** settings panel
57
+ (⌘, → Access): who holds a grant here, who may join, and whether this page is
58
+ public.
59
+
35
60
  All four ship from the same release train and carry the same version. The three
36
61
  `@abraca/*` siblings are **peers**, not dependencies, so your app resolves one
37
62
  copy of each — a second copy of `@abraca/convert` means a second `yjs` identity,
package/dist/module.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { JunBrand, JunPageTypesOption, JunFeatures, JunContextMenuOptions, JunNavigationOptions, JunCampfireOptions, JunBackdropKind, JunLayoutPolicy, JunSiteConfigDefaults, JunSeedOptions, JunJanitorOptions, JunGuestNames, JunRendererDefaults, JunEmbedOptions, JunMosaicOptions, JunOfflineOptions, JunPrefetchPolicy, JunServicesOptions, JunPaletteSet } from '../dist/runtime/types.js';
3
- export { JunBackdropKind, JunBrand, JunCampfireOptions, JunCampfirePillMode, JunCampfirePlacement, JunCampfireRosterStyle, JunCampfireSize, JunCampfireTab, JunContextMenuOptions, JunEmbedOptions, JunFeatures, JunGuestNames, JunJanitorBaselineMode, JunJanitorIdentity, JunJanitorIdentityMode, JunJanitorMode, JunJanitorOptions, JunJsonLdSpec, JunLayoutPolicy, JunMosaicOptions, JunNavActiveStyle, JunNavItemMode, JunNavPlacement, JunNavShape, JunNavSize, JunNavigationOptions, JunOfflineOptions, JunPageTypeKey, JunPageTypeOverride, JunPageTypesOption, JunPalette, JunPaletteSet, JunPrefetchPolicy, JunRendererDefaults, JunRuntimeOptions, JunSeedNode, JunSeedOptions, JunServicesOptions, JunSiteConfigDefaults } from '../dist/runtime/types.js';
2
+ import { JunBrand, JunPageTypesOption, JunFeatures, JunAccessOptions, JunContextMenuOptions, JunNavigationOptions, JunCampfireOptions, JunBackdropKind, JunLayoutPolicy, JunSiteConfigDefaults, JunSeedOptions, JunJanitorOptions, JunGuestNames, JunRendererDefaults, JunEmbedOptions, JunMosaicOptions, JunOfflineOptions, JunPrefetchPolicy, JunServicesOptions, JunPaletteSet } from '../dist/runtime/types.js';
3
+ export { JunAccessGateCopy, JunAccessMode, JunAccessOptions, JunAccessRuntime, JunBackdropKind, JunBrand, JunCampfireOptions, JunCampfirePillMode, JunCampfirePlacement, JunCampfireRosterStyle, JunCampfireSize, JunCampfireTab, JunContextMenuOptions, JunEmbedOptions, JunFeatures, JunGuestNames, JunJanitorBaselineMode, JunJanitorIdentity, JunJanitorIdentityMode, JunJanitorMode, JunJanitorOptions, JunJsonLdSpec, JunLayoutPolicy, JunMosaicOptions, JunNavActiveStyle, JunNavItemMode, JunNavPlacement, JunNavShape, JunNavSize, JunNavigationOptions, JunOfflineOptions, JunPageTypeKey, JunPageTypeOverride, JunPageTypesOption, JunPalette, JunPaletteSet, JunPrefetchPolicy, JunRendererDefaults, JunRuntimeOptions, JunSeedNode, JunSeedOptions, JunServicesOptions, JunSiteConfigDefaults } from '../dist/runtime/types.js';
4
4
 
5
5
  interface ModuleOptions {
6
6
  /** Site identity. The only thing most sites need to set. */
@@ -21,6 +21,18 @@ interface ModuleOptions {
21
21
  pageTypeAliases?: Record<string, string>;
22
22
  /** Site-wide behaviours — each gates both its client mount and its server half. */
23
23
  features?: JunFeatures;
24
+ /**
25
+ * **What kind of site this is** — `open`, `public` (the default) or
26
+ * `private`. The one decision every other option hangs off, and the one the
27
+ * module used to have no way to state.
28
+ *
29
+ * It contributes DEFAULTS to `features` and switches on the private gate; it
30
+ * never overrules a flag the site stated for itself. See
31
+ * `runtime/utils/junAccess.ts` for the three shapes and `ACCESS.md` for the
32
+ * server-side half, which is not optional — the backend is the authority and
33
+ * this option cannot grant or withhold anything on its own.
34
+ */
35
+ access?: JunAccessOptions;
24
36
  /**
25
37
  * Which items a document context menu offers, and to whom.
26
38
  *
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "2.100.0",
7
+ "version": "2.101.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -3,6 +3,7 @@ import { defineNuxtModule, createResolver, hasNuxtModule, installModule, addImpo
3
3
  import { defu } from 'defu';
4
4
  import { JUN_RUNTIME_BACKDROPS } from '../dist/runtime/types.js';
5
5
  import { JUN_NEUTRALS } from '../dist/runtime/utils/junMark.js';
6
+ import { resolveJunAccess, junAccessFeatureDefaults } from '../dist/runtime/utils/junAccess.js';
6
7
 
7
8
  const PAGE_TYPES = {
8
9
  journal: {
@@ -390,6 +391,12 @@ const BUILTIN_META_EXCLUDE_KEYS = [
390
391
  "publishAt",
391
392
  // Former URLs of a renamed page — routing bookkeeping, never owner-edited.
392
393
  "slugAliases",
394
+ // The one-way mirror of the server's `public_access = "private"`, written by
395
+ // the Access panel so the site's SHARED caches know to withhold the page.
396
+ // Never owner-typed: an editable chip here would let somebody "unseal" a
397
+ // document from the SSR surfaces without touching the server, which is the
398
+ // one shape of this flag that could be dangerous.
399
+ "junPrivate",
393
400
  // The home renderer's own composition. `homeSections` is an ARRAY of section
394
401
  // ids and `homeLayout` is picked from a card row — a chip for either would
395
402
  // be an editable string that can only be got wrong.
@@ -935,6 +942,11 @@ Switch them off with \`jun.pageTypes: { ${missing.map((e) => `${e.key}: false`).
935
942
  }
936
943
  return map;
937
944
  }
945
+ const access = resolveJunAccess(options.access);
946
+ const statedFeatures = asRecord(asRecord(nuxtOptionsRecord(nuxt).jun)?.features) ?? {};
947
+ const accessFeatures = Object.fromEntries(
948
+ Object.entries(junAccessFeatureDefaults(access)).filter(([key]) => statedFeatures[key] === void 0)
949
+ );
938
950
  const runtime = {
939
951
  version: moduleVersion(resolver),
940
952
  // Evaluated when the module's `setup()` runs — which is `nuxt build` for
@@ -967,8 +979,15 @@ Switch them off with \`jun.pageTypes: { ${missing.map((e) => `${e.key}: false`).
967
979
  iconBackground: options.brand?.iconBackground ?? options.brand?.themeColor,
968
980
  schemaType: options.brand?.schemaType ?? "Person"
969
981
  },
982
+ access,
970
983
  features: {
971
984
  ...options.features,
985
+ // What the ACCESS MODE contributes — only the keys the site left
986
+ // unstated (see `statedFeatures`). A `private` site gets no feeds, no
987
+ // sitemap and no link-preview cards unless it asks for them back; an
988
+ // `open` one gets the studio handed to every visitor, which is the
989
+ // single flag that shape exists for.
990
+ ...accessFeatures,
972
991
  // The player FOLLOWS the festival page type unless the site says
973
992
  // otherwise. It is one `<audio>` element and a Media Session handler
974
993
  // mounted in the layout for the whole session — worth it for a site
@@ -1197,6 +1216,12 @@ Switch them off with \`jun.pageTypes: { ${missing.map((e) => `${e.key}: false`).
1197
1216
  src: resolver.resolve("./runtime/plugins/jun-drag-affordance.client"),
1198
1217
  mode: "client"
1199
1218
  });
1219
+ if (access.mode === "private") {
1220
+ addPlugin({
1221
+ src: resolver.resolve("./runtime/plugins/jun-session.client"),
1222
+ mode: "client"
1223
+ });
1224
+ }
1200
1225
  addPlugin({ src: resolver.resolve("./runtime/plugins/jun-site-config") });
1201
1226
  addPlugin({ src: resolver.resolve("./runtime/plugins/jun-doc-tree") });
1202
1227
  if (options.layoutName !== false) {
@@ -1228,6 +1253,13 @@ Switch them off with \`jun.pageTypes: { ${missing.map((e) => `${e.key}: false`).
1228
1253
  }
1229
1254
  const base = runtime.apiBase;
1230
1255
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
1256
+ if (access.mode === "private") {
1257
+ addServerHandler({
1258
+ middleware: true,
1259
+ handler: resolver.resolve("./runtime/server/middleware/jun-access")
1260
+ });
1261
+ }
1262
+ addServerHandler({ route: "/robots.txt", handler: resolver.resolve("./runtime/server/routes/robots.txt.get") });
1231
1263
  addServerHandler({ route: `${base}/nav`, handler: resolver.resolve("./runtime/server/api/nav.get") });
1232
1264
  addServerHandler({ route: `${base}/tree`, handler: resolver.resolve("./runtime/server/api/tree.get") });
1233
1265
  addServerHandler({ route: `${base}/site-config`, handler: resolver.resolve("./runtime/server/api/site-config.get") });
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,146 @@
1
+ <script setup>
2
+ import { computed, ref } from "vue";
3
+ import { useAbracadabra } from "#imports";
4
+ import { useJunAccess } from "../composables/useJunAccess";
5
+ import { useJunOptions } from "../composables/useJunOptions";
6
+ const { brand } = useJunOptions();
7
+ const { gate } = useJunAccess();
8
+ const { loginWithPassword, registerWithPassword } = useAbracadabra();
9
+ const panel = ref("signin");
10
+ const username = ref("");
11
+ const password = ref("");
12
+ const inviteCode = ref("");
13
+ const displayName = ref("");
14
+ const busy = ref(false);
15
+ const error = ref(null);
16
+ const canSubmit = computed(
17
+ () => panel.value === "signin" ? username.value.trim().length > 0 && password.value.length > 0 : username.value.trim().length > 0 && password.value.length > 0 && inviteCode.value.trim().length > 0
18
+ );
19
+ function humanError(e) {
20
+ const msg = e instanceof Error ? e.message : String(e);
21
+ if (/invite/i.test(msg)) return "That invite code isn't valid any more.";
22
+ if (/exists|taken|409/i.test(msg)) return "That name is taken. Pick another.";
23
+ if (/rate|too many|429/i.test(msg)) return "Too many attempts \u2014 give it a moment.";
24
+ if (/invalid|credential|password|unauthorized|401|403/i.test(msg)) return "Those details didn't match.";
25
+ return "Couldn't sign in. Check the connection and try again.";
26
+ }
27
+ async function submit() {
28
+ if (!canSubmit.value || busy.value) return;
29
+ busy.value = true;
30
+ error.value = null;
31
+ try {
32
+ if (panel.value === "signin") {
33
+ await loginWithPassword({ username: username.value.trim(), password: password.value });
34
+ } else {
35
+ await registerWithPassword({
36
+ username: username.value.trim(),
37
+ password: password.value,
38
+ displayName: displayName.value.trim() || void 0,
39
+ inviteCode: inviteCode.value.trim()
40
+ });
41
+ }
42
+ } catch (e) {
43
+ error.value = humanError(e);
44
+ } finally {
45
+ busy.value = false;
46
+ }
47
+ }
48
+ </script>
49
+
50
+ <template>
51
+ <div class="jun-gate flex min-h-dvh items-center justify-center px-6 py-16">
52
+ <div class="w-full max-w-sm">
53
+ <div class="mb-8 flex flex-col items-center gap-3 text-center">
54
+ <JunLogo class="h-10" />
55
+ <div>
56
+ <h1 class="text-lg font-semibold text-highlighted">
57
+ {{ gate.headline }}
58
+ </h1>
59
+ <p class="mt-1 text-sm text-muted">
60
+ {{ gate.blurb }}
61
+ </p>
62
+ </div>
63
+ </div>
64
+
65
+ <form
66
+ class="jun-card space-y-4 rounded-2xl p-6"
67
+ @submit.prevent="submit"
68
+ >
69
+ <UFormField label="Name">
70
+ <UInput
71
+ v-model="username"
72
+ autocomplete="username"
73
+ autofocus
74
+ class="w-full"
75
+ />
76
+ </UFormField>
77
+
78
+ <UFormField label="Password">
79
+ <UInput
80
+ v-model="password"
81
+ type="password"
82
+ :autocomplete="panel === 'signin' ? 'current-password' : 'new-password'"
83
+ class="w-full"
84
+ />
85
+ </UFormField>
86
+
87
+ <template v-if="panel === 'invite'">
88
+ <UFormField
89
+ label="Invite code"
90
+ help="From whoever invited you."
91
+ >
92
+ <UInput
93
+ v-model="inviteCode"
94
+ class="w-full"
95
+ />
96
+ </UFormField>
97
+ <UFormField
98
+ label="Display name"
99
+ help="Optional — what other people see."
100
+ >
101
+ <UInput
102
+ v-model="displayName"
103
+ class="w-full"
104
+ />
105
+ </UFormField>
106
+ </template>
107
+
108
+ <p
109
+ v-if="error"
110
+ class="text-sm text-error"
111
+ role="alert"
112
+ >
113
+ {{ error }}
114
+ </p>
115
+
116
+ <UButton
117
+ type="submit"
118
+ block
119
+ color="neutral"
120
+ :loading="busy"
121
+ :disabled="!canSubmit"
122
+ >
123
+ {{ panel === "signin" ? "Sign in" : "Join" }}
124
+ </UButton>
125
+
126
+ <div
127
+ v-if="gate.invites"
128
+ class="text-center"
129
+ >
130
+ <UButton
131
+ variant="link"
132
+ color="neutral"
133
+ size="xs"
134
+ @click="panel = panel === 'signin' ? 'invite' : 'signin'"
135
+ >
136
+ {{ panel === "signin" ? "I have an invite code" : "I already have an account" }}
137
+ </UButton>
138
+ </div>
139
+ </form>
140
+
141
+ <p class="mt-6 text-center text-xs text-dimmed">
142
+ {{ brand.name }}
143
+ </p>
144
+ </div>
145
+ </div>
146
+ </template>
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -2,6 +2,7 @@
2
2
  import { computed } from "vue";
3
3
  import { useFetch } from "#app";
4
4
  import { junServiceIcon, junServiceLabel, useJunOptions } from "#imports";
5
+ import { junApiFetch } from "../composables/useJunApiFetch";
5
6
  const props = defineProps({
6
7
  docId: { type: String, required: true },
7
8
  label: { type: String, required: true },
@@ -13,6 +14,7 @@ const configured = computed(() => !!props.provider && !!props.serviceRef);
13
14
  const providerQuery = computed(() => props.provider);
14
15
  const refQuery = computed(() => props.serviceRef);
15
16
  const { data, pending } = await useFetch(`${opts.apiBase}/service`, {
17
+ $fetch: junApiFetch(),
16
18
  // Keyed by what it fetches, so two cards pointing at the same repository
17
19
  // share one payload entry instead of racing each other.
18
20
  key: `jun-service:${props.provider}:${props.serviceRef}`,
@@ -2,12 +2,14 @@
2
2
  import { computed } from "vue";
3
3
  import { useFetch, useRoute } from "#app";
4
4
  import { useDocTree } from "#imports";
5
+ import { junApiFetch } from "../composables/useJunApiFetch";
5
6
  import { useJunOptions } from "../composables/useJunOptions";
6
7
  import { normalizeIcon } from "../utils/junDocTypeIcons";
7
8
  const route = useRoute();
8
9
  const { apiBase } = useJunOptions();
9
10
  const { navigationItems, topLevelDocs } = useDocTree();
10
11
  const { data: ssrNav } = await useFetch(`${apiBase}/nav`, {
12
+ $fetch: junApiFetch(),
11
13
  key: "jun-nav",
12
14
  default: () => []
13
15
  });