@sovereignfs/create 0.13.0 → 0.17.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 (33) hide show
  1. package/README.md +13 -1
  2. package/dist/create.mjs +910 -47
  3. package/package.json +1 -1
  4. package/template/app/AGENTS.md +49 -0
  5. package/template/app/CHANGELOG.md +11 -0
  6. package/template/app/CLAUDE.md +9 -0
  7. package/template/app/CONTRIBUTING.md +41 -27
  8. package/template/app/README.md +5 -1
  9. package/template/app/RELEASING.md +31 -0
  10. package/template/app/_github/repository.json +50 -0
  11. package/template/app/_github/workflows/ci.yml +11 -3
  12. package/template/app/_github/workflows/promotion.yml +24 -0
  13. package/template/app/_github/workflows/publish.yml +56 -7
  14. package/template/app/_github/workflows/release.yml +40 -0
  15. package/template/components/RELEASING.md +27 -0
  16. package/template/encryption/ENCRYPTION.md +30 -0
  17. package/template/encryption/app/actions.ts +20 -0
  18. package/template/encryption/app/api/me/keys/route.ts +21 -0
  19. package/template/encryption/app/api/notes/[id]/route.ts +39 -0
  20. package/template/encryption/app/api/notes/route.ts +36 -0
  21. package/template/encryption/app/api/people/[sub]/keys/route.ts +26 -0
  22. package/template/encryption/app/api/people/route.ts +22 -0
  23. package/template/encryption/app/keys/return/page.tsx +11 -0
  24. package/template/encryption/app/keys/return/received.tsx +36 -0
  25. package/template/encryption/app/notes.tsx +529 -0
  26. package/template/encryption/app/page.tsx +71 -0
  27. package/template/encryption/app/ui.tsx +14 -0
  28. package/template/encryption/lib/auth.ts +19 -0
  29. package/template/encryption/lib/keys.ts +14 -0
  30. package/template/encryption/lib/notes.ts +201 -0
  31. package/template/encryption/lib/sovereign.ts +21 -0
  32. package/template/encryption/migrations/001_init.sql +39 -0
  33. package/template/encryption/sovereign.manifest.json +21 -0
