primitive-admin 1.3.0-alpha.0 → 1.3.0-alpha.2
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 +45 -0
- package/dist/src/commands/admins.js +91 -0
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/auth-passkeys.d.ts +7 -0
- package/dist/src/commands/auth-passkeys.js +99 -0
- package/dist/src/commands/auth-passkeys.js.map +1 -0
- package/dist/src/commands/auth-sessions.js +7 -28
- package/dist/src/commands/auth-sessions.js.map +1 -1
- package/dist/src/commands/auth.js +32 -6
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/db3-types.d.ts +27 -0
- package/dist/src/commands/db3-types.js +288 -2
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +16 -2
- package/dist/src/commands/db3.js +614 -5
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.js +7 -0
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/functions.js +8 -3
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/hosting.js +177 -14
- package/dist/src/commands/hosting.js.map +1 -1
- package/dist/src/commands/metadata.js +14 -6
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/secrets.d.ts +38 -0
- package/dist/src/commands/secrets.js +102 -4
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/spent-tokens.d.ts +19 -0
- package/dist/src/commands/spent-tokens.js +79 -0
- package/dist/src/commands/spent-tokens.js.map +1 -0
- package/dist/src/commands/sync-app-settings.d.ts +145 -0
- package/dist/src/commands/sync-app-settings.js +341 -8
- package/dist/src/commands/sync-app-settings.js.map +1 -1
- package/dist/src/commands/sync.d.ts +62 -15
- package/dist/src/commands/sync.js +437 -48
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/usage.d.ts +24 -0
- package/dist/src/commands/usage.js +54 -0
- package/dist/src/commands/usage.js.map +1 -1
- package/dist/src/commands/users.js +41 -1
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/lib/admin-login-tables.d.ts +31 -0
- package/dist/src/lib/admin-login-tables.js +75 -0
- package/dist/src/lib/admin-login-tables.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +241 -0
- package/dist/src/lib/api-client.js +203 -10
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.d.ts +42 -3
- package/dist/src/lib/app-settings-descriptor.js +114 -1
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/auth-flow.d.ts +13 -0
- package/dist/src/lib/auth-flow.js +23 -2
- package/dist/src/lib/auth-flow.js.map +1 -1
- package/dist/src/lib/command-groups.js +2 -0
- package/dist/src/lib/command-groups.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +6 -1
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +19 -0
- package/dist/src/lib/credentials-store.js +66 -2
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +2 -0
- package/dist/src/lib/db-codegen/dbTypeIR.js +3 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +20 -1
- package/dist/src/lib/db-type-records.js +17 -4
- package/dist/src/lib/db-type-records.js.map +1 -1
- package/dist/src/lib/db3-export.d.ts +43 -8
- package/dist/src/lib/db3-export.js +133 -13
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-json-fields.d.ts +49 -0
- package/dist/src/lib/db3-json-fields.js +195 -0
- package/dist/src/lib/db3-json-fields.js.map +1 -0
- package/dist/src/lib/db3-type-archive.d.ts +59 -0
- package/dist/src/lib/db3-type-archive.js +95 -0
- package/dist/src/lib/db3-type-archive.js.map +1 -0
- package/dist/src/lib/db3-type-models.d.ts +15 -1
- package/dist/src/lib/db3-type-models.js +147 -16
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/document-export-record-log.d.ts +7 -0
- package/dist/src/lib/document-export-record-log.js +9 -0
- package/dist/src/lib/document-export-record-log.js.map +1 -1
- package/dist/src/lib/document-ingest-artifact.d.ts +6 -0
- package/dist/src/lib/document-ingest-artifact.js +20 -1
- package/dist/src/lib/document-ingest-artifact.js.map +1 -1
- package/dist/src/lib/function-authorize-check.js +5 -0
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.d.ts +9 -0
- package/dist/src/lib/function-authorize-view.js +27 -4
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +28 -0
- package/dist/src/lib/function-collect.js +129 -2
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.js +31 -2
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-grants-preflight.d.ts +99 -0
- package/dist/src/lib/function-grants-preflight.js +154 -2
- package/dist/src/lib/function-grants-preflight.js.map +1 -1
- package/dist/src/lib/function-lint.d.ts +29 -1
- package/dist/src/lib/function-lint.js +208 -0
- package/dist/src/lib/function-lint.js.map +1 -1
- package/dist/src/lib/function-sync.d.ts +73 -0
- package/dist/src/lib/function-sync.js +107 -2
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/generated-command-status.js +46 -8
- package/dist/src/lib/generated-command-status.js.map +1 -1
- package/dist/src/lib/generated-config-surfaces.d.ts +351 -9
- package/dist/src/lib/generated-config-surfaces.js +1009 -24
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/hosting-trust-step.d.ts +67 -0
- package/dist/src/lib/hosting-trust-step.js +279 -0
- package/dist/src/lib/hosting-trust-step.js.map +1 -0
- package/dist/src/lib/hosting-trust.d.ts +77 -0
- package/dist/src/lib/hosting-trust.js +194 -0
- package/dist/src/lib/hosting-trust.js.map +1 -0
- package/dist/src/lib/primitive-declaration.js +89 -10
- package/dist/src/lib/primitive-declaration.js.map +1 -1
- package/dist/src/lib/refresh-admin-credentials.d.ts +34 -4
- package/dist/src/lib/refresh-admin-credentials.js +85 -29
- package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
- package/dist/src/lib/refresh-stored-login.d.ts +85 -0
- package/dist/src/lib/refresh-stored-login.js +233 -0
- package/dist/src/lib/refresh-stored-login.js.map +1 -0
- package/dist/src/lib/row-field-rename.d.ts +18 -0
- package/dist/src/lib/row-field-rename.js +32 -0
- package/dist/src/lib/row-field-rename.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +13 -2
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +24 -1
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -1
- package/dist/src/lib/schema-defs-module.d.ts +29 -0
- package/dist/src/lib/schema-defs-module.js +103 -0
- package/dist/src/lib/schema-defs-module.js.map +1 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +6 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +74 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -1
- package/dist/src/lib/toml-list-edit.d.ts +33 -0
- package/dist/src/lib/toml-list-edit.js +481 -0
- package/dist/src/lib/toml-list-edit.js.map +1 -0
- package/dist/src/lib/toml-scalar-edit.d.ts +9 -0
- package/dist/src/lib/toml-scalar-edit.js +67 -1
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/usage-meters.d.ts +16 -0
- package/dist/src/lib/usage-meters.js +52 -0
- package/dist/src/lib/usage-meters.js.map +1 -0
- package/dist/src/types/index.d.ts +9 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated-sdk-types.js","sourceRoot":"","sources":["../../../src/lib/generated-sdk-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"generated-sdk-types.js","sourceRoot":"","sources":["../../../src/lib/generated-sdk-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,k5ylBAAk5ylB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type TrustEntry, type TrustSkip } from "./hosting-trust.js";
|
|
2
|
+
/** How the step ended. `skipped` is `deploy --no-trust`. */
|
|
3
|
+
export type TrustStatus = "declared" | "removed" | "present" | "skipped" | "failed";
|
|
4
|
+
/** The named ways the step fails. */
|
|
5
|
+
export type TrustErrorCode = "settings_app_mismatch" | "settings_file_missing" | "settings_file_invalid" | "settings_out_of_sync" | "settings_unreadable" | "settings_edit_refused" | "settings_push_failed" | "settings_push_unknown";
|
|
6
|
+
/** One entry as reported: its kind, value and the diff line. */
|
|
7
|
+
export interface TrustEntryReport {
|
|
8
|
+
kind: TrustEntry["kind"];
|
|
9
|
+
value: string;
|
|
10
|
+
line: string;
|
|
11
|
+
}
|
|
12
|
+
/** What the step did for one origin. */
|
|
13
|
+
export interface TrustOutcome {
|
|
14
|
+
status: TrustStatus;
|
|
15
|
+
origin: string;
|
|
16
|
+
added: TrustEntryReport[];
|
|
17
|
+
removed: TrustEntryReport[];
|
|
18
|
+
present: TrustEntryReport[];
|
|
19
|
+
skipped: TrustSkip[];
|
|
20
|
+
warnings: string[];
|
|
21
|
+
notes: string[];
|
|
22
|
+
/** Diff lines to add by hand when the step did not write them. */
|
|
23
|
+
manual: string[];
|
|
24
|
+
error?: {
|
|
25
|
+
code: TrustErrorCode;
|
|
26
|
+
message: string;
|
|
27
|
+
/** The differing fields (`settings_out_of_sync`). */
|
|
28
|
+
fields?: string[];
|
|
29
|
+
/** The child push's own output (`settings_push_failed`, `settings_push_unknown`). */
|
|
30
|
+
pushOutput?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The outcome of `deploy --no-trust`: nothing read, written or pushed, and the
|
|
35
|
+
* entries the origin needs listed to add by hand.
|
|
36
|
+
*/
|
|
37
|
+
export declare function skippedTrust(origin: string, slug: string): TrustOutcome;
|
|
38
|
+
/**
|
|
39
|
+
* Adds `origin`'s entries to the environment's `app.toml` and pushes them.
|
|
40
|
+
*
|
|
41
|
+
* @param input.appId The app hosting acted on.
|
|
42
|
+
* @param input.origin Its hosted origin.
|
|
43
|
+
* @param input.slug Its slug (the passkey RP name when `[app].name` is absent).
|
|
44
|
+
*/
|
|
45
|
+
export declare function declareHostedTrust(input: {
|
|
46
|
+
appId: string;
|
|
47
|
+
origin: string;
|
|
48
|
+
slug: string;
|
|
49
|
+
}): Promise<TrustOutcome>;
|
|
50
|
+
/**
|
|
51
|
+
* Removes a former origin's entries from the environment's `app.toml` and
|
|
52
|
+
* pushes the change (`rename`, on a yes at the prompt).
|
|
53
|
+
*
|
|
54
|
+
* @param input.appId The app hosting acted on.
|
|
55
|
+
* @param input.origin The former hosted origin.
|
|
56
|
+
* @param input.slug The former slug.
|
|
57
|
+
*/
|
|
58
|
+
export declare function removeHostedTrust(input: {
|
|
59
|
+
appId: string;
|
|
60
|
+
origin: string;
|
|
61
|
+
slug: string;
|
|
62
|
+
}): Promise<TrustOutcome>;
|
|
63
|
+
/**
|
|
64
|
+
* The entries the environment's `app.toml` holds for `origin`, as diff lines,
|
|
65
|
+
* or an empty list when the file cannot be read (what `rename` lists as kept).
|
|
66
|
+
*/
|
|
67
|
+
export declare function hostedTrustEntriesInFile(origin: string): string[];
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hosting trust step: add a hosted origin's entries to the environment's
|
|
3
|
+
* `app.toml` and push them, or (for `rename`) remove a former origin's.
|
|
4
|
+
*
|
|
5
|
+
* The step never pushes anything but its own entries, and never edits or
|
|
6
|
+
* pushes another app's settings:
|
|
7
|
+
* 1. The app hosting acted on must be the environment's app, the one whose
|
|
8
|
+
* `app.toml` and `config push` the step would use; otherwise it stops
|
|
9
|
+
* with `settings_app_mismatch` before reading anything.
|
|
10
|
+
* 2. `app.toml` must exist, parse, and agree with the server field by field;
|
|
11
|
+
* otherwise `settings_file_missing`, `settings_file_invalid` or
|
|
12
|
+
* `settings_out_of_sync`, with nothing written.
|
|
13
|
+
* 3. The entries are spliced in textually (`toml-list-edit.ts`); an edit that
|
|
14
|
+
* cannot be verified is `settings_edit_refused`, with nothing written.
|
|
15
|
+
* 4. The file is pushed by `config push --only app --yes`, run as a child of
|
|
16
|
+
* the same CLI. The server is then read: when it does not hold the
|
|
17
|
+
* entries, the file is put back byte for byte (`settings_push_failed`);
|
|
18
|
+
* when the push failed but the server cannot be read, or holds them, the
|
|
19
|
+
* edit is kept and the outcome is unknown (`settings_push_unknown`).
|
|
20
|
+
*
|
|
21
|
+
* It returns an outcome and never throws.
|
|
22
|
+
*/
|
|
23
|
+
import { spawn } from "child_process";
|
|
24
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
25
|
+
import { join, relative } from "path";
|
|
26
|
+
import { ApiClient } from "./api-client.js";
|
|
27
|
+
import { buildAppSettingsPayload } from "./app-settings-descriptor.js";
|
|
28
|
+
import { getCurrentAppId } from "./config.js";
|
|
29
|
+
import { parseConfigToml, parseRawToml } from "./config-toml.js";
|
|
30
|
+
import { getCurrentEnvNameSafe, requireCurrentEnvironment } from "./env-resolver.js";
|
|
31
|
+
import { applyHostedTrust, describeTrustEntry, planHostedTrust, planHostedTrustRemoval, removeHostedTrustEntries, } from "./hosting-trust.js";
|
|
32
|
+
import { resolveSyncDir } from "./sync-paths.js";
|
|
33
|
+
import { TomlEditError, tomlErrorReason } from "./toml-list-edit.js";
|
|
34
|
+
import { appSettingsFieldDiffs } from "../commands/sync-app-settings.js";
|
|
35
|
+
const report = (entry) => ({ kind: entry.kind, value: entry.value, line: describeTrustEntry(entry) });
|
|
36
|
+
function emptyOutcome(origin, status) {
|
|
37
|
+
return { status, origin, added: [], removed: [], present: [], skipped: [], warnings: [], notes: [], manual: [] };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The outcome of `deploy --no-trust`: nothing read, written or pushed, and the
|
|
41
|
+
* entries the origin needs listed to add by hand.
|
|
42
|
+
*/
|
|
43
|
+
export function skippedTrust(origin, slug) {
|
|
44
|
+
const plan = planHostedTrust(origin, {}, { slug });
|
|
45
|
+
return { ...emptyOutcome(plan.origin, "skipped"), skipped: plan.skipped, notes: plan.notes, manual: plan.add.map(describeTrustEntry) };
|
|
46
|
+
}
|
|
47
|
+
/** The environment's app, or null when no environment resolves one. */
|
|
48
|
+
function environmentApp() {
|
|
49
|
+
try {
|
|
50
|
+
requireCurrentEnvironment();
|
|
51
|
+
return { appId: getCurrentAppId() };
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return { appId: null };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Runs `config push --only app --yes` as a child of this CLI. */
|
|
58
|
+
function pushAppSettings() {
|
|
59
|
+
const envName = getCurrentEnvNameSafe();
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const child = spawn(process.execPath, [...process.execArgv, process.argv[1], "config", "push", "--only", "app", "--yes"], {
|
|
62
|
+
env: { ...process.env, ...(envName ? { PRIMITIVE_ENV: envName } : {}) },
|
|
63
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
64
|
+
});
|
|
65
|
+
let output = "";
|
|
66
|
+
child.stdout.on("data", (chunk) => (output += chunk.toString()));
|
|
67
|
+
child.stderr.on("data", (chunk) => (output += chunk.toString()));
|
|
68
|
+
child.on("error", (err) => resolve({ code: 1, output: `${output}${err.message}` }));
|
|
69
|
+
child.on("close", (code) => resolve({ code: code ?? 1, output }));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const strings = (value) => (Array.isArray(value) ? value.filter((v) => typeof v === "string") : []);
|
|
73
|
+
function sameUrl(a, b) {
|
|
74
|
+
try {
|
|
75
|
+
return new URL(a).href === new URL(b).href;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return a === b;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function originOf(value) {
|
|
82
|
+
try {
|
|
83
|
+
return new URL(value).origin;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** True when the live settings hold `entry`, as the server canonicalized it. */
|
|
90
|
+
function liveHolds(live, entry) {
|
|
91
|
+
switch (entry.kind) {
|
|
92
|
+
case "cors_origin":
|
|
93
|
+
return strings(live?.corsAllowedOrigins).some((o) => o.replace(/\/+$/, "") === entry.value.replace(/\/+$/, ""));
|
|
94
|
+
case "email_redirect":
|
|
95
|
+
return strings(live?.emailRedirectUris).some((u) => sameUrl(u, entry.value) || originOf(u) === entry.value);
|
|
96
|
+
case "oauth_redirect":
|
|
97
|
+
return strings(live?.googleClients?.clients?.web?.redirectUris).some((u) => sameUrl(u, entry.value));
|
|
98
|
+
case "passkey_rp": {
|
|
99
|
+
const config = live?.passkeyRpConfig;
|
|
100
|
+
return !!config && typeof config === "object" && Object.prototype.hasOwnProperty.call(config, entry.value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function runStep(input) {
|
|
105
|
+
const origin = new URL(input.origin).origin;
|
|
106
|
+
const manualFor = () => {
|
|
107
|
+
const plan = planHostedTrust(origin, {}, { slug: input.slug });
|
|
108
|
+
return { manual: plan.add.map(describeTrustEntry), notes: plan.notes, skipped: plan.skipped };
|
|
109
|
+
};
|
|
110
|
+
const fail = (code, message, extra = {}) => {
|
|
111
|
+
const { fields, pushOutput, ...rest } = extra;
|
|
112
|
+
return {
|
|
113
|
+
...emptyOutcome(origin, "failed"),
|
|
114
|
+
...(input.mode === "add" ? manualFor() : {}),
|
|
115
|
+
...rest,
|
|
116
|
+
error: { code, message, ...(fields ? { fields } : {}), ...(pushOutput !== undefined ? { pushOutput } : {}) },
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const env = environmentApp();
|
|
120
|
+
if (env.appId !== input.appId) {
|
|
121
|
+
return fail("settings_app_mismatch", env.appId
|
|
122
|
+
? `Hosting acted on app ${input.appId}, but this environment's app.toml and 'primitive config push' belong to app ${env.appId}, so app.toml was not read or changed and nothing was pushed. Run 'primitive hosting trust' from app ${input.appId}'s environment, or add the entries below to its app.toml by hand.`
|
|
123
|
+
: `Hosting acted on app ${input.appId}, but no environment resolves an app.toml for it, so nothing was read, changed or pushed. Run 'primitive hosting trust' from app ${input.appId}'s environment, or add the entries below to its app.toml by hand.`);
|
|
124
|
+
}
|
|
125
|
+
let path;
|
|
126
|
+
try {
|
|
127
|
+
path = join(resolveSyncDir(), "app.toml");
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
return fail("settings_file_missing", `No app.toml could be located for this environment (${err?.message ?? String(err)}).`);
|
|
131
|
+
}
|
|
132
|
+
const shown = relative(process.cwd(), path) || path;
|
|
133
|
+
if (!existsSync(path)) {
|
|
134
|
+
return fail("settings_file_missing", `${shown} does not exist. Run 'primitive config pull --only app' to fetch it, then 'primitive hosting trust'.`);
|
|
135
|
+
}
|
|
136
|
+
const before = readFileSync(path, "utf-8");
|
|
137
|
+
let doc;
|
|
138
|
+
try {
|
|
139
|
+
doc = parseRawToml(before);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
return fail("settings_file_invalid", `${shown} is not valid TOML (${tomlErrorReason(err)}); nothing was written. Fix it, then run 'primitive hosting trust'.`);
|
|
143
|
+
}
|
|
144
|
+
const plan = planHostedTrust(origin, doc, { slug: input.slug });
|
|
145
|
+
const entries = input.mode === "add" ? plan.add : planHostedTrustRemoval(origin, doc);
|
|
146
|
+
const base = {
|
|
147
|
+
...emptyOutcome(origin, input.mode === "add" ? "declared" : "removed"),
|
|
148
|
+
present: input.mode === "add" ? plan.present.map(report) : [],
|
|
149
|
+
skipped: input.mode === "add" ? plan.skipped : [],
|
|
150
|
+
warnings: input.mode === "add" ? plan.warnings : [],
|
|
151
|
+
notes: input.mode === "add" ? plan.notes : [],
|
|
152
|
+
};
|
|
153
|
+
if (entries.length === 0 && input.mode === "remove")
|
|
154
|
+
return base;
|
|
155
|
+
const lines = entries.map(describeTrustEntry);
|
|
156
|
+
const withLines = (outcome) => ({ ...outcome, manual: input.mode === "add" ? lines : [] });
|
|
157
|
+
// The step pushes only its own entries: a file that already differs from the server is not pushed.
|
|
158
|
+
// Checked before reporting entries present too: entries in the file the server lacks are not trust.
|
|
159
|
+
const parsed = buildAppSettingsPayload(parseConfigToml(before), {});
|
|
160
|
+
if (parsed.errors.length > 0) {
|
|
161
|
+
return withLines({
|
|
162
|
+
...base,
|
|
163
|
+
status: "failed",
|
|
164
|
+
error: { code: "settings_file_invalid", message: `${shown} does not describe valid app settings (${parsed.errors.map(String).join("; ")}); nothing was written.` },
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const client = new ApiClient();
|
|
168
|
+
let live;
|
|
169
|
+
try {
|
|
170
|
+
live = await client.getAppSettings(input.appId);
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
return withLines({ ...base, status: "failed", error: { code: "settings_unreadable", message: `The app's settings could not be read (${err?.message ?? String(err)}); nothing was written.` } });
|
|
174
|
+
}
|
|
175
|
+
const diffs = appSettingsFieldDiffs(parsed.settings, live ?? {});
|
|
176
|
+
if (diffs.length > 0) {
|
|
177
|
+
const fields = diffs.map((d) => `[${d.section}].${d.key}`);
|
|
178
|
+
return withLines({
|
|
179
|
+
...base,
|
|
180
|
+
status: "failed",
|
|
181
|
+
error: {
|
|
182
|
+
code: "settings_out_of_sync",
|
|
183
|
+
message: `${shown} already differs from the app's settings in ${fields.join(", ")}, and this step pushes only its own entries, so nothing was written. Push or undo those changes ('primitive config diff --only app'), then run 'primitive hosting trust'.`,
|
|
184
|
+
fields,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (entries.length === 0)
|
|
189
|
+
return { ...base, status: "present" };
|
|
190
|
+
let next;
|
|
191
|
+
try {
|
|
192
|
+
next = input.mode === "add" ? applyHostedTrust(before, plan) : removeHostedTrustEntries(before, entries);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
const message = err instanceof TomlEditError ? err.message : String(err);
|
|
196
|
+
return withLines({ ...base, status: "failed", error: { code: "settings_edit_refused", message: `${shown} could not be edited safely: ${message}` } });
|
|
197
|
+
}
|
|
198
|
+
writeFileSync(path, next);
|
|
199
|
+
const done = input.mode === "add" ? { added: entries.map(report) } : { removed: entries.map(report) };
|
|
200
|
+
const pushed = await pushAppSettings();
|
|
201
|
+
let after = null;
|
|
202
|
+
let readError = null;
|
|
203
|
+
try {
|
|
204
|
+
after = await client.getAppSettings(input.appId);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
readError = err?.message ?? String(err);
|
|
208
|
+
}
|
|
209
|
+
const applied = after !== null && entries.every((entry) => liveHolds(after, entry) === (input.mode === "add"));
|
|
210
|
+
if (pushed.code === 0 && applied)
|
|
211
|
+
return { ...base, ...done };
|
|
212
|
+
if (after !== null && !applied) {
|
|
213
|
+
writeFileSync(path, before);
|
|
214
|
+
return withLines({
|
|
215
|
+
...base,
|
|
216
|
+
status: "failed",
|
|
217
|
+
error: {
|
|
218
|
+
code: "settings_push_failed",
|
|
219
|
+
message: `The push of ${shown} was refused, so ${shown} is as it was and the app's settings are unchanged.`,
|
|
220
|
+
pushOutput: pushed.output,
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
...base,
|
|
226
|
+
...done,
|
|
227
|
+
status: "failed",
|
|
228
|
+
error: {
|
|
229
|
+
code: "settings_push_unknown",
|
|
230
|
+
message: `The push of ${shown} ended without a clear answer${readError ? ` and the app's settings could not be read (${readError})` : ""}: the outcome is unknown. ${shown} keeps the edit. Run 'primitive config diff --only app' to see whether the server has it.`,
|
|
231
|
+
pushOutput: pushed.output,
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Adds `origin`'s entries to the environment's `app.toml` and pushes them.
|
|
237
|
+
*
|
|
238
|
+
* @param input.appId The app hosting acted on.
|
|
239
|
+
* @param input.origin Its hosted origin.
|
|
240
|
+
* @param input.slug Its slug (the passkey RP name when `[app].name` is absent).
|
|
241
|
+
*/
|
|
242
|
+
export async function declareHostedTrust(input) {
|
|
243
|
+
try {
|
|
244
|
+
return await runStep({ ...input, mode: "add" });
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
return { ...emptyOutcome(input.origin, "failed"), error: { code: "settings_unreadable", message: err?.message ?? String(err) } };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Removes a former origin's entries from the environment's `app.toml` and
|
|
252
|
+
* pushes the change (`rename`, on a yes at the prompt).
|
|
253
|
+
*
|
|
254
|
+
* @param input.appId The app hosting acted on.
|
|
255
|
+
* @param input.origin The former hosted origin.
|
|
256
|
+
* @param input.slug The former slug.
|
|
257
|
+
*/
|
|
258
|
+
export async function removeHostedTrust(input) {
|
|
259
|
+
try {
|
|
260
|
+
return await runStep({ ...input, mode: "remove" });
|
|
261
|
+
}
|
|
262
|
+
catch (err) {
|
|
263
|
+
return { ...emptyOutcome(input.origin, "failed"), error: { code: "settings_unreadable", message: err?.message ?? String(err) } };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The entries the environment's `app.toml` holds for `origin`, as diff lines,
|
|
268
|
+
* or an empty list when the file cannot be read (what `rename` lists as kept).
|
|
269
|
+
*/
|
|
270
|
+
export function hostedTrustEntriesInFile(origin) {
|
|
271
|
+
try {
|
|
272
|
+
const text = readFileSync(join(resolveSyncDir(), "app.toml"), "utf-8");
|
|
273
|
+
return planHostedTrustRemoval(origin, parseRawToml(text)).map(describeTrustEntry);
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return [];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=hosting-trust-step.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosting-trust-step.js","sourceRoot":"","sources":["../../../src/lib/hosting-trust-step.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACrF,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,wBAAwB,GAGzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AA6CzE,MAAM,MAAM,GAAG,CAAC,KAAiB,EAAoB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,I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AY,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACpF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** The kinds of entry a hosted origin needs. */
|
|
2
|
+
export type TrustEntryKind = "cors_origin" | "email_redirect" | "oauth_redirect" | "passkey_rp";
|
|
3
|
+
/** One `app.toml` entry: an item of the string array at `path`, or (passkey) the table at `path`. */
|
|
4
|
+
export interface TrustEntry {
|
|
5
|
+
kind: TrustEntryKind;
|
|
6
|
+
/** The array's path (table segments then key), or the passkey table's path. */
|
|
7
|
+
path: string[];
|
|
8
|
+
/** The array item, or the passkey RP ID. */
|
|
9
|
+
value: string;
|
|
10
|
+
/** The passkey RP's display name. */
|
|
11
|
+
name?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Why an entry was not added. */
|
|
14
|
+
export type TrustSkipReason = "http_redirect_not_allowed" | "no_web_google_client" | "oauth_uri_on_other_client";
|
|
15
|
+
/** An entry the plan leaves out, and why. */
|
|
16
|
+
export interface TrustSkip {
|
|
17
|
+
kind: TrustEntryKind;
|
|
18
|
+
value: string;
|
|
19
|
+
reason: TrustSkipReason;
|
|
20
|
+
/** The client type already listing the URI (`oauth_uri_on_other_client`). */
|
|
21
|
+
client?: string;
|
|
22
|
+
}
|
|
23
|
+
/** What a hosted origin needs added to one `app.toml`. */
|
|
24
|
+
export interface TrustPlan {
|
|
25
|
+
/** The hosted origin, normalized. */
|
|
26
|
+
origin: string;
|
|
27
|
+
hostname: string;
|
|
28
|
+
add: TrustEntry[];
|
|
29
|
+
/** Entries the file already holds. */
|
|
30
|
+
present: TrustEntry[];
|
|
31
|
+
skipped: TrustSkip[];
|
|
32
|
+
/** A list the step adds to was empty, so other origins are now treated differently. */
|
|
33
|
+
warnings: string[];
|
|
34
|
+
/** What the developer may want to do about a skipped entry. */
|
|
35
|
+
notes: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The entries `origin` needs in the parsed `app.toml` `doc`: what to add,
|
|
39
|
+
* what is present, what is skipped and why, and the warnings to print.
|
|
40
|
+
*
|
|
41
|
+
* @param origin The hosted origin, e.g. `https://my-app.primitive.app`.
|
|
42
|
+
* @param doc The parsed `app.toml`.
|
|
43
|
+
* @param options.slug The app's slug, the passkey RP name when `[app].name` is absent.
|
|
44
|
+
*/
|
|
45
|
+
export declare function planHostedTrust(origin: string, doc: Record<string, any>, options: {
|
|
46
|
+
slug: string;
|
|
47
|
+
}): TrustPlan;
|
|
48
|
+
/**
|
|
49
|
+
* One entry as a line of the diff the step prints, with its table and key:
|
|
50
|
+
* `[cors] allowedOrigins += "https://…"` or `[auth.passkeys."…"] name = "…"`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function describeTrustEntry(entry: TrustEntry): string;
|
|
53
|
+
/** `text` with every entry of `plan.add` added. Throws `TomlEditError` when an edit cannot be verified. */
|
|
54
|
+
export declare function applyHostedTrust(text: string, plan: TrustPlan): string;
|
|
55
|
+
/**
|
|
56
|
+
* The entries the parsed `doc` holds for `origin`, as written: the CORS
|
|
57
|
+
* origin, email redirects and `web` client redirect URIs on that origin, and
|
|
58
|
+
* its passkey RP. What `rename` offers to remove for the former origin.
|
|
59
|
+
*/
|
|
60
|
+
export declare function planHostedTrustRemoval(origin: string, doc: Record<string, any>): TrustEntry[];
|
|
61
|
+
/** `text` without `entries`. Throws `TomlEditError` when an edit cannot be verified. */
|
|
62
|
+
export declare function removeHostedTrustEntries(text: string, entries: TrustEntry[]): string;
|
|
63
|
+
/**
|
|
64
|
+
* Whether `rename` removes the former origin's entries: only on a yes at an
|
|
65
|
+
* interactive prompt. With `--yes` or without a terminal it keeps them.
|
|
66
|
+
*
|
|
67
|
+
* @param options.yes `--yes` was given.
|
|
68
|
+
* @param options.interactive stdin and stdout are a terminal.
|
|
69
|
+
* @param options.ask Asks a yes/no question.
|
|
70
|
+
* @param options.question The question to ask.
|
|
71
|
+
*/
|
|
72
|
+
export declare function decideFormerOriginTrust(options: {
|
|
73
|
+
yes: boolean;
|
|
74
|
+
interactive: boolean;
|
|
75
|
+
ask: (question: string) => Promise<boolean>;
|
|
76
|
+
question?: string;
|
|
77
|
+
}): Promise<"remove" | "keep">;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declared trust for a hosted origin: what `app.toml` must list before the
|
|
3
|
+
* app accepts sign-in on `https://<slug>.primitive.app` (or a local hosting
|
|
4
|
+
* service's origin), and the textual edit that adds or removes it.
|
|
5
|
+
*
|
|
6
|
+
* Pure: the planner reads a parsed `app.toml`, and the edits go through
|
|
7
|
+
* `toml-list-edit.ts`, which keeps every other byte and verifies each splice
|
|
8
|
+
* by re-parsing. The step that reads the file, compares it with the server,
|
|
9
|
+
* writes it and pushes it is `hosting-trust-step.ts`.
|
|
10
|
+
*
|
|
11
|
+
* For a hosted origin `O` with hostname `H`, the entries are:
|
|
12
|
+
* - `O` in `[cors].allowedOrigins`;
|
|
13
|
+
* - `O` in `[auth].emailRedirectUris` (the matcher compares origins, so the
|
|
14
|
+
* bare origin covers every path);
|
|
15
|
+
* - in `[auth.google.clients.web]` only (the client the JS client authorizes
|
|
16
|
+
* with), `O + path` for each distinct path among that client's `http(s)`
|
|
17
|
+
* redirect URIs, else `O/oauth/callback`;
|
|
18
|
+
* - `[auth.passkeys."H"]` named after `[app].name`, else the slug.
|
|
19
|
+
*
|
|
20
|
+
* The API accepts `http` redirect URIs only on `localhost` and `127.0.0.1`,
|
|
21
|
+
* so for any other `http` origin both redirect entries are left out.
|
|
22
|
+
*/
|
|
23
|
+
import { addTomlTable, appendTomlArrayItem, removeTomlArrayItem, removeTomlTable } from "./toml-list-edit.js";
|
|
24
|
+
const CORS_PATH = ["cors", "allowedOrigins"];
|
|
25
|
+
const EMAIL_PATH = ["auth", "emailRedirectUris"];
|
|
26
|
+
const WEB_REDIRECTS_PATH = ["auth", "google", "clients", "web", "redirectUris"];
|
|
27
|
+
const passkeyPath = (rpId) => ["auth", "passkeys", rpId];
|
|
28
|
+
const strings = (value) => (Array.isArray(value) ? value.filter((v) => typeof v === "string") : []);
|
|
29
|
+
const isTable = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
30
|
+
function parseUrl(value) {
|
|
31
|
+
try {
|
|
32
|
+
return new URL(value);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const withoutTrailingSlash = (value) => value.replace(/\/+$/, "");
|
|
39
|
+
/**
|
|
40
|
+
* The entries `origin` needs in the parsed `app.toml` `doc`: what to add,
|
|
41
|
+
* what is present, what is skipped and why, and the warnings to print.
|
|
42
|
+
*
|
|
43
|
+
* @param origin The hosted origin, e.g. `https://my-app.primitive.app`.
|
|
44
|
+
* @param doc The parsed `app.toml`.
|
|
45
|
+
* @param options.slug The app's slug, the passkey RP name when `[app].name` is absent.
|
|
46
|
+
*/
|
|
47
|
+
export function planHostedTrust(origin, doc, options) {
|
|
48
|
+
const url = new URL(origin);
|
|
49
|
+
const O = url.origin;
|
|
50
|
+
const H = url.hostname;
|
|
51
|
+
const plan = { origin: O, hostname: H, add: [], present: [], skipped: [], warnings: [], notes: [] };
|
|
52
|
+
const redirectsAllowed = url.protocol === "https:" || (url.protocol === "http:" && (H === "localhost" || H === "127.0.0.1"));
|
|
53
|
+
const cors = strings(doc?.cors?.allowedOrigins);
|
|
54
|
+
const corsEntry = { kind: "cors_origin", path: CORS_PATH, value: O };
|
|
55
|
+
if (cors.some((entry) => withoutTrailingSlash(entry) === O)) {
|
|
56
|
+
plan.present.push(corsEntry);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
plan.add.push(corsEntry);
|
|
60
|
+
if (cors.length === 0) {
|
|
61
|
+
plan.warnings.push("[cors].allowedOrigins was empty and now lists only the hosted origin. A browser on any origin not on the list gets no CORS answer from the app's API: add every other origin the app is served from.");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!redirectsAllowed) {
|
|
65
|
+
plan.skipped.push({ kind: "email_redirect", value: O, reason: "http_redirect_not_allowed" });
|
|
66
|
+
plan.skipped.push({ kind: "oauth_redirect", value: `${O}/oauth/callback`, reason: "http_redirect_not_allowed" });
|
|
67
|
+
plan.notes.push(`${O} is an http origin: the API accepts http redirect URIs only on localhost and 127.0.0.1, so the email redirect and the Google redirect URI were left out. Sign in there with a code or a passkey.`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const email = strings(doc?.auth?.emailRedirectUris);
|
|
71
|
+
const emailEntry = { kind: "email_redirect", path: EMAIL_PATH, value: O };
|
|
72
|
+
if (email.some((entry) => parseUrl(entry)?.origin === O)) {
|
|
73
|
+
plan.present.push(emailEntry);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
plan.add.push(emailEntry);
|
|
77
|
+
if (email.length === 0) {
|
|
78
|
+
plan.warnings.push("[auth].emailRedirectUris was empty and now lists only the hosted origin: a sign-in email asked for with a redirect on another origin is now refused instead of sent with a code only.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const clients = isTable(doc?.auth?.google?.clients) ? doc.auth.google.clients : {};
|
|
82
|
+
const web = isTable(clients.web) ? clients.web : null;
|
|
83
|
+
if (!web) {
|
|
84
|
+
plan.skipped.push({ kind: "oauth_redirect", value: `${O}/oauth/callback`, reason: "no_web_google_client" });
|
|
85
|
+
plan.notes.push(`The app has no [auth.google.clients.web] client, so no Google redirect URI was added. For Google sign-in on ${O}, list ${O}/oauth/callback in a web client's redirectUris.`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const webUris = strings(web.redirectUris);
|
|
89
|
+
const paths = [];
|
|
90
|
+
for (const uri of webUris) {
|
|
91
|
+
const parsed = parseUrl(uri);
|
|
92
|
+
if (!parsed || (parsed.protocol !== "https:" && parsed.protocol !== "http:"))
|
|
93
|
+
continue;
|
|
94
|
+
const path = `${parsed.pathname}${parsed.search}`;
|
|
95
|
+
if (!paths.includes(path))
|
|
96
|
+
paths.push(path);
|
|
97
|
+
}
|
|
98
|
+
if (paths.length === 0)
|
|
99
|
+
paths.push("/oauth/callback");
|
|
100
|
+
for (const path of paths) {
|
|
101
|
+
const uri = `${O}${path}`;
|
|
102
|
+
const entry = { kind: "oauth_redirect", path: WEB_REDIRECTS_PATH, value: uri };
|
|
103
|
+
if (webUris.includes(uri)) {
|
|
104
|
+
plan.present.push(entry);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const other = Object.entries(clients).find(([type, client]) => type !== "web" && strings(client?.redirectUris).includes(uri));
|
|
108
|
+
if (other) {
|
|
109
|
+
plan.skipped.push({ kind: "oauth_redirect", value: uri, reason: "oauth_uri_on_other_client", client: other[0] });
|
|
110
|
+
plan.notes.push(`${uri} is already listed by [auth.google.clients.${other[0]}]; a redirect URI selects one client, so it was not added to the web client.`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
plan.add.push(entry);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const passkeys = doc?.auth?.passkeys;
|
|
118
|
+
const name = typeof doc?.app?.name === "string" && doc.app.name.trim() ? doc.app.name : options.slug;
|
|
119
|
+
if (isTable(passkeys) && Object.prototype.hasOwnProperty.call(passkeys, H)) {
|
|
120
|
+
plan.present.push({ kind: "passkey_rp", path: passkeyPath(H), value: H, name: passkeys[H]?.name });
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
plan.add.push({ kind: "passkey_rp", path: passkeyPath(H), value: H, name });
|
|
124
|
+
}
|
|
125
|
+
return plan;
|
|
126
|
+
}
|
|
127
|
+
function renderKey(key) {
|
|
128
|
+
return /^[A-Za-z0-9_-]+$/.test(key) ? key : JSON.stringify(key);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* One entry as a line of the diff the step prints, with its table and key:
|
|
132
|
+
* `[cors] allowedOrigins += "https://…"` or `[auth.passkeys."…"] name = "…"`.
|
|
133
|
+
*/
|
|
134
|
+
export function describeTrustEntry(entry) {
|
|
135
|
+
if (entry.kind === "passkey_rp") {
|
|
136
|
+
return `[${entry.path.map(renderKey).join(".")}] name = ${JSON.stringify(entry.name ?? "")}`;
|
|
137
|
+
}
|
|
138
|
+
const table = entry.path.slice(0, -1).map(renderKey).join(".");
|
|
139
|
+
return `[${table}] ${renderKey(entry.path[entry.path.length - 1])} += ${JSON.stringify(entry.value)}`;
|
|
140
|
+
}
|
|
141
|
+
/** `text` with every entry of `plan.add` added. Throws `TomlEditError` when an edit cannot be verified. */
|
|
142
|
+
export function applyHostedTrust(text, plan) {
|
|
143
|
+
return plan.add.reduce((current, entry) => entry.kind === "passkey_rp"
|
|
144
|
+
? addTomlTable(current, entry.path, { name: entry.name ?? entry.value })
|
|
145
|
+
: appendTomlArrayItem(current, entry.path, entry.value), text);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The entries the parsed `doc` holds for `origin`, as written: the CORS
|
|
149
|
+
* origin, email redirects and `web` client redirect URIs on that origin, and
|
|
150
|
+
* its passkey RP. What `rename` offers to remove for the former origin.
|
|
151
|
+
*/
|
|
152
|
+
export function planHostedTrustRemoval(origin, doc) {
|
|
153
|
+
const url = new URL(origin);
|
|
154
|
+
const O = url.origin;
|
|
155
|
+
const H = url.hostname;
|
|
156
|
+
const entries = [];
|
|
157
|
+
for (const value of strings(doc?.cors?.allowedOrigins)) {
|
|
158
|
+
if (withoutTrailingSlash(value) === O)
|
|
159
|
+
entries.push({ kind: "cors_origin", path: CORS_PATH, value });
|
|
160
|
+
}
|
|
161
|
+
for (const value of strings(doc?.auth?.emailRedirectUris)) {
|
|
162
|
+
if (parseUrl(value)?.origin === O)
|
|
163
|
+
entries.push({ kind: "email_redirect", path: EMAIL_PATH, value });
|
|
164
|
+
}
|
|
165
|
+
for (const value of strings(doc?.auth?.google?.clients?.web?.redirectUris)) {
|
|
166
|
+
if (parseUrl(value)?.origin === O)
|
|
167
|
+
entries.push({ kind: "oauth_redirect", path: WEB_REDIRECTS_PATH, value });
|
|
168
|
+
}
|
|
169
|
+
const passkeys = doc?.auth?.passkeys;
|
|
170
|
+
if (isTable(passkeys) && Object.prototype.hasOwnProperty.call(passkeys, H)) {
|
|
171
|
+
entries.push({ kind: "passkey_rp", path: passkeyPath(H), value: H, name: passkeys[H]?.name });
|
|
172
|
+
}
|
|
173
|
+
return entries;
|
|
174
|
+
}
|
|
175
|
+
/** `text` without `entries`. Throws `TomlEditError` when an edit cannot be verified. */
|
|
176
|
+
export function removeHostedTrustEntries(text, entries) {
|
|
177
|
+
return entries.reduce((current, entry) => (entry.kind === "passkey_rp" ? removeTomlTable(current, entry.path) : removeTomlArrayItem(current, entry.path, entry.value)), text);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Whether `rename` removes the former origin's entries: only on a yes at an
|
|
181
|
+
* interactive prompt. With `--yes` or without a terminal it keeps them.
|
|
182
|
+
*
|
|
183
|
+
* @param options.yes `--yes` was given.
|
|
184
|
+
* @param options.interactive stdin and stdout are a terminal.
|
|
185
|
+
* @param options.ask Asks a yes/no question.
|
|
186
|
+
* @param options.question The question to ask.
|
|
187
|
+
*/
|
|
188
|
+
export async function decideFormerOriginTrust(options) {
|
|
189
|
+
if (options.yes || !options.interactive)
|
|
190
|
+
return "keep";
|
|
191
|
+
const question = options.question ?? "Remove the former origin's entries from app.toml and the app's settings?";
|
|
192
|
+
return (await options.ask(question)) ? "remove" : "keep";
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=hosting-trust.js.map
|