primitive-admin 1.1.0-alpha.9 → 1.1.0

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 (591) hide show
  1. package/README.md +523 -109
  2. package/assets/skill/skills/primitive-platform/SKILL.md +289 -0
  3. package/dist/bin/primitive.d.ts +2 -0
  4. package/dist/bin/primitive.js +372 -21
  5. package/dist/bin/primitive.js.map +1 -1
  6. package/dist/src/commands/admins.d.ts +2 -0
  7. package/dist/src/commands/admins.js +136 -30
  8. package/dist/src/commands/admins.js.map +1 -1
  9. package/dist/src/commands/analytics.d.ts +2 -0
  10. package/dist/src/commands/analytics.js +713 -55
  11. package/dist/src/commands/analytics.js.map +1 -1
  12. package/dist/src/commands/apps.d.ts +2 -0
  13. package/dist/src/commands/apps.js +65 -100
  14. package/dist/src/commands/apps.js.map +1 -1
  15. package/dist/src/commands/auth-sessions.d.ts +7 -0
  16. package/dist/src/commands/auth-sessions.js +144 -0
  17. package/dist/src/commands/auth-sessions.js.map +1 -0
  18. package/dist/src/commands/auth.d.ts +2 -0
  19. package/dist/src/commands/auth.js +238 -108
  20. package/dist/src/commands/auth.js.map +1 -1
  21. package/dist/src/commands/blob-buckets.d.ts +2 -0
  22. package/dist/src/commands/blob-buckets.js +331 -0
  23. package/dist/src/commands/blob-buckets.js.map +1 -0
  24. package/dist/src/commands/catalog.d.ts +2 -0
  25. package/dist/src/commands/catalog.js +63 -48
  26. package/dist/src/commands/catalog.js.map +1 -1
  27. package/dist/src/commands/collection-type-configs.d.ts +2 -0
  28. package/dist/src/commands/collection-type-configs.js +85 -0
  29. package/dist/src/commands/collection-type-configs.js.map +1 -0
  30. package/dist/src/commands/collections.d.ts +2 -0
  31. package/dist/src/commands/collections.js +1282 -0
  32. package/dist/src/commands/collections.js.map +1 -0
  33. package/dist/src/commands/comparisons.d.ts +2 -0
  34. package/dist/src/commands/comparisons.js +6 -6
  35. package/dist/src/commands/comparisons.js.map +1 -1
  36. package/dist/src/commands/config.d.ts +46 -0
  37. package/dist/src/commands/config.js +465 -0
  38. package/dist/src/commands/config.js.map +1 -0
  39. package/dist/src/commands/connections.d.ts +2 -0
  40. package/dist/src/commands/connections.js +99 -0
  41. package/dist/src/commands/connections.js.map +1 -0
  42. package/dist/src/commands/cron-triggers.d.ts +2 -0
  43. package/dist/src/commands/cron-triggers.js +266 -0
  44. package/dist/src/commands/cron-triggers.js.map +1 -0
  45. package/dist/src/commands/database-type-configs.d.ts +2 -0
  46. package/dist/src/commands/database-type-configs.js +164 -0
  47. package/dist/src/commands/database-type-configs.js.map +1 -0
  48. package/dist/src/commands/database-types.d.ts +2 -0
  49. package/dist/src/commands/database-types.js +471 -0
  50. package/dist/src/commands/database-types.js.map +1 -0
  51. package/dist/src/commands/databases.d.ts +65 -0
  52. package/dist/src/commands/databases.js +1887 -243
  53. package/dist/src/commands/databases.js.map +1 -1
  54. package/dist/src/commands/documents.d.ts +60 -0
  55. package/dist/src/commands/documents.js +2888 -22
  56. package/dist/src/commands/documents.js.map +1 -1
  57. package/dist/src/commands/email-templates.d.ts +2 -0
  58. package/dist/src/commands/email-templates.js +175 -0
  59. package/dist/src/commands/email-templates.js.map +1 -0
  60. package/dist/src/commands/env.d.ts +23 -0
  61. package/dist/src/commands/env.js +395 -0
  62. package/dist/src/commands/env.js.map +1 -0
  63. package/dist/src/commands/feature-flags.d.ts +14 -0
  64. package/dist/src/commands/feature-flags.js +117 -0
  65. package/dist/src/commands/feature-flags.js.map +1 -0
  66. package/dist/src/commands/functions.d.ts +20 -0
  67. package/dist/src/commands/functions.js +1630 -0
  68. package/dist/src/commands/functions.js.map +1 -0
  69. package/dist/src/commands/group-type-configs.d.ts +2 -0
  70. package/dist/src/commands/group-type-configs.js +87 -0
  71. package/dist/src/commands/group-type-configs.js.map +1 -0
  72. package/dist/src/commands/groups.d.ts +2 -0
  73. package/dist/src/commands/groups.js +65 -113
  74. package/dist/src/commands/groups.js.map +1 -1
  75. package/dist/src/commands/guides.d.ts +223 -0
  76. package/dist/src/commands/guides.js +627 -69
  77. package/dist/src/commands/guides.js.map +1 -1
  78. package/dist/src/commands/init.d.ts +37 -0
  79. package/dist/src/commands/init.js +1693 -208
  80. package/dist/src/commands/init.js.map +1 -1
  81. package/dist/src/commands/integrations.d.ts +2 -0
  82. package/dist/src/commands/integrations.js +428 -187
  83. package/dist/src/commands/integrations.js.map +1 -1
  84. package/dist/src/commands/llm.d.ts +2 -0
  85. package/dist/src/commands/llm.js +4 -2
  86. package/dist/src/commands/llm.js.map +1 -1
  87. package/dist/src/commands/locks.d.ts +8 -0
  88. package/dist/src/commands/locks.js +175 -0
  89. package/dist/src/commands/locks.js.map +1 -0
  90. package/dist/src/commands/metadata-category-configs.d.ts +12 -0
  91. package/dist/src/commands/metadata-category-configs.js +113 -0
  92. package/dist/src/commands/metadata-category-configs.js.map +1 -0
  93. package/dist/src/commands/metadata.d.ts +2 -0
  94. package/dist/src/commands/metadata.js +288 -0
  95. package/dist/src/commands/metadata.js.map +1 -0
  96. package/dist/src/commands/prompts.d.ts +2 -0
  97. package/dist/src/commands/prompts.js +322 -634
  98. package/dist/src/commands/prompts.js.map +1 -1
  99. package/dist/src/commands/rule-sets.d.ts +3 -0
  100. package/dist/src/commands/rule-sets.js +139 -148
  101. package/dist/src/commands/rule-sets.js.map +1 -1
  102. package/dist/src/commands/scripts.d.ts +30 -0
  103. package/dist/src/commands/scripts.js +688 -0
  104. package/dist/src/commands/scripts.js.map +1 -0
  105. package/dist/src/commands/secrets.d.ts +2 -0
  106. package/dist/src/commands/secrets.js +109 -0
  107. package/dist/src/commands/secrets.js.map +1 -0
  108. package/dist/src/commands/sessions.d.ts +2 -0
  109. package/dist/src/commands/sessions.js +76 -0
  110. package/dist/src/commands/sessions.js.map +1 -0
  111. package/dist/src/commands/skill.d.ts +2 -0
  112. package/dist/src/commands/skill.js +29 -0
  113. package/dist/src/commands/skill.js.map +1 -0
  114. package/dist/src/commands/sync-app-settings.d.ts +158 -0
  115. package/dist/src/commands/sync-app-settings.js +328 -0
  116. package/dist/src/commands/sync-app-settings.js.map +1 -0
  117. package/dist/src/commands/sync.d.ts +2670 -0
  118. package/dist/src/commands/sync.js +17144 -834
  119. package/dist/src/commands/sync.js.map +1 -1
  120. package/dist/src/commands/tokens.d.ts +2 -0
  121. package/dist/src/commands/tokens.js +132 -22
  122. package/dist/src/commands/tokens.js.map +1 -1
  123. package/dist/src/commands/users.d.ts +2 -0
  124. package/dist/src/commands/users.js +542 -24
  125. package/dist/src/commands/users.js.map +1 -1
  126. package/dist/src/commands/vars.d.ts +8 -0
  127. package/dist/src/commands/vars.js +97 -0
  128. package/dist/src/commands/vars.js.map +1 -0
  129. package/dist/src/commands/waitlist.d.ts +2 -0
  130. package/dist/src/commands/waitlist.js +12 -11
  131. package/dist/src/commands/waitlist.js.map +1 -1
  132. package/dist/src/commands/webhooks.d.ts +31 -0
  133. package/dist/src/commands/webhooks.js +633 -0
  134. package/dist/src/commands/webhooks.js.map +1 -0
  135. package/dist/src/commands/workflows.d.ts +88 -0
  136. package/dist/src/commands/workflows.js +1568 -742
  137. package/dist/src/commands/workflows.js.map +1 -1
  138. package/dist/src/lib/access-rule-display.d.ts +21 -0
  139. package/dist/src/lib/access-rule-display.js +34 -0
  140. package/dist/src/lib/access-rule-display.js.map +1 -0
  141. package/dist/src/lib/api-client.d.ts +2550 -0
  142. package/dist/src/lib/api-client.js +2503 -160
  143. package/dist/src/lib/api-client.js.map +1 -1
  144. package/dist/src/lib/app-settings-descriptor.d.ts +263 -0
  145. package/dist/src/lib/app-settings-descriptor.js +583 -0
  146. package/dist/src/lib/app-settings-descriptor.js.map +1 -0
  147. package/dist/src/lib/auth-flow.d.ts +8 -0
  148. package/dist/src/lib/batch.d.ts +26 -0
  149. package/dist/src/lib/batch.js +32 -0
  150. package/dist/src/lib/batch.js.map +1 -0
  151. package/dist/src/lib/block-layout.d.ts +160 -0
  152. package/dist/src/lib/block-layout.js +451 -0
  153. package/dist/src/lib/block-layout.js.map +1 -0
  154. package/dist/src/lib/block-selector.d.ts +58 -0
  155. package/dist/src/lib/block-selector.js +92 -0
  156. package/dist/src/lib/block-selector.js.map +1 -0
  157. package/dist/src/lib/canonical-json.d.ts +12 -0
  158. package/dist/src/lib/canonical-json.js +35 -0
  159. package/dist/src/lib/canonical-json.js.map +1 -0
  160. package/dist/src/lib/channel.d.ts +30 -0
  161. package/dist/src/lib/channel.js +68 -0
  162. package/dist/src/lib/channel.js.map +1 -0
  163. package/dist/src/lib/cli-manifest.d.ts +68 -0
  164. package/dist/src/lib/cli-manifest.js +71 -0
  165. package/dist/src/lib/cli-manifest.js.map +1 -0
  166. package/dist/src/lib/codegen-shared/generatedFiles.d.ts +101 -0
  167. package/dist/src/lib/codegen-shared/generatedFiles.js +191 -0
  168. package/dist/src/lib/codegen-shared/generatedFiles.js.map +1 -0
  169. package/dist/src/lib/codegen-shared/prettierStable.d.ts +262 -0
  170. package/dist/src/lib/codegen-shared/prettierStable.js +610 -0
  171. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -0
  172. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.d.ts +38 -0
  173. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js +46 -0
  174. package/dist/src/lib/codegen-shared/resolveCodegenSourceDir.js.map +1 -0
  175. package/dist/src/lib/collection-export.d.ts +184 -0
  176. package/dist/src/lib/collection-export.js +252 -0
  177. package/dist/src/lib/collection-export.js.map +1 -0
  178. package/dist/src/lib/config-json-field.d.ts +28 -0
  179. package/dist/src/lib/config-json-field.js +56 -0
  180. package/dist/src/lib/config-json-field.js.map +1 -0
  181. package/dist/src/lib/config-object-descriptor.d.ts +127 -0
  182. package/dist/src/lib/config-object-descriptor.js +740 -0
  183. package/dist/src/lib/config-object-descriptor.js.map +1 -0
  184. package/dist/src/lib/config-payload.d.ts +92 -0
  185. package/dist/src/lib/config-payload.js +161 -0
  186. package/dist/src/lib/config-payload.js.map +1 -0
  187. package/dist/src/lib/config-surface.d.ts +141 -0
  188. package/dist/src/lib/config-surface.js +368 -0
  189. package/dist/src/lib/config-surface.js.map +1 -0
  190. package/dist/src/lib/config-toml.d.ts +10 -0
  191. package/dist/src/lib/config-toml.js +42 -0
  192. package/dist/src/lib/config-toml.js.map +1 -0
  193. package/dist/src/lib/config.d.ts +71 -0
  194. package/dist/src/lib/config.js +71 -68
  195. package/dist/src/lib/config.js.map +1 -1
  196. package/dist/src/lib/confirm-prompt.d.ts +83 -0
  197. package/dist/src/lib/confirm-prompt.js +110 -0
  198. package/dist/src/lib/confirm-prompt.js.map +1 -0
  199. package/dist/src/lib/constants.d.ts +11 -0
  200. package/dist/src/lib/constants.js +12 -0
  201. package/dist/src/lib/constants.js.map +1 -0
  202. package/dist/src/lib/crash-handlers.d.ts +20 -0
  203. package/dist/src/lib/crash-handlers.js +49 -0
  204. package/dist/src/lib/crash-handlers.js.map +1 -0
  205. package/dist/src/lib/credentials-store.d.ts +104 -0
  206. package/dist/src/lib/credentials-store.js +336 -0
  207. package/dist/src/lib/credentials-store.js.map +1 -0
  208. package/dist/src/lib/csv.d.ts +47 -0
  209. package/dist/src/lib/csv.js +172 -0
  210. package/dist/src/lib/csv.js.map +1 -0
  211. package/dist/src/lib/data-input.d.ts +23 -0
  212. package/dist/src/lib/data-input.js +50 -0
  213. package/dist/src/lib/data-input.js.map +1 -0
  214. package/dist/src/lib/db-codegen/dbFingerprint.d.ts +10 -0
  215. package/dist/src/lib/db-codegen/dbFingerprint.js +17 -0
  216. package/dist/src/lib/db-codegen/dbFingerprint.js.map +1 -0
  217. package/dist/src/lib/db-codegen/dbGenerator.d.ts +67 -0
  218. package/dist/src/lib/db-codegen/dbGenerator.js +170 -0
  219. package/dist/src/lib/db-codegen/dbGenerator.js.map +1 -0
  220. package/dist/src/lib/db-codegen/dbNaming.d.ts +87 -0
  221. package/dist/src/lib/db-codegen/dbNaming.js +180 -0
  222. package/dist/src/lib/db-codegen/dbNaming.js.map +1 -0
  223. package/dist/src/lib/db-codegen/dbTemplates.d.ts +272 -0
  224. package/dist/src/lib/db-codegen/dbTemplates.js +480 -0
  225. package/dist/src/lib/db-codegen/dbTemplates.js.map +1 -0
  226. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +73 -0
  227. package/dist/src/lib/db-codegen/dbTsTypes.js +139 -0
  228. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -0
  229. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +146 -0
  230. package/dist/src/lib/db-codegen/dbTypeIR.js +525 -0
  231. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -0
  232. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.d.ts +112 -0
  233. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js +211 -0
  234. package/dist/src/lib/db-codegen/generated-operation-def-descriptor.js.map +1 -0
  235. package/dist/src/lib/deprecation.d.ts +22 -0
  236. package/dist/src/lib/deprecation.js +43 -0
  237. package/dist/src/lib/deprecation.js.map +1 -0
  238. package/dist/src/lib/document-export-permissions.d.ts +30 -0
  239. package/dist/src/lib/document-export-permissions.js +54 -0
  240. package/dist/src/lib/document-export-permissions.js.map +1 -0
  241. package/dist/src/lib/document-ingest-artifact.d.ts +120 -0
  242. package/dist/src/lib/document-ingest-artifact.js +505 -0
  243. package/dist/src/lib/document-ingest-artifact.js.map +1 -0
  244. package/dist/src/lib/document-ingest-input.d.ts +51 -0
  245. package/dist/src/lib/document-ingest-input.js +132 -0
  246. package/dist/src/lib/document-ingest-input.js.map +1 -0
  247. package/dist/src/lib/document-ingest-rows.d.ts +137 -0
  248. package/dist/src/lib/document-ingest-rows.js +181 -0
  249. package/dist/src/lib/document-ingest-rows.js.map +1 -0
  250. package/dist/src/lib/document-ingest.d.ts +101 -0
  251. package/dist/src/lib/document-ingest.js +384 -0
  252. package/dist/src/lib/document-ingest.js.map +1 -0
  253. package/dist/src/lib/env-resolver-core.d.ts +258 -0
  254. package/dist/src/lib/env-resolver-core.js +447 -0
  255. package/dist/src/lib/env-resolver-core.js.map +1 -0
  256. package/dist/src/lib/env-resolver.d.ts +99 -0
  257. package/dist/src/lib/env-resolver.js +153 -0
  258. package/dist/src/lib/env-resolver.js.map +1 -0
  259. package/dist/src/lib/fetch.d.ts +5 -0
  260. package/dist/src/lib/function-bundle.d.ts +147 -0
  261. package/dist/src/lib/function-bundle.js +341 -0
  262. package/dist/src/lib/function-bundle.js.map +1 -0
  263. package/dist/src/lib/function-collect.d.ts +123 -0
  264. package/dist/src/lib/function-collect.js +610 -0
  265. package/dist/src/lib/function-collect.js.map +1 -0
  266. package/dist/src/lib/function-db-types.d.ts +202 -0
  267. package/dist/src/lib/function-db-types.js +870 -0
  268. package/dist/src/lib/function-db-types.js.map +1 -0
  269. package/dist/src/lib/function-document-types.d.ts +144 -0
  270. package/dist/src/lib/function-document-types.js +370 -0
  271. package/dist/src/lib/function-document-types.js.map +1 -0
  272. package/dist/src/lib/function-grants-preflight.d.ts +64 -0
  273. package/dist/src/lib/function-grants-preflight.js +105 -0
  274. package/dist/src/lib/function-grants-preflight.js.map +1 -0
  275. package/dist/src/lib/function-log-lines.d.ts +76 -0
  276. package/dist/src/lib/function-log-lines.js +160 -0
  277. package/dist/src/lib/function-log-lines.js.map +1 -0
  278. package/dist/src/lib/function-log-row.d.ts +29 -0
  279. package/dist/src/lib/function-log-row.js +73 -0
  280. package/dist/src/lib/function-log-row.js.map +1 -0
  281. package/dist/src/lib/function-log-tail.d.ts +132 -0
  282. package/dist/src/lib/function-log-tail.js +262 -0
  283. package/dist/src/lib/function-log-tail.js.map +1 -0
  284. package/dist/src/lib/function-run.d.ts +289 -0
  285. package/dist/src/lib/function-run.js +389 -0
  286. package/dist/src/lib/function-run.js.map +1 -0
  287. package/dist/src/lib/function-schema-codegen.d.ts +143 -0
  288. package/dist/src/lib/function-schema-codegen.js +420 -0
  289. package/dist/src/lib/function-schema-codegen.js.map +1 -0
  290. package/dist/src/lib/function-sync.d.ts +459 -0
  291. package/dist/src/lib/function-sync.js +1258 -0
  292. package/dist/src/lib/function-sync.js.map +1 -0
  293. package/dist/src/lib/function-trigger-listing.d.ts +27 -0
  294. package/dist/src/lib/function-trigger-listing.js +70 -0
  295. package/dist/src/lib/function-trigger-listing.js.map +1 -0
  296. package/dist/src/lib/function-typecheck.d.ts +86 -0
  297. package/dist/src/lib/function-typecheck.js +370 -0
  298. package/dist/src/lib/function-typecheck.js.map +1 -0
  299. package/dist/src/lib/function-versions.d.ts +122 -0
  300. package/dist/src/lib/function-versions.js +182 -0
  301. package/dist/src/lib/function-versions.js.map +1 -0
  302. package/dist/src/lib/generated-allowlist.d.ts +28 -0
  303. package/dist/src/lib/generated-allowlist.js +281 -0
  304. package/dist/src/lib/generated-allowlist.js.map +1 -0
  305. package/dist/src/lib/generated-config-surfaces.d.ts +2936 -0
  306. package/dist/src/lib/generated-config-surfaces.js +10569 -0
  307. package/dist/src/lib/generated-config-surfaces.js.map +1 -0
  308. package/dist/src/lib/generated-sdk-types.d.ts +12 -0
  309. package/dist/src/lib/generated-sdk-types.js +13 -0
  310. package/dist/src/lib/generated-sdk-types.js.map +1 -0
  311. package/dist/src/lib/generated-template-lint.d.ts +212 -0
  312. package/dist/src/lib/generated-template-lint.js +624 -0
  313. package/dist/src/lib/generated-template-lint.js.map +1 -0
  314. package/dist/src/lib/init-adopt.d.ts +16 -0
  315. package/dist/src/lib/init-adopt.js +34 -0
  316. package/dist/src/lib/init-adopt.js.map +1 -0
  317. package/dist/src/lib/init-assets.d.ts +39 -0
  318. package/dist/src/lib/init-assets.js +97 -0
  319. package/dist/src/lib/init-assets.js.map +1 -0
  320. package/dist/src/lib/init-client-platforms.d.ts +14 -0
  321. package/dist/src/lib/init-client-platforms.js +71 -0
  322. package/dist/src/lib/init-client-platforms.js.map +1 -0
  323. package/dist/src/lib/init-config.d.ts +98 -0
  324. package/dist/src/lib/init-config.js +186 -0
  325. package/dist/src/lib/init-config.js.map +1 -0
  326. package/dist/src/lib/init-email-redirect-uris.d.ts +37 -0
  327. package/dist/src/lib/init-email-redirect-uris.js +46 -0
  328. package/dist/src/lib/init-email-redirect-uris.js.map +1 -0
  329. package/dist/src/lib/init-ios-links.d.ts +91 -0
  330. package/dist/src/lib/init-ios-links.js +219 -0
  331. package/dist/src/lib/init-ios-links.js.map +1 -0
  332. package/dist/src/lib/init-plan.d.ts +80 -0
  333. package/dist/src/lib/init-plan.js +95 -0
  334. package/dist/src/lib/init-plan.js.map +1 -0
  335. package/dist/src/lib/init-production-env.d.ts +48 -0
  336. package/dist/src/lib/init-production-env.js +59 -0
  337. package/dist/src/lib/init-production-env.js.map +1 -0
  338. package/dist/src/lib/init-schema.d.ts +74 -0
  339. package/dist/src/lib/init-schema.js +358 -0
  340. package/dist/src/lib/init-schema.js.map +1 -0
  341. package/dist/src/lib/init-xcode.d.ts +34 -0
  342. package/dist/src/lib/init-xcode.js +138 -0
  343. package/dist/src/lib/init-xcode.js.map +1 -0
  344. package/dist/src/lib/integration-request-config.d.ts +30 -0
  345. package/dist/src/lib/integration-request-config.js +145 -0
  346. package/dist/src/lib/integration-request-config.js.map +1 -0
  347. package/dist/src/lib/integration-selector.d.ts +42 -0
  348. package/dist/src/lib/integration-selector.js +46 -0
  349. package/dist/src/lib/integration-selector.js.map +1 -0
  350. package/dist/src/lib/ios-app-id.d.ts +34 -0
  351. package/dist/src/lib/ios-app-id.js +69 -0
  352. package/dist/src/lib/ios-app-id.js.map +1 -0
  353. package/dist/src/lib/list-options.d.ts +68 -0
  354. package/dist/src/lib/list-options.js +89 -0
  355. package/dist/src/lib/list-options.js.map +1 -0
  356. package/dist/src/lib/local-state.d.ts +55 -0
  357. package/dist/src/lib/local-state.js +167 -0
  358. package/dist/src/lib/local-state.js.map +1 -0
  359. package/dist/src/lib/local-test-cases.d.ts +63 -0
  360. package/dist/src/lib/local-test-cases.js +136 -0
  361. package/dist/src/lib/local-test-cases.js.map +1 -0
  362. package/dist/src/lib/log-inspection.d.ts +715 -0
  363. package/dist/src/lib/log-inspection.js +816 -0
  364. package/dist/src/lib/log-inspection.js.map +1 -0
  365. package/dist/src/lib/logout-admin-session.d.ts +33 -0
  366. package/dist/src/lib/logout-admin-session.js +70 -0
  367. package/dist/src/lib/logout-admin-session.js.map +1 -0
  368. package/dist/src/lib/migration-nag.d.ts +49 -0
  369. package/dist/src/lib/migration-nag.js +163 -0
  370. package/dist/src/lib/migration-nag.js.map +1 -0
  371. package/dist/src/lib/object-status-filter.d.ts +22 -0
  372. package/dist/src/lib/object-status-filter.js +45 -0
  373. package/dist/src/lib/object-status-filter.js.map +1 -0
  374. package/dist/src/lib/output.d.ts +124 -0
  375. package/dist/src/lib/output.js +219 -8
  376. package/dist/src/lib/output.js.map +1 -1
  377. package/dist/src/lib/package-manager.d.ts +140 -0
  378. package/dist/src/lib/package-manager.js +305 -0
  379. package/dist/src/lib/package-manager.js.map +1 -0
  380. package/dist/src/lib/paginate.d.ts +98 -0
  381. package/dist/src/lib/paginate.js +112 -0
  382. package/dist/src/lib/paginate.js.map +1 -0
  383. package/dist/src/lib/platform-owned.d.ts +63 -0
  384. package/dist/src/lib/platform-owned.js +85 -0
  385. package/dist/src/lib/platform-owned.js.map +1 -0
  386. package/dist/src/lib/project-config.d.ts +122 -0
  387. package/dist/src/lib/project-config.js +244 -0
  388. package/dist/src/lib/project-config.js.map +1 -0
  389. package/dist/src/lib/prompt-cost-format.d.ts +11 -0
  390. package/dist/src/lib/prompt-cost-format.js +41 -0
  391. package/dist/src/lib/prompt-cost-format.js.map +1 -0
  392. package/dist/src/lib/prompt-schema-codegen.d.ts +147 -0
  393. package/dist/src/lib/prompt-schema-codegen.js +462 -0
  394. package/dist/src/lib/prompt-schema-codegen.js.map +1 -0
  395. package/dist/src/lib/query-operators.d.ts +43 -0
  396. package/dist/src/lib/query-operators.js +80 -0
  397. package/dist/src/lib/query-operators.js.map +1 -0
  398. package/dist/src/lib/record-filter.d.ts +18 -0
  399. package/dist/src/lib/record-filter.js +55 -0
  400. package/dist/src/lib/record-filter.js.map +1 -0
  401. package/dist/src/lib/refresh-admin-credentials.d.ts +73 -0
  402. package/dist/src/lib/refresh-admin-credentials.js +123 -0
  403. package/dist/src/lib/refresh-admin-credentials.js.map +1 -0
  404. package/dist/src/lib/resolve-init-dev-port.d.ts +56 -0
  405. package/dist/src/lib/resolve-init-dev-port.js +55 -0
  406. package/dist/src/lib/resolve-init-dev-port.js.map +1 -0
  407. package/dist/src/lib/resolve-init-server.d.ts +64 -0
  408. package/dist/src/lib/resolve-init-server.js +77 -0
  409. package/dist/src/lib/resolve-init-server.js.map +1 -0
  410. package/dist/src/lib/resolve-owner.d.ts +19 -0
  411. package/dist/src/lib/resolve-owner.js +20 -0
  412. package/dist/src/lib/resolve-owner.js.map +1 -0
  413. package/dist/src/lib/resolve-platform.d.ts +74 -0
  414. package/dist/src/lib/resolve-platform.js +105 -0
  415. package/dist/src/lib/resolve-platform.js.map +1 -0
  416. package/dist/src/lib/run-status.d.ts +19 -0
  417. package/dist/src/lib/run-status.generated.d.ts +39 -0
  418. package/dist/src/lib/run-status.generated.js +66 -0
  419. package/dist/src/lib/run-status.generated.js.map +1 -0
  420. package/dist/src/lib/run-status.js +19 -0
  421. package/dist/src/lib/run-status.js.map +1 -0
  422. package/dist/src/lib/server-text-normalization.d.ts +51 -0
  423. package/dist/src/lib/server-text-normalization.js +90 -0
  424. package/dist/src/lib/server-text-normalization.js.map +1 -0
  425. package/dist/src/lib/server-url.d.ts +22 -0
  426. package/dist/src/lib/server-url.js +33 -0
  427. package/dist/src/lib/server-url.js.map +1 -0
  428. package/dist/src/lib/signing-secret-status.d.ts +81 -0
  429. package/dist/src/lib/signing-secret-status.js +116 -0
  430. package/dist/src/lib/signing-secret-status.js.map +1 -0
  431. package/dist/src/lib/skill-installer.d.ts +71 -0
  432. package/dist/src/lib/skill-installer.js +441 -0
  433. package/dist/src/lib/skill-installer.js.map +1 -0
  434. package/dist/src/lib/snapshot-audit-source.d.ts +45 -0
  435. package/dist/src/lib/snapshot-audit-source.js +58 -0
  436. package/dist/src/lib/snapshot-audit-source.js.map +1 -0
  437. package/dist/src/lib/snapshot-audit-store.d.ts +52 -0
  438. package/dist/src/lib/snapshot-audit-store.js +196 -0
  439. package/dist/src/lib/snapshot-audit-store.js.map +1 -0
  440. package/dist/src/lib/snapshot-audit.d.ts +207 -0
  441. package/dist/src/lib/snapshot-audit.js +431 -0
  442. package/dist/src/lib/snapshot-audit.js.map +1 -0
  443. package/dist/src/lib/snapshot-build-rows.d.ts +60 -0
  444. package/dist/src/lib/snapshot-build-rows.js +87 -0
  445. package/dist/src/lib/snapshot-build-rows.js.map +1 -0
  446. package/dist/src/lib/snapshot-build.d.ts +50 -0
  447. package/dist/src/lib/snapshot-build.js +111 -0
  448. package/dist/src/lib/snapshot-build.js.map +1 -0
  449. package/dist/src/lib/snapshot-manifest-layout.d.ts +61 -0
  450. package/dist/src/lib/snapshot-manifest-layout.js +70 -0
  451. package/dist/src/lib/snapshot-manifest-layout.js.map +1 -0
  452. package/dist/src/lib/snapshots.d.ts +98 -0
  453. package/dist/src/lib/snapshots.js +294 -0
  454. package/dist/src/lib/snapshots.js.map +1 -0
  455. package/dist/src/lib/step-run-table.d.ts +43 -0
  456. package/dist/src/lib/step-run-table.js +129 -0
  457. package/dist/src/lib/step-run-table.js.map +1 -0
  458. package/dist/src/lib/storage-pending-retry.d.ts +26 -0
  459. package/dist/src/lib/storage-pending-retry.js +42 -0
  460. package/dist/src/lib/storage-pending-retry.js.map +1 -0
  461. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +42 -0
  462. package/dist/src/lib/swift-codegen/agentGenerator.js +118 -0
  463. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -0
  464. package/dist/src/lib/swift-codegen/banners.d.ts +24 -0
  465. package/dist/src/lib/swift-codegen/banners.js +25 -0
  466. package/dist/src/lib/swift-codegen/banners.js.map +1 -0
  467. package/dist/src/lib/swift-codegen/dbGenerator.d.ts +113 -0
  468. package/dist/src/lib/swift-codegen/dbGenerator.js +926 -0
  469. package/dist/src/lib/swift-codegen/dbGenerator.js.map +1 -0
  470. package/dist/src/lib/swift-codegen/dbSwiftTypes.d.ts +42 -0
  471. package/dist/src/lib/swift-codegen/dbSwiftTypes.js +100 -0
  472. package/dist/src/lib/swift-codegen/dbSwiftTypes.js.map +1 -0
  473. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +139 -0
  474. package/dist/src/lib/swift-codegen/functionGenerator.js +462 -0
  475. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -0
  476. package/dist/src/lib/swift-codegen/generator.d.ts +100 -0
  477. package/dist/src/lib/swift-codegen/generator.js +457 -0
  478. package/dist/src/lib/swift-codegen/generator.js.map +1 -0
  479. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +87 -0
  480. package/dist/src/lib/swift-codegen/schemaToSwift.js +661 -0
  481. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -0
  482. package/dist/src/lib/swift-codegen/siblingSymbols.d.ts +94 -0
  483. package/dist/src/lib/swift-codegen/siblingSymbols.js +155 -0
  484. package/dist/src/lib/swift-codegen/siblingSymbols.js.map +1 -0
  485. package/dist/src/lib/swift-codegen/swiftNaming.d.ts +85 -0
  486. package/dist/src/lib/swift-codegen/swiftNaming.js +198 -0
  487. package/dist/src/lib/swift-codegen/swiftNaming.js.map +1 -0
  488. package/dist/src/lib/sync-dir-selector.d.ts +21 -0
  489. package/dist/src/lib/sync-dir-selector.js +30 -0
  490. package/dist/src/lib/sync-dir-selector.js.map +1 -0
  491. package/dist/src/lib/sync-paths.d.ts +128 -0
  492. package/dist/src/lib/sync-paths.js +195 -0
  493. package/dist/src/lib/sync-paths.js.map +1 -0
  494. package/dist/src/lib/sync-resource-types.d.ts +563 -0
  495. package/dist/src/lib/sync-resource-types.js +1073 -0
  496. package/dist/src/lib/sync-resource-types.js.map +1 -0
  497. package/dist/src/lib/sync-selectors.d.ts +138 -0
  498. package/dist/src/lib/sync-selectors.js +289 -0
  499. package/dist/src/lib/sync-selectors.js.map +1 -0
  500. package/dist/src/lib/template.d.ts +170 -0
  501. package/dist/src/lib/template.js +484 -68
  502. package/dist/src/lib/template.js.map +1 -1
  503. package/dist/src/lib/test-case-file-names.d.ts +40 -0
  504. package/dist/src/lib/test-case-file-names.js +91 -0
  505. package/dist/src/lib/test-case-file-names.js.map +1 -0
  506. package/dist/src/lib/test-case-keys.d.ts +29 -0
  507. package/dist/src/lib/test-case-keys.js +55 -0
  508. package/dist/src/lib/test-case-keys.js.map +1 -0
  509. package/dist/src/lib/test-case-variables.d.ts +29 -0
  510. package/dist/src/lib/test-case-variables.js +71 -0
  511. package/dist/src/lib/test-case-variables.js.map +1 -0
  512. package/dist/src/lib/token-inject.d.ts +56 -0
  513. package/dist/src/lib/token-inject.js +204 -0
  514. package/dist/src/lib/token-inject.js.map +1 -0
  515. package/dist/src/lib/toml-database-config.d.ts +123 -0
  516. package/dist/src/lib/toml-database-config.js +544 -0
  517. package/dist/src/lib/toml-database-config.js.map +1 -0
  518. package/dist/src/lib/toml-metadata-config.d.ts +151 -0
  519. package/dist/src/lib/toml-metadata-config.js +476 -0
  520. package/dist/src/lib/toml-metadata-config.js.map +1 -0
  521. package/dist/src/lib/toml-native-form.d.ts +46 -0
  522. package/dist/src/lib/toml-native-form.js +78 -0
  523. package/dist/src/lib/toml-native-form.js.map +1 -0
  524. package/dist/src/lib/toml-params-validator.d.ts +129 -0
  525. package/dist/src/lib/toml-params-validator.js +298 -0
  526. package/dist/src/lib/toml-params-validator.js.map +1 -0
  527. package/dist/src/lib/toml-scalar-edit.d.ts +43 -0
  528. package/dist/src/lib/toml-scalar-edit.js +283 -0
  529. package/dist/src/lib/toml-scalar-edit.js.map +1 -0
  530. package/dist/src/lib/user-selector.d.ts +24 -0
  531. package/dist/src/lib/user-selector.js +33 -0
  532. package/dist/src/lib/user-selector.js.map +1 -0
  533. package/dist/src/lib/version-check.d.ts +35 -0
  534. package/dist/src/lib/version-check.js +241 -0
  535. package/dist/src/lib/version-check.js.map +1 -0
  536. package/dist/src/lib/watch.d.ts +121 -0
  537. package/dist/src/lib/watch.js +169 -0
  538. package/dist/src/lib/watch.js.map +1 -0
  539. package/dist/src/lib/web-url.d.ts +40 -0
  540. package/dist/src/lib/web-url.js +76 -0
  541. package/dist/src/lib/web-url.js.map +1 -0
  542. package/dist/src/lib/webhook-deliver.d.ts +209 -0
  543. package/dist/src/lib/webhook-deliver.js +519 -0
  544. package/dist/src/lib/webhook-deliver.js.map +1 -0
  545. package/dist/src/lib/workflow-apply.d.ts +110 -0
  546. package/dist/src/lib/workflow-apply.js +164 -0
  547. package/dist/src/lib/workflow-apply.js.map +1 -0
  548. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.d.ts +129 -0
  549. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js +269 -0
  550. package/dist/src/lib/workflow-codegen/generated-schema-descriptor.js.map +1 -0
  551. package/dist/src/lib/workflow-codegen/generator.d.ts +96 -0
  552. package/dist/src/lib/workflow-codegen/generator.js +361 -0
  553. package/dist/src/lib/workflow-codegen/generator.js.map +1 -0
  554. package/dist/src/lib/workflow-codegen/invokerIR.d.ts +94 -0
  555. package/dist/src/lib/workflow-codegen/invokerIR.js +76 -0
  556. package/dist/src/lib/workflow-codegen/invokerIR.js.map +1 -0
  557. package/dist/src/lib/workflow-codegen/naming.d.ts +33 -0
  558. package/dist/src/lib/workflow-codegen/naming.js +81 -0
  559. package/dist/src/lib/workflow-codegen/naming.js.map +1 -0
  560. package/dist/src/lib/workflow-codegen/schemaToTs.d.ts +80 -0
  561. package/dist/src/lib/workflow-codegen/schemaToTs.js +303 -0
  562. package/dist/src/lib/workflow-codegen/schemaToTs.js.map +1 -0
  563. package/dist/src/lib/workflow-config-apply.d.ts +70 -0
  564. package/dist/src/lib/workflow-config-apply.js +137 -0
  565. package/dist/src/lib/workflow-config-apply.js.map +1 -0
  566. package/dist/src/lib/workflow-config-sidecar.d.ts +63 -0
  567. package/dist/src/lib/workflow-config-sidecar.js +96 -0
  568. package/dist/src/lib/workflow-config-sidecar.js.map +1 -0
  569. package/dist/src/lib/workflow-defaults.d.ts +29 -0
  570. package/dist/src/lib/workflow-defaults.js +41 -0
  571. package/dist/src/lib/workflow-defaults.js.map +1 -0
  572. package/dist/src/lib/workflow-fragments.d.ts +64 -0
  573. package/dist/src/lib/workflow-fragments.js +342 -0
  574. package/dist/src/lib/workflow-fragments.js.map +1 -0
  575. package/dist/src/lib/workflow-include-preserve.d.ts +76 -0
  576. package/dist/src/lib/workflow-include-preserve.js +286 -0
  577. package/dist/src/lib/workflow-include-preserve.js.map +1 -0
  578. package/dist/src/lib/workflow-payload.d.ts +98 -0
  579. package/dist/src/lib/workflow-payload.js +178 -0
  580. package/dist/src/lib/workflow-payload.js.map +1 -0
  581. package/dist/src/lib/workflow-toml-validator.d.ts +211 -0
  582. package/dist/src/lib/workflow-toml-validator.js +770 -0
  583. package/dist/src/lib/workflow-toml-validator.js.map +1 -0
  584. package/dist/src/lib/workflow-usage.d.ts +196 -0
  585. package/dist/src/lib/workflow-usage.js +310 -0
  586. package/dist/src/lib/workflow-usage.js.map +1 -0
  587. package/dist/src/types/index.d.ts +591 -0
  588. package/dist/src/validators.d.ts +65 -0
  589. package/dist/src/validators.js +64 -0
  590. package/dist/src/validators.js.map +1 -0
  591. package/package.json +34 -9
