@hubspot/local-dev-lib 1.13.0 → 2.0.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 (104) 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 +5 -5
  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 +2 -2
  54. package/lang/lang/en.json +2 -2
  55. package/lib/archive.js +11 -10
  56. package/lib/cms/functions.js +18 -17
  57. package/lib/cms/handleFieldsJS.js +8 -7
  58. package/lib/cms/modules.js +4 -5
  59. package/lib/cms/processFieldsJs.js +8 -7
  60. package/lib/cms/templates.js +2 -3
  61. package/lib/cms/uploadFolder.js +16 -14
  62. package/lib/cms/validate.js +1 -1
  63. package/lib/cms/watch.js +16 -9
  64. package/lib/customObjects.js +4 -15
  65. package/lib/fileManager.js +22 -21
  66. package/lib/fileMapper.js +24 -31
  67. package/lib/fs.js +2 -2
  68. package/lib/github.js +21 -21
  69. package/lib/gitignore.js +2 -2
  70. package/lib/hubdb.d.ts +3 -2
  71. package/lib/hubdb.js +11 -9
  72. package/lib/notify.js +2 -2
  73. package/lib/oauth.d.ts +1 -1
  74. package/lib/oauth.js +8 -17
  75. package/lib/personalAccessKey.js +16 -21
  76. package/lib/portManager.js +2 -2
  77. package/lib/trackUsage.js +12 -6
  78. package/models/FileSystemError.d.ts +6 -0
  79. package/models/FileSystemError.js +47 -0
  80. package/models/HubSpotHttpError.d.ts +24 -0
  81. package/models/HubSpotHttpError.js +197 -0
  82. package/models/OAuth2Manager.d.ts +1 -2
  83. package/models/OAuth2Manager.js +13 -28
  84. package/package.json +2 -1
  85. package/types/Error.d.ts +7 -5
  86. package/types/Files.d.ts +4 -4
  87. package/types/Http.d.ts +6 -10
  88. package/types/Sandbox.d.ts +0 -5
  89. package/utils/PortManagerServer.d.ts +3 -3
  90. package/utils/PortManagerServer.js +9 -9
  91. package/utils/cms/modules.js +2 -2
  92. package/utils/detectPort.js +3 -3
  93. package/errors/apiErrors.d.ts +0 -25
  94. package/errors/apiErrors.js +0 -176
  95. package/errors/fileSystemErrors.d.ts +0 -6
  96. package/errors/fileSystemErrors.js +0 -35
  97. package/errors/standardErrors.d.ts +0 -20
  98. package/errors/standardErrors.js +0 -62
  99. package/lib/developerTestAccounts.d.ts +0 -4
  100. package/lib/developerTestAccounts.js +0 -35
  101. package/lib/sandboxes.d.ts +0 -14
  102. package/lib/sandboxes.js +0 -70
  103. package/models/HubSpotAuthError.d.ts +0 -12
  104. package/models/HubSpotAuthError.js +0 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "1.13.0",
