primitive-admin 1.2.0-alpha.14 → 1.2.0-alpha.16

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 (400) hide show
  1. package/README.md +181 -73
  2. package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
  3. package/dist/bin/primitive.js +11 -82
  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.js +2 -0
  8. package/dist/src/commands/agent-sessions.js.map +1 -1
  9. package/dist/src/commands/analytics.js +181 -12
  10. package/dist/src/commands/analytics.js.map +1 -1
  11. package/dist/src/commands/apps-children.js +2 -0
  12. package/dist/src/commands/apps-children.js.map +1 -1
  13. package/dist/src/commands/apps-transitions.d.ts +39 -0
  14. package/dist/src/commands/apps-transitions.js +198 -0
  15. package/dist/src/commands/apps-transitions.js.map +1 -0
  16. package/dist/src/commands/apps.d.ts +11 -0
  17. package/dist/src/commands/apps.js +65 -3
  18. package/dist/src/commands/apps.js.map +1 -1
  19. package/dist/src/commands/auth-sessions.js +2 -0
  20. package/dist/src/commands/auth-sessions.js.map +1 -1
  21. package/dist/src/commands/auth.js +16 -1
  22. package/dist/src/commands/auth.js.map +1 -1
  23. package/dist/src/commands/blob-buckets.js +2 -0
  24. package/dist/src/commands/blob-buckets.js.map +1 -1
  25. package/dist/src/commands/collections.js +2 -0
  26. package/dist/src/commands/collections.js.map +1 -1
  27. package/dist/src/commands/comparisons.js +2 -0
  28. package/dist/src/commands/comparisons.js.map +1 -1
  29. package/dist/src/commands/config.d.ts +1 -1
  30. package/dist/src/commands/config.js +42 -9
  31. package/dist/src/commands/config.js.map +1 -1
  32. package/dist/src/commands/connections.js +2 -0
  33. package/dist/src/commands/connections.js.map +1 -1
  34. package/dist/src/commands/database-type-configs.js +5 -3
  35. package/dist/src/commands/database-type-configs.js.map +1 -1
  36. package/dist/src/commands/databases.js +6 -4
  37. package/dist/src/commands/databases.js.map +1 -1
  38. package/dist/src/commands/db3-types.js +2 -0
  39. package/dist/src/commands/db3-types.js.map +1 -1
  40. package/dist/src/commands/db3.d.ts +12 -0
  41. package/dist/src/commands/db3.js +408 -31
  42. package/dist/src/commands/db3.js.map +1 -1
  43. package/dist/src/commands/documents.d.ts +52 -12
  44. package/dist/src/commands/documents.js +120 -29
  45. package/dist/src/commands/documents.js.map +1 -1
  46. package/dist/src/commands/email-templates.js +74 -0
  47. package/dist/src/commands/email-templates.js.map +1 -1
  48. package/dist/src/commands/env.js +2 -0
  49. package/dist/src/commands/env.js.map +1 -1
  50. package/dist/src/commands/functions.js +90 -11
  51. package/dist/src/commands/functions.js.map +1 -1
  52. package/dist/src/commands/groups.js +20 -3
  53. package/dist/src/commands/groups.js.map +1 -1
  54. package/dist/src/commands/guides.js +2 -0
  55. package/dist/src/commands/guides.js.map +1 -1
  56. package/dist/src/commands/hosting.d.ts +8 -0
  57. package/dist/src/commands/hosting.js +346 -0
  58. package/dist/src/commands/hosting.js.map +1 -0
  59. package/dist/src/commands/init.js +9 -1
  60. package/dist/src/commands/init.js.map +1 -1
  61. package/dist/src/commands/integrations.js +82 -47
  62. package/dist/src/commands/integrations.js.map +1 -1
  63. package/dist/src/commands/locks.js +2 -0
  64. package/dist/src/commands/locks.js.map +1 -1
  65. package/dist/src/commands/metadata-category-configs.js +2 -0
  66. package/dist/src/commands/metadata-category-configs.js.map +1 -1
  67. package/dist/src/commands/metadata.js +41 -0
  68. package/dist/src/commands/metadata.js.map +1 -1
  69. package/dist/src/commands/prompts.js +75 -47
  70. package/dist/src/commands/prompts.js.map +1 -1
  71. package/dist/src/commands/rate-counters.d.ts +19 -0
  72. package/dist/src/commands/rate-counters.js +104 -0
  73. package/dist/src/commands/rate-counters.js.map +1 -0
  74. package/dist/src/commands/rule-sets.js +2 -0
  75. package/dist/src/commands/rule-sets.js.map +1 -1
  76. package/dist/src/commands/schemas.d.ts +15 -0
  77. package/dist/src/commands/schemas.js +122 -0
  78. package/dist/src/commands/schemas.js.map +1 -0
  79. package/dist/src/commands/secrets.js +47 -3
  80. package/dist/src/commands/secrets.js.map +1 -1
  81. package/dist/src/commands/sessions.js +2 -0
  82. package/dist/src/commands/sessions.js.map +1 -1
  83. package/dist/src/commands/skill.js +2 -0
  84. package/dist/src/commands/skill.js.map +1 -1
  85. package/dist/src/commands/sync-schemas.d.ts +202 -0
  86. package/dist/src/commands/sync-schemas.js +629 -0
  87. package/dist/src/commands/sync-schemas.js.map +1 -0
  88. package/dist/src/commands/sync-user-properties.d.ts +118 -0
  89. package/dist/src/commands/sync-user-properties.js +276 -0
  90. package/dist/src/commands/sync-user-properties.js.map +1 -0
  91. package/dist/src/commands/sync.d.ts +344 -14
  92. package/dist/src/commands/sync.js +1834 -345
  93. package/dist/src/commands/sync.js.map +1 -1
  94. package/dist/src/commands/tokens.js +2 -0
  95. package/dist/src/commands/tokens.js.map +1 -1
  96. package/dist/src/commands/transitions.d.ts +54 -0
  97. package/dist/src/commands/transitions.js +418 -0
  98. package/dist/src/commands/transitions.js.map +1 -0
  99. package/dist/src/commands/usage.d.ts +18 -0
  100. package/dist/src/commands/usage.js +343 -0
  101. package/dist/src/commands/usage.js.map +1 -0
  102. package/dist/src/commands/user-properties.d.ts +14 -0
  103. package/dist/src/commands/user-properties.js +79 -0
  104. package/dist/src/commands/user-properties.js.map +1 -0
  105. package/dist/src/commands/users.js +878 -16
  106. package/dist/src/commands/users.js.map +1 -1
  107. package/dist/src/commands/vars.js +2 -0
  108. package/dist/src/commands/vars.js.map +1 -1
  109. package/dist/src/commands/waitlist.js +39 -4
  110. package/dist/src/commands/waitlist.js.map +1 -1
  111. package/dist/src/lib/analytics-query.d.ts +58 -0
  112. package/dist/src/lib/analytics-query.js +134 -0
  113. package/dist/src/lib/analytics-query.js.map +1 -0
  114. package/dist/src/lib/api-client.d.ts +1354 -97
  115. package/dist/src/lib/api-client.js +513 -164
  116. package/dist/src/lib/api-client.js.map +1 -1
  117. package/dist/src/lib/app-settings-descriptor.d.ts +1 -1
  118. package/dist/src/lib/app-settings-descriptor.js +6 -0
  119. package/dist/src/lib/app-settings-descriptor.js.map +1 -1
  120. package/dist/src/lib/auth-flow.d.ts +33 -0
  121. package/dist/src/lib/auth-flow.js +404 -13
  122. package/dist/src/lib/auth-flow.js.map +1 -1
  123. package/dist/src/lib/block-selector.d.ts +9 -15
  124. package/dist/src/lib/block-selector.js +9 -20
  125. package/dist/src/lib/block-selector.js.map +1 -1
  126. package/dist/src/lib/cli-manifest.d.ts +9 -0
  127. package/dist/src/lib/cli-manifest.js +10 -1
  128. package/dist/src/lib/cli-manifest.js.map +1 -1
  129. package/dist/src/lib/cli-version.d.ts +14 -0
  130. package/dist/src/lib/cli-version.js +38 -0
  131. package/dist/src/lib/cli-version.js.map +1 -0
  132. package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
  133. package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
  134. package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
  135. package/dist/src/lib/command-groups.d.ts +30 -0
  136. package/dist/src/lib/command-groups.js +109 -0
  137. package/dist/src/lib/command-groups.js.map +1 -0
  138. package/dist/src/lib/command-status.d.ts +147 -0
  139. package/dist/src/lib/command-status.js +266 -0
  140. package/dist/src/lib/command-status.js.map +1 -0
  141. package/dist/src/lib/config-object-descriptor.d.ts +6 -0
  142. package/dist/src/lib/config-object-descriptor.js +71 -1
  143. package/dist/src/lib/config-object-descriptor.js.map +1 -1
  144. package/dist/src/lib/config-toml.d.ts +11 -2
  145. package/dist/src/lib/config-toml.js +25 -2
  146. package/dist/src/lib/config-toml.js.map +1 -1
  147. package/dist/src/lib/data-input.d.ts +1 -1
  148. package/dist/src/lib/data-input.js +1 -1
  149. package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
  150. package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
  151. package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
  152. package/dist/src/lib/db-codegen/dbTypeIR.d.ts +18 -1
  153. package/dist/src/lib/db-codegen/dbTypeIR.js +14 -5
  154. package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
  155. package/dist/src/lib/db-type-records.d.ts +106 -0
  156. package/dist/src/lib/db-type-records.js +224 -0
  157. package/dist/src/lib/db-type-records.js.map +1 -0
  158. package/dist/src/lib/db3-export.d.ts +51 -14
  159. package/dist/src/lib/db3-export.js +136 -28
  160. package/dist/src/lib/db3-export.js.map +1 -1
  161. package/dist/src/lib/db3-index-output.d.ts +92 -4
  162. package/dist/src/lib/db3-index-output.js +183 -11
  163. package/dist/src/lib/db3-index-output.js.map +1 -1
  164. package/dist/src/lib/db3-type-models.d.ts +49 -7
  165. package/dist/src/lib/db3-type-models.js +159 -28
  166. package/dist/src/lib/db3-type-models.js.map +1 -1
  167. package/dist/src/lib/deprecation.d.ts +2 -2
  168. package/dist/src/lib/deprecation.js +2 -2
  169. package/dist/src/lib/experimental-apis.d.ts +36 -0
  170. package/dist/src/lib/experimental-apis.js +46 -0
  171. package/dist/src/lib/experimental-apis.js.map +1 -0
  172. package/dist/src/lib/file-attachment.d.ts +24 -0
  173. package/dist/src/lib/file-attachment.js +31 -0
  174. package/dist/src/lib/file-attachment.js.map +1 -0
  175. package/dist/src/lib/function-authorize-check.d.ts +1 -1
  176. package/dist/src/lib/function-authorize-check.js +2 -1
  177. package/dist/src/lib/function-authorize-check.js.map +1 -1
  178. package/dist/src/lib/function-authorize-view.d.ts +12 -0
  179. package/dist/src/lib/function-authorize-view.js +38 -0
  180. package/dist/src/lib/function-authorize-view.js.map +1 -1
  181. package/dist/src/lib/function-bundle.d.ts +27 -5
  182. package/dist/src/lib/function-bundle.js +106 -7
  183. package/dist/src/lib/function-bundle.js.map +1 -1
  184. package/dist/src/lib/function-collect.d.ts +15 -0
  185. package/dist/src/lib/function-collect.js +73 -14
  186. package/dist/src/lib/function-collect.js.map +1 -1
  187. package/dist/src/lib/function-db-types.d.ts +63 -40
  188. package/dist/src/lib/function-db-types.js +289 -293
  189. package/dist/src/lib/function-db-types.js.map +1 -1
  190. package/dist/src/lib/function-document-types.d.ts +19 -7
  191. package/dist/src/lib/function-document-types.js +24 -12
  192. package/dist/src/lib/function-document-types.js.map +1 -1
  193. package/dist/src/lib/function-lint.d.ts +24 -1
  194. package/dist/src/lib/function-lint.js +123 -1
  195. package/dist/src/lib/function-lint.js.map +1 -1
  196. package/dist/src/lib/function-run.d.ts +1 -1
  197. package/dist/src/lib/function-run.js +1 -1
  198. package/dist/src/lib/function-run.js.map +1 -1
  199. package/dist/src/lib/function-schema-codegen.d.ts +85 -21
  200. package/dist/src/lib/function-schema-codegen.js +191 -85
  201. package/dist/src/lib/function-schema-codegen.js.map +1 -1
  202. package/dist/src/lib/function-schema-refs.d.ts +98 -0
  203. package/dist/src/lib/function-schema-refs.js +177 -0
  204. package/dist/src/lib/function-schema-refs.js.map +1 -0
  205. package/dist/src/lib/function-sync.d.ts +38 -4
  206. package/dist/src/lib/function-sync.js +91 -14
  207. package/dist/src/lib/function-sync.js.map +1 -1
  208. package/dist/src/lib/function-typecheck.d.ts +52 -0
  209. package/dist/src/lib/function-typecheck.js +171 -54
  210. package/dist/src/lib/function-typecheck.js.map +1 -1
  211. package/dist/src/lib/generated-build-flags.d.ts +13 -0
  212. package/dist/src/lib/generated-build-flags.js +14 -0
  213. package/dist/src/lib/generated-build-flags.js.map +1 -0
  214. package/dist/src/lib/generated-command-status.d.ts +6 -0
  215. package/dist/src/lib/generated-command-status.js +469 -0
  216. package/dist/src/lib/generated-command-status.js.map +1 -0
  217. package/dist/src/lib/generated-config-surfaces.d.ts +239 -14
  218. package/dist/src/lib/generated-config-surfaces.js +670 -85
  219. package/dist/src/lib/generated-config-surfaces.js.map +1 -1
  220. package/dist/src/lib/generated-sdk-types.d.ts +1 -1
  221. package/dist/src/lib/generated-sdk-types.js +1 -1
  222. package/dist/src/lib/generated-sdk-types.js.map +1 -1
  223. package/dist/src/lib/hosting-build.d.ts +97 -0
  224. package/dist/src/lib/hosting-build.js +204 -0
  225. package/dist/src/lib/hosting-build.js.map +1 -0
  226. package/dist/src/lib/hosting-client.d.ts +167 -0
  227. package/dist/src/lib/hosting-client.js +340 -0
  228. package/dist/src/lib/hosting-client.js.map +1 -0
  229. package/dist/src/lib/hosting-environments.d.ts +32 -0
  230. package/dist/src/lib/hosting-environments.js +74 -0
  231. package/dist/src/lib/hosting-environments.js.map +1 -0
  232. package/dist/src/lib/hosting-errors.d.ts +30 -0
  233. package/dist/src/lib/hosting-errors.js +43 -0
  234. package/dist/src/lib/hosting-errors.js.map +1 -0
  235. package/dist/src/lib/hosting-token.d.ts +46 -0
  236. package/dist/src/lib/hosting-token.js +60 -0
  237. package/dist/src/lib/hosting-token.js.map +1 -0
  238. package/dist/src/lib/hosting-wait.d.ts +42 -0
  239. package/dist/src/lib/hosting-wait.js +84 -0
  240. package/dist/src/lib/hosting-wait.js.map +1 -0
  241. package/dist/src/lib/hosting-wfp-upload.d.ts +86 -0
  242. package/dist/src/lib/hosting-wfp-upload.js +149 -0
  243. package/dist/src/lib/hosting-wfp-upload.js.map +1 -0
  244. package/dist/src/lib/integration-test-request.d.ts +54 -0
  245. package/dist/src/lib/integration-test-request.js +207 -0
  246. package/dist/src/lib/integration-test-request.js.map +1 -0
  247. package/dist/src/lib/invoker-shared-enums.d.ts +35 -0
  248. package/dist/src/lib/invoker-shared-enums.js +98 -0
  249. package/dist/src/lib/invoker-shared-enums.js.map +1 -0
  250. package/dist/src/lib/log-inspection.d.ts +4 -1
  251. package/dist/src/lib/log-inspection.js.map +1 -1
  252. package/dist/src/lib/metadata-report.d.ts +85 -0
  253. package/dist/src/lib/metadata-report.js +81 -0
  254. package/dist/src/lib/metadata-report.js.map +1 -0
  255. package/dist/src/lib/output.d.ts +1 -1
  256. package/dist/src/lib/output.js +1 -1
  257. package/dist/src/lib/platform-owned.js +5 -0
  258. package/dist/src/lib/platform-owned.js.map +1 -1
  259. package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
  260. package/dist/src/lib/primitive-declaration-names.js +22 -0
  261. package/dist/src/lib/primitive-declaration-names.js.map +1 -0
  262. package/dist/src/lib/primitive-declaration.d.ts +174 -0
  263. package/dist/src/lib/primitive-declaration.js +792 -0
  264. package/dist/src/lib/primitive-declaration.js.map +1 -0
  265. package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
  266. package/dist/src/lib/prompt-schema-codegen.js +94 -98
  267. package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
  268. package/dist/src/lib/prompt-schema-document.d.ts +35 -0
  269. package/dist/src/lib/prompt-schema-document.js +92 -0
  270. package/dist/src/lib/prompt-schema-document.js.map +1 -0
  271. package/dist/src/lib/prompt-schema-refs.d.ts +173 -0
  272. package/dist/src/lib/prompt-schema-refs.js +478 -0
  273. package/dist/src/lib/prompt-schema-refs.js.map +1 -0
  274. package/dist/src/lib/records-verbs.d.ts +12 -2
  275. package/dist/src/lib/records-verbs.js +7 -2
  276. package/dist/src/lib/records-verbs.js.map +1 -1
  277. package/dist/src/lib/register-commands.d.ts +36 -0
  278. package/dist/src/lib/register-commands.js +37 -0
  279. package/dist/src/lib/register-commands.js.map +1 -0
  280. package/dist/src/lib/retired-imports.d.ts +53 -0
  281. package/dist/src/lib/retired-imports.js +120 -0
  282. package/dist/src/lib/retired-imports.js.map +1 -0
  283. package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
  284. package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
  285. package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
  286. package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
  287. package/dist/src/lib/schema-codegen/generated-db3-bridge.js +227 -0
  288. package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
  289. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
  290. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
  291. package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
  292. package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +218 -0
  293. package/dist/src/lib/schema-codegen/generated-field-grammar.js +397 -0
  294. package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
  295. package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
  296. package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
  297. package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
  298. package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
  299. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
  300. package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
  301. package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
  302. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
  303. package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
  304. package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
  305. package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
  306. package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
  307. package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
  308. package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
  309. package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
  310. package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
  311. package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
  312. package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
  313. package/dist/src/lib/schema-codegen/generated-schema-shape.d.ts +27 -0
  314. package/dist/src/lib/schema-codegen/generated-schema-shape.js +126 -0
  315. package/dist/src/lib/schema-codegen/generated-schema-shape.js.map +1 -0
  316. package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
  317. package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
  318. package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
  319. package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
  320. package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
  321. package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
  322. package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
  323. package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
  324. package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
  325. package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
  326. package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
  327. package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
  328. package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
  329. package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
  330. package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
  331. package/dist/src/lib/schema-codegen/valuesLists.d.ts +48 -0
  332. package/dist/src/lib/schema-codegen/valuesLists.js +144 -0
  333. package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
  334. package/dist/src/lib/schema-family-index.d.ts +228 -0
  335. package/dist/src/lib/schema-family-index.js +813 -0
  336. package/dist/src/lib/schema-family-index.js.map +1 -0
  337. package/dist/src/lib/schema-pins.d.ts +82 -0
  338. package/dist/src/lib/schema-pins.js +198 -0
  339. package/dist/src/lib/schema-pins.js.map +1 -0
  340. package/dist/src/lib/schema-preview.d.ts +244 -0
  341. package/dist/src/lib/schema-preview.js +498 -0
  342. package/dist/src/lib/schema-preview.js.map +1 -0
  343. package/dist/src/lib/skill-installer.d.ts +2 -2
  344. package/dist/src/lib/skill-installer.js +2 -21
  345. package/dist/src/lib/skill-installer.js.map +1 -1
  346. package/dist/src/lib/step-run-table.d.ts +1 -2
  347. package/dist/src/lib/step-run-table.js +1 -2
  348. package/dist/src/lib/step-run-table.js.map +1 -1
  349. package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
  350. package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
  351. package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
  352. package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
  353. package/dist/src/lib/swift-codegen/banners.js +12 -0
  354. package/dist/src/lib/swift-codegen/banners.js.map +1 -1
  355. package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
  356. package/dist/src/lib/swift-codegen/functionGenerator.js +168 -50
  357. package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
  358. package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
  359. package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
  360. package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
  361. package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
  362. package/dist/src/lib/swift-codegen/sharedGenerator.js +165 -0
  363. package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
  364. package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
  365. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
  366. package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
  367. package/dist/src/lib/sync-resource-types.d.ts +37 -5
  368. package/dist/src/lib/sync-resource-types.js +50 -5
  369. package/dist/src/lib/sync-resource-types.js.map +1 -1
  370. package/dist/src/lib/sync-selectors.d.ts +7 -0
  371. package/dist/src/lib/sync-selectors.js +22 -2
  372. package/dist/src/lib/sync-selectors.js.map +1 -1
  373. package/dist/src/lib/test-runs.d.ts +45 -0
  374. package/dist/src/lib/test-runs.js +150 -0
  375. package/dist/src/lib/test-runs.js.map +1 -0
  376. package/dist/src/lib/toml-database-config.d.ts +2 -1
  377. package/dist/src/lib/toml-database-config.js +7 -4
  378. package/dist/src/lib/toml-database-config.js.map +1 -1
  379. package/dist/src/lib/toml-scalar-edit.js +6 -4
  380. package/dist/src/lib/toml-scalar-edit.js.map +1 -1
  381. package/dist/src/lib/transition-warnings.d.ts +21 -0
  382. package/dist/src/lib/transition-warnings.js +49 -0
  383. package/dist/src/lib/transition-warnings.js.map +1 -0
  384. package/dist/src/lib/user-index.d.ts +80 -0
  385. package/dist/src/lib/user-index.js +166 -0
  386. package/dist/src/lib/user-index.js.map +1 -0
  387. package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
  388. package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
  389. package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
  390. package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
  391. package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
  392. package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
  393. package/dist/src/lib/user-walk.d.ts +31 -0
  394. package/dist/src/lib/user-walk.js +102 -0
  395. package/dist/src/lib/user-walk.js.map +1 -0
  396. package/dist/src/lib/worker-perf-format.d.ts +22 -0
  397. package/dist/src/lib/worker-perf-format.js +27 -0
  398. package/dist/src/lib/worker-perf-format.js.map +1 -0
  399. package/dist/src/types/index.d.ts +13 -34
  400. package/package.json +5 -3
