@stepzen/sdk 0.20.0 → 0.21.0-beta.1

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 (73) hide show
  1. package/lib/client-v2.d.ts +39 -0
  2. package/lib/client-v2.d.ts.map +1 -0
  3. package/lib/client-v2.js +75 -0
  4. package/lib/client-v2.js.map +1 -0
  5. package/lib/client.d.ts +3 -7
  6. package/lib/client.d.ts.map +1 -1
  7. package/lib/client.js +7 -3
  8. package/lib/client.js.map +1 -1
  9. package/lib/commands/account.js +1 -1
  10. package/lib/commands/account.js.map +1 -1
  11. package/lib/commands/authenticate.js +1 -1
  12. package/lib/commands/authenticate.js.map +1 -1
  13. package/lib/commands/deploy.js +1 -1
  14. package/lib/commands/deploy.js.map +1 -1
  15. package/lib/commands/getPublicAccount.js +2 -3
  16. package/lib/commands/getPublicAccount.js.map +1 -1
  17. package/lib/commands/list.js +1 -1
  18. package/lib/commands/list.js.map +1 -1
  19. package/lib/commands/upload.js +1 -1
  20. package/lib/commands/upload.js.map +1 -1
  21. package/lib/commands-v2/account.d.ts +9 -0
  22. package/lib/commands-v2/account.d.ts.map +1 -0
  23. package/lib/commands-v2/account.js +68 -0
  24. package/lib/commands-v2/account.js.map +1 -0
  25. package/lib/commands-v2/deploy.d.ts +15 -0
  26. package/lib/commands-v2/deploy.d.ts.map +1 -0
  27. package/lib/commands-v2/deploy.js +90 -0
  28. package/lib/commands-v2/deploy.js.map +1 -0
  29. package/lib/commands-v2/getPublicAccount.d.ts +8 -0
  30. package/lib/commands-v2/getPublicAccount.d.ts.map +1 -0
  31. package/lib/commands-v2/getPublicAccount.js +46 -0
  32. package/lib/commands-v2/getPublicAccount.js.map +1 -0
  33. package/lib/index.d.ts +3 -34
  34. package/lib/index.d.ts.map +1 -1
  35. package/lib/index.js +6 -25
  36. package/lib/index.js.map +1 -1
  37. package/lib/init-v2.d.ts +26 -0
  38. package/lib/init-v2.d.ts.map +1 -0
  39. package/lib/init-v2.js +29 -0
  40. package/lib/init-v2.js.map +1 -0
  41. package/lib/init.d.ts +32 -0
  42. package/lib/init.d.ts.map +1 -0
  43. package/lib/init.js +27 -0
  44. package/lib/init.js.map +1 -0
  45. package/lib/shared/constants.d.ts +1 -0
  46. package/lib/shared/constants.d.ts.map +1 -1
  47. package/lib/shared/constants.js +2 -1
  48. package/lib/shared/constants.js.map +1 -1
  49. package/lib/shared/graphql-client.d.ts +38 -0
  50. package/lib/shared/graphql-client.d.ts.map +1 -0
  51. package/lib/shared/graphql-client.js +80 -0
  52. package/lib/shared/graphql-client.js.map +1 -0
  53. package/lib/shared/payloads.d.ts +3 -0
  54. package/lib/shared/payloads.d.ts.map +1 -1
  55. package/lib/shared/payloads.js +45 -1
  56. package/lib/shared/payloads.js.map +1 -1
  57. package/lib/shared/types.d.ts +117 -0
  58. package/lib/shared/types.d.ts.map +1 -1
  59. package/lib/shared/validation.js +1 -1
  60. package/lib/shared/validation.js.map +1 -1
  61. package/package.json +4 -3
  62. package/src/client-v2.ts +104 -0
  63. package/src/client.ts +3 -4
  64. package/src/commands-v2/account.ts +98 -0
  65. package/src/commands-v2/deploy.ts +145 -0
  66. package/src/commands-v2/getPublicAccount.ts +67 -0
  67. package/src/index.ts +3 -38
  68. package/src/init-v2.ts +40 -0
  69. package/src/init.ts +41 -0
  70. package/src/shared/constants.ts +2 -0
  71. package/src/shared/graphql-client.ts +136 -0
  72. package/src/shared/payloads.ts +65 -0
  73. package/src/shared/types.ts +142 -0
