primitive-admin 1.0.53 → 1.0.55

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 (173) hide show
  1. package/README.md +38 -10
  2. package/dist/bin/primitive.js +8 -0
  3. package/dist/bin/primitive.js.map +1 -1
  4. package/dist/src/commands/apps.js +54 -2
  5. package/dist/src/commands/apps.js.map +1 -1
  6. package/dist/src/commands/auth.js +16 -6
  7. package/dist/src/commands/auth.js.map +1 -1
  8. package/dist/src/commands/blob-buckets.js +84 -7
  9. package/dist/src/commands/blob-buckets.js.map +1 -1
  10. package/dist/src/commands/catalog.js +3 -3
  11. package/dist/src/commands/catalog.js.map +1 -1
  12. package/dist/src/commands/collections.js +12 -9
  13. package/dist/src/commands/collections.js.map +1 -1
  14. package/dist/src/commands/databases.js +220 -82
  15. package/dist/src/commands/databases.js.map +1 -1
  16. package/dist/src/commands/documents.js +77 -0
  17. package/dist/src/commands/documents.js.map +1 -1
  18. package/dist/src/commands/group-type-configs.js +1 -9
  19. package/dist/src/commands/group-type-configs.js.map +1 -1
  20. package/dist/src/commands/groups.js +12 -6
  21. package/dist/src/commands/groups.js.map +1 -1
  22. package/dist/src/commands/guides.d.ts +161 -0
  23. package/dist/src/commands/guides.js +502 -84
  24. package/dist/src/commands/guides.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/settings.d.ts +15 -0
  39. package/dist/src/commands/settings.js +102 -0
  40. package/dist/src/commands/settings.js.map +1 -0
  41. package/dist/src/commands/sync-app-settings.d.ts +105 -0
  42. package/dist/src/commands/sync-app-settings.js +339 -0
  43. package/dist/src/commands/sync-app-settings.js.map +1 -0
  44. package/dist/src/commands/sync.d.ts +204 -9
  45. package/dist/src/commands/sync.js +1706 -371
  46. package/dist/src/commands/sync.js.map +1 -1
  47. package/dist/src/commands/vars.d.ts +8 -0
  48. package/dist/src/commands/vars.js +110 -0
  49. package/dist/src/commands/vars.js.map +1 -0
  50. package/dist/src/commands/webhooks.js +17 -3
  51. package/dist/src/commands/webhooks.js.map +1 -1
  52. package/dist/src/commands/workflows.d.ts +30 -0
  53. package/dist/src/commands/workflows.js +667 -59
  54. package/dist/src/commands/workflows.js.map +1 -1
  55. package/dist/src/lib/api-client.d.ts +122 -18
  56. package/dist/src/lib/api-client.js +131 -2
  57. package/dist/src/lib/api-client.js.map +1 -1
  58. package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
  59. package/dist/src/lib/app-settings-descriptor.js +250 -0
  60. package/dist/src/lib/app-settings-descriptor.js.map +1 -0
  61. package/dist/src/lib/batch.d.ts +26 -0
  62. package/dist/src/lib/batch.js +32 -0
  63. package/dist/src/lib/batch.js.map +1 -0
  64. package/dist/src/lib/block-layout.d.ts +160 -0
  65. package/dist/src/lib/block-layout.js +451 -0
  66. package/dist/src/lib/block-layout.js.map +1 -0
  67. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +76 -0
  68. package/dist/src/lib/codegen-shared/generatedFiles.js +144 -0
  69. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
  70. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +68 -0
  71. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +168 -0
  72. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
  73. package/dist/src/lib/config-toml.d.ts +10 -0
  74. package/dist/src/lib/config-toml.js +42 -0
  75. package/dist/src/lib/config-toml.js.map +1 -0
  76. package/dist/src/lib/config.d.ts +16 -0
  77. package/dist/src/lib/config.js +41 -0
  78. package/dist/src/lib/config.js.map +1 -1
  79. package/dist/src/lib/constants.d.ts +9 -0
  80. package/dist/src/lib/constants.js +9 -0
  81. package/dist/src/lib/constants.js.map +1 -1
  82. package/dist/src/lib/csv.d.ts +1 -2
  83. package/dist/src/lib/csv.js +3 -8
  84. package/dist/src/lib/csv.js.map +1 -1
  85. package/dist/src/lib/db-codegen/dbGenerator.d.ts +21 -65
  86. package/dist/src/lib/db-codegen/dbGenerator.js +117 -321
  87. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  88. package/dist/src/lib/db-codegen/dbNaming.d.ts +37 -0
  89. package/dist/src/lib/db-codegen/dbNaming.js +70 -0
  90. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  91. package/dist/src/lib/db-codegen/dbTemplates.d.ts +165 -5
  92. package/dist/src/lib/db-codegen/dbTemplates.js +292 -16
  93. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  94. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +7 -3
  95. package/dist/src/lib/db-codegen/dbTsTypes.js +23 -1
  96. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  97. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
  98. package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
  99. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
  100. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +101 -0
  101. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +200 -0
  102. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
  103. package/dist/src/lib/generated-allowlist.js +43 -0
  104. package/dist/src/lib/generated-allowlist.js.map +1 -1
  105. package/dist/src/lib/init-config.js +2 -2
  106. package/dist/src/lib/init-config.js.map +1 -1
  107. package/dist/src/lib/output.d.ts +25 -5
  108. package/dist/src/lib/output.js +32 -4
  109. package/dist/src/lib/output.js.map +1 -1
  110. package/dist/src/lib/query-operators.d.ts +43 -0
  111. package/dist/src/lib/query-operators.js +80 -0
  112. package/dist/src/lib/query-operators.js.map +1 -0
  113. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +68 -0
  114. package/dist/src/lib/swift-codegen/dbGenerator.js +380 -0
  115. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
  116. package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
  117. package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
  118. package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
  119. package/dist/src/lib/swift-codegen/generator.d.ts +84 -0
  120. package/dist/src/lib/swift-codegen/generator.js +178 -0
  121. package/dist/src/lib/swift-codegen/generator.js.map +1 -0
  122. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
  123. package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
  124. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
  125. package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
  126. package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
  127. package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
  128. package/dist/src/lib/sync-resource-types.d.ts +225 -0
  129. package/dist/src/lib/sync-resource-types.js +394 -0
  130. package/dist/src/lib/sync-resource-types.js.map +1 -0
  131. package/dist/src/lib/toml-database-config.d.ts +10 -19
  132. package/dist/src/lib/toml-database-config.js +28 -59
  133. package/dist/src/lib/toml-database-config.js.map +1 -1
  134. package/dist/src/lib/toml-metadata-config.d.ts +147 -0
  135. package/dist/src/lib/toml-metadata-config.js +463 -0
  136. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  137. package/dist/src/lib/toml-native-form.d.ts +46 -0
  138. package/dist/src/lib/toml-native-form.js +78 -0
  139. package/dist/src/lib/toml-native-form.js.map +1 -0
  140. package/dist/src/lib/toml-params-validator.d.ts +34 -0
  141. package/dist/src/lib/toml-params-validator.js +118 -3
  142. package/dist/src/lib/toml-params-validator.js.map +1 -1
  143. package/dist/src/lib/workflow-apply.d.ts +86 -0
  144. package/dist/src/lib/workflow-apply.js +127 -0
  145. package/dist/src/lib/workflow-apply.js.map +1 -0
  146. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
  147. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
  148. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
  149. package/dist/src/lib/workflow-codegen/generator.d.ts +87 -0
  150. package/dist/src/lib/workflow-codegen/generator.js +290 -0
  151. package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
  152. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +85 -0
  153. package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
  154. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
  155. package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
  156. package/dist/src/lib/workflow-codegen/naming.js +81 -0
  157. package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
  158. package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +64 -0
  159. package/dist/src/lib/workflow-codegen/schemaToTs.js +282 -0
  160. package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
  161. package/dist/src/lib/workflow-fragments.js +3 -3
  162. package/dist/src/lib/workflow-fragments.js.map +1 -1
  163. package/dist/src/lib/workflow-payload.d.ts +68 -0
  164. package/dist/src/lib/workflow-payload.js +150 -0
  165. package/dist/src/lib/workflow-payload.js.map +1 -0
  166. package/dist/src/lib/workflow-toml-validator.d.ts +1 -1
  167. package/dist/src/lib/workflow-toml-validator.js +37 -1
  168. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  169. package/dist/src/types/index.d.ts +11 -0
  170. package/dist/src/validators.d.ts +4 -3
  171. package/dist/src/validators.js +6 -5
  172. package/dist/src/validators.js.map +1 -1
  173. package/package.json +7 -3
