@hubspot/local-dev-lib 0.0.4 → 0.0.6
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/customObjects.d.ts +7 -0
- package/api/customObjects.js +48 -0
- package/api/designManager.d.ts +13 -0
- package/api/designManager.js +21 -0
- package/api/fileManager.d.ts +5 -0
- package/api/fileManager.js +62 -0
- package/api/fileMapper.d.ts +10 -0
- package/api/fileMapper.js +104 -0
- package/api/functions.d.ts +4 -0
- package/api/functions.js +32 -0
- package/api/hubdb.d.ts +10 -0
- package/api/hubdb.js +61 -0
- package/api/lighthouseScore.d.ts +5 -0
- package/api/lighthouseScore.js +29 -0
- package/api/localDevAuth.d.ts +12 -0
- package/api/localDevAuth.js +38 -0
- package/api/marketplaceValidation.d.ts +5 -0
- package/api/marketplaceValidation.js +29 -0
- package/api/projects.d.ts +27 -0
- package/api/projects.js +126 -0
- package/api/sandboxHubs.d.ts +6 -0
- package/api/sandboxHubs.js +50 -0
- package/api/sandboxSync.d.ts +4 -0
- package/api/sandboxSync.js +35 -0
- package/api/secrets.d.ts +8 -0
- package/api/secrets.js +40 -0
- package/api/validateHubl.d.ts +2 -0
- package/api/validateHubl.js +18 -0
- package/config/CLIConfiguration.d.ts +22 -16
- package/config/CLIConfiguration.js +39 -9
- package/config/configFile.d.ts +4 -4
- package/config/configFile.js +2 -2
- package/config/configUtils.d.ts +8 -8
- package/config/config_DEPRECATED.d.ts +78 -0
- package/config/config_DEPRECATED.js +636 -0
- package/config/environment.d.ts +2 -3
- package/config/environment.js +11 -17
- package/config/index.d.ts +38 -0
- package/config/index.js +232 -0
- package/constants/api.d.ts +17 -0
- package/constants/api.js +20 -0
- package/constants/auth.d.ts +13 -0
- package/constants/auth.js +8 -1
- package/constants/config.d.ts +0 -4
- package/constants/config.js +1 -5
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +4 -1
- package/constants/files.d.ts +16 -0
- package/constants/files.js +17 -1
- 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/HubSpotAuthError.d.ts +8 -2
- package/errors/HubSpotAuthError.js +14 -0
- package/errors/apiErrors.d.ts +9 -0
- package/errors/apiErrors.js +182 -0
- package/errors/errors_DEPRECATED.d.ts +7 -0
- package/errors/errors_DEPRECATED.js +73 -0
- package/errors/fileSystemErrors.d.ts +1 -7
- package/errors/standardErrors.d.ts +7 -1
- package/errors/standardErrors.js +20 -23
- package/http/getAxiosConfig.d.ts +6 -0
- package/http/getAxiosConfig.js +22 -0
- package/http/index.d.ts +18 -0
- package/http/index.js +175 -0
- package/lang/en.lyaml +247 -0
- package/lib/cms/functions.d.ts +13 -0
- package/lib/cms/functions.js +181 -0
- package/lib/cms/handleFieldsJS.d.ts +2 -1
- package/lib/cms/handleFieldsJS.js +4 -3
- package/lib/cms/modules.js +3 -3
- package/lib/cms/processFieldsJs.d.ts +1 -0
- package/lib/cms/processFieldsJs.js +122 -0
- package/lib/cms/templates.d.ts +25 -0
- package/lib/cms/templates.js +62 -0
- package/lib/cms/themes.js +2 -2
- package/lib/cms/uploadFolder.d.ts +18 -0
- package/lib/cms/uploadFolder.js +182 -0
- package/lib/cms/watch.d.ts +20 -0
- package/lib/cms/watch.js +194 -0
- package/lib/customObjects.d.ts +5 -0
- package/lib/customObjects.js +36 -0
- package/lib/environment.d.ts +2 -1
- package/lib/fileMapper.d.ts +13 -0
- package/lib/fileMapper.js +322 -0
- package/lib/github.d.ts +6 -3
- package/lib/github.js +36 -27
- package/lib/gitignore.js +1 -46
- package/lib/hubdb.d.ts +16 -0
- package/lib/hubdb.js +130 -0
- package/lib/ignoreRules.d.ts +3 -0
- package/lib/ignoreRules.js +69 -0
- package/lib/logging/git.d.ts +2 -0
- package/lib/logging/git.js +54 -0
- package/lib/logging/logger.d.ts +44 -0
- package/lib/logging/logger.js +146 -0
- package/lib/logging/logs.d.ts +22 -0
- package/lib/logging/logs.js +82 -0
- package/lib/logging/table.d.ts +3 -0
- package/lib/logging/table.js +47 -0
- package/lib/oauth.d.ts +7 -0
- package/lib/oauth.js +44 -0
- package/lib/path.d.ts +2 -1
- package/lib/path.js +8 -3
- package/lib/personalAccessKey.d.ts +13 -0
- package/lib/personalAccessKey.js +135 -0
- package/lib/sandboxes.d.ts +14 -0
- package/lib/sandboxes.js +71 -0
- package/lib/trackUsage.d.ts +1 -0
- package/lib/trackUsage.js +53 -0
- package/lib/validate.d.ts +2 -0
- package/lib/validate.js +40 -0
- package/models/OAuth2Manager.d.ts +34 -0
- package/models/OAuth2Manager.js +126 -0
- package/package.json +25 -13
- package/types/Accounts.d.ts +66 -21
- 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/Build.d.ts +41 -0
- package/types/Build.js +2 -0
- package/types/CLIOptions.d.ts +5 -0
- package/types/ComponentStructure.d.ts +20 -0
- package/types/ComponentStructure.js +2 -0
- package/types/Config.d.ts +17 -4
- package/types/Deploy.d.ts +42 -0
- package/types/Deploy.js +2 -0
- package/types/Error.d.ts +32 -7
- package/types/FileManager.d.ts +66 -0
- package/types/FileManager.js +2 -0
- package/types/Files.d.ts +33 -1
- package/types/Functions.d.ts +40 -0
- package/types/Functions.js +2 -0
- package/types/Github.d.ts +6 -0
- package/types/Http.d.ts +33 -0
- package/types/Http.js +2 -0
- package/types/Hubdb.d.ts +90 -0
- package/types/Hubdb.js +2 -0
- package/types/HublValidation.d.ts +59 -0
- package/types/HublValidation.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/Project.d.ts +38 -0
- package/types/Project.js +2 -0
- package/types/Sandbox.d.ts +165 -0
- package/types/Sandbox.js +2 -0
- package/types/Schemas.d.ts +42 -0
- package/types/Schemas.js +2 -0
- package/utils/{modules.d.ts → cms/modules.d.ts} +1 -1
- package/utils/{modules.js → cms/modules.js} +3 -3
- package/utils/getAccountIdentifier.d.ts +10 -0
- package/utils/getAccountIdentifier.js +40 -0
- package/utils/git.d.ts +7 -2
- package/utils/git.js +54 -7
- package/utils/lang.d.ts +4 -0
- package/utils/lang.js +9 -2
- package/utils/notify.d.ts +1 -0
- package/utils/notify.js +42 -0
- package/utils/objectUtils.d.ts +8 -0
- package/utils/objectUtils.js +33 -0
- package/constants/index.d.ts +0 -16
- package/constants/index.js +0 -12
- package/http/requestOptions.d.ts +0 -20
- package/http/requestOptions.js +0 -27
- package/lib/cms/index.d.ts +0 -10
- package/lib/cms/index.js +0 -13
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -14
- /package/utils/{fieldsJS.d.ts → cms/fieldsJS.d.ts} +0 -0
- /package/utils/{fieldsJS.js → cms/fieldsJS.js} +0 -0
package/lib/path.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.getAbsoluteFilePath = exports.isAllowedExtension = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
|
|
6
|
+
exports.getAbsoluteFilePath = exports.isAllowedExtension = exports.getAllowedExtensions = exports.getExt = exports.getCwd = exports.splitHubSpotPath = exports.splitLocalPath = exports.convertToLocalFileSystemPath = exports.convertToUnixPath = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const unixify_1 = __importDefault(require("unixify"));
|
|
9
9
|
const extensions_1 = require("../constants/extensions");
|
|
@@ -73,9 +73,14 @@ function getExt(filepath) {
|
|
|
73
73
|
return ext[0] === '.' ? ext.slice(1) : ext;
|
|
74
74
|
}
|
|
75
75
|
exports.getExt = getExt;
|
|
76
|
-
function
|
|
76
|
+
function getAllowedExtensions(allowList = []) {
|
|
77
|
+
return new Set([...Array.from(extensions_1.ALLOWED_EXTENSIONS), ...allowList]);
|
|
78
|
+
}
|
|
79
|
+
exports.getAllowedExtensions = getAllowedExtensions;
|
|
80
|
+
function isAllowedExtension(filepath, allowList = []) {
|
|
77
81
|
const ext = getExt(filepath);
|
|
78
|
-
|
|
82
|
+
const allowedExtensions = getAllowedExtensions(allowList);
|
|
83
|
+
return allowedExtensions.has(ext);
|
|
79
84
|
}
|
|
80
85
|
exports.isAllowedExtension = isAllowedExtension;
|
|
81
86
|
function getAbsoluteFilePath(_path) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CLIAccount } from '../types/Accounts';
|
|
2
|
+
import { Environment } from '../types/Config';
|
|
3
|
+
type AccessToken = {
|
|
4
|
+
portalId: number;
|
|
5
|
+
accessToken: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
scopeGroups: Array<string>;
|
|
8
|
+
encodedOauthRefreshToken: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function getAccessToken(personalAccessKey: string, env?: Environment, accountId?: number): Promise<AccessToken>;
|
|
11
|
+
export declare function accessTokenForPersonalAccessKey(accountId: number): Promise<string | undefined>;
|
|
12
|
+
export declare const updateConfigWithPersonalAccessKey: (personalAccessKey: string, name: string, env: Environment, makeDefault?: boolean) => Promise<CLIAccount | null>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
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.updateConfigWithPersonalAccessKey = 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 standardErrors_1 = require("../errors/standardErrors");
|
|
11
|
+
const localDevAuth_1 = require("../api/localDevAuth");
|
|
12
|
+
const sandboxHubs_1 = require("../api/sandboxHubs");
|
|
13
|
+
const config_1 = require("../config");
|
|
14
|
+
const refreshRequests = new Map();
|
|
15
|
+
function getRefreshKey(personalAccessKey, expiration) {
|
|
16
|
+
return `${personalAccessKey}-${expiration || 'fresh'}`;
|
|
17
|
+
}
|
|
18
|
+
async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
const error = e;
|
|
25
|
+
if (error.response) {
|
|
26
|
+
(0, standardErrors_1.throwAuthErrorWithMessage)('personalAccessKey.invalidPersonalAccessKey', { errorMessage: error.response.body.message || '' }, error);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
(0, standardErrors_1.throwError)(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
portalId: response.hubId,
|
|
34
|
+
accessToken: response.oauthAccessToken,
|
|
35
|
+
expiresAt: (0, moment_1.default)(response.expiresAtMillis).toISOString(),
|
|
36
|
+
scopeGroups: response.scopeGroups,
|
|
37
|
+
encodedOauthRefreshToken: response.encodedOauthRefreshToken,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.getAccessToken = getAccessToken;
|
|
41
|
+
async function refreshAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
42
|
+
const { accessToken, expiresAt } = await getAccessToken(personalAccessKey, env, accountId);
|
|
43
|
+
const config = (0, config_1.getAccountConfig)(accountId);
|
|
44
|
+
(0, config_1.updateAccountConfig)({
|
|
45
|
+
env,
|
|
46
|
+
...config,
|
|
47
|
+
accountId,
|
|
48
|
+
tokenInfo: {
|
|
49
|
+
accessToken,
|
|
50
|
+
expiresAt: expiresAt,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
(0, config_1.writeConfig)();
|
|
54
|
+
return accessToken;
|
|
55
|
+
}
|
|
56
|
+
async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
|
|
57
|
+
const key = getRefreshKey(personalAccessKey, expiresAt);
|
|
58
|
+
if (refreshRequests.has(key)) {
|
|
59
|
+
return refreshRequests.get(key);
|
|
60
|
+
}
|
|
61
|
+
let accessToken;
|
|
62
|
+
try {
|
|
63
|
+
const refreshAccessPromise = refreshAccessToken(personalAccessKey, env, accountId);
|
|
64
|
+
if (key) {
|
|
65
|
+
refreshRequests.set(key, refreshAccessPromise);
|
|
66
|
+
}
|
|
67
|
+
accessToken = await refreshAccessPromise;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
if (key) {
|
|
71
|
+
refreshRequests.delete(key);
|
|
72
|
+
}
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
return accessToken;
|
|
76
|
+
}
|
|
77
|
+
async function accessTokenForPersonalAccessKey(accountId) {
|
|
78
|
+
const account = (0, config_1.getAccountConfig)(accountId);
|
|
79
|
+
if (!account) {
|
|
80
|
+
(0, standardErrors_1.throwErrorWithMessage)('personalAccessKey.accountNotFound', { accountId });
|
|
81
|
+
}
|
|
82
|
+
const { auth, personalAccessKey, env } = account;
|
|
83
|
+
const authTokenInfo = auth && auth.tokenInfo;
|
|
84
|
+
const authDataExists = authTokenInfo && auth?.tokenInfo?.accessToken;
|
|
85
|
+
if (!authDataExists ||
|
|
86
|
+
(0, moment_1.default)().add(5, 'minutes').isAfter((0, moment_1.default)(authTokenInfo.expiresAt))) {
|
|
87
|
+
return getNewAccessToken(accountId, personalAccessKey, authTokenInfo && authTokenInfo.expiresAt, env);
|
|
88
|
+
}
|
|
89
|
+
return auth?.tokenInfo?.accessToken;
|
|
90
|
+
}
|
|
91
|
+
exports.accessTokenForPersonalAccessKey = accessTokenForPersonalAccessKey;
|
|
92
|
+
// Adds a account to the config using authType: personalAccessKey
|
|
93
|
+
const updateConfigWithPersonalAccessKey = async (personalAccessKey, name, env, makeDefault = false) => {
|
|
94
|
+
const accountEnv = env || (0, config_1.getEnv)(name);
|
|
95
|
+
let token;
|
|
96
|
+
try {
|
|
97
|
+
token = await getAccessToken(personalAccessKey, accountEnv);
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
(0, standardErrors_1.throwError)(err);
|
|
101
|
+
}
|
|
102
|
+
const { portalId, accessToken, expiresAt } = token;
|
|
103
|
+
let hubInfo;
|
|
104
|
+
try {
|
|
105
|
+
hubInfo = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
// Ignore error, returns 404 if account is not a sandbox
|
|
109
|
+
}
|
|
110
|
+
let sandboxAccountType = null;
|
|
111
|
+
let parentAccountId = null;
|
|
112
|
+
if (hubInfo) {
|
|
113
|
+
if (hubInfo.type !== undefined) {
|
|
114
|
+
sandboxAccountType = hubInfo.type === null ? 'STANDARD' : hubInfo.type;
|
|
115
|
+
}
|
|
116
|
+
if (hubInfo.parentHubId) {
|
|
117
|
+
parentAccountId = hubInfo.parentHubId;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const updatedConfig = (0, config_1.updateAccountConfig)({
|
|
121
|
+
accountId: portalId,
|
|
122
|
+
personalAccessKey,
|
|
123
|
+
name,
|
|
124
|
+
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
125
|
+
tokenInfo: { accessToken, expiresAt },
|
|
126
|
+
sandboxAccountType,
|
|
127
|
+
parentAccountId,
|
|
128
|
+
});
|
|
129
|
+
(0, config_1.writeConfig)();
|
|
130
|
+
if (makeDefault) {
|
|
131
|
+
(0, config_1.updateDefaultAccount)(name);
|
|
132
|
+
}
|
|
133
|
+
return updatedConfig;
|
|
134
|
+
};
|
|
135
|
+
exports.updateConfigWithPersonalAccessKey = updateConfigWithPersonalAccessKey;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InitiateSyncResponse, Sandbox, SandboxType, SyncTask, Task, Usage } from '../types/Sandbox';
|
|
2
|
+
export declare function createSandbox(accountId: number, name: string, type: string): Promise<{
|
|
3
|
+
name: string;
|
|
4
|
+
sandbox: Sandbox;
|
|
5
|
+
personalAccessKey: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function deleteSandbox(parentAccountId: number, sandboxAccountId: number): Promise<{
|
|
8
|
+
parentAccountId: number;
|
|
9
|
+
sandboxAccountId: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function getSandboxUsageLimits(parentAccountId: number): Promise<Usage | void>;
|
|
12
|
+
export declare function initiateSync(fromHubId: number, toHubId: number, tasks: Array<SyncTask>, sandboxHubId: number): Promise<InitiateSyncResponse>;
|
|
13
|
+
export declare function fetchTaskStatus(accountId: number, taskId: number): Promise<Task>;
|
|
14
|
+
export declare function fetchTypes(accountId: number, toHubId: number): Promise<Array<SandboxType> | void>;
|
package/lib/sandboxes.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchTypes = exports.fetchTaskStatus = exports.initiateSync = exports.getSandboxUsageLimits = exports.deleteSandbox = exports.createSandbox = void 0;
|
|
4
|
+
const sandboxHubs_1 = require("../api/sandboxHubs");
|
|
5
|
+
const sandboxSync_1 = require("../api/sandboxSync");
|
|
6
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
7
|
+
const i18nKey = 'sandboxes';
|
|
8
|
+
async function createSandbox(accountId, name, type) {
|
|
9
|
+
try {
|
|
10
|
+
const resp = await (0, sandboxHubs_1.createSandbox)(accountId, name, type);
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
...resp,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.createSandbox`, {}, err);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.createSandbox = createSandbox;
|
|
21
|
+
async function deleteSandbox(parentAccountId, sandboxAccountId) {
|
|
22
|
+
try {
|
|
23
|
+
await (0, sandboxHubs_1.deleteSandbox)(parentAccountId, sandboxAccountId);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.deleteSandbox`, {}, err);
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
parentAccountId,
|
|
30
|
+
sandboxAccountId,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.deleteSandbox = deleteSandbox;
|
|
34
|
+
async function getSandboxUsageLimits(parentAccountId) {
|
|
35
|
+
try {
|
|
36
|
+
const resp = await (0, sandboxHubs_1.getSandboxUsageLimits)(parentAccountId);
|
|
37
|
+
return resp && resp.usage;
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.getSandboxUsageLimits`, {}, err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.getSandboxUsageLimits = getSandboxUsageLimits;
|
|
44
|
+
async function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
|
|
45
|
+
try {
|
|
46
|
+
return await (0, sandboxSync_1.initiateSync)(fromHubId, toHubId, tasks, sandboxHubId);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.initiateSync`, {}, err);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.initiateSync = initiateSync;
|
|
53
|
+
async function fetchTaskStatus(accountId, taskId) {
|
|
54
|
+
try {
|
|
55
|
+
return await (0, sandboxSync_1.fetchTaskStatus)(accountId, taskId);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchTaskStatus`, {}, err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.fetchTaskStatus = fetchTaskStatus;
|
|
62
|
+
async function fetchTypes(accountId, toHubId) {
|
|
63
|
+
try {
|
|
64
|
+
const resp = await (0, sandboxSync_1.fetchTypes)(accountId, toHubId);
|
|
65
|
+
return resp && resp.results;
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.fetchTypes`, {}, err);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.fetchTypes = fetchTypes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function trackUsage(eventName: string, eventClass: string, meta: {} | undefined, accountId: number): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 logger_1 = require("../utils/logger");
|
|
8
|
+
const http_1 = __importDefault(require("../http"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const fileMapper_1 = require("../api/fileMapper");
|
|
11
|
+
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
12
|
+
const i18nKey = 'api.filemapper.trackUsage';
|
|
13
|
+
const usageEvent = {
|
|
14
|
+
accountId,
|
|
15
|
+
eventName,
|
|
16
|
+
eventClass,
|
|
17
|
+
meta,
|
|
18
|
+
};
|
|
19
|
+
const EVENT_TYPES = {
|
|
20
|
+
VSCODE_EXTENSION_INTERACTION: 'vscode-extension-interaction',
|
|
21
|
+
CLI_INTERACTION: 'cli-interaction',
|
|
22
|
+
};
|
|
23
|
+
let analyticsEndpoint;
|
|
24
|
+
switch (eventName) {
|
|
25
|
+
case EVENT_TYPES.CLI_INTERACTION:
|
|
26
|
+
analyticsEndpoint = 'cms-cli-usage';
|
|
27
|
+
break;
|
|
28
|
+
case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
|
|
29
|
+
analyticsEndpoint = 'vscode-extension-usage';
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
(0, logger_1.debug)(`${i18nKey}.invalidEvent`, { eventName });
|
|
33
|
+
}
|
|
34
|
+
const path = `${fileMapper_1.FILE_MAPPER_API_PATH}/${analyticsEndpoint}`;
|
|
35
|
+
const accountConfig = accountId && (0, config_1.getAccountConfig)(accountId);
|
|
36
|
+
if (accountConfig && accountConfig.authType === 'personalaccesskey') {
|
|
37
|
+
(0, logger_1.debug)(`${i18nKey}.sendingEventAuthenticated`);
|
|
38
|
+
return http_1.default.post(accountId, {
|
|
39
|
+
url: `${path}/authenticated`,
|
|
40
|
+
body: usageEvent,
|
|
41
|
+
resolveWithFullResponse: true,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const env = (0, config_1.getEnv)(accountId);
|
|
45
|
+
(0, logger_1.debug)(`${i18nKey}.sendingEventUnauthenticated`);
|
|
46
|
+
http_1.default.post(accountId, {
|
|
47
|
+
env,
|
|
48
|
+
url: path,
|
|
49
|
+
body: usageEvent,
|
|
50
|
+
resolveWithFullResponse: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.trackUsage = trackUsage;
|
package/lib/validate.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
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.lint = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const extensions_1 = require("../constants/extensions");
|
|
9
|
+
const validateHubl_1 = require("../api/validateHubl");
|
|
10
|
+
const fs_1 = require("../lib/fs");
|
|
11
|
+
const path_1 = require("../lib/path");
|
|
12
|
+
async function lint(accountId, filepath, callback) {
|
|
13
|
+
const stats = await fs_extra_1.default.stat(filepath);
|
|
14
|
+
const files = stats.isDirectory() ? await (0, fs_1.walk)(filepath) : [filepath];
|
|
15
|
+
if (!(files && files.length)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return Promise.all(files
|
|
19
|
+
.filter(file => extensions_1.HUBL_EXTENSIONS.has((0, path_1.getExt)(file)))
|
|
20
|
+
.map(async (file) => {
|
|
21
|
+
const source = await fs_extra_1.default.readFile(file, { encoding: 'utf8' });
|
|
22
|
+
if (!(source && source.trim())) {
|
|
23
|
+
const result = { file, validation: null };
|
|
24
|
+
if (callback) {
|
|
25
|
+
callback(result);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
const validation = await (0, validateHubl_1.validateHubl)(accountId, source);
|
|
30
|
+
const result = {
|
|
31
|
+
file,
|
|
32
|
+
validation,
|
|
33
|
+
};
|
|
34
|
+
if (callback) {
|
|
35
|
+
callback(result);
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
exports.lint = lint;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FlatAccountFields, OAuthAccount, TokenInfo } from '../types/Accounts';
|
|
2
|
+
type WriteTokenInfoFunction = (tokenInfo: TokenInfo) => void;
|
|
3
|
+
type RefreshTokenResponse = {
|
|
4
|
+
refresh_token: string;
|
|
5
|
+
access_token: string;
|
|
6
|
+
expires_in: string;
|
|
7
|
+
};
|
|
8
|
+
type ExchangeProof = {
|
|
9
|
+
grant_type: string;
|
|
10
|
+
client_id?: string;
|
|
11
|
+
client_secret?: string;
|
|
12
|
+
refresh_token?: string;
|
|
13
|
+
};
|
|
14
|
+
declare class OAuth2Manager {
|
|
15
|
+
account: OAuthAccount;
|
|
16
|
+
writeTokenInfo: WriteTokenInfoFunction;
|
|
17
|
+
refreshTokenRequest: Promise<RefreshTokenResponse> | null;
|
|
18
|
+
constructor(account: OAuthAccount, writeTokenInfo: WriteTokenInfoFunction);
|
|
19
|
+
accessToken(): Promise<string | undefined>;
|
|
20
|
+
fetchAccessToken(exchangeProof: ExchangeProof): Promise<void>;
|
|
21
|
+
exchangeForTokens(exchangeProof: ExchangeProof): Promise<void>;
|
|
22
|
+
refreshAccessToken(): Promise<void>;
|
|
23
|
+
toObj(): {
|
|
24
|
+
environment: "prod" | "qa";
|
|
25
|
+
clientSecret: string | undefined;
|
|
26
|
+
clientId: string | undefined;
|
|
27
|
+
scopes: string[] | undefined;
|
|
28
|
+
tokenInfo: TokenInfo | undefined;
|
|
29
|
+
name: string | undefined;
|
|
30
|
+
accountId: number;
|
|
31
|
+
};
|
|
32
|
+
static fromConfig(accountConfig: FlatAccountFields, writeTokenInfo: WriteTokenInfoFunction): OAuth2Manager;
|
|
33
|
+
}
|
|
34
|
+
export default OAuth2Manager;
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const environments_1 = require("../constants/environments");
|
|
9
|
+
const urls_1 = require("../lib/urls");
|
|
10
|
+
const environment_1 = require("../lib/environment");
|
|
11
|
+
const logger_1 = require("../utils/logger");
|
|
12
|
+
const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
|
|
13
|
+
const auth_1 = require("../constants/auth");
|
|
14
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
15
|
+
const i18nKey = 'models.OAuth2Manager';
|
|
16
|
+
class OAuth2Manager {
|
|
17
|
+
account;
|
|
18
|
+
writeTokenInfo;
|
|
19
|
+
refreshTokenRequest;
|
|
20
|
+
constructor(account, writeTokenInfo) {
|
|
21
|
+
this.account = account;
|
|
22
|
+
this.writeTokenInfo = writeTokenInfo;
|
|
23
|
+
this.refreshTokenRequest = null;
|
|
24
|
+
}
|
|
25
|
+
async accessToken() {
|
|
26
|
+
if (!this.account.auth.tokenInfo?.refreshToken) {
|
|
27
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.missingRefreshToken`, {
|
|
28
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (!this.account.auth.tokenInfo?.accessToken ||
|
|
32
|
+
(0, moment_1.default)()
|
|
33
|
+
.add(5, 'minutes')
|
|
34
|
+
.isAfter((0, moment_1.default)(this.account.auth?.tokenInfo.expiresAt))) {
|
|
35
|
+
await this.refreshAccessToken();
|
|
36
|
+
}
|
|
37
|
+
return this.account.auth?.tokenInfo.accessToken;
|
|
38
|
+
}
|
|
39
|
+
async fetchAccessToken(exchangeProof) {
|
|
40
|
+
(0, logger_1.debug)(`${i18nKey}.fetchingAccessToken`, {
|
|
41
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
42
|
+
clientId: this.account.auth.clientId || '',
|
|
43
|
+
});
|
|
44
|
+
try {
|
|
45
|
+
const { data } = await axios_1.default.post(`${(0, urls_1.getHubSpotApiOrigin)((0, environment_1.getValidEnv)(this.account.env))}/oauth/v1/token`, {
|
|
46
|
+
form: exchangeProof,
|
|
47
|
+
json: true,
|
|
48
|
+
});
|
|
49
|
+
this.refreshTokenRequest = data;
|
|
50
|
+
const { refresh_token: refreshToken, access_token: accessToken, expires_in: expiresIn, } = data;
|
|
51
|
+
if (!this.account.auth.tokenInfo) {
|
|
52
|
+
this.account.auth.tokenInfo = {};
|
|
53
|
+
}
|
|
54
|
+
this.account.auth.tokenInfo.refreshToken = refreshToken;
|
|
55
|
+
this.account.auth.tokenInfo.accessToken = accessToken;
|
|
56
|
+
this.account.auth.tokenInfo.expiresAt = (0, moment_1.default)()
|
|
57
|
+
.add(Math.round(parseInt(expiresIn) * 0.75), 'seconds')
|
|
58
|
+
.toString();
|
|
59
|
+
if (this.writeTokenInfo) {
|
|
60
|
+
(0, logger_1.debug)(`${i18nKey}.updatingTokenInfo`, {
|
|
61
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
62
|
+
clientId: this.account.auth.clientId || '',
|
|
63
|
+
});
|
|
64
|
+
this.writeTokenInfo(this.account.auth.tokenInfo);
|
|
65
|
+
}
|
|
66
|
+
this.refreshTokenRequest = null;
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
this.refreshTokenRequest = null;
|
|
70
|
+
(0, standardErrors_1.throwError)(e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async exchangeForTokens(exchangeProof) {
|
|
74
|
+
try {
|
|
75
|
+
if (this.refreshTokenRequest) {
|
|
76
|
+
(0, logger_1.debug)(`${i18nKey}.refreshingAccessToken`, {
|
|
77
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
78
|
+
clientId: this.account.auth.clientId || '',
|
|
79
|
+
});
|
|
80
|
+
await this.refreshTokenRequest;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
await this.fetchAccessToken(exchangeProof);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
const error = e;
|
|
88
|
+
if (error.response) {
|
|
89
|
+
(0, standardErrors_1.throwAuthErrorWithMessage)(`${i18nKey}.auth`, {
|
|
90
|
+
token: error.response.body.message || '',
|
|
91
|
+
}, error);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
(0, standardErrors_1.throwError)(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async refreshAccessToken() {
|
|
99
|
+
const refreshTokenProof = {
|
|
100
|
+
grant_type: 'refresh_token',
|
|
101
|
+
client_id: this.account.auth.clientId,
|
|
102
|
+
client_secret: this.account.auth.clientSecret,
|
|
103
|
+
refresh_token: this.account.auth.tokenInfo?.refreshToken,
|
|
104
|
+
};
|
|
105
|
+
await this.exchangeForTokens(refreshTokenProof);
|
|
106
|
+
}
|
|
107
|
+
toObj() {
|
|
108
|
+
return {
|
|
109
|
+
environment: this.account.env ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD,
|
|
110
|
+
clientSecret: this.account.auth.clientSecret,
|
|
111
|
+
clientId: this.account.auth.clientId,
|
|
112
|
+
scopes: this.account.auth.scopes,
|
|
113
|
+
tokenInfo: this.account.auth.tokenInfo,
|
|
114
|
+
name: this.account.name,
|
|
115
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
static fromConfig(accountConfig, writeTokenInfo) {
|
|
119
|
+
return new OAuth2Manager({
|
|
120
|
+
...accountConfig,
|
|
121
|
+
authType: auth_1.AUTH_METHODS.oauth.value,
|
|
122
|
+
auth: accountConfig.auth || {},
|
|
123
|
+
}, writeTokenInfo);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.default = OAuth2Manager;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/HubSpot/hubspot-local-dev-lib"
|
|
@@ -12,28 +12,32 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsc --rootDir . --outdir dist",
|
|
15
|
+
"build": "rm -rf ./dist/ && tsc --rootDir . --outdir dist && yarn copy-files",
|
|
16
16
|
"check-main": "branch=$(git rev-parse --abbrev-ref HEAD) && [ $branch = main ] || (echo 'Error: New release can only be published on main branch' && exit 1)",
|
|
17
|
+
"copy-files": "cp -r lang dist/lang",
|
|
17
18
|
"lint": "eslint --max-warnings=0 . && prettier --check ./**/*.ts",
|
|
18
19
|
"local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
|
|
19
|
-
"
|
|
20
|
+
"postinstall": "husky install",
|
|
20
21
|
"prepack": "pinst --disable",
|
|
21
22
|
"postpack": "pinst --enable",
|
|
22
|
-
"prettier:write": "prettier --write ./**/*.{js,json}",
|
|
23
|
+
"prettier:write": "prettier --write ./**/*.{ts,js,json}",
|
|
23
24
|
"pub": "cd dist && npm publish --tag latest && cd ..",
|
|
24
25
|
"push": "git push --atomic origin main v$npm_package_version",
|
|
25
26
|
"release:major": "yarn check-main && yarn version --major && yarn build && yarn pub && yarn push",
|
|
26
27
|
"release:minor": "yarn check-main && yarn version --minor && yarn build && yarn pub && yarn push",
|
|
27
28
|
"release:patch": "yarn check-main && yarn version --patch && yarn build && yarn pub && yarn push",
|
|
28
|
-
"test": "jest"
|
|
29
|
+
"test": "jest --silent"
|
|
29
30
|
},
|
|
30
31
|
"license": "Apache-2.0",
|
|
31
32
|
"devDependencies": {
|
|
33
|
+
"@types/content-disposition": "^0.5.5",
|
|
34
|
+
"@types/debounce": "^1.2.1",
|
|
32
35
|
"@types/findup-sync": "^4.0.2",
|
|
33
36
|
"@types/fs-extra": "^11.0.1",
|
|
34
37
|
"@types/jest": "^29.5.0",
|
|
35
38
|
"@types/js-yaml": "^4.0.5",
|
|
36
39
|
"@types/node": "^18.14.2",
|
|
40
|
+
"@types/prettier": "^3.0.0",
|
|
37
41
|
"@types/unixify": "^1.0.0",
|
|
38
42
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
39
43
|
"@typescript-eslint/parser": "^5.59.7",
|
|
@@ -41,27 +45,35 @@
|
|
|
41
45
|
"husky": "^8.0.0",
|
|
42
46
|
"jest": "^29.5.0",
|
|
43
47
|
"pinst": "^3.0.0",
|
|
44
|
-
"prettier": "^2.8.4",
|
|
45
48
|
"ts-jest": "^29.0.5",
|
|
46
49
|
"typescript": "^4.9.5"
|
|
47
50
|
},
|
|
48
51
|
"exports": {
|
|
49
|
-
"
|
|
50
|
-
"./
|
|
51
|
-
"./
|
|
52
|
-
"./
|
|
53
|
-
"./
|
|
52
|
+
"./*": "./lib/*.js",
|
|
53
|
+
"./api/*": "./api/*.js",
|
|
54
|
+
"./errors/*": "./errors/*.js",
|
|
55
|
+
"./http": "./http/index.js",
|
|
56
|
+
"./config": "./config/index.js",
|
|
57
|
+
"./constants/*": "./constants/*.js",
|
|
58
|
+
"./logger": "./lib/logging/logger.js"
|
|
54
59
|
},
|
|
55
60
|
"dependencies": {
|
|
56
61
|
"axios": "^1.3.5",
|
|
62
|
+
"chokidar": "^3.5.3",
|
|
63
|
+
"content-disposition": "^0.5.4",
|
|
57
64
|
"extract-zip": "^2.0.1",
|
|
58
65
|
"findup-sync": "^5.0.0",
|
|
59
66
|
"fs-extra": "^11.1.0",
|
|
67
|
+
"ignore": "^5.1.4",
|
|
60
68
|
"js-yaml": "^4.1.0",
|
|
61
69
|
"moment": "^2.29.4",
|
|
70
|
+
"p-queue": "^6.0.2",
|
|
71
|
+
"prettier": "^3.0.3",
|
|
72
|
+
"semver": "^6.3.0",
|
|
73
|
+
"table": "^6.8.1",
|
|
62
74
|
"unixify": "^1.0.0"
|
|
63
75
|
},
|
|
64
76
|
"engines": {
|
|
65
|
-
"node": ">=
|
|
77
|
+
"node": ">=16.20.0"
|
|
66
78
|
}
|
|
67
79
|
}
|