@@ -0,0 +1,447 @@
1
+ /**
2
+ * The shared Primitive environment resolver (#2873).
3
+ *
4
+ * Three surfaces have to agree on which backend/app a project is pointed at:
5
+ * the CLI, the Vue build (`primitive-app`'s `primitiveEnv()` plugin), and the
6
+ * Swift template's pre-build script. This module is the single algorithm they
7
+ * share. The CLI owns it; `packages/primitive-app` carries a byte-identical
8
+ * GENERATED copy (`cli/scripts/gen-primitive-env-resolver.mjs`, checked for
9
+ * freshness by `cli/tests/unit/env-resolver-copy-drift-guard.test.ts`); the
10
+ * Swift script is an independent bash+python3 port pinned by a parity test.
11
+ *
12
+ * ── COPYABILITY (load-bearing) ────────────────────────────────────────────
13
+ * This file MUST stay self-contained: node builtins only, ZERO relative
14
+ * imports. The generator copies it verbatim into a package that cannot depend
15
+ * on the CLI, so any `./x.js` import here would break that copy at runtime.
16
+ * The drift guard asserts this.
17
+ *
18
+ * Scope: config discovery, the schema `version` check, structural validation,
19
+ * the local selection, the precedence, and the http→ws scheme swap. It
20
+ * deliberately does NOT duplicate the CLI's full field-level validation
21
+ * (`validateProjectConfig` in `project-config.ts`) — the CLI wrapper runs that
22
+ * first, and the other readers only need "version understood, shape sane, fail
23
+ * loudly otherwise".
24
+ *
25
+ * Precedence (one order, everywhere):
26
+ * 1. an explicit name (`--env` / `--primitive-env`)
27
+ * 2. PRIMITIVE_ENV (per-invocation intent, keeps CI working)
28
+ * 3. .primitive/local.json (this machine's `primitive env use`)
29
+ * 4. defaultEnvironment (the committed team default)
30
+ * 5. the sole environment, if there is exactly one
31
+ */
32
+ import { existsSync, readFileSync } from "node:fs";
33
+ import { basename, dirname, join, resolve } from "node:path";
34
+ /** Schema version of `primitive/config.json` this core understands. */
35
+ export const PRIMITIVE_CONFIG_VERSION = 1;
36
+ /** Schema version of `.primitive/local.json` this core writes and reads. */
37
+ export const PRIMITIVE_LOCAL_STATE_VERSION = 1;
38
+ /**
39
+ * The two directories, split apart by #3153 so one name never means two
40
+ * things: `primitive/` is the COMMITTED tree (the config and every
41
+ * environment's TOML), `.primitive/` is MACHINE-LOCAL state (credentials, this
42
+ * machine's selection, snapshot backups) and is gitignored whole.
43
+ */
44
+ export const PROJECT_TREE_DIR = "primitive";
45
+ export const PROJECT_LOCAL_STATE_DIR = ".primitive";
46
+ export const PROJECT_CONFIG_FILENAME = "config.json";
47
+ export const LOCAL_STATE_FILENAME = "local.json";
48
+ export const PROJECT_CONFIG_DISPLAY_NAME = "primitive/config.json";
49
+ export const LOCAL_STATE_DISPLAY_NAME = ".primitive/local.json";
50
+ /**
51
+ * The one refusal for a project that never migrated off the pre-#3153 layout:
52
+ * a `.primitive/config.json` with no `primitive/config.json` beside it.
53
+ *
54
+ * That shape is refused rather than walked past because the walk's next stop
55
+ * is the parent directory, and in a nested checkout the parent may be a
56
+ * DIFFERENT project — a command run in the unmigrated one would silently act
57
+ * on the other's app. Nothing else is refused (#3392): anything left under
58
+ * `.primitive/` beside a migrated tree is machine-local junk, not signal.
59
+ *
60
+ * One sentence, naming both halves — the file that was found and the file
61
+ * that is expected — and no document. The migration page this once pointed
62
+ * at was never published (#3155, won't-fix), and every reader that shares
63
+ * this refusal — this core, the generated Vite-plugin copy, the Swift
64
+ * pre-build script, the Vue template's deploy script — says the same thing.
65
+ */
66
+ export function unmigratedProjectMessage(found, expected) {
67
+ return (`Found ${found} but no ${expected}: this project still uses the retired ` +
68
+ `layout under ${PROJECT_LOCAL_STATE_DIR}/, which is never read.`);
69
+ }
70
+ /**
71
+ * The one refusal for a command run outside a Primitive project (#3154,
72
+ * intent criterion 5).
73
+ *
74
+ * There is exactly one way to resolve the configuration tree, the credentials
75
+ * and the app: the environment named by `primitive/config.json`. Outside a
76
+ * project there is no such thing, and the CLI says so once, in these words,
77
+ * wherever the question is asked — the resolver core, the CLI's
78
+ * `requireCurrentEnvironment()`, and the credentials store.
79
+ *
80
+ * Two constraints on the wording, both test-asserted:
81
+ *
82
+ * - it names `primitive init`, the one command that creates what is missing;
83
+ * - it never names `primitive env add`, which after this change also fails
84
+ * outside a project — an error may only offer an invocation it does not
85
+ * itself block.
86
+ */
87
+ export function missingConfigMessage(where) {
88
+ return (`No ${PROJECT_CONFIG_DISPLAY_NAME} found in ${where} or any parent directory. ` +
89
+ `Primitive commands run inside a Primitive project: it is where the CLI reads ` +
90
+ `the environment, the app that environment names, and the configuration tree ` +
91
+ `from. Run 'primitive init' to create one.`);
92
+ }
93
+ export class PrimitiveEnvError extends Error {
94
+ kind;
95
+ path;
96
+ constructor(kind, message, path) {
97
+ super(message);
98
+ this.name = "PrimitiveEnvError";
99
+ this.kind = kind;
100
+ this.path = path;
101
+ }
102
+ }
103
+ /**
104
+ * The app's web counterpart as a normalized ORIGIN, or undefined when the
105
+ * value cannot be one (#2982).
106
+ *
107
+ * Unlike `appId`/`appName`, a typed read is not enough. This value is not
108
+ * merely carried: the Swift app points its emailed sign-in link at
109
+ * `<webUrl>/oauth/callback` and trusts incoming universal links from the same
110
+ * origin, and BOTH jobs need an origin —
111
+ *
112
+ * - https except loopback, the rule the server applies to every redirect URI
113
+ * (`src/auth/redirect-uri.ts`): an origin that cannot be allow-listed turns
114
+ * every sign-in request into a 400, and a plain-http link would carry the
115
+ * magic token in clear;
116
+ * - no path, query or fragment: the web client serves its callback on its own
117
+ * origin plus `/oauth/callback`, which is also the exact path the
118
+ * `apple-app-site-association` component claims;
119
+ * - no credentials, which have no business in a link that goes out by email.
120
+ *
121
+ * `primitive env add --web-url` and the project-config validation reject those
122
+ * shapes with a field-named error, but neither is on the path from a
123
+ * hand-edited `primitive/config.json` to an Xcode build: the Swift template's
124
+ * pre-build script reads the file directly. So every reader that feeds
125
+ * `primitive.json` applies the contract, and a value that misses it is read as
126
+ * "this environment has no web counterpart" — code-only email, no trusted
127
+ * origin, nothing silently pointed at the wrong URL.
128
+ *
129
+ * The message-producing twin of this rule lives in `cli/src/lib/web-url.ts`;
130
+ * this file cannot import it (see COPYABILITY above), and a test pins that the
131
+ * two agree.
132
+ */
133
+ export function normalizeWebOrigin(value) {
134
+ if (typeof value !== "string")
135
+ return undefined;
136
+ const trimmed = value.trim();
137
+ if (!trimmed)
138
+ return undefined;
139
+ let url;
140
+ try {
141
+ url = new URL(trimmed);
142
+ }
143
+ catch {
144
+ return undefined;
145
+ }
146
+ if (url.protocol !== "https:" && url.protocol !== "http:")
147
+ return undefined;
148
+ if (url.protocol === "http:" &&
149
+ url.hostname !== "localhost" &&
150
+ url.hostname !== "127.0.0.1") {
151
+ return undefined;
152
+ }
153
+ if (url.username || url.password)
154
+ return undefined;
155
+ if (url.pathname !== "/" && url.pathname !== "")
156
+ return undefined;
157
+ if (url.search || url.hash)
158
+ return undefined;
159
+ return url.origin;
160
+ }
161
+ /**
162
+ * The one remedy for an environment that names no app (#3152), shared by every
163
+ * reader that can hit it: this core, the CLI's `validateProjectConfig`, the
164
+ * Swift template's pre-build script, and the Vue template's cf-deploy.
165
+ *
166
+ * Two constraints on the wording, both test-asserted:
167
+ *
168
+ * - it never says `primitive env add <name>`, which REFUSES an environment
169
+ * name that already exists — the shape this error is always about;
170
+ * - it names no command the failure itself blocks. The CLI validates the
171
+ * project config before any command parses, so every `primitive` command
172
+ * run inside the broken project fails with this same error. The only
173
+ * invocation it may offer is one it says out loud to run elsewhere.
174
+ */
175
+ export function missingAppIdMessage(name, configPath) {
176
+ const where = configPath
177
+ ? `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath})`
178
+ : PROJECT_CONFIG_DISPLAY_NAME;
179
+ return (`Environment "${name}" in ${where} has no "appId". ` +
180
+ `Every environment names exactly one app — add "appId": "<app-id>" to that environment in ${PROJECT_CONFIG_DISPLAY_NAME}. ` +
181
+ `Find the app id in the Primitive admin UI, with 'primitive apps list' run from another Primitive project, ` +
182
+ `or as the residual "currentAppId" in .primitive/credentials.json if this environment was ever pointed at an app by the retired per-machine app selection.`);
183
+ }
184
+ /**
185
+ * An environment's `appId` as a usable string, or undefined when the value
186
+ * cannot be one. Non-string and blank-after-trim are both "no app named": a
187
+ * numeric or whitespace appId reaches a consumer as an app id it cannot use,
188
+ * which is the silent version of the failure this field exists to prevent.
189
+ */
190
+ function readAppId(value) {
191
+ if (typeof value !== "string")
192
+ return undefined;
193
+ const trimmed = value.trim();
194
+ return trimmed || undefined;
195
+ }
196
+ /**
197
+ * Derives the WebSocket URL from the API URL. Every apiUrl/wsUrl pair in
198
+ * practice is the same host with the scheme swapped, so it is derived rather
199
+ * than authored — one less thing to get out of sync.
200
+ */
201
+ export function deriveWsUrl(apiUrl) {
202
+ if (apiUrl.startsWith("https://"))
203
+ return "wss://" + apiUrl.slice("https://".length);
204
+ if (apiUrl.startsWith("http://"))
205
+ return "ws://" + apiUrl.slice("http://".length);
206
+ return apiUrl;
207
+ }
208
+ /**
209
+ * Finds `primitive/config.json` by walking up from `cwd`, or returns the
210
+ * PRIMITIVE_PROJECT_CONFIG override when it is set (and exists).
211
+ *
212
+ * The override is checked for provenance BEFORE the file is read (#3153, F2):
213
+ * it bypasses the walk, so without this an old-layout config could be handed
214
+ * straight to a reader and defeat the cutover. An override that points inside
215
+ * a `.primitive/` directory IS the old layout, named explicitly.
216
+ *
217
+ * This is the one function every reader goes through — `resolvePrimitiveEnv`
218
+ * and the CLI's own `loadProjectConfig`/`findProjectRoot` alike — so the
219
+ * unmigrated-project refusal lives HERE, in the walk, or the commands that
220
+ * never call `resolvePrimitiveEnv` would walk past the old anchor into the
221
+ * parent directory's project.
222
+ */
223
+ export function findPrimitiveConfigPath(options = {}) {
224
+ const env = options.env ?? process.env;
225
+ const override = env.PRIMITIVE_PROJECT_CONFIG;
226
+ if (override) {
227
+ const forced = resolve(override);
228
+ if (basename(dirname(forced)) === PROJECT_LOCAL_STATE_DIR) {
229
+ throw new PrimitiveEnvError("stale-layout", unmigratedProjectMessage(forced, join(dirname(dirname(forced)), PROJECT_TREE_DIR, PROJECT_CONFIG_FILENAME)), forced);
230
+ }
231
+ return existsSync(forced) ? forced : null;
232
+ }
233
+ let current = resolve(options.cwd ?? process.cwd());
234
+ while (true) {
235
+ const candidate = join(current, PROJECT_TREE_DIR, PROJECT_CONFIG_FILENAME);
236
+ if (existsSync(candidate))
237
+ return candidate;
238
+ // No anchor here. The old one means this directory IS a project — one
239
+ // that never migrated — and the walk stops rather than resolving whatever
240
+ // project the parent turns out to be (#3392). Checked only when the new
241
+ // anchor is absent: beside a migrated tree the old file is a leftover.
242
+ const unmigrated = join(current, PROJECT_LOCAL_STATE_DIR, PROJECT_CONFIG_FILENAME);
243
+ if (existsSync(unmigrated)) {
244
+ throw new PrimitiveEnvError("stale-layout", unmigratedProjectMessage(unmigrated, candidate), unmigrated);
245
+ }
246
+ const parent = dirname(current);
247
+ if (parent === current)
248
+ return null;
249
+ current = parent;
250
+ }
251
+ }
252
+ /**
253
+ * The project root for a config path: the parent of `primitive/`, or the
254
+ * containing directory when the config was pointed at directly (a fixture via
255
+ * PRIMITIVE_PROJECT_CONFIG, which is not inside a `primitive/` directory).
256
+ */
257
+ export function projectRootForConfigPath(configPath) {
258
+ const dir = dirname(configPath);
259
+ return basename(dir) === PROJECT_TREE_DIR ? dirname(dir) : dir;
260
+ }
261
+ /**
262
+ * Machine-local state lives under the project root's `.primitive/`, not beside
263
+ * the config — the config is committed now, and the two must not share a
264
+ * directory. A fixture-pointed bare config still gets its own `.primitive/`
265
+ * in its own directory, so it never picks up a real project's selection.
266
+ */
267
+ export function localStatePathForConfigPath(configPath) {
268
+ return join(projectRootForConfigPath(configPath), PROJECT_LOCAL_STATE_DIR, LOCAL_STATE_FILENAME);
269
+ }
270
+ /**
271
+ * The message of a caught value. A catch binding is `unknown` under the
272
+ * strict config primitive-app compiles this copy with, so narrow first.
273
+ */
274
+ function errorMessage(err) {
275
+ return err instanceof Error ? err.message : String(err);
276
+ }
277
+ /**
278
+ * Reads and structurally validates `primitive/config.json`. Throws rather
279
+ * than guessing: a config that cannot be understood is always louder than a
280
+ * silent fallback to the wrong backend.
281
+ */
282
+ export function readCoreProjectConfig(configPath) {
283
+ if (!existsSync(configPath)) {
284
+ throw new PrimitiveEnvError("missing-config", missingConfigMessage(dirname(configPath)), configPath);
285
+ }
286
+ let raw;
287
+ try {
288
+ raw = readFileSync(configPath, "utf-8");
289
+ }
290
+ catch (err) {
291
+ throw new PrimitiveEnvError("malformed-config", `Failed to read ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}): ${errorMessage(err)}`, configPath);
292
+ }
293
+ let parsed;
294
+ try {
295
+ parsed = JSON.parse(raw);
296
+ }
297
+ catch (err) {
298
+ throw new PrimitiveEnvError("malformed-config", `Failed to parse ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}): ${errorMessage(err)}`, configPath);
299
+ }
300
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
301
+ throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) must contain a JSON object at the top level.`, configPath);
302
+ }
303
+ const obj = parsed;
304
+ if (typeof obj.version !== "number" || !Number.isInteger(obj.version)) {
305
+ throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) is missing required integer field "version".`, configPath);
306
+ }
307
+ if (obj.version !== PRIMITIVE_CONFIG_VERSION) {
308
+ throw new PrimitiveEnvError("unsupported-version", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) has version ${obj.version}, but this tool understands version ${PRIMITIVE_CONFIG_VERSION}.`, configPath);
309
+ }
310
+ if (!obj.environments || typeof obj.environments !== "object" || Array.isArray(obj.environments)) {
311
+ throw new PrimitiveEnvError("malformed-config", `${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}) is missing required "environments" object.`, configPath);
312
+ }
313
+ const environments = {};
314
+ for (const [name, entry] of Object.entries(obj.environments)) {
315
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
316
+ throw new PrimitiveEnvError("malformed-config", `Environment "${name}" must be an object in ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}).`, configPath);
317
+ }
318
+ const e = entry;
319
+ if (typeof e.apiUrl !== "string" || !e.apiUrl) {
320
+ throw new PrimitiveEnvError("malformed-config", `Environment "${name}" must have a non-empty "apiUrl" string in ${PROJECT_CONFIG_DISPLAY_NAME} (${configPath}).`, configPath);
321
+ }
322
+ // Every environment names one app, checked here rather than after the
323
+ // selection: the criterion is about the FILE, and a second reader (the
324
+ // Vite plugin, cf-deploy, the Swift pre-build script) may land on a
325
+ // different environment than the CLI did.
326
+ const appId = readAppId(e.appId);
327
+ if (!appId) {
328
+ throw new PrimitiveEnvError("missing-app-id", missingAppIdMessage(name, configPath), configPath);
329
+ }
330
+ environments[name] = {
331
+ apiUrl: e.apiUrl.replace(/\/$/, ""),
332
+ appId,
333
+ appName: typeof e.appName === "string" ? e.appName : undefined,
334
+ webUrl: normalizeWebOrigin(e.webUrl),
335
+ description: typeof e.description === "string" ? e.description : undefined,
336
+ };
337
+ }
338
+ return {
339
+ version: obj.version,
340
+ defaultEnvironment: typeof obj.defaultEnvironment === "string" && obj.defaultEnvironment
341
+ ? obj.defaultEnvironment
342
+ : undefined,
343
+ environments,
344
+ };
345
+ }
346
+ /**
347
+ * Reads this machine's selection from `.primitive/local.json`. Returns null
348
+ * when there is no file or no selection in it; throws when the file exists but
349
+ * cannot be read as the shape `primitive env use` writes.
350
+ */
351
+ export function readLocalSelection(configPath) {
352
+ const path = localStatePathForConfigPath(configPath);
353
+ if (!existsSync(path))
354
+ return null;
355
+ const corrupt = (detail) => {
356
+ throw new PrimitiveEnvError("corrupt-local-state", `${LOCAL_STATE_DISPLAY_NAME} (${path}) is unreadable: ${detail}. Delete the file or re-run 'primitive env use <name>'.`, path);
357
+ };
358
+ let parsed;
359
+ try {
360
+ parsed = JSON.parse(readFileSync(path, "utf-8"));
361
+ }
362
+ catch (err) {
363
+ return corrupt(errorMessage(err));
364
+ }
365
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
366
+ return corrupt("expected a JSON object");
367
+ }
368
+ const obj = parsed;
369
+ const selected = obj.selectedEnvironment;
370
+ if (selected === undefined || selected === null || selected === "")
371
+ return null;
372
+ if (typeof selected !== "string") {
373
+ return corrupt(`"selectedEnvironment" must be a string`);
374
+ }
375
+ return selected;
376
+ }
377
+ /**
378
+ * Applies the precedence to an already-loaded config. Exposed separately so
379
+ * the CLI wrapper can run its own field-level validation first and still share
380
+ * one ordering with every other reader.
381
+ */
382
+ export function selectEnvironmentName(config, options) {
383
+ const available = Object.keys(config.environments);
384
+ const list = available.join(", ") || "(none)";
385
+ const where = options.configPath
386
+ ? `${PROJECT_CONFIG_DISPLAY_NAME} (${options.configPath})`
387
+ : PROJECT_CONFIG_DISPLAY_NAME;
388
+ const requireKnown = (name, source, origin) => {
389
+ if (!config.environments[name]) {
390
+ throw new PrimitiveEnvError("unknown-environment", `Environment "${name}" is not defined in ${where} (selected ${origin}). Available: ${list}`, options.configPath);
391
+ }
392
+ return { name, source };
393
+ };
394
+ if (options.explicitEnvName) {
395
+ return requireKnown(options.explicitEnvName, "explicit", "explicitly");
396
+ }
397
+ if (options.envVarName) {
398
+ return requireKnown(options.envVarName, "env-var", "via PRIMITIVE_ENV");
399
+ }
400
+ if (options.localSelection) {
401
+ return requireKnown(options.localSelection, "local", `in ${LOCAL_STATE_DISPLAY_NAME}`);
402
+ }
403
+ if (config.defaultEnvironment) {
404
+ return requireKnown(config.defaultEnvironment, "default", `as "defaultEnvironment"`);
405
+ }
406
+ if (available.length === 1) {
407
+ return { name: available[0], source: "sole" };
408
+ }
409
+ if (available.length === 0) {
410
+ throw new PrimitiveEnvError("no-selection", `${where} has no environments defined. Run 'primitive env add <name>' or 'primitive init'.`, options.configPath);
411
+ }
412
+ throw new PrimitiveEnvError("no-selection", `No environment selected. Run 'primitive env use <name>', set "defaultEnvironment" in ${where}, or export PRIMITIVE_ENV. Available: ${list}`, options.configPath);
413
+ }
414
+ /**
415
+ * The whole algorithm end to end: discover the config, read the selection,
416
+ * apply the precedence, derive the WebSocket URL.
417
+ */
418
+ export function resolvePrimitiveEnv(options = {}) {
419
+ const env = options.env ?? process.env;
420
+ const configPath = options.configPath ?? findPrimitiveConfigPath({ cwd: options.cwd, env });
421
+ if (!configPath) {
422
+ throw new PrimitiveEnvError("missing-config", missingConfigMessage(options.cwd ?? process.cwd()));
423
+ }
424
+ const projectRoot = projectRootForConfigPath(configPath);
425
+ const config = readCoreProjectConfig(configPath);
426
+ const { name, source } = selectEnvironmentName(config, {
427
+ explicitEnvName: options.explicitEnvName || null,
428
+ envVarName: env.PRIMITIVE_ENV || null,
429
+ localSelection: readLocalSelection(configPath),
430
+ configPath,
431
+ });
432
+ const entry = config.environments[name];
433
+ return {
434
+ name,
435
+ apiUrl: entry.apiUrl,
436
+ wsUrl: deriveWsUrl(entry.apiUrl),
437
+ appId: entry.appId,
438
+ appName: entry.appName,
439
+ webUrl: entry.webUrl,
440
+ description: entry.description,
441
+ source,
442
+ configPath,
443
+ localStatePath: localStatePathForConfigPath(configPath),
444
+ projectRoot,
445
+ };
446
+ }
447
+ //# sourceMappingURL=env-resolver-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-resolver-core.js","sourceRoot":"","sources":["../../../src/lib/env-resolver-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7D,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAC1C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAC5C,MAAM,CAAC,MAAM,uBAAuB,GAAG,YAAY,CAAC;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AACjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,uBAAuB,CAAC;AACnE,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAa,EAAE,QAAgB;IACtE,OAAO,CACL,SAAS,KAAK,WAAW,QAAQ,wCAAwC;QACzE,gBAAgB,uBAAuB,yBAAyB,CACjE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,OAAO,CACL,MAAM,2BAA2B,aAAa,KAAK,4BAA4B;Q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QACrD,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,IAAI;QAChD,UAAU,EAAE,GAAG,CAAC,aAAa,IAAI,IAAI;QACrC,cAAc,EAAE,kBAAkB,CAAC,UAAU,CAAC;QAC9C,UAAU;KACX,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAExC,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC;QAChC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM;QACN,UAAU;QACV,cAAc,EAAE,2BAA2B,CAAC,UAAU,CAAC;QACvD,WAAW;KACZ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Environment resolution (CLI side).
3
+ *
4
+ * The algorithm itself lives in `env-resolver-core.ts` — the one copy the Vite
5
+ * plugin and the Swift pre-build script also run (#2873). This module is the
6
+ * CLI's thin wrapper around it: process-lifetime caching, the `--env` override
7
+ * commander sets, and — load-bearing — the CLI's own FULL field-level
8
+ * validation via `validateProjectConfig()`. The core carries only the version
9
+ * and structural checks the other readers need; running the CLI's validation
10
+ * first is what keeps `getProjectConfig()` and `getCurrentEnvironment()` from
11
+ * ever disagreeing about the same file.
12
+ *
13
+ * The resolution order is:
14
+ *
15
+ * 1. Explicit --env <name> flag (set via setCurrentEnvName from bin/primitive.ts)
16
+ * 2. PRIMITIVE_ENV environment variable
17
+ * 3. The per-machine selection in .primitive/local.json (`primitive env use`)
18
+ * 4. The project config's committed defaultEnvironment
19
+ * 5. If the project has exactly one environment, that one
20
+ * 6. null (legacy mode — fall back to ~/.primitive/credentials.json)
21
+ *
22
+ * Commands read the resolved environment once via getCurrentEnvironment().
23
+ * The resolution is cached for the lifetime of the process.
24
+ */
25
+ import { type ProjectConfig, type ProjectEnvironment } from "./project-config.js";
26
+ import { PrimitiveEnvError, type PrimitiveEnvSource } from "./env-resolver-core.js";
27
+ export interface ResolvedEnvironment {
28
+ /** The environment name (e.g. "dev", "prod"). */
29
+ name: string;
30
+ /** The config entry for this environment. */
31
+ config: ProjectEnvironment;
32
+ /** Absolute path to primitive/config.json. */
33
+ projectConfigPath: string;
34
+ /** Absolute path to the project root (the parent of .primitive/). */
35
+ projectRoot: string;
36
+ /** Which precedence step chose this environment. */
37
+ source: PrimitiveEnvSource;
38
+ }
39
+ /**
40
+ * Called by bin/primitive.ts when the user passes --env <name> on the command
41
+ * line. Must be called before any command code runs so subsequent calls to
42
+ * getCurrentEnvironment() see the override.
43
+ */
44
+ export declare function setCurrentEnvName(name: string | null): void;
45
+ /**
46
+ * Forces the resolver to re-read the project config on the next call.
47
+ * Used by tests and by commands that mutate the project config.
48
+ */
49
+ export declare function resetEnvResolver(): void;
50
+ /**
51
+ * Loads and caches the project config. Returns null if no
52
+ * primitive/config.json is present. Throws ProjectConfigError on a broken config.
53
+ */
54
+ export declare function getProjectConfig(): ProjectConfig | null;
55
+ /**
56
+ * Reads this machine's environment selection (`primitive env use`), or null
57
+ * when nothing is selected. Throws PrimitiveEnvError on corrupt local state —
58
+ * `env list` / `env show` surface that distinctly instead of quietly falling
59
+ * back to the committed default.
60
+ */
61
+ export declare function getLocalSelection(): string | null;
62
+ /** Absolute path of the local-state file for the current project, if any. */
63
+ export declare function getLocalStatePath(): string | null;
64
+ /**
65
+ * Resolves the current environment, or returns null if we're running in
66
+ * legacy mode (no primitive/config.json present).
67
+ *
68
+ * This never throws for a missing project config — that's legitimate
69
+ * "legacy mode" usage. It DOES throw if the project config exists but the
70
+ * requested environment doesn't.
71
+ */
72
+ export declare function getCurrentEnvironment(): ResolvedEnvironment | null;
73
+ /**
74
+ * The resolved environment, or the one refusal (#3154, intent criterion 5).
75
+ *
76
+ * `getCurrentEnvironment()` answers `null` outside a project, which used to
77
+ * mean "legacy mode — fall back to `./config` and `~/.primitive/`". There is
78
+ * no such mode any more: the environment is the ONLY thing that names the
79
+ * configuration tree, the app and the server, so a caller that needs one asks
80
+ * here and gets an error naming what is missing instead of a second answer.
81
+ *
82
+ * Everything else propagates untouched. `no-selection`, `unknown-environment`,
83
+ * `corrupt-local-state` and `stale-layout` are real answers about a real
84
+ * project, and the old `safeEnv()` swallowing them is exactly how a typo in
85
+ * `--env` used to end up writing into `./config`.
86
+ */
87
+ export declare function requireCurrentEnvironment(): ResolvedEnvironment;
88
+ /**
89
+ * Returns the current environment name for display purposes (e.g. in status
90
+ * headers). Returns null in legacy mode. Swallows resolution errors so the
91
+ * header never crashes the CLI.
92
+ */
93
+ export declare function getCurrentEnvNameSafe(): string | null;
94
+ /**
95
+ * Returns the explicit name set via setCurrentEnvName(), for commands that
96
+ * need to know whether the user passed --env vs. relying on defaults.
97
+ */
98
+ export declare function getExplicitEnvName(): string | null;
99
+ export { PrimitiveEnvError };