@takeshape/cli 9.14.0 → 9.14.1

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 (184) hide show
  1. package/dist/auth.d.ts +5 -0
  2. package/dist/auth.d.ts.map +1 -0
  3. package/dist/auth.js +76 -0
  4. package/dist/check-version.d.ts +2 -0
  5. package/dist/check-version.d.ts.map +1 -0
  6. package/dist/check-version.js +22 -0
  7. package/dist/commands/branch/commands/create.d.ts +2 -0
  8. package/dist/commands/branch/commands/create.d.ts.map +1 -0
  9. package/dist/commands/branch/commands/create.js +67 -0
  10. package/dist/commands/branch/commands/delete.d.ts +2 -0
  11. package/dist/commands/branch/commands/delete.d.ts.map +1 -0
  12. package/dist/commands/branch/commands/delete.js +58 -0
  13. package/dist/commands/branch/commands/list.d.ts +12 -0
  14. package/dist/commands/branch/commands/list.d.ts.map +1 -0
  15. package/dist/commands/branch/commands/list.js +54 -0
  16. package/dist/commands/branch/commands/merge.d.ts +2 -0
  17. package/dist/commands/branch/commands/merge.d.ts.map +1 -0
  18. package/dist/commands/branch/commands/merge.js +158 -0
  19. package/dist/commands/branch/commands/promote.d.ts +2 -0
  20. package/dist/commands/branch/commands/promote.d.ts.map +1 -0
  21. package/dist/commands/branch/commands/promote.js +50 -0
  22. package/dist/commands/branch/commands/tag-version.d.ts +2 -0
  23. package/dist/commands/branch/commands/tag-version.d.ts.map +1 -0
  24. package/dist/commands/branch/commands/tag-version.js +59 -0
  25. package/dist/commands/branch/commands/url.d.ts +3 -0
  26. package/dist/commands/branch/commands/url.d.ts.map +1 -0
  27. package/dist/commands/branch/commands/url.js +84 -0
  28. package/dist/commands/branch/index.d.ts +4 -0
  29. package/dist/commands/branch/index.d.ts.map +1 -0
  30. package/dist/commands/branch/index.js +47 -0
  31. package/dist/commands/build-or-watch.d.ts +4 -0
  32. package/dist/commands/build-or-watch.d.ts.map +1 -0
  33. package/dist/commands/build-or-watch.js +73 -0
  34. package/dist/commands/deploy/index.d.ts +9 -0
  35. package/dist/commands/deploy/index.d.ts.map +1 -0
  36. package/dist/commands/deploy/index.js +74 -0
  37. package/dist/commands/deploy/zip.d.ts +18 -0
  38. package/dist/commands/deploy/zip.d.ts.map +1 -0
  39. package/dist/commands/deploy/zip.js +57 -0
  40. package/dist/commands/export/index.d.ts +4 -0
  41. package/dist/commands/export/index.d.ts.map +1 -0
  42. package/dist/commands/export/index.js +23 -0
  43. package/dist/commands/export/project-export.d.ts +8 -0
  44. package/dist/commands/export/project-export.d.ts.map +1 -0
  45. package/dist/commands/export/project-export.js +109 -0
  46. package/dist/commands/export/schema-export.d.ts +3 -0
  47. package/dist/commands/export/schema-export.d.ts.map +1 -0
  48. package/dist/commands/export/schema-export.js +88 -0
  49. package/dist/commands/import/index.d.ts +4 -0
  50. package/dist/commands/import/index.d.ts.map +1 -0
  51. package/dist/commands/import/index.js +33 -0
  52. package/dist/commands/import/project-import.d.ts +11 -0
  53. package/dist/commands/import/project-import.d.ts.map +1 -0
  54. package/dist/commands/import/project-import.js +198 -0
  55. package/dist/commands/import/roles-import.d.ts +3 -0
  56. package/dist/commands/import/roles-import.d.ts.map +1 -0
  57. package/dist/commands/import/roles-import.js +59 -0
  58. package/dist/commands/import/schema-import.d.ts +3 -0
  59. package/dist/commands/import/schema-import.d.ts.map +1 -0
  60. package/dist/commands/import/schema-import.js +93 -0
  61. package/dist/commands/link.d.ts +3 -0
  62. package/dist/commands/link.d.ts.map +1 -0
  63. package/dist/commands/link.js +63 -0
  64. package/dist/commands/login.d.ts +4 -0
  65. package/dist/commands/login.d.ts.map +1 -0
  66. package/dist/commands/login.js +32 -0
  67. package/dist/commands/logout.d.ts +4 -0
  68. package/dist/commands/logout.d.ts.map +1 -0
  69. package/dist/commands/logout.js +30 -0
  70. package/dist/commands/schema.d.ts +3 -0
  71. package/dist/commands/schema.d.ts.map +1 -0
  72. package/dist/commands/schema.js +25 -0
  73. package/dist/commands/status.d.ts +3 -0
  74. package/dist/commands/status.d.ts.map +1 -0
  75. package/dist/commands/status.js +18 -0
  76. package/dist/commands/types.d.ts +3 -0
  77. package/dist/commands/types.d.ts.map +1 -0
  78. package/dist/commands/types.js +30 -0
  79. package/dist/commands/unlink.d.ts +4 -0
  80. package/dist/commands/unlink.d.ts.map +1 -0
  81. package/dist/commands/unlink.js +30 -0
  82. package/dist/commands/validate.d.ts +4 -0
  83. package/dist/commands/validate.d.ts.map +1 -0
  84. package/dist/commands/validate.js +57 -0
  85. package/dist/config.d.ts +13 -0
  86. package/dist/config.d.ts.map +1 -0
  87. package/dist/config.js +161 -0
  88. package/dist/deprecated.d.ts +2 -0
  89. package/dist/deprecated.d.ts.map +1 -0
  90. package/dist/deprecated.js +9 -0
  91. package/dist/errors.d.ts +7 -0
  92. package/dist/errors.d.ts.map +1 -0
  93. package/dist/errors.js +36 -0
  94. package/dist/files.d.ts +4 -0
  95. package/dist/files.d.ts.map +1 -0
  96. package/dist/files.js +56 -0
  97. package/dist/graphql.d.ts +22 -0
  98. package/dist/graphql.d.ts.map +1 -0
  99. package/dist/graphql.js +104 -0
  100. package/dist/index.d.ts +3 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +128 -0
  103. package/dist/log.d.ts +4 -0
  104. package/dist/log.d.ts.map +1 -0
  105. package/dist/log.js +21 -0
  106. package/dist/main.d.ts +2 -0
  107. package/dist/main.d.ts.map +1 -0
  108. package/dist/main.js +40 -0
  109. package/dist/options.d.ts +102 -0
  110. package/dist/options.d.ts.map +1 -0
  111. package/dist/options.js +103 -0
  112. package/dist/prompt.d.ts +11 -0
  113. package/dist/prompt.d.ts.map +1 -0
  114. package/dist/prompt.js +39 -0
  115. package/dist/types.d.ts +47 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +20 -0
  118. package/dist/util/api.d.ts +5 -0
  119. package/dist/util/api.d.ts.map +1 -0
  120. package/dist/util/api.js +76 -0
  121. package/dist/util/branches.d.ts +18 -0
  122. package/dist/util/branches.d.ts.map +1 -0
  123. package/dist/util/branches.js +77 -0
  124. package/dist/util/cached-connector.d.ts +5 -0
  125. package/dist/util/cached-connector.d.ts.map +1 -0
  126. package/dist/util/cached-connector.js +34 -0
  127. package/dist/util/connector.d.ts +8 -0
  128. package/dist/util/connector.d.ts.map +1 -0
  129. package/dist/util/connector.js +19 -0
  130. package/dist/util/data.d.ts +39 -0
  131. package/dist/util/data.d.ts.map +1 -0
  132. package/dist/util/data.js +165 -0
  133. package/dist/util/fatal-error.d.ts +2 -0
  134. package/dist/util/fatal-error.d.ts.map +1 -0
  135. package/dist/util/fatal-error.js +17 -0
  136. package/dist/util/format-error.d.ts +2 -0
  137. package/dist/util/format-error.d.ts.map +1 -0
  138. package/dist/util/format-error.js +10 -0
  139. package/dist/util/format-validation-result.d.ts +3 -0
  140. package/dist/util/format-validation-result.d.ts.map +1 -0
  141. package/dist/util/format-validation-result.js +17 -0
  142. package/dist/util/fs.d.ts +5 -0
  143. package/dist/util/fs.d.ts.map +1 -0
  144. package/dist/util/fs.js +42 -0
  145. package/dist/util/generate-types.d.ts +5 -0
  146. package/dist/util/generate-types.d.ts.map +1 -0
  147. package/dist/util/generate-types.js +63 -0
  148. package/dist/util/get-client-schema.d.ts +5 -0
  149. package/dist/util/get-client-schema.d.ts.map +1 -0
  150. package/dist/util/get-client-schema.js +31 -0
  151. package/dist/util/glitch.d.ts +5 -0
  152. package/dist/util/glitch.d.ts.map +1 -0
  153. package/dist/util/glitch.js +51 -0
  154. package/dist/util/linked-command.d.ts +5 -0
  155. package/dist/util/linked-command.d.ts.map +1 -0
  156. package/dist/util/linked-command.js +48 -0
  157. package/dist/util/login.d.ts +21 -0
  158. package/dist/util/login.d.ts.map +1 -0
  159. package/dist/util/login.js +141 -0
  160. package/dist/util/messages.d.ts +13 -0
  161. package/dist/util/messages.d.ts.map +1 -0
  162. package/dist/util/messages.js +60 -0
  163. package/dist/util/ora-wrapper.d.ts +2 -0
  164. package/dist/util/ora-wrapper.d.ts.map +1 -0
  165. package/dist/util/ora-wrapper.js +28 -0
  166. package/dist/util/pusher.d.ts +10 -0
  167. package/dist/util/pusher.d.ts.map +1 -0
  168. package/dist/util/pusher.js +34 -0
  169. package/dist/util/runner.d.ts +2 -0
  170. package/dist/util/runner.d.ts.map +1 -0
  171. package/dist/util/runner.js +46 -0
  172. package/dist/util/select-project.d.ts +4 -0
  173. package/dist/util/select-project.d.ts.map +1 -0
  174. package/dist/util/select-project.js +23 -0
  175. package/dist/util/spin.d.ts +7 -0
  176. package/dist/util/spin.d.ts.map +1 -0
  177. package/dist/util/spin.js +41 -0
  178. package/dist/util/upload.d.ts +5 -0
  179. package/dist/util/upload.d.ts.map +1 -0
  180. package/dist/util/upload.js +55 -0
  181. package/dist/util/watcher.d.ts +2 -0
  182. package/dist/util/watcher.d.ts.map +1 -0
  183. package/dist/util/watcher.js +30 -0
  184. package/package.json +8 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unlink.d.ts","sourceRoot":"","sources":["../../../src/commands/unlink.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAA4B,MAAM,UAAU,CAAC;AAI5D,QAAA,MAAM,MAAM,EAAE,OASb,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _log = _interopRequireDefault(require("../log"));
