primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.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 (546) hide show
  1. package/README.md +258 -186
  2. package/assets/skill/skills/primitive-platform/SKILL.md +93 -27
  3. package/dist/bin/primitive.js +15 -89
  4. package/dist/bin/primitive.js.map +1 -1
  5. package/dist/src/commands/admins.js +80 -17
  6. package/dist/src/commands/admins.js.map +1 -1
  7. package/dist/src/commands/agent-sessions.d.ts +129 -0
  8. package/dist/src/commands/agent-sessions.js +532 -20
  9. package/dist/src/commands/agent-sessions.js.map +1 -1
  10. package/dist/src/commands/analytics.js +207 -155
  11. package/dist/src/commands/analytics.js.map +1 -1
  12. package/dist/src/commands/apps-children.js +3 -0
  13. package/dist/src/commands/apps-children.js.map +1 -1
  14. package/dist/src/commands/apps-transitions.d.ts +39 -0
  15. package/dist/src/commands/apps-transitions.js +198 -0
  16. package/dist/src/commands/apps-transitions.js.map +1 -0
  17. package/dist/src/commands/apps.d.ts +17 -0
  18. package/dist/src/commands/apps.js +108 -3
  19. package/dist/src/commands/apps.js.map +1 -1
  20. package/dist/src/commands/auth-sessions.js +2 -0
  21. package/dist/src/commands/auth-sessions.js.map +1 -1
  22. package/dist/src/commands/auth.js +138 -44
  23. package/dist/src/commands/auth.js.map +1 -1
  24. package/dist/src/commands/blob-buckets.js +2 -0
  25. package/dist/src/commands/blob-buckets.js.map +1 -1
  26. package/dist/src/commands/collections.js +318 -256
  27. package/dist/src/commands/collections.js.map +1 -1
  28. package/dist/src/commands/comparisons.js +2 -0
  29. package/dist/src/commands/comparisons.js.map +1 -1
  30. package/dist/src/commands/config.d.ts +2 -2
  31. package/dist/src/commands/config.js +59 -33
  32. package/dist/src/commands/config.js.map +1 -1
  33. package/dist/src/commands/connections.js +2 -0
  34. package/dist/src/commands/connections.js.map +1 -1
  35. package/dist/src/commands/database-type-configs.js +5 -3
  36. package/dist/src/commands/database-type-configs.js.map +1 -1
  37. package/dist/src/commands/databases.js +6 -4
  38. package/dist/src/commands/databases.js.map +1 -1
  39. package/dist/src/commands/db3-types.d.ts +15 -0
  40. package/dist/src/commands/db3-types.js +159 -0
  41. package/dist/src/commands/db3-types.js.map +1 -0
  42. package/dist/src/commands/db3.d.ts +24 -0
  43. package/dist/src/commands/db3.js +1444 -0
  44. package/dist/src/commands/db3.js.map +1 -0
  45. package/dist/src/commands/documents.d.ts +110 -10
  46. package/dist/src/commands/documents.js +1012 -748
  47. package/dist/src/commands/documents.js.map +1 -1
  48. package/dist/src/commands/email-templates.js +74 -0
  49. package/dist/src/commands/email-templates.js.map +1 -1
  50. package/dist/src/commands/env.js +8 -4
  51. package/dist/src/commands/env.js.map +1 -1
  52. package/dist/src/commands/function-trigger-commands.d.ts +28 -0
  53. package/dist/src/commands/function-trigger-commands.js +341 -0
  54. package/dist/src/commands/function-trigger-commands.js.map +1 -0
  55. package/dist/src/commands/functions.js +376 -30
  56. package/dist/src/commands/functions.js.map +1 -1
  57. package/dist/src/commands/groups.js +168 -50
  58. package/dist/src/commands/groups.js.map +1 -1
  59. package/dist/src/commands/guides.js +7 -5
  60. package/dist/src/commands/guides.js.map +1 -1
  61. package/dist/src/commands/hosting.d.ts +8 -0
  62. package/dist/src/commands/hosting.js +346 -0
  63. package/dist/src/commands/hosting.js.map +1 -0
  64. package/dist/src/commands/init.js +129 -38
  65. package/dist/src/commands/init.js.map +1 -1
  66. package/dist/src/commands/integrations.js +82 -53
  67. package/dist/src/commands/integrations.js.map +1 -1
  68. package/dist/src/commands/locks.d.ts +5 -3
  69. package/dist/src/commands/locks.js +19 -61
  70. package/dist/src/commands/locks.js.map +1 -1
  71. package/dist/src/commands/metadata-category-configs.d.ts +2 -2
  72. package/dist/src/commands/metadata-category-configs.js +4 -2
  73. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  74. package/dist/src/commands/metadata.js +41 -0
  75. package/dist/src/commands/metadata.js.map +1 -1
  76. package/dist/src/commands/prompts.js +75 -52
  77. package/dist/src/commands/prompts.js.map +1 -1
  78. package/dist/src/commands/rate-counters.d.ts +19 -0
  79. package/dist/src/commands/rate-counters.js +104 -0
  80. package/dist/src/commands/rate-counters.js.map +1 -0
  81. package/dist/src/commands/rule-sets.d.ts +1 -1
  82. package/dist/src/commands/rule-sets.js +2 -1
  83. package/dist/src/commands/rule-sets.js.map +1 -1
  84. package/dist/src/commands/schemas.d.ts +15 -0
  85. package/dist/src/commands/schemas.js +122 -0
  86. package/dist/src/commands/schemas.js.map +1 -0
  87. package/dist/src/commands/scripts.d.ts +9 -17
  88. package/dist/src/commands/scripts.js +24 -479
  89. package/dist/src/commands/scripts.js.map +1 -1
  90. package/dist/src/commands/secrets.js +47 -3
  91. package/dist/src/commands/secrets.js.map +1 -1
  92. package/dist/src/commands/sessions.js +2 -0
  93. package/dist/src/commands/sessions.js.map +1 -1
  94. package/dist/src/commands/skill.js +2 -0
  95. package/dist/src/commands/skill.js.map +1 -1
  96. package/dist/src/commands/sync-schemas.d.ts +202 -0
  97. package/dist/src/commands/sync-schemas.js +629 -0
  98. package/dist/src/commands/sync-schemas.js.map +1 -0
  99. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  100. package/dist/src/commands/sync-user-properties.js +276 -0
  101. package/dist/src/commands/sync-user-properties.js.map +1 -0
  102. package/dist/src/commands/sync.d.ts +518 -546
  103. package/dist/src/commands/sync.js +3010 -4877
  104. package/dist/src/commands/sync.js.map +1 -1
  105. package/dist/src/commands/tokens.js +5 -3
  106. package/dist/src/commands/tokens.js.map +1 -1
  107. package/dist/src/commands/transitions.d.ts +54 -0
  108. package/dist/src/commands/transitions.js +418 -0
  109. package/dist/src/commands/transitions.js.map +1 -0
  110. package/dist/src/commands/usage.d.ts +18 -0
  111. package/dist/src/commands/usage.js +343 -0
  112. package/dist/src/commands/usage.js.map +1 -0
  113. package/dist/src/commands/user-properties.d.ts +14 -0
  114. package/dist/src/commands/user-properties.js +79 -0
  115. package/dist/src/commands/user-properties.js.map +1 -0
  116. package/dist/src/commands/users.js +911 -18
  117. package/dist/src/commands/users.js.map +1 -1
  118. package/dist/src/commands/vars.js +2 -0
  119. package/dist/src/commands/vars.js.map +1 -1
  120. package/dist/src/commands/waitlist.js +39 -4
  121. package/dist/src/commands/waitlist.js.map +1 -1
  122. package/dist/src/commands/workflows.d.ts +5 -83
  123. package/dist/src/commands/workflows.js +57 -2282
  124. package/dist/src/commands/workflows.js.map +1 -1
  125. package/dist/src/lib/analytics-query.d.ts +58 -0
  126. package/dist/src/lib/analytics-query.js +134 -0
  127. package/dist/src/lib/analytics-query.js.map +1 -0
  128. package/dist/src/lib/api-client.d.ts +1818 -438
  129. package/dist/src/lib/api-client.js +965 -544
  130. package/dist/src/lib/api-client.js.map +1 -1
  131. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  132. package/dist/src/lib/app-settings-descriptor.js +6 -0
  133. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  134. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  135. package/dist/src/lib/auth-fixtures.js +61 -0
  136. package/dist/src/lib/auth-fixtures.js.map +1 -0
  137. package/dist/src/lib/auth-flow.d.ts +34 -1
  138. package/dist/src/lib/auth-flow.js +429 -13
  139. package/dist/src/lib/auth-flow.js.map +1 -1
  140. package/dist/src/lib/block-layout.d.ts +12 -23
  141. package/dist/src/lib/block-layout.js +26 -92
  142. package/dist/src/lib/block-layout.js.map +1 -1
  143. package/dist/src/lib/block-selector.d.ts +8 -14
  144. package/dist/src/lib/block-selector.js +8 -19
  145. package/dist/src/lib/block-selector.js.map +1 -1
  146. package/dist/src/lib/child-apps-local.d.ts +3 -1
  147. package/dist/src/lib/child-apps-local.js +9 -1
  148. package/dist/src/lib/child-apps-local.js.map +1 -1
  149. package/dist/src/lib/cli-manifest.d.ts +9 -0
  150. package/dist/src/lib/cli-manifest.js +10 -1
  151. package/dist/src/lib/cli-manifest.js.map +1 -1
  152. package/dist/src/lib/cli-version.d.ts +14 -0
  153. package/dist/src/lib/cli-version.js +38 -0
  154. package/dist/src/lib/cli-version.js.map +1 -0
  155. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  156. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  157. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  158. package/dist/src/lib/collection-export.d.ts +76 -15
  159. package/dist/src/lib/collection-export.js +116 -23
  160. package/dist/src/lib/collection-export.js.map +1 -1
  161. package/dist/src/lib/collection-principal.d.ts +22 -0
  162. package/dist/src/lib/collection-principal.js +35 -0
  163. package/dist/src/lib/collection-principal.js.map +1 -0
  164. package/dist/src/lib/command-groups.d.ts +30 -0
  165. package/dist/src/lib/command-groups.js +109 -0
  166. package/dist/src/lib/command-groups.js.map +1 -0
  167. package/dist/src/lib/command-status.d.ts +147 -0
  168. package/dist/src/lib/command-status.js +266 -0
  169. package/dist/src/lib/command-status.js.map +1 -0
  170. package/dist/src/lib/config-object-descriptor.d.ts +9 -22
  171. package/dist/src/lib/config-object-descriptor.js +107 -276
  172. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  173. package/dist/src/lib/config-surface.d.ts +3 -7
  174. package/dist/src/lib/config-surface.js +9 -13
  175. package/dist/src/lib/config-surface.js.map +1 -1
  176. package/dist/src/lib/config-toml.d.ts +11 -2
  177. package/dist/src/lib/config-toml.js +25 -2
  178. package/dist/src/lib/config-toml.js.map +1 -1
  179. package/dist/src/lib/credentials-home.d.ts +7 -0
  180. package/dist/src/lib/credentials-home.js +45 -10
  181. package/dist/src/lib/credentials-home.js.map +1 -1
  182. package/dist/src/lib/credentials-lock.d.ts +14 -6
  183. package/dist/src/lib/credentials-lock.js +90 -10
  184. package/dist/src/lib/credentials-lock.js.map +1 -1
  185. package/dist/src/lib/credentials-store.d.ts +123 -70
  186. package/dist/src/lib/credentials-store.js +358 -113
  187. package/dist/src/lib/credentials-store.js.map +1 -1
  188. package/dist/src/lib/custodian.d.ts +8 -0
  189. package/dist/src/lib/custodian.js +18 -0
  190. package/dist/src/lib/custodian.js.map +1 -0
  191. package/dist/src/lib/data-input.d.ts +1 -1
  192. package/dist/src/lib/data-input.js +1 -1
  193. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  194. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  195. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  196. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
  197. package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
  198. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  199. package/dist/src/lib/db-type-records.d.ts +106 -0
  200. package/dist/src/lib/db-type-records.js +224 -0
  201. package/dist/src/lib/db-type-records.js.map +1 -0
  202. package/dist/src/lib/db3-export.d.ts +287 -0
  203. package/dist/src/lib/db3-export.js +647 -0
  204. package/dist/src/lib/db3-export.js.map +1 -0
  205. package/dist/src/lib/db3-index-output.d.ts +116 -0
  206. package/dist/src/lib/db3-index-output.js +223 -0
  207. package/dist/src/lib/db3-index-output.js.map +1 -0
  208. package/dist/src/lib/db3-type-models.d.ts +134 -0
  209. package/dist/src/lib/db3-type-models.js +452 -0
  210. package/dist/src/lib/db3-type-models.js.map +1 -0
  211. package/dist/src/lib/deprecation.d.ts +2 -2
  212. package/dist/src/lib/deprecation.js +2 -2
  213. package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
  214. package/dist/src/lib/document-ingest-artifact.js +36 -6
  215. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  216. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  217. package/dist/src/lib/document-ingest-format2.js +78 -0
  218. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  219. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  220. package/dist/src/lib/document-ingest-input.js +28 -1
  221. package/dist/src/lib/document-ingest-input.js.map +1 -1
  222. package/dist/src/lib/document-ingest.d.ts +11 -1
  223. package/dist/src/lib/document-ingest.js +16 -0
  224. package/dist/src/lib/document-ingest.js.map +1 -1
  225. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  226. package/dist/src/lib/document-schema-rows.js +53 -0
  227. package/dist/src/lib/document-schema-rows.js.map +1 -0
  228. package/dist/src/lib/experimental-apis.d.ts +36 -0
  229. package/dist/src/lib/experimental-apis.js +46 -0
  230. package/dist/src/lib/experimental-apis.js.map +1 -0
  231. package/dist/src/lib/file-attachment.d.ts +24 -0
  232. package/dist/src/lib/file-attachment.js +31 -0
  233. package/dist/src/lib/file-attachment.js.map +1 -0
  234. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  235. package/dist/src/lib/function-authorize-check.js +311 -0
  236. package/dist/src/lib/function-authorize-check.js.map +1 -0
  237. package/dist/src/lib/function-authorize-view.d.ts +27 -0
  238. package/dist/src/lib/function-authorize-view.js +88 -0
  239. package/dist/src/lib/function-authorize-view.js.map +1 -0
  240. package/dist/src/lib/function-bundle.d.ts +27 -5
  241. package/dist/src/lib/function-bundle.js +142 -7
  242. package/dist/src/lib/function-bundle.js.map +1 -1
  243. package/dist/src/lib/function-collect.d.ts +90 -12
  244. package/dist/src/lib/function-collect.js +482 -12
  245. package/dist/src/lib/function-collect.js.map +1 -1
  246. package/dist/src/lib/function-db-types.d.ts +65 -11
  247. package/dist/src/lib/function-db-types.js +297 -157
  248. package/dist/src/lib/function-db-types.js.map +1 -1
  249. package/dist/src/lib/function-document-types.d.ts +19 -7
  250. package/dist/src/lib/function-document-types.js +24 -12
  251. package/dist/src/lib/function-document-types.js.map +1 -1
  252. package/dist/src/lib/function-lint.d.ts +57 -0
  253. package/dist/src/lib/function-lint.js +234 -0
  254. package/dist/src/lib/function-lint.js.map +1 -0
  255. package/dist/src/lib/function-log-row.js +21 -2
  256. package/dist/src/lib/function-log-row.js.map +1 -1
  257. package/dist/src/lib/function-run.d.ts +13 -21
  258. package/dist/src/lib/function-run.js +14 -27
  259. package/dist/src/lib/function-run.js.map +1 -1
  260. package/dist/src/lib/function-schema-codegen.d.ts +86 -22
  261. package/dist/src/lib/function-schema-codegen.js +194 -88
  262. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  263. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  264. package/dist/src/lib/function-schema-refs.js +177 -0
  265. package/dist/src/lib/function-schema-refs.js.map +1 -0
  266. package/dist/src/lib/function-sync.d.ts +109 -6
  267. package/dist/src/lib/function-sync.js +179 -26
  268. package/dist/src/lib/function-sync.js.map +1 -1
  269. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  270. package/dist/src/lib/function-trigger-listing.js +32 -11
  271. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  272. package/dist/src/lib/function-typecheck.d.ts +52 -0
  273. package/dist/src/lib/function-typecheck.js +174 -54
  274. package/dist/src/lib/function-typecheck.js.map +1 -1
  275. package/dist/src/lib/function-versions.d.ts +2 -0
  276. package/dist/src/lib/function-versions.js +1 -0
  277. package/dist/src/lib/function-versions.js.map +1 -1
  278. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  279. package/dist/src/lib/generated-build-flags.js +14 -0
  280. package/dist/src/lib/generated-build-flags.js.map +1 -0
  281. package/dist/src/lib/generated-command-status.d.ts +6 -0
  282. package/dist/src/lib/generated-command-status.js +469 -0
  283. package/dist/src/lib/generated-command-status.js.map +1 -0
  284. package/dist/src/lib/generated-config-surfaces.d.ts +538 -141
  285. package/dist/src/lib/generated-config-surfaces.js +1772 -1854
  286. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  287. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  288. package/dist/src/lib/generated-sdk-types.js +1 -1
  289. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  290. package/dist/src/lib/hosting-build.d.ts +97 -0
  291. package/dist/src/lib/hosting-build.js +204 -0
  292. package/dist/src/lib/hosting-build.js.map +1 -0
  293. package/dist/src/lib/hosting-client.d.ts +167 -0
  294. package/dist/src/lib/hosting-client.js +340 -0
  295. package/dist/src/lib/hosting-client.js.map +1 -0
  296. package/dist/src/lib/hosting-environments.d.ts +32 -0
  297. package/dist/src/lib/hosting-environments.js +74 -0
  298. package/dist/src/lib/hosting-environments.js.map +1 -0
  299. package/dist/src/lib/hosting-errors.d.ts +30 -0
  300. package/dist/src/lib/hosting-errors.js +43 -0
  301. package/dist/src/lib/hosting-errors.js.map +1 -0
  302. package/dist/src/lib/hosting-token.d.ts +46 -0
  303. package/dist/src/lib/hosting-token.js +60 -0
  304. package/dist/src/lib/hosting-token.js.map +1 -0
  305. package/dist/src/lib/hosting-wait.d.ts +42 -0
  306. package/dist/src/lib/hosting-wait.js +84 -0
  307. package/dist/src/lib/hosting-wait.js.map +1 -0
  308. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  309. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  310. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  311. package/dist/src/lib/init-assets.d.ts +2 -6
  312. package/dist/src/lib/init-assets.js +11 -27
  313. package/dist/src/lib/init-assets.js.map +1 -1
  314. package/dist/src/lib/init-ios-links.d.ts +11 -7
  315. package/dist/src/lib/init-ios-links.js +28 -22
  316. package/dist/src/lib/init-ios-links.js.map +1 -1
  317. package/dist/src/lib/init-login-note.d.ts +13 -0
  318. package/dist/src/lib/init-login-note.js +22 -0
  319. package/dist/src/lib/init-login-note.js.map +1 -0
  320. package/dist/src/lib/init-schema.d.ts +15 -0
  321. package/dist/src/lib/init-schema.js +54 -0
  322. package/dist/src/lib/init-schema.js.map +1 -1
  323. package/dist/src/lib/integration-test-request.d.ts +54 -0
  324. package/dist/src/lib/integration-test-request.js +207 -0
  325. package/dist/src/lib/integration-test-request.js.map +1 -0
  326. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  327. package/dist/src/lib/invoker-shared-enums.js +98 -0
  328. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  329. package/dist/src/lib/json-value.d.ts +6 -0
  330. package/dist/src/lib/json-value.js +13 -0
  331. package/dist/src/lib/json-value.js.map +1 -0
  332. package/dist/src/lib/load-routes.d.ts +33 -0
  333. package/dist/src/lib/load-routes.js +35 -0
  334. package/dist/src/lib/load-routes.js.map +1 -0
  335. package/dist/src/lib/log-inspection.d.ts +23 -4
  336. package/dist/src/lib/log-inspection.js +14 -5
  337. package/dist/src/lib/log-inspection.js.map +1 -1
  338. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  339. package/dist/src/lib/login-exchange-check.js +27 -0
  340. package/dist/src/lib/login-exchange-check.js.map +1 -0
  341. package/dist/src/lib/login-scope-lines.d.ts +17 -7
  342. package/dist/src/lib/login-scope-lines.js +33 -10
  343. package/dist/src/lib/login-scope-lines.js.map +1 -1
  344. package/dist/src/lib/metadata-report.d.ts +85 -0
  345. package/dist/src/lib/metadata-report.js +81 -0
  346. package/dist/src/lib/metadata-report.js.map +1 -0
  347. package/dist/src/lib/object-status-filter.d.ts +9 -1
  348. package/dist/src/lib/object-status-filter.js +9 -1
  349. package/dist/src/lib/object-status-filter.js.map +1 -1
  350. package/dist/src/lib/output.d.ts +1 -1
  351. package/dist/src/lib/output.js +3 -1
  352. package/dist/src/lib/output.js.map +1 -1
  353. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  354. package/dist/src/lib/pin-refusal-hint.js +35 -0
  355. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  356. package/dist/src/lib/platform-owned.js +5 -0
  357. package/dist/src/lib/platform-owned.js.map +1 -1
  358. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  359. package/dist/src/lib/primitive-declaration-names.js +22 -0
  360. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  361. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  362. package/dist/src/lib/primitive-declaration.js +792 -0
  363. package/dist/src/lib/primitive-declaration.js.map +1 -0
  364. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  365. package/dist/src/lib/primitive-env-plugin.js +408 -0
  366. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  367. package/dist/src/lib/project-login-apps.d.ts +8 -0
  368. package/dist/src/lib/project-login-apps.js +27 -0
  369. package/dist/src/lib/project-login-apps.js.map +1 -0
  370. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  371. package/dist/src/lib/prompt-schema-codegen.js +96 -100
  372. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  373. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  374. package/dist/src/lib/prompt-schema-document.js +92 -0
  375. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  376. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  377. package/dist/src/lib/prompt-schema-refs.js +478 -0
  378. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  379. package/dist/src/lib/records-verbs.d.ts +79 -0
  380. package/dist/src/lib/records-verbs.js +45 -0
  381. package/dist/src/lib/records-verbs.js.map +1 -0
  382. package/dist/src/lib/register-commands.d.ts +36 -0
  383. package/dist/src/lib/register-commands.js +37 -0
  384. package/dist/src/lib/register-commands.js.map +1 -0
  385. package/dist/src/lib/retired-imports.d.ts +53 -0
  386. package/dist/src/lib/retired-imports.js +120 -0
  387. package/dist/src/lib/retired-imports.js.map +1 -0
  388. package/dist/src/lib/run-status.d.ts +1 -1
  389. package/dist/src/lib/run-status.generated.d.ts +2 -2
  390. package/dist/src/lib/run-status.generated.js +3 -1
  391. package/dist/src/lib/run-status.generated.js.map +1 -1
  392. package/dist/src/lib/run-status.js +1 -1
  393. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  394. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  395. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  396. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  397. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  398. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  399. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  400. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  401. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  402. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  403. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  404. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  405. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  406. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  407. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  408. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  409. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  410. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  411. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
  412. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
  413. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  414. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  415. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  416. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  417. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  418. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  419. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  420. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  421. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  422. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  423. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  424. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  425. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  426. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  427. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  428. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  429. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  430. package/dist/src/lib/schema-codegen/naming.js +83 -0
  431. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  432. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  433. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  434. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  435. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  436. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  437. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  438. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  439. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  440. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  441. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
  442. package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
  443. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  444. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  445. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  446. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  447. package/dist/src/lib/schema-family-index.d.ts +228 -0
  448. package/dist/src/lib/schema-family-index.js +813 -0
  449. package/dist/src/lib/schema-family-index.js.map +1 -0
  450. package/dist/src/lib/schema-pins.d.ts +82 -0
  451. package/dist/src/lib/schema-pins.js +198 -0
  452. package/dist/src/lib/schema-pins.js.map +1 -0
  453. package/dist/src/lib/schema-preview.d.ts +244 -0
  454. package/dist/src/lib/schema-preview.js +498 -0
  455. package/dist/src/lib/schema-preview.js.map +1 -0
  456. package/dist/src/lib/scope-request.d.ts +23 -11
  457. package/dist/src/lib/scope-request.js +69 -31
  458. package/dist/src/lib/scope-request.js.map +1 -1
  459. package/dist/src/lib/session-scope.d.ts +26 -0
  460. package/dist/src/lib/session-scope.js +58 -0
  461. package/dist/src/lib/session-scope.js.map +1 -0
  462. package/dist/src/lib/skill-installer.d.ts +2 -2
  463. package/dist/src/lib/skill-installer.js +2 -21
  464. package/dist/src/lib/skill-installer.js.map +1 -1
  465. package/dist/src/lib/step-run-table.d.ts +1 -2
  466. package/dist/src/lib/step-run-table.js +1 -2
  467. package/dist/src/lib/step-run-table.js.map +1 -1
  468. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  469. package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
  470. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  471. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  472. package/dist/src/lib/swift-codegen/banners.js +12 -0
  473. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  474. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  475. package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
  476. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  477. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
  478. package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
  479. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  480. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  481. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  482. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  483. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  484. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  485. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  486. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  487. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  488. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  489. package/dist/src/lib/sync-resource-types.d.ts +117 -31
  490. package/dist/src/lib/sync-resource-types.js +197 -189
  491. package/dist/src/lib/sync-resource-types.js.map +1 -1
  492. package/dist/src/lib/sync-selectors.d.ts +7 -0
  493. package/dist/src/lib/sync-selectors.js +22 -2
  494. package/dist/src/lib/sync-selectors.js.map +1 -1
  495. package/dist/src/lib/template.d.ts +39 -3
  496. package/dist/src/lib/template.js +103 -14
  497. package/dist/src/lib/template.js.map +1 -1
  498. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  499. package/dist/src/lib/test-case-file-names.js +3 -5
  500. package/dist/src/lib/test-case-file-names.js.map +1 -1
  501. package/dist/src/lib/test-runs.d.ts +45 -0
  502. package/dist/src/lib/test-runs.js +150 -0
  503. package/dist/src/lib/test-runs.js.map +1 -0
  504. package/dist/src/lib/test-users.d.ts +25 -0
  505. package/dist/src/lib/test-users.js +36 -0
  506. package/dist/src/lib/test-users.js.map +1 -0
  507. package/dist/src/lib/toml-database-config.d.ts +4 -2
  508. package/dist/src/lib/toml-database-config.js +11 -6
  509. package/dist/src/lib/toml-database-config.js.map +1 -1
  510. package/dist/src/lib/toml-scalar-edit.js +6 -4
  511. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  512. package/dist/src/lib/transition-warnings.d.ts +21 -0
  513. package/dist/src/lib/transition-warnings.js +49 -0
  514. package/dist/src/lib/transition-warnings.js.map +1 -0
  515. package/dist/src/lib/user-index.d.ts +80 -0
  516. package/dist/src/lib/user-index.js +166 -0
  517. package/dist/src/lib/user-index.js.map +1 -0
  518. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  519. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  520. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  521. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  522. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  523. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  524. package/dist/src/lib/user-walk.d.ts +31 -0
  525. package/dist/src/lib/user-walk.js +102 -0
  526. package/dist/src/lib/user-walk.js.map +1 -0
  527. package/dist/src/lib/webhook-capture.d.ts +43 -0
  528. package/dist/src/lib/webhook-capture.js +91 -0
  529. package/dist/src/lib/webhook-capture.js.map +1 -0
  530. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  531. package/dist/src/lib/webhook-deliver.js +34 -89
  532. package/dist/src/lib/webhook-deliver.js.map +1 -1
  533. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  534. package/dist/src/lib/webhook-test-run.js +108 -0
  535. package/dist/src/lib/webhook-test-run.js.map +1 -0
  536. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  537. package/dist/src/lib/worker-perf-format.js +27 -0
  538. package/dist/src/lib/worker-perf-format.js.map +1 -0
  539. package/dist/src/types/index.d.ts +20 -65
  540. package/dist/src/validators.d.ts +7 -55
  541. package/dist/src/validators.js +7 -53
  542. package/dist/src/validators.js.map +1 -1
  543. package/dist/src/vite.d.ts +17 -0
  544. package/dist/src/vite.js +18 -0
  545. package/dist/src/vite.js.map +1 -0
  546. package/package.json +20 -9
