@poli-page/cli 0.9.0 → 0.11.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.
- package/README.md +287 -134
- package/dist/api-client.d.ts +117 -93
- package/dist/api-client.d.ts.map +1 -1
- package/dist/api-client.js +99 -115
- package/dist/api-client.js.map +1 -1
- package/dist/api-origin.d.ts +28 -0
- package/dist/api-origin.d.ts.map +1 -0
- package/dist/api-origin.js +84 -0
- package/dist/api-origin.js.map +1 -0
- package/dist/auth.d.ts +14 -4
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +22 -13
- package/dist/auth.js.map +1 -1
- package/dist/cloud-context.d.ts +8 -2
- package/dist/cloud-context.d.ts.map +1 -1
- package/dist/cloud-context.js +16 -34
- package/dist/cloud-context.js.map +1 -1
- package/dist/cloud-link.d.ts +41 -0
- package/dist/cloud-link.d.ts.map +1 -0
- package/dist/cloud-link.js +112 -0
- package/dist/cloud-link.js.map +1 -0
- package/dist/commands/auth.d.ts +31 -8
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +77 -25
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/dev.d.ts +6 -6
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +55 -103
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/documents/delete.d.ts.map +1 -1
- package/dist/commands/documents/delete.js +2 -9
- package/dist/commands/documents/delete.js.map +1 -1
- package/dist/commands/documents/document-id.d.ts +2 -0
- package/dist/commands/documents/document-id.d.ts.map +1 -0
- package/dist/commands/documents/document-id.js +10 -0
- package/dist/commands/documents/document-id.js.map +1 -0
- package/dist/commands/documents/get.d.ts +4 -0
- package/dist/commands/documents/get.d.ts.map +1 -1
- package/dist/commands/documents/get.js +5 -14
- package/dist/commands/documents/get.js.map +1 -1
- package/dist/commands/documents/preview.d.ts +1 -0
- package/dist/commands/documents/preview.d.ts.map +1 -1
- package/dist/commands/documents/preview.js +89 -14
- package/dist/commands/documents/preview.js.map +1 -1
- package/dist/commands/documents/thumbnails.d.ts.map +1 -1
- package/dist/commands/documents/thumbnails.js +35 -20
- package/dist/commands/documents/thumbnails.js.map +1 -1
- package/dist/commands/env.d.ts +3 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +212 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +35 -37
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/link.d.ts +6 -0
- package/dist/commands/link.d.ts.map +1 -1
- package/dist/commands/link.js +68 -35
- package/dist/commands/link.js.map +1 -1
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +13 -6
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/publish.d.ts +22 -0
- package/dist/commands/publish.d.ts.map +1 -0
- package/dist/commands/publish.js +179 -0
- package/dist/commands/publish.js.map +1 -0
- package/dist/commands/render.d.ts +27 -11
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +140 -61
- package/dist/commands/render.js.map +1 -1
- package/dist/commands/watch.d.ts +3 -0
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +7 -1
- package/dist/commands/watch.js.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/credentials.d.ts +10 -0
- package/dist/credentials.d.ts.map +1 -1
- package/dist/credentials.js +27 -15
- package/dist/credentials.js.map +1 -1
- package/dist/dev-page.d.ts +12 -5
- package/dist/dev-page.d.ts.map +1 -1
- package/dist/dev-page.js +30 -68
- package/dist/dev-page.js.map +1 -1
- package/dist/dev-server.d.ts +19 -0
- package/dist/dev-server.d.ts.map +1 -1
- package/dist/dev-server.js +70 -8
- package/dist/dev-server.js.map +1 -1
- package/dist/environment-name.d.ts +8 -0
- package/dist/environment-name.d.ts.map +1 -0
- package/dist/environment-name.js +21 -0
- package/dist/environment-name.js.map +1 -0
- package/dist/exit-codes.d.ts +4 -0
- package/dist/exit-codes.d.ts.map +1 -1
- package/dist/exit-codes.js +25 -15
- package/dist/exit-codes.js.map +1 -1
- package/dist/file-watcher.d.ts +4 -1
- package/dist/file-watcher.d.ts.map +1 -1
- package/dist/file-watcher.js +26 -11
- package/dist/file-watcher.js.map +1 -1
- package/dist/format-resolver.d.ts +6 -0
- package/dist/format-resolver.d.ts.map +1 -1
- package/dist/format-resolver.js +14 -6
- package/dist/format-resolver.js.map +1 -1
- package/dist/manifest.d.ts +16 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +62 -6
- package/dist/manifest.js.map +1 -1
- package/dist/manifest.schema.d.ts +4 -4
- package/dist/manifest.schema.d.ts.map +1 -1
- package/dist/manifest.schema.js +40 -16
- package/dist/manifest.schema.js.map +1 -1
- package/dist/output.d.ts +5 -0
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +7 -0
- package/dist/output.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +53 -27
- package/dist/program.js.map +1 -1
- package/dist/project-files.d.ts +30 -0
- package/dist/project-files.d.ts.map +1 -0
- package/dist/project-files.js +75 -0
- package/dist/project-files.js.map +1 -0
- package/dist/project-loader.d.ts +6 -3
- package/dist/project-loader.d.ts.map +1 -1
- package/dist/project-loader.js +36 -61
- package/dist/project-loader.js.map +1 -1
- package/dist/project-sync.d.ts +37 -3
- package/dist/project-sync.d.ts.map +1 -1
- package/dist/project-sync.js +170 -84
- package/dist/project-sync.js.map +1 -1
- package/dist/security/paths.d.ts +29 -0
- package/dist/security/paths.d.ts.map +1 -0
- package/dist/security/paths.js +109 -0
- package/dist/security/paths.js.map +1 -0
- package/dist/sync-engine.d.ts +3 -3
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/sync-engine.js +4 -3
- package/dist/sync-engine.js.map +1 -1
- package/dist/template-importer.d.ts.map +1 -1
- package/dist/template-importer.js +170 -59
- package/dist/template-importer.js.map +1 -1
- package/dist/template-prompt.d.ts +8 -0
- package/dist/template-prompt.d.ts.map +1 -1
- package/dist/template-prompt.js +4 -4
- package/dist/template-prompt.js.map +1 -1
- package/package.json +1 -1
- package/dist/commands/preview.d.ts +0 -30
- package/dist/commands/preview.d.ts.map +0 -1
- package/dist/commands/preview.js +0 -129
- package/dist/commands/preview.js.map +0 -1
- package/dist/commands/push.d.ts +0 -26
- package/dist/commands/push.d.ts.map +0 -1
- package/dist/commands/push.js +0 -139
- package/dist/commands/push.js.map +0 -1
- package/dist/commands/version-state.d.ts +0 -35
- package/dist/commands/version-state.d.ts.map +0 -1
- package/dist/commands/version-state.js +0 -179
- package/dist/commands/version-state.js.map +0 -1
- package/dist/commands/versions.d.ts +0 -11
- package/dist/commands/versions.d.ts.map +0 -1
- package/dist/commands/versions.js +0 -63
- package/dist/commands/versions.js.map +0 -1
package/dist/commands/watch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveCloudContext } from '../cloud-context.js';
|
|
2
|
+
import { confirmLinkPrompt } from '../cloud-link.js';
|
|
2
3
|
import { createFileWatcher } from '../file-watcher.js';
|
|
3
|
-
import { createProjectSyncer } from '../project-sync.js';
|
|
4
|
+
import { createProjectSyncer, listProjectFiles } from '../project-sync.js';
|
|
4
5
|
import { errorToExitCode } from '../exit-codes.js';
|
|
5
6
|
export class TtyRequiredError extends Error {
|
|
6
7
|
exitCode = 2;
|
|
@@ -14,10 +15,13 @@ export async function executeWatch(options) {
|
|
|
14
15
|
if (!isTTY) {
|
|
15
16
|
throw new TtyRequiredError();
|
|
16
17
|
}
|
|
18
|
+
// An over-limit file set fails before the first request, not after the link check.
|
|
19
|
+
await listProjectFiles(cwd);
|
|
17
20
|
const { client, ctx } = await resolveCloudContext({
|
|
18
21
|
cwd,
|
|
19
22
|
apiClient: options.apiClient,
|
|
20
23
|
homeDir: options.homeDir,
|
|
24
|
+
confirmLink: options.confirmLink,
|
|
21
25
|
});
|
|
22
26
|
const syncer = createProjectSyncer({ cwd, client, ctx, signal: options.signal });
|
|
23
27
|
const tracked = await syncer.prime();
|
|
@@ -69,6 +73,8 @@ export function registerWatchCommand(program) {
|
|
|
69
73
|
try {
|
|
70
74
|
await executeWatch({
|
|
71
75
|
signal: controller.signal,
|
|
76
|
+
// stdout is a TTY (checked above); the answer needs stdin too.
|
|
77
|
+
confirmLink: process.stdin.isTTY ? confirmLinkPrompt : undefined,
|
|
72
78
|
onEvent: (e) => {
|
|
73
79
|
const ts = new Date().toLocaleTimeString();
|
|
74
80
|
switch (e.type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAA6C,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/commands/watch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAmB,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAA6C,MAAM,oBAAoB,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAuBnD,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACjC,QAAQ,GAAG,CAAC,CAAC;IACtB;QACC,KAAK,CAAC,4DAA4D,CAAC,CAAC;IACrE,CAAC;CACD;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAqB;IACvD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,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C,GAAG,CAAC,kBAAkB,CAAC,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC;YAChE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9B,OAAO,CAAC,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC;gBAAS,CAAC;YACV,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const MANIFEST_FILENAME = "poli-page.json";
|
|
2
2
|
export declare const CREDENTIALS_DIR = ".polipage";
|
|
3
3
|
export declare const CREDENTIALS_FILENAME = "credentials";
|
|
4
|
+
export declare const LINKS_FILENAME = "links.json";
|
|
4
5
|
export declare const DEFAULT_FORMAT = "A4";
|
|
5
6
|
export declare const DEFAULT_ORIENTATION = "portrait";
|
|
6
7
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAClD,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAClD,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,mBAAmB,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAClD,eAAO,MAAM,eAAe,cAAc,CAAC;AAC3C,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAClD,eAAO,MAAM,cAAc,eAAe,CAAC;AAC3C,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,eAAO,MAAM,mBAAmB,aAAa,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const MANIFEST_FILENAME = 'poli-page.json';
|
|
2
2
|
export const CREDENTIALS_DIR = '.polipage';
|
|
3
3
|
export const CREDENTIALS_FILENAME = 'credentials';
|
|
4
|
+
export const LINKS_FILENAME = 'links.json';
|
|
4
5
|
export const DEFAULT_FORMAT = 'A4';
|
|
5
6
|
export const DEFAULT_ORIENTATION = 'portrait';
|
|
6
7
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAC3C,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAC;AAC3C,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC"}
|
package/dist/credentials.d.ts
CHANGED
|
@@ -9,14 +9,24 @@ export interface OrgCredentials {
|
|
|
9
9
|
}
|
|
10
10
|
export interface StoredCredentials {
|
|
11
11
|
apiUrl?: string;
|
|
12
|
+
/** The API origin that issued `session`; a file without it means the default origin. */
|
|
13
|
+
origin?: string;
|
|
12
14
|
session: string;
|
|
13
15
|
user: UserInfo;
|
|
14
16
|
orgs: Record<string, OrgCredentials>;
|
|
15
17
|
}
|
|
18
|
+
export declare function getCredentialsDir(homeDir?: string): string;
|
|
16
19
|
export declare function readCredentials(homeDir?: string): Promise<StoredCredentials | null>;
|
|
17
20
|
export declare function writeCredentials(credentials: StoredCredentials, homeDir?: string): Promise<void>;
|
|
21
|
+
/** Writes `~/.polipage/<filename>` readable by the user only (dir 0700, file 0600). */
|
|
22
|
+
export declare function writePrivateFile(filename: string, content: string, homeDir?: string): Promise<void>;
|
|
18
23
|
export declare function clearCredentials(homeDir?: string): Promise<void>;
|
|
19
24
|
export declare function updateOrgKeys(orgSlug: string, keys: OrgCredentials, homeDir?: string): Promise<void>;
|
|
25
|
+
export declare class SessionOriginError extends Error {
|
|
26
|
+
readonly exitCode: 4;
|
|
27
|
+
}
|
|
28
|
+
/** The stored session, refused for any API origin other than the one that issued it. */
|
|
29
|
+
export declare function sessionFor(credentials: StoredCredentials, origin?: string): string;
|
|
20
30
|
export declare function getSessionToken(homeDir?: string): Promise<string>;
|
|
21
31
|
export declare function getApiKey(orgSlug: string, environment: 'test' | 'live', homeDir?: string): Promise<string>;
|
|
22
32
|
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IAC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AED,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMvE;AAED,wBAAsB,SAAS,CAC9B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
|
package/dist/credentials.js
CHANGED
|
@@ -2,11 +2,13 @@ import { readFile, writeFile, mkdir, chmod } from 'node:fs/promises';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { CREDENTIALS_DIR, CREDENTIALS_FILENAME } from './constants.js';
|
|
5
|
+
import { apiOrigin, DEFAULT_API_URL } from './api-origin.js';
|
|
6
|
+
import { ExitCode } from './exit-codes.js';
|
|
5
7
|
function getCredentialsPath(homeDir) {
|
|
6
8
|
const home = homeDir ?? homedir();
|
|
7
9
|
return join(home, CREDENTIALS_DIR, CREDENTIALS_FILENAME);
|
|
8
10
|
}
|
|
9
|
-
function getCredentialsDir(homeDir) {
|
|
11
|
+
export function getCredentialsDir(homeDir) {
|
|
10
12
|
const home = homeDir ?? homedir();
|
|
11
13
|
return join(home, CREDENTIALS_DIR);
|
|
12
14
|
}
|
|
@@ -21,32 +23,31 @@ export async function readCredentials(homeDir) {
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
export async function writeCredentials(credentials, homeDir) {
|
|
26
|
+
await writePrivateFile(CREDENTIALS_FILENAME, JSON.stringify(credentials, null, '\t') + '\n', homeDir);
|
|
27
|
+
}
|
|
28
|
+
/** Writes `~/.polipage/<filename>` readable by the user only (dir 0700, file 0600). */
|
|
29
|
+
export async function writePrivateFile(filename, content, homeDir) {
|
|
24
30
|
const dir = getCredentialsDir(homeDir);
|
|
25
|
-
const path =
|
|
31
|
+
const path = join(dir, filename);
|
|
26
32
|
// mkdir/writeFile modes only apply on creation and go through the umask:
|
|
27
33
|
// chmod both so an existing or umask-widened dir/file ends up 0700/0600.
|
|
28
34
|
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
29
35
|
await chmod(dir, 0o700);
|
|
30
|
-
// Tighten an existing file before the new
|
|
36
|
+
// Tighten an existing file before the new content goes in; fail closed if we can't.
|
|
31
37
|
await chmod(path, 0o600).catch((error) => {
|
|
32
38
|
if (error.code !== 'ENOENT')
|
|
33
39
|
throw error;
|
|
34
40
|
});
|
|
35
|
-
await writeFile(path,
|
|
36
|
-
encoding: 'utf-8',
|
|
37
|
-
mode: 0o600,
|
|
38
|
-
});
|
|
41
|
+
await writeFile(path, content, { encoding: 'utf-8', mode: 0o600 });
|
|
39
42
|
await chmod(path, 0o600);
|
|
40
43
|
}
|
|
41
44
|
export async function clearCredentials(homeDir) {
|
|
42
45
|
const path = getCredentialsPath(homeDir);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Already gone — that's fine
|
|
49
|
-
}
|
|
46
|
+
const { unlink } = await import('node:fs/promises');
|
|
47
|
+
await unlink(path).catch((error) => {
|
|
48
|
+
if (error.code !== 'ENOENT')
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
50
51
|
}
|
|
51
52
|
export async function updateOrgKeys(orgSlug, keys, homeDir) {
|
|
52
53
|
const credentials = await readCredentials(homeDir);
|
|
@@ -56,12 +57,23 @@ export async function updateOrgKeys(orgSlug, keys, homeDir) {
|
|
|
56
57
|
credentials.orgs[orgSlug] = { ...credentials.orgs[orgSlug], ...keys };
|
|
57
58
|
await writeCredentials(credentials, homeDir);
|
|
58
59
|
}
|
|
60
|
+
export class SessionOriginError extends Error {
|
|
61
|
+
exitCode = ExitCode.NOT_AUTHENTICATED;
|
|
62
|
+
}
|
|
63
|
+
/** The stored session, refused for any API origin other than the one that issued it. */
|
|
64
|
+
export function sessionFor(credentials, origin = apiOrigin()) {
|
|
65
|
+
const issuer = credentials.origin ?? DEFAULT_API_URL;
|
|
66
|
+
if (issuer !== origin) {
|
|
67
|
+
throw new SessionOriginError(`Your session was issued by ${issuer}, not ${origin}. Run \`poli login\` against ${origin}.`);
|
|
68
|
+
}
|
|
69
|
+
return credentials.session;
|
|
70
|
+
}
|
|
59
71
|
export async function getSessionToken(homeDir) {
|
|
60
72
|
const credentials = await readCredentials(homeDir);
|
|
61
73
|
if (!credentials?.session) {
|
|
62
74
|
throw new Error('Not logged in. Run "poli login" first.');
|
|
63
75
|
}
|
|
64
|
-
return credentials
|
|
76
|
+
return sessionFor(credentials);
|
|
65
77
|
}
|
|
66
78
|
export async function getApiKey(orgSlug, environment, homeDir) {
|
|
67
79
|
const credentials = await readCredentials(homeDir);
|
package/dist/credentials.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC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,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACd,MAAM,WAAW,iBAAiB,OAAO,kCAAkC,CAC3E,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/dist/dev-page.d.ts
CHANGED
|
@@ -11,12 +11,19 @@ export declare const DEV_ERROR_TITLES: Record<DevError['stage'], string>;
|
|
|
11
11
|
* Static by construction: it carries no server data at all and pulls
|
|
12
12
|
* everything from `GET /state` plus the `/events` SSE stream. The only
|
|
13
13
|
* interpolation is the compile-time `DEV_ERROR_TITLES` table above —
|
|
14
|
-
* nothing request-derived to escape or inject — and the
|
|
15
|
-
*
|
|
16
|
-
* without losing the switcher, the pin, or the scroll
|
|
17
|
-
* chrome.
|
|
14
|
+
* nothing request-derived to escape or inject — and the draft PDF
|
|
15
|
+
* lives in an iframe, shown by the browser's own PDF viewer, so a reload
|
|
16
|
+
* swaps the frame without losing the switcher, the pin, or the scroll
|
|
17
|
+
* position of the chrome.
|
|
18
18
|
*/
|
|
19
19
|
export declare const DEV_PAGE_HTML: string;
|
|
20
|
-
/** Placeholder served on `/
|
|
20
|
+
/** Placeholder served on `/pdf` before the first successful render. */
|
|
21
21
|
export declare const DEV_PLACEHOLDER_HTML = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\" /><title>poli dev</title>\n<style>\n\tbody { margin: 0; height: 100vh; display: grid; place-items: center;\n\t\tfont: 14px/1.6 ui-sans-serif, system-ui, sans-serif; color: #71717a; background: #fff; }\n</style>\n</head><body><p>Waiting for the first render\u2026</p></body></html>\n";
|
|
22
|
+
/**
|
|
23
|
+
* The page's CSP allows its own inline script and style by hash, computed
|
|
24
|
+
* from the markup above so an edit cannot leave a stale hash behind.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DEV_PAGE_SECURITY_HEADERS: Record<string, string>;
|
|
27
|
+
/** The placeholder fills the page's own `/pdf` frame, so same-origin framing stays allowed. */
|
|
28
|
+
export declare const DEV_PLACEHOLDER_SECURITY_HEADERS: Record<string, string>;
|
|
22
29
|
//# sourceMappingURL=dev-page.d.ts.map
|
package/dist/dev-page.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-page.d.ts","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"dev-page.d.ts","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAI9D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,QAwPzB,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,gWAOhC,CAAC;AAOF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,wBAGpC,CAAC;AAEH,+FAA+F;AAC/F,eAAO,MAAM,gCAAgC,wBAG3C,CAAC"}
|
package/dist/dev-page.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { securityHeaders } from './dev-server.js';
|
|
1
2
|
/**
|
|
2
3
|
* Overlay title for each failure stage. Typed against `DevError['stage']`
|
|
3
4
|
* so a stage added without a title is a compile error, and embedded into
|
|
@@ -6,7 +7,6 @@
|
|
|
6
7
|
export const DEV_ERROR_TITLES = {
|
|
7
8
|
sync: 'Sync failed',
|
|
8
9
|
render: 'Render failed',
|
|
9
|
-
pdf: 'PDF render failed',
|
|
10
10
|
project: 'Project error',
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
@@ -15,10 +15,10 @@ export const DEV_ERROR_TITLES = {
|
|
|
15
15
|
* Static by construction: it carries no server data at all and pulls
|
|
16
16
|
* everything from `GET /state` plus the `/events` SSE stream. The only
|
|
17
17
|
* interpolation is the compile-time `DEV_ERROR_TITLES` table above —
|
|
18
|
-
* nothing request-derived to escape or inject — and the
|
|
19
|
-
*
|
|
20
|
-
* without losing the switcher, the pin, or the scroll
|
|
21
|
-
* chrome.
|
|
18
|
+
* nothing request-derived to escape or inject — and the draft PDF
|
|
19
|
+
* lives in an iframe, shown by the browser's own PDF viewer, so a reload
|
|
20
|
+
* swaps the frame without losing the switcher, the pin, or the scroll
|
|
21
|
+
* position of the chrome.
|
|
22
22
|
*/
|
|
23
23
|
export const DEV_PAGE_HTML = `<!doctype html>
|
|
24
24
|
<html lang="en">
|
|
@@ -92,18 +92,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
92
92
|
@keyframes pulse { 50% { opacity: 0.25; } }
|
|
93
93
|
.stage { position: relative; flex: 1; min-height: 0; }
|
|
94
94
|
iframe { width: 100%; height: 100%; border: 0; background: #fff; }
|
|
95
|
-
.badge {
|
|
96
|
-
position: absolute;
|
|
97
|
-
left: 50%;
|
|
98
|
-
bottom: 16px;
|
|
99
|
-
transform: translateX(-50%);
|
|
100
|
-
background: var(--accent);
|
|
101
|
-
color: #fff;
|
|
102
|
-
border: 0;
|
|
103
|
-
border-radius: 999px;
|
|
104
|
-
padding: 6px 14px;
|
|
105
|
-
box-shadow: 0 6px 20px rgba(0,0,0,0.25);
|
|
106
|
-
}
|
|
107
95
|
.overlay {
|
|
108
96
|
position: absolute;
|
|
109
97
|
inset: 0;
|
|
@@ -146,24 +134,21 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
146
134
|
</head>
|
|
147
135
|
<body>
|
|
148
136
|
<header>
|
|
149
|
-
<span class="brand">poli dev<small
|
|
137
|
+
<span class="brand">poli dev<small>draft</small></span>
|
|
150
138
|
<label class="visually-hidden" for="template">Template</label>
|
|
151
139
|
<select id="template" title="Template shown in the preview"></select>
|
|
152
140
|
<button id="pin" aria-pressed="false" title="Freeze the view on this template — saves elsewhere will not switch it">Pin</button>
|
|
153
|
-
<button id="pdf" title="Render the real PDF for this template">Render PDF</button>
|
|
154
|
-
<button id="live" hidden title="Go back to the live HTML preview">Live preview</button>
|
|
155
141
|
<span class="spacer"></span>
|
|
156
142
|
<span class="status"><span class="dot" id="dot"></span><span id="statusText">connecting…</span></span>
|
|
157
143
|
</header>
|
|
158
144
|
<div class="stage">
|
|
159
|
-
<iframe id="frame" src="/
|
|
160
|
-
<button class="badge" id="newRender" hidden>New render available — show live preview</button>
|
|
145
|
+
<iframe id="frame" src="/pdf" title="Draft PDF"></iframe>
|
|
161
146
|
<div class="overlay" id="overlay" hidden>
|
|
162
147
|
<div class="overlay-card">
|
|
163
148
|
<h2 id="errTitle">Render failed</h2>
|
|
164
149
|
<div class="where" id="errWhere"></div>
|
|
165
150
|
<pre id="errMessage"></pre>
|
|
166
|
-
<div class="hint">The last good
|
|
151
|
+
<div class="hint">The last good PDF is still behind this overlay. Fix the file and save — the overlay clears on the next successful render.</div>
|
|
167
152
|
</div>
|
|
168
153
|
</div>
|
|
169
154
|
</div>
|
|
@@ -172,37 +157,26 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
172
157
|
var frame = document.getElementById('frame');
|
|
173
158
|
var select = document.getElementById('template');
|
|
174
159
|
var pinBtn = document.getElementById('pin');
|
|
175
|
-
var pdfBtn = document.getElementById('pdf');
|
|
176
|
-
var liveBtn = document.getElementById('live');
|
|
177
|
-
var newRenderBtn = document.getElementById('newRender');
|
|
178
160
|
var overlay = document.getElementById('overlay');
|
|
179
161
|
var errTitle = document.getElementById('errTitle');
|
|
180
162
|
var errWhere = document.getElementById('errWhere');
|
|
181
163
|
var errMessage = document.getElementById('errMessage');
|
|
182
164
|
var statusText = document.getElementById('statusText');
|
|
183
165
|
var dot = document.getElementById('dot');
|
|
184
|
-
var pages = document.getElementById('pages');
|
|
185
166
|
|
|
186
167
|
var stageTitles = ${JSON.stringify(DEV_ERROR_TITLES)};
|
|
187
168
|
|
|
188
169
|
var shownVersion = -1;
|
|
189
|
-
var latestVersion = -1;
|
|
190
|
-
var mode = 'preview';
|
|
191
170
|
// Optimistic: the very first /state fetch races the EventSource open
|
|
192
171
|
// event, and a one-frame "disconnected" flash would be a lie.
|
|
193
172
|
var connected = true;
|
|
194
173
|
|
|
195
|
-
function
|
|
196
|
-
mode = 'preview';
|
|
174
|
+
function showPdf(version) {
|
|
197
175
|
shownVersion = version;
|
|
198
|
-
|
|
199
|
-
newRenderBtn.hidden = true;
|
|
200
|
-
frame.src = '/preview?v=' + version;
|
|
176
|
+
frame.src = '/pdf?v=' + version;
|
|
201
177
|
}
|
|
202
178
|
|
|
203
179
|
function apply(state) {
|
|
204
|
-
latestVersion = state.renderVersion;
|
|
205
|
-
|
|
206
180
|
if (state.templates.join('\\u0000') !== Array.prototype.map.call(select.options, function (o) { return o.value; }).join('\\u0000')) {
|
|
207
181
|
select.textContent = '';
|
|
208
182
|
state.templates.forEach(function (name) {
|
|
@@ -221,8 +195,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
221
195
|
? 'Pinned to ' + (state.activeTemplate || 'this template') + ' — click to follow the most recently changed template again'
|
|
222
196
|
: 'Following the most recently changed template — click to freeze this one';
|
|
223
197
|
|
|
224
|
-
pages.textContent = state.pageCount ? ' · ' + state.pageCount + (state.pageCount === 1 ? ' page' : ' pages') : '';
|
|
225
|
-
|
|
226
198
|
if (state.error) {
|
|
227
199
|
errTitle.textContent = stageTitles[state.error.stage] || 'Error';
|
|
228
200
|
var where = '';
|
|
@@ -254,8 +226,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
254
226
|
}
|
|
255
227
|
|
|
256
228
|
if (state.renderVersion > 0 && state.renderVersion !== shownVersion) {
|
|
257
|
-
|
|
258
|
-
else newRenderBtn.hidden = false;
|
|
229
|
+
showPdf(state.renderVersion);
|
|
259
230
|
}
|
|
260
231
|
}
|
|
261
232
|
|
|
@@ -273,10 +244,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
273
244
|
}
|
|
274
245
|
|
|
275
246
|
select.addEventListener('change', function () {
|
|
276
|
-
post('/api/select?template=' + encodeURIComponent(select.value)).then(
|
|
277
|
-
mode = 'preview';
|
|
278
|
-
apply(s);
|
|
279
|
-
});
|
|
247
|
+
post('/api/select?template=' + encodeURIComponent(select.value)).then(apply);
|
|
280
248
|
});
|
|
281
249
|
|
|
282
250
|
pinBtn.addEventListener('click', function () {
|
|
@@ -284,29 +252,6 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
284
252
|
post('/api/pin?value=' + (next ? 'true' : 'false')).then(apply);
|
|
285
253
|
});
|
|
286
254
|
|
|
287
|
-
pdfBtn.addEventListener('click', function () {
|
|
288
|
-
pdfBtn.disabled = true;
|
|
289
|
-
var previous = pdfBtn.textContent;
|
|
290
|
-
pdfBtn.textContent = 'Rendering PDF…';
|
|
291
|
-
post('/api/pdf')
|
|
292
|
-
.then(function (result) {
|
|
293
|
-
if (result && result.url) {
|
|
294
|
-
mode = 'pdf';
|
|
295
|
-
frame.src = result.url;
|
|
296
|
-
liveBtn.hidden = false;
|
|
297
|
-
newRenderBtn.hidden = true;
|
|
298
|
-
}
|
|
299
|
-
return refresh();
|
|
300
|
-
})
|
|
301
|
-
.finally(function () {
|
|
302
|
-
pdfBtn.disabled = false;
|
|
303
|
-
pdfBtn.textContent = previous;
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
liveBtn.addEventListener('click', function () { showPreview(latestVersion); });
|
|
308
|
-
newRenderBtn.addEventListener('click', function () { showPreview(latestVersion); });
|
|
309
|
-
|
|
310
255
|
var source = new EventSource('/events');
|
|
311
256
|
source.addEventListener('state', function (event) { apply(JSON.parse(event.data)); });
|
|
312
257
|
source.addEventListener('open', function () {
|
|
@@ -324,7 +269,7 @@ export const DEV_PAGE_HTML = `<!doctype html>
|
|
|
324
269
|
</body>
|
|
325
270
|
</html>
|
|
326
271
|
`;
|
|
327
|
-
/** Placeholder served on `/
|
|
272
|
+
/** Placeholder served on `/pdf` before the first successful render. */
|
|
328
273
|
export const DEV_PLACEHOLDER_HTML = `<!doctype html>
|
|
329
274
|
<html lang="en"><head><meta charset="utf-8" /><title>poli dev</title>
|
|
330
275
|
<style>
|
|
@@ -333,4 +278,21 @@ export const DEV_PLACEHOLDER_HTML = `<!doctype html>
|
|
|
333
278
|
</style>
|
|
334
279
|
</head><body><p>Waiting for the first render…</p></body></html>
|
|
335
280
|
`;
|
|
281
|
+
function inlineBlocks(html, tag) {
|
|
282
|
+
const pattern = new RegExp(`<${tag}>([\\s\\S]*?)</${tag}>`, 'g');
|
|
283
|
+
return [...html.matchAll(pattern)].map((match) => match[1] ?? '');
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The page's CSP allows its own inline script and style by hash, computed
|
|
287
|
+
* from the markup above so an edit cannot leave a stale hash behind.
|
|
288
|
+
*/
|
|
289
|
+
export const DEV_PAGE_SECURITY_HEADERS = securityHeaders({
|
|
290
|
+
inlineScripts: inlineBlocks(DEV_PAGE_HTML, 'script'),
|
|
291
|
+
inlineStyles: inlineBlocks(DEV_PAGE_HTML, 'style'),
|
|
292
|
+
});
|
|
293
|
+
/** The placeholder fills the page's own `/pdf` frame, so same-origin framing stays allowed. */
|
|
294
|
+
export const DEV_PLACEHOLDER_SECURITY_HEADERS = securityHeaders({
|
|
295
|
+
frameable: true,
|
|
296
|
+
inlineStyles: inlineBlocks(DEV_PLACEHOLDER_HTML, 'style'),
|
|
297
|
+
});
|
|
336
298
|
//# sourceMappingURL=dev-page.js.map
|
package/dist/dev-page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-page.js","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev-page.js","sourceRoot":"","sources":["../src/dev-page.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;GAIG;AACH,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AC,oBAAoB,EAAE,OAAO,CAAC;CACzD,CAAC,CAAC"}
|
package/dist/dev-server.d.ts
CHANGED
|
@@ -14,6 +14,25 @@ export declare const DEV_SERVER_HOST = "127.0.0.1";
|
|
|
14
14
|
* is busy anyway the server walks upwards (7655, 7656, …).
|
|
15
15
|
*/
|
|
16
16
|
export declare const DEFAULT_DEV_PORT = 7654;
|
|
17
|
+
export interface SecurityHeaderOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Allow this response inside a frame of the same origin: the dev page
|
|
20
|
+
* shows `/pdf` in an iframe, which `frame-ancestors 'none'` would blank.
|
|
21
|
+
*/
|
|
22
|
+
frameable?: boolean;
|
|
23
|
+
/** Exact contents of the response's inline `<script>` elements, allowed by hash. */
|
|
24
|
+
inlineScripts?: readonly string[];
|
|
25
|
+
/** Exact contents of the response's inline `<style>` elements, allowed by hash. */
|
|
26
|
+
inlineStyles?: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Headers every dev server response carries, so no other site can frame
|
|
30
|
+
* the preview (clickjacking the Pin and template controls) or sniff a
|
|
31
|
+
* response into a script. The server sets the default set before any
|
|
32
|
+
* handler runs; a handler passes its own set to `writeHead` to loosen
|
|
33
|
+
* framing or allow its inline code.
|
|
34
|
+
*/
|
|
35
|
+
export declare function securityHeaders(options?: SecurityHeaderOptions): Record<string, string>;
|
|
17
36
|
export interface DevServerRequest {
|
|
18
37
|
method: string;
|
|
19
38
|
pathname: string;
|
package/dist/dev-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../src/dev-server.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,eAAe,EAAe,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAIjG;;;GAGG;AACH,eAAO,MAAM,eAAe,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AgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAsMlF"}
|
package/dist/dev-server.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
1
2
|
import { createServer } from 'node:http';
|
|
2
3
|
/**
|
|
3
4
|
* Loopback only. `poli dev` serves the rendered *draft* of a private
|
|
@@ -16,6 +17,34 @@ export const DEV_SERVER_HOST = '127.0.0.1';
|
|
|
16
17
|
export const DEFAULT_DEV_PORT = 7654;
|
|
17
18
|
const DEFAULT_PORT_ATTEMPTS = 20;
|
|
18
19
|
const SSE_HEARTBEAT_MS = 25_000;
|
|
20
|
+
/**
|
|
21
|
+
* Headers every dev server response carries, so no other site can frame
|
|
22
|
+
* the preview (clickjacking the Pin and template controls) or sniff a
|
|
23
|
+
* response into a script. The server sets the default set before any
|
|
24
|
+
* handler runs; a handler passes its own set to `writeHead` to loosen
|
|
25
|
+
* framing or allow its inline code.
|
|
26
|
+
*/
|
|
27
|
+
export function securityHeaders(options = {}) {
|
|
28
|
+
const directives = [
|
|
29
|
+
"default-src 'self'",
|
|
30
|
+
"frame-src 'self'",
|
|
31
|
+
`frame-ancestors ${options.frameable ? "'self'" : "'none'"}`,
|
|
32
|
+
];
|
|
33
|
+
if (options.inlineScripts?.length) {
|
|
34
|
+
directives.push(`script-src 'self' ${options.inlineScripts.map(cspHash).join(' ')}`);
|
|
35
|
+
}
|
|
36
|
+
if (options.inlineStyles?.length) {
|
|
37
|
+
directives.push(`style-src 'self' ${options.inlineStyles.map(cspHash).join(' ')}`);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
'X-Frame-Options': options.frameable ? 'SAMEORIGIN' : 'DENY',
|
|
41
|
+
'Content-Security-Policy': directives.join('; '),
|
|
42
|
+
'X-Content-Type-Options': 'nosniff',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function cspHash(source) {
|
|
46
|
+
return `'sha256-${createHash('sha256').update(source, 'utf8').digest('base64')}'`;
|
|
47
|
+
}
|
|
19
48
|
/**
|
|
20
49
|
* Minimal `node:http` server with a Server-Sent Events channel.
|
|
21
50
|
*
|
|
@@ -34,6 +63,8 @@ export async function startDevServer(options) {
|
|
|
34
63
|
const sockets = new Set();
|
|
35
64
|
let closed = false;
|
|
36
65
|
const server = createServer((req, res) => {
|
|
66
|
+
for (const [name, value] of Object.entries(securityHeaders()))
|
|
67
|
+
res.setHeader(name, value);
|
|
37
68
|
// The request target is the first attacker-controlled input this
|
|
38
69
|
// listener touches, and the WHATWG parser throws on targets the
|
|
39
70
|
// HTTP parser lets through (an absolute-form URI with an
|
|
@@ -48,13 +79,13 @@ export async function startDevServer(options) {
|
|
|
48
79
|
res.end(JSON.stringify({ error: 'Malformed request URL.' }));
|
|
49
80
|
return;
|
|
50
81
|
}
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
// draft preview, the SSE stream
|
|
57
|
-
// route,
|
|
82
|
+
// With DNS rebinding a web page can read the responses of a
|
|
83
|
+
// loopback server, and its requests look same-origin to the
|
|
84
|
+
// fetch-metadata check below. The Host header is the one thing the
|
|
85
|
+
// browser pins to the page's origin, so only the names a legitimate
|
|
86
|
+
// local browser sends are answered — everything else (rebinding
|
|
87
|
+
// against the draft preview, the SSE stream, the POST endpoints) gets
|
|
88
|
+
// a 403. Applies to every route and method, and must run first.
|
|
58
89
|
if (!isAllowedHost(req.headers.host)) {
|
|
59
90
|
res.writeHead(403, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
60
91
|
res.end(JSON.stringify({
|
|
@@ -62,12 +93,23 @@ export async function startDevServer(options) {
|
|
|
62
93
|
}));
|
|
63
94
|
return;
|
|
64
95
|
}
|
|
96
|
+
// The Host check does not stop CSRF: a page on any site can send a
|
|
97
|
+
// simple POST to 127.0.0.1 with the right Host and no preflight,
|
|
98
|
+
// and each one would trigger a draft render on the user's session.
|
|
99
|
+
const method = (req.method ?? 'GET').toUpperCase();
|
|
100
|
+
if (method !== 'GET' && method !== 'HEAD' && !isSameOriginRequest(req)) {
|
|
101
|
+
res.writeHead(403, { 'Content-Type': 'application/json; charset=utf-8' });
|
|
102
|
+
res.end(JSON.stringify({
|
|
103
|
+
error: 'Blocked cross-site request. poli dev accepts changes only from its own page.',
|
|
104
|
+
}));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
65
107
|
if (url.pathname === eventsPath) {
|
|
66
108
|
attachSseClient(req, res);
|
|
67
109
|
return;
|
|
68
110
|
}
|
|
69
111
|
void Promise.resolve(options.handleRequest({
|
|
70
|
-
method
|
|
112
|
+
method,
|
|
71
113
|
pathname: url.pathname,
|
|
72
114
|
query: url.searchParams,
|
|
73
115
|
req,
|
|
@@ -110,6 +152,26 @@ export async function startDevServer(options) {
|
|
|
110
152
|
const requestPort = authority.port === '' ? '80' : authority.port;
|
|
111
153
|
return requestPort === String(address.port);
|
|
112
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Called after `isAllowedHost`, so the Host header names this server.
|
|
157
|
+
* `Sec-Fetch-Site` is set by the browser and cannot be forged by a
|
|
158
|
+
* page; browsers without it still send `Origin` on a POST. A request
|
|
159
|
+
* with neither is not from a browser page we can vouch for.
|
|
160
|
+
*/
|
|
161
|
+
function isSameOriginRequest(req) {
|
|
162
|
+
const site = req.headers['sec-fetch-site'];
|
|
163
|
+
if (site !== undefined)
|
|
164
|
+
return site === 'same-origin';
|
|
165
|
+
const origin = req.headers.origin;
|
|
166
|
+
if (origin === undefined)
|
|
167
|
+
return false;
|
|
168
|
+
try {
|
|
169
|
+
return new URL(origin).origin === new URL(`http://${req.headers.host}`).origin;
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
113
175
|
server.on('connection', (socket) => {
|
|
114
176
|
sockets.add(socket);
|
|
115
177
|
socket.on('close', () => sockets.delete(socket));
|