@hubspot/local-dev-lib 0.0.1-experimental.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/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -0
- package/api/customObjects.js +45 -0
- package/api/designManager.d.ts +5 -0
- package/api/designManager.js +18 -0
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -0
- package/api/fileManager.js +63 -0
- package/api/fileMapper.d.ts +12 -0
- package/api/fileMapper.js +106 -0
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +8 -0
- package/api/functions.js +43 -0
- package/api/github.d.ts +11 -0
- package/api/github.js +71 -0
- package/api/hubdb.d.ts +12 -0
- package/api/hubdb.js +67 -0
- package/api/lighthouseScore.d.ts +6 -0
- package/api/lighthouseScore.js +26 -0
- package/api/localDevAuth.d.ts +8 -0
- package/api/localDevAuth.js +53 -0
- package/api/marketplaceValidation.d.ts +6 -0
- package/api/marketplaceValidation.js +26 -0
- package/api/projects.d.ts +40 -0
- package/api/projects.js +216 -0
- package/api/sandboxHubs.d.ts +7 -0
- package/api/sandboxHubs.js +49 -0
- package/api/sandboxSync.d.ts +4 -0
- package/api/sandboxSync.js +26 -0
- package/api/secrets.d.ts +6 -0
- package/api/secrets.js +37 -0
- package/api/validateHubl.d.ts +3 -0
- package/api/validateHubl.js +15 -0
- package/config/CLIConfiguration.d.ts +62 -0
- package/config/CLIConfiguration.js +467 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +102 -0
- package/config/configUtils.d.ts +5 -0
- package/config/configUtils.js +87 -0
- package/config/config_DEPRECATED.d.ts +75 -0
- package/config/config_DEPRECATED.js +678 -0
- package/config/environment.d.ts +2 -0
- package/config/environment.js +60 -0
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +41 -0
- package/config/index.js +260 -0
- package/constants/api.d.ts +15 -0
- package/constants/api.js +18 -0
- package/constants/auth.d.ts +37 -0
- package/constants/auth.js +38 -0
- package/constants/config.d.ts +18 -0
- package/constants/config.js +22 -0
- package/constants/environments.d.ts +15 -0
- package/constants/environments.js +18 -0
- package/constants/extensions.d.ts +6 -0
- package/constants/extensions.js +28 -0
- package/constants/files.d.ts +21 -0
- package/constants/files.js +24 -0
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/enums/build.d.ts +36 -0
- package/enums/build.js +39 -0
- package/enums/deploy.d.ts +11 -0
- package/enums/deploy.js +14 -0
- package/enums/project.d.ts +6 -0
- package/enums/project.js +9 -0
- package/errors/errors_DEPRECATED.d.ts +3 -0
- package/errors/errors_DEPRECATED.js +60 -0
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +9 -0
- package/http/getAxiosConfig.js +66 -0
- package/http/index.d.ts +17 -0
- package/http/index.js +173 -0
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +389 -0
- package/lib/archive.d.ts +3 -0
- package/lib/archive.js +117 -0
- package/lib/cms/functions.d.ts +8 -0
- package/lib/cms/functions.js +181 -0
- package/lib/cms/handleFieldsJS.d.ts +33 -0
- package/lib/cms/handleFieldsJS.js +148 -0
- package/lib/cms/modules.d.ts +14 -0
- package/lib/cms/modules.js +186 -0
- package/lib/cms/processFieldsJs.d.ts +1 -0
- package/lib/cms/processFieldsJs.js +97 -0
- package/lib/cms/templates.d.ts +65 -0
- package/lib/cms/templates.js +107 -0
- package/lib/cms/themes.d.ts +2 -0
- package/lib/cms/themes.js +34 -0
- package/lib/cms/uploadFolder.d.ts +7 -0
- package/lib/cms/uploadFolder.js +202 -0
- package/lib/cms/validate.d.ts +2 -0
- package/lib/cms/validate.js +40 -0
- package/lib/cms/watch.d.ts +4 -0
- package/lib/cms/watch.js +201 -0
- package/lib/customObjects.d.ts +5 -0
- package/lib/customObjects.js +42 -0
- package/lib/environment.d.ts +2 -0
- package/lib/environment.js +16 -0
- package/lib/escapeRegExp.d.ts +1 -0
- package/lib/escapeRegExp.js +7 -0
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +18 -0
- package/lib/fileMapper.js +317 -0
- package/lib/fs.d.ts +4 -0
- package/lib/fs.js +71 -0
- package/lib/github.d.ts +8 -0
- package/lib/github.js +167 -0
- package/lib/gitignore.d.ts +3 -0
- package/lib/gitignore.js +49 -0
- package/lib/hubdb.d.ts +17 -0
- package/lib/hubdb.js +133 -0
- package/lib/ignoreRules.d.ts +3 -0
- package/lib/ignoreRules.js +69 -0
- package/lib/logger.d.ts +56 -0
- package/lib/logger.js +146 -0
- package/lib/notify.d.ts +1 -0
- package/lib/notify.js +43 -0
- package/lib/oauth.d.ts +4 -0
- package/lib/oauth.js +34 -0
- package/lib/path.d.ts +14 -0
- package/lib/path.js +134 -0
- package/lib/personalAccessKey.d.ts +10 -0
- package/lib/personalAccessKey.js +163 -0
- package/lib/portManager.d.ts +10 -0
- package/lib/portManager.js +46 -0
- package/lib/text.d.ts +2 -0
- package/lib/text.js +24 -0
- package/lib/trackUsage.d.ts +1 -0
- package/lib/trackUsage.js +63 -0
- package/lib/urls.d.ts +2 -0
- package/lib/urls.js +24 -0
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +12 -0
- package/models/OAuth2Manager.js +105 -0
- package/package.json +81 -0
- package/types/Accounts.d.ts +178 -0
- package/types/Accounts.js +2 -0
- package/types/Activity.d.ts +20 -0
- package/types/Activity.js +2 -0
- package/types/Api.d.ts +2 -0
- package/types/Api.js +2 -0
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +41 -0
- package/types/Build.js +2 -0
- package/types/CLIOptions.d.ts +8 -0
- package/types/CLIOptions.js +2 -0
- package/types/ComponentStructure.d.ts +40 -0
- package/types/ComponentStructure.js +2 -0
- package/types/Config.d.ts +37 -0
- package/types/Config.js +2 -0
- package/types/Deploy.d.ts +42 -0
- package/types/Deploy.js +2 -0
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +37 -0
- package/types/Error.js +2 -0
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +71 -0
- package/types/FileManager.js +2 -0
- package/types/Files.d.ts +79 -0
- package/types/Files.js +2 -0
- package/types/Functions.d.ts +66 -0
- package/types/Functions.js +2 -0
- package/types/Github.d.ts +76 -0
- package/types/Github.js +2 -0
- package/types/Http.d.ts +29 -0
- package/types/Http.js +2 -0
- package/types/Hubdb.d.ts +109 -0
- package/types/Hubdb.js +2 -0
- package/types/HublValidation.d.ts +59 -0
- package/types/HublValidation.js +2 -0
- package/types/Lang.d.ts +10 -0
- package/types/Lang.js +2 -0
- package/types/Lighthouse.d.ts +25 -0
- package/types/Lighthouse.js +2 -0
- package/types/MarketplaceValidation.d.ts +28 -0
- package/types/MarketplaceValidation.js +2 -0
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +16 -0
- package/types/Modules.js +2 -0
- package/types/PortManager.d.ts +11 -0
- package/types/PortManager.js +2 -0
- package/types/Project.d.ts +42 -0
- package/types/Project.js +2 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +155 -0
- package/types/Sandbox.js +2 -0
- package/types/Schemas.d.ts +39 -0
- package/types/Schemas.js +2 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/Utils.d.ts +6 -0
- package/types/Utils.js +2 -0
- package/types/developerTestAccounts.d.ts +12 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +26 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/accounts.d.ts +4 -0
- package/utils/accounts.js +28 -0
- package/utils/cms/fieldsJS.d.ts +2 -0
- package/utils/cms/fieldsJS.js +18 -0
- package/utils/cms/modules.d.ts +4 -0
- package/utils/cms/modules.js +54 -0
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/git.d.ts +3 -0
- package/utils/git.js +71 -0
- package/utils/lang.d.ts +6 -0
- package/utils/lang.js +88 -0
package/lib/notify.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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.triggerNotify = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const moment_1 = __importDefault(require("moment"));
|
|
9
|
+
const debounce_1 = __importDefault(require("debounce"));
|
|
10
|
+
const lang_1 = require("../utils/lang");
|
|
11
|
+
const i18nKey = 'utils.notify';
|
|
12
|
+
const notifyQueue = [];
|
|
13
|
+
const notifyPromises = [];
|
|
14
|
+
const debouncedWaitForActionsToCompleteAndWriteQueueToFile = (0, debounce_1.default)(waitForActionsToCompleteAndWriteQueueToFile, 500);
|
|
15
|
+
// Collects actions that have been taken on files and the corresponding Promise
|
|
16
|
+
// for the remote action that is in-process
|
|
17
|
+
function triggerNotify(filePathToNotify, actionType, filePath, actionPromise) {
|
|
18
|
+
if (filePathToNotify) {
|
|
19
|
+
notifyQueue.push(`${(0, moment_1.default)().toISOString()} ${actionType}: ${filePath}\n`);
|
|
20
|
+
notifyPromises.push(actionPromise);
|
|
21
|
+
debouncedWaitForActionsToCompleteAndWriteQueueToFile(filePathToNotify);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.triggerNotify = triggerNotify;
|
|
25
|
+
// Clears both the notifyQueue and notifyPromises array, generates the output
|
|
26
|
+
// string that will be eventually logged, and waits for all promises currently
|
|
27
|
+
// in the notifyPromises array to resolve before logging the output
|
|
28
|
+
function waitForActionsToCompleteAndWriteQueueToFile(filePathToNotify) {
|
|
29
|
+
const actionOutput = notifyQueue.splice(0, notifyQueue.length).join('');
|
|
30
|
+
const allNotifyPromisesResolution = Promise.all(notifyPromises.splice(0, notifyPromises.length));
|
|
31
|
+
allNotifyPromisesResolution.then(() => notifyFilePath(filePathToNotify, actionOutput));
|
|
32
|
+
}
|
|
33
|
+
// Logs output to the "notify" file
|
|
34
|
+
function notifyFilePath(filePathToNotify, outputToWrite) {
|
|
35
|
+
if (filePathToNotify) {
|
|
36
|
+
try {
|
|
37
|
+
fs_1.default.appendFileSync(filePathToNotify, outputToWrite);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.filePath`, { filePath: filePathToNotify }), { cause: e });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/lib/oauth.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OAuth2Manager } from '../models/OAuth2Manager';
|
|
2
|
+
import { FlatAccountFields } from '../types/Accounts';
|
|
3
|
+
export declare function getOauthManager(accountId: number, accountConfig: FlatAccountFields): OAuth2Manager | undefined;
|
|
4
|
+
export declare function addOauthToAccountConfig(oauth: OAuth2Manager): void;
|
package/lib/oauth.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addOauthToAccountConfig = exports.getOauthManager = void 0;
|
|
4
|
+
const OAuth2Manager_1 = require("../models/OAuth2Manager");
|
|
5
|
+
const auth_1 = require("../constants/auth");
|
|
6
|
+
const logger_1 = require("./logger");
|
|
7
|
+
const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
|
|
8
|
+
const config_1 = require("../config");
|
|
9
|
+
const lang_1 = require("../utils/lang");
|
|
10
|
+
const i18nKey = 'lib.oauth';
|
|
11
|
+
const oauthManagers = new Map();
|
|
12
|
+
function writeOauthTokenInfo(accountConfig) {
|
|
13
|
+
const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
|
|
14
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeTokenInfo`, { portalId: accountId || '' }));
|
|
15
|
+
(0, config_1.updateAccountConfig)(accountConfig);
|
|
16
|
+
(0, config_1.writeConfig)();
|
|
17
|
+
}
|
|
18
|
+
function getOauthManager(accountId, accountConfig) {
|
|
19
|
+
if (!oauthManagers.has(accountId)) {
|
|
20
|
+
oauthManagers.set(accountId, OAuth2Manager_1.OAuth2Manager.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
|
|
21
|
+
}
|
|
22
|
+
return oauthManagers.get(accountId);
|
|
23
|
+
}
|
|
24
|
+
exports.getOauthManager = getOauthManager;
|
|
25
|
+
function addOauthToAccountConfig(oauth) {
|
|
26
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.init`));
|
|
27
|
+
(0, config_1.updateAccountConfig)({
|
|
28
|
+
...oauth.account,
|
|
29
|
+
authType: auth_1.AUTH_METHODS.oauth.value,
|
|
30
|
+
});
|
|
31
|
+
(0, config_1.writeConfig)();
|
|
32
|
+
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.success`));
|
|
33
|
+
}
|
|
34
|
+
exports.addOauthToAccountConfig = addOauthToAccountConfig;
|
package/lib/path.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export declare function convertToUnixPath(_path: string): string;
|
|
4
|
+
export declare function convertToLocalFileSystemPath(_path: string): string;
|
|
5
|
+
export declare function splitLocalPath(filepath: string, pathImplementation?: path.PlatformPath): Array<string>;
|
|
6
|
+
export declare function splitHubSpotPath(filepath: string): Array<string>;
|
|
7
|
+
export declare function getCwd(): string;
|
|
8
|
+
export declare function getExt(filepath: string): string;
|
|
9
|
+
export declare function getAllowedExtensions(allowList?: Array<string>): Set<string>;
|
|
10
|
+
export declare function isAllowedExtension(filepath: string, allowList?: Array<string>): boolean;
|
|
11
|
+
export declare function getAbsoluteFilePath(_path: string): string;
|
|
12
|
+
export declare function sanitizeFileName(fileName: string): string;
|
|
13
|
+
export declare function isValidPath(_path: string): boolean;
|
|
14
|
+
export declare function untildify(pathWithTilde: string): string;
|
package/lib/path.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
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.untildify = exports.isValidPath = exports.sanitizeFileName = exports.getAbsoluteFilePath = exports.isAllowedExtension = exports.getAllowedExtensions = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const unixify_1 = __importDefault(require("unixify"));
|
|
9
|
+
const extensions_1 = require("../constants/extensions");
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
11
|
+
function convertToUnixPath(_path) {
|
|
12
|
+
return (0, unixify_1.default)(path_1.default.normalize(_path));
|
|
13
|
+
}
|
|
14
|
+
exports.convertToUnixPath = convertToUnixPath;
|
|
15
|
+
function convertToWindowsPath(_path) {
|
|
16
|
+
const rgx = new RegExp(`\\${path_1.default.posix.sep}`, 'g');
|
|
17
|
+
return path_1.default.normalize(_path).replace(rgx, path_1.default.win32.sep);
|
|
18
|
+
}
|
|
19
|
+
function convertToLocalFileSystemPath(_path) {
|
|
20
|
+
switch (path_1.default.sep) {
|
|
21
|
+
case path_1.default.posix.sep:
|
|
22
|
+
return convertToUnixPath(_path);
|
|
23
|
+
case path_1.default.win32.sep:
|
|
24
|
+
return convertToWindowsPath(_path);
|
|
25
|
+
default:
|
|
26
|
+
return path_1.default.normalize(_path);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.convertToLocalFileSystemPath = convertToLocalFileSystemPath;
|
|
30
|
+
function removeTrailingSlashFromSplits(parts) {
|
|
31
|
+
if (parts.length > 1 && parts[parts.length - 1] === '') {
|
|
32
|
+
return parts.slice(0, parts.length - 1);
|
|
33
|
+
}
|
|
34
|
+
return parts;
|
|
35
|
+
}
|
|
36
|
+
// Splits a filepath for local file system sources.
|
|
37
|
+
function splitLocalPath(filepath, pathImplementation = path_1.default) {
|
|
38
|
+
if (!filepath)
|
|
39
|
+
return [];
|
|
40
|
+
const { sep } = pathImplementation;
|
|
41
|
+
const rgx = new RegExp(`\\${sep}+`, 'g');
|
|
42
|
+
const parts = pathImplementation.normalize(filepath).split(rgx);
|
|
43
|
+
// Restore posix root if present
|
|
44
|
+
if (sep === path_1.default.posix.sep && parts[0] === '') {
|
|
45
|
+
parts[0] = '/';
|
|
46
|
+
}
|
|
47
|
+
return removeTrailingSlashFromSplits(parts);
|
|
48
|
+
}
|
|
49
|
+
exports.splitLocalPath = splitLocalPath;
|
|
50
|
+
// Splits a filepath for remote sources (HubSpot).
|
|
51
|
+
function splitHubSpotPath(filepath) {
|
|
52
|
+
if (!filepath)
|
|
53
|
+
return [];
|
|
54
|
+
const rgx = new RegExp(`\\${path_1.default.posix.sep}+`, 'g');
|
|
55
|
+
const parts = convertToUnixPath(filepath).split(rgx);
|
|
56
|
+
// Restore root if present
|
|
57
|
+
if (parts[0] === '') {
|
|
58
|
+
parts[0] = '/';
|
|
59
|
+
}
|
|
60
|
+
return removeTrailingSlashFromSplits(parts);
|
|
61
|
+
}
|
|
62
|
+
exports.splitHubSpotPath = splitHubSpotPath;
|
|
63
|
+
function getCwd() {
|
|
64
|
+
if (process.env.INIT_CWD) {
|
|
65
|
+
return process.env.INIT_CWD;
|
|
66
|
+
}
|
|
67
|
+
return process.cwd();
|
|
68
|
+
}
|
|
69
|
+
exports.getCwd = getCwd;
|
|
70
|
+
function getExt(filepath) {
|
|
71
|
+
if (typeof filepath !== 'string')
|
|
72
|
+
return '';
|
|
73
|
+
const ext = path_1.default.extname(filepath).trim().toLowerCase();
|
|
74
|
+
return ext[0] === '.' ? ext.slice(1) : ext;
|
|
75
|
+
}
|
|
76
|
+
exports.getExt = getExt;
|
|
77
|
+
function getAllowedExtensions(allowList = []) {
|
|
78
|
+
return new Set([...Array.from(extensions_1.ALLOWED_EXTENSIONS), ...allowList]);
|
|
79
|
+
}
|
|
80
|
+
exports.getAllowedExtensions = getAllowedExtensions;
|
|
81
|
+
function isAllowedExtension(filepath, allowList = []) {
|
|
82
|
+
const ext = getExt(filepath);
|
|
83
|
+
const allowedExtensions = getAllowedExtensions(allowList);
|
|
84
|
+
return allowedExtensions.has(ext);
|
|
85
|
+
}
|
|
86
|
+
exports.isAllowedExtension = isAllowedExtension;
|
|
87
|
+
function getAbsoluteFilePath(_path) {
|
|
88
|
+
return path_1.default.resolve(getCwd(), _path);
|
|
89
|
+
}
|
|
90
|
+
exports.getAbsoluteFilePath = getAbsoluteFilePath;
|
|
91
|
+
// Reserved names (Windows specific)
|
|
92
|
+
const reservedNames = /^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i;
|
|
93
|
+
// Based on the node-sanitize-filename package: https://github.com/parshap/node-sanitize-filename/blob/master/index.js
|
|
94
|
+
function sanitizeFileName(fileName) {
|
|
95
|
+
// Windows invalid/control characters
|
|
96
|
+
// eslint-disable-next-line no-control-regex
|
|
97
|
+
const invalidChars = /[<>:"/|?*\x00-\x1F]/g;
|
|
98
|
+
//Replace invalid characters with dash
|
|
99
|
+
let sanitizedFileName = fileName.replace(invalidChars, '-');
|
|
100
|
+
// Removes trailing periods and spaces for Windows
|
|
101
|
+
sanitizedFileName = sanitizedFileName.replace(/[. ]+$/, '');
|
|
102
|
+
//Reserved names check for Windows
|
|
103
|
+
if (reservedNames.test(sanitizedFileName)) {
|
|
104
|
+
sanitizedFileName = `-${sanitizedFileName}`;
|
|
105
|
+
}
|
|
106
|
+
return sanitizedFileName;
|
|
107
|
+
}
|
|
108
|
+
exports.sanitizeFileName = sanitizeFileName;
|
|
109
|
+
// Based on the node-sanitize-filename package: https://github.com/parshap/node-sanitize-filename/blob/master/index.js
|
|
110
|
+
function isValidPath(_path) {
|
|
111
|
+
// Invalid characters excluding forward slash
|
|
112
|
+
// eslint-disable-next-line no-control-regex
|
|
113
|
+
const invalidChars = /[<>:"|?*\x00-\x1F]/;
|
|
114
|
+
const baseName = path_1.default.basename(_path);
|
|
115
|
+
if (invalidChars.test(baseName)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (reservedNames.test(baseName)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
exports.isValidPath = isValidPath;
|
|
124
|
+
// Based on the untildify package: https://github.com/sindresorhus/untildify/blob/main/index.js
|
|
125
|
+
function untildify(pathWithTilde) {
|
|
126
|
+
const homeDirectory = os_1.default.homedir();
|
|
127
|
+
if (typeof pathWithTilde !== 'string') {
|
|
128
|
+
throw new TypeError(`Expected a string, got ${typeof pathWithTilde}`);
|
|
129
|
+
}
|
|
130
|
+
return homeDirectory
|
|
131
|
+
? pathWithTilde.replace(/^~(?=$|\/|\\)/, homeDirectory)
|
|
132
|
+
: pathWithTilde;
|
|
133
|
+
}
|
|
134
|
+
exports.untildify = untildify;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CLIAccount } from '../types/Accounts';
|
|
2
|
+
import { Environment } from '../types/Config';
|
|
3
|
+
import { AccessToken } from '../types/Accounts';
|
|
4
|
+
export declare function getAccessToken(personalAccessKey: string, env?: Environment, accountId?: number): Promise<AccessToken>;
|
|
5
|
+
export declare function accessTokenForPersonalAccessKey(accountId: number, forceRefresh?: boolean): Promise<string | undefined>;
|
|
6
|
+
export declare function enabledFeaturesForPersonalAccessKey(accountId: number): Promise<{
|
|
7
|
+
[key: string]: number;
|
|
8
|
+
} | undefined>;
|
|
9
|
+
export declare function scopesOnAccessToken(accountId: number): Promise<Array<string>>;
|
|
10
|
+
export declare function updateConfigWithAccessToken(token: AccessToken, personalAccessKey: string, env?: Environment, name?: string, makeDefault?: boolean): Promise<CLIAccount | null>;
|
|
@@ -0,0 +1,163 @@
|
|
|
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.updateConfigWithAccessToken = exports.scopesOnAccessToken = exports.enabledFeaturesForPersonalAccessKey = exports.accessTokenForPersonalAccessKey = exports.getAccessToken = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const environments_1 = require("../constants/environments");
|
|
9
|
+
const auth_1 = require("../constants/auth");
|
|
10
|
+
const localDevAuth_1 = require("../api/localDevAuth");
|
|
11
|
+
const sandboxHubs_1 = require("../api/sandboxHubs");
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
const config_2 = require("../constants/config");
|
|
14
|
+
const developerTestAccounts_1 = require("../api/developerTestAccounts");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
16
|
+
const CLIConfiguration_1 = require("../config/CLIConfiguration");
|
|
17
|
+
const lang_1 = require("../utils/lang");
|
|
18
|
+
const errors_1 = require("../errors");
|
|
19
|
+
const i18nKey = 'lib.personalAccessKey';
|
|
20
|
+
const refreshRequests = new Map();
|
|
21
|
+
function getRefreshKey(personalAccessKey, expiration) {
|
|
22
|
+
return `${personalAccessKey}-${expiration || 'fresh'}`;
|
|
23
|
+
}
|
|
24
|
+
async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
25
|
+
const axiosResponse = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
|
|
26
|
+
const response = axiosResponse.data;
|
|
27
|
+
return {
|
|
28
|
+
portalId: response.hubId,
|
|
29
|
+
accessToken: response.oauthAccessToken,
|
|
30
|
+
expiresAt: (0, moment_1.default)(response.expiresAtMillis).toISOString(),
|
|
31
|
+
scopeGroups: response.scopeGroups,
|
|
32
|
+
enabledFeatures: response.enabledFeatures,
|
|
33
|
+
encodedOAuthRefreshToken: response.encodedOAuthRefreshToken,
|
|
34
|
+
hubName: response.hubName,
|
|
35
|
+
accountType: response.accountType,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.getAccessToken = getAccessToken;
|
|
39
|
+
async function refreshAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
40
|
+
const accessTokenResponse = await getAccessToken(personalAccessKey, env, accountId);
|
|
41
|
+
const { accessToken, expiresAt } = accessTokenResponse;
|
|
42
|
+
const config = (0, config_1.getAccountConfig)(accountId);
|
|
43
|
+
(0, config_1.updateAccountConfig)({
|
|
44
|
+
env,
|
|
45
|
+
...config,
|
|
46
|
+
accountId,
|
|
47
|
+
tokenInfo: {
|
|
48
|
+
accessToken,
|
|
49
|
+
expiresAt: expiresAt,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
(0, config_1.writeConfig)();
|
|
53
|
+
return accessTokenResponse;
|
|
54
|
+
}
|
|
55
|
+
async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
|
|
56
|
+
const key = getRefreshKey(personalAccessKey, expiresAt);
|
|
57
|
+
if (refreshRequests.has(key)) {
|
|
58
|
+
return refreshRequests.get(key);
|
|
59
|
+
}
|
|
60
|
+
let accessTokenResponse;
|
|
61
|
+
try {
|
|
62
|
+
const refreshAccessPromise = refreshAccessToken(personalAccessKey, env, accountId);
|
|
63
|
+
if (key) {
|
|
64
|
+
refreshRequests.set(key, refreshAccessPromise);
|
|
65
|
+
}
|
|
66
|
+
accessTokenResponse = await refreshAccessPromise;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
if (key) {
|
|
70
|
+
refreshRequests.delete(key);
|
|
71
|
+
}
|
|
72
|
+
throw e;
|
|
73
|
+
}
|
|
74
|
+
return accessTokenResponse;
|
|
75
|
+
}
|
|
76
|
+
async function getNewAccessTokenByAccountId(accountId) {
|
|
77
|
+
const account = (0, config_1.getAccountConfig)(accountId);
|
|
78
|
+
if (!account) {
|
|
79
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
80
|
+
}
|
|
81
|
+
const { auth, personalAccessKey, env } = account;
|
|
82
|
+
const accessTokenResponse = await getNewAccessToken(accountId, personalAccessKey, auth?.tokenInfo?.expiresAt, env);
|
|
83
|
+
return accessTokenResponse;
|
|
84
|
+
}
|
|
85
|
+
async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
|
|
86
|
+
const account = (0, config_1.getAccountConfig)(accountId);
|
|
87
|
+
if (!account) {
|
|
88
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
89
|
+
}
|
|
90
|
+
const { auth, personalAccessKey, env } = account;
|
|
91
|
+
const authTokenInfo = auth && auth.tokenInfo;
|
|
92
|
+
const authDataExists = authTokenInfo && auth?.tokenInfo?.accessToken;
|
|
93
|
+
if (!authDataExists ||
|
|
94
|
+
forceRefresh ||
|
|
95
|
+
(0, moment_1.default)().add(5, 'minutes').isAfter((0, moment_1.default)(authTokenInfo.expiresAt))) {
|
|
96
|
+
return getNewAccessToken(accountId, personalAccessKey, authTokenInfo && authTokenInfo.expiresAt, env).then(tokenInfo => tokenInfo.accessToken);
|
|
97
|
+
}
|
|
98
|
+
return auth?.tokenInfo?.accessToken;
|
|
99
|
+
}
|
|
100
|
+
exports.accessTokenForPersonalAccessKey = accessTokenForPersonalAccessKey;
|
|
101
|
+
async function enabledFeaturesForPersonalAccessKey(accountId) {
|
|
102
|
+
const accessTokenResponse = await getNewAccessTokenByAccountId(accountId);
|
|
103
|
+
return accessTokenResponse?.enabledFeatures;
|
|
104
|
+
}
|
|
105
|
+
exports.enabledFeaturesForPersonalAccessKey = enabledFeaturesForPersonalAccessKey;
|
|
106
|
+
async function scopesOnAccessToken(accountId) {
|
|
107
|
+
return (await getNewAccessTokenByAccountId(accountId)).scopeGroups;
|
|
108
|
+
}
|
|
109
|
+
exports.scopesOnAccessToken = scopesOnAccessToken;
|
|
110
|
+
async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
111
|
+
const { portalId, accessToken, expiresAt, accountType } = token;
|
|
112
|
+
const accountEnv = env || (0, config_1.getEnv)(name);
|
|
113
|
+
let parentAccountId;
|
|
114
|
+
try {
|
|
115
|
+
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
|
|
116
|
+
accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
117
|
+
const { data: sandboxDataResponse } = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
|
|
118
|
+
if (sandboxDataResponse.parentHubId) {
|
|
119
|
+
parentAccountId = sandboxDataResponse.parentHubId;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
// Log error but do not throw
|
|
125
|
+
if ((0, errors_1.isHubSpotHttpError)(err)) {
|
|
126
|
+
logger_1.logger.debug(err.message);
|
|
127
|
+
}
|
|
128
|
+
logger_1.logger.debug(err);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
|
|
132
|
+
const { data: developerTestAccountResponse } = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
|
|
133
|
+
if (developerTestAccountResponse) {
|
|
134
|
+
parentAccountId = developerTestAccountResponse.parentPortalId;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
// Log error but do not throw
|
|
140
|
+
if ((0, errors_1.isHubSpotHttpError)(err)) {
|
|
141
|
+
logger_1.logger.debug(err.message);
|
|
142
|
+
}
|
|
143
|
+
logger_1.logger.debug(err);
|
|
144
|
+
}
|
|
145
|
+
const updatedAccount = (0, config_1.updateAccountConfig)({
|
|
146
|
+
accountId: portalId,
|
|
147
|
+
accountType,
|
|
148
|
+
personalAccessKey,
|
|
149
|
+
name,
|
|
150
|
+
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
151
|
+
tokenInfo: { accessToken, expiresAt },
|
|
152
|
+
parentAccountId,
|
|
153
|
+
env: accountEnv,
|
|
154
|
+
});
|
|
155
|
+
if (!CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
156
|
+
(0, config_1.writeConfig)();
|
|
157
|
+
}
|
|
158
|
+
if (makeDefault && name) {
|
|
159
|
+
(0, config_1.updateDefaultAccount)(name);
|
|
160
|
+
}
|
|
161
|
+
return updatedAccount;
|
|
162
|
+
}
|
|
163
|
+
exports.updateConfigWithAccessToken = updateConfigWithAccessToken;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RequestPortsData } from '../types/PortManager';
|
|
2
|
+
export declare const BASE_URL: string;
|
|
3
|
+
export declare function isPortManagerServerRunning(): Promise<boolean>;
|
|
4
|
+
export declare function startPortManagerServer(): Promise<void>;
|
|
5
|
+
export declare function stopPortManagerServer(): Promise<void>;
|
|
6
|
+
export declare function requestPorts(portData: Array<RequestPortsData>): Promise<{
|
|
7
|
+
[instanceId: string]: number;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function deleteServerInstance(serverInstanceId: string): Promise<void>;
|
|
10
|
+
export declare function portManagerHasActiveServers(): Promise<boolean>;
|
|
@@ -0,0 +1,46 @@
|
|
|
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.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.isPortManagerServerRunning = exports.BASE_URL = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const PortManagerServer_1 = require("../utils/PortManagerServer");
|
|
9
|
+
const detectPort_1 = require("../utils/detectPort");
|
|
10
|
+
const ports_1 = require("../constants/ports");
|
|
11
|
+
exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
|
|
12
|
+
async function isPortManagerServerRunning() {
|
|
13
|
+
const port = await (0, detectPort_1.detectPort)(ports_1.PORT_MANAGER_SERVER_PORT);
|
|
14
|
+
return port !== ports_1.PORT_MANAGER_SERVER_PORT;
|
|
15
|
+
}
|
|
16
|
+
exports.isPortManagerServerRunning = isPortManagerServerRunning;
|
|
17
|
+
async function startPortManagerServer() {
|
|
18
|
+
const isRunning = await isPortManagerServerRunning();
|
|
19
|
+
if (!isRunning) {
|
|
20
|
+
await PortManagerServer_1.PortManagerServer.init();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.startPortManagerServer = startPortManagerServer;
|
|
24
|
+
async function stopPortManagerServer() {
|
|
25
|
+
const isRunning = await isPortManagerServerRunning();
|
|
26
|
+
if (isRunning) {
|
|
27
|
+
await axios_1.default.post(`${exports.BASE_URL}/close`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.stopPortManagerServer = stopPortManagerServer;
|
|
31
|
+
async function requestPorts(portData) {
|
|
32
|
+
const { data } = await axios_1.default.post(`${exports.BASE_URL}/servers`, {
|
|
33
|
+
portData: portData,
|
|
34
|
+
});
|
|
35
|
+
return data.ports;
|
|
36
|
+
}
|
|
37
|
+
exports.requestPorts = requestPorts;
|
|
38
|
+
async function deleteServerInstance(serverInstanceId) {
|
|
39
|
+
await axios_1.default.delete(`${exports.BASE_URL}/servers/${serverInstanceId}`);
|
|
40
|
+
}
|
|
41
|
+
exports.deleteServerInstance = deleteServerInstance;
|
|
42
|
+
async function portManagerHasActiveServers() {
|
|
43
|
+
const { data } = await axios_1.default.get(`${exports.BASE_URL}/servers`);
|
|
44
|
+
return data.count > 0;
|
|
45
|
+
}
|
|
46
|
+
exports.portManagerHasActiveServers = portManagerHasActiveServers;
|
package/lib/text.d.ts
ADDED
package/lib/text.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toKebabCase = exports.commaSeparatedValues = void 0;
|
|
4
|
+
function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
|
|
5
|
+
const l = arr.length;
|
|
6
|
+
if (!l)
|
|
7
|
+
return ifempty;
|
|
8
|
+
if (l < 2)
|
|
9
|
+
return arr[0];
|
|
10
|
+
if (l < 3)
|
|
11
|
+
return arr.join(` ${conjunction} `);
|
|
12
|
+
arr = arr.slice();
|
|
13
|
+
arr[l - 1] = `${conjunction} ${arr[l - 1]}`;
|
|
14
|
+
return arr.join(', ');
|
|
15
|
+
}
|
|
16
|
+
exports.commaSeparatedValues = commaSeparatedValues;
|
|
17
|
+
function toKebabCase(str) {
|
|
18
|
+
return (str
|
|
19
|
+
.replace(/[.,/#!$%^&*;:{}=\-_'"`~()]/g, '')
|
|
20
|
+
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) || [])
|
|
21
|
+
.join('-')
|
|
22
|
+
.toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
exports.toKebabCase = toKebabCase;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trackUsage(eventName: string, eventClass: string, meta?: {}, accountId?: number): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
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.trackUsage = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const getAxiosConfig_1 = require("../http/getAxiosConfig");
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const http_1 = require("../http");
|
|
11
|
+
const config_1 = require("../config");
|
|
12
|
+
const fileMapper_1 = require("../api/fileMapper");
|
|
13
|
+
const lang_1 = require("../utils/lang");
|
|
14
|
+
const i18nKey = 'lib.trackUsage';
|
|
15
|
+
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
16
|
+
const usageEvent = {
|
|
17
|
+
accountId,
|
|
18
|
+
eventName,
|
|
19
|
+
eventClass,
|
|
20
|
+
meta,
|
|
21
|
+
};
|
|
22
|
+
const EVENT_TYPES = {
|
|
23
|
+
VSCODE_EXTENSION_INTERACTION: 'vscode-extension-interaction',
|
|
24
|
+
CLI_INTERACTION: 'cli-interaction',
|
|
25
|
+
};
|
|
26
|
+
let analyticsEndpoint;
|
|
27
|
+
switch (eventName) {
|
|
28
|
+
case EVENT_TYPES.CLI_INTERACTION:
|
|
29
|
+
analyticsEndpoint = 'cms-cli-usage';
|
|
30
|
+
break;
|
|
31
|
+
case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
|
|
32
|
+
analyticsEndpoint = 'vscode-extension-usage';
|
|
33
|
+
break;
|
|
34
|
+
default:
|
|
35
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.invalidEvent`, { eventName }));
|
|
36
|
+
}
|
|
37
|
+
const path = `${fileMapper_1.FILE_MAPPER_API_PATH}/${analyticsEndpoint}`;
|
|
38
|
+
const accountConfig = accountId && (0, config_1.getAccountConfig)(accountId);
|
|
39
|
+
if (accountConfig && accountConfig.authType === 'personalaccesskey') {
|
|
40
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
|
|
41
|
+
try {
|
|
42
|
+
await http_1.http.post(accountId, {
|
|
43
|
+
url: `${path}/authenticated`,
|
|
44
|
+
data: usageEvent,
|
|
45
|
+
resolveWithFullResponse: true,
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const env = (0, config_1.getEnv)(accountId);
|
|
54
|
+
const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
|
|
55
|
+
env,
|
|
56
|
+
url: path,
|
|
57
|
+
data: usageEvent,
|
|
58
|
+
resolveWithFullResponse: true,
|
|
59
|
+
});
|
|
60
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventUnauthenticated`));
|
|
61
|
+
return (0, axios_1.default)({ ...axiosConfig, method: 'post' });
|
|
62
|
+
}
|
|
63
|
+
exports.trackUsage = trackUsage;
|
package/lib/urls.d.ts
ADDED
package/lib/urls.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHubSpotApiOrigin = exports.getHubSpotWebsiteOrigin = void 0;
|
|
4
|
+
const environments_1 = require("../constants/environments");
|
|
5
|
+
function getEnvUrlString(env) {
|
|
6
|
+
if (typeof env !== 'string') {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
return env.toLowerCase() === environments_1.ENVIRONMENTS.QA ? environments_1.ENVIRONMENTS.QA : '';
|
|
10
|
+
}
|
|
11
|
+
const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
|
|
12
|
+
exports.getHubSpotWebsiteOrigin = getHubSpotWebsiteOrigin;
|
|
13
|
+
function getHubSpotApiOrigin(env, useLocalHost) {
|
|
14
|
+
let domain;
|
|
15
|
+
const domainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
16
|
+
if (domainOverride && typeof domainOverride === 'string') {
|
|
17
|
+
domain = `${domainOverride}${getEnvUrlString(env)}`;
|
|
18
|
+
}
|
|
19
|
+
if (!domain || typeof domain !== 'string') {
|
|
20
|
+
domain = `${useLocalHost ? 'local' : 'api'}.hubapi${getEnvUrlString(env)}`;
|
|
21
|
+
}
|
|
22
|
+
return `https://${domain}.com`;
|
|
23
|
+
}
|
|
24
|
+
exports.getHubSpotApiOrigin = getHubSpotApiOrigin;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileSystemError = void 0;
|
|
4
|
+
const lang_1 = require("../utils/lang");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const i18nKey = 'errors.fileSystemErrors';
|
|
7
|
+
class FileSystemError extends Error {
|
|
8
|
+
context;
|
|
9
|
+
constructor(options, context) {
|
|
10
|
+
super('', options);
|
|
11
|
+
this.name = 'FileSystemError';
|
|
12
|
+
this.context = context;
|
|
13
|
+
if (context) {
|
|
14
|
+
let fileAction = '';
|
|
15
|
+
if (context.operation === 'read') {
|
|
16
|
+
fileAction = (0, lang_1.i18n)(`${i18nKey}.readAction`);
|
|
17
|
+
}
|
|
18
|
+
else if (context.operation === 'write') {
|
|
19
|
+
fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
|
|
23
|
+
}
|
|
24
|
+
const filepath = context.filepath
|
|
25
|
+
? `"${context.filepath}"`
|
|
26
|
+
: (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
|
|
27
|
+
const messages = [
|
|
28
|
+
(0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath }),
|
|
29
|
+
];
|
|
30
|
+
// Many `fs` errors will be `SystemError`s
|
|
31
|
+
if ((0, errors_1.isSystemError)(options?.cause)) {
|
|
32
|
+
messages.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, {
|
|
33
|
+
errorMessage: options?.cause?.message || '',
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
this.message = messages.join(' ');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
toString() {
|
|
40
|
+
let baseString = `${this.name}: ${this.message}`;
|
|
41
|
+
if (this.context) {
|
|
42
|
+
baseString = `${baseString} context: ${this.context}`;
|
|
43
|
+
}
|
|
44
|
+
return baseString;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.FileSystemError = FileSystemError;
|