@stepzen/sdk 0.28.0-beta.2 → 0.28.0-beta.4
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/commands/upload.d.ts.map +1 -1
- package/lib/commands/upload.js +9 -2
- package/lib/commands/upload.js.map +1 -1
- package/lib/shared/payloads.d.ts.map +1 -1
- package/lib/shared/payloads.js +14 -4
- package/lib/shared/payloads.js.map +1 -1
- package/lib/shared/rmtemp.d.ts +11 -0
- package/lib/shared/rmtemp.d.ts.map +1 -0
- package/lib/shared/rmtemp.js +43 -0
- package/lib/shared/rmtemp.js.map +1 -0
- package/lib/shared/transpiling.d.ts.map +1 -1
- package/lib/shared/transpiling.js +14 -6
- package/lib/shared/transpiling.js.map +1 -1
- package/package.json +5 -4
- package/src/commands/upload.ts +8 -2
- package/src/shared/payloads.ts +14 -4
- package/src/shared/rmtemp.ts +48 -0
- package/src/shared/transpiling.ts +13 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"AASA,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAA;kCAMb,aAAa,WACb,cAAc,aACZ,gBAAgB,KAC1B,QAAQ,cAAc,CAAC;AAJ1B,wBA6EC"}
|
package/lib/commands/upload.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const debug = require("debug");
|
|
5
|
+
const path = require("path");
|
|
5
6
|
const fetch_1 = require("@stepzen/fetch");
|
|
6
7
|
const constants_1 = require("../shared/constants");
|
|
7
8
|
const payloads_1 = require("../shared/payloads");
|
|
8
9
|
const request_1 = require("../shared/request");
|
|
9
10
|
const transpiling_1 = require("../shared/transpiling");
|
|
10
11
|
const validation_1 = require("../shared/validation");
|
|
12
|
+
const rmtemp_1 = require("../shared/rmtemp");
|
|
11
13
|
exports.default = async (details, account, sdkConfig) => {
|
|
12
14
|
const headers = (0, request_1.getRequestHeaders)(account, sdkConfig);
|
|
13
15
|
let payload;
|
|
@@ -15,8 +17,13 @@ exports.default = async (details, account, sdkConfig) => {
|
|
|
15
17
|
case 'configurationset':
|
|
16
18
|
await (0, validation_1.validateConfigurationset)(details.file);
|
|
17
19
|
const transpiled = await (0, transpiling_1.transpileConfigurationset)(details.file);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
try {
|
|
21
|
+
debug('stepzen:sdk')(`effective config written to ${transpiled}`);
|
|
22
|
+
payload = await (0, payloads_1.generateYamlPayload)(transpiled);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
(0, rmtemp_1.rmtemp)(path.dirname(transpiled));
|
|
26
|
+
}
|
|
20
27
|
break;
|
|
21
28
|
case 'schema':
|
|
22
29
|
await (0, validation_1.validateSchema)(details.directory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":";AAAA,mDAAmD;;AAEnD,+BAA8B;AAC9B,0CAAkC;AAElC,mDAAoD;AACpD,iDAA0E;AAC1E,+CAAmD;AAOnD,uDAA+D;AAC/D,qDAA6E;
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":";AAAA,mDAAmD;;AAEnD,+BAA8B;AAC9B,6BAA4B;AAC5B,0CAAkC;AAElC,mDAAoD;AACpD,iDAA0E;AAC1E,+CAAmD;AAOnD,uDAA+D;AAC/D,qDAA6E;AAC7E,6CAAuC;AAEvC,kBAAe,KAAK,EAClB,OAAsB,EACtB,OAAuB,EACvB,SAA2B,EACF,E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,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,EAAE;QACnD,OAAO;YACL,OAAO,EACL,uFAAuF;YACzF,OAAO,EAAE,KAAK;SACf,CAAA;KACF;IAED,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE;QAC1B,OAAO;YACL,MAAM,EAAE,CAAC,uBAAuB,CAAC;YACjC,OAAO,EAAE,QAAQ,CAAC,UAAU;YAC5B,OAAO,EAAE,KAAK;SACf,CAAA;KACF;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IAClC,IAAI,IAAI,CAAA;IAER,IAAI;QACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KACxB;IAAC,MAAM;QACN,OAAO;YACL,MAAM,EAAE,CAAC,oCAAoC,IAAI,EAAE,CAAC;YACpD,OAAO,EAAE,oCAAoC,IAAI,EAAE;YACnD,OAAO,EAAE,KAAK;SACf,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payloads.d.ts","sourceRoot":"","sources":["../../src/shared/payloads.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAA;AAQrC,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"payloads.d.ts","sourceRoot":"","sources":["../../src/shared/payloads.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAA;AAQrC,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,SAAS,CAAA;AAGlD,aAAK,WAAW,GAAG,QAAQ,CAAA;AAC3B,aAAK,UAAU,GAAG,QAAQ,CAAA;AAI1B,eAAO,MAAM,mBAAmB,SACxB,MAAM,GAAG,SAAS,KACvB,QAAQ,WAAW,CAgBrB,CAAA;AAKD,eAAO,MAAM,kBAAkB,cAClB,MAAM,GAAG,SAAS,QACvB,MAAM,GAAG,SAAS,WACf,MAAM,EAAE,KAChB,QAAQ,UAAU,CAiEpB,CAAA;AAED,eAAO,MAAM,0BAA0B,wBAChB,MAAM,KAC1B,WA0BF,CAAA;AAED,eAAO,MAAM,4BAA4B,oBACtB,MAAM,KACtB,QAAQ,aAAa,GAAG,IAAI,CAc9B,CAAA"}
|
package/lib/shared/payloads.js
CHANGED
|
@@ -13,6 +13,7 @@ const path = require("path");
|
|
|
13
13
|
const yaml = require("yaml");
|
|
14
14
|
const transpiling_1 = require("./transpiling");
|
|
15
15
|
const validation_1 = require("./validation");
|
|
16
|
+
const rmtemp_1 = require("./rmtemp");
|
|
16
17
|
// This function takes a (yaml) file path
|
|
17
18
|
// and creates a FormData payload, containing the yaml content as 'yaml'
|
|
18
19
|
const generateYamlPayload = async (file) => {
|
|
@@ -46,11 +47,15 @@ const generateZipPayload = async (directory, data, filters) => {
|
|
|
46
47
|
}
|
|
47
48
|
// Store it in /tmp. Create a WriteStream
|
|
48
49
|
const filepath = path.join(os.tmpdir(), `stepzen-payload-${Date.now()}.zip`);
|
|
49
|
-
const output = fs.createWriteStream(filepath);
|
|
50
|
+
const output = fs.createWriteStream(filepath, { mode: 0o600 });
|
|
50
51
|
// We're making a zip file
|
|
51
52
|
const archive = archiver('zip', {
|
|
52
53
|
zlib: { level: 9 },
|
|
53
54
|
});
|
|
55
|
+
archive.on('error', error => {
|
|
56
|
+
fs.unlinkSync(filepath);
|
|
57
|
+
reject(error);
|
|
58
|
+
});
|
|
54
59
|
// We're piping it to the WriteStream
|
|
55
60
|
archive.pipe(output);
|
|
56
61
|
// If we've specified a directory, add it to the archive
|
|
@@ -115,9 +120,14 @@ const generateConfigurationPayload = async (configFilePath) => {
|
|
|
115
120
|
}
|
|
116
121
|
await (0, validation_1.validateConfigurationset)(configFilePath);
|
|
117
122
|
const transpiled = await (0, transpiling_1.transpileConfigurationset)(configFilePath);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
try {
|
|
124
|
+
debug('stepzen:sdk')(`effective config written to ${transpiled}`);
|
|
125
|
+
const content = fs.readFileSync(transpiled, 'utf-8');
|
|
126
|
+
return yaml.parse(content, { schema: 'failsafe' }) || null;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
(0, rmtemp_1.rmtemp)(path.dirname(transpiled));
|
|
130
|
+
}
|
|
121
131
|
};
|
|
122
132
|
exports.generateConfigurationPayload = generateConfigurationPayload;
|
|
123
133
|
//# sourceMappingURL=payloads.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payloads.js","sourceRoot":"","sources":["../../src/shared/payloads.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,0DAA0D;AAE1D,qCAAoC;AACpC,+BAA8B;AAC9B,sCAAqC;AACrC,yBAAwB;AACxB,6BAA4B;AAC5B,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAC5B,+CAAuD;AACvD,6CAAqD;
|
|
1
|
+
{"version":3,"file":"payloads.js","sourceRoot":"","sources":["../../src/shared/payloads.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,0DAA0D;AAE1D,qCAAoC;AACpC,+BAA8B;AAC9B,sCAAqC;AACrC,yBAAwB;AACxB,6BAA4B;AAC5B,yBAAwB;AACxB,6BAA4B;AAC5B,6BAA4B;AAC5B,+CAAuD;AACvD,6CAAqD;AAErD,qCAA+B;AAK/B,yCAAyC;AACzC,wEAAwE;AACjE,MAAM,mBAAmB,GAAG,KAAK,EACtC,IAAwB,EACF,EAAE;IACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,OAAO,GAAG,IAAI,QAAQ,EAAE,CAAA;QAE9B,IAAI,IAAI,EAAE;YACR,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;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AA;KACZ;IAED,MAAM,IAAA,qCAAwB,EAAC,cAAc,CAAC,CAAA;IAC9C,MAAM,UAAU,GAAG,MAAM,IAAA,uCAAyB,EAAC,cAAc,CAAC,CAAA;IAClE,IAAI;QACF,KAAK,CAAC,aAAa,CAAC,CAAC,+BAA+B,UAAU,EAAE,CAAC,CAAA;QACjE,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAC,MAAM,EAAE,UAAU,EAAC,CAAC,IAAI,IAAI,CAAA;KACzD;YAAS;QACR,IAAA,eAAM,EAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;KACjC;AACH,CAAC,CAAA;AAhBY,QAAA,4BAA4B,gCAgBxC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify that the given path is indeed inside the tmp folder,
|
|
3
|
+
* and delete it recursively suppressing any errors.
|
|
4
|
+
*
|
|
5
|
+
* If the given path is not inside the tmp folder, do nothing.
|
|
6
|
+
*
|
|
7
|
+
* @param {*} fileOrDirPath path to a temp file or folder to delete
|
|
8
|
+
*/
|
|
9
|
+
export declare const rmtemp: (fileOrDirPath?: string) => void;
|
|
10
|
+
export default rmtemp;
|
|
11
|
+
//# sourceMappingURL=rmtemp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rmtemp.d.ts","sourceRoot":"","sources":["../../src/shared/rmtemp.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,mBAAoB,MAAM,SAyB5C,CAAA;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.rmtemp = void 0;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const debug = require("debug");
|
|
9
|
+
// ----------------------------------------------------------------------------
|
|
10
|
+
// THIS ENTIRE FILE IS COPIED FROM packages/cli/src/shared/rmtemp.ts
|
|
11
|
+
// (because there is no effective way to share util classes between packages yet)
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
/**
|
|
14
|
+
* Verify that the given path is indeed inside the tmp folder,
|
|
15
|
+
* and delete it recursively suppressing any errors.
|
|
16
|
+
*
|
|
17
|
+
* If the given path is not inside the tmp folder, do nothing.
|
|
18
|
+
*
|
|
19
|
+
* @param {*} fileOrDirPath path to a temp file or folder to delete
|
|
20
|
+
*/
|
|
21
|
+
const rmtemp = (fileOrDirPath) => {
|
|
22
|
+
if (!fileOrDirPath) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// https://stackoverflow.com/a/45242825
|
|
26
|
+
const relative = path.relative(os.tmpdir(), fileOrDirPath);
|
|
27
|
+
const isInTemp = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
28
|
+
if (isInTemp) {
|
|
29
|
+
try {
|
|
30
|
+
fs.rmSync(fileOrDirPath, { recursive: true, force: true });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
// ignore errors
|
|
34
|
+
debug('stepzen:rmtemp')(`WARN: caught an exception while deleting ${fileOrDirPath}: `, error);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
debug('stepzen:rmtemp')(`WARN: got a temp path ${fileOrDirPath} out of the TMP folder -- ignoring`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.rmtemp = rmtemp;
|
|
42
|
+
exports.default = exports.rmtemp;
|
|
43
|
+
//# sourceMappingURL=rmtemp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rmtemp.js","sourceRoot":"","sources":["../../src/shared/rmtemp.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,yBAAwB;AACxB,6BAA4B;AAC5B,yBAAwB;AACxB,+BAA8B;AAE9B,+EAA+E;AAC/E,yEAAyE;AACzE,iFAAiF;AACjF,+EAA+E;AAE/E;;;;;;;GAOG;AACI,MAAM,MAAM,GAAG,CAAC,aAAsB,EAAE,EAAE;IAC/C,IAAI,CAAC,aAAa,EAAE;QAClB,OAAM;KACP;IAED,uCAAuC;IACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,aAAa,CAAC,CAAA;IAC1D,MAAM,QAAQ,GACZ,QAAQ,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IAEtE,IAAI,QAAQ,EAAE;QACZ,IAAI;YACF,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,CAAA;SACzD;QAAC,OAAO,KAAK,EAAE;YACd,gBAAgB;YAChB,KAAK,CAAC,gBAAgB,CAAC,CACrB,4CAA4C,aAAa,IAAI,EAC7D,KAAK,CACN,CAAA;SACF;KACF;SAAM;QACL,KAAK,CAAC,gBAAgB,CAAC,CACrB,yBAAyB,aAAa,oCAAoC,CAC3E,CAAA;KACF;AACH,CAAC,CAAA;AAzBY,QAAA,MAAM,UAyBlB;AAED,kBAAe,cAAM,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpiling.d.ts","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transpiling.d.ts","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,SAAS,CAAC,CAAA;AAErE;;;;;;;;GAQG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -8,6 +8,7 @@ const fsx = require("fs-extra");
|
|
|
8
8
|
const os = require("os");
|
|
9
9
|
const path = require("path");
|
|
10
10
|
const transpiler_1 = require("@stepzen/transpiler");
|
|
11
|
+
const rmtemp_1 = require("./rmtemp");
|
|
11
12
|
async function transpileConfigurationset(file) {
|
|
12
13
|
if (!file) {
|
|
13
14
|
return;
|
|
@@ -18,12 +19,19 @@ async function transpileConfigurationset(file) {
|
|
|
18
19
|
dotenv.config({ path: path.resolve(source, '.env') });
|
|
19
20
|
const tmp = path.join(os.tmpdir(), `stepzen-transpiler-${Date.now()}`);
|
|
20
21
|
const configPath = path.join(tmp, 'config.yaml');
|
|
21
|
-
fsx.ensureDirSync(tmp);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
fsx.ensureDirSync(tmp, 0o700);
|
|
23
|
+
try {
|
|
24
|
+
fsx.copyFileSync(file, configPath);
|
|
25
|
+
fsx.chmodSync(configPath, 0o600);
|
|
26
|
+
const result = await (0, transpiler_1.transpile)(tmp);
|
|
27
|
+
fsx.emptyDirSync(tmp);
|
|
28
|
+
fsx.writeFileSync(configPath, result.config || '', { mode: 0o600 });
|
|
29
|
+
return configPath;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
(0, rmtemp_1.rmtemp)(tmp);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
exports.transpileConfigurationset = transpileConfigurationset;
|
|
29
37
|
//# sourceMappingURL=transpiling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpiling.js","sourceRoot":"","sources":["../../src/shared/transpiling.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,iCAAgC;AA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G,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAA;QACjE,OAAO,UAAU,CAAA;KAClB;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,eAAM,EAAC,GAAG,CAAC,CAAA;QACX,MAAM,KAAK,CAAA;KACZ;AACH,CAAC;AA7BD,8DA6BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stepzen/sdk",
|
|
3
|
-
"version": "0.28.0-beta.
|
|
3
|
+
"version": "0.28.0-beta.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Darren Waddell <darren@stepzen.com>",
|
|
6
6
|
"homepage": "https://stepzen.com",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"posttest": "prettier . --check"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@stepzen/fetch": "0.28.0-beta.
|
|
26
|
-
"@stepzen/transpiler": "0.28.0-beta.
|
|
25
|
+
"@stepzen/fetch": "0.28.0-beta.4",
|
|
26
|
+
"@stepzen/transpiler": "0.28.0-beta.4",
|
|
27
27
|
"archiver": "^5.3.0",
|
|
28
28
|
"debug": "^4.3.4",
|
|
29
29
|
"dotenv": "^16.0.3",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@types/glob": "^7.2.0",
|
|
42
42
|
"@types/license-checker": "^25.0.1",
|
|
43
43
|
"@types/mocha": "^8.2.2",
|
|
44
|
+
"@types/node": "^14.18.36",
|
|
44
45
|
"@types/node-fetch": "^2.6.2",
|
|
45
46
|
"chai": "^4.3.4",
|
|
46
47
|
"fancy-test": "^1.4.10",
|
|
@@ -50,5 +51,5 @@
|
|
|
50
51
|
"prettier": "^2.8.3",
|
|
51
52
|
"ts-node": "^10.8.2"
|
|
52
53
|
},
|
|
53
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "4f145daa32cad0b126a49c960055258462dc9056"
|
|
54
55
|
}
|
package/src/commands/upload.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
2
2
|
|
|
3
3
|
import * as debug from 'debug'
|
|
4
|
+
import * as path from 'path'
|
|
4
5
|
import fetch from '@stepzen/fetch'
|
|
5
6
|
|
|
6
7
|
import {ADMIN_UPLOAD_URL} from '../shared/constants'
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
} from '../shared/types'
|
|
15
16
|
import {transpileConfigurationset} from '../shared/transpiling'
|
|
16
17
|
import {validateConfigurationset, validateSchema} from '../shared/validation'
|
|
18
|
+
import {rmtemp} from '../shared/rmtemp'
|
|
17
19
|
|
|
18
20
|
export default async (
|
|
19
21
|
details: StepZenUpload,
|
|
@@ -27,8 +29,12 @@ export default async (
|
|
|
27
29
|
case 'configurationset':
|
|
28
30
|
await validateConfigurationset(details.file)
|
|
29
31
|
const transpiled = await transpileConfigurationset(details.file!)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
try {
|
|
33
|
+
debug('stepzen:sdk')(`effective config written to ${transpiled}`)
|
|
34
|
+
payload = await generateYamlPayload(transpiled)
|
|
35
|
+
} finally {
|
|
36
|
+
rmtemp(path.dirname(transpiled))
|
|
37
|
+
}
|
|
32
38
|
break
|
|
33
39
|
|
|
34
40
|
case 'schema':
|
package/src/shared/payloads.ts
CHANGED
|
@@ -13,6 +13,7 @@ import * as yaml from 'yaml'
|
|
|
13
13
|
import {transpileConfigurationset} from './transpiling'
|
|
14
14
|
import {validateConfigurationset} from './validation'
|
|
15
15
|
import {Configuration, SchemaFiles} from './types'
|
|
16
|
+
import {rmtemp} from './rmtemp'
|
|
16
17
|
|
|
17
18
|
type YamlPayload = FormData
|
|
18
19
|
type ZipPayload = FormData
|
|
@@ -58,13 +59,18 @@ export const generateZipPayload = async (
|
|
|
58
59
|
|
|
59
60
|
// Store it in /tmp. Create a WriteStream
|
|
60
61
|
const filepath = path.join(os.tmpdir(), `stepzen-payload-${Date.now()}.zip`)
|
|
61
|
-
const output = fs.createWriteStream(filepath)
|
|
62
|
+
const output = fs.createWriteStream(filepath, {mode: 0o600})
|
|
62
63
|
|
|
63
64
|
// We're making a zip file
|
|
64
65
|
const archive = archiver('zip', {
|
|
65
66
|
zlib: {level: 9},
|
|
66
67
|
})
|
|
67
68
|
|
|
69
|
+
archive.on('error', error => {
|
|
70
|
+
fs.unlinkSync(filepath)
|
|
71
|
+
reject(error)
|
|
72
|
+
})
|
|
73
|
+
|
|
68
74
|
// We're piping it to the WriteStream
|
|
69
75
|
archive.pipe(output)
|
|
70
76
|
|
|
@@ -147,7 +153,11 @@ export const generateConfigurationPayload = async (
|
|
|
147
153
|
|
|
148
154
|
await validateConfigurationset(configFilePath)
|
|
149
155
|
const transpiled = await transpileConfigurationset(configFilePath)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
try {
|
|
157
|
+
debug('stepzen:sdk')(`effective config written to ${transpiled}`)
|
|
158
|
+
const content = fs.readFileSync(transpiled, 'utf-8')
|
|
159
|
+
return yaml.parse(content, {schema: 'failsafe'}) || null
|
|
160
|
+
} finally {
|
|
161
|
+
rmtemp(path.dirname(transpiled))
|
|
162
|
+
}
|
|
153
163
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
2
|
+
|
|
3
|
+
import * as fs from 'fs'
|
|
4
|
+
import * as path from 'path'
|
|
5
|
+
import * as os from 'os'
|
|
6
|
+
import * as debug from 'debug'
|
|
7
|
+
|
|
8
|
+
// ----------------------------------------------------------------------------
|
|
9
|
+
// THIS ENTIRE FILE IS COPIED FROM packages/cli/src/shared/rmtemp.ts
|
|
10
|
+
// (because there is no effective way to share util classes between packages yet)
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Verify that the given path is indeed inside the tmp folder,
|
|
15
|
+
* and delete it recursively suppressing any errors.
|
|
16
|
+
*
|
|
17
|
+
* If the given path is not inside the tmp folder, do nothing.
|
|
18
|
+
*
|
|
19
|
+
* @param {*} fileOrDirPath path to a temp file or folder to delete
|
|
20
|
+
*/
|
|
21
|
+
export const rmtemp = (fileOrDirPath?: string) => {
|
|
22
|
+
if (!fileOrDirPath) {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// https://stackoverflow.com/a/45242825
|
|
27
|
+
const relative = path.relative(os.tmpdir(), fileOrDirPath)
|
|
28
|
+
const isInTemp =
|
|
29
|
+
relative && !relative.startsWith('..') && !path.isAbsolute(relative)
|
|
30
|
+
|
|
31
|
+
if (isInTemp) {
|
|
32
|
+
try {
|
|
33
|
+
fs.rmSync(fileOrDirPath, {recursive: true, force: true})
|
|
34
|
+
} catch (error) {
|
|
35
|
+
// ignore errors
|
|
36
|
+
debug('stepzen:rmtemp')(
|
|
37
|
+
`WARN: caught an exception while deleting ${fileOrDirPath}: `,
|
|
38
|
+
error,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
debug('stepzen:rmtemp')(
|
|
43
|
+
`WARN: got a temp path ${fileOrDirPath} out of the TMP folder -- ignoring`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default rmtemp
|
|
@@ -6,6 +6,7 @@ import * as fsx from 'fs-extra'
|
|
|
6
6
|
import * as os from 'os'
|
|
7
7
|
import * as path from 'path'
|
|
8
8
|
import {transpile} from '@stepzen/transpiler'
|
|
9
|
+
import {rmtemp} from './rmtemp'
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @returns `undefined` when called without arguments
|
|
@@ -38,12 +39,18 @@ export async function transpileConfigurationset(file?: string) {
|
|
|
38
39
|
const tmp = path.join(os.tmpdir(), `stepzen-transpiler-${Date.now()}`)
|
|
39
40
|
const configPath = path.join(tmp, 'config.yaml')
|
|
40
41
|
|
|
41
|
-
fsx.ensureDirSync(tmp)
|
|
42
|
-
|
|
42
|
+
fsx.ensureDirSync(tmp, 0o700)
|
|
43
|
+
try {
|
|
44
|
+
fsx.copyFileSync(file, configPath)
|
|
45
|
+
fsx.chmodSync(configPath, 0o600)
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
const result = await transpile(tmp)
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
fsx.emptyDirSync(tmp)
|
|
50
|
+
fsx.writeFileSync(configPath, result.config || '', {mode: 0o600})
|
|
51
|
+
return configPath
|
|
52
|
+
} catch (error) {
|
|
53
|
+
rmtemp(tmp)
|
|
54
|
+
throw error
|
|
55
|
+
}
|
|
49
56
|
}
|