@@ -0,0 +1,147 @@
1
+ /**
2
+ * CLI TOML parser / validator / serializer for resource-metadata config
3
+ * surfaces (issue #1304, P-B — CLI/TOML config-sync).
4
+ *
5
+ * Two surfaces, mirroring the "config change ships all three surfaces" rule
6
+ * (CLAUDE.md; same shape as the database type-config helpers in
7
+ * `toml-database-config.ts`):
8
+ *
9
+ * 1. `MetadataCategoryConfig` blocks — a per-`{resourceType, category}`
10
+ * typed-schema + read/write-rule definition. These round-trip through
11
+ * `primitive sync push` / `pull` against the P-A REST API
12
+ * (`metadata-categories` CRUD). One file = one category, using a single
13
+ * `[metadataCategoryConfig]` section so the nested `schema.fields.*`
14
+ * tables serialize cleanly and byte-stably.
15
+ *
16
+ * 2. The declared-access manifest (`[metadata]` + `secrets` blocks) that
17
+ * lives on the owning config surfaces (`CollectionTypeConfig` /
18
+ * `DatabaseTypeConfig` / `WorkflowDefinition`). This module provides the
19
+ * TOML *structure* + *validator* + byte-stable round-trip helpers for the
20
+ * manifest so a bad value is rejected with a clear error. Wiring the
21
+ * manifest onto those config models' sync push/pull (which needs a
22
+ * storage field on each model) is P-C's "persist the manifest on owning
23
+ * configs" work — this module ships the parse/validate/serialize the
24
+ * P-C eval-site folding will call, matching how earlier phases shipped a
25
+ * validated mechanism ahead of its live wiring.
26
+ *
27
+ * All functions here are pure and unit-testable (no network, no filesystem).
28
+ * `validate*` functions return an error string (or `null` when valid) rather
29
+ * than throwing, mirroring `validateCategorySchema` server-side.
30
+ */
31
+ /** The reserved projected category (computed live from a resource's columns).
32
+ * Matches the server's `RESERVED_PROJECTED_CATEGORY`. */
33
+ export declare const RESERVED_CATEGORY = "attrs";
34
+ /** The REST body shape for a category-config upsert (P-A `metadata-categories`). */
35
+ export interface MetadataCategoryConfigInput {
36
+ resourceType: string;
37
+ category: string;
38
+ schema: unknown;
39
+ readRule: string | null;
40
+ writeRule: string | null;
41
+ description: string | null;
42
+ /**
43
+ * Declared-access manifest (#1420 Phase 2) — the top-level `[metadata]` /
44
+ * `secrets` block that lets the category's `readRule`/`writeRule` reach
45
+ * `md.self.*` / `secrets.*`. Null when the config declares none.
46
+ */
47
+ metadataManifest: DeclaredAccessManifest | null;
48
+ }
49
+ /**
50
+ * Normalize a parsed `[metadataCategoryConfig]` TOML section into the REST
51
+ * upsert body. Server-managed fields (`schemaVersion`, `generation`) are never
52
+ * emitted or read here — they'd churn a round-trip.
53
+ */
54
+ export declare function parseMetadataCategoryToml(tomlData: any): MetadataCategoryConfigInput;
55
+ /**
56
+ * Validate a parsed category config (post-{@link parseMetadataCategoryToml}).
57
+ * Returns an error string, or `null` when valid. The server re-validates on
58
+ * write; this is the fast local check so `sync push` fails with a clear
59
+ * message before hitting the network.
60
+ */
61
+ export declare function validateMetadataCategoryConfig(input: MetadataCategoryConfigInput): string | null;
62
+ /**
63
+ * Validate the `schema` block is a well-formed js-bao `FieldOptions` map:
64
+ * `{ fields: { <name>: { type, required?, maxLength?, maxCount?, enum? } } }`.
65
+ * Mirrors the server's `validateCategorySchema`.
66
+ */
67
+ export declare function validateCategorySchema(schema: unknown): string | null;
68
+ /**
69
+ * Serialize a category config (as returned by the P-A REST API — `schema` is a
70
+ * parsed object) to byte-stable TOML. Only the authored fields are emitted;
71
+ * server-managed `schemaVersion` / `generation` / `appId` / `categoryKey` are
72
+ * dropped so a pull → push → pull cycle is a no-op.
73
+ *
74
+ * Scalars are inserted before `schema` so `smol-toml` emits them ahead of
75
+ * the nested `[metadataCategoryConfig.schema.fields.*]` tables.
76
+ */
77
+ export declare function serializeMetadataCategoryConfig(config: any): string;
78
+ /** The one **server-authenticated** `rootFrom` root — the calling user's id
79
+ * (issue #1362). Unlike the {@link ROOT_CONTEXT_PREFIXES} roots (caller-supplied),
80
+ * `user.userId` binds the authenticated principal, so a rule may read the
81
+ * caller's own metadata (`md.<name>`). Mirrors the server's `CALLER_ROOTFROM`. */
82
+ export declare const CALLER_ROOTFROM = "user.userId";
83
+ /** The target `type` a {@link CALLER_ROOTFROM} path must declare. `user.userId`
84
+ * names a user, so the path must resolve `user`-typed metadata; a mismatched
85
+ * type would silently query `app#<type>#<userId>` for a resource that isn't the
86
+ * user. Mirrors the server's `CALLER_ROOTFROM_TYPE`. */
87
+ export declare const CALLER_ROOTFROM_TYPE = "user";
88
+ /**
89
+ * Validate a path's `rootFrom` value together with its declared target `type`
90
+ * (issue #1362), mirroring the server's `validateRootFromPath`
91
+ * (`src/app-api/helpers/metadata-cel-access.ts`). A `rootFrom` is sound when it
92
+ * is either:
93
+ *
94
+ * - a static dotted **caller-supplied** context path rooted at one of
95
+ * {@link ROOT_CONTEXT_PREFIXES} (`input.*`/`record.*`/`params.*`), with at
96
+ * least two segments; or
97
+ * - exactly {@link CALLER_ROOTFROM} (`user.userId`) — the one
98
+ * **server-authenticated** root — in which case the path must also declare
99
+ * `type = "user"` ({@link CALLER_ROOTFROM_TYPE}).
100
+ *
101
+ * Any other `user.*` path is rejected outright — the caller root is a single
102
+ * special case, not a blanket `user.*` namespace (Fork 1 = A). This is the fast
103
+ * local check so `sync push` fails with a clear message before the network call;
104
+ * the server's `validateRootFromPath` re-validates at persist time. Returns a
105
+ * human-readable reason (worded to follow `metadata.paths."<name>" `), or null
106
+ * when sound.
107
+ */
108
+ export declare function validateRootFromPath(root: string, type: string | undefined): string | null;
109
+ export interface DeclaredAccessManifest {
110
+ self?: {
111
+ categories: string[];
112
+ };
113
+ paths?: Record<string, {
114
+ from?: string;
115
+ rootFrom?: string;
116
+ via?: string;
117
+ type?: string;
118
+ categories: string[];
119
+ }>;
120
+ secrets?: string[];
121
+ vars?: string[];
122
+ }
123
+ /**
124
+ * Read the declared-access manifest out of a parsed config TOML: the top-level
125
+ * `[metadata]` table (self + paths) and the `secrets` / `vars` arrays. Returns
126
+ * `null` when none is present (the config declares no metadata/scalar access).
127
+ */
128
+ export declare function parseDeclaredAccessManifestToml(tomlData: any): DeclaredAccessManifest | null;
129
+ /**
130
+ * Validate a declared-access manifest structurally. Returns an error string,
131
+ * or `null` when valid. This is the local surface-level check (identifier
132
+ * names, key shape, exactly-one-root per path); the server's
133
+ * `validatePathGraph` still does the deep graph validation (cycles, depth,
134
+ * schema-mismatch) at persist time.
135
+ */
136
+ export declare function validateDeclaredAccessManifest(manifest: DeclaredAccessManifest | null | undefined): string | null;
137
+ /**
138
+ * Serialize a declared-access manifest into the TOML fragment object that
139
+ * merges into an owning config's TOML data (the caller spreads the returned
140
+ * keys alongside the config's own section). Returns `{}` when empty so a
141
+ * config with no declared access emits nothing (byte-stable).
142
+ */
143
+ export declare function serializeDeclaredAccessManifest(manifest: DeclaredAccessManifest | null | undefined): {
144
+ metadata?: any;
145
+ secrets?: string[];
146
+ vars?: string[];
147
+ };
@@ -0,0 +1,463 @@
1
+ /**
2
+ * CLI TOML parser / validator / serializer for resource-metadata config
3
+ * surfaces (issue #1304, P-B — CLI/TOML config-sync).
4
+ *
5
+ * Two surfaces, mirroring the "config change ships all three surfaces" rule
6
+ * (CLAUDE.md; same shape as the database type-config helpers in
7
+ * `toml-database-config.ts`):
8
+ *
9
+ * 1. `MetadataCategoryConfig` blocks — a per-`{resourceType, category}`
10
+ * typed-schema + read/write-rule definition. These round-trip through
11
+ * `primitive sync push` / `pull` against the P-A REST API
12
+ * (`metadata-categories` CRUD). One file = one category, using a single
13
+ * `[metadataCategoryConfig]` section so the nested `schema.fields.*`
14
+ * tables serialize cleanly and byte-stably.
15
+ *
16
+ * 2. The declared-access manifest (`[metadata]` + `secrets` blocks) that
17
+ * lives on the owning config surfaces (`CollectionTypeConfig` /
18
+ * `DatabaseTypeConfig` / `WorkflowDefinition`). This module provides the
19
+ * TOML *structure* + *validator* + byte-stable round-trip helpers for the
20
+ * manifest so a bad value is rejected with a clear error. Wiring the
21
+ * manifest onto those config models' sync push/pull (which needs a
22
+ * storage field on each model) is P-C's "persist the manifest on owning
23
+ * configs" work — this module ships the parse/validate/serialize the
24
+ * P-C eval-site folding will call, matching how earlier phases shipped a
25
+ * validated mechanism ahead of its live wiring.
26
+ *
27
+ * All functions here are pure and unit-testable (no network, no filesystem).
28
+ * `validate*` functions return an error string (or `null` when valid) rather
29
+ * than throwing, mirroring `validateCategorySchema` server-side.
30
+ */
31
+ import { stringifyConfigToml } from "./config-toml.js";
32
+ /** Identifier-safe name: letters, digits, underscore; not starting with a digit.
33
+ * Matches the server's `METADATA_KEY_PATTERN`. */
34
+ const IDENTIFIER_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
35
+ /** The key format the `secrets` / `vars` services accept when a value is created
36
+ * (server's `SCALAR_KEY_RE`, secrets/vars service `KEY_REGEX`). A declared
37
+ * scalar-root key that is identifier-safe but does not match this (e.g.
38
+ * lowercase) can never be created via the API, so reject it at manifest-parse
39
+ * time on both ends (issue #1364). */
40
+ const SCALAR_KEY_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/;
41
+ /** The reserved projected category (computed live from a resource's columns).
42
+ * Matches the server's `RESERVED_PROJECTED_CATEGORY`. */
43
+ export const RESERVED_CATEGORY = "attrs";
44
+ /** The subset of js-bao `FieldOptions` field types the metadata schema accepts.
45
+ * Matches the server's `MetadataFieldType`. */
46
+ const METADATA_FIELD_TYPES = new Set([
47
+ "string",
48
+ "number",
49
+ "boolean",
50
+ "date",
51
+ "id",
52
+ "stringset",
53
+ ]);
54
+ const CATEGORY_SECTION_KEYS = new Set([
55
+ "resourceType",
56
+ "category",
57
+ "schema",
58
+ "readRule",
59
+ "writeRule",
60
+ "description",
61
+ ]);
62
+ /**
63
+ * Normalize a parsed `[metadataCategoryConfig]` TOML section into the REST
64
+ * upsert body. Server-managed fields (`schemaVersion`, `generation`) are never
65
+ * emitted or read here — they'd churn a round-trip.
66
+ */
67
+ export function parseMetadataCategoryToml(tomlData) {
68
+ const section = (tomlData && tomlData.metadataCategoryConfig) || {};
69
+ return {
70
+ resourceType: section.resourceType,
71
+ category: section.category,
72
+ schema: section.schema,
73
+ readRule: section.readRule ?? null,
74
+ writeRule: section.writeRule ?? null,
75
+ description: section.description ?? null,
76
+ // #1420 Phase 2: the manifest lives in the top-level `[metadata]`/`secrets`
77
+ // block (sibling to `[metadataCategoryConfig]`), reusing the shared parser.
78
+ metadataManifest: parseDeclaredAccessManifestToml(tomlData),
79
+ };
80
+ }
81
+ /**
82
+ * Validate a parsed category config (post-{@link parseMetadataCategoryToml}).
83
+ * Returns an error string, or `null` when valid. The server re-validates on
84
+ * write; this is the fast local check so `sync push` fails with a clear
85
+ * message before hitting the network.
86
+ */
87
+ export function validateMetadataCategoryConfig(input) {
88
+ if (!input.resourceType || typeof input.resourceType !== "string") {
89
+ return "metadataCategoryConfig.resourceType is required and must be a string";
90
+ }
91
+ if (!IDENTIFIER_PATTERN.test(input.resourceType)) {
92
+ return `metadataCategoryConfig.resourceType "${input.resourceType}" must be identifier-safe (letters, digits, underscore; not starting with a digit)`;
93
+ }
94
+ if (!input.category || typeof input.category !== "string") {
95
+ return "metadataCategoryConfig.category is required and must be a string";
96
+ }
97
+ if (!IDENTIFIER_PATTERN.test(input.category)) {
98
+ return `metadataCategoryConfig.category "${input.category}" must be identifier-safe (letters, digits, underscore; not starting with a digit)`;
99
+ }
100
+ if (input.category === RESERVED_CATEGORY) {
101
+ return `metadataCategoryConfig.category "${RESERVED_CATEGORY}" is reserved (a projected category computed from the resource's own columns) and cannot be defined`;
102
+ }
103
+ if (input.readRule !== null &&
104
+ input.readRule !== undefined &&
105
+ typeof input.readRule !== "string") {
106
+ return "metadataCategoryConfig.readRule must be a string (a CEL expression)";
107
+ }
108
+ if (input.writeRule !== null &&
109
+ input.writeRule !== undefined &&
110
+ typeof input.writeRule !== "string") {
111
+ return "metadataCategoryConfig.writeRule must be a string (a CEL expression)";
112
+ }
113
+ if (input.description !== null &&
114
+ input.description !== undefined &&
115
+ typeof input.description !== "string") {
116
+ return "metadataCategoryConfig.description must be a string";
117
+ }
118
+ const schemaError = validateCategorySchema(input.schema);
119
+ if (schemaError)
120
+ return schemaError;
121
+ // #1420 Phase 2: local surface-level check on the declared-access manifest;
122
+ // the server re-validates the deep path graph at persist time.
123
+ return validateDeclaredAccessManifest(input.metadataManifest);
124
+ }
125
+ /**
126
+ * Validate the `schema` block is a well-formed js-bao `FieldOptions` map:
127
+ * `{ fields: { <name>: { type, required?, maxLength?, maxCount?, enum? } } }`.
128
+ * Mirrors the server's `validateCategorySchema`.
129
+ */
130
+ export function validateCategorySchema(schema) {
131
+ if (schema === null || typeof schema !== "object" || Array.isArray(schema)) {
132
+ return "metadataCategoryConfig.schema must be a table with a 'fields' map";
133
+ }
134
+ const fields = schema.fields;
135
+ if (fields === null || typeof fields !== "object" || Array.isArray(fields)) {
136
+ return "metadataCategoryConfig.schema.fields must be a table";
137
+ }
138
+ // Reject unknown top-level keys under `schema` (only `fields` is meaningful).
139
+ for (const key of Object.keys(schema)) {
140
+ if (key !== "fields") {
141
+ return `metadataCategoryConfig.schema has an unknown key "${key}" (only "fields" is allowed)`;
142
+ }
143
+ }
144
+ for (const [name, def] of Object.entries(fields)) {
145
+ if (!IDENTIFIER_PATTERN.test(name)) {
146
+ return `schema field name "${name}" must be identifier-safe`;
147
+ }
148
+ if (def === null || typeof def !== "object" || Array.isArray(def)) {
149
+ return `schema field "${name}" must be a table with a "type"`;
150
+ }
151
+ const field = def;
152
+ if (typeof field.type !== "string" || !METADATA_FIELD_TYPES.has(field.type)) {
153
+ return `schema field "${name}" has an invalid type (allowed: ${[
154
+ ...METADATA_FIELD_TYPES,
155
+ ].join(", ")})`;
156
+ }
157
+ if (field.enum !== undefined) {
158
+ if (!Array.isArray(field.enum) ||
159
+ field.enum.some((v) => typeof v !== "string")) {
160
+ return `schema field "${name}" enum must be an array of strings`;
161
+ }
162
+ if (field.type !== "string") {
163
+ return `schema field "${name}" enum is only valid on a "string" field`;
164
+ }
165
+ }
166
+ if (field.maxLength !== undefined && typeof field.maxLength !== "number") {
167
+ return `schema field "${name}" maxLength must be a number`;
168
+ }
169
+ if (field.maxCount !== undefined && typeof field.maxCount !== "number") {
170
+ return `schema field "${name}" maxCount must be a number`;
171
+ }
172
+ if (field.required !== undefined && typeof field.required !== "boolean") {
173
+ return `schema field "${name}" required must be a boolean`;
174
+ }
175
+ }
176
+ return null;
177
+ }
178
+ /**
179
+ * Serialize a category config (as returned by the P-A REST API — `schema` is a
180
+ * parsed object) to byte-stable TOML. Only the authored fields are emitted;
181
+ * server-managed `schemaVersion` / `generation` / `appId` / `categoryKey` are
182
+ * dropped so a pull → push → pull cycle is a no-op.
183
+ *
184
+ * Scalars are inserted before `schema` so `smol-toml` emits them ahead of
185
+ * the nested `[metadataCategoryConfig.schema.fields.*]` tables.
186
+ */
187
+ export function serializeMetadataCategoryConfig(config) {
188
+ const section = {
189
+ resourceType: config.resourceType,
190
+ category: config.category,
191
+ };
192
+ if (config.readRule !== null && config.readRule !== undefined) {
193
+ section.readRule = config.readRule;
194
+ }
195
+ if (config.writeRule !== null && config.writeRule !== undefined) {
196
+ section.writeRule = config.writeRule;
197
+ }
198
+ if (config.description !== null &&
199
+ config.description !== undefined &&
200
+ config.description !== "") {
201
+ section.description = config.description;
202
+ }
203
+ // `schema` may arrive as a parsed object (REST) or a JSON string (defensive).
204
+ let schema = config.schema;
205
+ if (typeof schema === "string") {
206
+ try {
207
+ schema = JSON.parse(schema);
208
+ }
209
+ catch {
210
+ schema = { fields: {} };
211
+ }
212
+ }
213
+ section.schema = schema ?? { fields: {} };
214
+ // #1420 Phase 2: emit the declared-access manifest as a top-level
215
+ // `[metadata]`/`secrets` block (sibling to `[metadataCategoryConfig]`),
216
+ // reusing the shared serializer so it round-trips byte-stable.
217
+ return stringifyConfigToml({
218
+ metadataCategoryConfig: section,
219
+ ...serializeDeclaredAccessManifest(config.metadataManifest),
220
+ });
221
+ }
222
+ // --- Declared-access manifest (`[metadata]` + `secrets` + `vars`) ----------
223
+ //
224
+ // The manifest that lives on an owning config surface. Shape mirrors the
225
+ // server's `MetadataDeclaration` (`src/app-api/helpers/metadata-cel-access.ts`):
226
+ // metadata.self.categories = ["profile"]
227
+ // [metadata.paths.<name>] from|rootFrom, via, type, categories
228
+ // secrets = ["STRIPE_KEY"]
229
+ // vars = ["ADMIN_GROUP_ID"] # non-secret twin of secrets (issue #1364)
230
+ /** Root contexts a `rootFrom` path may start at (caller-supplied subjectless
231
+ * contexts). Mirrors the server's `ROOT_CONTEXT_PREFIXES`
232
+ * (`src/app-api/helpers/metadata-cel-access.ts`). */
233
+ const ROOT_CONTEXT_PREFIXES = ["input", "record", "params"];
234
+ /** The one **server-authenticated** `rootFrom` root — the calling user's id
235
+ * (issue #1362). Unlike the {@link ROOT_CONTEXT_PREFIXES} roots (caller-supplied),
236
+ * `user.userId` binds the authenticated principal, so a rule may read the
237
+ * caller's own metadata (`md.<name>`). Mirrors the server's `CALLER_ROOTFROM`. */
238
+ export const CALLER_ROOTFROM = "user.userId";
239
+ /** The target `type` a {@link CALLER_ROOTFROM} path must declare. `user.userId`
240
+ * names a user, so the path must resolve `user`-typed metadata; a mismatched
241
+ * type would silently query `app#<type>#<userId>` for a resource that isn't the
242
+ * user. Mirrors the server's `CALLER_ROOTFROM_TYPE`. */
243
+ export const CALLER_ROOTFROM_TYPE = "user";
244
+ /**
245
+ * Validate a path's `rootFrom` value together with its declared target `type`
246
+ * (issue #1362), mirroring the server's `validateRootFromPath`
247
+ * (`src/app-api/helpers/metadata-cel-access.ts`). A `rootFrom` is sound when it
248
+ * is either:
249
+ *
250
+ * - a static dotted **caller-supplied** context path rooted at one of
251
+ * {@link ROOT_CONTEXT_PREFIXES} (`input.*`/`record.*`/`params.*`), with at
252
+ * least two segments; or
253
+ * - exactly {@link CALLER_ROOTFROM} (`user.userId`) — the one
254
+ * **server-authenticated** root — in which case the path must also declare
255
+ * `type = "user"` ({@link CALLER_ROOTFROM_TYPE}).
256
+ *
257
+ * Any other `user.*` path is rejected outright — the caller root is a single
258
+ * special case, not a blanket `user.*` namespace (Fork 1 = A). This is the fast
259
+ * local check so `sync push` fails with a clear message before the network call;
260
+ * the server's `validateRootFromPath` re-validates at persist time. Returns a
261
+ * human-readable reason (worded to follow `metadata.paths."<name>" `), or null
262
+ * when sound.
263
+ */
264
+ export function validateRootFromPath(root, type) {
265
+ if (root === CALLER_ROOTFROM) {
266
+ if (type !== CALLER_ROOTFROM_TYPE) {
267
+ return `rootFrom "${CALLER_ROOTFROM}" requires type = "${CALLER_ROOTFROM_TYPE}" (got ${type ? `"${type}"` : "no type"})`;
268
+ }
269
+ return null;
270
+ }
271
+ const prefix = root.split(".")[0];
272
+ if (prefix === "user") {
273
+ return `rootFrom "${root}" is not allowed — the only server-authenticated root is "${CALLER_ROOTFROM}"`;
274
+ }
275
+ const segments = root.split(".");
276
+ const isStaticDotted = segments.length >= 1 && segments.every((s) => IDENTIFIER_PATTERN.test(s));
277
+ if (!isStaticDotted ||
278
+ segments.length < 2 ||
279
+ !ROOT_CONTEXT_PREFIXES.includes(prefix)) {
280
+ return `rootFrom "${root}" must be a static dotted context path rooted at ${ROOT_CONTEXT_PREFIXES.join("/")} or "${CALLER_ROOTFROM}"`;
281
+ }
282
+ return null;
283
+ }
284
+ const MANIFEST_KEYS = new Set(["self", "paths", "secrets", "vars"]);
285
+ const SELF_KEYS = new Set(["categories"]);
286
+ const PATH_KEYS = new Set(["from", "rootFrom", "via", "type", "categories"]);
287
+ /** The declared scalar roots: `secrets` (masked) and `vars` (non-secret). */
288
+ const SCALAR_ROOT_KEYS = [
289
+ { key: "secrets", singular: "secret" },
290
+ { key: "vars", singular: "var" },
291
+ ];
292
+ /**
293
+ * Read the declared-access manifest out of a parsed config TOML: the top-level
294
+ * `[metadata]` table (self + paths) and the `secrets` / `vars` arrays. Returns
295
+ * `null` when none is present (the config declares no metadata/scalar access).
296
+ */
297
+ export function parseDeclaredAccessManifestToml(tomlData) {
298
+ const metadata = tomlData?.metadata;
299
+ const secrets = tomlData?.secrets;
300
+ const vars = tomlData?.vars;
301
+ if (metadata === undefined && secrets === undefined && vars === undefined) {
302
+ return null;
303
+ }
304
+ const manifest = {};
305
+ if (metadata && typeof metadata === "object") {
306
+ if (metadata.self !== undefined) {
307
+ manifest.self = { categories: metadata.self?.categories };
308
+ }
309
+ if (metadata.paths !== undefined) {
310
+ manifest.paths = metadata.paths;
311
+ }
312
+ }
313
+ if (secrets !== undefined) {
314
+ manifest.secrets = secrets;
315
+ }
316
+ if (vars !== undefined) {
317
+ manifest.vars = vars;
318
+ }
319
+ return manifest;
320
+ }
321
+ /**
322
+ * Validate a declared-access manifest structurally. Returns an error string,
323
+ * or `null` when valid. This is the local surface-level check (identifier
324
+ * names, key shape, exactly-one-root per path); the server's
325
+ * `validatePathGraph` still does the deep graph validation (cycles, depth,
326
+ * schema-mismatch) at persist time.
327
+ */
328
+ export function validateDeclaredAccessManifest(manifest) {
329
+ if (manifest === null || manifest === undefined)
330
+ return null;
331
+ if (typeof manifest !== "object" || Array.isArray(manifest)) {
332
+ return "declared-access manifest must be a table";
333
+ }
334
+ // `self`
335
+ if (manifest.self !== undefined) {
336
+ const self = manifest.self;
337
+ if (self === null || typeof self !== "object" || Array.isArray(self)) {
338
+ return "metadata.self must be a table with a 'categories' array";
339
+ }
340
+ for (const key of Object.keys(self)) {
341
+ if (!SELF_KEYS.has(key)) {
342
+ return `metadata.self has an unknown key "${key}" (only "categories" is allowed)`;
343
+ }
344
+ }
345
+ const catError = validateCategoryList(self.categories, "metadata.self");
346
+ if (catError)
347
+ return catError;
348
+ }
349
+ // `paths`
350
+ if (manifest.paths !== undefined) {
351
+ const paths = manifest.paths;
352
+ if (paths === null || typeof paths !== "object" || Array.isArray(paths)) {
353
+ return "metadata.paths must be a table of named path declarations";
354
+ }
355
+ const declaredNodes = new Set(["self", ...Object.keys(paths)]);
356
+ for (const [name, raw] of Object.entries(paths)) {
357
+ if (!IDENTIFIER_PATTERN.test(name)) {
358
+ return `metadata.paths."${name}" name must be identifier-safe`;
359
+ }
360
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
361
+ return `metadata.paths."${name}" must be a table`;
362
+ }
363
+ const p = raw;
364
+ for (const key of Object.keys(p)) {
365
+ if (!PATH_KEYS.has(key)) {
366
+ return `metadata.paths."${name}" has an unknown key "${key}" (allowed: ${[
367
+ ...PATH_KEYS,
368
+ ].join(", ")})`;
369
+ }
370
+ }
371
+ const hasFrom = typeof p.from === "string" && p.from !== "";
372
+ const hasRoot = typeof p.rootFrom === "string" && p.rootFrom !== "";
373
+ if (hasFrom === hasRoot) {
374
+ return `metadata.paths."${name}" must declare exactly one of "from" or "rootFrom"`;
375
+ }
376
+ if (hasFrom) {
377
+ if (!declaredNodes.has(p.from)) {
378
+ return `metadata.paths."${name}" from "${p.from}" references an undeclared node (must be "self" or another declared path)`;
379
+ }
380
+ if (typeof p.via !== "string" || !p.via.includes(".")) {
381
+ return `metadata.paths."${name}" must declare a "via" of the form "<category>.<key>"`;
382
+ }
383
+ }
384
+ else {
385
+ // rootFrom: a caller-supplied static context path
386
+ // (`input.*`/`record.*`/`params.*`) OR the server-authenticated
387
+ // `user.userId` root (which requires `type = "user"`). Mirrors the
388
+ // server's `validateRootFromPath` (issue #1362).
389
+ const rootFrom = p.rootFrom;
390
+ const type = typeof p.type === "string" ? p.type : undefined;
391
+ const rootReason = validateRootFromPath(rootFrom, type);
392
+ if (rootReason) {
393
+ return `metadata.paths."${name}" ${rootReason}`;
394
+ }
395
+ if (p.via !== undefined) {
396
+ return `metadata.paths."${name}" roots at "${rootFrom}" and must not also declare "via"`;
397
+ }
398
+ }
399
+ if (typeof p.type !== "string" || p.type === "") {
400
+ return `metadata.paths."${name}" must declare a target "type" (the resource type)`;
401
+ }
402
+ const catError = validateCategoryList(p.categories, `metadata.paths."${name}"`);
403
+ if (catError)
404
+ return catError;
405
+ }
406
+ }
407
+ // `secrets` / `vars` — the declared scalar roots share one key-list shape.
408
+ for (const { key: rootKey, singular } of SCALAR_ROOT_KEYS) {
409
+ const keys = manifest[rootKey];
410
+ if (keys === undefined)
411
+ continue;
412
+ if (!Array.isArray(keys) || keys.some((s) => typeof s !== "string")) {
413
+ return `${rootKey} must be an array of ${singular} key names (strings)`;
414
+ }
415
+ for (const key of keys) {
416
+ if (!SCALAR_KEY_PATTERN.test(key)) {
417
+ return `${rootKey} key "${key}" must match ^[A-Z][A-Z0-9_]{0,63}$ (uppercase letters, digits, underscores; must start with a letter; max 64 chars)`;
418
+ }
419
+ }
420
+ }
421
+ return null;
422
+ }
423
+ function validateCategoryList(categories, where) {
424
+ if (!Array.isArray(categories) ||
425
+ categories.some((c) => typeof c !== "string")) {
426
+ return `${where}.categories must be an array of category names (strings)`;
427
+ }
428
+ for (const cat of categories) {
429
+ if (cat !== RESERVED_CATEGORY && !IDENTIFIER_PATTERN.test(cat)) {
430
+ return `${where}.categories entry "${cat}" must be identifier-safe`;
431
+ }
432
+ }
433
+ return null;
434
+ }
435
+ /**
436
+ * Serialize a declared-access manifest into the TOML fragment object that
437
+ * merges into an owning config's TOML data (the caller spreads the returned
438
+ * keys alongside the config's own section). Returns `{}` when empty so a
439
+ * config with no declared access emits nothing (byte-stable).
440
+ */
441
+ export function serializeDeclaredAccessManifest(manifest) {
442
+ if (!manifest)
443
+ return {};
444
+ const out = {};
445
+ const metadata = {};
446
+ if (manifest.self && Array.isArray(manifest.self.categories)) {
447
+ metadata.self = { categories: manifest.self.categories };
448
+ }
449
+ if (manifest.paths && Object.keys(manifest.paths).length > 0) {
450
+ metadata.paths = manifest.paths;
451
+ }
452
+ if (Object.keys(metadata).length > 0) {
453
+ out.metadata = metadata;
454
+ }
455
+ if (Array.isArray(manifest.secrets) && manifest.secrets.length > 0) {
456
+ out.secrets = manifest.secrets;
457
+ }
458
+ if (Array.isArray(manifest.vars) && manifest.vars.length > 0) {
459
+ out.vars = manifest.vars;
460
+ }
461
+ return out;
462
+ }
463
+ //# sourceMappingURL=toml-metadata-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toml-metadata-config.js","sourceRoot":"","sources":["../../../src/lib/toml-metadata-config.ts"],"names":[],"mappings":"AAAA;;;;;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