@@ -18,7 +18,7 @@ const validateConfigurationset = async (file) => {
18
18
  try {
19
19
  yaml.parse(content);
20
20
  }
21
- catch (_a) {
21
+ catch {
22
22
  throw new Error('The file is not valid YAML');
23
23
  }
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,qCAAqC;AAC9B,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAwB,EAAE,EAAE;IACzE,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAE7C,gCAAgC;IAChC,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACpB;IAAC,WAAM;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;AACH,CAAC,CAAA;AAjBY,QAAA,wBAAwB,4BAiBpC;AAED,gCAAgC;AACzB,MAAM,cAAc,GAAG,KAAK,EAAE,SAA6B,EAAE,EAAE;IACpE,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,6CAA6C;IAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,EAAC,GAAG,EAAE,SAAS,EAAC,CAAC,CAAA;IACnE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;AACH,CAAC,CAAA;AAdY,QAAA,cAAc,kBAc1B"}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,qCAAqC;AAC9B,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAwB,EAAE,EAAE;IACzE,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAE7C,gCAAgC;IAChC,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;KACpB;IAAC,MAAM;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;AACH,CAAC,CAAA;AAjBY,QAAA,wBAAwB,4BAiBpC;AAED,gCAAgC;AACzB,MAAM,cAAc,GAAG,KAAK,EAAE,SAA6B,EAAE,EAAE;IACpE,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,6CAA6C;IAC7C,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,EAAC,GAAG,EAAE,SAAS,EAAC,CAAC,CAAA;IACnE,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAChE;AACH,CAAC,CAAA;AAdY,QAAA,cAAc,kBAc1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stepzen/sdk",
3
- "version": "0.20.0",
3
+ "version": "0.21.0-beta.1",
4
4
  "license": "MIT",
5
5
  "author": "Darren Waddell <darren@stepzen.com>",
6
6
  "homepage": "https://stepzen.com",
@@ -18,10 +18,11 @@
18
18
  "clean": "rm -rf lib tsconfig.tsbuildinfo",
19
19
  "build": "../../node_modules/.bin/tsc -b",
20
20
  "test": "npm run build && nyc --extension .ts mocha --config test/mocha.opts.json",
21
+ "test:single": "npm run build && mocha --config test/mocha.opts.json",
21
22
  "posttest": "prettier . --check"
22
23
  },
23
24
  "dependencies": {
24
- "@stepzen/transpiler": "^0.20.0",
25
+ "@stepzen/transpiler": "^0.21.0-beta.1",
25
26
  "archiver": "^5.3.0",
26
27
  "debug": "^4.3.4",
27
28
  "dotenv": "^16.0.1",
@@ -48,5 +49,5 @@
48
49
  "prettier": "^2.5.1",
49
50
  "ts-node": "^10.8.2"
50
51
  },
51
- "gitHead": "ff448d5486922f3ebd3fe0e4bc6665f2f91060f4"
52
+ "gitHead": "6dddebabddbbd69adb07b5e7c816125ae5dc3430"
52
53
  }
