primitive-admin 1.2.0-alpha.9 → 1.3.0-alpha.1

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 (590) hide show
  1. package/README.md +303 -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 +170 -50
  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 +42 -0
  40. package/dist/src/commands/db3-types.js +445 -0
  41. package/dist/src/commands/db3-types.js.map +1 -0
  42. package/dist/src/commands/db3.d.ts +38 -0
  43. package/dist/src/commands/db3.js +2053 -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 +1019 -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 +383 -32
  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 +509 -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 +55 -6
  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.d.ts +38 -0
  91. package/dist/src/commands/secrets.js +148 -6
  92. package/dist/src/commands/secrets.js.map +1 -1
  93. package/dist/src/commands/sessions.js +2 -0
  94. package/dist/src/commands/sessions.js.map +1 -1
  95. package/dist/src/commands/skill.js +2 -0
  96. package/dist/src/commands/skill.js.map +1 -1
  97. package/dist/src/commands/spent-tokens.d.ts +19 -0
  98. package/dist/src/commands/spent-tokens.js +79 -0
  99. package/dist/src/commands/spent-tokens.js.map +1 -0
  100. package/dist/src/commands/sync-app-settings.d.ts +58 -0
  101. package/dist/src/commands/sync-app-settings.js +119 -2
  102. package/dist/src/commands/sync-app-settings.js.map +1 -1
  103. package/dist/src/commands/sync-schemas.d.ts +202 -0
  104. package/dist/src/commands/sync-schemas.js +629 -0
  105. package/dist/src/commands/sync-schemas.js.map +1 -0
  106. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  107. package/dist/src/commands/sync-user-properties.js +276 -0
  108. package/dist/src/commands/sync-user-properties.js.map +1 -0
  109. package/dist/src/commands/sync.d.ts +578 -546
  110. package/dist/src/commands/sync.js +3516 -5134
  111. package/dist/src/commands/sync.js.map +1 -1
  112. package/dist/src/commands/tokens.js +5 -3
  113. package/dist/src/commands/tokens.js.map +1 -1
  114. package/dist/src/commands/transitions.d.ts +54 -0
  115. package/dist/src/commands/transitions.js +418 -0
  116. package/dist/src/commands/transitions.js.map +1 -0
  117. package/dist/src/commands/usage.d.ts +42 -0
  118. package/dist/src/commands/usage.js +397 -0
  119. package/dist/src/commands/usage.js.map +1 -0
  120. package/dist/src/commands/user-properties.d.ts +14 -0
  121. package/dist/src/commands/user-properties.js +79 -0
  122. package/dist/src/commands/user-properties.js.map +1 -0
  123. package/dist/src/commands/users.js +951 -18
  124. package/dist/src/commands/users.js.map +1 -1
  125. package/dist/src/commands/vars.js +2 -0
  126. package/dist/src/commands/vars.js.map +1 -1
  127. package/dist/src/commands/waitlist.js +39 -4
  128. package/dist/src/commands/waitlist.js.map +1 -1
  129. package/dist/src/commands/workflows.d.ts +5 -83
  130. package/dist/src/commands/workflows.js +57 -2282
  131. package/dist/src/commands/workflows.js.map +1 -1
  132. package/dist/src/lib/analytics-query.d.ts +58 -0
  133. package/dist/src/lib/analytics-query.js +134 -0
  134. package/dist/src/lib/analytics-query.js.map +1 -0
  135. package/dist/src/lib/api-client.d.ts +1976 -431
  136. package/dist/src/lib/api-client.js +1095 -550
  137. package/dist/src/lib/api-client.js.map +1 -1
  138. package/dist/src/lib/app-settings-descriptor.d.ts +14 -2
  139. package/dist/src/lib/app-settings-descriptor.js +55 -1
  140. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  141. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  142. package/dist/src/lib/auth-fixtures.js +61 -0
  143. package/dist/src/lib/auth-fixtures.js.map +1 -0
  144. package/dist/src/lib/auth-flow.d.ts +47 -1
  145. package/dist/src/lib/auth-flow.js +451 -14
  146. package/dist/src/lib/auth-flow.js.map +1 -1
  147. package/dist/src/lib/block-layout.d.ts +12 -23
  148. package/dist/src/lib/block-layout.js +26 -92
  149. package/dist/src/lib/block-layout.js.map +1 -1
  150. package/dist/src/lib/block-selector.d.ts +8 -14
  151. package/dist/src/lib/block-selector.js +8 -19
  152. package/dist/src/lib/block-selector.js.map +1 -1
  153. package/dist/src/lib/child-apps-local.d.ts +3 -1
  154. package/dist/src/lib/child-apps-local.js +9 -1
  155. package/dist/src/lib/child-apps-local.js.map +1 -1
  156. package/dist/src/lib/cli-manifest.d.ts +9 -0
  157. package/dist/src/lib/cli-manifest.js +10 -1
  158. package/dist/src/lib/cli-manifest.js.map +1 -1
  159. package/dist/src/lib/cli-version.d.ts +14 -0
  160. package/dist/src/lib/cli-version.js +38 -0
  161. package/dist/src/lib/cli-version.js.map +1 -0
  162. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  163. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  164. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  165. package/dist/src/lib/collection-export.d.ts +76 -15
  166. package/dist/src/lib/collection-export.js +116 -23
  167. package/dist/src/lib/collection-export.js.map +1 -1
  168. package/dist/src/lib/collection-principal.d.ts +22 -0
  169. package/dist/src/lib/collection-principal.js +35 -0
  170. package/dist/src/lib/collection-principal.js.map +1 -0
  171. package/dist/src/lib/command-groups.d.ts +30 -0
  172. package/dist/src/lib/command-groups.js +111 -0
  173. package/dist/src/lib/command-groups.js.map +1 -0
  174. package/dist/src/lib/command-status.d.ts +147 -0
  175. package/dist/src/lib/command-status.js +266 -0
  176. package/dist/src/lib/command-status.js.map +1 -0
  177. package/dist/src/lib/config-object-descriptor.d.ts +9 -22
  178. package/dist/src/lib/config-object-descriptor.js +113 -277
  179. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  180. package/dist/src/lib/config-surface.d.ts +3 -7
  181. package/dist/src/lib/config-surface.js +9 -13
  182. package/dist/src/lib/config-surface.js.map +1 -1
  183. package/dist/src/lib/config-toml.d.ts +11 -2
  184. package/dist/src/lib/config-toml.js +25 -2
  185. package/dist/src/lib/config-toml.js.map +1 -1
  186. package/dist/src/lib/credentials-home.d.ts +7 -0
  187. package/dist/src/lib/credentials-home.js +45 -10
  188. package/dist/src/lib/credentials-home.js.map +1 -1
  189. package/dist/src/lib/credentials-lock.d.ts +14 -6
  190. package/dist/src/lib/credentials-lock.js +90 -10
  191. package/dist/src/lib/credentials-lock.js.map +1 -1
  192. package/dist/src/lib/credentials-store.d.ts +142 -70
  193. package/dist/src/lib/credentials-store.js +420 -111
  194. package/dist/src/lib/credentials-store.js.map +1 -1
  195. package/dist/src/lib/custodian.d.ts +8 -0
  196. package/dist/src/lib/custodian.js +18 -0
  197. package/dist/src/lib/custodian.js.map +1 -0
  198. package/dist/src/lib/data-input.d.ts +1 -1
  199. package/dist/src/lib/data-input.js +1 -1
  200. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  201. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  202. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  203. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +40 -1
  204. package/dist/src/lib/db-codegen/dbTypeIR.js +32 -8
  205. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  206. package/dist/src/lib/db-type-records.d.ts +125 -0
  207. package/dist/src/lib/db-type-records.js +237 -0
  208. package/dist/src/lib/db-type-records.js.map +1 -0
  209. package/dist/src/lib/db3-export.d.ts +322 -0
  210. package/dist/src/lib/db3-export.js +767 -0
  211. package/dist/src/lib/db3-export.js.map +1 -0
  212. package/dist/src/lib/db3-index-output.d.ts +116 -0
  213. package/dist/src/lib/db3-index-output.js +223 -0
  214. package/dist/src/lib/db3-index-output.js.map +1 -0
  215. package/dist/src/lib/db3-json-fields.d.ts +49 -0
  216. package/dist/src/lib/db3-json-fields.js +195 -0
  217. package/dist/src/lib/db3-json-fields.js.map +1 -0
  218. package/dist/src/lib/db3-type-archive.d.ts +59 -0
  219. package/dist/src/lib/db3-type-archive.js +95 -0
  220. package/dist/src/lib/db3-type-archive.js.map +1 -0
  221. package/dist/src/lib/db3-type-models.d.ts +148 -0
  222. package/dist/src/lib/db3-type-models.js +583 -0
  223. package/dist/src/lib/db3-type-models.js.map +1 -0
  224. package/dist/src/lib/deprecation.d.ts +2 -2
  225. package/dist/src/lib/deprecation.js +2 -2
  226. package/dist/src/lib/document-export-record-log.d.ts +7 -0
  227. package/dist/src/lib/document-export-record-log.js +9 -0
  228. package/dist/src/lib/document-export-record-log.js.map +1 -1
  229. package/dist/src/lib/document-ingest-artifact.d.ts +19 -0
  230. package/dist/src/lib/document-ingest-artifact.js +55 -6
  231. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  232. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  233. package/dist/src/lib/document-ingest-format2.js +78 -0
  234. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  235. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  236. package/dist/src/lib/document-ingest-input.js +28 -1
  237. package/dist/src/lib/document-ingest-input.js.map +1 -1
  238. package/dist/src/lib/document-ingest.d.ts +11 -1
  239. package/dist/src/lib/document-ingest.js +16 -0
  240. package/dist/src/lib/document-ingest.js.map +1 -1
  241. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  242. package/dist/src/lib/document-schema-rows.js +53 -0
  243. package/dist/src/lib/document-schema-rows.js.map +1 -0
  244. package/dist/src/lib/experimental-apis.d.ts +36 -0
  245. package/dist/src/lib/experimental-apis.js +46 -0
  246. package/dist/src/lib/experimental-apis.js.map +1 -0
  247. package/dist/src/lib/file-attachment.d.ts +24 -0
  248. package/dist/src/lib/file-attachment.js +31 -0
  249. package/dist/src/lib/file-attachment.js.map +1 -0
  250. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  251. package/dist/src/lib/function-authorize-check.js +311 -0
  252. package/dist/src/lib/function-authorize-check.js.map +1 -0
  253. package/dist/src/lib/function-authorize-view.d.ts +36 -0
  254. package/dist/src/lib/function-authorize-view.js +110 -0
  255. package/dist/src/lib/function-authorize-view.js.map +1 -0
  256. package/dist/src/lib/function-bundle.d.ts +27 -5
  257. package/dist/src/lib/function-bundle.js +142 -7
  258. package/dist/src/lib/function-bundle.js.map +1 -1
  259. package/dist/src/lib/function-collect.d.ts +112 -12
  260. package/dist/src/lib/function-collect.js +601 -12
  261. package/dist/src/lib/function-collect.js.map +1 -1
  262. package/dist/src/lib/function-db-types.d.ts +65 -11
  263. package/dist/src/lib/function-db-types.js +326 -157
  264. package/dist/src/lib/function-db-types.js.map +1 -1
  265. package/dist/src/lib/function-document-types.d.ts +19 -7
  266. package/dist/src/lib/function-document-types.js +24 -12
  267. package/dist/src/lib/function-document-types.js.map +1 -1
  268. package/dist/src/lib/function-grants-preflight.d.ts +99 -0
  269. package/dist/src/lib/function-grants-preflight.js +154 -2
  270. package/dist/src/lib/function-grants-preflight.js.map +1 -1
  271. package/dist/src/lib/function-lint.d.ts +85 -0
  272. package/dist/src/lib/function-lint.js +442 -0
  273. package/dist/src/lib/function-lint.js.map +1 -0
  274. package/dist/src/lib/function-log-row.js +21 -2
  275. package/dist/src/lib/function-log-row.js.map +1 -1
  276. package/dist/src/lib/function-run.d.ts +13 -21
  277. package/dist/src/lib/function-run.js +14 -27
  278. package/dist/src/lib/function-run.js.map +1 -1
  279. package/dist/src/lib/function-schema-codegen.d.ts +86 -22
  280. package/dist/src/lib/function-schema-codegen.js +194 -88
  281. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  282. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  283. package/dist/src/lib/function-schema-refs.js +177 -0
  284. package/dist/src/lib/function-schema-refs.js.map +1 -0
  285. package/dist/src/lib/function-sync.d.ts +120 -6
  286. package/dist/src/lib/function-sync.js +217 -26
  287. package/dist/src/lib/function-sync.js.map +1 -1
  288. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  289. package/dist/src/lib/function-trigger-listing.js +32 -11
  290. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  291. package/dist/src/lib/function-typecheck.d.ts +52 -0
  292. package/dist/src/lib/function-typecheck.js +174 -54
  293. package/dist/src/lib/function-typecheck.js.map +1 -1
  294. package/dist/src/lib/function-versions.d.ts +2 -0
  295. package/dist/src/lib/function-versions.js +1 -0
  296. package/dist/src/lib/function-versions.js.map +1 -1
  297. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  298. package/dist/src/lib/generated-build-flags.js +14 -0
  299. package/dist/src/lib/generated-build-flags.js.map +1 -0
  300. package/dist/src/lib/generated-command-status.d.ts +6 -0
  301. package/dist/src/lib/generated-command-status.js +502 -0
  302. package/dist/src/lib/generated-command-status.js.map +1 -0
  303. package/dist/src/lib/generated-config-surfaces.d.ts +804 -140
  304. package/dist/src/lib/generated-config-surfaces.js +2491 -1806
  305. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  306. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  307. package/dist/src/lib/generated-sdk-types.js +1 -1
  308. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  309. package/dist/src/lib/hosting-build.d.ts +97 -0
  310. package/dist/src/lib/hosting-build.js +204 -0
  311. package/dist/src/lib/hosting-build.js.map +1 -0
  312. package/dist/src/lib/hosting-client.d.ts +167 -0
  313. package/dist/src/lib/hosting-client.js +340 -0
  314. package/dist/src/lib/hosting-client.js.map +1 -0
  315. package/dist/src/lib/hosting-environments.d.ts +32 -0
  316. package/dist/src/lib/hosting-environments.js +74 -0
  317. package/dist/src/lib/hosting-environments.js.map +1 -0
  318. package/dist/src/lib/hosting-errors.d.ts +30 -0
  319. package/dist/src/lib/hosting-errors.js +43 -0
  320. package/dist/src/lib/hosting-errors.js.map +1 -0
  321. package/dist/src/lib/hosting-token.d.ts +46 -0
  322. package/dist/src/lib/hosting-token.js +60 -0
  323. package/dist/src/lib/hosting-token.js.map +1 -0
  324. package/dist/src/lib/hosting-trust-step.d.ts +67 -0
  325. package/dist/src/lib/hosting-trust-step.js +279 -0
  326. package/dist/src/lib/hosting-trust-step.js.map +1 -0
  327. package/dist/src/lib/hosting-trust.d.ts +77 -0
  328. package/dist/src/lib/hosting-trust.js +194 -0
  329. package/dist/src/lib/hosting-trust.js.map +1 -0
  330. package/dist/src/lib/hosting-wait.d.ts +42 -0
  331. package/dist/src/lib/hosting-wait.js +84 -0
  332. package/dist/src/lib/hosting-wait.js.map +1 -0
  333. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  334. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  335. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  336. package/dist/src/lib/init-assets.d.ts +2 -6
  337. package/dist/src/lib/init-assets.js +11 -27
  338. package/dist/src/lib/init-assets.js.map +1 -1
  339. package/dist/src/lib/init-ios-links.d.ts +11 -7
  340. package/dist/src/lib/init-ios-links.js +28 -22
  341. package/dist/src/lib/init-ios-links.js.map +1 -1
  342. package/dist/src/lib/init-login-note.d.ts +13 -0
  343. package/dist/src/lib/init-login-note.js +22 -0
  344. package/dist/src/lib/init-login-note.js.map +1 -0
  345. package/dist/src/lib/init-schema.d.ts +15 -0
  346. package/dist/src/lib/init-schema.js +54 -0
  347. package/dist/src/lib/init-schema.js.map +1 -1
  348. package/dist/src/lib/integration-test-request.d.ts +54 -0
  349. package/dist/src/lib/integration-test-request.js +207 -0
  350. package/dist/src/lib/integration-test-request.js.map +1 -0
  351. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  352. package/dist/src/lib/invoker-shared-enums.js +98 -0
  353. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  354. package/dist/src/lib/json-value.d.ts +6 -0
  355. package/dist/src/lib/json-value.js +13 -0
  356. package/dist/src/lib/json-value.js.map +1 -0
  357. package/dist/src/lib/load-routes.d.ts +33 -0
  358. package/dist/src/lib/load-routes.js +35 -0
  359. package/dist/src/lib/load-routes.js.map +1 -0
  360. package/dist/src/lib/log-inspection.d.ts +23 -4
  361. package/dist/src/lib/log-inspection.js +14 -5
  362. package/dist/src/lib/log-inspection.js.map +1 -1
  363. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  364. package/dist/src/lib/login-exchange-check.js +27 -0
  365. package/dist/src/lib/login-exchange-check.js.map +1 -0
  366. package/dist/src/lib/login-scope-lines.d.ts +17 -7
  367. package/dist/src/lib/login-scope-lines.js +33 -10
  368. package/dist/src/lib/login-scope-lines.js.map +1 -1
  369. package/dist/src/lib/metadata-report.d.ts +85 -0
  370. package/dist/src/lib/metadata-report.js +81 -0
  371. package/dist/src/lib/metadata-report.js.map +1 -0
  372. package/dist/src/lib/object-status-filter.d.ts +9 -1
  373. package/dist/src/lib/object-status-filter.js +9 -1
  374. package/dist/src/lib/object-status-filter.js.map +1 -1
  375. package/dist/src/lib/output.d.ts +1 -1
  376. package/dist/src/lib/output.js +3 -1
  377. package/dist/src/lib/output.js.map +1 -1
  378. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  379. package/dist/src/lib/pin-refusal-hint.js +35 -0
  380. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  381. package/dist/src/lib/platform-owned.js +5 -0
  382. package/dist/src/lib/platform-owned.js.map +1 -1
  383. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  384. package/dist/src/lib/primitive-declaration-names.js +22 -0
  385. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  386. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  387. package/dist/src/lib/primitive-declaration.js +871 -0
  388. package/dist/src/lib/primitive-declaration.js.map +1 -0
  389. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  390. package/dist/src/lib/primitive-env-plugin.js +408 -0
  391. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  392. package/dist/src/lib/project-login-apps.d.ts +8 -0
  393. package/dist/src/lib/project-login-apps.js +27 -0
  394. package/dist/src/lib/project-login-apps.js.map +1 -0
  395. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  396. package/dist/src/lib/prompt-schema-codegen.js +96 -100
  397. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  398. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  399. package/dist/src/lib/prompt-schema-document.js +92 -0
  400. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  401. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  402. package/dist/src/lib/prompt-schema-refs.js +478 -0
  403. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  404. package/dist/src/lib/records-verbs.d.ts +79 -0
  405. package/dist/src/lib/records-verbs.js +45 -0
  406. package/dist/src/lib/records-verbs.js.map +1 -0
  407. package/dist/src/lib/refresh-admin-credentials.d.ts +34 -4
  408. package/dist/src/lib/refresh-admin-credentials.js +85 -29
  409. package/dist/src/lib/refresh-admin-credentials.js.map +1 -1
  410. package/dist/src/lib/refresh-stored-login.d.ts +85 -0
  411. package/dist/src/lib/refresh-stored-login.js +233 -0
  412. package/dist/src/lib/refresh-stored-login.js.map +1 -0
  413. package/dist/src/lib/register-commands.d.ts +36 -0
  414. package/dist/src/lib/register-commands.js +37 -0
  415. package/dist/src/lib/register-commands.js.map +1 -0
  416. package/dist/src/lib/retired-imports.d.ts +53 -0
  417. package/dist/src/lib/retired-imports.js +120 -0
  418. package/dist/src/lib/retired-imports.js.map +1 -0
  419. package/dist/src/lib/row-field-rename.d.ts +18 -0
  420. package/dist/src/lib/row-field-rename.js +32 -0
  421. package/dist/src/lib/row-field-rename.js.map +1 -0
  422. package/dist/src/lib/run-status.d.ts +1 -1
  423. package/dist/src/lib/run-status.generated.d.ts +2 -2
  424. package/dist/src/lib/run-status.generated.js +3 -1
  425. package/dist/src/lib/run-status.generated.js.map +1 -1
  426. package/dist/src/lib/run-status.js +1 -1
  427. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  428. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  429. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  430. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  431. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  432. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  433. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  434. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  435. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  436. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +229 -0
  437. package/dist/src/lib/schema-codegen/generated-field-grammar.js +420 -0
  438. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  439. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  440. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  441. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  442. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  443. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  444. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  445. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
  446. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
  447. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  448. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  449. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  450. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  451. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  452. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  453. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  454. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  455. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  456. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  457. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  458. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  459. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  460. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  461. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  462. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  463. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  464. package/dist/src/lib/schema-codegen/naming.js +83 -0
  465. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  466. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  467. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  468. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  469. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  470. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  471. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  472. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  473. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  474. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  475. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
  476. package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
  477. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  478. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  479. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  480. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  481. package/dist/src/lib/schema-defs-module.d.ts +29 -0
  482. package/dist/src/lib/schema-defs-module.js +103 -0
  483. package/dist/src/lib/schema-defs-module.js.map +1 -0
  484. package/dist/src/lib/schema-family-index.d.ts +228 -0
  485. package/dist/src/lib/schema-family-index.js +813 -0
  486. package/dist/src/lib/schema-family-index.js.map +1 -0
  487. package/dist/src/lib/schema-pins.d.ts +82 -0
  488. package/dist/src/lib/schema-pins.js +198 -0
  489. package/dist/src/lib/schema-pins.js.map +1 -0
  490. package/dist/src/lib/schema-preview.d.ts +244 -0
  491. package/dist/src/lib/schema-preview.js +498 -0
  492. package/dist/src/lib/schema-preview.js.map +1 -0
  493. package/dist/src/lib/scope-request.d.ts +23 -11
  494. package/dist/src/lib/scope-request.js +69 -31
  495. package/dist/src/lib/scope-request.js.map +1 -1
  496. package/dist/src/lib/session-scope.d.ts +26 -0
  497. package/dist/src/lib/session-scope.js +58 -0
  498. package/dist/src/lib/session-scope.js.map +1 -0
  499. package/dist/src/lib/skill-installer.d.ts +2 -2
  500. package/dist/src/lib/skill-installer.js +2 -21
  501. package/dist/src/lib/skill-installer.js.map +1 -1
  502. package/dist/src/lib/step-run-table.d.ts +1 -2
  503. package/dist/src/lib/step-run-table.js +1 -2
  504. package/dist/src/lib/step-run-table.js.map +1 -1
  505. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  506. package/dist/src/lib/swift-codegen/agentGenerator.js +25 -23
  507. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  508. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  509. package/dist/src/lib/swift-codegen/banners.js +12 -0
  510. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  511. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  512. package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
  513. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  514. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
  515. package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
  516. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  517. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +51 -0
  518. package/dist/src/lib/swift-codegen/sharedGenerator.js +239 -0
  519. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  520. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  521. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  522. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  523. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  524. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  525. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  526. package/dist/src/lib/sync-resource-types.d.ts +117 -31
  527. package/dist/src/lib/sync-resource-types.js +197 -189
  528. package/dist/src/lib/sync-resource-types.js.map +1 -1
  529. package/dist/src/lib/sync-selectors.d.ts +7 -0
  530. package/dist/src/lib/sync-selectors.js +22 -2
  531. package/dist/src/lib/sync-selectors.js.map +1 -1
  532. package/dist/src/lib/template.d.ts +39 -3
  533. package/dist/src/lib/template.js +103 -14
  534. package/dist/src/lib/template.js.map +1 -1
  535. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  536. package/dist/src/lib/test-case-file-names.js +3 -5
  537. package/dist/src/lib/test-case-file-names.js.map +1 -1
  538. package/dist/src/lib/test-runs.d.ts +45 -0
  539. package/dist/src/lib/test-runs.js +150 -0
  540. package/dist/src/lib/test-runs.js.map +1 -0
  541. package/dist/src/lib/test-users.d.ts +25 -0
  542. package/dist/src/lib/test-users.js +36 -0
  543. package/dist/src/lib/test-users.js.map +1 -0
  544. package/dist/src/lib/toml-database-config.d.ts +4 -2
  545. package/dist/src/lib/toml-database-config.js +11 -6
  546. package/dist/src/lib/toml-database-config.js.map +1 -1
  547. package/dist/src/lib/toml-list-edit.d.ts +33 -0
  548. package/dist/src/lib/toml-list-edit.js +481 -0
  549. package/dist/src/lib/toml-list-edit.js.map +1 -0
  550. package/dist/src/lib/toml-scalar-edit.d.ts +9 -0
  551. package/dist/src/lib/toml-scalar-edit.js +73 -5
  552. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  553. package/dist/src/lib/transition-warnings.d.ts +21 -0
  554. package/dist/src/lib/transition-warnings.js +49 -0
  555. package/dist/src/lib/transition-warnings.js.map +1 -0
  556. package/dist/src/lib/usage-meters.d.ts +16 -0
  557. package/dist/src/lib/usage-meters.js +52 -0
  558. package/dist/src/lib/usage-meters.js.map +1 -0
  559. package/dist/src/lib/user-index.d.ts +80 -0
  560. package/dist/src/lib/user-index.js +166 -0
  561. package/dist/src/lib/user-index.js.map +1 -0
  562. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  563. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  564. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  565. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  566. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  567. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  568. package/dist/src/lib/user-walk.d.ts +31 -0
  569. package/dist/src/lib/user-walk.js +102 -0
  570. package/dist/src/lib/user-walk.js.map +1 -0
  571. package/dist/src/lib/webhook-capture.d.ts +43 -0
  572. package/dist/src/lib/webhook-capture.js +91 -0
  573. package/dist/src/lib/webhook-capture.js.map +1 -0
  574. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  575. package/dist/src/lib/webhook-deliver.js +34 -89
  576. package/dist/src/lib/webhook-deliver.js.map +1 -1
  577. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  578. package/dist/src/lib/webhook-test-run.js +108 -0
  579. package/dist/src/lib/webhook-test-run.js.map +1 -0
  580. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  581. package/dist/src/lib/worker-perf-format.js +27 -0
  582. package/dist/src/lib/worker-perf-format.js.map +1 -0
  583. package/dist/src/types/index.d.ts +20 -65
  584. package/dist/src/validators.d.ts +7 -55
  585. package/dist/src/validators.js +7 -53
  586. package/dist/src/validators.js.map +1 -1
  587. package/dist/src/vite.d.ts +17 -0
  588. package/dist/src/vite.js +18 -0
  589. package/dist/src/vite.js.map +1 -0
  590. 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
