@hubspot/local-dev-lib 0.3.0 → 0.3.1-experimental.0

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 (194) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +16 -16
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/fireAlarm.d.ts +3 -0
  18. package/api/fireAlarm.js +11 -0
  19. package/api/functions.d.ts +7 -7
  20. package/api/functions.js +13 -16
  21. package/api/github.d.ts +8 -9
  22. package/api/github.js +31 -13
  23. package/api/hubdb.d.ts +11 -10
  24. package/api/hubdb.js +28 -22
  25. package/api/lighthouseScore.d.ts +4 -4
  26. package/api/lighthouseScore.js +9 -12
  27. package/api/localDevAuth.d.ts +9 -16
  28. package/api/localDevAuth.js +36 -14
  29. package/api/marketplaceValidation.d.ts +4 -4
  30. package/api/marketplaceValidation.js +8 -11
  31. package/api/projects.d.ts +47 -24
  32. package/api/projects.js +178 -43
  33. package/api/sandboxHubs.d.ts +6 -4
  34. package/api/sandboxHubs.js +10 -11
  35. package/api/sandboxSync.d.ts +4 -4
  36. package/api/sandboxSync.js +4 -13
  37. package/api/secrets.d.ts +6 -8
  38. package/api/secrets.js +9 -12
  39. package/api/validateHubl.d.ts +2 -1
  40. package/api/validateHubl.js +3 -6
  41. package/config/CLIConfiguration.d.ts +12 -8
  42. package/config/CLIConfiguration.js +140 -64
  43. package/config/configFile.js +9 -18
  44. package/config/configUtils.d.ts +2 -21
  45. package/config/configUtils.js +3 -3
  46. package/config/config_DEPRECATED.d.ts +5 -8
  47. package/config/config_DEPRECATED.js +60 -26
  48. package/config/environment.js +1 -1
  49. package/config/getAccountIdentifier.d.ts +2 -0
  50. package/config/getAccountIdentifier.js +15 -0
  51. package/config/index.d.ts +13 -8
  52. package/config/index.js +99 -59
  53. package/config/migrate.d.ts +22 -0
  54. package/config/migrate.js +178 -0
  55. package/constants/config.d.ts +22 -3
  56. package/constants/config.js +29 -5
  57. package/constants/environments.d.ts +1 -0
  58. package/constants/environments.js +1 -0
  59. package/constants/extensions.d.ts +2 -0
  60. package/constants/extensions.js +3 -1
  61. package/constants/files.d.ts +2 -2
  62. package/constants/files.js +3 -3
  63. package/constants/projects.d.ts +12 -0
  64. package/constants/projects.js +15 -0
  65. package/errors/errors_DEPRECATED.d.ts +1 -5
  66. package/errors/errors_DEPRECATED.js +2 -2
  67. package/errors/index.d.ts +18 -0
  68. package/errors/index.js +63 -0
  69. package/http/addQueryParams.d.ts +2 -0
  70. package/http/addQueryParams.js +14 -0
  71. package/http/getAxiosConfig.d.ts +6 -3
  72. package/http/getAxiosConfig.js +49 -6
  73. package/http/index.d.ts +11 -10
  74. package/http/index.js +87 -36
  75. package/http/unauthed.d.ts +14 -0
  76. package/http/unauthed.js +38 -0
  77. package/lang/en.json +384 -386
  78. package/lib/archive.d.ts +3 -6
  79. package/lib/archive.js +27 -21
  80. package/lib/cms/functions.d.ts +6 -9
  81. package/lib/cms/functions.js +25 -20
  82. package/lib/cms/handleFieldsJS.d.ts +2 -2
  83. package/lib/cms/handleFieldsJS.js +15 -11
  84. package/lib/cms/modules.d.ts +5 -13
  85. package/lib/cms/modules.js +71 -73
  86. package/lib/cms/processFieldsJs.js +10 -33
  87. package/lib/cms/templates.d.ts +42 -0
  88. package/lib/cms/templates.js +49 -6
  89. package/lib/cms/uploadFolder.d.ts +3 -12
  90. package/lib/cms/uploadFolder.js +57 -39
  91. package/lib/cms/validate.js +1 -1
  92. package/lib/cms/watch.d.ts +2 -15
  93. package/lib/cms/watch.js +36 -28
  94. package/lib/customObjects.js +4 -15
  95. package/lib/fileManager.js +24 -24
  96. package/lib/fileMapper.d.ts +4 -13
  97. package/lib/fileMapper.js +57 -67
  98. package/lib/fs.d.ts +1 -1
  99. package/lib/fs.js +10 -6
  100. package/lib/github.d.ts +11 -11
  101. package/lib/github.js +45 -31
  102. package/lib/gitignore.d.ts +2 -0
  103. package/lib/gitignore.js +21 -4
  104. package/lib/hubdb.d.ts +3 -2
  105. package/lib/hubdb.js +11 -9
  106. package/{utils → lib}/notify.js +2 -2
  107. package/lib/oauth.d.ts +1 -1
  108. package/lib/oauth.js +10 -19
  109. package/lib/path.d.ts +3 -0
  110. package/lib/path.js +46 -1
  111. package/lib/personalAccessKey.d.ts +8 -11
  112. package/lib/personalAccessKey.js +72 -52
  113. package/lib/portManager.d.ts +3 -5
  114. package/lib/portManager.js +18 -6
  115. package/lib/text.d.ts +1 -1
  116. package/lib/text.js +3 -0
  117. package/lib/trackUsage.js +14 -8
  118. package/lib/urls.js +5 -1
  119. package/models/FileSystemError.d.ts +6 -0
  120. package/models/FileSystemError.js +47 -0
  121. package/models/HubSpotHttpError.d.ts +26 -0
  122. package/models/HubSpotHttpError.js +208 -0
  123. package/models/OAuth2Manager.d.ts +2 -27
  124. package/models/OAuth2Manager.js +15 -30
  125. package/package.json +38 -36
  126. package/types/Accounts.d.ts +98 -3
  127. package/types/Apps.d.ts +77 -0
  128. package/types/Apps.js +2 -0
  129. package/types/Archive.d.ts +9 -0
  130. package/types/Archive.js +2 -0
  131. package/types/Build.d.ts +4 -2
  132. package/types/ComponentStructure.d.ts +30 -10
  133. package/types/Config.d.ts +19 -2
  134. package/types/Deploy.d.ts +3 -2
  135. package/types/DesignManager.d.ts +15 -0
  136. package/types/DesignManager.js +2 -0
  137. package/types/Error.d.ts +9 -5
  138. package/types/FieldsJS.d.ts +1 -0
  139. package/types/FieldsJS.js +2 -0
  140. package/types/FileManager.d.ts +1 -1
  141. package/types/Files.d.ts +43 -4
  142. package/types/FireAlarm.d.ts +9 -0
  143. package/types/FireAlarm.js +2 -0
  144. package/types/Functions.d.ts +52 -0
  145. package/types/Github.d.ts +13 -0
  146. package/types/Http.d.ts +13 -12
  147. package/types/Hubdb.d.ts +9 -0
  148. package/types/MarketplaceValidation.d.ts +7 -3
  149. package/types/Migration.d.ts +30 -0
  150. package/types/Migration.js +12 -0
  151. package/types/Modules.d.ts +11 -0
  152. package/types/PortManager.d.ts +7 -0
  153. package/types/Project.d.ts +30 -0
  154. package/types/ProjectLog.d.ts +9 -0
  155. package/types/ProjectLog.js +2 -0
  156. package/types/Sandbox.d.ts +25 -36
  157. package/types/Schemas.d.ts +56 -0
  158. package/types/Secrets.d.ts +3 -0
  159. package/types/Secrets.js +2 -0
  160. package/types/developerTestAccounts.d.ts +23 -0
  161. package/types/developerTestAccounts.js +2 -0
  162. package/utils/PortManagerServer.d.ts +6 -7
  163. package/utils/PortManagerServer.js +16 -10
  164. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  165. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  166. package/utils/cms/fieldsJS.d.ts +1 -2
  167. package/utils/cms/modules.js +2 -2
  168. package/utils/detectPort.js +3 -3
  169. package/utils/git.d.ts +1 -7
  170. package/utils/git.js +2 -18
  171. package/errors/apiErrors.d.ts +0 -21
  172. package/errors/apiErrors.js +0 -177
  173. package/errors/fileSystemErrors.d.ts +0 -6
  174. package/errors/fileSystemErrors.js +0 -35
  175. package/errors/standardErrors.d.ts +0 -21
  176. package/errors/standardErrors.js +0 -52
  177. package/lang/lang/en.json +0 -401
  178. package/lib/logging/git.d.ts +0 -2
  179. package/lib/logging/git.js +0 -54
  180. package/lib/logging/logs.d.ts +0 -22
  181. package/lib/logging/logs.js +0 -86
  182. package/lib/logging/table.d.ts +0 -3
  183. package/lib/logging/table.js +0 -47
  184. package/lib/sandboxes.d.ts +0 -14
  185. package/lib/sandboxes.js +0 -70
  186. package/models/HubSpotAuthError.d.ts +0 -12
  187. package/models/HubSpotAuthError.js +0 -20
  188. package/utils/objectUtils.d.ts +0 -8
  189. package/utils/objectUtils.js +0 -33
  190. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  191. /package/{utils → lib}/escapeRegExp.js +0 -0
  192. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  193. /package/lib/{logging/logger.js → logger.js} +0 -0
  194. /package/{utils → lib}/notify.d.ts +0 -0