@@ -0,0 +1,104 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import accountCmd from './commands-v2/account'
4
+ import deployCmd from './commands-v2/deploy'
5
+ import getPublicAccount from './commands-v2/getPublicAccount'
6
+ import {
7
+ generateConfigurationPayload,
8
+ generateSchemaFilesPayload,
9
+ } from './shared/payloads'
10
+ import {SDKConfigurationV2} from './shared/types'
11
+
12
+ export const ensureValidCredentials = async (
13
+ auth:
14
+ | {account: string; adminKey: string; deploymentType: string}
15
+ | {publicAccountToken: string; deploymentType: string},
16
+ sdkConfig: SDKConfigurationV2,
17
+ ) => {
18
+ let credentials
19
+
20
+ if ('publicAccountToken' in auth) {
21
+ // create an anonymous account and use it to initialize an SDK client instance
22
+ const {data, error} = await getPublicAccount({
23
+ token: auth.publicAccountToken,
24
+ deploymentType: auth.deploymentType,
25
+ sdkConfig,
26
+ })
27
+
28
+ if (error) {
29
+ throw new Error(`An unexpected error occurred: ${error.message}`)
30
+ }
31
+
32
+ credentials = data
33
+ } else {
34
+ // use the provided account to initialize an SDK client instance
35
+ const {data, error} = await accountCmd({
36
+ account: auth.account,
37
+ adminKey: auth.adminKey,
38
+ deploymentType: auth.deploymentType,
39
+ sdkConfig,
40
+ })
41
+
42
+ if (error) {
43
+ throw new Error(error.message)
44
+ }
45
+
46
+ credentials = data
47
+ }
48
+
49
+ return credentials
50
+ }
51
+
52
+ export const createSdkClient = async (
53
+ auth:
54
+ | {account: string; adminKey: string; deploymentType: string}
55
+ | {publicAccountToken: string; deploymentType: string},
56
+ sdkConfig: SDKConfigurationV2,
57
+ ) => {
58
+ const credentials = await ensureValidCredentials(auth, sdkConfig)
59
+
60
+ return {
61
+ get credentials(): typeof credentials {
62
+ // always return a copy to avoid accidential modification by the caller
63
+ return {...credentials}
64
+ },
65
+ /**
66
+ * Create or update a GraphQL endpoint at StepZen.
67
+ * The URL of the endpoint is formed as {StepZen instance URL}/{folder}/{name}/__graphql
68
+ * e.g. https://account.stepzen.net/api/users/__graphql
69
+ *
70
+ * @param folder - folder name (e.g. `api`); will be a part of the endpoint URL
71
+ * @param name - endpoint name (e.g. `users`); will be a part of the endpoint URL
72
+ * @param directory - full path to a GraphQL schema directory (should have `index.graphql` in it)
73
+ * @param config - full path to a config `.yml` file
74
+ * @param public - whether or not to allow public access to the endpoint (`false` by default)
75
+ * @returns details of the created / updated endpoint
76
+ */
77
+ deploy: ({
78
+ folder,
79
+ name,
80
+ directory,
81
+ config,
82
+ public: _public = false,
83
+ }: {
84
+ folder: string
85
+ name: string
86
+ directory: string
87
+ config?: string
88
+ public?: boolean
89
+ }) => {
90
+ return deployCmd({
91
+ account: credentials.account,
92
+ adminKey: credentials.adminKey,
93
+ deploymentType: credentials.deploymentType,
94
+ endpointName: name,
95
+ endpointType: 'dev',
96
+ folderName: folder,
97
+ public: _public,
98
+ schemaFiles: generateSchemaFilesPayload(directory),
99
+ configuration: generateConfigurationPayload(config),
100
+ sdkConfig,
101
+ })
102
+ },
103
+ }
104
+ }
package/src/client.ts CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  AnonymousClientOptions,
7
7
  SDKConfiguration,
8
8
  StepZenAccount,
9
- StepZenCredentials,
10
9
  } from './shared/types'
11
10
  import list from './commands/list'
12
11
  import upload from './commands/upload'
