@seamapi/cli 0.0.1 → 0.5.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 +54 -3
- package/bin/cli.d.ts +2 -0
- package/bin/cli.js +233 -0
- package/bin/cli.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/lib/blueprint.d.ts +6 -0
- package/lib/blueprint.js +37 -0
- package/lib/blueprint.js.map +1 -0
- package/lib/get-api-blueprint.d.ts +3 -0
- package/lib/get-api-blueprint.js +19 -0
- package/lib/get-api-blueprint.js.map +1 -0
- package/lib/get-command-blueprint-def.d.ts +2 -0
- package/lib/get-command-blueprint-def.js +11 -0
- package/lib/get-command-blueprint-def.js.map +1 -0
- package/lib/get-config-store.d.ts +2 -0
- package/lib/get-config-store.js +5 -0
- package/lib/get-config-store.js.map +1 -0
- package/lib/get-current-workspace-id.d.ts +1 -0
- package/lib/get-current-workspace-id.js +10 -0
- package/lib/get-current-workspace-id.js.map +1 -0
- package/lib/get-seam.d.ts +3 -0
- package/lib/get-seam.js +26 -0
- package/lib/get-seam.js.map +1 -0
- package/lib/get-server.d.ts +1 -0
- package/lib/get-server.js +7 -0
- package/lib/get-server.js.map +1 -0
- package/lib/interact-for-access-code.d.ts +3 -0
- package/lib/interact-for-access-code.js +19 -0
- package/lib/interact-for-access-code.js.map +1 -0
- package/lib/interact-for-acs-entrance.d.ts +1 -0
- package/lib/interact-for-acs-entrance.js +15 -0
- package/lib/interact-for-acs-entrance.js.map +1 -0
- package/lib/interact-for-acs-system.d.ts +1 -0
- package/lib/interact-for-acs-system.js +16 -0
- package/lib/interact-for-acs-system.js.map +1 -0
- package/lib/interact-for-acs-user.d.ts +1 -0
- package/lib/interact-for-acs-user.js +17 -0
- package/lib/interact-for-acs-user.js.map +1 -0
- package/lib/interact-for-action-attempt-poll.d.ts +2 -0
- package/lib/interact-for-action-attempt-poll.js +22 -0
- package/lib/interact-for-action-attempt-poll.js.map +1 -0
- package/lib/interact-for-array.d.ts +1 -0
- package/lib/interact-for-array.js +53 -0
- package/lib/interact-for-array.js.map +1 -0
- package/lib/interact-for-blueprint-object.d.ts +9 -0
- package/lib/interact-for-blueprint-object.js +235 -0
- package/lib/interact-for-blueprint-object.js.map +1 -0
- package/lib/interact-for-command-params.d.ts +5 -0
- package/lib/interact-for-command-params.js +11 -0
- package/lib/interact-for-command-params.js.map +1 -0
- package/lib/interact-for-command-selection.d.ts +2 -0
- package/lib/interact-for-command-selection.js +76 -0
- package/lib/interact-for-command-selection.js.map +1 -0
- package/lib/interact-for-connected-account.d.ts +1 -0
- package/lib/interact-for-connected-account.js +20 -0
- package/lib/interact-for-connected-account.js.map +1 -0
- package/lib/interact-for-custom-metadata.d.ts +6 -0
- package/lib/interact-for-custom-metadata.js +71 -0
- package/lib/interact-for-custom-metadata.js.map +1 -0
- package/lib/interact-for-device.d.ts +1 -0
- package/lib/interact-for-device.js +15 -0
- package/lib/interact-for-device.js.map +1 -0
- package/lib/interact-for-login.d.ts +1 -0
- package/lib/interact-for-login.js +39 -0
- package/lib/interact-for-login.js.map +1 -0
- package/lib/interact-for-resource.d.ts +11 -0
- package/lib/interact-for-resource.js +13 -0
- package/lib/interact-for-resource.js.map +1 -0
- package/lib/interact-for-server-selection.d.ts +1 -0
- package/lib/interact-for-server-selection.js +41 -0
- package/lib/interact-for-server-selection.js.map +1 -0
- package/lib/interact-for-timestamp.d.ts +1 -0
- package/lib/interact-for-timestamp.js +10 -0
- package/lib/interact-for-timestamp.js.map +1 -0
- package/lib/interact-for-use-remote-api-defs.d.ts +1 -0
- package/lib/interact-for-use-remote-api-defs.js +25 -0
- package/lib/interact-for-use-remote-api-defs.js.map +1 -0
- package/lib/interact-for-user-identity.d.ts +1 -0
- package/lib/interact-for-user-identity.js +15 -0
- package/lib/interact-for-user-identity.js.map +1 -0
- package/lib/interact-for-workspace-id.d.ts +1 -0
- package/lib/interact-for-workspace-id.js +31 -0
- package/lib/interact-for-workspace-id.js.map +1 -0
- package/lib/types.d.ts +5 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/util/ellipsis.d.ts +1 -0
- package/lib/util/ellipsis.js +6 -0
- package/lib/util/ellipsis.js.map +1 -0
- package/lib/util/request-seam-api.d.ts +4 -0
- package/lib/util/request-seam-api.js +28 -0
- package/lib/util/request-seam-api.js.map +1 -0
- package/lib/util/with-loading.d.ts +1 -0
- package/lib/util/with-loading.js +14 -0
- package/lib/util/with-loading.js.map +1 -0
- package/lib/validate-token.d.ts +1 -0
- package/lib/validate-token.js +19 -0
- package/lib/validate-token.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.js +3 -0
- package/lib/version.js.map +1 -0
- package/package.json +44 -18
- package/src/bin/cli.ts +265 -0
- package/src/index.ts +4 -1
- package/src/lib/blueprint.ts +53 -0
- package/src/lib/get-api-blueprint.ts +27 -0
- package/src/lib/get-command-blueprint-def.ts +15 -0
- package/src/lib/get-config-store.ts +5 -0
- package/src/lib/get-current-workspace-id.ts +11 -0
- package/src/lib/get-seam.ts +43 -0
- package/src/lib/get-server.ts +9 -0
- package/src/lib/interact-for-access-code.ts +25 -0
- package/src/lib/interact-for-acs-entrance.ts +16 -0
- package/src/lib/interact-for-acs-system.ts +17 -0
- package/src/lib/interact-for-acs-user.ts +21 -0
- package/src/lib/interact-for-action-attempt-poll.ts +35 -0
- package/src/lib/interact-for-array.ts +61 -0
- package/src/lib/interact-for-blueprint-object.ts +274 -0
- package/src/lib/interact-for-command-params.ts +22 -0
- package/src/lib/interact-for-command-selection.ts +107 -0
- package/src/lib/interact-for-connected-account.ts +24 -0
- package/src/lib/interact-for-custom-metadata.ts +89 -0
- package/src/lib/interact-for-device.ts +15 -0
- package/src/lib/interact-for-login.ts +53 -0
- package/src/lib/interact-for-resource.ts +34 -0
- package/src/lib/interact-for-server-selection.ts +46 -0
- package/src/lib/interact-for-timestamp.ts +10 -0
- package/src/lib/interact-for-use-remote-api-defs.ts +27 -0
- package/src/lib/interact-for-user-identity.ts +16 -0
- package/src/lib/interact-for-workspace-id.ts +37 -0
- package/src/lib/types.ts +6 -0
- package/src/lib/util/ellipsis.ts +4 -0
- package/src/lib/util/request-seam-api.ts +43 -0
- package/src/lib/util/with-loading.ts +16 -0
- package/src/lib/validate-token.ts +28 -0
- package/src/lib/version.ts +3 -0
- package/src/lib/index.ts +0 -1
- package/src/lib/todo.ts +0 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Blueprint } from '@seamapi/blueprint'
|
|
2
|
+
|
|
3
|
+
import getBlueprint from './blueprint.js'
|
|
4
|
+
import { getServer } from './get-server.js'
|
|
5
|
+
|
|
6
|
+
export type ApiBlueprint = Blueprint
|
|
7
|
+
|
|
8
|
+
export const getApiBlueprint = async (
|
|
9
|
+
useRemoteDefinitions: boolean,
|
|
10
|
+
): Promise<ApiBlueprint> => {
|
|
11
|
+
// Remote definitions describe whatever the server is currently running, so
|
|
12
|
+
// build them directly from the server's OpenAPI document. This runtime path
|
|
13
|
+
// does not load @seamapi/types.
|
|
14
|
+
if (useRemoteDefinitions) return await createRemoteBlueprint()
|
|
15
|
+
|
|
16
|
+
return await getBlueprint()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const createRemoteBlueprint = async (): Promise<Blueprint> => {
|
|
20
|
+
const [{ createBlueprint }, { getOpenapiSchema }] = await Promise.all([
|
|
21
|
+
import('@seamapi/blueprint'),
|
|
22
|
+
import('@seamapi/http/connect'),
|
|
23
|
+
])
|
|
24
|
+
const openapi = await getOpenapiSchema(getServer())
|
|
25
|
+
|
|
26
|
+
return await createBlueprint({ openapi }, { omitUndocumented: true })
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContextHelpers } from './types.js'
|
|
2
|
+
export const getCommandBlueprintDef = (
|
|
3
|
+
cmd: string[],
|
|
4
|
+
helpers: ContextHelpers,
|
|
5
|
+
) => {
|
|
6
|
+
const path = `/${cmd.join('/').replace(/-/g, '_')}`
|
|
7
|
+
const def = helpers.blueprint.routes
|
|
8
|
+
.flatMap((route) => route.endpoints)
|
|
9
|
+
.find((endpoint) => endpoint.path === path)
|
|
10
|
+
if (!def) {
|
|
11
|
+
throw new Error(`No definition for path ${path}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return def
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getConfigStore } from './get-config-store.js'
|
|
2
|
+
import { interactForWorkspaceId } from './interact-for-workspace-id.js'
|
|
3
|
+
|
|
4
|
+
export const getCurrentWorkspaceId = async (): Promise<string> => {
|
|
5
|
+
const configStore = getConfigStore()
|
|
6
|
+
|
|
7
|
+
const currentWorkspaceId = configStore.get('current_workspace_id')
|
|
8
|
+
if (typeof currentWorkspaceId === 'string') return currentWorkspaceId
|
|
9
|
+
|
|
10
|
+
return await interactForWorkspaceId()
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isConsoleSessionToken,
|
|
3
|
+
isPersonalAccessToken,
|
|
4
|
+
SeamHttp,
|
|
5
|
+
SeamHttpWithoutWorkspace,
|
|
6
|
+
} from '@seamapi/http/connect'
|
|
7
|
+
|
|
8
|
+
import { getConfigStore } from './get-config-store.js'
|
|
9
|
+
import { getServer } from './get-server.js'
|
|
10
|
+
|
|
11
|
+
export const getSeam = async (): Promise<SeamHttp> => {
|
|
12
|
+
const config = getConfigStore()
|
|
13
|
+
|
|
14
|
+
const token = config.get(`${getServer()}.pat`) as string
|
|
15
|
+
|
|
16
|
+
const workspaceId = config.get('current_workspace_id') as string
|
|
17
|
+
|
|
18
|
+
const options = { endpoint: getServer() }
|
|
19
|
+
|
|
20
|
+
if (isPersonalAccessToken(token)) {
|
|
21
|
+
return SeamHttp.fromPersonalAccessToken(token, workspaceId, options)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isConsoleSessionToken(token)) {
|
|
25
|
+
return SeamHttp.fromConsoleSessionToken(token, workspaceId, options)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return SeamHttp.fromApiKey(token, options)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const getSeamMultiWorkspace = async (): Promise<
|
|
32
|
+
SeamHttpWithoutWorkspace | SeamHttp
|
|
33
|
+
> => {
|
|
34
|
+
const config = getConfigStore()
|
|
35
|
+
const token = config.get(`${getServer()}.pat`) as string
|
|
36
|
+
const options = { endpoint: getServer() }
|
|
37
|
+
|
|
38
|
+
if (isPersonalAccessToken(token)) {
|
|
39
|
+
return SeamHttpWithoutWorkspace.fromPersonalAccessToken(token, options)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return getSeam()
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getSeam } from './get-seam.js'
|
|
2
|
+
import { interactForDevice } from './interact-for-device.js'
|
|
3
|
+
import { interactForResource } from './interact-for-resource.js'
|
|
4
|
+
|
|
5
|
+
export const interactForAccessCode = async ({
|
|
6
|
+
device_id,
|
|
7
|
+
}: {
|
|
8
|
+
device_id?: string
|
|
9
|
+
}) => {
|
|
10
|
+
const seam = await getSeam()
|
|
11
|
+
|
|
12
|
+
if (!device_id) {
|
|
13
|
+
device_id = await interactForDevice()
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return interactForResource({
|
|
17
|
+
resourceName: 'access_code',
|
|
18
|
+
fetchResources: () => seam.accessCodes.list({ device_id }),
|
|
19
|
+
toChoice: (accessCode) => ({
|
|
20
|
+
title: accessCode.name ?? '<No Name>',
|
|
21
|
+
value: accessCode.access_code_id,
|
|
22
|
+
description: `${accessCode.type} ${accessCode.access_code_id}`,
|
|
23
|
+
}),
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getSeam } from './get-seam.js'
|
|
2
|
+
import { interactForResource } from './interact-for-resource.js'
|
|
3
|
+
|
|
4
|
+
export const interactForAcsEntrance = async () => {
|
|
5
|
+
const seam = await getSeam()
|
|
6
|
+
|
|
7
|
+
return interactForResource({
|
|
8
|
+
resourceName: 'ACS entrance',
|
|
9
|
+
fetchResources: () => seam.acs.entrances.list(),
|
|
10
|
+
toChoice: (entrance) => ({
|
|
11
|
+
title: entrance.display_name ?? '<No Name>',
|
|
12
|
+
value: entrance.acs_entrance_id,
|
|
13
|
+
description: entrance.acs_entrance_id,
|
|
14
|
+
}),
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getSeam } from './get-seam.js'
|
|
2
|
+
import { interactForResource } from './interact-for-resource.js'
|
|
3
|
+
|
|
4
|
+
export const interactForAcsSystem = async (message?: string) => {
|
|
5
|
+
const seam = await getSeam()
|
|
6
|
+
|
|
7
|
+
return interactForResource({
|
|
8
|
+
resourceName: 'ACS system',
|
|
9
|
+
fetchResources: () => seam.acs.systems.list(),
|
|
10
|
+
message,
|
|
11
|
+
toChoice: (system) => ({
|
|
12
|
+
title: `${system.name} ${system.external_type_display_name}`,
|
|
13
|
+
value: system.acs_system_id,
|
|
14
|
+
description: system.acs_system_id,
|
|
15
|
+
}),
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getSeam } from './get-seam.js'
|
|
2
|
+
import { interactForAcsSystem } from './interact-for-acs-system.js'
|
|
3
|
+
import { interactForResource } from './interact-for-resource.js'
|
|
4
|
+
|
|
5
|
+
export const interactForAcsUser = async () => {
|
|
6
|
+
const seam = await getSeam()
|
|
7
|
+
|
|
8
|
+
const acs_system_id = await interactForAcsSystem(
|
|
9
|
+
'What acs_system does the acs_user belong to?',
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
return interactForResource({
|
|
13
|
+
resourceName: 'ACS user',
|
|
14
|
+
fetchResources: () => seam.acs.users.list({ acs_system_id }),
|
|
15
|
+
toChoice: (user) => ({
|
|
16
|
+
title: `${user.display_name} ${user.email_address}`,
|
|
17
|
+
value: user.acs_user_id,
|
|
18
|
+
description: user.acs_user_id,
|
|
19
|
+
}),
|
|
20
|
+
})
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ActionAttemptsGetResponse } from '@seamapi/http/connect'
|
|
2
|
+
import prompts from 'prompts'
|
|
3
|
+
|
|
4
|
+
import { getSeam } from './get-seam.js'
|
|
5
|
+
import { withLoading } from './util/with-loading.js'
|
|
6
|
+
|
|
7
|
+
export const interactForActionAttemptPoll = async (
|
|
8
|
+
action_attempt: ActionAttemptsGetResponse['action_attempt'],
|
|
9
|
+
) => {
|
|
10
|
+
if (action_attempt.status === 'pending') {
|
|
11
|
+
const { poll_for_action_attempt } = await prompts({
|
|
12
|
+
name: 'poll_for_action_attempt',
|
|
13
|
+
message: "Would you like to poll the action attempt until it's ready?",
|
|
14
|
+
type: 'toggle',
|
|
15
|
+
initial: true,
|
|
16
|
+
active: 'yes',
|
|
17
|
+
inactive: 'no',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
if (poll_for_action_attempt) {
|
|
21
|
+
const seam = await getSeam()
|
|
22
|
+
const { action_attempt_id } = action_attempt
|
|
23
|
+
|
|
24
|
+
const updated_action_attempt = await withLoading(
|
|
25
|
+
'Polling action attempt...',
|
|
26
|
+
() =>
|
|
27
|
+
seam.actionAttempts.get(
|
|
28
|
+
{ action_attempt_id },
|
|
29
|
+
{ waitForActionAttempt: { pollingInterval: 240, timeout: 10_000 } },
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
console.dir(updated_action_attempt, { depth: null })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import prompts from 'prompts'
|
|
2
|
+
|
|
3
|
+
export const interactForArray = async (
|
|
4
|
+
array: string[],
|
|
5
|
+
message: string,
|
|
6
|
+
): Promise<string[]> => {
|
|
7
|
+
const updatedArray = [...array]
|
|
8
|
+
|
|
9
|
+
const displayList = () => {
|
|
10
|
+
console.log(`${message} Current list:`)
|
|
11
|
+
if (updatedArray.length > 0) {
|
|
12
|
+
updatedArray.forEach((item, index) => {
|
|
13
|
+
console.log(`${index + 1}: ${item}`)
|
|
14
|
+
})
|
|
15
|
+
} else {
|
|
16
|
+
console.log('The list is currently empty.')
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let action: string
|
|
21
|
+
do {
|
|
22
|
+
displayList()
|
|
23
|
+
|
|
24
|
+
const response = await prompts({
|
|
25
|
+
type: 'select',
|
|
26
|
+
name: 'action',
|
|
27
|
+
message: 'Choose an action:',
|
|
28
|
+
choices: [
|
|
29
|
+
{ title: 'Add an item', value: 'add' },
|
|
30
|
+
{ title: 'Remove an item', value: 'remove' },
|
|
31
|
+
{ title: 'Finish editing', value: 'done' },
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
action = response.action
|
|
36
|
+
|
|
37
|
+
if (action === 'add') {
|
|
38
|
+
const { newItem } = await prompts({
|
|
39
|
+
type: 'text',
|
|
40
|
+
name: 'newItem',
|
|
41
|
+
message: 'Enter the new item:',
|
|
42
|
+
})
|
|
43
|
+
if (newItem) {
|
|
44
|
+
updatedArray.push(newItem)
|
|
45
|
+
}
|
|
46
|
+
} else if (action === 'remove') {
|
|
47
|
+
const { index } = await prompts({
|
|
48
|
+
type: 'number',
|
|
49
|
+
name: 'index',
|
|
50
|
+
message: 'Enter the index of the item to remove:',
|
|
51
|
+
validate: (value) =>
|
|
52
|
+
value > 0 && value <= updatedArray.length ? true : 'Invalid index',
|
|
53
|
+
})
|
|
54
|
+
if (index) {
|
|
55
|
+
updatedArray.splice(index - 1, 1)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} while (action !== 'done')
|
|
59
|
+
|
|
60
|
+
return updatedArray
|
|
61
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import type { Parameter } from '@seamapi/blueprint'
|
|
2
|
+
import prompts from 'prompts'
|
|
3
|
+
|
|
4
|
+
import { interactForAccessCode } from './interact-for-access-code.js'
|
|
5
|
+
import { interactForAcsEntrance } from './interact-for-acs-entrance.js'
|
|
6
|
+
import { interactForAcsSystem } from './interact-for-acs-system.js'
|
|
7
|
+
import { interactForAcsUser } from './interact-for-acs-user.js'
|
|
8
|
+
import { interactForArray } from './interact-for-array.js'
|
|
9
|
+
import { interactForConnectedAccount } from './interact-for-connected-account.js'
|
|
10
|
+
import { interactForCustomMetadata } from './interact-for-custom-metadata.js'
|
|
11
|
+
import { interactForDevice } from './interact-for-device.js'
|
|
12
|
+
import { interactForTimestamp } from './interact-for-timestamp.js'
|
|
13
|
+
import { interactForUserIdentity } from './interact-for-user-identity.js'
|
|
14
|
+
import type { ContextHelpers } from './types.js'
|
|
15
|
+
import { ellipsis } from './util/ellipsis.js'
|
|
16
|
+
|
|
17
|
+
const ergonomicPropOrder = [
|
|
18
|
+
'name',
|
|
19
|
+
'connected_account_id',
|
|
20
|
+
'device_id',
|
|
21
|
+
'access_code_id',
|
|
22
|
+
'user_identity_id',
|
|
23
|
+
'code',
|
|
24
|
+
'starts_at',
|
|
25
|
+
'ends_at',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
export const interactForBlueprintObject = async (
|
|
29
|
+
args: {
|
|
30
|
+
command: string[]
|
|
31
|
+
parameters: Parameter[]
|
|
32
|
+
params: Record<string, any>
|
|
33
|
+
isSubProperty?: boolean
|
|
34
|
+
subPropertyPath?: string
|
|
35
|
+
},
|
|
36
|
+
ctx: ContextHelpers,
|
|
37
|
+
): Promise<any> => {
|
|
38
|
+
// Clone args and args params so that we can mutate it
|
|
39
|
+
args = { ...args, params: { ...args.params } }
|
|
40
|
+
|
|
41
|
+
const properties = Object.fromEntries(
|
|
42
|
+
args.parameters.map((parameter) => [parameter.name, parameter]),
|
|
43
|
+
)
|
|
44
|
+
const required = args.parameters
|
|
45
|
+
.filter((parameter) => parameter.isRequired)
|
|
46
|
+
.map((parameter) => parameter.name)
|
|
47
|
+
|
|
48
|
+
const haveAllRequiredParams = required.every((k) => args.params[k])
|
|
49
|
+
|
|
50
|
+
const should_auto_submit =
|
|
51
|
+
!ctx.is_interactive && haveAllRequiredParams && !args.isSubProperty
|
|
52
|
+
if (should_auto_submit) {
|
|
53
|
+
return args.params
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const propSortScore = (prop: string) => {
|
|
57
|
+
if (required.includes(prop)) return 100 - ergonomicPropOrder.indexOf(prop)
|
|
58
|
+
if (args.params[prop] !== undefined) {
|
|
59
|
+
return 50 - Object.keys(args.params).indexOf(prop)
|
|
60
|
+
}
|
|
61
|
+
return ergonomicPropOrder.indexOf(prop)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const cmdPath = `/${args.command.join('/').replace(/-/g, '_')}`
|
|
65
|
+
const parameterSelectionMessage = args.isSubProperty
|
|
66
|
+
? `Editing "${args.subPropertyPath}"`
|
|
67
|
+
: `[${cmdPath}] Parameters`
|
|
68
|
+
|
|
69
|
+
console.log('')
|
|
70
|
+
const { paramToEdit } = await prompts({
|
|
71
|
+
name: 'paramToEdit',
|
|
72
|
+
message: parameterSelectionMessage,
|
|
73
|
+
type: 'autocomplete',
|
|
74
|
+
choices: [
|
|
75
|
+
...(haveAllRequiredParams && !args.isSubProperty
|
|
76
|
+
? [
|
|
77
|
+
{
|
|
78
|
+
value: 'done',
|
|
79
|
+
title: `[Make API Call] ${cmdPath}`,
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
: []),
|
|
83
|
+
...(haveAllRequiredParams && args.isSubProperty
|
|
84
|
+
? [
|
|
85
|
+
{
|
|
86
|
+
title: `[Save]`,
|
|
87
|
+
value: 'done',
|
|
88
|
+
},
|
|
89
|
+
]
|
|
90
|
+
: []),
|
|
91
|
+
...Object.keys(properties)
|
|
92
|
+
.map((k) => {
|
|
93
|
+
return {
|
|
94
|
+
title: k + (required.includes(k) ? '*' : ''),
|
|
95
|
+
value: k,
|
|
96
|
+
description:
|
|
97
|
+
args.params[k] !== undefined
|
|
98
|
+
? typeof args.params[k] === 'object'
|
|
99
|
+
? ellipsis(JSON.stringify(args.params[k]), 60)
|
|
100
|
+
: `[${args.params[k]}]`
|
|
101
|
+
: undefined,
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
.sort((a, b) => propSortScore(b.value) - propSortScore(a.value)),
|
|
105
|
+
...(args.isSubProperty
|
|
106
|
+
? [
|
|
107
|
+
{
|
|
108
|
+
title: `[Leave Empty]`,
|
|
109
|
+
value: 'empty',
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
: []),
|
|
113
|
+
{
|
|
114
|
+
title: `[Back]`,
|
|
115
|
+
value: 'back',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
if (paramToEdit === 'empty') {
|
|
121
|
+
return undefined
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (paramToEdit === 'done') {
|
|
125
|
+
// TODO check for required
|
|
126
|
+
return args.params
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (paramToEdit === 'back') {
|
|
130
|
+
if (args.subPropertyPath) {
|
|
131
|
+
return args.params
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return '[Back]'
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const prop = properties[paramToEdit]
|
|
138
|
+
|
|
139
|
+
if (paramToEdit === 'device_id') {
|
|
140
|
+
args.params[paramToEdit] = await interactForDevice()
|
|
141
|
+
return interactForBlueprintObject(args, ctx)
|
|
142
|
+
} else if (paramToEdit === 'access_code_id') {
|
|
143
|
+
args.params[paramToEdit] = await interactForAccessCode(args.params as any)
|
|
144
|
+
return interactForBlueprintObject(args, ctx)
|
|
145
|
+
} else if (paramToEdit === 'connected_account_id') {
|
|
146
|
+
const connected_account_id = await interactForConnectedAccount()
|
|
147
|
+
args.params[paramToEdit] = connected_account_id
|
|
148
|
+
return interactForBlueprintObject(args, ctx)
|
|
149
|
+
} else if (
|
|
150
|
+
paramToEdit === 'user_identity_id' ||
|
|
151
|
+
paramToEdit === 'user_identity_ids'
|
|
152
|
+
) {
|
|
153
|
+
const user_identity_id = await interactForUserIdentity()
|
|
154
|
+
args.params[paramToEdit] =
|
|
155
|
+
paramToEdit === 'user_identity_ids'
|
|
156
|
+
? [user_identity_id]
|
|
157
|
+
: user_identity_id
|
|
158
|
+
return interactForBlueprintObject(args, ctx)
|
|
159
|
+
} else if (paramToEdit.endsWith('acs_system_id')) {
|
|
160
|
+
args.params[paramToEdit] = await interactForAcsSystem()
|
|
161
|
+
return interactForBlueprintObject(args, ctx)
|
|
162
|
+
} else if (paramToEdit.endsWith('acs_user_id')) {
|
|
163
|
+
args.params[paramToEdit] = await interactForAcsUser()
|
|
164
|
+
return interactForBlueprintObject(args, ctx)
|
|
165
|
+
} else if (paramToEdit.endsWith('acs_entrance_id')) {
|
|
166
|
+
args.params['acs_entrance_id'] = await interactForAcsEntrance()
|
|
167
|
+
return interactForBlueprintObject(args, ctx)
|
|
168
|
+
} else if (
|
|
169
|
+
paramToEdit.endsWith('_at') ||
|
|
170
|
+
paramToEdit === 'since' ||
|
|
171
|
+
paramToEdit.endsWith('_before') ||
|
|
172
|
+
paramToEdit.endsWith('_after')
|
|
173
|
+
) {
|
|
174
|
+
args.params[paramToEdit] = await interactForTimestamp()
|
|
175
|
+
return interactForBlueprintObject(args, ctx)
|
|
176
|
+
} else if (paramToEdit === 'custom_metadata') {
|
|
177
|
+
args.params[paramToEdit] = await interactForCustomMetadata(
|
|
178
|
+
args.params[paramToEdit] || {},
|
|
179
|
+
)
|
|
180
|
+
return interactForBlueprintObject(args, ctx)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (prop) {
|
|
184
|
+
if (['string', 'id', 'datetime'].includes(prop.format)) {
|
|
185
|
+
let value
|
|
186
|
+
if (prop.format === 'datetime') {
|
|
187
|
+
value = await interactForTimestamp()
|
|
188
|
+
} else {
|
|
189
|
+
value = (
|
|
190
|
+
await prompts({
|
|
191
|
+
name: 'value',
|
|
192
|
+
message: `${paramToEdit}:`,
|
|
193
|
+
type: 'text',
|
|
194
|
+
})
|
|
195
|
+
).value
|
|
196
|
+
}
|
|
197
|
+
args.params[paramToEdit] = value
|
|
198
|
+
return interactForBlueprintObject(args, ctx)
|
|
199
|
+
} else if (prop.format === 'enum') {
|
|
200
|
+
const value = (
|
|
201
|
+
await prompts({
|
|
202
|
+
name: 'value',
|
|
203
|
+
message: `${paramToEdit}:`,
|
|
204
|
+
type: 'select',
|
|
205
|
+
choices: prop.values.map((v) => ({
|
|
206
|
+
title: v.name,
|
|
207
|
+
value: v.name,
|
|
208
|
+
})),
|
|
209
|
+
})
|
|
210
|
+
).value
|
|
211
|
+
args.params[paramToEdit] = value
|
|
212
|
+
return interactForBlueprintObject(args, ctx)
|
|
213
|
+
} else if (prop.format === 'boolean') {
|
|
214
|
+
const { value } = await prompts({
|
|
215
|
+
name: 'value',
|
|
216
|
+
message: `${paramToEdit}:`,
|
|
217
|
+
type: 'toggle',
|
|
218
|
+
initial: true,
|
|
219
|
+
active: 'true',
|
|
220
|
+
inactive: 'false',
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
args.params[paramToEdit] = value
|
|
224
|
+
|
|
225
|
+
return interactForBlueprintObject(args, ctx)
|
|
226
|
+
} else if (prop.format === 'list' && prop.itemFormat === 'enum') {
|
|
227
|
+
const value = (
|
|
228
|
+
await prompts({
|
|
229
|
+
name: 'value',
|
|
230
|
+
message: `${paramToEdit}:`,
|
|
231
|
+
type: 'autocompleteMultiselect',
|
|
232
|
+
choices: prop.itemEnumValues.map((v) => ({
|
|
233
|
+
title: v.name,
|
|
234
|
+
value: v.name,
|
|
235
|
+
})),
|
|
236
|
+
})
|
|
237
|
+
).value
|
|
238
|
+
args.params[paramToEdit] = value
|
|
239
|
+
return interactForBlueprintObject(args, ctx)
|
|
240
|
+
} else if (prop.format === 'list') {
|
|
241
|
+
args.params[paramToEdit] = await interactForArray(
|
|
242
|
+
args.params[paramToEdit] || [],
|
|
243
|
+
`Edit the list for ${paramToEdit}`,
|
|
244
|
+
)
|
|
245
|
+
return interactForBlueprintObject(args, ctx)
|
|
246
|
+
} else if (prop.format === 'object') {
|
|
247
|
+
args.params[paramToEdit] = await interactForBlueprintObject(
|
|
248
|
+
{
|
|
249
|
+
command: args.command,
|
|
250
|
+
params: {},
|
|
251
|
+
parameters: prop.parameters,
|
|
252
|
+
isSubProperty: true,
|
|
253
|
+
subPropertyPath: paramToEdit,
|
|
254
|
+
},
|
|
255
|
+
ctx,
|
|
256
|
+
)
|
|
257
|
+
return interactForBlueprintObject(args, ctx)
|
|
258
|
+
} else if (prop.format === 'number') {
|
|
259
|
+
const { value } = await prompts({
|
|
260
|
+
name: 'value',
|
|
261
|
+
message: `${paramToEdit}:`,
|
|
262
|
+
type: 'number',
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
args.params[paramToEdit] = value
|
|
266
|
+
|
|
267
|
+
return interactForBlueprintObject(args, ctx)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
throw new Error(
|
|
272
|
+
`Didn't know how to handle Blueprint parameter for property: "${paramToEdit}"`,
|
|
273
|
+
)
|
|
274
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getCommandBlueprintDef } from './get-command-blueprint-def.js'
|
|
2
|
+
import { interactForBlueprintObject } from './interact-for-blueprint-object.js'
|
|
3
|
+
import type { ContextHelpers } from './types.js'
|
|
4
|
+
|
|
5
|
+
export const interactForCommandParams = async (
|
|
6
|
+
args: {
|
|
7
|
+
command: string[]
|
|
8
|
+
params: Record<string, any>
|
|
9
|
+
},
|
|
10
|
+
ctx: ContextHelpers,
|
|
11
|
+
): Promise<any> => {
|
|
12
|
+
const endpoint = getCommandBlueprintDef(args.command, ctx)
|
|
13
|
+
|
|
14
|
+
return interactForBlueprintObject(
|
|
15
|
+
{
|
|
16
|
+
command: args.command,
|
|
17
|
+
params: args.params,
|
|
18
|
+
parameters: endpoint.request.parameters,
|
|
19
|
+
},
|
|
20
|
+
ctx,
|
|
21
|
+
)
|
|
22
|
+
}
|