@glw907/cairn-cms 0.5.1 → 0.6.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/crypto.d.ts +13 -0
- package/dist/auth/crypto.d.ts.map +1 -0
- package/dist/auth/crypto.js +31 -0
- package/dist/auth/store.d.ts +41 -0
- package/dist/auth/store.d.ts.map +1 -0
- package/dist/auth/store.js +115 -0
- package/dist/auth/types.d.ts +25 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +1 -0
- package/dist/components/AdminLayout.svelte +58 -164
- package/dist/components/AdminLayout.svelte.d.ts +14 -18
- package/dist/components/AdminLayout.svelte.d.ts.map +1 -1
- package/dist/components/ComponentPalette.svelte +36 -20
- package/dist/components/ComponentPalette.svelte.d.ts +11 -4
- package/dist/components/ComponentPalette.svelte.d.ts.map +1 -1
- package/dist/components/ConceptList.svelte +81 -0
- package/dist/components/ConceptList.svelte.d.ts +13 -0
- package/dist/components/ConceptList.svelte.d.ts.map +1 -0
- package/dist/components/ConfirmPage.svelte +23 -20
- package/dist/components/ConfirmPage.svelte.d.ts +6 -0
- package/dist/components/ConfirmPage.svelte.d.ts.map +1 -1
- package/dist/components/EditPage.svelte +155 -136
- package/dist/components/EditPage.svelte.d.ts +16 -8
- package/dist/components/EditPage.svelte.d.ts.map +1 -1
- package/dist/components/LoginPage.svelte +42 -52
- package/dist/components/LoginPage.svelte.d.ts +12 -0
- package/dist/components/LoginPage.svelte.d.ts.map +1 -1
- package/dist/components/ManageEditors.svelte +81 -0
- package/dist/components/ManageEditors.svelte.d.ts +23 -0
- package/dist/components/ManageEditors.svelte.d.ts.map +1 -0
- package/dist/components/MarkdownEditor.svelte +81 -0
- package/dist/components/MarkdownEditor.svelte.d.ts +20 -0
- package/dist/components/MarkdownEditor.svelte.d.ts.map +1 -0
- package/dist/components/NavTree.svelte +73 -63
- package/dist/components/NavTree.svelte.d.ts +13 -4
- package/dist/components/NavTree.svelte.d.ts.map +1 -1
- package/dist/components/cairn-admin.css +42 -0
- package/dist/components/index.d.ts +3 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +5 -4
- package/dist/content/compose.d.ts +7 -0
- package/dist/content/compose.d.ts.map +1 -0
- package/dist/content/compose.js +32 -0
- package/dist/content/concepts.d.ts +17 -0
- package/dist/content/concepts.d.ts.map +1 -0
- package/dist/content/concepts.js +41 -0
- package/dist/content/frontmatter.d.ts +18 -0
- package/dist/content/frontmatter.d.ts.map +1 -0
- package/dist/content/frontmatter.js +58 -0
- package/dist/content/ids.d.ts +17 -0
- package/dist/content/ids.d.ts.map +1 -0
- package/dist/content/ids.js +33 -0
- package/dist/content/types.d.ts +210 -0
- package/dist/content/types.d.ts.map +1 -0
- package/dist/content/types.js +1 -0
- package/dist/content/validate.d.ts +13 -0
- package/dist/content/validate.d.ts.map +1 -0
- package/dist/content/validate.js +45 -0
- package/dist/email.d.ts +25 -12
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +24 -24
- package/dist/env.d.ts +24 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +29 -0
- package/dist/github/credentials.d.ts +12 -0
- package/dist/github/credentials.d.ts.map +1 -0
- package/dist/github/credentials.js +11 -0
- package/dist/github/repo.d.ts +49 -0
- package/dist/github/repo.d.ts.map +1 -0
- package/dist/github/repo.js +123 -0
- package/dist/github/signing.d.ts +17 -0
- package/dist/github/signing.d.ts.map +1 -0
- package/dist/github/signing.js +79 -0
- package/dist/github/types.d.ts +35 -0
- package/dist/github/types.d.ts.map +1 -0
- package/dist/github/types.js +19 -0
- package/dist/index.d.ts +27 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -10
- package/dist/{nav.d.ts → nav/site-config.d.ts} +16 -24
- package/dist/nav/site-config.d.ts.map +1 -0
- package/dist/{nav.js → nav/site-config.js} +27 -13
- package/dist/render/glyph.d.ts +1 -1
- package/dist/render/glyph.d.ts.map +1 -1
- package/dist/render/index.d.ts +5 -5
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +6 -6
- package/dist/render/pipeline.d.ts +7 -6
- package/dist/render/pipeline.d.ts.map +1 -1
- package/dist/render/pipeline.js +5 -5
- package/dist/render/registry.d.ts +10 -6
- package/dist/render/registry.d.ts.map +1 -1
- package/dist/render/registry.js +8 -6
- package/dist/render/rehype-dispatch.d.ts +8 -7
- package/dist/render/rehype-dispatch.d.ts.map +1 -1
- package/dist/render/rehype-dispatch.js +16 -14
- package/dist/render/remark-directives.d.ts +1 -1
- package/dist/render/remark-directives.d.ts.map +1 -1
- package/dist/render/sanitize.d.ts +8 -0
- package/dist/render/sanitize.d.ts.map +1 -0
- package/dist/render/sanitize.js +26 -0
- package/dist/sveltekit/auth-routes.d.ts +23 -0
- package/dist/sveltekit/auth-routes.d.ts.map +1 -0
- package/dist/sveltekit/auth-routes.js +85 -0
- package/dist/sveltekit/content-routes.d.ts +80 -0
- package/dist/sveltekit/content-routes.d.ts.map +1 -0
- package/dist/sveltekit/content-routes.js +183 -0
- package/dist/sveltekit/editors-routes.d.ts +24 -0
- package/dist/sveltekit/editors-routes.d.ts.map +1 -0
- package/dist/sveltekit/editors-routes.js +73 -0
- package/dist/sveltekit/guard.d.ts +9 -0
- package/dist/sveltekit/guard.d.ts.map +1 -0
- package/dist/sveltekit/guard.js +43 -0
- package/dist/sveltekit/health.d.ts +19 -0
- package/dist/sveltekit/health.d.ts.map +1 -0
- package/dist/sveltekit/health.js +12 -0
- package/dist/sveltekit/index.d.ts +9 -173
- package/dist/sveltekit/index.d.ts.map +1 -1
- package/dist/sveltekit/index.js +8 -348
- package/dist/sveltekit/nav-routes.d.ts +30 -0
- package/dist/sveltekit/nav-routes.d.ts.map +1 -0
- package/dist/sveltekit/nav-routes.js +103 -0
- package/dist/sveltekit/types.d.ts +32 -0
- package/dist/sveltekit/types.d.ts.map +1 -0
- package/dist/sveltekit/types.js +1 -0
- package/package.json +33 -57
- package/src/lib/auth/crypto.ts +37 -0
- package/src/lib/auth/store.ts +158 -0
- package/src/lib/auth/types.ts +27 -0
- package/src/lib/components/AdminLayout.svelte +58 -164
- package/src/lib/components/ComponentPalette.svelte +36 -20
- package/src/lib/components/ConceptList.svelte +81 -0
- package/src/lib/components/ConfirmPage.svelte +23 -20
- package/src/lib/components/EditPage.svelte +155 -136
- package/src/lib/components/LoginPage.svelte +42 -52
- package/src/lib/components/ManageEditors.svelte +81 -0
- package/src/lib/components/MarkdownEditor.svelte +81 -0
- package/src/lib/components/NavTree.svelte +73 -63
- package/src/lib/components/cairn-admin.css +42 -0
- package/src/lib/components/index.ts +5 -4
- package/src/lib/content/compose.ts +39 -0
- package/src/lib/content/concepts.ts +57 -0
- package/src/lib/content/frontmatter.ts +71 -0
- package/src/lib/content/ids.ts +38 -0
- package/src/lib/content/types.ts +235 -0
- package/src/lib/content/validate.ts +51 -0
- package/src/lib/email.ts +52 -38
- package/src/lib/env.ts +32 -0
- package/src/lib/github/credentials.ts +27 -0
- package/src/lib/github/repo.ts +138 -0
- package/src/lib/github/signing.ts +97 -0
- package/src/lib/github/types.ts +46 -0
- package/src/lib/index.ts +86 -10
- package/src/lib/{nav.ts → nav/site-config.ts} +31 -24
- package/src/lib/render/glyph.ts +6 -6
- package/src/lib/render/index.ts +6 -6
- package/src/lib/render/pipeline.ts +23 -22
- package/src/lib/render/registry.ts +35 -26
- package/src/lib/render/rehype-dispatch.ts +58 -56
- package/src/lib/render/remark-directives.ts +46 -46
- package/src/lib/render/sanitize.ts +27 -0
- package/src/lib/sveltekit/auth-routes.ts +107 -0
- package/src/lib/sveltekit/content-routes.ts +261 -0
- package/src/lib/sveltekit/editors-routes.ts +82 -0
- package/src/lib/sveltekit/guard.ts +47 -0
- package/src/lib/sveltekit/health.ts +24 -0
- package/src/lib/sveltekit/index.ts +19 -512
- package/src/lib/sveltekit/nav-routes.ts +139 -0
- package/src/lib/sveltekit/types.ts +33 -0
- package/dist/adapter.d.ts +0 -93
- package/dist/adapter.d.ts.map +0 -1
- package/dist/adapter.js +0 -30
- package/dist/auth/admins.d.ts +0 -33
- package/dist/auth/admins.d.ts.map +0 -1
- package/dist/auth/admins.js +0 -90
- package/dist/auth/capabilities.d.ts +0 -7
- package/dist/auth/capabilities.d.ts.map +0 -1
- package/dist/auth/capabilities.js +0 -26
- package/dist/auth/config.d.ts +0 -2097
- package/dist/auth/config.d.ts.map +0 -1
- package/dist/auth/config.js +0 -78
- package/dist/auth/guard.d.ts +0 -34
- package/dist/auth/guard.d.ts.map +0 -1
- package/dist/auth/guard.js +0 -47
- package/dist/auth/index.d.ts +0 -5
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -7
- package/dist/auth/schema.d.ts +0 -750
- package/dist/auth/schema.d.ts.map +0 -1
- package/dist/auth/schema.js +0 -93
- package/dist/carta.d.ts +0 -39
- package/dist/carta.d.ts.map +0 -1
- package/dist/carta.js +0 -30
- package/dist/components/CollectionList.svelte +0 -96
- package/dist/components/CollectionList.svelte.d.ts +0 -8
- package/dist/components/CollectionList.svelte.d.ts.map +0 -1
- package/dist/components/ManageAdmins.svelte +0 -84
- package/dist/components/ManageAdmins.svelte.d.ts +0 -10
- package/dist/components/ManageAdmins.svelte.d.ts.map +0 -1
- package/dist/content.d.ts +0 -3
- package/dist/content.d.ts.map +0 -1
- package/dist/content.js +0 -10
- package/dist/editor.d.ts +0 -25
- package/dist/editor.d.ts.map +0 -1
- package/dist/editor.js +0 -20
- package/dist/frontmatter.d.ts +0 -3
- package/dist/frontmatter.d.ts.map +0 -1
- package/dist/frontmatter.js +0 -16
- package/dist/github.d.ts +0 -72
- package/dist/github.d.ts.map +0 -1
- package/dist/github.js +0 -171
- package/dist/nav.d.ts.map +0 -1
- package/dist/slug.d.ts +0 -7
- package/dist/slug.d.ts.map +0 -1
- package/dist/slug.js +0 -15
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -11
- package/src/lib/adapter.ts +0 -144
- package/src/lib/auth/admins.ts +0 -106
- package/src/lib/auth/capabilities.ts +0 -35
- package/src/lib/auth/config.ts +0 -108
- package/src/lib/auth/guard.ts +0 -60
- package/src/lib/auth/index.ts +0 -7
- package/src/lib/auth/schema.ts +0 -112
- package/src/lib/carta.ts +0 -59
- package/src/lib/components/CollectionList.svelte +0 -96
- package/src/lib/components/ManageAdmins.svelte +0 -84
- package/src/lib/content.ts +0 -11
- package/src/lib/editor.ts +0 -38
- package/src/lib/frontmatter.ts +0 -17
- package/src/lib/github.ts +0 -220
- package/src/lib/slug.ts +0 -16
- package/src/lib/utils.ts +0 -12
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/auth/config.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAK9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAU3D,2FAA2F;AAC3F,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4FAA4F;IAC5F,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0FAA0F;AAC1F,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,MAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAHz1hB;AAED,MAAM,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC"}
|
package/dist/auth/config.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// cairn-core: the better-auth instance. Auth is engine code (engine-fat rule), so the whole
|
|
2
|
-
// config lives here: Drizzle/D1 adapter, magic-link (POST-confirm-shaped send), admin roles.
|
|
3
|
-
// Instantiated PER REQUEST in hooks.server.ts (the D1 binding is request-scoped); the factory
|
|
4
|
-
// is cheap (no I/O at construction).
|
|
5
|
-
import { betterAuth } from 'better-auth';
|
|
6
|
-
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
|
|
7
|
-
import { drizzle } from 'drizzle-orm/d1';
|
|
8
|
-
import { magicLink, admin } from 'better-auth/plugins';
|
|
9
|
-
import { createAccessControl } from 'better-auth/plugins/access';
|
|
10
|
-
import { defaultStatements } from 'better-auth/plugins/admin/access';
|
|
11
|
-
import { sendMagicLink } from '../email';
|
|
12
|
-
import * as schema from './schema';
|
|
13
|
-
// Two-tier roles on the admin plugin's access-control system: `owner` holds every admin
|
|
14
|
-
// statement (manage editors, revoke sessions); `editor` holds none (content-only). `adminRoles`
|
|
15
|
-
// must name a role defined here, so owner (not the plugin's built-in `admin`) is the gate.
|
|
16
|
-
const ac = createAccessControl(defaultStatements);
|
|
17
|
-
const owner = ac.newRole(defaultStatements);
|
|
18
|
-
const editor = ac.newRole({});
|
|
19
|
-
/**
|
|
20
|
-
* The shared better-auth config. Kept separate from `createAuth` so the test harness can run
|
|
21
|
-
* the EXACT plugin set (allowlist semantics, expiry, POST-confirm send) over an in-memory
|
|
22
|
-
* SQLite instead of D1. `disableSignUp:true` makes the `user` table the editor allowlist:
|
|
23
|
-
* magic-link never auto-creates, so the only way in is the owner-gated admin `createUser`
|
|
24
|
-
* (see auth/admins.ts). `adminRoles:['owner']` lets owners (not the default `admin` role)
|
|
25
|
-
* drive the admin API. Tokens are stored hashed and consumed atomically on first verify
|
|
26
|
-
* (better-auth GHSA-hc7v-rggr-4hvx), single-use by construction (C1).
|
|
27
|
-
*/
|
|
28
|
-
export function buildAuth(opts) {
|
|
29
|
-
return betterAuth({
|
|
30
|
-
appName: opts.branding.siteName,
|
|
31
|
-
secret: opts.secret,
|
|
32
|
-
baseURL: opts.baseURL,
|
|
33
|
-
trustedOrigins: [opts.baseURL],
|
|
34
|
-
database: opts.database,
|
|
35
|
-
plugins: [
|
|
36
|
-
magicLink({
|
|
37
|
-
disableSignUp: true,
|
|
38
|
-
expiresIn: 600,
|
|
39
|
-
storeToken: 'hashed',
|
|
40
|
-
sendMagicLink: async ({ email, token }, ctx) => {
|
|
41
|
-
// Allowlist gate: better-auth always fires this callback (even for unknown emails, to
|
|
42
|
-
// avoid enumeration) and only blocks user creation at verify. So gate the actual send
|
|
43
|
-
// here. Never email a non-editor. The login UI shows neutral copy either way, so this
|
|
44
|
-
// leaks nothing; it just stops strangers receiving a dead link.
|
|
45
|
-
const existing = await ctx?.context.internalAdapter.findUserByEmail(email);
|
|
46
|
-
if (!existing?.user)
|
|
47
|
-
return;
|
|
48
|
-
await opts.sendLink(email, token);
|
|
49
|
-
},
|
|
50
|
-
}),
|
|
51
|
-
admin({ ac, roles: { owner, editor }, defaultRole: 'editor', adminRoles: ['owner'] }),
|
|
52
|
-
],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Build the per-request better-auth instance over the site's D1 binding. The magic-link email
|
|
57
|
-
* points at OUR confirm page carrying only the token; consumption happens when the user clicks
|
|
58
|
-
* "Confirm sign-in" there (a POST), never on a scanner GET (C2 / POST-confirm). The origin is
|
|
59
|
-
* config-derived (`PUBLIC_ORIGIN`/`BETTER_AUTH_URL`), never request-derived (H3).
|
|
60
|
-
*/
|
|
61
|
-
export function createAuth(env, branding) {
|
|
62
|
-
if (!env.AUTH_DB)
|
|
63
|
-
throw new Error('AUTH_DB (D1) binding is required');
|
|
64
|
-
const origin = env.PUBLIC_ORIGIN || env.BETTER_AUTH_URL || 'http://localhost';
|
|
65
|
-
const db = drizzle(env.AUTH_DB, { schema });
|
|
66
|
-
return buildAuth({
|
|
67
|
-
database: drizzleAdapter(db, { provider: 'sqlite', schema }),
|
|
68
|
-
baseURL: origin,
|
|
69
|
-
secret: env.AUTH_SECRET,
|
|
70
|
-
branding,
|
|
71
|
-
sendLink: async (email, token) => {
|
|
72
|
-
if (!env.EMAIL)
|
|
73
|
-
throw new Error('EMAIL binding is required to send magic links');
|
|
74
|
-
const link = `${origin}/admin/auth/confirm?token=${encodeURIComponent(token)}`;
|
|
75
|
-
await sendMagicLink(env.EMAIL, email, link, branding.siteName, branding.sender);
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}
|
package/dist/auth/guard.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Auth } from './config';
|
|
2
|
-
/** The session shape the whole admin reads: layout, guards, content fns, manage-editors. */
|
|
3
|
-
export interface CairnUser {
|
|
4
|
-
id: string;
|
|
5
|
-
email: string;
|
|
6
|
-
name: string;
|
|
7
|
-
role: 'owner' | 'editor';
|
|
8
|
-
}
|
|
9
|
-
/** Read the better-auth session into a cairn user (or null). */
|
|
10
|
-
export declare function loadSession(auth: Auth, request: Request): Promise<CairnUser | null>;
|
|
11
|
-
export declare function requireSession(user: CairnUser | null): CairnUser;
|
|
12
|
-
type ConfirmEvent = {
|
|
13
|
-
request: Request;
|
|
14
|
-
locals: {
|
|
15
|
-
auth: Auth;
|
|
16
|
-
};
|
|
17
|
-
url: URL;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* POST-confirm verification (C2). Invoked from the confirm page's POST action: proxies the
|
|
21
|
-
* token to better-auth's GET verify endpoint via the per-request handler, then forwards the
|
|
22
|
-
* resulting Set-Cookie(s) onto a 303 to /admin. Scanners GET the confirm *page* (nothing is
|
|
23
|
-
* consumed); only this explicit POST consumes the token.
|
|
24
|
-
*/
|
|
25
|
-
export declare function confirmSignIn(event: ConfirmEvent): Promise<Response>;
|
|
26
|
-
/** Sign out via better-auth, forwarding the session-clearing cookies, then 303 to login. */
|
|
27
|
-
export declare function signOut(event: {
|
|
28
|
-
request: Request;
|
|
29
|
-
locals: {
|
|
30
|
-
auth: Auth;
|
|
31
|
-
};
|
|
32
|
-
}): Promise<Response>;
|
|
33
|
-
export {};
|
|
34
|
-
//# sourceMappingURL=guard.d.ts.map
|
package/dist/auth/guard.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/lib/auth/guard.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAErC,4FAA4F;AAC5F,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1B;AAED,gEAAgE;AAChE,wBAAsB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAKzF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,CAGhE;AAED,KAAK,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;IAAC,GAAG,EAAE,GAAG,CAAA;CAAE,CAAC;AAE3E;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAa1E;AAED,4FAA4F;AAC5F,wBAAsB,OAAO,CAAC,KAAK,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAA;CAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAQpG"}
|
package/dist/auth/guard.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// cairn-core: server-side auth helpers the site route shims delegate to. Each takes the
|
|
2
|
-
// SvelteKit event, typed structurally so the package never depends on a site's generated
|
|
3
|
-
// `App.*` ambient types, plus the per-request `Auth` from `locals`.
|
|
4
|
-
import { redirect } from '@sveltejs/kit';
|
|
5
|
-
/** Read the better-auth session into a cairn user (or null). */
|
|
6
|
-
export async function loadSession(auth, request) {
|
|
7
|
-
const session = await auth.api.getSession({ headers: request.headers });
|
|
8
|
-
if (!session?.user)
|
|
9
|
-
return null;
|
|
10
|
-
const u = session.user;
|
|
11
|
-
return { id: u.id, email: u.email, name: u.name, role: u.role === 'owner' ? 'owner' : 'editor' };
|
|
12
|
-
}
|
|
13
|
-
export function requireSession(user) {
|
|
14
|
-
if (!user)
|
|
15
|
-
throw redirect(303, '/admin/login');
|
|
16
|
-
return user;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* POST-confirm verification (C2). Invoked from the confirm page's POST action: proxies the
|
|
20
|
-
* token to better-auth's GET verify endpoint via the per-request handler, then forwards the
|
|
21
|
-
* resulting Set-Cookie(s) onto a 303 to /admin. Scanners GET the confirm *page* (nothing is
|
|
22
|
-
* consumed); only this explicit POST consumes the token.
|
|
23
|
-
*/
|
|
24
|
-
export async function confirmSignIn(event) {
|
|
25
|
-
const form = await event.request.formData();
|
|
26
|
-
const token = String(form.get('token') ?? '');
|
|
27
|
-
if (!token)
|
|
28
|
-
throw redirect(303, '/admin/login?error=expired');
|
|
29
|
-
const verifyUrl = `${event.url.origin}/api/auth/magic-link/verify?token=${encodeURIComponent(token)}&callbackURL=/admin`;
|
|
30
|
-
const res = await event.locals.auth.handler(new Request(verifyUrl, { headers: event.request.headers }));
|
|
31
|
-
const cookies = res.headers.getSetCookie();
|
|
32
|
-
if (cookies.length === 0)
|
|
33
|
-
throw redirect(303, '/admin/login?error=expired');
|
|
34
|
-
const headers = new Headers({ location: '/admin' });
|
|
35
|
-
for (const cookie of cookies)
|
|
36
|
-
headers.append('set-cookie', cookie);
|
|
37
|
-
return new Response(null, { status: 303, headers });
|
|
38
|
-
}
|
|
39
|
-
/** Sign out via better-auth, forwarding the session-clearing cookies, then 303 to login. */
|
|
40
|
-
export async function signOut(event) {
|
|
41
|
-
const origin = new URL(event.request.url).origin;
|
|
42
|
-
const res = await event.locals.auth.handler(new Request(`${origin}/api/auth/sign-out`, { method: 'POST', headers: event.request.headers }));
|
|
43
|
-
const headers = new Headers({ location: '/admin/login' });
|
|
44
|
-
for (const cookie of res.headers.getSetCookie())
|
|
45
|
-
headers.append('set-cookie', cookie);
|
|
46
|
-
return new Response(null, { status: 303, headers });
|
|
47
|
-
}
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { createAuth, type Auth, type AuthEnv, type AuthBranding } from './config';
|
|
2
|
-
export { loadSession, requireSession, confirmSignIn, signOut, type CairnUser } from './guard';
|
|
3
|
-
export { adminsLoad, addAdmin, removeAdmin, setAdminRole, requireOwner, type AdminsData } from './admins';
|
|
4
|
-
export { can, requireCapability, type Capability } from './capabilities';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/auth/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC1G,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/auth/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Public surface of `@glw907/cairn-cms/auth`: the per-request factory + server-side helpers
|
|
2
|
-
// the site route shims and hooks delegate to. The browser client is intentionally NOT here
|
|
3
|
-
// (it lives component-local in LoginPage to keep better-auth's deep client types out of dist).
|
|
4
|
-
export { createAuth } from './config';
|
|
5
|
-
export { loadSession, requireSession, confirmSignIn, signOut } from './guard';
|
|
6
|
-
export { adminsLoad, addAdmin, removeAdmin, setAdminRole, requireOwner } from './admins';
|
|
7
|
-
export { can, requireCapability } from './capabilities';
|