@hubspot/local-dev-lib 0.0.6 → 0.0.7

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.
@@ -1,9 +1,23 @@
1
- import { StatusCodeError, StatusCodeErrorContext } from '../types/Error';
2
- import { HubSpotAuthError } from './HubSpotAuthError';
3
- export declare function isMissingScopeError(err: StatusCodeError): boolean;
4
- export declare function isGatingError(err: StatusCodeError): boolean;
5
- export declare function isSpecifiedHubSpotAuthError(err: HubSpotAuthError, { statusCode, category, subCategory }: Partial<HubSpotAuthError>): boolean;
1
+ import { GenericError, StatusCodeError, StatusCodeErrorContext } from '../types/Error';
2
+ import { HubSpotAuthError } from '../models/HubSpotAuthError';
3
+ export declare function isApiStatusCodeError(err: GenericError): boolean;
4
+ export declare function isMissingScopeError(err: GenericError): boolean;
5
+ export declare function isGatingError(err: GenericError): boolean;
6
+ export declare function isApiUploadValidationError(err: GenericError): boolean;
7
+ export declare function isSpecifiedHubSpotAuthError(err: GenericError, { statusCode, category, subCategory }: Partial<HubSpotAuthError>): boolean;
8
+ /**
9
+ * @throws
10
+ */
6
11
  export declare function throwStatusCodeError(error: StatusCodeError, context?: StatusCodeErrorContext): never;
7
- export declare function throwApiStatusCodeError(error: StatusCodeError, context: StatusCodeErrorContext): never;
8
- export declare function throwApiError(error: StatusCodeError, context: StatusCodeErrorContext): never;
9
- export declare function throwApiUploadError(error: StatusCodeError, context: StatusCodeErrorContext): never;
12
+ /**
13
+ * @throws
14
+ */
15
+ export declare function throwApiStatusCodeError(error: StatusCodeError, context?: StatusCodeErrorContext): never;
16
+ /**
17
+ * @throws
18
+ */
19
+ export declare function throwApiError(error: StatusCodeError, context?: StatusCodeErrorContext): never;
20
+ /**
21
+ * @throws
22
+ */
23
+ export declare function throwApiUploadError(error: StatusCodeError, context?: StatusCodeErrorContext): never;
@@ -1,38 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwApiUploadError = exports.throwApiError = exports.throwApiStatusCodeError = exports.throwStatusCodeError = exports.isSpecifiedHubSpotAuthError = exports.isGatingError = exports.isMissingScopeError = void 0;
3
+ exports.throwApiUploadError = exports.throwApiError = exports.throwApiStatusCodeError = exports.throwStatusCodeError = exports.isSpecifiedHubSpotAuthError = exports.isApiUploadValidationError = exports.isGatingError = exports.isMissingScopeError = exports.isApiStatusCodeError = void 0;
4
4
  const api_1 = require("../constants/api");
5
5
  const lang_1 = require("../utils/lang");
6
6
  const standardErrors_1 = require("./standardErrors");
7
7
  function isApiStatusCodeError(err) {
8
8
  return (err.name === 'StatusCodeError' ||
9
- (err.statusCode && err.statusCode >= 100 && err.statusCode < 600));
9
+ (!!err.statusCode && err.statusCode >= 100 && err.statusCode < 600));
10
10
  }
