@hubspot/local-dev-lib 0.0.9 → 0.0.11

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.
@@ -26,7 +26,7 @@ export declare function loadConfig(path?: string, options?: CLIOptions): CLIConf
26
26
  export declare function isTrackingAllowed(): boolean;
27
27
  export declare function getAndLoadConfigIfNeeded(options?: {}): Partial<CLIConfig_DEPRECATED>;
28
28
  export declare function findConfig(directory: string): string | null;
29
- export declare function getEnv(nameOrId: string | number): Environment;
29
+ export declare function getEnv(nameOrId?: string | number): Environment;
30
30
  export declare function getAccountConfig(accountId: number | undefined): CLIAccount_DEPRECATED | undefined;
31
31
  export declare function getAccountId(nameOrId?: string | number): number | undefined;
32
32
  /**
package/config/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare function updateAllowUsageTracking(isEnabled: boolean): void;
26
26
  export declare function deleteConfigFile(): void;
27
27
  export declare function isConfigFlagEnabled(flag: keyof CLIConfig): boolean;
28
28
  export declare function isTrackingAllowed(): boolean;
29
- export declare function getEnv(nameOrId: string | number): import("../types/Config").Environment;
29
+ export declare function getEnv(nameOrId?: string | number): import("../types/Config").Environment;
30
30
  export declare const getConfigAccounts: typeof config_DEPRECATED.getConfigAccounts;
31
31
  export declare const getConfigDefaultAccount: typeof config_DEPRECATED.getConfigDefaultAccount;
32
32
  export declare const getConfigAccountId: typeof config_DEPRECATED.getConfigAccountId;
@@ -1,2 +1,5 @@
1
1
  import { BaseError, FileSystemErrorContext } from '../types/Error';
2
+ /**
3
+ * @throws
4
+ */
2
5
  export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
@@ -4,6 +4,9 @@ exports.throwFileSystemError = void 0;
4
4
  const lang_1 = require("../utils/lang");
5
5
  const standardErrors_1 = require("./standardErrors");
6
6
  const i18nKey = 'errors.fileSystemErrors';
