primitive-admin 1.2.0-alpha.8 → 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 (563) hide show
  1. package/README.md +258 -186
  2. package/assets/skill/skills/primitive-platform/SKILL.md +103 -29
  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.d.ts +1 -1
  13. package/dist/src/commands/apps-children.js +56 -145
  14. package/dist/src/commands/apps-children.js.map +1 -1
  15. package/dist/src/commands/apps-transitions.d.ts +39 -0
  16. package/dist/src/commands/apps-transitions.js +198 -0
  17. package/dist/src/commands/apps-transitions.js.map +1 -0
  18. package/dist/src/commands/apps.d.ts +17 -0
  19. package/dist/src/commands/apps.js +108 -3
  20. package/dist/src/commands/apps.js.map +1 -1
  21. package/dist/src/commands/auth-sessions.js +2 -0
  22. package/dist/src/commands/auth-sessions.js.map +1 -1
  23. package/dist/src/commands/auth.js +138 -44
  24. package/dist/src/commands/auth.js.map +1 -1
  25. package/dist/src/commands/blob-buckets.js +2 -0
  26. package/dist/src/commands/blob-buckets.js.map +1 -1
  27. package/dist/src/commands/collections.js +318 -256
  28. package/dist/src/commands/collections.js.map +1 -1
  29. package/dist/src/commands/comparisons.js +2 -0
  30. package/dist/src/commands/comparisons.js.map +1 -1
  31. package/dist/src/commands/config.d.ts +2 -2
  32. package/dist/src/commands/config.js +59 -33
  33. package/dist/src/commands/config.js.map +1 -1
  34. package/dist/src/commands/connections.js +2 -0
  35. package/dist/src/commands/connections.js.map +1 -1
  36. package/dist/src/commands/database-type-configs.js +5 -3
  37. package/dist/src/commands/database-type-configs.js.map +1 -1
  38. package/dist/src/commands/database-types.js +13 -313
  39. package/dist/src/commands/database-types.js.map +1 -1
  40. package/dist/src/commands/databases.js +6 -4
  41. package/dist/src/commands/databases.js.map +1 -1
  42. package/dist/src/commands/db3-types.d.ts +15 -0
  43. package/dist/src/commands/db3-types.js +159 -0
  44. package/dist/src/commands/db3-types.js.map +1 -0
  45. package/dist/src/commands/db3.d.ts +24 -0
  46. package/dist/src/commands/db3.js +1444 -0
  47. package/dist/src/commands/db3.js.map +1 -0
  48. package/dist/src/commands/documents.d.ts +110 -10
  49. package/dist/src/commands/documents.js +1012 -748
  50. package/dist/src/commands/documents.js.map +1 -1
  51. package/dist/src/commands/email-templates.js +74 -0
  52. package/dist/src/commands/email-templates.js.map +1 -1
  53. package/dist/src/commands/env.js +8 -4
  54. package/dist/src/commands/env.js.map +1 -1
  55. package/dist/src/commands/function-trigger-commands.d.ts +28 -0
  56. package/dist/src/commands/function-trigger-commands.js +341 -0
  57. package/dist/src/commands/function-trigger-commands.js.map +1 -0
  58. package/dist/src/commands/functions.js +376 -30
  59. package/dist/src/commands/functions.js.map +1 -1
  60. package/dist/src/commands/groups.js +168 -50
  61. package/dist/src/commands/groups.js.map +1 -1
  62. package/dist/src/commands/guides.js +7 -5
  63. package/dist/src/commands/guides.js.map +1 -1
  64. package/dist/src/commands/hosting.d.ts +8 -0
  65. package/dist/src/commands/hosting.js +346 -0
  66. package/dist/src/commands/hosting.js.map +1 -0
  67. package/dist/src/commands/init.js +129 -38
  68. package/dist/src/commands/init.js.map +1 -1
  69. package/dist/src/commands/integrations.js +82 -53
  70. package/dist/src/commands/integrations.js.map +1 -1
  71. package/dist/src/commands/llm.js +9 -6
  72. package/dist/src/commands/llm.js.map +1 -1
  73. package/dist/src/commands/locks.d.ts +5 -3
  74. package/dist/src/commands/locks.js +19 -61
  75. package/dist/src/commands/locks.js.map +1 -1
  76. package/dist/src/commands/metadata-category-configs.d.ts +2 -2
  77. package/dist/src/commands/metadata-category-configs.js +4 -2
  78. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  79. package/dist/src/commands/metadata.js +41 -0
  80. package/dist/src/commands/metadata.js.map +1 -1
  81. package/dist/src/commands/prompts.js +75 -52
  82. package/dist/src/commands/prompts.js.map +1 -1
  83. package/dist/src/commands/rate-counters.d.ts +19 -0
  84. package/dist/src/commands/rate-counters.js +104 -0
  85. package/dist/src/commands/rate-counters.js.map +1 -0
  86. package/dist/src/commands/rule-sets.d.ts +1 -1
  87. package/dist/src/commands/rule-sets.js +2 -1
  88. package/dist/src/commands/rule-sets.js.map +1 -1
  89. package/dist/src/commands/schemas.d.ts +15 -0
  90. package/dist/src/commands/schemas.js +122 -0
  91. package/dist/src/commands/schemas.js.map +1 -0
  92. package/dist/src/commands/scripts.d.ts +9 -17
  93. package/dist/src/commands/scripts.js +24 -479
  94. package/dist/src/commands/scripts.js.map +1 -1
  95. package/dist/src/commands/secrets.js +47 -3
  96. package/dist/src/commands/secrets.js.map +1 -1
  97. package/dist/src/commands/sessions.js +2 -0
  98. package/dist/src/commands/sessions.js.map +1 -1
  99. package/dist/src/commands/settings.d.ts +12 -9
  100. package/dist/src/commands/settings.js +31 -79
  101. package/dist/src/commands/settings.js.map +1 -1
  102. package/dist/src/commands/skill.js +2 -0
  103. package/dist/src/commands/skill.js.map +1 -1
  104. package/dist/src/commands/sync-schemas.d.ts +202 -0
  105. package/dist/src/commands/sync-schemas.js +629 -0
  106. package/dist/src/commands/sync-schemas.js.map +1 -0
  107. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  108. package/dist/src/commands/sync-user-properties.js +276 -0
  109. package/dist/src/commands/sync-user-properties.js.map +1 -0
  110. package/dist/src/commands/sync.d.ts +519 -554
  111. package/dist/src/commands/sync.js +3010 -4909
  112. package/dist/src/commands/sync.js.map +1 -1
  113. package/dist/src/commands/tokens.js +5 -3
  114. package/dist/src/commands/tokens.js.map +1 -1
  115. package/dist/src/commands/transitions.d.ts +54 -0
  116. package/dist/src/commands/transitions.js +418 -0
  117. package/dist/src/commands/transitions.js.map +1 -0
  118. package/dist/src/commands/usage.d.ts +18 -0
  119. package/dist/src/commands/usage.js +343 -0
  120. package/dist/src/commands/usage.js.map +1 -0
  121. package/dist/src/commands/user-properties.d.ts +14 -0
  122. package/dist/src/commands/user-properties.js +79 -0
  123. package/dist/src/commands/user-properties.js.map +1 -0
  124. package/dist/src/commands/users.js +911 -18
  125. package/dist/src/commands/users.js.map +1 -1
  126. package/dist/src/commands/vars.js +2 -0
  127. package/dist/src/commands/vars.js.map +1 -1
  128. package/dist/src/commands/waitlist.js +39 -4
  129. package/dist/src/commands/waitlist.js.map +1 -1
  130. package/dist/src/commands/workflows.d.ts +5 -83
  131. package/dist/src/commands/workflows.js +57 -2282
  132. package/dist/src/commands/workflows.js.map +1 -1
  133. package/dist/src/lib/analytics-query.d.ts +58 -0
  134. package/dist/src/lib/analytics-query.js +134 -0
  135. package/dist/src/lib/analytics-query.js.map +1 -0
  136. package/dist/src/lib/api-client.d.ts +1830 -429
  137. package/dist/src/lib/api-client.js +1025 -546
  138. package/dist/src/lib/api-client.js.map +1 -1
  139. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  140. package/dist/src/lib/app-settings-descriptor.js +6 -0
  141. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  142. package/dist/src/lib/auth-fixtures.d.ts +44 -0
  143. package/dist/src/lib/auth-fixtures.js +61 -0
  144. package/dist/src/lib/auth-fixtures.js.map +1 -0
  145. package/dist/src/lib/auth-flow.d.ts +34 -1
  146. package/dist/src/lib/auth-flow.js +429 -13
  147. package/dist/src/lib/auth-flow.js.map +1 -1
  148. package/dist/src/lib/block-layout.d.ts +12 -23
  149. package/dist/src/lib/block-layout.js +26 -92
  150. package/dist/src/lib/block-layout.js.map +1 -1
  151. package/dist/src/lib/block-selector.d.ts +8 -14
  152. package/dist/src/lib/block-selector.js +8 -19
  153. package/dist/src/lib/block-selector.js.map +1 -1
  154. package/dist/src/lib/child-apps-local.d.ts +3 -47
  155. package/dist/src/lib/child-apps-local.js +11 -73
  156. package/dist/src/lib/child-apps-local.js.map +1 -1
  157. package/dist/src/lib/cli-manifest.d.ts +9 -0
  158. package/dist/src/lib/cli-manifest.js +10 -1
  159. package/dist/src/lib/cli-manifest.js.map +1 -1
  160. package/dist/src/lib/cli-version.d.ts +14 -0
  161. package/dist/src/lib/cli-version.js +38 -0
  162. package/dist/src/lib/cli-version.js.map +1 -0
  163. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  164. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  165. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  166. package/dist/src/lib/collection-export.d.ts +76 -15
  167. package/dist/src/lib/collection-export.js +116 -23
  168. package/dist/src/lib/collection-export.js.map +1 -1
  169. package/dist/src/lib/collection-principal.d.ts +22 -0
  170. package/dist/src/lib/collection-principal.js +35 -0
  171. package/dist/src/lib/collection-principal.js.map +1 -0
  172. package/dist/src/lib/command-groups.d.ts +30 -0
  173. package/dist/src/lib/command-groups.js +109 -0
  174. package/dist/src/lib/command-groups.js.map +1 -0
  175. package/dist/src/lib/command-status.d.ts +147 -0
  176. package/dist/src/lib/command-status.js +266 -0
  177. package/dist/src/lib/command-status.js.map +1 -0
  178. package/dist/src/lib/config-object-descriptor.d.ts +9 -22
  179. package/dist/src/lib/config-object-descriptor.js +107 -276
  180. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  181. package/dist/src/lib/config-surface.d.ts +3 -7
  182. package/dist/src/lib/config-surface.js +9 -13
  183. package/dist/src/lib/config-surface.js.map +1 -1
  184. package/dist/src/lib/config-toml.d.ts +11 -2
  185. package/dist/src/lib/config-toml.js +25 -2
  186. package/dist/src/lib/config-toml.js.map +1 -1
  187. package/dist/src/lib/credentials-home.d.ts +7 -0
  188. package/dist/src/lib/credentials-home.js +45 -10
  189. package/dist/src/lib/credentials-home.js.map +1 -1
  190. package/dist/src/lib/credentials-lock.d.ts +14 -6
  191. package/dist/src/lib/credentials-lock.js +90 -10
  192. package/dist/src/lib/credentials-lock.js.map +1 -1
  193. package/dist/src/lib/credentials-store.d.ts +123 -70
  194. package/dist/src/lib/credentials-store.js +358 -113
  195. package/dist/src/lib/credentials-store.js.map +1 -1
  196. package/dist/src/lib/custodian.d.ts +8 -0
  197. package/dist/src/lib/custodian.js +18 -0
  198. package/dist/src/lib/custodian.js.map +1 -0
  199. package/dist/src/lib/data-input.d.ts +1 -1
  200. package/dist/src/lib/data-input.js +1 -1
  201. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  202. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  203. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  204. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +38 -1
  205. package/dist/src/lib/db-codegen/dbTypeIR.js +29 -7
  206. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  207. package/dist/src/lib/db-type-records.d.ts +106 -0
  208. package/dist/src/lib/db-type-records.js +224 -0
  209. package/dist/src/lib/db-type-records.js.map +1 -0
  210. package/dist/src/lib/db3-export.d.ts +287 -0
  211. package/dist/src/lib/db3-export.js +647 -0
  212. package/dist/src/lib/db3-export.js.map +1 -0
  213. package/dist/src/lib/db3-index-output.d.ts +116 -0
  214. package/dist/src/lib/db3-index-output.js +223 -0
  215. package/dist/src/lib/db3-index-output.js.map +1 -0
  216. package/dist/src/lib/db3-type-models.d.ts +134 -0
  217. package/dist/src/lib/db3-type-models.js +452 -0
  218. package/dist/src/lib/db3-type-models.js.map +1 -0
  219. package/dist/src/lib/deprecation.d.ts +2 -2
  220. package/dist/src/lib/deprecation.js +2 -2
  221. package/dist/src/lib/document-ingest-artifact.d.ts +13 -0
  222. package/dist/src/lib/document-ingest-artifact.js +36 -6
  223. package/dist/src/lib/document-ingest-artifact.js.map +1 -1
  224. package/dist/src/lib/document-ingest-format2.d.ts +36 -0
  225. package/dist/src/lib/document-ingest-format2.js +78 -0
  226. package/dist/src/lib/document-ingest-format2.js.map +1 -0
  227. package/dist/src/lib/document-ingest-input.d.ts +9 -0
  228. package/dist/src/lib/document-ingest-input.js +28 -1
  229. package/dist/src/lib/document-ingest-input.js.map +1 -1
  230. package/dist/src/lib/document-ingest.d.ts +11 -1
  231. package/dist/src/lib/document-ingest.js +16 -0
  232. package/dist/src/lib/document-ingest.js.map +1 -1
  233. package/dist/src/lib/document-schema-rows.d.ts +42 -0
  234. package/dist/src/lib/document-schema-rows.js +53 -0
  235. package/dist/src/lib/document-schema-rows.js.map +1 -0
  236. package/dist/src/lib/experimental-apis.d.ts +36 -0
  237. package/dist/src/lib/experimental-apis.js +46 -0
  238. package/dist/src/lib/experimental-apis.js.map +1 -0
  239. package/dist/src/lib/file-attachment.d.ts +24 -0
  240. package/dist/src/lib/file-attachment.js +31 -0
  241. package/dist/src/lib/file-attachment.js.map +1 -0
  242. package/dist/src/lib/function-authorize-check.d.ts +142 -0
  243. package/dist/src/lib/function-authorize-check.js +311 -0
  244. package/dist/src/lib/function-authorize-check.js.map +1 -0
  245. package/dist/src/lib/function-authorize-view.d.ts +27 -0
  246. package/dist/src/lib/function-authorize-view.js +88 -0
  247. package/dist/src/lib/function-authorize-view.js.map +1 -0
  248. package/dist/src/lib/function-bundle.d.ts +27 -5
  249. package/dist/src/lib/function-bundle.js +142 -7
  250. package/dist/src/lib/function-bundle.js.map +1 -1
  251. package/dist/src/lib/function-collect.d.ts +90 -12
  252. package/dist/src/lib/function-collect.js +482 -12
  253. package/dist/src/lib/function-collect.js.map +1 -1
  254. package/dist/src/lib/function-db-types.d.ts +65 -11
  255. package/dist/src/lib/function-db-types.js +297 -157
  256. package/dist/src/lib/function-db-types.js.map +1 -1
  257. package/dist/src/lib/function-document-types.d.ts +19 -7
  258. package/dist/src/lib/function-document-types.js +24 -12
  259. package/dist/src/lib/function-document-types.js.map +1 -1
  260. package/dist/src/lib/function-lint.d.ts +57 -0
  261. package/dist/src/lib/function-lint.js +234 -0
  262. package/dist/src/lib/function-lint.js.map +1 -0
  263. package/dist/src/lib/function-log-row.js +21 -2
  264. package/dist/src/lib/function-log-row.js.map +1 -1
  265. package/dist/src/lib/function-run.d.ts +13 -21
  266. package/dist/src/lib/function-run.js +14 -27
  267. package/dist/src/lib/function-run.js.map +1 -1
  268. package/dist/src/lib/function-schema-codegen.d.ts +86 -22
  269. package/dist/src/lib/function-schema-codegen.js +194 -88
  270. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  271. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  272. package/dist/src/lib/function-schema-refs.js +177 -0
  273. package/dist/src/lib/function-schema-refs.js.map +1 -0
  274. package/dist/src/lib/function-sync.d.ts +109 -6
  275. package/dist/src/lib/function-sync.js +179 -26
  276. package/dist/src/lib/function-sync.js.map +1 -1
  277. package/dist/src/lib/function-trigger-listing.d.ts +11 -6
  278. package/dist/src/lib/function-trigger-listing.js +32 -11
  279. package/dist/src/lib/function-trigger-listing.js.map +1 -1
  280. package/dist/src/lib/function-triggers.d.ts +15 -3
  281. package/dist/src/lib/function-triggers.js +72 -10
  282. package/dist/src/lib/function-triggers.js.map +1 -1
  283. package/dist/src/lib/function-typecheck.d.ts +52 -0
  284. package/dist/src/lib/function-typecheck.js +174 -54
  285. package/dist/src/lib/function-typecheck.js.map +1 -1
  286. package/dist/src/lib/function-versions.d.ts +2 -0
  287. package/dist/src/lib/function-versions.js +1 -0
  288. package/dist/src/lib/function-versions.js.map +1 -1
  289. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  290. package/dist/src/lib/generated-build-flags.js +14 -0
  291. package/dist/src/lib/generated-build-flags.js.map +1 -0
  292. package/dist/src/lib/generated-command-status.d.ts +6 -0
  293. package/dist/src/lib/generated-command-status.js +469 -0
  294. package/dist/src/lib/generated-command-status.js.map +1 -0
  295. package/dist/src/lib/generated-config-surfaces.d.ts +586 -152
  296. package/dist/src/lib/generated-config-surfaces.js +1919 -1883
  297. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  298. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  299. package/dist/src/lib/generated-sdk-types.js +1 -1
  300. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  301. package/dist/src/lib/generated-workflow-model-fields.d.ts +20 -0
  302. package/dist/src/lib/generated-workflow-model-fields.js +53 -0
  303. package/dist/src/lib/generated-workflow-model-fields.js.map +1 -0
  304. package/dist/src/lib/hosting-build.d.ts +97 -0
  305. package/dist/src/lib/hosting-build.js +204 -0
  306. package/dist/src/lib/hosting-build.js.map +1 -0
  307. package/dist/src/lib/hosting-client.d.ts +167 -0
  308. package/dist/src/lib/hosting-client.js +340 -0
  309. package/dist/src/lib/hosting-client.js.map +1 -0
  310. package/dist/src/lib/hosting-environments.d.ts +32 -0
  311. package/dist/src/lib/hosting-environments.js +74 -0
  312. package/dist/src/lib/hosting-environments.js.map +1 -0
  313. package/dist/src/lib/hosting-errors.d.ts +30 -0
  314. package/dist/src/lib/hosting-errors.js +43 -0
  315. package/dist/src/lib/hosting-errors.js.map +1 -0
  316. package/dist/src/lib/hosting-token.d.ts +46 -0
  317. package/dist/src/lib/hosting-token.js +60 -0
  318. package/dist/src/lib/hosting-token.js.map +1 -0
  319. package/dist/src/lib/hosting-wait.d.ts +42 -0
  320. package/dist/src/lib/hosting-wait.js +84 -0
  321. package/dist/src/lib/hosting-wait.js.map +1 -0
  322. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  323. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  324. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  325. package/dist/src/lib/init-assets.d.ts +2 -6
  326. package/dist/src/lib/init-assets.js +11 -27
  327. package/dist/src/lib/init-assets.js.map +1 -1
  328. package/dist/src/lib/init-ios-links.d.ts +11 -7
  329. package/dist/src/lib/init-ios-links.js +28 -22
  330. package/dist/src/lib/init-ios-links.js.map +1 -1
  331. package/dist/src/lib/init-login-note.d.ts +13 -0
  332. package/dist/src/lib/init-login-note.js +22 -0
  333. package/dist/src/lib/init-login-note.js.map +1 -0
  334. package/dist/src/lib/init-schema.d.ts +15 -0
  335. package/dist/src/lib/init-schema.js +54 -0
  336. package/dist/src/lib/init-schema.js.map +1 -1
  337. package/dist/src/lib/integration-test-request.d.ts +54 -0
  338. package/dist/src/lib/integration-test-request.js +207 -0
  339. package/dist/src/lib/integration-test-request.js.map +1 -0
  340. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  341. package/dist/src/lib/invoker-shared-enums.js +98 -0
  342. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  343. package/dist/src/lib/json-value.d.ts +6 -0
  344. package/dist/src/lib/json-value.js +13 -0
  345. package/dist/src/lib/json-value.js.map +1 -0
  346. package/dist/src/lib/load-routes.d.ts +33 -0
  347. package/dist/src/lib/load-routes.js +35 -0
  348. package/dist/src/lib/load-routes.js.map +1 -0
  349. package/dist/src/lib/log-inspection.d.ts +23 -4
  350. package/dist/src/lib/log-inspection.js +14 -5
  351. package/dist/src/lib/log-inspection.js.map +1 -1
  352. package/dist/src/lib/login-exchange-check.d.ts +18 -0
  353. package/dist/src/lib/login-exchange-check.js +27 -0
  354. package/dist/src/lib/login-exchange-check.js.map +1 -0
  355. package/dist/src/lib/login-scope-lines.d.ts +17 -7
  356. package/dist/src/lib/login-scope-lines.js +33 -10
  357. package/dist/src/lib/login-scope-lines.js.map +1 -1
  358. package/dist/src/lib/metadata-report.d.ts +85 -0
  359. package/dist/src/lib/metadata-report.js +81 -0
  360. package/dist/src/lib/metadata-report.js.map +1 -0
  361. package/dist/src/lib/object-status-filter.d.ts +9 -1
  362. package/dist/src/lib/object-status-filter.js +9 -1
  363. package/dist/src/lib/object-status-filter.js.map +1 -1
  364. package/dist/src/lib/output.d.ts +1 -1
  365. package/dist/src/lib/output.js +3 -1
  366. package/dist/src/lib/output.js.map +1 -1
  367. package/dist/src/lib/pin-refusal-hint.d.ts +12 -0
  368. package/dist/src/lib/pin-refusal-hint.js +35 -0
  369. package/dist/src/lib/pin-refusal-hint.js.map +1 -0
  370. package/dist/src/lib/platform-owned.js +5 -0
  371. package/dist/src/lib/platform-owned.js.map +1 -1
  372. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  373. package/dist/src/lib/primitive-declaration-names.js +22 -0
  374. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  375. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  376. package/dist/src/lib/primitive-declaration.js +792 -0
  377. package/dist/src/lib/primitive-declaration.js.map +1 -0
  378. package/dist/src/lib/primitive-env-plugin.d.ts +99 -0
  379. package/dist/src/lib/primitive-env-plugin.js +408 -0
  380. package/dist/src/lib/primitive-env-plugin.js.map +1 -0
  381. package/dist/src/lib/project-login-apps.d.ts +8 -0
  382. package/dist/src/lib/project-login-apps.js +27 -0
  383. package/dist/src/lib/project-login-apps.js.map +1 -0
  384. package/dist/src/lib/prompt-schema-codegen.d.ts +46 -15
  385. package/dist/src/lib/prompt-schema-codegen.js +142 -108
  386. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  387. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  388. package/dist/src/lib/prompt-schema-document.js +92 -0
  389. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  390. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  391. package/dist/src/lib/prompt-schema-refs.js +478 -0
  392. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  393. package/dist/src/lib/records-verbs.d.ts +79 -0
  394. package/dist/src/lib/records-verbs.js +45 -0
  395. package/dist/src/lib/records-verbs.js.map +1 -0
  396. package/dist/src/lib/register-commands.d.ts +36 -0
  397. package/dist/src/lib/register-commands.js +37 -0
  398. package/dist/src/lib/register-commands.js.map +1 -0
  399. package/dist/src/lib/retired-imports.d.ts +53 -0
  400. package/dist/src/lib/retired-imports.js +120 -0
  401. package/dist/src/lib/retired-imports.js.map +1 -0
  402. package/dist/src/lib/run-status.d.ts +1 -1
  403. package/dist/src/lib/run-status.generated.d.ts +2 -2
  404. package/dist/src/lib/run-status.generated.js +3 -1
  405. package/dist/src/lib/run-status.generated.js.map +1 -1
  406. package/dist/src/lib/run-status.js +1 -1
  407. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  408. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  409. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  410. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  411. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  412. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  413. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  414. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  415. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  416. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  417. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  418. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  419. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  420. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  421. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  422. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  423. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  424. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  425. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +258 -0
  426. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +422 -0
  427. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -0
  428. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  429. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  430. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  431. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  432. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  433. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  434. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  435. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  436. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  437. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  438. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  439. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  440. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  441. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  442. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  443. package/dist/src/lib/schema-codegen/naming.d.ts +35 -0
  444. package/dist/src/lib/schema-codegen/naming.js +83 -0
  445. package/dist/src/lib/schema-codegen/naming.js.map +1 -0
  446. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  447. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  448. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  449. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  450. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  451. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  452. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  453. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  454. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  455. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +109 -0
  456. package/dist/src/lib/schema-codegen/schemaToTs.js +269 -0
  457. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -0
  458. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  459. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  460. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  461. package/dist/src/lib/schema-family-index.d.ts +228 -0
  462. package/dist/src/lib/schema-family-index.js +813 -0
  463. package/dist/src/lib/schema-family-index.js.map +1 -0
  464. package/dist/src/lib/schema-pins.d.ts +82 -0
  465. package/dist/src/lib/schema-pins.js +198 -0
  466. package/dist/src/lib/schema-pins.js.map +1 -0
  467. package/dist/src/lib/schema-preview.d.ts +244 -0
  468. package/dist/src/lib/schema-preview.js +498 -0
  469. package/dist/src/lib/schema-preview.js.map +1 -0
  470. package/dist/src/lib/scope-request.d.ts +23 -11
  471. package/dist/src/lib/scope-request.js +69 -31
  472. package/dist/src/lib/scope-request.js.map +1 -1
  473. package/dist/src/lib/session-scope.d.ts +26 -0
  474. package/dist/src/lib/session-scope.js +58 -0
  475. package/dist/src/lib/session-scope.js.map +1 -0
  476. package/dist/src/lib/skill-installer.d.ts +2 -2
  477. package/dist/src/lib/skill-installer.js +2 -21
  478. package/dist/src/lib/skill-installer.js.map +1 -1
  479. package/dist/src/lib/step-run-table.d.ts +1 -2
  480. package/dist/src/lib/step-run-table.js +1 -2
  481. package/dist/src/lib/step-run-table.js.map +1 -1
  482. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +8 -3
  483. package/dist/src/lib/swift-codegen/agentGenerator.js +76 -22
  484. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  485. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  486. package/dist/src/lib/swift-codegen/banners.js +12 -0
  487. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  488. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  489. package/dist/src/lib/swift-codegen/functionGenerator.js +169 -51
  490. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  491. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +33 -9
  492. package/dist/src/lib/swift-codegen/schemaToSwift.js +215 -179
  493. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  494. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  495. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  496. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  497. package/dist/src/lib/swift-codegen/swiftKeys.d.ts +19 -0
  498. package/dist/src/lib/swift-codegen/swiftKeys.js +31 -0
  499. package/dist/src/lib/swift-codegen/swiftKeys.js.map +1 -0
  500. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  501. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  502. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  503. package/dist/src/lib/sync-resource-types.d.ts +117 -31
  504. package/dist/src/lib/sync-resource-types.js +197 -189
  505. package/dist/src/lib/sync-resource-types.js.map +1 -1
  506. package/dist/src/lib/sync-selectors.d.ts +7 -0
  507. package/dist/src/lib/sync-selectors.js +22 -2
  508. package/dist/src/lib/sync-selectors.js.map +1 -1
  509. package/dist/src/lib/template.d.ts +39 -3
  510. package/dist/src/lib/template.js +103 -14
  511. package/dist/src/lib/template.js.map +1 -1
  512. package/dist/src/lib/test-case-file-names.d.ts +3 -5
  513. package/dist/src/lib/test-case-file-names.js +3 -5
  514. package/dist/src/lib/test-case-file-names.js.map +1 -1
  515. package/dist/src/lib/test-runs.d.ts +45 -0
  516. package/dist/src/lib/test-runs.js +150 -0
  517. package/dist/src/lib/test-runs.js.map +1 -0
  518. package/dist/src/lib/test-users.d.ts +25 -0
  519. package/dist/src/lib/test-users.js +36 -0
  520. package/dist/src/lib/test-users.js.map +1 -0
  521. package/dist/src/lib/toml-database-config.d.ts +4 -2
  522. package/dist/src/lib/toml-database-config.js +11 -6
  523. package/dist/src/lib/toml-database-config.js.map +1 -1
  524. package/dist/src/lib/toml-scalar-edit.js +6 -4
  525. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  526. package/dist/src/lib/transition-warnings.d.ts +21 -0
  527. package/dist/src/lib/transition-warnings.js +49 -0
  528. package/dist/src/lib/transition-warnings.js.map +1 -0
  529. package/dist/src/lib/user-index.d.ts +80 -0
  530. package/dist/src/lib/user-index.js +166 -0
  531. package/dist/src/lib/user-index.js.map +1 -0
  532. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  533. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  534. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  535. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  536. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  537. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  538. package/dist/src/lib/user-walk.d.ts +31 -0
  539. package/dist/src/lib/user-walk.js +102 -0
  540. package/dist/src/lib/user-walk.js.map +1 -0
  541. package/dist/src/lib/webhook-capture.d.ts +43 -0
  542. package/dist/src/lib/webhook-capture.js +91 -0
  543. package/dist/src/lib/webhook-capture.js.map +1 -0
  544. package/dist/src/lib/webhook-deliver.d.ts +18 -20
  545. package/dist/src/lib/webhook-deliver.js +34 -89
  546. package/dist/src/lib/webhook-deliver.js.map +1 -1
  547. package/dist/src/lib/webhook-test-run.d.ts +32 -0
  548. package/dist/src/lib/webhook-test-run.js +108 -0
  549. package/dist/src/lib/webhook-test-run.js.map +1 -0
  550. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  551. package/dist/src/lib/worker-perf-format.js +27 -0
  552. package/dist/src/lib/worker-perf-format.js.map +1 -0
  553. package/dist/src/lib/workflow-field-descriptor.d.ts +91 -0
  554. package/dist/src/lib/workflow-field-descriptor.js +153 -0
  555. package/dist/src/lib/workflow-field-descriptor.js.map +1 -0
  556. package/dist/src/types/index.d.ts +20 -65
  557. package/dist/src/validators.d.ts +7 -55
  558. package/dist/src/validators.js +7 -53
  559. package/dist/src/validators.js.map +1 -1
  560. package/dist/src/vite.d.ts +17 -0
  561. package/dist/src/vite.js +18 -0
  562. package/dist/src/vite.js.map +1 -0
  563. package/package.json +20 -9
