primitive-admin 1.1.0-alpha.46 → 1.1.0-alpha.48

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 (78) hide show
  1. package/dist/bin/primitive.js +2 -0
  2. package/dist/bin/primitive.js.map +1 -1
  3. package/dist/src/commands/apps.js +54 -2
  4. package/dist/src/commands/apps.js.map +1 -1
  5. package/dist/src/commands/databases.js +31 -10
  6. package/dist/src/commands/databases.js.map +1 -1
  7. package/dist/src/commands/documents.js +77 -0
  8. package/dist/src/commands/documents.js.map +1 -1
  9. package/dist/src/commands/groups.js +9 -4
  10. package/dist/src/commands/groups.js.map +1 -1
  11. package/dist/src/commands/metadata.js +150 -0
  12. package/dist/src/commands/metadata.js.map +1 -1
  13. package/dist/src/commands/settings.d.ts +15 -0
  14. package/dist/src/commands/settings.js +102 -0
  15. package/dist/src/commands/settings.js.map +1 -0
  16. package/dist/src/commands/sync-app-settings.d.ts +105 -0
  17. package/dist/src/commands/sync-app-settings.js +339 -0
  18. package/dist/src/commands/sync-app-settings.js.map +1 -0
  19. package/dist/src/commands/sync.d.ts +169 -19
  20. package/dist/src/commands/sync.js +942 -190
  21. package/dist/src/commands/sync.js.map +1 -1
  22. package/dist/src/commands/webhooks.js +10 -1
  23. package/dist/src/commands/webhooks.js.map +1 -1
  24. package/dist/src/commands/workflows.d.ts +30 -0
  25. package/dist/src/commands/workflows.js +305 -12
  26. package/dist/src/commands/workflows.js.map +1 -1
  27. package/dist/src/lib/api-client.d.ts +33 -2
  28. package/dist/src/lib/api-client.js +52 -7
  29. package/dist/src/lib/api-client.js.map +1 -1
  30. package/dist/src/lib/app-settings-descriptor.d.ts +108 -0
  31. package/dist/src/lib/app-settings-descriptor.js +250 -0
  32. package/dist/src/lib/app-settings-descriptor.js.map +1 -0
  33. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +15 -0
  34. package/dist/src/lib/codegen-shared/generatedFiles.js +27 -10
  35. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -1
  36. package/dist/src/lib/db-codegen/dbGenerator.d.ts +11 -83
  37. package/dist/src/lib/db-codegen/dbGenerator.js +93 -556
  38. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -1
  39. package/dist/src/lib/db-codegen/dbNaming.d.ts +15 -7
  40. package/dist/src/lib/db-codegen/dbNaming.js +25 -13
  41. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -1
  42. package/dist/src/lib/db-codegen/dbTemplates.d.ts +55 -4
  43. package/dist/src/lib/db-codegen/dbTemplates.js +169 -40
  44. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  45. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
  46. package/dist/src/lib/db-codegen/dbTypeIR.js +517 -0
  47. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
  48. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +101 -0
  49. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +200 -0
  50. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
  51. package/dist/src/lib/generated-allowlist.js +10 -0
  52. package/dist/src/lib/generated-allowlist.js.map +1 -1
  53. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +68 -0
  54. package/dist/src/lib/swift-codegen/dbGenerator.js +380 -0
  55. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
  56. package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
  57. package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
  58. package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
  59. package/dist/src/lib/swift-codegen/generator.d.ts +84 -0
  60. package/dist/src/lib/swift-codegen/generator.js +178 -0
  61. package/dist/src/lib/swift-codegen/generator.js.map +1 -0
  62. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +72 -0
  63. package/dist/src/lib/swift-codegen/schemaToSwift.js +644 -0
  64. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
  65. package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
  66. package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
  67. package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
  68. package/dist/src/lib/sync-resource-types.d.ts +225 -0
  69. package/dist/src/lib/sync-resource-types.js +394 -0
  70. package/dist/src/lib/sync-resource-types.js.map +1 -0
  71. package/dist/src/lib/workflow-codegen/generator.d.ts +18 -5
  72. package/dist/src/lib/workflow-codegen/generator.js +116 -41
  73. package/dist/src/lib/workflow-codegen/generator.js.map +1 -1
  74. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +85 -0
  75. package/dist/src/lib/workflow-codegen/invokerIR.js +71 -0
  76. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
  77. package/dist/src/types/index.d.ts +4 -0
  78. package/package.json +4 -2
