@stepzen/sdk 0.49.0-experimental.3bed976 → 0.49.0-experimental.7f0fcac
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/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/shared/request.d.ts +3 -3
- package/lib/shared/request.d.ts.map +1 -1
- package/lib/shared/request.js.map +1 -1
- package/lib/shared/types.d.ts +0 -5
- package/lib/shared/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +0 -1
- package/src/shared/request.ts +3 -3
- package/src/shared/types.ts +0 -6
- package/lib/client.d.ts +0 -33
- package/lib/client.d.ts.map +0 -1
- package/lib/client.js +0 -88
- package/lib/client.js.map +0 -1
- package/lib/commands/account.d.ts +0 -10
- package/lib/commands/account.d.ts.map +0 -1
- package/lib/commands/account.js +0 -37
- package/lib/commands/account.js.map +0 -1
- package/lib/commands/authenticate.d.ts +0 -4
- package/lib/commands/authenticate.d.ts.map +0 -1
- package/lib/commands/authenticate.js +0 -23
- package/lib/commands/authenticate.js.map +0 -1
- package/lib/commands/deploy.d.ts +0 -4
- package/lib/commands/deploy.d.ts.map +0 -1
- package/lib/commands/deploy.js +0 -44
- package/lib/commands/deploy.js.map +0 -1
- package/lib/commands/getPublicAccount.d.ts +0 -7
- package/lib/commands/getPublicAccount.d.ts.map +0 -1
- package/lib/commands/getPublicAccount.js +0 -57
- package/lib/commands/getPublicAccount.js.map +0 -1
- package/lib/commands/list.d.ts +0 -4
- package/lib/commands/list.d.ts.map +0 -1
- package/lib/commands/list.js +0 -27
- package/lib/commands/list.js.map +0 -1
- package/lib/commands/upload.d.ts +0 -4
- package/lib/commands/upload.d.ts.map +0 -1
- package/lib/commands/upload.js +0 -69
- package/lib/commands/upload.js.map +0 -1
- package/lib/init.d.ts +0 -33
- package/lib/init.d.ts.map +0 -1
- package/lib/init.js +0 -25
- package/lib/init.js.map +0 -1
- package/src/client.ts +0 -132
- package/src/commands/account.ts +0 -54
- package/src/commands/authenticate.ts +0 -30
- package/src/commands/deploy.ts +0 -72
- package/src/commands/getPublicAccount.ts +0 -77
- package/src/commands/list.ts +0 -50
- package/src/commands/upload.ts +0 -97
- package/src/init.ts +0 -43
package/lib/commands/upload.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
import debug from 'debug';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import fetch from '@stepzen/fetch';
|
|
5
|
-
import { ADMIN_UPLOAD_URL } from '../shared/constants.js';
|
|
6
|
-
import { generateYamlPayload, generateZipPayload } from '../shared/payloads.js';
|
|
7
|
-
import { getRequestHeaders } from '../shared/request.js';
|
|
8
|
-
import { transpileConfigurationset } from '../shared/transpiling.js';
|
|
9
|
-
import { validateConfigurationset, validateSchema } from '../shared/validation.js';
|
|
10
|
-
import { rmtemp } from '../shared/rmtemp.js';
|
|
11
|
-
export default async (details, account, sdkConfig) => {
|
|
12
|
-
const headers = getRequestHeaders(account, sdkConfig);
|
|
13
|
-
let payload;
|
|
14
|
-
switch (details.type) {
|
|
15
|
-
case 'configurationset':
|
|
16
|
-
await validateConfigurationset(details.file);
|
|
17
|
-
const transpiled = await transpileConfigurationset(details.file);
|
|
18
|
-
try {
|
|
19
|
-
debug('stepzen:sdk')(`effective config written to ${transpiled}`);
|
|
20
|
-
payload = await generateYamlPayload(transpiled);
|
|
21
|
-
}
|
|
22
|
-
finally {
|
|
23
|
-
rmtemp(path.dirname(transpiled));
|
|
24
|
-
}
|
|
25
|
-
break;
|
|
26
|
-
case 'schema':
|
|
27
|
-
await validateSchema(details.directory);
|
|
28
|
-
payload = await generateZipPayload(details.directory, {
|
|
29
|
-
destination: details.destination,
|
|
30
|
-
stitcherName: 'index.graphql',
|
|
31
|
-
}, [/.*\.graphql$/i]);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
debug('stepzen:headers')(headers);
|
|
35
|
-
debug('stepzen:payload')(payload);
|
|
36
|
-
const response = await fetch(`${account.server}${ADMIN_UPLOAD_URL}/${details.type}/${details.destination}`, {
|
|
37
|
-
body: payload,
|
|
38
|
-
headers: headers,
|
|
39
|
-
method: 'POST',
|
|
40
|
-
});
|
|
41
|
-
debug('stepzen:response')(response);
|
|
42
|
-
if (response.status >= 400 && response.status < 500) {
|
|
43
|
-
return {
|
|
44
|
-
message: 'Could not complete the request. Please check your authentication details are correct.',
|
|
45
|
-
success: false,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
if (response.status >= 500) {
|
|
49
|
-
return {
|
|
50
|
-
errors: ['Internal Server Error'],
|
|
51
|
-
message: response.statusText,
|
|
52
|
-
success: false,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const text = await response.text();
|
|
56
|
-
let json;
|
|
57
|
-
try {
|
|
58
|
-
json = JSON.parse(text);
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return {
|
|
62
|
-
errors: [`An unexpected error occurred.\n\n${text}`],
|
|
63
|
-
message: `An unexpected error occurred.\n\n${text}`,
|
|
64
|
-
success: false,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return json;
|
|
68
|
-
};
|
|
69
|
-
//# sourceMappingURL=upload.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"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"}
|
package/lib/init.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AnonymousClientOptions, SDKConfiguration, UserCredentialsClientOptions } from './shared/types.js';
|
|
2
|
-
export declare const init: (sdkConfig: SDKConfiguration) => {
|
|
3
|
-
verify: (account: string, adminkey: string) => Promise<boolean>;
|
|
4
|
-
client: (options: UserCredentialsClientOptions | AnonymousClientOptions) => Promise<{
|
|
5
|
-
readonly credentials: import("./client.js").StepZenCredentials;
|
|
6
|
-
account: () => Promise<{
|
|
7
|
-
account: string;
|
|
8
|
-
apikey: string;
|
|
9
|
-
} | {
|
|
10
|
-
success: false;
|
|
11
|
-
errors: string[];
|
|
12
|
-
}>;
|
|
13
|
-
deploy: (destination: string, properties: {
|
|
14
|
-
configurationsets?: string[] | undefined;
|
|
15
|
-
schema: string;
|
|
16
|
-
}) => Promise<import("./client.js").ZenCtlResponse>;
|
|
17
|
-
list: {
|
|
18
|
-
deployments: () => Promise<import("./client.js").ZenCtlResponse>;
|
|
19
|
-
configurationsets: () => Promise<import("./client.js").ZenCtlResponse>;
|
|
20
|
-
schemas: () => Promise<import("./client.js").ZenCtlResponse>;
|
|
21
|
-
};
|
|
22
|
-
upload: {
|
|
23
|
-
configurationset: (destination: string, file: string) => Promise<import("./client.js").ZenCtlResponse>;
|
|
24
|
-
schema: (destination: string, directory: string) => Promise<import("./client.js").ZenCtlResponse>;
|
|
25
|
-
};
|
|
26
|
-
}>;
|
|
27
|
-
readonly userAgent: string;
|
|
28
|
-
};
|
|
29
|
-
type PromisedType<T> = T extends Promise<infer U> ? U : T;
|
|
30
|
-
export type SDK = ReturnType<typeof init>;
|
|
31
|
-
export type SDKClient = PromisedType<ReturnType<SDK['client']>>;
|
|
32
|
-
export {};
|
|
33
|
-
//# sourceMappingURL=init.d.ts.map
|
package/lib/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,eAAO,MAAM,IAAI,cAAe,gBAAgB;sBAM1B,MAAM,YAAY,MAAM;sBAW/B,4BAA4B,GAAG,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;CAQnE,CAAA;AAGD,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAA;AACzC,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA"}
|
package/lib/init.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
import authenticate from './commands/authenticate.js';
|
|
3
|
-
import { createSdkClient } from './client.js';
|
|
4
|
-
import { getUserAgent } from './shared/request.js';
|
|
5
|
-
export const init = (sdkConfig) => {
|
|
6
|
-
const defaults = {
|
|
7
|
-
server: process.env.STEPZEN_SERVER_URL || 'https://{account}.stepzen.io',
|
|
8
|
-
};
|
|
9
|
-
return {
|
|
10
|
-
verify: (account, adminkey) => {
|
|
11
|
-
return authenticate({
|
|
12
|
-
account,
|
|
13
|
-
adminkey,
|
|
14
|
-
server: defaults.server.replace('{account}', account),
|
|
15
|
-
}, sdkConfig);
|
|
16
|
-
},
|
|
17
|
-
client: async (options) => {
|
|
18
|
-
return createSdkClient({ ...defaults, ...options }, sdkConfig);
|
|
19
|
-
},
|
|
20
|
-
get userAgent() {
|
|
21
|
-
return getUserAgent(sdkConfig);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=init.js.map
|
package/lib/init.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,OAAO,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAA;AAOhD,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,SAA2B,EAAE,EAAE;IAClD,MAAM,QAAQ,GAAG;QACf,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,8BAA8B;KACzE,CAAA;IAED,OAAO;QACL,MAAM,EAAE,CAAC,OAAe,EAAE,QAAgB,EAAE,EAAE;YAC5C,OAAO,YAAY,CACjB;gBACE,OAAO;gBACP,QAAQ;gBACR,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC;aACtD,EACD,SAAS,CACV,CAAA;QACH,CAAC;QACD,MAAM,EAAE,KAAK,EACX,OAA8D,EAC9D,EAAE;YACF,OAAO,eAAe,CAAC,EAAC,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAC,EAAE,SAAS,CAAC,CAAA;QAC9D,CAAC;QACD,IAAI,SAAS;YACX,OAAO,YAAY,CAAC,SAAS,CAAC,CAAA;QAChC,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/src/client.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import accountCommand from './commands/account.js'
|
|
4
|
-
import deploy from './commands/deploy.js'
|
|
5
|
-
import {
|
|
6
|
-
AnonymousClientOptions,
|
|
7
|
-
SDKConfiguration,
|
|
8
|
-
StepZenAccount,
|
|
9
|
-
} from './shared/types.js'
|
|
10
|
-
import list from './commands/list.js'
|
|
11
|
-
import upload from './commands/upload.js'
|
|
12
|
-
import getPublicAccount from './commands/getPublicAccount.js'
|
|
13
|
-
|
|
14
|
-
export * from './shared/types.js'
|
|
15
|
-
|
|
16
|
-
export const validateCreateClientOptions = async (
|
|
17
|
-
options: StepZenAccount | Required<AnonymousClientOptions>,
|
|
18
|
-
sdkConfig: SDKConfiguration,
|
|
19
|
-
) => {
|
|
20
|
-
let credentials
|
|
21
|
-
let account
|
|
22
|
-
|
|
23
|
-
if ('publicAccountToken' in options) {
|
|
24
|
-
// create an anonymous account and use it to initialize an SDK client instance
|
|
25
|
-
const credentialsOrError = await getPublicAccount(options, sdkConfig)
|
|
26
|
-
if ('errors' in credentialsOrError) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
`An unexpected error occurred. ${JSON.stringify(
|
|
29
|
-
credentialsOrError.errors,
|
|
30
|
-
)}`,
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
credentials = credentialsOrError
|
|
35
|
-
account = {
|
|
36
|
-
...credentialsOrError,
|
|
37
|
-
server: options.server,
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
// use the provided account to initialize an SDK client instance
|
|
41
|
-
options.server = options.server.replace('{account}', options.account)
|
|
42
|
-
let accountOrError
|
|
43
|
-
try {
|
|
44
|
-
accountOrError = await accountCommand(options, sdkConfig)
|
|
45
|
-
} catch (error) {
|
|
46
|
-
if (
|
|
47
|
-
error instanceof Error &&
|
|
48
|
-
error.message.includes('Please check your authentication details')
|
|
49
|
-
) {
|
|
50
|
-
throw new Error('Your credentials are invalid.')
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error(`An unexpected error occurred. ${error}`)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if ('errors' in accountOrError) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
`An unexpected error occurred. ${JSON.stringify(
|
|
59
|
-
accountOrError.errors,
|
|
60
|
-
)}`,
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
account = options
|
|
65
|
-
|
|
66
|
-
credentials = {
|
|
67
|
-
account: options.account,
|
|
68
|
-
adminkey: options.adminkey,
|
|
69
|
-
apikey: accountOrError.apikey,
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return {account, credentials}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const createSdkClient = async (
|
|
76
|
-
options: Required<StepZenAccount | AnonymousClientOptions>,
|
|
77
|
-
sdkConfig: SDKConfiguration,
|
|
78
|
-
) => {
|
|
79
|
-
const {account, credentials} = await validateCreateClientOptions(
|
|
80
|
-
options,
|
|
81
|
-
sdkConfig,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
get credentials(): typeof credentials {
|
|
86
|
-
// always return a copy to avoid accidential modification by the caller
|
|
87
|
-
return {...credentials}
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* @deprecated use `.credentials` or create a new SDK client instead
|
|
91
|
-
**/
|
|
92
|
-
account: () => {
|
|
93
|
-
return accountCommand(account, sdkConfig)
|
|
94
|
-
},
|
|
95
|
-
deploy: (
|
|
96
|
-
destination: string,
|
|
97
|
-
properties: {
|
|
98
|
-
configurationsets?: string[]
|
|
99
|
-
schema: string
|
|
100
|
-
},
|
|
101
|
-
) => {
|
|
102
|
-
return deploy({destination, ...properties}, account, sdkConfig)
|
|
103
|
-
},
|
|
104
|
-
list: {
|
|
105
|
-
deployments: async () => {
|
|
106
|
-
return list({type: 'deployments'}, account, sdkConfig)
|
|
107
|
-
},
|
|
108
|
-
configurationsets: async () => {
|
|
109
|
-
return list({type: 'configurationsets'}, account, sdkConfig)
|
|
110
|
-
},
|
|
111
|
-
schemas: async () => {
|
|
112
|
-
return list({type: 'schemas'}, account, sdkConfig)
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
upload: {
|
|
116
|
-
configurationset: async (destination: string, file: string) => {
|
|
117
|
-
return upload(
|
|
118
|
-
{type: 'configurationset', destination, file},
|
|
119
|
-
account,
|
|
120
|
-
sdkConfig,
|
|
121
|
-
)
|
|
122
|
-
},
|
|
123
|
-
schema: async (destination: string, directory: string) => {
|
|
124
|
-
return upload(
|
|
125
|
-
{type: 'schema', destination, directory},
|
|
126
|
-
account,
|
|
127
|
-
sdkConfig,
|
|
128
|
-
)
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
}
|
|
132
|
-
}
|
package/src/commands/account.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import fetch from '@stepzen/fetch'
|
|
5
|
-
|
|
6
|
-
import {ADMIN_ACCOUNT_URL} from '../shared/constants.js'
|
|
7
|
-
import {getRequestHeaders} from '../shared/request.js'
|
|
8
|
-
import {SDKConfiguration, StepZenAccount} from '../shared/types.js'
|
|
9
|
-
|
|
10
|
-
export default async (
|
|
11
|
-
account: StepZenAccount,
|
|
12
|
-
sdkConfig: SDKConfiguration,
|
|
13
|
-
): Promise<
|
|
14
|
-
{account: string; apikey: string} | {success: false; errors: string[]}
|
|
15
|
-
> => {
|
|
16
|
-
const headers = getRequestHeaders(account, sdkConfig)
|
|
17
|
-
const url = `${account.server}${ADMIN_ACCOUNT_URL}`
|
|
18
|
-
|
|
19
|
-
debug('stepzen:headers')(headers)
|
|
20
|
-
|
|
21
|
-
const response = await fetch(url, {
|
|
22
|
-
headers: headers as any,
|
|
23
|
-
method: 'POST',
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
debug('stepzen:response')(response)
|
|
27
|
-
|
|
28
|
-
if (response.status === 401 || response.status === 403) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
'Could not complete the request. Please check your authentication details are correct.',
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (response.status >= 400) {
|
|
35
|
-
return {
|
|
36
|
-
errors: [response.statusText],
|
|
37
|
-
success: false,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const text = await response.text()
|
|
42
|
-
let json
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
json = JSON.parse(text)
|
|
46
|
-
} catch {
|
|
47
|
-
return {
|
|
48
|
-
errors: [`An unexpected error occurred.\n\n${text}`],
|
|
49
|
-
success: false,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return json
|
|
54
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import fetch from '@stepzen/fetch'
|
|
5
|
-
|
|
6
|
-
import {ADMIN_VERIFY_URL} from '../shared/constants.js'
|
|
7
|
-
import {getRequestHeaders} from '../shared/request.js'
|
|
8
|
-
import {SDKConfiguration, StepZenAccount} from '../shared/types.js'
|
|
9
|
-
|
|
10
|
-
export default async (
|
|
11
|
-
settings: StepZenAccount,
|
|
12
|
-
sdkConfig: SDKConfiguration,
|
|
13
|
-
): Promise<boolean> => {
|
|
14
|
-
const headers = getRequestHeaders(settings, sdkConfig)
|
|
15
|
-
const url = `${settings.server}${ADMIN_VERIFY_URL}`
|
|
16
|
-
|
|
17
|
-
debug('stepzen:headers')(headers)
|
|
18
|
-
debug('stepzen:url')(url)
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const response = await fetch(url, {
|
|
22
|
-
headers: headers as any,
|
|
23
|
-
method: 'POST',
|
|
24
|
-
})
|
|
25
|
-
await response.json()
|
|
26
|
-
return true
|
|
27
|
-
} catch {
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
}
|
package/src/commands/deploy.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import fetch from '@stepzen/fetch'
|
|
5
|
-
|
|
6
|
-
import {ADMIN_DEPLOY_URL} from '../shared/constants.js'
|
|
7
|
-
import {getRequestHeaders} from '../shared/request.js'
|
|
8
|
-
import {
|
|
9
|
-
SDKConfiguration,
|
|
10
|
-
StepZenAccount,
|
|
11
|
-
StepZenDeploy,
|
|
12
|
-
ZenCtlResponse,
|
|
13
|
-
} from '../shared/types.js'
|
|
14
|
-
|
|
15
|
-
export default async (
|
|
16
|
-
details: StepZenDeploy,
|
|
17
|
-
account: StepZenAccount,
|
|
18
|
-
sdkConfig: SDKConfiguration,
|
|
19
|
-
): Promise<ZenCtlResponse> => {
|
|
20
|
-
const headers = getRequestHeaders(account, sdkConfig)
|
|
21
|
-
|
|
22
|
-
const payload: any = {
|
|
23
|
-
schema: `/workspaces/schemas/${details.schema}`,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (details.configurationsets) {
|
|
27
|
-
payload.configurationsets = details.configurationsets.map(
|
|
28
|
-
config => `/workspaces/configurationsets/${config}`,
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
debug('stepzen:headers')(headers)
|
|
33
|
-
debug('stepzen:payload')(payload)
|
|
34
|
-
|
|
35
|
-
const response = await fetch(
|
|
36
|
-
`${account.server}${ADMIN_DEPLOY_URL}/${details.destination}`,
|
|
37
|
-
{
|
|
38
|
-
body: JSON.stringify(payload),
|
|
39
|
-
headers: headers as any,
|
|
40
|
-
method: 'POST',
|
|
41
|
-
},
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
debug('stepzen:response')(response)
|
|
45
|
-
|
|
46
|
-
if (response.status >= 400 && response.status < 500) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
'Could not complete the request. Please check your authentication details are correct.',
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (response.status >= 500) {
|
|
53
|
-
return {
|
|
54
|
-
errors: [response.statusText],
|
|
55
|
-
success: false,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const text = await response.text()
|
|
60
|
-
let json
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
json = JSON.parse(text)
|
|
64
|
-
} catch {
|
|
65
|
-
return {
|
|
66
|
-
errors: [`An unexpected error occurred.\n\n${text}`],
|
|
67
|
-
success: false,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return json
|
|
72
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import fetch from '@stepzen/fetch'
|
|
5
|
-
|
|
6
|
-
import {getUserAgent} from '../shared/request.js'
|
|
7
|
-
import {
|
|
8
|
-
AnonymousClientOptions,
|
|
9
|
-
SDKConfiguration,
|
|
10
|
-
StepZenCredentials,
|
|
11
|
-
} from '../shared/types.js'
|
|
12
|
-
|
|
13
|
-
export default async (
|
|
14
|
-
options: Required<AnonymousClientOptions>,
|
|
15
|
-
sdkConfig: SDKConfiguration,
|
|
16
|
-
): Promise<
|
|
17
|
-
| StepZenCredentials
|
|
18
|
-
| {
|
|
19
|
-
success: false
|
|
20
|
-
errors: string[]
|
|
21
|
-
}
|
|
22
|
-
> => {
|
|
23
|
-
const account = process.env.STEPZEN_PUBLIC_ACCOUNT_API_ACCOUNT || 'stepzen'
|
|
24
|
-
const endpoint =
|
|
25
|
-
process.env.STEPZEN_PUBLIC_ACCOUNT_API_ENDPOINT || 'api/publicaccount'
|
|
26
|
-
const server = options.server
|
|
27
|
-
.replace('{account}', account)
|
|
28
|
-
.replace('.io', '.net')
|
|
29
|
-
|
|
30
|
-
const url = new URL(`${server}/${endpoint}/__graphql`)
|
|
31
|
-
// Inlclude the token into the URL so that it is visible in the logs
|
|
32
|
-
// (allows StepZen to do analytics based on the GCP logs).
|
|
33
|
-
url.searchParams.set('token', options.publicAccountToken)
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
debug('stepzen:createAnonymousAccount')(url)
|
|
37
|
-
const response = await fetch(url, {
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: {
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
'User-Agent': getUserAgent(sdkConfig),
|
|
42
|
-
},
|
|
43
|
-
body: JSON.stringify({
|
|
44
|
-
query: `query (
|
|
45
|
-
$token: String!
|
|
46
|
-
) {
|
|
47
|
-
getAccountDetails(
|
|
48
|
-
token: $token
|
|
49
|
-
) {
|
|
50
|
-
account: accountName
|
|
51
|
-
adminkey: adminKey
|
|
52
|
-
apikey: apiKey
|
|
53
|
-
}
|
|
54
|
-
}`,
|
|
55
|
-
variables: {
|
|
56
|
-
token: options.publicAccountToken,
|
|
57
|
-
},
|
|
58
|
-
}),
|
|
59
|
-
})
|
|
60
|
-
const json = await response.json()
|
|
61
|
-
debug('stepzen:createAnonymousAccount')(json)
|
|
62
|
-
if (json.errors) {
|
|
63
|
-
return {
|
|
64
|
-
success: false,
|
|
65
|
-
errors: json.errors,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (!json.data?.getAccountDetails) {
|
|
70
|
-
throw new Error('No data returned from the API endpoint.')
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return json.data?.getAccountDetails
|
|
74
|
-
} catch (error) {
|
|
75
|
-
throw new Error(`Could not create a public account (${error})`)
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/commands/list.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import fetch from '@stepzen/fetch'
|
|
5
|
-
|
|
6
|
-
import {ADMIN_LIST_URL} from '../shared/constants.js'
|
|
7
|
-
import {getRequestHeaders} from '../shared/request.js'
|
|
8
|
-
import {
|
|
9
|
-
SDKConfiguration,
|
|
10
|
-
StepZenAccount,
|
|
11
|
-
StepZenList,
|
|
12
|
-
ZenCtlResponse,
|
|
13
|
-
} from '../shared/types.js'
|
|
14
|
-
|
|
15
|
-
export default async (
|
|
16
|
-
details: StepZenList,
|
|
17
|
-
account: StepZenAccount,
|
|
18
|
-
sdkConfig: SDKConfiguration,
|
|
19
|
-
): Promise<ZenCtlResponse> => {
|
|
20
|
-
const headers = getRequestHeaders(account, sdkConfig)
|
|
21
|
-
|
|
22
|
-
debug('stepzen:headers')(headers)
|
|
23
|
-
|
|
24
|
-
const response = await fetch(
|
|
25
|
-
`${account.server}${ADMIN_LIST_URL}/${details.type}`,
|
|
26
|
-
{
|
|
27
|
-
headers: headers as any,
|
|
28
|
-
method: 'GET',
|
|
29
|
-
},
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
debug('stepzen:response')(response)
|
|
33
|
-
|
|
34
|
-
if (response.status >= 400 && response.status < 500) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
'Could not complete the request. Please check your authentication details are correct.',
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const text = await response.text()
|
|
41
|
-
let json
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
json = JSON.parse(text)
|
|
45
|
-
} catch {
|
|
46
|
-
throw new Error(`An unexpected error occurred.\n\n${text}`)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return json
|
|
50
|
-
}
|
package/src/commands/upload.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// Copyright IBM Corp. 2020, 2025
|
|
2
|
-
|
|
3
|
-
import debug from 'debug'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import fetch from '@stepzen/fetch'
|
|
6
|
-
|
|
7
|
-
import {ADMIN_UPLOAD_URL} from '../shared/constants.js'
|
|
8
|
-
import {generateYamlPayload, generateZipPayload} from '../shared/payloads.js'
|
|
9
|
-
import {getRequestHeaders} from '../shared/request.js'
|
|
10
|
-
import {
|
|
11
|
-
SDKConfiguration,
|
|
12
|
-
StepZenAccount,
|
|
13
|
-
StepZenUpload,
|
|
14
|
-
ZenCtlResponse,
|
|
15
|
-
} from '../shared/types.js'
|
|
16
|
-
import {transpileConfigurationset} from '../shared/transpiling.js'
|
|
17
|
-
import {validateConfigurationset, validateSchema} from '../shared/validation.js'
|
|
18
|
-
import {rmtemp} from '../shared/rmtemp.js'
|
|
19
|
-
|
|
20
|
-
export default async (
|
|
21
|
-
details: StepZenUpload,
|
|
22
|
-
account: StepZenAccount,
|
|
23
|
-
sdkConfig: SDKConfiguration,
|
|
24
|
-
): Promise<ZenCtlResponse> => {
|
|
25
|
-
const headers = getRequestHeaders(account, sdkConfig)
|
|
26
|
-
let payload
|
|
27
|
-
|
|
28
|
-
switch (details.type) {
|
|
29
|
-
case 'configurationset':
|
|
30
|
-
await validateConfigurationset(details.file)
|
|
31
|
-
const transpiled = await transpileConfigurationset(details.file!)
|
|
32
|
-
try {
|
|
33
|
-
debug('stepzen:sdk')(`effective config written to ${transpiled}`)
|
|
34
|
-
payload = await generateYamlPayload(transpiled)
|
|
35
|
-
} finally {
|
|
36
|
-
rmtemp(path.dirname(transpiled))
|
|
37
|
-
}
|
|
38
|
-
break
|
|
39
|
-
|
|
40
|
-
case 'schema':
|
|
41
|
-
await validateSchema(details.directory)
|
|
42
|
-
payload = await generateZipPayload(
|
|
43
|
-
details.directory,
|
|
44
|
-
{
|
|
45
|
-
destination: details.destination,
|
|
46
|
-
stitcherName: 'index.graphql',
|
|
47
|
-
},
|
|
48
|
-
[/.*\.graphql$/i],
|
|
49
|
-
)
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
debug('stepzen:headers')(headers)
|
|
54
|
-
debug('stepzen:payload')(payload)
|
|
55
|
-
|
|
56
|
-
const response = await fetch(
|
|
57
|
-
`${account.server}${ADMIN_UPLOAD_URL}/${details.type}/${details.destination}`,
|
|
58
|
-
{
|
|
59
|
-
body: payload,
|
|
60
|
-
headers: headers as any,
|
|
61
|
-
method: 'POST',
|
|
62
|
-
},
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
debug('stepzen:response')(response)
|
|
66
|
-
|
|
67
|
-
if (response.status >= 400 && response.status < 500) {
|
|
68
|
-
return {
|
|
69
|
-
message:
|
|
70
|
-
'Could not complete the request. Please check your authentication details are correct.',
|
|
71
|
-
success: false,
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (response.status >= 500) {
|
|
76
|
-
return {
|
|
77
|
-
errors: ['Internal Server Error'],
|
|
78
|
-
message: response.statusText,
|
|
79
|
-
success: false,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const text = await response.text()
|
|
84
|
-
let json
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
json = JSON.parse(text)
|
|
88
|
-
} catch {
|
|
89
|
-
return {
|
|
90
|
-
errors: [`An unexpected error occurred.\n\n${text}`],
|
|
91
|
-
message: `An unexpected error occurred.\n\n${text}`,
|
|
92
|
-
success: false,
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return json
|
|
97
|
-
}
|