@seamapi/cli 0.0.1 → 0.4.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 +59 -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/get-api-blueprint.d.ts +3 -0
- package/lib/get-api-blueprint.js +11 -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/get-api-blueprint.ts +17 -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 +86 -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 prompts from 'prompts'
|
|
2
|
+
|
|
3
|
+
import { getConfigStore } from './get-config-store.js'
|
|
4
|
+
|
|
5
|
+
export async function interactForUseRemoteApiDefs() {
|
|
6
|
+
const { use_remote_api_defs } = await prompts([
|
|
7
|
+
{
|
|
8
|
+
type: 'select',
|
|
9
|
+
name: 'use_remote_api_defs',
|
|
10
|
+
message: 'Always use remote API Definitions?',
|
|
11
|
+
choices: [
|
|
12
|
+
{
|
|
13
|
+
title: 'Yes',
|
|
14
|
+
value: true,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
title: 'No',
|
|
18
|
+
value: false,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
const config = getConfigStore()
|
|
25
|
+
config.set('use_remote_api_defs', use_remote_api_defs)
|
|
26
|
+
console.log(`Use remote API Definitions: ${use_remote_api_defs}`)
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getSeam } from './get-seam.js'
|
|
2
|
+
import { interactForResource } from './interact-for-resource.js'
|
|
3
|
+
|
|
4
|
+
export const interactForUserIdentity = async () => {
|
|
5
|
+
const seam = await getSeam()
|
|
6
|
+
|
|
7
|
+
return interactForResource({
|
|
8
|
+
resourceName: 'user_identity',
|
|
9
|
+
fetchResources: () => seam.userIdentities.list(),
|
|
10
|
+
toChoice: (userIdentity) => ({
|
|
11
|
+
title: `${userIdentity.email_address} "${userIdentity.full_name}: ${userIdentity.user_identity_key}`,
|
|
12
|
+
value: userIdentity.user_identity_id,
|
|
13
|
+
description: userIdentity.user_identity_id,
|
|
14
|
+
}),
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SeamHttpWithoutWorkspace } from '@seamapi/http/connect'
|
|
2
|
+
import prompts from 'prompts'
|
|
3
|
+
|
|
4
|
+
import { getConfigStore } from './get-config-store.js'
|
|
5
|
+
import { getSeamMultiWorkspace } from './get-seam.js'
|
|
6
|
+
import { getServer } from './get-server.js'
|
|
7
|
+
import { withLoading } from './util/with-loading.js'
|
|
8
|
+
|
|
9
|
+
export const interactForWorkspaceId = async (personalAccessToken?: string) => {
|
|
10
|
+
const config = getConfigStore()
|
|
11
|
+
const seam = personalAccessToken
|
|
12
|
+
? SeamHttpWithoutWorkspace.fromPersonalAccessToken(personalAccessToken, {
|
|
13
|
+
endpoint: getServer(),
|
|
14
|
+
})
|
|
15
|
+
: await getSeamMultiWorkspace()
|
|
16
|
+
|
|
17
|
+
const workspaces = await withLoading('Fetching workspaces...', () =>
|
|
18
|
+
seam.workspaces.list(),
|
|
19
|
+
)
|
|
20
|
+
const { workspaceId } = await prompts({
|
|
21
|
+
name: 'workspaceId',
|
|
22
|
+
type: 'select',
|
|
23
|
+
message: 'Select a workspace:',
|
|
24
|
+
choices: workspaces.map((workspace: any) => ({
|
|
25
|
+
title: workspace.name,
|
|
26
|
+
value: workspace.workspace_id,
|
|
27
|
+
description: workspace.workspace_id,
|
|
28
|
+
})),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
if (workspaceId) {
|
|
32
|
+
config.set('current_workspace_id', workspaceId)
|
|
33
|
+
return workspaceId
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new Error('Bailed')
|
|
37
|
+
}
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import { getSeam } from 'lib/get-seam.js'
|
|
4
|
+
|
|
5
|
+
import { withLoading } from './with-loading.js'
|
|
6
|
+
|
|
7
|
+
export const RequestSeamApi = async ({
|
|
8
|
+
path,
|
|
9
|
+
params,
|
|
10
|
+
}: {
|
|
11
|
+
path: string
|
|
12
|
+
params: Record<string, any>
|
|
13
|
+
}) => {
|
|
14
|
+
const seam = await getSeam()
|
|
15
|
+
|
|
16
|
+
logRequest(path, params)
|
|
17
|
+
|
|
18
|
+
const response = await withLoading('Making request...', () =>
|
|
19
|
+
seam.client.post(path, params, {
|
|
20
|
+
validateStatus: () => true,
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
logResponse(response)
|
|
25
|
+
|
|
26
|
+
return response
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const logResponse = (response: { status: number; data: unknown }) => {
|
|
30
|
+
if (response.status >= 400) {
|
|
31
|
+
console.log(chalk.red(`\n\n[${response.status}]\n`))
|
|
32
|
+
} else {
|
|
33
|
+
console.log(chalk.green(`\n\n[${response.status}]`))
|
|
34
|
+
}
|
|
35
|
+
console.dir(response.data, { depth: null })
|
|
36
|
+
console.log('\n')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const logRequest = (apiPath: string, params: Record<string, any>) => {
|
|
40
|
+
console.log(`\n\n${chalk.green(apiPath)}`)
|
|
41
|
+
console.log(`Request Params:`)
|
|
42
|
+
console.log(params)
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createSpinner } from 'nanospinner'
|
|
2
|
+
|
|
3
|
+
export const withLoading = async <T>(
|
|
4
|
+
message: string,
|
|
5
|
+
fn: () => Promise<T>,
|
|
6
|
+
): Promise<T> => {
|
|
7
|
+
const spinner = createSpinner(message).start()
|
|
8
|
+
try {
|
|
9
|
+
const result = await fn()
|
|
10
|
+
spinner.success()
|
|
11
|
+
return result
|
|
12
|
+
} catch (error) {
|
|
13
|
+
spinner.error()
|
|
14
|
+
throw error
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isApiKey,
|
|
3
|
+
isPersonalAccessToken,
|
|
4
|
+
SeamHttp,
|
|
5
|
+
SeamHttpWithoutWorkspace,
|
|
6
|
+
} from '@seamapi/http/connect'
|
|
7
|
+
|
|
8
|
+
import { getServer } from './get-server.js'
|
|
9
|
+
|
|
10
|
+
export const validateToken = async (token: string, workspaceId?: string) => {
|
|
11
|
+
const options = { endpoint: getServer() }
|
|
12
|
+
|
|
13
|
+
if (isPersonalAccessToken(token)) {
|
|
14
|
+
const seam = workspaceId
|
|
15
|
+
? SeamHttp.fromPersonalAccessToken(token, workspaceId, options)
|
|
16
|
+
: SeamHttpWithoutWorkspace.fromPersonalAccessToken(token, options)
|
|
17
|
+
await seam.workspaces.list()
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isApiKey(token)) {
|
|
22
|
+
const seam = SeamHttp.fromApiKey(token, options)
|
|
23
|
+
await seam.workspaces.list()
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
throw new Error('Invalid token: expected a Personal Access Token or API Key')
|
|
28
|
+
}
|
package/src/lib/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { todo } from './todo.js'
|
package/src/lib/todo.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const todo = (x: string): string => x
|