@@ -1,5 +1,6 @@
1
1
  import { Command } from "commander";
2
2
  import { ApiClient } from "../lib/api-client.js";
3
+ import { type PresenceOutcome } from "../lib/sync-resource-types.js";
3
4
  /**
4
5
  * Wrap a server-side error so the printed message identifies which entity
5
6
  * was in flight. Used by every entity create/update/delete call site in the
@@ -66,34 +67,164 @@ export declare function hashWorkflowTomlForDiff(parsed: any): string;
66
67
  * through `hashWorkflowTomlForDiff` so it lines up with the local-file hash.
67
68
  */
68
69
  export declare function hashRemoteWorkflowForDiff(workflow: any, draft: any, configs: any[]): string;
70
+ export interface ParsedAuthSettings {
71
+ settings: Record<string, any>;
72
+ warnings: string[];
73
+ }
69
74
  /**
70
75
  * Build the [auth] block of app.toml from server settings (pull direction).
71
76
  *
72
- * Apple/OTP fields round-trip alongside the legacy google/passkey/magic-link
73
- * keys. Two asymmetries are handled deliberately:
74
- * - `appleSignInEnabled` comes back as `boolean | null`; smol-toml throws on
75
- * null, so an unset value (null) is omitted rather than written.
76
- * - `appleAudiences` is omitted when empty. An empty array and an omitted key
77
- * both mean "no audiences" (the server normalizes [] -> null), so omitting
78
- * an empty list on pull is not lossy.
77
+ * Thin wrapper over the shared field descriptor
78
+ * (`cli/src/lib/app-settings-descriptor.ts`), which now owns the [auth] field
79
+ * set that `AUTH_BOOLEAN_KEYS`/`RECOGNIZED_AUTH_KEYS` used to hard-code. The
80
+ * descriptor drives all four sections in one place, so pull, push, and the
81
+ * unrecognized-key warning can never drift apart. `googleClientSecret` is a
82
+ * secret descriptor entry and is never written.
79
83
  */
80
84
  export declare function serializeAuthBlock(settings: any): Record<string, any>;
81
- export interface ParsedAuthSettings {
82
- settings: Record<string, any>;
83
- warnings: string[];
84
- }
85
85
  /**
86
86
  * Translate the [auth] block of app.toml into app-settings fields (push
87
- * direction).
88
- *
89
- * Only keys actually present in the TOML are forwarded an omitted key is left
90
- * untouched so it never overwrites server state (e.g. flipping a previously-true
91
- * flag to false). An explicit value, including `false`, is forwarded as-is.
92
- * `appleAudiences = []` is forwarded too; the server normalizes [] -> null
93
- * ("no audiences"). Keys outside RECOGNIZED_AUTH_KEYS produce a warning rather
94
- * than a hard error, so a typo or a future key doesn't silently drop.
87
+ * direction). Kept as a focused helper over the shared descriptor; the full
88
+ * push path uses `parseTomlToAppSettings` for every section. Only keys present
89
+ * in the TOML are forwarded, so an omitted key never overwrites server state.
90
+ * Descriptor errors (a secret key, a type mismatch) are surfaced alongside the
91
+ * unrecognized-key warnings.
95
92
  */
96
93
  export declare function parseAppAuthSettings(auth: Record<string, any>): ParsedAuthSettings;