@@ -313,6 +371,59 @@ function sameSession(a, b) {
313
371
  return sid === sessionIdOfToken(b.accessToken);
314
372
  return Boolean(a.accessToken) && a.accessToken === b.accessToken;
315
373
  }
374
+ /** A claim a JWT carries, or undefined. */
375
+ function claimOfToken(token, claim) {
376
+ if (!token)
377
+ return undefined;
378
+ try {
379
+ const payload = JSON.parse(Buffer.from(token.split(".")[1] ?? "", "base64url").toString("utf-8"));
380
+ return payload?.[claim];
381
+ }
382
+ catch {
383
+ return undefined;
384
+ }
385
+ }
386
+ /** The generation (`rg`) a rotating login's refresh token carries, or undefined. */
387
+ function generationOfToken(token) {
388
+ const rg = claimOfToken(token, "rg");
389
+ return typeof rg === "number" ? rg : undefined;
390
+ }
391
+ /** The session (`sid`) a login's refresh token, or else its access token, names. */
392
+ function loginSessionOf(login) {
393
+ for (const token of [login.refreshToken, login.accessToken]) {
394
+ const sid = claimOfToken(token, "sid");
395
+ if (typeof sid === "string" && sid)
396
+ return sid;
397
+ }
398
+ return undefined;
399
+ }
400
+ /**
401
+ * The login to store when `incoming` replaces `stored` (#5926). A rotating
402
+ * login's refresh token is replaced on every refresh, and the server ends the
403
+ * login when a replaced one is used after the grace. So when `stored` is the
404
+ * same session with a newer generation than `incoming` (a save that started
405
+ * from a copy read before another process refreshed: a step-up approved in
406
+ * the browser meanwhile, or a refresh answer saved late), the stored tokens
407
+ * and their expiry are kept; everything else is `incoming`'s. Any other pair
408
+ * is `incoming` unchanged. Pure.
409
+ */
410
+ export function keepNewerRotation(stored, incoming) {
411
+ if (!stored?.refreshToken || !stored.accessToken || !stored.expiresAt)
412
+ return incoming;
413
+ const mine = generationOfToken(stored.refreshToken);
414
+ const theirs = generationOfToken(incoming.refreshToken);
415
+ if (mine === undefined || theirs === undefined || mine <= theirs)
416
+ return incoming;
417
+ const sid = loginSessionOf(incoming);
418
+ if (!sid || loginSessionOf(stored) !== sid)
419
+ return incoming;
420
+ return {
421
+ ...incoming,
422
+ accessToken: stored.accessToken,
423
+ refreshToken: stored.refreshToken,
424
+ expiresAt: stored.expiresAt,
425
+ };
426
+ }
316
427
  /** The expiry (`exp`, in seconds) a JWT carries, or undefined. */
