@hubspot/local-dev-lib 1.7.0 → 1.9.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.
package/api/projects.d.ts CHANGED
@@ -5,7 +5,7 @@ import { Build, FetchProjectBuildsResponse } from '../types/Build';
5
5
  import { ComponentMetadataResponse, ComponentStructureResponse } from '../types/ComponentStructure';
6
6
  import { Deploy, ProjectDeployResponse } from '../types/Deploy';
7
7
  import { ProjectLog } from '../types/ProjectLog';
8
- import { MigrateAppResponse, PollAppResponse } from '../types/Migration';
8
+ import { MigrateAppResponse, CloneAppResponse, PollAppResponse } from '../types/Migration';
9
9
  export declare function fetchProjects(accountId: number): Promise<FetchProjectResponse>;
10
10
  export declare function createProject(accountId: number, name: string): Promise<Project>;
11
11
  export declare function uploadProject(accountId: number, projectName: string, projectFile: string, uploadMessage: string, platformVersion?: string): Promise<UploadProjectResponse>;
@@ -38,4 +38,7 @@ export declare function fetchDeployWarnLogs(accountId: number, projectName: stri
38
38
  }>;
39
39
  export declare function migrateApp(accountId: number, appId: number, projectName: string): Promise<MigrateAppResponse>;
40
40
  export declare function checkMigrationStatus(accountId: number, id: number): Promise<PollAppResponse>;
41
+ export declare function cloneApp(accountId: number, appId: number): Promise<CloneAppResponse>;
42
+ export declare function checkCloneStatus(accountId: number, exportId: number): Promise<CloneAppResponse>;
43
+ export declare function downloadClonedProject(accountId: number, exportId: number): Promise<Buffer>;
41
44
  export {};
package/api/projects.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.checkMigrationStatus = exports.migrateApp = exports.fetchDeployWarnLogs = exports.fetchBuildWarnLogs = exports.cancelStagedBuild = exports.deleteFileFromBuild = exports.uploadFileToBuild = exports.queueBuild = exports.provisionBuild = exports.fetchDeployComponentsMetadata = exports.fetchProjectSettings = exports.getDeployStructure = exports.getDeployStatus = exports.deployProject = exports.getBuildStructure = exports.getBuildStatus = exports.fetchProjectBuilds = exports.fetchPlatformVersions = exports.deleteProject = exports.downloadProject = exports.fetchProject = exports.uploadProject = exports.createProject = exports.fetchProjects = void 0;
6
+ exports.downloadClonedProject = exports.checkCloneStatus = exports.cloneApp = exports.checkMigrationStatus = exports.migrateApp = exports.fetchDeployWarnLogs = exports.fetchBuildWarnLogs = exports.cancelStagedBuild = exports.deleteFileFromBuild = exports.uploadFileToBuild = exports.queueBuild = exports.provisionBuild = exports.fetchDeployComponentsMetadata = exports.fetchProjectSettings = exports.getDeployStructure = exports.getDeployStatus = exports.deployProject = exports.getBuildStructure = exports.getBuildStatus = exports.fetchProjectBuilds = exports.fetchPlatformVersions = exports.deleteProject = exports.downloadProject = exports.fetchProject = exports.uploadProject = exports.createProject = exports.fetchProjects = void 0;
7
7
  const http_1 = __importDefault(require("../http"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const PROJECTS_API_PATH = 'dfs/v1/projects';
@@ -190,3 +190,26 @@ async function checkMigrationStatus(accountId, id) {
190
190
  });
191
191
  }
192
192
  exports.checkMigrationStatus = checkMigrationStatus;
193
+ async function cloneApp(accountId, appId) {
194
+ return http_1.default.post(accountId, {
195
+ url: `${MIGRATIONS_API_PATH}/exports`,
196
+ data: {
197
+ componentId: appId,
198
+ componentType: 'PUBLIC_APP_ID',
199
+ },
200
+ });
201
+ }
202
+ exports.cloneApp = cloneApp;
203
+ async function checkCloneStatus(accountId, exportId) {
204
+ return http_1.default.get(accountId, {
205
+ url: `${MIGRATIONS_API_PATH}/exports/${exportId}/status`,
206
+ });
207
+ }
208
+ exports.checkCloneStatus = checkCloneStatus;
209
+ async function downloadClonedProject(accountId, exportId) {
210
+ return http_1.default.get(accountId, {
211
+ url: `${MIGRATIONS_API_PATH}/exports/${exportId}/download-as-clone`,
212
+ responseType: 'arraybuffer',
213
+ });
214
+ }
215
+ exports.downloadClonedProject = downloadClonedProject;
@@ -1,18 +1,18 @@
1
1
  import { AxiosError } from 'axios';
2
- import { GenericError, AxiosErrorContext, ValidationError } from '../types/Error';
2
+ import { AxiosErrorContext, ValidationError } from '../types/Error';
3
3
  import { HubSpotAuthError } from '../models/HubSpotAuthError';