@@ -18,8 +17,8 @@ export const validateCreateClientOptions = async (
18
17
  options: StepZenAccount | Required<AnonymousClientOptions>,
19
18
  sdkConfig: SDKConfiguration,
20
19
  ) => {
21
- let credentials: StepZenCredentials
22
- let account: StepZenAccount
20
+ let credentials
21
+ let account
23
22
 
24
23
  if ('publicAccountToken' in options) {
25
24
  // create an anonymous account and use it to initialize an SDK client instance
@@ -84,7 +83,7 @@ export const createSdkClient = async (
84
83
  )
85
84
 
86
85
  return {
87
- get credentials() {
86
+ get credentials(): typeof credentials {
88
87
  // always return a copy to avoid accidential modification by the caller
89
88
  return {...credentials}
90
89
  },
@@ -0,0 +1,98 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import {
4
+ SDKConfigurationV2,
5
+ StepZenAccountV2,
6
+ ZenCtlResponseV2,
7
+ } from '../shared/types'
8
+ import {fetchZenCtlGraphQLQuery} from '../shared/graphql-client'
9
+
10
+ export default async ({
11
+ account,
12
+ adminKey,
13
+ deploymentType,
14
+ sdkConfig,
15
+ }: {
16
+ account: string
17
+ adminKey: string
18
+ deploymentType: string
19
+ sdkConfig: SDKConfigurationV2
20
+ }): Promise<ZenCtlResponseV2<StepZenAccountV2>> => {
21
+ const {data, errors} = await fetchZenCtlGraphQLQuery<{
22
+ accounts: Array<{
23
+ deploymentType: string
24
+ account: string
25
+ ownerEmail: string
26
+ adminKey: string
27
+ apiKeysAsJsonArray: string
28
+ }>
29
+ }>({
30
+ account,
31
+ adminKey,
32
+ deploymentType,
33
+ query: `query (
34
+ $account: String!
35
+ $adminKey: String!
36
+ $deploymentType: String!
37
+ ) {
38
+ accounts: account(
39
+ account: $account
40
+ adminkey: $adminKey
41
+ deploymentType: $deploymentType
42
+ ) {
43
+ deploymentType: account_deployment_type
44
+ account: account_name
45
+ ownerEmail: account_owner_email
46
+ adminKey: key_value_admin
47
+ apiKeysAsJsonArray: key_value_service
48
+ }
49
+ }`,
50
+ variables: {
51
+ account,
52
+ adminKey,
53
+ deploymentType,
54
+ },
55
+ sdkConfig,
56
+ })
57
+
58
+ if (errors) {
59
+ // strip graphql-specific error details, leave only the message
60
+ const message = errors
61
+ .map(({message}) =>
62
+ message.startsWith(
63
+ 'ERROR: invalid input value for enum zenctl.deployment_type',
64
+ )
65
+ ? `Invalid deployment type: ${deploymentType}`
66
+ : message,
67
+ )
68
+ .join('\n')
69
+
70
+ return {
71
+ data: undefined,
72
+ error: {
73
+ message,
74
+ },
75
+ }
76
+ }
77
+
78
+ const accounts = data.accounts.filter(Boolean)
79
+ if (!accounts.length) {
80
+ return {
81
+ data: undefined,
82
+ error: {
83
+ message: 'Invalid credentials',
84
+ },
85
+ }
86
+ }
87
+
88
+ return {
89
+ data: {
90
+ account: accounts[0].account,
91
+ deploymentType: accounts[0].deploymentType,
92
+ ownerEmail: accounts[0].ownerEmail,
93
+ adminKey: accounts[0].adminKey,
94
+ apiKeys: JSON.parse(accounts[0].apiKeysAsJsonArray),
95
+ },
96
+ error: undefined,
97
+ }
98
+ }
@@ -0,0 +1,145 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import {
4
+ Configuration,
5
+ SchemaFiles,
6
+ SDKConfigurationV2,
7
+ StepZenEndpointV2,
8
+ ZenCtlResponseV2,
9
+ } from '../shared/types'
10
+ import {fetchZenCtlGraphQLQuery} from '../shared/graphql-client'
11
+
12
+ export default async ({
13
+ account,
14
+ deploymentType,
15
+ folderName,
16
+ endpointName,
17
+ public: _public,
18
+ endpointType,
19
+ schemaFiles,
20
+ configuration,
21
+ adminKey,
22
+ sdkConfig,
23
+ }: {
24
+ account: string
25
+ deploymentType: string
26
+ folderName: string
27
+ endpointName: string
28
+ public: boolean
29
+ endpointType: string
30
+ schemaFiles: Readonly<SchemaFiles>
31
+ configuration?: Readonly<Configuration>
32
+ adminKey: string
33
+ sdkConfig: SDKConfigurationV2
34
+ }): Promise<ZenCtlResponseV2<StepZenEndpointV2>> => {
35
+ const {data, errors} = await fetchZenCtlGraphQLQuery<{
36
+ endpoints: Array<{
37
+ account: string
38
+ deploymentType: string
39
+ folderName: string
40
+ endpointName: string
41
+ public: boolean
42
+ endpointType: string
43
+ }>
44
+ }>({
45
+ account,
46
+ adminKey,
47
+ deploymentType,
48
+ query: /* GraphQL */ `
49
+ mutation (
50
+ $account: String!
51
+ $deploymentType: String!
52
+ $folderName: String!
53
+ $endpointName: String!
54
+ $public: Boolean!
55
+ $endpointType: String!
56
+ $schemaFiles: SchemaFilesInput!
57
+ $configuration: Configuration
58
+ $adminKey: String!
59
+ ) {
60
+ endpoints: addEndpoint(
61
+ account: $account
62
+ deploymentType: $deploymentType
63
+ folderName: $folderName
64
+ endpointName: $endpointName
65
+ public: $public
66
+ endpointType: $endpointType
67
+ schemaFiles: $schemaFiles
68
+ configuration: $configuration
69
+ adminkey: $adminKey
70
+ ) {
71
+ account: account_name
72
+ deploymentType: deployment_type
73
+ folderName: folder_name
74
+ endpointName: endpoint_name
75
+ public: endpoint_public
76
+ endpointType: endpoint_type
77
+ }
78
+ }
79
+ `,
80
+ variables: {
81
+ account,
82
+ deploymentType,
83
+ folderName,
84
+ endpointName,
85
+ public: _public,
86
+ endpointType,
87
+ schemaFiles,
88
+ configuration: configuration ? configuration : null,
89
+ adminKey,
90
+ },
91
+ sdkConfig,
92
+ })
93
+
94
+ if (errors) {
95
+ // strip graphql-specific error details, leave only the message
96
+ const message = errors
97
+ .map(({message}) => {
98
+ if (
99
+ message.startsWith(
100
+ 'ERROR: invalid input value for enum zenctl.deployment_type',
101
+ )
102
+ ) {
103
+ return (
104
+ `Invalid deployment type: ${deploymentType}.` +
105
+ ` Please check the 'deploymentType' parameter.`
106
+ )
107
+ }
108
+
109
+ if (
110
+ message.startsWith(
111
+ 'ERROR: invalid input value for enum zenctl.endpoint_type',
112
+ )
113
+ ) {
114
+ return (
115
+ `Invalid endpoint type: ${endpointType}.` +
116
+ ` Please check the 'endpointType' parameter.`
117
+ )
118
+ }
119
+
120
+ return message
121
+ })
122
+ .join('\n')
123
+
124
+ return {
125
+ data: undefined,
126
+ error: {
127
+ message,
128
+ },
129
+ }
130
+ }
131
+
132
+ if (!data.endpoints.length) {
133
+ return {
134
+ data: undefined,
135
+ error: {
136
+ message: 'Invalid credentials',
137
+ },
138
+ }
139
+ }
140
+
141
+ return {
142
+ data: data.endpoints[0],
143
+ error: undefined,
144
+ }
145
+ }
@@ -0,0 +1,67 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import {
4
+ SDKConfigurationV2,
5
+ StepZenCredentialsV2,
6
+ ZenCtlResponseV2,
7
+ } from '../shared/types'
8
+ import {fetchPublicAccountGraphQLQuery} from '../shared/graphql-client'
9
+
10
+ export default async ({
11
+ token,
12
+ deploymentType,
13
+ sdkConfig,
14
+ }: {
15
+ token: string
16
+ deploymentType: string
17
+ sdkConfig: SDKConfigurationV2
18
+ }): Promise<ZenCtlResponseV2<StepZenCredentialsV2>> => {
19
+ const url = new URL(sdkConfig.publicAccountApiUrl)
20
+ // Include the token into the URL so that it is visible in the logs
21
+ // (allows StepZen to do analytics based on the GCP logs).
22
+ url.searchParams.set('token', token)
23
+
24
+ const {data, errors} = await fetchPublicAccountGraphQLQuery<{
25
+ account: {
26
+ account: string
27
+ adminKey: string
28
+ apiKey: string
29
+ }
30
+ }>({
31
+ url,
32
+ query: `query (
33
+ $token: String!
34
+ ) {
35
+ account: getAccountDetails(
36
+ token: $token
37
+ ) {
38
+ account: accountName
39
+ adminKey
40
+ apiKey
41
+ }
42
+ }`,
43
+ variables: {
44
+ token,
45
+ },
46
+ sdkConfig,
47
+ })
48
+
49
+ if (errors) {
50
+ // strip graphql-specific error details, leave only the message
51
+ const message = errors.map(error => error.message).join('\n')
52
+ return {
53
+ data: undefined,
54
+ error: {message},
55
+ }
56
+ }
57
+
58
+ return {
59
+ data: {
60
+ account: data.account.account,
61
+ adminKey: data.account.adminKey,
62
+ apiKeys: [data.account.apiKey],
63
+ deploymentType,
64
+ },
65
+ error: undefined,
66
+ }
67
+ }
package/src/index.ts CHANGED
@@ -1,45 +1,10 @@
1
1
  // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
2
 
3
3
  import * as path from 'path'
4
- import authenticate from './commands/authenticate'
5
- import {createSdkClient} from './client'
6
- import {
7
- AnonymousClientOptions,
8
- SDKConfiguration,
9
- UserCredentialsClientOptions,
10
- } from './shared/types'
4
+ import {init, SDK} from './init'
11
5
 
12
- export const init = (sdkConfig: SDKConfiguration) => {
13
- const defaults = {
14
- domain: process.env.STEPZEN_DOMAIN || 'stepzen.io',
15
- server: process.env.STEPZEN_SERVER_URL || 'https://{account}.stepzen.io',
16
- }
17
-
18
- return {
19
- verify: (account: string, adminkey: string) => {
20
- return authenticate(
21
- {
22
- account,
23
- adminkey,
24
- server: defaults.server.replace('{account}', account),
25
- domain: defaults.domain,
26
- },
27
- sdkConfig,
28
- )
29
- },
30
- client: async (
31
- options: UserCredentialsClientOptions | AnonymousClientOptions,
32
- ) => {
33
- return createSdkClient({...defaults, ...options}, sdkConfig)
34
- },
35
- }
36
- }
37
-
38
- // a helper type to unwrap Promise<U> into U
39
- type PromisedType<T> = T extends Promise<infer U> ? U : T
40
-
41
- export type SDK = ReturnType<typeof init>
42
- export type SDKClient = PromisedType<ReturnType<SDK['client']>>
6
+ export * from './init'
7
+ export * from './init-v2'
43
8
 
44
9
  /**
45
10
  * The default SDK instance that does not know the name of the app using the SDK.
package/src/init-v2.ts ADDED
@@ -0,0 +1,40 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import accountCommand from './commands-v2/account'
4
+ import {createSdkClient} from './client-v2'
5
+ import {SDKConfigurationV2} from './shared/types'
6
+
7
+ export const initV2 = (sdkConfig: SDKConfigurationV2) => {
8
+ return {
9
+ verify: async (
10
+ account: string,
11
+ adminkey: string,
12
+ deploymentType: string,
13
+ ) => {
14
+ try {
15
+ const {data} = await accountCommand({
16
+ account,
17
+ adminKey: adminkey,
18
+ deploymentType,
19
+ sdkConfig,
20
+ })
21
+ return Boolean(data)
22
+ } catch {
23
+ return false
24
+ }
25
+ },
26
+ client: async (
27
+ auth:
28
+ | {account: string; adminKey: string; deploymentType: string}
29
+ | {publicAccountToken: string; deploymentType: string},
30
+ ) => {
31
+ return createSdkClient(auth, sdkConfig)
32
+ },
33
+ }
34
+ }
35
+
36
+ // a helper type to unwrap Promise<U> into U
37
+ type PromisedType<T> = T extends Promise<infer U> ? U : T
38
+
39
+ export type SDKV2 = ReturnType<typeof initV2>
40
+ export type SDKClientV2 = PromisedType<ReturnType<SDKV2['client']>>
package/src/init.ts ADDED
@@ -0,0 +1,41 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import authenticate from './commands/authenticate'
4
+ import {createSdkClient} from './client'
5
+ import {
6
+ AnonymousClientOptions,
7
+ SDKConfiguration,
8
+ UserCredentialsClientOptions,
9
+ } from './shared/types'
10
+
11
+ export const init = (sdkConfig: SDKConfiguration) => {
12
+ const defaults = {
13
+ domain: process.env.STEPZEN_DOMAIN || 'stepzen.io',
14
+ server: process.env.STEPZEN_SERVER_URL || 'https://{account}.stepzen.io',
15
+ }
16
+
17
+ return {
18
+ verify: (account: string, adminkey: string) => {
19
+ return authenticate(
20
+ {
21
+ account,
22
+ adminkey,
23
+ server: defaults.server.replace('{account}', account),
24
+ domain: defaults.domain,
25
+ },
26
+ sdkConfig,
27
+ )
28
+ },
29
+ client: async (
30
+ options: UserCredentialsClientOptions | AnonymousClientOptions,
31
+ ) => {
32
+ return createSdkClient({...defaults, ...options}, sdkConfig)
33
+ },
34
+ }
35
+ }
36
+
37
+ // a helper type to unwrap Promise<U> into U
38
+ type PromisedType<T> = T extends Promise<infer U> ? U : T
39
+
40
+ export type SDK = ReturnType<typeof init>
41
+ export type SDKClient = PromisedType<ReturnType<SDK['client']>>
@@ -5,3 +5,5 @@ export const ADMIN_DEPLOY_URL = '/cli/admin/deploy'
5
5
  export const ADMIN_LIST_URL = '/cli/admin/list'
6
6
  export const ADMIN_UPLOAD_URL = '/cli/admin/upload'
7
7
  export const ADMIN_VERIFY_URL = '/cli/admin/verify'
8
+
9
+ export const ZENCTL2_URL = '/api/zenctl/__graphql'