@stepzen/sdk 0.9.35 → 0.9.39

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.
@@ -6,6 +6,7 @@ const node_fetch_1 = require("node-fetch");
6
6
  const constants_1 = require("../shared/constants");
7
7
  const payloads_1 = require("../shared/payloads");
8
8
  const request_1 = require("../shared/request");
9
+ const transpiling_1 = require("../shared/transpiling");
9
10
  const validation_1 = require("../shared/validation");
10
11
  exports.default = async (details, account) => {
11
12
  const headers = request_1.getRequestHeaders(account);
@@ -13,7 +14,14 @@ exports.default = async (details, account) => {
13
14
  switch (details.type) {
14
15
  case "configurationset":
15
16
  await validation_1.validateConfigurationset(details.file);
16
- payload = await payloads_1.generateYamlPayload(details.file);
17
+ const transpiled = await transpiling_1.transpileConfigurationset(details.file);
18
+ debug("stepzen:transpiler")(transpiled);
19
+ if (transpiled) {
20
+ payload = await payloads_1.generateYamlPayload(transpiled);
21
+ }
22
+ else {
23
+ payload = await payloads_1.generateYamlPayload(details.file);
24
+ }
17
25
  break;
18
26
  case "schema":
19
27
  await validation_1.validateSchema(details.directory);
@@ -9,6 +9,7 @@ const FormData = require("form-data");
9
9
  const fs = require("fs");
10
10
  const glob = require("glob");
11
11
  const os = require("os");
12
+ const path = require("path");
12
13
  // This function takes a (yaml) file path
13
14
  // and creates a FormData payload, containing the yaml content as 'yaml'
14
15
  const generateYamlPayload = async (file) => {
@@ -18,6 +19,8 @@ const generateYamlPayload = async (file) => {
18
19
  if (!fs.existsSync(file)) {
19
20
  reject(new Error(`File does not exist: ${file}`));
20
21
  }
22
+ const content = fs.readFileSync(file, 'utf8');
23
+ debug("stepzen:generate-yaml-payload")(content);
21
24
  payload.append("yaml", fs.readFileSync(file));
22
25
  resolve(payload);
23
26
  }
@@ -39,7 +42,7 @@ const generateZipPayload = async (directory, data, filters) => {
39
42
  }
40
43
  }
41
44
  // Store it in /tmp. Create a WriteStream
42
- const filepath = `${os.tmpdir()}/stepzen-payload-${Date.now()}.zip`;
45
+ const filepath = path.join(os.tmpdir(), `stepzen-payload-${Date.now()}.zip`);
43
46
  const output = fs.createWriteStream(filepath);
44
47
  // We're making a zip file
45
48
  const archive = archiver("zip", {
@@ -62,7 +65,7 @@ const generateZipPayload = async (directory, data, filters) => {
62
65
  const include = filters.some((filter) => file.match(filter));
63
66
  if (include) {
64
67
  debug("stepzen:archive")(file);
65
- archive.file(`${directory}/${file}`, { name: file });
68
+ archive.file(path.join(directory, file), { name: file });
66
69
  }
67
70
  });
68
71
  }
@@ -2,13 +2,15 @@
2
2
  // Copyright (c) 2020,2021, StepZen, Inc.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getRequestHeaders = void 0;
5
+ const os = require("os");
5
6
  const { version } = require("../../package.json");
6
7
  const getRequestHeaders = (settings) => {
8
+ const userAgent = `stepzen-cli/${version} ${os.platform()}/${os.arch()}/${os.release()}`;
7
9
  return {
8
10
  authorization: `Apikey ${settings.adminkey}`,
9
11
  host: `${settings.account}.${settings.domain}`,
10
12
  "stepzen-cli-version": version,
11
- "user-agent": `stepzen-cli/${version}`,
13
+ "user-agent": userAgent,
12
14
  };
13
15
  };
14
16
  exports.getRequestHeaders = getRequestHeaders;
@@ -1 +1 @@
1
- export declare const transpileConfig: (file: string | undefined) => string | undefined;
1
+ export declare const transpileConfigurationset: (file: string | undefined) => Promise<string | undefined>;
@@ -1,25 +1,29 @@
1
1
  "use strict";
2
2
  // Copyright (c) 2020,2021, StepZen, Inc.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.transpileConfig = void 0;
4
+ exports.transpileConfigurationset = void 0;
5
+ const dotenv = require("dotenv");
5
6
  const fs = require("fs-extra");
6
7
  const os = require("os");
7
- const { transpile } = require('@stepzen/transpiler');
8
- const transpileConfig = (file) => {
8
+ const path = require("path");
9
+ const { transpile } = require("@stepzen/transpiler");
10
+ const transpileConfigurationset = async (file) => {
9
11
  if (!file) {
10
12
  return;
11
13
  }
12
- const tmp = `${os.tmpdir()}/stepzen-transpiler-${Date.now()}`;
14
+ const source = file.substring(0, file.lastIndexOf("/"));
15
+ dotenv.config({ path: path.resolve(source, ".env") });
16
+ const tmp = path.join(os.tmpdir(), `stepzen-transpiler-${Date.now()}`);
17
+ const configPath = path.join(tmp, 'config.yaml');
13
18
  fs.ensureDirSync(tmp);
14
- fs.copyFileSync(file, `${tmp}/config.yaml`);
15
- fs.writeFileSync(`${tmp}/index.graphql`, '');
16
- const result = transpile(tmp);
19
+ fs.copyFileSync(file, configPath);
20
+ const result = await transpile(tmp);
17
21
  if (result.transpiled) {
18
22
  fs.emptyDirSync(tmp);
19
- fs.writeFileSync(`${tmp}/config.yaml`, result.config);
20
- return `${tmp}/config.yaml`;
23
+ fs.writeFileSync(configPath, result.config);
24
+ return configPath;
21
25
  }
22
26
  fs.removeSync(tmp);
23
27
  return;
24
28
  };
25
- exports.transpileConfig = transpileConfig;
29
+ exports.transpileConfigurationset = transpileConfigurationset;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stepzen/sdk",
3
- "version": "0.9.35",
3
+ "version": "0.9.39",
4
4
  "license": "MIT",
5
5
  "author": "Darren Waddell <darren@stepzen.com>",
6
6
  "homepage": "https://stepzen.com",
@@ -18,7 +18,7 @@
18
18
  "test": "tsc -b && nyc --extension .ts mocha --config test/mocha.opts.json"
19
19
  },
20
20
  "dependencies": {
21
- "@stepzen/transpiler": "0.0.23",
21
+ "@stepzen/transpiler": "0.0.24",
22
22
  "archiver": "^5.3.0",
23
23
  "debug": "^4.3.1",
24
24
  "form-data": "^4.0.0",