4
- export declare function isSpecifiedError(err: Error | AxiosError, { statusCode, category, subCategory, errorType, code, }: {
4
+ export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
5
5
  statusCode?: number;
6
6
  category?: string;
7
7
  subCategory?: string;
8
8
  errorType?: string;
9
9
  code?: string;
10
10
  }): boolean;
11
- export declare function isMissingScopeError(err: Error | AxiosError): boolean;
12
- export declare function isGatingError(err: Error | AxiosError): boolean;
13
- export declare function isTimeoutError(err: Error | AxiosError): boolean;
14
- export declare function isApiUploadValidationError(err: AxiosError<any>): boolean;
15
- export declare function isSpecifiedHubSpotAuthError(err: GenericError, { status, category, subCategory }: Partial<HubSpotAuthError>): 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
16
  export declare function parseValidationErrors(responseData?: {
17
17
  errors?: Array<ValidationError>;
18
18
  message?: string;
@@ -21,5 +21,5 @@ export declare function getAxiosErrorWithContext(error: AxiosError<any>, context
21
21
  /**
22
22
  * @throws
23
23
  */
24
- export declare function throwApiError(error: AxiosError, context?: AxiosErrorContext): never;
24
+ export declare function throwApiError(error: unknown, context?: AxiosErrorContext): never;
25
25
  export declare function throwApiUploadError(error: AxiosError, context?: AxiosErrorContext): never;
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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");
4
5
  const api_1 = require("../constants/api");
5
6
  const lang_1 = require("../utils/lang");
6
7
  const standardErrors_1 = require("./standardErrors");
8
+ const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
7
9
  const i18nKey = 'errors.apiErrors';
8
10
  function isSpecifiedError(err, { statusCode, category, subCategory, errorType, code, }) {
11
+ if (!(err instanceof Error)) {
12
+ return false;
13
+ }
9
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
15
  const error = (err && err.cause) || err;
11
16
  const statusCodeErr = !statusCode || error.response?.status === statusCode;
@@ -35,20 +40,20 @@ function isTimeoutError(err) {
35
40
  exports.isTimeoutError = isTimeoutError;
36
41
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
42
  function isApiUploadValidationError(err) {
38
- return (err.isAxiosError &&
43
+ return ((0, axios_1.isAxiosError)(err) &&
39
44
  (err.status === 400 || err.response?.status === 400) &&
40
45
  !!err.response &&
41
46
  !!(err.response?.data?.message || !!err.response?.data?.errors));
42
47
  }
43
48
  exports.isApiUploadValidationError = isApiUploadValidationError;
44
49
  function isSpecifiedHubSpotAuthError(err, { status, category, subCategory }) {
50
+ if (!err || !(err instanceof HubSpotAuthError_1.HubSpotAuthError)) {
51
+ return false;
52
+ }
45
53
  const statusCodeErr = !status || err.status === status;
46
54
  const categoryErr = !category || err.category === category;
47
55
  const subCategoryErr = !subCategory || err.subCategory === subCategory;
48
- return Boolean(err.name === 'HubSpotAuthError' &&
49
- statusCodeErr &&
50
- categoryErr &&
51
- subCategoryErr);
56
+ return Boolean(statusCodeErr && categoryErr && subCategoryErr);
52
57
  }
53
58
  exports.isSpecifiedHubSpotAuthError = isSpecifiedHubSpotAuthError;
54
59
  function parseValidationErrors(responseData = { errors: [], message: '' }) {
@@ -171,7 +176,7 @@ exports.getAxiosErrorWithContext = getAxiosErrorWithContext;
171
176
  * @throws
172
177
  */
173
178
  function throwApiError(error, context = {}) {
174
- if (error.isAxiosError) {
179
+ if ((0, axios_1.isAxiosError)(error)) {
175
180
  throw getAxiosErrorWithContext(error, context);
176
181
  }
177
182
  (0, standardErrors_1.throwError)(error);
@@ -1,6 +1,6 @@
1
- import { BaseError, FileSystemErrorContext } from '../types/Error';
2
- export declare function getFileSystemError(error: BaseError, context: FileSystemErrorContext): Error;
1
+ import { FileSystemErrorContext } from '../types/Error';
2
+ export declare function getFileSystemError(error: unknown, context: FileSystemErrorContext): Error;
3
3
  /**
4
4
  * @throws
5
5
  */
6
- export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
6
+ export declare function throwFileSystemError(error: unknown, context: FileSystemErrorContext): void;
@@ -1,21 +1,20 @@
1
1
  import { BaseError } from '../types/Error';
2
2
  import { LangKey } from '../types/Lang';
3
- import { AxiosError } from 'axios';
4
- export declare function isSystemError(err: BaseError): boolean;
5
- export declare function isFatalError(err: BaseError): boolean;
3
+ export declare function isSystemError(err: unknown): err is BaseError;
4
+ export declare function isFatalError(err: unknown): err is BaseError;
6
5
  /**
7
6
  * @throws
8
7
  */
9
8
  export declare function throwErrorWithMessage(identifier: LangKey, interpolation?: {
10
9
  [key: string]: string | number;
11
- }, cause?: BaseError | AxiosError): never;
10
+ }, cause?: unknown): never;
12
11
  /**
13
12
  * @throws
14
13
  */
15
14
  export declare function throwAuthErrorWithMessage(identifier: LangKey, interpolation?: {
16
15
  [key: string]: string | number;
17
- }, cause?: AxiosError): never;
16
+ }, cause?: unknown): never;
18
17
  /**
19
18
  * @throws
20
19
  */
21
- export declare function throwError(error: BaseError): never;
20
+ export declare function throwError(error: unknown): never;
@@ -4,7 +4,13 @@ exports.throwError = exports.throwAuthErrorWithMessage = exports.throwErrorWithM
4
4
  const HubSpotAuthError_1 = require("../models/HubSpotAuthError");
5
5
  const lang_1 = require("../utils/lang");
6
6
  function isSystemError(err) {
7
- return err.errno != null && err.code != null && err.syscall != null;
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);
8
14
  }
9
15
  exports.isSystemError = isSystemError;
10
16
  function isFatalError(err) {
@@ -38,15 +44,19 @@ exports.throwAuthErrorWithMessage = throwAuthErrorWithMessage;
38
44
  * @throws
39
45
  */
40
46
  function throwError(error) {
47
+ if (!(error instanceof Error)) {
48
+ throw new Error('', { cause: error });
49
+ }
41
50
  // Error or Error subclass
42
51
  const message = error.name && error.name !== 'Error'
43
52
  ? [(0, lang_1.i18n)('errors.generic', { name: error.name })]
44
53
  : [];
45
- [error.message, error.reason].forEach(msg => {
46
- if (msg) {
47
- message.push(msg);
48
- }
49
- });
54
+ if (error.message) {
55
+ message.push(error.message);
56
+ }
57
+ if ('reason' in error && error.reason) {
58
+ message.push(error.reason);
59
+ }
50
60
  throw new Error(message.join(' '), { cause: error });
51
61
  }
52
62
  exports.throwError = throwError;
@@ -38,9 +38,8 @@ async function uploadFolder(accountId, src, dest) {
38
38
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.uploadSuccess`, { file, destPath }));
39
39
  }
40
40
  catch (err) {
41
- const error = err;
42
- if ((0, standardErrors_1.isFatalError)(error)) {
43
- (0, standardErrors_1.throwError)(error);
41
+ if ((0, standardErrors_1.isFatalError)(err)) {
42
+ (0, standardErrors_1.throwError)(err);
44
43
  }
45
44
  (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.uploadFailed`, {
46
45
  file,
package/lib/github.js CHANGED
@@ -38,8 +38,7 @@ async function fetchReleaseData(repoPath, tag) {
38
38
  return data;
39
39
  }
40
40
  catch (err) {
41
- const error = err;
42
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, { tag: tag || 'latest' }, error);
41
+ (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, { tag: tag || 'latest' }, err);
43
42
  }
44
43
  }
45
44
  exports.fetchReleaseData = fetchReleaseData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "1.7.0",
3
+ "version": "1.9.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": {
@@ -51,6 +51,7 @@
51
51
  "./api/*": "./api/*.js",
52
52
  "./errors/*": "./errors/*.js",
53
53
  "./http": "./http/index.js",
54
+ "./http/*": "./http/*.js",
54
55
  "./config": "./config/index.js",
55
56
  "./constants/*": "./constants/*.js",
56
57
  "./models/*": "./models/*.js"
package/types/Http.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { ReadStream } from 'fs';
5
+ import { Stream } from 'stream';
3
6
  export type Data = {
4
7
  [key: string]: any;
5
8
  };
@@ -12,7 +15,7 @@ export type AxiosConfigOptions = {
12
15
  env?: string;
13
16
  localHostOverride?: boolean;
14
17
  params?: QueryParams;
15
- data?: Data;
18
+ data?: Data | string | ArrayBuffer | ArrayBufferView | URLSearchParams | Stream | Buffer;
16
19
  resolveWithFullResponse?: boolean;
17
20
  timeout?: number;
18
21
  headers?: Data;
@@ -11,6 +11,10 @@ export type MigrateAppResponse = {
11
11
  id: number;
12
12
  status: ValueOf<typeof MIGRATION_STATUS>;
13
13
  };
14
+ export type CloneAppResponse = {
15
+ exportId: number;
16
+ status: ValueOf<typeof MIGRATION_STATUS>;
17
+ };
14
18
  export type PollAppResponse = {
15
19
  id: number;
16
20
  project?: {
@@ -19,6 +23,6 @@ export type PollAppResponse = {
19
23
  buildId: number;
20
24
  deployId: number;
21
25
  };
22
- error: OptionalError;
26
+ error?: OptionalError;
23
27
  status: ValueOf<typeof MIGRATION_STATUS>;
24
28
  };