@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/hubdb.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
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.clearHubDbTableRows = exports.downloadHubDbTable = exports.updateHubDbTable = exports.createHubDbTable = exports.addRowsToHubDbTable = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const prettier_1 = __importDefault(require("prettier"));
|
|
10
|
+
const hubdb_1 = require("../api/hubdb");
|
|
11
|
+
const path_2 = require("./path");
|
|
12
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
13
|
+
function validateJsonPath(src) {
|
|
14
|
+
if (path_1.default.extname(src) !== '.json') {
|
|
15
|
+
(0, standardErrors_1.throwErrorWithMessage)('hubdb.invalidJsonPath');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function validateJsonFile(src) {
|
|
19
|
+
let stats;
|
|
20
|
+
try {
|
|
21
|
+
stats = fs_extra_1.default.statSync(src);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
(0, standardErrors_1.throwErrorWithMessage)('hubdb.invalidJsonFile', { src }, err);
|
|
25
|
+
}
|
|
26
|
+
if (!stats.isFile()) {
|
|
27
|
+
(0, standardErrors_1.throwErrorWithMessage)('hubdb.invalidJsonFile', { src });
|
|
28
|
+
}
|
|
29
|
+
validateJsonPath(src);
|
|
30
|
+
}
|
|
31
|
+
async function addRowsToHubDbTable(accountId, tableId, rows) {
|
|
32
|
+
const rowsToUpdate = rows.map(row => {
|
|
33
|
+
const values = row.values;
|
|
34
|
+
return {
|
|
35
|
+
childTableId: '0',
|
|
36
|
+
isSoftEditable: false,
|
|
37
|
+
...row,
|
|
38
|
+
values,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
if (rowsToUpdate.length > 0) {
|
|
42
|
+
await (0, hubdb_1.createRows)(accountId, tableId, rowsToUpdate);
|
|
43
|
+
}
|
|
44
|
+
const { rowCount } = await (0, hubdb_1.publishTable)(accountId, tableId);
|
|
45
|
+
return {
|
|
46
|
+
tableId,
|
|
47
|
+
rowCount,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.addRowsToHubDbTable = addRowsToHubDbTable;
|
|
51
|
+
async function createHubDbTable(accountId, src) {
|
|
52
|
+
validateJsonFile(src);
|
|
53
|
+
const table = fs_extra_1.default.readJsonSync(src);
|
|
54
|
+
const { rows, ...schema } = table;
|
|
55
|
+
const { id } = await (0, hubdb_1.createTable)(accountId, schema);
|
|
56
|
+
return addRowsToHubDbTable(accountId, id, rows);
|
|
57
|
+
}
|
|
58
|
+
exports.createHubDbTable = createHubDbTable;
|
|
59
|
+
async function updateHubDbTable(accountId, tableId, src) {
|
|
60
|
+
validateJsonFile(src);
|
|
61
|
+
const table = fs_extra_1.default.readJsonSync(src);
|
|
62
|
+
const { ...schema } = table;
|
|
63
|
+
return (0, hubdb_1.updateTable)(accountId, tableId, schema);
|
|
64
|
+
}
|
|
65
|
+
exports.updateHubDbTable = updateHubDbTable;
|
|
66
|
+
function convertToJSON(table, rows) {
|
|
67
|
+
const { allowChildTables, allowPublicApiAccess, columns, dynamicMetaTags, enableChildTablePages, label, name, useForPages, } = table;
|
|
68
|
+
const cleanedColumns = columns
|
|
69
|
+
.filter(column => !column.deleted || !column.archived)
|
|
70
|
+
.map(({
|
|
71
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
72
|
+
id, deleted, archived, foreignIdsByName, foreignIdsById,
|
|
73
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
74
|
+
...cleanedColumn }) => cleanedColumn);
|
|
75
|
+
const cleanedRows = rows.map(row => {
|
|
76
|
+
return {
|
|
77
|
+
path: row.path,
|
|
78
|
+
name: row.name,
|
|
79
|
+
values: row.values,
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
useForPages,
|
|
85
|
+
label,
|
|
86
|
+
allowChildTables,
|
|
87
|
+
allowPublicApiAccess,
|
|
88
|
+
dynamicMetaTags,
|
|
89
|
+
enableChildTablePages,
|
|
90
|
+
columns: cleanedColumns,
|
|
91
|
+
rows: cleanedRows,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function fetchAllRows(accountId, tableId) {
|
|
95
|
+
let rows = [];
|
|
96
|
+
let after = null;
|
|
97
|
+
do {
|
|
98
|
+
const response = await (0, hubdb_1.fetchRows)(accountId, tableId, after ? { after } : undefined);
|
|
99
|
+
const { paging, results } = response;
|
|
100
|
+
rows = rows.concat(results);
|
|
101
|
+
after = paging && paging.next ? paging.next.after : null;
|
|
102
|
+
} while (after !== null);
|
|
103
|
+
return rows;
|
|
104
|
+
}
|
|
105
|
+
async function downloadHubDbTable(accountId, tableId, dest) {
|
|
106
|
+
const table = await (0, hubdb_1.fetchTable)(accountId, tableId);
|
|
107
|
+
dest = path_1.default.resolve((0, path_2.getCwd)(), dest || `${table.name}.hubdb.json`);
|
|
108
|
+
if (fs_extra_1.default.pathExistsSync(dest)) {
|
|
109
|
+
validateJsonFile(dest);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
validateJsonPath(dest);
|
|
113
|
+
}
|
|
114
|
+
const rows = await fetchAllRows(accountId, tableId);
|
|
115
|
+
const tableToWrite = JSON.stringify(convertToJSON(table, rows));
|
|
116
|
+
const tableJson = await prettier_1.default.format(tableToWrite, {
|
|
117
|
+
parser: 'json',
|
|
118
|
+
});
|
|
119
|
+
await fs_extra_1.default.outputFile(dest, tableJson);
|
|
120
|
+
return { filePath: dest };
|
|
121
|
+
}
|
|
122
|
+
exports.downloadHubDbTable = downloadHubDbTable;
|
|
123
|
+
async function clearHubDbTableRows(accountId, tableId) {
|
|
124
|
+
const rows = await fetchAllRows(accountId, tableId);
|
|
125
|
+
await (0, hubdb_1.deleteRows)(accountId, tableId, rows.map(row => row.id));
|
|
126
|
+
return {
|
|
127
|
+
deletedRowCount: rows.length,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
exports.clearHubDbTableRows = clearHubDbTableRows;
|
|
@@ -0,0 +1,69 @@
|
|
|
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.ignoreFile = exports.createIgnoreFilter = exports.shouldIgnoreFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const ignore_1 = __importDefault(require("ignore"));
|
|
10
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
11
|
+
const ignoreList = [
|
|
12
|
+
'fields.output.json',
|
|
13
|
+
'hubspot.config.yml',
|
|
14
|
+
'hubspot.config.yaml',
|
|
15
|
+
'node_modules',
|
|
16
|
+
'.*',
|
|
17
|
+
'*.log',
|
|
18
|
+
'*.swp',
|
|
19
|
+
'.env',
|
|
20
|
+
// # macOS
|
|
21
|
+
'Icon\\r',
|
|
22
|
+
'__MACOSX',
|
|
23
|
+
// # Linux
|
|
24
|
+
'~',
|
|
25
|
+
// # Emacs
|
|
26
|
+
'*~',
|
|
27
|
+
// # Windows
|
|
28
|
+
'Thumbs.db',
|
|
29
|
+
'ehthumbs.db',
|
|
30
|
+
'Desktop.ini',
|
|
31
|
+
'@eaDir', // Synology Diskstation "hidden" folder where the server stores thumbnails
|
|
32
|
+
];
|
|
33
|
+
const ignoreRules = (0, ignore_1.default)().add(ignoreList);
|
|
34
|
+
let searchDomain = null;
|
|
35
|
+
let loaded = false;
|
|
36
|
+
function loadIgnoreConfig(isInProject = false) {
|
|
37
|
+
if (loaded) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Temporary solution to improve serverless beta: https://git.hubteam.com/HubSpot/cms-devex-super-repo/issues/2
|
|
41
|
+
// Do not do this when in a developer project b/c we want the package-lock.json file uploaded.
|
|
42
|
+
if (!isInProject) {
|
|
43
|
+
ignoreRules.add('package-lock.json');
|
|
44
|
+
}
|
|
45
|
+
const file = (0, findup_sync_1.default)('.hsignore');
|
|
46
|
+
if (file) {
|
|
47
|
+
if (fs_1.default.existsSync(file)) {
|
|
48
|
+
ignoreRules.add(fs_1.default.readFileSync(file).toString());
|
|
49
|
+
searchDomain = path_1.default.dirname(file);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
loaded = true;
|
|
53
|
+
}
|
|
54
|
+
function shouldIgnoreFile(file, isInProject = false) {
|
|
55
|
+
loadIgnoreConfig(isInProject);
|
|
56
|
+
const relativeTo = searchDomain || '/';
|
|
57
|
+
const relativePath = path_1.default.relative(relativeTo, file);
|
|
58
|
+
return !!relativePath && ignoreRules.ignores(relativePath);
|
|
59
|
+
}
|
|
60
|
+
exports.shouldIgnoreFile = shouldIgnoreFile;
|
|
61
|
+
function createIgnoreFilter(isInProject) {
|
|
62
|
+
loadIgnoreConfig(isInProject);
|
|
63
|
+
return (file) => !shouldIgnoreFile(file);
|
|
64
|
+
}
|
|
65
|
+
exports.createIgnoreFilter = createIgnoreFilter;
|
|
66
|
+
function ignoreFile(filePath) {
|
|
67
|
+
ignoreRules.add(filePath);
|
|
68
|
+
}
|
|
69
|
+
exports.ignoreFile = ignoreFile;
|
|
@@ -0,0 +1,54 @@
|
|
|
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.checkAndUpdateGitignore = exports.checkAndWarnGitInclusion = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const git_1 = require("../../utils/git");
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const lang_1 = require("../../utils/lang");
|
|
13
|
+
const config_1 = require("../../constants/config");
|
|
14
|
+
const GITIGNORE_FILE = '.gitignore';
|
|
15
|
+
const i18nKey = 'debug.git';
|
|
16
|
+
function checkAndWarnGitInclusion(configPath) {
|
|
17
|
+
try {
|
|
18
|
+
const { inGit, configIgnored } = (0, git_1.checkGitInclusion)(configPath);
|
|
19
|
+
if (!inGit || configIgnored)
|
|
20
|
+
return;
|
|
21
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.securityIssue`));
|
|
22
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.configFileTracked`));
|
|
23
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.fileName`, { configPath }));
|
|
24
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.remediate`));
|
|
25
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.moveConfig`, { homeDir: os_1.default.homedir() }));
|
|
26
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.addGitignore`, { configPath }));
|
|
27
|
+
logger_1.logger.warn((0, lang_1.i18n)(`${i18nKey}.noRemote`));
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
// fail silently
|
|
31
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.checkFailed`));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.checkAndWarnGitInclusion = checkAndWarnGitInclusion;
|
|
35
|
+
function checkAndUpdateGitignore(configPath) {
|
|
36
|
+
try {
|
|
37
|
+
const { configIgnored, gitignoreFiles } = (0, git_1.checkGitInclusion)(configPath);
|
|
38
|
+
if (configIgnored)
|
|
39
|
+
return;
|
|
40
|
+
let gitignoreFilePath = gitignoreFiles && gitignoreFiles.length ? gitignoreFiles[0] : null;
|
|
41
|
+
if (!gitignoreFilePath) {
|
|
42
|
+
gitignoreFilePath = path_1.default.resolve(configPath, GITIGNORE_FILE);
|
|
43
|
+
fs_extra_1.default.writeFileSync(gitignoreFilePath, '');
|
|
44
|
+
}
|
|
45
|
+
const gitignoreContents = fs_extra_1.default.readFileSync(gitignoreFilePath).toString();
|
|
46
|
+
const updatedContents = `${gitignoreContents.trim()}\n\n# HubSpot config file\n${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}\n`;
|
|
47
|
+
fs_extra_1.default.writeFileSync(gitignoreFilePath, updatedContents);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// fail silently
|
|
51
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.checkFailed`));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.checkAndUpdateGitignore = checkAndUpdateGitignore;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export declare const LOG_LEVEL: {
|
|
3
|
+
NONE: number;
|
|
4
|
+
DEBUG: number;
|
|
5
|
+
LOG: number;
|
|
6
|
+
WARN: number;
|
|
7
|
+
ERROR: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Chalk styles for logger strings.
|
|
11
|
+
*/
|
|
12
|
+
export declare const Styles: {
|
|
13
|
+
debug: chalk.Chalk;
|
|
14
|
+
log: chalk.Chalk;
|
|
15
|
+
success: chalk.Chalk;
|
|
16
|
+
info: chalk.Chalk;
|
|
17
|
+
warn: chalk.Chalk;
|
|
18
|
+
error: chalk.Chalk;
|
|
19
|
+
};
|
|
20
|
+
export declare function stylize(label: string, style: (...text: unknown[]) => string, args: any[]): any[];
|
|
21
|
+
export declare class Logger {
|
|
22
|
+
error(...args: any[]): void;
|
|
23
|
+
warn(...args: any[]): void;
|
|
24
|
+
log(...args: any[]): void;
|
|
25
|
+
success(...args: any[]): void;
|
|
26
|
+
info(...args: any[]): void;
|
|
27
|
+
debug(...args: any[]): void;
|
|
28
|
+
group(...args: any[]): void;
|
|
29
|
+
groupEnd(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare function setLogger(logger: Logger): void;
|
|
32
|
+
export declare function setLogLevel(level: number): void;
|
|
33
|
+
export declare function shouldLog(level: number): number;
|
|
34
|
+
export declare function getLogLevel(): number;
|
|
35
|
+
export declare const logger: {
|
|
36
|
+
error(...args: any[]): void;
|
|
37
|
+
warn(...args: any[]): void;
|
|
38
|
+
log(...args: any[]): void;
|
|
39
|
+
success(...args: any[]): void;
|
|
40
|
+
info(...args: any[]): void;
|
|
41
|
+
debug(...args: any[]): void;
|
|
42
|
+
group(...args: any[]): void;
|
|
43
|
+
groupEnd(): void;
|
|
44
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.logger = exports.getLogLevel = exports.shouldLog = exports.setLogLevel = exports.setLogger = exports.Logger = exports.stylize = exports.Styles = exports.LOG_LEVEL = void 0;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
exports.LOG_LEVEL = {
|
|
10
|
+
NONE: 0,
|
|
11
|
+
DEBUG: 1,
|
|
12
|
+
LOG: 2,
|
|
13
|
+
WARN: 4,
|
|
14
|
+
ERROR: 8,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Chalk styles for logger strings.
|
|
18
|
+
*/
|
|
19
|
+
exports.Styles = {
|
|
20
|
+
debug: chalk_1.default.reset.blue,
|
|
21
|
+
log: chalk_1.default.reset,
|
|
22
|
+
success: chalk_1.default.reset.green,
|
|
23
|
+
info: chalk_1.default.reset.white,
|
|
24
|
+
warn: chalk_1.default.reset.yellow,
|
|
25
|
+
error: chalk_1.default.reset.red,
|
|
26
|
+
};
|
|
27
|
+
function stylize(label, style, args) {
|
|
28
|
+
const styledLabel = style(label);
|
|
29
|
+
const [firstArg, ...rest] = args;
|
|
30
|
+
if (typeof firstArg === 'string') {
|
|
31
|
+
return [`${styledLabel} ${firstArg}`, ...rest];
|
|
32
|
+
}
|
|
33
|
+
return [styledLabel, ...args];
|
|
34
|
+
}
|
|
35
|
+
exports.stylize = stylize;
|
|
36
|
+
class Logger {
|
|
37
|
+
error(...args) {
|
|
38
|
+
console.error(...stylize('[ERROR]', exports.Styles.error, args));
|
|
39
|
+
}
|
|
40
|
+
warn(...args) {
|
|
41
|
+
console.warn(...stylize('[WARNING]', exports.Styles.warn, args));
|
|
42
|
+
}
|
|
43
|
+
log(...args) {
|
|
44
|
+
console.log(...args);
|
|
45
|
+
}
|
|
46
|
+
success(...args) {
|
|
47
|
+
console.log(...stylize('[SUCCESS]', exports.Styles.success, args));
|
|
48
|
+
}
|
|
49
|
+
info(...args) {
|
|
50
|
+
console.info(...stylize('[INFO]', exports.Styles.info, args));
|
|
51
|
+
}
|
|
52
|
+
debug(...args) {
|
|
53
|
+
console.debug(...stylize('[DEBUG]', exports.Styles.log, args));
|
|
54
|
+
}
|
|
55
|
+
group(...args) {
|
|
56
|
+
console.group(...args);
|
|
57
|
+
}
|
|
58
|
+
groupEnd() {
|
|
59
|
+
console.groupEnd();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Logger = Logger;
|
|
63
|
+
let currentLogger = new Logger();
|
|
64
|
+
let currentLogLevel = exports.LOG_LEVEL.ERROR;
|
|
65
|
+
function setLogger(logger) {
|
|
66
|
+
currentLogger = logger;
|
|
67
|
+
}
|
|
68
|
+
exports.setLogger = setLogger;
|
|
69
|
+
function setLogLevel(level) {
|
|
70
|
+
switch (level) {
|
|
71
|
+
case exports.LOG_LEVEL.DEBUG:
|
|
72
|
+
currentLogLevel =
|
|
73
|
+
exports.LOG_LEVEL.DEBUG | exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
|
|
74
|
+
break;
|
|
75
|
+
case exports.LOG_LEVEL.LOG:
|
|
76
|
+
currentLogLevel = exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
|
|
77
|
+
break;
|
|
78
|
+
case exports.LOG_LEVEL.WARN:
|
|
79
|
+
currentLogLevel = exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR;
|
|
80
|
+
break;
|
|
81
|
+
case exports.LOG_LEVEL.ERROR:
|
|
82
|
+
currentLogLevel = exports.LOG_LEVEL.ERROR;
|
|
83
|
+
break;
|
|
84
|
+
case exports.LOG_LEVEL.NONE:
|
|
85
|
+
default:
|
|
86
|
+
currentLogLevel = exports.LOG_LEVEL.NONE;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.setLogLevel = setLogLevel;
|
|
90
|
+
function shouldLog(level) {
|
|
91
|
+
return currentLogLevel & level;
|
|
92
|
+
}
|
|
93
|
+
exports.shouldLog = shouldLog;
|
|
94
|
+
function getLogLevel() {
|
|
95
|
+
switch (currentLogLevel) {
|
|
96
|
+
case exports.LOG_LEVEL.DEBUG | exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
|
|
97
|
+
return exports.LOG_LEVEL.DEBUG;
|
|
98
|
+
case exports.LOG_LEVEL.LOG | exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
|
|
99
|
+
return exports.LOG_LEVEL.LOG;
|
|
100
|
+
case exports.LOG_LEVEL.WARN | exports.LOG_LEVEL.ERROR:
|
|
101
|
+
return exports.LOG_LEVEL.WARN;
|
|
102
|
+
case exports.LOG_LEVEL.ERROR:
|
|
103
|
+
return exports.LOG_LEVEL.ERROR;
|
|
104
|
+
default:
|
|
105
|
+
return exports.LOG_LEVEL.NONE;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.getLogLevel = getLogLevel;
|
|
109
|
+
exports.logger = {
|
|
110
|
+
error(...args) {
|
|
111
|
+
if (shouldLog(exports.LOG_LEVEL.ERROR)) {
|
|
112
|
+
currentLogger.error(...args);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
warn(...args) {
|
|
116
|
+
if (shouldLog(exports.LOG_LEVEL.WARN)) {
|
|
117
|
+
currentLogger.warn(...args);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
log(...args) {
|
|
121
|
+
if (shouldLog(exports.LOG_LEVEL.LOG)) {
|
|
122
|
+
currentLogger.log(...args);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
success(...args) {
|
|
126
|
+
if (shouldLog(exports.LOG_LEVEL.LOG)) {
|
|
127
|
+
currentLogger.success(...args);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
info(...args) {
|
|
131
|
+
if (shouldLog(exports.LOG_LEVEL.LOG)) {
|
|
132
|
+
currentLogger.info(...args);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
debug(...args) {
|
|
136
|
+
if (shouldLog(exports.LOG_LEVEL.DEBUG)) {
|
|
137
|
+
currentLogger.debug(...args);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
group(...args) {
|
|
141
|
+
currentLogger.group(...args);
|
|
142
|
+
},
|
|
143
|
+
groupEnd() {
|
|
144
|
+
currentLogger.groupEnd();
|
|
145
|
+
},
|
|
146
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
type Log = {
|
|
2
|
+
log: string;
|
|
3
|
+
status: 'SUCCESS' | 'ERROR' | 'UNHANDLED_ERROR' | 'HANDLED_ERROR';
|
|
4
|
+
createdAt: string;
|
|
5
|
+
executionTime: string;
|
|
6
|
+
error: {
|
|
7
|
+
type: string;
|
|
8
|
+
message: string;
|
|
9
|
+
stackTrace: Array<Array<string>>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type Options = {
|
|
13
|
+
compact: boolean;
|
|
14
|
+
insertions: {
|
|
15
|
+
header: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
type LogsResponse = {
|
|
19
|
+
results: Array<Log>;
|
|
20
|
+
};
|
|
21
|
+
export declare function outputLogs(logsResp: LogsResponse, options: Options): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
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.outputLogs = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const logger_1 = require("./logger");
|
|
10
|
+
const SEPARATOR = ' - ';
|
|
11
|
+
const LOG_STATUS_COLORS = {
|
|
12
|
+
SUCCESS: logger_1.Styles.success,
|
|
13
|
+
ERROR: logger_1.Styles.error,
|
|
14
|
+
UNHANDLED_ERROR: logger_1.Styles.error,
|
|
15
|
+
HANDLED_ERROR: logger_1.Styles.error,
|
|
16
|
+
};
|
|
17
|
+
function errorHandler(log, options) {
|
|
18
|
+
return `${formatLogHeader(log, options)}${formatError(log, options)}`;
|
|
19
|
+
}
|
|
20
|
+
const logHandler = {
|
|
21
|
+
ERROR: errorHandler,
|
|
22
|
+
UNHANDLED_ERROR: errorHandler,
|
|
23
|
+
HANDLED_ERROR: errorHandler,
|
|
24
|
+
SUCCESS: (log, options) => {
|
|
25
|
+
return `${formatLogHeader(log, options)}${formatSuccess(log, options)}`;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
function formatSuccess(log, options) {
|
|
29
|
+
if (!log.log || options.compact) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
return `\n${log.log}`;
|
|
33
|
+
}
|
|
34
|
+
function formatError(log, options) {
|
|
35
|
+
if (!log.error || options.compact) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
return `${log.error.type}: ${log.error.message}\n${formatStackTrace(log)}`;
|
|
39
|
+
}
|
|
40
|
+
function formatLogHeader(log, options) {
|
|
41
|
+
const color = LOG_STATUS_COLORS[log.status];
|
|
42
|
+
const headerInsertion = options && options.insertions && options.insertions.header;
|
|
43
|
+
return `${formatTimestamp(log)}${SEPARATOR}${color(log.status)}${headerInsertion ? `${SEPARATOR}${headerInsertion}` : ''}${SEPARATOR}${formatExecutionTime(log)}`;
|
|
44
|
+
}
|
|
45
|
+
function formatStackTrace(log) {
|
|
46
|
+
const stackTrace = (log.error.stackTrace && log.error.stackTrace[0]) || [];
|
|
47
|
+
return stackTrace
|
|
48
|
+
.map(trace => {
|
|
49
|
+
return ` at ${trace}\n`;
|
|
50
|
+
})
|
|
51
|
+
.join('');
|
|
52
|
+
}
|
|
53
|
+
function formatTimestamp(log) {
|
|
54
|
+
return `${chalk_1.default.whiteBright((0, moment_1.default)(log.createdAt).toISOString())}`;
|
|
55
|
+
}
|
|
56
|
+
function formatExecutionTime(log) {
|
|
57
|
+
return `${chalk_1.default.whiteBright('Execution Time:')} ${log.executionTime}ms`;
|
|
58
|
+
}
|
|
59
|
+
function processLog(log, options) {
|
|
60
|
+
try {
|
|
61
|
+
return logHandler[log.status](log, options);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
logger_1.logger.error(`Unable to process log ${JSON.stringify(log)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function processLogs(logsResp, options) {
|
|
68
|
+
if (!logsResp || (logsResp.results && !logsResp.results.length)) {
|
|
69
|
+
return 'No logs found.';
|
|
70
|
+
}
|
|
71
|
+
else if (logsResp.results && logsResp.results.length) {
|
|
72
|
+
return logsResp.results
|
|
73
|
+
.map(log => {
|
|
74
|
+
return processLog(log, options);
|
|
75
|
+
})
|
|
76
|
+
.join('\n');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function outputLogs(logsResp, options) {
|
|
80
|
+
logger_1.logger.log(processLogs(logsResp, options));
|
|
81
|
+
}
|
|
82
|
+
exports.outputLogs = outputLogs;
|
|
@@ -0,0 +1,47 @@
|
|
|
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.getTableHeader = exports.getTableContents = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const table_1 = require("table");
|
|
9
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
10
|
+
const tableConfigDefaults = {
|
|
11
|
+
singleLine: true,
|
|
12
|
+
border: {
|
|
13
|
+
topBody: '',
|
|
14
|
+
topJoin: '',
|
|
15
|
+
topLeft: '',
|
|
16
|
+
topRight: '',
|
|
17
|
+
bottomBody: '',
|
|
18
|
+
bottomJoin: '',
|
|
19
|
+
bottomLeft: '',
|
|
20
|
+
bottomRight: '',
|
|
21
|
+
bodyLeft: '',
|
|
22
|
+
bodyRight: '',
|
|
23
|
+
bodyJoin: '',
|
|
24
|
+
joinBody: '',
|
|
25
|
+
joinLeft: '',
|
|
26
|
+
joinRight: '',
|
|
27
|
+
joinJoin: '',
|
|
28
|
+
},
|
|
29
|
+
columnDefault: {
|
|
30
|
+
paddingLeft: 0,
|
|
31
|
+
paddingRight: 1,
|
|
32
|
+
},
|
|
33
|
+
drawHorizontalLine: () => {
|
|
34
|
+
return false;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
function getTableContents(
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
tableData = [], tableConfig = {}) {
|
|
40
|
+
const mergedConfig = (0, objectUtils_1.mergeDeep)({}, tableConfigDefaults, tableConfig);
|
|
41
|
+
return (0, table_1.table)(tableData, mergedConfig);
|
|
42
|
+
}
|
|
43
|
+
exports.getTableContents = getTableContents;
|
|
44
|
+
function getTableHeader(headerItems) {
|
|
45
|
+
return headerItems.map(headerItem => chalk_1.default.bold(headerItem));
|
|
46
|
+
}
|
|
47
|
+
exports.getTableHeader = getTableHeader;
|
package/lib/oauth.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import OAuth2Manager from '../models/OAuth2Manager';
|
|
2
|
+
import { FlatAccountFields } from '../types/Accounts';
|
|
3
|
+
import { LogCallbacksArg } from '../types/LogCallbacks';
|
|
4
|
+
export declare function getOauthManager(accountId: number, accountConfig: FlatAccountFields): OAuth2Manager | undefined;
|
|
5
|
+
declare const addOauthToAccountConfigCallbackKeys: string[];
|
|
6
|
+
export declare function addOauthToAccountConfig(oauth: OAuth2Manager, logCallbacks: LogCallbacksArg<typeof addOauthToAccountConfigCallbackKeys>): void;
|
|
7
|
+
export {};
|
package/lib/oauth.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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.addOauthToAccountConfig = exports.getOauthManager = void 0;
|
|
7
|
+
const OAuth2Manager_1 = __importDefault(require("../models/OAuth2Manager"));
|
|
8
|
+
const auth_1 = require("../constants/auth");
|
|
9
|
+
const standardErrors_1 = require("../errors/standardErrors");
|
|
10
|
+
const logger_1 = require("../utils/logger");
|
|
11
|
+
const logger_2 = require("../utils/logger");
|
|
12
|
+
const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
|
|
13
|
+
const config_1 = require("../config");
|
|
14
|
+
const oauthManagers = new Map();
|
|
15
|
+
function writeOauthTokenInfo(accountConfig) {
|
|
16
|
+
const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
|
|
17
|
+
(0, logger_1.debug)('oauth.writeTokenInfo', { portalId: accountId || '' });
|
|
18
|
+
(0, config_1.updateAccountConfig)(accountConfig);
|
|
19
|
+
(0, config_1.writeConfig)();
|
|
20
|
+
}
|
|
21
|
+
function getOauthManager(accountId, accountConfig) {
|
|
22
|
+
if (!oauthManagers.has(accountId)) {
|
|
23
|
+
oauthManagers.set(accountId, OAuth2Manager_1.default.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
|
|
24
|
+
}
|
|
25
|
+
return oauthManagers.get(accountId);
|
|
26
|
+
}
|
|
27
|
+
exports.getOauthManager = getOauthManager;
|
|
28
|
+
const addOauthToAccountConfigCallbackKeys = ['init', 'success'];
|
|
29
|
+
function addOauthToAccountConfig(oauth, logCallbacks) {
|
|
30
|
+
const logger = (0, logger_2.makeTypedLogger)(logCallbacks, 'oauth.addOauthToAccountConfig');
|
|
31
|
+
logger('init');
|
|
32
|
+
try {
|
|
33
|
+
(0, config_1.updateAccountConfig)({
|
|
34
|
+
...oauth.toObj(),
|
|
35
|
+
authType: auth_1.AUTH_METHODS.oauth.value,
|
|
36
|
+
});
|
|
37
|
+
(0, config_1.writeConfig)();
|
|
38
|
+
logger('success');
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
(0, standardErrors_1.throwError)(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.addOauthToAccountConfig = addOauthToAccountConfig;
|
package/lib/path.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export declare function splitLocalPath(filepath: string, pathImplementation?: pa
|
|
|
6
6
|
export declare function splitHubSpotPath(filepath: string): Array<string>;
|
|
7
7
|
export declare function getCwd(): string;
|
|
8
8
|
export declare function getExt(filepath: string): string;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function getAllowedExtensions(allowList?: Array<string>): Set<string>;
|
|
10
|
+
export declare function isAllowedExtension(filepath: string, allowList?: Array<string>): boolean;
|
|
10
11
|
export declare function getAbsoluteFilePath(_path: string): string;
|