@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
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -47,13 +47,13 @@ type MutationError = {
47
47
  };
48
48
  };
49
49
  };
50
- type TaskStatus = {
50
+ type SyncMutationData = {
51
51
  numRequests: number;
52
52
  numSuccesses: number;
53
53
  errors: Array<TaskError>;
54
54
  mutationErrors: Array<MutationError>;
55
55
  };
56
- export type Task = {
56
+ export type CompositeSyncTask = {
57
57
  id: string;
58
58
  parentHubId: number;
59
59
  sandboxHubId: number;
@@ -70,12 +70,29 @@ export type Task = {
70
70
  startedAt: string;
71
71
  completedAt: string;
72
72
  error: MutationError;
73
- creates: TaskStatus;
74
- updates: TaskStatus;
75
- deletes: TaskStatus;
73
+ creates: SyncMutationData;
74
+ updates: SyncMutationData;
75
+ deletes: SyncMutationData;
76
76
  diffSummary: string;
77
77
  portableKeys: Array<string>;
78
78
  };
79
+ export type SyncTask = {
80
+ id: string;
81
+ parentHubId: number;
82
+ sandboxHubId: number;
83
+ fromHubId: number;
84
+ toHubId: number;
85
+ command: string;
86
+ status: string;
87
+ result: string;
88
+ sandboxType: string;
89
+ requestedAt: string;
90
+ requestedByUserId: number;
91
+ requestedByUser: User;
92
+ startedAt: string;
93
+ completedAt: string;
94
+ tasks: Array<CompositeSyncTask>;
95
+ };
79
96
  export type Sandbox = {
80
97
  sandboxHubId: number;
81
98
  parentHubId: number;
@@ -88,23 +105,7 @@ export type Sandbox = {
88
105
  domain: string;
89
106
  createdByUser: User;
90
107
  updatedByUser?: User | null;
91
- lastSync?: {
92
- id: string;
93
- parentHubId: number;
94
- sandboxHubId: number;
95
- fromHubId: number;
96
- toHubId: number;
97
- command: string;
98
- status: string;
99
- result: string;
100
- sandboxType: string;
101
- requestedAt: string;
102
- requestedByUserId: number;
103
- requestedByUser: User;
104
- startedAt: string;
105
- completedAt: string;
106
- tasks: Array<Task>;
107
- };
108
+ lastSync?: SyncTask;
108
109
  currentUserHasAccess?: boolean;
109
110
  currentUserHasSuperAdminAccess?: boolean;
110
111
  requestAccessFrom?: User | null;
@@ -129,26 +130,14 @@ export type Usage = {
129
130
  export type SandboxUsageLimitsResponse = {
130
131
  usage: Usage;
131
132
  };
132
- export type SyncTask = {
133
+ export type TaskRequestData = {
133
134
  type: string;
134
135
  };
135
136
  export type InitiateSyncResponse = {
136
137
  links: {
137
138
  status: string;
138
139
  };
139
- sync: {
140
- id: string;
141
- parentHubId: number;
142
- sandboxHubId: number;
143
- fromHubId: number;
144
- toHubId: number;
145
- command: string;
146
- status: string;
147
- sandboxType: string;
148
- requestedAt: string;
149
- requestedByUserId: number;
150
- tasks: Array<Task>;
151
- };
140
+ sync: SyncTask;
152
141
  id: string;
153
142
  };
154
143
  export type SandboxType = {
@@ -25,3 +25,59 @@ export type Schema = {
25
25
  export type FetchSchemasResponse = {
26
26
  results: Array<Schema>;
27
27
  };
28
+ export type CreateObjectsResponse = {
29
+ status: string;
30
+ startedAt: string;
31
+ completedAt: string;
32
+ results: Array<{
33
+ id: string;
34
+ properties: Array<any>;
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ archived: boolean;
38
+ }>;
39
+ };
40
+ export type SchemaDefinition = {
41
+ allowsSensitiveProperties?: boolean;
42
+ associatedObjects?: Array<string>;
43
+ description?: string;
44
+ labels: {
45
+ plural: string;
46
+ singular: string;
47
+ };
48
+ searchableProperties?: Array<string>;
49
+ secondaryDisplayProperties?: Array<string>;
50
+ name: string;
51
+ primaryDisplayProperty?: string;
52
+ properties: [
53
+ {
54
+ isPrimaryDisplayLabel: true;
55
+ label: string;
56
+ name: string;
57
+ }
58
+ ];
59
+ requiredProperties: Array<string>;
60
+ };
61
+ export type ObjectDefinition = {
62
+ inputs: [
63
+ {
64
+ associations?: [
65
+ {
66
+ types: [
67
+ {
68
+ associationCategory: string;
69
+ associationTypeId: number;
70
+ }
71
+ ];
72
+ to: {
73
+ id: string;
74
+ };
75
+ }
76
+ ];
77
+ objectWriteTraceId?: number;
78
+ properties: {
79
+ [key: string]: string;
80
+ };
81
+ }
82
+ ];
83
+ };
@@ -0,0 +1,3 @@
1
+ export type FetchSecretsResponse = {
2
+ results: Array<string>;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,23 @@
1
+ export type DeveloperTestAccount = {
2
+ testPortalId: number;
3
+ parentPortalId: number;
4
+ accountName: string;
5
+ createdAt: string;
6
+ updatedAt: string;
7
+ status: string;
8
+ id: number;
9
+ };
10
+ export type CreateDeveloperTestAccountResponse = {
11
+ id: number;
12
+ accountName: string;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ trialEndsAt: string;
16
+ status: string;
17
+ currentUserHasAccess: boolean;
18
+ personalAccessKey: string;
19
+ };
20
+ export type FetchDeveloperTestAccountsResponse = {
21
+ results: DeveloperTestAccount[];
22
+ maxTestPortals: number;
23
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { Express, Request, Response } from 'express';
3
3
  import { Server } from 'http';
4
- import { RequestPortsData } from '../types/PortManager';
5
- type ServerPortMap = {
6
- [instanceId: string]: number;
7
- };
8
- declare class PortManagerServer {
4
+ import { RequestPortsData, ServerPortMap } from '../types/PortManager';
5
+ export declare const HEALTH_CHECK_PATH = "/port-manager-health-check";
6
+ export declare const SERVICE_HEALTHY = "OK";
7
+ declare class _PortManagerServer {
9
8
  app?: Express;
10
9
  server?: Server;
11
10
  serverPortMap: ServerPortMap;
@@ -25,5 +24,5 @@ declare class PortManagerServer {
25
24
  deleteServerInstance: (req: Request, res: Response) => void;
26
25
  closeServer: (req: Request, res: Response) => void;
27
26
  }
28
- declare const _default: PortManagerServer;
29
- export default _default;
27
+ export declare const PortManagerServer: _PortManagerServer;
28
+ export {};
@@ -3,15 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PortManagerServer = exports.SERVICE_HEALTHY = exports.HEALTH_CHECK_PATH = void 0;
6
7
  const express_1 = __importDefault(require("express"));
7
8
  const cors_1 = __importDefault(require("cors"));
8
9
  const detectPort_1 = require("./detectPort");
9
10
  const ports_1 = require("../constants/ports");
10
- const standardErrors_1 = require("../errors/standardErrors");
11
- const logger_1 = require("../lib/logging/logger");
11
+ const errors_1 = require("../errors");
12
+ const logger_1 = require("../lib/logger");
12
13
  const lang_1 = require("./lang");
13
14
  const i18nKey = 'utils.PortManagerServer';
14
- class PortManagerServer {
15
+ exports.HEALTH_CHECK_PATH = '/port-manager-health-check';
16
+ exports.SERVICE_HEALTHY = 'OK';
17
+ class _PortManagerServer {
15
18
  app;
16
19
  server;
17
20
  serverPortMap;
@@ -20,7 +23,7 @@ class PortManagerServer {
20
23
  }
21
24
  async init() {
22
25
  if (this.app) {
23
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.duplicateInstance`);
26
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.duplicateInstance`));
24
27
  }
25
28
  this.app = (0, express_1.default)();
26
29
  this.app.use(express_1.default.json());
@@ -28,15 +31,15 @@ class PortManagerServer {
28
31
  this.setupRoutes();
29
32
  try {
30
33
  this.server = await this.listen();
34
+ logger_1.logger.debug(this.server);
31
35
  }
32
36
  catch (e) {
33
- const error = e;
34
- if (error.code === 'EADDRINUSE') {
35
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.portInUse`, {
37
+ if ((0, errors_1.isSystemError)(e) && e.code === 'EADDRINUSE') {
38
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.portInUse`, {
36
39
  port: ports_1.PORT_MANAGER_SERVER_PORT,
37
- }, error);
40
+ }), { cause: e });
38
41
  }
39
- throw error;
42
+ throw e;
40
43
  }
41
44
  }
42
45
  reset() {
@@ -65,6 +68,9 @@ class PortManagerServer {
65
68
  this.app.post('/servers', this.assignPortsToServers);
66
69
  this.app.delete('/servers/:instanceId', this.deleteServerInstance);
67
70
  this.app.post('/close', this.closeServer);
71
+ this.app.use(exports.HEALTH_CHECK_PATH, (req, res) => {
72
+ res.status(200).send({ status: exports.SERVICE_HEALTHY });
73
+ });
68
74
  }
69
75
  setPort(instanceId, port) {
70
76
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.setPort`, { instanceId, port }));
@@ -155,4 +161,4 @@ class PortManagerServer {
155
161
  }
156
162
  };
157
163
  }
158
- exports.default = new PortManagerServer();
164
+ exports.PortManagerServer = new _PortManagerServer();
@@ -1,10 +1,4 @@
1
1
  import { CLIAccount } from '../types/Accounts';
2
2
  import { CLIConfig } from '../types/Config';
3
- type Account = {
4
- portalId?: number;
5
- accountId?: number;
6
- };
7
- export declare function getAccountIdentifier(account?: Account | null): number | undefined;
8
3
  export declare function getAccounts(config?: CLIConfig | null): Array<CLIAccount>;
9
4
  export declare function getDefaultAccount(config?: CLIConfig | null): string | number | undefined;
10
- export {};
@@ -1,18 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultAccount = exports.getAccounts = exports.getAccountIdentifier = void 0;
4
- function getAccountIdentifier(account) {
5
- if (!account) {
6
- return undefined;
7
- }
8
- else if (Object.hasOwn(account, 'portalId')) {
9
- return account.portalId;
10
- }
11
- else if (Object.hasOwn(account, 'accountId')) {
12
- return account.accountId;
13
- }
14
- }
15
- exports.getAccountIdentifier = getAccountIdentifier;
3
+ exports.getDefaultAccount = exports.getAccounts = void 0;
16
4
  function getAccounts(config) {
17
5
  if (!config) {
18
6
  return [];
@@ -1,3 +1,2 @@
1
- type FieldsArray<T> = Array<T | FieldsArray<T>>;
1
+ import { FieldsArray } from '../../types/FieldsJS';
2
2
  export declare function fieldsArrayToJson<T>(fields: FieldsArray<T>): string;
3
- export {};
@@ -7,7 +7,7 @@ exports.isModuleFolderChild = exports.isModuleFolder = exports.isPathInput = voi
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const path_2 = require("../../lib/path");
9
9
  const extensions_1 = require("../../constants/extensions");
10
- const standardErrors_1 = require("../../errors/standardErrors");
10
+ const lang_1 = require("../lang");
11
11
  const i18nKey = 'utils.cms.modules';
12
12
  const isBool = (x) => !!x === x;
13
13
  function isPathInput(pathInput) {
@@ -19,7 +19,7 @@ exports.isPathInput = isPathInput;
19
19
  function throwInvalidPathInput(pathInput) {
20
20
  if (isPathInput(pathInput))
21
21
  return;
22
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.throwInvalidPathInput`);
22
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.throwInvalidPathInput`));
23
23
  }
24
24
  function isModuleFolder(pathInput) {
25
25
  throwInvalidPathInput(pathInput);
@@ -30,15 +30,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.detectPort = void 0;
31
31
  const net_1 = __importDefault(require("net"));
32
32
  const address_1 = require("address");
33
- const standardErrors_1 = require("../errors/standardErrors");
34
33
  const ports_1 = require("../constants/ports");
34
+ const lang_1 = require("./lang");
35
35
  const i18nKey = 'utils.detectPort';
36
36
  function detectPort(port, exclude = []) {
37
37
  if (port && (port < ports_1.MIN_PORT_NUMBER || port > ports_1.MAX_PORT_NUMBER)) {
38
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidPort`, {
38
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidPort`, {
39
39
  minPort: ports_1.MIN_PORT_NUMBER,
40
40
  maxPort: ports_1.MAX_PORT_NUMBER,
41
- });
41
+ }));
42
42
  }
43
43
  const portToUse = port || 0;
44
44
  const maxPort = Math.min(portToUse + 10, ports_1.MAX_PORT_NUMBER);
package/utils/git.d.ts CHANGED
@@ -1,9 +1,3 @@
1
+ export declare function getGitignoreFiles(configPath: string): Array<string>;
1
2
  export declare function isConfigPathInGitRepo(configPath: string): boolean;
2
3
  export declare function configFilenameIsIgnoredByGitignore(ignoreFiles: Array<string>, configPath: string): boolean;
3
- type GitInclusionResult = {
4
- inGit: boolean;
5
- configIgnored: boolean;
6
- gitignoreFiles: Array<string>;
7
- };
8
- export declare function checkGitInclusion(configPath: string): GitInclusionResult;
9
- export {};
package/utils/git.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkGitInclusion = exports.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = void 0;
6
+ exports.configFilenameIsIgnoredByGitignore = exports.isConfigPathInGitRepo = exports.getGitignoreFiles = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const ignore_1 = __importDefault(require("ignore"));
@@ -47,6 +47,7 @@ function getGitignoreFiles(configPath) {
47
47
  }
48
48
  return files;
49
49
  }
50
+ exports.getGitignoreFiles = getGitignoreFiles;
50
51
  function isConfigPathInGitRepo(configPath) {
51
52
  const gitDir = getGitComparisonDir();
52
53
  if (!gitDir)
@@ -68,20 +69,3 @@ function configFilenameIsIgnoredByGitignore(ignoreFiles, configPath) {
68
69
  });
69
70
  }
70
71
  exports.configFilenameIsIgnoredByGitignore = configFilenameIsIgnoredByGitignore;
71
- function checkGitInclusion(configPath) {
72
- const result = {
73
- inGit: false,
74
- configIgnored: false,
75
- gitignoreFiles: [],
76
- };
77
- if (isConfigPathInGitRepo(configPath)) {
78
- result.inGit = true;
79
- result.gitignoreFiles = getGitignoreFiles(configPath);
80
- if (configFilenameIsIgnoredByGitignore(result.gitignoreFiles, configPath)) {
81
- // Found ignore statement in .gitignore that matches config filename
82
- result.configIgnored = true;
83
- }
84
- }
85
- return result;
86
- }
87
- exports.checkGitInclusion = checkGitInclusion;
@@ -1,21 +0,0 @@
1
- import { AxiosError } from 'axios';
2
- import { GenericError, AxiosErrorContext } from '../types/Error';
3
- import { HubSpotAuthError } from '../models/HubSpotAuthError';
4
- export declare function isSpecifiedError(err: Error | AxiosError, { statusCode, category, subCategory, }: {
5
- statusCode?: number;
6
- category?: string;
7
- subCategory?: string;
8
- }): boolean;
9
- export declare function isMissingScopeError(err: Error | AxiosError): boolean;
10
- export declare function isGatingError(err: Error | AxiosError): boolean;
11
- export declare function isApiUploadValidationError(err: AxiosError<any>): boolean;
12
- export declare function isSpecifiedHubSpotAuthError(err: GenericError, { status, category, subCategory }: Partial<HubSpotAuthError>): boolean;
13
- export declare function getAxiosErrorWithContext(error: AxiosError<any>, context?: AxiosErrorContext): Error;
14
- /**
15
- * @throws
16
- */
17
- export declare function throwApiError(error: AxiosError, context?: AxiosErrorContext): never;
18
- /**
19
- * @throws
20
- */
21
- export declare function throwApiUploadError(error: AxiosError, context?: AxiosErrorContext): never;
@@ -1,177 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwApiUploadError = exports.throwApiError = exports.getAxiosErrorWithContext = exports.isSpecifiedHubSpotAuthError = exports.isApiUploadValidationError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
4
- const api_1 = require("../constants/api");
5
- const lang_1 = require("../utils/lang");
6
- const standardErrors_1 = require("./standardErrors");
7
- const i18nKey = 'errors.apiErrors';
8
- function isSpecifiedError(err, { statusCode, category, subCategory, }) {
9
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
- const error = (err && err.cause) || err;
11
- const statusCodeErr = !statusCode || error.response?.status === statusCode;
12
- const categoryErr = !category || error.response?.data?.category === category;
13
- const subCategoryErr = !subCategory || error.response?.data?.subCategory === subCategory;
14
- return error.isAxiosError && statusCodeErr && categoryErr && subCategoryErr;
15
- }
16
- exports.isSpecifiedError = isSpecifiedError;
17
- function isMissingScopeError(err) {
18
- return isSpecifiedError(err, { statusCode: 403, category: 'MISSING_SCOPES' });
19
- }
20
- exports.isMissingScopeError = isMissingScopeError;
21
- function isGatingError(err) {
22
- return isSpecifiedError(err, { statusCode: 403, category: 'GATED' });
23
- }
24
- exports.isGatingError = isGatingError;
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- function isApiUploadValidationError(err) {
27
- return (err.isAxiosError &&
28
- err.status === 400 &&
29
- !!err.response &&
30
- !!(err.response?.data?.message || !!err.response?.data?.errors));
31
- }
32
- exports.isApiUploadValidationError = isApiUploadValidationError;
33
- function isSpecifiedHubSpotAuthError(err, { status, category, subCategory }) {
34
- const statusCodeErr = !status || err.status === status;
35
- const categoryErr = !category || err.category === category;
36
- const subCategoryErr = !subCategory || err.subCategory === subCategory;
37
- return Boolean(err.name === 'HubSpotAuthError' &&
38
- statusCodeErr &&
39
- categoryErr &&
40
- subCategoryErr);
41
- }
42
- exports.isSpecifiedHubSpotAuthError = isSpecifiedHubSpotAuthError;
43
- function parseValidationErrors(responseData = { errors: [], message: '' }) {
44
- const errorMessages = [];
45
- const { errors, message } = responseData;
46
- if (message) {
47
- errorMessages.push(message);
48
- }
49
- if (errors) {
50
- const specificErrors = errors.map(error => {
51
- let errorMessage = error.message;
52
- if (error.errorTokens && error.errorTokens.line) {
53
- errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
54
- }
55
- return errorMessage;
56
- });
57
- errorMessages.push(...specificErrors);
58
- }
59
- return errorMessages;
60
- }
61
- /**
62
- * @throws
63
- */
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- function throwValidationErrors(error) {
66
- const validationErrorMessages = parseValidationErrors(error?.response?.data);
67
- if (validationErrorMessages.length) {
68
- (0, standardErrors_1.throwError)(new Error(validationErrorMessages.join(' '), { cause: error }));
69
- }
70
- }
71
- function getAxiosErrorWithContext(
72
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- error, context = {}) {
74
- const { status } = error;
75
- const method = error.config?.method;
76
- const { projectName } = context;
77
- let messageDetail;
78
- if (context.accountId) {
79
- const action = (method && api_1.HTTP_METHOD_VERBS[method]) || api_1.HTTP_METHOD_VERBS.get;
80
- const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
81
- api_1.HTTP_METHOD_PREPOSITIONS.get;
82
- const requestName = context.request
83
- ? `${action} ${preposition} '${context.request}'`
84
- : action;
85
- messageDetail = (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
86
- accountId: context.accountId,
87
- requestName,
88
- });
89
- }
90
- else {
91
- messageDetail = (0, lang_1.i18n)(`${i18nKey}.genericMessageDetail`);
92
- }
93
- const errorMessage = [];
94
- if ((method === 'put' || method === 'post') && context.payload) {
95
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
96
- }
97
- const isProjectMissingScopeError = isMissingScopeError(error) && projectName;
98
- const isProjectGatingError = isGatingError(error) && projectName;
99
- switch (status) {
100
- case 400:
101
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
102
- break;
103
- case 401:
104
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
105
- break;
106
- case 403:
107
- if (isProjectMissingScopeError) {
108
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403ProjectMissingScope`, {
109
- accountId: context.accountId || '',
110
- }));
111
- }
112
- else if (isProjectGatingError) {
113
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403ProjectGating`, {
114
- accountId: context.accountId || '',
115
- }));
116
- }
117
- else {
118
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403`, { messageDetail }));
119
- }
120
- break;
121
- case 404:
122
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
123
- break;
124
- case 429:
125
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
126
- break;
127
- case 503:
128
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
129
- break;
130
- default:
131
- if (status && status >= 500 && status < 600) {
132
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
133
- }
134
- else if (status && status >= 400 && status < 500) {
135
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
136
- }
137
- else {
138
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
139
- }
140
- break;
141
- }
142
- if (error?.response?.data) {
143
- const { message, errors } = error.response.data;
144
- if (message && !isProjectMissingScopeError && !isProjectGatingError) {
145
- errorMessage.push(message);
146
- }
147
- if (errors) {
148
- errors.forEach((err) => {
149
- if (err.message) {
150
- errorMessage.push('\n- ' + err.message);
151
- }
152
- });
153
- }
154
- }
155
- return new Error(errorMessage.join(' '), { cause: error });
156
- }
157
- exports.getAxiosErrorWithContext = getAxiosErrorWithContext;
158
- /**
159
- * @throws
160
- */
161
- function throwApiError(error, context = {}) {
162
- if (error.isAxiosError) {
163
- throw getAxiosErrorWithContext(error, context);
164
- }
165
- (0, standardErrors_1.throwError)(error);
166
- }
167
- exports.throwApiError = throwApiError;
168
- /**
169
- * @throws
170
- */
171
- function throwApiUploadError(error, context = {}) {
172
- if (isApiUploadValidationError(error)) {
173
- throwValidationErrors(error);
174
- }
175
- throwApiError(error, context);
176
- }
177
- exports.throwApiUploadError = throwApiUploadError;
@@ -1,6 +0,0 @@
1
- import { BaseError, FileSystemErrorContext } from '../types/Error';
2
- export declare function getFileSystemError(error: BaseError, context: FileSystemErrorContext): Error;
3
- /**
4
- * @throws
5
- */
6
- export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwFileSystemError = exports.getFileSystemError = void 0;
4
- const lang_1 = require("../utils/lang");
5
- const standardErrors_1 = require("./standardErrors");
6
- const i18nKey = 'errors.fileSystemErrors';
7
- function getFileSystemError(error, context) {
8
- let fileAction = '';
9
- if (context.read) {
10
- fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
11
- }
12
- else if (context.write) {
13
- fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
14
- }
15
- else {
16
- fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
17
- }
18
- const filepath = context.filepath
19
- ? `"${context.filepath}"`
20
- : (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
21
- const message = [(0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath })];
22
- // Many `fs` errors will be `SystemError`s
23
- if ((0, standardErrors_1.isSystemError)(error)) {
24
- message.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, { errorMessage: error.message }));
25
- }
26
- return new Error(message.join(' '), { cause: error });
27
- }
28
- exports.getFileSystemError = getFileSystemError;
29
- /**
30
- * @throws
31
- */
32
- function throwFileSystemError(error, context) {
33
- throw getFileSystemError(error, context);
34
- }
35
- exports.throwFileSystemError = throwFileSystemError;