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,10 +1,232 @@
1
+ import { readFileSync } from "fs";
2
+ import { commandStatus } from "../lib/command-status.js";
1
3
  import { ApiClient } from "../lib/api-client.js";
2
4
  import { resolveAppId } from "../lib/config.js";
3
- import { success, error, info, keyValue, formatTable, formatId, formatDate, json, } from "../lib/output.js";
5
+ import { success, error, info, warn, keyValue, formatTable, formatId, formatDate, formatStatus, json, } from "../lib/output.js";
4
6
  import { confirmPrompt } from "../lib/confirm-prompt.js";
5
7
  import { warnDeprecated } from "../lib/deprecation.js";
8
+ import { TEST_USERS_MODES } from "../lib/test-users.js";
6
9
  import { pageCursorOption, pageLimitOption, parsePageLimit, printEmptyPage, printPageHint, } from "../lib/list-options.js";
7
10
  import { normalizeCliListEnvelope, wholeListEnvelope, } from "../lib/paginate.js";
11
+ import { parseFilterOptions } from "../lib/record-filter.js";
12
+ import { renderAggregateResult } from "../lib/aggregate-output.js";
13
+ import { describeRecordsFailure } from "./documents.js";
14
+ import { EXIT_TIMED_OUT } from "../lib/function-run.js";
15
+ import { USER_INDEX_LIMIT_FLAGS, USER_PROPERTIES_CAP_FLAGS, USER_INDEX_WAIT_DEFAULT_SECONDS, UserIndexFlagError, collectOption, formatLastSliceLine, formatReconcileCounts, formatRevalidationLine, formatSliceCounts, formatUserIndexShards, limitsPatchOf, parseWaitTimeout, revalidationComplete, sumSliceCounts, waitForUserIndex, } from "../lib/user-index.js";
16
+ import { walkCounts, walkStartBodyOf, walkStatusLines, waitForUserWalk } from "../lib/user-walk.js";
17
+ /** The aggregate operations `users aggregate` takes. */
18
+ const AGGREGATE_OPS = ["count", "sum", "avg", "min", "max"];
19
+ /** The date periods a `--group-by <field>:<period>` level takes. */
20
+ const GROUP_BY_PERIODS = ["month", "quarter", "year"];
21
+ /** A `--group-by` value as a level: `<field>:<period>` is a date period, anything else a field. */
22
+ function groupByLevel(value) {
23
+ const at = value.lastIndexOf(":");
24
+ if (at > 0 && GROUP_BY_PERIODS.includes(value.slice(at + 1)))
25
+ return { field: value.slice(0, at), period: value.slice(at + 1) };
26
+ return value;
27
+ }
28
+ /** A JSON flag's value parsed, or exit naming the flag; `undefined` when the flag is absent. */
29
+ function parseJsonFlag(flag, raw) {
30
+ if (raw === undefined)
31
+ return undefined;
32
+ try {
33
+ return JSON.parse(raw);
34
+ }
35
+ catch {
36
+ error(`Invalid ${flag} JSON.`);
37
+ process.exit(1);
38
+ }
39
+ }
40
+ /** `--initial-properties` parsed: a JSON object of property names to values, or exit naming the flag; `undefined` when absent. */
41
+ function initialPropertiesFlag(raw) {
42
+ const value = parseJsonFlag("--initial-properties", raw);
43
+ if (value === undefined)
44
+ return undefined;
45
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
46
+ error("--initial-properties must be a JSON object of property names to values.");
47
+ process.exit(1);
48
+ }
49
+ return value;
50
+ }
51
+ /** `[app-id] [user-id]` as set-profile reads them: one argument is the user, two are the app and the user. */
52
+ function appAndUser(appIdOrUserId, userIdOrUndefined, options) {
53
+ const appId = userIdOrUndefined ? resolveAppId(appIdOrUserId, options) : resolveAppId(undefined, options);
54
+ const userId = userIdOrUndefined ?? appIdOrUserId;
55
+ if (!userId) {
56
+ error("User ID is required.");
57
+ process.exit(1);
58
+ }
59
+ return { appId, userId };
60
+ }
61
+ /** A command-line value as JSON when it parses, else the string itself (`12` is a number, `ada` a string). */
62
+ function jsonOrString(value) {
63
+ try {
64
+ return JSON.parse(value);
65
+ }
66
+ catch {
67
+ return value;
68
+ }
69
+ }
70
+ /** A refusal as the server named it: its code, then its message. */
71
+ function describeUserPropertyFailure(err) {
72
+ return err?.code ? `${err.code}: ${err.message}` : String(err?.message ?? err);
73
+ }
74
+ /** The repeatable `<field>=<value>` options of one set operation, grouped by field; exit naming the flag on a malformed one. */
75
+ function setMembersOf(flag, pairs) {
76
+ if (pairs.length === 0)
77
+ return undefined;
78
+ // Grouped in a Map: a field named like an Object.prototype member (`toString`) is still just a field.
79
+ const members = new Map();
80
+ for (const pair of pairs) {
81
+ const at = pair.indexOf("=");
82
+ if (at <= 0) {
83
+ error(`${flag} takes <field>=<value>, e.g. ${flag} tags=beta; got "${pair}".`);
84
+ process.exit(1);
85
+ }
86
+ const field = pair.slice(0, at);
87
+ const values = members.get(field) ?? [];
88
+ values.push(pair.slice(at + 1));
89
+ members.set(field, values);
90
+ }
91
+ return Object.fromEntries(members);
92
+ }
93
+ /** `users set-properties`'s flags as one write; exit naming what is wrong before any request. */
94
+ function propertiesWriteOf(options) {
95
+ const usage = "Pass at least one of --data, --data-file, --unset, --add-to-set, --remove-from-set.";
96
+ if (options.data !== undefined && options.dataFile !== undefined) {
97
+ error("Pass --data or --data-file, not both.");
98
+ process.exit(1);
99
+ }
100
+ let raw;
101
+ if (options.data !== undefined)
102
+ raw = parseJsonFlag("--data", options.data);
103
+ if (options.dataFile !== undefined) {
104
+ let text;
105
+ try {
106
+ text = readFileSync(options.dataFile, "utf-8");
107
+ }
108
+ catch (err) {
109
+ error(`Cannot read --data-file ${options.dataFile}: ${err.message}`);
110
+ process.exit(1);
111
+ }
112
+ raw = parseJsonFlag("--data-file", text);
113
+ }
114
+ if (raw !== undefined && (raw === null || typeof raw !== "object" || Array.isArray(raw))) {
115
+ error("--data and --data-file take a JSON object of property names to values.");
116
+ process.exit(1);
117
+ }
118
+ const patch = { ...(raw ?? {}) };
119
+ for (const field of options.unset)
120
+ patch[field] = null;
121
+ const addToSet = setMembersOf("--add-to-set", options.addToSet);
122
+ const removeFromSet = setMembersOf("--remove-from-set", options.removeFromSet);
123
+ if (Object.keys(patch).length === 0 && !addToSet && !removeFromSet) {
124
+ error(usage);
125
+ process.exit(1);
126
+ }
127
+ const condition = parseJsonFlag("--condition", options.condition);
128
+ if (condition !== undefined && (condition === null || typeof condition !== "object" || Array.isArray(condition))) {
129
+ error("--condition takes a JSON filter object.");
130
+ process.exit(1);
131
+ }
132
+ return {
133
+ ...(Object.keys(patch).length > 0 ? { patch } : {}),
134
+ ...(addToSet ? { addToSet } : {}),
135
+ ...(removeFromSet ? { removeFromSet } : {}),
136
+ ...(condition !== undefined ? { condition: condition } : {}),
137
+ };
138
+ }
139
+ /** A member's properties, one per line as JSON values; "(none)" when there are none. */
140
+ function printProperties(properties) {
141
+ console.log("Properties:");
142
+ const entries = Object.entries(properties ?? {});
143
+ if (entries.length === 0)
144
+ console.log(" (none)");
145
+ for (const [name, value] of entries)
146
+ console.log(` ${name}: ${JSON.stringify(value)}`);
147
+ }
148
+ /** A member: the roster row, then the properties. */
149
+ function printAppUser(user) {
150
+ keyValue("User ID", user.userId);
151
+ keyValue("Email", user.email ?? "");
152
+ keyValue("Name", user.name ?? "");
153
+ keyValue("Role", user.role ?? "");
154
+ keyValue("Status", formatStatus(user.status));
155
+ if (user.disabledAt)
156
+ keyValue("Disabled", formatDate(user.disabledAt));
157
+ keyValue("Added", user.addedAt ? formatDate(user.addedAt) : "");
158
+ printProperties(user.properties);
159
+ }
160
+ /** `--test-users`, refused before any request when not one of the three modes. */
161
+ function parseTestUsersMode(value) {
162
+ if (value === undefined)
163
+ return "include";
164
+ if (!TEST_USERS_MODES.includes(value)) {
165
+ error(`--test-users must be one of: ${TEST_USERS_MODES.join(", ")}.`);
166
+ process.exit(1);
167
+ }
168
+ return value;
169
+ }
170
+ /**
171
+ * Where an invitation row stands, read the way the invitation lookup reads it:
172
+ * accepted wins, then a past `expiresAt` makes it expired.
173
+ */
174
+ function invitationStatus(inv) {
175
+ if (inv.accepted)
176
+ return "accepted";
177
+ if (inv.expiresAt && new Date(inv.expiresAt) < new Date())
178
+ return "expired";
179
+ return "pending";
180
+ }
181
+ /** A server message as the middle of a sentence: its own final stop dropped. */
182
+ function withoutFinalStop(message) {
183
+ return message.replace(/[.\s]+$/, "");
184
+ }
185
+ /**
186
+ * The accept link of each invitation on a page, `null` where there is none.
187
+ *
188
+ * Only a pending invitation has one: the platform's accept URL,
189
+ * `<baseUrl>/invite/accept?inviteToken=<token>`, which the invitation email
190
+ * carries and the templates route. The base URL comes from one settings read
191
+ * and each token from one point read of that invitation, so the cost is
192
+ * bounded by the page. An app without a base URL costs no point read. A read
193
+ * that fails leaves its links `null` and says why on stderr; the listing
194
+ * itself still succeeds.
195
+ */
196
+ async function invitationAcceptLinks(client, appId, invitations) {
197
+ const links = invitations.map(() => null);
198
+ const pending = invitations
199
+ .map((inv, i) => ({ inv, i }))
200
+ .filter(({ inv }) => invitationStatus(inv) === "pending");
201
+ if (pending.length === 0)
202
+ return links;
203
+ let baseUrl;
204
+ try {
205
+ const settings = await client.getAppSettings(appId);
206
+ baseUrl = String(settings?.baseUrl ?? "").replace(/\/+$/, "");
207
+ }
208
+ catch (err) {
209
+ warn(`Accept links are unavailable: the app settings could not be read: ${withoutFinalStop(err.message)}.`);
210
+ return links;
211
+ }
212
+ if (!baseUrl) {
213
+ warn("Accept links are unavailable: the app has no base URL. " +
214
+ "Set [app].baseUrl in app.toml and run 'primitive config push --only app'.");
215
+ return links;
216
+ }
217
+ for (const { inv, i } of pending) {
218
+ try {
219
+ const read = await client.getInvitation(appId, inv.invitationId);
220
+ if (!read.inviteToken)
221
+ throw new Error("the invitation has no invite token");
222
+ links[i] = `${baseUrl}/invite/accept?inviteToken=${encodeURIComponent(read.inviteToken)}`;
223
+ }
224
+ catch (err) {
225
+ warn(`Accept link for ${inv.invitationId} unavailable: ${withoutFinalStop(err.message)}.`);
226
+ }
227
+ }
228
+ return links;
229
+ }
8
230
  export function registerUsersCommands(program) {
9
231
  const users = program
10
232
  .command("users")
@@ -12,13 +234,21 @@ export function registerUsersCommands(program) {
12
234
  .addHelpText("after", `
13
235
  Examples:
14
236
  $ primitive users list
237
+ $ primitive users list --test-users exclude
15
238
  $ primitive users create user@example.com --role admin
16
239
  $ primitive users create user@example.com --name "Ada Lovelace" --avatar-url https://example.com/ada.png
17
240
  $ primitive users set-profile 01HXY... --name "Ada Lovelace"
18
241
  $ primitive users invite user@example.com --role admin
19
242
  $ primitive users set-role 01HXY... member
20
243
  $ primitive users mint-jwt <user-id>
244
+ $ primitive users query --filter '{"role":"admin"}' --sort '{"addedAt":-1}'
245
+ $ primitive users count --filter '{"status":"disabled"}'
246
+ $ primitive users aggregate --op count --group-by role --sort '{"field":"count","direction":-1}'
247
+ $ primitive users get 01HXY...
248
+ $ primitive users get-by handle ada
249
+ $ primitive users set-properties 01HXY... --data '{"plan":"pro"}' --add-to-set tags=beta
21
250
  `);
251
+ commandStatus(users, { stability: "production" });
22
252
  // List users
23
253
  users
24
254
  .command("list")
@@ -26,11 +256,13 @@ Examples:
26
256
  .argument("[app-id]", "App ID (uses current app if not specified)")
27
257
  .option("--app <app-id>", "App ID")
28
258
  .option("--search <query>", "Filter users. ULID -> userId lookup; contains '@' -> email lookup; otherwise substring name search.")
259
+ .option("--test-users <mode>", "+primitivetest test users: include (default), exclude (real users only), or only")
29
260
  .addOption(pageLimitOption())
30
261
  .addOption(pageCursorOption())
31
262
  .option("--json", "Output as JSON")
32
263
  .action(async (appId, options) => {
33
264
  const limit = parsePageLimit(options.limit);
265
+ const testUsers = parseTestUsersMode(options.testUsers);
34
266
  const resolvedAppId = resolveAppId(appId, options);
35
267
  const client = new ApiClient();
36
268
  const params = {};
@@ -38,6 +270,9 @@ Examples:
38
270
  params.limit = limit;
39
271
  if (options.cursor)
40
272
  params.cursor = options.cursor;
273
+ // `include` is the route's default, so it sends nothing (#5104).
274
+ if (testUsers !== "include")
275
+ params.testUsers = testUsers;
41
276
  if (options.search) {
42
277
  const q = String(options.search).trim();
43
278
  // ULID is exactly 26 chars from Crockford's base32 alphabet (excludes I,L,O,U).
@@ -51,10 +286,16 @@ Examples:
51
286
  params.name = q;
52
287
  }
53
288
  try {
54
- const page = normalizeCliListEnvelope(await client.listUsers(resolvedAppId, params));
289
+ const result = await client.listUsers(resolvedAppId, params);
290
+ const page = normalizeCliListEnvelope(result);
55
291
  const usersList = page.items;
56
292
  if (options.json) {
57
- json(page);
293
+ // #5104: `scanned` says how far a filtered read got, beside the
294
+ // envelope's three keys and only when the server sent it, as
295
+ // `workflows runs list` prints it.
296
+ json(typeof result.scanned === "number"
297
+ ? { ...page, scanned: result.scanned }
298
+ : page);
58
299
  return;
59
300
  }
60
301
  if (!usersList || usersList.length === 0) {
@@ -74,6 +315,14 @@ Examples:
74
315
  key: "status",
75
316
  format: (value) => String(value || "active") === "disabled" ? "disabled" : "active",
76
317
  },
318
+ // #5104 — a `+primitivetest` fixture user looked exactly like a
319
+ // real one. Blank otherwise, including for an older server that
320
+ // sends no `testUser`.
321
+ {
322
+ header: "TEST",
323
+ key: "testUser",
324
+ format: (value) => (value === true ? "test" : ""),
325
+ },
77
326
  { header: "ADDED", key: "addedAt", format: formatDate },
78
327
  ]));
79
328
  printPageHint(page);
@@ -91,10 +340,12 @@ Examples:
91
340
  .option("--role <role>", "Role: admin or member", "member")
92
341
  .option("--name <name>", "Display name (defaults to the email's local part)")
93
342
  .option("--avatar-url <url>", "Avatar image URL (http or https)")
343
+ .option("--initial-properties <json>", "User properties to set, as a JSON object; an existing user keeps the ones already set")
94
344
  .option("--app <app-id>", "App ID")
95
345
  .option("--json", "Output as JSON")
96
346
  .action(async (email, options) => {
97
347
  const resolvedAppId = resolveAppId(undefined, options);
348
+ const initialProperties = initialPropertiesFlag(options.initialProperties);
98
349
  const client = new ApiClient();
99
350
  try {
100
351
  const result = await client.addUserByEmail(resolvedAppId, {
@@ -102,6 +353,7 @@ Examples:
102
353
  role: options.role,
103
354
  ...(options.name !== undefined ? { name: options.name } : {}),
104
355
  ...(options.avatarUrl !== undefined ? { avatarUrl: options.avatarUrl } : {}),
356
+ ...(initialProperties !== undefined ? { initialProperties } : {}),
105
357
  });
106
358
  if (options.json) {
107
359
  json(result);
@@ -116,6 +368,9 @@ Examples:
116
368
  keyValue("Name", result.name);
117
369
  if (result.avatarUrl)
118
370
  keyValue("Avatar URL", result.avatarUrl);
371
+ if (result.properties && Object.keys(result.properties).length > 0) {
372
+ keyValue("Properties", JSON.stringify(result.properties));
373
+ }
119
374
  }
120
375
  catch (err) {
121
376
  error(err.message);
@@ -170,17 +425,416 @@ Examples:
170
425
  process.exit(1);
171
426
  }
172
427
  });
428
+ // ---- The user search (#5382): query, count and aggregate over the user index ----
429
+ users
430
+ .command("query")
431
+ .description("Query an app's users with a records filter and sort (base fields bare, properties as properties.<name>)")
432
+ .option("--app <app-id>", "App ID")
433
+ .option("--filter <json>", 'Filter as JSON, e.g. \'{"role":"admin"}\' or \'{"properties.plan":"pro"}\'')
434
+ .option("--filter-file <path>", "Read filter from a JSON or TOML file")
435
+ .option("--sort <json>", 'Sort as JSON, e.g. \'{"addedAt":-1}\'; 1 ascending, -1 descending, key order is precedence; repeat it with --cursor')
436
+ .option("--limit <n>", "Users per page (default 100, at most 1000)")
437
+ .option("--cursor <cursor>", "The nextCursor or prevCursor of a previous page of the same query")
438
+ .option("--json", "Output as JSON")
439
+ .action(async (options) => {
440
+ const filter = parseFilterOptions(options);
441
+ const sort = parseJsonFlag("--sort", options.sort);
442
+ const limit = parsePageLimit(options.limit);
443
+ const resolvedAppId = resolveAppId(undefined, options);
444
+ const client = new ApiClient();
445
+ try {
446
+ const page = await client.queryUsers(resolvedAppId, {
447
+ ...(filter !== undefined ? { filter } : {}),
448
+ ...(sort !== undefined ? { sort } : {}),
449
+ ...(limit !== undefined ? { limit } : {}),
450
+ ...(options.cursor ? { cursor: options.cursor } : {}),
451
+ });
452
+ if (options.json) {
453
+ json(page);
454
+ return;
455
+ }
456
+ if (page.items.length === 0) {
457
+ printEmptyPage(page, "users");
458
+ return;
459
+ }
460
+ const withProperties = page.items.some((user) => user.properties && Object.keys(user.properties).length > 0);
461
+ console.log(formatTable(page.items, [
462
+ { header: "ID", key: "userId", format: formatId },
463
+ { header: "EMAIL", key: "email" },
464
+ { header: "NAME", key: "name" },
465
+ { header: "ROLE", key: "role" },
466
+ { header: "STATUS", key: "status" },
467
+ { header: "ADDED", key: "addedAt", format: formatDate },
468
+ ...(withProperties ? [{ header: "PROPERTIES", key: "properties", format: (value) => JSON.stringify(value ?? {}) }] : []),
469
+ ]));
470
+ printPageHint(page);
471
+ }
472
+ catch (err) {
473
+ error(describeRecordsFailure(err));
474
+ process.exit(1);
475
+ }
476
+ });
477
+ users
478
+ .command("count")
479
+ .description("Count an app's users matching a records filter")
480
+ .option("--app <app-id>", "App ID")
481
+ .option("--filter <json>", 'Filter as JSON, e.g. \'{"status":"disabled"}\'')
482
+ .option("--filter-file <path>", "Read filter from a JSON or TOML file")
483
+ .option("--json", "Output as JSON")
484
+ .action(async (options) => {
485
+ const filter = parseFilterOptions(options);
486
+ const resolvedAppId = resolveAppId(undefined, options);
487
+ const client = new ApiClient();
488
+ try {
489
+ const answer = await client.countUsers(resolvedAppId, filter !== undefined ? { filter } : {});
490
+ if (options.json) {
491
+ json(answer);
492
+ return;
493
+ }
494
+ console.log(` ${answer.count}`);
495
+ }
496
+ catch (err) {
497
+ error(describeRecordsFailure(err));
498
+ process.exit(1);
499
+ }
500
+ });
501
+ users
502
+ .command("aggregate")
503
+ .description("Aggregate an app's users (count/sum/avg/min/max, optional group-by, sort and limit)")
504
+ .option("--app <app-id>", "App ID")
505
+ .requiredOption("--op <operation>", "Aggregate operation: count|sum|avg|min|max")
506
+ .option("--field <field>", "Field to aggregate (required for sum/avg/min/max)")
507
+ .option("--group-by <level>", "Group by a field, or <field>:month|quarter|year for a date period (repeatable)", (value, previous = []) => previous.concat(value), [])
508
+ .option("--filter <json>", "Filter as JSON")
509
+ .option("--filter-file <path>", "Read filter from a JSON or TOML file")
510
+ .option("--sort <json>", 'Sort the groups as JSON { "field": <key>, "direction": 1 | -1 }; key is count, <op>_<field>, <field>_<period> or a group-by field')
511
+ .option("--limit <n>", "Most groups answered (1 to 10000)")
512
+ .option("--json", "Output as JSON")
513
+ .action(async (options) => {
514
+ if (!AGGREGATE_OPS.includes(options.op)) {
515
+ error(`Invalid --op "${options.op}". Expected one of: ${AGGREGATE_OPS.join(", ")}.`);
516
+ process.exit(1);
517
+ }
518
+ const operation = { type: options.op };
519
+ if (options.op === "count") {
520
+ if (options.field) {
521
+ error("--field is not valid for --op count.");
522
+ process.exit(1);
523
+ }
524
+ }
525
+ else {
526
+ if (!options.field) {
527
+ error(`--op ${options.op} requires --field.`);
528
+ process.exit(1);
529
+ }
530
+ operation.field = options.field;
531
+ }
532
+ const filter = parseFilterOptions(options);
533
+ const sort = parseJsonFlag("--sort", options.sort);
534
+ const limit = parsePageLimit(options.limit);
535
+ const levels = options.groupBy || [];
536
+ const groupBy = levels.map(groupByLevel);
537
+ const resolvedAppId = resolveAppId(undefined, options);
538
+ const client = new ApiClient();
539
+ try {
540
+ const answer = await client.aggregateUsers(resolvedAppId, {
541
+ options: {
542
+ operations: [operation],
543
+ ...(groupBy.length > 0 ? { groupBy } : {}),
544
+ ...(filter !== undefined ? { filter } : {}),
545
+ ...(sort !== undefined ? { sort } : {}),
546
+ ...(limit !== undefined ? { limit } : {}),
547
+ },
548
+ });
549
+ if (options.json) {
550
+ json(answer);
551
+ return;
552
+ }
553
+ const rendered = renderAggregateResult(answer.result, { groupBy: levels, op: options.op, field: options.field });
554
+ if (rendered.kind === "scalar")
555
+ keyValue(rendered.label, rendered.value);
556
+ else
557
+ console.log(rendered.text);
558
+ }
559
+ catch (err) {
560
+ error(describeRecordsFailure(err));
561
+ process.exit(1);
562
+ }
563
+ });
564
+ // ---- The user index (#5383): status, rebuild, reconcile and limits ----
565
+ const index = users
566
+ .command("index")
567
+ .description("Inspect and operate an app's user index: its status, a rebuild, a reconciliation and its shard limits");
568
+ commandStatus(index, { stability: "beta" });
569
+ /** Run `body`, refusing a bad flag before any request (exit 1) and printing a server failure (exit 1). */
570
+ const indexAction = (body) => async (options) => {
571
+ try {
572
+ await body(options);
573
+ }
574
+ catch (err) {
575
+ error(err instanceof UserIndexFlagError ? err.message : describeRecordsFailure(err));
576
+ process.exit(1);
577
+ }
578
+ };
579
+ index
580
+ .command("status")
581
+ .description("Show the user index: generation, shards with bounds and counts, queued applies, last apply and reconcile, superseded generations, a rebuild in progress, limits")
582
+ .option("--app <app-id>", "App ID")
583
+ .option("--json", "Output as JSON")
584
+ .action(indexAction(async (options) => {
585
+ const resolvedAppId = resolveAppId(undefined, options);
586
+ const client = new ApiClient();
587
+ const status = await client.getUserIndexStatus(resolvedAppId);
588
+ if (options.json) {
589
+ json(status);
590
+ return;
591
+ }
592
+ printUserIndexStatus(status);
593
+ }));
594
+ index
595
+ .command("rebuild")
596
+ .description("Build the next generation of the user index from the app's members, then make it current")
597
+ .option("--app <app-id>", "App ID")
598
+ .option("-y, --yes", "Skip the confirmation")
599
+ .option("--wait", "Wait until the new generation is current")
600
+ .option("--timeout <seconds>", `How long --wait waits (default ${USER_INDEX_WAIT_DEFAULT_SECONDS})`)
601
+ .option("--json", "Output as JSON")
602
+ .action(indexAction(async (options) => {
603
+ const timeoutMs = parseWaitTimeout(options.timeout);
604
+ const resolvedAppId = resolveAppId(undefined, options);
605
+ if (!options.yes && !(await confirmPrompt(`Rebuild the user index of ${resolvedAppId}?`))) {
606
+ info("Cancelled.");
607
+ return;
608
+ }
609
+ const client = new ApiClient();
610
+ const started = await client.rebuildUserIndex(resolvedAppId);
611
+ if (!options.wait) {
612
+ if (options.json)
613
+ json(started);
614
+ else
615
+ success(`Rebuilding the user index of ${resolvedAppId}: generation ${started.generation} started.`);
616
+ return;
617
+ }
618
+ if (!options.json)
619
+ info(`Rebuilding the user index of ${resolvedAppId}: generation ${started.generation} started; waiting for it to be current.`);
620
+ const status = await waitForUserIndex(() => client.getUserIndexStatus(resolvedAppId), (s) => s.build === null && typeof s.generation === "number" && s.generation >= started.generation, timeoutMs);
621
+ if (!status) {
622
+ error(`Generation ${started.generation} was not current within ${Math.round(timeoutMs / 1000)} s; it is still building.`);
623
+ process.exit(EXIT_TIMED_OUT);
624
+ }
625
+ if (options.json)
626
+ json({ generation: status.generation, status });
627
+ else
628
+ success(`Generation ${status.generation} of the user index of ${resolvedAppId} is current (${status.shards.length} shard(s)).`);
629
+ }));
630
+ index
631
+ .command("reconcile")
632
+ .description("Revalidate the user index now: run one slice, which verifies the recently read users, the records verified longest ago and the next page of members, and repairs what differs")
633
+ .option("--app <app-id>", "App ID")
634
+ .option("--wait", "Run slices, one a second at most, until every shard and the member walk are verified since the first began")
635
+ .option("--timeout <seconds>", `How long --wait waits (default ${USER_INDEX_WAIT_DEFAULT_SECONDS})`)
636
+ .option("--json", "Output as JSON")
637
+ .action(indexAction(async (options) => {
638
+ const timeoutMs = parseWaitTimeout(options.timeout);
639
+ const resolvedAppId = resolveAppId(undefined, options);
640
+ const client = new ApiClient();
641
+ const commandStart = Date.now();
642
+ const first = await client.reconcileUserIndex(resolvedAppId);
643
+ if (!first.started) {
644
+ if (options.json)
645
+ json(first);
646
+ else
647
+ info(`No slice ran for ${resolvedAppId}: ${first.reason ?? "the app's index is not available"}.`);
648
+ return;
649
+ }
650
+ if (!options.wait) {
651
+ if (options.json)
652
+ json({ mode: "slice", slice: first.slice });
653
+ else
654
+ success(`Reconciled ${resolvedAppId}: ${formatSliceCounts(first.slice)}.`);
655
+ return;
656
+ }
657
+ // Measured on the server's clock: done once everything was verified since the first slice began.
658
+ const since = Date.parse(first.slice?.startedAt ?? "") || commandStart;
659
+ const slices = [first.slice];
660
+ if (!options.json)
661
+ info(`Revalidating ${resolvedAppId} until every shard and the member walk are verified since ${formatDate(new Date(since).toISOString())}.`);
662
+ for (;;) {
663
+ const status = await client.getUserIndexStatus(resolvedAppId);
664
+ if (revalidationComplete(status, since)) {
665
+ const totals = sumSliceCounts(slices);
666
+ if (options.json)
667
+ json({ mode: "slice", slices: slices.length, totals, revalidation: status.revalidation });
668
+ else
669
+ success(`Reconciled ${resolvedAppId}: ${formatSliceCounts(totals)}.`);
670
+ return;
671
+ }
672
+ if (Date.now() - commandStart > timeoutMs) {
673
+ error(`The user index of ${resolvedAppId} was not fully revalidated within ${Math.round(timeoutMs / 1000)} s (${slices.length} slice(s) ran).`);
674
+ process.exit(EXIT_TIMED_OUT);
675
+ }
676
+ const lastStarted = Date.parse(slices[slices.length - 1]?.startedAt ?? "") || 0;
677
+ const pause = lastStarted + 1000 - Date.now();
678
+ if (pause > 0)
679
+ await new Promise((resolve) => setTimeout(resolve, pause));
680
+ const next = await client.reconcileUserIndex(resolvedAppId);
681
+ if (!next.started) {
682
+ error(`The revalidation of ${resolvedAppId} stopped: ${next.reason ?? "no slice ran"}.`);
683
+ process.exit(1);
684
+ }
685
+ slices.push(next.slice);
686
+ }
687
+ }));
688
+ index
689
+ .command("limits")
690
+ .description("Show, set or clear the app's user index shard limits (threshold, byte backstop, ceiling) and user property caps")
691
+ .option("--app <app-id>", "App ID")
692
+ .option("--shard-threshold <n>", "Records a shard holds before the next opens")
693
+ .option("--shard-bytes <n>", "A shard's database size in bytes that opens the next early")
694
+ .option("--shard-ceiling <n>", "The most shards a generation opens")
695
+ .option("--max-fields <n>", "The most fields user-properties.toml may declare")
696
+ .option("--max-unique <n>", "The most unique fields plus unique constraints")
697
+ .option("--max-indexed <n>", "The most indexed fields")
698
+ .option("--max-bytes <n>", "The most bytes one user's stored properties take")
699
+ .option("--clear <field>", "Clear an override (shard-threshold, shard-bytes, shard-ceiling, max-fields, max-unique, max-indexed or max-bytes); repeatable", collectOption)
700
+ .option("--json", "Output as JSON")
701
+ .action(indexAction(async (options) => {
702
+ const patch = limitsPatchOf(options);
703
+ const resolvedAppId = resolveAppId(undefined, options);
704
+ const client = new ApiClient();
705
+ const limits = patch ? await client.patchUserIndexLimits(resolvedAppId, patch) : await client.getUserIndexLimits(resolvedAppId);
706
+ if (options.json) {
707
+ json(limits);
708
+ return;
709
+ }
710
+ if (patch)
711
+ success(`Updated the user index limits of ${resolvedAppId}.`);
712
+ for (const { field, label, effective } of USER_INDEX_LIMIT_FLAGS) {
713
+ const override = limits.overrides?.[field] ?? null;
714
+ keyValue(label, `${limits.effective[effective]} (${override !== null ? "app" : "platform"})`);
715
+ }
716
+ if (limits.caps) {
717
+ for (const { field, label } of USER_PROPERTIES_CAP_FLAGS) {
718
+ const override = limits.caps.overrides?.[field] ?? null;
719
+ keyValue(label, `${limits.caps.effective[field]} (${override !== null ? "app" : "platform"})`);
720
+ }
721
+ }
722
+ }));
723
+ // ---- A users walk (#5393): start, status and terminate ----
724
+ const walk = users
725
+ .command("walk")
726
+ .description("Start, read and stop a walk that hands an app's users to a batch function in batches");
727
+ commandStatus(walk, { stability: "beta" });
728
+ walk
729
+ .command("start")
730
+ .description("Start a walk over the users a filter matches, or find the one already started under the key")
731
+ .requiredOption("--function <key>", "The batch function's key; it receives { userIds, input } under the users-batch trigger")
732
+ .requiredOption("--key <key>", "The walk's key; with the batch function, its identity (a repeat answers the same walk)")
733
+ .option("--filter <json>", 'Filter as JSON, e.g. \'{"properties.plan":"pro"}\'; omitted, every member')
734
+ .option("--filter-file <path>", "Read filter from a JSON or TOML file")
735
+ .option("--sort <json>", 'Sort as JSON, e.g. \'{"addedAt":-1}\'; needs --snapshot')
736
+ .option("--input <json>", "Handed to every batch as input, as JSON")
737
+ .option("--batch-size <n>", "Ids per batch (default 100, at most 100)")
738
+ .option("--concurrency <n>", "Batches in flight at once (default 4, at most 16)")
739
+ .option("--snapshot", "Capture the matching ids before the first batch")
740
+ .option("--wait", "Wait until the walk completes, fails or is terminated")
741
+ .option("--timeout <seconds>", `How long --wait waits (default ${USER_INDEX_WAIT_DEFAULT_SECONDS})`)
742
+ .option("--app <app-id>", "App ID")
743
+ .option("--json", "Output as JSON")
744
+ .action(indexAction(async (options) => {
745
+ const filter = parseFilterOptions(options);
746
+ const body = walkStartBodyOf(options, filter);
747
+ const timeoutMs = parseWaitTimeout(options.timeout);
748
+ const resolvedAppId = resolveAppId(undefined, options);
749
+ const client = new ApiClient();
750
+ const startedAt = Date.now();
751
+ const started = await client.startUserWalk(resolvedAppId, body);
752
+ if (!options.wait || !options.json) {
753
+ if (options.json)
754
+ json(started);
755
+ else if (started.existing)
756
+ info(`Walk ${started.runId} already exists for key ${started.key} (existing)`);
757
+ else
758
+ success(`Started walk ${started.runId} (walk ${started.walkId}) of ${body.function} under key ${started.key}`);
759
+ }
760
+ if (!options.wait)
761
+ return;
762
+ const settled = await waitForUserWalk(() => client.getUserWalk(resolvedAppId, started.runId), timeoutMs, startedAt);
763
+ if (!settled) {
764
+ error(`Walk ${started.runId} did not end within ${Math.round(timeoutMs / 1000)} s; it is still running.`);
765
+ process.exit(EXIT_TIMED_OUT);
766
+ }
767
+ const status = String(settled.status.status);
768
+ const { done, failed } = walkCounts(settled);
769
+ if (options.json)
770
+ json({ ...started, status: settled.status, run: settled.run });
771
+ else {
772
+ keyValue("Matched", settled.status.walk?.matched?.count ?? null);
773
+ const line = `Walk ${started.runId} ${status}: ${done} done, ${failed} failed`;
774
+ if (status === "completed")
775
+ success(line);
776
+ else
777
+ error(`${line}${settled.status.walk?.lastError ? ` (${settled.status.walk.lastError})` : ""}`);
778
+ }
779
+ if (status !== "completed")
780
+ process.exit(1);
781
+ }));
782
+ walk
783
+ .command("status <run-id>")
784
+ .description("Show a walk: its status, batches done, failed, in flight, retrying and remaining, its match count and partitions")
785
+ .option("--app <app-id>", "App ID")
786
+ .option("--json", "Output as JSON")
787
+ .action(async (runId, options) => {
788
+ await indexAction(async () => {
789
+ const resolvedAppId = resolveAppId(undefined, options);
790
+ const answer = await new ApiClient().getUserWalk(resolvedAppId, runId);
791
+ if (options.json) {
792
+ json(answer);
793
+ return;
794
+ }
795
+ for (const [label, value] of walkStatusLines(answer))
796
+ keyValue(label, value);
797
+ })(options);
798
+ });
799
+ walk
800
+ .command("terminate <run-id>")
801
+ .description("Stop a walk: no batch starts after this, and the batches in flight finish")
802
+ .option("-y, --yes", "Skip the confirmation")
803
+ .option("--app <app-id>", "App ID")
804
+ .option("--json", "Output as JSON")
805
+ .action(async (runId, options) => {
806
+ await indexAction(async () => {
807
+ const resolvedAppId = resolveAppId(undefined, options);
808
+ if (!options.yes && !(await confirmPrompt(`Terminate walk ${runId} of ${resolvedAppId}?`))) {
809
+ info("Cancelled.");
810
+ return;
811
+ }
812
+ const answer = await new ApiClient().terminateUserWalk(resolvedAppId, runId);
813
+ if (options.json) {
814
+ json(answer);
815
+ return;
816
+ }
817
+ const { done, failed } = walkCounts(answer);
818
+ if (answer.terminated)
819
+ success(`Terminated walk ${runId}: ${done} batches done, ${failed} failed`);
820
+ else
821
+ info(`Walk ${runId} had already ended (${answer.status.status})`);
822
+ })(options);
823
+ });
173
824
  // Invite user
174
825
  users
175
826
  .command("invite")
176
827
  .description("Invite a user to an app")
828
+ // Optional in commander, required in the action: an `<email>` after
829
+ // `[app-id]` would bind a lone email to `[app-id]` and refuse the call.
177
830
  .argument("[app-id]", "App ID (uses current app if not specified)")
178
- .argument("<email>", "Email address to invite")
831
+ .argument("[email]", "Email address to invite (required)")
179
832
  .option("--app <app-id>", "App ID")
180
833
  .option("--role <role>", "Role: admin or member", "member")
181
834
  .option("--send-email", "Send invitation email")
182
835
  .option("--expires-days <days>", "Days until invitation expires", "7")
183
836
  .option("--note <note>", "Personal note to include in the invitation email")
837
+ .option("--initial-properties <json>", "User properties the invitee gets at acceptance, as a JSON object (only those they have not set)")
184
838
  .option("--json", "Output as JSON")
185
839
  .action(async (appIdOrEmail, emailOrUndefined, options) => {
186
840
  // Handle argument flexibility
@@ -204,6 +858,12 @@ Examples:
204
858
  error("Email is required.");
205
859
  process.exit(1);
206
860
  }
861
+ const initialProperties = initialPropertiesFlag(options.initialProperties);
862
+ const expiresDays = Number(options.expiresDays);
863
+ if (!Number.isFinite(expiresDays) || expiresDays <= 0) {
864
+ error("--expires-days must be a positive number of days.");
865
+ process.exit(1);
866
+ }
207
867
  const client = new ApiClient();
208
868
  try {
209
869
  // When inviting as admin, create the console admin first — the backend
@@ -211,12 +871,13 @@ Examples:
211
871
  if (options.role === "admin") {
212
872
  await client.addAppAdmin(resolvedAppId, { adminEmail: email });
213
873
  }
214
- const result = await client.createInvitation(resolvedAppId, {
874
+ const result = await client.inviteUser(resolvedAppId, {
215
875
  email,
216
876
  role: options.role,
217
- expiresInDays: parseInt(options.expiresDays),
877
+ expiresAt: new Date(Date.now() + expiresDays * 24 * 60 * 60 * 1000).toISOString(),
218
878
  sendEmail: options.sendEmail || false,
219
879
  ...(options.note ? { note: options.note } : {}),
880
+ ...(initialProperties !== undefined ? { initialProperties } : {}),
220
881
  });
221
882
  if (options.json) {
222
883
  json(result);
@@ -225,6 +886,8 @@ Examples:
225
886
  success(`Invitation sent to ${email}`);
226
887
  keyValue("Invitation ID", result.invitationId);
227
888
  keyValue("Expires", formatDate(result.expiresAt));
889
+ if (initialProperties !== undefined)
890
+ keyValue("Initial properties", JSON.stringify(result.initialProperties ?? initialProperties));
228
891
  }
229
892
  catch (err) {
230
893
  error(err.message);
@@ -425,6 +1088,90 @@ Examples:
425
1088
  process.exit(1);
426
1089
  }
427
1090
  });
1091
+ // ---- One app user's properties (#5386): get, get-by, set-properties ----
1092
+ users
1093
+ .command("get")
1094
+ .description("Show one member of an app with their properties")
1095
+ // Optional in commander, required in the action, as set-profile does.
1096
+ .argument("[app-id]", "App ID (uses current app if not specified)")
1097
+ .argument("[user-id]", "User ID (required)")
1098
+ .option("--app <app-id>", "App ID")
1099
+ .option("--json", "Output as JSON")
1100
+ .action(async (appIdOrUserId, userIdOrUndefined, options) => {
1101
+ const { appId, userId } = appAndUser(appIdOrUserId, userIdOrUndefined, options);
1102
+ const client = new ApiClient();
1103
+ try {
1104
+ const user = await client.getAppUser(appId, userId);
1105
+ if (options.json) {
1106
+ json(user);
1107
+ return;
1108
+ }
1109
+ printAppUser(user);
1110
+ }
1111
+ catch (err) {
1112
+ error(describeUserPropertyFailure(err));
1113
+ process.exit(1);
1114
+ }
1115
+ });
1116
+ users
1117
+ .command("get-by")
1118
+ .description("Find the member who holds a unique property value, or a unique constraint's values in declared order")
1119
+ .argument("<name>", "A unique property or a unique constraint")
1120
+ .argument("<value...>", "The value (one for a property, the constituents' values in order for a constraint); each is parsed as JSON when it parses")
1121
+ .option("--app <app-id>", "App ID")
1122
+ .option("--json", "Output as JSON")
1123
+ .action(async (name, values, options) => {
1124
+ const appId = resolveAppId(undefined, options);
1125
+ const parsed = values.map(jsonOrString);
1126
+ const client = new ApiClient();
1127
+ try {
1128
+ const { user } = await client.getAppUserBy(appId, parsed.length === 1 ? { field: name, value: parsed[0] } : { constraint: name, values: parsed });
1129
+ if (options.json) {
1130
+ json(user);
1131
+ return;
1132
+ }
1133
+ if (!user) {
1134
+ info(`No user holds ${name} = ${values.join(", ")}.`);
1135
+ return;
1136
+ }
1137
+ printAppUser(user);
1138
+ }
1139
+ catch (err) {
1140
+ error(describeUserPropertyFailure(err));
1141
+ process.exit(1);
1142
+ }
1143
+ });
1144
+ users
1145
+ .command("set-properties")
1146
+ .description("Set a member's properties: a merge-patch, set additions and removals, and an optional condition")
1147
+ .argument("[app-id]", "App ID (uses current app if not specified)")
1148
+ .argument("[user-id]", "User ID (required)")
1149
+ .option("--data <json>", 'Properties to set as a JSON object, e.g. \'{"plan":"pro"}\'; null clears one')
1150
+ .option("--data-file <path>", "Read the properties to set from a JSON file")
1151
+ .option("--unset <field>", "Clear a property (its default shows on read); repeat for more", collectOption, [])
1152
+ .option("--add-to-set <field=value>", "Add a string to a stringset property; repeat for more", collectOption, [])
1153
+ .option("--remove-from-set <field=value>", "Remove a string from a stringset property; repeat for more", collectOption, [])
1154
+ .option("--condition <json>", 'Write only if this filter holds, e.g. \'{"properties.plan":"free"}\'')
1155
+ .option("--app <app-id>", "App ID")
1156
+ .option("--json", "Output as JSON")
1157
+ .action(async (appIdOrUserId, userIdOrUndefined, options) => {
1158
+ const { appId, userId } = appAndUser(appIdOrUserId, userIdOrUndefined, options);
1159
+ const body = propertiesWriteOf(options);
1160
+ const client = new ApiClient();
1161
+ try {
1162
+ const user = await client.setAppUserProperties(appId, userId, body);
1163
+ if (options.json) {
1164
+ json(user);
1165
+ return;
1166
+ }
1167
+ success(`Properties updated for ${userId}.`);
1168
+ printProperties(user.properties);
1169
+ }
1170
+ catch (err) {
1171
+ error(describeUserPropertyFailure(err));
1172
+ process.exit(1);
1173
+ }
1174
+ });
428
1175
  // Set user role
429
1176
  users
430
1177
  .command("set-role")
@@ -478,12 +1225,13 @@ Examples:
478
1225
  users
479
1226
  .command("transfer-owner")
480
1227
  .description("Transfer app ownership to another user")
481
- .argument("[app-id]", "App ID (uses current app if not specified)")
482
- .argument("<email-or-admin-id>", "New owner's email or admin ID")
1228
+ .argument("[app-id-or-target]", "App ID, or the new owner's email or admin ID")
1229
+ .argument("[email-or-admin-id]", "New owner's email or admin ID (if first arg is app ID)")
483
1230
  .option("--app <app-id>", "App ID")
484
1231
  .option("-y, --yes", "Skip confirmation prompt")
485
1232
  .action(async (appIdOrTarget, targetOrUndefined, options) => {
486
- // Handle argument flexibility
1233
+ // Both positionals are optional so `transfer-owner <email>` binds the
1234
+ // one value to the target rather than to the app id (#3645).
487
1235
  let resolvedAppId;
488
1236
  let target;
489
1237
  if (targetOrUndefined) {
@@ -529,39 +1277,155 @@ Examples:
529
1277
  process.exit(1);
530
1278
  }
531
1279
  });
532
- // List invitations subcommand
533
- users
1280
+ // --- App invitations subcommands ---
1281
+ const invitations = users
534
1282
  .command("invitations")
535
- .description("List pending invitations")
1283
+ .description("List and revoke app invitations");
1284
+ invitations
1285
+ .command("list")
1286
+ .description("List invitations with their status and accept links")
536
1287
  .argument("[app-id]", "App ID (uses current app if not specified)")
537
1288
  .option("--app <app-id>", "App ID")
1289
+ .addOption(pageLimitOption())
1290
+ .addOption(pageCursorOption())
538
1291
  .option("--json", "Output as JSON")
539
1292
  .action(async (appId, options) => {
1293
+ const limit = parsePageLimit(options.limit);
540
1294
  const resolvedAppId = resolveAppId(appId, options);
541
1295
  const client = new ApiClient();
1296
+ const params = {};
1297
+ if (limit !== undefined)
1298
+ params.limit = limit;
1299
+ if (options.cursor)
1300
+ params.cursor = options.cursor;
542
1301
  try {
543
- const result = await client.listInvitations(resolvedAppId);
544
- const invitations = result.items;
1302
+ const page = normalizeCliListEnvelope(await client.listInvitations(resolvedAppId, params));
1303
+ const links = await invitationAcceptLinks(client, resolvedAppId, page.items);
1304
+ const items = page.items.map((inv, i) => ({
1305
+ ...inv,
1306
+ acceptLink: links[i],
1307
+ }));
545
1308
  if (options.json) {
546
- json(invitations);
1309
+ json({ ...page, items });
547
1310
  return;
548
1311
  }
549
- if (!invitations || invitations.length === 0) {
550
- info("No pending invitations.");
1312
+ if (items.length === 0) {
1313
+ printEmptyPage(page, "invitations", "No invitations.");
551
1314
  return;
552
1315
  }
553
- console.log(formatTable(invitations, [
1316
+ const rows = items.map((inv) => {
1317
+ const status = invitationStatus(inv);
1318
+ return {
1319
+ ...inv,
1320
+ status,
1321
+ acceptLinkCell: status !== "pending" ? "-" : (inv.acceptLink ?? "unavailable"),
1322
+ };
1323
+ });
1324
+ console.log(formatTable(rows, [
554
1325
  { header: "ID", key: "invitationId", format: formatId },
555
1326
  { header: "EMAIL", key: "email" },
556
1327
  { header: "ROLE", key: "role" },
1328
+ { header: "STATUS", key: "status", format: formatStatus },
557
1329
  { header: "EXPIRES", key: "expiresAt", format: formatDate },
1330
+ { header: "ACCEPT LINK", key: "acceptLinkCell" },
558
1331
  ]));
1332
+ printPageHint(page);
559
1333
  }
560
1334
  catch (err) {
561
1335
  error(err.message);
562
1336
  process.exit(1);
563
1337
  }
564
1338
  });
1339
+ invitations
1340
+ .command("revoke")
1341
+ .description("Revoke an app invitation; for an admin invitation, also delete its console admin invitations")
1342
+ .argument("<invitation-id>", "Invitation ID")
1343
+ .option("--app <app-id>", "App ID")
1344
+ .option("-y, --yes", "Skip confirmation prompt")
1345
+ .option("--json", "Output as JSON")
1346
+ .action(async (invitationId, options) => {
1347
+ const resolvedAppId = resolveAppId(undefined, options);
1348
+ if (!options.yes) {
1349
+ let confirm;
1350
+ try {
1351
+ confirm = await confirmPrompt(`Revoke invitation ${invitationId}?`);
1352
+ }
1353
+ catch (err) {
1354
+ error(err.message);
1355
+ process.exit(1);
1356
+ }
1357
+ if (!confirm) {
1358
+ info("Cancelled.");
1359
+ return;
1360
+ }
1361
+ }
1362
+ const client = new ApiClient();
1363
+ // The role and email the console admin cross-delete needs come from the
1364
+ // invitation itself, read before anything is deleted.
1365
+ let invitation;
1366
+ try {
1367
+ invitation = await client.getInvitation(resolvedAppId, invitationId);
1368
+ await client.deleteInvitation(resolvedAppId, invitationId);
1369
+ }
1370
+ catch (err) {
1371
+ error(err.message);
1372
+ process.exit(1);
1373
+ }
1374
+ const { email, role } = invitation;
1375
+ const consoleAdminInvitations = { deleted: [], outstanding: [] };
1376
+ let failure;
1377
+ if (!options.json)
1378
+ success(`Invitation ${invitationId} for ${email} revoked.`);
1379
+ if (role === "admin") {
1380
+ let matching;
1381
+ try {
1382
+ const listed = await client.listAppAdminInvitations(resolvedAppId);
1383
+ matching = listed
1384
+ .filter((inv) => String(inv.email ?? "").toLowerCase() === email.toLowerCase())
1385
+ .map((inv) => inv.invitationId);
1386
+ }
1387
+ catch (err) {
1388
+ consoleAdminInvitations.error = err.message;
1389
+ failure =
1390
+ `Invitation ${invitationId} revoked, but the console admin invitations for ${email} ` +
1391
+ `could not be read: ${withoutFinalStop(err.message)}. ` +
1392
+ `Run 'primitive users admin-invitations list' and delete any for ${email}.`;
1393
+ }
1394
+ if (matching) {
1395
+ // Every match is attempted, so the outstanding list is exact.
1396
+ for (const id of matching) {
1397
+ try {
1398
+ await client.deleteAppAdminInvitation(resolvedAppId, id);
1399
+ consoleAdminInvitations.deleted.push(id);
1400
+ if (!options.json) {
1401
+ success(`Console admin invitation ${id} for ${email} deleted.`);
1402
+ }
1403
+ }
1404
+ catch (err) {
1405
+ consoleAdminInvitations.outstanding.push(id);
1406
+ consoleAdminInvitations.error ??= err.message;
1407
+ }
1408
+ }
1409
+ if (matching.length === 0 && !options.json) {
1410
+ info(`No console admin invitation for ${email} was outstanding.`);
1411
+ }
1412
+ if (consoleAdminInvitations.outstanding.length > 0) {
1413
+ failure =
1414
+ `Invitation ${invitationId} revoked, but console admin invitation(s) for ${email} ` +
1415
+ `still outstanding: ${consoleAdminInvitations.outstanding.join(", ")}. ` +
1416
+ `${withoutFinalStop(consoleAdminInvitations.error)}. ` +
1417
+ `Delete them with 'primitive users admin-invitations delete <id>'.`;
1418
+ }
1419
+ }
1420
+ }
1421
+ if (options.json) {
1422
+ json({ invitationId, email, role, revoked: true, consoleAdminInvitations });
1423
+ }
1424
+ if (failure) {
1425
+ error(failure);
1426
+ process.exit(1);
1427
+ }
1428
+ });
565
1429
  // --- Console admins subcommands ---
566
1430
  const admins = users
567
1431
  .command("admins")
@@ -875,4 +1739,33 @@ Examples:
875
1739
  }
876
1740
  });
877
1741
  }
1742
+ /** The human form of `users index status`. */
1743
+ function printUserIndexStatus(status) {
1744
+ console.log(`User index of ${status.appId} (${status.environment})`);
1745
+ console.log(` Generation: ${status.generation ?? "none yet"}`);
1746
+ console.log(` Queue: ${status.queue?.pending ?? 0} pending, ${status.queue?.dead ?? 0} dead`);
1747
+ const lastApply = status.lastApply;
1748
+ console.log(` Last apply: ${lastApply ? `${formatDate(lastApply.at)} (${lastApply.count} user(s), ${lastApply.ms} ms)` : "never"}`);
1749
+ const last = status.lastReconcile;
1750
+ console.log(` Last reconcile: ${last ? `${formatDate(last.at)} (${formatReconcileCounts(last.counts)})` : "never"}`);
1751
+ if (status.revalidation) {
1752
+ console.log(` Revalidation: ${formatRevalidationLine(status.revalidation)}`);
1753
+ console.log(` Last slice: ${formatLastSliceLine(status.revalidation.lastSlice)}`);
1754
+ }
1755
+ const limits = status.limits ?? {};
1756
+ console.log(` Limits: threshold ${limits.placed}, bytes ${limits.bytes}, ceiling ${limits.ceiling} (${limits.source})`);
1757
+ console.log(` Ceiling reached: ${status.ceilingReached ? "yes" : "no"}`);
1758
+ if (status.build) {
1759
+ const build = status.build;
1760
+ console.log(` Rebuild: generation ${build.generation} since ${formatDate(build.startedAt)}, ${build.scanned} scanned, frontier ${build.frontier ?? "-"}`);
1761
+ }
1762
+ if (status.reconcile?.running)
1763
+ console.log(` Reconciling: a slice of generation ${status.reconcile.running.generation}, ${status.reconcile.running.chunks} continuation(s)`);
1764
+ console.log("");
1765
+ console.log(formatUserIndexShards(status.shards ?? []));
1766
+ for (const entry of status.superseded ?? []) {
1767
+ const pins = entry.pins?.length ? `pinned by ${entry.pins.join(", ")}` : "no pins";
1768
+ console.log(`Superseded generation ${entry.generation}: ${entry.shards.length} shard(s), retires after ${formatDate(entry.retireAfter)}, ${pins}`);
1769
+ }
1770
+ }
878
1771
  //# sourceMappingURL=users.js.map