@hubspot/local-dev-lib 1.13.1 → 2.0.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 (105) hide show
  1. package/api/appsDev.d.ts +6 -5
  2. package/api/appsDev.js +6 -10
  3. package/api/customObjects.d.ts +7 -6
  4. package/api/customObjects.js +13 -16
  5. package/api/designManager.d.ts +3 -2
  6. package/api/designManager.js +5 -8
  7. package/api/developerTestAccounts.d.ts +5 -4
  8. package/api/developerTestAccounts.js +9 -10
  9. package/api/fileManager.d.ts +5 -4
  10. package/api/fileManager.js +9 -9
  11. package/api/fileMapper.d.ts +8 -8
  12. package/api/fileMapper.js +16 -16
  13. package/api/fileTransport.d.ts +4 -3
  14. package/api/fileTransport.js +5 -5
  15. package/api/functions.d.ts +6 -5
  16. package/api/functions.js +11 -14
  17. package/api/github.d.ts +6 -6
  18. package/api/github.js +29 -13
  19. package/api/hubdb.d.ts +9 -8
  20. package/api/hubdb.js +17 -20
  21. package/api/lighthouseScore.d.ts +4 -3
  22. package/api/lighthouseScore.js +7 -10
  23. package/api/localDevAuth.d.ts +5 -4
  24. package/api/localDevAuth.js +8 -9
  25. package/api/marketplaceValidation.d.ts +4 -3
  26. package/api/marketplaceValidation.js +4 -7
  27. package/api/projects.d.ts +31 -30
  28. package/api/projects.js +52 -52
  29. package/api/sandboxHubs.d.ts +5 -4
  30. package/api/sandboxHubs.js +9 -10
  31. package/api/sandboxSync.d.ts +4 -4
  32. package/api/sandboxSync.js +5 -14
  33. package/api/secrets.d.ts +5 -4
  34. package/api/secrets.js +9 -12
  35. package/api/validateHubl.d.ts +2 -1
  36. package/api/validateHubl.js +3 -6
  37. package/config/CLIConfiguration.d.ts +3 -3
  38. package/config/CLIConfiguration.js +22 -20
  39. package/config/configFile.js +7 -14
  40. package/config/config_DEPRECATED.js +5 -2
  41. package/config/index.js +45 -48
  42. package/errors/errors_DEPRECATED.js +2 -2
  43. package/errors/index.d.ts +18 -0
  44. package/errors/index.js +63 -0
  45. package/http/addQueryParams.d.ts +2 -0
  46. package/http/addQueryParams.js +14 -0
  47. package/http/getAxiosConfig.d.ts +2 -2
  48. package/http/getAxiosConfig.js +10 -2
  49. package/http/index.d.ts +9 -14
  50. package/http/index.js +28 -53
  51. package/http/unauthed.d.ts +15 -0
  52. package/http/unauthed.js +38 -0
  53. package/lang/en.json +1 -2
  54. package/lang/lang/en.json +1 -2
  55. package/lib/archive.js +11 -10
  56. package/lib/cms/functions.d.ts +7 -1
  57. package/lib/cms/functions.js +22 -18
  58. package/lib/cms/handleFieldsJS.js +8 -7
  59. package/lib/cms/modules.js +4 -5
  60. package/lib/cms/processFieldsJs.js +8 -7
  61. package/lib/cms/templates.js +2 -3
  62. package/lib/cms/uploadFolder.js +16 -14
  63. package/lib/cms/validate.js +1 -1
  64. package/lib/cms/watch.js +16 -9
  65. package/lib/customObjects.js +4 -15
  66. package/lib/fileManager.js +22 -21
  67. package/lib/fileMapper.js +24 -31
  68. package/lib/fs.js +2 -2
  69. package/lib/github.js +21 -21
  70. package/lib/gitignore.js +2 -2
  71. package/lib/hubdb.d.ts +3 -2
  72. package/lib/hubdb.js +11 -9
  73. package/lib/notify.js +2 -2
  74. package/lib/oauth.d.ts +1 -1
  75. package/lib/oauth.js +8 -17
  76. package/lib/personalAccessKey.js +16 -21
  77. package/lib/portManager.js +2 -2
  78. package/lib/trackUsage.js +3 -3
  79. package/models/FileSystemError.d.ts +6 -0
  80. package/models/FileSystemError.js +47 -0
  81. package/models/HubSpotHttpError.d.ts +24 -0
  82. package/models/HubSpotHttpError.js +197 -0
  83. package/models/OAuth2Manager.d.ts +1 -2
  84. package/models/OAuth2Manager.js +13 -28
  85. package/package.json +2 -1
  86. package/types/Error.d.ts +7 -5
  87. package/types/Files.d.ts +4 -4
  88. package/types/Http.d.ts +6 -10
  89. package/types/Sandbox.d.ts +0 -5
  90. package/utils/PortManagerServer.d.ts +3 -3
  91. package/utils/PortManagerServer.js +9 -9
  92. package/utils/cms/modules.js +2 -2
  93. package/utils/detectPort.js +3 -3
  94. package/errors/apiErrors.d.ts +0 -25
  95. package/errors/apiErrors.js +0 -176
  96. package/errors/fileSystemErrors.d.ts +0 -6
  97. package/errors/fileSystemErrors.js +0 -35
  98. package/errors/standardErrors.d.ts +0 -20
  99. package/errors/standardErrors.js +0 -62
  100. package/lib/developerTestAccounts.d.ts +0 -4
  101. package/lib/developerTestAccounts.js +0 -35
  102. package/lib/sandboxes.d.ts +0 -14
  103. package/lib/sandboxes.js +0 -70
  104. package/models/HubSpotAuthError.d.ts +0 -12
  105. package/models/HubSpotAuthError.js +0 -20
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HubSpotHttpError = void 0;
4
+ const axios_1 = require("axios");
5
+ const api_1 = require("../constants/api");
6
+ const lang_1 = require("../utils/lang");
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ class HubSpotHttpError extends Error {
9
+ status;
10
+ code;
11
+ statusText;
12
+ data;
13
+ headers;
14
+ method;
15
+ context;
16
+ derivedContext;
17
+ validationErrors;
18
+ detailedMessage;
19
+ divider = `\n- `;
20
+ cause;
21
+ constructor(message, options, context) {
22
+ super(message, options);
23
+ this.name = 'HubSpotHttpError';
24
+ this.context = context;
25
+ this.cause = options?.cause;
26
+ if (options && (0, axios_1.isAxiosError)(options.cause)) {
27
+ this.extractDerivedContext(options.cause);
28
+ const { response, config, code } = options.cause;
29
+ this.message = this.joinErrorMessages(options.cause, {
30
+ accountId: this.context?.accountId || this.derivedContext?.accountId,
31
+ });
32
+ this.detailedMessage = this.joinErrorMessages(options.cause, this.context);
33
+ this.code = code;
34
+ this.method = config?.method;
35
+ // Pull the request fields to the top level
36
+ if (response) {
37
+ this.status = response.status;
38
+ this.statusText = response.statusText;
39
+ this.data = response.data;
40
+ this.headers = response.headers;
41
+ this.parseValidationErrors(response.data);
42
+ }
43
+ }
44
+ else if (options && options.cause instanceof Error) {
45
+ const messages = options.cause.name !== 'Error' ? [`${options.cause.name}:`] : [];
46
+ if (options.cause.message) {
47
+ messages.push(options.cause.message);
48
+ }
49
+ if ('reason' in options.cause && options.cause.reason) {
50
+ messages.push(`${options.cause.reason}`);
51
+ }
52
+ this.message = messages.join(' ');
53
+ }
54
+ }
55
+ updateContext(context) {
56
+ this.context = { ...this.context, ...context };
57
+ // Update the error messages when the context is updated
58
+ if ((0, axios_1.isAxiosError)(this.cause)) {
59
+ this.message = this.joinErrorMessages(this.cause, this.context);
60
+ }
61
+ }
62
+ toString() {
63
+ const messages = [
64
+ `${this.name}: ${this.divider}message: ${this.detailedMessage}`,
65
+ ];
66
+ ['status', 'statusText', 'method', 'code'].forEach(field => {
67
+ if (Object.hasOwn(this, field)) {
68
+ // @ts-expect-error this[field] exists, so we know it is a property of this
69
+ messages.push(`${field}: ${this[field]}`);
70
+ }
71
+ });
72
+ if (this.validationErrors && this.validationErrors.length > 0) {
73
+ messages.push(`errors: ${this.formattedValidationErrors()}`);
74
+ }
75
+ if (this.context) {
76
+ messages.push(`context: ${JSON.stringify(this.context, undefined, 2)}`);
77
+ }
78
+ if (this.derivedContext) {
79
+ messages.push(`derivedContext: ${JSON.stringify(this.derivedContext, undefined, 2)}`);
80
+ }
81
+ return messages.join(this.divider);
82
+ }
83
+ formattedValidationErrors() {
84
+ if (!this.validationErrors || this.validationErrors?.length === 0) {
85
+ return '';
86
+ }
87
+ return this.validationErrors?.join(this.divider);
88
+ }
89
+ extractDerivedContext(cause) {
90
+ const generatedContext = {};
91
+ if (!cause) {
92
+ return;
93
+ }
94
+ generatedContext.accountId = cause.config?.params?.portalId;
95
+ generatedContext.payload = JSON.stringify(cause.config?.data);
96
+ // This will just be the url path
97
+ generatedContext.request = cause.config?.url;
98
+ // Allow the provided context to override the generated context
99
+ this.derivedContext = { ...this.derivedContext, ...generatedContext };
100
+ }
101
+ parseValidationErrors(responseData = { errors: [], message: '' }) {
102
+ if (!responseData) {
103
+ return;
104
+ }
105
+ const errorMessages = [];
106
+ const { errors, message } = responseData;
107
+ if (message) {
108
+ errorMessages.push(message);
109
+ }
110
+ if (errors) {
111
+ const specificErrors = errors.map(error => {
112
+ let errorMessage = error.message;
113
+ if (error.context?.requiredScopes) {
114
+ // Sometimes the scopes come back with duplicates
115
+ const scopes = new Set(error.context.requiredScopes);
116
+ scopes.forEach(item => {
117
+ errorMessage = `${errorMessage}\n - ${item}`;
118
+ });
119
+ }
120
+ else if (error.errorTokens && error.errorTokens.line) {
121
+ errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
122
+ }
123
+ return errorMessage;
124
+ });
125
+ errorMessages.push(...specificErrors);
126
+ }
127
+ this.validationErrors = errorMessages;
128
+ }
129
+ joinErrorMessages(error, context = {}) {
130
+ const i18nKey = 'errors.apiErrors';
131
+ const status = error.response?.status;
132
+ const method = error.config?.method;
133
+ let messageDetail;
134
+ if (context.accountId) {
135
+ const action = (method && api_1.HTTP_METHOD_VERBS[method]) || api_1.HTTP_METHOD_VERBS.get;
136
+ const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
137
+ api_1.HTTP_METHOD_PREPOSITIONS.get;
138
+ const requestName = context.request
139
+ ? `${action} ${preposition} '${context.request}'`
140
+ : action;
141
+ messageDetail = (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
142
+ accountId: context.accountId,
143
+ requestName,
144
+ });
145
+ }
146
+ else {
147
+ messageDetail = (0, lang_1.i18n)(`${i18nKey}.genericMessageDetail`);
148
+ }
149
+ const errorMessage = [];
150
+ if ((method === 'put' || method === 'post') && context.payload) {
151
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
152
+ }
153
+ switch (status) {
154
+ case 400:
155
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
156
+ break;
157
+ case 401:
158
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
159
+ break;
160
+ case 403:
161
+ break;
162
+ case 404:
163
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
164
+ break;
165
+ case 429:
166
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
167
+ break;
168
+ case 503:
169
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
170
+ break;
171
+ default:
172
+ if (status && status >= 500 && status < 600) {
173
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
174
+ }
175
+ else if (status && status >= 400 && status < 500) {
176
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
177
+ }
178
+ else {
179
+ errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
180
+ }
181
+ break;
182
+ }
183
+ if (error?.response?.data) {
184
+ const { message, errors } = error.response.data;
185
+ if (message) {
186
+ errorMessage.push(message);
187
+ }
188
+ (errors || []).forEach(err => {
189
+ if (err.message) {
190
+ errorMessage.push(`${this.divider}${err.message}`);
191
+ }
192
+ });
193
+ }
194
+ return errorMessage.join(' ');
195
+ }
196
+ }
197
+ exports.HubSpotHttpError = HubSpotHttpError;
@@ -1,5 +1,5 @@
1
1
  import { FlatAccountFields, OAuth2ManagerAccountConfig, WriteTokenInfoFunction, RefreshTokenResponse, ExchangeProof } from '../types/Accounts';
