@sovereignfs/create 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/README.md +10 -2
- package/dist/create.mjs +471 -0
- package/package.json +37 -3
- package/template/app/Dockerfile +29 -0
- package/template/app/README.md +48 -0
- package/template/app/_dockerignore +7 -0
- package/template/app/_env.example +9 -0
- package/template/app/_gitignore +7 -0
- package/template/app/_tsconfig.json +21 -0
- package/template/app/app/actions.ts +25 -0
- package/template/app/app/api/health/route.ts +16 -0
- package/template/app/app/auth/[action]/route.ts +7 -0
- package/template/app/app/globals.css +27 -0
- package/template/app/app/layout.tsx +14 -0
- package/template/app/app/page.tsx +49 -0
- package/template/app/app/ui.tsx +5 -0
- package/template/app/instrumentation.ts +7 -0
- package/template/app/lib/auth.ts +15 -0
- package/template/app/lib/config.ts +20 -0
- package/template/app/lib/crypto.ts +29 -0
- package/template/app/lib/db.ts +10 -0
- package/template/app/lib/migrate.ts +44 -0
- package/template/app/lib/sovereign.ts +13 -0
- package/template/app/lib/stores.ts +101 -0
- package/template/app/migrations/001_init.sql +27 -0
- package/template/app/next.config.mjs +8 -0
- package/template/app/scripts/manifest.mjs +25 -0
- package/template/app/sovereign.manifest.json +19 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// /auth/login, /auth/callback, /auth/logout, /auth/backchannel-logout and /auth/account-deleted: the addresses in sovereign.manifest.json.
|
|
2
|
+
import { auth } from '@/lib/auth';
|
|
3
|
+
|
|
4
|
+
export const dynamic = 'force-dynamic';
|
|
5
|
+
|
|
6
|
+
export const GET = (request: Request) => auth().handlers.GET(request);
|
|
7
|
+
export const POST = (request: Request) => auth().handlers.POST(request);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: var(--sv-font-family);
|
|
4
|
+
color: var(--sv-color-text-primary);
|
|
5
|
+
background: var(--sv-color-surface);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
main {
|
|
9
|
+
max-width: 40rem;
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
padding: var(--sv-space-6) var(--sv-space-4);
|
|
12
|
+
display: grid;
|
|
13
|
+
gap: var(--sv-space-4);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
form {
|
|
17
|
+
display: flex;
|
|
18
|
+
gap: var(--sv-space-2);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ul {
|
|
22
|
+
list-style: none;
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 0;
|
|
25
|
+
display: grid;
|
|
26
|
+
gap: var(--sv-space-2);
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Metadata } from 'next';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import '@sovereignfs/ui/tokens.css';
|
|
4
|
+
import './globals.css';
|
|
5
|
+
|
|
6
|
+
export const metadata: Metadata = { title: '__TITLE__' };
|
|
7
|
+
|
|
8
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
9
|
+
return (
|
|
10
|
+
<html lang="en">
|
|
11
|
+
<body>{children}</body>
|
|
12
|
+
</html>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { auth } from '@/lib/auth';
|
|
2
|
+
import { db } from '@/lib/db';
|
|
3
|
+
import { addNote, deleteNote } from './actions';
|
|
4
|
+
import { Button, Card, Input, PageHeader } from './ui';
|
|
5
|
+
|
|
6
|
+
// The page is for the person signed in, so it is made for each request.
|
|
7
|
+
export const dynamic = 'force-dynamic';
|
|
8
|
+
|
|
9
|
+
export default async function Home() {
|
|
10
|
+
// Sends a person to sign in with core, and back here.
|
|
11
|
+
const session = await auth().requireSession('/');
|
|
12
|
+
const { rows } = await db().query<{ id: string; body: string }>(
|
|
13
|
+
'SELECT id, body FROM notes WHERE owner = $1 ORDER BY id DESC LIMIT 100',
|
|
14
|
+
[session.sub],
|
|
15
|
+
);
|
|
16
|
+
const name = typeof session.claims.name === 'string' ? session.claims.name : 'there';
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<main>
|
|
20
|
+
<PageHeader title="__TITLE__" description={`Signed in as ${name}`} />
|
|
21
|
+
<Card>
|
|
22
|
+
<form action={addNote}>
|
|
23
|
+
<Input name="body" placeholder="A note" aria-label="A note" maxLength={2000} required />
|
|
24
|
+
<Button type="submit">Add</Button>
|
|
25
|
+
</form>
|
|
26
|
+
</Card>
|
|
27
|
+
<ul>
|
|
28
|
+
{rows.map((note) => (
|
|
29
|
+
<li key={note.id}>
|
|
30
|
+
<Card>
|
|
31
|
+
<form action={deleteNote}>
|
|
32
|
+
<span style={{ flex: 1 }}>{note.body}</span>
|
|
33
|
+
<input type="hidden" name="id" value={note.id} />
|
|
34
|
+
<Button type="submit" variant="ghost" size="sm">
|
|
35
|
+
Delete
|
|
36
|
+
</Button>
|
|
37
|
+
</form>
|
|
38
|
+
</Card>
|
|
39
|
+
</li>
|
|
40
|
+
))}
|
|
41
|
+
</ul>
|
|
42
|
+
<form action="/auth/logout" method="post">
|
|
43
|
+
<Button type="submit" variant="secondary">
|
|
44
|
+
Sign out
|
|
45
|
+
</Button>
|
|
46
|
+
</form>
|
|
47
|
+
</main>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// `@sovereignfs/ui` is one bundle with components that use React context, so a Server Component cannot import it directly. It is
|
|
4
|
+
// re-exported from here, a Client Component module, and pages import the parts they use from "./ui". They still render on the server.
|
|
5
|
+
export { Button, Card, Input, PageHeader } from '@sovereignfs/ui';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Runs once when the server starts. The app applies its own migrations before it takes a request (spec/app-manifest.md §4). */
|
|
2
|
+
export async function register() {
|
|
3
|
+
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
|
4
|
+
const { migrate } = await import('./lib/migrate');
|
|
5
|
+
await migrate();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { nextAuth } from '@sovereignfs/sdk/next';
|
|
2
|
+
import { db } from './db';
|
|
3
|
+
import { sovereign } from './sovereign';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sign-in for this app (docs/using-the-sdk.md). When a person deletes their account on the instance, core tells the app and keeps
|
|
7
|
+
* telling it until it answers 200, which the SDK sends only after this function has finished. It must be safe to run twice.
|
|
8
|
+
*/
|
|
9
|
+
export const auth = () =>
|
|
10
|
+
nextAuth(sovereign(), {
|
|
11
|
+
onAccountDeleted: async ({ sub }) => {
|
|
12
|
+
await db().query('DELETE FROM notes WHERE owner = $1', [sub]);
|
|
13
|
+
// The SDK has already ended the person's sessions and forgotten their refresh token.
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reads a setting the instance gives this app (spec/app-manifest.md §3). A secret arrives as a file named by `NAME_FILE`, so it is
|
|
5
|
+
* never in the process list or a log; the plain `NAME` is read as well, for running it on your own machine.
|
|
6
|
+
*/
|
|
7
|
+
export function setting(name: string): string | undefined {
|
|
8
|
+
const file = process.env[`${name}_FILE`];
|
|
9
|
+
if (file) return readFileSync(file, 'utf8').replace(/\r?\n$/, '');
|
|
10
|
+
return process.env[name] || undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function required(name: string): string {
|
|
14
|
+
const value = setting(name);
|
|
15
|
+
if (!value)
|
|
16
|
+
throw new Error(
|
|
17
|
+
`${name} is not set. The instance gives it to the app; see .env.example to run it yourself.`,
|
|
18
|
+
);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, createHash, randomBytes, scryptSync } from 'node:crypto';
|
|
2
|
+
import { required } from './config';
|
|
3
|
+
|
|
4
|
+
let key: Buffer | undefined;
|
|
5
|
+
|
|
6
|
+
/** The key a person's refresh token is kept under: derived from `__PREFIX___AUTH_SECRET`, which the instance made once and keeps. */
|
|
7
|
+
function secretKey(): Buffer {
|
|
8
|
+
key ??= scryptSync(required('__PREFIX___AUTH_SECRET'), '__NAME__ refresh tokens', 32);
|
|
9
|
+
return key;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A refresh token is a credential, so it is kept encrypted, with AES-256-GCM and a fresh nonce each time. */
|
|
13
|
+
export function seal(plain: string): string {
|
|
14
|
+
const nonce = randomBytes(12);
|
|
15
|
+
const cipher = createCipheriv('aes-256-gcm', secretKey(), nonce);
|
|
16
|
+
const body = Buffer.concat([cipher.update(plain, 'utf8'), cipher.final()]);
|
|
17
|
+
return Buffer.concat([nonce, cipher.getAuthTag(), body]).toString('base64');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function open(sealed: string): string {
|
|
21
|
+
const bytes = Buffer.from(sealed, 'base64');
|
|
22
|
+
const decipher = createDecipheriv('aes-256-gcm', secretKey(), bytes.subarray(0, 12));
|
|
23
|
+
decipher.setAuthTag(bytes.subarray(12, 28));
|
|
24
|
+
return Buffer.concat([decipher.update(bytes.subarray(28)), decipher.final()]).toString('utf8');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** What the conditional update compares, since the ciphertext differs every time it is made. */
|
|
28
|
+
export const fingerprint = (token: string): string =>
|
|
29
|
+
createHash('sha256').update(token).digest('hex');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
import { required } from './config';
|
|
3
|
+
|
|
4
|
+
let pool: Pool | undefined;
|
|
5
|
+
|
|
6
|
+
/** The app's own database, as its own role. One pool for the process, made when it is first used so that building needs none. */
|
|
7
|
+
export function db(): Pool {
|
|
8
|
+
pool ??= new Pool({ connectionString: required('__PREFIX___POSTGRES_URL'), max: 10 });
|
|
9
|
+
return pool;
|
|
10
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { db } from './db';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies the files in `migrations/`, in name order, each once (spec/app-manifest.md §4: an app applies its own migrations when it
|
|
7
|
+
* starts, and is safe to start again). One advisory lock holds a second copy of the app back until the first has finished.
|
|
8
|
+
*/
|
|
9
|
+
export async function migrate(): Promise<void> {
|
|
10
|
+
const client = await db().connect();
|
|
11
|
+
try {
|
|
12
|
+
await client.query('SELECT pg_advisory_lock(hashtext($1))', ['__NAME__-migrations']);
|
|
13
|
+
await client.query(
|
|
14
|
+
'CREATE TABLE IF NOT EXISTS schema_migrations (name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())',
|
|
15
|
+
);
|
|
16
|
+
const done = new Set(
|
|
17
|
+
(await client.query<{ name: string }>('SELECT name FROM schema_migrations')).rows.map(
|
|
18
|
+
(row) => row.name,
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
const folder = path.join(process.cwd(), 'migrations');
|
|
22
|
+
for (const file of readdirSync(folder)
|
|
23
|
+
.filter((name) => name.endsWith('.sql'))
|
|
24
|
+
.sort()) {
|
|
25
|
+
if (done.has(file)) continue;
|
|
26
|
+
await client.query('BEGIN');
|
|
27
|
+
try {
|
|
28
|
+
await client.query(readFileSync(path.join(folder, file), 'utf8'));
|
|
29
|
+
await client.query('INSERT INTO schema_migrations (name) VALUES ($1)', [file]);
|
|
30
|
+
await client.query('COMMIT');
|
|
31
|
+
} catch (error) {
|
|
32
|
+
await client.query('ROLLBACK');
|
|
33
|
+
throw new Error(
|
|
34
|
+
`The migration ${file} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} finally {
|
|
39
|
+
await client
|
|
40
|
+
.query('SELECT pg_advisory_unlock(hashtext($1))', ['__NAME__-migrations'])
|
|
41
|
+
.catch(() => undefined);
|
|
42
|
+
client.release();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createSovereign, type Sovereign } from '@sovereignfs/sdk';
|
|
2
|
+
import { sessionStore, tokenStore } from './stores';
|
|
3
|
+
|
|
4
|
+
let client: Sovereign | undefined;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one client for this process. It reads __PREFIX___URL, __PREFIX___CORE_URL, __PREFIX___CORE_CLIENT_ID and __PREFIX___CORE_CLIENT_SECRET,
|
|
8
|
+
* makes no call to core, and is made when first used, so building the app needs none of them.
|
|
9
|
+
*/
|
|
10
|
+
export function sovereign(): Sovereign {
|
|
11
|
+
client ??= createSovereign({ prefix: '__PREFIX__', sessionStore, tokenStore });
|
|
12
|
+
return client;
|
|
13
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { SessionStore, StoredRecord, TokenStore } from '@sovereignfs/sdk';
|
|
2
|
+
import { db } from './db';
|
|
3
|
+
import { fingerprint, open, seal } from './crypto';
|
|
4
|
+
|
|
5
|
+
/** The SDK's sessions, in the app's database (sdk §9.1). Nothing is returned after its expiry. */
|
|
6
|
+
export const sessionStore: SessionStore = {
|
|
7
|
+
async get(id) {
|
|
8
|
+
const { rows } = await db().query<{
|
|
9
|
+
kind: StoredRecord['kind'];
|
|
10
|
+
sub: string | null;
|
|
11
|
+
sid: string | null;
|
|
12
|
+
data: Record<string, unknown>;
|
|
13
|
+
}>('SELECT kind, sub, sid, data FROM sv_sessions WHERE id = $1 AND expires_at > $2', [
|
|
14
|
+
id,
|
|
15
|
+
Date.now(),
|
|
16
|
+
]);
|
|
17
|
+
const row = rows[0];
|
|
18
|
+
if (!row) return undefined;
|
|
19
|
+
return {
|
|
20
|
+
kind: row.kind,
|
|
21
|
+
...(row.sub ? { sub: row.sub } : {}),
|
|
22
|
+
...(row.sid ? { sid: row.sid } : {}),
|
|
23
|
+
data: row.data,
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
async set(id, record, expiresAt) {
|
|
28
|
+
await db().query(
|
|
29
|
+
`INSERT INTO sv_sessions (id, kind, sub, sid, data, expires_at) VALUES ($1, $2, $3, $4, $5, $6)
|
|
30
|
+
ON CONFLICT (id) DO UPDATE SET kind = $2, sub = $3, sid = $4, data = $5, expires_at = $6`,
|
|
31
|
+
[
|
|
32
|
+
id,
|
|
33
|
+
record.kind,
|
|
34
|
+
record.sub ?? null,
|
|
35
|
+
record.sid ?? null,
|
|
36
|
+
JSON.stringify(record.data),
|
|
37
|
+
expiresAt,
|
|
38
|
+
],
|
|
39
|
+
);
|
|
40
|
+
// What has expired is of no use to anyone; a small share of writes clears it.
|
|
41
|
+
if (Math.random() < 0.02)
|
|
42
|
+
await db().query('DELETE FROM sv_sessions WHERE expires_at <= $1', [Date.now()]);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
async delete(id) {
|
|
46
|
+
await db().query('DELETE FROM sv_sessions WHERE id = $1', [id]);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
async deleteMatching(match) {
|
|
50
|
+
if (match.sub !== undefined)
|
|
51
|
+
await db().query('DELETE FROM sv_sessions WHERE sub = $1', [match.sub]);
|
|
52
|
+
if (match.sid !== undefined)
|
|
53
|
+
await db().query('DELETE FROM sv_sessions WHERE sid = $1', [match.sid]);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A person's refresh token, encrypted. Core rotates it on every use and takes one used twice for theft, so `write` is a conditional
|
|
59
|
+
* update, and `lock` holds a database lock so that two copies of the app never refresh at once (sdk §5.1).
|
|
60
|
+
*/
|
|
61
|
+
export const tokenStore: TokenStore = {
|
|
62
|
+
async read(sub) {
|
|
63
|
+
const { rows } = await db().query<{ sealed: string }>(
|
|
64
|
+
'SELECT sealed FROM sv_tokens WHERE sub = $1',
|
|
65
|
+
[sub],
|
|
66
|
+
);
|
|
67
|
+
return rows[0] ? open(rows[0].sealed) : undefined;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async write(sub, next, previous) {
|
|
71
|
+
if (previous === undefined) {
|
|
72
|
+
const done = await db().query(
|
|
73
|
+
'INSERT INTO sv_tokens (sub, sealed, fingerprint) VALUES ($1, $2, $3) ON CONFLICT (sub) DO NOTHING',
|
|
74
|
+
[sub, seal(next), fingerprint(next)],
|
|
75
|
+
);
|
|
76
|
+
return done.rowCount === 1;
|
|
77
|
+
}
|
|
78
|
+
const done = await db().query(
|
|
79
|
+
'UPDATE sv_tokens SET sealed = $2, fingerprint = $3 WHERE sub = $1 AND fingerprint = $4',
|
|
80
|
+
[sub, seal(next), fingerprint(next), fingerprint(previous)],
|
|
81
|
+
);
|
|
82
|
+
return done.rowCount === 1;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
async lock(sub, work) {
|
|
86
|
+
const client = await db().connect();
|
|
87
|
+
try {
|
|
88
|
+
await client.query('SELECT pg_advisory_lock(hashtext($1))', [`__NAME__-token:${sub}`]);
|
|
89
|
+
return await work();
|
|
90
|
+
} finally {
|
|
91
|
+
await client
|
|
92
|
+
.query('SELECT pg_advisory_unlock(hashtext($1))', [`__NAME__-token:${sub}`])
|
|
93
|
+
.catch(() => undefined);
|
|
94
|
+
client.release();
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async delete(sub) {
|
|
99
|
+
await db().query('DELETE FROM sv_tokens WHERE sub = $1', [sub]);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- What the SDK needs the app to keep (docs/using-the-sdk.md §2), and one table of the app's own to show it.
|
|
2
|
+
|
|
3
|
+
CREATE TABLE sv_sessions (
|
|
4
|
+
id text PRIMARY KEY,
|
|
5
|
+
kind text NOT NULL,
|
|
6
|
+
sub text,
|
|
7
|
+
sid text,
|
|
8
|
+
data jsonb NOT NULL,
|
|
9
|
+
expires_at bigint NOT NULL
|
|
10
|
+
);
|
|
11
|
+
CREATE INDEX sv_sessions_sub ON sv_sessions (sub);
|
|
12
|
+
CREATE INDEX sv_sessions_sid ON sv_sessions (sid);
|
|
13
|
+
CREATE INDEX sv_sessions_expires ON sv_sessions (expires_at);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE sv_tokens (
|
|
16
|
+
sub text PRIMARY KEY,
|
|
17
|
+
sealed text NOT NULL,
|
|
18
|
+
fingerprint text NOT NULL
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE TABLE notes (
|
|
22
|
+
id bigserial PRIMARY KEY,
|
|
23
|
+
owner text NOT NULL,
|
|
24
|
+
body text NOT NULL,
|
|
25
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX notes_owner ON notes (owner, id DESC);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @type {import('next').NextConfig} */
|
|
2
|
+
export default {
|
|
3
|
+
// One self-contained server in .next/standalone: what the image runs (see the Dockerfile).
|
|
4
|
+
output: 'standalone',
|
|
5
|
+
// The database driver is loaded by the server and not bundled into it.
|
|
6
|
+
serverExternalPackages: ['pg'],
|
|
7
|
+
poweredByHeader: false,
|
|
8
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The manifest label in the Dockerfile is what an instance reads to host this app, so it must say what sovereign.manifest.json says.
|
|
2
|
+
// node scripts/manifest.mjs checks that it does
|
|
3
|
+
// node scripts/manifest.mjs --write copies the manifest into the label
|
|
4
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
+
|
|
6
|
+
const PREFIX = 'LABEL io.github.sovereignfs.app-manifest=';
|
|
7
|
+
const manifest = JSON.parse(readFileSync('sovereign.manifest.json', 'utf8'));
|
|
8
|
+
// A Dockerfile quotes a value as JSON quotes a string, so the label is the manifest as a JSON string of JSON.
|
|
9
|
+
const wanted = `${PREFIX}${JSON.stringify(JSON.stringify(manifest))}`;
|
|
10
|
+
const lines = readFileSync('Dockerfile', 'utf8').split('\n');
|
|
11
|
+
const at = lines.findIndex((line) => line.startsWith(PREFIX));
|
|
12
|
+
|
|
13
|
+
if (process.argv.includes('--write')) {
|
|
14
|
+
if (at === -1) lines.push(wanted);
|
|
15
|
+
else lines[at] = wanted;
|
|
16
|
+
writeFileSync('Dockerfile', lines.join('\n'));
|
|
17
|
+
console.log('Wrote the manifest label.');
|
|
18
|
+
} else if (lines[at] !== wanted) {
|
|
19
|
+
console.error(
|
|
20
|
+
'The manifest label in the Dockerfile differs from sovereign.manifest.json. Run: npm run manifest:write',
|
|
21
|
+
);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
} else {
|
|
24
|
+
console.log('The manifest label matches.');
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest": 1,
|
|
3
|
+
"prefix": "__PREFIX__",
|
|
4
|
+
"name": "__TITLE__",
|
|
5
|
+
"description": "Notes, as a starting point for an app on a Sovereign instance",
|
|
6
|
+
"port": 3000,
|
|
7
|
+
"health": "/api/health",
|
|
8
|
+
"launch": "/",
|
|
9
|
+
"signIn": {
|
|
10
|
+
"redirect": ["/auth/callback"],
|
|
11
|
+
"postLogout": ["/"],
|
|
12
|
+
"backChannel": "/auth/backchannel-logout",
|
|
13
|
+
"accountDeleted": "/auth/account-deleted",
|
|
14
|
+
"scopes": ["openid", "profile", "email", "offline_access"]
|
|
15
|
+
},
|
|
16
|
+
"database": true,
|
|
17
|
+
"generate": ["__PREFIX___AUTH_SECRET"],
|
|
18
|
+
"core": ">=0.49.0 <1.0.0"
|
|
19
|
+
}
|