11
+ exports.isApiStatusCodeError = isApiStatusCodeError;
11
12
  function isMissingScopeError(err) {
12
- return Boolean(err.name === 'StatusCodeError' &&
13
+ return (isApiStatusCodeError(err) &&
13
14
  err.statusCode === 403 &&
14
- err.error &&
15
+ !!err.error &&
15
16
  err.error.category === 'MISSING_SCOPES');
16
17
  }
17
18
  exports.isMissingScopeError = isMissingScopeError;
18
19
  function isGatingError(err) {
19
- return Boolean(err.name === 'StatusCodeError' &&
20
+ return (isApiStatusCodeError(err) &&
20
21
  err.statusCode === 403 &&
21
- err.error &&
22
+ !!err.error &&
22
23
  err.error.category === 'GATED');
23
24
  }
24
25
  exports.isGatingError = isGatingError;
25
26
  function isApiUploadValidationError(err) {
26
- return Boolean(err.statusCode === 400 &&
27
- err.response &&
28
- err.response.body &&
29
- (err.response.body.message || err.response.body.errors));
27
+ return (isApiStatusCodeError(err) &&
28
+ err.statusCode === 400 &&
29
+ !!err.response &&
30
+ !!err.response.body &&
31
+ !!(err.response.body.message || !!err.response.body.errors));
30
32
  }
33
+ exports.isApiUploadValidationError = isApiUploadValidationError;
31
34
  function isSpecifiedHubSpotAuthError(err, { statusCode, category, subCategory }) {
32
35
  const statusCodeErr = !statusCode || err.statusCode === statusCode;
33
36
  const categoryErr = !category || err.category === category;
34
37
  const subCategoryErr = !subCategory || err.subCategory === subCategory;
35
- return (err.name === 'HubSpotAuthError' &&
38
+ return Boolean(err.name === 'HubSpotAuthError' &&
36
39
  statusCodeErr &&
37
40
  categoryErr &&
38
41
  subCategoryErr);
@@ -63,22 +66,28 @@ function logValidationErrors(error) {
63
66
  (0, standardErrors_1.throwError)(new Error(validationErrorMessages.join(' '), { cause: error }));
64
67
  }
65
68
  }
69
+ /**
70
+ * @throws
71
+ */
66
72
  function throwStatusCodeError(error, context = {}) {
67
73
  const { statusCode, message, response } = error;
68
74
  const errorData = JSON.stringify({
69
75
  statusCode,
70
76
  message,
71
- url: response.request.href,
72
- method: response.request.method,
73
- response: response.body,
74
- headers: response.headers,
77
+ url: response ? response.request.href : null,
78
+ method: response ? response.request.method : null,
79
+ response: response ? response.body : null,
80
+ headers: response ? response.headers : null,
75
81
  context,
76
82
  });
77
83
  throw new Error(errorData, { cause: error });
78
84
  }
79
85
  exports.throwStatusCodeError = throwStatusCodeError;
80
- function throwApiStatusCodeError(error, context) {
81
- const i18nKey = 'errors.api';
86
+ /**
87
+ * @throws
88
+ */
89
+ function throwApiStatusCodeError(error, context = {}) {
90
+ const i18nKey = 'errors.errorTypes.api';
82
91
  const { statusCode } = error;
83
92
  const { method } = error.options || {};
84
93
  const { projectName } = context;
@@ -166,14 +175,20 @@ function throwApiStatusCodeError(error, context) {
166
175
  (0, standardErrors_1.throwError)(new Error(errorMessage.join(' '), { cause: error }));
167
176
  }
168
177
  exports.throwApiStatusCodeError = throwApiStatusCodeError;
169
- function throwApiError(error, context) {
178
+ /**
179
+ * @throws
180
+ */
181
+ function throwApiError(error, context = {}) {
170
182
  if (isApiStatusCodeError(error)) {
171
183
  throwApiStatusCodeError(error, context);
172
184
  }
173
185
  (0, standardErrors_1.throwError)(error);
174
186
  }
175
187
  exports.throwApiError = throwApiError;
176
- function throwApiUploadError(error, context) {
188
+ /**
189
+ * @throws
190
+ */
191
+ function throwApiUploadError(error, context = {}) {
177
192
  if (isApiUploadValidationError(error)) {
178
193
  logValidationErrors(error);
179
194
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.throwError = exports.throwAuthErrorWithMessage = exports.throwTypeErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
4
- const HubSpotAuthError_1 = require("./HubSpotAuthError");
4
+ const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
5
5
  const lang_1 = require("../utils/lang");
6
6
  const apiErrors_1 = require("./apiErrors");
7
7
  function isSystemError(err) {
package/lang/en.lyaml CHANGED
@@ -134,8 +134,8 @@ en:
134
134
  logging:
135
135
  creatingFile: "Creating file at {{ path }}"
136
136
  processFieldsJs:
137
- converting: "Converting \"{{ src }}\" to \"{{ dest }}\"."
138
- converted: "Finished converting \"{{ src }}\" to \"{{ dest }}\"."
137
+ converting: 'Converting "{{ src }}" to "{{ dest }}".'
138
+ converted: 'Finished converting "{{ src }}" to "{{ dest }}".'
139
139
  errors:
140
140
  hubdb:
141
141
  invalidJsonPath: "The HubDB table file must be a '.json' file"
@@ -242,6 +242,6 @@ en:
242
242
  fetchTaskStatus: "There was an error fetching the task status while syncing sandboxes."
243
243
  fetchTypes: "There was an error fetching sandbox types."
244
244
  processFieldsJs:
245
- fieldsJsNotReturnArray: "There was an error loading JS file \"{{ path }}\". Expected type \"Array\". Make sure that your function returns an array"
246
- fieldsJsNotFunction: "There was an error loading JS file \"{{ path }}\". Expected type \"Function\". Make sure that your default export is a function."
245
+ fieldsJsNotReturnArray: 'There was an error loading JS file "{{ path }}". Expected type "Array". Make sure that your function returns an array'
246
+ fieldsJsNotFunction: 'There was an error loading JS file "{{ path }}". Expected type "Function". Make sure that your default export is a function.'
247
247
  invalidMjsFile: ".mjs files are only supported when using Node 13.2.0+"
@@ -1,7 +1,23 @@
1
- import { Mode, FileMapperOptions, FileMapperInputOptions } from '../types/Files';
1
+ import { FileMapperNode, Mode, FileMapperOptions, FileMapperInputOptions } from '../types/Files';
2
2
  import { LogCallbacksArg } from '../types/LogCallbacks';
3
- export declare function getFileMapperQueryValues(mode: Mode | null, { staging, assetVersion }: FileMapperInputOptions): FileMapperOptions;
3
+ export declare function isPathToFile(filepath: string): boolean;
4
+ export declare function isPathToModule(filepath: string): boolean;
5
+ export declare function isPathToRoot(filepath: string): boolean;
6
+ export declare function isPathToHubspot(filepath: string): boolean;
7
+ export declare function getFileMapperQueryValues(mode?: Mode | null, { staging, assetVersion }?: FileMapperInputOptions): FileMapperOptions;
8
+ type PathTypeData = {
9
+ isModule: boolean;
10
+ isHubspot: boolean;
11
+ isFile: boolean;
12
+ isRoot: boolean;
13
+ isFolder: boolean;
14
+ };
15
+ export declare function getTypeDataFromPath(src: string): PathTypeData;
16
+ type RecursiveFileMapperCallback = (node: FileMapperNode, filepath?: string, depth?: number) => boolean;
17
+ export declare function recurseFolder(node: FileMapperNode, callback: RecursiveFileMapperCallback, filepath?: string, depth?: number): boolean;
18
+ export declare function writeUtimes(accountId: number, filepath: string, node: FileMapperNode): Promise<void>;
4
19
  declare const filemapperCallbackKeys: string[];
20
+ export declare function fetchFolderFromApi(accountId: number, src: string, mode?: Mode, options?: FileMapperInputOptions, logCallbacks?: LogCallbacksArg<typeof filemapperCallbackKeys>): Promise<FileMapperNode>;
5
21
  /**
6
22
  * Fetch a file/folder and write to local file system.
7
23
  *
@@ -9,5 +25,5 @@ declare const filemapperCallbackKeys: string[];
9
25
  * @param {FileMapperInputArguments} input
10
26
  * @returns {Promise}
11
27
  */
12
- export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, mode: Mode, options: FileMapperInputOptions | undefined, logCallbacks: LogCallbacksArg<typeof filemapperCallbackKeys>): Promise<void>;
28
+ export declare function downloadFileOrFolder(accountId: number, src: string, dest: string, mode?: Mode, options?: FileMapperInputOptions, logCallbacks?: LogCallbacksArg<typeof filemapperCallbackKeys>): Promise<void>;
13
29
  export {};
package/lib/fileMapper.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.downloadFileOrFolder = exports.getFileMapperQueryValues = void 0;
6
+ exports.downloadFileOrFolder = exports.fetchFolderFromApi = exports.writeUtimes = exports.recurseFolder = exports.getTypeDataFromPath = exports.getFileMapperQueryValues = exports.isPathToHubspot = exports.isPathToRoot = exports.isPathToModule = exports.isPathToFile = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const p_queue_1 = __importDefault(require("p-queue"));
@@ -22,26 +22,30 @@ function isPathToFile(filepath) {
22
22
  const ext = (0, path_2.getExt)(filepath);
23
23
  return !!ext && ext !== extensions_1.MODULE_EXTENSION && ext !== extensions_1.FUNCTIONS_EXTENSION;
24
24
  }
25
+ exports.isPathToFile = isPathToFile;
25
26
  function isPathToModule(filepath) {
26
27
  const ext = (0, path_2.getExt)(filepath);
27
28
  return ext === extensions_1.MODULE_EXTENSION;
28
29
  }
30
+ exports.isPathToModule = isPathToModule;
29
31
  function isPathToRoot(filepath) {
30
32
  if (typeof filepath !== 'string')
31
33
  return false;
32
34
  // Root pattern matches empty strings and: / \
33
35
  return /^(\/|\\)?$/.test(filepath.trim());
34
36
  }
37
+ exports.isPathToRoot = isPathToRoot;
35
38
  function isPathToHubspot(filepath) {
36
39
  if (typeof filepath !== 'string')
37
40
  return false;
38
41
  return /^(\/|\\)?@hubspot/i.test(filepath.trim());
39
42
  }
43
+ exports.isPathToHubspot = isPathToHubspot;
40
44
  function useApiBuffer(mode) {
41
45
  return mode === files_1.MODE.draft;
42
46
  }
43
47
  // Determines API param based on mode an options
44
- function getFileMapperQueryValues(mode, { staging, assetVersion }) {
48
+ function getFileMapperQueryValues(mode, { staging, assetVersion } = {}) {
45
49
  return {
46
50
  params: {
47
51
  buffer: useApiBuffer(mode),
@@ -88,6 +92,7 @@ function getTypeDataFromPath(src) {
88
92
  isFolder,
89
93
  };
90
94
  }
95
+ exports.getTypeDataFromPath = getTypeDataFromPath;
91
96
  function recurseFolder(node, callback, filepath = '', depth = 0) {
92
97
  validateFileMapperNode(node);
93
98
  const isRootFolder = node.folder && depth === 0;
@@ -108,6 +113,7 @@ function recurseFolder(node, callback, filepath = '', depth = 0) {
108
113
  });
109
114
  return depth === 0 ? false : __break;
110
115
  }
116
+ exports.recurseFolder = recurseFolder;
111
117
  async function writeUtimes(accountId, filepath, node) {
112
118
  try {
113
119
  const now = new Date();
@@ -123,6 +129,7 @@ async function writeUtimes(accountId, filepath, node) {
123
129
  });
124
130
  }
125
131
  }
132
+ exports.writeUtimes = writeUtimes;
126
133
  async function skipExisting(filepath, overwrite = false) {
127
134
  if (overwrite) {
128
135
  return false;
@@ -145,9 +152,9 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
145
152
  if (!(0, path_2.isAllowedExtension)(srcPath)) {
146
153
  (0, standardErrors_1.throwErrorWithMessage)('filemapper.invalidFileType', { srcPath });
147
154
  }
155
+ let node;
148
156
  try {
149
- const node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
150
- await writeUtimes(accountId, filepath, node);
157
+ node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
151
158
  }
152
159
  catch (err) {
153
160
  (0, apiErrors_1.throwStatusCodeError)(err, {
@@ -155,6 +162,7 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
155
162
  request: srcPath,
156
163
  });
157
164
  }
165
+ await writeUtimes(accountId, filepath, node);
158
166
  }
159
167
  // Writes an individual file or folder (not recursive). If file source is missing, the
160
168
  //file is fetched.
@@ -263,6 +271,7 @@ async function fetchFolderFromApi(accountId, src, mode, options = {}, logCallbac
263
271
  }
264
272
  }
265
273
  }
274
+ exports.fetchFolderFromApi = fetchFolderFromApi;
266
275
  async function downloadFolder(accountId, src, destPath, mode, options = {}, logCallbacks) {
267
276
  const logger = (0, logger_1.makeTypedLogger)(logCallbacks, 'filemapper');
268
277
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -12,14 +12,12 @@
12
12
  "access": "public"
13
13
  },
14
14
  "scripts": {
15
- "build": "rm -rf ./dist/ && tsc --rootDir . --outdir dist && yarn copy-files",
15
+ "build": "rm -rf ./dist/ && tsc --rootDir . --outdir dist && yarn copy-files && yarn clear-postinstall",
16
16
  "check-main": "branch=$(git rev-parse --abbrev-ref HEAD) && [ $branch = main ] || (echo 'Error: New release can only be published on main branch' && exit 1)",
17
+ "clear-postinstall": "cd dist && npm pkg delete scripts.postinstall",
17
18
  "copy-files": "cp -r lang dist/lang",
18
19
  "lint": "eslint --max-warnings=0 . && prettier --check ./**/*.ts",
19
20
  "local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
20
- "postinstall": "husky install",
21
- "prepack": "pinst --disable",
22
- "postpack": "pinst --enable",
23
21
  "prettier:write": "prettier --write ./**/*.{ts,js,json}",
24
22
  "pub": "cd dist && npm publish --tag latest && cd ..",
25
23
  "push": "git push --atomic origin main v$npm_package_version",
@@ -44,7 +42,6 @@
44
42
  "eslint": "^8.35.0",
45
43
  "husky": "^8.0.0",
46
44
  "jest": "^29.5.0",
47
- "pinst": "^3.0.0",
48
45
  "ts-jest": "^29.0.5",
49
46
  "typescript": "^4.9.5"
50
47
  },
package/types/Error.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { HttpMethod } from './Api';
2
+ export interface GenericError extends Error {
3
+ [key: string]: any;
4
+ }
2
5
  export interface BaseError extends Error {
3
6
  name: string;
4
7
  message: string;
File without changes
File without changes