@@ -1,11 +1,162 @@
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";
6
8
  import { TEST_USERS_MODES } from "../lib/test-users.js";
7
9
  import { pageCursorOption, pageLimitOption, parsePageLimit, printEmptyPage, printPageHint, } from "../lib/list-options.js";
8
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
+ }
9
160
  /** `--test-users`, refused before any request when not one of the three modes. */
10
161
  function parseTestUsersMode(value) {
11
162
  if (value === undefined)
@@ -16,6 +167,66 @@ function parseTestUsersMode(value) {
16
167
  }
17
168
  return value;
18
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
+ }
19
230
  export function registerUsersCommands(program) {
20
231
  const users = program
21
232
  .command("users")
@@ -30,7 +241,14 @@ Examples:
30
241
  $ primitive users invite user@example.com --role admin
31
242
  $ primitive users set-role 01HXY... member
32
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
33
250
  `);
251
+ commandStatus(users, { stability: "production" });
34
252
  // List users
35
253
  users
36
254
  .command("list")
@@ -122,10 +340,12 @@ Examples:
122
340
  .option("--role <role>", "Role: admin or member", "member")
123
341
  .option("--name <name>", "Display name (defaults to the email's local part)")
124
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")
125
344
  .option("--app <app-id>", "App ID")
126
345
  .option("--json", "Output as JSON")
127
346
  .action(async (email, options) => {
128
347
  const resolvedAppId = resolveAppId(undefined, options);
348
+ const initialProperties = initialPropertiesFlag(options.initialProperties);
129
349
  const client = new ApiClient();
130
350
  try {
131
351
  const result = await client.addUserByEmail(resolvedAppId, {
@@ -133,6 +353,7 @@ Examples:
133
353
  role: options.role,
134
354
  ...(options.name !== undefined ? { name: options.name } : {}),
135
355
  ...(options.avatarUrl !== undefined ? { avatarUrl: options.avatarUrl } : {}),
356
+ ...(initialProperties !== undefined ? { initialProperties } : {}),
136
357
  });
137
358
  if (options.json) {
138
359
  json(result);
@@ -147,6 +368,9 @@ Examples:
147
368
  keyValue("Name", result.name);
148
369
  if (result.avatarUrl)
149
370
  keyValue("Avatar URL", result.avatarUrl);
371
+ if (result.properties && Object.keys(result.properties).length > 0) {
372
+ keyValue("Properties", JSON.stringify(result.properties));
373
+ }
150
374
  }
151
375
  catch (err) {
152
376
  error(err.message);
@@ -201,17 +425,416 @@ Examples:
201
425
  process.exit(1);
202
426
  }
203
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
+ });
204
824
  // Invite user
205
825
  users
206
826
  .command("invite")
207
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.
208
830
  .argument("[app-id]", "App ID (uses current app if not specified)")
209
- .argument("<email>", "Email address to invite")
831
+ .argument("[email]", "Email address to invite (required)")
210
832
  .option("--app <app-id>", "App ID")
211
833
  .option("--role <role>", "Role: admin or member", "member")
212
834
  .option("--send-email", "Send invitation email")
213
835
  .option("--expires-days <days>", "Days until invitation expires", "7")
214
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)")
215
838
  .option("--json", "Output as JSON")
216
839
  .action(async (appIdOrEmail, emailOrUndefined, options) => {
217
840
  // Handle argument flexibility
@@ -235,6 +858,12 @@ Examples:
235
858
  error("Email is required.");
236
859
  process.exit(1);
237
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
+ }
238
867
  const client = new ApiClient();
239
868
  try {
240
869
  // When inviting as admin, create the console admin first — the backend
@@ -242,12 +871,13 @@ Examples:
242
871
  if (options.role === "admin") {
243
872
  await client.addAppAdmin(resolvedAppId, { adminEmail: email });
244
873
  }
245
- const result = await client.createInvitation(resolvedAppId, {
874
+ const result = await client.inviteUser(resolvedAppId, {
246
875
  email,
247
876
  role: options.role,
248
- expiresInDays: parseInt(options.expiresDays),
877
+ expiresAt: new Date(Date.now() + expiresDays * 24 * 60 * 60 * 1000).toISOString(),
249
878
  sendEmail: options.sendEmail || false,
250
879
  ...(options.note ? { note: options.note } : {}),
880
+ ...(initialProperties !== undefined ? { initialProperties } : {}),
251
881
  });
252
882
  if (options.json) {
253
883
  json(result);
@@ -256,6 +886,8 @@ Examples:
256
886
  success(`Invitation sent to ${email}`);
257
887
  keyValue("Invitation ID", result.invitationId);
258
888
  keyValue("Expires", formatDate(result.expiresAt));
889
+ if (initialProperties !== undefined)
890
+ keyValue("Initial properties", JSON.stringify(result.initialProperties ?? initialProperties));
259
891
  }
260
892
  catch (err) {
261
893
  error(err.message);
@@ -456,6 +1088,90 @@ Examples:
456
1088
  process.exit(1);
457
1089
  }
458
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
+ });
459
1175
  // Set user role
460
1176
  users
461
1177
  .command("set-role")
@@ -509,12 +1225,13 @@ Examples:
509
1225
  users
510
1226
  .command("transfer-owner")
511
1227
  .description("Transfer app ownership to another user")
512
- .argument("[app-id]", "App ID (uses current app if not specified)")
513
- .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)")
514
1230
  .option("--app <app-id>", "App ID")
515
1231
  .option("-y, --yes", "Skip confirmation prompt")
516
1232
  .action(async (appIdOrTarget, targetOrUndefined, options) => {
517
- // 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).
518
1235
  let resolvedAppId;
519
1236
  let target;
520
1237
  if (targetOrUndefined) {
@@ -560,39 +1277,155 @@ Examples:
560
1277
  process.exit(1);
561
1278
  }
562
1279
  });
563
- // List invitations subcommand
564
- users
1280
+ // --- App invitations subcommands ---
1281
+ const invitations = users
565
1282
  .command("invitations")
566
- .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")
567
1287
  .argument("[app-id]", "App ID (uses current app if not specified)")
568
1288
  .option("--app <app-id>", "App ID")
1289
+ .addOption(pageLimitOption())
1290
+ .addOption(pageCursorOption())
569
1291
  .option("--json", "Output as JSON")
570
1292
  .action(async (appId, options) => {
1293
+ const limit = parsePageLimit(options.limit);
571
1294
  const resolvedAppId = resolveAppId(appId, options);
572
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;
573
1301
  try {
574
- const result = await client.listInvitations(resolvedAppId);
575
- 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
+ }));
576
1308
  if (options.json) {
577
- json(invitations);
1309
+ json({ ...page, items });
578
1310
  return;
579
1311
  }
580
- if (!invitations || invitations.length === 0) {
581
- info("No pending invitations.");
1312
+ if (items.length === 0) {
1313
+ printEmptyPage(page, "invitations", "No invitations.");
582
1314
  return;
583
1315
  }
584
- 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, [
585
1325
  { header: "ID", key: "invitationId", format: formatId },
586
1326
  { header: "EMAIL", key: "email" },
587
1327
  { header: "ROLE", key: "role" },
1328
+ { header: "STATUS", key: "status", format: formatStatus },
588
1329
  { header: "EXPIRES", key: "expiresAt", format: formatDate },
1330
+ { header: "ACCEPT LINK", key: "acceptLinkCell" },
589
1331
  ]));
1332
+ printPageHint(page);
590
1333
  }
591
1334
  catch (err) {
592
1335
  error(err.message);
593
1336
  process.exit(1);
594
1337
  }
595
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
+ });
596
1429
  // --- Console admins subcommands ---
597
1430
  const admins = users
598
1431
  .command("admins")
@@ -906,4 +1739,33 @@ Examples:
906
1739
  }
907
1740
  });
908
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
+ }
909
1771
  //# sourceMappingURL=users.js.map