@@ -1,3 +1,4 @@
1
+ import { commandStatus } from "../lib/command-status.js";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { ApiClient } from "../lib/api-client.js";
@@ -7,7 +8,9 @@ import { confirmPrompt } from "../lib/confirm-prompt.js";
7
8
  import { pageCursorOption, pageLimitOption, parsePageLimit, printEmptyPage, printPageHint, } from "../lib/list-options.js";
8
9
  import { normalizeCliListEnvelope, wholeListEnvelope, } from "../lib/paginate.js";
9
10
  import { resolveOwnerUserId } from "../lib/resolve-owner.js";
10
- import { COLLECTION_EXPORT_FILENAME, COLLECTION_EXPORT_VERSION, duplicateNameSources, emptyImportSummary, grantDisposition, grantUpdateLine, groupTargetsByName, importExitCode, planCollection, readCollectionExportFile, serverReason, } from "../lib/collection-export.js";
11
+ import { parseCustodianOrExit } from "../lib/custodian.js";
12
+ import { parseCollectionPrincipal, parseCollectionRole } from "../lib/collection-principal.js";
13
+ import { COLLECTION_EXPORT_FILENAME, COLLECTION_EXPORT_VERSION, duplicateNameSources, emptyImportSummary, grantDisposition, grantUpdateLine, sameGrantGroup, groupTargetsByName, importExitCode, planCollection, readCollectionExportFile, rowCustodian, custodianUserId, permissionForRole, serverReason, } from "../lib/collection-export.js";
11
14
  export function registerCollectionsCommands(program) {
12
15
  const collections = program
13
16
  .command("collections")
@@ -18,14 +21,17 @@ Examples:
18
21
  $ primitive collections create "Sprint 12"
19
22
  $ primitive collections create "Sprint 12" --owner user@example.com
20
23
  $ primitive collections get <collection-id>
24
+ $ primitive collections list --custodian user:<user-id>
25
+ $ primitive collections transfer <collection-id> user:<user-id>
21
26
  $ primitive collections documents list <collection-id>
22
27
  $ primitive collections documents add <collection-id> <document-id>
23
- $ primitive collections access <collection-id>
24
- $ primitive collections share <collection-id> --group team/engineering --permission read-write
25
28
  $ primitive collections members list <collection-id>
26
- $ primitive collections members add <collection-id> <user-id> --permission reader
29
+ $ primitive collections members add <collection-id> <user-id> --role contributor
30
+ $ primitive collections members add <collection-id> group:<group-id> --role viewer
31
+ $ primitive collections members set-role <collection-id> <user-id> editor
27
32
  $ primitive collections for-document <document-id>
28
33
  `);
34
+ commandStatus(collections, { stability: "production" });
29
35
  // List collections
30
36
  collections
31
37
  .command("list")
@@ -34,18 +40,26 @@ Examples:
34
40
  .argument("[app-id]", "App ID (uses current app if not specified)")
35
41
  .option("--app <app-id>", "App ID")
36
42
  .option("--all", "List every collection in the app (admin-only). Default is collections you're a direct member of.")
43
+ .option("--custodian <custodian>", 'Only this custodian\'s collections: "app" or "user:<user-id>" (needs an admin token)')
37
44
  .addOption(pageLimitOption())
38
45
  .addOption(pageCursorOption())
39
46
  .option("--json", "Output as JSON")
40
47
  .action(async (appId, options) => {
41
48
  const limit = parsePageLimit(options.limit);
49
+ const custodian = options.custodian === undefined ? undefined : parseCustodianOrExit(options.custodian, "--custodian");
50
+ if (custodian && options.all) {
51
+ error("--custodian and --all are alternatives; pass one.");
52
+ process.exit(1);
53
+ }
42
54
  const resolvedAppId = resolveAppId(appId, options);
43
55
  const client = new ApiClient();
44
56
  try {
45
57
  const params = { limit, cursor: options.cursor };
46
- const page = normalizeCliListEnvelope(options.all
47
- ? await client.listAllCollections(resolvedAppId, params)
48
- : await client.listCollections(resolvedAppId, params));
58
+ const page = normalizeCliListEnvelope(custodian
59
+ ? await client.listCollectionsByCustodian(resolvedAppId, custodian, params)
60
+ : options.all
61
+ ? await client.listAllCollections(resolvedAppId, params)
62
+ : await client.listCollections(resolvedAppId, params));
49
63
  const list = page.items;
50
64
  if (options.json) {
51
65
  json(page);
@@ -63,7 +77,10 @@ Examples:
63
77
  { header: "CREATED", key: "createdAt", format: formatDate },
64
78
  ];
65
79
  // `permission` is only returned by the default list() endpoint
66
- if (!options.all) {
80
+ if (custodian) {
81
+ columns.splice(2, 0, { header: "CUSTODIAN", key: "custodian" });
82
+ }
83
+ else if (!options.all) {
67
84
  columns.splice(4, 0, { header: "PERMISSION", key: "permission", format: (v) => v || "—" });
68
85
  }
69
86
  console.log(formatTable(list, columns));
@@ -82,25 +99,21 @@ Examples:
82
99
  // Create collection
83
100
  collections
84
101
  .command("create")
85
- .description("Create a new collection")
102
+ .description("Create a new collection, held by the caller or by --owner")
86
103
  .argument("<name>", "Collection name")
87
104
  .option("--description <description>", "Collection description")
88
- .option("--initial-metadata <json>", "Create-time resource metadata as JSON, keyed by category name (issue #1420)")
105
+ .option("--initial-metadata <json>", "Create-time resource metadata as JSON, keyed by category name")
89
106
  .option("--app <app-id>", "App ID")
90
- .option("--owner <userId-or-email>", "User ID or email to own the collection (super-admin or assigned-console-admin tokens only)")
107
+ .option("--owner <userId-or-email>", "The user who holds the collection (its custodian and owner); needs an admin token")
91
108
  .option("--json", "Output as JSON")
92
109
  .addHelpText("after", `
93
- Ownership:
94
- An app-user token — member, admin, or owner — always creates the collection
95
- owned by the caller: the server ignores --owner for those tokens.
96
- A super-admin token, or a console-admin token assigned to this app, acts
97
- through an admin shadow app user — without --owner that shadow user owns the
98
- collection, with --owner the named user does.
99
- A console admin not assigned to this app has no access to the app at all.
100
-
101
- The owner is the collection's creator, so under the default rules they — and
102
- no other non-admin — can edit it, delete it, and manage its documents and
103
- members.
110
+ Custody:
111
+ Without --owner the caller holds the new collection: an app user's token
112
+ makes them its custodian and owner; a console admin's token gives the app
113
+ custody.
114
+ With --owner the collection is created through the admin API for that user,
115
+ who becomes its custodian and owner; this needs an admin token assigned to
116
+ the app.
104
117
 
105
118
  An email given to --owner is resolved to a user id before anything is
106
119
  created; a user who is not in the app fails the command without creating a
@@ -111,7 +124,7 @@ Ownership:
111
124
  const client = new ApiClient();
112
125
  // Resolve --owner to a userId through the one shared lookup (#2763),
113
126
  // before the create: an email nobody answers to must fail with nothing
114
- // created, not leave a collection owned by the admin.
127
+ // created.
115
128
  let ownerUserId;
116
129
  if (options.owner) {
117
130
  try {
@@ -124,8 +137,6 @@ Ownership:
124
137
  }
125
138
  try {
126
139
  const data = { name };
127
- if (ownerUserId)
128
- data.createdBy = ownerUserId;
129
140
  if (options.description)
130
141
  data.description = options.description;
131
142
  // Create-time per-category ResourceMetadata rows (issue #1420).
@@ -138,7 +149,9 @@ Ownership:
138
149
  process.exit(1);
139
150
  }
140
151
  }
141
- const result = await client.createCollection(resolvedAppId, data);
152
+ const result = ownerUserId
153
+ ? await client.createCollectionAsAdmin(resolvedAppId, { ...data, custodian: `user:${ownerUserId}` })
154
+ : await client.createCollection(resolvedAppId, data);
142
155
  if (options.json) {
143
156
  json(result);
144
157
  return;
@@ -146,9 +159,8 @@ Ownership:
146
159
  success("Collection created.");
147
160
  keyValue("Collection ID", result.collectionId);
148
161
  keyValue("Name", result.name);
149
- // Read back from the RESPONSE, not from --owner: whom the server
150
- // credited is the answer, and for a non-admin token it is the caller.
151
- keyValue("Owner", result.createdBy);
162
+ // Read back from the RESPONSE: who holds it is the server's answer.
163
+ keyValue("Custodian", result.custodian ?? "(none)");
152
164
  if (result.description)
153
165
  keyValue("Description", result.description);
154
166
  }
@@ -184,6 +196,38 @@ Ownership:
184
196
  process.exit(1);
185
197
  }
