@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.
Files changed (136) hide show
  1. package/README.md +59 -3
  2. package/bin/cli.d.ts +2 -0
  3. package/bin/cli.js +233 -0
  4. package/bin/cli.js.map +1 -0
  5. package/index.d.ts +2 -0
  6. package/index.js +5 -0
  7. package/index.js.map +1 -0
  8. package/lib/get-api-blueprint.d.ts +3 -0
  9. package/lib/get-api-blueprint.js +11 -0
  10. package/lib/get-api-blueprint.js.map +1 -0
  11. package/lib/get-command-blueprint-def.d.ts +2 -0
  12. package/lib/get-command-blueprint-def.js +11 -0
  13. package/lib/get-command-blueprint-def.js.map +1 -0
  14. package/lib/get-config-store.d.ts +2 -0
  15. package/lib/get-config-store.js +5 -0
  16. package/lib/get-config-store.js.map +1 -0
  17. package/lib/get-current-workspace-id.d.ts +1 -0
  18. package/lib/get-current-workspace-id.js +10 -0
  19. package/lib/get-current-workspace-id.js.map +1 -0
  20. package/lib/get-seam.d.ts +3 -0
  21. package/lib/get-seam.js +26 -0
  22. package/lib/get-seam.js.map +1 -0
  23. package/lib/get-server.d.ts +1 -0
  24. package/lib/get-server.js +7 -0
  25. package/lib/get-server.js.map +1 -0
  26. package/lib/interact-for-access-code.d.ts +3 -0
  27. package/lib/interact-for-access-code.js +19 -0
  28. package/lib/interact-for-access-code.js.map +1 -0
  29. package/lib/interact-for-acs-entrance.d.ts +1 -0
  30. package/lib/interact-for-acs-entrance.js +15 -0
  31. package/lib/interact-for-acs-entrance.js.map +1 -0
  32. package/lib/interact-for-acs-system.d.ts +1 -0
  33. package/lib/interact-for-acs-system.js +16 -0
  34. package/lib/interact-for-acs-system.js.map +1 -0
  35. package/lib/interact-for-acs-user.d.ts +1 -0
  36. package/lib/interact-for-acs-user.js +17 -0
  37. package/lib/interact-for-acs-user.js.map +1 -0
  38. package/lib/interact-for-action-attempt-poll.d.ts +2 -0
  39. package/lib/interact-for-action-attempt-poll.js +22 -0
  40. package/lib/interact-for-action-attempt-poll.js.map +1 -0
  41. package/lib/interact-for-array.d.ts +1 -0
  42. package/lib/interact-for-array.js +53 -0
  43. package/lib/interact-for-array.js.map +1 -0
  44. package/lib/interact-for-blueprint-object.d.ts +9 -0
  45. package/lib/interact-for-blueprint-object.js +235 -0
  46. package/lib/interact-for-blueprint-object.js.map +1 -0
  47. package/lib/interact-for-command-params.d.ts +5 -0
  48. package/lib/interact-for-command-params.js +11 -0
  49. package/lib/interact-for-command-params.js.map +1 -0
  50. package/lib/interact-for-command-selection.d.ts +2 -0
  51. package/lib/interact-for-command-selection.js +76 -0
  52. package/lib/interact-for-command-selection.js.map +1 -0
  53. package/lib/interact-for-connected-account.d.ts +1 -0
  54. package/lib/interact-for-connected-account.js +20 -0
  55. package/lib/interact-for-connected-account.js.map +1 -0
  56. package/lib/interact-for-custom-metadata.d.ts +6 -0
  57. package/lib/interact-for-custom-metadata.js +71 -0
  58. package/lib/interact-for-custom-metadata.js.map +1 -0
  59. package/lib/interact-for-device.d.ts +1 -0
  60. package/lib/interact-for-device.js +15 -0
  61. package/lib/interact-for-device.js.map +1 -0
  62. package/lib/interact-for-login.d.ts +1 -0
  63. package/lib/interact-for-login.js +39 -0
  64. package/lib/interact-for-login.js.map +1 -0
  65. package/lib/interact-for-resource.d.ts +11 -0
  66. package/lib/interact-for-resource.js +13 -0
  67. package/lib/interact-for-resource.js.map +1 -0
  68. package/lib/interact-for-server-selection.d.ts +1 -0
  69. package/lib/interact-for-server-selection.js +41 -0
  70. package/lib/interact-for-server-selection.js.map +1 -0
  71. package/lib/interact-for-timestamp.d.ts +1 -0
  72. package/lib/interact-for-timestamp.js +10 -0
  73. package/lib/interact-for-timestamp.js.map +1 -0
  74. package/lib/interact-for-use-remote-api-defs.d.ts +1 -0
  75. package/lib/interact-for-use-remote-api-defs.js +25 -0
  76. package/lib/interact-for-use-remote-api-defs.js.map +1 -0
  77. package/lib/interact-for-user-identity.d.ts +1 -0
  78. package/lib/interact-for-user-identity.js +15 -0
  79. package/lib/interact-for-user-identity.js.map +1 -0
  80. package/lib/interact-for-workspace-id.d.ts +1 -0
  81. package/lib/interact-for-workspace-id.js +31 -0
  82. package/lib/interact-for-workspace-id.js.map +1 -0
  83. package/lib/types.d.ts +5 -0
  84. package/lib/types.js +2 -0
  85. package/lib/types.js.map +1 -0
  86. package/lib/util/ellipsis.d.ts +1 -0
  87. package/lib/util/ellipsis.js +6 -0
  88. package/lib/util/ellipsis.js.map +1 -0
  89. package/lib/util/request-seam-api.d.ts +4 -0
  90. package/lib/util/request-seam-api.js +28 -0
  91. package/lib/util/request-seam-api.js.map +1 -0
  92. package/lib/util/with-loading.d.ts +1 -0
  93. package/lib/util/with-loading.js +14 -0
  94. package/lib/util/with-loading.js.map +1 -0
  95. package/lib/validate-token.d.ts +1 -0
  96. package/lib/validate-token.js +19 -0
  97. package/lib/validate-token.js.map +1 -0
  98. package/lib/version.d.ts +2 -0
  99. package/lib/version.js +3 -0
  100. package/lib/version.js.map +1 -0
  101. package/package.json +44 -18
  102. package/src/bin/cli.ts +265 -0
  103. package/src/index.ts +4 -1
  104. package/src/lib/get-api-blueprint.ts +17 -0
  105. package/src/lib/get-command-blueprint-def.ts +15 -0
  106. package/src/lib/get-config-store.ts +5 -0
  107. package/src/lib/get-current-workspace-id.ts +11 -0
  108. package/src/lib/get-seam.ts +43 -0
  109. package/src/lib/get-server.ts +9 -0
  110. package/src/lib/interact-for-access-code.ts +25 -0
  111. package/src/lib/interact-for-acs-entrance.ts +16 -0
  112. package/src/lib/interact-for-acs-system.ts +17 -0
  113. package/src/lib/interact-for-acs-user.ts +21 -0
  114. package/src/lib/interact-for-action-attempt-poll.ts +35 -0
  115. package/src/lib/interact-for-array.ts +61 -0
  116. package/src/lib/interact-for-blueprint-object.ts +274 -0
  117. package/src/lib/interact-for-command-params.ts +22 -0
  118. package/src/lib/interact-for-command-selection.ts +107 -0
  119. package/src/lib/interact-for-connected-account.ts +24 -0
  120. package/src/lib/interact-for-custom-metadata.ts +86 -0
  121. package/src/lib/interact-for-device.ts +15 -0
  122. package/src/lib/interact-for-login.ts +53 -0
  123. package/src/lib/interact-for-resource.ts +34 -0
  124. package/src/lib/interact-for-server-selection.ts +46 -0
  125. package/src/lib/interact-for-timestamp.ts +10 -0
  126. package/src/lib/interact-for-use-remote-api-defs.ts +27 -0
  127. package/src/lib/interact-for-user-identity.ts +16 -0
  128. package/src/lib/interact-for-workspace-id.ts +37 -0
  129. package/src/lib/types.ts +6 -0
  130. package/src/lib/util/ellipsis.ts +4 -0
  131. package/src/lib/util/request-seam-api.ts +43 -0
  132. package/src/lib/util/with-loading.ts +16 -0
  133. package/src/lib/validate-token.ts +28 -0
  134. package/src/lib/version.ts +3 -0
  135. package/src/lib/index.ts +0 -1
  136. 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
+ }
@@ -0,0 +1,6 @@
1
+ import type { ApiBlueprint } from './get-api-blueprint.js'
2
+
3
+ export interface ContextHelpers {
4
+ blueprint: ApiBlueprint
5
+ is_interactive: boolean
6
+ }
@@ -0,0 +1,4 @@
1
+ export const ellipsis = (str: string, len: number) => {
2
+ if (str.length <= len) return str
3
+ return str.slice(0, len - 3) + '...'
4
+ }
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ const seamapiCliVersion = '0.4.0'
2
+
3
+ export default seamapiCliVersion
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