primitive-admin 1.0.60 → 1.0.62

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 (310) hide show
  1. package/README.md +125 -69
  2. package/assets/skill/skills/primitive-platform/SKILL.md +336 -37
  3. package/dist/bin/primitive.js +29 -14
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +22 -8
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/analytics.js +96 -16
  8. package/dist/src/commands/analytics.js.map +1 -1
  9. package/dist/src/commands/apps.js +49 -188
  10. package/dist/src/commands/apps.js.map +1 -1
  11. package/dist/src/commands/blob-buckets.js +50 -155
  12. package/dist/src/commands/blob-buckets.js.map +1 -1
  13. package/dist/src/commands/collection-type-configs.js +14 -100
  14. package/dist/src/commands/collection-type-configs.js.map +1 -1
  15. package/dist/src/commands/collections.js +47 -8
  16. package/dist/src/commands/collections.js.map +1 -1
  17. package/dist/src/commands/config.d.ts +46 -0
  18. package/dist/src/commands/config.js +479 -0
  19. package/dist/src/commands/config.js.map +1 -0
  20. package/dist/src/commands/connections.d.ts +2 -0
  21. package/dist/src/commands/connections.js +100 -0
  22. package/dist/src/commands/connections.js.map +1 -0
  23. package/dist/src/commands/cron-triggers.js +84 -176
  24. package/dist/src/commands/cron-triggers.js.map +1 -1
  25. package/dist/src/commands/database-type-configs.d.ts +2 -0
  26. package/dist/src/commands/database-type-configs.js +171 -0
  27. package/dist/src/commands/database-type-configs.js.map +1 -0
  28. package/dist/src/commands/database-types.js +4 -4
  29. package/dist/src/commands/database-types.js.map +1 -1
  30. package/dist/src/commands/databases.d.ts +63 -0
  31. package/dist/src/commands/databases.js +649 -87
  32. package/dist/src/commands/databases.js.map +1 -1
  33. package/dist/src/commands/documents.js +869 -12
  34. package/dist/src/commands/documents.js.map +1 -1
  35. package/dist/src/commands/email-templates.js +18 -125
  36. package/dist/src/commands/email-templates.js.map +1 -1
  37. package/dist/src/commands/env.d.ts +12 -1
  38. package/dist/src/commands/env.js +98 -25
  39. package/dist/src/commands/env.js.map +1 -1
  40. package/dist/src/commands/feature-flags.d.ts +14 -0
  41. package/dist/src/commands/feature-flags.js +116 -0
  42. package/dist/src/commands/feature-flags.js.map +1 -0
  43. package/dist/src/commands/group-type-configs.js +14 -109
  44. package/dist/src/commands/group-type-configs.js.map +1 -1
  45. package/dist/src/commands/init.d.ts +9 -1
  46. package/dist/src/commands/init.js +1058 -279
  47. package/dist/src/commands/init.js.map +1 -1
  48. package/dist/src/commands/integrations.js +136 -421
  49. package/dist/src/commands/integrations.js.map +1 -1
  50. package/dist/src/commands/metadata-category-configs.d.ts +12 -0
  51. package/dist/src/commands/metadata-category-configs.js +112 -0
  52. package/dist/src/commands/metadata-category-configs.js.map +1 -0
  53. package/dist/src/commands/metadata.js +33 -141
  54. package/dist/src/commands/metadata.js.map +1 -1
  55. package/dist/src/commands/prompts.js +206 -563
  56. package/dist/src/commands/prompts.js.map +1 -1
  57. package/dist/src/commands/rule-sets.d.ts +1 -1
  58. package/dist/src/commands/rule-sets.js +16 -132
  59. package/dist/src/commands/rule-sets.js.map +1 -1
  60. package/dist/src/commands/scripts.js +67 -234
  61. package/dist/src/commands/scripts.js.map +1 -1
  62. package/dist/src/commands/sessions.d.ts +2 -0
  63. package/dist/src/commands/sessions.js +75 -0
  64. package/dist/src/commands/sessions.js.map +1 -0
  65. package/dist/src/commands/skill.js +2 -2
  66. package/dist/src/commands/skill.js.map +1 -1
  67. package/dist/src/commands/sync-app-settings.d.ts +113 -70
  68. package/dist/src/commands/sync-app-settings.js +193 -242
  69. package/dist/src/commands/sync-app-settings.js.map +1 -1
  70. package/dist/src/commands/sync.d.ts +1932 -49
  71. package/dist/src/commands/sync.js +9584 -1725
  72. package/dist/src/commands/sync.js.map +1 -1
  73. package/dist/src/commands/tokens.js +8 -2
  74. package/dist/src/commands/tokens.js.map +1 -1
  75. package/dist/src/commands/users.js +92 -1
  76. package/dist/src/commands/users.js.map +1 -1
  77. package/dist/src/commands/vars.js +44 -58
  78. package/dist/src/commands/vars.js.map +1 -1
  79. package/dist/src/commands/webhooks.js +318 -156
  80. package/dist/src/commands/webhooks.js.map +1 -1
  81. package/dist/src/commands/workflows.d.ts +49 -12
  82. package/dist/src/commands/workflows.js +652 -1043
  83. package/dist/src/commands/workflows.js.map +1 -1
  84. package/dist/src/lib/access-rule-display.d.ts +21 -0
  85. package/dist/src/lib/access-rule-display.js +34 -0
  86. package/dist/src/lib/access-rule-display.js.map +1 -0
  87. package/dist/src/lib/api-client.d.ts +630 -61
  88. package/dist/src/lib/api-client.js +676 -116
  89. package/dist/src/lib/api-client.js.map +1 -1
  90. package/dist/src/lib/app-settings-descriptor.d.ts +180 -25
  91. package/dist/src/lib/app-settings-descriptor.js +403 -82
  92. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  93. package/dist/src/lib/canonical-json.d.ts +12 -0
  94. package/dist/src/lib/canonical-json.js +35 -0
  95. package/dist/src/lib/canonical-json.js.map +1 -0
  96. package/dist/src/lib/cli-manifest.d.ts +8 -0
  97. package/dist/src/lib/cli-manifest.js +1 -0
  98. package/dist/src/lib/cli-manifest.js.map +1 -1
  99. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +6 -2
  100. package/dist/src/lib/codegen-shared/generatedFiles.js +9 -2
  101. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -1
  102. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +6 -6
  103. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +8 -8
  104. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -1
  105. package/dist/src/lib/config-object-descriptor.d.ts +127 -0
  106. package/dist/src/lib/config-object-descriptor.js +658 -0
  107. package/dist/src/lib/config-object-descriptor.js.map +1 -0
  108. package/dist/src/lib/config-payload.d.ts +85 -0
  109. package/dist/src/lib/config-payload.js +116 -0
  110. package/dist/src/lib/config-payload.js.map +1 -0
  111. package/dist/src/lib/config-surface.d.ts +130 -0
  112. package/dist/src/lib/config-surface.js +300 -0
  113. package/dist/src/lib/config-surface.js.map +1 -0
  114. package/dist/src/lib/credentials-store.d.ts +10 -0
  115. package/dist/src/lib/credentials-store.js +23 -0
  116. package/dist/src/lib/credentials-store.js.map +1 -1
  117. package/dist/src/lib/data-input.d.ts +23 -0
  118. package/dist/src/lib/data-input.js +50 -0
  119. package/dist/src/lib/data-input.js.map +1 -0
  120. package/dist/src/lib/db-codegen/dbTemplates.js +1 -1
  121. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -1
  122. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +1 -1
  123. package/dist/src/lib/env-resolver-core.d.ts +147 -0
  124. package/dist/src/lib/env-resolver-core.js +265 -0
  125. package/dist/src/lib/env-resolver-core.js.map +1 -0
  126. package/dist/src/lib/env-resolver.d.ts +28 -6
  127. package/dist/src/lib/env-resolver.js +44 -32
  128. package/dist/src/lib/env-resolver.js.map +1 -1
  129. package/dist/src/lib/generated-allowlist.js +13 -0
  130. package/dist/src/lib/generated-allowlist.js.map +1 -1
  131. package/dist/src/lib/generated-config-surfaces.d.ts +682 -0
  132. package/dist/src/lib/generated-config-surfaces.js +4058 -0
  133. package/dist/src/lib/generated-config-surfaces.js.map +1 -0
  134. package/dist/src/lib/generated-template-lint.d.ts +212 -0
  135. package/dist/src/lib/generated-template-lint.js +624 -0
  136. package/dist/src/lib/generated-template-lint.js.map +1 -0
  137. package/dist/src/lib/init-adopt.d.ts +16 -0
  138. package/dist/src/lib/init-adopt.js +34 -0
  139. package/dist/src/lib/init-adopt.js.map +1 -0
  140. package/dist/src/lib/init-assets.d.ts +39 -0
  141. package/dist/src/lib/init-assets.js +97 -0
  142. package/dist/src/lib/init-assets.js.map +1 -0
  143. package/dist/src/lib/init-config.d.ts +44 -5
  144. package/dist/src/lib/init-config.js +80 -7
  145. package/dist/src/lib/init-config.js.map +1 -1
  146. package/dist/src/lib/init-ios-links.d.ts +50 -0
  147. package/dist/src/lib/init-ios-links.js +153 -0
  148. package/dist/src/lib/init-ios-links.js.map +1 -0
  149. package/dist/src/lib/init-plan.d.ts +80 -0
  150. package/dist/src/lib/init-plan.js +95 -0
  151. package/dist/src/lib/init-plan.js.map +1 -0
  152. package/dist/src/lib/init-production-env.d.ts +48 -0
  153. package/dist/src/lib/init-production-env.js +59 -0
  154. package/dist/src/lib/init-production-env.js.map +1 -0
  155. package/dist/src/lib/init-schema.d.ts +74 -0
  156. package/dist/src/lib/init-schema.js +358 -0
  157. package/dist/src/lib/init-schema.js.map +1 -0
  158. package/dist/src/lib/init-xcode.d.ts +33 -0
  159. package/dist/src/lib/init-xcode.js +114 -0
  160. package/dist/src/lib/init-xcode.js.map +1 -0
  161. package/dist/src/lib/integration-request-config.d.ts +30 -0
  162. package/dist/src/lib/integration-request-config.js +145 -0
  163. package/dist/src/lib/integration-request-config.js.map +1 -0
  164. package/dist/src/lib/local-state.d.ts +55 -0
  165. package/dist/src/lib/local-state.js +167 -0
  166. package/dist/src/lib/local-state.js.map +1 -0
  167. package/dist/src/lib/log-inspection.d.ts +568 -0
  168. package/dist/src/lib/log-inspection.js +639 -0
  169. package/dist/src/lib/log-inspection.js.map +1 -0
  170. package/dist/src/lib/migration-nag.d.ts +2 -2
  171. package/dist/src/lib/migration-nag.js +3 -3
  172. package/dist/src/lib/object-status-filter.d.ts +22 -0
  173. package/dist/src/lib/object-status-filter.js +45 -0
  174. package/dist/src/lib/object-status-filter.js.map +1 -0
  175. package/dist/src/lib/output.d.ts +24 -1
  176. package/dist/src/lib/output.js +42 -1
  177. package/dist/src/lib/output.js.map +1 -1
  178. package/dist/src/lib/package-manager.d.ts +140 -0
  179. package/dist/src/lib/package-manager.js +305 -0
  180. package/dist/src/lib/package-manager.js.map +1 -0
  181. package/dist/src/lib/paginate.d.ts +50 -0
  182. package/dist/src/lib/paginate.js +53 -0
  183. package/dist/src/lib/paginate.js.map +1 -1
  184. package/dist/src/lib/platform-owned.d.ts +29 -3
  185. package/dist/src/lib/platform-owned.js +42 -3
  186. package/dist/src/lib/platform-owned.js.map +1 -1
  187. package/dist/src/lib/project-config.js +13 -5
  188. package/dist/src/lib/project-config.js.map +1 -1
  189. package/dist/src/lib/query-operators.d.ts +1 -1
  190. package/dist/src/lib/query-operators.js +1 -1
  191. package/dist/src/lib/record-filter.d.ts +18 -0
  192. package/dist/src/lib/record-filter.js +55 -0
  193. package/dist/src/lib/record-filter.js.map +1 -0
  194. package/dist/src/lib/resolve-init-dev-port.d.ts +56 -0
  195. package/dist/src/lib/resolve-init-dev-port.js +55 -0
  196. package/dist/src/lib/resolve-init-dev-port.js.map +1 -0
  197. package/dist/src/lib/resolve-init-server.d.ts +64 -0
  198. package/dist/src/lib/resolve-init-server.js +77 -0
  199. package/dist/src/lib/resolve-init-server.js.map +1 -0
  200. package/dist/src/lib/resolve-platform.d.ts +43 -14
  201. package/dist/src/lib/resolve-platform.js +74 -12
  202. package/dist/src/lib/resolve-platform.js.map +1 -1
  203. package/dist/src/lib/run-status.d.ts +19 -0
  204. package/dist/src/lib/run-status.generated.d.ts +39 -0
  205. package/dist/src/lib/run-status.generated.js +66 -0
  206. package/dist/src/lib/run-status.generated.js.map +1 -0
  207. package/dist/src/lib/run-status.js +19 -0
  208. package/dist/src/lib/run-status.js.map +1 -0
  209. package/dist/src/lib/server-text-normalization.d.ts +51 -0
  210. package/dist/src/lib/server-text-normalization.js +90 -0
  211. package/dist/src/lib/server-text-normalization.js.map +1 -0
  212. package/dist/src/lib/server-url.d.ts +22 -0
  213. package/dist/src/lib/server-url.js +33 -0
  214. package/dist/src/lib/server-url.js.map +1 -0
  215. package/dist/src/lib/signing-secret-status.d.ts +81 -0
  216. package/dist/src/lib/signing-secret-status.js +116 -0
  217. package/dist/src/lib/signing-secret-status.js.map +1 -0
  218. package/dist/src/lib/skill-installer.d.ts +4 -2
  219. package/dist/src/lib/skill-installer.js +143 -12
  220. package/dist/src/lib/skill-installer.js.map +1 -1
  221. package/dist/src/lib/snapshots.d.ts +2 -2
  222. package/dist/src/lib/snapshots.js +2 -2
  223. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +15 -2
  224. package/dist/src/lib/swift-codegen/dbGenerator.js +250 -18
  225. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -1
  226. package/dist/src/lib/swift-codegen/generator.d.ts +11 -2
  227. package/dist/src/lib/swift-codegen/generator.js +181 -7
  228. package/dist/src/lib/swift-codegen/generator.js.map +1 -1
  229. package/dist/src/lib/swift-codegen/siblingSymbols.d.ts +7 -3
  230. package/dist/src/lib/swift-codegen/siblingSymbols.js +4 -1
  231. package/dist/src/lib/swift-codegen/siblingSymbols.js.map +1 -1
  232. package/dist/src/lib/sync-dir-selector.d.ts +21 -0
  233. package/dist/src/lib/sync-dir-selector.js +30 -0
  234. package/dist/src/lib/sync-dir-selector.js.map +1 -0
  235. package/dist/src/lib/sync-paths.d.ts +39 -0
  236. package/dist/src/lib/sync-paths.js +70 -2
  237. package/dist/src/lib/sync-paths.js.map +1 -1
  238. package/dist/src/lib/sync-resource-types.d.ts +138 -31
  239. package/dist/src/lib/sync-resource-types.js +241 -47
  240. package/dist/src/lib/sync-resource-types.js.map +1 -1
  241. package/dist/src/lib/sync-selectors.d.ts +95 -0
  242. package/dist/src/lib/sync-selectors.js +228 -0
  243. package/dist/src/lib/sync-selectors.js.map +1 -0
  244. package/dist/src/lib/template.d.ts +62 -4
  245. package/dist/src/lib/template.js +147 -39
  246. package/dist/src/lib/template.js.map +1 -1
  247. package/dist/src/lib/test-case-keys.d.ts +29 -0
  248. package/dist/src/lib/test-case-keys.js +55 -0
  249. package/dist/src/lib/test-case-keys.js.map +1 -0
  250. package/dist/src/lib/test-case-variables.d.ts +15 -0
  251. package/dist/src/lib/test-case-variables.js +29 -0
  252. package/dist/src/lib/test-case-variables.js.map +1 -0
  253. package/dist/src/lib/toml-database-config.d.ts +4 -4
  254. package/dist/src/lib/toml-database-config.js +27 -34
  255. package/dist/src/lib/toml-database-config.js.map +1 -1
  256. package/dist/src/lib/toml-metadata-config.d.ts +9 -5
  257. package/dist/src/lib/toml-metadata-config.js +40 -45
  258. package/dist/src/lib/toml-metadata-config.js.map +1 -1
  259. package/dist/src/lib/toml-native-form.d.ts +1 -1
  260. package/dist/src/lib/toml-native-form.js +1 -1
  261. package/dist/src/lib/toml-params-validator.d.ts +1 -1
  262. package/dist/src/lib/toml-params-validator.js +1 -1
  263. package/dist/src/lib/toml-scalar-edit.d.ts +43 -0
  264. package/dist/src/lib/toml-scalar-edit.js +283 -0
  265. package/dist/src/lib/toml-scalar-edit.js.map +1 -0
  266. package/dist/src/lib/user-selector.d.ts +24 -0
  267. package/dist/src/lib/user-selector.js +33 -0
  268. package/dist/src/lib/user-selector.js.map +1 -0
  269. package/dist/src/lib/version-check.d.ts +25 -0
  270. package/dist/src/lib/version-check.js +77 -8
  271. package/dist/src/lib/version-check.js.map +1 -1
  272. package/dist/src/lib/watch.d.ts +121 -0
  273. package/dist/src/lib/watch.js +169 -0
  274. package/dist/src/lib/watch.js.map +1 -0
  275. package/dist/src/lib/workflow-apply.d.ts +69 -45
  276. package/dist/src/lib/workflow-apply.js +99 -72
  277. package/dist/src/lib/workflow-apply.js.map +1 -1
  278. package/dist/src/lib/workflow-codegen/generator.js +4 -4
  279. package/dist/src/lib/workflow-codegen/generator.js.map +1 -1
  280. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +11 -0
  281. package/dist/src/lib/workflow-codegen/invokerIR.js +5 -0
  282. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -1
  283. package/dist/src/lib/workflow-config-apply.d.ts +70 -0
  284. package/dist/src/lib/workflow-config-apply.js +137 -0
  285. package/dist/src/lib/workflow-config-apply.js.map +1 -0
  286. package/dist/src/lib/workflow-config-sidecar.d.ts +63 -0
  287. package/dist/src/lib/workflow-config-sidecar.js +96 -0
  288. package/dist/src/lib/workflow-config-sidecar.js.map +1 -0
  289. package/dist/src/lib/workflow-defaults.d.ts +29 -0
  290. package/dist/src/lib/workflow-defaults.js +41 -0
  291. package/dist/src/lib/workflow-defaults.js.map +1 -0
  292. package/dist/src/lib/workflow-fragments.d.ts +23 -0
  293. package/dist/src/lib/workflow-fragments.js +229 -8
  294. package/dist/src/lib/workflow-fragments.js.map +1 -1
  295. package/dist/src/lib/workflow-include-preserve.d.ts +76 -0
  296. package/dist/src/lib/workflow-include-preserve.js +286 -0
  297. package/dist/src/lib/workflow-include-preserve.js.map +1 -0
  298. package/dist/src/lib/workflow-payload.d.ts +31 -20
  299. package/dist/src/lib/workflow-payload.js +100 -93
  300. package/dist/src/lib/workflow-payload.js.map +1 -1
  301. package/dist/src/lib/workflow-toml-validator.d.ts +80 -3
  302. package/dist/src/lib/workflow-toml-validator.js +231 -3
  303. package/dist/src/lib/workflow-toml-validator.js.map +1 -1
  304. package/dist/src/types/index.d.ts +78 -22
  305. package/dist/src/validators.d.ts +7 -7
  306. package/dist/src/validators.js +6 -6
  307. package/package.json +11 -6
  308. package/dist/src/commands/settings.d.ts +0 -15
  309. package/dist/src/commands/settings.js +0 -102
  310. package/dist/src/commands/settings.js.map +0 -1