186
198
  });
199
+ // Transfer collection
200
+ collections
201
+ .command("transfer")
202
+ .description("Transfer a collection to another user or to the app")
203
+ .argument("<collection-id>", "Collection ID")
204
+ .argument("<custodian>", '"user:<user-id>" (a member of the app) or "app"')
205
+ .option("--app <app-id>", "App ID")
206
+ .option("--json", "Output as JSON")
207
+ .allowExcessArguments(false)
208
+ .addHelpText("after", `
209
+ The custodian and the owner row move together: the new custodian holds the
210
+ owner role, the previous owner stays as a manager (or, moving to the app,
211
+ loses the owner row), and no other role changes.
212
+ `)
213
+ .action(async (collectionId, custodianArg, options) => {
214
+ const to = parseCustodianOrExit(custodianArg, "custodian");
215
+ const resolvedAppId = resolveAppId(undefined, options);
216
+ const client = new ApiClient();
217
+ try {
218
+ const result = await client.transferCollection(resolvedAppId, collectionId, to);
219
+ if (options.json) {
220
+ json(result);
221
+ return;
222
+ }
223
+ success(`Collection ${collectionId} transferred.`);
224
+ printResult("Custodian", result.custodian);
225
+ }
226
+ catch (err) {
227
+ error(err.message);
228
+ process.exit(1);
229
+ }
230
+ });
187
231
  // Update collection