317
428
  function expiryOfToken(token) {
318
429
  if (!token)
@@ -390,6 +501,80 @@ function dropCopiedChildSlots(projectRoot, file, slot, children) {
390
501
  // The copies are ignored either way; the next read tries again.
391
502
  }
392
503
  }
504
+ /**
505
+ * The key of `apiUrl`'s login in `servers` (#4512): scheme, host and port,
506
+ * and the path without trailing slashes. A URL that does not parse keys as
507
+ * its trailing-slash-trimmed string.
508
+ */
509
+ function serverKey(apiUrl) {
510
+ return normalizeServerUrl(apiUrl) ?? trimSlash(apiUrl);
511
+ }
512
+ /**
513
+ * The server of every environment of the project whose config is at
514
+ * `configPath`, committed and machine-local, by name in config order. Null
515
+ * when the config cannot be read, so a caller never takes "no environment"
516
+ * for an answer it did not get.
517
+ */
518
+ function environmentServers(configPath) {
519
+ const config = readJsonFile(configPath);
520
+ if (!config?.environments || typeof config.environments !== "object")
521
+ return null;
522
+ const servers = {};
523
+ for (const [name, entry] of Object.entries(config.environments)) {
524
+ if (typeof entry?.apiUrl === "string")
525
+ servers[name] = entry.apiUrl;
526
+ }
527
+ try {
528
+ for (const [name, entry] of Object.entries(readLocalState(configPath).environments)) {
529
+ if (!(name in servers))
530
+ servers[name] = entry.apiUrl;
531
+ }
532
+ }
533
+ catch {
534
+ // An unreadable local state names no machine-local environment.
535
+ }
536
+ return servers;
537
+ }
538
+ /** The project config of a project root, where `init` and `env remove` find it. */
539
+ function configPathOf(projectRoot) {
540
+ return join(projectRoot, PROJECT_TREE_DIR, PROJECT_CONFIG_FILENAME);
541
+ }
542
+ /**
543
+ * The legacy slots of `file` that belong to `server`: one recording that
544
+ * server, and one named after an environment on it, whatever it records. The
545
+ * latter is the slot that environment read; one recording another server was
546
+ * never used there, and keeps its server so `logout` revokes it where it was
547
+ * issued.
548
+ */
549
+ function legacySlotsOn(file, server, servers) {
550
+ const on = (apiUrl) => apiUrl !== undefined && serverKey(apiUrl) === server;
551
+ return Object.entries(file.environments)
552
+ .filter(([name, slot]) => on(slot.serverUrl) || on(servers?.[name]))
553
+ .map(([name]) => name);
554
+ }
555
+ /**
556
+ * Create `servers[server]` for the login about to be written, moving the
557
+ * server's legacy slots out of `environments`. A slot holding `login`'s
558
+ * session that nothing a logout needs is dropped (an identical or older
559
+ * refresh token, no live step-up of its own, #4511's rules); any other slot
560
+ * becomes a leftover. No-op once the server has an entry.
561
+ */
562
+ function migrateServer(file, server, login, servers) {
563
+ const existing = file.servers[server];
564
+ if (existing)
565
+ return existing;
566
+ const leftovers = {};
567
+ for (const name of legacySlotsOn(file, server, servers)) {
568
+ const slot = file.environments[name];
569
+ const copy = sameSession(slot, login) && !outlivesRefresh(slot, login) && !ownStepUp(slot, login);
570
+ if (!copy)
571
+ leftovers[name] = slot;
572
+ delete file.environments[name];
573
+ }
574
+ const entry = Object.keys(leftovers).length > 0 ? { leftovers } : {};
575
+ file.servers[server] = entry;
576
+ return entry;
577
+ }
393
578
  /** The variable a CI job puts its admin token in (#3890). */
