@stepzen/sdk 0.11.4 → 1.0.0-alpha.3

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 (59) hide show
  1. package/lib/client-v2.d.ts +33 -0
  2. package/lib/client-v2.js +71 -0
  3. package/lib/client-v2.js.map +1 -0
  4. package/lib/client.js +9 -9
  5. package/lib/client.js.map +1 -1
  6. package/lib/commands/account.js +2 -2
  7. package/lib/commands/account.js.map +1 -1
  8. package/lib/commands/authenticate.js +2 -2
  9. package/lib/commands/authenticate.js.map +1 -1
  10. package/lib/commands/deploy.js +2 -2
  11. package/lib/commands/deploy.js.map +1 -1
  12. package/lib/commands/getPublicAccount.js +2 -2
  13. package/lib/commands/getPublicAccount.js.map +1 -1
  14. package/lib/commands/list.js +2 -2
  15. package/lib/commands/list.js.map +1 -1
  16. package/lib/commands/upload.js +8 -8
  17. package/lib/commands/upload.js.map +1 -1
  18. package/lib/commands-v2/account.d.ts +8 -0
  19. package/lib/commands-v2/account.js +78 -0
  20. package/lib/commands-v2/account.js.map +1 -0
  21. package/lib/commands-v2/deploy.d.ts +14 -0
  22. package/lib/commands-v2/deploy.js +92 -0
  23. package/lib/commands-v2/deploy.js.map +1 -0
  24. package/lib/commands-v2/getPublicAccount.d.ts +7 -0
  25. package/lib/commands-v2/getPublicAccount.js +46 -0
  26. package/lib/commands-v2/getPublicAccount.js.map +1 -0
  27. package/lib/commands-v2/list.d.ts +8 -0
  28. package/lib/commands-v2/list.js +62 -0
  29. package/lib/commands-v2/list.js.map +1 -0
  30. package/lib/index.d.ts +3 -33
  31. package/lib/index.js +5 -24
  32. package/lib/index.js.map +1 -1
  33. package/lib/init-v2.d.ts +35 -0
  34. package/lib/init-v2.js +40 -0
  35. package/lib/init-v2.js.map +1 -0
  36. package/lib/init.d.ts +34 -0
  37. package/lib/init.js +27 -0
  38. package/lib/init.js.map +1 -0
  39. package/lib/shared/graphql-client.d.ts +34 -0
  40. package/lib/shared/graphql-client.js +60 -0
  41. package/lib/shared/graphql-client.js.map +1 -0
  42. package/lib/shared/request.d.ts +3 -1
  43. package/lib/shared/request.js +3 -3
  44. package/lib/shared/request.js.map +1 -1
  45. package/lib/shared/transpiling.js +1 -1
  46. package/lib/shared/transpiling.js.map +1 -1
  47. package/lib/shared/types.d.ts +72 -0
  48. package/package.json +4 -4
  49. package/src/client-v2.ts +104 -0
  50. package/src/commands-v2/account.ts +111 -0
  51. package/src/commands-v2/deploy.ts +150 -0
  52. package/src/commands-v2/getPublicAccount.ts +67 -0
  53. package/src/commands-v2/list.ts +96 -0
  54. package/src/index.ts +3 -38
  55. package/src/init-v2.ts +70 -0
  56. package/src/init.ts +41 -0
  57. package/src/shared/graphql-client.ts +108 -0
  58. package/src/shared/request.ts +2 -2
  59. package/src/shared/types.ts +87 -0
