@hubspot/local-dev-lib 1.13.1 → 2.0.1
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/appsDev.d.ts +6 -5
- package/api/appsDev.js +6 -10
- package/api/customObjects.d.ts +7 -6
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +3 -2
- package/api/designManager.js +5 -8
- package/api/developerTestAccounts.d.ts +5 -4
- package/api/developerTestAccounts.js +9 -10
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +9 -9
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -3
- package/api/fileTransport.js +5 -5
- package/api/functions.d.ts +6 -5
- package/api/functions.js +11 -14
- package/api/github.d.ts +6 -6
- package/api/github.js +29 -13
- package/api/hubdb.d.ts +9 -8
- package/api/hubdb.js +17 -20
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +7 -10
- package/api/localDevAuth.d.ts +5 -4
- package/api/localDevAuth.js +8 -9
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +4 -7
- package/api/projects.d.ts +31 -30
- package/api/projects.js +52 -52
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +9 -10
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +5 -4
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +3 -3
- package/config/CLIConfiguration.js +22 -20
- package/config/configFile.js +7 -14
- package/config/config_DEPRECATED.js +5 -2
- package/config/index.js +45 -48
- package/errors/errors_DEPRECATED.js +2 -2
- 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 +2 -2
- package/http/getAxiosConfig.js +10 -2
- package/http/index.d.ts +9 -14
- package/http/index.js +28 -53
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +1 -2
- package/lang/lang/en.json +1 -2
- package/lib/archive.js +11 -10
- package/lib/cms/functions.d.ts +7 -1
- package/lib/cms/functions.js +22 -18
- package/lib/cms/handleFieldsJS.js +8 -7
- package/lib/cms/modules.js +4 -5
- package/lib/cms/processFieldsJs.js +8 -7
- package/lib/cms/templates.js +2 -3
- package/lib/cms/uploadFolder.js +16 -14
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.js +16 -9
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +22 -21
- package/lib/fileMapper.js +24 -31
- package/lib/fs.js +2 -2
- package/lib/github.js +21 -21
- package/lib/gitignore.js +2 -2
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +8 -17
- package/lib/personalAccessKey.js +16 -21
- package/lib/portManager.js +2 -2
- package/lib/trackUsage.js +3 -3
- 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 +1 -2
- package/models/OAuth2Manager.js +13 -28
- package/package.json +2 -1
- package/types/Error.d.ts +7 -5
- package/types/Files.d.ts +4 -4
- package/types/Http.d.ts +6 -10
- package/types/Sandbox.d.ts +0 -5
- package/utils/PortManagerServer.d.ts +3 -3
- package/utils/PortManagerServer.js +9 -9
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/errors/apiErrors.d.ts +0 -25
- package/errors/apiErrors.js +0 -176
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -20
- package/errors/standardErrors.js +0 -62
- package/lib/developerTestAccounts.d.ts +0 -4
- package/lib/developerTestAccounts.js +0 -35
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -70
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
package/lib/fileMapper.js
CHANGED
|
@@ -11,12 +11,11 @@ const p_queue_1 = __importDefault(require("p-queue"));
|
|
|
11
11
|
const path_2 = require("./path");
|
|
12
12
|
const logger_1 = require("./logger");
|
|
13
13
|
const fileMapper_1 = require("../api/fileMapper");
|
|
14
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
15
14
|
const extensions_1 = require("../constants/extensions");
|
|
16
15
|
const files_1 = require("../constants/files");
|
|
17
|
-
const
|
|
18
|
-
const apiErrors_1 = require("../errors/apiErrors");
|
|
16
|
+
const errors_1 = require("../errors");
|
|
19
17
|
const lang_1 = require("../utils/lang");
|
|
18
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
20
19
|
const i18nKey = 'lib.fileMapper';
|
|
21
20
|
const queue = new p_queue_1.default({
|
|
22
21
|
concurrency: 10,
|
|
@@ -77,9 +76,9 @@ function validateFileMapperNode(node) {
|
|
|
77
76
|
catch (err) {
|
|
78
77
|
json = node;
|
|
79
78
|
}
|
|
80
|
-
(0,
|
|
79
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidNode`, {
|
|
81
80
|
json: JSON.stringify(json),
|
|
82
|
-
});
|
|
81
|
+
}));
|
|
83
82
|
}
|
|
84
83
|
function getTypeDataFromPath(src) {
|
|
85
84
|
const isModule = isPathToModule(src);
|
|
@@ -125,10 +124,10 @@ async function writeUtimes(accountId, filepath, node) {
|
|
|
125
124
|
await fs_extra_1.default.utimes(filepath, atime, mtime);
|
|
126
125
|
}
|
|
127
126
|
catch (err) {
|
|
128
|
-
|
|
127
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
129
128
|
filepath,
|
|
130
129
|
accountId,
|
|
131
|
-
|
|
130
|
+
operation: 'write',
|
|
132
131
|
});
|
|
133
132
|
}
|
|
134
133
|
}
|
|
@@ -151,15 +150,9 @@ async function fetchAndWriteFileStream(accountId, srcPath, filepath, mode, optio
|
|
|
151
150
|
return;
|
|
152
151
|
}
|
|
153
152
|
if (!(0, path_2.isAllowedExtension)(srcPath, Array.from(extensions_1.JSR_ALLOWED_EXTENSIONS))) {
|
|
154
|
-
(0,
|
|
155
|
-
}
|
|
156
|
-
let node;
|
|
157
|
-
try {
|
|
158
|
-
node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
(0, standardErrors_1.throwError)(err);
|
|
153
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFileType`, { srcPath }));
|
|
162
154
|
}
|
|
155
|
+
const node = await (0, fileMapper_1.fetchFileStream)(accountId, srcPath, filepath, getFileMapperQueryValues(mode, options));
|
|
163
156
|
await writeUtimes(accountId, filepath, node);
|
|
164
157
|
}
|
|
165
158
|
// Writes an individual file or folder (not recursive). If file source is missing, the
|
|
@@ -188,21 +181,20 @@ async function writeFileMapperNode(accountId, filepath, node, mode, options = {}
|
|
|
188
181
|
}));
|
|
189
182
|
}
|
|
190
183
|
catch (err) {
|
|
191
|
-
|
|
184
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
192
185
|
filepath: localFilepath,
|
|
193
186
|
accountId,
|
|
194
|
-
|
|
187
|
+
operation: 'write',
|
|
195
188
|
});
|
|
196
|
-
return false;
|
|
197
189
|
}
|
|
198
190
|
return true;
|
|
199
191
|
}
|
|
200
192
|
async function downloadFile(accountId, src, destPath, mode, options = {}) {
|
|
201
193
|
const { isFile, isHubspot } = getTypeDataFromPath(src);
|
|
194
|
+
if (!isFile) {
|
|
195
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidRequest`, { src }));
|
|
196
|
+
}
|
|
202
197
|
try {
|
|
203
|
-
if (!isFile) {
|
|
204
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.invalidRequest`, { src });
|
|
205
|
-
}
|
|
206
198
|
const dest = path_1.default.resolve(destPath);
|
|
207
199
|
const cwd = (0, path_2.getCwd)();
|
|
208
200
|
let filepath;
|
|
@@ -232,24 +224,24 @@ async function downloadFile(accountId, src, destPath, mode, options = {}) {
|
|
|
232
224
|
}
|
|
233
225
|
catch (err) {
|
|
234
226
|
const error = err;
|
|
235
|
-
if (isHubspot && (0,
|
|
236
|
-
(0,
|
|
227
|
+
if (isHubspot && (0, errors_1.isTimeoutError)(error)) {
|
|
228
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
|
|
237
229
|
}
|
|
238
230
|
else {
|
|
239
|
-
(0,
|
|
231
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFile`, { src, dest: destPath }), { cause: error });
|
|
240
232
|
}
|
|
241
233
|
}
|
|
242
234
|
}
|
|
243
235
|
async function fetchFolderFromApi(accountId, src, mode, options = {}) {
|
|
244
236
|
const { isRoot, isFolder, isHubspot } = getTypeDataFromPath(src);
|
|
245
237
|
if (!isFolder) {
|
|
246
|
-
(0,
|
|
238
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidFetchFolderRequest`, {
|
|
247
239
|
src,
|
|
248
|
-
});
|
|
240
|
+
}));
|
|
249
241
|
}
|
|
250
242
|
const srcPath = isRoot ? '@root' : src;
|
|
251
243
|
const queryValues = getFileMapperQueryValues(mode, options);
|
|
252
|
-
const node = isHubspot
|
|
244
|
+
const { data: node } = isHubspot
|
|
253
245
|
? await (0, fileMapper_1.downloadDefault)(accountId, srcPath, queryValues)
|
|
254
246
|
: await (0, fileMapper_1.download)(accountId, srcPath, queryValues);
|
|
255
247
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.folderFetch`, { src, accountId }));
|
|
@@ -289,16 +281,17 @@ async function downloadFolder(accountId, src, destPath, mode, options = {}) {
|
|
|
289
281
|
}));
|
|
290
282
|
}
|
|
291
283
|
else {
|
|
292
|
-
|
|
284
|
+
// TODO: Fix this exception. It is triggering the catch block so this error is being rewritten
|
|
285
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.incompleteFetch`, { src }));
|
|
293
286
|
}
|
|
294
287
|
}
|
|
295
288
|
catch (err) {
|
|
296
289
|
const error = err;
|
|
297
|
-
if ((0,
|
|
298
|
-
(0,
|
|
290
|
+
if ((0, errors_1.isTimeoutError)(error)) {
|
|
291
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.assetTimeout`), { cause: error });
|
|
299
292
|
}
|
|
300
293
|
else {
|
|
301
|
-
(0,
|
|
294
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.failedToFetchFolder`, { src, dest: destPath }), { cause: err });
|
|
302
295
|
}
|
|
303
296
|
}
|
|
304
297
|
}
|
package/lib/fs.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.walk = exports.flattenAndRemoveSymlinks = exports.getFileInfoAsync = voi
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const files_1 = require("../constants/files");
|
|
10
|
-
const
|
|
10
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
11
11
|
function getFileInfoAsync(dir, file) {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
const filepath = path_1.default.join(dir, file);
|
|
@@ -65,7 +65,7 @@ async function walk(dir) {
|
|
|
65
65
|
.then(processFiles)
|
|
66
66
|
.then(flattenAndRemoveSymlinks)
|
|
67
67
|
.catch(err => {
|
|
68
|
-
|
|
68
|
+
throw new FileSystemError_1.FileSystemError({ cause: err });
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
exports.walk = walk;
|
package/lib/github.js
CHANGED
|
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.listGithubRepoContents = exports.downloadGithubRepoContents = exports.fetchGitHubRepoContentFromDownloadUrl = exports.cloneGithubRepo = exports.fetchReleaseData = exports.fetchFileFromRepository = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
10
9
|
const archive_1 = require("./archive");
|
|
11
10
|
const logger_1 = require("./logger");
|
|
12
11
|
const github_1 = require("../api/github");
|
|
13
12
|
const lang_1 = require("../utils/lang");
|
|
13
|
+
const errors_1 = require("../errors");
|
|
14
14
|
const i18nKey = 'lib.github';
|
|
15
15
|
async function fetchFileFromRepository(repoPath, filePath, ref) {
|
|
16
16
|
try {
|
|
@@ -21,7 +21,9 @@ async function fetchFileFromRepository(repoPath, filePath, ref) {
|
|
|
21
21
|
return data;
|
|
22
22
|
}
|
|
23
23
|
catch (err) {
|
|
24
|
-
(0,
|
|
24
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchFileFromRepository.errors.fetchFail`), {
|
|
25
|
+
cause: err,
|
|
26
|
+
});
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
exports.fetchFileFromRepository = fetchFileFromRepository;
|
|
@@ -38,7 +40,9 @@ async function fetchReleaseData(repoPath, tag) {
|
|
|
38
40
|
return data;
|
|
39
41
|
}
|
|
40
42
|
catch (err) {
|
|
41
|
-
(0,
|
|
43
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.fetchReleaseData.errors.fetchFail`, {
|
|
44
|
+
tag: tag || 'latest',
|
|
45
|
+
}), { cause: err });
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
exports.fetchReleaseData = fetchReleaseData;
|
|
@@ -65,7 +69,9 @@ async function downloadGithubRepoZip(repoPath, isRelease = false, options = {})
|
|
|
65
69
|
return data;
|
|
66
70
|
}
|
|
67
71
|
catch (err) {
|
|
68
|
-
(0,
|
|
72
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoZip.errors.fetchFail`), {
|
|
73
|
+
cause: err,
|
|
74
|
+
});
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
async function cloneGithubRepo(repoPath, dest, options = {}) {
|
|
@@ -95,7 +101,7 @@ async function fetchGitHubRepoContentFromDownloadUrl(dest, downloadUrl) {
|
|
|
95
101
|
else {
|
|
96
102
|
fileContents = resp.data;
|
|
97
103
|
}
|
|
98
|
-
|
|
104
|
+
fs_extra_1.default.outputFileSync(dest, fileContents);
|
|
99
105
|
}
|
|
100
106
|
exports.fetchGitHubRepoContentFromDownloadUrl = fetchGitHubRepoContentFromDownloadUrl;
|
|
101
107
|
// Writes files from a public repository to the destination folder
|
|
@@ -131,15 +137,12 @@ async function downloadGithubRepoContents(repoPath, contentPath, dest, ref, filt
|
|
|
131
137
|
await Promise.all(contentPromises);
|
|
132
138
|
}
|
|
133
139
|
catch (e) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}, error);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
(0, standardErrors_1.throwError)(error);
|
|
140
|
+
if ((0, errors_1.isSystemError)(e) && e?.error?.message) {
|
|
141
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
|
|
142
|
+
errorMessage: e.error.message,
|
|
143
|
+
}), { cause: e });
|
|
142
144
|
}
|
|
145
|
+
throw e;
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
exports.downloadGithubRepoContents = downloadGithubRepoContents;
|
|
@@ -153,15 +156,12 @@ async function listGithubRepoContents(repoPath, contentPath, fileFilter) {
|
|
|
153
156
|
return filteredFiles;
|
|
154
157
|
}
|
|
155
158
|
catch (e) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
(0, standardErrors_1.throwError)(error);
|
|
159
|
+
if ((0, errors_1.isHubSpotHttpError)(e) && e.data.message) {
|
|
160
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.downloadGithubRepoContents.errors.fetchFail`, {
|
|
161
|
+
errorMessage: e.data.message,
|
|
162
|
+
}));
|
|
164
163
|
}
|
|
164
|
+
throw e;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
exports.listGithubRepoContents = listGithubRepoContents;
|
package/lib/gitignore.js
CHANGED
|
@@ -8,7 +8,7 @@ const fs_extra_1 = require("fs-extra");
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const git_1 = require("../utils/git");
|
|
10
10
|
const config_1 = require("../constants/config");
|
|
11
|
-
const
|
|
11
|
+
const lang_1 = require("../utils/lang");
|
|
12
12
|
const i18nKey = 'lib.gitignore';
|
|
13
13
|
const GITIGNORE_FILE = '.gitignore';
|
|
14
14
|
function checkAndAddConfigToGitignore(configPath) {
|
|
@@ -26,7 +26,7 @@ function checkAndAddConfigToGitignore(configPath) {
|
|
|
26
26
|
(0, fs_extra_1.writeFileSync)(gitignoreFilePath, updatedContents);
|
|
27
27
|
}
|
|
28
28
|
catch (e) {
|
|
29
|
-
(0,
|
|
29
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.configIgnore`), { cause: e });
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.checkAndAddConfigToGitignore = checkAndAddConfigToGitignore;
|
package/lib/hubdb.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { Row, Table } from '../types/Hubdb';
|
|
2
3
|
export declare function addRowsToHubDbTable(accountId: number, tableId: string, rows?: Array<Row>): Promise<{
|
|
3
4
|
tableId: string;
|
|
4
5
|
rowCount: number;
|
|
@@ -7,7 +8,7 @@ export declare function createHubDbTable(accountId: number, src: string): Promis
|
|
|
7
8
|
tableId: string;
|
|
8
9
|
rowCount: number;
|
|
9
10
|
}>;
|
|
10
|
-
export declare function updateHubDbTable(accountId: number, tableId: string, src: string): Promise<
|
|
11
|
+
export declare function updateHubDbTable(accountId: number, tableId: string, src: string): Promise<AxiosResponse<Table, any>>;
|
|
11
12
|
export declare function downloadHubDbTable(accountId: number, tableId: string, dest: string): Promise<{
|
|
12
13
|
filePath: string;
|
|
13
14
|
}>;
|
package/lib/hubdb.js
CHANGED
|
@@ -9,11 +9,11 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
9
9
|
const prettier_1 = __importDefault(require("prettier"));
|
|
10
10
|
const hubdb_1 = require("../api/hubdb");
|
|
11
11
|
const path_2 = require("./path");
|
|
12
|
-
const
|
|
12
|
+
const lang_1 = require("../utils/lang");
|
|
13
13
|
const i18nKey = 'lib.hubdb';
|
|
14
14
|
function validateJsonPath(src) {
|
|
15
15
|
if (path_1.default.extname(src) !== '.json') {
|
|
16
|
-
(0,
|
|
16
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonPath`));
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
function validateJsonFile(src) {
|
|
@@ -22,10 +22,12 @@ function validateJsonFile(src) {
|
|
|
22
22
|
stats = fs_extra_1.default.statSync(src);
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|
|
25
|
-
(0,
|
|
25
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }), {
|
|
26
|
+
cause: err,
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
if (!stats.isFile()) {
|
|
28
|
-
(0,
|
|
30
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidJsonFile`, { src }));
|
|
29
31
|
}
|
|
30
32
|
validateJsonPath(src);
|
|
31
33
|
}
|
|
@@ -42,7 +44,7 @@ async function addRowsToHubDbTable(accountId, tableId, rows = []) {
|
|
|
42
44
|
if (rowsToUpdate.length > 0) {
|
|
43
45
|
await (0, hubdb_1.createRows)(accountId, tableId, rowsToUpdate);
|
|
44
46
|
}
|
|
45
|
-
const { rowCount } = await (0, hubdb_1.publishTable)(accountId, tableId);
|
|
47
|
+
const { data: { rowCount }, } = await (0, hubdb_1.publishTable)(accountId, tableId);
|
|
46
48
|
return {
|
|
47
49
|
tableId,
|
|
48
50
|
rowCount,
|
|
@@ -53,7 +55,7 @@ async function createHubDbTable(accountId, src) {
|
|
|
53
55
|
validateJsonFile(src);
|
|
54
56
|
const table = fs_extra_1.default.readJsonSync(src);
|
|
55
57
|
const { rows, ...schema } = table;
|
|
56
|
-
const { id } = await (0, hubdb_1.createTable)(accountId, schema);
|
|
58
|
+
const { data: { id }, } = await (0, hubdb_1.createTable)(accountId, schema);
|
|
57
59
|
return addRowsToHubDbTable(accountId, id, rows);
|
|
58
60
|
}
|
|
59
61
|
exports.createHubDbTable = createHubDbTable;
|
|
@@ -96,15 +98,15 @@ async function fetchAllRows(accountId, tableId) {
|
|
|
96
98
|
let rows = [];
|
|
97
99
|
let after = null;
|
|
98
100
|
do {
|
|
99
|
-
const
|
|
100
|
-
const { paging, results } =
|
|
101
|
+
const axiosResponse = await (0, hubdb_1.fetchRows)(accountId, tableId, after ? { after } : undefined);
|
|
102
|
+
const { paging, results } = axiosResponse.data;
|
|
101
103
|
rows = rows.concat(results);
|
|
102
104
|
after = paging && paging.next ? paging.next.after : null;
|
|
103
105
|
} while (after !== null);
|
|
104
106
|
return rows;
|
|
105
107
|
}
|
|
106
108
|
async function downloadHubDbTable(accountId, tableId, dest) {
|
|
107
|
-
const table = await (0, hubdb_1.fetchTable)(accountId, tableId);
|
|
109
|
+
const { data: table } = await (0, hubdb_1.fetchTable)(accountId, tableId);
|
|
108
110
|
dest = path_1.default.resolve((0, path_2.getCwd)(), dest || `${table.name}.hubdb.json`);
|
|
109
111
|
if (fs_extra_1.default.pathExistsSync(dest)) {
|
|
110
112
|
validateJsonFile(dest);
|
package/lib/notify.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.triggerNotify = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const debounce_1 = __importDefault(require("debounce"));
|
|
10
|
-
const
|
|
10
|
+
const lang_1 = require("../utils/lang");
|
|
11
11
|
const i18nKey = 'utils.notify';
|
|
12
12
|
const notifyQueue = [];
|
|
13
13
|
const notifyPromises = [];
|
|
@@ -37,7 +37,7 @@ function notifyFilePath(filePathToNotify, outputToWrite) {
|
|
|
37
37
|
fs_1.default.appendFileSync(filePathToNotify, outputToWrite);
|
|
38
38
|
}
|
|
39
39
|
catch (e) {
|
|
40
|
-
(0,
|
|
40
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.filePath`, { filePath: filePathToNotify }), { cause: e });
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
package/lib/oauth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import OAuth2Manager from '../models/OAuth2Manager';
|
|
1
|
+
import { OAuth2Manager } from '../models/OAuth2Manager';
|
|
2
2
|
import { FlatAccountFields } from '../types/Accounts';
|
|
3
3
|
export declare function getOauthManager(accountId: number, accountConfig: FlatAccountFields): OAuth2Manager | undefined;
|
|
4
4
|
export declare function addOauthToAccountConfig(oauth: OAuth2Manager): void;
|
package/lib/oauth.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addOauthToAccountConfig = exports.getOauthManager = void 0;
|
|
7
|
-
const OAuth2Manager_1 =
|
|
4
|
+
const OAuth2Manager_1 = require("../models/OAuth2Manager");
|
|
8
5
|
const auth_1 = require("../constants/auth");
|
|
9
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
10
6
|
const logger_1 = require("./logger");
|
|
11
7
|
const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
|
|
12
8
|
const config_1 = require("../config");
|
|
@@ -21,23 +17,18 @@ function writeOauthTokenInfo(accountConfig) {
|
|
|
21
17
|
}
|
|
22
18
|
function getOauthManager(accountId, accountConfig) {
|
|
23
19
|
if (!oauthManagers.has(accountId)) {
|
|
24
|
-
oauthManagers.set(accountId, OAuth2Manager_1.
|
|
20
|
+
oauthManagers.set(accountId, OAuth2Manager_1.OAuth2Manager.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
|
|
25
21
|
}
|
|
26
22
|
return oauthManagers.get(accountId);
|
|
27
23
|
}
|
|
28
24
|
exports.getOauthManager = getOauthManager;
|
|
29
25
|
function addOauthToAccountConfig(oauth) {
|
|
30
26
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.init`));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.success`));
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
(0, standardErrors_1.throwError)(err);
|
|
41
|
-
}
|
|
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`));
|
|
42
33
|
}
|
|
43
34
|
exports.addOauthToAccountConfig = addOauthToAccountConfig;
|
package/lib/personalAccessKey.js
CHANGED
|
@@ -7,33 +7,22 @@ exports.updateConfigWithAccessToken = exports.scopesOnAccessToken = exports.enab
|
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
const environments_1 = require("../constants/environments");
|
|
9
9
|
const auth_1 = require("../constants/auth");
|
|
10
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
11
10
|
const localDevAuth_1 = require("../api/localDevAuth");
|
|
12
11
|
const sandboxHubs_1 = require("../api/sandboxHubs");
|
|
13
12
|
const config_1 = require("../config");
|
|
14
13
|
const config_2 = require("../constants/config");
|
|
15
14
|
const developerTestAccounts_1 = require("../api/developerTestAccounts");
|
|
16
15
|
const logger_1 = require("./logger");
|
|
17
|
-
const
|
|
16
|
+
const lang_1 = require("../utils/lang");
|
|
17
|
+
const errors_1 = require("../errors");
|
|
18
18
|
const i18nKey = 'lib.personalAccessKey';
|
|
19
19
|
const refreshRequests = new Map();
|
|
20
20
|
function getRefreshKey(personalAccessKey, expiration) {
|
|
21
21
|
return `${personalAccessKey}-${expiration || 'fresh'}`;
|
|
22
22
|
}
|
|
23
23
|
async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
response = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
29
|
-
const error = e;
|
|
30
|
-
if (error.response) {
|
|
31
|
-
(0, standardErrors_1.throwAuthErrorWithMessage)(`${i18nKey}.errors.invalidPersonalAccessKey`, { errorMessage: error.response.data.message || '' }, error);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
(0, standardErrors_1.throwError)(e);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
24
|
+
const axiosResponse = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
|
|
25
|
+
const response = axiosResponse.data;
|
|
37
26
|
return {
|
|
38
27
|
portalId: response.hubId,
|
|
39
28
|
accessToken: response.oauthAccessToken,
|
|
@@ -86,7 +75,7 @@ async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
|
|
|
86
75
|
async function getNewAccessTokenByAccountId(accountId) {
|
|
87
76
|
const account = (0, config_1.getAccountConfig)(accountId);
|
|
88
77
|
if (!account) {
|
|
89
|
-
(0,
|
|
78
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
90
79
|
}
|
|
91
80
|
const { auth, personalAccessKey, env } = account;
|
|
92
81
|
const accessTokenResponse = await getNewAccessToken(accountId, personalAccessKey, auth?.tokenInfo?.expiresAt, env);
|
|
@@ -95,7 +84,7 @@ async function getNewAccessTokenByAccountId(accountId) {
|
|
|
95
84
|
async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
|
|
96
85
|
const account = (0, config_1.getAccountConfig)(accountId);
|
|
97
86
|
if (!account) {
|
|
98
|
-
(0,
|
|
87
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
99
88
|
}
|
|
100
89
|
const { auth, personalAccessKey, env } = account;
|
|
101
90
|
const authTokenInfo = auth && auth.tokenInfo;
|
|
@@ -124,7 +113,7 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
124
113
|
try {
|
|
125
114
|
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
|
|
126
115
|
accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
127
|
-
const sandboxDataResponse = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
|
|
116
|
+
const { data: sandboxDataResponse } = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
|
|
128
117
|
if (sandboxDataResponse.parentHubId) {
|
|
129
118
|
parentAccountId = sandboxDataResponse.parentHubId;
|
|
130
119
|
}
|
|
@@ -132,11 +121,14 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
132
121
|
}
|
|
133
122
|
catch (err) {
|
|
134
123
|
// Log error but do not throw
|
|
135
|
-
|
|
124
|
+
if ((0, errors_1.isHubSpotHttpError)(err)) {
|
|
125
|
+
logger_1.logger.debug(err.message);
|
|
126
|
+
}
|
|
127
|
+
logger_1.logger.debug(err);
|
|
136
128
|
}
|
|
137
129
|
try {
|
|
138
130
|
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
|
|
139
|
-
const developerTestAccountResponse = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
|
|
131
|
+
const { data: developerTestAccountResponse } = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
|
|
140
132
|
if (developerTestAccountResponse) {
|
|
141
133
|
parentAccountId = developerTestAccountResponse.parentPortalId;
|
|
142
134
|
}
|
|
@@ -144,7 +136,10 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
144
136
|
}
|
|
145
137
|
catch (err) {
|
|
146
138
|
// Log error but do not throw
|
|
147
|
-
|
|
139
|
+
if ((0, errors_1.isHubSpotHttpError)(err)) {
|
|
140
|
+
logger_1.logger.debug(err.message);
|
|
141
|
+
}
|
|
142
|
+
logger_1.logger.debug(err);
|
|
148
143
|
}
|
|
149
144
|
const updatedConfig = (0, config_1.updateAccountConfig)({
|
|
150
145
|
accountId: portalId,
|
package/lib/portManager.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.BASE_URL = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const PortManagerServer_1 =
|
|
8
|
+
const PortManagerServer_1 = require("../utils/PortManagerServer");
|
|
9
9
|
const detectPort_1 = require("../utils/detectPort");
|
|
10
10
|
const ports_1 = require("../constants/ports");
|
|
11
11
|
exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
|
|
@@ -16,7 +16,7 @@ async function isPortManagerServerRunning() {
|
|
|
16
16
|
async function startPortManagerServer() {
|
|
17
17
|
const isRunning = await isPortManagerServerRunning();
|
|
18
18
|
if (!isRunning) {
|
|
19
|
-
await PortManagerServer_1.
|
|
19
|
+
await PortManagerServer_1.PortManagerServer.init();
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.startPortManagerServer = startPortManagerServer;
|
package/lib/trackUsage.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.trackUsage = void 0;
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const getAxiosConfig_1 = require("../http/getAxiosConfig");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
10
|
-
const http_1 =
|
|
10
|
+
const http_1 = require("../http");
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
const fileMapper_1 = require("../api/fileMapper");
|
|
13
13
|
const lang_1 = require("../utils/lang");
|
|
@@ -39,12 +39,12 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
39
39
|
if (accountConfig && accountConfig.authType === 'personalaccesskey') {
|
|
40
40
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
await http_1.http.post(accountId, {
|
|
43
43
|
url: `${path}/authenticated`,
|
|
44
44
|
data: usageEvent,
|
|
45
45
|
resolveWithFullResponse: true,
|
|
46
46
|
});
|
|
47
|
-
return
|
|
47
|
+
return;
|
|
48
48
|
}
|
|
49
49
|
catch (e) {
|
|
50
50
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
|
|
@@ -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;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HubSpotHttpErrorContext } from '../types/Error';
|
|
2
|
+
export declare class HubSpotHttpError<T = any> extends Error {
|
|
3
|
+
status?: number;
|
|
4
|
+
code?: string;
|
|
5
|
+
statusText?: string;
|
|
6
|
+
data?: T;
|
|
7
|
+
headers?: {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
method: string | undefined;
|
|
11
|
+
context: HubSpotHttpErrorContext | undefined;
|
|
12
|
+
derivedContext: HubSpotHttpErrorContext | undefined;
|
|
13
|
+
validationErrors: string[] | undefined;
|
|
14
|
+
detailedMessage?: string;
|
|
15
|
+
private divider;
|
|
16
|
+
cause: ErrorOptions['cause'];
|
|
17
|
+
constructor(message?: string, options?: ErrorOptions, context?: HubSpotHttpErrorContext);
|
|
18
|
+
updateContext(context: Partial<HubSpotHttpErrorContext>): void;
|
|
19
|
+
toString(): string;
|
|
20
|
+
formattedValidationErrors(): string;
|
|
21
|
+
private extractDerivedContext;
|
|
22
|
+
private parseValidationErrors;
|
|
23
|
+
private joinErrorMessages;
|
|
24
|
+
}
|