@@ -0,0 +1,80 @@
1
+ import type { Platform } from "./resolve-platform.js";
2
+ export type InitMode = "standalone" | "multi-client" | "add-client";
3
+ export interface ClientPlan {
4
+ platform: Platform;
5
+ /** Absolute directory this client's template is installed into. */
6
+ dir: string;
7
+ }
8
+ export interface InitPlan {
9
+ mode: InitMode;
10
+ /** Every client this run scaffolds, in processing order (web first). */
11
+ clients: ClientPlan[];
12
+ /** The directory holding the ONE `.primitive/` for this app. */
13
+ projectRoot: string;
14
+ /**
15
+ * Whether this run writes `.primitive/config.json` and seeds the
16
+ * environment's credential slot. False when adopting: the config is already
17
+ * there and is not this run's to rewrite.
18
+ */
19
+ writesProjectConfig: boolean;
20
+ /**
21
+ * Whether this run may create the app and point the CLI's global "current
22
+ * app" at it. False when adopting — the app already exists and belongs to the
23
+ * project config.
24
+ */
25
+ ownsApp: boolean;
26
+ /**
27
+ * Whether this run creates the git repository and its initial commit. False
28
+ * when adopting: the surrounding repository owns the history, and the new
29
+ * files are left for the user to review and commit.
30
+ */
31
+ initsGit: boolean;
32
+ /**
33
+ * The one schema both clients read, or `null` in standalone mode where the
34
+ * client keeps the template's own copy (spec decision 1: single-client output
35
+ * is unchanged).
36
+ */
37
+ canonicalSchemaPath: string | null;
38
+ /**
39
+ * Whether this run may write an app-wide `AGENTS.md` at the project root.
40
+ * Never over an existing file — client `AGENTS.md` files ship with their
41
+ * templates and an adopted repo's root file is the user's.
42
+ */
43
+ writesRootAgents: boolean;
44
+ }
45
+ export interface PlanInitInput {
46
+ /** The resolved platforms, in canonical order. */
47
+ platforms: Platform[];
48
+ /** Absolute directory the command was pointed at. */
49
+ targetDir: string;
50
+ /**
51
+ * The nearest ancestor project root, passed ONLY when it differs from
52
+ * `targetDir` — `primitive init .` at an existing project root keeps its
53
+ * merge behavior rather than adopting itself.
54
+ */
55
+ ancestorProjectRoot?: string | null;
56
+ }
57
+ /** Resolve the layout for this run. */
58
+ export declare function planInit(input: PlanInitInput): InitPlan;
59
+ export interface InitGuardInput {
60
+ /** The init config's `action`, when a non-interactive config is in effect. */
61
+ action?: "create" | "use-existing" | "add-client";
62
+ /** Whether an init config is in effect at all. */
63
+ hasConfig: boolean;
64
+ /** The nearest ancestor project root, or null/undefined outside a project. */
65
+ ancestorProjectRoot?: string | null;
66
+ /** `app_id` from a `use-existing` init config. */
67
+ configAppId?: string;
68
+ /** `--use-existing-app-id`. */
69
+ flagAppId?: string;
70
+ /** The adopted environment's `appId`, when adopting. */
71
+ environmentAppId?: string;
72
+ /** The adopted environment's name, for the error messages. */
73
+ environmentName?: string;
74
+ }
75
+ /**
76
+ * Everything a run must be refused for, checked before any download, any API
77
+ * call and any write. Returns the user-facing message, or `null` when the run
78
+ * may proceed.
79
+ */
80
+ export declare function checkInitGuards(input: InitGuardInput): string | null;
@@ -0,0 +1,95 @@
1
+ /**
2
+ * What shape does this `primitive init` run produce? (#2890)
3
+ *
4
+ * One Primitive app can have several clients — a web client and a native
5
+ * client — and they are one app: one appId, one project config, one exported
6
+ * server-config tree, one model schema. `init` therefore composes one of three
7
+ * layouts, and the choice decides everything downstream:
8
+ *
9
+ * standalone — one client, no surrounding project. Today's flat scaffold,
10
+ * unchanged: the client IS the project root.
11
+ * multi-client — several clients, no surrounding project. Each client gets a
12
+ * platform-named subdirectory; the project config, the git
13
+ * repository and the canonical schema live at the root.
14
+ * add-client — an ancestor `.primitive/config.json` already exists. The run
15
+ * ADOPTS it: no nested project config, no nested git
16
+ * repository, no app creation, no commit. This is the path the
17
+ * issue opens with — running init in a subdirectory used to
18
+ * scaffold a second project that had to be partly undone.
19
+ *
20
+ * Pure on purpose: the layout and the guards are the part that is expensive to
21
+ * get wrong and impossible to assert from a half-written scaffold.
22
+ */
23
+ import { join } from "path";
24
+ import { PROJECT_CONFIG_DISPLAY_NAME } from "./project-config.js";
25
+ /** Resolve the layout for this run. */
26
+ export function planInit(input) {
27
+ const adopting = Boolean(input.ancestorProjectRoot);
28
+ const projectRoot = adopting ? input.ancestorProjectRoot : input.targetDir;
29
+ const composed = adopting || input.platforms.length > 1;
30
+ // One client in an adopt run lands exactly where the user pointed the
31
+ // command; anything else gets a platform-named subdirectory, which is what
32
+ // makes `web/` and `ios/` siblings under one root.
33
+ const useSubdirectories = input.platforms.length > 1;
34
+ const clients = input.platforms.map((platform) => ({
35
+ platform,
36
+ dir: useSubdirectories ? join(input.targetDir, platform) : input.targetDir,
37
+ }));
38
+ const mode = adopting
39
+ ? "add-client"
40
+ : input.platforms.length > 1
41
+ ? "multi-client"
42
+ : "standalone";
43
+ return {
44
+ mode,
45
+ clients,
46
+ projectRoot,
47
+ writesProjectConfig: !adopting,
48
+ ownsApp: !adopting,
49
+ initsGit: !adopting,
50
+ canonicalSchemaPath: composed
51
+ ? join(projectRoot, "models", "models.toml")
52
+ : null,
53
+ writesRootAgents: composed,
54
+ };
55
+ }
56
+ /**
57
+ * Everything a run must be refused for, checked before any download, any API
58
+ * call and any write. Returns the user-facing message, or `null` when the run
59
+ * may proceed.
60
+ */
61
+ export function checkInitGuards(input) {
62
+ const root = input.ancestorProjectRoot;
63
+ if (!root) {
64
+ // `add-client` describes adopting a project that is not there.
65
+ if (input.action === "add-client") {
66
+ return (`action = "add-client" adds a client to an existing Primitive app, but there is no ` +
67
+ `${PROJECT_CONFIG_DISPLAY_NAME} in this directory or any parent. ` +
68
+ `Run init from inside the app's repository, or use action = "create" to start a new app.`);
69
+ }
70
+ return null;
71
+ }
72
+ const envName = input.environmentName ?? "the selected environment";
73
+ // Creating a SECOND app inside a repository that already has one is the
74
+ // nesting this change removes.
75
+ if (input.action === "create") {
76
+ return (`action = "create" would create a second Primitive app inside the existing project at ${root}. ` +
77
+ `Use action = "add-client" to add this client to the app that project already targets.`);
78
+ }
79
+ if (!input.environmentAppId) {
80
+ return (`The "${envName}" environment in ${root}/${PROJECT_CONFIG_DISPLAY_NAME} has no appId, so there is no app to add this client to. ` +
81
+ `Set one with \`primitive env add <name> --api-url <url> --app-id <appId>\`, or select an environment that has one with \`primitive env use <name>\`.`);
82
+ }
83
+ // Naming an app explicitly is allowed only when it is the SAME app: a
84
+ // different one would wire this client to a backend the rest of the repo does
85
+ // not target.
86
+ const named = input.flagAppId ?? (input.action === "use-existing" ? input.configAppId : undefined);
87
+ if (named && named !== input.environmentAppId) {
88
+ const source = input.flagAppId ? "--use-existing-app-id" : '`app_id` (action = "use-existing")';
89
+ return (`${source} names app ${named}, but the "${envName}" environment of the project at ${root} targets app ${input.environmentAppId}. ` +
90
+ `A client added to this repository belongs to that app — drop the app id and use action = "add-client", ` +
91
+ `or run init outside this project to scaffold a separate app.`);
92
+ }
93
+ return null;
94
+ }
95
+ //# sourceMappingURL=init-plan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-plan.js","sourceRoot":"","sources":["../../../src/lib/init-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,O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AAK,CAAC,gBAAgB,IAAI;YAClI,yGAAyG;YACzG,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Which backend a scaffolded client's PRODUCTION build talks to (#2890).
3
+ *
4
+ * `init` used to write the hosted production URL into `.env.production`
5
+ * unconditionally, alongside the app ID of the app it had just created. On the
6
+ * hosted server those agree. On any other one — a self-hosted server, a staging
7
+ * server, an alpha channel — they do not: the production build points at a
8
+ * backend the app ID does not exist on, and the mismatch only shows up after a
9
+ * deploy.
10
+ *
11
+ * So a composed run derives the pair from the project's own environments
12
+ * instead, and only falls back to the old behavior where it was right anyway:
13
+ *
14
+ * 1. a `prod` environment, then a `production` one — the team already said
15
+ * which backend/app pair production means
16
+ * 2. otherwise, when this run targets the hosted production server, the
17
+ * hosted production URL with this app (today's output)
18
+ * 3. otherwise the selected environment's own server and app — one backend,
19
+ * one app, consistently
20
+ *
21
+ * Standalone runs keep calling the old path verbatim, so a single-client
22
+ * scaffold's output is unchanged (spec decision 1).
23
+ */
24
+ export interface ProductionRuntime {
25
+ serverUrl: string;
26
+ appId: string;
27
+ appName?: string;
28
+ /** Which rule chose it, for the message init prints. */
29
+ source: "environment" | "hosted-production" | "selected";
30
+ /** The environment name, when one was used. */
31
+ environmentName?: string;
32
+ }
33
+ export interface ResolveProductionRuntimeInput {
34
+ /** The project's environments, keyed by name. */
35
+ environments?: Record<string, {
36
+ apiUrl?: string;
37
+ appId?: string;
38
+ appName?: string;
39
+ } | undefined>;
40
+ /** The server this run targets. */
41
+ selectedServerUrl: string;
42
+ /** The app this run scaffolds against. */
43
+ selectedAppId: string;
44
+ selectedAppName?: string;
45
+ /** The hosted production server URL. */
46
+ productionServerUrl: string;
47
+ }
48
+ export declare function resolveProductionRuntime(input: ResolveProductionRuntimeInput): ProductionRuntime;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Which backend a scaffolded client's PRODUCTION build talks to (#2890).
3
+ *
4
+ * `init` used to write the hosted production URL into `.env.production`
5
+ * unconditionally, alongside the app ID of the app it had just created. On the
6
+ * hosted server those agree. On any other one — a self-hosted server, a staging
7
+ * server, an alpha channel — they do not: the production build points at a
8
+ * backend the app ID does not exist on, and the mismatch only shows up after a
9
+ * deploy.
10
+ *
11
+ * So a composed run derives the pair from the project's own environments
12
+ * instead, and only falls back to the old behavior where it was right anyway:
13
+ *
14
+ * 1. a `prod` environment, then a `production` one — the team already said
15
+ * which backend/app pair production means
16
+ * 2. otherwise, when this run targets the hosted production server, the
17
+ * hosted production URL with this app (today's output)
18
+ * 3. otherwise the selected environment's own server and app — one backend,
19
+ * one app, consistently
20
+ *
21
+ * Standalone runs keep calling the old path verbatim, so a single-client
22
+ * scaffold's output is unchanged (spec decision 1).
23
+ */
24
+ /** Trailing-slash-insensitive comparison, as elsewhere in init. */
25
+ function sameServer(a, b) {
26
+ return a.replace(/\/+$/, "") === b.replace(/\/+$/, "");
27
+ }
28
+ export function resolveProductionRuntime(input) {
29
+ const environments = input.environments ?? {};
30
+ // `prod` first, deliberately: a repo with both names has one of them as the
31
+ // real one, and `prod` is what `primitive init` and the templates use.
32
+ for (const name of ["prod", "production"]) {
33
+ const env = environments[name];
34
+ if (env?.apiUrl && env?.appId) {
35
+ return {
36
+ serverUrl: env.apiUrl,
37
+ appId: env.appId,
38
+ appName: env.appName ?? input.selectedAppName,
39
+ source: "environment",
40
+ environmentName: name,
41
+ };
42
+ }
43
+ }
44
+ if (sameServer(input.selectedServerUrl, input.productionServerUrl)) {
45
+ return {
46
+ serverUrl: input.productionServerUrl,
47
+ appId: input.selectedAppId,
48
+ appName: input.selectedAppName,
49
+ source: "hosted-production",
50
+ };
51
+ }
52
+ return {
53
+ serverUrl: input.selectedServerUrl,
54
+ appId: input.selectedAppId,
55
+ appName: input.selectedAppName,
56
+ source: "selected",
57
+ };
58
+ }
59
+ //# sourceMappingURL=init-production-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3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C,eAAe;QAC9B,MAAM,EAAE,UAAU;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { Platform } from "./resolve-platform.js";
2
+ /** The canonical schema's path, relative to the project root. */
3
+ export declare const CANONICAL_SCHEMA_RELATIVE: string;
4
+ /**
5
+ * A POSIX-style relative specifier from `fromDir` to `toFile`, always prefixed
6
+ * with `./` or `../` — what both an import specifier and a `-i` argument need.
7
+ */
8
+ export declare function relativeSchemaPath(fromDir: string, toFile: string): string;
9
+ /**
10
+ * The schema a freshly installed client template ships, or null when it has
11
+ * none (the Swift starter is comment-only but the file is still there).
12
+ */
13
+ export declare function findClientSchema(clientDir: string, platform: Platform): string | null;
14
+ /** The Swift target's source directory (`Sources/<AppName>`), if there is one. */
15
+ export declare function findSwiftTargetDir(clientDir: string): string | null;
16
+ /**
17
+ * The models a schema declares, in the order it declares them.
18
+ *
19
+ * `[models.<name>]`, `[models.<name>.fields.<field>]` and the array form all
20
+ * name the same model; the loader treats the first path segment after `models`
21
+ * as the model name, and so does this.
22
+ */
23
+ export declare function declaredModelNames(toml: string): string[];
24
+ /**
25
+ * The app's one schema has to declare every model its clients read.
26
+ *
27
+ * A client's template ships both a starter schema and code generated from it —
28
+ * the web template's store reads `UserPref`, and the model generator refuses a
29
+ * schema with no models at all. So composing the shared schema is not "pick a
30
+ * starter": it is the base schema (an existing client's, when one is being
31
+ * promoted) PLUS every model a client being added declares and the base does
32
+ * not. Nothing is ever overwritten — a model the base already declares is the
33
+ * app's definition of it, and stays exactly as it is.
34
+ */
35
+ export declare function composeSchemaContent(input: {
36
+ /** The schema the app already has, or the one being promoted to the root. */
37
+ base: string;
38
+ /** The starter schemas of the clients this run is adding. */
39
+ starters: string[];
40
+ }): {
41
+ content: string;
42
+ added: string[];
43
+ };
44
+ /** What `wireClientToSchema` actually rewrote, for the caller to report. */
45
+ export interface SchemaWiringResult {
46
+ /** Files rewritten or created so this client reads the shared schema. */
47
+ rewired: string[];
48
+ /** The client-local schema copy that was removed, if any. */
49
+ removed?: string;
50
+ /** Set when the client's shape was not recognized and nothing was rewired. */
51
+ error?: string;
52
+ }
53
+ /**
54
+ * Points one client at the shared schema and drops its own copy.
55
+ *
56
+ * Writes the new wiring BEFORE removing the client-local schema, so a failure
57
+ * leaves a client that still has a schema rather than one with neither.
58
+ */
59
+ export declare function wireClientToSchema(clientDir: string, platform: Platform, schemaPath: string): SchemaWiringResult;
60
+ /**
61
+ * Why this client cannot be pointed at the shared schema, or null when it can.
62
+ *
63
+ * Separate from the wiring itself because the answer decides whether the run
64
+ * happens at all: a client that keeps its own schema while the app has another
65
+ * is the two-copies layout the shared schema exists to prevent, so a caller
66
+ * asks this BEFORE it writes the shared file — before the download, when the
67
+ * client already exists.
68
+ */
69
+ export declare function checkClientWiring(clientDir: string, platform: Platform, schemaPath: string): string | null;
70
+ /**
71
+ * Writes the canonical schema, creating `models/` if needed. Never overwrites:
72
+ * an existing shared schema is the app's, not this run's.
73
+ */
74
+ export declare function writeCanonicalSchema(schemaPath: string, content: string): boolean;