3
+ "version": "2.0.0",
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;
@@ -1,176 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwApiUploadError = exports.throwApiError = exports.getAxiosErrorWithContext = exports.parseValidationErrors = exports.isSpecifiedHubSpotAuthError = exports.isApiUploadValidationError = exports.isTimeoutError = exports.isGatingError = exports.isMissingScopeError = exports.isSpecifiedError = void 0;
4
- const axios_1 = require("axios");
5
- const api_1 = require("../constants/api");
6
- const lang_1 = require("../utils/lang");
7
- const standardErrors_1 = require("./standardErrors");
8
- const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
9
- const i18nKey = 'errors.apiErrors';
10
- function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
11
- if (!(err instanceof Error)) {
12
- return false;
13
- }
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- const error = (err && err.cause) || err;
16
- const statusCodeErr = !statusCode || error.response?.status === statusCode;
17
- const categoryErr = !category || error.response?.data?.category === category;
18
- const subCategoryErr = !subCategory || error.response?.data?.subCategory === subCategory;
19
- const errorTypeErr = !errorType || error.response?.data?.errorType === errorType;
20
- const codeError = !code || error.code === code;
21
- return (error.isAxiosError &&
22
- statusCodeErr &&
23
- categoryErr &&
24
- subCategoryErr &&
25
- errorTypeErr &&
26
- codeError);
27
- }
28
- exports.isSpecifiedError = isSpecifiedError;
29
- function isMissingScopeError(err) {
30
- return isSpecifiedError(err, { statusCode: 403, category: 'MISSING_SCOPES' });
31
- }
32
- exports.isMissingScopeError = isMissingScopeError;
33
- function isGatingError(err) {
34
- return isSpecifiedError(err, { statusCode: 403, category: 'GATED' });
35
- }
36
- exports.isGatingError = isGatingError;
37
- function isTimeoutError(err) {
38
- return isSpecifiedError(err, { code: 'ETIMEDOUT' });
39
- }
40
- exports.isTimeoutError = isTimeoutError;
41
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- function isApiUploadValidationError(err) {
43
- return ((0, axios_1.isAxiosError)(err) &&
44
- (err.status === 400 || err.response?.status === 400) &&
45
- !!err.response &&
46
- !!(err.response?.data?.message || !!err.response?.data?.errors));
47
- }
48
- exports.isApiUploadValidationError = isApiUploadValidationError;
49
- function isSpecifiedHubSpotAuthError(err, { status, category, subCategory }) {
50
- if (!err || !(err instanceof HubSpotAuthError_1.HubSpotAuthError)) {
51
- return false;
52
- }
53
- const statusCodeErr = !status || err.status === status;
54
- const categoryErr = !category || err.category === category;
55
- const subCategoryErr = !subCategory || err.subCategory === subCategory;
56
- return Boolean(statusCodeErr && categoryErr && subCategoryErr);
57
- }
58
- exports.isSpecifiedHubSpotAuthError = isSpecifiedHubSpotAuthError;
59
- function parseValidationErrors(responseData = { errors: [], message: '' }) {
60
- const errorMessages = [];
61
- const { errors, message } = responseData;
62
- if (message) {
63
- errorMessages.push(message);
64
- }
65
- if (errors) {
66
- const specificErrors = errors.map(error => {
67
- let errorMessage = error.message;
68
- if (error.errorTokens && error.errorTokens.line) {
69
- errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
70
- }
71
- return errorMessage;
72
- });
73
- errorMessages.push(...specificErrors);
74
- }
75
- return errorMessages;
76
- }
77
- exports.parseValidationErrors = parseValidationErrors;
78
- /**
79
- * @throws
80
- */
81
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
- function throwValidationError(error) {
83
- const validationErrorMessages = parseValidationErrors(error?.response?.data);
84
- if (validationErrorMessages.length) {
85
- return new Error(validationErrorMessages.join(' '), { cause: error });
86
- }
87
- }
88
- function getAxiosErrorWithContext(
89
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
- error, context = {}) {
91
- const status = error.response?.status;
92
- const method = error.config?.method;
93
- let messageDetail;
94
- if (context.accountId) {
95
- const action = (method && api_1.HTTP_METHOD_VERBS[method]) || api_1.HTTP_METHOD_VERBS.get;
96
- const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
97
- api_1.HTTP_METHOD_PREPOSITIONS.get;
98
- const requestName = context.request
99
- ? `${action} ${preposition} '${context.request}'`
100
- : action;
101
- messageDetail = (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
102
- accountId: context.accountId,
103
- requestName,
104
- });
105
- }
106
- else {
107
- messageDetail = (0, lang_1.i18n)(`${i18nKey}.genericMessageDetail`);
108
- }
109
- const errorMessage = [];
110
- if ((method === 'put' || method === 'post') && context.payload) {
111
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
112
- }
113
- switch (status) {
114
- case 400:
115
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
116
- break;
117
- case 401:
118
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
119
- break;
120
- case 403:
121
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.403`, { messageDetail }));
122
- break;
123
- case 404:
124
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
125
- break;
126
- case 429:
127
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
128
- break;
129
- case 503:
130
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
131
- break;
132
- default:
133
- if (status && status >= 500 && status < 600) {
134
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
135
- }
136
- else if (status && status >= 400 && status < 500) {
137
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
138
- }
139
- else {
140
- errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
141
- }
142
- break;
143
- }
144
- if (error?.response?.data) {
145
- const { message, errors } = error.response.data;
146
- if (message) {
147
- errorMessage.push(message);
148
- }
149
- if (errors) {
150
- errors.forEach((err) => {
151
- if (err.message) {
152
- errorMessage.push('\n- ' + err.message);
153
- }
154
- });
155
- }
156
- }
157
- return new Error(errorMessage.join(' '), { cause: error });
158
- }
159
- exports.getAxiosErrorWithContext = getAxiosErrorWithContext;
160
- /**
161
- * @throws
162
- */
163
- function throwApiError(error, context = {}) {
164
- if ((0, axios_1.isAxiosError)(error)) {
165
- throw getAxiosErrorWithContext(error, context);
166
- }
167
- (0, standardErrors_1.throwError)(error);
168
- }
169
- exports.throwApiError = throwApiError;
170
- function throwApiUploadError(error, context = {}) {
171
- if (isApiUploadValidationError(error)) {
172
- throwValidationError(error);
173
- }
174
- throwApiError(error, context);
175
- }
176
- exports.throwApiUploadError = throwApiUploadError;
@@ -1,6 +0,0 @@
1
- import { FileSystemErrorContext } from '../types/Error';
2
- export declare function getFileSystemError(error: unknown, context: FileSystemErrorContext): Error;
3
- /**
4
- * @throws
5
- */
6
- export declare function throwFileSystemError(error: unknown, 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;
@@ -1,20 +0,0 @@
1
- import { BaseError } from '../types/Error';
2
- import { LangKey } from '../types/Lang';
3
- export declare function isSystemError(err: unknown): err is BaseError;
4
- export declare function isFatalError(err: unknown): err is BaseError;
5
- /**
6
- * @throws
7
- */
8
- export declare function throwErrorWithMessage(identifier: LangKey, interpolation?: {
9
- [key: string]: string | number;
10
- }, cause?: unknown): never;
11
- /**
12
- * @throws
13
- */
14
- export declare function throwAuthErrorWithMessage(identifier: LangKey, interpolation?: {
15
- [key: string]: string | number;
16
- }, cause?: unknown): never;
17
- /**
18
- * @throws
19
- */
20
- export declare function throwError(error: unknown): never;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwError = exports.throwAuthErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
4
- const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
5
- const lang_1 = require("../utils/lang");
6
- function isSystemError(err) {
7
- return (err instanceof Error &&
8
- 'errno' in err &&
9
- err.errno != null &&
10
- 'code' in err &&
11
- err.code != null &&
12
- 'syscall' in err &&
13
- err.syscall != null);
14
- }
15
- exports.isSystemError = isSystemError;
16
- function isFatalError(err) {
17
- return err instanceof HubSpotAuthError_1.HubSpotAuthError;
18
- }
19
- exports.isFatalError = isFatalError;
20
- function genericThrowErrorWithMessage(ErrorType, identifier, interpolation, cause) {
21
- const message = (0, lang_1.i18n)(identifier, interpolation);
22
- if (cause) {
23
- throw new ErrorType(message, { cause });
24
- }
25
- throw new ErrorType(message);
26
- }
27
- /**
28
- * @throws
29
- */
30
- function throwErrorWithMessage(identifier, interpolation, cause) {
31
- genericThrowErrorWithMessage(Error, identifier, interpolation, cause);
32
- }
33
- exports.throwErrorWithMessage = throwErrorWithMessage;
34
- /**
35
- * @throws
36
- */
37
- function throwAuthErrorWithMessage(identifier, interpolation, cause) {
38
- genericThrowErrorWithMessage(
39
- // @ts-expect-error HubSpotAuthError is not callable
40
- HubSpotAuthError_1.HubSpotAuthError, identifier, interpolation, cause);
41
- }
42
- exports.throwAuthErrorWithMessage = throwAuthErrorWithMessage;
43
- /**
44
- * @throws
45
- */
46
- function throwError(error) {
47
- if (!(error instanceof Error)) {
48
- throw new Error('', { cause: error });
49
- }
50
- // Error or Error subclass
51
- const message = error.name && error.name !== 'Error'
52
- ? [(0, lang_1.i18n)('errors.generic', { name: error.name })]
53
- : [];
54
- if (error.message) {
55
- message.push(error.message);
56
- }
57
- if ('reason' in error && error.reason) {
58
- message.push(error.reason);
59
- }
60
- throw new Error(message.join(' '), { cause: error });
61
- }
62
- exports.throwError = throwError;
@@ -1,4 +0,0 @@
1
- import { DeveloperTestAccount, FetchDeveloperTestAccountsResponse } from '../types/developerTestAccounts';
2
- export declare function createDeveloperTestAccount(accountId: number, accountName: string): Promise<DeveloperTestAccount>;
3
- export declare function deleteDeveloperTestAccount(accountId: number, testAccountId: number): Promise<void>;
4
- export declare function fetchDeveloperTestAccounts(accountId: number): Promise<FetchDeveloperTestAccountsResponse>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchDeveloperTestAccounts = exports.deleteDeveloperTestAccount = exports.createDeveloperTestAccount = void 0;
4
- const developerTestAccounts_1 = require("../api/developerTestAccounts");
5
- const apiErrors_1 = require("../errors/apiErrors");
6
- async function createDeveloperTestAccount(accountId, accountName) {
7
- try {
8
- const resp = await (0, developerTestAccounts_1.createDeveloperTestAccount)(accountId, accountName);
9
- return resp;
10
- }
11
- catch (err) {
12
- (0, apiErrors_1.throwApiError)(err);
13
- }
14
- }
15
- exports.createDeveloperTestAccount = createDeveloperTestAccount;
16
- async function deleteDeveloperTestAccount(accountId, testAccountId) {
17
- try {
18
- const resp = await (0, developerTestAccounts_1.deleteDeveloperTestAccount)(accountId, testAccountId);
19
- return resp;
20
- }
21
- catch (err) {
22
- (0, apiErrors_1.throwApiError)(err);
23
- }
24
- }
25
- exports.deleteDeveloperTestAccount = deleteDeveloperTestAccount;
26
- async function fetchDeveloperTestAccounts(accountId) {
27
- try {
28
- const resp = await (0, developerTestAccounts_1.fetchDeveloperTestAccounts)(accountId);
29
- return resp;
30
- }
31
- catch (err) {
32
- (0, apiErrors_1.throwApiError)(err);
33
- }
34
- }
35
- exports.fetchDeveloperTestAccounts = fetchDeveloperTestAccounts;
@@ -1,14 +0,0 @@
1
- import { InitiateSyncResponse, Sandbox, SandboxType, SyncTaskStatusType, TaskRequestData, Usage } from '../types/Sandbox';
2
- export declare function createSandbox(accountId: number, name: string, type: 1 | 2): Promise<{
3
- name: string;
4
- sandbox: Sandbox;
5
- personalAccessKey: string;
6
- }>;
7
- export declare function deleteSandbox(parentAccountId: number, sandboxAccountId: number): Promise<{
8
- parentAccountId: number;
9
- sandboxAccountId: number;
10
- }>;
11
- export declare function getSandboxUsageLimits(parentAccountId: number): Promise<Usage | void>;
12
- export declare function initiateSync(fromHubId: number, toHubId: number, tasks: Array<TaskRequestData>, sandboxHubId: number): Promise<InitiateSyncResponse>;
13
- export declare function fetchTaskStatus(accountId: number, taskId: number): Promise<SyncTaskStatusType>;
14
- export declare function fetchTypes(accountId: number, toHubId: number): Promise<Array<SandboxType> | void>;