2
- declare class OAuth2Manager {
2
+ export declare class OAuth2Manager {
3
3
  account: OAuth2ManagerAccountConfig;
4
4
  writeTokenInfo?: WriteTokenInfoFunction;
5
5
  refreshTokenRequest: Promise<RefreshTokenResponse> | null;
@@ -10,4 +10,3 @@ declare class OAuth2Manager {
10
10
  refreshAccessToken(): Promise<void>;
11
11
  static fromConfig(accountConfig: FlatAccountFields, writeTokenInfo: WriteTokenInfoFunction): OAuth2Manager;
12
12
  }
13
- export default OAuth2Manager;
@@ -3,6 +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.OAuth2Manager = void 0;
6
7
  const axios_1 = __importDefault(require("axios"));
7
8
  const moment_1 = __importDefault(require("moment"));
8
9
  const urls_1 = require("../lib/urls");
@@ -10,7 +11,6 @@ const environment_1 = require("../lib/environment");
10
11
  const logger_1 = require("../lib/logger");
11
12
  const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
12
13
  const auth_1 = require("../constants/auth");
13
- const standardErrors_1 = require("../errors/standardErrors");
14
14
  const lang_1 = require("../utils/lang");
15
15
  const i18nKey = 'models.OAuth2Manager';
16
16
  class OAuth2Manager {
@@ -27,9 +27,9 @@ class OAuth2Manager {
27
27
  }
28
28
  async accessToken() {
29
29
  if (!this.account.tokenInfo?.refreshToken) {
30
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.missingRefreshToken`, {
30
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.missingRefreshToken`, {
31
31
  accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
32
- });
32
+ }));
33
33
  }
