@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.
Files changed (84) hide show
  1. package/README.md +58 -0
  2. package/bin/cli.js +62 -24
  3. package/bin/cli.js.map +1 -1
  4. package/lib/get-response-key.d.ts +9 -0
  5. package/lib/get-response-key.js +21 -0
  6. package/lib/get-response-key.js.map +1 -0
  7. package/lib/interact-for-action-attempt-poll.js +4 -3
  8. package/lib/interact-for-action-attempt-poll.js.map +1 -1
  9. package/lib/interact-for-array.js +9 -7
  10. package/lib/interact-for-array.js.map +1 -1
  11. package/lib/interact-for-blueprint-object.js +9 -8
  12. package/lib/interact-for-blueprint-object.js.map +1 -1
  13. package/lib/interact-for-command-selection.js +2 -2
  14. package/lib/interact-for-command-selection.js.map +1 -1
  15. package/lib/interact-for-custom-metadata.js +10 -8
  16. package/lib/interact-for-custom-metadata.js.map +1 -1
  17. package/lib/interact-for-login.js +8 -6
  18. package/lib/interact-for-login.js.map +1 -1
  19. package/lib/interact-for-resource.js +2 -2
  20. package/lib/interact-for-resource.js.map +1 -1
  21. package/lib/interact-for-server-selection.js +7 -5
  22. package/lib/interact-for-server-selection.js.map +1 -1
  23. package/lib/interact-for-timestamp.js +2 -2
  24. package/lib/interact-for-timestamp.js.map +1 -1
  25. package/lib/interact-for-use-remote-api-defs.js +4 -3
  26. package/lib/interact-for-use-remote-api-defs.js.map +1 -1
  27. package/lib/interact-for-workspace-id.js +2 -2
  28. package/lib/interact-for-workspace-id.js.map +1 -1
  29. package/lib/output/create-memory-output.d.ts +13 -0
  30. package/lib/output/create-memory-output.js +22 -0
  31. package/lib/output/create-memory-output.js.map +1 -0
  32. package/lib/output/create-output.d.ts +50 -0
  33. package/lib/output/create-output.js +34 -0
  34. package/lib/output/create-output.js.map +1 -0
  35. package/lib/output/get-output.d.ts +12 -0
  36. package/lib/output/get-output.js +21 -0
  37. package/lib/output/get-output.js.map +1 -0
  38. package/lib/output/resolve-output-format.d.ts +16 -0
  39. package/lib/output/resolve-output-format.js +23 -0
  40. package/lib/output/resolve-output-format.js.map +1 -0
  41. package/lib/output/select-response-payload.d.ts +16 -0
  42. package/lib/output/select-response-payload.js +33 -0
  43. package/lib/output/select-response-payload.js.map +1 -0
  44. package/lib/util/cli-args.d.ts +16 -1
  45. package/lib/util/cli-args.js +18 -2
  46. package/lib/util/cli-args.js.map +1 -1
  47. package/lib/util/prompt.d.ts +17 -0
  48. package/lib/util/prompt.js +25 -0
  49. package/lib/util/prompt.js.map +1 -0
  50. package/lib/util/read-stdin-json.d.ts +22 -0
  51. package/lib/util/read-stdin-json.js +42 -0
  52. package/lib/util/read-stdin-json.js.map +1 -0
  53. package/lib/util/request-seam-api.d.ts +5 -2
  54. package/lib/util/request-seam-api.js +13 -15
  55. package/lib/util/request-seam-api.js.map +1 -1
  56. package/lib/util/with-loading.js +6 -1
  57. package/lib/util/with-loading.js.map +1 -1
  58. package/lib/version.d.ts +1 -1
  59. package/lib/version.js +1 -1
  60. package/package.json +1 -1
  61. package/src/bin/cli.ts +69 -25
  62. package/src/lib/get-response-key.ts +25 -0
  63. package/src/lib/interact-for-action-attempt-poll.ts +4 -3
  64. package/src/lib/interact-for-array.ts +9 -7
  65. package/src/lib/interact-for-blueprint-object.ts +9 -8
  66. package/src/lib/interact-for-command-selection.ts +2 -3
  67. package/src/lib/interact-for-custom-metadata.ts +10 -8
  68. package/src/lib/interact-for-login.ts +8 -6
  69. package/src/lib/interact-for-resource.ts +2 -3
  70. package/src/lib/interact-for-server-selection.ts +7 -6
  71. package/src/lib/interact-for-timestamp.ts +2 -2
  72. package/src/lib/interact-for-use-remote-api-defs.ts +4 -4
  73. package/src/lib/interact-for-workspace-id.ts +2 -2
  74. package/src/lib/output/create-memory-output.ts +39 -0
  75. package/src/lib/output/create-output.ts +104 -0
  76. package/src/lib/output/get-output.ts +24 -0
  77. package/src/lib/output/resolve-output-format.ts +33 -0
  78. package/src/lib/output/select-response-payload.ts +56 -0
  79. package/src/lib/util/cli-args.ts +32 -2
  80. package/src/lib/util/prompt.ts +38 -0
  81. package/src/lib/util/read-stdin-json.ts +59 -0
  82. package/src/lib/util/request-seam-api.ts +24 -20
  83. package/src/lib/util/with-loading.ts +9 -1
  84. 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
- path: string
12
- params: Record<string, any>
13
- }) => {
19
+ responseKey,
20
+ }: RequestSeamApiOptions) => {
14
21
  const seam = await getSeam()
22
+ const output = getOutput()
15
23
 
16
- logRequest(path, params)
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
- console.log(chalk.red(`\n\n[${response.status}]\n`))
35
+ output.warn(chalk.red(`[${response.status}]`))
36
+ process.exitCode = 1
32
37
  } else {
33
- console.log(chalk.green(`\n\n[${response.status}]`))
38
+ output.info(chalk.green(`[${response.status}]`))
34
39
  }
35
- console.dir(response.data, { depth: null })
36
- console.log('\n')
37
- }
38
40
 
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)
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
- const spinner = createSpinner(message).start()
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
@@ -1,5 +1,5 @@
1
1
  // Versions are replaced with generated values when the package is packed.
2
- const seamapiCliVersion = '0.10.0'
2
+ const seamapiCliVersion = '0.11.0'
3
3
  const seamapiBlueprintVersion = '1.2.0'
4
4
 
5
5
  export { seamapiBlueprintVersion }