@glw907/cairn-cms 0.3.1 → 0.5.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 (99) hide show
  1. package/README.md +17 -9
  2. package/dist/adapter.d.ts +10 -1
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/auth/admins.d.ts +33 -0
  5. package/dist/auth/admins.d.ts.map +1 -0
  6. package/dist/auth/admins.js +90 -0
  7. package/dist/auth/config.d.ts +2097 -0
  8. package/dist/auth/config.d.ts.map +1 -0
  9. package/dist/auth/config.js +78 -0
  10. package/dist/auth/guard.d.ts +34 -0
  11. package/dist/auth/guard.d.ts.map +1 -0
  12. package/dist/auth/guard.js +47 -0
  13. package/dist/auth/index.d.ts +4 -0
  14. package/dist/auth/index.d.ts.map +1 -0
  15. package/dist/auth/index.js +6 -0
  16. package/dist/auth/schema.d.ts +750 -0
  17. package/dist/auth/schema.d.ts.map +1 -0
  18. package/dist/auth/schema.js +93 -0
  19. package/dist/carta.d.ts +1 -1
  20. package/dist/carta.d.ts.map +1 -1
  21. package/dist/components/AdminLayout.svelte +9 -9
  22. package/dist/components/AdminLayout.svelte.d.ts +2 -2
  23. package/dist/components/AdminLayout.svelte.d.ts.map +1 -1
  24. package/dist/components/AdminList.svelte +1 -1
  25. package/dist/components/ConfirmPage.svelte +31 -0
  26. package/dist/components/ConfirmPage.svelte.d.ts +11 -0
  27. package/dist/components/ConfirmPage.svelte.d.ts.map +1 -0
  28. package/dist/components/EditPage.svelte +5 -5
  29. package/dist/components/LoginPage.svelte +35 -18
  30. package/dist/components/LoginPage.svelte.d.ts +0 -2
  31. package/dist/components/LoginPage.svelte.d.ts.map +1 -1
  32. package/dist/components/ManageAdmins.svelte +1 -1
  33. package/dist/components/ManageAdmins.svelte.d.ts +1 -1
  34. package/dist/components/ManageAdmins.svelte.d.ts.map +1 -1
  35. package/dist/components/index.d.ts +1 -0
  36. package/dist/components/index.d.ts.map +1 -1
  37. package/dist/components/index.js +1 -0
  38. package/dist/email.d.ts.map +1 -1
  39. package/dist/email.js +19 -11
  40. package/dist/github.d.ts +22 -2
  41. package/dist/github.d.ts.map +1 -1
  42. package/dist/github.js +40 -5
  43. package/dist/index.d.ts +1 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +3 -2
  46. package/dist/render/glyph.d.ts +6 -0
  47. package/dist/render/glyph.d.ts.map +1 -0
  48. package/dist/render/glyph.js +5 -0
  49. package/dist/render/index.d.ts +6 -0
  50. package/dist/render/index.d.ts.map +1 -0
  51. package/dist/render/index.js +8 -0
  52. package/dist/render/pipeline.d.ts +16 -0
  53. package/dist/render/pipeline.d.ts.map +1 -0
  54. package/dist/render/pipeline.js +29 -0
  55. package/dist/render/registry.d.ts +28 -0
  56. package/dist/render/registry.d.ts.map +1 -0
  57. package/dist/render/registry.js +11 -0
  58. package/dist/render/rehype-dispatch.d.ts +24 -0
  59. package/dist/render/rehype-dispatch.d.ts.map +1 -0
  60. package/dist/render/rehype-dispatch.js +86 -0
  61. package/dist/render/remark-directives.d.ts +4 -0
  62. package/dist/render/remark-directives.d.ts.map +1 -0
  63. package/dist/render/remark-directives.js +74 -0
  64. package/dist/sveltekit/index.d.ts +20 -58
  65. package/dist/sveltekit/index.d.ts.map +1 -1
  66. package/dist/sveltekit/index.js +35 -152
  67. package/dist/utils.d.ts +1 -1
  68. package/dist/utils.d.ts.map +1 -1
  69. package/dist/utils.js +2 -2
  70. package/package.json +48 -6
  71. package/src/lib/adapter.ts +12 -3
  72. package/src/lib/auth/admins.ts +106 -0
  73. package/src/lib/auth/config.ts +108 -0
  74. package/src/lib/auth/guard.ts +60 -0
  75. package/src/lib/auth/index.ts +6 -0
  76. package/src/lib/auth/schema.ts +112 -0
  77. package/src/lib/carta.ts +2 -2
  78. package/src/lib/components/AdminLayout.svelte +9 -9
  79. package/src/lib/components/AdminList.svelte +1 -1
  80. package/src/lib/components/ConfirmPage.svelte +31 -0
  81. package/src/lib/components/EditPage.svelte +5 -5
  82. package/src/lib/components/LoginPage.svelte +35 -18
  83. package/src/lib/components/ManageAdmins.svelte +1 -1
  84. package/src/lib/components/index.ts +1 -0
  85. package/src/lib/email.ts +18 -11
  86. package/src/lib/github.ts +38 -6
  87. package/src/lib/index.ts +3 -2
  88. package/src/lib/render/glyph.ts +14 -0
  89. package/src/lib/render/index.ts +8 -0
  90. package/src/lib/render/pipeline.ts +37 -0
  91. package/src/lib/render/registry.ts +36 -0
  92. package/src/lib/render/rehype-dispatch.ts +97 -0
  93. package/src/lib/render/remark-directives.ts +71 -0
  94. package/src/lib/sveltekit/index.ts +59 -227
  95. package/src/lib/utils.ts +2 -2
  96. package/dist/auth.d.ts +0 -25
  97. package/dist/auth.d.ts.map +0 -1
  98. package/dist/auth.js +0 -132
  99. package/src/lib/auth.ts +0 -185
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/lib/auth/schema.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBf,CAAC;AAEH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoBnB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BnB,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBxB,CAAC;AAEF,eAAO,MAAM,aAAa;;;EAGvB,CAAC;AAEJ,eAAO,MAAM,gBAAgB;;EAK1B,CAAC;AAEJ,eAAO,MAAM,gBAAgB;;EAK1B,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { relations, sql } from "drizzle-orm";
2
+ import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core";
3
+ export const user = sqliteTable("user", {
4
+ id: text("id").primaryKey(),
5
+ name: text("name").notNull(),
6
+ email: text("email").notNull().unique(),
7
+ emailVerified: integer("email_verified", { mode: "boolean" })
8
+ .default(false)
9
+ .notNull(),
10
+ image: text("image"),
11
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
12
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
13
+ .notNull(),
14
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
15
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
16
+ .$onUpdate(() => /* @__PURE__ */ new Date())
17
+ .notNull(),
18
+ role: text("role"),
19
+ banned: integer("banned", { mode: "boolean" }).default(false),
20
+ banReason: text("ban_reason"),
21
+ banExpires: integer("ban_expires", { mode: "timestamp_ms" }),
22
+ });
23
+ export const session = sqliteTable("session", {
24
+ id: text("id").primaryKey(),
25
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
26
+ token: text("token").notNull().unique(),
27
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
28
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
29
+ .notNull(),
30
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
31
+ .$onUpdate(() => /* @__PURE__ */ new Date())
32
+ .notNull(),
33
+ ipAddress: text("ip_address"),
34
+ userAgent: text("user_agent"),
35
+ userId: text("user_id")
36
+ .notNull()
37
+ .references(() => user.id, { onDelete: "cascade" }),
38
+ impersonatedBy: text("impersonated_by"),
39
+ }, (table) => [index("session_userId_idx").on(table.userId)]);
40
+ export const account = sqliteTable("account", {
41
+ id: text("id").primaryKey(),
42
+ accountId: text("account_id").notNull(),
43
+ providerId: text("provider_id").notNull(),
44
+ userId: text("user_id")
45
+ .notNull()
46
+ .references(() => user.id, { onDelete: "cascade" }),
47
+ accessToken: text("access_token"),
48
+ refreshToken: text("refresh_token"),
49
+ idToken: text("id_token"),
50
+ accessTokenExpiresAt: integer("access_token_expires_at", {
51
+ mode: "timestamp_ms",
52
+ }),
53
+ refreshTokenExpiresAt: integer("refresh_token_expires_at", {
54
+ mode: "timestamp_ms",
55
+ }),
56
+ scope: text("scope"),
57
+ password: text("password"),
58
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
59
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
60
+ .notNull(),
61
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
62
+ .$onUpdate(() => /* @__PURE__ */ new Date())
63
+ .notNull(),
64
+ }, (table) => [index("account_userId_idx").on(table.userId)]);
65
+ export const verification = sqliteTable("verification", {
66
+ id: text("id").primaryKey(),
67
+ identifier: text("identifier").notNull(),
68
+ value: text("value").notNull(),
69
+ expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
70
+ createdAt: integer("created_at", { mode: "timestamp_ms" })
71
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
72
+ .notNull(),
73
+ updatedAt: integer("updated_at", { mode: "timestamp_ms" })
74
+ .default(sql `(cast(unixepoch('subsecond') * 1000 as integer))`)
75
+ .$onUpdate(() => /* @__PURE__ */ new Date())
76
+ .notNull(),
77
+ }, (table) => [index("verification_identifier_idx").on(table.identifier)]);
78
+ export const userRelations = relations(user, ({ many }) => ({
79
+ sessions: many(session),
80
+ accounts: many(account),
81
+ }));
82
+ export const sessionRelations = relations(session, ({ one }) => ({
83
+ user: one(user, {
84
+ fields: [session.userId],
85
+ references: [user.id],
86
+ }),
87
+ }));
88
+ export const accountRelations = relations(account, ({ one }) => ({
89
+ user: one(user, {
90
+ fields: [account.userId],
91
+ references: [user.id],
92
+ }),
93
+ }));
package/dist/carta.d.ts CHANGED
@@ -18,7 +18,7 @@ interface PreviewTransformer {
18
18
  * so this ordering reproduces render.ts exactly. Pure (no Carta) so it is unit-testable.
19
19
  */
20
20
  export declare function previewTransformers({ remarkPlugins, rehypePlugins }: PreviewPlugins): PreviewTransformer[];
21
- /** Minimal Options subset we populate avoids importing carta-md (Svelte re-exports). */
21
+ /** Minimal Options subset we populate (avoids importing carta-md, which re-exports Svelte components). */
22
22
  interface PreviewCartaOptions {
23
23
  sanitizer: false;
24
24
  rehypeOptions: {
@@ -1 +1 @@
1
- {"version":3,"file":"carta.d.ts","sourceRoot":"","sources":["../src/lib/carta.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpD,MAAM,WAAW,cAAc;IAC7B,mEAAmE;IACnE,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,oDAAoD;IACpD,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,UAAU,kBAAkB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,SAAS,EAAE,CAAC,GAAG,EAAE;QAAE,SAAS,EAAE,SAAS,CAAA;KAAE,KAAK,IAAI,CAAC;CACpD;AAYD;;;;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ACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,mBAAmB,CAMhF"}
@@ -1,19 +1,19 @@
1
1
  <script lang="ts">
2
2
  // Neutral admin chrome, shared across sites so the tool looks identical everywhere (only the
3
3
  // adapter's siteName varies). When signed in it's a responsive DaisyUI drawer+navbar shell
4
- // (`drawer lg:drawer-open` sidebar pinned on desktop, slide-over + hamburger on mobile),
4
+ // (`drawer lg:drawer-open`, sidebar pinned on desktop, slide-over + hamburger on mobile),
5
5
  // patterned on scosman/CMSaasStarter's `(admin)/(menu)` layout. The nav is data-driven and
6
6
  // role-gated, so a new surface is one entry in `nav` (plus its route + component). Signed out
7
7
  // (the login page lives under this layout) it falls back to a minimal centered shell.
8
8
  // Each site's `admin/+layout.svelte` is a one-line shim that forwards `data` + `children`.
9
9
  import type { Snippet } from 'svelte';
10
- import type { Editor } from '../auth';
10
+ import type { CairnUser } from '../auth';
11
11
 
12
12
  let {
13
13
  data,
14
14
  children,
15
15
  }: {
16
- data: { siteName: string; editor: Editor | null; pathname: string };
16
+ data: { siteName: string; user: CairnUser | null; pathname: string };
17
17
  children: Snippet;
18
18
  } = $props();
19
19
 
@@ -22,7 +22,7 @@
22
22
  label: string;
23
23
  icon: Snippet;
24
24
  active: boolean;
25
- /** Owner-only surface hidden from regular editors. */
25
+ /** Owner-only surface; hidden from regular editors. */
26
26
  owner?: boolean;
27
27
  }
28
28
 
@@ -41,7 +41,7 @@
41
41
  active: data.pathname.startsWith('/admin/admins'),
42
42
  },
43
43
  ]);