34
34
  if (!this.account.tokenInfo?.accessToken ||
35
35
  (0, moment_1.default)()
@@ -68,36 +68,21 @@ class OAuth2Manager {
68
68
  }));
69
69
  this.writeTokenInfo(this.account.tokenInfo);
70
70
  }
71
- this.refreshTokenRequest = null;
72
71
  }
73
- catch (e) {
72
+ finally {
74
73
  this.refreshTokenRequest = null;
75
- (0, standardErrors_1.throwError)(e);
76
74
  }
77
75
  }
78
76
  async exchangeForTokens(exchangeProof) {
79
- try {
80
- if (this.refreshTokenRequest) {
81
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.refreshingAccessToken`, {
82
- accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
83
- clientId: this.account.clientId || '',
84
- }));
85
- await this.refreshTokenRequest;
86
- }
87
- else {
88
- await this.fetchAccessToken(exchangeProof);
89
- }
77
+ if (this.refreshTokenRequest) {
78
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.refreshingAccessToken`, {
79
+ accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
80
+ clientId: this.account.clientId || '',
81
+ }));
82
+ await this.refreshTokenRequest;
90
83
  }
91
- catch (e) {
92
- const error = e;
93
- if (error.response) {
94
- (0, standardErrors_1.throwAuthErrorWithMessage)(`${i18nKey}.errors.auth`, {
95
- token: error.response.data.message || '',
96
- }, error);
97
- }
98
- else {
99
- (0, standardErrors_1.throwError)(error);
100
- }
84
+ else {
85
+ await this.fetchAccessToken(exchangeProof);
101
86
  }
102
87
  }