@@ -7,11 +7,13 @@
7
7
  *
8
8
  * Mode A (project mode): credentials live at
9
9
  * <projectRoot>/.primitive/credentials.json
10
- * with per-environment slots:
10
+ * with one login per server (#4512), keyed by normalized server URL:
11
11
  * {
12
- * "environments": {
13
- * "dev": { "accessToken": "...", "refreshToken": "...", ... },
14
- * "prod": { ... }
12
+ * "servers": {
13
+ * "https://api.example.com": {
14
+ * "login": { "accessToken": "...", "refreshToken": "...", ... },
15
+ * "leftovers": { "staging": { ... } }
16
+ * }
15
17
  * }
16
18
  * }
17
19
  *
@@ -33,24 +35,34 @@
33
35
  * project either. The last two are the divergence from the intent's "login and
34
36
  * init and nothing else", adjudicated on #3154 as finding F1.
35
37
  *
38
+ * A fifth, `apps delete`, says it pinned to a server (#4905,
39
+ * `allowGlobalCredentialsForServer()`): the server `PRIMITIVE_SERVER_URL`
40
+ * names, or production when it is unset, as `login` resolves it. The global
41
+ * login is used only when that server issued it, so the command still never
42
+ * acts against whatever server the last `login` targeted.
43
+ *
36
44
  * The opt-in is per ACTION, not per argv: `primitive --env prod login` and
37
45
  * `primitive login` reach the same line, so there is no flag shape for a
38
46
  * pre-parse to miss. And it only PERMITS the global file — inside a project
39
- * all four still use the per-environment slots.
47
+ * all five still use the project's file.
48
+ *
49
+ * Every environment on a server — committed or machine-local — reads and
50
+ * writes that server's one login, so one login and one logout cover them all
51
+ * (#4512). A server's `leftovers` are logins an older CLI stored per
52
+ * environment: never read, revoked by `logout`.
40
53
  *
41
- * A child environment (#4511) — a machine-local environment on the server of
42
- * the committed environment whose tree it shares — has no slot of its own: it
43
- * reads and writes its parent's, so one login and one logout cover the parent
44
- * and all of its children.
54
+ * Before #4512 a login lived in a per-environment slot under `environments`,
55
+ * a child environment (#4511) using its parent's. Such a slot is read only
56
+ * while the file has no entry for its server. The first write for a server
57
+ * creates the entry and moves the server's legacy slots out: a mere copy of
58
+ * the login being written is dropped, any other becomes a leftover. From then
59
+ * on a cleared login stays cleared; no legacy slot is read for that server.
45
60
  *
46
- * A slot records the server that issued it (#4492). A slot is keyed by
47
- * environment name while the environment's `apiUrl` is committed, so a branch
48
- * switch can point `dev` at another server than the one its stored tokens
49
- * came from. A slot recording another server than the invoking environment's
50
- * is never used (its tokens are not sent), and credentials from another server
51
- * than the slot's environment's are never stored. A slot written before this
52
- * records no server; it is read against the environment's `apiUrl`, and its
53
- * next write records one.
61
+ * A login records the server that issued it (#4492), and credentials from
62
+ * another server than the environment's are never stored. A legacy slot
63
+ * recording another server than the invoking environment's is never used (its
64
+ * tokens are not sent); a legacy slot that records no server is read against
65
+ * the environment's `apiUrl`.
54
66
  *
55
67
  * In a linked git worktree the project's file is the main worktree's
56
68
  * (#4492, `credentials-home.ts`), so one login serves every worktree of the
@@ -63,8 +75,9 @@ import { homedir } from "os";
63
75
  import { dirname, join } from "path";
64
76
  import { getCurrentEnvironment, getProjectConfig, } from "./env-resolver.js";
65
77
  import { missingConfigMessage, PROJECT_CONFIG_FILENAME, PROJECT_TREE_DIR, PrimitiveEnvError, readLocalState, } from "./env-resolver-core.js";
66
- import { DEFAULT_SERVER_URL } from "./constants.js";
67
- import { credentialsRootFor, ignoredLocalCredentialsFile, oldGitHint, sharedWorktreeCount, } from "./credentials-home.js";
78
+ import { DEFAULT_SERVER_URL, PRODUCTION_SERVER_URL } from "./constants.js";
79
+ import { normalizeServerUrl } from "./channel.js";
80
+ import { credentialsRootFor, ignoredLocalCredentialsFile, oldGitHint, otherSharingProjectRoots, sharedWorktreeCount, } from "./credentials-home.js";
68
81
  import { acquireCredentialsLock, fileVersion, replaceFileUnderLock } from "./credentials-lock.js";
69
82
  import { sessionIdOfToken } from "./session-id.js";
70
83
  export const PROJECT_LOCAL_DIR = ".primitive";
@@ -123,11 +136,17 @@ export function credentialsFileForProject(projectRoot) {
123
136
  return join(credentialsRootFor(projectRoot), PROJECT_LOCAL_DIR, PROJECT_CREDENTIALS_FILENAME);
124
137
  }
125
138
  /**
126
- * Set by the four actions that may read or write the global credentials file
139
+ * Set by the actions that may read or write the global credentials file
127
140
  * with no project in scope. Process-wide, because one invocation runs one
128
141
  * command; never reset, because a command does not stop being `login`.
129
142
  */
130
143
  let globalCredentialsAllowed = false;
144
+ /**
145
+ * The server a pinned allowance names (#4905): the global login is used only
146
+ * when this server issued it, and only its credentials are written. Null for
147
+ * the unpinned allowance of the login family.
148
+ */
149
+ let globalCredentialsServer = null;
131
150
  /**
132
151
  * Declare that THIS command may fall back to `~/.primitive/credentials.json`
133
152
  * when no project is in scope. Called at the top of `login`, `logout`, `init`
@@ -136,6 +155,17 @@ let globalCredentialsAllowed = false;
136
155
  export function allowGlobalCredentials() {
137
156
  globalCredentialsAllowed = true;
138
157
  }
158
+ /**
159
+ * Declare that THIS command may use the global credentials file when no
160
+ * project is in scope, but only for `serverUrl`: a stored login another server
161
+ * issued is refused with `server-mismatch` before any of its tokens is sent,
162
+ * credentials from another server are never written, and `PRIMITIVE_TOKEN` is
163
+ * sent to `serverUrl`. Called by `apps delete` (#4905), and nowhere else.
164
+ */
165
+ export function allowGlobalCredentialsForServer(serverUrl) {
166
+ globalCredentialsAllowed = true;
167
+ globalCredentialsServer = trimSlash(serverUrl);
168
+ }
139
169
  /**
140
170
  * Drop the declaration again. One invocation runs one command, so nothing in
141
171
  * the CLI calls this — it exists so a test file can exercise both sides of the
@@ -143,6 +173,25 @@ export function allowGlobalCredentials() {
143
173
  */
144
174
  export function resetGlobalCredentialsAllowance() {
145
175
  globalCredentialsAllowed = false;
176
+ globalCredentialsServer = null;
177
+ }
178
+ /**
179
+ * The login command for the global login of `serverUrl`, up to its `--app`
180
+ * value: prefixed with `PRIMITIVE_SERVER_URL=<server>` unless the server is
181
+ * production, which `login` targets when the variable is unset.
182
+ */
183
+ export function globalLoginCommand(serverUrl) {
184
+ const prefix = sameServer(serverUrl, PRODUCTION_SERVER_URL) ? "" : `PRIMITIVE_SERVER_URL=${serverUrl} `;
185
+ return `${prefix}primitive login --app`;
186
+ }
187
+ /** The refusal of a global login another server than the pinned one issued. */
188
+ function globalReadMismatch(stored, pinned) {
189
+ const issuer = stored ?? "a server it does not record";
190
+ const target = stored ? ` To target ${stored}, set PRIMITIVE_SERVER_URL=${stored}.` : "";
191
+ return new PrimitiveEnvError("server-mismatch", `The login in ${getLegacyCredentialsFile()} was issued by ${issuer}, but this command targets ` +
192
+ `${pinned} (PRIMITIVE_SERVER_URL, or production when it is unset); its tokens were not sent.` +
193
+ `${target} To sign in to ${pinned}, run '${globalLoginCommand(pinned)} <app-id>' (or --app all); ` +
194
+ `it replaces the stored login.`);
146
195
  }
147
196
  /**
148
197
  * Resolves the current environment. If an environment CAN'T be resolved
@@ -210,15 +259,24 @@ function legacyCredentialsRecord(credentials) {
210
259
  function loadProjectCredentialsFile(projectRoot) {
211
260
  const path = credentialsFileForProject(projectRoot);
212
261
  const data = readJsonFile(path);
213
- if (!data || typeof data !== "object" || !data.environments) {
214
- return { environments: {} };
215
- }
262
+ const isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
263
+ if (!isRecord(data))
264
+ return { environments: {}, servers: {} };
265
+ const file = {
266
+ environments: isRecord(data.environments) ? data.environments : {},
267
+ servers: isRecord(data.servers) ? data.servers : {},
268
+ };
216
269
  // EVERY slot, not just the one about to be written: each write reserializes
217
270
  // the whole file, so a stale key anywhere would survive forever.
218
- for (const slot of Object.values(data.environments)) {
271
+ for (const slot of Object.values(file.environments)) {
219
272
  stripRetiredCurrentApp(slot);
220
273
  }
221
- return data;
274
+ for (const entry of Object.values(file.servers)) {
275
+ stripRetiredCurrentApp(entry?.login);
276
+ for (const slot of Object.values(entry?.leftovers ?? {}))
277
+ stripRetiredCurrentApp(slot);
278
+ }
279
+ return file;
222
280
  }
223
281
  /**
224
282
  * The one way a project's credentials file is written: take the lock, read
@@ -390,6 +448,80 @@ function dropCopiedChildSlots(projectRoot, file, slot, children) {
390
448
  // The copies are ignored either way; the next read tries again.
391
449
  }
392
450
  }
451
+ /**
452
+ * The key of `apiUrl`'s login in `servers` (#4512): scheme, host and port,
453
+ * and the path without trailing slashes. A URL that does not parse keys as
454
+ * its trailing-slash-trimmed string.
455
+ */
456
+ function serverKey(apiUrl) {
457
+ return normalizeServerUrl(apiUrl) ?? trimSlash(apiUrl);
458
+ }
459
+ /**
460
+ * The server of every environment of the project whose config is at
461
+ * `configPath`, committed and machine-local, by name in config order. Null
462
+ * when the config cannot be read, so a caller never takes "no environment"
463
+ * for an answer it did not get.
464
+ */
465
+ function environmentServers(configPath) {
466
+ const config = readJsonFile(configPath);
467
+ if (!config?.environments || typeof config.environments !== "object")
468
+ return null;
469
+ const servers = {};
470
+ for (const [name, entry] of Object.entries(config.environments)) {
471
+ if (typeof entry?.apiUrl === "string")
472
+ servers[name] = entry.apiUrl;
473
+ }
474
+ try {
475
+ for (const [name, entry] of Object.entries(readLocalState(configPath).environments)) {
476
+ if (!(name in servers))
477
+ servers[name] = entry.apiUrl;
478
+ }
479
+ }
480
+ catch {
481
+ // An unreadable local state names no machine-local environment.
482
+ }
483
+ return servers;
484
+ }
485
+ /** The project config of a project root, where `init` and `env remove` find it. */
486
+ function configPathOf(projectRoot) {
487
+ return join(projectRoot, PROJECT_TREE_DIR, PROJECT_CONFIG_FILENAME);
488
+ }
489
+ /**
490
+ * The legacy slots of `file` that belong to `server`: one recording that
491
+ * server, and one named after an environment on it, whatever it records. The
492
+ * latter is the slot that environment read; one recording another server was
493
+ * never used there, and keeps its server so `logout` revokes it where it was
494
+ * issued.
495
+ */
496
+ function legacySlotsOn(file, server, servers) {
497
+ const on = (apiUrl) => apiUrl !== undefined && serverKey(apiUrl) === server;
498
+ return Object.entries(file.environments)
499
+ .filter(([name, slot]) => on(slot.serverUrl) || on(servers?.[name]))
500
+ .map(([name]) => name);
501
+ }
502
+ /**
503
+ * Create `servers[server]` for the login about to be written, moving the
504
+ * server's legacy slots out of `environments`. A slot holding `login`'s
505
+ * session that nothing a logout needs is dropped (an identical or older
506
+ * refresh token, no live step-up of its own, #4511's rules); any other slot
507
+ * becomes a leftover. No-op once the server has an entry.
508
+ */
509
+ function migrateServer(file, server, login, servers) {
510
+ const existing = file.servers[server];
511
+ if (existing)
512
+ return existing;
513
+ const leftovers = {};
514
+ for (const name of legacySlotsOn(file, server, servers)) {
515
+ const slot = file.environments[name];
516
+ const copy = sameSession(slot, login) && !outlivesRefresh(slot, login) && !ownStepUp(slot, login);
517
+ if (!copy)
518
+ leftovers[name] = slot;
519
+ delete file.environments[name];
520
+ }
521
+ const entry = Object.keys(leftovers).length > 0 ? { leftovers } : {};
522
+ file.servers[server] = entry;
523
+ return entry;
524
+ }
393
525
  /** The variable a CI job puts its admin token in (#3890). */
394
526
  export const PRIMITIVE_TOKEN_VAR = "PRIMITIVE_TOKEN";
395
527
  /**
@@ -397,6 +529,14 @@ export const PRIMITIVE_TOKEN_VAR = "PRIMITIVE_TOKEN";
397
529
  * names one. Deployed servers ignore the header for admin identity.
398
530
  */
399
531
  const PARTITION_VAR = "PRIMITIVE_GLOBAL_ADMIN_APP_ID";
532
+ /**
533
+ * The partition a login exchanges in when it builds on no stored login: the
534
+ * one `PRIMITIVE_GLOBAL_ADMIN_APP_ID` names, which only the live test harness
535
+ * sets. Deployed servers ignore the header for admin identity.
536
+ */
537
+ export function partitionFromEnvironment() {
538
+ return process.env[PARTITION_VAR]?.trim() || undefined;
539
+ }
400
540
  /** The token in `PRIMITIVE_TOKEN`, or null when it is unset or blank. */
401
541
  export function environmentToken() {
402
542
  const value = process.env[PRIMITIVE_TOKEN_VAR]?.trim();
@@ -436,24 +576,38 @@ function assertStorable(credentials) {
436
576
  * legacy global file. Returns the standard Credentials shape so existing
437
577
  * callers don't need to change.
438
578
  *
439
- * In project mode, we blend the per-env stored creds with the serverUrl
440
- * and appId from primitive/config.json to produce the Credentials the rest of
441
- * the CLI expects. A child environment reads its parent's slot (#4511), and
442
- * any child slot found to be a copy of that login is removed.
579
+ * In project mode, we blend the server's stored login with the serverUrl
580
+ * from primitive/config.json to produce the Credentials the rest of the CLI
581
+ * expects (#4512). Before the server's first write a legacy slot is read
582
+ * instead: the environment's own, or its parent's for a child environment
583
+ * (#4511), and any child slot found to be a copy of that login is removed.
443
584
  *
444
585
  * `PRIMITIVE_TOKEN` (#3890), when set, takes precedence over any stored
445
586
  * login and no file is read. It does not loosen the outside-a-project
446
587
  * refusal: the environment is resolved first, exactly as for a stored login.
588
+ *
589
+ * Outside a project under a server pin (#4905), the global login is returned
590
+ * only when the pinned server issued it, and `PRIMITIVE_TOKEN` is for the
591
+ * pinned server.
447
592
  */
448
593
  export function loadCredentialsStore() {
449
594
  const env = resolveCurrentEnvironment();
450
- const fromEnvironment = environmentCredentials(env ? env.config.apiUrl : DEFAULT_SERVER_URL.replace(/\/$/, ""));
595
+ const fromEnvironment = environmentCredentials(env ? env.config.apiUrl : globalCredentialsServer ?? DEFAULT_SERVER_URL.replace(/\/$/, ""));
451
596
  if (fromEnvironment)
452
597
  return fromEnvironment;
453
598
  if (!env) {
454
- return loadLegacyCredentials();
599
+ const stored = loadLegacyCredentials();
600
+ if (stored &&
601
+ globalCredentialsServer !== null &&
602
+ (!stored.serverUrl || !sameServer(stored.serverUrl, globalCredentialsServer))) {
603
+ throw globalReadMismatch(stored.serverUrl, globalCredentialsServer);
604
+ }
605
+ return stored;
455
606
  }
456
607
  const file = loadProjectCredentialsFile(env.projectRoot);
608
+ const entry = file.servers[serverKey(env.config.apiUrl)];
609
+ if (entry)
610
+ return entry.login ? storedCredentials(env.config.apiUrl, entry.login) : null;
457
611
  const { slot, children } = loginSlotOf(env);
458
612
  const stored = file.environments[slot];
459
613
  if (!stored)
@@ -467,16 +621,20 @@ export function loadCredentialsStore() {
467
621
  return storedCredentials(env.config.apiUrl, stored);
468
622
  }
469
623
  /**
470
- * The current environment's stored login when its slot records another server
471
- * than the environment's, blended with the server it RECORDS; null otherwise.
472
- * For `logout` alone, which revokes such a login at the server that issued it
473
- * and so never sends its tokens anywhere else.
624
+ * The current environment's legacy login when its slot records another server
625
+ * than the environment's, blended with the server it RECORDS; null otherwise,
626
+ * and always once the environment's server has a login entry (#4512). For
627
+ * `logout` alone, which revokes such a login at the server that issued it and
628
+ * so never sends its tokens anywhere else.
474
629
  */
475
630
  export function mismatchedLogin() {
476
631
  const env = resolveCurrentEnvironment();
477
632
  if (!env || environmentToken())
478
633
  return null;
479
- const stored = loadProjectCredentialsFile(env.projectRoot).environments[loginSlotOf(env).slot];
634
+ const file = loadProjectCredentialsFile(env.projectRoot);
635
+ if (file.servers[serverKey(env.config.apiUrl)])
636
+ return null;
637
+ const stored = file.environments[loginSlotOf(env).slot];
480
638
  if (!stored || !recordsOtherServer(stored, env.config.apiUrl))
481
639
  return null;
482
640
  return storedCredentials(stored.serverUrl, stored);
@@ -496,16 +654,22 @@ function storedCredentials(serverUrl, stored) {
496
654
  };
497
655
  }
498
656
  /**
499
- * The environments that share the current environment's login (#4511): the
500
- * one whose slot holds it, and its child environments on this machine. Null
501
- * outside a project, where there is one global login.
657
+ * The environments that share the current environment's login (#4512): every
658
+ * environment of the project on its server, committed and machine-local, in
659
+ * config order; and the committed environment whose tree the current one
660
+ * uses, which names the login. Null outside a project, where there is one
661
+ * global login.
502
662
  */
503
663
  export function loginEnvironments() {
504
664
  const env = resolveCurrentEnvironment();
505
665
  if (!env)
506
666
  return null;
507
- const { slot, children } = loginSlotOf(env);
508
- return { parent: slot, children };
667
+ const server = serverKey(env.config.apiUrl);
668
+ const servers = environmentServers(env.projectConfigPath) ?? {};
669
+ const environments = Object.entries(servers)
670
+ .filter(([, apiUrl]) => serverKey(apiUrl) === server)
671
+ .map(([name]) => name);
672
+ return { tree: env.tree, environments: environments.length > 0 ? environments : [env.name] };
509
673
  }
510
674
  /** The current project's root, or null outside a project or when it cannot be resolved. */
511
675
  function currentProjectRoot() {
@@ -551,37 +715,49 @@ export const worktreeLoginNotes = {
551
715
  },
552
716
  };
553
717
  /**
554
- * The logins still held in the slots of the current login's child
555
- * environments: sessions signed in to a child before children used their
556
- * parent's login, and copies of the parent's that kept a step-up or a refresh
557
- * token of their own. No command reads them; `logout` revokes them before
558
- * {@link clearLeftoverChildLogins} removes them. Empty outside a project.
718
+ * The logins on the current environment's server that no command reads: the
719
+ * server's leftovers (#4512), or before its first write the legacy slots on
720
+ * it other than the one the environment reads — sessions signed in to another
721
+ * environment, and copies that kept a step-up or a refresh token of their own
722
+ * (#4511). `logout` revokes them before {@link clearLeftoverLogins} removes
723
+ * them. Empty outside a project.
559
724
  */
560
- export function leftoverChildLogins() {
725
+ export function leftoverLogins() {
561
726
  const env = resolveCurrentEnvironment();
562
727
  if (!env)
563
728
  return [];
564
729
  const file = loadProjectCredentialsFile(env.projectRoot);
565
- return loginSlotOf(env)
566
- .children.filter((name) => file.environments[name] !== undefined)
567
- .map((name) => {
568
- const stored = file.environments[name];
569
- return storedCredentials(stored.serverUrl ?? env.config.apiUrl, stored);
570
- });
571
- }
572
- /**
573
- * Saves credentials. In project mode, writes to the per-env slot in the
574
- * project credentials file. In legacy mode, writes the global file.
730
+ const server = serverKey(env.config.apiUrl);
731
+ const entry = file.servers[server];
732
+ const stored = entry
733
+ ? Object.values(entry.leftovers ?? {})
734
+ : legacyLeftovers(file, env).map((name) => file.environments[name]);
735
+ return stored.map((slot) => storedCredentials(slot.serverUrl ?? env.config.apiUrl, slot));
736
+ }
737
+ /** The legacy slots on `env`'s server other than the one it reads. */
738
+ function legacyLeftovers(file, env) {
739
+ const own = loginSlotOf(env).slot;
740
+ return legacySlotsOn(file, serverKey(env.config.apiUrl), environmentServers(env.projectConfigPath)).filter((name) => name !== own);
741
+ }
742
+ /**
743
+ * Saves credentials. In project mode, writes the login of the environment's
744
+ * server (#4512), migrating the server's legacy slots at its first write. In
745
+ * legacy mode, writes the global file.
575
746
  *
576
- * In project mode the slot records the incoming `serverUrl`, which must be
577
- * the same server as the slot's environment's `apiUrl`: credentials from
578
- * another server are refused with `server-mismatch` and nothing is written
579
- * (#4492). In a child environment the parent's slot is written (#4511).
747
+ * In project mode the login records the incoming `serverUrl`, which must be
748
+ * the same server as the environment's `apiUrl`: credentials from another
749
+ * server are refused with `server-mismatch` and nothing is written (#4492).
750
+ * In legacy mode under a server pin (#4905), so are credentials from another
751
+ * server than the pinned one.
580
752
  */
581
753
  export function saveCredentialsStore(credentials) {
582
754
  assertStorable(credentials);
583
755
  const env = resolveCurrentEnvironment();
584
756
  if (!env) {
757
+ if (globalCredentialsServer !== null && !sameServer(credentials.serverUrl, globalCredentialsServer)) {
758
+ throw new PrimitiveEnvError("server-mismatch", `These credentials were issued by ${credentials.serverUrl}, but this command targets ` +
759
+ `${globalCredentialsServer}; nothing was stored.`);
760
+ }
585
761
  ensureDir(getLegacyConfigDir());
586
762
  writeFileSync(getLegacyCredentialsFile(), JSON.stringify(legacyCredentialsRecord(credentials), null, 2), { mode: 0o600 });
587
763
  try {
@@ -592,23 +768,29 @@ export function saveCredentialsStore(credentials) {
592
768
  }
593
769
  return;
594
770
  }
595
- const { slot, serverUrl } = loginSlotOf(env);
596
- if (!sameServer(credentials.serverUrl, serverUrl)) {
597
- throw writeMismatch(env.name, credentials.serverUrl, serverUrl);
771
+ if (!sameServer(credentials.serverUrl, env.config.apiUrl)) {
772
+ throw writeMismatch(env.name, credentials.serverUrl, env.config.apiUrl);
598
773
  }
599
- updateProjectCredentialsFile(env.projectRoot, (file) => {
600
- file.environments[slot] = storedRecord(credentials);
774
+ writeServerLogin(env.projectRoot, environmentServers(env.projectConfigPath), credentials);
775
+ }
776
+ /** Write `credentials` as their server's login in the project at `projectRoot`. */
777
+ function writeServerLogin(projectRoot, servers, credentials) {
778
+ const record = storedRecord(credentials);
779
+ const server = serverKey(credentials.serverUrl);
780
+ updateProjectCredentialsFile(projectRoot, (file) => {
781
+ migrateServer(file, server, record, servers).login = record;
601
782
  return true;
602
783
  });
603
784
  }
604
785
  /**
605
786
  * Clears credentials for the current environment (project mode) or
606
- * deletes the legacy file (legacy mode). In project mode that is the slot
607
- * holding the environment's login, whichever environment of the tree is
608
- * current, and the child slots holding only that login's session (#4511),
609
- * which its caller has just revoked. A child slot holding another session or
610
- * a step-up of its own stays for `logout` to revoke
611
- * ({@link clearLeftoverChildLogins}).
787
+ * deletes the legacy file (legacy mode). In project mode that is the login of
788
+ * the environment's server; its entry and leftovers stay, so a legacy slot is
789
+ * never read for the server again (#4512). Before the server's first write it
790
+ * is the legacy slot the environment reads, and the child slots holding only
791
+ * that login's session (#4511), which its caller has just revoked. A slot
792
+ * holding another session or a step-up of its own stays for `logout` to
793
+ * revoke ({@link clearLeftoverLogins}).
612
794
  */
613
795
  export function clearCredentialsStore() {
614
796
  const env = resolveCurrentEnvironment();
@@ -625,8 +807,16 @@ export function clearCredentialsStore() {
625
807
  }
626
808
  if (!existsSync(credentialsFileForProject(env.projectRoot)))
627
809
  return;
810
+ const server = serverKey(env.config.apiUrl);
628
811
  const { slot, children } = loginSlotOf(env);
629
812
  updateProjectCredentialsFile(env.projectRoot, (file) => {
813
+ const entry = file.servers[server];
814
+ if (entry) {
815
+ if (!entry.login)
816
+ return false;
817
+ delete entry.login;
818
+ return true;
819
+ }
630
820
  const login = file.environments[slot];
631
821
  if (!login)
632
822
  return false;
@@ -641,86 +831,141 @@ export function clearCredentialsStore() {
641
831
  });
642
832
  }
643
833
  /**
644
- * Removes every slot the current login's child environments kept, once
645
- * `logout` has revoked the logins {@link leftoverChildLogins} returned. No-op
646
- * outside a project.
834
+ * Removes the logins {@link leftoverLogins} returned, once `logout` has
835
+ * revoked them: the server's leftovers, or before its first write the other
836
+ * legacy slots on it. No-op outside a project.
647
837
  */
648
- export function clearLeftoverChildLogins() {
838
+ export function clearLeftoverLogins() {
649
839
  const env = resolveCurrentEnvironment();
650
840
  if (!env)
651
841
  return;
652
- const { children } = loginSlotOf(env);
842
+ const server = serverKey(env.config.apiUrl);
653
843
  const file = loadProjectCredentialsFile(env.projectRoot);
654
- if (!children.some((name) => file.environments[name]))
844
+ const entry = file.servers[server];
845
+ if (entry ? !entry.leftovers : legacyLeftovers(file, env).length === 0)
655
846
  return;
656
847
  updateProjectCredentialsFile(env.projectRoot, (current) => {
657
- const kept = children.filter((name) => current.environments[name]);
658
- for (const name of kept)
848
+ const currentEntry = current.servers[server];
849
+ if (currentEntry) {
850
+ if (!currentEntry.leftovers)
851
+ return false;
852
+ delete currentEntry.leftovers;
853
+ return true;
854
+ }
855
+ const names = legacyLeftovers(current, env);
856
+ for (const name of names)
659
857
  delete current.environments[name];
660
- return kept.length > 0;
858
+ return names.length > 0;
661
859
  });
662
860
  }
663
861
  /**
664
- * Removes the credentials slot for the named environment in a specific
665
- * project's credentials file. Used by `env remove` so stale tokens from a
666
- * previously-removed environment can never be silently re-used if the same
667
- * name is later added back. Returns whether a slot was removed. Never throws.
668
- */
669
- export function clearCredentialsForEnvInProject(projectRoot, envName) {
862
+ * Removes what a removed environment leaves in a specific project's
863
+ * credentials file, so stale tokens from a previously-removed environment can
864
+ * never be silently re-used if the same name is later added back: a legacy
865
+ * slot or leftover of its name, and the login of the removed environment's
866
+ * server `removedApiUrl` when no remaining environment uses it (#4512). No
867
+ * other server's entry is touched: the file is shared by every worktree
868
+ * (#4492), and a server this worktree does not use may be another worktree's
869
+ * machine-local environment's. For the same reason the removed server's
870
+ * login stays while an environment of any worktree sharing the file uses it,
871
+ * or while that cannot be told. Used by `env remove`, after the environment
872
+ * left the config at `configPath`. Returns whether anything was removed.
873
+ * Never throws.
874
+ */
875
+ export function clearCredentialsForEnvInProject(projectRoot, envName, configPath = configPathOf(projectRoot), removedApiUrl) {
670
876
  try {
671
- return removeCredentialsSlotInProject(projectRoot, envName);
877
+ const removed = removeCredentialsSlotInProject(projectRoot, envName);
878
+ if (removedApiUrl === undefined)
879
+ return removed;
880
+ const server = serverKey(removedApiUrl);
881
+ const others = otherSharingProjectRoots(projectRoot);
882
+ if (!others)
883
+ return removed;
884
+ for (const path of [configPath, ...others.map(configPathOf)]) {
885
+ const servers = environmentServers(path);
886
+ if (!servers)
887
+ return removed;
888
+ if (Object.values(servers).some((apiUrl) => serverKey(apiUrl) === server))
889
+ return removed;
890
+ }
891
+ if (!loadProjectCredentialsFile(projectRoot).servers[server])
892
+ return removed;
893
+ updateProjectCredentialsFile(projectRoot, (file) => {
894
+ if (!file.servers[server])
895
+ return false;
896
+ delete file.servers[server];
897
+ return true;
898
+ });
899
+ return true;
672
900
  }
673
901
  catch {
674
902
  // Best-effort — removal is not a hard requirement for env removal to succeed.
675
903
  return false;
676
904
  }
677
905
  }
906
+ /** Whether `file` holds a legacy slot or a leftover named `envName`. */
907
+ function holdsSlotOf(file, envName) {
908
+ return (file.environments[envName] !== undefined ||
909
+ Object.values(file.servers).some((entry) => entry.leftovers?.[envName] !== undefined));
910
+ }
678
911
  /**
679
- * Removes the credentials slot for the named environment in a specific
680
- * project's credentials file. Returns false when there was no slot; throws
681
- * when the slot exists and the file could not be rewritten, so a caller that
682
- * must not lose track of a login can tell the two apart.
912
+ * Removes the legacy slot and the leftovers named `envName` in a specific
913
+ * project's credentials file; a server's login, which every environment on
914
+ * the server uses, is never one of them (#4512). Returns false when there was
915
+ * none; throws when there was one and the file could not be rewritten, so a
916
+ * caller that must not lose track of a login can tell the two apart.
683
917
  */
684
918
  export function removeCredentialsSlotInProject(projectRoot, envName) {
685
- if (!loadProjectCredentialsFile(projectRoot).environments[envName])
919
+ if (!holdsSlotOf(loadProjectCredentialsFile(projectRoot), envName))
686
920
  return false;
687
921
  let removed = false;
688
922
  updateProjectCredentialsFile(projectRoot, (file) => {
689
- removed = file.environments[envName] !== undefined;
923
+ removed = holdsSlotOf(file, envName);
690
924
  delete file.environments[envName];
925
+ for (const entry of Object.values(file.servers)) {
926
+ if (!entry.leftovers?.[envName])
927
+ continue;
928
+ delete entry.leftovers[envName];
929
+ if (Object.keys(entry.leftovers).length === 0)
930
+ delete entry.leftovers;
931
+ }
691
932
  return removed;
692
933
  });
693
934
  return removed;
694
935
  }
695
936
  /**
696
- * Writes the credentials slot for the named environment in a specific
697
- * project's credentials file. Used by `primitive init` to carry the session
698
- * it just authenticated into the freshly scaffolded project, so the first
699
- * in-project CLI command works without a second `primitive login`. The slot
700
- * records the credentials' server, which must be the named environment's
701
- * `apiUrl` in the project's config (#4492).
937
+ * Writes `credentials` as their server's login in a specific project's
938
+ * credentials file (#4512). Used by `primitive init` to carry the session it
939
+ * just authenticated into the freshly scaffolded project, so the first
940
+ * in-project CLI command works without a second `primitive login`.
702
941
  */
703
- export function seedCredentialsForEnvInProject(projectRoot, envName, credentials) {
942
+ export function seedCredentialsForServerInProject(projectRoot, credentials) {
704
943
  assertStorable(credentials);
705
- const config = readJsonFile(join(projectRoot, PROJECT_TREE_DIR, PROJECT_CONFIG_FILENAME));
706
- const apiUrl = config?.environments?.[envName]?.apiUrl;
707
- if (typeof apiUrl === "string" && !sameServer(credentials.serverUrl, apiUrl)) {
708
- throw writeMismatch(envName, credentials.serverUrl, apiUrl);
709
- }
710
- updateProjectCredentialsFile(projectRoot, (file) => {
711
- file.environments[envName] = storedRecord(credentials);
712
- return true;
713
- });
944
+ writeServerLogin(projectRoot, environmentServers(configPathOf(projectRoot)), credentials);
714
945
  }
715
946
  /**
716
- * Lists all environments that have stored credentials in project mode.
717
- * Returns an empty array in legacy mode.
947
+ * Lists the environments of the project that have a login to use: every
948
+ * environment on a server holding a login, and before a server's first write
949
+ * the environments with a legacy slot of their own. Returns an empty array in
950
+ * legacy mode.
718
951
  */
719
952
  export function listAuthenticatedEnvironments() {
720
953
  const env = resolveCurrentEnvironment();
721
954
  if (!env)
722
955
  return [];
723
956
  const file = loadProjectCredentialsFile(env.projectRoot);
724
- return Object.keys(file.environments);
957
+ const servers = environmentServers(env.projectConfigPath) ?? {};
958
+ const names = new Set();
959
+ for (const [name, apiUrl] of Object.entries(servers)) {
960
+ const entry = file.servers[serverKey(apiUrl)];
961
+ if (entry ? entry.login : file.environments[name])
962
+ names.add(name);
963
+ }
964
+ for (const name of Object.keys(file.environments)) {
965
+ const apiUrl = servers[name];
966
+ if (apiUrl === undefined || !file.servers[serverKey(apiUrl)])
967
+ names.add(name);
968
+ }
969
+ return [...names];
725
970
  }
726
971
  //# sourceMappingURL=credentials-store.js.map