package/http/index.js CHANGED
@@ -1,25 +1,92 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.http = exports.addUserAgentHeader = void 0;
6
30
  const path_1 = __importDefault(require("path"));
7
31
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
32
  const content_disposition_1 = __importDefault(require("content-disposition"));
9
- const axios_1 = __importDefault(require("axios"));
33
+ const axios_1 = __importStar(require("axios"));
10
34
  const config_1 = require("../config");
11
35
  const getAxiosConfig_1 = require("./getAxiosConfig");
36
+ const addQueryParams_1 = require("./addQueryParams");
12
37
  const personalAccessKey_1 = require("../lib/personalAccessKey");
13
38
  const oauth_1 = require("../lib/oauth");
14
- const standardErrors_1 = require("../errors/standardErrors");
15
- const logger_1 = require("../lib/logging/logger");
39
+ const logger_1 = require("../lib/logger");
16
40
  const lang_1 = require("../utils/lang");
41
+ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
42
+ const localDevAuth_1 = require("../api/localDevAuth");
43
+ const util = __importStar(require("util"));
17
44
  const i18nKey = 'http.index';
45
+ function logRequest(response) {
46
+ try {
47
+ if (process.env.HUBSPOT_NETWORK_LOGGING) {
48
+ if (response.config.url === localDevAuth_1.LOCALDEVAUTH_ACCESS_TOKEN_PATH) {
49
+ // Don't log access tokens
50
+ return;
51
+ }
52
+ logger_1.logger.debug(util.inspect({
53
+ method: response.config.method,
54
+ baseURL: response.config.baseURL,
55
+ url: response.config.url,
56
+ data: response.data,
57
+ status: response.status,
58
+ }, false, null, true));
59
+ }
60
+ }
61
+ catch (error) {
62
+ // Ignore any errors that occur while logging the response
63
+ }
64
+ }
65
+ axios_1.default.interceptors.response.use((response) => {
66
+ logRequest(response);
67
+ return response;
68
+ }, error => {
69
+ try {
70
+ if ((0, axios_1.isAxiosError)(error) && error.response) {
71
+ logRequest(error.response);
72
+ }
73
+ }
74
+ catch (e) {
75
+ // Ignore any errors that occur while logging the response
76
+ }
77
+ // Wrap all axios errors in our own Error class. Attach the error
78
+ // as the cause for the new error, so we maintain the stack trace
79
+ return Promise.reject(new HubSpotHttpError_1.HubSpotHttpError(error.message, { cause: error }));
80
+ });
81
+ function addUserAgentHeader(key, value) {
82
+ getAxiosConfig_1.USER_AGENTS[key] = value;
83
+ }
84
+ exports.addUserAgentHeader = addUserAgentHeader;
18
85
  async function withOauth(accountId, accountConfig, axiosConfig) {
19
86
  const { headers } = axiosConfig;
20
87
  const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
21
88
  if (!oauth) {
22
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withOauth`, { accountId });
89
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
23
90
  }
24
91
  const accessToken = await oauth.accessToken();
25
92
  return {
@@ -54,7 +121,7 @@ function withPortalId(portalId, axiosConfig) {
54
121
  async function withAuth(accountId, options) {
55
122
  const accountConfig = (0, config_1.getAccountConfig)(accountId);
56
123
  if (!accountConfig) {
57
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withAuth`, { accountId });
124
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
58
125
  }
