primitive-admin 1.2.0-alpha.14 → 1.2.0-alpha.15
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.
- package/README.md +102 -78
- package/assets/skill/skills/primitive-platform/SKILL.md +87 -23
- package/dist/bin/primitive.js +11 -82
- package/dist/bin/primitive.js.map +1 -1
- package/dist/src/commands/admins.js +79 -17
- package/dist/src/commands/admins.js.map +1 -1
- package/dist/src/commands/agent-sessions.js +2 -0
- package/dist/src/commands/agent-sessions.js.map +1 -1
- package/dist/src/commands/analytics.js +183 -12
- package/dist/src/commands/analytics.js.map +1 -1
- package/dist/src/commands/apps-children.js +2 -0
- package/dist/src/commands/apps-children.js.map +1 -1
- package/dist/src/commands/apps.js +19 -2
- package/dist/src/commands/apps.js.map +1 -1
- package/dist/src/commands/auth.js +11 -1
- package/dist/src/commands/auth.js.map +1 -1
- package/dist/src/commands/collections.js +13 -0
- package/dist/src/commands/collections.js.map +1 -1
- package/dist/src/commands/config.d.ts +1 -1
- package/dist/src/commands/config.js +40 -9
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/connections.js +2 -0
- package/dist/src/commands/connections.js.map +1 -1
- package/dist/src/commands/database-type-configs.js +5 -3
- package/dist/src/commands/database-type-configs.js.map +1 -1
- package/dist/src/commands/databases.js +6 -4
- package/dist/src/commands/databases.js.map +1 -1
- package/dist/src/commands/db3-types.js +2 -0
- package/dist/src/commands/db3-types.js.map +1 -1
- package/dist/src/commands/db3.d.ts +12 -0
- package/dist/src/commands/db3.js +343 -24
- package/dist/src/commands/db3.js.map +1 -1
- package/dist/src/commands/documents.d.ts +52 -12
- package/dist/src/commands/documents.js +120 -29
- package/dist/src/commands/documents.js.map +1 -1
- package/dist/src/commands/email-templates.js +72 -0
- package/dist/src/commands/email-templates.js.map +1 -1
- package/dist/src/commands/functions.js +47 -10
- package/dist/src/commands/functions.js.map +1 -1
- package/dist/src/commands/groups.js +18 -3
- package/dist/src/commands/groups.js.map +1 -1
- package/dist/src/commands/init.js +7 -1
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/integrations.js +80 -47
- package/dist/src/commands/integrations.js.map +1 -1
- package/dist/src/commands/metadata-category-configs.js +2 -0
- package/dist/src/commands/metadata-category-configs.js.map +1 -1
- package/dist/src/commands/metadata.js +41 -0
- package/dist/src/commands/metadata.js.map +1 -1
- package/dist/src/commands/prompts.js +73 -47
- package/dist/src/commands/prompts.js.map +1 -1
- package/dist/src/commands/rule-sets.js +2 -0
- package/dist/src/commands/rule-sets.js.map +1 -1
- package/dist/src/commands/schemas.d.ts +15 -0
- package/dist/src/commands/schemas.js +122 -0
- package/dist/src/commands/schemas.js.map +1 -0
- package/dist/src/commands/secrets.js +45 -3
- package/dist/src/commands/secrets.js.map +1 -1
- package/dist/src/commands/sessions.js +2 -0
- package/dist/src/commands/sessions.js.map +1 -1
- package/dist/src/commands/sync-schemas.d.ts +202 -0
- package/dist/src/commands/sync-schemas.js +629 -0
- package/dist/src/commands/sync-schemas.js.map +1 -0
- package/dist/src/commands/sync-user-properties.d.ts +118 -0
- package/dist/src/commands/sync-user-properties.js +276 -0
- package/dist/src/commands/sync-user-properties.js.map +1 -0
- package/dist/src/commands/sync.d.ts +243 -12
- package/dist/src/commands/sync.js +1474 -314
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/user-properties.d.ts +14 -0
- package/dist/src/commands/user-properties.js +79 -0
- package/dist/src/commands/user-properties.js.map +1 -0
- package/dist/src/commands/users.js +879 -16
- package/dist/src/commands/users.js.map +1 -1
- package/dist/src/commands/waitlist.js +39 -4
- package/dist/src/commands/waitlist.js.map +1 -1
- package/dist/src/lib/analytics-query.d.ts +58 -0
- package/dist/src/lib/analytics-query.js +134 -0
- package/dist/src/lib/analytics-query.js.map +1 -0
- package/dist/src/lib/api-client.d.ts +748 -95
- package/dist/src/lib/api-client.js +356 -158
- package/dist/src/lib/api-client.js.map +1 -1
- package/dist/src/lib/block-selector.d.ts +9 -15
- package/dist/src/lib/block-selector.js +9 -20
- package/dist/src/lib/block-selector.js.map +1 -1
- package/dist/src/lib/cli-manifest.d.ts +8 -0
- package/dist/src/lib/cli-manifest.js +10 -1
- package/dist/src/lib/cli-manifest.js.map +1 -1
- package/dist/src/lib/cli-version.d.ts +14 -0
- package/dist/src/lib/cli-version.js +38 -0
- package/dist/src/lib/cli-version.js.map +1 -0
- package/dist/src/lib/codegen-shared/prettierStable.d.ts +41 -0
- package/dist/src/lib/codegen-shared/prettierStable.js +146 -24
- package/dist/src/lib/codegen-shared/prettierStable.js.map +1 -1
- package/dist/src/lib/command-status.d.ts +110 -0
- package/dist/src/lib/command-status.js +184 -0
- package/dist/src/lib/command-status.js.map +1 -0
- package/dist/src/lib/config-object-descriptor.d.ts +6 -0
- package/dist/src/lib/config-object-descriptor.js +71 -0
- package/dist/src/lib/config-object-descriptor.js.map +1 -1
- package/dist/src/lib/config-toml.d.ts +11 -2
- package/dist/src/lib/config-toml.js +25 -2
- package/dist/src/lib/config-toml.js.map +1 -1
- package/dist/src/lib/data-input.d.ts +1 -1
- package/dist/src/lib/data-input.js +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.d.ts +1 -1
- package/dist/src/lib/db-codegen/dbTsTypes.js +3 -0
- package/dist/src/lib/db-codegen/dbTsTypes.js.map +1 -1
- package/dist/src/lib/db-codegen/dbTypeIR.d.ts +11 -1
- package/dist/src/lib/db-codegen/dbTypeIR.js +11 -5
- package/dist/src/lib/db-codegen/dbTypeIR.js.map +1 -1
- package/dist/src/lib/db-type-records.d.ts +95 -0
- package/dist/src/lib/db-type-records.js +219 -0
- package/dist/src/lib/db-type-records.js.map +1 -0
- package/dist/src/lib/db3-export.d.ts +51 -14
- package/dist/src/lib/db3-export.js +135 -27
- package/dist/src/lib/db3-export.js.map +1 -1
- package/dist/src/lib/db3-index-output.d.ts +68 -3
- package/dist/src/lib/db3-index-output.js +139 -3
- package/dist/src/lib/db3-index-output.js.map +1 -1
- package/dist/src/lib/db3-type-models.d.ts +39 -7
- package/dist/src/lib/db3-type-models.js +138 -27
- package/dist/src/lib/db3-type-models.js.map +1 -1
- package/dist/src/lib/deprecation.d.ts +2 -2
- package/dist/src/lib/deprecation.js +2 -2
- package/dist/src/lib/experimental-apis.d.ts +36 -0
- package/dist/src/lib/experimental-apis.js +46 -0
- package/dist/src/lib/experimental-apis.js.map +1 -0
- package/dist/src/lib/file-attachment.d.ts +24 -0
- package/dist/src/lib/file-attachment.js +31 -0
- package/dist/src/lib/file-attachment.js.map +1 -0
- package/dist/src/lib/function-authorize-check.d.ts +1 -1
- package/dist/src/lib/function-authorize-check.js +2 -1
- package/dist/src/lib/function-authorize-check.js.map +1 -1
- package/dist/src/lib/function-authorize-view.js +4 -0
- package/dist/src/lib/function-authorize-view.js.map +1 -1
- package/dist/src/lib/function-bundle.d.ts +27 -5
- package/dist/src/lib/function-bundle.js +106 -7
- package/dist/src/lib/function-bundle.js.map +1 -1
- package/dist/src/lib/function-collect.d.ts +2 -0
- package/dist/src/lib/function-collect.js +36 -7
- package/dist/src/lib/function-collect.js.map +1 -1
- package/dist/src/lib/function-db-types.d.ts +57 -40
- package/dist/src/lib/function-db-types.js +246 -285
- package/dist/src/lib/function-db-types.js.map +1 -1
- package/dist/src/lib/function-document-types.d.ts +19 -7
- package/dist/src/lib/function-document-types.js +24 -12
- package/dist/src/lib/function-document-types.js.map +1 -1
- package/dist/src/lib/function-run.d.ts +1 -1
- package/dist/src/lib/function-run.js +1 -1
- package/dist/src/lib/function-run.js.map +1 -1
- package/dist/src/lib/function-schema-codegen.d.ts +58 -18
- package/dist/src/lib/function-schema-codegen.js +85 -74
- package/dist/src/lib/function-schema-codegen.js.map +1 -1
- package/dist/src/lib/function-schema-refs.d.ts +98 -0
- package/dist/src/lib/function-schema-refs.js +177 -0
- package/dist/src/lib/function-schema-refs.js.map +1 -0
- package/dist/src/lib/function-sync.d.ts +38 -4
- package/dist/src/lib/function-sync.js +83 -14
- package/dist/src/lib/function-sync.js.map +1 -1
- package/dist/src/lib/function-typecheck.d.ts +52 -0
- package/dist/src/lib/function-typecheck.js +171 -54
- package/dist/src/lib/function-typecheck.js.map +1 -1
- package/dist/src/lib/generated-build-flags.d.ts +13 -0
- package/dist/src/lib/generated-build-flags.js +14 -0
- package/dist/src/lib/generated-build-flags.js.map +1 -0
- package/dist/src/lib/generated-config-surfaces.d.ts +211 -11
- package/dist/src/lib/generated-config-surfaces.js +579 -69
- package/dist/src/lib/generated-config-surfaces.js.map +1 -1
- package/dist/src/lib/generated-sdk-types.d.ts +1 -1
- package/dist/src/lib/generated-sdk-types.js +1 -1
- package/dist/src/lib/generated-sdk-types.js.map +1 -1
- package/dist/src/lib/integration-test-request.d.ts +54 -0
- package/dist/src/lib/integration-test-request.js +207 -0
- package/dist/src/lib/integration-test-request.js.map +1 -0
- package/dist/src/lib/metadata-report.d.ts +85 -0
- package/dist/src/lib/metadata-report.js +81 -0
- package/dist/src/lib/metadata-report.js.map +1 -0
- package/dist/src/lib/output.d.ts +1 -1
- package/dist/src/lib/output.js +1 -1
- package/dist/src/lib/platform-owned.js +5 -0
- package/dist/src/lib/platform-owned.js.map +1 -1
- package/dist/src/lib/primitive-declaration-names.d.ts +21 -0
- package/dist/src/lib/primitive-declaration-names.js +22 -0
- package/dist/src/lib/primitive-declaration-names.js.map +1 -0
- package/dist/src/lib/primitive-declaration.d.ts +143 -0
- package/dist/src/lib/primitive-declaration.js +658 -0
- package/dist/src/lib/primitive-declaration.js.map +1 -0
- package/dist/src/lib/prompt-schema-codegen.d.ts +36 -12
- package/dist/src/lib/prompt-schema-codegen.js +82 -98
- package/dist/src/lib/prompt-schema-codegen.js.map +1 -1
- package/dist/src/lib/prompt-schema-document.d.ts +35 -0
- package/dist/src/lib/prompt-schema-document.js +92 -0
- package/dist/src/lib/prompt-schema-document.js.map +1 -0
- package/dist/src/lib/prompt-schema-refs.d.ts +164 -0
- package/dist/src/lib/prompt-schema-refs.js +452 -0
- package/dist/src/lib/prompt-schema-refs.js.map +1 -0
- package/dist/src/lib/records-verbs.d.ts +12 -2
- package/dist/src/lib/records-verbs.js +7 -2
- package/dist/src/lib/records-verbs.js.map +1 -1
- package/dist/src/lib/register-commands.d.ts +28 -0
- package/dist/src/lib/register-commands.js +101 -0
- package/dist/src/lib/register-commands.js.map +1 -0
- package/dist/src/lib/retired-imports.d.ts +53 -0
- package/dist/src/lib/retired-imports.js +120 -0
- package/dist/src/lib/retired-imports.js.map +1 -0
- package/dist/src/lib/schema-codegen/compiledSpace.d.ts +62 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js +103 -0
- package/dist/src/lib/schema-codegen/compiledSpace.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.d.ts +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js +221 -0
- package/dist/src/lib/schema-codegen/generated-db3-bridge.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.d.ts +85 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js +86 -0
- package/dist/src/lib/schema-codegen/generated-db3-query-capabilities.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.d.ts +209 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js +379 -0
- package/dist/src/lib/schema-codegen/generated-field-grammar.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-field-table.d.ts +80 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js +542 -0
- package/dist/src/lib/schema-codegen/generated-field-table.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.d.ts +195 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js +503 -0
- package/dist/src/lib/schema-codegen/generated-prompt-schemas.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js +154 -1
- package/dist/src/lib/schema-codegen/generated-schema-descriptor.js.map +1 -1
- package/dist/src/lib/schema-codegen/generated-schema-file.d.ts +129 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js +475 -0
- package/dist/src/lib/schema-codegen/generated-schema-file.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.d.ts +115 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js +274 -0
- package/dist/src/lib/schema-codegen/generated-schema-provenance.js.map +1 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.d.ts +366 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js +1789 -0
- package/dist/src/lib/schema-codegen/generated-schema-refs.js.map +1 -0
- package/dist/src/lib/schema-codegen/namedRefs.d.ts +56 -0
- package/dist/src/lib/schema-codegen/namedRefs.js +143 -0
- package/dist/src/lib/schema-codegen/namedRefs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaChanges.d.ts +74 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js +277 -0
- package/dist/src/lib/schema-codegen/schemaChanges.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaDocs.d.ts +69 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js +219 -0
- package/dist/src/lib/schema-codegen/schemaDocs.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaIR.d.ts +158 -0
- package/dist/src/lib/schema-codegen/schemaIR.js +279 -0
- package/dist/src/lib/schema-codegen/schemaIR.js.map +1 -0
- package/dist/src/lib/schema-codegen/schemaToTs.d.ts +40 -13
- package/dist/src/lib/schema-codegen/schemaToTs.js +124 -160
- package/dist/src/lib/schema-codegen/schemaToTs.js.map +1 -1
- package/dist/src/lib/schema-codegen/valuesLists.d.ts +35 -0
- package/dist/src/lib/schema-codegen/valuesLists.js +128 -0
- package/dist/src/lib/schema-codegen/valuesLists.js.map +1 -0
- package/dist/src/lib/schema-family-index.d.ts +228 -0
- package/dist/src/lib/schema-family-index.js +813 -0
- package/dist/src/lib/schema-family-index.js.map +1 -0
- package/dist/src/lib/schema-pins.d.ts +82 -0
- package/dist/src/lib/schema-pins.js +198 -0
- package/dist/src/lib/schema-pins.js.map +1 -0
- package/dist/src/lib/schema-preview.d.ts +244 -0
- package/dist/src/lib/schema-preview.js +498 -0
- package/dist/src/lib/schema-preview.js.map +1 -0
- package/dist/src/lib/skill-installer.d.ts +2 -2
- package/dist/src/lib/skill-installer.js +2 -21
- package/dist/src/lib/skill-installer.js.map +1 -1
- package/dist/src/lib/step-run-table.d.ts +1 -2
- package/dist/src/lib/step-run-table.js +1 -2
- package/dist/src/lib/step-run-table.js.map +1 -1
- package/dist/src/lib/swift-codegen/agentGenerator.d.ts +2 -1
- package/dist/src/lib/swift-codegen/agentGenerator.js +24 -22
- package/dist/src/lib/swift-codegen/agentGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/banners.d.ts +12 -0
- package/dist/src/lib/swift-codegen/banners.js +12 -0
- package/dist/src/lib/swift-codegen/banners.js.map +1 -1
- package/dist/src/lib/swift-codegen/functionGenerator.d.ts +36 -1
- package/dist/src/lib/swift-codegen/functionGenerator.js +167 -50
- package/dist/src/lib/swift-codegen/functionGenerator.js.map +1 -1
- package/dist/src/lib/swift-codegen/schemaToSwift.d.ts +31 -7
- package/dist/src/lib/swift-codegen/schemaToSwift.js +213 -177
- package/dist/src/lib/swift-codegen/schemaToSwift.js.map +1 -1
- package/dist/src/lib/swift-codegen/sharedGenerator.d.ts +45 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js +120 -0
- package/dist/src/lib/swift-codegen/sharedGenerator.js.map +1 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.d.ts +30 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js +69 -0
- package/dist/src/lib/swift-codegen/userPropertiesGenerator.js.map +1 -0
- package/dist/src/lib/sync-resource-types.d.ts +37 -5
- package/dist/src/lib/sync-resource-types.js +53 -5
- package/dist/src/lib/sync-resource-types.js.map +1 -1
- package/dist/src/lib/sync-selectors.d.ts +7 -0
- package/dist/src/lib/sync-selectors.js +22 -2
- package/dist/src/lib/sync-selectors.js.map +1 -1
- package/dist/src/lib/test-runs.d.ts +45 -0
- package/dist/src/lib/test-runs.js +150 -0
- package/dist/src/lib/test-runs.js.map +1 -0
- package/dist/src/lib/toml-database-config.d.ts +2 -1
- package/dist/src/lib/toml-database-config.js +4 -3
- package/dist/src/lib/toml-database-config.js.map +1 -1
- package/dist/src/lib/toml-scalar-edit.js +6 -4
- package/dist/src/lib/toml-scalar-edit.js.map +1 -1
- package/dist/src/lib/user-index.d.ts +80 -0
- package/dist/src/lib/user-index.js +166 -0
- package/dist/src/lib/user-index.js.map +1 -0
- package/dist/src/lib/user-properties/generated-properties-schema.d.ts +159 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js +471 -0
- package/dist/src/lib/user-properties/generated-properties-schema.js.map +1 -0
- package/dist/src/lib/user-properties/user-properties-codegen.d.ts +55 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js +129 -0
- package/dist/src/lib/user-properties/user-properties-codegen.js.map +1 -0
- package/dist/src/lib/user-walk.d.ts +31 -0
- package/dist/src/lib/user-walk.js +102 -0
- package/dist/src/lib/user-walk.js.map +1 -0
- package/dist/src/lib/worker-perf-format.d.ts +22 -0
- package/dist/src/lib/worker-perf-format.js +27 -0
- package/dist/src/lib/worker-perf-format.js.map +1 -0
- package/dist/src/types/index.d.ts +13 -34
- package/package.json +5 -3
|
@@ -1,11 +1,163 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { subcommandStatus } 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 { commandStatus } from "../lib/command-status.js";
|
|
12
|
+
import { parseFilterOptions } from "../lib/record-filter.js";
|
|
13
|
+
import { renderAggregateResult } from "../lib/aggregate-output.js";
|
|
14
|
+
import { describeRecordsFailure } from "./documents.js";
|
|
15
|
+
import { EXIT_TIMED_OUT } from "../lib/function-run.js";
|
|
16
|
+
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";
|
|
17
|
+
import { walkCounts, walkStartBodyOf, walkStatusLines, waitForUserWalk } from "../lib/user-walk.js";
|
|
18
|
+
/** The aggregate operations `users aggregate` takes. */
|
|
19
|
+
const AGGREGATE_OPS = ["count", "sum", "avg", "min", "max"];
|
|
20
|
+
/** The date periods a `--group-by <field>:<period>` level takes. */
|
|
21
|
+
const GROUP_BY_PERIODS = ["month", "quarter", "year"];
|
|
22
|
+
/** A `--group-by` value as a level: `<field>:<period>` is a date period, anything else a field. */
|
|
23
|
+
function groupByLevel(value) {
|
|
24
|
+
const at = value.lastIndexOf(":");
|
|
25
|
+
if (at > 0 && GROUP_BY_PERIODS.includes(value.slice(at + 1)))
|
|
26
|
+
return { field: value.slice(0, at), period: value.slice(at + 1) };
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
/** A JSON flag's value parsed, or exit naming the flag; `undefined` when the flag is absent. */
|
|
30
|
+
function parseJsonFlag(flag, raw) {
|
|
31
|
+
if (raw === undefined)
|
|
32
|
+
return undefined;
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(raw);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
error(`Invalid ${flag} JSON.`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** `--initial-properties` parsed: a JSON object of property names to values, or exit naming the flag; `undefined` when absent. */
|
|
42
|
+
function initialPropertiesFlag(raw) {
|
|
43
|
+
const value = parseJsonFlag("--initial-properties", raw);
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
47
|
+
error("--initial-properties must be a JSON object of property names to values.");
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
/** `[app-id] [user-id]` as set-profile reads them: one argument is the user, two are the app and the user. */
|
|
53
|
+
function appAndUser(appIdOrUserId, userIdOrUndefined, options) {
|
|
54
|
+
const appId = userIdOrUndefined ? resolveAppId(appIdOrUserId, options) : resolveAppId(undefined, options);
|
|
55
|
+
const userId = userIdOrUndefined ?? appIdOrUserId;
|
|
56
|
+
if (!userId) {
|
|
57
|
+
error("User ID is required.");
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
return { appId, userId };
|
|
61
|
+
}
|
|
62
|
+
/** A command-line value as JSON when it parses, else the string itself (`12` is a number, `ada` a string). */
|
|
63
|
+
function jsonOrString(value) {
|
|
64
|
+
try {
|
|
65
|
+
return JSON.parse(value);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** A refusal as the server named it: its code, then its message. */
|
|
72
|
+
function describeUserPropertyFailure(err) {
|
|
73
|
+
return err?.code ? `${err.code}: ${err.message}` : String(err?.message ?? err);
|
|
74
|
+
}
|
|
75
|
+
/** The repeatable `<field>=<value>` options of one set operation, grouped by field; exit naming the flag on a malformed one. */
|
|
76
|
+
function setMembersOf(flag, pairs) {
|
|
77
|
+
if (pairs.length === 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
// Grouped in a Map: a field named like an Object.prototype member (`toString`) is still just a field.
|
|
80
|
+
const members = new Map();
|
|
81
|
+
for (const pair of pairs) {
|
|
82
|
+
const at = pair.indexOf("=");
|
|
83
|
+
if (at <= 0) {
|
|
84
|
+
error(`${flag} takes <field>=<value>, e.g. ${flag} tags=beta; got "${pair}".`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
const field = pair.slice(0, at);
|
|
88
|
+
const values = members.get(field) ?? [];
|
|
89
|
+
values.push(pair.slice(at + 1));
|
|
90
|
+
members.set(field, values);
|
|
91
|
+
}
|
|
92
|
+
return Object.fromEntries(members);
|
|
93
|
+
}
|
|
94
|
+
/** `users set-properties`'s flags as one write; exit naming what is wrong before any request. */
|
|
95
|
+
function propertiesWriteOf(options) {
|
|
96
|
+
const usage = "Pass at least one of --data, --data-file, --unset, --add-to-set, --remove-from-set.";
|
|
97
|
+
if (options.data !== undefined && options.dataFile !== undefined) {
|
|
98
|
+
error("Pass --data or --data-file, not both.");
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
let raw;
|
|
102
|
+
if (options.data !== undefined)
|
|
103
|
+
raw = parseJsonFlag("--data", options.data);
|
|
104
|
+
if (options.dataFile !== undefined) {
|
|
105
|
+
let text;
|
|
106
|
+
try {
|
|
107
|
+
text = readFileSync(options.dataFile, "utf-8");
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
error(`Cannot read --data-file ${options.dataFile}: ${err.message}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
raw = parseJsonFlag("--data-file", text);
|
|
114
|
+
}
|
|
115
|
+
if (raw !== undefined && (raw === null || typeof raw !== "object" || Array.isArray(raw))) {
|
|
116
|
+
error("--data and --data-file take a JSON object of property names to values.");
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
const patch = { ...(raw ?? {}) };
|
|
120
|
+
for (const field of options.unset)
|
|
121
|
+
patch[field] = null;
|
|
122
|
+
const addToSet = setMembersOf("--add-to-set", options.addToSet);
|
|
123
|
+
const removeFromSet = setMembersOf("--remove-from-set", options.removeFromSet);
|
|
124
|
+
if (Object.keys(patch).length === 0 && !addToSet && !removeFromSet) {
|
|
125
|
+
error(usage);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
const condition = parseJsonFlag("--condition", options.condition);
|
|
129
|
+
if (condition !== undefined && (condition === null || typeof condition !== "object" || Array.isArray(condition))) {
|
|
130
|
+
error("--condition takes a JSON filter object.");
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
...(Object.keys(patch).length > 0 ? { patch } : {}),
|
|
135
|
+
...(addToSet ? { addToSet } : {}),
|
|
136
|
+
...(removeFromSet ? { removeFromSet } : {}),
|
|
137
|
+
...(condition !== undefined ? { condition: condition } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** A member's properties, one per line as JSON values; "(none)" when there are none. */
|
|
141
|
+
function printProperties(properties) {
|
|
142
|
+
console.log("Properties:");
|
|
143
|
+
const entries = Object.entries(properties ?? {});
|
|
144
|
+
if (entries.length === 0)
|
|
145
|
+
console.log(" (none)");
|
|
146
|
+
for (const [name, value] of entries)
|
|
147
|
+
console.log(` ${name}: ${JSON.stringify(value)}`);
|
|
148
|
+
}
|
|
149
|
+
/** A member: the roster row, then the properties. */
|
|
150
|
+
function printAppUser(user) {
|
|
151
|
+
keyValue("User ID", user.userId);
|
|
152
|
+
keyValue("Email", user.email ?? "");
|
|
153
|
+
keyValue("Name", user.name ?? "");
|
|
154
|
+
keyValue("Role", user.role ?? "");
|
|
155
|
+
keyValue("Status", formatStatus(user.status));
|
|
156
|
+
if (user.disabledAt)
|
|
157
|
+
keyValue("Disabled", formatDate(user.disabledAt));
|
|
158
|
+
keyValue("Added", user.addedAt ? formatDate(user.addedAt) : "");
|
|
159
|
+
printProperties(user.properties);
|
|
160
|
+
}
|
|
9
161
|
/** `--test-users`, refused before any request when not one of the three modes. */
|
|
10
162
|
function parseTestUsersMode(value) {
|
|
11
163
|
if (value === undefined)
|
|
@@ -16,6 +168,66 @@ function parseTestUsersMode(value) {
|
|
|
16
168
|
}
|
|
17
169
|
return value;
|
|
18
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Where an invitation row stands, read the way the invitation lookup reads it:
|
|
173
|
+
* accepted wins, then a past `expiresAt` makes it expired.
|
|
174
|
+
*/
|
|
175
|
+
function invitationStatus(inv) {
|
|
176
|
+
if (inv.accepted)
|
|
177
|
+
return "accepted";
|
|
178
|
+
if (inv.expiresAt && new Date(inv.expiresAt) < new Date())
|
|
179
|
+
return "expired";
|
|
180
|
+
return "pending";
|
|
181
|
+
}
|
|
182
|
+
/** A server message as the middle of a sentence: its own final stop dropped. */
|
|
183
|
+
function withoutFinalStop(message) {
|
|
184
|
+
return message.replace(/[.\s]+$/, "");
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* The accept link of each invitation on a page, `null` where there is none.
|
|
188
|
+
*
|
|
189
|
+
* Only a pending invitation has one: the platform's accept URL,
|
|
190
|
+
* `<baseUrl>/invite/accept?inviteToken=<token>`, which the invitation email
|
|
191
|
+
* carries and the templates route. The base URL comes from one settings read
|
|
192
|
+
* and each token from one point read of that invitation, so the cost is
|
|
193
|
+
* bounded by the page. An app without a base URL costs no point read. A read
|
|
194
|
+
* that fails leaves its links `null` and says why on stderr; the listing
|
|
195
|
+
* itself still succeeds.
|
|
196
|
+
*/
|
|
197
|
+
async function invitationAcceptLinks(client, appId, invitations) {
|
|
198
|
+
const links = invitations.map(() => null);
|
|
199
|
+
const pending = invitations
|
|
200
|
+
.map((inv, i) => ({ inv, i }))
|
|
201
|
+
.filter(({ inv }) => invitationStatus(inv) === "pending");
|
|
202
|
+
if (pending.length === 0)
|
|
203
|
+
return links;
|
|
204
|
+
let baseUrl;
|
|
205
|
+
try {
|
|
206
|
+
const settings = await client.getAppSettings(appId);
|
|
207
|
+
baseUrl = String(settings?.baseUrl ?? "").replace(/\/+$/, "");
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
warn(`Accept links are unavailable: the app settings could not be read: ${withoutFinalStop(err.message)}.`);
|
|
211
|
+
return links;
|
|
212
|
+
}
|
|
213
|
+
if (!baseUrl) {
|
|
214
|
+
warn("Accept links are unavailable: the app has no base URL. " +
|
|
215
|
+
"Set [app].baseUrl in app.toml and run 'primitive config push --only app'.");
|
|
216
|
+
return links;
|
|
217
|
+
}
|
|
218
|
+
for (const { inv, i } of pending) {
|
|
219
|
+
try {
|
|
220
|
+
const read = await client.getInvitation(appId, inv.invitationId);
|
|
221
|
+
if (!read.inviteToken)
|
|
222
|
+
throw new Error("the invitation has no invite token");
|
|
223
|
+
links[i] = `${baseUrl}/invite/accept?inviteToken=${encodeURIComponent(read.inviteToken)}`;
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
warn(`Accept link for ${inv.invitationId} unavailable: ${withoutFinalStop(err.message)}.`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return links;
|
|
230
|
+
}
|
|
19
231
|
export function registerUsersCommands(program) {
|
|
20
232
|
const users = program
|
|
21
233
|
.command("users")
|
|
@@ -30,6 +242,12 @@ Examples:
|
|
|
30
242
|
$ primitive users invite user@example.com --role admin
|
|
31
243
|
$ primitive users set-role 01HXY... member
|
|
32
244
|
$ primitive users mint-jwt <user-id>
|
|
245
|
+
$ primitive users query --filter '{"role":"admin"}' --sort '{"addedAt":-1}'
|
|
246
|
+
$ primitive users count --filter '{"status":"disabled"}'
|
|
247
|
+
$ primitive users aggregate --op count --group-by role --sort '{"field":"count","direction":-1}'
|
|
248
|
+
$ primitive users get 01HXY...
|
|
249
|
+
$ primitive users get-by handle ada
|
|
250
|
+
$ primitive users set-properties 01HXY... --data '{"plan":"pro"}' --add-to-set tags=beta
|
|
33
251
|
`);
|
|
34
252
|
// List users
|
|
35
253
|
users
|
|
@@ -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
|
+
commandStatus(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
|
+
}), { stability: "beta" });
|
|
477
|
+
commandStatus(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
|
+
}), { stability: "beta" });
|
|
501
|
+
commandStatus(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
|
+
}), { stability: "beta" });
|
|
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
|
+
commandStatus(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
|
+
})), { stability: "beta" });
|
|
594
|
+
commandStatus(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
|
+
})), { stability: "beta" });
|
|
630
|
+
commandStatus(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
|
+
})), { stability: "beta" });
|
|
688
|
+
commandStatus(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
|
+
})), { stability: "beta" });
|
|
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
|
+
commandStatus(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
|
+
})), { stability: "beta" });
|
|
782
|
+
commandStatus(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
|
+
}), { stability: "beta" });
|
|
799
|
+
commandStatus(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
|
+
}), { stability: "beta" });
|
|
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("
|
|
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.
|
|
874
|
+
const result = await client.inviteUser(resolvedAppId, {
|
|
246
875
|
email,
|
|
247
876
|
role: options.role,
|
|
248
|
-
|
|
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);
|
|
@@ -311,6 +943,7 @@ Examples:
|
|
|
311
943
|
process.exit(1);
|
|
312
944
|
}
|
|
313
945
|
});
|
|
946
|
+
subcommandStatus(users, "remove", { stability: "production", deprecated: true });
|
|
314
947
|
// #2803 — an app user could be disabled from the console but not from the
|
|
315
948
|
// CLI, and the console could not undo it. Both routes already existed; the
|
|
316
949
|
// operational control just was not reachable. Deliberately distinct from
|
|
@@ -456,6 +1089,90 @@ Examples:
|
|
|
456
1089
|
process.exit(1);
|
|
457
1090
|
}
|
|
458
1091
|
});
|
|
1092
|
+
// ---- One app user's properties (#5386): get, get-by, set-properties ----
|
|
1093
|
+
commandStatus(users
|
|
1094
|
+
.command("get")
|
|
1095
|
+
.description("Show one member of an app with their properties")
|
|
1096
|
+
// Optional in commander, required in the action, as set-profile does.
|
|
1097
|
+
.argument("[app-id]", "App ID (uses current app if not specified)")
|
|
1098
|
+
.argument("[user-id]", "User ID (required)")
|
|
1099
|
+
.option("--app <app-id>", "App ID")
|
|
1100
|
+
.option("--json", "Output as JSON")
|
|
1101
|
+
.action(async (appIdOrUserId, userIdOrUndefined, options) => {
|
|
1102
|
+
const { appId, userId } = appAndUser(appIdOrUserId, userIdOrUndefined, options);
|
|
1103
|
+
const client = new ApiClient();
|
|
1104
|
+
try {
|
|
1105
|
+
const user = await client.getAppUser(appId, userId);
|
|
1106
|
+
if (options.json) {
|
|
1107
|
+
json(user);
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
printAppUser(user);
|
|
1111
|
+
}
|
|
1112
|
+
catch (err) {
|
|
1113
|
+
error(describeUserPropertyFailure(err));
|
|
1114
|
+
process.exit(1);
|
|
1115
|
+
}
|
|
1116
|
+
}), { stability: "beta" });
|
|
1117
|
+
commandStatus(users
|
|
1118
|
+
.command("get-by")
|
|
1119
|
+
.description("Find the member who holds a unique property value, or a unique constraint's values in declared order")
|
|
1120
|
+
.argument("<name>", "A unique property or a unique constraint")
|
|
1121
|
+
.argument("<value...>", "The value (one for a property, the constituents' values in order for a constraint); each is parsed as JSON when it parses")
|
|
1122
|
+
.option("--app <app-id>", "App ID")
|
|
1123
|
+
.option("--json", "Output as JSON")
|
|
1124
|
+
.action(async (name, values, options) => {
|
|
1125
|
+
const appId = resolveAppId(undefined, options);
|
|
1126
|
+
const parsed = values.map(jsonOrString);
|
|
1127
|
+
const client = new ApiClient();
|
|
1128
|
+
try {
|
|
1129
|
+
const { user } = await client.getAppUserBy(appId, parsed.length === 1 ? { field: name, value: parsed[0] } : { constraint: name, values: parsed });
|
|
1130
|
+
if (options.json) {
|
|
1131
|
+
json(user);
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
if (!user) {
|
|
1135
|
+
info(`No user holds ${name} = ${values.join(", ")}.`);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
printAppUser(user);
|
|
1139
|
+
}
|
|
1140
|
+
catch (err) {
|
|
1141
|
+
error(describeUserPropertyFailure(err));
|
|
1142
|
+
process.exit(1);
|
|
1143
|
+
}
|
|
1144
|
+
}), { stability: "beta" });
|
|
1145
|
+
commandStatus(users
|
|
1146
|
+
.command("set-properties")
|
|
1147
|
+
.description("Set a member's properties: a merge-patch, set additions and removals, and an optional condition")
|
|
1148
|
+
.argument("[app-id]", "App ID (uses current app if not specified)")
|
|
1149
|
+
.argument("[user-id]", "User ID (required)")
|
|
1150
|
+
.option("--data <json>", 'Properties to set as a JSON object, e.g. \'{"plan":"pro"}\'; null clears one')
|
|
1151
|
+
.option("--data-file <path>", "Read the properties to set from a JSON file")
|
|
1152
|
+
.option("--unset <field>", "Clear a property (its default shows on read); repeat for more", collectOption, [])
|
|
1153
|
+
.option("--add-to-set <field=value>", "Add a string to a stringset property; repeat for more", collectOption, [])
|
|
1154
|
+
.option("--remove-from-set <field=value>", "Remove a string from a stringset property; repeat for more", collectOption, [])
|
|
1155
|
+
.option("--condition <json>", 'Write only if this filter holds, e.g. \'{"properties.plan":"free"}\'')
|
|
1156
|
+
.option("--app <app-id>", "App ID")
|
|
1157
|
+
.option("--json", "Output as JSON")
|
|
1158
|
+
.action(async (appIdOrUserId, userIdOrUndefined, options) => {
|
|
1159
|
+
const { appId, userId } = appAndUser(appIdOrUserId, userIdOrUndefined, options);
|
|
1160
|
+
const body = propertiesWriteOf(options);
|
|
1161
|
+
const client = new ApiClient();
|
|
1162
|
+
try {
|
|
1163
|
+
const user = await client.setAppUserProperties(appId, userId, body);
|
|
1164
|
+
if (options.json) {
|
|
1165
|
+
json(user);
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
success(`Properties updated for ${userId}.`);
|
|
1169
|
+
printProperties(user.properties);
|
|
1170
|
+
}
|
|
1171
|
+
catch (err) {
|
|
1172
|
+
error(describeUserPropertyFailure(err));
|
|
1173
|
+
process.exit(1);
|
|
1174
|
+
}
|
|
1175
|
+
}), { stability: "beta" });
|
|
459
1176
|
// Set user role
|
|
460
1177
|
users
|
|
461
1178
|
.command("set-role")
|
|
@@ -509,12 +1226,13 @@ Examples:
|
|
|
509
1226
|
users
|
|
510
1227
|
.command("transfer-owner")
|
|
511
1228
|
.description("Transfer app ownership to another user")
|
|
512
|
-
.argument("[app-id]", "App ID
|
|
513
|
-
.argument("
|
|
1229
|
+
.argument("[app-id-or-target]", "App ID, or the new owner's email or admin ID")
|
|
1230
|
+
.argument("[email-or-admin-id]", "New owner's email or admin ID (if first arg is app ID)")
|
|
514
1231
|
.option("--app <app-id>", "App ID")
|
|
515
1232
|
.option("-y, --yes", "Skip confirmation prompt")
|
|
516
1233
|
.action(async (appIdOrTarget, targetOrUndefined, options) => {
|
|
517
|
-
//
|
|
1234
|
+
// Both positionals are optional so `transfer-owner <email>` binds the
|
|
1235
|
+
// one value to the target rather than to the app id (#3645).
|
|
518
1236
|
let resolvedAppId;
|
|
519
1237
|
let target;
|
|
520
1238
|
if (targetOrUndefined) {
|
|
@@ -560,39 +1278,155 @@ Examples:
|
|
|
560
1278
|
process.exit(1);
|
|
561
1279
|
}
|
|
562
1280
|
});
|
|
563
|
-
//
|
|
564
|
-
users
|
|
1281
|
+
// --- App invitations subcommands ---
|
|
1282
|
+
const invitations = users
|
|
565
1283
|
.command("invitations")
|
|
566
|
-
.description("List
|
|
1284
|
+
.description("List and revoke app invitations");
|
|
1285
|
+
invitations
|
|
1286
|
+
.command("list")
|
|
1287
|
+
.description("List invitations with their status and accept links")
|
|
567
1288
|
.argument("[app-id]", "App ID (uses current app if not specified)")
|
|
568
1289
|
.option("--app <app-id>", "App ID")
|
|
1290
|
+
.addOption(pageLimitOption())
|
|
1291
|
+
.addOption(pageCursorOption())
|
|
569
1292
|
.option("--json", "Output as JSON")
|
|
570
1293
|
.action(async (appId, options) => {
|
|
1294
|
+
const limit = parsePageLimit(options.limit);
|
|
571
1295
|
const resolvedAppId = resolveAppId(appId, options);
|
|
572
1296
|
const client = new ApiClient();
|
|
1297
|
+
const params = {};
|
|
1298
|
+
if (limit !== undefined)
|
|
1299
|
+
params.limit = limit;
|
|
1300
|
+
if (options.cursor)
|
|
1301
|
+
params.cursor = options.cursor;
|
|
573
1302
|
try {
|
|
574
|
-
const
|
|
575
|
-
const
|
|
1303
|
+
const page = normalizeCliListEnvelope(await client.listInvitations(resolvedAppId, params));
|
|
1304
|
+
const links = await invitationAcceptLinks(client, resolvedAppId, page.items);
|
|
1305
|
+
const items = page.items.map((inv, i) => ({
|
|
1306
|
+
...inv,
|
|
1307
|
+
acceptLink: links[i],
|
|
1308
|
+
}));
|
|
576
1309
|
if (options.json) {
|
|
577
|
-
json(
|
|
1310
|
+
json({ ...page, items });
|
|
578
1311
|
return;
|
|
579
1312
|
}
|
|
580
|
-
if (
|
|
581
|
-
|
|
1313
|
+
if (items.length === 0) {
|
|
1314
|
+
printEmptyPage(page, "invitations", "No invitations.");
|
|
582
1315
|
return;
|
|
583
1316
|
}
|
|
584
|
-
|
|
1317
|
+
const rows = items.map((inv) => {
|
|
1318
|
+
const status = invitationStatus(inv);
|
|
1319
|
+
return {
|
|
1320
|
+
...inv,
|
|
1321
|
+
status,
|
|
1322
|
+
acceptLinkCell: status !== "pending" ? "-" : (inv.acceptLink ?? "unavailable"),
|
|
1323
|
+
};
|
|
1324
|
+
});
|
|
1325
|
+
console.log(formatTable(rows, [
|
|
585
1326
|
{ header: "ID", key: "invitationId", format: formatId },
|
|
586
1327
|
{ header: "EMAIL", key: "email" },
|
|
587
1328
|
{ header: "ROLE", key: "role" },
|
|
1329
|
+
{ header: "STATUS", key: "status", format: formatStatus },
|
|
588
1330
|
{ header: "EXPIRES", key: "expiresAt", format: formatDate },
|
|
1331
|
+
{ header: "ACCEPT LINK", key: "acceptLinkCell" },
|
|
589
1332
|
]));
|
|
1333
|
+
printPageHint(page);
|
|
590
1334
|
}
|
|
591
1335
|
catch (err) {
|
|
592
1336
|
error(err.message);
|
|
593
1337
|
process.exit(1);
|
|
594
1338
|
}
|
|
595
1339
|
});
|
|
1340
|
+
invitations
|
|
1341
|
+
.command("revoke")
|
|
1342
|
+
.description("Revoke an app invitation; for an admin invitation, also delete its console admin invitations")
|
|
1343
|
+
.argument("<invitation-id>", "Invitation ID")
|
|
1344
|
+
.option("--app <app-id>", "App ID")
|
|
1345
|
+
.option("-y, --yes", "Skip confirmation prompt")
|
|
1346
|
+
.option("--json", "Output as JSON")
|
|
1347
|
+
.action(async (invitationId, options) => {
|
|
1348
|
+
const resolvedAppId = resolveAppId(undefined, options);
|
|
1349
|
+
if (!options.yes) {
|
|
1350
|
+
let confirm;
|
|
1351
|
+
try {
|
|
1352
|
+
confirm = await confirmPrompt(`Revoke invitation ${invitationId}?`);
|
|
1353
|
+
}
|
|
1354
|
+
catch (err) {
|
|
1355
|
+
error(err.message);
|
|
1356
|
+
process.exit(1);
|
|
1357
|
+
}
|
|
1358
|
+
if (!confirm) {
|
|
1359
|
+
info("Cancelled.");
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
const client = new ApiClient();
|
|
1364
|
+
// The role and email the console admin cross-delete needs come from the
|
|
1365
|
+
// invitation itself, read before anything is deleted.
|
|
1366
|
+
let invitation;
|
|
1367
|
+
try {
|
|
1368
|
+
invitation = await client.getInvitation(resolvedAppId, invitationId);
|
|
1369
|
+
await client.deleteInvitation(resolvedAppId, invitationId);
|
|
1370
|
+
}
|
|
1371
|
+
catch (err) {
|
|
1372
|
+
error(err.message);
|
|
1373
|
+
process.exit(1);
|
|
1374
|
+
}
|
|
1375
|
+
const { email, role } = invitation;
|
|
1376
|
+
const consoleAdminInvitations = { deleted: [], outstanding: [] };
|
|
1377
|
+
let failure;
|
|
1378
|
+
if (!options.json)
|
|
1379
|
+
success(`Invitation ${invitationId} for ${email} revoked.`);
|
|
1380
|
+
if (role === "admin") {
|
|
1381
|
+
let matching;
|
|
1382
|
+
try {
|
|
1383
|
+
const listed = await client.listAppAdminInvitations(resolvedAppId);
|
|
1384
|
+
matching = listed
|
|
1385
|
+
.filter((inv) => String(inv.email ?? "").toLowerCase() === email.toLowerCase())
|
|
1386
|
+
.map((inv) => inv.invitationId);
|
|
1387
|
+
}
|
|
1388
|
+
catch (err) {
|
|
1389
|
+
consoleAdminInvitations.error = err.message;
|
|
1390
|
+
failure =
|
|
1391
|
+
`Invitation ${invitationId} revoked, but the console admin invitations for ${email} ` +
|
|
1392
|
+
`could not be read: ${withoutFinalStop(err.message)}. ` +
|
|
1393
|
+
`Run 'primitive users admin-invitations list' and delete any for ${email}.`;
|
|
1394
|
+
}
|
|
1395
|
+
if (matching) {
|
|
1396
|
+
// Every match is attempted, so the outstanding list is exact.
|
|
1397
|
+
for (const id of matching) {
|
|
1398
|
+
try {
|
|
1399
|
+
await client.deleteAppAdminInvitation(resolvedAppId, id);
|
|
1400
|
+
consoleAdminInvitations.deleted.push(id);
|
|
1401
|
+
if (!options.json) {
|
|
1402
|
+
success(`Console admin invitation ${id} for ${email} deleted.`);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
catch (err) {
|
|
1406
|
+
consoleAdminInvitations.outstanding.push(id);
|
|
1407
|
+
consoleAdminInvitations.error ??= err.message;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (matching.length === 0 && !options.json) {
|
|
1411
|
+
info(`No console admin invitation for ${email} was outstanding.`);
|
|
1412
|
+
}
|
|
1413
|
+
if (consoleAdminInvitations.outstanding.length > 0) {
|
|
1414
|
+
failure =
|
|
1415
|
+
`Invitation ${invitationId} revoked, but console admin invitation(s) for ${email} ` +
|
|
1416
|
+
`still outstanding: ${consoleAdminInvitations.outstanding.join(", ")}. ` +
|
|
1417
|
+
`${withoutFinalStop(consoleAdminInvitations.error)}. ` +
|
|
1418
|
+
`Delete them with 'primitive users admin-invitations delete <id>'.`;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
if (options.json) {
|
|
1423
|
+
json({ invitationId, email, role, revoked: true, consoleAdminInvitations });
|
|
1424
|
+
}
|
|
1425
|
+
if (failure) {
|
|
1426
|
+
error(failure);
|
|
1427
|
+
process.exit(1);
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
596
1430
|
// --- Console admins subcommands ---
|
|
597
1431
|
const admins = users
|
|
598
1432
|
.command("admins")
|
|
@@ -906,4 +1740,33 @@ Examples:
|
|
|
906
1740
|
}
|
|
907
1741
|
});
|
|
908
1742
|
}
|
|
1743
|
+
/** The human form of `users index status`. */
|
|
1744
|
+
function printUserIndexStatus(status) {
|
|
1745
|
+
console.log(`User index of ${status.appId} (${status.environment})`);
|
|
1746
|
+
console.log(` Generation: ${status.generation ?? "none yet"}`);
|
|
1747
|
+
console.log(` Queue: ${status.queue?.pending ?? 0} pending, ${status.queue?.dead ?? 0} dead`);
|
|
1748
|
+
const lastApply = status.lastApply;
|
|
1749
|
+
console.log(` Last apply: ${lastApply ? `${formatDate(lastApply.at)} (${lastApply.count} user(s), ${lastApply.ms} ms)` : "never"}`);
|
|
1750
|
+
const last = status.lastReconcile;
|
|
1751
|
+
console.log(` Last reconcile: ${last ? `${formatDate(last.at)} (${formatReconcileCounts(last.counts)})` : "never"}`);
|
|
1752
|
+
if (status.revalidation) {
|
|
1753
|
+
console.log(` Revalidation: ${formatRevalidationLine(status.revalidation)}`);
|
|
1754
|
+
console.log(` Last slice: ${formatLastSliceLine(status.revalidation.lastSlice)}`);
|
|
1755
|
+
}
|
|
1756
|
+
const limits = status.limits ?? {};
|
|
1757
|
+
console.log(` Limits: threshold ${limits.placed}, bytes ${limits.bytes}, ceiling ${limits.ceiling} (${limits.source})`);
|
|
1758
|
+
console.log(` Ceiling reached: ${status.ceilingReached ? "yes" : "no"}`);
|
|
1759
|
+
if (status.build) {
|
|
1760
|
+
const build = status.build;
|
|
1761
|
+
console.log(` Rebuild: generation ${build.generation} since ${formatDate(build.startedAt)}, ${build.scanned} scanned, frontier ${build.frontier ?? "-"}`);
|
|
1762
|
+
}
|
|
1763
|
+
if (status.reconcile?.running)
|
|
1764
|
+
console.log(` Reconciling: a slice of generation ${status.reconcile.running.generation}, ${status.reconcile.running.chunks} continuation(s)`);
|
|
1765
|
+
console.log("");
|
|
1766
|
+
console.log(formatUserIndexShards(status.shards ?? []));
|
|
1767
|
+
for (const entry of status.superseded ?? []) {
|
|
1768
|
+
const pins = entry.pins?.length ? `pinned by ${entry.pins.join(", ")}` : "no pins";
|
|
1769
|
+
console.log(`Superseded generation ${entry.generation}: ${entry.shards.length} shard(s), retires after ${formatDate(entry.retireAfter)}, ${pins}`);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
909
1772
|
//# sourceMappingURL=users.js.map
|