94
+ type VarEntity = {
95
+ modifiedAt: string;
96
+ contentHash?: string;
97
+ };
98
+ /**
99
+ * Decide whether `sync pull` should (over)write `vars.toml`, given the outcome
100
+ * of fetching the app's config vars.
101
+ *
102
+ * The distinction that matters (issue #1423 review): a SUCCESSFUL fetch that
103
+ * returns zero vars is safe to write — the comment-only file is the intended
104
+ * empty state. A FAILED fetch (transient 401/500/network) must NOT write,
105
+ * because `serializeVars([])` would clobber a good local `vars.toml` with a
106
+ * comment-only file while the pull otherwise reports success. On failure we
107
+ * keep the prior manifest entries so the untouched file and the sync state stay
108
+ * consistent.
109
+ *
110
+ * Pure and side-effect-free (the caller owns the actual `writeFileSync`) so the
111
+ * clobber guard is unit-testable without a live server.
112
+ */
113
+ export declare function planVarsPull(outcome: {
114
+ ok: true;
115
+ vars: any[];
116
+ } | {
117
+ ok: false;
118
+ }, priorVars?: Record<string, VarEntity>): {
119
+ write: boolean;
120
+ content: string | null;
121
+ varEntities: Record<string, VarEntity>;
122
+ };
123
+ /**
124
+ * Validate a parsed `vars.toml` table against the same key/value constraints
125
+ * the server enforces (key format, string type, non-empty, size cap) plus the
126
+ * aggregate per-app var-count cap. Returns a list of human-readable errors
127
+ * (empty when valid).
128
+ *
129
+ * Run in `sync push`'s up-front preflight pass (issue #1423 review) so an
130
+ * invalid entry — or a file that would exceed the server's `MAX_VARS_PER_APP`
131
+ * cap — aborts BEFORE any mutation is applied. Validating only individual
132
+ * entries let a 101-entry file create/update many vars before the server
133
+ * rejected a later create at the cap, leaving a partial push (issue #1423
134
+ * review pass 3). Pure and side-effect-free so it's unit-testable without a
135
+ * live server.
136
+ */
137
+ export declare function validateVarsFile(parsedVars: Record<string, unknown>): string[];
138
+ /**
139
+ * Plan the config-var writes a `sync push` should make, detecting concurrent
140
+ * remote edits before overwriting them (issue #1423 review).
141
+ *
142
+ * This is the client-side half of a two-layer concurrency guard. The vars
143
+ * PUT/DELETE endpoints now honor an `expectedModifiedAt` precondition (issue
144
+ * #1423 review r-2 P1) and raise a `ConflictError` when the server row changed
145
+ * since the caller's snapshot — the atomic, server-side check every other
146
+ * synced entity relies on. This function is the fast fail-before-mutate layer:
147
+ * it compares the recorded baseline against the current remote snapshot and, for
148
+ * a var whose remote value has drifted from what we last synced, reports a
149
+ * conflict (fed into the same `conflicts[]` accumulator the other entities use)
150
+ * before any write is attempted. A var tracked at the baseline but absent from
151
+ * the remote snapshot (deleted remotely while edited locally) is remote drift
152
+ * too, and also reported as a conflict rather than silently recreated.
153
+ * Conversely, a var removed locally that is already absent remotely is NOT
154
+ * planned for deletion — its desired (absent) state is already met, so a DELETE
155
+ * would 404 and fail the push. The same drift check guards deletions: a var
156
+ * removed locally whose remote value no longer matches the baseline was edited
157
+ * remotely since the last sync, and deleting it would silently discard that
158
+ * edit — reported as a conflict instead. `force` skips the conflict guard,
159
+ * matching `sync push --force` for every other entity.
160
+ *
161
+ * Pure and side-effect-free (the caller owns the API calls and sync-state
162
+ * updates) so the guard is unit-testable without a live server. Assumes
163
+ * `parsedVars` has already passed `validateVarsFile` (values are strings). The
164
+ * caller normally fails the push closed when the remote snapshot can't be
165
+ * fetched, but under `--force` it falls back to an empty snapshot and sets
166
+ * `snapshotUnavailable` — which keeps removed-key deletions in the plan (they'd
167
+ * otherwise be mistaken for already-deleted and dropped) and leans on the apply
168
+ * loop's idempotent 404 handling (issue #1423 review r-2 P2).
169
+ */
170
+ export declare function planVarsPush(parsedVars: Record<string, string>, baseline: Record<string, VarEntity> | undefined, remoteVars: Array<{
171
+ key: string;
172
+ value?: string;
173
+ updatedAt?: string;
174
+ }>, options?: {
175
+ force?: boolean;
176
+ snapshotUnavailable?: boolean;
177
+ }): {
178
+ upserts: Array<{
179
+ action: "create" | "update";
180
+ key: string;
181
+ value: string;
182
+ valueHash: string;
183
+ }>;
184
+ deletions: string[];
185
+ conflicts: Array<{
186
+ key: string;
187
+ serverModifiedAt: string;
188
+ localModifiedAt: string;
189
+ }>;
190
+ skippedCount: number;
191
+ };
192
+ /**
193
+ * Compute the number of config vars the server would hold after a push plan
194
+ * is applied (issue #1423 review pass 5). Validating only the local file's
195
+ * entry count misses remote-only vars: 95 local entries plus 10 vars that
196
+ * exist only on the server passes a local-count check, and the creates then
197
+ * exceed the server's cap mid-push, after earlier writes were already
198
+ * applied. Counted from the fetched remote snapshot: planned deletions remove
199
+ * keys that exist remotely (the plan already omits deletes for absent keys),
200
+ * and only upserts whose key is NOT already on the server add to the total.
201
+ * Conflicted keys are not mutated, so they contribute nothing beyond their
202
+ * current remote presence. Pure and side-effect-free so it's unit-testable
203
+ * without a live server.
204
+ */
205
+ export declare function countVarsAfterPush(remoteVars: Array<{
206
+ key: string;
207
+ }>, plan: {
208
+ upserts: Array<{
209
+ key: string;
210
+ }>;
211
+ deletions: string[];
212
+ }): number;
213
+ /**
214
+ * Compute the `sync diff` rows for config vars (issue #1423 review). Before
215
+ * this, `sync diff` ignored vars entirely, so an add/remove/value-drift between
216
+ * the local `vars.toml` and the server read as no difference. Value-aware: a
217
+ * var present on both sides whose value differs is reported as `modified`
218
+ * (framed like the other content-aware entities — `sync pull` would rewrite the
219
+ * local value). Pure and side-effect-free so it's unit-testable without a live
220
+ * server.
221
+ */
222
+ export declare function diffVars(localVars: Map<string, string>, remoteVars: Map<string, string>): Array<{
223
+ type: "var";
224
+ key: string;
225
+ status: string;
226
+ hint?: string;
227
+ }>;
97
228
  export declare function serializeWebhook(webhook: any): string;