59
126
  const { env, authType, apiKey } = accountConfig;
60
127
  const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
@@ -73,47 +140,32 @@ async function withAuth(accountId, options) {
73
140
  },
74
141
  };
75
142
  }
76
- function addQueryParams(configOptions, queryParams = {}) {
77
- const { params } = configOptions;
78
- return {
79
- ...configOptions,
80
- params: {
81
- ...queryParams,
82
- ...params,
83
- },
84
- };
85
- }
86
143
  async function getRequest(accountId, options) {
87
- const { query, ...rest } = options;
88
- const axiosConfig = addQueryParams(rest, query);
89
- const configWithAuth = await withAuth(accountId, axiosConfig);
90
- const { data } = await (0, axios_1.default)(configWithAuth);
91
- return data;
144
+ const { params, ...rest } = options;
145
+ const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
146
+ const requestConfig = await withAuth(accountId, optionsWithParams);
147
+ return (0, axios_1.default)(requestConfig);
92
148
  }
93
149
  async function postRequest(accountId, options) {
94
- const configWithAuth = await withAuth(accountId, options);
95
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'post' });
96
- return data;
150
+ const requestConfig = await withAuth(accountId, options);
151
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
97
152
  }
98
153
  async function putRequest(accountId, options) {
99
- const configWithAuth = await withAuth(accountId, options);
100
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
101
- return data;
154
+ const requestConfig = await withAuth(accountId, options);
155
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
102
156
  }