188
232
  collections
189
233
  .command("update")
@@ -259,130 +303,6 @@ Ownership:
259
303
  process.exit(1);
260
304
  }
261
305
  });
262
- // ---- Access command ----
263
- collections
264
- .command("access")
265
- .description("Combined view of the groups and members with access to a collection " +
266
- "(members only: 'collections members list'; group grants: 'collections share'/'unshare')")
267
- .argument("<collection-id>", "Collection ID")
268
- .option("--app <app-id>", "App ID")
269
- .option("--json", "Output as JSON")
270
- .action(async (collectionId, options) => {
271
- const resolvedAppId = resolveAppId(undefined, options);
272
- const client = new ApiClient();
273
- try {
274
- const result = await client.getCollectionAccess(resolvedAppId, collectionId);
275
- if (options.json) {
276
- json(result);
277
- return;
278
- }
279
- const groups = result.groups || [];
280
- const members = result.members || [];
281
- if (groups.length === 0 && members.length === 0) {
282
- info("No groups or members have access to this collection.");
283
- return;
284
- }
285
- if (groups.length > 0) {
286
- console.log("\nGroups:");
287
- console.log(formatTable(groups, [
288
- { header: "TYPE", key: "groupType" },
289
- { header: "ID", key: "groupId" },
290
- { header: "PERMISSION", key: "permission" },
291
- { header: "GRANTED", key: "grantedAt", format: formatDate },
292
- ]));
293
- }
294
- if (members.length > 0) {
295
- console.log("\nMembers:");
296
- console.log(formatTable(members, [
297
- { header: "USER_ID", key: "userId", format: formatId },
298
- { header: "PERMISSION", key: "permission" },
299
- ]));
300
- }
301
- }
302
- catch (err) {
303
- error(err.message);
304
- process.exit(1);
305
- }
306
- });
307
- // ---- Share / unshare (group permissions) ----
308
- collections
309
- .command("share")
310
- .description("Grant a group access to a collection")
311
- .argument("<collection-id>", "Collection ID")
312
- .requiredOption("--group <group>", "Group in format type/id (e.g. team/engineering)")
313
- .requiredOption("--permission <permission>", "Permission level (reader or read-write)")
314
- .option("--app <app-id>", "App ID")
315
- .option("--json", "Output as JSON")
316
- .action(async (collectionId, options) => {
317
- const resolvedAppId = resolveAppId(undefined, options);
318
- const client = new ApiClient();
319
- const parts = options.group.split("/");
320
- if (parts.length !== 2) {
321
- error("Group must be in format type/id (e.g. team/engineering).");
322
- process.exit(1);
323
- }
324
- const [groupType, groupId] = parts;
325
- try {
326
- const result = await client.grantCollectionGroupPermission(resolvedAppId, collectionId, {
327
- groupType,
328
- groupId,
329
- permission: options.permission,
330
- });
331
- if (options.json) {
332
- json(result);
333
- return;
334
- }
335
- success(`Granted ${options.permission} access to ${groupType}/${groupId} on collection.`);
336
- }
337
- catch (err) {
338
- error(err.message);
339
- process.exit(1);
340
- }
341
- });
342
- collections
343
- .command("unshare")
344
- .description("Revoke a group's access to a collection")
345
- .argument("<collection-id>", "Collection ID")
346
- .requiredOption("--group <group>", "Group in format type/id (e.g. team/engineering)")
347
- .option("--app <app-id>", "App ID")
348
- .option("-y, --yes", "Skip confirmation prompt")
349
- .option("--json", "Output as JSON")
350
- .action(async (collectionId, options) => {
351
- const resolvedAppId = resolveAppId(undefined, options);
352
- const parts = options.group.split("/");
353
- if (parts.length !== 2) {
354
- error("Group must be in format type/id (e.g. team/engineering).");
355
- process.exit(1);
356
- }
357
- const [groupType, groupId] = parts;
358
- if (!options.yes) {
359
- let confirm;
360
- try {
361
- confirm = await confirmPrompt(`Revoke ${groupType}/${groupId} access to collection ${collectionId}?`);
362
- }
363
- catch (err) {
364
- error(err.message);
365
- process.exit(1);
366
- }
367
- if (!confirm) {
368
- info("Cancelled.");
369
- return;
370
- }
371
- }
372
- const client = new ApiClient();
373
- try {
374
- await client.revokeCollectionGroupPermission(resolvedAppId, collectionId, groupType, groupId);
375
- if (options.json) {
376
- json({ success: true, collectionId, groupType, groupId });
377
- return;
378
- }
379
- success(`Revoked ${groupType}/${groupId} access from collection.`);
380
- }
381
- catch (err) {
382
- error(err.message);
383
- process.exit(1);
384
- }
385
- });
386
306
  // ---- Documents subcommand group ----