@@ -0,0 +1,39 @@
1
+ import { auth } from '@/lib/auth';
2
+ import { refuseCrossOrigin, unauthorised } from '@/lib/files';
3
+ import { checkWrite, NoteError, notes } from '@/lib/notes';
4
+
5
+ export const dynamic = 'force-dynamic';
6
+
7
+ type Context = { params: Promise<{ id: string }> };
8
+
9
+ const refused = (error: unknown) =>
10
+ error instanceof NoteError
11
+ ? Response.json({ error: error.message }, { status: error.status })
12
+ : undefined;
13
+
14
+ /** Writes one of the signed-in person's notes, new or changed, with everyone who may read it: what the browser encrypted, as it is. */
15
+ export async function PUT(request: Request, { params }: Context) {
16
+ const cross = refuseCrossOrigin(request);
17
+ if (cross) return cross;
18
+ const session = await auth().getSession();
19
+ if (!session) return unauthorised();
20
+ try {
21
+ const note = checkWrite(session.sub, (await params).id, await request.json().catch(() => null));
22
+ await notes().save(session.sub, note);
23
+ return new Response(null, { status: 204 });
24
+ } catch (error) {
25
+ const answer = refused(error);
26
+ if (answer) return answer;
27
+ throw error;
28
+ }
29
+ }
30
+
31
+ /** Deletes one of the signed-in person's notes, and every key sealed for it. */
32
+ export async function DELETE(request: Request, { params }: Context) {
33
+ const cross = refuseCrossOrigin(request);
34
+ if (cross) return cross;
35
+ const session = await auth().getSession();
36
+ if (!session) return unauthorised();
37
+ const removed = await notes().remove(session.sub, (await params).id);
38
+ return new Response(null, { status: removed ? 204 : 404 });
39
+ }
@@ -0,0 +1,36 @@
1
+ import { auth } from '@/lib/auth';
2
+ import { unauthorised } from '@/lib/files';
3
+ import { notes } from '@/lib/notes';
4
+ import { sovereign } from '@/lib/sovereign';
5
+
6
+ export const dynamic = 'force-dynamic';
7
+
8
+ /**
9
+ * The notes the signed-in person can read, encrypted as the browser stored them, with the names of the people they involve (from the
10
+ * instance's Directory) so the page can say who shared what with whom. Nothing here opens a note.
11
+ */
12
+ export async function GET() {
13
+ const session = await auth().getSession();
14
+ if (!session) return unauthorised();
15
+ const list = await notes().list(session.sub);
16
+ const subs = [
17
+ ...new Set(
18
+ list.flatMap((note) => [note.owner, ...note.readers]).filter((s) => s !== session.sub),
19
+ ),
20
+ ];
21
+ let names: Record<string, string> = {};
22
+ if (subs.length > 0) {
23
+ try {
24
+ const { users } = await sovereign()
25
+ .as({ sub: session.sub })
26
+ .directory.resolveUsers({ subs: subs.slice(0, 100) });
27
+ names = Object.fromEntries(users.map((user) => [user.sub, user.name]));
28
+ } catch {
29
+ // Without the Directory the page names nobody, and still opens every note.
30
+ }
31
+ }
32
+ return Response.json(
33
+ { me: session.sub, notes: list, names },
34
+ { headers: { 'cache-control': 'no-store' } },
35
+ );
36
+ }
@@ -0,0 +1,26 @@
1
+ import { CoreApiError } from '@sovereignfs/sdk';
2
+ import { auth } from '@/lib/auth';
3
+ import { unauthorised } from '@/lib/files';
4
+ import { sovereign } from '@/lib/sovereign';
5
+
6
+ export const dynamic = 'force-dynamic';
7
+
8
+ /**
9
+ * Another person's public keys for this app, from core (sdk §8): what the page checks, then seals a note's key to. A 404 when they have
10
+ * never opened this app, since their keys are made then. The page checks the account's signature itself; it does not trust this route.
11
+ */
12
+ export async function GET(_request: Request, { params }: { params: Promise<{ sub: string }> }) {
13
+ const session = await auth().getSession();
14
+ if (!session) return unauthorised();
15
+ try {
16
+ const keys = await sovereign()
17
+ .as({ sub: session.sub })
18
+ .keys.person((await params).sub);
19
+ return Response.json(keys, { headers: { 'cache-control': 'no-store' } });
20
+ } catch (error) {
21
+ if (error instanceof CoreApiError && error.status === 404) {
22
+ return Response.json({ error: 'not-opened' }, { status: 404 });
23
+ }
24
+ throw error;
25
+ }
26
+ }
@@ -0,0 +1,22 @@
1
+ import { auth } from '@/lib/auth';
2
+ import { unauthorised } from '@/lib/files';
3
+ import { sovereign } from '@/lib/sovereign';
4
+
5
+ export const dynamic = 'force-dynamic';
6
+
7
+ /** People on the instance to share with, found by name (or a whole address) in its Directory, as the signed-in person. */
8
+ export async function GET(request: Request) {
9
+ const session = await auth().getSession();
10
+ if (!session) return unauthorised();
11
+ const q = (new URL(request.url).searchParams.get('q') ?? '').trim().slice(0, 100);
12
+ if (q.length < 2) return Response.json({ people: [] });
13
+ const { users } = await sovereign().as({ sub: session.sub }).directory.searchUsers({ q });
14
+ return Response.json(
15
+ {
16
+ people: users
17
+ .filter((user) => user.sub !== session.sub)
18
+ .map((user) => ({ sub: user.sub, name: user.name })),
19
+ },
20
+ { headers: { 'cache-control': 'no-store' } },
21
+ );
22
+ }
@@ -0,0 +1,11 @@
1
+ import { auth } from '@/lib/auth';
2
+ import { keySettings } from '@/lib/keys';
3
+ import { Received } from './received';
4
+
5
+ export const dynamic = 'force-dynamic';
6
+
7
+ /** The key return address (`encryption.return` in the manifest): core sends the person back here with the app's key, sealed. */
8
+ export default async function KeyReturn() {
9
+ await auth().requireSession('/');
10
+ return <Received {...keySettings()} />;
11
+ }
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+
3
+ import { appKeys } from '@sovereignfs/sdk/keys';
4
+ import { useRouter } from 'next/navigation';
5
+ import { useEffect, useState } from 'react';
6
+ import { Alert, Button, Card } from '../../ui';
7
+
8
+ /** Takes core's answer from the address, checks it and keeps the key (sdk §9.3), then goes back to where the person was. */
9
+ export function Received(props: { core: string; clientId: string; returnTo: string }) {
10
+ const router = useRouter();
11
+ const [failed, setFailed] = useState(false);
12
+
13
+ useEffect(() => {
14
+ const keys = appKeys(props);
15
+ keys
16
+ .receive()
17
+ .then((received) => (received.ok ? router.replace(received.returnPath) : setFailed(true)))
18
+ .catch(() => setFailed(true));
19
+ // Once, when the page loads: the answer is in the address only until it is read.
20
+ }, []);
21
+
22
+ if (!failed)
23
+ return (
24
+ <Card>
25
+ <h1>Unlocking…</h1>
26
+ <p>Taking you back to where you were.</p>
27
+ </Card>
28
+ );
29
+ return (
30
+ <Alert variant="error" heading="Couldn’t unlock">
31
+ <p>Try again.</p>
32
+ <Button onClick={() => void appKeys(props).unlock('/')}>Try again</Button>{' '}
33
+ <a href="/">Back to your notes</a>
34
+ </Alert>
35
+ );
36
+ }