@stepzen/sdk 0.20.1 → 0.21.0-beta.2
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/client-v2.d.ts +50 -0
- package/lib/client-v2.d.ts.map +1 -0
- package/lib/client-v2.js +91 -0
- package/lib/client-v2.js.map +1 -0
- package/lib/client.d.ts +3 -7
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +7 -3
- package/lib/client.js.map +1 -1
- package/lib/commands/account.js +1 -1
- package/lib/commands/account.js.map +1 -1
- package/lib/commands/authenticate.js +1 -1
- package/lib/commands/authenticate.js.map +1 -1
- package/lib/commands/deploy.js +1 -1
- package/lib/commands/deploy.js.map +1 -1
- package/lib/commands/getPublicAccount.js +2 -3
- package/lib/commands/getPublicAccount.js.map +1 -1
- package/lib/commands/list.js +1 -1
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/upload.d.ts.map +1 -1
- package/lib/commands/upload.js +3 -8
- package/lib/commands/upload.js.map +1 -1
- package/lib/commands-v2/account.d.ts +9 -0
- package/lib/commands-v2/account.d.ts.map +1 -0
- package/lib/commands-v2/account.js +68 -0
- package/lib/commands-v2/account.js.map +1 -0
- package/lib/commands-v2/deploy.d.ts +15 -0
- package/lib/commands-v2/deploy.d.ts.map +1 -0
- package/lib/commands-v2/deploy.js +90 -0
- package/lib/commands-v2/deploy.js.map +1 -0
- package/lib/commands-v2/getPublicAccount.d.ts +8 -0
- package/lib/commands-v2/getPublicAccount.d.ts.map +1 -0
- package/lib/commands-v2/getPublicAccount.js +46 -0
- package/lib/commands-v2/getPublicAccount.js.map +1 -0
- package/lib/commands-v2/list.d.ts +12 -0
- package/lib/commands-v2/list.d.ts.map +1 -0
- package/lib/commands-v2/list.js +58 -0
- package/lib/commands-v2/list.js.map +1 -0
- package/lib/index.d.ts +3 -34
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -25
- package/lib/index.js.map +1 -1
- package/lib/init-v2.d.ts +32 -0
- package/lib/init-v2.d.ts.map +1 -0
- package/lib/init-v2.js +29 -0
- package/lib/init-v2.js.map +1 -0
- package/lib/init.d.ts +32 -0
- package/lib/init.d.ts.map +1 -0
- package/lib/init.js +27 -0
- package/lib/init.js.map +1 -0
- package/lib/shared/constants.d.ts +1 -0
- package/lib/shared/constants.d.ts.map +1 -1
- package/lib/shared/constants.js +2 -1
- package/lib/shared/constants.js.map +1 -1
- package/lib/shared/graphql-client.d.ts +38 -0
- package/lib/shared/graphql-client.d.ts.map +1 -0
- package/lib/shared/graphql-client.js +80 -0
- package/lib/shared/graphql-client.js.map +1 -0
- package/lib/shared/payloads.d.ts +3 -0
- package/lib/shared/payloads.d.ts.map +1 -1
- package/lib/shared/payloads.js +37 -2
- package/lib/shared/payloads.js.map +1 -1
- package/lib/shared/transpiling.d.ts +14 -1
- package/lib/shared/transpiling.d.ts.map +1 -1
- package/lib/shared/transpiling.js +8 -9
- package/lib/shared/transpiling.js.map +1 -1
- package/lib/shared/types.d.ts +117 -0
- package/lib/shared/types.d.ts.map +1 -1
- package/lib/shared/validation.d.ts.map +1 -1
- package/lib/shared/validation.js +7 -1
- package/lib/shared/validation.js.map +1 -1
- package/package.json +4 -3
- package/src/client-v2.ts +120 -0
- package/src/client.ts +3 -4
- package/src/commands/upload.ts +3 -7
- package/src/commands-v2/account.ts +98 -0
- package/src/commands-v2/deploy.ts +145 -0
- package/src/commands-v2/getPublicAccount.ts +67 -0
- package/src/commands-v2/list.ts +91 -0
- package/src/index.ts +3 -38
- package/src/init-v2.ts +40 -0
- package/src/init.ts +41 -0
- package/src/shared/constants.ts +2 -0
- package/src/shared/graphql-client.ts +136 -0
- package/src/shared/payloads.ts +49 -1
- package/src/shared/transpiling.ts +25 -11
- package/src/shared/types.ts +142 -0
- package/src/shared/validation.ts +11 -1
|
@@ -3,28 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.transpileConfigurationset = void 0;
|
|
5
5
|
const dotenv = require("dotenv");
|
|
6
|
+
const debug = require("debug");
|
|
6
7
|
const fs = require("fs-extra");
|
|
7
8
|
const os = require("os");
|
|
8
9
|
const path = require("path");
|
|
9
10
|
const transpiler_1 = require("@stepzen/transpiler");
|
|
10
|
-
|
|
11
|
+
async function transpileConfigurationset(file) {
|
|
11
12
|
if (!file) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
const source = file.substring(0, file.lastIndexOf('/'));
|
|
16
|
+
debug('stepzen:dotenv')(`loading .env from ${path.resolve(source)}` +
|
|
17
|
+
`, at sdk/src/shared/transpiling.ts`);
|
|
15
18
|
dotenv.config({ path: path.resolve(source, '.env') });
|
|
16
19
|
const tmp = path.join(os.tmpdir(), `stepzen-transpiler-${Date.now()}`);
|
|
17
20
|
const configPath = path.join(tmp, 'config.yaml');
|
|
18
21
|
fs.ensureDirSync(tmp);
|
|
19
22
|
fs.copyFileSync(file, configPath);
|
|
20
23
|
const result = await (0, transpiler_1.transpile)(tmp);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
fs.removeSync(tmp);
|
|
27
|
-
return;
|
|
28
|
-
};
|
|
24
|
+
fs.emptyDirSync(tmp);
|
|
25
|
+
fs.writeFileSync(configPath, result.config || '');
|
|
26
|
+
return configPath;
|
|
27
|
+
}
|
|
29
28
|
exports.transpileConfigurationset = transpileConfigurationset;
|
|
30
29
|
//# sourceMappingURL=transpiling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpiling.js","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,iCAAgC;AAChC,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,oDAA6C;
|
|
1
|
+
{"version":3,"file":"transpiling.js","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,iCAAgC;AAChC,+BAA8B;AAC9B,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,oDAA6C;AAkBtC,KAAK,UAAU,yBAAyB,CAAC,IAAa;IAC3D,IAAI,CAAC,IAAI,EAAE;QACT,OAAM;KACP;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,KAAK,CAAC,gBAAgB,CAAC,CACrB,qBAAqB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzC,oCAAoC,CACvC,CAAA;IACD,MAAM,CAAC,MAAM,CAAC,EAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAC,CAAC,CAAA;IAEnD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,sBAAsB,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACtE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;IAEhD,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;IACrB,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAEjC,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAS,EAAC,GAAG,CAAC,CAAA;IAEnC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IACjD,OAAO,UAAU,CAAA;AACnB,CAAC;AAvBD,8DAuBC"}
|
package/lib/shared/types.d.ts
CHANGED
|
@@ -74,4 +74,121 @@ export interface SDKConfiguration {
|
|
|
74
74
|
*/
|
|
75
75
|
appName: string;
|
|
76
76
|
}
|
|
77
|
+
export interface SDKConfigurationV2 extends SDKConfiguration {
|
|
78
|
+
/**
|
|
79
|
+
* The name and version of that app that uses the SDK,
|
|
80
|
+
* e.g. `stepzen-cli/0.9.32`
|
|
81
|
+
*
|
|
82
|
+
* It is appended to the user-agent string in all requests made to StepZen
|
|
83
|
+
* through the SDK and becomes availabe in the log analytics.
|
|
84
|
+
*/
|
|
85
|
+
appName: string;
|
|
86
|
+
/**
|
|
87
|
+
* Version of ZenCtl API to use:
|
|
88
|
+
* - `undefined`, `v1`: implies the v1 REST API at /ctl/admin/
|
|
89
|
+
* - `v2`: implies the v2 GraphQL API
|
|
90
|
+
*/
|
|
91
|
+
apiVersion: string;
|
|
92
|
+
/**
|
|
93
|
+
* URL of the ZenCtl GraphQL API,
|
|
94
|
+
* e.g. https://stepzen.stepzen.net/api/zenctl2/__graphql
|
|
95
|
+
*/
|
|
96
|
+
zenctlApiUrl: string;
|
|
97
|
+
/**
|
|
98
|
+
* URL of the StepZen getPublicAccount GraphQL API,
|
|
99
|
+
* e.g. https://stepzen.stepzen.net/api/publicaccount/__graphql
|
|
100
|
+
*/
|
|
101
|
+
publicAccountApiUrl: string;
|
|
102
|
+
}
|
|
103
|
+
export interface ZenCtlSuccessResponseV2<T> {
|
|
104
|
+
data: T;
|
|
105
|
+
error: undefined;
|
|
106
|
+
}
|
|
107
|
+
export interface ZenCtlErrorResponseV2 {
|
|
108
|
+
data: undefined;
|
|
109
|
+
error: {
|
|
110
|
+
message: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export declare type ZenCtlResponseV2<T> = ZenCtlSuccessResponseV2<T> | ZenCtlErrorResponseV2;
|
|
114
|
+
export interface StepZenCredentialsV2 {
|
|
115
|
+
account: string;
|
|
116
|
+
adminKey: string;
|
|
117
|
+
apiKeys: string[];
|
|
118
|
+
deploymentType: string;
|
|
119
|
+
}
|
|
120
|
+
export interface StepZenAccountV2 {
|
|
121
|
+
account: string;
|
|
122
|
+
ownerEmail: string;
|
|
123
|
+
adminKey: string;
|
|
124
|
+
apiKeys: string[];
|
|
125
|
+
deploymentType: string;
|
|
126
|
+
}
|
|
127
|
+
export interface StepZenEndpointV2 {
|
|
128
|
+
account: string;
|
|
129
|
+
deploymentType: string;
|
|
130
|
+
folderName: string;
|
|
131
|
+
endpointName: string;
|
|
132
|
+
public: boolean;
|
|
133
|
+
endpointType: string;
|
|
134
|
+
}
|
|
135
|
+
export interface SchemaFiles {
|
|
136
|
+
files: SchemaFile[];
|
|
137
|
+
entryPoint?: String;
|
|
138
|
+
}
|
|
139
|
+
export interface SchemaFile {
|
|
140
|
+
name: string;
|
|
141
|
+
content: string;
|
|
142
|
+
}
|
|
143
|
+
export interface Configuration {
|
|
144
|
+
configurationset?: ConfigurationSet[];
|
|
145
|
+
ruleset?: QueryRule[];
|
|
146
|
+
access?: Policies;
|
|
147
|
+
deployment?: DeploymentSettings;
|
|
148
|
+
}
|
|
149
|
+
export interface ConfigurationSet {
|
|
150
|
+
configuration?: Record<string, any>;
|
|
151
|
+
}
|
|
152
|
+
export interface QueryRule {
|
|
153
|
+
query: string;
|
|
154
|
+
disabled?: boolean;
|
|
155
|
+
rules?: Rule[];
|
|
156
|
+
}
|
|
157
|
+
export interface Rule {
|
|
158
|
+
predicate: string;
|
|
159
|
+
action: string;
|
|
160
|
+
}
|
|
161
|
+
export interface Policies {
|
|
162
|
+
policies?: Policy[];
|
|
163
|
+
}
|
|
164
|
+
export interface Policy {
|
|
165
|
+
type?: string;
|
|
166
|
+
rules?: FieldRule[];
|
|
167
|
+
policyDefault?: FieldCondition;
|
|
168
|
+
}
|
|
169
|
+
export interface FieldRule {
|
|
170
|
+
name?: string;
|
|
171
|
+
description?: string;
|
|
172
|
+
condition: string;
|
|
173
|
+
fields?: string[];
|
|
174
|
+
}
|
|
175
|
+
export interface FieldCondition {
|
|
176
|
+
condition: string;
|
|
177
|
+
}
|
|
178
|
+
export interface DeploymentSettings {
|
|
179
|
+
identity?: IdentitySettings;
|
|
180
|
+
}
|
|
181
|
+
export interface IdentitySettings {
|
|
182
|
+
keys?: JWTKey[];
|
|
183
|
+
issuer?: string;
|
|
184
|
+
subject?: string;
|
|
185
|
+
audience?: string;
|
|
186
|
+
claims?: string[];
|
|
187
|
+
jwksendpoint?: string;
|
|
188
|
+
}
|
|
189
|
+
export interface JWTKey {
|
|
190
|
+
algorithm?: string;
|
|
191
|
+
keyid?: string;
|
|
192
|
+
key?: string;
|
|
193
|
+
}
|
|
77
194
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAEhB;;;;;;;;;;;OAWG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;;;;;;;;OAUG;IACH,MAAM,EAAE,MAAM,CAAA;CACf;AAED,oBAAY,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,oBAAY,4BAA4B,GAAG,IAAI,CAC7C,cAAc,EACd,SAAS,GAAG,UAAU,CACvB,GACC,OAAO,CAAC,cAAc,CAAC,CAAA;AAEzB,oBAAY,sBAAsB,GAAG;IACnC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;IACjC,MAAM,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAA;CAClC,CAAA;AAED,MAAM,WAAW,aAAa;IAC5B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,aAAa,GAAG,SAAS,GAAG,mBAAmB,CAAA;CACtD;AAED,MAAM,WAA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"
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,wBAAwB,SAAgB,MAAM,GAAG,SAAS,kBA0BtE,CAAA;AAGD,eAAO,MAAM,cAAc,cAAqB,MAAM,GAAG,SAAS,kBAcjE,CAAA"}
|
package/lib/shared/validation.js
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.validateSchema = exports.validateConfigurationset = void 0;
|
|
5
|
+
const debug = require("debug");
|
|
5
6
|
const fs = require("fs");
|
|
6
7
|
const glob = require("glob");
|
|
7
8
|
const yaml = require("yaml");
|
|
8
9
|
// Validate the Configurationset file
|
|
9
10
|
const validateConfigurationset = async (file) => {
|
|
10
11
|
if (!file) {
|
|
12
|
+
debug('stepzen:sdk')(`validateConfigurationset() expected 'file' to be a` +
|
|
13
|
+
` non-empty string but got ${file}`);
|
|
11
14
|
throw new Error('You must provide a file path');
|
|
12
15
|
}
|
|
13
16
|
if (!fs.existsSync(file)) {
|
|
17
|
+
debug('stepzen:sdk')(`validateConfigurationset() expected ${file} to exist`);
|
|
14
18
|
throw new Error('The file does not exist');
|
|
15
19
|
}
|
|
16
20
|
const content = fs.readFileSync(file, 'utf8');
|
|
@@ -18,7 +22,9 @@ const validateConfigurationset = async (file) => {
|
|
|
18
22
|
try {
|
|
19
23
|
yaml.parse(content);
|
|
20
24
|
}
|
|
21
|
-
catch (
|
|
25
|
+
catch (error) {
|
|
26
|
+
debug('stepzen:sdk')(`validateConfigurationset() expected ${file} to parse as YAML,` +
|
|
27
|
+
` but got an error ${error}`);
|
|
22
28
|
throw new Error('The file is not valid YAML');
|
|
23
29
|
}
|
|
24
30
|
};
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/shared/validation.ts"],"names":[],"mappings":";AAAA,8CAA8C;;;AAE9C,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAE5B,qCAAqC;AAC9B,MAAM,wBAAwB,GAAG,KAAK,EAAE,IAAwB,EAAE,EAAE;IACzE,IAAI,CAAC,IAAI,EAAE;QACT,KAAK,CAAC,aAAa,CAAC,CAClB,oDAAoD;YAClD,6BAA6B,IAAI,EAAE,CACtC,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxB,KAAK,CAAC,aAAa,CAAC,CAAC,uCAAuC,IAAI,WAAW,CAAC,CAAA;QAC5E,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,OAAO,KAAK,EAAE;QACd,KAAK,CAAC,aAAa,CAAC,CAClB,uCAAuC,IAAI,oBAAoB;YAC7D,qBAAqB,KAAK,EAAE,CAC/B,CAAA;QACD,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;KAC9C;AACH,CAAC,CAAA;AA1BY,QAAA,wBAAwB,4BA0BpC;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.
|
|
3
|
+
"version": "0.21.0-beta.2",
|
|
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.
|
|
25
|
+
"@stepzen/transpiler": "^0.21.0-beta.2",
|
|
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": "
|
|
52
|
+
"gitHead": "58b85cc37fa990639bf7170d4224cf51cc1f7ad1"
|
|
52
53
|
}
|
package/src/client-v2.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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 listEndpointsCmd from './commands-v2/list'
|
|
6
|
+
import getPublicAccount from './commands-v2/getPublicAccount'
|
|
7
|
+
import {
|
|
8
|
+
generateConfigurationPayload,
|
|
9
|
+
generateSchemaFilesPayload,
|
|
10
|
+
} from './shared/payloads'
|
|
11
|
+
import {SDKConfigurationV2} from './shared/types'
|
|
12
|
+
|
|
13
|
+
export const ensureValidCredentials = async (
|
|
14
|
+
auth:
|
|
15
|
+
| {account: string; adminKey: string; deploymentType: string}
|
|
16
|
+
| {publicAccountToken: string; deploymentType: string},
|
|
17
|
+
sdkConfig: SDKConfigurationV2,
|
|
18
|
+
) => {
|
|
19
|
+
let credentials
|
|
20
|
+
|
|
21
|
+
if ('publicAccountToken' in auth) {
|
|
22
|
+
// create an anonymous account and use it to initialize an SDK client instance
|
|
23
|
+
const {data, error} = await getPublicAccount({
|
|
24
|
+
token: auth.publicAccountToken,
|
|
25
|
+
deploymentType: auth.deploymentType,
|
|
26
|
+
sdkConfig,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
if (error) {
|
|
30
|
+
throw new Error(`An unexpected error occurred: ${error.message}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
credentials = data
|
|
34
|
+
} else {
|
|
35
|
+
// use the provided account to initialize an SDK client instance
|
|
36
|
+
const {data, error} = await accountCmd({
|
|
37
|
+
account: auth.account,
|
|
38
|
+
adminKey: auth.adminKey,
|
|
39
|
+
deploymentType: auth.deploymentType,
|
|
40
|
+
sdkConfig,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (error) {
|
|
44
|
+
throw new Error(error.message)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
credentials = data
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return credentials
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const createSdkClient = async (
|
|
54
|
+
auth:
|
|
55
|
+
| {account: string; adminKey: string; deploymentType: string}
|
|
56
|
+
| {publicAccountToken: string; deploymentType: string},
|
|
57
|
+
sdkConfig: SDKConfigurationV2,
|
|
58
|
+
) => {
|
|
59
|
+
const credentials = await ensureValidCredentials(auth, sdkConfig)
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
get credentials(): typeof credentials {
|
|
63
|
+
// always return a copy to avoid accidential modification by the caller
|
|
64
|
+
return {...credentials}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Create or update a GraphQL endpoint at StepZen.
|
|
68
|
+
* The URL of the endpoint is formed as {StepZen instance URL}/{folder}/{name}/__graphql
|
|
69
|
+
* e.g. https://account.stepzen.net/api/users/__graphql
|
|
70
|
+
*
|
|
71
|
+
* @param folder - folder name (e.g. `api`); will be a part of the endpoint URL
|
|
72
|
+
* @param name - endpoint name (e.g. `users`); will be a part of the endpoint URL
|
|
73
|
+
* @param directory - full path to a GraphQL schema directory (should have `index.graphql` in it)
|
|
74
|
+
* @param config - full path to a config `.yml` file
|
|
75
|
+
* @param public - whether or not to allow public access to the endpoint (`false` by default)
|
|
76
|
+
* @returns details of the created / updated endpoint
|
|
77
|
+
*/
|
|
78
|
+
deploy: async ({
|
|
79
|
+
folder,
|
|
80
|
+
name,
|
|
81
|
+
directory,
|
|
82
|
+
config,
|
|
83
|
+
public: _public = false,
|
|
84
|
+
}: {
|
|
85
|
+
folder: string
|
|
86
|
+
name: string
|
|
87
|
+
directory: string
|
|
88
|
+
config?: string
|
|
89
|
+
public?: boolean
|
|
90
|
+
}) => {
|
|
91
|
+
return deployCmd({
|
|
92
|
+
account: credentials.account,
|
|
93
|
+
adminKey: credentials.adminKey,
|
|
94
|
+
deploymentType: credentials.deploymentType,
|
|
95
|
+
endpointName: name,
|
|
96
|
+
endpointType: 'dev',
|
|
97
|
+
folderName: folder,
|
|
98
|
+
public: _public,
|
|
99
|
+
schemaFiles: generateSchemaFilesPayload(directory),
|
|
100
|
+
configuration: await generateConfigurationPayload(config),
|
|
101
|
+
sdkConfig,
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
list: {
|
|
105
|
+
/**
|
|
106
|
+
* List deployed endpoints.
|
|
107
|
+
*
|
|
108
|
+
* @returns list of deployed endpoints
|
|
109
|
+
*/
|
|
110
|
+
endpoints: () => {
|
|
111
|
+
return listEndpointsCmd({
|
|
112
|
+
account: credentials.account,
|
|
113
|
+
adminKey: credentials.adminKey,
|
|
114
|
+
deploymentType: credentials.deploymentType,
|
|
115
|
+
sdkConfig,
|
|
116
|
+
})
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
}
|
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
|
|
22
|
-
let account
|
|
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
|
},
|
package/src/commands/upload.ts
CHANGED
|
@@ -26,13 +26,9 @@ export default async (
|
|
|
26
26
|
switch (details.type) {
|
|
27
27
|
case 'configurationset':
|
|
28
28
|
await validateConfigurationset(details.file)
|
|
29
|
-
const transpiled = await transpileConfigurationset(details.file)
|
|
30
|
-
debug('stepzen:
|
|
31
|
-
|
|
32
|
-
payload = await generateYamlPayload(transpiled)
|
|
33
|
-
} else {
|
|
34
|
-
payload = await generateYamlPayload(details.file)
|
|
35
|
-
}
|
|
29
|
+
const transpiled = await transpileConfigurationset(details.file!)
|
|
30
|
+
debug('stepzen:sdk')(`effective config written to ${transpiled}`)
|
|
31
|
+
payload = await generateYamlPayload(transpiled)
|
|
36
32
|
break
|
|
37
33
|
|
|
38
34
|
case 'schema':
|
|
@@ -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_api
|
|
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> | null
|
|
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,
|
|
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
|
+
}
|