103
88
  async refreshAccessToken() {
@@ -117,4 +102,4 @@ class OAuth2Manager {
117
102
  }, writeTokenInfo);
118
103
  }
119
104
  }
120
- exports.default = OAuth2Manager;
105
+ exports.OAuth2Manager = OAuth2Manager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "1.13.1",
3
+ "version": "2.0.1",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -41,6 +41,7 @@
41
41
  "@typescript-eslint/eslint-plugin": "^5.54.0",
42
42
  "@typescript-eslint/parser": "^5.59.7",
43
43
  "eslint": "^8.35.0",
44
+ "eslint-plugin-import": "^2.29.1",
44
45
  "husky": "^8.0.0",
45
46
  "jest": "^29.5.0",
46
47
  "ts-jest": "^29.0.5",
package/types/Error.d.ts CHANGED
@@ -16,19 +16,21 @@ export interface ValidationError extends BaseError {
16
16
  errorTokens?: {
17
17
  line: number;
18
18
  };
19
+ context?: {
20
+ requiredScopes?: string[];
21
+ };
19
22
  }
20
23
  export type FileSystemErrorContext = {
21
24
  filepath?: string;
22
- write?: boolean;
23
- read?: boolean;
25
+ operation?: 'write' | 'read';
24
26
  accountId?: number;
25
27
  dest?: string;
26
28
  };