394
579
  export const PRIMITIVE_TOKEN_VAR = "PRIMITIVE_TOKEN";
395
580
  /**
@@ -397,6 +582,14 @@ export const PRIMITIVE_TOKEN_VAR = "PRIMITIVE_TOKEN";
397
582
  * names one. Deployed servers ignore the header for admin identity.
398
583
  */
399
584
  const PARTITION_VAR = "PRIMITIVE_GLOBAL_ADMIN_APP_ID";
585
+ /**
586
+ * The partition a login exchanges in when it builds on no stored login: the
587
+ * one `PRIMITIVE_GLOBAL_ADMIN_APP_ID` names, which only the live test harness
588
+ * sets. Deployed servers ignore the header for admin identity.
589
+ */
590
+ export function partitionFromEnvironment() {
591
+ return process.env[PARTITION_VAR]?.trim() || undefined;
592
+ }
400
593
  /** The token in `PRIMITIVE_TOKEN`, or null when it is unset or blank. */
401
594
  export function environmentToken() {
402
595
  const value = process.env[PRIMITIVE_TOKEN_VAR]?.trim();
@@ -436,24 +629,38 @@ function assertStorable(credentials) {
436
629
  * legacy global file. Returns the standard Credentials shape so existing
437
630
  * callers don't need to change.
438
631
  *
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.
632
+ * In project mode, we blend the server's stored login with the serverUrl
633
+ * from primitive/config.json to produce the Credentials the rest of the CLI
634
+ * expects (#4512). Before the server's first write a legacy slot is read
635
+ * instead: the environment's own, or its parent's for a child environment
636
+ * (#4511), and any child slot found to be a copy of that login is removed.
443
637
  *
444
638
  * `PRIMITIVE_TOKEN` (#3890), when set, takes precedence over any stored
445
639
  * login and no file is read. It does not loosen the outside-a-project
446
640
  * refusal: the environment is resolved first, exactly as for a stored login.
641
+ *
642
+ * Outside a project under a server pin (#4905), the global login is returned
643
+ * only when the pinned server issued it, and `PRIMITIVE_TOKEN` is for the
644
+ * pinned server.
447
645
  */
448
646
  export function loadCredentialsStore() {
449
647
  const env = resolveCurrentEnvironment();
450
- const fromEnvironment = environmentCredentials(env ? env.config.apiUrl : DEFAULT_SERVER_URL.replace(/\/$/, ""));
648
+ const fromEnvironment = environmentCredentials(env ? env.config.apiUrl : globalCredentialsServer ?? DEFAULT_SERVER_URL.replace(/\/$/, ""));
451
649
  if (fromEnvironment)
452
650
  return fromEnvironment;
453
651
  if (!env) {
454
- return loadLegacyCredentials();
652
+ const stored = loadLegacyCredentials();
653
+ if (stored &&
654
+ globalCredentialsServer !== null &&
655
+ (!stored.serverUrl || !sameServer(stored.serverUrl, globalCredentialsServer))) {
656
+ throw globalReadMismatch(stored.serverUrl, globalCredentialsServer);
657
+ }
658
+ return stored;
455
659
  }
456
660
  const file = loadProjectCredentialsFile(env.projectRoot);
661
+ const entry = file.servers[serverKey(env.config.apiUrl)];
662
+ if (entry)
663
+ return entry.login ? storedCredentials(env.config.apiUrl, entry.login) : null;
457
664
  const { slot, children } = loginSlotOf(env);
458
665
  const stored = file.environments[slot];
459
666
  if (!stored)
@@ -467,16 +674,20 @@ export function loadCredentialsStore() {
467
674
  return storedCredentials(env.config.apiUrl, stored);
468
675
  }
469
676
  /**
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.
677
+ * The current environment's legacy login when its slot records another server
678
+ * than the environment's, blended with the server it RECORDS; null otherwise,
679
+ * and always once the environment's server has a login entry (#4512). For
680
+ * `logout` alone, which revokes such a login at the server that issued it and
681
+ * so never sends its tokens anywhere else.
474
682
  */
475
683
  export function mismatchedLogin() {
476
684
  const env = resolveCurrentEnvironment();
477
685
  if (!env || environmentToken())
478
686
  return null;
479
- const stored = loadProjectCredentialsFile(env.projectRoot).environments[loginSlotOf(env).slot];
687
+ const file = loadProjectCredentialsFile(env.projectRoot);
688
+ if (file.servers[serverKey(env.config.apiUrl)])
689
+ return null;
690
+ const stored = file.environments[loginSlotOf(env).slot];
480
691
  if (!stored || !recordsOtherServer(stored, env.config.apiUrl))
481
692
  return null;
482
693
  return storedCredentials(stored.serverUrl, stored);
@@ -496,16 +707,22 @@ function storedCredentials(serverUrl, stored) {
496
707
  };
497
708
  }
498
709
  /**
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.
710
+ * The environments that share the current environment's login (#4512): every
711
+ * environment of the project on its server, committed and machine-local, in
712
+ * config order; and the committed environment whose tree the current one
713
+ * uses, which names the login. Null outside a project, where there is one
714
+ * global login.
502
715
  */
503
716
  export function loginEnvironments() {
504
717
  const env = resolveCurrentEnvironment();
505
718
  if (!env)
506
719
  return null;
507
- const { slot, children } = loginSlotOf(env);
508
- return { parent: slot, children };
720
+ const server = serverKey(env.config.apiUrl);
721
+ const servers = environmentServers(env.projectConfigPath) ?? {};
722
+ const environments = Object.entries(servers)
723
+ .filter(([, apiUrl]) => serverKey(apiUrl) === server)
724
+ .map(([name]) => name);
725
+ return { tree: env.tree, environments: environments.length > 0 ? environments : [env.name] };
509
726
  }
510
727
  /** The current project's root, or null outside a project or when it cannot be resolved. */
511
728
  function currentProjectRoot() {
@@ -551,39 +768,54 @@ export const worktreeLoginNotes = {
551
768
  },
552
769
  };
553
770
  /**
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.
771
+ * The logins on the current environment's server that no command reads: the
772
+ * server's leftovers (#4512), or before its first write the legacy slots on
773
+ * it other than the one the environment reads — sessions signed in to another
774
+ * environment, and copies that kept a step-up or a refresh token of their own
775
+ * (#4511). `logout` revokes them before {@link clearLeftoverLogins} removes
776
+ * them. Empty outside a project.
559
777
  */
560
- export function leftoverChildLogins() {
778
+ export function leftoverLogins() {
561
779
  const env = resolveCurrentEnvironment();
562
780
  if (!env)
563
781
  return [];
564
782
  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
- });
783
+ const server = serverKey(env.config.apiUrl);
784
+ const entry = file.servers[server];
785
+ const stored = entry
786
+ ? Object.values(entry.leftovers ?? {})
787
+ : legacyLeftovers(file, env).map((name) => file.environments[name]);
788
+ return stored.map((slot) => storedCredentials(slot.serverUrl ?? env.config.apiUrl, slot));
789
+ }
790
+ /** The legacy slots on `env`'s server other than the one it reads. */
791
+ function legacyLeftovers(file, env) {
792
+ const own = loginSlotOf(env).slot;
793
+ return legacySlotsOn(file, serverKey(env.config.apiUrl), environmentServers(env.projectConfigPath)).filter((name) => name !== own);
571
794
  }
572
795
  /**
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.
796
+ * Saves credentials. In project mode, writes the login of the environment's
797
+ * server (#4512), migrating the server's legacy slots at its first write. In
798
+ * legacy mode, writes the global file.
575
799
  *
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).
800
+ * In project mode the login records the incoming `serverUrl`, which must be
801
+ * the same server as the environment's `apiUrl`: credentials from another
802
+ * server are refused with `server-mismatch` and nothing is written (#4492).
803
+ * In legacy mode under a server pin (#4905), so are credentials from another
804
+ * server than the pinned one.
580
805
  */
581
806
  export function saveCredentialsStore(credentials) {
582
807
  assertStorable(credentials);
583
808
  const env = resolveCurrentEnvironment();
584
809
  if (!env) {
810
+ if (globalCredentialsServer !== null && !sameServer(credentials.serverUrl, globalCredentialsServer)) {
811
+ throw new PrimitiveEnvError("server-mismatch", `These credentials were issued by ${credentials.serverUrl}, but this command targets ` +
812
+ `${globalCredentialsServer}; nothing was stored.`);
813
+ }
585
814
  ensureDir(getLegacyConfigDir());
586
- writeFileSync(getLegacyCredentialsFile(), JSON.stringify(legacyCredentialsRecord(credentials), null, 2), { mode: 0o600 });
815
+ // #5926 — the legacy file has no lock; this narrows, not closes, the window
816
+ // in which a replaced rotating token is written over a newer one.
817
+ const record = keepNewerRotation(loadLegacyCredentials(), legacyCredentialsRecord(credentials));
818
+ writeFileSync(getLegacyCredentialsFile(), JSON.stringify(record, null, 2), { mode: 0o600 });
587
819
  try {
588
820
  chmodSync(getLegacyCredentialsFile(), 0o600);
589
821
  }
@@ -592,23 +824,37 @@ export function saveCredentialsStore(credentials) {
592
824
  }
593
825
  return;
594
826
  }
595
- const { slot, serverUrl } = loginSlotOf(env);
596
- if (!sameServer(credentials.serverUrl, serverUrl)) {
597
- throw writeMismatch(env.name, credentials.serverUrl, serverUrl);
827
+ if (!sameServer(credentials.serverUrl, env.config.apiUrl)) {
828
+ throw writeMismatch(env.name, credentials.serverUrl, env.config.apiUrl);
598
829
  }
599
- updateProjectCredentialsFile(env.projectRoot, (file) => {
600
- file.environments[slot] = storedRecord(credentials);
830
+ writeServerLogin(env.projectRoot, environmentServers(env.projectConfigPath), credentials);
831
+ }
832
+ /** Write `credentials` as their server's login in the project at `projectRoot`. */
833
+ function writeServerLogin(projectRoot, servers, credentials) {
834
+ const incoming = storedRecord(credentials);
835
+ const server = serverKey(credentials.serverUrl);
836
+ updateProjectCredentialsFile(projectRoot, (file) => {
837
+ // #5926 — under the lock: never write back a rotating login's replaced
838
+ // token over the newer one another process stored. Before the server's
839
+ // first write the login is in a legacy slot on the server.
840
+ const current = file.servers[server]?.login ??
841
+ legacySlotsOn(file, server, servers)
842
+ .map((name) => file.environments[name])
843
+ .find((slot) => keepNewerRotation(slot, incoming) !== incoming);
844
+ const record = keepNewerRotation(current, incoming);
845
+ migrateServer(file, server, record, servers).login = record;
601
846
  return true;
602
847
  });
603
848
  }
604
849
  /**
605
850
  * 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}).
851
+ * deletes the legacy file (legacy mode). In project mode that is the login of
852
+ * the environment's server; its entry and leftovers stay, so a legacy slot is
853
+ * never read for the server again (#4512). Before the server's first write it
854
+ * is the legacy slot the environment reads, and the child slots holding only
855
+ * that login's session (#4511), which its caller has just revoked. A slot
856
+ * holding another session or a step-up of its own stays for `logout` to
857
+ * revoke ({@link clearLeftoverLogins}).
612
858
  */
613
859
  export function clearCredentialsStore() {
614
860
  const env = resolveCurrentEnvironment();
@@ -625,8 +871,16 @@ export function clearCredentialsStore() {
625
871
  }
626
872
  if (!existsSync(credentialsFileForProject(env.projectRoot)))
627
873
  return;
874
+ const server = serverKey(env.config.apiUrl);
628
875
  const { slot, children } = loginSlotOf(env);
629
876
  updateProjectCredentialsFile(env.projectRoot, (file) => {
877
+ const entry = file.servers[server];
878
+ if (entry) {
879
+ if (!entry.login)
880
+ return false;
881
+ delete entry.login;
882
+ return true;
883
+ }
630
884
  const login = file.environments[slot];
631
885
  if (!login)
632
886
  return false;
@@ -641,86 +895,141 @@ export function clearCredentialsStore() {
641
895
  });
642
896
  }
643
897
  /**
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.
898
+ * Removes the logins {@link leftoverLogins} returned, once `logout` has
899
+ * revoked them: the server's leftovers, or before its first write the other
900
+ * legacy slots on it. No-op outside a project.
647
901
  */
648
- export function clearLeftoverChildLogins() {
902
+ export function clearLeftoverLogins() {
649
903
  const env = resolveCurrentEnvironment();
650
904
  if (!env)
651
905
  return;
652
- const { children } = loginSlotOf(env);
906
+ const server = serverKey(env.config.apiUrl);
653
907
  const file = loadProjectCredentialsFile(env.projectRoot);
654
- if (!children.some((name) => file.environments[name]))
908
+ const entry = file.servers[server];
909
+ if (entry ? !entry.leftovers : legacyLeftovers(file, env).length === 0)
655
910
  return;
656
911
  updateProjectCredentialsFile(env.projectRoot, (current) => {
657
- const kept = children.filter((name) => current.environments[name]);
658
- for (const name of kept)
912
+ const currentEntry = current.servers[server];
913
+ if (currentEntry) {
914
+ if (!currentEntry.leftovers)
915
+ return false;
916
+ delete currentEntry.leftovers;
917
+ return true;
918
+ }
919
+ const names = legacyLeftovers(current, env);
920
+ for (const name of names)
659
921
  delete current.environments[name];
660
- return kept.length > 0;
922
+ return names.length > 0;
661
923
  });
662
924
  }
663
925
  /**
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.
926
+ * Removes what a removed environment leaves in a specific project's
927
+ * credentials file, so stale tokens from a previously-removed environment can
928
+ * never be silently re-used if the same name is later added back: a legacy
929
+ * slot or leftover of its name, and the login of the removed environment's
930
+ * server `removedApiUrl` when no remaining environment uses it (#4512). No
931
+ * other server's entry is touched: the file is shared by every worktree
932
+ * (#4492), and a server this worktree does not use may be another worktree's
933
+ * machine-local environment's. For the same reason the removed server's
934
+ * login stays while an environment of any worktree sharing the file uses it,
935
+ * or while that cannot be told. Used by `env remove`, after the environment
936
+ * left the config at `configPath`. Returns whether anything was removed.
937
+ * Never throws.
668
938
  */
669
- export function clearCredentialsForEnvInProject(projectRoot, envName) {
939
+ export function clearCredentialsForEnvInProject(projectRoot, envName, configPath = configPathOf(projectRoot), removedApiUrl) {
670
940
  try {
671
- return removeCredentialsSlotInProject(projectRoot, envName);
941
+ const removed = removeCredentialsSlotInProject(projectRoot, envName);
942
+ if (removedApiUrl === undefined)
943
+ return removed;
944
+ const server = serverKey(removedApiUrl);
945
+ const others = otherSharingProjectRoots(projectRoot);
946
+ if (!others)
947
+ return removed;
948
+ for (const path of [configPath, ...others.map(configPathOf)]) {
949
+ const servers = environmentServers(path);
950
+ if (!servers)
951
+ return removed;
952
+ if (Object.values(servers).some((apiUrl) => serverKey(apiUrl) === server))
953
+ return removed;
954
+ }
955
+ if (!loadProjectCredentialsFile(projectRoot).servers[server])
956
+ return removed;
957
+ updateProjectCredentialsFile(projectRoot, (file) => {
958
+ if (!file.servers[server])
959
+ return false;
960
+ delete file.servers[server];
961
+ return true;
962
+ });
963
+ return true;
672
964
  }
673
965
  catch {
674
966
  // Best-effort — removal is not a hard requirement for env removal to succeed.
675
967
  return false;
676
968
  }
677
969
  }
970
+ /** Whether `file` holds a legacy slot or a leftover named `envName`. */
971
+ function holdsSlotOf(file, envName) {
972
+ return (file.environments[envName] !== undefined ||
973
+ Object.values(file.servers).some((entry) => entry.leftovers?.[envName] !== undefined));
974
+ }
678
975
  /**
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.
976
+ * Removes the legacy slot and the leftovers named `envName` in a specific
977
+ * project's credentials file; a server's login, which every environment on
978
+ * the server uses, is never one of them (#4512). Returns false when there was
979
+ * none; throws when there was one and the file could not be rewritten, so a
980
+ * caller that must not lose track of a login can tell the two apart.
683
981
  */
684
982
  export function removeCredentialsSlotInProject(projectRoot, envName) {
685
- if (!loadProjectCredentialsFile(projectRoot).environments[envName])
983
+ if (!holdsSlotOf(loadProjectCredentialsFile(projectRoot), envName))
686
984
  return false;
687
985
  let removed = false;
688
986
  updateProjectCredentialsFile(projectRoot, (file) => {
689
- removed = file.environments[envName] !== undefined;
987
+ removed = holdsSlotOf(file, envName);
690
988
  delete file.environments[envName];
989
+ for (const entry of Object.values(file.servers)) {
990
+ if (!entry.leftovers?.[envName])
991
+ continue;
992
+ delete entry.leftovers[envName];
993
+ if (Object.keys(entry.leftovers).length === 0)
994
+ delete entry.leftovers;
995
+ }
691
996
  return removed;
692
997
  });
693
998
  return removed;
694
999
  }
695
1000
  /**
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).
1001
+ * Writes `credentials` as their server's login in a specific project's
1002
+ * credentials file (#4512). Used by `primitive init` to carry the session it
1003
+ * just authenticated into the freshly scaffolded project, so the first
1004
+ * in-project CLI command works without a second `primitive login`.
702
1005
  */
703
- export function seedCredentialsForEnvInProject(projectRoot, envName, credentials) {
1006
+ export function seedCredentialsForServerInProject(projectRoot, credentials) {
704
1007
  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
- });
1008
+ writeServerLogin(projectRoot, environmentServers(configPathOf(projectRoot)), credentials);
714
1009
  }
715
1010
  /**
716
- * Lists all environments that have stored credentials in project mode.
717
- * Returns an empty array in legacy mode.
1011
+ * Lists the environments of the project that have a login to use: every
1012
+ * environment on a server holding a login, and before a server's first write
1013
+ * the environments with a legacy slot of their own. Returns an empty array in
1014
+ * legacy mode.
718
1015
  */
719
1016
  export function listAuthenticatedEnvironments() {
720
1017
  const env = resolveCurrentEnvironment();
721
1018
  if (!env)
722
1019
  return [];
723
1020
  const file = loadProjectCredentialsFile(env.projectRoot);
724
- return Object.keys(file.environments);
1021
+ const servers = environmentServers(env.projectConfigPath) ?? {};
1022
+ const names = new Set();
1023
+ for (const [name, apiUrl] of Object.entries(servers)) {
1024
+ const entry = file.servers[serverKey(apiUrl)];
1025
+ if (entry ? entry.login : file.environments[name])
1026
+ names.add(name);
1027
+ }
1028
+ for (const name of Object.keys(file.environments)) {
1029
+ const apiUrl = servers[name];
1030
+ if (apiUrl === undefined || !file.servers[serverKey(apiUrl)])
1031
+ names.add(name);
1032
+ }
1033
+ return [...names];
725
1034
  }
726
1035
  //# sourceMappingURL=credentials-store.js.map