7
+ /**
8
+ * @throws
9
+ */
7
10
  function throwFileSystemError(error, context) {
8
11
  let fileAction = '';
9
12
  if (context.read) {
package/lib/archive.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
+ import { LogCallbacksArg } from '../types/LogCallbacks';
3
+ declare const archiveCallbackKeys: string[];
2
4
  type CopySourceToDestOptions = {
3
5
  sourceDir?: string;
4
6
  includesRootDir?: boolean;
5
7
  };
6
- export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
8
+ export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions, logCallbacks?: LogCallbacksArg<typeof archiveCallbackKeys>): Promise<boolean>;
7
9
  export {};
package/lib/archive.js CHANGED
@@ -7,17 +7,17 @@ exports.extractZipArchive = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = require("path");
9
9
  const os_1 = require("os");
10
- const util_1 = require("util");
11
10
  const extract_zip_1 = __importDefault(require("extract-zip"));
12
11
  const fileSystemErrors_1 = require("../errors/fileSystemErrors");
13
12
  const standardErrors_1 = require("../errors/standardErrors");
14
13
  const logger_1 = require("../utils/logger");
15
- const extract = (0, util_1.promisify)(extract_zip_1.default);
16
14
  const i18nKey = 'lib.archive';
17
- async function extractZip(name, zip) {
15
+ const archiveCallbackKeys = ['init', 'copy'];
16
+ async function extractZip(name, zip, logCallbacks) {
17
+ const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
18
18
  const result = { extractDir: '', tmpDir: '' };
19
19
  const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
20
- (0, logger_1.debug)(`${i18nKey}.extractZip.init`);
20
+ logger('init', `${i18nKey}.extractZip.init`);
21
21
  // Write zip to disk
22
22
  let tmpZipPath = '';
23
23
  try {
@@ -43,7 +43,7 @@ async function extractZip(name, zip) {
43
43
  // Extract zip
44
44
  try {
45
45
  const tmpExtractPath = (0, path_1.join)(result.tmpDir, 'extracted');
46
- await extract(tmpZipPath, { dir: tmpExtractPath });
46
+ await (0, extract_zip_1.default)(tmpZipPath, { dir: tmpExtractPath });
47
47
  result.extractDir = tmpExtractPath;
48
48
  }
49
49
  catch (err) {
@@ -52,9 +52,10 @@ async function extractZip(name, zip) {
52
52
  (0, logger_1.debug)(`${i18nKey}.extractZip.success`);
53
53
  return result;
54
54
  }
55
- async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
55
+ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}, logCallbacks) {
56
56
  try {
57
- (0, logger_1.debug)(`${i18nKey}.copySourceToDest.init`);
57
+ const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
58
+ logger('copy', `${i18nKey}.copySourceToDest.init`);
58
59
  const srcDirPath = [src];
59
60
  if (includesRootDir) {
60
61
  const files = await fs_extra_1.default.readdir(src);
@@ -95,15 +96,15 @@ function cleanupTempDir(tmpDir) {
95
96
  (0, logger_1.debug)(`${i18nKey}.cleanupTempDir.error`, { tmpDir });
96
97
  }
97
98
  }
98
- async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
99
+ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}, logCallbacks) {
99
100
  let success = false;
100
101
  if (zip) {
101
- const { extractDir, tmpDir } = await extractZip(name, zip);
102
+ const { extractDir, tmpDir } = await extractZip(name, zip, logCallbacks);
102
103
  if (extractDir !== null) {
103
104
  success = await copySourceToDest(extractDir, dest, {
104
105
  sourceDir,
105
106
  includesRootDir,
106
- });
107
+ }, logCallbacks);
107
108
  }
108
109
  cleanupTempDir(tmpDir);
109
110
  }
@@ -10,10 +10,13 @@ const findup_sync_1 = __importDefault(require("findup-sync"));
10
10
  const path_2 = require("../path");
11
11
  const github_1 = require("../github");
12
12
  const logger_1 = require("../../utils/logger");
13
- const objectUtils_1 = require("../../utils/objectUtils");
14
13
  const standardErrors_1 = require("../../errors/standardErrors");
15
14
  const fileSystemErrors_1 = require("../../errors/fileSystemErrors");
16
15
  const i18nKey = 'lib.cms.functions';
16
+ function isObjectOrFunction(value) {
17
+ const type = typeof value;
18
+ return value != null && (type === 'object' || type === 'function');
19
+ }
17
20
  function createEndpoint(endpointMethod, filename) {
18
21
  return {
19
22
  method: endpointMethod || 'GET',
@@ -62,7 +65,7 @@ function updateExistingConfig(configFilePath, { endpointPath, endpointMethod, fu
62
65
  read: true,
63
66
  });
64
67
  }
65
- if (!(0, objectUtils_1.isObject)(config)) {
68
+ if (!isObjectOrFunction(config)) {
66
69
  (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateExistingConfig.errors.configIsNotObjectError`, { configFilePath });
67
70
  }
68
71
  if (config.endpoints) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getValidEnv = void 0;
4
4
  const environments_1 = require("../constants/environments");
5
5
  function getValidEnv(env, maskedProductionValue) {
6
- const prodValue = maskedProductionValue
6
+ const prodValue = typeof maskedProductionValue === 'string'
7
7
  ? maskedProductionValue
8
8
  : environments_1.ENVIRONMENTS.PROD;
9
9
  const returnVal = typeof env &&
@@ -30,7 +30,7 @@ export declare class Logger {
30
30
  }
31
31
  export declare function setLogger(logger: Logger): void;
32
32
  export declare function setLogLevel(level: number): void;
33
- export declare function shouldLog(level: number): number;
33
+ export declare function shouldLog(level: number): boolean;
34
34
  export declare function getLogLevel(): number;
35
35
  export declare const logger: {
36
36
  error(...args: any[]): void;
@@ -88,7 +88,7 @@ function setLogLevel(level) {
88
88
  }
89
89
  exports.setLogLevel = setLogLevel;
90
90
  function shouldLog(level) {
91
- return currentLogLevel & level;
91
+ return !!(currentLogLevel & level);
92
92
  }
93
93
  exports.shouldLog = shouldLog;
94
94
  function getLogLevel() {
package/lib/text.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function commaSeparatedValues(arr: Array<string>, conjunction?: string, ifempty?: string): string;
1
+ export declare function commaSeparatedValues(arr: Array<string>, conjunction?: null | string, ifempty?: string): string;
@@ -1 +1 @@
1
- export declare function trackUsage(eventName: string, eventClass: string, meta: {} | undefined, accountId: number): Promise<void>;
1
+ export declare function trackUsage(eventName: string, eventClass: string, meta?: {}, accountId?: number): Promise<void>;
package/lib/trackUsage.js CHANGED
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.trackUsage = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const getAxiosConfig_1 = require("../http/getAxiosConfig");
7
9
  const logger_1 = require("../utils/logger");
8
10
  const http_1 = __importDefault(require("../http"));
9
11
  const config_1 = require("../config");
@@ -42,12 +44,13 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
42
44
  });
43
45
  }
44
46
  const env = (0, config_1.getEnv)(accountId);
45
- (0, logger_1.debug)(`${i18nKey}.sendingEventUnauthenticated`);
46
- http_1.default.post(accountId, {
47
+ const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
47
48
  env,
48
49
  url: path,
49
50
  data: usageEvent,
50
51
  resolveWithFullResponse: true,
51
52
  });
53
+ (0, logger_1.debug)(`${i18nKey}.sendingEventUnauthenticated`);
54
+ (0, axios_1.default)({ ...axiosConfig, method: 'post' });
52
55
  }
53
56
  exports.trackUsage = trackUsage;
package/lib/validate.js CHANGED
@@ -7,8 +7,8 @@ exports.lint = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const extensions_1 = require("../constants/extensions");
9
9
  const validateHubl_1 = require("../api/validateHubl");
10
- const fs_1 = require("../lib/fs");
11
- const path_1 = require("../lib/path");
10
+ const fs_1 = require("./fs");
11
+ const path_1 = require("./path");
12
12
  async function lint(accountId, filepath, callback) {
13
13
  const stats = await fs_extra_1.default.stat(filepath);
14
14
  const files = stats.isDirectory() ? await (0, fs_1.walk)(filepath) : [filepath];
@@ -20,7 +20,9 @@ class OAuth2Manager {
20
20
  this.writeTokenInfo = writeTokenInfo;
21
21
  this.refreshTokenRequest = null;
22
22
  this.account = account;
23
- // NOTE: Potential issues by not using maskProductionValue = '' for env like in cli-lib
23
+ if (this.account.env) {
24
+ this.account.env = (0, environment_1.getValidEnv)(this.account.env, '');
25
+ }
24
26
  }
25
27
  async accessToken() {
26
28
  if (!this.account.auth.tokenInfo?.refreshToken) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -1,4 +1,4 @@
1
- export declare function isObject(value: object): boolean;
1
+ export declare function isObject(item: any): any;
2
2
  export declare function mergeDeep(target: {
3
3
  [key: string]: any;
4
4
  }, ...sources: Array<{
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeDeep = exports.isObject = void 0;
4
- function isObject(value) {
5
- const type = typeof value;
6
- return value != null && (type === 'object' || type === 'function');
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ function isObject(item) {
6
+ return item && typeof item === 'object' && !Array.isArray(item);
7
7
  }
8
8
  exports.isObject = isObject;
9
9
  function mergeDeep(