@seamapi/cli 0.18.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -1
- package/bin/cli.js +73 -249
- package/bin/cli.js.map +1 -1
- package/lib/args/coerce.d.ts +28 -0
- package/lib/args/coerce.js +131 -0
- package/lib/args/coerce.js.map +1 -0
- package/lib/{util/cli-args.d.ts → args/parse.d.ts} +12 -15
- package/lib/{util/cli-args.js → args/parse.js} +21 -24
- package/lib/args/parse.js.map +1 -0
- package/lib/args/validate.d.ts +23 -0
- package/lib/args/validate.js +42 -0
- package/lib/args/validate.js.map +1 -0
- package/lib/auth/operations.d.ts +54 -0
- package/lib/auth/operations.js +115 -0
- package/lib/auth/operations.js.map +1 -0
- package/lib/{validate-token.js → auth/validate-token.js} +2 -2
- package/lib/auth/validate-token.js.map +1 -0
- package/lib/blueprint/cache.d.ts +16 -0
- package/lib/blueprint/cache.js +73 -0
- package/lib/blueprint/cache.js.map +1 -0
- package/lib/blueprint/endpoint.d.ts +14 -0
- package/lib/{get-response-key.js → blueprint/endpoint.js} +11 -2
- package/lib/blueprint/endpoint.js.map +1 -0
- package/lib/blueprint/index.d.ts +12 -0
- package/lib/blueprint/index.js +10 -0
- package/lib/blueprint/index.js.map +1 -0
- package/lib/blueprint/source-npm.d.ts +10 -0
- package/lib/{blueprint.js → blueprint/source-npm.js} +20 -74
- package/lib/blueprint/source-npm.js.map +1 -0
- package/lib/blueprint/source-remote.d.ts +6 -0
- package/lib/blueprint/source-remote.js +14 -0
- package/lib/blueprint/source-remote.js.map +1 -0
- package/lib/commands/api-command.d.ts +8 -0
- package/lib/commands/api-command.js +71 -0
- package/lib/commands/api-command.js.map +1 -0
- package/lib/commands/local/completion.d.ts +18 -0
- package/lib/commands/local/completion.js +35 -0
- package/lib/commands/local/completion.js.map +1 -0
- package/lib/commands/local/config-reveal-location.d.ts +2 -0
- package/lib/commands/local/config-reveal-location.js +15 -0
- package/lib/commands/local/config-reveal-location.js.map +1 -0
- package/lib/commands/local/config-set-fake-server.d.ts +3 -0
- package/lib/commands/local/config-set-fake-server.js +20 -0
- package/lib/commands/local/config-set-fake-server.js.map +1 -0
- package/lib/commands/local/config-use-remote-api-defs.d.ts +2 -0
- package/lib/commands/local/config-use-remote-api-defs.js +20 -0
- package/lib/commands/local/config-use-remote-api-defs.js.map +1 -0
- package/lib/commands/local/health.d.ts +2 -0
- package/lib/commands/local/health.js +18 -0
- package/lib/commands/local/health.js.map +1 -0
- package/lib/commands/local/login.d.ts +2 -0
- package/lib/commands/local/login.js +35 -0
- package/lib/commands/local/login.js.map +1 -0
- package/lib/commands/local/logout.d.ts +2 -0
- package/lib/commands/local/logout.js +17 -0
- package/lib/commands/local/logout.js.map +1 -0
- package/lib/commands/local/select-server.d.ts +2 -0
- package/lib/commands/local/select-server.js +27 -0
- package/lib/commands/local/select-server.js.map +1 -0
- package/lib/commands/local/select-workspace.d.ts +2 -0
- package/lib/commands/local/select-workspace.js +22 -0
- package/lib/commands/local/select-workspace.js.map +1 -0
- package/lib/commands/local/wizard.d.ts +9 -0
- package/lib/commands/local/wizard.js +28 -0
- package/lib/commands/local/wizard.js.map +1 -0
- package/lib/commands/registry.d.ts +54 -0
- package/lib/commands/registry.js +64 -0
- package/lib/commands/registry.js.map +1 -0
- package/lib/{command-spec.d.ts → commands/spec.d.ts} +8 -12
- package/lib/{command-spec.js → commands/spec.js} +27 -120
- package/lib/commands/spec.js.map +1 -0
- package/lib/config/config-store.d.ts +23 -8
- package/lib/config/config-store.js +16 -42
- package/lib/config/config-store.js.map +1 -1
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +2 -1
- package/lib/config/index.js.map +1 -1
- package/lib/config/memory-config-store.d.ts +21 -0
- package/lib/config/memory-config-store.js +48 -0
- package/lib/config/memory-config-store.js.map +1 -0
- package/lib/config/migrate.js +1 -1
- package/lib/config/migrate.js.map +1 -1
- package/lib/config/values.d.ts +12 -0
- package/lib/config/values.js +50 -0
- package/lib/config/values.js.map +1 -0
- package/lib/context.d.ts +37 -0
- package/lib/context.js +31 -0
- package/lib/context.js.map +1 -0
- package/lib/env.d.ts +5 -0
- package/lib/env.js +5 -0
- package/lib/env.js.map +1 -1
- package/lib/errors.d.ts +31 -0
- package/lib/errors.js +58 -0
- package/lib/errors.js.map +1 -0
- package/lib/http/api.d.ts +37 -0
- package/lib/http/api.js +20 -0
- package/lib/http/api.js.map +1 -0
- package/lib/http/client.d.ts +4 -0
- package/lib/{get-seam.js → http/client.js} +16 -17
- package/lib/http/client.js.map +1 -0
- package/lib/http/follow-ups.d.ts +6 -0
- package/lib/http/follow-ups.js +30 -0
- package/lib/http/follow-ups.js.map +1 -0
- package/lib/http/memory-seam-api.d.ts +22 -0
- package/lib/http/memory-seam-api.js +41 -0
- package/lib/http/memory-seam-api.js.map +1 -0
- package/lib/http/request.d.ts +19 -0
- package/lib/http/request.js +39 -0
- package/lib/http/request.js.map +1 -0
- package/lib/{interact-for-access-code.js → interactions/access-code.js} +4 -4
- package/lib/interactions/access-code.js.map +1 -0
- package/lib/{interact-for-acs-entrance.js → interactions/acs-entrance.js} +3 -3
- package/lib/interactions/acs-entrance.js.map +1 -0
- package/lib/{interact-for-acs-system.js → interactions/acs-system.js} +3 -3
- package/lib/interactions/acs-system.js.map +1 -0
- package/lib/{interact-for-acs-user.js → interactions/acs-user.js} +4 -4
- package/lib/interactions/acs-user.js.map +1 -0
- package/lib/{interact-for-action-attempt-poll.js → interactions/action-attempt-poll.js} +5 -5
- package/lib/interactions/action-attempt-poll.js.map +1 -0
- package/lib/{interact-for-array.js → interactions/array.js} +4 -3
- package/lib/interactions/array.js.map +1 -0
- package/lib/{interact-for-blueprint-object.d.ts → interactions/blueprint-object.d.ts} +3 -2
- package/lib/{interact-for-blueprint-object.js → interactions/blueprint-object.js} +49 -20
- package/lib/interactions/blueprint-object.js.map +1 -0
- package/lib/{interact-for-command-params.d.ts → interactions/command-params.d.ts} +2 -2
- package/lib/{interact-for-command-params.js → interactions/command-params.js} +4 -3
- package/lib/interactions/command-params.js.map +1 -0
- package/lib/interactions/command-selection.d.ts +10 -0
- package/lib/{interact-for-command-selection.js → interactions/command-selection.js} +9 -15
- package/lib/interactions/command-selection.js.map +1 -0
- package/lib/{interact-for-connected-account.js → interactions/connected-account.js} +3 -3
- package/lib/interactions/connected-account.js.map +1 -0
- package/lib/{interact-for-custom-metadata.js → interactions/custom-metadata.js} +4 -3
- package/lib/interactions/custom-metadata.js.map +1 -0
- package/lib/{interact-for-device.js → interactions/device.js} +3 -3
- package/lib/interactions/device.js.map +1 -0
- package/lib/interactions/index.d.ts +19 -0
- package/lib/interactions/index.js +20 -0
- package/lib/interactions/index.js.map +1 -0
- package/lib/{interact-for-login.js → interactions/login.js} +16 -14
- package/lib/interactions/login.js.map +1 -0
- package/lib/{interact-for-resource.js → interactions/resource.js} +3 -3
- package/lib/interactions/resource.js.map +1 -0
- package/lib/{interact-for-server-selection.js → interactions/server-selection.js} +10 -13
- package/lib/interactions/server-selection.js.map +1 -0
- package/lib/{interact-for-timestamp.js → interactions/timestamp.js} +2 -2
- package/lib/interactions/timestamp.js.map +1 -0
- package/lib/{interact-for-use-remote-api-defs.js → interactions/use-remote-api-defs.js} +5 -6
- package/lib/interactions/use-remote-api-defs.js.map +1 -0
- package/lib/{interact-for-user-identity.js → interactions/user-identity.js} +3 -3
- package/lib/interactions/user-identity.js.map +1 -0
- package/lib/{interact-for-workspace-id.js → interactions/workspace-id.js} +11 -10
- package/lib/interactions/workspace-id.js.map +1 -0
- package/lib/memory-prompt.d.ts +32 -0
- package/lib/memory-prompt.js +41 -0
- package/lib/memory-prompt.js.map +1 -0
- package/lib/output/get-output.d.ts +1 -1
- package/lib/output/get-output.js +1 -1
- package/lib/output/get-output.js.map +1 -1
- package/lib/output/{create-memory-output.d.ts → memory-output.d.ts} +1 -1
- package/lib/output/{create-memory-output.js → memory-output.js} +2 -2
- package/lib/output/memory-output.js.map +1 -0
- package/lib/output/{create-output.d.ts → output.d.ts} +18 -1
- package/lib/output/output.js +46 -0
- package/lib/output/output.js.map +1 -0
- package/lib/output/read-stdin-json.js.map +1 -0
- package/lib/output/resolve-output-format.d.ts +1 -1
- package/lib/{util → output}/with-loading.js +1 -1
- package/lib/output/with-loading.js.map +1 -0
- package/lib/prompt.d.ts +101 -0
- package/lib/{util/prompt.js → prompt.js} +83 -56
- package/lib/prompt.js.map +1 -0
- package/lib/{completion → render/completion}/describe.js +1 -2
- package/lib/render/completion/describe.js.map +1 -0
- package/lib/{completion → render/completion}/index.d.ts +2 -2
- package/lib/{completion → render/completion}/index.js +1 -2
- package/lib/render/completion/index.js.map +1 -0
- package/lib/{completion → render/completion}/render-bash.d.ts +1 -1
- package/lib/{completion → render/completion}/render-bash.js +1 -1
- package/lib/render/completion/render-bash.js.map +1 -0
- package/lib/{completion → render/completion}/render-fish.d.ts +1 -1
- package/lib/render/completion/render-fish.js.map +1 -0
- package/lib/{completion → render/completion}/render-zsh.d.ts +1 -1
- package/lib/{completion → render/completion}/render-zsh.js +1 -1
- package/lib/render/completion/render-zsh.js.map +1 -0
- package/lib/{render-help.d.ts → render/help.d.ts} +1 -1
- package/lib/{render-help.js → render/help.js} +2 -2
- package/lib/render/help.js.map +1 -0
- package/lib/render/text.d.ts +4 -0
- package/lib/render/text.js +16 -0
- package/lib/render/text.js.map +1 -0
- package/lib/version.d.ts +2 -2
- package/lib/version.js +2 -2
- package/package.json +4 -3
- package/src/bin/cli.ts +91 -332
- package/src/lib/args/coerce.ts +164 -0
- package/src/lib/{util/cli-args.ts → args/parse.ts} +30 -25
- package/src/lib/args/validate.ts +73 -0
- package/src/lib/auth/operations.ts +169 -0
- package/src/lib/{validate-token.ts → auth/validate-token.ts} +2 -2
- package/src/lib/blueprint/cache.ts +97 -0
- package/src/lib/{get-response-key.ts → blueprint/endpoint.ts} +17 -3
- package/src/lib/blueprint/index.ts +27 -0
- package/src/lib/{blueprint.ts → blueprint/source-npm.ts} +27 -99
- package/src/lib/blueprint/source-remote.ts +17 -0
- package/src/lib/commands/api-command.ts +109 -0
- package/src/lib/commands/local/completion.ts +51 -0
- package/src/lib/commands/local/config-reveal-location.ts +16 -0
- package/src/lib/commands/local/config-set-fake-server.ts +21 -0
- package/src/lib/commands/local/config-use-remote-api-defs.ts +23 -0
- package/src/lib/commands/local/health.ts +22 -0
- package/src/lib/commands/local/login.ts +42 -0
- package/src/lib/commands/local/logout.ts +18 -0
- package/src/lib/commands/local/select-server.ts +30 -0
- package/src/lib/commands/local/select-workspace.ts +25 -0
- package/src/lib/commands/local/wizard.ts +31 -0
- package/src/lib/commands/registry.ts +127 -0
- package/src/lib/{command-spec.ts → commands/spec.ts} +30 -131
- package/src/lib/config/config-store.ts +39 -64
- package/src/lib/config/index.ts +8 -1
- package/src/lib/config/memory-config-store.ts +62 -0
- package/src/lib/config/migrate.ts +1 -1
- package/src/lib/config/values.ts +72 -0
- package/src/lib/context.ts +84 -0
- package/src/lib/env.ts +9 -2
- package/src/lib/errors.ts +67 -0
- package/src/lib/http/api.ts +61 -0
- package/src/lib/{get-seam.ts → http/client.ts} +19 -18
- package/src/lib/http/follow-ups.ts +42 -0
- package/src/lib/http/memory-seam-api.ts +57 -0
- package/src/lib/http/request.ts +69 -0
- package/src/lib/{interact-for-access-code.ts → interactions/access-code.ts} +4 -3
- package/src/lib/{interact-for-acs-entrance.ts → interactions/acs-entrance.ts} +3 -2
- package/src/lib/{interact-for-acs-system.ts → interactions/acs-system.ts} +3 -2
- package/src/lib/{interact-for-acs-user.ts → interactions/acs-user.ts} +4 -3
- package/src/lib/{interact-for-action-attempt-poll.ts → interactions/action-attempt-poll.ts} +4 -4
- package/src/lib/{interact-for-array.ts → interactions/array.ts} +3 -3
- package/src/lib/{interact-for-blueprint-object.ts → interactions/blueprint-object.ts} +57 -24
- package/src/lib/{interact-for-command-params.ts → interactions/command-params.ts} +6 -4
- package/src/lib/{interact-for-command-selection.ts → interactions/command-selection.ts} +11 -23
- package/src/lib/{interact-for-connected-account.ts → interactions/connected-account.ts} +3 -2
- package/src/lib/{interact-for-custom-metadata.ts → interactions/custom-metadata.ts} +3 -7
- package/src/lib/{interact-for-device.ts → interactions/device.ts} +3 -2
- package/src/lib/interactions/index.ts +19 -0
- package/src/lib/{interact-for-login.ts → interactions/login.ts} +16 -13
- package/src/lib/{interact-for-resource.ts → interactions/resource.ts} +2 -2
- package/src/lib/{interact-for-server-selection.ts → interactions/server-selection.ts} +12 -17
- package/src/lib/{interact-for-timestamp.ts → interactions/timestamp.ts} +1 -1
- package/src/lib/{interact-for-use-remote-api-defs.ts → interactions/use-remote-api-defs.ts} +4 -5
- package/src/lib/{interact-for-user-identity.ts → interactions/user-identity.ts} +3 -2
- package/src/lib/{interact-for-workspace-id.ts → interactions/workspace-id.ts} +10 -17
- package/src/lib/memory-prompt.ts +89 -0
- package/src/lib/output/get-output.ts +1 -1
- package/src/lib/output/{create-memory-output.ts → memory-output.ts} +1 -1
- package/src/lib/output/{create-output.ts → output.ts} +47 -32
- package/src/lib/output/resolve-output-format.ts +1 -1
- package/src/lib/{util → output}/with-loading.ts +1 -1
- package/src/lib/prompt.ts +306 -0
- package/src/lib/{completion → render/completion}/describe.ts +1 -2
- package/src/lib/{completion → render/completion}/index.ts +3 -4
- package/src/lib/{completion → render/completion}/render-bash.ts +1 -1
- package/src/lib/{completion → render/completion}/render-fish.ts +2 -1
- package/src/lib/{completion → render/completion}/render-zsh.ts +2 -1
- package/src/lib/{render-help.ts → render/help.ts} +1 -1
- package/src/lib/render/text.ts +17 -0
- package/src/lib/version.ts +2 -2
- package/lib/blueprint.d.ts +0 -7
- package/lib/blueprint.js.map +0 -1
- package/lib/command-spec.js.map +0 -1
- package/lib/completion/describe.js.map +0 -1
- package/lib/completion/index.js.map +0 -1
- package/lib/completion/render-bash.js.map +0 -1
- package/lib/completion/render-fish.js.map +0 -1
- package/lib/completion/render-zsh.js.map +0 -1
- package/lib/get-api-blueprint.d.ts +0 -6
- package/lib/get-api-blueprint.js +0 -18
- package/lib/get-api-blueprint.js.map +0 -1
- package/lib/get-command-blueprint-def.d.ts +0 -2
- package/lib/get-command-blueprint-def.js +0 -11
- package/lib/get-command-blueprint-def.js.map +0 -1
- package/lib/get-credentials.d.ts +0 -15
- package/lib/get-credentials.js +0 -35
- package/lib/get-credentials.js.map +0 -1
- package/lib/get-current-workspace-id.d.ts +0 -1
- package/lib/get-current-workspace-id.js +0 -9
- package/lib/get-current-workspace-id.js.map +0 -1
- package/lib/get-response-key.d.ts +0 -9
- package/lib/get-response-key.js.map +0 -1
- package/lib/get-seam.d.ts +0 -3
- package/lib/get-seam.js.map +0 -1
- package/lib/get-server.d.ts +0 -6
- package/lib/get-server.js +0 -17
- package/lib/get-server.js.map +0 -1
- package/lib/interact-for-access-code.js.map +0 -1
- package/lib/interact-for-acs-entrance.js.map +0 -1
- package/lib/interact-for-acs-system.js.map +0 -1
- package/lib/interact-for-acs-user.js.map +0 -1
- package/lib/interact-for-action-attempt-poll.js.map +0 -1
- package/lib/interact-for-array.js.map +0 -1
- package/lib/interact-for-blueprint-object.js.map +0 -1
- package/lib/interact-for-command-params.js.map +0 -1
- package/lib/interact-for-command-selection.d.ts +0 -2
- package/lib/interact-for-command-selection.js.map +0 -1
- package/lib/interact-for-connected-account.js.map +0 -1
- package/lib/interact-for-custom-metadata.js.map +0 -1
- package/lib/interact-for-device.js.map +0 -1
- package/lib/interact-for-login.js.map +0 -1
- package/lib/interact-for-resource.js.map +0 -1
- package/lib/interact-for-server-selection.js.map +0 -1
- package/lib/interact-for-timestamp.js.map +0 -1
- package/lib/interact-for-use-remote-api-defs.js.map +0 -1
- package/lib/interact-for-user-identity.js.map +0 -1
- package/lib/interact-for-workspace-id.js.map +0 -1
- package/lib/output/create-memory-output.js.map +0 -1
- package/lib/output/create-output.js +0 -34
- package/lib/output/create-output.js.map +0 -1
- package/lib/render-help.js.map +0 -1
- package/lib/types.d.ts +0 -6
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/util/cli-args.js.map +0 -1
- package/lib/util/ellipsis.d.ts +0 -1
- package/lib/util/ellipsis.js +0 -6
- package/lib/util/ellipsis.js.map +0 -1
- package/lib/util/prompt.d.ts +0 -80
- package/lib/util/prompt.js.map +0 -1
- package/lib/util/read-stdin-json.js.map +0 -1
- package/lib/util/request-seam-api.d.ts +0 -7
- package/lib/util/request-seam-api.js +0 -26
- package/lib/util/request-seam-api.js.map +0 -1
- package/lib/util/with-loading.js.map +0 -1
- package/lib/validate-token.js.map +0 -1
- package/src/lib/get-api-blueprint.ts +0 -31
- package/src/lib/get-command-blueprint-def.ts +0 -15
- package/src/lib/get-credentials.ts +0 -38
- package/src/lib/get-current-workspace-id.ts +0 -9
- package/src/lib/get-server.ts +0 -20
- package/src/lib/types.ts +0 -7
- package/src/lib/util/ellipsis.ts +0 -4
- package/src/lib/util/prompt.ts +0 -229
- package/src/lib/util/request-seam-api.ts +0 -47
- /package/lib/{validate-token.d.ts → auth/validate-token.d.ts} +0 -0
- /package/lib/{interact-for-access-code.d.ts → interactions/access-code.d.ts} +0 -0
- /package/lib/{interact-for-acs-entrance.d.ts → interactions/acs-entrance.d.ts} +0 -0
- /package/lib/{interact-for-acs-system.d.ts → interactions/acs-system.d.ts} +0 -0
- /package/lib/{interact-for-acs-user.d.ts → interactions/acs-user.d.ts} +0 -0
- /package/lib/{interact-for-action-attempt-poll.d.ts → interactions/action-attempt-poll.d.ts} +0 -0
- /package/lib/{interact-for-array.d.ts → interactions/array.d.ts} +0 -0
- /package/lib/{interact-for-connected-account.d.ts → interactions/connected-account.d.ts} +0 -0
- /package/lib/{interact-for-custom-metadata.d.ts → interactions/custom-metadata.d.ts} +0 -0
- /package/lib/{interact-for-device.d.ts → interactions/device.d.ts} +0 -0
- /package/lib/{interact-for-login.d.ts → interactions/login.d.ts} +0 -0
- /package/lib/{interact-for-resource.d.ts → interactions/resource.d.ts} +0 -0
- /package/lib/{interact-for-server-selection.d.ts → interactions/server-selection.d.ts} +0 -0
- /package/lib/{interact-for-timestamp.d.ts → interactions/timestamp.d.ts} +0 -0
- /package/lib/{interact-for-use-remote-api-defs.d.ts → interactions/use-remote-api-defs.d.ts} +0 -0
- /package/lib/{interact-for-user-identity.d.ts → interactions/user-identity.d.ts} +0 -0
- /package/lib/{interact-for-workspace-id.d.ts → interactions/workspace-id.d.ts} +0 -0
- /package/lib/{util → output}/read-stdin-json.d.ts +0 -0
- /package/lib/{util → output}/read-stdin-json.js +0 -0
- /package/lib/{util → output}/with-loading.d.ts +0 -0
- /package/lib/{completion → render/completion}/describe.d.ts +0 -0
- /package/lib/{completion → render/completion}/render-fish.js +0 -0
- /package/src/lib/{util → output}/read-stdin-json.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coerce.js","sourceRoot":"","sources":["../../src/lib/args/coerce.ts"],"names":[],"mappings":"AAYA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAuB,EACvB,SAAkC,EAC4B,EAAE;IAChE,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC3D,CAAA;IAED,MAAM,MAAM,GAA4B,EAAE,CAAA;IAC1C,MAAM,MAAM,GAAoB,EAAE,CAAA;IAElC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACtD,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,SAAS,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;YACpB,SAAQ;QACV,CAAC;QAED,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;QAC7C,IAAI,OAAO,IAAI,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B,SAAyC,EACzC,IAAa,EACJ,EAAE;IACX,IAAI,SAAS,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,OAAO,IAAI,OAAO;YAAE,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAA;QAC7D,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;QACnC,IAAI,OAAO,IAAI,OAAO;YAAE,OAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE,CAAA;QACnE,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,IAAI,SAAS,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QAC1B,MAAM,KAAK,GAAG,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;QAC9D,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,EAAE,KAAK,EAAE,aAAa,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QACnD,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,CAAA;IAClB,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;AAChC,CAAC,CAAA"}
|
|
@@ -20,24 +20,21 @@ export declare const interactivityFlags: string[];
|
|
|
20
20
|
* and are therefore never sent as command parameters.
|
|
21
21
|
*/
|
|
22
22
|
export declare const cliFlags: string[];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export interface ParseCliArgsOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Argument keys read exactly as given rather than by guessing at a type,
|
|
26
|
+
* e.g., every parameter of an endpoint that does not take a number or a
|
|
27
|
+
* boolean. Read as a number, an opaque value like an access code would
|
|
28
|
+
* lose leading zeroes or turn exponent notation into a digit string.
|
|
29
|
+
*/
|
|
30
|
+
stringKeys?: string[];
|
|
28
31
|
}
|
|
32
|
+
export declare const parseCliArgs: (argv: string[], { stringKeys }?: ParseCliArgsOptions) => ParsedArgs;
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* The request params among the parsed arguments: every key normalized to
|
|
35
|
+
* the parameter it names, minus the flags that configure the CLI itself.
|
|
31
36
|
*/
|
|
32
|
-
export declare
|
|
33
|
-
name: string;
|
|
34
|
-
/** What to run instead, reported after the message. */
|
|
35
|
-
readonly hint: string;
|
|
36
|
-
constructor(message: string, { hint }?: {
|
|
37
|
-
hint?: string;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export declare const parseCliArgs: (argv: string[]) => ParsedArgs;
|
|
37
|
+
export declare const toArgParams: (args: ParsedArgs) => Record<string, unknown>;
|
|
41
38
|
export interface GetInteractivityOptions {
|
|
42
39
|
/**
|
|
43
40
|
* Whether there is a terminal to prompt on.
|
|
@@ -22,34 +22,31 @@ export const cliFlags = [
|
|
|
22
22
|
'update',
|
|
23
23
|
'version',
|
|
24
24
|
];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name = 'NonInteractiveError';
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Thrown when the arguments do not name something the CLI can run.
|
|
33
|
-
*/
|
|
34
|
-
export class UsageError extends Error {
|
|
35
|
-
name = 'UsageError';
|
|
36
|
-
/** What to run instead, reported after the message. */
|
|
37
|
-
hint;
|
|
38
|
-
constructor(message, { hint = '' } = {}) {
|
|
39
|
-
super(message);
|
|
40
|
-
this.hint = hint;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export const parseCliArgs = (argv) => parseArgs(argv, {
|
|
44
|
-
// A page cursor is opaque, so keep it exactly as given: read as a number
|
|
45
|
-
// it would lose leading zeroes and turn exponent notation into a digit
|
|
46
|
-
// string, naming a page the API never issued.
|
|
47
|
-
string: ['code', 'page-cursor', 'page_cursor'],
|
|
25
|
+
export const parseCliArgs = (argv, { stringKeys = [] } = {}) => parseArgs(argv, {
|
|
26
|
+
// A page cursor and a code are opaque even before the endpoint's own
|
|
27
|
+
// parameter types are known, so always keep them exactly as given.
|
|
28
|
+
string: ['code', 'page-cursor', 'page_cursor', ...stringKeys],
|
|
48
29
|
boolean: ['non-interactive', 'interactive', 'json'],
|
|
49
30
|
// Deliberately not aliased to -n, which is reserved for a future
|
|
50
31
|
// --dry-run flag.
|
|
51
32
|
alias: { 'non-interactive': 'y', interactive: 'i' },
|
|
52
33
|
});
|
|
34
|
+
/**
|
|
35
|
+
* The request params among the parsed arguments: every key normalized to
|
|
36
|
+
* the parameter it names, minus the flags that configure the CLI itself.
|
|
37
|
+
*/
|
|
38
|
+
export const toArgParams = (args) => {
|
|
39
|
+
const argParams = {};
|
|
40
|
+
for (const [key, value] of Object.entries(args)) {
|
|
41
|
+
if (key === '_')
|
|
42
|
+
continue;
|
|
43
|
+
const name = toParameterName(key);
|
|
44
|
+
if (cliFlags.includes(name))
|
|
45
|
+
continue;
|
|
46
|
+
argParams[name] = value;
|
|
47
|
+
}
|
|
48
|
+
return argParams;
|
|
49
|
+
};
|
|
53
50
|
export const getInteractivity = (args, { canPrompt = true } = {}) => {
|
|
54
51
|
const isNonInteractive = args['non_interactive'] === true || args['y'] === true;
|
|
55
52
|
const isInteractive = args['interactive'] === true || args['i'] === true;
|
|
@@ -80,4 +77,4 @@ export const toParameterName = (argKey) => argKey.toLowerCase().replace(/-/g, '_
|
|
|
80
77
|
* key as the short form it can only have been written as, e.g., `-n`.
|
|
81
78
|
*/
|
|
82
79
|
export const toGivenArgName = (argKey) => argKey.length === 1 ? `-${argKey}` : toArgName(argKey);
|
|
83
|
-
//# sourceMappingURL=
|
|
80
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/lib/args/parse.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,EAAE,EAAmB,MAAM,UAAU,CAAA;AAcrD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAa;IAC1C,iBAAiB;IACjB,GAAG;IACH,aAAa;IACb,GAAG;CACJ,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAa;IAChC,GAAG,kBAAkB;IACrB,GAAG;IACH,MAAM;IACN,MAAM;IACN,iBAAiB;IACjB,QAAQ;IACR,SAAS;CACV,CAAA;AAYD,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAc,EACd,EAAE,UAAU,GAAG,EAAE,KAA0B,EAAE,EACjC,EAAE,CACd,SAAS,CAAC,IAAI,EAAE;IACd,qEAAqE;IACrE,mEAAmE;IACnE,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,UAAU,CAAC;IAC7D,OAAO,EAAE,CAAC,iBAAiB,EAAE,aAAa,EAAE,MAAM,CAAC;IACnD,iEAAiE;IACjE,kBAAkB;IAClB,KAAK,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE;CACpD,CAAC,CAAA;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAgB,EAA2B,EAAE;IACvE,MAAM,SAAS,GAA4B,EAAE,CAAA;IAC7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,IAAI,GAAG,KAAK,GAAG;YAAE,SAAQ;QACzB,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;QAC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AAE,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Parameter } from '@seamapi/blueprint';
|
|
2
|
+
/**
|
|
3
|
+
* Report every required parameter still missing from the params, rather
|
|
4
|
+
* than prompting for it.
|
|
5
|
+
*
|
|
6
|
+
* @param target What the params are for, e.g., `/devices/list`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const assertRequiredParams: (parameters: Parameter[], params: Record<string, unknown>, target: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Report any argument the command does not accept, rather than acting on it.
|
|
11
|
+
* An unrecognized argument is a mistake: forwarded to the API it would fail
|
|
12
|
+
* somewhere less obvious or be quietly ignored, and on a command the CLI
|
|
13
|
+
* handles itself it would go nowhere at all.
|
|
14
|
+
*
|
|
15
|
+
* Only arguments are checked. Params read from stdin are passed through as
|
|
16
|
+
* given, so a caller may send whatever the API itself accepts.
|
|
17
|
+
*/
|
|
18
|
+
export declare const assertKnownArgs: (argParams: Record<string, unknown>, command: string[], { accepted, isLocal, }: {
|
|
19
|
+
/** Parameter names the command accepts. */
|
|
20
|
+
accepted: Set<string>;
|
|
21
|
+
/** Whether the CLI handles the command itself. */
|
|
22
|
+
isLocal: boolean;
|
|
23
|
+
}) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { NonInteractiveError, UsageError } from '../errors.js';
|
|
2
|
+
import { toArgName, toGivenArgName } from './parse.js';
|
|
3
|
+
/**
|
|
4
|
+
* Report every required parameter still missing from the params, rather
|
|
5
|
+
* than prompting for it.
|
|
6
|
+
*
|
|
7
|
+
* @param target What the params are for, e.g., `/devices/list`.
|
|
8
|
+
*/
|
|
9
|
+
export const assertRequiredParams = (parameters, params, target) => {
|
|
10
|
+
// A required parameter is satisfied by being present, not by being
|
|
11
|
+
// truthy: `false`, `0` and `''` are values a caller can supply.
|
|
12
|
+
const missing = parameters
|
|
13
|
+
.filter((parameter) => parameter.isRequired)
|
|
14
|
+
.map((parameter) => parameter.name)
|
|
15
|
+
.filter((name) => params[name] === undefined);
|
|
16
|
+
if (missing.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
throw new NonInteractiveError(`Missing required ${missing.length === 1 ? 'parameter' : 'parameters'} for ${target}: ${missing.map(toArgName).join(' ')}`);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Report any argument the command does not accept, rather than acting on it.
|
|
22
|
+
* An unrecognized argument is a mistake: forwarded to the API it would fail
|
|
23
|
+
* somewhere less obvious or be quietly ignored, and on a command the CLI
|
|
24
|
+
* handles itself it would go nowhere at all.
|
|
25
|
+
*
|
|
26
|
+
* Only arguments are checked. Params read from stdin are passed through as
|
|
27
|
+
* given, so a caller may send whatever the API itself accepts.
|
|
28
|
+
*/
|
|
29
|
+
export const assertKnownArgs = (argParams, command, { accepted, isLocal, }) => {
|
|
30
|
+
const unknown = Object.keys(argParams).filter((key) => !accepted.has(key));
|
|
31
|
+
if (unknown.length === 0)
|
|
32
|
+
return;
|
|
33
|
+
// Name an endpoint command by its path, as missing params are named, and a
|
|
34
|
+
// command the CLI handles itself by the words that run it.
|
|
35
|
+
const target = isLocal
|
|
36
|
+
? command.join(' ')
|
|
37
|
+
: `/${command.join('/').replace(/-/g, '_')}`;
|
|
38
|
+
throw new UsageError(`Unknown ${unknown.length === 1 ? 'parameter' : 'parameters'} for ${target}: ${unknown.map(toGivenArgName).join(' ')}`, {
|
|
39
|
+
hint: `Run 'seam ${command.join(' ')} --help' to see what it accepts.`,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/lib/args/validate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE/D,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YA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CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAA;IAE9C,MAAM,IAAI,UAAU,CAClB,WACE,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YACvC,QAAQ,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAC1D;QACE,IAAI,EAAE,aAAa,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,kCAAkC;KACvE,CACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type ConfigStore } from '../config/index.js';
|
|
2
|
+
import { type AuthContext } from '../context.js';
|
|
3
|
+
import { validateToken } from './validate-token.js';
|
|
4
|
+
/** A stored auth setting an environment variable may override. */
|
|
5
|
+
export type AuthSetting = 'server' | 'token' | 'workspaceId';
|
|
6
|
+
/**
|
|
7
|
+
* Refuse to store a setting the environment overrides.
|
|
8
|
+
*
|
|
9
|
+
* The env-override policy lives here alone: every auth mutation asserts
|
|
10
|
+
* through this before writing, so a command that appears to succeed cannot
|
|
11
|
+
* leave the CLI using something else.
|
|
12
|
+
*
|
|
13
|
+
* @param action What the command does, e.g., `log in`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const assertMutable: (auth: AuthContext, setting: AuthSetting, action: string) => void;
|
|
16
|
+
export interface LoginOptions {
|
|
17
|
+
server?: string | undefined;
|
|
18
|
+
token?: string | undefined;
|
|
19
|
+
workspaceId?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Store the given credentials, validating the token first.
|
|
23
|
+
*
|
|
24
|
+
* The token is stored under the server it will be used with, so a given
|
|
25
|
+
* server is stored and re-resolved before the token key is derived.
|
|
26
|
+
*
|
|
27
|
+
* Validation reaches the network, so a test may inject its own `validate`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const login: ({ server, token, workspaceId }: LoginOptions, config?: ConfigStore, validate?: typeof validateToken) => Promise<void>;
|
|
30
|
+
/** Store the token for the current server, e.g., one just prompted for. */
|
|
31
|
+
export declare const storeToken: (token: string, config?: ConfigStore) => void;
|
|
32
|
+
/** Remove the stored token and workspace selection. */
|
|
33
|
+
export declare const logout: (config?: ConfigStore) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Store the server to make requests against.
|
|
36
|
+
*
|
|
37
|
+
* The workspace selection belongs to the previous server, so it is cleared.
|
|
38
|
+
*/
|
|
39
|
+
export declare const selectServer: (server: string, config?: ConfigStore) => void;
|
|
40
|
+
/** Store the workspace requests are made against. */
|
|
41
|
+
export declare const selectWorkspace: (workspaceId: string, config?: ConfigStore) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Point the CLI at a fake Seam Connect server and store the well-known
|
|
44
|
+
* token it accepts. Returns the generated server URL for reporting.
|
|
45
|
+
*/
|
|
46
|
+
export declare const selectFakeServer: ({ urlSeed, config, }?: {
|
|
47
|
+
urlSeed?: string;
|
|
48
|
+
config?: ConfigStore;
|
|
49
|
+
}) => {
|
|
50
|
+
server: string;
|
|
51
|
+
token: string;
|
|
52
|
+
};
|
|
53
|
+
/** Store whether API definitions come from the server instead of npm. */
|
|
54
|
+
export declare const setUseRemoteApiDefs: (useRemoteApiDefs: boolean, config?: ConfigStore) => void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { getConfigStore } from '../config/index.js';
|
|
3
|
+
import { resolveAuth } from '../context.js';
|
|
4
|
+
import { assertEnvVarUnset, endpointEnvVar, tokenEnvVar, workspaceIdEnvVar, } from '../env.js';
|
|
5
|
+
import { validateToken } from './validate-token.js';
|
|
6
|
+
/**
|
|
7
|
+
* Refuse to store a setting the environment overrides.
|
|
8
|
+
*
|
|
9
|
+
* The env-override policy lives here alone: every auth mutation asserts
|
|
10
|
+
* through this before writing, so a command that appears to succeed cannot
|
|
11
|
+
* leave the CLI using something else.
|
|
12
|
+
*
|
|
13
|
+
* @param action What the command does, e.g., `log in`.
|
|
14
|
+
*/
|
|
15
|
+
export const assertMutable = (auth, setting, action) => {
|
|
16
|
+
const { envVar, source, value } = {
|
|
17
|
+
server: {
|
|
18
|
+
envVar: endpointEnvVar,
|
|
19
|
+
source: auth.serverSource,
|
|
20
|
+
value: auth.server,
|
|
21
|
+
},
|
|
22
|
+
token: { envVar: tokenEnvVar, source: auth.tokenSource, value: auth.token },
|
|
23
|
+
workspaceId: {
|
|
24
|
+
envVar: workspaceIdEnvVar,
|
|
25
|
+
source: auth.workspaceIdSource,
|
|
26
|
+
value: auth.workspaceId,
|
|
27
|
+
},
|
|
28
|
+
}[setting];
|
|
29
|
+
if (source !== 'env')
|
|
30
|
+
return;
|
|
31
|
+
assertEnvVarUnset(envVar, value, action);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Store the given credentials, validating the token first.
|
|
35
|
+
*
|
|
36
|
+
* The token is stored under the server it will be used with, so a given
|
|
37
|
+
* server is stored and re-resolved before the token key is derived.
|
|
38
|
+
*
|
|
39
|
+
* Validation reaches the network, so a test may inject its own `validate`.
|
|
40
|
+
*/
|
|
41
|
+
export const login = async ({ server, token, workspaceId }, config = getConfigStore(), validate = validateToken) => {
|
|
42
|
+
let auth = resolveAuth(config);
|
|
43
|
+
// Nothing is stored while the environment overrides it, so refuse before
|
|
44
|
+
// storing anything rather than part way through.
|
|
45
|
+
assertMutable(auth, 'token', 'log in');
|
|
46
|
+
if (server != null)
|
|
47
|
+
assertMutable(auth, 'server', 'select a server');
|
|
48
|
+
if (workspaceId != null) {
|
|
49
|
+
assertMutable(auth, 'workspaceId', 'select a workspace');
|
|
50
|
+
}
|
|
51
|
+
if (server != null) {
|
|
52
|
+
config.set('server', server);
|
|
53
|
+
config.delete('current_workspace_id');
|
|
54
|
+
auth = resolveAuth(config);
|
|
55
|
+
}
|
|
56
|
+
if (token != null) {
|
|
57
|
+
await validate(token, workspaceId);
|
|
58
|
+
config.set(`${auth.server}.pat`, token);
|
|
59
|
+
config.delete('current_workspace_id');
|
|
60
|
+
}
|
|
61
|
+
if (workspaceId != null) {
|
|
62
|
+
config.set('current_workspace_id', workspaceId);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/** Store the token for the current server, e.g., one just prompted for. */
|
|
66
|
+
export const storeToken = (token, config = getConfigStore()) => {
|
|
67
|
+
const auth = resolveAuth(config);
|
|
68
|
+
assertMutable(auth, 'token', 'log in');
|
|
69
|
+
config.set(`${auth.server}.pat`, token);
|
|
70
|
+
};
|
|
71
|
+
/** Remove the stored token and workspace selection. */
|
|
72
|
+
export const logout = (config = getConfigStore()) => {
|
|
73
|
+
const auth = resolveAuth(config);
|
|
74
|
+
assertMutable(auth, 'token', 'log out');
|
|
75
|
+
config.delete(`${auth.server}.pat`);
|
|
76
|
+
// Configs written before tokens were stored per server may still hold an
|
|
77
|
+
// un-namespaced token, so drop that too.
|
|
78
|
+
config.delete('pat');
|
|
79
|
+
config.delete('current_workspace_id');
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Store the server to make requests against.
|
|
83
|
+
*
|
|
84
|
+
* The workspace selection belongs to the previous server, so it is cleared.
|
|
85
|
+
*/
|
|
86
|
+
export const selectServer = (server, config = getConfigStore()) => {
|
|
87
|
+
assertMutable(resolveAuth(config), 'server', 'select a server');
|
|
88
|
+
config.set('server', server);
|
|
89
|
+
config.delete('current_workspace_id');
|
|
90
|
+
};
|
|
91
|
+
/** Store the workspace requests are made against. */
|
|
92
|
+
export const selectWorkspace = (workspaceId, config = getConfigStore()) => {
|
|
93
|
+
assertMutable(resolveAuth(config), 'workspaceId', 'select a workspace');
|
|
94
|
+
config.set('current_workspace_id', workspaceId);
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Point the CLI at a fake Seam Connect server and store the well-known
|
|
98
|
+
* token it accepts. Returns the generated server URL for reporting.
|
|
99
|
+
*/
|
|
100
|
+
export const selectFakeServer = ({ urlSeed = randomBytes(5).toString('hex'), config = getConfigStore(), } = {}) => {
|
|
101
|
+
const auth = resolveAuth(config);
|
|
102
|
+
assertMutable(auth, 'server', 'select a server');
|
|
103
|
+
assertMutable(auth, 'token', 'log in');
|
|
104
|
+
const server = `https://${urlSeed}.fakeseamconnect.seam.vc`;
|
|
105
|
+
const token = 'seam_apikey1_token';
|
|
106
|
+
config.set('server', server);
|
|
107
|
+
config.set(`${server}.pat`, token);
|
|
108
|
+
config.delete('current_workspace_id');
|
|
109
|
+
return { server, token };
|
|
110
|
+
};
|
|
111
|
+
/** Store whether API definitions come from the server instead of npm. */
|
|
112
|
+
export const setUseRemoteApiDefs = (useRemoteApiDefs, config = getConfigStore()) => {
|
|
113
|
+
config.set('use_remote_api_defs', useRemoteApiDefs);
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/lib/auth/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAoB,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAoB,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAKnD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,IAAiB,EACjB,OAAoB,EACpB,MAAc,EACR,EAAE;IACR,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;QAChC,MAAM,EAAE;YACN,MAAM,EAAE,cAAc;YACtB,MAAM,EAAE,IAAI,CAAC,YAAY;YACzB,KAAK,EAAE,IAAI,CAAC,MAAM;SACnB;QACD,KAAK,EAAE,EA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CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isApiKey, isPersonalAccessToken, SeamHttp, SeamHttpWithoutWorkspace, } from '@seamapi/http/connect';
|
|
2
|
-
import {
|
|
2
|
+
import { resolveAuth } from '../context.js';
|
|
3
3
|
export const validateToken = async (token, workspaceId) => {
|
|
4
|
-
const options = { endpoint:
|
|
4
|
+
const options = { endpoint: resolveAuth().server };
|
|
5
5
|
if (isPersonalAccessToken(token)) {
|
|
6
6
|
const seam = workspaceId
|
|
7
7
|
? SeamHttp.fromPersonalAccessToken(token, workspaceId, options)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-token.js","sourceRoot":"","sources":["../../src/lib/auth/validate-token.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,qBAAqB,EACrB,QAAQ,EACR,wBAAwB,GACzB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,KAAa,EAAE,WAAoB,EAAE,EAAE;IACzE,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,CAAA;IAElD,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,WAAW;YACtB,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC;YAC/D,CAAC,CAAC,wBAAwB,CAAC,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACpE,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;QAC5B,OAAM;IACR,CAAC;IAED,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAChD,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAA;QAC5B,OAAM;IACR,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAA;AAC/E,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Blueprint } from '@seamapi/blueprint';
|
|
2
|
+
export interface BlueprintCache {
|
|
3
|
+
blueprintVersion: string;
|
|
4
|
+
typesVersion: string;
|
|
5
|
+
checkedAt: string;
|
|
6
|
+
blueprint: Blueprint;
|
|
7
|
+
}
|
|
8
|
+
export declare const getCacheFile: (cacheDirectory: string) => string;
|
|
9
|
+
export declare const readCache: (file: string) => Promise<BlueprintCache | null>;
|
|
10
|
+
export declare const writeCache: (file: string, cache: BlueprintCache) => Promise<void>;
|
|
11
|
+
export declare const isUpdateCheckDue: (checkedAt: string) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The blueprint version the cache is keyed on: a cached blueprint built by a
|
|
14
|
+
* different @seamapi/blueprint version is stale even for the same types.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getBlueprintVersion: () => Promise<string>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { seamapiBlueprintVersion } from '../version.js';
|
|
5
|
+
const cacheFileName = 'blueprint.json';
|
|
6
|
+
const updateCheckInterval = 24 * 60 * 60 * 1000;
|
|
7
|
+
export const getCacheFile = (cacheDirectory) => join(cacheDirectory, cacheFileName);
|
|
8
|
+
export const readCache = async (file) => {
|
|
9
|
+
try {
|
|
10
|
+
const contents = await readFile(file, 'utf8');
|
|
11
|
+
const cache = JSON.parse(contents);
|
|
12
|
+
if (!isBlueprintCache(cache))
|
|
13
|
+
return null;
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const writeCache = async (file, cache) => {
|
|
21
|
+
const temporaryFile = `${file}.tmp`;
|
|
22
|
+
await mkdir(dirname(file), { recursive: true });
|
|
23
|
+
await writeFile(temporaryFile, `${JSON.stringify(cache)}\n`, 'utf8');
|
|
24
|
+
await rename(temporaryFile, file);
|
|
25
|
+
};
|
|
26
|
+
export const isUpdateCheckDue = (checkedAt) => {
|
|
27
|
+
const checkedAtTime = Date.parse(checkedAt);
|
|
28
|
+
if (Number.isNaN(checkedAtTime))
|
|
29
|
+
return true;
|
|
30
|
+
return Date.now() - checkedAtTime > updateCheckInterval;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The blueprint version the cache is keyed on: a cached blueprint built by a
|
|
34
|
+
* different @seamapi/blueprint version is stale even for the same types.
|
|
35
|
+
*/
|
|
36
|
+
export const getBlueprintVersion = async () => {
|
|
37
|
+
if (seamapiBlueprintVersion !== '0.0.0')
|
|
38
|
+
return seamapiBlueprintVersion;
|
|
39
|
+
// The version is only injected when the package is packed, so a
|
|
40
|
+
// development checkout reads the pinned version from package.json
|
|
41
|
+
// to keep invalidating the cache on version changes as expected.
|
|
42
|
+
const pkg = await findOwnPackageJson();
|
|
43
|
+
return pkg?.dependencies?.['@seamapi/blueprint'] ?? seamapiBlueprintVersion;
|
|
44
|
+
};
|
|
45
|
+
const findOwnPackageJson = async () => {
|
|
46
|
+
let directory = dirname(fileURLToPath(import.meta.url));
|
|
47
|
+
while (true) {
|
|
48
|
+
try {
|
|
49
|
+
const contents = await readFile(join(directory, 'package.json'), 'utf8');
|
|
50
|
+
const pkg = JSON.parse(contents);
|
|
51
|
+
if (pkg.name === '@seamapi/cli')
|
|
52
|
+
return pkg;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Keep walking up until a package.json for this package is found.
|
|
56
|
+
}
|
|
57
|
+
const parent = dirname(directory);
|
|
58
|
+
if (parent === directory)
|
|
59
|
+
return null;
|
|
60
|
+
directory = parent;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const isBlueprintCache = (cache) => {
|
|
64
|
+
if (cache == null || typeof cache !== 'object')
|
|
65
|
+
return false;
|
|
66
|
+
const { blueprintVersion, typesVersion, checkedAt, blueprint } = cache;
|
|
67
|
+
return (typeof blueprintVersion === 'string' &&
|
|
68
|
+
typeof typesVersion === 'string' &&
|
|
69
|
+
typeof checkedAt === 'string' &&
|
|
70
|
+
blueprint != null &&
|
|
71
|
+
typeof blueprint === 'object');
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/lib/blueprint/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAIxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAExD,MAAM,aAAa,GAAG,gBAAgB,CAAA;AACtC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAS/C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,cAAsB,EAAU,EAAE,CAC7D,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,IAAY,EACoB,EAAE;IAClC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAY,CAAA;QAC7C,IAAI,CAAC,gBAAgB,CAAC,KAAK,CA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,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAA;YACxE,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAG9B,CAAA;YACD,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc;gBAAE,OAAO,GAAG,CAAA;QAC7C,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;QACpE,CAAC;QACD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;QACjC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,IAAI,CAAA;QACrC,SAAS,GAAG,MAAM,CAAA;IACpB,CAAC;AACH,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE;IACnE,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC5D,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,GAC5D,KAAgC,CAAA;IAClC,OAAO,CACL,OAAO,gBAAgB,KAAK,QAAQ;QACpC,OAAO,YAAY,KAAK,QAAQ;QAChC,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,IAAI,IAAI;QACjB,OAAO,SAAS,KAAK,QAAQ,CAC9B,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ApiBlueprint } from './index.js';
|
|
2
|
+
export declare const getCommandBlueprintDef: (cmd: string[], helpers: {
|
|
3
|
+
blueprint: ApiBlueprint;
|
|
4
|
+
}) => import("@seamapi/blueprint").Endpoint;
|
|
5
|
+
/**
|
|
6
|
+
* The top level response key documented for a command,
|
|
7
|
+
* e.g., `devices` for `seam devices list`.
|
|
8
|
+
*
|
|
9
|
+
* Returns null when the command is not in the blueprint,
|
|
10
|
+
* or when it does not respond with a resource.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getResponseKey: (command: string[], ctx: {
|
|
13
|
+
blueprint: ApiBlueprint;
|
|
14
|
+
}) => string | null;
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
export const getCommandBlueprintDef = (cmd, helpers) => {
|
|
2
|
+
const path = `/${cmd.join('/').replace(/-/g, '_')}`;
|
|
3
|
+
const def = helpers.blueprint.routes
|
|
4
|
+
.flatMap((route) => route.endpoints)
|
|
5
|
+
.find((endpoint) => endpoint.path === path);
|
|
6
|
+
if (!def) {
|
|
7
|
+
throw new Error(`No definition for path ${path}`);
|
|
8
|
+
}
|
|
9
|
+
return def;
|
|
10
|
+
};
|
|
2
11
|
/**
|
|
3
12
|
* The top level response key documented for a command,
|
|
4
13
|
* e.g., `devices` for `seam devices list`.
|
|
@@ -18,4 +27,4 @@ export const getResponseKey = (command, ctx) => {
|
|
|
18
27
|
return null;
|
|
19
28
|
return endpoint.response.responseKey;
|
|
20
29
|
};
|
|
21
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=endpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/lib/blueprint/endpoint.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,GAAa,EACb,OAAoC,EACpC,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAA;IACnD,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM;SACjC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC;SACnC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAC7C,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAA;IACnD,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAAiB,EACjB,GAAgC,EACjB,EAAE;IACjB,IAAI,QAAQ,CAAA;IACZ,IAAI,CAAC;QACH,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,YAAY,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IAE1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAA;AACtC,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Blueprint } from '@seamapi/blueprint';
|
|
2
|
+
export type ApiBlueprint = Blueprint;
|
|
3
|
+
export interface GetApiBlueprintOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Build from the OpenAPI document the configured server is currently
|
|
6
|
+
* running, instead of the published npm types.
|
|
7
|
+
*/
|
|
8
|
+
useRemoteDefinitions?: boolean;
|
|
9
|
+
/** Force an update of the cached Seam API definitions. */
|
|
10
|
+
update?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const getApiBlueprint: ({ useRemoteDefinitions, update, }?: GetApiBlueprintOptions) => Promise<ApiBlueprint>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getBlueprint } from './source-npm.js';
|
|
2
|
+
import { createRemoteBlueprint } from './source-remote.js';
|
|
3
|
+
export const getApiBlueprint = async ({ useRemoteDefinitions = false, update = false, } = {}) => {
|
|
4
|
+
// Remote definitions describe whatever the server is currently running, so
|
|
5
|
+
// build them directly from the server's OpenAPI document.
|
|
6
|
+
if (useRemoteDefinitions)
|
|
7
|
+
return await createRemoteBlueprint();
|
|
8
|
+
return await getBlueprint({ update });
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/blueprint/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAc1D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,oBAAoB,GAAG,KAAK,EAC5B,MAAM,GAAG,KAAK,MACY,EAAE,EAAyB,EAAE;IACvD,2EAA2E;IAC3E,0DAA0D;IAC1D,IAAI,oBAAoB;QAAE,OAAO,MAAM,qBAAqB,EAAE,CAAA;IAE9D,OAAO,MAAM,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;AACvC,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Blueprint } from '@seamapi/blueprint';
|
|
2
|
+
export interface GetBlueprintOptions {
|
|
3
|
+
update?: boolean;
|
|
4
|
+
cacheDirectory?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Build a blueprint from the latest published Seam API types on npm,
|
|
8
|
+
* using the on-disk cache unless it is stale or an update is forced.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getBlueprint: (options?: GetBlueprintOptions) => Promise<Blueprint>;
|