44
- const visibleNav = $derived(nav.filter((item) => !item.owner || data.editor?.role === 'owner'));
44
+ const visibleNav = $derived(nav.filter((item) => !item.owner || data.user?.role === 'owner'));
45
45
 
46
46
  // Close the slide-over after a nav tap on mobile (no-op on desktop where it's pinned open).
47
47
  function closeDrawer(): void {
@@ -68,12 +68,12 @@
68
68
  <meta name="robots" content="noindex, nofollow" />
69
69
  </svelte:head>
70
70
 
71
- {#if data.editor}
71
+ {#if data.user}
72
72
  <div class="drawer min-h-screen bg-base-200 lg:drawer-open" data-pagefind-ignore>
73
73
  <input id="admin-drawer" type="checkbox" class="drawer-toggle" />
74
74
 
75
75
  <div class="drawer-content">
76
- <!-- Mobile top bar the desktop sidebar replaces this at lg. -->
76
+ <!-- Mobile top bar; the desktop sidebar replaces this at lg. -->
77
77
  <div class="navbar bg-base-100 lg:hidden">
78
78
  <div class="flex-1">
79
79
  <span class="px-2 text-xl font-bold">{data.siteName} CMS</span>
@@ -111,8 +111,8 @@
111
111
  </ul>
112
112
 
113
113
  <div class="border-t border-base-300 p-4">
114
- <p class="text-sm font-medium">{data.editor.name}</p>
115
- <p class="text-xs opacity-60">{data.editor.email}</p>
114
+ <p class="text-sm font-medium">{data.user.name}</p>
115
+ <p class="text-xs opacity-60">{data.user.email}</p>
116
116
  <form method="POST" action="/admin/auth/logout" class="mt-3">
117
117
  <button type="submit" class="btn btn-ghost btn-sm btn-block justify-start">Sign out</button>
118
118
  </form>
@@ -1,9 +1,9 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { Editor } from '../auth';
2
+ import type { CairnUser } from '../auth';
3
3
  type $$ComponentProps = {
4
4
  data: {
5
5
  siteName: string;
6
- editor: Editor | null;
6
+ user: CairnUser | null;
7
7
  pathname: string;
8
8
  };
9
9
  children: Snippet;
@@ -1 +1 @@
1
- {"version":3,"file":"AdminLayout.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/AdminLayout.svelte.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAWrC,KAAK,gBAAgB,GAAI;IACtB,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACpE,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAyHJ,QAAA,MAAM,WAAW,sDAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"AdminLayout.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/AdminLayout.svelte.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAWxC,KAAK,gBAAgB,GAAI;IACtB,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACrE,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAyHJ,QAAA,MAAM,WAAW,sDAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  // The /admin content list: every collection's files, linking into the editor. Data comes
3
3
  // from `adminListLoad` (collections) merged with `adminLayoutLoad` (siteName). The shell
4
- // (AdminLayout) owns the chrome site title, signed-in identity, nav, sign out so this
4
+ // (AdminLayout) owns the chrome (site title, signed-in identity, nav, sign out), so this
5
5
  // page renders only the content body.
6
6
  import type { AdminCollectionList } from '../sveltekit';
7
7
 
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ // The scanner-safe confirm surface (C2). A GET renders this static page and consumes nothing.
3
+ // The token rides in a hidden field; only the explicit form POST (the route's default action,
4
+ // confirmSignIn) verifies it. Mail scanners GET URLs but don't submit forms, so prefetch can't
5
+ // burn the link. JS-free by design.
6
+ interface Props {
7
+ data: { token: string; siteName: string; error: string | null };
8
+ }
9
+ let { data }: Props = $props();
10
+ </script>
11
+
12
+ <svelte:head>
13
+ <title>Confirm sign-in · {data.siteName} CMS</title>
14
+ </svelte:head>
15
+
16
+ <div class="mx-auto mt-16 max-w-md rounded-box border border-base-300 bg-base-100 p-8">
17
+ <h1 class="text-2xl font-bold">Confirm sign-in</h1>
18
+ <p class="mt-1 text-sm opacity-70">to {data.siteName} CMS</p>
19
+
20
+ {#if data.error || !data.token}
21
+ <div class="alert alert-error mt-6">
22
+ <span>This sign-in link is invalid or expired. Request a new one.</span>
23
+ </div>
24
+ <a href="/admin/login" class="btn btn-primary mt-6">Back to sign-in</a>
25
+ {:else}
26
+ <form method="POST" class="mt-6 flex flex-col gap-3">
27
+ <input type="hidden" name="token" value={data.token} />
28
+ <button type="submit" class="btn btn-primary">Confirm sign-in</button>
29
+ </form>
30
+ {/if}
31
+ </div>
@@ -0,0 +1,11 @@
1
+ interface Props {
2
+ data: {
3
+ token: string;
4
+ siteName: string;
5
+ error: string | null;
6
+ };
7
+ }
8
+ declare const ConfirmPage: import("svelte").Component<Props, {}, "">;
9
+ type ConfirmPage = ReturnType<typeof ConfirmPage>;
10
+ export default ConfirmPage;
11
+ //# sourceMappingURL=ConfirmPage.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfirmPage.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/ConfirmPage.svelte.ts"],"names":[],"mappings":"AAOE,UAAU,KAAK;IACb,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjE;AA6BH,QAAA,MAAM,WAAW,2CAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
@@ -13,21 +13,21 @@
13
13
 
14
14
  // Body is editable state; the Carta editor's preview runs the exact site plugin set, so it
15
15
  // matches the live page. A hidden input carries the current value into the form.
16
- // svelte-ignore state_referenced_locally seeding from the initial load is intended.
16
+ // svelte-ignore state_referenced_locally (seeding from the initial load is intended)
17
17
  let body = $state(data.body);
18
18
 
19
- // svelte-ignore state_referenced_locally the preview plugin set is fixed for the load.
19
+ // svelte-ignore state_referenced_locally (the preview plugin set is fixed for the load)
20
20
  const carta = new Carta(previewCartaOptions(preview));
21
21
 
22
22
  // Carta's MarkdownEditor must not render on the worker (it pulls Shiki). onMount fires only
23
- // in the browser, so SSR renders the plain textarea and the client swaps in the editor
24
- // the kit-free equivalent of the per-site route's `$app/environment` `browser` guard.
23
+ // in the browser, so SSR renders the plain textarea and the client swaps in the editor.
24
+ // This is the kit-free equivalent of the per-site route's `$app/environment` `browser` guard.
25
25
  let mounted = $state(false);
26
26
  onMount(() => {
27
27
  mounted = true;
28
28
  });
29
29
 
30
- // svelte-ignore state_referenced_locally form defaults from the initial load.
30
+ // svelte-ignore state_referenced_locally (form defaults from the initial load)
31
31
  const fm = data.frontmatter as Record<string, unknown>;
32
32
 
33
33
  function fmString(key: string): string {
@@ -1,17 +1,33 @@
1
1
  <script lang="ts">
2
- // The magic-link sign-in page. Posts the email to /admin/auth/request; `sent`/`error` come
3
- // from `loginLoad` (querystring) merged with `adminLayoutLoad` (siteName).
2
+ // The magic-link sign-in page. Requests a link via the better-auth client (client-side, same
3
+ // origin). To avoid enumeration the UI shows the same neutral copy whether or not the email is
4
+ // on the allowlist. The server only emails actual editors (see auth/config.ts send gate).
5
+ import { createAuthClient } from 'better-auth/svelte';
6
+ import { magicLinkClient } from 'better-auth/client/plugins';
7
+
8
+ // The browser client lives in the one component that needs it (requesting a link). Sign-out
9
+ // and editor management go through server endpoints, so no shared client module is needed.
10
+ // A component-local const keeps better-auth's deep client types out of the packaged .d.ts.
11
+ const authClient = createAuthClient({ plugins: [magicLinkClient()] });
12
+
4
13
  interface Props {
5
- data: { siteName: string; sent: boolean; error: string | null };
14
+ data: { siteName: string };
6
15
  }
7
16
  let { data }: Props = $props();
8
17
 
9
- const errorMessages: Record<string, string> = {
10
- invalid: 'Please enter a valid email address.',
11
- denied: 'That email is not on the editor allowlist.',
12
- expired: 'That sign-in link has expired or was already used. Request a new one.',
13
- config: 'Sign-in is not configured. Contact the site admin.',
14
- };
18
+ let email = $state('');
19
+ let requested = $state(false);
20
+ let busy = $state(false);
21
+
22
+ async function request(event: SubmitEvent) {
23
+ event.preventDefault();
24
+ busy = true;
25
+ // The magic-link email points at our /admin/auth/confirm page (built in config.ts), not a
26
+ // GET-verify URL, so the result is the same regardless of allowlist membership.
27
+ await authClient.signIn.magicLink({ email });
28
+ busy = false;
29
+ requested = true;
30
+ }
15
31
  </script>
16
32
 
17
33
  <svelte:head>
@@ -22,26 +38,27 @@
22
38
  <h1 class="text-2xl font-bold">{data.siteName} CMS</h1>
23
39
  <p class="mt-1 text-sm opacity-70">Sign in with your editor email.</p>
24
40
 
25
- {#if data.sent}
41
+ {#if requested}
26
42
  <div class="alert alert-success mt-6">
27
- <span>Check your inbox — a sign-in link is on its way. It expires in 10 minutes.</span>
43
+ <span>
44
+ If that address is on the editor list, a sign-in link is on its way. It expires in 10
45
+ minutes.
46
+ </span>
28
47
  </div>
29
48
  {:else}
30
- {#if data.error}
31
- <div class="alert alert-error mt-6">
32
- <span>{errorMessages[data.error] ?? 'Something went wrong. Try again.'}</span>
33
- </div>
34
- {/if}
35
- <form method="POST" action="/admin/auth/request" class="mt-6 flex flex-col gap-3">
49
+ <form onsubmit={request} class="mt-6 flex flex-col gap-3">
36
50
  <input
37
51
  type="email"
38
52
  name="email"
53
+ bind:value={email}
39
54
  required
40
55
  autocomplete="email"
41
56
  placeholder="you@example.com"
42
57
  class="input w-full"
43
58
  />
44
- <button type="submit" class="btn btn-primary">Email me a sign-in link</button>
59
+ <button type="submit" class="btn btn-primary" disabled={busy}>
60
+ {busy ? 'Sending…' : 'Email me a sign-in link'}
61
+ </button>
45
62
  </form>
46
63
  {/if}
47
64
  </div>
@@ -1,8 +1,6 @@
1
1
  interface Props {
2
2
  data: {
3
3
  siteName: string;
4
- sent: boolean;
5
- error: string | null;
6
4
  };
7
5
  }
8
6
  declare const LoginPage: import("svelte").Component<Props, {}, "">;
@@ -1 +1 @@
1
- {"version":3,"file":"LoginPage.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/LoginPage.svelte.ts"],"names":[],"mappings":"AAKE,UAAU,KAAK;IACb,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACjE;AAwCH,QAAA,MAAM,SAAS,2CAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"LoginPage.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/LoginPage.svelte.ts"],"names":[],"mappings":"AAUE,UAAU,KAAK;IACb,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5B;AAyDH,QAAA,MAAM,SAAS,2CAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
@@ -3,7 +3,7 @@
3
3
  // ones. Reuses the same neutral DaisyUI chrome as the rest of the admin (panels, alerts,
4
4
  // table, buttons). Data comes from `adminsLoad` merged with `adminLayoutLoad` (siteName);
5
5
  // mutations post to the page's named form actions (`?/add`, `?/remove`, `?/setRole`).
6
- import type { AdminsData } from '../sveltekit';
6
+ import type { AdminsData } from '../auth';
7
7
 
8
8
  interface Props {
9
9
  data: AdminsData & { siteName: string };
@@ -1,4 +1,4 @@
1
- import type { AdminsData } from '../sveltekit';
1
+ import type { AdminsData } from '../auth';
2
2
  interface Props {
3
3
  data: AdminsData & {
4
4
  siteName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ManageAdmins.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/ManageAdmins.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG7C,UAAU,KAAK;IACb,IAAI,EAAE,UAAU,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC;AAmFH,QAAA,MAAM,YAAY,2CAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"ManageAdmins.svelte.d.ts","sourceRoot":"","sources":["../../src/lib/components/ManageAdmins.svelte.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGxC,UAAU,KAAK;IACb,IAAI,EAAE,UAAU,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC;AAmFH,QAAA,MAAM,YAAY,2CAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export { default as AdminLayout } from './AdminLayout.svelte';
2
2
  export { default as AdminList } from './AdminList.svelte';
3
3
  export { default as LoginPage } from './LoginPage.svelte';
4
+ export { default as ConfirmPage } from './ConfirmPage.svelte';
4
5
  export { default as EditPage } from './EditPage.svelte';
5
6
  export { default as ManageAdmins } from './ManageAdmins.svelte';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/components/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAC"}
@@ -3,5 +3,6 @@
3
3
  export { default as AdminLayout } from './AdminLayout.svelte';
4
4
  export { default as AdminList } from './AdminList.svelte';
5
5
  export { default as LoginPage } from './LoginPage.svelte';
6
+ export { default as ConfirmPage } from './ConfirmPage.svelte';
6
7
  export { default as EditPage } from './EditPage.svelte';
7
8
  export { default as ManageAdmins } from './ManageAdmins.svelte';
@@ -1 +1 @@
1
- {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/lib/email.ts"],"names":[],"mappings":"AAQA,4FAA4F;AAC5F,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,OAAO,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpC;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CASf"}
1
+ {"version":3,"file":"email.d.ts","sourceRoot":"","sources":["../src/lib/email.ts"],"names":[],"mappings":"AAQA,4FAA4F;AAC5F,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,OAAO,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpC;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAgBf"}
package/dist/email.js CHANGED
@@ -1,17 +1,25 @@
1
1
  // cairn-core: pluggable magic-link email sender.
2
2
  //
3
- // Default adapter is Cloudflare Email Service Email Sending (transactional, arbitrary
4
- // recipients) distinct from Email Routing's recipient-restricted `EmailMessage` flow.
5
- // It is reached through the same `send_email` binding (configured without a
6
- // destination_address) but a different call shape: `binding.send({ to, from, ... })`.
3
+ // The default adapter targets Cloudflare Email Service (Email Sending, transactional,
4
+ // arbitrary recipients), distinct from Email Routing's recipient-restricted `EmailMessage`
5
+ // flow. Both share the same `send_email` binding (configured without a destination_address)
6
+ // but use a different call shape: `binding.send({ to, from, ... })`.
7
7
  // Resend can slot in behind the same `sendMagicLink` signature if needed.
8
8
  export async function sendMagicLink(sender, to, link, siteName, from) {
9
9
  const expiry = "This link expires in 10 minutes and works only once. If you didn't request it, ignore this email.";
10
- await sender.send({
11
- to,
12
- from,
13
- subject: `Your ${siteName} sign-in link`,
14
- text: `Sign in to ${siteName}:\n\n${link}\n\n${expiry}`,
15
- html: `<p>Sign in to ${siteName}:</p><p><a href="${link}">Sign in</a></p><p style="color:#666;font-size:0.9em">${expiry}</p>`,
16
- });
10
+ try {
11
+ await sender.send({
12
+ to,
13
+ from,
14
+ subject: `Your ${siteName} sign-in link`,
15
+ text: `Sign in to ${siteName}:\n\n${link}\n\n${expiry}`,
16
+ html: `<p>Sign in to ${siteName}:</p><p><a href="${link}">Confirm sign-in</a></p><p style="color:#666;font-size:0.9em">${expiry}</p>`,
17
+ });
18
+ }
19
+ catch (err) {
20
+ // H6: Email Sending is beta + the sole auth channel. Surface + audit; a Resend fallback
21
+ // can slot in behind this same signature if Sending proves unreliable.
22
+ console.error(`magic-link email send failed for ${to}:`, err);
23
+ throw err;
24
+ }
17
25
  }
package/dist/github.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare function appJwt(appId: string, privateKeyPem: string): Promise<st
27
27
  export interface AppCredentials {
28
28
  appId: string;
29
29
  installationId: string;
30
- /** The stored GITHUB_APP_PRIVATE_KEY_B64 base64 of the PEM, single line. */
30
+ /** The stored GITHUB_APP_PRIVATE_KEY_B64: base64 of the PEM, single line. */
31
31
  privateKeyB64: string;
32
32
  }
33
33
  /** Exchange the App JWT for a short-lived installation access token. */
@@ -38,15 +38,35 @@ export interface CommitAuthor {
38
38
  name: string;
39
39
  email: string;
40
40
  }
41
+ /**
42
+ * A concurrent edit lost the SHA race (C3): the file changed between the read and the PUT,
43
+ * from another editor or the site's own CI. Thrown so callers can fail safe (re-fetch and ask
44
+ * the editor to reapply) instead of surfacing a raw 409. Defined and caught inside the package
45
+ * so `instanceof` is reliable (no peer-boundary identity split, unlike kit's `redirect`/`error`).
46
+ */
47
+ export declare class CommitConflictError extends Error {
48
+ readonly path: string;
49
+ constructor(path: string);
50
+ }
41
51
  /**
42
52
  * Commit `content` to `path` on the configured branch via the contents API. Author is the
43
53
  * editor; committer is omitted so GitHub attributes it to the App (cairn-cms[bot]). Updates
44
54
  * the file in place when it exists (passing its sha), creates it otherwise. Returns the
45
- * commit sha.
55
+ * commit sha. A stale-sha 409 (someone committed in between) becomes a `CommitConflictError`.
46
56
  */
47
57
  export declare function commitFile(repo: RepoRef, path: string, content: string, opts: {
48
58
  message: string;
49
59
  author: CommitAuthor;
50
60
  }, token: string): Promise<string>;
61
+ /**
62
+ * Deploy-time self-test for the GitHub App signer (M2): sign a dummy JWT with the configured
63
+ * private key. Exercises the brittle PKCS#1→PKCS#8 conversion + Web Crypto import/sign without
64
+ * any network call or secret in the result, so `/admin/healthz` catches a bad/rotated key
65
+ * before an editor's save fails. Returns `{ ok: false, detail }` rather than throwing.
66
+ */
67
+ export declare function signingSelfTest(appId: string, privateKeyB64: string): Promise<{
68
+ ok: boolean;
69
+ detail?: string;
70
+ }>;
51
71
  export {};
52
72
  //# sourceMappingURL=github.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../src/lib/github.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,4FAA4F;AAC5F,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAcD,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,QAAQ,EAAE,CAKlE;A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AAOD,+EAA+E;AAC/E,wBAAsB,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKhG;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;aAChB,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM;CAIzC;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,EAC/C,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAQrH"}
package/dist/github.js CHANGED
@@ -2,8 +2,8 @@
2
2
  //
3
3
  // Reads (Pass B) list a collection directory and fetch a file's raw markdown; the token
4
4
  // is optional because ecnordic's repo is public. Writes (Pass C) mint a short-lived
5
- // GitHub App installation token App JWT (RS256) signed with Web Crypto, no octokit
6
- // dependency and commit through the contents API with author = editor, committer = the
5
+ // GitHub App installation token (App JWT, RS256 signed with Web Crypto, no octokit
6
+ // dependency) and commit through the contents API with author = editor, committer = the
7
7
  // App (cairn-cms[bot]). The same token also lifts reads to the authenticated rate limit
8
8
  // and unlocks private repos (e.g. 907-life).
9
9
  import { bytesToB64url } from './utils';
@@ -64,7 +64,7 @@ function derLength(n) {
64
64
  }
65
65
  // AlgorithmIdentifier for rsaEncryption (OID 1.2.840.113549.1.1.1) with NULL parameters.
66
66
  const RSA_ALG_ID = [0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00];
67
- /** Wrap a PKCS#1 RSAPrivateKey (DER) as PKCS#8 the only RSA form Web Crypto importKey takes. */
67
+ /** Wrap a PKCS#1 RSAPrivateKey (DER) as PKCS#8 (the only RSA form Web Crypto importKey takes). */
68
68
  function pkcs1ToPkcs8(pkcs1) {
69
69
  const octet = [0x04, ...derLength(pkcs1.length), ...pkcs1];
70
70
  const body = [0x02, 0x01, 0x00, ...RSA_ALG_ID, ...octet];
@@ -97,7 +97,7 @@ export async function installationToken(creds) {
97
97
  throw new Error(`GitHub installation token failed: ${res.status}`);
98
98
  return (await res.json()).token;
99
99
  }
100
- /** Standard (padded) base64 of UTF-8 text the encoding the contents API expects. */
100
+ /** Standard (padded) base64 of UTF-8 text, as the contents API expects. */
101
101
  function toBase64(text) {
102
102
  return btoa(Array.from(encoder.encode(text), (b) => String.fromCharCode(b)).join(''));
103
103
  }
@@ -110,11 +110,25 @@ export async function fileSha(repo, path, token) {
110
110
  throw new Error(`GitHub stat ${path} failed: ${res.status}`);
111
111
  return (await res.json()).sha;
112
112
  }
113
+ /**
114
+ * A concurrent edit lost the SHA race (C3): the file changed between the read and the PUT,
115
+ * from another editor or the site's own CI. Thrown so callers can fail safe (re-fetch and ask
116
+ * the editor to reapply) instead of surfacing a raw 409. Defined and caught inside the package
117
+ * so `instanceof` is reliable (no peer-boundary identity split, unlike kit's `redirect`/`error`).
118
+ */
119
+ export class CommitConflictError extends Error {
120
+ path;
121
+ constructor(path) {
122
+ super(`Commit conflict on ${path}: it changed since it was opened`);
123
+ this.path = path;
124
+ this.name = 'CommitConflictError';
125
+ }
126
+ }
113
127
  /**
114
128
  * Commit `content` to `path` on the configured branch via the contents API. Author is the
115
129
  * editor; committer is omitted so GitHub attributes it to the App (cairn-cms[bot]). Updates
116
130
  * the file in place when it exists (passing its sha), creates it otherwise. Returns the
117
- * commit sha.
131
+ * commit sha. A stale-sha 409 (someone committed in between) becomes a `CommitConflictError`.
118
132
  */
119
133
  export async function commitFile(repo, path, content, opts, token) {
120
134
  const sha = await fileSha(repo, path, token);
@@ -130,7 +144,28 @@ export async function commitFile(repo, path, content, opts, token) {
130
144
  ...(sha ? { sha } : {}),
131
145
  }),
132
146
  });
147
+ // 409 = the blob sha we read is no longer current. Fail safe: the caller re-fetches and the
148
+ // editor reapplies. (Full three-way merge stays out of scope; see ARCHITECTURE §5.)
149
+ if (res.status === 409)
150
+ throw new CommitConflictError(path);
133
151
  if (!res.ok)
134
152
  throw new Error(`GitHub commit ${path} failed: ${res.status} ${await res.text()}`);
135
153
  return (await res.json()).commit.sha;
136
154
  }
155
+ /**
156
+ * Deploy-time self-test for the GitHub App signer (M2): sign a dummy JWT with the configured
157
+ * private key. Exercises the brittle PKCS#1→PKCS#8 conversion + Web Crypto import/sign without
158
+ * any network call or secret in the result, so `/admin/healthz` catches a bad/rotated key
159
+ * before an editor's save fails. Returns `{ ok: false, detail }` rather than throwing.
160
+ */
161
+ export async function signingSelfTest(appId, privateKeyB64) {
162
+ try {
163
+ const jwt = await appJwt(appId, atob(privateKeyB64));
164
+ if (jwt.split('.').length !== 3)
165
+ return { ok: false, detail: 'malformed JWT' };
166
+ return { ok: true };
167
+ }
168
+ catch (err) {
169
+ return { ok: false, detail: err instanceof Error ? err.message : 'sign failed' };
170
+ }
171
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './auth';
2
1
  export * from './email';
3
2
  export * from './github';
4
3
  export * from './carta';
5
4
  export * from './content';
6
5
  export * from './adapter';
6
+ export * from './render';
7
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AACA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAEA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}