@takeshape/cli 9.80.4 → 9.81.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 (61) hide show
  1. package/dist/auth.js +2 -18
  2. package/dist/check-version.js +0 -6
  3. package/dist/commands/branch/commands/create.js +0 -11
  4. package/dist/commands/branch/commands/delete.js +0 -11
  5. package/dist/commands/branch/commands/list.js +0 -9
  6. package/dist/commands/branch/commands/merge.js +3 -29
  7. package/dist/commands/branch/commands/promote.js +0 -10
  8. package/dist/commands/branch/commands/tag-version.js +1 -10
  9. package/dist/commands/branch/commands/url.js +2 -17
  10. package/dist/commands/branch/index.js +0 -13
  11. package/dist/commands/build-or-watch.js +0 -18
  12. package/dist/commands/deploy/index.js +0 -18
  13. package/dist/commands/deploy/zip.js +0 -10
  14. package/dist/commands/export/index.js +0 -6
  15. package/dist/commands/export/project-export.js +1 -21
  16. package/dist/commands/export/schema-export.js +0 -21
  17. package/dist/commands/import/index.js +0 -9
  18. package/dist/commands/import/project-import.js +8 -45
  19. package/dist/commands/import/roles-import.js +0 -17
  20. package/dist/commands/import/schema-import.js +0 -23
  21. package/dist/commands/link.js +4 -19
  22. package/dist/commands/login.js +0 -8
  23. package/dist/commands/logout.js +0 -7
  24. package/dist/commands/schema.js +0 -7
  25. package/dist/commands/status.js +0 -5
  26. package/dist/commands/types.js +1 -6
  27. package/dist/commands/unlink.js +0 -7
  28. package/dist/commands/validate.js +0 -14
  29. package/dist/config.js +2 -31
  30. package/dist/deprecated.js +0 -3
  31. package/dist/errors.js +0 -7
  32. package/dist/files.js +0 -14
  33. package/dist/graphql.js +2 -19
  34. package/dist/index.js +0 -6
  35. package/dist/log.js +0 -3
  36. package/dist/main.js +0 -6
  37. package/dist/prompt.js +0 -5
  38. package/dist/types.js +0 -3
  39. package/dist/util/api.js +2 -18
  40. package/dist/util/branches.js +0 -16
  41. package/dist/util/cached-connector.js +0 -10
  42. package/dist/util/connector.js +2 -5
  43. package/dist/util/data.js +0 -16
  44. package/dist/util/fatal-error.js +0 -4
  45. package/dist/util/format-error.js +0 -1
  46. package/dist/util/format-validation-result.js +0 -2
  47. package/dist/util/fs.js +0 -8
  48. package/dist/util/generate-types.js +3 -15
  49. package/dist/util/get-client-schema.js +0 -8
  50. package/dist/util/glitch.js +0 -12
  51. package/dist/util/linked-command.js +0 -7
  52. package/dist/util/login.js +6 -30
  53. package/dist/util/messages.js +0 -10
  54. package/dist/util/ora-wrapper.js +0 -6
  55. package/dist/util/pusher.js +0 -5
  56. package/dist/util/runner.js +0 -8
  57. package/dist/util/select-project.js +0 -6
  58. package/dist/util/spin.js +0 -9
  59. package/dist/util/upload.js +0 -12
  60. package/dist/util/watcher.js +0 -5
  61. package/package.json +7 -7
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _log = _interopRequireDefault(require("../log"));
9
-
10
8
  var _types = require("../types");
11
-
12
9
  var _config = require("../config");