387
307
  const documents = collections
388
308
  .command("documents")
@@ -526,18 +446,17 @@ Ownership:
526
446
  }
527
447
  });
528
448
  // ---- Members subcommand group ----
449
+ //
450
+ // The one home for who holds a role on a collection: users and groups,
451
+ // addressed as principals (`<user-id>`, `group:<group-id>`). Writes go
452
+ // through the admin API, as the console's do, so the owner row can be
453
+ // restored and demoted from here.
529
454
  const members = collections
530
455
  .command("members")
531
- .description("Manage individual user access to a collection");
532
- // List members
533
- //
534
- // The server has no GET /collections/:id/members route — membership is read
535
- // from the access endpoint, which returns groups and members together. This
536
- // command is the members half of it, so reading "who is on this collection"
537
- // doesn't require knowing about a command named for neither (#2764).
456
+ .description("Manage a collection's members — users and groups — and their roles");
538
457
  members
539
458
  .command("list")
540
- .description("List users with direct access to a collection")
459
+ .description("List a collection's members, users and groups, with their roles")
541
460
  .argument("<collection-id>", "Collection ID")
542
461
  .option("--app <app-id>", "App ID")
543
462
  .option("--json", "Output as JSON")
@@ -545,21 +464,20 @@ Ownership:
545
464
  const resolvedAppId = resolveAppId(undefined, options);
546
465
  const client = new ApiClient();