27
- export type AxiosErrorContext = {
28
- accountId?: number;
29
+ export interface HubSpotHttpErrorContext extends FileSystemErrorContext {
29
30
  request?: string;
30
31
  payload?: string;
31
- };
32
+ projectName?: string;
33
+ }
32
34
  export type OptionalError = BaseError | null | undefined;
33
35
  export type ErrorContext = {
34
36
  accountId?: number;
package/types/Files.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { AxiosError } from 'axios';
2
1
  import { ValueOf } from '../types/Utils';
3
2
  import { STAT_TYPES, FILE_TYPES, FILE_UPLOAD_RESULT_TYPES } from '../constants/files';
4
3
  import { MODE } from '../constants/files';
5
4
  import { HttpOptions } from './Http';
5
+ import { AxiosError } from 'axios';
6
6
  export type StatType = ValueOf<typeof STAT_TYPES>;
7
7
  export type FileData = {
8
8
  filepath: string;
@@ -29,7 +29,7 @@ export type FileType = ValueOf<typeof FILE_TYPES>;
29
29
  type ResultType = ValueOf<typeof FILE_UPLOAD_RESULT_TYPES>;
30
30
  export type UploadFolderResults = {
31
31
  resultType: ResultType;
32
- error: AxiosError | null;
32
+ error: unknown;
33
33
  file: string;
34
34
  };
35
35
  export type FileTree = {
@@ -51,9 +51,9 @@ export type CommandOptions = {
51
51
  saveOutput?: boolean;
52
52
  onAttemptCallback?: (file: string | undefined, destPath: string) => void;
53
53
  onSuccessCallback?: (file: string | undefined, destPath: string) => void;
54
- onFirstErrorCallback?: (file: string, destPath: string, error: AxiosError) => void;
54
+ onFirstErrorCallback?: (file: string, destPath: string, error: unknown) => void;
55
55
  onRetryCallback?: (file: string, destPath: string) => void;
56
- onFinalErrorCallback?: (accountId: number, file: string, destPath: string, error: AxiosError) => void;
56
+ onFinalErrorCallback?: (accountId: number, file: string, destPath: string, error: unknown) => void;
57
57
  };
58
58
  export type FilePathsByType = {
59
59
  [key: string]: Array<string>;
package/types/Http.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
+ import { ResponseType } from 'axios';
4
5
  import { ReadStream } from 'fs';
5
6
  import { Stream } from 'stream';
6
7
  export type Data = {
@@ -9,24 +10,19 @@ export type Data = {
9
10
  export type QueryParams = {
10
11
  [key: string]: string | number | boolean | undefined;
11
12
  };
12
- export type AxiosConfigOptions = {
13
+ export type FormData = {
14
+ [key: string]: string | ReadStream;
15
+ };
16
+ export type HttpOptions = {
13
17
  baseURL?: string;
14
18
  url: string;
15
19
  env?: string;
16
20
  localHostOverride?: boolean;
17
- params?: QueryParams;
18
21
  data?: Data | string | ArrayBuffer | ArrayBufferView | URLSearchParams | Stream | Buffer;
19
22
  resolveWithFullResponse?: boolean;
20
- timeout?: number;
21
- headers?: Data;
22
- };
23
- export type FormData = {
24
- [key: string]: string | ReadStream;
25
- };
26
- export type HttpOptions = AxiosConfigOptions & {
27
23
  params?: QueryParams;
28
24
  timeout?: number;
29
- responseType?: string;
25
+ responseType?: ResponseType;
30
26
  headers?: {
31
27
  [header: string]: string | string[] | undefined;
32
28
  };
@@ -47,11 +47,6 @@ type MutationError = {
47
47
  };
48
48
  };
49
49
  };
50
- export type SyncTaskStatusType = {
51
- status: string;
52
- result?: string;
53
- tasks: Pick<CompositeSyncTask, 'type' | 'status'>[];
54
- };
55
50
  type SyncMutationData = {
56
51
  numRequests: number;
57
52
  numSuccesses: number;
@@ -2,7 +2,7 @@
2
2
  import { Express, Request, Response } from 'express';
3
3
  import { Server } from 'http';
4
4
  import { RequestPortsData, ServerPortMap } from '../types/PortManager';
5
- declare class PortManagerServer {
5
+ declare class _PortManagerServer {
6
6
  app?: Express;
7
7
  server?: Server;
8
8
  serverPortMap: ServerPortMap;
@@ -22,5 +22,5 @@ declare class PortManagerServer {
22
22
  deleteServerInstance: (req: Request, res: Response) => void;
23
23
  closeServer: (req: Request, res: Response) => void;
24
24
  }
25
- declare const _default: PortManagerServer;
26
- export default _default;
25
+ export declare const PortManagerServer: _PortManagerServer;
26
+ export {};
@@ -3,15 +3,16 @@ 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 = 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 errors_1 = require("../errors");
11
12
  const logger_1 = require("../lib/logger");
12
13
  const lang_1 = require("./lang");
13
14
  const i18nKey = 'utils.PortManagerServer';
14
- class PortManagerServer {
15
+ class _PortManagerServer {
15
16
  app;
16
17
  server;
17
18
  serverPortMap;
@@ -20,7 +21,7 @@ class PortManagerServer {
20
21
  }
21
22
  async init() {
22
23
  if (this.app) {
23
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.duplicateInstance`);
24
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.duplicateInstance`));
24
25
  }
25
26
  this.app = (0, express_1.default)();
26
27
  this.app.use(express_1.default.json());
@@ -30,13 +31,12 @@ class PortManagerServer {
30
31
  this.server = await this.listen();
31
32
  }
32
33
  catch (e) {
33
- const error = e;
34
- if (error.code === 'EADDRINUSE') {
35
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.portInUse`, {
34
+ if ((0, errors_1.isSystemError)(e) && e.code === 'EADDRINUSE') {
35
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.portInUse`, {
36
36
  port: ports_1.PORT_MANAGER_SERVER_PORT,
37
- }, error);
37
+ }), { cause: e });
38
38
  }
39
- throw error;
39
+ throw e;
40
40
  }
41
41
  }
42
42
  reset() {
@@ -155,4 +155,4 @@ class PortManagerServer {
155
155
  }
156
156
  };
157
157
  }
158
- exports.default = new PortManagerServer();
158
+ exports.PortManagerServer = new _PortManagerServer();
@@ -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);
@@ -1,25 +0,0 @@
1
- import { AxiosError } from 'axios';
2
- import { AxiosErrorContext, ValidationError } from '../types/Error';
3
- import { HubSpotAuthError } from '../models/HubSpotAuthError';
4
- export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
5
- statusCode?: number;
6
- category?: string;
7
- subCategory?: string;
8
- errorType?: string;
9
- code?: string;
10
- }): boolean;
11
- export declare function isMissingScopeError(err: unknown): boolean;
12
- export declare function isGatingError(err: unknown): boolean;
13
- export declare function isTimeoutError(err: unknown): boolean;
14
- export declare function isApiUploadValidationError(err: unknown): boolean;
15
- export declare function isSpecifiedHubSpotAuthError(err: unknown, { status, category, subCategory }: Partial<HubSpotAuthError>): err is HubSpotAuthError;
16
- export declare function parseValidationErrors(responseData?: {
17
- errors?: Array<ValidationError>;
18
- message?: string;
19
- }): Array<string>;
20
- export declare function getAxiosErrorWithContext(error: AxiosError<any>, context?: AxiosErrorContext): Error;
21
- /**
22
- * @throws
23
- */
24
- export declare function throwApiError(error: unknown, context?: AxiosErrorContext): never;
25
- export declare function throwApiUploadError(error: AxiosError, context?: AxiosErrorContext): never;