@hubspot/local-dev-lib 0.0.2 → 0.0.4

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 (87) hide show
  1. package/config/CLIConfiguration.d.ts +55 -0
  2. package/config/CLIConfiguration.js +392 -0
  3. package/config/configFile.d.ts +21 -0
  4. package/config/configFile.js +109 -0
  5. package/config/configUtils.d.ts +24 -0
  6. package/config/configUtils.js +85 -0
  7. package/config/environment.d.ts +3 -0
  8. package/config/environment.js +64 -0
  9. package/constants/auth.d.ts +24 -0
  10. package/constants/auth.js +31 -0
  11. package/constants/config.d.ts +8 -0
  12. package/constants/config.js +12 -0
  13. package/constants/environments.d.ts +13 -0
  14. package/constants/environments.js +16 -0
  15. package/constants/extensions.d.ts +2 -0
  16. package/constants/extensions.js +23 -0
  17. package/constants/files.d.ts +5 -0
  18. package/constants/files.js +8 -0
  19. package/constants/github.d.ts +4 -0
  20. package/constants/github.js +7 -0
  21. package/constants/index.d.ts +16 -0
  22. package/constants/index.js +12 -0
  23. package/errors/HubSpotAuthError.d.ts +3 -0
  24. package/errors/HubSpotAuthError.js +6 -0
  25. package/errors/fileSystemErrors.d.ts +8 -0
  26. package/errors/fileSystemErrors.js +28 -0
  27. package/errors/standardErrors.d.ts +19 -0
  28. package/errors/standardErrors.js +67 -0
  29. package/http/requestOptions.d.ts +20 -0
  30. package/http/requestOptions.js +27 -0
  31. package/lib/archive.d.ts +7 -0
  32. package/lib/archive.js +111 -0
  33. package/lib/cms/handleFieldsJS.d.ts +32 -0
  34. package/lib/cms/handleFieldsJS.js +143 -0
  35. package/lib/cms/index.d.ts +10 -0
  36. package/lib/cms/index.js +13 -0
  37. package/lib/cms/modules.d.ts +24 -0
  38. package/lib/cms/modules.js +124 -0
  39. package/lib/cms/themes.d.ts +2 -0
  40. package/lib/cms/themes.js +34 -0
  41. package/lib/environment.d.ts +1 -0
  42. package/lib/environment.js +16 -0
  43. package/lib/fs.d.ts +4 -0
  44. package/lib/fs.js +71 -0
  45. package/lib/github.d.ts +17 -0
  46. package/lib/github.js +133 -0
  47. package/lib/gitignore.d.ts +1 -0
  48. package/lib/gitignore.js +76 -0
  49. package/lib/index.d.ts +11 -0
  50. package/lib/index.js +14 -0
  51. package/lib/path.d.ts +10 -0
  52. package/lib/path.js +84 -0
  53. package/lib/text.d.ts +1 -0
  54. package/lib/text.js +16 -0
  55. package/lib/urls.d.ts +2 -0
  56. package/lib/urls.js +20 -0
  57. package/package.json +8 -11
  58. package/types/Accounts.d.ts +50 -0
  59. package/types/Accounts.js +2 -0
  60. package/types/CLIOptions.d.ts +3 -0
  61. package/types/CLIOptions.js +2 -0
  62. package/types/Config.d.ts +10 -0
  63. package/types/Config.js +2 -0
  64. package/types/Error.d.ts +31 -0
  65. package/types/Error.js +2 -0
  66. package/types/Files.d.ts +8 -0
  67. package/types/Files.js +2 -0
  68. package/types/Github.d.ts +58 -0
  69. package/types/Github.js +2 -0
  70. package/types/LogCallbacks.d.ts +6 -0
  71. package/types/LogCallbacks.js +2 -0
  72. package/types/Modules.d.ts +5 -0
  73. package/types/Modules.js +2 -0
  74. package/types/Utils.d.ts +1 -0
  75. package/types/Utils.js +2 -0
  76. package/utils/escapeRegExp.d.ts +1 -0
  77. package/utils/escapeRegExp.js +7 -0
  78. package/utils/fieldsJS.d.ts +3 -0
  79. package/utils/fieldsJS.js +18 -0
  80. package/utils/git.d.ts +4 -0
  81. package/utils/git.js +40 -0
  82. package/utils/lang.d.ts +8 -0
  83. package/utils/lang.js +83 -0
  84. package/utils/logger.d.ts +10 -0
  85. package/utils/logger.js +22 -0
  86. package/utils/modules.d.ts +4 -0
  87. package/utils/modules.js +53 -0
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadConfigFromEnvironment = exports.getValidEnv = void 0;
4
+ const logger_1 = require("../utils/logger");
5
+ const constants_1 = require("../constants");
6
+ const auth_1 = require("../constants/auth");
7
+ const configUtils_1 = require("./configUtils");
8
+ function getValidEnv(env, useProdDefault = true) {
9
+ if (typeof env === 'string' && env.toLowerCase() === constants_1.ENVIRONMENTS.QA) {
10
+ return constants_1.ENVIRONMENTS.QA;
11
+ }
12
+ return useProdDefault ? constants_1.ENVIRONMENTS.PROD : undefined;
13
+ }
14
+ exports.getValidEnv = getValidEnv;
15
+ function getConfigVariablesFromEnv() {
16
+ const env = process.env;
17
+ return {
18
+ apiKey: env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_API_KEY],
19
+ clientId: env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_ID],
20
+ clientSecret: env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_SECRET],
21
+ personalAccessKey: env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY],
22
+ accountId: parseInt(env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_ACCOUNT_ID], 10),
23
+ refreshToken: env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN],
24
+ env: getValidEnv(env[constants_1.ENVIRONMENT_VARIABLES.HUBSPOT_ENVIRONMENT]),
25
+ };
26
+ }
27
+ function loadConfigFromEnvironment() {
28
+ const { apiKey, clientId, clientSecret, personalAccessKey, accountId, refreshToken, env, } = getConfigVariablesFromEnv();
29
+ if (!accountId) {
30
+ (0, logger_1.debug)('environment.loadConfig.missingAccountId');
31
+ return null;
32
+ }
33
+ if (!env) {
34
+ (0, logger_1.debug)('environment.loadConfig.env');
35
+ return null;
36
+ }
37
+ if (personalAccessKey) {
38
+ return (0, configUtils_1.generateConfig)(auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value, {
39
+ accountId,
40
+ personalAccessKey,
41
+ env,
42
+ });
43
+ }
44
+ else if (clientId && clientSecret && refreshToken) {
45
+ return (0, configUtils_1.generateConfig)(auth_1.OAUTH_AUTH_METHOD.value, {
46
+ accountId,
47
+ clientId,
48
+ clientSecret,
49
+ refreshToken,
50
+ scopes: auth_1.OAUTH_SCOPES.map((scope) => scope.value),
51
+ env,
52
+ });
53
+ }
54
+ else if (apiKey) {
55
+ return (0, configUtils_1.generateConfig)(auth_1.API_KEY_AUTH_METHOD.value, {
56
+ accountId,
57
+ apiKey,
58
+ env,
59
+ });
60
+ }
61
+ (0, logger_1.debug)('environment.loadConfig.unknownAuthType');
62
+ return null;
63
+ }
64
+ exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
@@ -0,0 +1,24 @@
1
+ export declare const API_KEY_AUTH_METHOD: {
2
+ readonly value: "apikey";
3
+ readonly name: "API Key";
4
+ };
5
+ export declare const OAUTH_AUTH_METHOD: {
6
+ readonly value: "oauth2";
7
+ readonly name: "OAuth2";
8
+ };
9
+ export declare const PERSONAL_ACCESS_KEY_AUTH_METHOD: {
10
+ readonly value: "personalaccesskey";
11
+ readonly name: "Personal Access Key";
12
+ };
13
+ export declare const DEFAULT_OAUTH_SCOPES: readonly ["content"];
14
+ export declare const OAUTH_SCOPES: readonly [{
15
+ readonly name: "All CMS APIs, Calendar API, Email and Email Events APIs";
16
+ readonly value: "content";
17
+ readonly checked: true;
18
+ }, {
19
+ readonly name: "HubDB API";
20
+ readonly value: "hubdb";
21
+ }, {
22
+ readonly name: "File Manager API";
23
+ readonly value: "files";
24
+ }];
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OAUTH_SCOPES = exports.DEFAULT_OAUTH_SCOPES = exports.PERSONAL_ACCESS_KEY_AUTH_METHOD = exports.OAUTH_AUTH_METHOD = exports.API_KEY_AUTH_METHOD = void 0;
4
+ exports.API_KEY_AUTH_METHOD = {
5
+ value: 'apikey',
6
+ name: 'API Key',
7
+ };
8
+ exports.OAUTH_AUTH_METHOD = {
9
+ value: 'oauth2',
10
+ name: 'OAuth2',
11
+ };
12
+ exports.PERSONAL_ACCESS_KEY_AUTH_METHOD = {
13
+ value: 'personalaccesskey',
14
+ name: 'Personal Access Key',
15
+ };
16
+ exports.DEFAULT_OAUTH_SCOPES = ['content'];
17
+ exports.OAUTH_SCOPES = [
18
+ {
19
+ name: 'All CMS APIs, Calendar API, Email and Email Events APIs',
20
+ value: 'content',
21
+ checked: true,
22
+ },
23
+ {
24
+ name: 'HubDB API',
25
+ value: 'hubdb',
26
+ },
27
+ {
28
+ name: 'File Manager API',
29
+ value: 'files',
30
+ },
31
+ ];
@@ -0,0 +1,8 @@
1
+ export declare const DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = "hubspot.config.yml";
2
+ export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hubspot";
3
+ export declare const HUBSPOT_CONFIGURATION_FILE = "config.yml";
4
+ export declare const DEFAULT_MODES: {
5
+ readonly draft: "draft";
6
+ readonly publish: "publish";
7
+ };
8
+ export declare const MIN_HTTP_TIMEOUT = 3000;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_MODES = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
4
+ // NOTE this is the legacy config file name (We still need to keep it around though)
5
+ exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = 'hubspot.config.yml';
6
+ exports.HUBSPOT_CONFIGURATION_FOLDER = '.hubspot';
7
+ exports.HUBSPOT_CONFIGURATION_FILE = 'config.yml';
8
+ exports.DEFAULT_MODES = {
9
+ draft: 'draft',
10
+ publish: 'publish',
11
+ };
12
+ exports.MIN_HTTP_TIMEOUT = 3000;
@@ -0,0 +1,13 @@
1
+ export declare const ENVIRONMENTS: {
2
+ readonly PROD: "prod";
3
+ readonly QA: "qa";
4
+ };
5
+ export declare const ENVIRONMENT_VARIABLES: {
6
+ readonly HUBSPOT_API_KEY: "HUBSPOT_API_KEY";
7
+ readonly HUBSPOT_CLIENT_ID: "HUBSPOT_CLIENT_ID";
8
+ readonly HUBSPOT_CLIENT_SECRET: "HUBSPOT_CLIENT_SECRET";
9
+ readonly HUBSPOT_PERSONAL_ACCESS_KEY: "HUBSPOT_PERSONAL_ACCESS_KEY";
10
+ readonly HUBSPOT_ACCOUNT_ID: "HUBSPOT_ACCOUNT_ID";
11
+ readonly HUBSPOT_REFRESH_TOKEN: "HUBSPOT_REFRESH_TOKEN";
12
+ readonly HUBSPOT_ENVIRONMENT: "HUBSPOT_ENVIRONMENT";
13
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENVIRONMENT_VARIABLES = exports.ENVIRONMENTS = void 0;
4
+ exports.ENVIRONMENTS = {
5
+ PROD: 'prod',
6
+ QA: 'qa',
7
+ };
8
+ exports.ENVIRONMENT_VARIABLES = {
9
+ HUBSPOT_API_KEY: 'HUBSPOT_API_KEY',
10
+ HUBSPOT_CLIENT_ID: 'HUBSPOT_CLIENT_ID',
11
+ HUBSPOT_CLIENT_SECRET: 'HUBSPOT_CLIENT_SECRET',
12
+ HUBSPOT_PERSONAL_ACCESS_KEY: 'HUBSPOT_PERSONAL_ACCESS_KEY',
13
+ HUBSPOT_ACCOUNT_ID: 'HUBSPOT_ACCOUNT_ID',
14
+ HUBSPOT_REFRESH_TOKEN: 'HUBSPOT_REFRESH_TOKEN',
15
+ HUBSPOT_ENVIRONMENT: 'HUBSPOT_ENVIRONMENT',
16
+ };
@@ -0,0 +1,2 @@
1
+ export declare const ALLOWED_EXTENSIONS: Set<string>;
2
+ export declare const MODULE_EXTENSION = "module";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MODULE_EXTENSION = exports.ALLOWED_EXTENSIONS = void 0;
4
+ exports.ALLOWED_EXTENSIONS = new Set([
5
+ 'css',
6
+ 'js',
7
+ 'json',
8
+ 'html',
9
+ 'txt',
10
+ 'md',
11
+ 'jpg',
12
+ 'jpeg',
13
+ 'png',
14
+ 'gif',
15
+ 'map',
16
+ 'svg',
17
+ 'eot',
18
+ 'ttf',
19
+ 'woff',
20
+ 'woff2',
21
+ 'graphql',
22
+ ]);
23
+ exports.MODULE_EXTENSION = 'module';
@@ -0,0 +1,5 @@
1
+ export declare const STAT_TYPES: {
2
+ readonly FILE: "file";
3
+ readonly SYMBOLIC_LINK: "symlink";
4
+ readonly DIRECTORY: "dir";
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STAT_TYPES = void 0;
4
+ exports.STAT_TYPES = {
5
+ FILE: 'file',
6
+ SYMBOLIC_LINK: 'symlink',
7
+ DIRECTORY: 'dir',
8
+ };
@@ -0,0 +1,4 @@
1
+ export declare const GITHUB_RELEASE_TYPES: {
2
+ readonly RELEASE: "release";
3
+ readonly REPOSITORY: "repository";
4
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GITHUB_RELEASE_TYPES = void 0;
4
+ exports.GITHUB_RELEASE_TYPES = {
5
+ RELEASE: 'release',
6
+ REPOSITORY: 'repository',
7
+ };
@@ -0,0 +1,16 @@
1
+ export declare const ENVIRONMENTS: {
2
+ readonly PROD: "prod";
3
+ readonly QA: "qa";
4
+ };
5
+ export declare const ENVIRONMENT_VARIABLES: {
6
+ readonly HUBSPOT_API_KEY: "HUBSPOT_API_KEY";
7
+ readonly HUBSPOT_CLIENT_ID: "HUBSPOT_CLIENT_ID";
8
+ readonly HUBSPOT_CLIENT_SECRET: "HUBSPOT_CLIENT_SECRET";
9
+ readonly HUBSPOT_PERSONAL_ACCESS_KEY: "HUBSPOT_PERSONAL_ACCESS_KEY";
10
+ readonly HUBSPOT_ACCOUNT_ID: "HUBSPOT_ACCOUNT_ID";
11
+ readonly HUBSPOT_REFRESH_TOKEN: "HUBSPOT_REFRESH_TOKEN";
12
+ readonly HUBSPOT_ENVIRONMENT: "HUBSPOT_ENVIRONMENT";
13
+ };
14
+ export declare const DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = "hubspot.config.yml";
15
+ export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hubspot";
16
+ export declare const HUBSPOT_CONFIGURATION_FILE = "config.yml";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = exports.ENVIRONMENT_VARIABLES = exports.ENVIRONMENTS = void 0;
4
+ const environments_1 = require("./environments");
5
+ const config_1 = require("./config");
6
+ // Environment Variables
7
+ exports.ENVIRONMENTS = environments_1.ENVIRONMENTS;
8
+ exports.ENVIRONMENT_VARIABLES = environments_1.ENVIRONMENT_VARIABLES;
9
+ // Config Variables
10
+ exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME;
11
+ exports.HUBSPOT_CONFIGURATION_FOLDER = config_1.HUBSPOT_CONFIGURATION_FOLDER;
12
+ exports.HUBSPOT_CONFIGURATION_FILE = config_1.HUBSPOT_CONFIGURATION_FILE;
@@ -0,0 +1,3 @@
1
+ import { BaseError } from '../types/Error';
2
+ export declare class HubSpotAuthError extends Error implements BaseError {
3
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HubSpotAuthError = void 0;
4
+ class HubSpotAuthError extends Error {
5
+ }
6
+ exports.HubSpotAuthError = HubSpotAuthError;
@@ -0,0 +1,8 @@
1
+ import { BaseError } from '../types/Error';
2
+ type FileSystemErrorContext = {
3
+ filepath: string;
4
+ write?: boolean;
5
+ read?: boolean;
6
+ };
7
+ export declare function throwFileSystemError(error: BaseError, context: FileSystemErrorContext): void;
8
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwFileSystemError = void 0;
4
+ const lang_1 = require("../utils/lang");
5
+ const standardErrors_1 = require("./standardErrors");
6
+ const i18nKey = 'errors.errorTypes.fileSystem';
7
+ function throwFileSystemError(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
+ throw new Error(message.join(' '), { cause: error });
27
+ }
28
+ exports.throwFileSystemError = throwFileSystemError;
@@ -0,0 +1,19 @@
1
+ import { BaseError } from '../types/Error';
2
+ export declare function isSystemError(err: BaseError): boolean;
3
+ export declare function isFatalError(err: BaseError): boolean;
4
+ /**
5
+ * @throws
6
+ */
7
+ export declare function throwErrorWithMessage(identifier: string, interpolation?: {
8
+ [key: string]: string | number;
9
+ }, cause?: BaseError): never;
10
+ /**
11
+ * @throws
12
+ */
13
+ export declare function throwTypeErrorWithMessage(identifier: string, interpolation?: {
14
+ [key: string]: string | number;
15
+ }, cause?: BaseError): never;
16
+ /**
17
+ * @throws
18
+ */
19
+ export declare function throwError(error: BaseError): never;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwError = exports.throwTypeErrorWithMessage = exports.throwErrorWithMessage = exports.isFatalError = exports.isSystemError = void 0;
4
+ const HubSpotAuthError_1 = require("./HubSpotAuthError");
5
+ const lang_1 = require("../utils/lang");
6
+ function isSystemError(err) {
7
+ return err.errno != null && err.code != null && err.syscall != null;
8
+ }
9
+ exports.isSystemError = isSystemError;
10
+ function isFatalError(err) {
11
+ return err instanceof HubSpotAuthError_1.HubSpotAuthError;
12
+ }
13
+ exports.isFatalError = isFatalError;
14
+ /**
15
+ * @throws
16
+ */
17
+ function throwErrorWithMessage(identifier, interpolation, cause) {
18
+ const message = (0, lang_1.i18n)(`errors.${identifier}`, interpolation);
19
+ if (cause) {
20
+ throw new Error(message, { cause });
21
+ }
22
+ throw new Error(message);
23
+ }
24
+ exports.throwErrorWithMessage = throwErrorWithMessage;
25
+ /**
26
+ * @throws
27
+ */
28
+ function throwTypeErrorWithMessage(identifier, interpolation, cause) {
29
+ const message = (0, lang_1.i18n)(`errors.${identifier}`, interpolation);
30
+ if (cause) {
31
+ throw new TypeError(message, { cause });
32
+ }
33
+ throw new TypeError(message);
34
+ }
35
+ exports.throwTypeErrorWithMessage = throwTypeErrorWithMessage;
36
+ function throwStatusCodeError(error) {
37
+ const { statusCode, message, response } = error;
38
+ const errorData = JSON.stringify({
39
+ statusCode,
40
+ message,
41
+ url: response.request.href,
42
+ method: response.request.method,
43
+ response: response.body,
44
+ headers: response.headers,
45
+ });
46
+ throw new Error(errorData, { cause: error });
47
+ }
48
+ /**
49
+ * @throws
50
+ */
51
+ function throwError(error) {
52
+ if (error.name === 'StatusCodeError') {
53
+ throwStatusCodeError(error);
54
+ }
55
+ else {
56
+ // Error or Error subclass
57
+ const name = error.name || 'Error';
58
+ const message = [(0, lang_1.i18n)('errors.errorTypes.generic', { name })];
59
+ [error.message, error.reason].forEach(msg => {
60
+ if (msg) {
61
+ message.push(msg);
62
+ }
63
+ });
64
+ throw new Error(message.join(' '), { cause: error });
65
+ }
66
+ }
67
+ exports.throwError = throwError;
@@ -0,0 +1,20 @@
1
+ export declare const DEFAULT_USER_AGENT_HEADERS: {
2
+ 'User-Agent': string;
3
+ };
4
+ type GetRequestOptionsOptions = {
5
+ env?: string;
6
+ localHostOverride?: boolean;
7
+ };
8
+ type RequestOptions = {
9
+ baseUrl: string;
10
+ headers: {
11
+ 'User-Agent': string;
12
+ };
13
+ json: boolean;
14
+ simple: boolean;
15
+ timeout: number;
16
+ env?: string;
17
+ localHostOverride?: boolean;
18
+ };
19
+ export declare function getRequestOptions(options?: GetRequestOptionsOptions, requestOptions?: {}): RequestOptions;
20
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRequestOptions = exports.DEFAULT_USER_AGENT_HEADERS = void 0;
7
+ const package_json_1 = require("../package.json");
8
+ const CLIConfiguration_1 = __importDefault(require("../config/CLIConfiguration"));
9
+ const urls_1 = require("../lib/urls");
10
+ exports.DEFAULT_USER_AGENT_HEADERS = {
11
+ 'User-Agent': `HubSpot Local Dev Lib/${package_json_1.version}`,
12
+ };
13
+ function getRequestOptions(options = {}, requestOptions = {}) {
14
+ const { env, localHostOverride } = options;
15
+ const { httpTimeout, httpUseLocalhost } = CLIConfiguration_1.default.getAndLoadConfigIfNeeded();
16
+ return {
17
+ baseUrl: (0, urls_1.getHubSpotApiOrigin)(env, localHostOverride ? false : httpUseLocalhost),
18
+ headers: {
19
+ ...exports.DEFAULT_USER_AGENT_HEADERS,
20
+ },
21
+ json: true,
22
+ simple: true,
23
+ timeout: httpTimeout || 15000,
24
+ ...requestOptions,
25
+ };
26
+ }
27
+ exports.getRequestOptions = getRequestOptions;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ type CopySourceToDestOptions = {
3
+ sourceDir?: string;
4
+ includesRootDir?: boolean;
5
+ };
6
+ export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir }?: CopySourceToDestOptions): Promise<boolean>;
7
+ export {};
package/lib/archive.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractZipArchive = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = require("path");
9
+ const os_1 = require("os");
10
+ const util_1 = require("util");
11
+ const extract_zip_1 = __importDefault(require("extract-zip"));
12
+ const fileSystemErrors_1 = require("../errors/fileSystemErrors");
13
+ const standardErrors_1 = require("../errors/standardErrors");
14
+ const logger_1 = require("../utils/logger");
15
+ const extract = (0, util_1.promisify)(extract_zip_1.default);
16
+ async function extractZip(name, zip) {
17
+ const result = { extractDir: '', tmpDir: '' };
18
+ const TMP_FOLDER_PREFIX = `hubspot-temp-${name}-`;
19
+ (0, logger_1.debug)('archive.extractZip.init');
20
+ // Write zip to disk
21
+ let tmpZipPath = '';
22
+ try {
23
+ result.tmpDir = await fs_extra_1.default.mkdtemp((0, path_1.join)((0, os_1.tmpdir)(), TMP_FOLDER_PREFIX));
24
+ tmpZipPath = (0, path_1.join)(result.tmpDir, 'hubspot-temp.zip');
25
+ await fs_extra_1.default.ensureFile(tmpZipPath);
26
+ await fs_extra_1.default.writeFile(tmpZipPath, zip, {
27
+ mode: 0o777,
28
+ });
29
+ }
30
+ catch (err) {
31
+ if (tmpZipPath || result.tmpDir) {
32
+ (0, fileSystemErrors_1.throwFileSystemError)(err, {
33
+ filepath: tmpZipPath || result.tmpDir,
34
+ write: true,
35
+ });
36
+ }
37
+ else {
38
+ (0, standardErrors_1.throwErrorWithMessage)('archive.extractZip.write', {}, err);
39
+ }
40
+ return result;
41
+ }
42
+ // Extract zip
43
+ try {
44
+ const tmpExtractPath = (0, path_1.join)(result.tmpDir, 'extracted');
45
+ await extract(tmpZipPath, { dir: tmpExtractPath });
46
+ result.extractDir = tmpExtractPath;
47
+ }
48
+ catch (err) {
49
+ (0, standardErrors_1.throwErrorWithMessage)('archive.extractZip.extract', {}, err);
50
+ }
51
+ (0, logger_1.debug)('archive.extractZip.success');
52
+ return result;
53
+ }
54
+ async function copySourceToDest(src, dest, { sourceDir, includesRootDir = true } = {}) {
55
+ try {
56
+ (0, logger_1.debug)('archive.copySourceToDest.init');
57
+ const srcDirPath = [src];
58
+ if (includesRootDir) {
59
+ const files = await fs_extra_1.default.readdir(src);
60
+ const rootDir = files[0];
61
+ if (!rootDir) {
62
+ (0, logger_1.debug)('archive.copySourceToDest.sourceEmpty');
63
+ // Create the dest path if it doesn't already exist
64
+ fs_extra_1.default.ensureDir(dest);
65
+ // No root found so nothing to copy
66
+ return true;
67
+ }
68
+ srcDirPath.push(rootDir);
69
+ }
70
+ if (sourceDir) {
71
+ srcDirPath.push(sourceDir);
72
+ }
73
+ const projectSrcDir = (0, path_1.join)(...srcDirPath);
74
+ await fs_extra_1.default.copy(projectSrcDir, dest);
75
+ (0, logger_1.debug)('archive.copySourceToDest.success');
76
+ return true;
77
+ }
78
+ catch (err) {
79
+ (0, logger_1.debug)('archive.copySourceToDest.error', { dest });
80
+ (0, fileSystemErrors_1.throwFileSystemError)(err, {
81
+ filepath: dest,
82
+ write: true,
83
+ });
84
+ }
85
+ return false;
86
+ }
87
+ function cleanupTempDir(tmpDir) {
88
+ if (!tmpDir)
89
+ return;
90
+ try {
91
+ fs_extra_1.default.remove(tmpDir);
92
+ }
93
+ catch (e) {
94
+ (0, logger_1.debug)('archive.cleanupTempDir.error', { tmpDir });
95
+ }
96
+ }
97
+ async function extractZipArchive(zip, name, dest, { sourceDir, includesRootDir } = {}) {
98
+ let success = false;
99
+ if (zip) {
100
+ const { extractDir, tmpDir } = await extractZip(name, zip);
101
+ if (extractDir !== null) {
102
+ success = await copySourceToDest(extractDir, dest, {
103
+ sourceDir,
104
+ includesRootDir,
105
+ });
106
+ }
107
+ cleanupTempDir(tmpDir);
108
+ }
109
+ return success;
110
+ }
111
+ exports.extractZipArchive = extractZipArchive;
@@ -0,0 +1,32 @@
1
+ export declare class FieldsJs {
2
+ projectDir: string;
3
+ filePath: string;
4
+ rootWriteDir: string;
5
+ rejected: boolean;
6
+ fieldOptions: string;
7
+ outputPath?: string;
8
+ constructor(projectDir: string, filePath: string, rootWriteDir?: string, fieldOptions?: string);
9
+ init(): Promise<this>;
10
+ convertFieldsJs(writeDir: string): Promise<string | void>;
11
+ /**
12
+ * If there has been a fields.json written to the output path, then copy it from the output
13
+ * directory to the project directory, respecting the path within the output directory.
14
+ * Ex: path/to/tmp/example.module/fields.json => path/to/project/example.module/fields.output.json
15
+ */
16
+ saveOutput(): void;
17
+ /**
18
+ * Resolves the relative path to the fields.js within the project directory and returns
19
+ * directory name to write to in rootWriteDir directory.
20
+ *
21
+ * Ex: If rootWriteDir = 'path/to/temp', filePath = 'projectRoot/sample.module/fields.js'. Then getWriteDir() => path/to/temp/sample.module
22
+ */
23
+ getWriteDir(): string;
24
+ getOutputPathPromise(): Promise<string | void>;
25
+ }
26
+ /**
27
+ * Determines if file is a convertable fields.js file i.e., if it is called
28
+ * 'fields.js' and in a root or in a module folder, and if convertFields flag is true.
29
+ */
30
+ export declare function isConvertableFieldJs(rootDir: string, filePath: string, convertFields?: boolean): boolean;
31
+ export declare function createTmpDirSync(prefix: string): string;
32
+ export declare function cleanupTmpDirSync(tmpDir: string): void;