@seamapi/cli 0.10.0 → 0.11.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 +58 -0
- package/bin/cli.js +62 -24
- package/bin/cli.js.map +1 -1
- package/lib/get-response-key.d.ts +9 -0
- package/lib/get-response-key.js +21 -0
- package/lib/get-response-key.js.map +1 -0
- package/lib/interact-for-action-attempt-poll.js +4 -3
- package/lib/interact-for-action-attempt-poll.js.map +1 -1
- package/lib/interact-for-array.js +9 -7
- package/lib/interact-for-array.js.map +1 -1
- package/lib/interact-for-blueprint-object.js +9 -8
- package/lib/interact-for-blueprint-object.js.map +1 -1
- package/lib/interact-for-command-selection.js +2 -2
- package/lib/interact-for-command-selection.js.map +1 -1
- package/lib/interact-for-custom-metadata.js +10 -8
- package/lib/interact-for-custom-metadata.js.map +1 -1
- package/lib/interact-for-login.js +8 -6
- package/lib/interact-for-login.js.map +1 -1
- package/lib/interact-for-resource.js +2 -2
- package/lib/interact-for-resource.js.map +1 -1
- package/lib/interact-for-server-selection.js +7 -5
- package/lib/interact-for-server-selection.js.map +1 -1
- package/lib/interact-for-timestamp.js +2 -2
- package/lib/interact-for-timestamp.js.map +1 -1
- package/lib/interact-for-use-remote-api-defs.js +4 -3
- package/lib/interact-for-use-remote-api-defs.js.map +1 -1
- package/lib/interact-for-workspace-id.js +2 -2
- package/lib/interact-for-workspace-id.js.map +1 -1
- package/lib/output/create-memory-output.d.ts +13 -0
- package/lib/output/create-memory-output.js +22 -0
- package/lib/output/create-memory-output.js.map +1 -0
- package/lib/output/create-output.d.ts +50 -0
- package/lib/output/create-output.js +34 -0
- package/lib/output/create-output.js.map +1 -0
- package/lib/output/get-output.d.ts +12 -0
- package/lib/output/get-output.js +21 -0
- package/lib/output/get-output.js.map +1 -0
- package/lib/output/resolve-output-format.d.ts +16 -0
- package/lib/output/resolve-output-format.js +23 -0
- package/lib/output/resolve-output-format.js.map +1 -0
- package/lib/output/select-response-payload.d.ts +16 -0
- package/lib/output/select-response-payload.js +33 -0
- package/lib/output/select-response-payload.js.map +1 -0
- package/lib/util/cli-args.d.ts +16 -1
- package/lib/util/cli-args.js +18 -2
- package/lib/util/cli-args.js.map +1 -1
- package/lib/util/prompt.d.ts +17 -0
- package/lib/util/prompt.js +25 -0
- package/lib/util/prompt.js.map +1 -0
- package/lib/util/read-stdin-json.d.ts +22 -0
- package/lib/util/read-stdin-json.js +42 -0
- package/lib/util/read-stdin-json.js.map +1 -0
- package/lib/util/request-seam-api.d.ts +5 -2
- package/lib/util/request-seam-api.js +13 -15
- package/lib/util/request-seam-api.js.map +1 -1
- package/lib/util/with-loading.js +6 -1
- package/lib/util/with-loading.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/bin/cli.ts +69 -25
- package/src/lib/get-response-key.ts +25 -0
- package/src/lib/interact-for-action-attempt-poll.ts +4 -3
- package/src/lib/interact-for-array.ts +9 -7
- package/src/lib/interact-for-blueprint-object.ts +9 -8
- package/src/lib/interact-for-command-selection.ts +2 -3
- package/src/lib/interact-for-custom-metadata.ts +10 -8
- package/src/lib/interact-for-login.ts +8 -6
- package/src/lib/interact-for-resource.ts +2 -3
- package/src/lib/interact-for-server-selection.ts +7 -6
- package/src/lib/interact-for-timestamp.ts +2 -2
- package/src/lib/interact-for-use-remote-api-defs.ts +4 -4
- package/src/lib/interact-for-workspace-id.ts +2 -2
- package/src/lib/output/create-memory-output.ts +39 -0
- package/src/lib/output/create-output.ts +104 -0
- package/src/lib/output/get-output.ts +24 -0
- package/src/lib/output/resolve-output-format.ts +33 -0
- package/src/lib/output/select-response-payload.ts +56 -0
- package/src/lib/util/cli-args.ts +32 -2
- package/src/lib/util/prompt.ts +38 -0
- package/src/lib/util/read-stdin-json.ts +59 -0
- package/src/lib/util/request-seam-api.ts +24 -20
- package/src/lib/util/with-loading.ts +9 -1
- package/src/lib/version.ts +1 -1
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
|
|
3
3
|
import { getSeam } from 'lib/get-seam.js'
|
|
4
|
+
import { getOutput } from 'lib/output/get-output.js'
|
|
5
|
+
import { selectResponsePayload } from 'lib/output/select-response-payload.js'
|
|
4
6
|
|
|
5
7
|
import { withLoading } from './with-loading.js'
|
|
6
8
|
|
|
9
|
+
export interface RequestSeamApiOptions {
|
|
10
|
+
path: string
|
|
11
|
+
params: Record<string, any>
|
|
12
|
+
/** Response key for the endpoint, used to trim the reported payload. */
|
|
13
|
+
responseKey?: string | null | undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
7
16
|
export const RequestSeamApi = async ({
|
|
8
17
|
path,
|
|
9
18
|
params,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
params: Record<string, any>
|
|
13
|
-
}) => {
|
|
19
|
+
responseKey,
|
|
20
|
+
}: RequestSeamApiOptions) => {
|
|
14
21
|
const seam = await getSeam()
|
|
22
|
+
const output = getOutput()
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
output.info(`\n${chalk.green(path)}`)
|
|
25
|
+
output.info(`Request Params:`)
|
|
26
|
+
output.info(formatParams(params))
|
|
17
27
|
|
|
18
28
|
const response = await withLoading('Making request...', () =>
|
|
19
29
|
seam.client.post(path, params, {
|
|
@@ -21,23 +31,17 @@ export const RequestSeamApi = async ({
|
|
|
21
31
|
}),
|
|
22
32
|
)
|
|
23
33
|
|
|
24
|
-
logResponse(response)
|
|
25
|
-
|
|
26
|
-
return response
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const logResponse = (response: { status: number; data: unknown }) => {
|
|
30
34
|
if (response.status >= 400) {
|
|
31
|
-
|
|
35
|
+
output.warn(chalk.red(`[${response.status}]`))
|
|
36
|
+
process.exitCode = 1
|
|
32
37
|
} else {
|
|
33
|
-
|
|
38
|
+
output.info(chalk.green(`[${response.status}]`))
|
|
34
39
|
}
|
|
35
|
-
console.dir(response.data, { depth: null })
|
|
36
|
-
console.log('\n')
|
|
37
|
-
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
console.log(params)
|
|
41
|
+
output.data(selectResponsePayload(response.data, { responseKey }))
|
|
42
|
+
|
|
43
|
+
return response
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
const formatParams = (params: Record<string, any>): string =>
|
|
47
|
+
JSON.stringify(params, null, 2)
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { createSpinner } from 'nanospinner'
|
|
2
2
|
|
|
3
|
+
import { getOutput } from 'lib/output/get-output.js'
|
|
4
|
+
|
|
3
5
|
export const withLoading = async <T>(
|
|
4
6
|
message: string,
|
|
5
7
|
fn: () => Promise<T>,
|
|
6
8
|
): Promise<T> => {
|
|
7
|
-
|
|
9
|
+
if (!shouldSpin()) return await fn()
|
|
10
|
+
|
|
11
|
+
// Progress is not a command result, so it is rendered to stderr.
|
|
12
|
+
const spinner = createSpinner(message, { stream: process.stderr }).start()
|
|
8
13
|
try {
|
|
9
14
|
const result = await fn()
|
|
10
15
|
spinner.success()
|
|
@@ -14,3 +19,6 @@ export const withLoading = async <T>(
|
|
|
14
19
|
throw error
|
|
15
20
|
}
|
|
16
21
|
}
|
|
22
|
+
|
|
23
|
+
const shouldSpin = (): boolean =>
|
|
24
|
+
getOutput().format === 'text' && process.stderr.isTTY === true
|
package/src/lib/version.ts
CHANGED