primitive-admin 1.1.0-alpha.73 → 1.1.0-alpha.74
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 +18 -25
- package/assets/skill/skills/primitive-platform/SKILL.md +30 -14
- package/dist/bin/primitive.js +14 -11
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/analytics.js +117 -2
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/auth.js +13 -107
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/collection-type-configs.js +1 -1
- package/dist/src/commands/collection-type-configs.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +1 -1
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +1 -1
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/documents.js +749 -29
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/env.js +44 -6
- package/dist/src/commands/env.js.map +1 -1
- package/dist/src/commands/functions.d.ts +20 -0
- package/dist/src/commands/functions.js +329 -0
- package/dist/src/commands/functions.js.map +1 -0
- package/dist/src/commands/groups.js +1 -1
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/init.js +2 -15
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +5 -3
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/prompts.js +5 -7
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.js +1 -1
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/scripts.js +6 -7
- package/dist/src/commands/scripts.js.map +1 -1
- package/dist/src/commands/sync.d.ts +63 -0
- package/dist/src/commands/sync.js +650 -2
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/workflows.js +5 -7
- package/dist/src/commands/workflows.js.map +1 -1
- package/dist/src/lib/api-client.d.ts +156 -1
- package/dist/src/lib/api-client.js +219 -3
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/app-settings-descriptor.js +4 -0
- package/dist/src/lib/app-settings-descriptor.js.map +1 -1
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +5 -7
- package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -1
- package/dist/src/lib/config-object-descriptor.js +39 -0
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-surface.d.ts +10 -0
- package/dist/src/lib/config-surface.js +17 -0
- package/dist/src/lib/config-surface.js.map +1 -1
- package/dist/src/lib/config.d.ts +13 -2
- package/dist/src/lib/config.js +20 -37
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/credentials-store.d.ts +4 -12
- package/dist/src/lib/credentials-store.js +49 -82
- package/dist/src/lib/credentials-store.js.map +1 -1
- package/dist/src/lib/env-resolver-core.d.ts +23 -7
- package/dist/src/lib/env-resolver-core.js +44 -4
- package/dist/src/lib/env-resolver-core.js.map +1 -1
- package/dist/src/lib/function-bundle.d.ts +131 -0
- package/dist/src/lib/function-bundle.js +321 -0
- package/dist/src/lib/function-bundle.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +157 -0
- package/dist/src/lib/function-sync.js +371 -0
- package/dist/src/lib/function-sync.js.map +1 -0
- package/dist/src/lib/function-triggers.d.ts +54 -0
- package/dist/src/lib/function-triggers.js +223 -0
- package/dist/src/lib/function-triggers.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +1 -0
- package/dist/src/lib/generated-config-surfaces.js +279 -1
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/init-ios-links.d.ts +6 -5
- package/dist/src/lib/init-ios-links.js +8 -7
- package/dist/src/lib/init-ios-links.js.map +1 -1
- package/dist/src/lib/init-xcode.d.ts +4 -3
- package/dist/src/lib/init-xcode.js +28 -5
- package/dist/src/lib/init-xcode.js.map +1 -1
- package/dist/src/lib/ios-app-id.d.ts +34 -0
- package/dist/src/lib/ios-app-id.js +69 -0
- package/dist/src/lib/ios-app-id.js.map +1 -0
- package/dist/src/lib/project-config.d.ts +15 -1
- package/dist/src/lib/project-config.js +31 -3
- package/dist/src/lib/project-config.js.map +1 -1
- package/dist/src/lib/sync-resource-types.d.ts +21 -2
- package/dist/src/lib/sync-resource-types.js +104 -6
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/test-case-variables.d.ts +14 -0
- package/dist/src/lib/test-case-variables.js +42 -0
- package/dist/src/lib/test-case-variables.js.map +1 -1
- package/dist/src/lib/workflow-usage.d.ts +198 -0
- package/dist/src/lib/workflow-usage.js +312 -0
- package/dist/src/lib/workflow-usage.js.map +1 -0
- package/dist/src/types/index.d.ts +12 -2
- package/package.json +2 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `functions/<key>.toml` on the wire and back (#3179, project
|
|
3
|
+
* `server-functions`).
|
|
4
|
+
*
|
|
5
|
+
* A function is the one configuration object whose file is not its whole
|
|
6
|
+
* authored surface: the TOML states the gate, the entry and the limits, and the
|
|
7
|
+
* TypeScript the entry reaches is the rest of it. `config push` therefore sends
|
|
8
|
+
* TWO things — a header (create/update) and an immutable config VERSION
|
|
9
|
+
* carrying the authored TOML bytes, every source file and the built bundle —
|
|
10
|
+
* and `config pull` writes both halves back.
|
|
11
|
+
*
|
|
12
|
+
* ── The envelope hash is the shared answer to "changed?" ──────────────────
|
|
13
|
+
*
|
|
14
|
+
* The server decides whether a push is a no-op on `envelopeHash` (sha256 over
|
|
15
|
+
* the TOML bytes, the sources and the bundle), because a comment-only or
|
|
16
|
+
* CRLF-only edit leaves the BUNDLE identical and must still make a version
|
|
17
|
+
* (F-003). The CLI computes the same number to decide whether to make the call
|
|
18
|
+
* at all, through `function-bundle.ts`'s copy of the server's canonical
|
|
19
|
+
* encoding. If those two encodings ever drift, one side re-pushes forever and
|
|
20
|
+
* the other silently drops an edit — `function-bundle-3179.test.ts` pins them
|
|
21
|
+
* against each other.
|
|
22
|
+
*
|
|
23
|
+
* ── Pull writes bytes ────────────────────────────────────────────────────
|
|
24
|
+
*
|
|
25
|
+
* Canonical re-serialization cannot preserve comments, key order or line
|
|
26
|
+
* endings, so the envelope stores the AUTHORED bytes and pull writes those
|
|
27
|
+
* (F-009). It also never trusts a stored path: the files it writes are named by
|
|
28
|
+
* the server, so a path that normalizes outside the tree — or into
|
|
29
|
+
* `node_modules`, which is never authored source — is refused rather than
|
|
30
|
+
* written to a developer's disk. The lexical rules cannot see a symlinked
|
|
31
|
+
* directory inside the tree, so the write step resolves the real path one last
|
|
32
|
+
* time and refuses a destination that lands outside the real root.
|
|
33
|
+
*/
|
|
34
|
+
export interface FunctionConfigPush {
|
|
35
|
+
entry: string;
|
|
36
|
+
/** base64 of the authored `functions/<key>.toml` bytes. */
|
|
37
|
+
toml: string;
|
|
38
|
+
sources: Array<{
|
|
39
|
+
path: string;
|
|
40
|
+
content: string;
|
|
41
|
+
}>;
|
|
42
|
+
/** base64 of the built bundle. */
|
|
43
|
+
bundle: string;
|
|
44
|
+
contentHash: string;
|
|
45
|
+
/** The number BOTH sides compare to decide "is this a no-op?". */
|
|
46
|
+
envelopeHash: string;
|
|
47
|
+
durable: boolean;
|
|
48
|
+
limits?: Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build everything the config-version route needs for one function file.
|
|
52
|
+
*
|
|
53
|
+
* Throws `FunctionBuildError` for a missing `entry`, a missing entry file, a
|
|
54
|
+
* build error, or an import that escapes the config tree — one class, so the
|
|
55
|
+
* push loop has one thing to report and pushes nothing for that function.
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildFunctionConfigPush(options: {
|
|
58
|
+
configDir: string;
|
|
59
|
+
functionKey: string;
|
|
60
|
+
/** Absolute path of `functions/<key>.toml`. */
|
|
61
|
+
filePath: string;
|
|
62
|
+
/** The already-parsed document, so the file is read once. */
|
|
63
|
+
tomlData: any;
|
|
64
|
+
}): Promise<FunctionConfigPush>;
|
|
65
|
+
/**
|
|
66
|
+
* The create body. `functionKey` is attached here rather than spread from the
|
|
67
|
+
* table: the identity comes from the file name, exactly as it does for every
|
|
68
|
+
* other keyed type.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildFunctionCreatePayload(functionKey: string, table: any): Record<string, any>;
|
|
71
|
+
/**
|
|
72
|
+
* The update body. The key is NOT re-sent — it is the function's claim on the
|
|
73
|
+
* app's single key namespace and the URL already names the row — and `status`
|
|
74
|
+
* is server-owned on the sixth carrying type as on the other five.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildFunctionUpdatePayload(table: any): Record<string, any>;
|
|
77
|
+
/** The version-carried keys, as the config-version row holds them. */
|
|
78
|
+
export interface ActiveFunctionVersion {
|
|
79
|
+
entry?: string;
|
|
80
|
+
durable?: boolean;
|
|
81
|
+
/** JSON string on the row; an object is accepted too. */
|
|
82
|
+
limits?: unknown;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The canonical TOML for a function with no stored authored bytes — a function
|
|
86
|
+
* created through the API that has never had code pushed. When bytes exist,
|
|
87
|
+
* pull writes THOSE; this is the fallback that still produces a pushable file.
|
|
88
|
+
*/
|
|
89
|
+
export declare function serializeFunction(record: any, active?: ActiveFunctionVersion): string;
|
|
90
|
+
/**
|
|
91
|
+
* The entity both sides of `config diff` are projected onto: the header's
|
|
92
|
+
* authored fields plus the three keys the VERSION carries. Stated once so a
|
|
93
|
+
* local file and a server record cannot be read into different shapes.
|
|
94
|
+
*
|
|
95
|
+
* Text the server rewrites on the way in is read the same way it will come
|
|
96
|
+
* back (the DSO-003 rule the webhook comparator states): `access` is stored
|
|
97
|
+
* trimmed and `entry` normalized, so an authored value that differs only in
|
|
98
|
+
* that respect is not permanent drift.
|
|
99
|
+
*/
|
|
100
|
+
export declare function functionDiffEntity(tomlData: any): Record<string, any>;
|
|
101
|
+
export interface FunctionPullFile {
|
|
102
|
+
/** Tree-relative, POSIX. */
|
|
103
|
+
relative: string;
|
|
104
|
+
absolute: string;
|
|
105
|
+
content: Buffer;
|
|
106
|
+
}
|
|
107
|
+
export interface FunctionPullPlan {
|
|
108
|
+
configDir: string;
|
|
109
|
+
functionKey: string;
|
|
110
|
+
files: FunctionPullFile[];
|
|
111
|
+
/** The source paths written, for the sync-state record prune reads. */
|
|
112
|
+
sourcePaths: string[];
|
|
113
|
+
/** One line per stored path this pull refused to write. */
|
|
114
|
+
refusals: string[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Why a stored source path may not be written, or null.
|
|
118
|
+
*
|
|
119
|
+
* The same rule the server applies on the way in, applied again on the way out:
|
|
120
|
+
* the file is written to a developer's disk from a path the SERVER chose, so a
|
|
121
|
+
* second check here is the one that matters.
|
|
122
|
+
*/
|
|
123
|
+
export declare function unsafePulledPath(path: string): string | null;
|
|
124
|
+
/**
|
|
125
|
+
* Plan the files `config pull` writes for one function: the authored TOML at
|
|
126
|
+
* `functions/<key>.toml`, and each stored source at its own path.
|
|
127
|
+
*
|
|
128
|
+
* Pure — the caller applies it — so the refusal rules are testable without a
|
|
129
|
+
* server and without touching a disk.
|
|
130
|
+
*/
|
|
131
|
+
export declare function planFunctionPull(options: {
|
|
132
|
+
configDir: string;
|
|
133
|
+
functionKey: string;
|
|
134
|
+
envelope: {
|
|
135
|
+
entry?: string;
|
|
136
|
+
toml?: string;
|
|
137
|
+
sources?: Array<{
|
|
138
|
+
path: string;
|
|
139
|
+
content: string;
|
|
140
|
+
}>;
|
|
141
|
+
};
|
|
142
|
+
}): FunctionPullPlan;
|
|
143
|
+
/** What one `applyFunctionPull` actually did. */
|
|
144
|
+
export interface FunctionPullOutcome {
|
|
145
|
+
/** The source paths written — what the sync state records for prune. */
|
|
146
|
+
writtenSources: string[];
|
|
147
|
+
/** One line per file the write step refused. */
|
|
148
|
+
refusals: string[];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Write a plan's files, creating the directories they need.
|
|
152
|
+
*
|
|
153
|
+
* Returns what was written and what was refused; a refusal is reported by the
|
|
154
|
+
* caller and keeps the file out of the sync state, so prune never claims to
|
|
155
|
+
* own a path this pull did not write.
|
|
156
|
+
*/
|
|
157
|
+
export declare function applyFunctionPull(plan: FunctionPullPlan): FunctionPullOutcome;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `functions/<key>.toml` on the wire and back (#3179, project
|
|
3
|
+
* `server-functions`).
|
|
4
|
+
*
|
|
5
|
+
* A function is the one configuration object whose file is not its whole
|
|
6
|
+
* authored surface: the TOML states the gate, the entry and the limits, and the
|
|
7
|
+
* TypeScript the entry reaches is the rest of it. `config push` therefore sends
|
|
8
|
+
* TWO things — a header (create/update) and an immutable config VERSION
|
|
9
|
+
* carrying the authored TOML bytes, every source file and the built bundle —
|
|
10
|
+
* and `config pull` writes both halves back.
|
|
11
|
+
*
|
|
12
|
+
* ── The envelope hash is the shared answer to "changed?" ──────────────────
|
|
13
|
+
*
|
|
14
|
+
* The server decides whether a push is a no-op on `envelopeHash` (sha256 over
|
|
15
|
+
* the TOML bytes, the sources and the bundle), because a comment-only or
|
|
16
|
+
* CRLF-only edit leaves the BUNDLE identical and must still make a version
|
|
17
|
+
* (F-003). The CLI computes the same number to decide whether to make the call
|
|
18
|
+
* at all, through `function-bundle.ts`'s copy of the server's canonical
|
|
19
|
+
* encoding. If those two encodings ever drift, one side re-pushes forever and
|
|
20
|
+
* the other silently drops an edit — `function-bundle-3179.test.ts` pins them
|
|
21
|
+
* against each other.
|
|
22
|
+
*
|
|
23
|
+
* ── Pull writes bytes ────────────────────────────────────────────────────
|
|
24
|
+
*
|
|
25
|
+
* Canonical re-serialization cannot preserve comments, key order or line
|
|
26
|
+
* endings, so the envelope stores the AUTHORED bytes and pull writes those
|
|
27
|
+
* (F-009). It also never trusts a stored path: the files it writes are named by
|
|
28
|
+
* the server, so a path that normalizes outside the tree — or into
|
|
29
|
+
* `node_modules`, which is never authored source — is refused rather than
|
|
30
|
+
* written to a developer's disk. The lexical rules cannot see a symlinked
|
|
31
|
+
* directory inside the tree, so the write step resolves the real path one last
|
|
32
|
+
* time and refuses a destination that lands outside the real root.
|
|
33
|
+
*/
|
|
34
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, writeFileSync, } from "fs";
|
|
35
|
+
import { dirname, isAbsolute, join, posix as posixPath, relative, resolve, sep, } from "path";
|
|
36
|
+
import { stringifyConfigToml } from "./config-toml.js";
|
|
37
|
+
import { SERVER_FUNCTION_TABLE } from "./config-surface.js";
|
|
38
|
+
import { buildPayloadFromToml, projectRecordToToml, tomlOwned } from "./config-payload.js";
|
|
39
|
+
import { normalizeFunctionTriggers, TriggerDeclarationError, } from "./function-triggers.js";
|
|
40
|
+
import { buildFunctionBundle, FunctionBuildError, functionEnvelopeHash, FUNCTION_ENVELOPE_SCHEMA_VERSION, isDependencyPath, } from "./function-bundle.js";
|
|
41
|
+
const toPosix = (value) => value.split(sep).join("/");
|
|
42
|
+
/**
|
|
43
|
+
* Build everything the config-version route needs for one function file.
|
|
44
|
+
*
|
|
45
|
+
* Throws `FunctionBuildError` for a missing `entry`, a missing entry file, a
|
|
46
|
+
* build error, or an import that escapes the config tree — one class, so the
|
|
47
|
+
* push loop has one thing to report and pushes nothing for that function.
|
|
48
|
+
*/
|
|
49
|
+
export async function buildFunctionConfigPush(options) {
|
|
50
|
+
const { configDir, functionKey, filePath, tomlData } = options;
|
|
51
|
+
const table = tomlData?.function ?? {};
|
|
52
|
+
const entry = String(table.entry ?? "").trim();
|
|
53
|
+
if (!entry) {
|
|
54
|
+
throw new FunctionBuildError(`function '${functionKey}': \`entry\` is required — name the TypeScript ` +
|
|
55
|
+
"entry point, relative to the config tree root.");
|
|
56
|
+
}
|
|
57
|
+
// #3181 — the trigger blocks, checked before the bundle is built so an
|
|
58
|
+
// author with a mistyped key does not wait on esbuild first. Reported as a
|
|
59
|
+
// `FunctionBuildError` so the push loop keeps its one failure class per
|
|
60
|
+
// function and lands every unrelated change in the tree.
|
|
61
|
+
try {
|
|
62
|
+
normalizeFunctionTriggers(table, { durable: table.durable === true });
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
if (err instanceof TriggerDeclarationError) {
|
|
66
|
+
throw new FunctionBuildError(`function '${functionKey}': ${err.message}`);
|
|
67
|
+
}
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
const built = await buildFunctionBundle({ configDir, entry, functionKey });
|
|
71
|
+
// The AUTHORED bytes. Read from disk rather than re-serialized, so the round
|
|
72
|
+
// trip is byte-identical (F-009).
|
|
73
|
+
const authored = readFileSync(filePath);
|
|
74
|
+
const limits = normalizeLimits(table.limits);
|
|
75
|
+
const push = {
|
|
76
|
+
entry: built.entry,
|
|
77
|
+
toml: authored.toString("base64"),
|
|
78
|
+
sources: built.sources.map((s) => ({
|
|
79
|
+
path: s.path,
|
|
80
|
+
content: s.content.toString("base64"),
|
|
81
|
+
})),
|
|
82
|
+
bundle: built.bundle.toString("base64"),
|
|
83
|
+
contentHash: built.contentHash,
|
|
84
|
+
envelopeHash: "",
|
|
85
|
+
durable: table.durable === true,
|
|
86
|
+
...(limits ? { limits } : {}),
|
|
87
|
+
};
|
|
88
|
+
push.envelopeHash = functionEnvelopeHash({
|
|
89
|
+
schemaVersion: FUNCTION_ENVELOPE_SCHEMA_VERSION,
|
|
90
|
+
entry: push.entry,
|
|
91
|
+
toml: push.toml,
|
|
92
|
+
sources: push.sources,
|
|
93
|
+
bundle: push.bundle,
|
|
94
|
+
});
|
|
95
|
+
return push;
|
|
96
|
+
}
|
|
97
|
+
/** `[function.limits]` as the server stores it, or undefined when absent. */
|
|
98
|
+
function normalizeLimits(value) {
|
|
99
|
+
if (value === undefined || value === null)
|
|
100
|
+
return undefined;
|
|
101
|
+
if (typeof value === "string") {
|
|
102
|
+
try {
|
|
103
|
+
const parsed = JSON.parse(value);
|
|
104
|
+
return parsed && typeof parsed === "object" ? parsed : undefined;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (typeof value !== "object" || Array.isArray(value))
|
|
111
|
+
return undefined;
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The create body. `functionKey` is attached here rather than spread from the
|
|
116
|
+
* table: the identity comes from the file name, exactly as it does for every
|
|
117
|
+
* other keyed type.
|
|
118
|
+
*/
|
|
119
|
+
export function buildFunctionCreatePayload(functionKey, table) {
|
|
120
|
+
const payload = buildPayloadFromToml(SERVER_FUNCTION_TABLE, table ?? {}, {
|
|
121
|
+
mode: "create",
|
|
122
|
+
values: { description: tomlOwned },
|
|
123
|
+
});
|
|
124
|
+
dropUndefined(payload);
|
|
125
|
+
return { functionKey, ...payload };
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The update body. The key is NOT re-sent — it is the function's claim on the
|
|
129
|
+
* app's single key namespace and the URL already names the row — and `status`
|
|
130
|
+
* is server-owned on the sixth carrying type as on the other five.
|
|
131
|
+
*/
|
|
132
|
+
export function buildFunctionUpdatePayload(table) {
|
|
133
|
+
const payload = buildPayloadFromToml(SERVER_FUNCTION_TABLE, table ?? {}, {
|
|
134
|
+
mode: "update",
|
|
135
|
+
values: { description: tomlOwned },
|
|
136
|
+
});
|
|
137
|
+
dropUndefined(payload);
|
|
138
|
+
return payload;
|
|
139
|
+
}
|
|
140
|
+
function dropUndefined(payload) {
|
|
141
|
+
for (const key of Object.keys(payload)) {
|
|
142
|
+
if (payload[key] === undefined)
|
|
143
|
+
delete payload[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The canonical TOML for a function with no stored authored bytes — a function
|
|
148
|
+
* created through the API that has never had code pushed. When bytes exist,
|
|
149
|
+
* pull writes THOSE; this is the fallback that still produces a pushable file.
|
|
150
|
+
*/
|
|
151
|
+
export function serializeFunction(record, active) {
|
|
152
|
+
const table = {
|
|
153
|
+
key: record.functionKey,
|
|
154
|
+
...projectRecordToToml(SERVER_FUNCTION_TABLE, record),
|
|
155
|
+
};
|
|
156
|
+
if (active?.entry)
|
|
157
|
+
table.entry = active.entry;
|
|
158
|
+
if (active?.durable === true)
|
|
159
|
+
table.durable = true;
|
|
160
|
+
const limits = normalizeLimits(active?.limits);
|
|
161
|
+
if (limits && Object.keys(limits).length > 0)
|
|
162
|
+
table.limits = limits;
|
|
163
|
+
for (const key of Object.keys(table)) {
|
|
164
|
+
if (table[key] === undefined || table[key] === null)
|
|
165
|
+
delete table[key];
|
|
166
|
+
}
|
|
167
|
+
return stringifyConfigToml({ function: table });
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The tree-relative spelling of `entry` that push actually sends.
|
|
171
|
+
*
|
|
172
|
+
* The build normalizes the authored value (`resolve` + `relative`), and the
|
|
173
|
+
* server stores what it is sent, so a valid `./functions/greet/index.ts`
|
|
174
|
+
* arrives as `functions/greet/index.ts`. Comparing the authored spelling
|
|
175
|
+
* against the stored one would report a function as Modified the instant it
|
|
176
|
+
* was pushed and re-send the same update forever, so both sides are read
|
|
177
|
+
* through the same normalization here.
|
|
178
|
+
*
|
|
179
|
+
* Lexical only: an in-tree SYMLINK spelling is resolved by the build and not
|
|
180
|
+
* by this, which is the one remaining way for the two to differ.
|
|
181
|
+
*/
|
|
182
|
+
function canonicalEntry(value) {
|
|
183
|
+
const raw = toPosix(String(value ?? "").trim());
|
|
184
|
+
if (!raw)
|
|
185
|
+
return null;
|
|
186
|
+
const normalized = posixPath.normalize(raw).replace(/\/+$/, "");
|
|
187
|
+
return normalized || null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The entity both sides of `config diff` are projected onto: the header's
|
|
191
|
+
* authored fields plus the three keys the VERSION carries. Stated once so a
|
|
192
|
+
* local file and a server record cannot be read into different shapes.
|
|
193
|
+
*
|
|
194
|
+
* Text the server rewrites on the way in is read the same way it will come
|
|
195
|
+
* back (the DSO-003 rule the webhook comparator states): `access` is stored
|
|
196
|
+
* trimmed and `entry` normalized, so an authored value that differs only in
|
|
197
|
+
* that respect is not permanent drift.
|
|
198
|
+
*/
|
|
199
|
+
export function functionDiffEntity(tomlData) {
|
|
200
|
+
const table = tomlData?.function ?? {};
|
|
201
|
+
const limits = normalizeLimits(table.limits);
|
|
202
|
+
const access = typeof table.access === "string" && table.access.trim()
|
|
203
|
+
? table.access.trim()
|
|
204
|
+
: null;
|
|
205
|
+
return {
|
|
206
|
+
description: table.description ?? null,
|
|
207
|
+
runAs: table.runAs ?? "caller",
|
|
208
|
+
access,
|
|
209
|
+
inputSchema: table.inputSchema ?? null,
|
|
210
|
+
outputSchema: table.outputSchema ?? null,
|
|
211
|
+
entry: canonicalEntry(table.entry),
|
|
212
|
+
durable: table.durable === true,
|
|
213
|
+
limits: limits && Object.keys(limits).length > 0 ? limits : null,
|
|
214
|
+
// #3181 — normalized locally from the SAME rules the server applies, so a
|
|
215
|
+
// trigger edit reads as a named field rather than only as the code-axis
|
|
216
|
+
// `envelopeHash` change it also is. A file whose triggers do not parse is
|
|
217
|
+
// reported as drift rather than throwing out of a read-only diff: push is
|
|
218
|
+
// where the refusal belongs.
|
|
219
|
+
triggers: safeTriggers(table),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function safeTriggers(table) {
|
|
223
|
+
try {
|
|
224
|
+
return normalizeFunctionTriggers(table, { durable: table?.durable === true });
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Why a stored source path may not be written, or null.
|
|
232
|
+
*
|
|
233
|
+
* The same rule the server applies on the way in, applied again on the way out:
|
|
234
|
+
* the file is written to a developer's disk from a path the SERVER chose, so a
|
|
235
|
+
* second check here is the one that matters.
|
|
236
|
+
*/
|
|
237
|
+
export function unsafePulledPath(path) {
|
|
238
|
+
const raw = toPosix(String(path ?? ""));
|
|
239
|
+
if (!raw)
|
|
240
|
+
return "a stored source path is empty";
|
|
241
|
+
if (raw.startsWith("/") || /^[a-zA-Z]:\//.test(raw)) {
|
|
242
|
+
return `refused stored source path '${raw}': absolute paths are never written`;
|
|
243
|
+
}
|
|
244
|
+
if (raw.split("/").includes("..")) {
|
|
245
|
+
return `refused stored source path '${raw}': it normalizes outside the config tree`;
|
|
246
|
+
}
|
|
247
|
+
if (isDependencyPath(raw)) {
|
|
248
|
+
return `refused stored source path '${raw}': node_modules is never authored source`;
|
|
249
|
+
}
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Plan the files `config pull` writes for one function: the authored TOML at
|
|
254
|
+
* `functions/<key>.toml`, and each stored source at its own path.
|
|
255
|
+
*
|
|
256
|
+
* Pure — the caller applies it — so the refusal rules are testable without a
|
|
257
|
+
* server and without touching a disk.
|
|
258
|
+
*/
|
|
259
|
+
export function planFunctionPull(options) {
|
|
260
|
+
const { configDir, functionKey, envelope } = options;
|
|
261
|
+
const root = resolve(configDir);
|
|
262
|
+
const files = [];
|
|
263
|
+
const sourcePaths = [];
|
|
264
|
+
const refusals = [];
|
|
265
|
+
if (typeof envelope?.toml === "string") {
|
|
266
|
+
const relativePath = `functions/${functionKey}.toml`;
|
|
267
|
+
files.push({
|
|
268
|
+
relative: relativePath,
|
|
269
|
+
absolute: join(root, "functions", `${functionKey}.toml`),
|
|
270
|
+
content: Buffer.from(envelope.toml, "base64"),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
for (const source of envelope?.sources ?? []) {
|
|
274
|
+
const path = toPosix(String(source?.path ?? ""));
|
|
275
|
+
const refusal = unsafePulledPath(path);
|
|
276
|
+
if (refusal) {
|
|
277
|
+
refusals.push(refusal);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const absolute = resolve(root, path);
|
|
281
|
+
// Belt and braces: the string rules above state the contract, this catches
|
|
282
|
+
// a spelling they did not anticipate on a platform they were not written on.
|
|
283
|
+
const rel = relative(root, absolute);
|
|
284
|
+
if (rel.startsWith("..") || isAbsolute(rel)) {
|
|
285
|
+
refusals.push(`refused stored source path '${path}': it normalizes outside the config tree`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
files.push({
|
|
289
|
+
relative: path,
|
|
290
|
+
absolute,
|
|
291
|
+
content: Buffer.from(String(source?.content ?? ""), "base64"),
|
|
292
|
+
});
|
|
293
|
+
sourcePaths.push(path);
|
|
294
|
+
}
|
|
295
|
+
return { configDir: root, functionKey, files, sourcePaths, refusals };
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Why a destination may not be written even though its stored path is
|
|
299
|
+
* tree-relative, or null.
|
|
300
|
+
*
|
|
301
|
+
* `planFunctionPull`'s rules are lexical, and a lexical rule cannot see a
|
|
302
|
+
* SYMLINK: `functions/shared` pointing at `/etc` makes `functions/shared/x`
|
|
303
|
+
* normalize inside the tree and land outside it. So the last check before the
|
|
304
|
+
* write is against the real path — the deepest directory that already exists
|
|
305
|
+
* is resolved and must still be inside the real tree root, and an existing
|
|
306
|
+
* destination that is itself a symlink is refused rather than written through.
|
|
307
|
+
*/
|
|
308
|
+
function unsafeDestination(realRoot, absolute) {
|
|
309
|
+
const contained = (path) => path === realRoot || path.startsWith(realRoot + sep);
|
|
310
|
+
let dir = dirname(absolute);
|
|
311
|
+
while (!existsSync(dir)) {
|
|
312
|
+
const parent = dirname(dir);
|
|
313
|
+
if (parent === dir)
|
|
314
|
+
break;
|
|
315
|
+
dir = parent;
|
|
316
|
+
}
|
|
317
|
+
let realDir;
|
|
318
|
+
try {
|
|
319
|
+
realDir = realpathSync(dir);
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return `refused writing '${absolute}': its directory could not be resolved`;
|
|
323
|
+
}
|
|
324
|
+
if (!contained(realDir)) {
|
|
325
|
+
return (`refused writing '${absolute}': a symlinked directory takes it outside ` +
|
|
326
|
+
"the config tree");
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
if (lstatSync(absolute).isSymbolicLink()) {
|
|
330
|
+
return (`refused writing '${absolute}': the destination is a symlink, and a ` +
|
|
331
|
+
"pull writes files, never through links");
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
/* the destination does not exist yet — the normal case */
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Write a plan's files, creating the directories they need.
|
|
341
|
+
*
|
|
342
|
+
* Returns what was written and what was refused; a refusal is reported by the
|
|
343
|
+
* caller and keeps the file out of the sync state, so prune never claims to
|
|
344
|
+
* own a path this pull did not write.
|
|
345
|
+
*/
|
|
346
|
+
export function applyFunctionPull(plan) {
|
|
347
|
+
const outcome = { writtenSources: [], refusals: [] };
|
|
348
|
+
let realRoot;
|
|
349
|
+
try {
|
|
350
|
+
realRoot = realpathSync(plan.configDir);
|
|
351
|
+
}
|
|
352
|
+
catch {
|
|
353
|
+
realRoot = plan.configDir;
|
|
354
|
+
}
|
|
355
|
+
const sourcePaths = new Set(plan.sourcePaths);
|
|
356
|
+
for (const file of plan.files) {
|
|
357
|
+
const refusal = unsafeDestination(realRoot, file.absolute);
|
|
358
|
+
if (refusal) {
|
|
359
|
+
outcome.refusals.push(refusal);
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
const dir = dirname(file.absolute);
|
|
363
|
+
if (!existsSync(dir))
|
|
364
|
+
mkdirSync(dir, { recursive: true });
|
|
365
|
+
writeFileSync(file.absolute, file.content);
|
|
366
|
+
if (sourcePaths.has(file.relative))
|
|
367
|
+
outcome.writtenSources.push(file.relative);
|
|
368
|
+
}
|
|
369
|
+
return outcome;
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=function-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-sync.js","sourceRoot":"","sources":["../../../src/lib/function-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;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*
|
|
4
|
+
* The SERVER is the authority: it derives the declaration from the TOML bytes
|
|
5
|
+
* inside the version envelope and validates it there, so a direct API push
|
|
6
|
+
* cannot ship a trigger the authored file does not declare (D3181-005). What
|
|
7
|
+
* this file buys is the other half of the `entry` dual-validation shape #3179
|
|
8
|
+
* established — an author who mistypes a key hears about it against their own
|
|
9
|
+
* file, by name, before a request is made.
|
|
10
|
+
*
|
|
11
|
+
* It is deliberately a VENDORED copy of the shape rules in
|
|
12
|
+
* `src/server-functions/trigger-declaration.ts` rather than an import: the CLI
|
|
13
|
+
* compiles with `rootDir: "."` and cannot reach the worker sources, which is
|
|
14
|
+
* the same constraint that made `generated-config-surfaces.ts` a vendored
|
|
15
|
+
* artifact. `cli/tests/unit/function-triggers-3181.test.ts` drives both copies
|
|
16
|
+
* from one fixture list so they cannot drift apart silently.
|
|
17
|
+
*
|
|
18
|
+
* Everything that needs the APP's state stays on the server: whether a
|
|
19
|
+
* referenced secret exists, whether the scheme-specific config is valid under
|
|
20
|
+
* this environment's JWKS policy, whether the app is at its webhook or cron
|
|
21
|
+
* cap, whether a standalone webhook holds the key. A local copy of those would
|
|
22
|
+
* be a preflight that can give a false all-clear.
|
|
23
|
+
*/
|
|
24
|
+
export interface WebhookTriggerDeclaration {
|
|
25
|
+
verificationScheme: string;
|
|
26
|
+
signingSecret?: string;
|
|
27
|
+
toleranceSeconds?: number;
|
|
28
|
+
deduplicationEnabled?: boolean;
|
|
29
|
+
deduplicationWindowMs?: number;
|
|
30
|
+
maxBodyBytes?: number;
|
|
31
|
+
secretGracePeriodMs?: number;
|
|
32
|
+
verification?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export interface CronTriggerDeclaration {
|
|
35
|
+
name: string;
|
|
36
|
+
cron: string;
|
|
37
|
+
timezone?: string;
|
|
38
|
+
overlapPolicy?: string;
|
|
39
|
+
rootInput?: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface TriggerDeclaration {
|
|
42
|
+
webhook: WebhookTriggerDeclaration | null;
|
|
43
|
+
cron: CronTriggerDeclaration[];
|
|
44
|
+
}
|
|
45
|
+
export declare const MAX_CRON_TRIGGERS_PER_FUNCTION = 10;
|
|
46
|
+
export declare class TriggerDeclarationError extends Error {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Normalize (and check) the `triggers` table of a parsed `[function]` table.
|
|
50
|
+
* Returns null when nothing is declared, so a caller can skip the work.
|
|
51
|
+
*/
|
|
52
|
+
export declare function normalizeFunctionTriggers(functionTable: any, options?: {
|
|
53
|
+
durable?: boolean;
|
|
54
|
+
}): TriggerDeclaration | null;
|