13
-
14
10
  var _data = require("../util/data");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  const unlink = async (_, params) => {
19
13
  try {
20
14
  if ((0, _types.isLoggedInAndLinkedConfig)(params)) {
@@ -25,6 +19,5 @@ const unlink = async (_, params) => {
25
19
  (0, _log.default)(e);
26
20
  }
27
21
  };
28
-
29
22
  var _default = unlink;
30
23
  exports.default = _default;
@@ -4,27 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
-
10
8
  var _log = _interopRequireDefault(require("../log"));
11
-
12
9
  var _fatalError = require("../util/fatal-error");
13
-
14
10
  var _path = _interopRequireDefault(require("path"));
15
-
16
11
  var _formatValidationResult = require("../util/format-validation-result");
17
-
18
12
  var _schema = require("@takeshape/schema");
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  const validate = async cli => {
23
15
  const {
24
16
  flags
25
17
  } = cli;
26
18
  let schemaPath;
27
-
28
19
  if (flags.path) {
29
20
  if (_fsExtra.default.existsSync(flags.path) && _fsExtra.default.statSync(flags.path).isDirectory()) {
30
21
  schemaPath = _path.default.join(flags.path, 'schema.json');
@@ -34,24 +25,19 @@ const validate = async cli => {
34
25
  } else {
35
26
  schemaPath = _path.default.join('.', 'schema.json');
36
27
  }
37
-
38
28
  if (!_fsExtra.default.existsSync(schemaPath)) {
39
29
  return (0, _fatalError.fatalError)(`${schemaPath} does not exist. You can download a project schema with 'takeshape export --schema'` + ` or specify a path with 'takeshape validate --path=/path/to/schema.json'`);
40
30
  }
41
-
42
31
  try {
43
32
  const schema = JSON.parse(_fsExtra.default.readFileSync(schemaPath).toString());
44
33
  const validationString = (0, _formatValidationResult.formatValidationResult)(await (0, _schema.validateSchema)({}, schema));
45
-
46
34
  if (validationString) {
47
35
  return (0, _fatalError.fatalError)(validationString);
48
36
  }
49
37
  } catch (e) {
50
38
  return (0, _fatalError.fatalError)(e.message);
51
39
  }
52
-
53
40
  (0, _log.default)(`${schemaPath} is valid.`);
54
41
  };
55
-
56
42
  var _default = validate;
57
43
  exports.default = _default;
package/dist/config.js CHANGED
@@ -10,56 +10,36 @@ exports.getHomeConfigPath = getHomeConfigPath;
10
10
  exports.loadConfig = loadConfig;
11
11
  exports.writeHomeConfig = writeHomeConfig;
12
12
  exports.writeLinkedProjectConfig = writeLinkedProjectConfig;
13
-
14
13
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
15
-
16
14
  var _path = _interopRequireDefault(require("path"));
17
-
18
15
  var _os = _interopRequireDefault(require("os"));
19
-
20
16
  var _isDocker = _interopRequireDefault(require("is-docker"));
21
-
22
17
  var _messages = require("./util/messages");
23
-
24
18
  var _graphql = require("./graphql");
25
-
26
19
  var _api = require("./util/api");
27
-
28
20
  var _connector = require("./util/connector");
29
-
30
21
  var _getClientSchema = _interopRequireDefault(require("./util/get-client-schema"));
31
-
32
22
  var _ignore = _interopRequireDefault(require("ignore"));
33
-
34
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
-
36
24
  const TAKESHAPE_CONFIG_FILENAME = '.takeshaperc';
37
25
  exports.TAKESHAPE_CONFIG_FILENAME = TAKESHAPE_CONFIG_FILENAME;
38
26
  const GRAPHQL_CONFIG_FILENAME = '.graphqlconfig';
39
27
  exports.GRAPHQL_CONFIG_FILENAME = GRAPHQL_CONFIG_FILENAME;
40
-
41
28
  function getHomeConfigPath() {
42
29
  return _path.default.join(_os.default.homedir(), TAKESHAPE_CONFIG_FILENAME);
43
30
  }
44
-
45
31
  function loadConfig(cwd, cli) {
46
32
  let config = {};
47
-
48
33
  const configPath = _path.default.join(cwd, TAKESHAPE_CONFIG_FILENAME);
49
-
50
34
  if (_fsExtra.default.existsSync(configPath)) {
51
35
  config = _fsExtra.default.readJsonSync(configPath);
52
36
  }
53
-
54
37
  const homeConfigPath = getHomeConfigPath();
55
-
56
38
  if (_fsExtra.default.existsSync(homeConfigPath)) {
57
39
  const homeConfig = _fsExtra.default.readJsonSync(homeConfigPath);
58
-
59
40
  config.authToken = homeConfig.accessToken;
60
41
  config.personalAccessTokenId = homeConfig.id;
61
42
  }
62
-
63
43
  return {
64
44
  buildPath: _path.default.join(cwd, cli.flags.output ?? 'build'),
65
45
  configFilePath: _path.default.join(cwd, cli.flags.file ?? 'tsg.yml'),
@@ -80,23 +60,18 @@ function loadConfig(cwd, cli) {
80
60
  watchContent: Boolean(cli.flags.watchContent)
81
61
  };
82
62
  }
83
-
84
63
  function gitignores(files) {
85
64
  if (_fsExtra.default.existsSync('.gitignore')) {
86
65
  const ig = (0, _ignore.default)().add(_fsExtra.default.readFileSync('.gitignore', 'utf8'));
87
66
  return ig.filter(files).length === 0;
88
67
  }
89
-
90
68
  return false;
91
69
  }
92
-
93
70
  async function writeLinkedProjectConfig(params, linkedApiKey, project, site) {
94
71
  (0, _messages.writingFilesMsg)();
95
-
96
72
  if (!gitignores([GRAPHQL_CONFIG_FILENAME, TAKESHAPE_CONFIG_FILENAME])) {
97
73
  (0, _messages.consoleWarning)();
98
74
  }
99
-
100
75
  const graphqlEndpoint = (0, _graphql.getGraphQLEndpoint)(params, project.value);
101
76
  const takeshaperc = {
102
77
  projectId: project.value,
@@ -127,7 +102,8 @@ async function writeLinkedProjectConfig(params, linkedApiKey, project, site) {
127
102
  }
128
103
  }
129
104
  };
130
- await Promise.all([_fsExtra.default.writeJSON(GRAPHQL_CONFIG_FILENAME, graphqlConfigJson), _fsExtra.default.writeJSON(TAKESHAPE_CONFIG_FILENAME, takeshaperc), (0, _getClientSchema.default)((0, _connector.createConnector)({ ...params,
105
+ await Promise.all([_fsExtra.default.writeJSON(GRAPHQL_CONFIG_FILENAME, graphqlConfigJson), _fsExtra.default.writeJSON(TAKESHAPE_CONFIG_FILENAME, takeshaperc), (0, _getClientSchema.default)((0, _connector.createConnector)({
106
+ ...params,
131
107
  ...takeshaperc
132
108
  }, {
133
109
  environment: 'PRODUCTION'
@@ -135,26 +111,21 @@ async function writeLinkedProjectConfig(params, linkedApiKey, project, site) {
135
111
  cache: false
136
112
  }))]);
137
113
  }
138
-
139
114
  function deleteLinkedConfig() {
140
115
  if (_fsExtra.default.existsSync(GRAPHQL_CONFIG_FILENAME)) {
141
116
  _fsExtra.default.removeSync(GRAPHQL_CONFIG_FILENAME);
142
117
  }
143
-
144
118
  if (_fsExtra.default.existsSync(TAKESHAPE_CONFIG_FILENAME)) {
145
119
  _fsExtra.default.removeSync(TAKESHAPE_CONFIG_FILENAME);
146
120
  }
147
121
  }
148
-
149
122
  async function writeHomeConfig(accessToken) {
150
123
  const configPath = getHomeConfigPath();
151
124
  await _fsExtra.default.writeJSON(configPath, accessToken);
152
125
  (0, _messages.writingHomeConfigDoneMsg)(configPath);
153
126
  }
154
-
155
127
  function deleteHomeConfig() {
156
128
  const homeConfigPath = getHomeConfigPath();
157
-
158
129
  if (_fsExtra.default.existsSync(homeConfigPath)) {
159
130
  _fsExtra.default.removeSync(homeConfigPath);
160
131
  }
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _log = _interopRequireDefault(require("./log"));
4
-
5
4
  var _chalk = _interopRequireDefault(require("chalk"));
6
-
7
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
6
  (0, _log.default)(`${_chalk.default.red('Error:')} The "tsg" command has been deprecated. Use "takeshape" instead`);
package/dist/errors.js CHANGED
@@ -6,31 +6,24 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.HTTPError = void 0;
7
7
  exports.formatErrorMessage = formatErrorMessage;
8
8
  exports.handleHttpErrors = handleHttpErrors;
9
-
10
9
  class HTTPError extends Error {
11
10
  constructor(message, statusCode) {
12
11
  super(message);
13
12
  this.statusCode = statusCode;
14
13
  }
15
-
16
14
  }
17
-
18
15
  exports.HTTPError = HTTPError;
19
-
20
16
  function formatErrorMessage(error, activity) {
21
17
  if ('statusCode' in error) {
22
18
  if (error.statusCode === 401 || error.statusCode === 403) {
23
19
  return new Error('Insufficient Permissions to develop with TakeShape CLI. Your account must have the "Admin" role or better.');
24
20
  }
25
-
26
21
  if (error.statusCode === 500) {
27
22
  return new Error(`A Server error occurred while ${activity}.`);
28
23
  }
29
24
  }
30
-
31
25
  return error;
32
26
  }
33
-
34
27
  function handleHttpErrors(error, activity) {
35
28
  throw formatErrorMessage(error, activity);
36
29
  }
package/dist/files.js CHANGED
@@ -6,50 +6,36 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.copyStatic = copyStatic;
7
7
  exports.syncStatic = syncStatic;
8
8
  exports.writePages = writePages;
9
-
10
9
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
-
12
10
  var _path = _interopRequireDefault(require("path"));
13
-
14
11
  var _bluebird = _interopRequireDefault(require("bluebird"));
15
-
16
12
  var _log = _interopRequireDefault(require("./log"));
17
-
18
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
14
  async function copyStatic(config) {
21
15
  return _fsExtra.default.mkdirs(config.buildPath).then(async () => _fsExtra.default.copy(config.staticPath, config.buildPath, {
22
16
  preserveTimestamps: true
23
17
  }));
24
18
  }
25
-
26
19
  function syncStatic(config) {
27
20
  return (event, sourcePath) => {
28
21
  const relativePath = sourcePath.replace(config.staticPath, '');
29
-
30
22
  const destPath = _path.default.join(config.buildPath, relativePath);
31
-
32
23
  if (event === 'addDir') {
33
24
  (0, _log.default)('takeshape watch - copied ' + relativePath);
34
-
35
25
  _fsExtra.default.mkdirs(destPath);
36
26
  } else if (event === 'unlink' || event === 'unlinkDir') {
37
27
  (0, _log.default)('takeshape watch - deleted ' + relativePath);
38
-
39
28
  _fsExtra.default.remove(destPath);
40
29
  } else {
41
30
  (0, _log.default)('takeshape watch - copied ' + relativePath);
42
-
43
31
  _fsExtra.default.copy(sourcePath, destPath);
44
32
  }
45
33
  };
46
34
  }
47
-
48
35
  function writePages(outputPath) {
49
36
  return generated => {
50
37
  return _bluebird.default.map(generated.pages, async page => {
51
38
  const filePath = _path.default.join(outputPath, page.path);
52
-
53
39
  return _fsExtra.default.mkdirs(_path.default.dirname(filePath)).then(async () => _fsExtra.default.writeFile(filePath, page.contents, 'utf8'));
54
40
  }).then(() => generated.stats);
55
41
  };
package/dist/graphql.js CHANGED
@@ -5,21 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getGraphQLEndpoint = exports.getGraphQLAdminEndpoint = exports.createConnectorFactory = exports.createConnector = exports.createAdminConnector = void 0;
7
7
  exports.graphQLQuery = graphQLQuery;
8
-
9
8
  var _branches = require("@takeshape/branches");
10
-
11
9
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
12
-
13
10
  var _asyncRetry = _interopRequireDefault(require("async-retry"));
14
-
15
11
  var _errors = require("./errors");
16
-
17
12
  var _api = require("./util/api");
18
-
19
13
  var _branches2 = require("./util/branches");
20
-
21
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
-
23
15
  const getGraphQLEndpointFactory = (path, useBranch) => (params, pathParams) => {
24
16
  const projectId = typeof pathParams === 'object' ? pathParams.projectId : pathParams;
25
17
  const branchParams = typeof pathParams === 'object' ? pathParams : {
@@ -28,7 +20,6 @@ const getGraphQLEndpointFactory = (path, useBranch) => (params, pathParams) => {
28
20
  const basePath = projectId ? useBranch ? (0, _branches2.getBranchBasePath)(branchParams, projectId) : `/project/${projectId}` : '';
29
21
  return `${params.endpoint}${basePath}${path}`;
30
22
  };
31
-
32
23
  const getGraphQLEndpoint = getGraphQLEndpointFactory('/graphql', true);
33
24
  exports.getGraphQLEndpoint = getGraphQLEndpoint;
34
25
  const getGraphQLAdminEndpoint = getGraphQLEndpointFactory('/admin-graphql', false);
@@ -37,7 +28,6 @@ const defaultOptions = {
37
28
  retries: 3,
38
29
  timeout: 0
39
30
  };
40
-
41
31
  const createConnectorFactory = getGraphQLEndpoint => (params, authToken, pathParams, options) => {
42
32
  const endpoint = getGraphQLEndpoint(params, pathParams ?? {
43
33
  environment: _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM
@@ -46,7 +36,8 @@ const createConnectorFactory = getGraphQLEndpoint => (params, authToken, pathPar
46
36
  const {
47
37
  timeout,
48
38
  retries
49
- } = { ...defaultOptions,
39
+ } = {
40
+ ...defaultOptions,
50
41
  ...options
51
42
  };
52
43
  return async params => (0, _asyncRetry.default)(async bail => {
@@ -60,31 +51,25 @@ const createConnectorFactory = getGraphQLEndpoint => (params, authToken, pathPar
60
51
  }
61
52
  });
62
53
  const body = await res.json();
63
-
64
54
  if (res.ok) {
65
55
  return body;
66
56
  }
67
-
68
57
  const error = new _errors.HTTPError(`${res.statusText}: ${body.message}`, res.status);
69
-
70
58
  if (res.status === 401 || res.status === 403) {
71
59
  // Bail to stop retrying
72
60
  bail(error);
73
61
  return;
74
62
  }
75
-
76
63
  throw error;
77
64
  }, {
78
65
  retries
79
66
  });
80
67
  };
81
-
82
68
  exports.createConnectorFactory = createConnectorFactory;
83
69
  const createConnector = createConnectorFactory(getGraphQLEndpoint);
84
70
  exports.createConnector = createConnector;
85
71
  const createAdminConnector = createConnectorFactory(getGraphQLAdminEndpoint);
86
72
  exports.createAdminConnector = createAdminConnector;
87
-
88
73
  function graphQLQuery(query) {
89
74
  return async (client, variables) => {
90
75
  const {
@@ -94,11 +79,9 @@ function graphQLQuery(query) {
94
79
  query,
95
80
  variables
96
81
  });
97
-
98
82
  if (errors) {
99
83
  throw new Error(errors.map(error => error.message).join(', '));
100
84
  }
101
-
102
85
  return data.result;
103
86
  };
104
87
  }
package/dist/index.js CHANGED
@@ -2,17 +2,11 @@
2
2
  "use strict";
3
3
 
4
4
  var _meow = _interopRequireDefault(require("meow"));
5
-
6
5
  var _main = _interopRequireDefault(require("./main"));
7
-
8
6
  var _config = require("./config");
9
-
10
7
  var _checkVersion = require("./check-version");
11
-
12
8
  var _options = require("./options");
13
-
14
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
10
  const help = `
17
11
  Usage
18
12
  $ takeshape <comand>
package/dist/log.js CHANGED
@@ -6,16 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  exports.log = log;
8
8
  exports.logError = logError;
9
-
10
9
  function log(...args) {
11
10
  // eslint-disable-next-line no-console
12
11
  console.log.apply(null, args);
13
12
  }
14
-
15
13
  function logError(...args) {
16
14
  // eslint-disable-next-line no-console
17
15
  console.error.apply(null, args);
18
16
  }
19
-
20
17
  var _default = log;
21
18
  exports.default = _default;
package/dist/main.js CHANGED
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = _default;
7
-
8
7
  var _log = _interopRequireDefault(require("./log"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  const commandPath = {
13
10
  build: 'build-or-watch',
14
11
  watch: 'build-or-watch',
@@ -25,14 +22,11 @@ const commandPath = {
25
22
  validate: 'validate',
26
23
  branch: 'branch'
27
24
  };
28
-
29
25
  async function _default(cli, params) {
30
26
  const command = cli.input[0];
31
27
  const path = commandPath[command];
32
-
33
28
  if (path) {
34
29
  const fn = require(`./commands/${path}`).default;
35
-
36
30
  await fn(cli, params);
37
31
  } else {
38
32
  (0, _log.default)('No such command:' + cli.help);
package/dist/prompt.js CHANGED
@@ -6,15 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.confirm = confirm;
7
7
  exports.prompt = prompt;
8
8
  exports.promptList = promptList;
9
-
10
9
  var _inquirer = _interopRequireDefault(require("inquirer"));
11
-
12
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
11
  function prompt(options) {
15
12
  return _inquirer.default.prompt(options);
16
13
  }
17
-
18
14
  async function confirm(message) {
19
15
  const {
20
16
  isConfirmed
@@ -25,7 +21,6 @@ async function confirm(message) {
25
21
  });
26
22
  return isConfirmed;
27
23
  }
28
-
29
24
  async function promptList(message, choices) {
30
25
  const {
31
26
  id
package/dist/types.js CHANGED
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isLinkedCliConfig = isLinkedCliConfig;
7
7
  exports.isLoggedInAndLinkedConfig = isLoggedInAndLinkedConfig;
8
8
  exports.isLoggedInCliConfig = isLoggedInCliConfig;
9
-
10
9
  function isLinkedCliConfig(cliConfig) {
11
10
  return cliConfig.projectId !== undefined && cliConfig.linkedApiKey !== undefined;
12
11
  }
13
-
14
12
  function isLoggedInCliConfig(cliConfig) {
15
13
  return cliConfig.authToken !== undefined;
16
14
  }
17
-
18
15
  function isLoggedInAndLinkedConfig(cliConfig) {
19
16
  return isLinkedCliConfig(cliConfig) && isLoggedInCliConfig(cliConfig);
20
17
  }
package/dist/util/api.js CHANGED
@@ -6,16 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = api;
7
7
  exports.getAuthHeader = getAuthHeader;
8
8
  exports.isJWT = isJWT;
9
-
10
9
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
11
-
12
10
  var _errors = require("../errors");
13
-
14
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
12
  function isValidHeader(str) {
17
13
  const json = Buffer.from(str, 'base64').toString('utf8');
18
-
19
14
  try {
20
15
  const header = JSON.parse(json);
21
16
  return header.typ === 'JWT';
@@ -23,54 +18,43 @@ function isValidHeader(str) {
23
18
  return false;
24
19
  }
25
20
  }
26
-
27
21
  function isJWT(str) {
28
22
  const parts = str.split('.');
29
23
  return parts.length === 3 && isValidHeader(parts[0]);
30
24
  }
31
-
32
25
  function getAuthHeader(authToken) {
33
26
  if (!authToken) {
34
27
  return {};
35
28
  }
36
-
37
29
  return isJWT(authToken) ? {
38
30
  'X-TakeShape-Token': authToken
39
31
  } : {
40
32
  Authorization: `Bearer ${authToken}`
41
33
  };
42
34
  }
43
-
44
35
  async function api(params, method, path, body) {
45
36
  var _params$linkedApiKey;
46
-
47
37
  const requestParams = {
48
38
  method,
49
- headers: { ...getAuthHeader(params.authToken ?? ((_params$linkedApiKey = params.linkedApiKey) === null || _params$linkedApiKey === void 0 ? void 0 : _params$linkedApiKey.apiKey)),
39
+ headers: {
40
+ ...getAuthHeader(params.authToken ?? ((_params$linkedApiKey = params.linkedApiKey) === null || _params$linkedApiKey === void 0 ? void 0 : _params$linkedApiKey.apiKey)),
50
41
  'Content-Type': 'application/json'
51
42
  }
52
43
  };
53
-
54
44
  if (body) {
55
45
  requestParams.body = JSON.stringify(body);
56
46
  }
57
-
58
47
  const endpoint = `${params.endpoint}${path}`;
59
48
  const res = await (0, _nodeFetch.default)(endpoint, requestParams);
60
-
61
49
  if (res.ok) {
62
50
  const contentLengthHeader = res.headers.get('content-length');
63
-
64
51
  if (contentLengthHeader !== null) {
65
52
  const contentLength = parseInt(contentLengthHeader, 10);
66
-
67
53
  if (contentLength === 0) {
68
54
  return;
69
55
  }
70
56
  }
71
-
72
57
  return res.json();
73
58
  }
74
-
75
59
  throw new _errors.HTTPError(`${res.statusText}`, res.status);
76
60
  }
@@ -8,66 +8,50 @@ exports.getBranchBasePath = getBranchBasePath;
8
8
  exports.getBranchParams = getBranchParams;
9
9
  exports.getEnvironment = getEnvironment;
10
10
  exports.isEnvironment = isEnvironment;
11
-
12
11
  var _fatalError = require("./fatal-error");
13
-
14
12
  var _compact = _interopRequireDefault(require("lodash/compact"));
15
-
16
13
  var _branches = require("@takeshape/branches");
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
15
  function getEnvironment(cli, flag = 'branch') {
21
16
  if (cli.flags.production) {
22
17
  return _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM;
23
18
  }
24
-
25
19
  if (cli.flags.development) {
26
20
  return _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM;
27
21
  }
28
-
29
22
  if (cli.flags.scratch) {
30
23
  return _branches.BRANCH_ENVIRONMENT_SCRATCH_ENUM;
31
24
  }
32
-
33
25
  return cli.flags[flag] ? _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM : _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM;
34
26
  }
35
-
36
27
  function isEnvironment(environment) {
37
28
  return [_branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM, _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM, _branches.BRANCH_ENVIRONMENT_SCRATCH_ENUM].includes(environment);
38
29
  }
39
-
40
30
  function getBranchArgs(name) {
41
31
  if (name === _branches.BRANCH_ENVIRONMENT_PRODUCTION) {
42
32
  return {
43
33
  environment: _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM
44
34
  };
45
35
  }
46
-
47
36
  return {
48
37
  environment: _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM,
49
38
  branchName: name
50
39
  };
51
40
  }
52
-
53
41
  function getBranchParams(cli, flag = 'branch') {
54
42
  const branch = cli.flags[flag];
55
43
  const environment = getEnvironment(cli, flag);
56
-
57
44
  if (environment === _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM && branch) {
58
45
  return (0, _fatalError.fatalError)('There is only one production branch --name is invalid');
59
46
  }
60
-
61
47
  if (environment === _branches.BRANCH_ENVIRONMENT_DEVELOPMENT_ENUM && !branch) {
62
48
  return (0, _fatalError.fatalError)('Development branches require a name, please specify one with --name');
63
49
  }
64
-
65
50
  return {
66
51
  branch,
67
52
  environment
68
53
  };
69
54
  }
70
-
71
55
  function getBranchBasePath({
72
56
  environment,
73
57
  branch
@@ -4,31 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.connectorWithCache = connectorWithCache;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
-
12
9
  var _objectHash = _interopRequireDefault(require("object-hash"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  const cacheDir = '.cache';
17
-
18
12
  function connectorWithCache(connector) {
19
13
  const decorated = async params => {
20
14
  const cachePath = _path.default.join(cacheDir, `${(0, _objectHash.default)(params)}.json`);
21
-
22
15
  if (await _fsExtra.default.pathExists(cachePath)) {
23
16
  return _fsExtra.default.readJSON(cachePath);
24
17
  }
25
-
26
18
  const [result] = await Promise.all([connector(params), _fsExtra.default.mkdirs(cacheDir)]);
27
19
  await _fsExtra.default.writeJSON(cachePath, result);
28
20
  return result;
29
21
  };
30
-
31
22
  decorated.clearCache = async () => _fsExtra.default.remove(cacheDir);
32
-
33
23
  return decorated;
34
24
  }
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createConnector = createConnector;
7
-
8
7
  var _ssg = require("@takeshape/ssg");
9
-
10
8
  var _graphql = require("../graphql");
11
-
12
9
  var _cachedConnector = require("./cached-connector");
13
-
14
10
  function createConnector(params, branchParams, options) {
15
- const connector = (0, _ssg.connectorWithMigrations)((0, _graphql.createConnector)(params, params.linkedApiKey.apiKey, { ...branchParams,
11
+ const connector = (0, _ssg.connectorWithMigrations)((0, _graphql.createConnector)(params, params.linkedApiKey.apiKey, {
12
+ ...branchParams,
16
13
  projectId: params.projectId
17
14
  }, options));
18
15
  return options !== null && options !== void 0 && options.cache ? (0, _cachedConnector.connectorWithCache)(connector) : connector;