primitive-admin 1.0.52 → 1.0.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/README.md +38 -10
  2. package/dist/bin/primitive.js +6 -0
  3. package/dist/bin/primitive.js.map +1 -1
  4. package/dist/src/commands/auth.js +16 -6
  5. package/dist/src/commands/auth.js.map +1 -1
  6. package/dist/src/commands/blob-buckets.js +84 -7
  7. package/dist/src/commands/blob-buckets.js.map +1 -1
  8. package/dist/src/commands/catalog.js +3 -3
  9. package/dist/src/commands/catalog.js.map +1 -1
  10. package/dist/src/commands/collections.js +12 -9
  11. package/dist/src/commands/collections.js.map +1 -1
  12. package/dist/src/commands/database-types.js +11 -1
  13. package/dist/src/commands/database-types.js.map +1 -1
  14. package/dist/src/commands/databases.js +197 -74
  15. package/dist/src/commands/databases.js.map +1 -1
  16. package/dist/src/commands/group-type-configs.js +1 -9
  17. package/dist/src/commands/group-type-configs.js.map +1 -1
  18. package/dist/src/commands/groups.js +12 -6
  19. package/dist/src/commands/groups.js.map +1 -1
  20. package/dist/src/commands/guides.d.ts +161 -0
  21. package/dist/src/commands/guides.js +502 -84
  22. package/dist/src/commands/guides.js.map +1 -1
  23. package/dist/src/commands/init.js +77 -45
  24. package/dist/src/commands/init.js.map +1 -1
  25. package/dist/src/commands/integrations.js +2 -2
  26. package/dist/src/commands/integrations.js.map +1 -1
  27. package/dist/src/commands/metadata.d.ts +2 -0
  28. package/dist/src/commands/metadata.js +344 -0
  29. package/dist/src/commands/metadata.js.map +1 -0
  30. package/dist/src/commands/prompts.js +2 -2
  31. package/dist/src/commands/prompts.js.map +1 -1
  32. package/dist/src/commands/rule-sets.d.ts +1 -0
  33. package/dist/src/commands/rule-sets.js +25 -3
  34. package/dist/src/commands/rule-sets.js.map +1 -1
  35. package/dist/src/commands/scripts.d.ts +2 -0
  36. package/dist/src/commands/scripts.js +667 -0
  37. package/dist/src/commands/scripts.js.map +1 -0
  38. package/dist/src/commands/sync.d.ts +212 -16
  39. package/dist/src/commands/sync.js +1688 -287
  40. package/dist/src/commands/sync.js.map +1 -1
  41. package/dist/src/commands/vars.d.ts +8 -0
  42. package/dist/src/commands/vars.js +110 -0
  43. package/dist/src/commands/vars.js.map +1 -0
  44. package/dist/src/commands/webhooks.js +17 -3
  45. package/dist/src/commands/webhooks.js.map +1 -1
  46. package/dist/src/commands/workflows.d.ts +30 -0
  47. package/dist/src/commands/workflows.js +651 -52
  48. package/dist/src/commands/workflows.js.map +1 -1
  49. package/dist/src/lib/api-client.d.ts +123 -19
  50. package/dist/src/lib/api-client.js +128 -4
  51. package/dist/src/lib/api-client.js.map +1 -1
  52. package/dist/src/lib/batch.d.ts +26 -0
  53. package/dist/src/lib/batch.js +32 -0
  54. package/dist/src/lib/batch.js.map +1 -0
  55. package/dist/src/lib/block-layout.d.ts +160 -0
  56. package/dist/src/lib/block-layout.js +451 -0
  57. package/dist/src/lib/block-layout.js.map +1 -0
  58. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +61 -0
  59. package/dist/src/lib/codegen-shared/generatedFiles.js +127 -0
  60. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
  61. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
  62. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
  63. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
  64. package/dist/src/lib/config-toml.d.ts +10 -0
  65. package/dist/src/lib/config-toml.js +42 -0
  66. package/dist/src/lib/config-toml.js.map +1 -0
  67. package/dist/src/lib/config.d.ts +16 -0
  68. package/dist/src/lib/config.js +41 -0
  69. package/dist/src/lib/config.js.map +1 -1
  70. package/dist/src/lib/constants.d.ts +9 -0
  71. package/dist/src/lib/constants.js +9 -0
  72. package/dist/src/lib/constants.js.map +1 -1
  73. package/dist/src/lib/csv.d.ts +1 -2
  74. package/dist/src/lib/csv.js +3 -8
  75. package/dist/src/lib/csv.js.map +1 -1
  76. package/dist/src/lib/db-codegen/dbGenerator.d.ts +35 -7
  77. package/dist/src/lib/db-codegen/dbGenerator.js +384 -125
  78. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  79. package/dist/src/lib/db-codegen/dbNaming.d.ts +29 -0
  80. package/dist/src/lib/db-codegen/dbNaming.js +58 -0
  81. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  82. package/dist/src/lib/db-codegen/dbTemplates.d.ts +114 -5
  83. package/dist/src/lib/db-codegen/dbTemplates.js +163 -16
  84. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  85. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
  86. package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
  87. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  88. package/dist/src/lib/generated-allowlist.js +52 -0
  89. package/dist/src/lib/generated-allowlist.js.map +1 -1
  90. package/dist/src/lib/init-config.d.ts +13 -0
  91. package/dist/src/lib/init-config.js +21 -2
  92. package/dist/src/lib/init-config.js.map +1 -1
  93. package/dist/src/lib/output.d.ts +42 -5
  94. package/dist/src/lib/output.js +70 -4
  95. package/dist/src/lib/output.js.map +1 -1
  96. package/dist/src/lib/query-operators.d.ts +43 -0
  97. package/dist/src/lib/query-operators.js +80 -0
  98. package/dist/src/lib/query-operators.js.map +1 -0
  99. package/dist/src/lib/template.d.ts +9 -5
  100. package/dist/src/lib/template.js +58 -45
  101. package/dist/src/lib/template.js.map +1 -1
  102. package/dist/src/lib/toml-database-config.d.ts +10 -19
  103. package/dist/src/lib/toml-database-config.js +28 -59
  104. package/dist/src/lib/toml-database-config.js.map +1 -1
  105. package/dist/src/lib/toml-metadata-config.d.ts +147 -0
  106. package/dist/src/lib/toml-metadata-config.js +463 -0
  107. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  108. package/dist/src/lib/toml-native-form.d.ts +46 -0
  109. package/dist/src/lib/toml-native-form.js +78 -0
  110. package/dist/src/lib/toml-native-form.js.map +1 -0
  111. package/dist/src/lib/toml-params-validator.d.ts +34 -0
  112. package/dist/src/lib/toml-params-validator.js +118 -3
  113. package/dist/src/lib/toml-params-validator.js.map +1 -1
  114. package/dist/src/lib/workflow-apply.d.ts +86 -0
  115. package/dist/src/lib/workflow-apply.js +127 -0
  116. package/dist/src/lib/workflow-apply.js.map +1 -0
  117. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
  118. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
  119. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
  120. package/dist/src/lib/workflow-codegen/generator.d.ts +74 -0
  121. package/dist/src/lib/workflow-codegen/generator.js +215 -0
  122. package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
  123. package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
  124. package/dist/src/lib/workflow-codegen/naming.js +81 -0
  125. package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
  126. package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
  127. package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
  128. package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
  129. package/dist/src/lib/workflow-fragments.js +3 -3
  130. package/dist/src/lib/workflow-fragments.js.map +1 -1
  131. package/dist/src/lib/workflow-payload.d.ts +68 -0
  132. package/dist/src/lib/workflow-payload.js +150 -0
  133. package/dist/src/lib/workflow-payload.js.map +1 -0
  134. package/dist/src/lib/workflow-toml-validator.d.ts +1 -1
  135. package/dist/src/lib/workflow-toml-validator.js +37 -1
  136. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  137. package/dist/src/types/index.d.ts +11 -0
  138. package/dist/src/validators.d.ts +4 -3
  139. package/dist/src/validators.js +6 -5
  140. package/dist/src/validators.js.map +1 -1
  141. package/package.json +5 -3
