@hubspot/local-dev-lib 0.3.0 → 0.3.1-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +4 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +11 -11
- package/api/fileMapper.d.ts +8 -7
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/fireAlarm.d.ts +3 -0
- package/api/fireAlarm.js +11 -0
- package/api/functions.d.ts +7 -7
- package/api/functions.js +13 -16
- package/api/github.d.ts +8 -9
- package/api/github.js +31 -13
- package/api/hubdb.d.ts +11 -10
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -4
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +9 -16
- package/api/localDevAuth.js +36 -14
- package/api/marketplaceValidation.d.ts +4 -4
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +47 -24
- package/api/projects.js +178 -43
- package/api/sandboxHubs.d.ts +6 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +4 -13
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +12 -8
- package/config/CLIConfiguration.js +140 -64
- package/config/configFile.js +9 -18
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +3 -3
- package/config/config_DEPRECATED.d.ts +5 -8
- package/config/config_DEPRECATED.js +60 -26
- package/config/environment.js +1 -1
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +13 -8
- package/config/index.js +99 -59
- package/config/migrate.d.ts +22 -0
- package/config/migrate.js +178 -0
- package/constants/config.d.ts +22 -3
- package/constants/config.js +29 -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 +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/constants/projects.d.ts +12 -0
- package/constants/projects.js +15 -0
- package/errors/errors_DEPRECATED.d.ts +1 -5
- 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 +6 -3
- package/http/getAxiosConfig.js +49 -6
- package/http/index.d.ts +11 -10
- package/http/index.js +87 -36
- package/http/unauthed.d.ts +14 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +384 -386
- package/lib/archive.d.ts +3 -6
- package/lib/archive.js +27 -21
- package/lib/cms/functions.d.ts +6 -9
- package/lib/cms/functions.js +25 -20
- package/lib/cms/handleFieldsJS.d.ts +2 -2
- package/lib/cms/handleFieldsJS.js +15 -11
- package/lib/cms/modules.d.ts +5 -13
- package/lib/cms/modules.js +71 -73
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +42 -0
- package/lib/cms/templates.js +49 -6
- package/lib/cms/uploadFolder.d.ts +3 -12
- package/lib/cms/uploadFolder.js +57 -39
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.d.ts +2 -15
- package/lib/cms/watch.js +36 -28
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +24 -24
- package/lib/fileMapper.d.ts +4 -13
- package/lib/fileMapper.js +57 -67
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +10 -6
- package/lib/github.d.ts +11 -11
- package/lib/github.js +45 -31
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +10 -19
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +8 -11
- package/lib/personalAccessKey.js +72 -52
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -1
- package/lib/text.js +3 -0
- package/lib/trackUsage.js +14 -8
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +26 -0
- package/models/HubSpotHttpError.js +208 -0
- package/models/OAuth2Manager.d.ts +2 -27
- package/models/OAuth2Manager.js +15 -30
- package/package.json +38 -36
- package/types/Accounts.d.ts +98 -3
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +4 -2
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/Deploy.d.ts +3 -2
- package/types/DesignManager.d.ts +15 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +9 -5
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +1 -1
- package/types/Files.d.ts +43 -4
- package/types/FireAlarm.d.ts +9 -0
- package/types/FireAlarm.js +2 -0
- package/types/Functions.d.ts +52 -0
- package/types/Github.d.ts +13 -0
- package/types/Http.d.ts +13 -12
- package/types/Hubdb.d.ts +9 -0
- package/types/MarketplaceValidation.d.ts +7 -3
- package/types/Migration.d.ts +30 -0
- package/types/Migration.js +12 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +30 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +25 -36
- package/types/Schemas.d.ts +56 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +23 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +16 -10
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/errors/apiErrors.d.ts +0 -21
- package/errors/apiErrors.js +0 -177
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -21
- package/errors/standardErrors.js +0 -52
- package/lang/lang/en.json +0 -401
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- 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/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
|
@@ -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,26 @@
|
|
|
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
|
+
timeout?: number;
|
|
18
|
+
correlationId?: string;
|
|
19
|
+
constructor(message?: string, options?: ErrorOptions, context?: HubSpotHttpErrorContext);
|
|
20
|
+
updateContext(context: Partial<HubSpotHttpErrorContext>): void;
|
|
21
|
+
toString(): string;
|
|
22
|
+
formattedValidationErrors(): string;
|
|
23
|
+
private extractDerivedContext;
|
|
24
|
+
private parseValidationErrors;
|
|
25
|
+
private joinErrorMessages;
|
|
26
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HubSpotHttpError = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const api_1 = require("../constants/api");
|
|
6
|
+
const lang_1 = require("../utils/lang");
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
class HubSpotHttpError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
statusText;
|
|
12
|
+
data;
|
|
13
|
+
headers;
|
|
14
|
+
method;
|
|
15
|
+
context;
|
|
16
|
+
derivedContext;
|
|
17
|
+
validationErrors;
|
|
18
|
+
detailedMessage;
|
|
19
|
+
divider = `\n- `;
|
|
20
|
+
cause;
|
|
21
|
+
timeout;
|
|
22
|
+
correlationId;
|
|
23
|
+
constructor(message, options, context) {
|
|
24
|
+
super(message, options);
|
|
25
|
+
this.name = 'HubSpotHttpError';
|
|
26
|
+
this.context = context;
|
|
27
|
+
this.cause = options?.cause;
|
|
28
|
+
if (options && (0, axios_1.isAxiosError)(options.cause)) {
|
|
29
|
+
this.extractDerivedContext(options.cause);
|
|
30
|
+
const { response, config, code } = options.cause;
|
|
31
|
+
this.message = this.joinErrorMessages(options.cause, {
|
|
32
|
+
accountId: this.context?.accountId || this.derivedContext?.accountId,
|
|
33
|
+
});
|
|
34
|
+
this.detailedMessage = this.joinErrorMessages(options.cause, this.context);
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.method = config?.method;
|
|
37
|
+
this.timeout = config?.timeout;
|
|
38
|
+
// Pull the request fields to the top level
|
|
39
|
+
if (response) {
|
|
40
|
+
this.status = response.status;
|
|
41
|
+
this.statusText = response.statusText;
|
|
42
|
+
this.data = response.data;
|
|
43
|
+
if (response.data &&
|
|
44
|
+
typeof response.data === 'object' &&
|
|
45
|
+
'correlationId' in response.data) {
|
|
46
|
+
this.correlationId = response.data.correlationId;
|
|
47
|
+
}
|
|
48
|
+
this.headers = response.headers;
|
|
49
|
+
this.parseValidationErrors(response.data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (options && options.cause instanceof Error) {
|
|
53
|
+
const messages = options.cause.name !== 'Error' ? [`${options.cause.name}:`] : [];
|
|
54
|
+
if (options.cause.message) {
|
|
55
|
+
messages.push(options.cause.message);
|
|
56
|
+
}
|
|
57
|
+
if ('reason' in options.cause && options.cause.reason) {
|
|
58
|
+
messages.push(`${options.cause.reason}`);
|
|
59
|
+
}
|
|
60
|
+
this.message = messages.join(' ');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
updateContext(context) {
|
|
64
|
+
this.context = { ...this.context, ...context };
|
|
65
|
+
// Update the error messages when the context is updated
|
|
66
|
+
if ((0, axios_1.isAxiosError)(this.cause)) {
|
|
67
|
+
this.message = this.joinErrorMessages(this.cause, this.context);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
toString() {
|
|
71
|
+
const messages = [
|
|
72
|
+
`${this.name}: ${this.divider}message: ${this.detailedMessage}`,
|
|
73
|
+
];
|
|
74
|
+
['status', 'statusText', 'method', 'code'].forEach(field => {
|
|
75
|
+
if (Object.hasOwn(this, field)) {
|
|
76
|
+
// @ts-expect-error this[field] exists, so we know it is a property of this
|
|
77
|
+
messages.push(`${field}: ${this[field]}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (this.validationErrors && this.validationErrors.length > 0) {
|
|
81
|
+
messages.push(`errors: ${this.formattedValidationErrors()}`);
|
|
82
|
+
}
|
|
83
|
+
if (this.context) {
|
|
84
|
+
messages.push(`context: ${JSON.stringify(this.context, undefined, 2)}`);
|
|
85
|
+
}
|
|
86
|
+
if (this.correlationId) {
|
|
87
|
+
messages.push(`correlationId: ${this.correlationId}`);
|
|
88
|
+
}
|
|
89
|
+
if (this.derivedContext) {
|
|
90
|
+
messages.push(`derivedContext: ${JSON.stringify(this.derivedContext, undefined, 2)}`);
|
|
91
|
+
}
|
|
92
|
+
return messages.join(this.divider);
|
|
93
|
+
}
|
|
94
|
+
formattedValidationErrors() {
|
|
95
|
+
if (!this.validationErrors || this.validationErrors?.length === 0) {
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
return this.validationErrors?.join(this.divider);
|
|
99
|
+
}
|
|
100
|
+
extractDerivedContext(cause) {
|
|
101
|
+
const generatedContext = {};
|
|
102
|
+
if (!cause) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
generatedContext.accountId = cause.config?.params?.portalId;
|
|
106
|
+
generatedContext.payload = JSON.stringify(cause.config?.data);
|
|
107
|
+
// This will just be the url path
|
|
108
|
+
generatedContext.request = cause.config?.url;
|
|
109
|
+
// Allow the provided context to override the generated context
|
|
110
|
+
this.derivedContext = { ...this.derivedContext, ...generatedContext };
|
|
111
|
+
}
|
|
112
|
+
parseValidationErrors(responseData = { errors: [], message: '' }) {
|
|
113
|
+
if (!responseData) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const errorMessages = [];
|
|
117
|
+
const { errors, message } = responseData;
|
|
118
|
+
if (message) {
|
|
119
|
+
errorMessages.push(message);
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(errors)) {
|
|
122
|
+
const specificErrors = errors.map(error => {
|
|
123
|
+
let errorMessage = error.message;
|
|
124
|
+
if (error.context?.requiredScopes) {
|
|
125
|
+
// Sometimes the scopes come back with duplicates
|
|
126
|
+
const scopes = new Set(error.context.requiredScopes);
|
|
127
|
+
scopes.forEach(item => {
|
|
128
|
+
errorMessage = `${errorMessage}\n - ${item}`;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
else if (error.errorTokens && error.errorTokens.line) {
|
|
132
|
+
errorMessage = `line ${error.errorTokens.line}: ${errorMessage}`;
|
|
133
|
+
}
|
|
134
|
+
return errorMessage;
|
|
135
|
+
});
|
|
136
|
+
errorMessages.push(...specificErrors);
|
|
137
|
+
}
|
|
138
|
+
this.validationErrors = errorMessages;
|
|
139
|
+
}
|
|
140
|
+
joinErrorMessages(error, context = {}) {
|
|
141
|
+
const i18nKey = 'errors.apiErrors';
|
|
142
|
+
const status = error.response?.status;
|
|
143
|
+
const method = error.config?.method;
|
|
144
|
+
let messageDetail;
|
|
145
|
+
if (context.accountId) {
|
|
146
|
+
const action = (method && api_1.HTTP_METHOD_VERBS[method]) || api_1.HTTP_METHOD_VERBS.get;
|
|
147
|
+
const preposition = (method && api_1.HTTP_METHOD_PREPOSITIONS[method]) ||
|
|
148
|
+
api_1.HTTP_METHOD_PREPOSITIONS.get;
|
|
149
|
+
const requestName = context.request
|
|
150
|
+
? `${action} ${preposition} '${context.request}'`
|
|
151
|
+
: action;
|
|
152
|
+
messageDetail = (0, lang_1.i18n)(`${i18nKey}.messageDetail`, {
|
|
153
|
+
accountId: context.accountId,
|
|
154
|
+
requestName,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
messageDetail = (0, lang_1.i18n)(`${i18nKey}.genericMessageDetail`);
|
|
159
|
+
}
|
|
160
|
+
const errorMessage = [];
|
|
161
|
+
if ((method === 'put' || method === 'post') && context.payload) {
|
|
162
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.unableToUpload`, { payload: context.payload }));
|
|
163
|
+
}
|
|
164
|
+
switch (status) {
|
|
165
|
+
case 400:
|
|
166
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400`, { messageDetail }));
|
|
167
|
+
break;
|
|
168
|
+
case 401:
|
|
169
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.401`, { messageDetail }));
|
|
170
|
+
break;
|
|
171
|
+
case 403:
|
|
172
|
+
break;
|
|
173
|
+
case 404:
|
|
174
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.404`, { messageDetail }));
|
|
175
|
+
break;
|
|
176
|
+
case 429:
|
|
177
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.429`, { messageDetail }));
|
|
178
|
+
break;
|
|
179
|
+
case 503:
|
|
180
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.503`, { messageDetail }));
|
|
181
|
+
break;
|
|
182
|
+
default:
|
|
183
|
+
if (status && status >= 500 && status < 600) {
|
|
184
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.500Generic`, { messageDetail }));
|
|
185
|
+
}
|
|
186
|
+
else if (status && status >= 400 && status < 500) {
|
|
187
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.400Generic`, { messageDetail }));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
errorMessage.push((0, lang_1.i18n)(`${i18nKey}.codes.generic`, { messageDetail }));
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
if (error?.response?.data) {
|
|
195
|
+
const { message, errors } = error.response.data;
|
|
196
|
+
if (message) {
|
|
197
|
+
errorMessage.push(message);
|
|
198
|
+
}
|
|
199
|
+
(errors || []).forEach(err => {
|
|
200
|
+
if (err.message) {
|
|
201
|
+
errorMessage.push(`${this.divider}${err.message}`);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return errorMessage.join(' ');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.HubSpotHttpError = HubSpotHttpError;
|
|
@@ -1,29 +1,5 @@
|
|
|
1
|
-
import { FlatAccountFields,
|
|
2
|
-
|
|
3
|
-
type OAuth2ManagerAccountConfig = {
|
|
4
|
-
name?: string;
|
|
5
|
-
accountId?: number;
|
|
6
|
-
clientId?: string;
|
|
7
|
-
clientSecret?: string;
|
|
8
|
-
scopes?: Array<string>;
|
|
9
|
-
env?: Environment;
|
|
10
|
-
environment?: Environment;
|
|
11
|
-
tokenInfo?: TokenInfo;
|
|
12
|
-
authType?: 'oauth2';
|
|
13
|
-
};
|
|
14
|
-
type WriteTokenInfoFunction = (tokenInfo: TokenInfo) => void;
|
|
15
|
-
type RefreshTokenResponse = {
|
|
16
|
-
refresh_token: string;
|
|
17
|
-
access_token: string;
|
|
18
|
-
expires_in: string;
|
|
19
|
-
};
|
|
20
|
-
type ExchangeProof = {
|
|
21
|
-
grant_type: string;
|
|
22
|
-
client_id?: string;
|
|
23
|
-
client_secret?: string;
|
|
24
|
-
refresh_token?: string;
|
|
25
|
-
};
|
|
26
|
-
declare class OAuth2Manager {
|
|
1
|
+
import { FlatAccountFields, OAuth2ManagerAccountConfig, WriteTokenInfoFunction, RefreshTokenResponse, ExchangeProof } from '../types/Accounts';
|
|
2
|
+
export declare class OAuth2Manager {
|
|
27
3
|
account: OAuth2ManagerAccountConfig;
|
|
28
4
|
writeTokenInfo?: WriteTokenInfoFunction;
|
|
29
5
|
refreshTokenRequest: Promise<RefreshTokenResponse> | null;
|
|
@@ -34,4 +10,3 @@ declare class OAuth2Manager {
|
|
|
34
10
|
refreshAccessToken(): Promise<void>;
|
|
35
11
|
static fromConfig(accountConfig: FlatAccountFields, writeTokenInfo: WriteTokenInfoFunction): OAuth2Manager;
|
|
36
12
|
}
|
|
37
|
-
export default OAuth2Manager;
|
package/models/OAuth2Manager.js
CHANGED
|
@@ -3,14 +3,14 @@ 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.OAuth2Manager = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
9
|
const urls_1 = require("../lib/urls");
|
|
9
10
|
const environment_1 = require("../lib/environment");
|
|
10
|
-
const logger_1 = require("../lib/
|
|
11
|
-
const getAccountIdentifier_1 = require("../
|
|
11
|
+
const logger_1 = require("../lib/logger");
|
|
12
|
+
const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
|
|
12
13
|
const auth_1 = require("../constants/auth");
|
|
13
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
14
14
|
const lang_1 = require("../utils/lang");
|
|
15
15
|
const i18nKey = 'models.OAuth2Manager';
|
|
16
16
|
class OAuth2Manager {
|
|
@@ -27,9 +27,9 @@ class OAuth2Manager {
|
|
|
27
27
|
}
|
|
28
28
|
async accessToken() {
|
|
29
29
|
if (!this.account.tokenInfo?.refreshToken) {
|
|
30
|
-
(0,
|
|
30
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.missingRefreshToken`, {
|
|
31
31
|
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
32
|
-
});
|
|
32
|
+
}));
|
|
33
33
|
}
|
|
34
34
|
if (!this.account.tokenInfo?.accessToken ||
|
|
35
35
|
(0, moment_1.default)()
|
|
@@ -68,36 +68,21 @@ class OAuth2Manager {
|
|
|
68
68
|
}));
|
|
69
69
|
this.writeTokenInfo(this.account.tokenInfo);
|
|
70
70
|
}
|
|
71
|
-
this.refreshTokenRequest = null;
|
|
72
71
|
}
|
|
73
|
-
|
|
72
|
+
finally {
|
|
74
73
|
this.refreshTokenRequest = null;
|
|
75
|
-
(0, standardErrors_1.throwError)(e);
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
async exchangeForTokens(exchangeProof) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await this.refreshTokenRequest;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
await this.fetchAccessToken(exchangeProof);
|
|
89
|
-
}
|
|
77
|
+
if (this.refreshTokenRequest) {
|
|
78
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.refreshingAccessToken`, {
|
|
79
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
80
|
+
clientId: this.account.clientId || '',
|
|
81
|
+
}));
|
|
82
|
+
await this.refreshTokenRequest;
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (error.response) {
|
|
94
|
-
(0, standardErrors_1.throwAuthErrorWithMessage)(`${i18nKey}.errors.auth`, {
|
|
95
|
-
token: error.response.data.message || '',
|
|
96
|
-
}, error);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
(0, standardErrors_1.throwError)(error);
|
|
100
|
-
}
|
|
84
|
+
else {
|
|
85
|
+
await this.fetchAccessToken(exchangeProof);
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
88
|
async refreshAccessToken() {
|
|
@@ -117,4 +102,4 @@ class OAuth2Manager {
|
|
|
117
102
|
}, writeTokenInfo);
|
|
118
103
|
}
|
|
119
104
|
}
|
|
120
|
-
exports.
|
|
105
|
+
exports.OAuth2Manager = OAuth2Manager;
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "0.3.0",
|
|
3
|
+
"version": "0.3.1-experimental.0",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
7
|
"url": "https://github.com/HubSpot/hubspot-local-dev-lib"
|
|
@@ -12,22 +11,16 @@
|
|
|
12
11
|
"access": "public"
|
|
13
12
|
},
|
|
14
13
|
"scripts": {
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
17
|
-
"clear-postinstall": "cd dist && npm pkg delete scripts.postinstall",
|
|
18
|
-
"copy-files": "cp -r lang dist/lang",
|
|
19
|
-
"lint": "eslint --max-warnings=0 . && prettier --check ./**/*.ts",
|
|
14
|
+
"build": "ts-node ./scripts/build.ts",
|
|
15
|
+
"lint": "eslint --max-warnings=0 . && prettier . --check",
|
|
20
16
|
"local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
|
|
21
|
-
"prettier:write": "prettier --write
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"release:major": "yarn check-main && yarn version --major && yarn build && yarn pub && yarn push",
|
|
25
|
-
"release:minor": "yarn check-main && yarn version --minor && yarn build && yarn pub && yarn push",
|
|
26
|
-
"release:patch": "yarn check-main && yarn version --patch && yarn build && yarn pub && yarn push",
|
|
27
|
-
"test": "node --experimental-vm-modules ./node_modules/.bin/jest"
|
|
17
|
+
"prettier:write": "prettier . --write",
|
|
18
|
+
"release": "ts-node ./scripts/release.ts release",
|
|
19
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ./node_modules/.bin/jest"
|
|
28
20
|
},
|
|
29
21
|
"license": "Apache-2.0",
|
|
30
22
|
"devDependencies": {
|
|
23
|
+
"@inquirer/prompts": "^7.0.1",
|
|
31
24
|
"@types/content-disposition": "^0.5.5",
|
|
32
25
|
"@types/cors": "^2.8.15",
|
|
33
26
|
"@types/debounce": "^1.2.1",
|
|
@@ -37,45 +30,54 @@
|
|
|
37
30
|
"@types/jest": "^29.5.0",
|
|
38
31
|
"@types/js-yaml": "^4.0.5",
|
|
39
32
|
"@types/node": "^18.14.2",
|
|
40
|
-
"@types/prettier": "^3.0.0",
|
|
41
33
|
"@types/unixify": "^1.0.0",
|
|
42
34
|
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
43
35
|
"@typescript-eslint/parser": "^5.59.7",
|
|
44
36
|
"eslint": "^8.35.0",
|
|
37
|
+
"eslint-plugin-import": "^2.29.1",
|
|
45
38
|
"husky": "^8.0.0",
|
|
46
39
|
"jest": "^29.5.0",
|
|
40
|
+
"open": "^8.4.2",
|
|
47
41
|
"ts-jest": "^29.0.5",
|
|
48
|
-
"
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^4.9.5",
|
|
44
|
+
"yargs": "^17.7.2"
|
|
49
45
|
},
|
|
50
46
|
"exports": {
|
|
51
47
|
"./*": "./lib/*.js",
|
|
52
48
|
"./api/*": "./api/*.js",
|
|
53
49
|
"./errors/*": "./errors/*.js",
|
|
54
50
|
"./http": "./http/index.js",
|
|
51
|
+
"./http/*": "./http/*.js",
|
|
52
|
+
"./config/getAccountIdentifier": "./config/getAccountIdentifier.js",
|
|
53
|
+
"./config/migrate": "./config/migrate.js",
|
|
55
54
|
"./config": "./config/index.js",
|
|
56
55
|
"./constants/*": "./constants/*.js",
|
|
57
|
-
"./
|
|
58
|
-
"./
|
|
56
|
+
"./models/*": "./models/*.js",
|
|
57
|
+
"./types/*": {
|
|
58
|
+
"types": "./types/*.d.ts",
|
|
59
|
+
"default": "./types/*.js"
|
|
60
|
+
}
|
|
59
61
|
},
|
|
60
62
|
"dependencies": {
|
|
61
|
-
"address": "
|
|
62
|
-
"axios": "
|
|
63
|
-
"chalk": "
|
|
64
|
-
"chokidar": "
|
|
65
|
-
"content-disposition": "
|
|
66
|
-
"cors": "
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"unixify": "
|
|
63
|
+
"address": "2.0.2",
|
|
64
|
+
"axios": "1.8.4",
|
|
65
|
+
"chalk": "2.4.2",
|
|
66
|
+
"chokidar": "3.6.0",
|
|
67
|
+
"content-disposition": "0.5.4",
|
|
68
|
+
"cors": "2.8.5",
|
|
69
|
+
"debounce": "1.2.1",
|
|
70
|
+
"express": "4.21.2",
|
|
71
|
+
"extract-zip": "2.0.1",
|
|
72
|
+
"findup-sync": "5.0.0",
|
|
73
|
+
"fs-extra": "11.2.0",
|
|
74
|
+
"ignore": "5.3.1",
|
|
75
|
+
"js-yaml": "4.1.0",
|
|
76
|
+
"moment": "2.30.1",
|
|
77
|
+
"p-queue": "6.6.2",
|
|
78
|
+
"prettier": "3.3.1",
|
|
79
|
+
"semver": "6.3.1",
|
|
80
|
+
"unixify": "1.0.0"
|
|
79
81
|
},
|
|
80
82
|
"engines": {
|
|
81
83
|
"node": ">=16.20.0"
|
package/types/Accounts.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HUBSPOT_ACCOUNT_TYPES } from '../constants/config';
|
|
2
|
-
import {
|
|
2
|
+
import { CmsPublishMode } from './Files';
|
|
3
3
|
import { Environment } from './Config';
|
|
4
4
|
import { ValueOf } from './Utils';
|
|
5
5
|
export type AuthType = 'personalaccesskey' | 'apikey' | 'oauth2';
|
|
@@ -7,11 +7,13 @@ export interface CLIAccount_NEW {
|
|
|
7
7
|
name?: string;
|
|
8
8
|
accountId: number;
|
|
9
9
|
accountType?: AccountType;
|
|
10
|
-
|
|
10
|
+
defaultCmsPublishMode?: CmsPublishMode;
|
|
11
11
|
env: Environment;
|
|
12
12
|
authType?: AuthType;
|
|
13
13
|
auth?: {
|
|
14
14
|
tokenInfo?: TokenInfo;
|
|
15
|
+
clientId?: string;
|
|
16
|
+
clientSecret?: string;
|
|
15
17
|
};
|
|
16
18
|
sandboxAccountType?: string | null;
|
|
17
19
|
parentAccountId?: number | null;
|
|
@@ -21,12 +23,14 @@ export interface CLIAccount_NEW {
|
|
|
21
23
|
export interface CLIAccount_DEPRECATED {
|
|
22
24
|
name?: string;
|
|
23
25
|
portalId?: number;
|
|
24
|
-
|
|
26
|
+
defaultCmsPublishMode?: CmsPublishMode;
|
|
25
27
|
env: Environment;
|
|
26
28
|
accountType?: AccountType;
|
|
27
29
|
authType?: AuthType;
|
|
28
30
|
auth?: {
|
|
29
31
|
tokenInfo?: TokenInfo;
|
|
32
|
+
clientId?: string;
|
|
33
|
+
clientSecret?: string;
|
|
30
34
|
};
|
|
31
35
|
sandboxAccountType?: string | null;
|
|
32
36
|
parentAccountId?: number | null;
|
|
@@ -34,6 +38,10 @@ export interface CLIAccount_DEPRECATED {
|
|
|
34
38
|
personalAccessKey?: string;
|
|
35
39
|
}
|
|
36
40
|
export type CLIAccount = CLIAccount_NEW | CLIAccount_DEPRECATED;
|
|
41
|
+
export type GenericAccount = {
|
|
42
|
+
portalId?: number;
|
|
43
|
+
accountId?: number;
|
|
44
|
+
};
|
|
37
45
|
export type AccountType = ValueOf<typeof HUBSPOT_ACCOUNT_TYPES>;
|
|
38
46
|
export type TokenInfo = {
|
|
39
47
|
accessToken?: string;
|
|
@@ -98,3 +106,90 @@ export type ScopeData = {
|
|
|
98
106
|
portalScopesInGroup: Array<string>;
|
|
99
107
|
userScopesInGroup: Array<string>;
|
|
100
108
|
};
|
|
109
|
+
export type ScopeAuthorizationResponse = {
|
|
110
|
+
results: Array<ScopeGroupAuthorization>;
|
|
111
|
+
};
|
|
112
|
+
export type ScopeGroupAuthorization = {
|
|
113
|
+
scopeGroup: ScopeGroup;
|
|
114
|
+
portalAuthorized: boolean;
|
|
115
|
+
userAuthorized: boolean;
|
|
116
|
+
};
|
|
117
|
+
export type ScopeGroup = {
|
|
118
|
+
name: string;
|
|
119
|
+
shortDescription: string;
|
|
120
|
+
longDescription: string;
|
|
121
|
+
};
|
|
122
|
+
export type AccessTokenResponse = {
|
|
123
|
+
hubId: number;
|
|
124
|
+
userId: number;
|
|
125
|
+
oauthAccessToken: string;
|
|
126
|
+
expiresAtMillis: number;
|
|
127
|
+
enabledFeatures?: {
|
|
128
|
+
[key: string]: number;
|
|
129
|
+
};
|
|
130
|
+
scopeGroups: Array<string>;
|
|
131
|
+
encodedOAuthRefreshToken: string;
|
|
132
|
+
hubName: string;
|
|
133
|
+
accountType: ValueOf<typeof HUBSPOT_ACCOUNT_TYPES>;
|
|
134
|
+
};
|
|
135
|
+
export type EnabledFeaturesResponse = {
|
|
136
|
+
enabledFeatures: {
|
|
137
|
+
[key: string]: boolean;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export type UpdateAccountConfigOptions = Partial<FlatAccountFields_DEPRECATED> & {
|
|
141
|
+
environment?: Environment;
|
|
142
|
+
};
|
|
143
|
+
export type PersonalAccessKeyOptions = {
|
|
144
|
+
accountId: number;
|
|
145
|
+
personalAccessKey: string;
|
|
146
|
+
env: Environment;
|
|
147
|
+
};
|
|
148
|
+
export type OAuthOptions = {
|
|
149
|
+
accountId: number;
|
|
150
|
+
clientId: string;
|
|
151
|
+
clientSecret: string;
|
|
152
|
+
refreshToken: string;
|
|
153
|
+
scopes: Array<string>;
|
|
154
|
+
env: Environment;
|
|
155
|
+
};
|
|
156
|
+
export type APIKeyOptions = {
|
|
157
|
+
accountId: number;
|
|
158
|
+
apiKey: string;
|
|
159
|
+
env: Environment;
|
|
160
|
+
};
|
|
161
|
+
export type AccessToken = {
|
|
162
|
+
portalId: number;
|
|
163
|
+
accessToken: string;
|
|
164
|
+
expiresAt: string;
|
|
165
|
+
scopeGroups: Array<string>;
|
|
166
|
+
enabledFeatures?: {
|
|
167
|
+
[key: string]: number;
|
|
168
|
+
};
|
|
169
|
+
encodedOAuthRefreshToken: string;
|
|
170
|
+
hubName: string;
|
|
171
|
+
accountType: ValueOf<typeof HUBSPOT_ACCOUNT_TYPES>;
|
|
172
|
+
};
|
|
173
|
+
export type OAuth2ManagerAccountConfig = {
|
|
174
|
+
name?: string;
|
|
175
|
+
accountId?: number;
|
|
176
|
+
clientId?: string;
|
|
177
|
+
clientSecret?: string;
|
|
178
|
+
scopes?: Array<string>;
|
|
179
|
+
env?: Environment;
|
|
180
|
+
environment?: Environment;
|
|
181
|
+
tokenInfo?: TokenInfo;
|
|
182
|
+
authType?: 'oauth2';
|
|
183
|
+
};
|
|
184
|
+
export type WriteTokenInfoFunction = (tokenInfo: TokenInfo) => void;
|
|
185
|
+
export type RefreshTokenResponse = {
|
|
186
|
+
refresh_token: string;
|
|
187
|
+
access_token: string;
|
|
188
|
+
expires_in: string;
|
|
189
|
+
};
|
|
190
|
+
export type ExchangeProof = {
|
|
191
|
+
grant_type: string;
|
|
192
|
+
client_id?: string;
|
|
193
|
+
client_secret?: string;
|
|
194
|
+
refresh_token?: string;
|
|
195
|
+
};
|