9
+
10
+ var _types = require("../types");
11
+
12
+ var _config = require("../config");
13
+
14
+ var _data = require("../util/data");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const unlink = async (_, params) => {
19
+ try {
20
+ if ((0, _types.isLoggedInAndLinkedConfig)(params)) {
21
+ await (0, _data.deleteApiKey)(params, params.projectId, params.linkedApiKey.id);
22
+ (0, _config.deleteLinkedConfig)();
23
+ }
24
+ } catch (e) {
25
+ (0, _log.default)(e);
26
+ }
27
+ };
28
+
29
+ var _default = unlink;
30
+ exports.default = _default;
@@ -0,0 +1,4 @@
1
+ import { Handler } from '../types';
2
+ declare const validate: Handler;
3
+ export default validate;
4
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/commands/validate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AAEjC,QAAA,MAAM,QAAQ,EAAE,OA+Bf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+
10
+ var _log = _interopRequireDefault(require("../log"));
11
+
12
+ var _fatalError = require("../util/fatal-error");
13
+
14
+ var _path = _interopRequireDefault(require("path"));
15
+
16
+ var _formatValidationResult = require("../util/format-validation-result");
17
+
18
+ var _schema = require("@takeshape/schema");
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const validate = async cli => {
23
+ const {
24
+ flags
25
+ } = cli;
26
+ let schemaPath;
27
+
28
+ if (flags.path) {
29
+ if (_fsExtra.default.existsSync(flags.path) && _fsExtra.default.statSync(flags.path).isDirectory()) {
30
+ schemaPath = _path.default.join(flags.path, 'schema.json');
31
+ } else {
32
+ schemaPath = flags.path;
33
+ }
34
+ } else {
35
+ schemaPath = _path.default.join('.', 'schema.json');
36
+ }
37
+
38
+ if (!_fsExtra.default.existsSync(schemaPath)) {
39
+ 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
+ }
41
+
42
+ try {
43
+ const schema = JSON.parse(_fsExtra.default.readFileSync(schemaPath).toString());
44
+ const validationString = (0, _formatValidationResult.formatValidationResult)((0, _schema.validateSchema)(schema));
45
+
46
+ if (validationString) {
47
+ return (0, _fatalError.fatalError)(validationString);
48
+ }
49
+ } catch (e) {
50
+ return (0, _fatalError.fatalError)(e.message);
51
+ }
52
+
53
+ (0, _log.default)(`${schemaPath} is valid.`);
54
+ };
55
+
56
+ var _default = validate;
57
+ exports.default = _default;
@@ -0,0 +1,13 @@
1
+ import { CliConfig } from './types';
2
+ import { Choice } from './prompt';
3
+ import { ApiKey, PersonalAccessToken } from './util/data';
4
+ import meow, { AnyFlags } from 'meow';
5
+ export declare const TAKESHAPE_CONFIG_FILENAME = ".takeshaperc";
6
+ export declare const GRAPHQL_CONFIG_FILENAME = ".graphqlconfig";
7
+ export declare function getHomeConfigPath(): string;
8
+ export declare function loadConfig(cwd: string, cli: meow.Result<AnyFlags>): CliConfig;
9
+ export declare function writeLinkedProjectConfig(params: CliConfig, linkedApiKey: ApiKey, project: Choice, site: Choice | undefined): Promise<void>;
10
+ export declare function deleteLinkedConfig(): void;
11
+ export declare function writeHomeConfig(accessToken: PersonalAccessToken): Promise<void>;
12
+ export declare function deleteHomeConfig(): void;
13
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAOlC,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,MAAM,EAAE,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAExD,OAAO,IAAI,EAAE,EAAC,QAAQ,EAAC,MAAM,MAAM,CAAC;AAEpC,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AACxD,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CA8B7E;AAWD,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,OAAO,CAAC,IAAI,CAAC,CA6Cf;AAED,wBAAgB,kBAAkB,SAQjC;AAED,wBAAsB,eAAe,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAED,wBAAgB,gBAAgB,SAK/B"}
package/dist/config.js ADDED
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TAKESHAPE_CONFIG_FILENAME = exports.GRAPHQL_CONFIG_FILENAME = void 0;
7
+ exports.deleteHomeConfig = deleteHomeConfig;
8
+ exports.deleteLinkedConfig = deleteLinkedConfig;
9
+ exports.getHomeConfigPath = getHomeConfigPath;
10
+ exports.loadConfig = loadConfig;
11
+ exports.writeHomeConfig = writeHomeConfig;
12
+ exports.writeLinkedProjectConfig = writeLinkedProjectConfig;
13
+
14
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
15
+
16
+ var _path = _interopRequireDefault(require("path"));
17
+
18
+ var _os = _interopRequireDefault(require("os"));
19
+
20
+ var _isDocker = _interopRequireDefault(require("is-docker"));
21
+
22
+ var _messages = require("./util/messages");
23
+
24
+ var _graphql = require("./graphql");
25
+
26
+ var _api = require("./util/api");
27
+
28
+ var _connector = require("./util/connector");
29
+
30
+ var _getClientSchema = _interopRequireDefault(require("./util/get-client-schema"));
31
+
32
+ var _ignore = _interopRequireDefault(require("ignore"));
33
+
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+
36
+ const TAKESHAPE_CONFIG_FILENAME = '.takeshaperc';
37
+ exports.TAKESHAPE_CONFIG_FILENAME = TAKESHAPE_CONFIG_FILENAME;
38
+ const GRAPHQL_CONFIG_FILENAME = '.graphqlconfig';
39
+ exports.GRAPHQL_CONFIG_FILENAME = GRAPHQL_CONFIG_FILENAME;
40
+
41
+ function getHomeConfigPath() {
42
+ return _path.default.join(_os.default.homedir(), TAKESHAPE_CONFIG_FILENAME);
43
+ }
44
+
45
+ function loadConfig(cwd, cli) {
46
+ let config = {};
47
+
48
+ const configPath = _path.default.join(cwd, TAKESHAPE_CONFIG_FILENAME);
49
+
50
+ if (_fsExtra.default.existsSync(configPath)) {
51
+ config = _fsExtra.default.readJsonSync(configPath);
52
+ }
53
+
54
+ const homeConfigPath = getHomeConfigPath();
55
+
56
+ if (_fsExtra.default.existsSync(homeConfigPath)) {
57
+ const homeConfig = _fsExtra.default.readJsonSync(homeConfigPath);
58
+
59
+ config.authToken = homeConfig.accessToken;
60
+ config.personalAccessTokenId = homeConfig.id;
61
+ }
62
+
63
+ return {
64
+ buildPath: _path.default.join(cwd, cli.flags.output ?? 'build'),
65
+ configFilePath: _path.default.join(cwd, cli.flags.file ?? 'tsg.yml'),
66
+ appUrl: process.env.TS_APP_URL ?? config.appUrl ?? 'https://app.takeshape.io',
67
+ endpoint: process.env.TS_API_ENDPOINT ?? config.endpoint ?? 'https://api.takeshape.io',
68
+ authToken: cli.flags.token ?? process.env.TS_AUTH_TOKEN ?? config.authToken,
69
+ personalAccessTokenId: config.personalAccessTokenId,
70
+ linkedApiKey: process.env.TS_API_KEY ? {
71
+ id: 'TS_API_KEY',
72
+ apiKey: process.env.TS_API_KEY
73
+ } : config.linkedApiKey,
74
+ cliLogin: Boolean(cli.flags.cliLogin) || (0, _isDocker.default)() || Boolean(process.env.GITHUB_ACTIONS),
75
+ siteId: cli.flags.site ?? process.env.TS_SITE_ID ?? config.siteId,
76
+ projectName: process.env.TS_PROJECT_NAME ?? config.projectName,
77
+ projectId: process.env.TS_PROJECT_ID ?? config.projectId,
78
+ siteName: process.env.TS_SITE_NAME ?? config.siteName,
79
+ cache: Boolean(cli.flags.cache),
80
+ watchContent: Boolean(cli.flags.watchContent)
81
+ };
82
+ }
83
+
84
+ function gitignores(files) {
85
+ if (_fsExtra.default.existsSync('.gitignore')) {
86
+ const ig = (0, _ignore.default)().add(_fsExtra.default.readFileSync('.gitignore', 'utf8'));
87
+ return ig.filter(files).length === 0;
88
+ }
89
+
90
+ return false;
91
+ }
92
+
93
+ async function writeLinkedProjectConfig(params, linkedApiKey, project, site) {
94
+ (0, _messages.writingFilesMsg)();
95
+
96
+ if (!gitignores([GRAPHQL_CONFIG_FILENAME, TAKESHAPE_CONFIG_FILENAME])) {
97
+ (0, _messages.consoleWarning)();
98
+ }
99
+
100
+ const graphqlEndpoint = (0, _graphql.getGraphQLEndpoint)(params, project.value);
101
+ const takeshaperc = {
102
+ projectId: project.value,
103
+ siteId: site === null || site === void 0 ? void 0 : site.value,
104
+ siteName: site === null || site === void 0 ? void 0 : site.name,
105
+ endpoint: params.endpoint,
106
+ appUrl: params.appUrl,
107
+ projectName: project.name,
108
+ linkedApiKey
109
+ };
110
+ const options = {
111
+ headers: {
112
+ 'Content-Type': 'application/json',
113
+ ...(0, _api.getAuthHeader)(linkedApiKey.apiKey)
114
+ },
115
+ introspect: true
116
+ };
117
+ const graphqlConfigJson = {
118
+ schemaPath: 'takeshape-project.graphql',
119
+ includes: ['**/*.graphql'],
120
+ excludes: ['node_modules/**/*.graphql'],
121
+ extensions: {
122
+ endpoints: {
123
+ TakeShape: {
124
+ url: graphqlEndpoint,
125
+ ...options
126
+ }
127
+ }
128
+ }
129
+ };
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,
131
+ ...takeshaperc
132
+ }, {
133
+ environment: 'PRODUCTION'
134
+ }, {
135
+ cache: false
136
+ }))]);
137
+ }
138
+
139
+ function deleteLinkedConfig() {
140
+ if (_fsExtra.default.existsSync(GRAPHQL_CONFIG_FILENAME)) {
141
+ _fsExtra.default.removeSync(GRAPHQL_CONFIG_FILENAME);
142
+ }
143
+
144
+ if (_fsExtra.default.existsSync(TAKESHAPE_CONFIG_FILENAME)) {
145
+ _fsExtra.default.removeSync(TAKESHAPE_CONFIG_FILENAME);
146
+ }
147
+ }
148
+
149
+ async function writeHomeConfig(accessToken) {
150
+ const configPath = getHomeConfigPath();
151
+ await _fsExtra.default.writeJSON(configPath, accessToken);
152
+ (0, _messages.writingHomeConfigDoneMsg)(configPath);
153
+ }
154
+
155
+ function deleteHomeConfig() {
156
+ const homeConfigPath = getHomeConfigPath();
157
+
158
+ if (_fsExtra.default.existsSync(homeConfigPath)) {
159
+ _fsExtra.default.removeSync(homeConfigPath);
160
+ }
161
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=deprecated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deprecated.d.ts","sourceRoot":"","sources":["../../src/deprecated.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ var _log = _interopRequireDefault(require("./log"));
4
+
5
+ var _chalk = _interopRequireDefault(require("chalk"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ (0, _log.default)(`${_chalk.default.red('Error:')} The "tsg" command has been deprecated. Use "takeshape" instead`);
@@ -0,0 +1,7 @@
1
+ export declare class HTTPError extends Error {
2
+ statusCode: number;
3
+ constructor(message: string, statusCode: number);
4
+ }
5
+ export declare function formatErrorMessage(error: Error | HTTPError, activity: string): Error;
6
+ export declare function handleHttpErrors(error: Error | HTTPError, activity: string): void;
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAC3B,UAAU,EAAE,MAAM,CAAC;gBACP,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAIvD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAcpF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAEjF"}
package/dist/errors.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HTTPError = void 0;
7
+ exports.formatErrorMessage = formatErrorMessage;
8
+ exports.handleHttpErrors = handleHttpErrors;
9
+
10
+ class HTTPError extends Error {
11
+ constructor(message, statusCode) {
12
+ super(message);
13
+ this.statusCode = statusCode;
14
+ }
15
+
16
+ }
17
+
18
+ exports.HTTPError = HTTPError;
19
+
20
+ function formatErrorMessage(error, activity) {
21
+ if ('statusCode' in error) {
22
+ if (error.statusCode === 401 || error.statusCode === 403) {
23
+ return new Error('Insufficient Permissions to develop with TakeShape CLI. Your account must have the "Admin" role or better.');
24
+ }
25
+
26
+ if (error.statusCode === 500) {
27
+ return new Error(`A Server error occurred while ${activity}.`);
28
+ }
29
+ }
30
+
31
+ return error;
32
+ }
33
+
34
+ function handleHttpErrors(error, activity) {
35
+ throw formatErrorMessage(error, activity);
36
+ }
@@ -0,0 +1,4 @@
1
+ export function copyStatic(config: any): Promise<void>;
2
+ export function syncStatic(config: any): (event: any, sourcePath: any) => void;
3
+ export function writePages(outputPath: any): (generated: any) => any;
4
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/files.js"],"names":[],"mappings":"AAKA,uDAIC;AAED,+EAgBC;AAED,qEAOC"}
package/dist/files.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.copyStatic = copyStatic;
7
+ exports.syncStatic = syncStatic;
8
+ exports.writePages = writePages;
9
+
10
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _bluebird = _interopRequireDefault(require("bluebird"));
15
+
16
+ var _log = _interopRequireDefault(require("./log"));
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ async function copyStatic(config) {
21
+ return _fsExtra.default.mkdirs(config.buildPath).then(async () => _fsExtra.default.copy(config.staticPath, config.buildPath, {
22
+ preserveTimestamps: true
23
+ }));
24
+ }
25
+
26
+ function syncStatic(config) {
27
+ return (event, sourcePath) => {
28
+ const relativePath = sourcePath.replace(config.staticPath, '');
29
+
30
+ const destPath = _path.default.join(config.buildPath, relativePath);
31
+
32
+ if (event === 'addDir') {
33
+ (0, _log.default)('takeshape watch - copied ' + relativePath);
34
+
35
+ _fsExtra.default.mkdirs(destPath);
36
+ } else if (event === 'unlink' || event === 'unlinkDir') {
37
+ (0, _log.default)('takeshape watch - deleted ' + relativePath);
38
+
39
+ _fsExtra.default.remove(destPath);
40
+ } else {
41
+ (0, _log.default)('takeshape watch - copied ' + relativePath);
42
+
43
+ _fsExtra.default.copy(sourcePath, destPath);
44
+ }
45
+ };
46
+ }
47
+
48
+ function writePages(outputPath) {
49
+ return generated => {
50
+ return _bluebird.default.map(generated.pages, async page => {
51
+ const filePath = _path.default.join(outputPath, page.path);
52
+
53
+ return _fsExtra.default.mkdirs(_path.default.dirname(filePath)).then(async () => _fsExtra.default.writeFile(filePath, page.contents, 'utf8'));
54
+ }).then(() => generated.stats);
55
+ };
56
+ }
@@ -0,0 +1,22 @@
1
+ import { Client, CliConfig } from './types';
2
+ import { BranchParams } from './util/branches';
3
+ export type PathParams = (BranchParams & {
4
+ projectId?: string;
5
+ }) | string | undefined;
6
+ export type ProjectPathParams = (PathParams & {
7
+ projectId: string;
8
+ }) | string;
9
+ export type GetGraphQLEndpoint = (params: CliConfig, pathParams: PathParams) => string;
10
+ export declare const getGraphQLEndpoint: GetGraphQLEndpoint;
11
+ export declare const getGraphQLAdminEndpoint: GetGraphQLEndpoint;
12
+ export interface GraphQLConnectorOptions {
13
+ retries?: number;
14
+ timeout?: number;
15
+ cache?: boolean;
16
+ branch?: BranchParams;
17
+ }
18
+ export declare const createConnectorFactory: (getGraphQLEndpoint: GetGraphQLEndpoint) => (params: CliConfig, authToken: string, pathParams?: PathParams, options?: GraphQLConnectorOptions) => Client;
19
+ export declare const createConnector: (params: CliConfig, authToken: string, pathParams?: PathParams, options?: GraphQLConnectorOptions) => Client;
20
+ export declare const createAdminConnector: (params: CliConfig, authToken: string, pathParams?: PathParams, options?: GraphQLConnectorOptions) => Client;
21
+ export declare function graphQLQuery<Variables extends Record<string, unknown>, Data>(query: string): (client: Client, variables: Variables) => Promise<Data>;
22
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/graphql.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAC,YAAY,EAAoB,MAAM,iBAAiB,CAAC;AAEhE,MAAM,MAAM,UAAU,GAClB,CAAC,YAAY,GAAG;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,GACF,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,MAAM,iBAAiB,GACzB,CAAC,UAAU,GAAG;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,GACF,MAAM,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC;AAgBvF,eAAO,MAAM,kBAAkB,oBAA8C,CAAC;AAC9E,eAAO,MAAM,uBAAuB,oBAAqD,CAAC;AAE1F,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;AAOD,eAAO,MAAM,sBAAsB,uBACZ,kBAAkB,cAC9B,SAAS,aAAa,MAAM,eAAe,UAAU,YAAY,uBAAuB,KAAG,MAkCnG,CAAC;AAEJ,eAAO,MAAM,eAAe,WApCjB,SAAS,aAAa,MAAM,eAAe,UAAU,YAAY,uBAAuB,KAAG,MAoC7B,CAAC;AAC1E,eAAO,MAAM,oBAAoB,WArCtB,SAAS,aAAa,MAAM,eAAe,UAAU,YAAY,uBAAuB,KAAG,MAqCnB,CAAC;AAEpF,wBAAgB,YAAY,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YACnE,MAAM,aAAa,SAAS,KAAG,QAAQ,IAAI,CAAC,CAQnE"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getGraphQLEndpoint = exports.getGraphQLAdminEndpoint = exports.createConnectorFactory = exports.createConnector = exports.createAdminConnector = void 0;
7
+ exports.graphQLQuery = graphQLQuery;
8
+
9
+ var _branches = require("@takeshape/branches");
10
+
11
+ var _nodeFetch = _interopRequireDefault(require("node-fetch"));
12
+
13
+ var _asyncRetry = _interopRequireDefault(require("async-retry"));
14
+
15
+ var _errors = require("./errors");
16
+
17
+ var _api = require("./util/api");
18
+
19
+ var _branches2 = require("./util/branches");
20
+
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
23
+ const getGraphQLEndpointFactory = (path, useBranch) => (params, pathParams) => {
24
+ const projectId = typeof pathParams === 'object' ? pathParams.projectId : pathParams;
25
+ const branchParams = typeof pathParams === 'object' ? pathParams : {
26
+ environment: _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM
27
+ };
28
+ const basePath = projectId ? useBranch ? (0, _branches2.getBranchBasePath)(branchParams, projectId) : `/project/${projectId}` : '';
29
+ return `${params.endpoint}${basePath}${path}`;
30
+ };
31
+
32
+ const getGraphQLEndpoint = getGraphQLEndpointFactory('/graphql', true);
33
+ exports.getGraphQLEndpoint = getGraphQLEndpoint;
34
+ const getGraphQLAdminEndpoint = getGraphQLEndpointFactory('/admin-graphql', false);
35
+ exports.getGraphQLAdminEndpoint = getGraphQLAdminEndpoint;
36
+ const defaultOptions = {
37
+ retries: 3,
38
+ timeout: 0
39
+ };
40
+
41
+ const createConnectorFactory = getGraphQLEndpoint => (params, authToken, pathParams, options) => {
42
+ const endpoint = getGraphQLEndpoint(params, pathParams ?? {
43
+ environment: _branches.BRANCH_ENVIRONMENT_PRODUCTION_ENUM
44
+ });
45
+ const authHeader = (0, _api.getAuthHeader)(authToken);
46
+ const {
47
+ timeout,
48
+ retries
49
+ } = { ...defaultOptions,
50
+ ...options
51
+ };
52
+ return async params => (0, _asyncRetry.default)(async bail => {
53
+ const res = await (0, _nodeFetch.default)(endpoint, {
54
+ method: 'POST',
55
+ timeout,
56
+ body: JSON.stringify(params),
57
+ headers: {
58
+ 'Content-Type': 'application/json',
59
+ ...authHeader
60
+ }
61
+ });
62
+ const body = await res.json();
63
+
64
+ if (res.ok) {
65
+ return body;
66
+ }
67
+
68
+ const error = new _errors.HTTPError(`${res.statusText}: ${body.message}`, res.status);
69
+
70
+ if (res.status === 401 || res.status === 403) {
71
+ // Bail to stop retrying
72
+ bail(error);
73
+ return;
74
+ }
75
+
76
+ throw error;
77
+ }, {
78
+ retries
79
+ });
80
+ };
81
+
82
+ exports.createConnectorFactory = createConnectorFactory;
83
+ const createConnector = createConnectorFactory(getGraphQLEndpoint);
84
+ exports.createConnector = createConnector;
85
+ const createAdminConnector = createConnectorFactory(getGraphQLAdminEndpoint);
86
+ exports.createAdminConnector = createAdminConnector;
87
+
88
+ function graphQLQuery(query) {
89
+ return async (client, variables) => {
90
+ const {
91
+ data,
92
+ errors
93
+ } = await client({
94
+ query,
95
+ variables
96
+ });
97
+
98
+ if (errors) {
99
+ throw new Error(errors.map(error => error.message).join(', '));
100
+ }
101
+
102
+ return data.result;
103
+ };
104
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}