103
157
  async function patchRequest(accountId, options) {
104
- const configWithAuth = await withAuth(accountId, options);
105
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'put' });
106
- return data;
158
+ const requestConfig = await withAuth(accountId, options);
159
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
107
160
  }
108
161
  async function deleteRequest(accountId, options) {
109
- const configWithAuth = await withAuth(accountId, options);
110
- const { data } = await (0, axios_1.default)({ ...configWithAuth, method: 'delete' });
111
- return data;
162
+ const requestConfig = await withAuth(accountId, options);
163
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
112
164
  }
113
165
  function createGetRequestStream(contentType) {
114
166
  return async (accountId, options, destPath) => {
115
- const { query, ...rest } = options;
116
- const axiosConfig = addQueryParams(rest, query);
167
+ const { params, ...rest } = options;
168
+ const axiosConfig = (0, addQueryParams_1.addQueryParams)(rest, params);
117
169
  // eslint-disable-next-line no-async-promise-executor
118
170
  return new Promise(async (resolve, reject) => {
119
171
  try {
@@ -167,7 +219,7 @@ function createGetRequestStream(contentType) {
167
219
  };
168
220
  }
169
221
  const getOctetStream = createGetRequestStream('application/octet-stream');
170
- const http = {
222
+ exports.http = {
171
223
  get: getRequest,
172
224
  post: postRequest,
173
225
  put: putRequest,
@@ -175,4 +227,3 @@ const http = {
175
227
  delete: deleteRequest,
176
228
  getOctetStream,
177
229
  };
178
- exports.default = http;
@@ -0,0 +1,14 @@
1
+ import { HttpOptions, HubSpotPromise } from '../types/Http';
2
+ declare function getRequest<T>(options: HttpOptions): HubSpotPromise<T>;
3
+ declare function postRequest<T>(options: HttpOptions): HubSpotPromise<T>;
4
+ declare function putRequest<T>(options: HttpOptions): HubSpotPromise<T>;
5
+ declare function patchRequest<T>(options: HttpOptions): HubSpotPromise<T>;
6
+ declare function deleteRequest<T>(options: HttpOptions): HubSpotPromise<T>;
7
+ export declare const http: {
8
+ get: typeof getRequest;
9
+ post: typeof postRequest;
10
+ put: typeof putRequest;
11
+ patch: typeof patchRequest;
12
+ delete: typeof deleteRequest;
13
+ };
14
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.http = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const getAxiosConfig_1 = require("./getAxiosConfig");
9
+ const addQueryParams_1 = require("./addQueryParams");
10
+ async function getRequest(options) {
11
+ const { params, ...rest } = options;
12
+ const optionsWithParams = (0, addQueryParams_1.addQueryParams)(rest, params);
13
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(optionsWithParams);
14
+ return (0, axios_1.default)(requestConfig);
15
+ }
16
+ async function postRequest(options) {
17
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
18
+ return (0, axios_1.default)({ ...requestConfig, method: 'post' });
19
+ }
20
+ async function putRequest(options) {
21
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
22
+ return (0, axios_1.default)({ ...requestConfig, method: 'put' });
23
+ }
24
+ async function patchRequest(options) {
25
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
26
+ return (0, axios_1.default)({ ...requestConfig, method: 'patch' });
27
+ }
28
+ async function deleteRequest(options) {
29
+ const requestConfig = await (0, getAxiosConfig_1.getAxiosConfig)(options);
30
+ return (0, axios_1.default)({ ...requestConfig, method: 'delete' });
31
+ }
32
+ exports.http = {
33
+ get: getRequest,
34
+ post: postRequest,
35
+ put: putRequest,
36
+ patch: patchRequest,
37
+ delete: deleteRequest,
38
+ };