@@ -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 listCmd from './commands-v2/list'
6
+ import getPublicAccount from './commands-v2/getPublicAccount'
7
+ import {
8
+ ConfigurationSet,
9
+ SchemaFile,
10
+ SDKConfigurationV2,
11
+ StepZenCredentialsV2,
12
+ } from './shared/types'
13
+
14
+ export const ensureValidCredentials = async (
15
+ auth:
16
+ | {account: string; adminKey: string; deploymentType: string}
17
+ | {publicAccountToken: string; deploymentType: string},
18
+ sdkConfig: SDKConfigurationV2,
19
+ ) => {
20
+ let credentials: StepZenCredentialsV2
21
+
22
+ if ('publicAccountToken' in auth) {
23
+ // create an anonymous account and use it to initialize an SDK client instance
24
+ const {data, error} = await getPublicAccount({
25
+ token: auth.publicAccountToken,
26
+ deploymentType: auth.deploymentType,
27
+ sdkConfig,
28
+ })
29
+
30
+ if (error) {
31
+ throw new Error(`An unexpected error occurred: ${error.message}`)
32
+ }
33
+
34
+ credentials = data
35
+ } else {
36
+ // use the provided account to initialize an SDK client instance
37
+ const {data, error} = await accountCmd({
38
+ account: auth.account,
39
+ adminKey: auth.adminKey,
40
+ deploymentType: auth.deploymentType,
41
+ sdkConfig,
42
+ })
43
+
44
+ if (error) {
45
+ throw new Error(error.message)
46
+ }
47
+
48
+ credentials = data
49
+ }
50
+
51
+ return credentials
52
+ }
53
+
54
+ export const createSdkClient = async (
55
+ auth:
56
+ | {account: string; adminKey: string; deploymentType: string}
57
+ | {publicAccountToken: string; deploymentType: string},
58
+ sdkConfig: SDKConfigurationV2,
59
+ ) => {
60
+ const credentials = await ensureValidCredentials(auth, sdkConfig)
61
+
62
+ return {
63
+ get credentials() {
64
+ // always return a copy to avoid accidential modification by the caller
65
+ return {...credentials}
66
+ },
67
+ deploy: ({
68
+ endpointName,
69
+ schemaFiles,
70
+ folderName,
71
+ public: _public,
72
+ endpointType,
73
+ configurationSets,
74
+ }: {
75
+ endpointName: string
76
+ schemaFiles: readonly SchemaFile[]
77
+ folderName?: string
78
+ public?: boolean
79
+ endpointType?: string
80
+ configurationSets?: readonly ConfigurationSet[]
81
+ }) => {
82
+ return deployCmd({
83
+ folderName: folderName || 'default',
84
+ endpointName,
85
+ public: typeof _public === 'boolean' ? _public : false,
86
+ endpointType: endpointType || 'dev',
87
+ schemaFiles,
88
+ configurationSets,
89
+ account: credentials.account,
90
+ adminKey: credentials.adminKey,
91
+ deploymentType: credentials.deploymentType,
92
+ sdkConfig,
93
+ })
94
+ },
95
+ list: () => {
96
+ return listCmd({
97
+ account: credentials.account,
98
+ adminKey: credentials.adminKey,
99
+ deploymentType: credentials.deploymentType,
100
+ sdkConfig,
101
+ })
102
+ },
103
+ }
104
+ }
@@ -0,0 +1,111 @@
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
+ serviceKeys: string
28
+ }>
29
+ }>({
30
+ query: `query (
31
+ $account: String!
32
+ $adminKey: String!
33
+ $deploymentType: String!
34
+ ) {
35
+ accounts: account(
36
+ account: $account
37
+ adminkey: $adminKey
38
+ deploymentType: $deploymentType
39
+ ) {
40
+ deploymentType: account_deployment_type
41
+ account: account_name
42
+ ownerEmail: account_owner_email
43
+ adminKey: key_value_admin
44
+ serviceKeys: key_value_service
45
+ }
46
+ }`,
47
+ variables: {
48
+ account,
49
+ adminKey,
50
+ deploymentType,
51
+ },
52
+ sdkConfig,
53
+ })
54
+
55
+ if (errors) {
56
+ // strip graphql-specific error details, leave only the message
57
+ const message = errors
58
+ .map(({message}) =>
59
+ message.startsWith(
60
+ 'ERROR: invalid input value for enum zenctl.deployment_type',
61
+ )
62
+ ? `Invalid deployment type: ${deploymentType}`
63
+ : message,
64
+ )
65
+ .join('\n')
66
+
67
+ return {
68
+ data: undefined,
69
+ error: {
70
+ message,
71
+ },
72
+ }
73
+ }
74
+
75
+ const accounts = data.accounts.filter(Boolean)
76
+ if (!accounts.length) {
77
+ return {
78
+ data: undefined,
79
+ error: {
80
+ message: 'Invalid credentials',
81
+ },
82
+ }
83
+ }
84
+
85
+ // https://stepzen.slack.com/archives/C01J1N6JCHM/p1655468161447439
86
+ // Split a string like "{servicekey1,servicekey2}" into an array of strings.
87
+ // Handle cases when a service key contains a comma or a quote.
88
+ const serviceKeysString = accounts[0].serviceKeys.substring(
89
+ 1,
90
+ accounts[0].serviceKeys.length - 1,
91
+ )
92
+ let serviceKeys
93
+ if (serviceKeysString.charAt(0) === '"') {
94
+ serviceKeys = serviceKeysString
95
+ .split(/(?<!\\)"/g)
96
+ .filter(key => key !== ',' && key !== '')
97
+ } else {
98
+ serviceKeys = serviceKeysString.split(',')
99
+ }
100
+
101
+ return {
102
+ data: {
103
+ account: accounts[0].account,
104
+ deploymentType: accounts[0].deploymentType,
105
+ ownerEmail: accounts[0].ownerEmail,
106
+ adminKey: accounts[0].adminKey,
107
+ serviceKeys: serviceKeys,
108
+ },
109
+ error: undefined,
110
+ }
111
+ }
@@ -0,0 +1,150 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import {
4
+ ConfigurationSet,
5
+ SchemaFile,
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
+ configurationSets,
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 SchemaFile[]
31
+ configurationSets?: readonly ConfigurationSet[]
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
+ endpointName: string
40
+ public: boolean
41
+ endpointType: string
42
+ folderName: string
43
+ }>
44
+ }>({
45
+ query: `query (
46
+ $account: String!
47
+ $deploymentType: String!
48
+ $folderName: String!
49
+ $endpointName: String!
50
+ $public: Boolean!
51
+ $endpointType: String!
52
+ $schemaFiles: SchemaFilesInput!
53
+ $configurations: ConfigurationsInput
54
+ $adminKey: String!
55
+ ) {
56
+ endpoints: internalAddEndpoint(
57
+ account: $account
58
+ deploymentType: $deploymentType
59
+ folderName: $folderName
60
+ endpointName: $endpointName
61
+ public: $public
62
+ endpointType: $endpointType
63
+ schemaFiles: $schemaFiles
64
+ configurations: $configurations
65
+ adminkey: $adminKey
66
+ ) {
67
+ account: account_name
68
+ deploymentType: deployment_type
69
+ endpointName: endpoint_name
70
+ public: endpoint_public
71
+ endpointType: endpoint_type
72
+ folderName: folder_name
73
+ }
74
+ }`,
75
+ variables: {
76
+ account,
77
+ deploymentType,
78
+ folderName,
79
+ endpointName,
80
+ public: _public,
81
+ endpointType,
82
+ schemaFiles: {files: schemaFiles},
83
+ configurations: configurationSets
84
+ ? {configurationsets: configurationSets}
85
+ : null,
86
+ adminKey,
87
+ },
88
+ sdkConfig,
89
+ })
90
+
91
+ if (errors) {
92
+ // strip graphql-specific error details, leave only the message
93
+ const message = errors
94
+ .map(({message}) => {
95
+ if (
96
+ message.startsWith(
97
+ 'ERROR: invalid input value for enum zenctl.deployment_type',
98
+ )
99
+ ) {
100
+ return (
101
+ `Invalid deployment type: ${deploymentType}.` +
102
+ ` Please check the 'deploymentType' parameter.`
103
+ )
104
+ }
105
+
106
+ if (
107
+ message.startsWith(
108
+ 'ERROR: invalid input value for enum zenctl.endpoint_type',
109
+ )
110
+ ) {
111
+ return (
112
+ `Invalid endpoint type: ${endpointType}.` +
113
+ ` Please check the 'endpointType' parameter.`
114
+ )
115
+ }
116
+
117
+ if (message.startsWith('ERROR: invalid input syntax for type json')) {
118
+ return (
119
+ `Could not parse a string as JSON.` +
120
+ ` Please check the 'sdl' or 'config' parameters.`
121
+ )
122
+ }
123
+
124
+ return message
125
+ })
126
+ .join('\n')
127
+
128
+ return {
129
+ data: undefined,
130
+ error: {
131
+ message,
132
+ },
133
+ }
134
+ }
135
+
136
+ const endpoints = data.endpoints.filter(Boolean)
137
+ if (!endpoints.length) {
138
+ return {
139
+ data: undefined,
140
+ error: {
141
+ message: 'Invalid credentials',
142
+ },
143
+ }
144
+ }
145
+
146
+ return {
147
+ data: endpoints[0],
148
+ error: undefined,
149
+ }
150
+ }
@@ -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
+ // Inlclude 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
+ serviceKey: 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
+ serviceKey: 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
+ serviceKeys: [data.account.serviceKey],
63
+ deploymentType,
64
+ },
65
+ error: undefined,
66
+ }
67
+ }
@@ -0,0 +1,96 @@
1
+ // Copyright (c) 2020,2021,2022, StepZen, Inc.
2
+
3
+ import {
4
+ SDKConfigurationV2,
5
+ StepZenEndpointV2,
6
+ ZenCtlResponseV2,
7
+ } from '../shared/types'
8
+ import {fetchZenCtlGraphQLQuery} from '../shared/graphql-client'
9
+
10
+ export default async ({
11
+ account,
12
+ deploymentType,
13
+ adminKey,
14
+ sdkConfig,
15
+ }: {
16
+ account: string
17
+ deploymentType: string
18
+ adminKey: string
19
+ sdkConfig: SDKConfigurationV2
20
+ }): Promise<ZenCtlResponseV2<StepZenEndpointV2[]>> => {
21
+ const {data, errors} = await fetchZenCtlGraphQLQuery<{
22
+ endpoints: Array<{
23
+ endpointName: string
24
+ folderName: string
25
+ }>
26
+ }>({
27
+ query: `query (
28
+ $account: String!
29
+ $deploymentType: String!
30
+ $adminKey: String!
31
+ ) {
32
+ endpoints: endpointsForAccount(
33
+ account: $account
34
+ deploymentType: $deploymentType
35
+ adminkey: $adminKey
36
+ ) {
37
+ endpointName: endpoint_name
38
+ folderName: folder_name
39
+ }
40
+ }`,
41
+ variables: {
42
+ account,
43
+ deploymentType,
44
+ adminKey,
45
+ },
46
+ sdkConfig,
47
+ })
48
+
49
+ if (errors) {
50
+ // strip graphql-specific error details, leave only the message
51
+ const message = errors
52
+ .map(({message}) => {
53
+ if (
54
+ message.startsWith(
55
+ 'ERROR: invalid input value for enum zenctl.deployment_type',
56
+ )
57
+ ) {
58
+ return (
59
+ `Invalid deployment type: ${deploymentType}.` +
60
+ ` Please check the 'deploymentType' parameter.`
61
+ )
62
+ }
63
+
64
+ return message
65
+ })
66
+ .join('\n')
67
+
68
+ return {
69
+ data: undefined,
70
+ error: {
71
+ message,
72
+ },
73
+ }
74
+ }
75
+
76
+ const endpoints = data.endpoints.filter(Boolean)
77
+ if (!endpoints.length) {
78
+ return {
79
+ data: undefined,
80
+ error: {
81
+ message: 'Invalid credentials',
82
+ },
83
+ }
84
+ }
85
+
86
+ return {
87
+ data: endpoints.map(endpoint => ({
88
+ ...endpoint,
89
+ public: false, // TODO: implement
90
+ endpointType: 'dev', // TODO: implement
91
+ account,
92
+ deploymentType,
93
+ })),
94
+ error: undefined,
95
+ }
96
+ }
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,70 @@
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 = (config: {
8
+ appName: string
9
+ zenctlApiUrl?: string
10
+ publicAccountApiUrl?: string
11
+ }) => {
12
+ const defaults = {
13
+ zenctlApiUrl:
14
+ process.env.STEPZEN_ZENCTL_API_URL ||
15
+ 'https://braselton.stepzen.net/api/zenctl2/__graphql',
16
+ publicAccountApiUrl:
17
+ process.env.STEPZEN_PUBLIC_ACCOUNT_API_URL ||
18
+ 'https://stepzen.stepzen.net/api/publicaccount/__graphql',
19
+ deploymentType:
20
+ process.env.STEPZEN_DEPLOYMENT_TYPE ||
21
+ process.env.STEPZEN_DOMAIN?.replace('.io', '') ||
22
+ 'steprz',
23
+ }
24
+
25
+ const sdkConfig: SDKConfigurationV2 = {
26
+ apiVersion: 'v2',
27
+ zenctlApiUrl: defaults.zenctlApiUrl,
28
+ publicAccountApiUrl: defaults.publicAccountApiUrl,
29
+ ...config,
30
+ }
31
+
32
+ return {
33
+ verify: async (
34
+ account: string,
35
+ adminkey: string,
36
+ deploymentType: string = defaults.deploymentType,
37
+ ) => {
38
+ try {
39
+ const {data} = await accountCommand({
40
+ account,
41
+ adminKey: adminkey,
42
+ deploymentType,
43
+ sdkConfig,
44
+ })
45
+ return Boolean(data)
46
+ } catch {
47
+ return false
48
+ }
49
+ },
50
+ client: async (
51
+ auth:
52
+ | {account: string; adminKey: string; deploymentType?: string}
53
+ | {publicAccountToken: string; deploymentType?: string},
54
+ ) => {
55
+ return createSdkClient(
56
+ {
57
+ deploymentType: defaults.deploymentType,
58
+ ...auth,
59
+ },
60
+ sdkConfig,
61
+ )
62
+ },
63
+ }
64
+ }
65
+
66
+ // a helper type to unwrap Promise<U> into U
67
+ type PromisedType<T> = T extends Promise<infer U> ? U : T
68
+
69
+ export type SDKV2 = ReturnType<typeof initV2>
70
+ 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']>>