547
466
  try {
548
- const result = await client.getCollectionAccess(resolvedAppId, collectionId);
549
- const list = result.members ?? [];
467
+ const { items } = await client.listCollectionMembers(resolvedAppId, collectionId);
550
468
  if (options.json) {
551
- // The members half of the access payload, in the one list envelope
552
- // (#3646) — the same shape `groups members list` prints (#2764).
553
- json(wholeListEnvelope(list));
469
+ // The whole membership, in the one list envelope (#3646).
470
+ json(wholeListEnvelope(items));
554
471
  return;
555
472
  }
556
- if (list.length === 0) {
557
- info("No members have direct access to this collection. Groups may still have access — see 'collections access'.");
473
+ if (items.length === 0) {
474
+ info("No user or group holds a role on this collection.");
558
475
  return;
559
476
  }
560
- console.log(formatTable(list, [
561
- { header: "USER_ID", key: "userId", format: formatId },
562
- { header: "PERMISSION", key: "permission" },
477
+ console.log(formatTable(items, [
478
+ { header: "PRINCIPAL", key: "principal" },
479
+ { header: "ROLE", key: "role" },
480
+ { header: "ADDED", key: "addedAt", format: formatDate },
563
481
  ]));
564
482
  }
565
483
  catch (err) {
@@ -567,49 +485,97 @@ Ownership:
567
485
  process.exit(1);
568
486
  }
569
487
  });
570
- // Add member
571
488
  members
572
489
  .command("add")
573
- .description("Add a user to a collection")
490
+ .description("Give a user or a group a role on a collection")
574
491
  .argument("<collection-id>", "Collection ID")
575
- .argument("<user-id>", "User ID")
576
- .requiredOption("--permission <permission>", "Permission level (reader or read-write)")
492
+ .argument("<principal>", "A user id, or group:<group-id>")
493
+ .requiredOption("--role <role>", "viewer, contributor, editor or manager (a group holds up to manager); owner restores the custodian's owner row")
577
494
  .option("--app <app-id>", "App ID")
578
495
  .option("--json", "Output as JSON")
579
- .action(async (collectionId, userId, options) => {
496
+ .allowExcessArguments(false)
497
+ .action(async (collectionId, principalArg, options) => {
498
+ let principal;
499
+ let role;
500
+ try {
501
+ principal = parseCollectionPrincipal(principalArg);
502
+ role = parseCollectionRole(options.role);
503
+ }
504
+ catch (err) {
505
+ error(err.message);
506
+ process.exit(1);
507
+ }
580
508
  const resolvedAppId = resolveAppId(undefined, options);
581
509
  const client = new ApiClient();
582
510
  try {
583
- const result = await client.addCollectionMember(resolvedAppId, collectionId, {
584
- userId,
585
- permission: options.permission,
586
- });
511
+ const result = await client.addCollectionMember(resolvedAppId, collectionId, { ...principal, role: role });
587
512
  if (options.json) {
588
513
  json(result);
589
514
  return;
590
515
  }
591
- success(`User ${userId} added to collection with ${options.permission} access.`);
516
+ success(`${principalArg} holds ${result.role ?? role} on collection ${collectionId}.`);
517
+ }
518
+ catch (err) {
519
+ error(err.message);
520
+ process.exit(1);
521
+ }
522
+ });
523
+ members
524
+ .command("set-role")
525
+ .description("Change a collection member's role")
526
+ .argument("<collection-id>", "Collection ID")
527
+ .argument("<principal>", "A user id, or group:<group-id>")
528
+ .argument("<role>", "owner, manager, editor, contributor or viewer")
529
+ .option("--app <app-id>", "App ID")
530
+ .option("--json", "Output as JSON")
531
+ .allowExcessArguments(false)
532
+ .action(async (collectionId, principalArg, roleArg, options) => {
533
+ let role;
534
+ try {
535
+ parseCollectionPrincipal(principalArg);
536
+ role = parseCollectionRole(roleArg);
537
+ }
538
+ catch (err) {
539
+ error(err.message);
540
+ process.exit(1);
541
+ }
542
+ const resolvedAppId = resolveAppId(undefined, options);
543
+ const client = new ApiClient();
544
+ try {
545
+ const result = await client.setCollectionMemberRole(resolvedAppId, collectionId, principalArg, role);
546
+ if (options.json) {
547
+ json(result);
548
+ return;
549
+ }
550
+ success(`${principalArg} is now ${result.role ?? role} on collection ${collectionId}.`);
592
551
  }
593
552
  catch (err) {
594
553
  error(err.message);
595
554
  process.exit(1);
596
555
  }
597
556
  });
598
- // Remove member
599
557
  members
600
558
  .command("remove")
601
- .description("Remove a user from a collection")
559
+ .description("Remove a user or a group from a collection")
602
560
  .argument("<collection-id>", "Collection ID")
603
- .argument("<user-id>", "User ID")
561
+ .argument("<principal>", "A user id, or group:<group-id>")
604
562
  .option("--app <app-id>", "App ID")
605
563
  .option("-y, --yes", "Skip confirmation prompt")
606
564
  .option("--json", "Output as JSON")
607
- .action(async (collectionId, userId, options) => {
565
+ .allowExcessArguments(false)
566
+ .action(async (collectionId, principalArg, options) => {
567
+ try {
568
+ parseCollectionPrincipal(principalArg);
569
+ }
570
+ catch (err) {
571
+ error(err.message);
572
+ process.exit(1);
573
+ }
608
574
  const resolvedAppId = resolveAppId(undefined, options);
609
575
  if (!options.yes) {
610
576
  let confirm;
611
577
  try {
612
- confirm = await confirmPrompt(`Remove user ${userId} from collection ${collectionId}?`);
578
+ confirm = await confirmPrompt(`Remove ${principalArg} from collection ${collectionId}?`);
613
579
  }
614
580
  catch (err) {
615
581
  error(err.message);
@@ -622,12 +588,12 @@ Ownership:
622
588
  }
623
589
  const client = new ApiClient();
624
590
  try {
625
- await client.removeCollectionMember(resolvedAppId, collectionId, userId);
591
+ await client.removeCollectionMember(resolvedAppId, collectionId, principalArg);
626
592
  if (options.json) {
627
- json({ success: true, collectionId, userId });
593
+ json({ success: true, collectionId, principal: principalArg });
628
594
  return;
629
595
  }
630
- success(`User ${userId} removed from collection.`);
596
+ success(`${principalArg} removed from collection.`);
631
597
  }
632
598
  catch (err) {
633
599
  error(err.message);
@@ -648,12 +614,13 @@ Ownership:
648
614
  * whole app. Owner and member identities travel as EMAILS wherever the server
649
615
  * can resolve one: users are app-scoped (`models.yaml`), so the same person is
650
616
  * a different userId in every app and a recorded source userId means nothing
651
- * in the target.
617
+ * in the target. Custody and roles travel as they are: `app` or the owner,
618
+ * and each member's and group's role.
652
619
  */
653
620
  function registerCollectionsExport(collections) {
654
621
  collections
655
622
  .command("export")
656
- .description("Export every collection in an app (name, owner, members, documents, group grants)")
623
+ .description("Export every collection in an app (name, custodian, members and groups with roles, documents)")
657
624
  .option("--app <app-id>", "App ID")
658
625
  .option("--output <dir>", "Output directory", "./primitive-export")
659
626
  .option("--json", "Output as JSON")
@@ -665,6 +632,9 @@ that 'documents export-all' writes, so one directory is one app's migration.
665
632
  Import it with 'primitive collections import' AFTER 'documents import', which
666
633
  preserves document ids.
667
634
 
635
+ The file records each collection's custodian (the app, or the user holding
636
+ the owner row), its settings, and every member's and group's role.
637
+
668
638
  Owner and member identities are recorded as emails wherever the server can
669
639
  resolve one — users are app-scoped, so a source app's userId means nothing in
670
640
  the target. A userId with no resolvable email is recorded as-is and will only
@@ -750,30 +720,34 @@ async function exportCollections(client, appId, options) {
750
720
  const collectionId = row.collectionId;
751
721
  try {
752
722
  const documents = await readAllCollectionDocuments(client, appId, collectionId);
753
- const access = await client.getCollectionAccess(appId, collectionId);
723
+ const roster = await client.listCollectionMembers(appId, collectionId);
754
724
  const members = [];
755
- for (const m of access?.members ?? []) {
756
- members.push({
757
- ...(await identity(m.userId)),
758
- permission: m.permission,
759
- });
725
+ const groups = [];
726
+ for (const m of roster.items) {
727
+ // `permission` and `groupType` stay beside `role`: a CLI written
728
+ // before roles reads them, and a group written before the role model
729
+ // resolves only with its type.
730
+ const permission = m.permission ?? permissionForRole(m.role);
731
+ if (m.groupId) {
732
+ // The server already leaves system groups out of the member list.
733
+ groups.push({ groupType: m.groupType, groupId: m.groupId, permission, role: m.role });
734
+ }
735
+ else if (m.userId) {
736
+ members.push({ ...(await identity(m.userId)), permission, role: m.role });
737
+ }
760
738
  }
761
- const groups = (access?.groups ?? [])
762
- // The server already filters system groups out of this response; a
763
- // `_`-prefixed type could never be re-granted anyway (it is reserved).
764
- .filter((g) => !String(g.groupType).startsWith("_"))
765
- .map((g) => ({
766
- groupType: g.groupType,
767
- groupId: g.groupId,
768
- permission: g.permission,
769
- }));
739
+ // A row created before custody has none (null); its creator holds the
740
+ // owner row and is recorded as the owner.
741
+ const ownerUserId = custodianUserId(rowCustodian(row));
770
742
  exported.push({
771
743
  collectionId,
772
744
  name: row.name,
773
745
  description: row.description ?? null,
774
746
  collectionType: row.collectionType ?? null,
775
747
  createdAt: row.createdAt ?? null,
776
- owner: row.createdBy ? await identity(row.createdBy) : null,
748
+ custodian: typeof row.custodian === "string" && row.custodian ? row.custodian : null,
749
+ owner: ownerUserId ? await identity(ownerUserId) : null,
750
+ settings: row.settings ?? null,
777
751
  documents,
778
752
  members,
779
753
  groups,
@@ -845,21 +819,34 @@ async function exportCollections(client, appId, options) {
845
819
  * go first ON PURPOSE: `addDocument` materializes every existing grant
846
820
  * onto a newly added document, so a fresh collection's access never
847
821
  * depends on the grant's own fan-out over the document list (F4).
822
+ *
823
+ * A collection is created through the admin route with its custodian — the
824
+ * owner resolved by email, or the app — so the server writes the owner row;
825
+ * members and groups are then replayed by role through the admin member
826
+ * route (#4731).
848
827
  */
849
828
  function registerCollectionsImport(collections) {
850
829
  collections
851
830
  .command("import")
852
- .description("Recreate collections from a collections.json export (owner, members, documents, group grants)")
831
+ .description("Recreate collections from a collections.json export (custodian, members and groups with roles, documents)")
853
832
  .argument("<path>", "Export directory holding collections.json, or the file itself")
854
833
  .option("--app <app-id>", "App ID")
855
- .option("--owner <userId-or-email>", "Own every imported collection with this user, instead of the owner each one records")
834
+ .option("--owner <userId-or-email>", "Give every imported collection this user as custodian and owner, instead of the custodian each one records")
856
835
  .option("--overwrite", "Merge into a collection that already carries the same name")
857
836
  .option("--dry-run", "Show the plan and the problems without writing anything")
858
837
  .option("--json", "Output as JSON")
859
838
  .addHelpText("after", `
860
- For admin tokens. Assigning an owner is admin-only, so under an app-user token
861
- the server creates every collection owned by the caller and each one whose
862
- recorded owner is somebody else is reported as an 'owner' problem.
839
+ Needs an admin token assigned to the app, checked before anything is read or
840
+ written: each collection is created through the admin API with the custodian
841
+ the file records — the app, or the owner, who holds the owner row — and
842
+ members and groups are added at the role the file records, through the admin
843
+ member routes. The custodian's own row follows the file too: a role below
844
+ owner is replayed, and a newly created collection whose file records no row
845
+ for its custodian has the owner row removed again. A member recorded as owner
846
+ who is not the custodian (with --owner, the recorded owner) is reported as an
847
+ 'owner' problem and not imported. A file written before roles is read with
848
+ reader as viewer and read-write as editor, and its owner's own read-write row
849
+ as the owner row.
863
850
 
864
851
  Run 'primitive documents import' FIRST: it preserves document ids, which is
865
852
  what the collections file refers to.
@@ -869,16 +856,16 @@ app's userId means nothing here. A recorded userId is used only when the file
869
856
  came from this same app.
870
857
 
871
858
  Matching is by name. Without --overwrite a name already in the target is
872
- skipped; with it, the collection is merged — but only when its owner, type and
873
- context id match, since none of those can be changed after creation.
859
+ skipped; with it, the collection is merged — but only when its custodian and
860
+ type match, since neither can be changed by a merge.
874
861
  A name more than one collection in the target carries is ambiguous: that
875
862
  collection is refused as a 'collection' problem naming every matching id, with
876
863
  or without --overwrite, and nothing is written for it. A name repeated inside
877
864
  the file is refused for the second and later occurrences, since matching by
878
865
  name could not tell them apart.
879
866
 
880
- A group grant the target already holds at another level is UPDATED to the level
881
- the file records, and what the group can reach follows the change. On a
867
+ A group or member the target already holds at another role is UPDATED to the
868
+ role the file records, and what the group can reach follows the change. On a
882
869
  collection holding more than 200 documents the server refuses a collection-wide
883
870
  group change whole (COLLECTION_FANOUT_LIMIT): that is reported as a 'group'
884
871
  problem, and the rest of the collection is still merged.
@@ -905,8 +892,39 @@ Exit code 1 when any per-item problem was reported. A skip is not a problem.
905
892
  function isNotFound(err) {
906
893
  return err?.statusCode === 404;
907
894
  }
895
+ /**
896
+ * The recorded type of a grant's group, sent beside its id: a group written
897
+ * before the role model carries no public id, and resolves only by its type.
898
+ */
899
+ function groupTypeOf(grant) {
900
+ return grant.groupType ? { groupType: grant.groupType } : {};
901
+ }
902
+ /**
903
+ * The import's writes all go through the admin API, so an app user's token —
904
+ * the app owner's included — could apply only part of a file (a merge's
905
+ * documents through the app route, and nothing else). Refused before any read
906
+ * of the target app (E14). The probe is one row of an admin-API read on the
907
+ * app, behind the same app-assignment gate as the admin create.
908
+ */
909
+ async function requireAdminAppAccess(client, appId) {
910
+ try {
911
+ await client.listGroupsByCustodian(appId, "app", { limit: 1 });
912
+ }
913
+ catch (err) {
914
+ const status = err?.statusCode;
915
+ if (status === 401 || status === 403 || status === 404) {
916
+ throw new Error(`collections import needs an admin token assigned to app ${appId}: it ` +
917
+ `creates collections and replays members through the admin API ` +
918
+ `(${serverReason(err)}). Log in as an admin of the app and re-run. ` +
919
+ `Nothing has been written.`);
920
+ }
921
+ throw new Error(`Checking admin access to app ${appId} failed: ${err?.message ?? err}. ` +
922
+ `Nothing has been written.`);
923
+ }
924
+ }
908
925
  async function importCollections(client, appId, importPath, options) {
909
926
  const file = readCollectionExportFile(importPath);
927
+ await requireAdminAppAccess(client, appId);
910
928
  // A file exported before the platform removed collection `contextId` (#3926)
911
929
  // still carries it. Said once for the run, on stderr, and never sent: the
912
930
  // server refuses the key, and the binding belongs in a metadata category.
@@ -1033,7 +1051,9 @@ async function importCollections(client, appId, importPath, options) {
1033
1051
  };
1034
1052
  let ownerUserId = explicitOwnerUserId ?? null;
1035
1053
  let ownerReason;
1036
- if (!ownerUserId) {
1054
+ // App custody needs no owner; `--owner` gives every collection one.
1055
+ const appCustody = !explicitOwnerUserId && source.custodian === "app";
1056
+ if (!ownerUserId && !appCustody) {
1037
1057
  try {
1038
1058
  const resolved = await resolveIdentity(source.owner);
1039
1059
  ownerUserId = resolved.userId;
@@ -1047,6 +1067,7 @@ async function importCollections(client, appId, importPath, options) {
1047
1067
  const row = planCollection(source, {
1048
1068
  ownerUserId,
1049
1069
  ownerReason,
1070
+ appCustody,
1050
1071
  existing: matches.length === 1 ? matches[0] : null,
1051
1072
  ambiguousTargetIds: matches.length > 1 ? matches.map((m) => m.collectionId) : null,
1052
1073
  duplicateOfSourceId: duplicates.get(source.collectionId) ?? null,
@@ -1058,33 +1079,36 @@ async function importCollections(client, appId, importPath, options) {
1058
1079
  planned.push({ row, source, grants: [], members: [], documents: [] });
1059
1080
  continue;
1060
1081
  }
1061
- // What the target already grants, so a merge can compare levels.
1082
+ // What the target already grants, so a merge can compare roles.
1062
1083
  let targetGrants = [];
1063
1084
  if (row.action === "merge" && row.targetCollectionId) {
1064
1085
  try {
1065
- const access = await client.getCollectionAccess(appId, row.targetCollectionId);
1066
- targetGrants = (access?.groups ?? []).map((g) => ({
1067
- groupType: g.groupType,
1068
- groupId: g.groupId,
1069
- permission: g.permission,
1086
+ const roster = await client.listCollectionMembers(appId, row.targetCollectionId);
1087
+ targetGrants = roster.items
1088
+ .filter((m) => m.groupId)
1089
+ .map((m) => ({
1090
+ groupId: m.groupId,
1091
+ ...(m.groupType ? { groupType: m.groupType } : {}),
1092
+ role: m.role,
1070
1093
  }));
1071
1094
  }
1072
1095
  catch (err) {
1073
- fatal(`the access of ${row.targetCollectionId}`, err);
1096
+ fatal(`the members of ${row.targetCollectionId}`, err);
1074
1097
  }
1075
1098
  }
1076
1099
  const grants = [];
1077
1100
  for (const grant of source.groups ?? []) {
1078
- const label = `${grant.groupType}/${grant.groupId}`;
1079
- // The server reserves the `_` prefix for its own system groups; an
1080
- // export never writes one, and re-granting one is a 400.
1081
- if (String(grant.groupType).startsWith("_")) {
1082
- warn(`${source.name}: skipping the reserved group type ${grant.groupType} ` +
1101
+ const label = `group:${grant.groupId}`;
1102
+ // The server reserves the `_` group-type prefix for its own system
1103
+ // groups; an export never writes one, and re-granting one is a 400. A
1104
+ // group id may start with `_` (only the type is reserved).
1105
+ if (String(grant.groupType ?? "").startsWith("_")) {
1106
+ warn(`${source.name}: skipping the reserved group ${grant.groupType ? `type ${grant.groupType} ` : ""}` +
1083
1107
  `(${label}); the server manages those itself.`);
1084
1108
  continue;
1085
1109
  }
1086
1110
  try {
1087
- await client.getGroup(appId, grant.groupType, grant.groupId);
1111
+ await client.getGroup(appId, grant.groupId, groupTypeOf(grant));
1088
1112
  }
1089
1113
  catch (err) {
1090
1114
  if (isNotFound(err)) {
@@ -1094,14 +1118,16 @@ async function importCollections(client, appId, importPath, options) {
1094
1118
  fatal(`group ${label}`, err);
1095
1119
  }
1096
1120
  const disposition = grantDisposition(grant, targetGrants);
1097
- const existing = targetGrants.find((g) => g.groupType === grant.groupType && g.groupId === grant.groupId);
1121
+ const existing = targetGrants.find((g) => sameGrantGroup(g, grant));
1098
1122
  grants.push({
1099
1123
  grant,
1100
1124
  disposition,
1101
- ...(existing ? { existingPermission: existing.permission } : {}),
1125
+ ...(existing ? { existingRole: existing.role } : {}),
1102
1126
  });
1103
1127
  }
1128
+ const custodianUser = row.custodian ? custodianUserId(row.custodian) : null;
1104
1129
  const members = [];
1130
+ let custodianRecorded = false;
1105
1131
  for (const member of source.members ?? []) {
1106
1132
  let resolved;
1107
1133
  try {
@@ -1115,8 +1141,32 @@ async function importCollections(client, appId, importPath, options) {
1115
1141
  note("member", resolved.id, resolved.reason);
1116
1142
  continue;
1117
1143
  }
1118
- members.push({ userId: resolved.userId, permission: member.permission });
1144
+ if (resolved.userId === custodianUser) {
1145
+ // The custodian's own row is replayed as the file records it: a role
1146
+ // below owner demotes the owner row custody wrote, and on a merge an
1147
+ // owner entry restores it. A create's owner entry is already written.
1148
+ custodianRecorded = true;
1149
+ if (row.action === "create" && member.role === "owner")
1150
+ continue;
1151
+ members.push({ userId: resolved.userId, role: member.role });
1152
+ continue;
1153
+ }
1154
+ if (member.role === "owner") {
1155
+ // The owner row is the custodian's alone; anyone else recorded as
1156
+ // owner is invalid data, reported rather than granted another role.
1157
+ note("owner", resolved.id, `recorded as owner, but the owner row belongs to the custodian ` +
1158
+ `(${row.custodian}); not imported`);
1159
+ continue;
1160
+ }
1161
+ members.push({ userId: resolved.userId, role: member.role });
1119
1162
  }
1163
+ // A user custodian the file records no row for had it removed in the
1164
+ // source; a create writes one, so it goes again. `--owner` names a new
1165
+ // custodian the file cannot speak for, and a merge leaves rows it does not
1166
+ // record alone.
1167
+ const removeOwnerRowOf = row.action === "create" && custodianUser && !custodianRecorded && !explicitOwnerUserId
1168
+ ? custodianUser
1169
+ : undefined;
1120
1170
  const documents = [];
1121
1171
  for (const document of source.documents ?? []) {
1122
1172
  try {
@@ -1132,7 +1182,7 @@ async function importCollections(client, appId, importPath, options) {
1132
1182
  }
1133
1183
  documents.push(document.documentId);
1134
1184
  }
1135
- planned.push({ row, source, grants, members, documents });
1185
+ planned.push({ row, source, grants, members, ...(removeOwnerRowOf ? { removeOwnerRowOf } : {}), documents });
1136
1186
  }
1137
1187
  // ── Apply phase ────────────────────────────────────────────────────────
1138
1188
  for (const entry of planned) {
@@ -1167,38 +1217,41 @@ async function importCollections(client, appId, importPath, options) {
1167
1217
  summary.merged += 1;
1168
1218
  info(`[dry-run] Would merge ${source.name} into ${row.targetCollectionId}`);
1169
1219
  }
1170
- for (const { grant, disposition, existingPermission } of entry.grants) {
1220
+ for (const { grant, disposition, existingRole } of entry.grants) {
1171
1221
  if (disposition === "already-applied")
1172
1222
  continue;
1173
- const label = `${grant.groupType}/${grant.groupId}`;
1223
+ const label = `group:${grant.groupId}`;
1174
1224
  info(disposition === "update"
1175
- ? `[dry-run] Would update ${grantUpdateLine(label, existingPermission, grant.permission)}`
1176
- : `[dry-run] Would grant ${label} ${grant.permission}`);
1225
+ ? `[dry-run] Would update ${grantUpdateLine(label, existingRole, grant.role)}`
1226
+ : `[dry-run] Would grant ${label} ${grant.role}`);
1177
1227
  summary.groupsGranted += 1;
1178
1228
  }
1179
1229
  summary.membersAdded += entry.members.length;
1230
+ if (entry.removeOwnerRowOf) {
1231
+ info(`[dry-run] Would remove the owner row of ${entry.removeOwnerRowOf} ` +
1232
+ `(the export records no membership for the custodian)`);
1233
+ }
1180
1234
  summary.documentsAdded += entry.documents.length;
1181
1235
  continue;
1182
1236
  }
1183
1237
  let targetCollectionId = row.targetCollectionId;
1184
1238
  if (row.action === "create") {
1185
1239
  try {
1186
- const created = await client.createCollection(appId, {
1240
+ const created = await client.createCollectionAsAdmin(appId, {
1187
1241
  name: source.name,
1188
1242
  ...(source.description ? { description: source.description } : {}),
1189
1243
  ...(source.collectionType ? { collectionType: source.collectionType } : {}),
1190
- createdBy: row.ownerUserId,
1244
+ custodian: row.custodian,
1245
+ ...(source.settings ? { settings: source.settings } : {}),
1191
1246
  });
1192
1247
  targetCollectionId = created.collectionId;
1193
1248
  row.targetCollectionId = targetCollectionId;
1194
1249
  summary.created += 1;
1195
1250
  info(`Created ${source.name} as ${targetCollectionId}`);
1196
- // Whom the server CREDITED is the answer. A server predating #3641
1197
- // ignores the field, and so does any server for a non-admin token.
1198
- if (created.createdBy && created.createdBy !== row.ownerUserId) {
1199
- note("owner", row.ownerUserId, `the server did not assign the owner (it credited ` +
1200
- `${created.createdBy}); the token is not an admin one, or the ` +
1201
- `server predates #3641`);
1251
+ // The custodian the server RECORDED is the answer.
1252
+ if (created.custodian && created.custodian !== row.custodian) {
1253
+ note("owner", row.custodian, `the server recorded ${created.custodian} as custodian, not ` +
1254
+ `${row.custodian}`);
1202
1255
  }
1203
1256
  }
1204
1257
  catch (err) {
@@ -1210,21 +1263,21 @@ async function importCollections(client, appId, importPath, options) {
1210
1263
  summary.merged += 1;
1211
1264
  info(`Merged ${source.name} into ${targetCollectionId}`);
1212
1265
  }
1213
- for (const { grant, disposition, existingPermission } of entry.grants) {
1266
+ for (const { grant, disposition, existingRole } of entry.grants) {
1214
1267
  if (disposition === "already-applied")
1215
1268
  continue;
1216
- const label = `${grant.groupType}/${grant.groupId}`;
1269
+ const label = `group:${grant.groupId}`;
1217
1270
  try {
1218
- await client.grantCollectionGroupPermission(appId, targetCollectionId, {
1219
- groupType: grant.groupType,
1271
+ await client.addCollectionMember(appId, targetCollectionId, {
1220
1272
  groupId: grant.groupId,
1221
- permission: grant.permission,
1273
+ ...groupTypeOf(grant),
1274
+ role: grant.role,
1222
1275
  });
1223
1276
  summary.groupsGranted += 1;
1224
- // A level change is worth saying out loud: it is the one grant write
1277
+ // A role change is worth saying out loud: it is the one grant write
1225
1278
  // that can take access away from people who already had it.
1226
1279
  if (disposition === "update") {
1227
- info(`Updated ${grantUpdateLine(label, existingPermission, grant.permission)}`);
1280
+ info(`Updated ${grantUpdateLine(label, existingRole, grant.role)}`);
1228
1281
  }
1229
1282
  }
1230
1283
  catch (err) {
@@ -1235,10 +1288,9 @@ async function importCollections(client, appId, importPath, options) {
1235
1288
  try {
1236
1289
  const result = await client.addCollectionMember(appId, targetCollectionId, {
1237
1290
  userId: member.userId,
1238
- permission: member.permission,
1291
+ role: member.role,
1239
1292
  });
1240
- // `already_member` is the server saying it was already so — including
1241
- // the owner's own `_col-writer` enrolment, which every export records.
1293
+ // `already_member` is the server saying it already held that role.
1242
1294
  if (result?.status !== "already_member")
1243
1295
  summary.membersAdded += 1;
1244
1296
  }
@@ -1246,6 +1298,16 @@ async function importCollections(client, appId, importPath, options) {
1246
1298
  note("member", member.userId, serverReason(err));
1247
1299
  }
1248
1300
  }
1301
+ if (entry.removeOwnerRowOf) {
1302
+ try {
1303
+ await client.removeCollectionMember(appId, targetCollectionId, entry.removeOwnerRowOf);
1304
+ info(`Removed the owner row of ${entry.removeOwnerRowOf} from ${source.name}: ` +
1305
+ `the export records no membership for the custodian`);
1306
+ }
1307
+ catch (err) {
1308
+ note("owner", entry.removeOwnerRowOf, serverReason(err));
1309
+ }
1310
+ }
1249
1311
  for (const documentId of entry.documents) {
1250
1312
  try {
1251
1313
  await client.addCollectionDocument(appId, targetCollectionId, { documentId });