98
229
  /**
99
230
  * Rewrite a workflow TOML file's string-form `inputSchema` / `outputSchema` to
@@ -186,5 +317,24 @@ export declare function pullScripts(client: ApiClient, appId: string, configDir:
186
317
  contentHash?: string;
187
318
  }>;
188
319
  count: number;
320
+ /**
321
+ * Which scripts the server listed, for the #1659 prune pass. `ok: false` when
322
+ * the listing failed (an older server without the route, or a transient
323
+ * error) or when any per-script fetch failed — in either case this pull's
324
+ * picture of the type is incomplete and must not drive deletions. Scripts
325
+ * skipped for having no active config are still *present*, so their keys stay
326
+ * in the set and their local `.rhai` survives.
327
+ */
328
+ presence: PresenceOutcome;
329
+ /**
330
+ * Whether the script LISTING succeeded. Distinct from `presence`: a failed
331
+ * per-script fetch blocks pruning but still leaves the other scripts written,
332
+ * so their fresh state entries must be kept. Only a failed listing means
333
+ * nothing was written and the prior state slot should be preserved whole.
334
+ */
335
+ listOk: boolean;
336
+ /** Names the server listed, empty when the listing failed. */
337
+ serverKeys: string[];
189
338
  }>;
190
339
  export declare function registerSyncCommands(program: Command): void;
340
+ export {};