@@ -29,6 +29,7 @@
29
29
  * `$params.config.subKey` without listing every sub-field
30
30
  * individually (review feedback r3246635661).
31
31
  */
32
+ import { collectUnknownOperators } from "./query-operators.js";
32
33
  /**
33
34
  * Walk an arbitrary JSON-ish value and collect `$params.X` references
34
35
  * found in string-valued leaves, returning only the first dotted segment
@@ -58,6 +59,88 @@ export function collectParamRefs(value) {
58
59
  }
59
60
  return refs;
60
61
  }
62
+ /**
63
+ * Collect bare `params.X` references from a CEL string (issue #1239).
64
+ *
65
+ * Access rules reference operation params with the bare `params.X` form (no
66
+ * `$` prefix), unlike `definition`, which uses `$params.X` (scanned by
67
+ * {@link collectParamRefs}). This helper feeds the operation's `access` CEL
68
+ * and each per-param `access` CEL into the "referenced" set so a param used
69
+ * only by an access rule is not wrongly flagged "declared but not referenced".
70
+ *
71
+ * Supported forms, all whitespace-tolerant:
72
+ * - dot notation: `params.claimedUserId`, `params . claimedUserId`
73
+ * - dot path: `params.config.subField` → first segment `config`
74
+ * - bracket notation: `params["claimedUserId"]`, `params['claimedUserId']`
75
+ *
76
+ * Word-boundary guard: a `params` preceded by an identifier char, `$`, or `.`
77
+ * is NOT a match, so `$params.x` (definition syntax), `myparams.x`, and a
78
+ * dotted member access like `database.metadata.params.userId` are ignored —
79
+ * `params` only counts as the params root when it's a standalone root
80
+ * identifier. To avoid counting a `params.` that merely appears inside a quoted
81
+ * string literal (e.g. `note == "see params.docs"`), bracket keys are scanned
82
+ * first (they legitimately contain quotes), then string literals are stripped
83
+ * before the dot-notation scan.
84
+ *
85
+ * Purely additive: this only grows the referenced set, loosening the soft
86
+ * warning. The blocking `$params` error path is untouched.
87
+ */
88
+ export function collectCelParamRefs(cel) {
89
+ if (typeof cel !== "string" || cel.length === 0)
90
+ return [];
91
+ const refs = [];
92
+ // Bracket notation: params["X"] / params['X']. Run before stripping string
93
+ // literals so the quoted key survives.
94
+ const bracketRe = /(?<![\w$.])params\s*\[\s*["']([^"']+)["']\s*\]/g;
95
+ let m;
96
+ while ((m = bracketRe.exec(cel)) !== null) {
97
+ const first = m[1].split(/[.\[]/)[0];
98
+ if (first)
99
+ refs.push(first);
100
+ }
101
+ // Drop string literals so `params.` inside a quoted string is not counted.
102
+ const withoutStrings = cel.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, "");
103
+ // Dot notation: params.X (first segment only, mirroring collectParamRefs).
104
+ const dotRe = /(?<![\w$.])params\s*\.\s*([A-Za-z_$][\w$]*)/g;
105
+ while ((m = dotRe.exec(withoutStrings)) !== null) {
106
+ refs.push(m[1]);
107
+ }
108
+ return refs;
109
+ }
110
+ /**
111
+ * Collect the per-param `access` CEL strings from an operation's `params`
112
+ * value (object, array, or JSON string form). Used by issue #1239 to count
113
+ * params referenced only inside another param's `access` rule.
114
+ */
115
+ function collectParamAccessCels(params) {
116
+ const cels = [];
117
+ if (params == null)
118
+ return cels;
119
+ let value = params;
120
+ if (typeof value === "string") {
121
+ try {
122
+ value = JSON.parse(value);
123
+ }
124
+ catch {
125
+ return cels;
126
+ }
127
+ }
128
+ if (Array.isArray(value)) {
129
+ for (const row of value) {
130
+ if (row && typeof row === "object" && typeof row.access === "string") {
131
+ cels.push(row.access);
132
+ }
133
+ }
134
+ }
135
+ else if (typeof value === "object" && value !== null) {
136
+ for (const entry of Object.values(value)) {
137
+ if (entry && typeof entry === "object" && typeof entry.access === "string") {
138
+ cels.push(entry.access);
139
+ }
140
+ }
141
+ }
142
+ return cels;
143
+ }
61
144
  /**
62
145
  * Normalize a `params` value (object, array, or JSON string) into the
63
146
  * set of declared param names.
@@ -146,9 +229,24 @@ export function validateOperations(opts) {
146
229
  if (!op || !op.name)
147
230
  continue;
148
231
  const declared = declaredParamNames(op.params);
149
- const refs = new Set(collectParamRefs(op.definition));
232
+ // `definitionRefs` drives the BLOCKING error loop and must stay limited to
233
+ // `$params.X` references inside `definition` — access CEL refs are NOT
234
+ // declarations, so they must never produce an "undeclared" error.
235
+ const definitionRefs = new Set(collectParamRefs(op.definition));
236
+ // Issue #1239: a param referenced only by an access CEL rule (bare
237
+ // `params.X`) is still referenced. The "declared but not referenced"
238
+ // warning uses a wider set that also counts the operation-level `access`
239
+ // and each per-param `access` CEL. Purely additive — the blocking error
240
+ // path below is built only from `definitionRefs`.
241
+ const referenced = new Set(definitionRefs);
242
+ for (const ref of collectCelParamRefs(op.access))
243
+ referenced.add(ref);
244
+ for (const cel of collectParamAccessCels(op.params)) {
245
+ for (const ref of collectCelParamRefs(cel))
246
+ referenced.add(ref);
247
+ }
150
248
  const line = locateOperationLine(opts.rawToml, op.name);
151
- for (const ref of refs) {
249
+ for (const ref of definitionRefs) {
152
250
  if (!declared.has(ref)) {
153
251
  errors.push({
154
252
  file: opts.filePath,
@@ -159,7 +257,7 @@ export function validateOperations(opts) {
159
257
  }
160
258
  }
161
259
  for (const name of declared) {
162
- if (!refs.has(name)) {
260
+ if (!referenced.has(name)) {
163
261
  warnings.push({
164
262
  file: opts.filePath,
165
263
  line,
@@ -168,6 +266,23 @@ export function validateOperations(opts) {
168
266
  });
169
267
  }
170
268
  }
269
+ // Issue #1255 (Fork 4): warn on unknown filter operators. The server only
270
+ // checks that `filter` is an object at push time, so a typo like
271
+ // `$gt` → `$gte` or an invented `$foo` slips through and throws
272
+ // `InvalidOperatorError` only at query execution. We warn (not error) to
273
+ // avoid CLI/server divergence — the operator set could drift, and the
274
+ // server stays authoritative.
275
+ const filter = op.definition && typeof op.definition === "object"
276
+ ? op.definition.filter
277
+ : undefined;
278
+ for (const badOp of collectUnknownOperators(filter)) {
279
+ warnings.push({
280
+ file: opts.filePath,
281
+ line,
282
+ op: op.name,
283
+ message: `unknown filter operator '${badOp}' in operation '${op.name}' — not a recognized query operator; it will fail at query execution`,
284
+ });
285
+ }
171
286
  }
172
287
  return { errors, warnings };
173
288
  }
@@ -1 +1 @@
1
- {"version":3,"file":"toml-params-validator.js","sourceRoot":"","sources":["../../../src/lib/toml-params-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAcH;;;;;;GAMG;AACH,MAAM,UAAU,gB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AI,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Shared "apply a TOML body to an existing workflow" helper.
3
+ *
4
+ * Extracted from the `sync push` update-existing path (#1249, Fork 4) so that
5
+ * both `sync push` and `workflows update --from-file` push a revised body the
6
+ * same way. A second inlined copy would regress #807: the update is
7
+ * ordering-sensitive and a naive metadata-then-body sequence rejects valid
8
+ * sync-callable edits.
9
+ *
10
+ * Ordering invariant (#807 / codex review):
11
+ * 1. metadata PATCH — WITHOUT `syncCallable`. The server re-validates
12
+ * `syncCallable: true` against the workflow's CURRENTLY-active server
13
+ * steps (`loadCurrentActiveSteps`, src/admin-api.ts:4734), not the steps
14
+ * being pushed in the same call. So enabling sync-callable in the first
15
+ * PATCH would validate against the stale active steps and be rejected.
16
+ * 2. body write — steps to the active config (config-model) or the legacy
17
+ * draft slot (no active config).
18
+ * 3. a SECOND `syncCallable` PATCH — issued AFTER the new steps are active,
19
+ * so it validates against the new (compatible) steps.
20
+ */
21
+ import type { ApiClient } from "./api-client.js";
22
+ import { safeJsonParse } from "./workflow-payload.js";
23
+ export { safeJsonParse };
24
+ export interface ApplyWorkflowBodyOptions {
25
+ /** Optimistic-concurrency guard for the metadata + syncCallable PATCHes. */
26
+ expectedModifiedAt?: string;
27
+ /**
28
+ * Active config to overwrite in place (config-model workflows). When absent,
29
+ * the body falls back to the legacy draft slot — non-live for config-model
30
+ * workflows, which the server rejects with 409 WORKFLOW_CONFIG_MODEL.
31
+ */
32
+ activeConfigId?: string;
33
+ /** When true, skip the optimistic-concurrency check (mirrors `--force`). */
34
+ force?: boolean;
35
+ }
36
+ export interface ApplyWorkflowBodyResult {
37
+ /** The freshest workflow `modifiedAt` after all PATCHes (for sync state). */
38
+ latestModifiedAt?: string;
39
+ /** Which slot the steps landed in: "active config" or "draft (legacy)". */
40
+ updateSlotLabel: string;
41
+ /** A fresh `getWorkflow` result so callers can read back configs/state. */
42
+ fullWorkflow: any;
43
+ }
44
+ /**
45
+ * Apply a parsed workflow body (metadata + steps) to an existing workflow,
46
+ * preserving the key/id. `workflow` is the TOML's `[workflow]` table (already
47
+ * merged with any explicit CLI flag overrides by the caller); `steps` is the
48
+ * TOML's `steps` array. The function performs the three-step ordered update
49
+ * and returns the latest `modifiedAt`, the slot label, and a fresh workflow.
50
+ */
51
+ export declare function applyWorkflowBody(client: ApiClient, appId: string, workflowId: string, workflow: any, steps: any[], opts?: ApplyWorkflowBodyOptions): Promise<ApplyWorkflowBodyResult>;
52
+ /**
53
+ * #1232 — parse the `workflows update --capabilities` flag into the array the
54
+ * server's update handler expects. This is the CLI fallback the issue asked
55
+ * for ("workflows update has no capability flag"): a grant/revoke channel for
56
+ * an existing workflow, since `sync push` create deliberately does not forward
57
+ * capabilities (#1233, Q2) and there was otherwise no way to set them on an
58
+ * existing workflow.
59
+ *
60
+ * Semantics (mirrors how the server normalizes the field):
61
+ * --capabilities membership → ["membership"] (grant)
62
+ * --capabilities membership,secrets → ["membership","secrets"]
63
+ * --capabilities " membership , x " → ["membership","x"] (trimmed)
64
+ * --capabilities "" → [] (revoke all;
65
+ * server stores empty as null)
66
+ *
67
+ * The set of grantable capability names ("membership" / "secrets") is validated
68
+ * server-side by `validateWorkflowIdentityConfig`; the CLI intentionally does
69
+ * NOT duplicate that allowlist so it can't drift from the server. An unknown
70
+ * name is surfaced via the server's structured `details[]` error.
71
+ *
72
+ * The caller applies presence-guarded plumbing (`options.capabilities !==
73
+ * undefined`) so an omitted flag never reaches the payload — the server's
74
+ * `hasOwnProperty` guard then leaves the existing grant untouched.
75
+ */
76
+ export declare function parseCapabilitiesFlag(value: string): string[];
77
+ /**
78
+ * Fork 2 (#1249): a TOML pushed at a specific `<id>` may also declare a `key` /
79
+ * `workflowKey`. If it differs from the target's actual key, that's almost
80
+ * certainly the wrong file — error rather than silently ignoring it. An absent
81
+ * TOML key is advisory and allowed (the operation targets `<id>`).
82
+ *
83
+ * Returns an error message string when there is a mismatch, otherwise null.
84
+ * Pure function for unit testing.
85
+ */
86
+ export declare function workflowKeyMismatchError(tomlWorkflow: any, existingWorkflowKey: string | undefined): string | null;
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Shared "apply a TOML body to an existing workflow" helper.
3
+ *
4
+ * Extracted from the `sync push` update-existing path (#1249, Fork 4) so that
5
+ * both `sync push` and `workflows update --from-file` push a revised body the
6
+ * same way. A second inlined copy would regress #807: the update is
7
+ * ordering-sensitive and a naive metadata-then-body sequence rejects valid
8
+ * sync-callable edits.
9
+ *
10
+ * Ordering invariant (#807 / codex review):
11
+ * 1. metadata PATCH — WITHOUT `syncCallable`. The server re-validates
12
+ * `syncCallable: true` against the workflow's CURRENTLY-active server
13
+ * steps (`loadCurrentActiveSteps`, src/admin-api.ts:4734), not the steps
14
+ * being pushed in the same call. So enabling sync-callable in the first
15
+ * PATCH would validate against the stale active steps and be rejected.
16
+ * 2. body write — steps to the active config (config-model) or the legacy
17
+ * draft slot (no active config).
18
+ * 3. a SECOND `syncCallable` PATCH — issued AFTER the new steps are active,
19
+ * so it validates against the new (compatible) steps.
20
+ */
21
+ import { buildWorkflowPayloadFromToml, safeJsonParse } from "./workflow-payload.js";
22
+ // #1177: `safeJsonParse` now lives in the shared `workflow-payload` lib module
23
+ // (the builder needs it too); re-exported here so existing importers of this
24
+ // module keep working. Both `cli/src/lib` modules; no dep-direction problem.
25
+ export { safeJsonParse };
26
+ /**
27
+ * Apply a parsed workflow body (metadata + steps) to an existing workflow,
28
+ * preserving the key/id. `workflow` is the TOML's `[workflow]` table (already
29
+ * merged with any explicit CLI flag overrides by the caller); `steps` is the
30
+ * TOML's `steps` array. The function performs the three-step ordered update
31
+ * and returns the latest `modifiedAt`, the slot label, and a fresh workflow.
32
+ */
33
+ export async function applyWorkflowBody(client, appId, workflowId, workflow, steps, opts = {}) {
34
+ const { expectedModifiedAt, activeConfigId, force } = opts;
35
+ // 1. Metadata PATCH — note: NO `syncCallable` here (deferred to step 3). The
36
+ // shared builder (#1177, `mode: "update"`) omits `syncCallable` for exactly
37
+ // this reason and applies the presence-aware clear-vs-leave semantics for
38
+ // `accessRule` / `runAs` / `capabilities` / schemas. `requiresClientApply`
39
+ // has no step-dependent validation, so the builder keeps it here. The
40
+ // `metadataManifest` declared-access manifest (#1304) is call-site-specific
41
+ // and attached below, not owned by the shared builder.
42
+ const updated = await client.updateWorkflow(appId, workflowId, {
43
+ ...buildWorkflowPayloadFromToml(workflow, { mode: "update" }),
44
+ // #1304 (P-C): declared-access manifest. Absent key → undefined (server's
45
+ // hasOwnProperty guard leaves it untouched); a parsed value/null is
46
+ // forwarded so a pull → push round-trips it (null clears). `sync push`
47
+ // always attaches this (null when the TOML drops `[metadata]`); the
48
+ // `workflows update --from-file` caller may leave it undefined.
49
+ metadataManifest: workflow.metadataManifest !== undefined ? workflow.metadataManifest : undefined,
50
+ }, expectedModifiedAt);
51
+ // The first PATCH bumps `modifiedAt`; the syncCallable PATCH (if any) bumps
52
+ // it again. The config/step update does NOT touch the workflow definition's
53
+ // `modifiedAt`.
54
+ let latestModifiedAt = updated?.workflow?.modifiedAt;
55
+ // 2. Body write — active config (config-model) or legacy draft slot.
56
+ let updateSlotLabel = "active config";
57
+ if (activeConfigId) {
58
+ await client.updateWorkflowConfig(appId, workflowId, activeConfigId, { steps });
59
+ }
60
+ else {
61
+ await client.updateWorkflowDraft(appId, workflowId, {
62
+ steps,
63
+ inputSchema: workflow.inputSchema ? safeJsonParse(workflow.inputSchema) : null,
64
+ });
65
+ updateSlotLabel = "draft (legacy)";
66
+ }
67
+ // 3. Deferred `syncCallable` PATCH — now that the new steps are active (#807).
68
+ // Only sent when the TOML actually carries the key; an absent key stays
69
+ // `undefined` and the call is skipped, preserving no-clobber discipline.
70
+ if (workflow.syncCallable !== undefined) {
71
+ const syncCallableUpdated = await client.updateWorkflow(appId, workflowId, { syncCallable: workflow.syncCallable }, force ? undefined : latestModifiedAt);
72
+ if (syncCallableUpdated?.workflow?.modifiedAt) {
73
+ latestModifiedAt = syncCallableUpdated.workflow.modifiedAt;
74
+ }
75
+ }
76
+ const fullWorkflow = await client.getWorkflow(appId, workflowId);
77
+ return { latestModifiedAt, updateSlotLabel, fullWorkflow };
78
+ }
79
+ /**
80
+ * #1232 — parse the `workflows update --capabilities` flag into the array the
81
+ * server's update handler expects. This is the CLI fallback the issue asked
82
+ * for ("workflows update has no capability flag"): a grant/revoke channel for
83
+ * an existing workflow, since `sync push` create deliberately does not forward
84
+ * capabilities (#1233, Q2) and there was otherwise no way to set them on an
85
+ * existing workflow.
86
+ *
87
+ * Semantics (mirrors how the server normalizes the field):
88
+ * --capabilities membership → ["membership"] (grant)
89
+ * --capabilities membership,secrets → ["membership","secrets"]
90
+ * --capabilities " membership , x " → ["membership","x"] (trimmed)
91
+ * --capabilities "" → [] (revoke all;
92
+ * server stores empty as null)
93
+ *
94
+ * The set of grantable capability names ("membership" / "secrets") is validated
95
+ * server-side by `validateWorkflowIdentityConfig`; the CLI intentionally does
96
+ * NOT duplicate that allowlist so it can't drift from the server. An unknown
97
+ * name is surfaced via the server's structured `details[]` error.
98
+ *
99
+ * The caller applies presence-guarded plumbing (`options.capabilities !==
100
+ * undefined`) so an omitted flag never reaches the payload — the server's
101
+ * `hasOwnProperty` guard then leaves the existing grant untouched.
102
+ */
103
+ export function parseCapabilitiesFlag(value) {
104
+ return value
105
+ .split(",")
106
+ .map((cap) => cap.trim())
107
+ .filter((cap) => cap.length > 0);
108
+ }
109
+ /**
110
+ * Fork 2 (#1249): a TOML pushed at a specific `<id>` may also declare a `key` /
111
+ * `workflowKey`. If it differs from the target's actual key, that's almost
112
+ * certainly the wrong file — error rather than silently ignoring it. An absent
113
+ * TOML key is advisory and allowed (the operation targets `<id>`).
114
+ *
115
+ * Returns an error message string when there is a mismatch, otherwise null.
116
+ * Pure function for unit testing.
117
+ */
118
+ export function workflowKeyMismatchError(tomlWorkflow, existingWorkflowKey) {
119
+ const tomlKey = tomlWorkflow?.key ?? tomlWorkflow?.workflowKey;
120
+ if (tomlKey && existingWorkflowKey && tomlKey !== existingWorkflowKey) {
121
+ return (`TOML workflow key "${tomlKey}" does not match the target workflow's key ` +
122
+ `"${existingWorkflowKey}". This usually means you pointed --from-file at the ` +
123
+ `wrong workflow id. Remove the key from the TOML or target the matching id.`);
124
+ }
125
+ return null;
126
+ }
127
+ //# sourceMappingURL=workflow-apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-apply.js","sourceRoot":"","sources":["../../../src/lib/workflow-apply.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEpF,+EAA+E;AAC/E,6EAA6E;AAC7E,6EAA6E;AAC7E,OAAO,EAAE,aAAa,EAAE,CAAC;AAwBzB;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAiB,EACjB,KAAa,EACb,UAAkB,EAClB,QAAa,EACb,KAAY,EACZ,OAAiC,EAAE;IAEnC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAE3D,6EAA6E;IAC7E,+EAA+E;IAC/E,6EAA6E;IAC7E,8EAA8E;IAC9E,yEAAyE;IACzE,+EAA+E;IAC/E,0DAA0D;IAC1D,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,cAAc,CACzC,KAAK,EACL,UAAU,EACV;QACE,GAAG,4BAA4B,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QAC7D,0EAA0E;QAC1E,oEAAoE;QACpE,uEAAuE;QACvE,oEAAoE;QACpE,gEAAgE;QAChE,gBAAgB,EACd,QAAQ,CAAC,gBAAgB,KAAK,SAAS,CAAC,C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,EAAE,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACxB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAAiB,EACjB,mBAAuC;IAEvC,MAAM,OAAO,GAAG,YAAY,EAAE,GAAG,IAAI,YAAY,EAAE,WAAW,CAAC;IAC/D,IAAI,OAAO,IAAI,mBAAmB,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;QACtE,OAAO,CACL,sBAAsB,OAAO,6CAA6C;YAC1E,IAAI,mBAAmB,uDAAuD;YAC9E,4EAA4E,CAC7E,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * GENERATED FILE — DO NOT EDIT BY HAND.
3
+ *
4
+ * Vendored byte-for-byte from the canonical server module
5
+ * `src/workflows/schema-descriptor.ts` — the SAME interpretation the server
6
+ * validator (`validateValue`) enforces. The CLI cannot import server `src/`
7
+ * at runtime, so `workflows codegen`'s type converter imports this committed
8
+ * copy instead.
9
+ *
10
+ * Regenerate with:
11
+ * node cli/scripts/gen-workflow-schema-descriptor.mjs (runs at CLI prebuild)
12
+ *
13
+ * A CI freshness guard
14
+ * (`cli/scripts/gen-workflow-schema-descriptor.mjs --check`, also asserted by
15
+ * `cli/tests/unit/workflow-codegen-descriptor-drift-guard.test.ts`) fails if
16
+ * this committed copy does not match the source — see issue #1442 / #998.
17
+ */
18
+ /**
19
+ * Canonical interpretation of the JSON-Schema subset the workflow platform
20
+ * supports (issue #1442).
21
+ *
22
+ * The server validator (`validateValue` in `schema-validation.ts`) and the CLI
23
+ * `workflows codegen` type converter (`workflow-codegen/schemaToTs.ts`) must
24
+ * agree EXACTLY on how a workflow `inputSchema`/`outputSchema` is interpreted —
25
+ * otherwise a generated `<Key>Input` type promises a shape the runtime does not
26
+ * enforce (or rejects a value the runtime accepts). Previously the converter
27
+ * re-derived those interpretation decisions by hand, which drifts from the
28
+ * validator over time.
29
+ *
30
+ * This module is the single source of that interpretation. Both consumers read
31
+ * from `describeSchema` + `isType`:
32
+ *
33
+ * - the type gate is checked before `enum` (a value failing `type` is
34
+ * rejected before `enum` is consulted);
35
+ * - a type UNION (`type: ["string","null"]`) never descends into
36
+ * `properties`/`items` — only the exact string types `"object"`/`"array"`
37
+ * do;
38
+ * - `integer` means `Number.isInteger`;
39
+ * - `additionalProperties` only closes an object; it is not a nested schema.
40
+ *
41
+ * It is deliberately dependency-free (no imports) so the CLI can vendor a
42
+ * byte-for-byte copy as a committed artifact via
43
+ * `cli/scripts/gen-workflow-schema-descriptor.mjs` (the #998 gen-allowlist
44
+ * pattern). A drift-guard test runs that generator in `--check` mode, so a
45
+ * change here that isn't regenerated into the CLI artifact fails CI. The CLI
46
+ * never imports server `src/` at runtime — only the build-time generator reads
47
+ * this file.
48
+ */
49
+ /** Does a value satisfy a JSON-schema `type` name? `integer` = `Number.isInteger`. */
50
+ export declare function isType(value: any, type: string): boolean;
51
+ /**
52
+ * The interpretation of a single schema node, normalized so both the validator
53
+ * and the type converter can consume it without re-reading raw schema fields.
54
+ */
55
+ export interface SchemaDescriptor {
56
+ /** True when `schema.type` is an array (a type union). */
57
+ isUnion: boolean;
58
+ /** `schema.type` when it is a single string; null for a union or absent type. */
59
+ singularType: string | null;
60
+ /**
61
+ * The declared type(s) normalized to an array. An array `type` is kept as-is;
62
+ * a single string becomes a one-element array; an absent/falsy type is `[]`
63
+ * (no type gate). Matches the validator's `allowedTypes` normalization.
64
+ */
65
+ types: string[];
66
+ /** The `enum` array when present, else null. */
67
+ enumValues: any[] | null;
68
+ /**
69
+ * Object descent info — non-null ONLY when `schema.type` is exactly the
70
+ * string `"object"` AND `properties` is a declared object (matching the
71
+ * validator's `schema.type === "object" && schema.properties` descent gate).
72
+ * A type UNION containing `"object"` never descends.
73
+ */
74
+ object: {
75
+ /** The raw `properties` map (child schemas). May be empty `{}`. */
76
+ properties: Record<string, any>;
77
+ /** The raw `required` list (unfiltered, as the validator reads it). */
78
+ required: any[];
79
+ /** True when `additionalProperties === false` (a closed object). */
80
+ additionalPropertiesClosed: boolean;
81
+ } | null;
82
+ /**
83
+ * Array descent info — non-null ONLY when `schema.type` is exactly the string
84
+ * `"array"` AND `items` is present (matching the validator's
85
+ * `schema.type === "array" && schema.items` descent gate).
86
+ */
87
+ array: {
88
+ /** The raw `items` schema (may be a tuple array the validator no-ops on). */
89
+ items: any;
90
+ } | null;
91
+ /**
92
+ * Discriminated-union (tagged-union) interpretation of a `oneOf` node (#1511).
93
+ *
94
+ * Populated ONLY when the node carries a `oneOf` (or `anyOf`) array whose
95
+ * members are ALL `type: "object"` — a clearly-intended tagged union. A
96
+ * `oneOf`/`anyOf` with any non-object member is NOT a tagged union: `oneOf`
97
+ * stays `null` here and is ignored (renders `unknown` / validates
98
+ * permissively) exactly as before, preserving backward compatibility.
99
+ *
100
+ * - `kind: "valid"` — a clean discriminated union: ≥2 object members sharing
101
+ * exactly one discriminator property declared as a single-literal `enum`
102
+ * in every member with distinct literals across members. The validator
103
+ * branch-selects by `discriminant` and validates only the matched member;
104
+ * the type converter renders the `|`-union of member object types.
105
+ * - `kind: "invalid"` — an all-object-member union that LOOKS like a tagged
106
+ * union but is defective (fewer than 2 members, no/ambiguous discriminator,
107
+ * or `anyOf` — unsupported in v1). `reason` is the codegen error message.
108
+ * The runtime validator ignores this (stays permissive); the codegen
109
+ * converter throws `reason` (Fork 3 = strict, resolved by the maintainer).
110
+ */
111
+ oneOf: {
112
+ kind: "valid";
113
+ /** The auto-detected discriminator property name. */
114
+ discriminant: string;
115
+ /** One entry per member: its discriminant literal + raw member schema. */
116
+ members: Array<{
117
+ discriminantValue: any;
118
+ schema: any;
119
+ }>;
120
+ } | {
121
+ kind: "invalid";
122
+ reason: string;
123
+ } | null;
124
+ }
125
+ /**
126
+ * Interpret a parsed schema node. A non-object schema (null, array, scalar)
127
+ * enforces nothing → the empty descriptor.
128
+ */
129
+ export declare function describeSchema(schema: any): SchemaDescriptor;