@hubspot/local-dev-lib 0.2.1-experimental.1 → 0.2.2-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.
Files changed (46) hide show
  1. package/api/github.d.ts +0 -1
  2. package/api/projects.d.ts +0 -1
  3. package/config/CLIConfiguration.d.ts +65 -0
  4. package/config/CLIConfiguration.js +509 -0
  5. package/config/configFile.d.ts +21 -0
  6. package/config/configFile.js +100 -0
  7. package/config/configUtils.d.ts +5 -0
  8. package/config/configUtils.js +87 -0
  9. package/config/config_DEPRECATED.d.ts +76 -0
  10. package/config/config_DEPRECATED.js +693 -0
  11. package/config/environment.d.ts +2 -0
  12. package/config/environment.js +60 -0
  13. package/config/getAccountIdentifier.d.ts +2 -0
  14. package/config/getAccountIdentifier.js +15 -0
  15. package/config/index.d.ts +41 -25
  16. package/config/index.js +236 -248
  17. package/config/migrate.d.ts +20 -0
  18. package/config/migrate.js +150 -0
  19. package/constants/config.d.ts +7 -24
  20. package/constants/config.js +13 -25
  21. package/constants/environments.d.ts +11 -0
  22. package/constants/environments.js +12 -1
  23. package/http/getAxiosConfig.js +1 -7
  24. package/http/index.js +19 -23
  25. package/lang/en.json +81 -67
  26. package/lib/archive.d.ts +0 -1
  27. package/lib/cms/themes.js +1 -3
  28. package/lib/environment.d.ts +1 -1
  29. package/lib/github.d.ts +0 -1
  30. package/lib/oauth.d.ts +2 -2
  31. package/lib/oauth.js +16 -8
  32. package/lib/personalAccessKey.d.ts +2 -2
  33. package/lib/personalAccessKey.js +30 -39
  34. package/lib/trackUsage.js +3 -6
  35. package/models/OAuth2Manager.d.ts +4 -3
  36. package/models/OAuth2Manager.js +29 -20
  37. package/package.json +4 -3
  38. package/types/Accounts.d.ts +109 -20
  39. package/types/Config.d.ts +24 -11
  40. package/types/Http.d.ts +0 -1
  41. package/utils/accounts.d.ts +4 -0
  42. package/utils/accounts.js +28 -0
  43. package/config/defaultAccountOverride.d.ts +0 -2
  44. package/config/defaultAccountOverride.js +0 -57
  45. package/config/utils.d.ts +0 -70
  46. package/config/utils.js +0 -328
package/config/utils.d.ts DELETED
@@ -1,70 +0,0 @@
1
- import { ACCOUNT_IDENTIFIERS } from '../constants/config';
2
- import { HubSpotConfig, DeprecatedHubSpotConfigFields } from '../types/Config';
3
- import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
4
- import { ValueOf } from '../types/Utils';
5
- export declare function getGlobalConfigFilePath(): string;
6
- export declare function getLocalConfigFilePath(): string | null;
7
- export declare function getLocalConfigDefaultFilePath(): string;
8
- export declare function getConfigPathEnvironmentVariables(): {
9
- useEnvironmentConfig: boolean;
10
- configFilePathFromEnvironment: string | undefined;
11
- };
12
- export declare function readConfigFile(configPath: string): string;
13
- export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
14
- export declare function formatConfigForWrite(config: HubSpotConfig): {
15
- accounts: ({
16
- personalAccessKey: string;
17
- auth: {
18
- tokenInfo: TokenInfo;
19
- };
20
- accountType?: AccountType | undefined;
21
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
22
- parentAccountId?: number | undefined;
23
- name: string;
24
- accountId: number;
25
- env: import("../types/Config").Environment;
26
- authType: "apikey" | "oauth2" | "personalaccesskey";
27
- } | {
28
- auth: {
29
- clientId: string;
30
- clientSecret: string;
31
- scopes: string[];
32
- tokenInfo: TokenInfo;
33
- };
34
- accountType?: AccountType | undefined;
35
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
36
- parentAccountId?: number | undefined;
37
- name: string;
38
- accountId: number;
39
- env: import("../types/Config").Environment;
40
- authType: "apikey" | "oauth2" | "personalaccesskey";
41
- } | {
42
- apiKey: string;
43
- accountType?: AccountType | undefined;
44
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
45
- parentAccountId?: number | undefined;
46
- name: string;
47
- accountId: number;
48
- env: import("../types/Config").Environment;
49
- authType: "apikey" | "oauth2" | "personalaccesskey";
50
- })[];
51
- env?: import("../types/Config").Environment | undefined;
52
- httpUseLocalhost?: boolean | undefined;
53
- useCustomObjectHubfile?: boolean | undefined;
54
- defaultCmsPublishMode: import("../types/Files").CmsPublishMode | undefined;
55
- httpTimeout: number | undefined;
56
- allowUsageTracking: boolean | undefined;
57
- defaultAccount?: number | undefined;
58
- };
59
- export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
60
- export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
61
- export declare function parseConfig(configSource: string): HubSpotConfig;
62
- export declare function buildConfigFromEnvironment(): HubSpotConfig;
63
- export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
64
- identifier: string | number;
65
- identifierType: ValueOf<typeof ACCOUNT_IDENTIFIERS>;
66
- };
67
- export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
68
- export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
69
- export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
70
- export declare function isConfigAccountValid(account: Partial<HubSpotConfigAccount>): boolean;
package/config/utils.js DELETED
@@ -1,328 +0,0 @@
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.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = exports.getLocalConfigFilePath = exports.getGlobalConfigFilePath = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const os_1 = __importDefault(require("os"));
9
- const fs_extra_1 = __importDefault(require("fs-extra"));
10
- const js_yaml_1 = __importDefault(require("js-yaml"));
11
- const findup_sync_1 = __importDefault(require("findup-sync"));
12
- const config_1 = require("../constants/config");
13
- const auth_1 = require("../constants/auth");
14
- const FileSystemError_1 = require("../models/FileSystemError");
15
- const logger_1 = require("../lib/logger");
16
- const environment_1 = require("../lib/environment");
17
- const path_2 = require("../lib/path");
18
- const files_1 = require("../constants/files");
19
- const lang_1 = require("../utils/lang");
20
- function getGlobalConfigFilePath() {
21
- return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_1.HUBSPOT_CONFIGURATION_FILE);
22
- }
23
- exports.getGlobalConfigFilePath = getGlobalConfigFilePath;
24
- function getLocalConfigFilePath() {
25
- return (0, findup_sync_1.default)([
26
- config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
27
- config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
28
- ]);
29
- }
30
- exports.getLocalConfigFilePath = getLocalConfigFilePath;
31
- function getLocalConfigDefaultFilePath() {
32
- return `${(0, path_2.getCwd)()}/${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
33
- }
34
- exports.getLocalConfigDefaultFilePath = getLocalConfigDefaultFilePath;
35
- function getConfigPathEnvironmentVariables() {
36
- const configFilePathFromEnvironment = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_CONFIG_PATH];
37
- const useEnvironmentConfig = process.env[config_1.ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG] ===
38
- 'true';
39
- if (configFilePathFromEnvironment && useEnvironmentConfig) {
40
- throw new Error((0, lang_1.i18n)('config.utils.getConfigPathEnvironmentVariables.invalidEnvironmentVariables'));
41
- }
42
- return {
43
- configFilePathFromEnvironment,
44
- useEnvironmentConfig,
45
- };
46
- }
47
- exports.getConfigPathEnvironmentVariables = getConfigPathEnvironmentVariables;
48
- function readConfigFile(configPath) {
49
- let source = '';
50
- try {
51
- source = fs_extra_1.default.readFileSync(configPath).toString();
52
- }
53
- catch (err) {
54
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
55
- filepath: configPath,
56
- operation: 'read',
57
- });
58
- }
59
- return source;
60
- }
61
- exports.readConfigFile = readConfigFile;
62
- function removeUndefinedFieldsFromConfigAccount(account) {
63
- Object.keys(account).forEach(k => {
64
- const key = k;
65
- if (account[key] === undefined) {
66
- delete account[key];
67
- }
68
- });
69
- if ('auth' in account && account.auth) {
70
- if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
71
- Object.keys(account.auth).forEach(k => {
72
- const key = k;
73
- if (account.auth?.[key] === undefined) {
74
- delete account.auth?.[key];
75
- }
76
- });
77
- }
78
- if ('tokenInfo' in account.auth &&
79
- typeof account.auth.tokenInfo === 'object') {
80
- Object.keys(account.auth.tokenInfo).forEach(k => {
81
- const key = k;
82
- if (account.auth?.tokenInfo[key] === undefined) {
83
- delete account.auth?.tokenInfo[key];
84
- }
85
- });
86
- }
87
- }
88
- return account;
89
- }
90
- exports.removeUndefinedFieldsFromConfigAccount = removeUndefinedFieldsFromConfigAccount;
91
- // Ensure written config files have fields in a consistent order
92
- function formatConfigForWrite(config) {
93
- const { defaultAccount, defaultCmsPublishMode, httpTimeout, allowUsageTracking, accounts, ...rest } = config;
94
- const orderedConfig = {
95
- ...(defaultAccount && { defaultAccount }),
96
- defaultCmsPublishMode,
97
- httpTimeout,
98
- allowUsageTracking,
99
- ...rest,
100
- accounts: accounts.map(account => {
101
- const { name, accountId, env, authType, ...rest } = account;
102
- return {
103
- name,
104
- accountId,
105
- env,
106
- authType,
107
- ...rest,
108
- };
109
- }),
110
- };
111
- return removeUndefinedFieldsFromConfigAccount(orderedConfig);
112
- }
113
- exports.formatConfigForWrite = formatConfigForWrite;
114
- function writeConfigFile(config, configPath) {
115
- const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify(formatConfigForWrite(config), null, 2)));
116
- try {
117
- fs_extra_1.default.ensureFileSync(configPath);
118
- fs_extra_1.default.writeFileSync(configPath, source);
119
- }
120
- catch (err) {
121
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
122
- filepath: configPath,
123
- operation: 'write',
124
- });
125
- }
126
- }
127
- exports.writeConfigFile = writeConfigFile;
128
- function getAccountType(sandboxAccountType) {
129
- if (sandboxAccountType) {
130
- if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
131
- return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
132
- }
133
- if (sandboxAccountType.toUpperCase() === 'STANDARD') {
134
- return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
135
- }
136
- }
137
- return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
138
- }
139
- function normalizeParsedConfig(parsedConfig) {
140
- if (parsedConfig.portals) {
141
- parsedConfig.accounts = parsedConfig.portals.map(account => {
142
- if (account.portalId) {
143
- account.accountId = account.portalId;
144
- delete account.portalId;
145
- }
146
- if (!account.accountType) {
147
- account.accountType = getAccountType(account.sandboxAccountType);
148
- delete account.sandboxAccountType;
149
- }
150
- return account;
151
- });
152
- delete parsedConfig.portals;
153
- }
154
- if (parsedConfig.defaultPortal) {
155
- const defaultAccount = getConfigAccountByInferredIdentifier(parsedConfig.accounts, parsedConfig.defaultPortal);
156
- if (defaultAccount) {
157
- parsedConfig.defaultAccount = defaultAccount.accountId;
158
- }
159
- delete parsedConfig.defaultPortal;
160
- }
161
- if (parsedConfig.defaultMode) {
162
- parsedConfig.defaultCmsPublishMode = parsedConfig.defaultMode;
163
- delete parsedConfig.defaultMode;
164
- }
165
- return parsedConfig;
166
- }
167
- exports.normalizeParsedConfig = normalizeParsedConfig;
168
- function parseConfig(configSource) {
169
- let parsedYaml;
170
- try {
171
- parsedYaml = js_yaml_1.default.load(configSource);
172
- }
173
- catch (err) {
174
- throw new Error((0, lang_1.i18n)('config.utils.parseConfig.error'), { cause: err });
175
- }
176
- return normalizeParsedConfig(parsedYaml);
177
- }
178
- exports.parseConfig = parseConfig;
179
- function buildConfigFromEnvironment() {
180
- const apiKey = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_API_KEY];
181
- const clientId = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_ID];
182
- const clientSecret = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_SECRET];
183
- const personalAccessKey = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY];
184
- const accountIdVar = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_ACCOUNT_ID] ||
185
- process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID];
186
- const refreshToken = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN];
187
- const hubspotEnvironment = process.env[config_1.ENVIRONMENT_VARIABLES.HUBSPOT_ENVIRONMENT];
188
- const httpTimeoutVar = process.env[config_1.ENVIRONMENT_VARIABLES.HTTP_TIMEOUT];
189
- const httpUseLocalhostVar = process.env[config_1.ENVIRONMENT_VARIABLES.HTTP_USE_LOCALHOST];
190
- const allowUsageTrackingVar = process.env[config_1.ENVIRONMENT_VARIABLES.ALLOW_USAGE_TRACKING];
191
- const defaultCmsPublishModeVar = process.env[config_1.ENVIRONMENT_VARIABLES.DEFAULT_CMS_PUBLISH_MODE];
192
- if (!accountIdVar) {
193
- throw new Error((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.missingAccountId'));
194
- }
195
- const accountId = parseInt(accountIdVar);
196
- const httpTimeout = httpTimeoutVar ? parseInt(httpTimeoutVar) : undefined;
197
- const httpUseLocalhost = httpUseLocalhostVar
198
- ? httpUseLocalhostVar === 'true'
199
- : undefined;
200
- const allowUsageTracking = allowUsageTrackingVar
201
- ? allowUsageTrackingVar === 'true'
202
- : undefined;
203
- const defaultCmsPublishMode = defaultCmsPublishModeVar === files_1.CMS_PUBLISH_MODE.draft ||
204
- defaultCmsPublishModeVar === files_1.CMS_PUBLISH_MODE.publish
205
- ? defaultCmsPublishModeVar
206
- : undefined;
207
- const env = (0, environment_1.getValidEnv)(hubspotEnvironment);
208
- let account;
209
- if (personalAccessKey) {
210
- account = {
211
- authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
212
- accountId,
213
- personalAccessKey,
214
- env,
215
- name: accountIdVar,
216
- auth: {
217
- tokenInfo: {},
218
- },
219
- };
220
- }
221
- else if (clientId && clientSecret && refreshToken) {
222
- account = {
223
- authType: auth_1.OAUTH_AUTH_METHOD.value,
224
- accountId,
225
- auth: {
226
- clientId,
227
- clientSecret,
228
- scopes: auth_1.OAUTH_SCOPES.map((scope) => scope.value),
229
- tokenInfo: {
230
- refreshToken,
231
- },
232
- },
233
- env,
234
- name: accountIdVar,
235
- };
236
- }
237
- else if (apiKey) {
238
- account = {
239
- authType: auth_1.API_KEY_AUTH_METHOD.value,
240
- accountId,
241
- apiKey,
242
- env,
243
- name: accountIdVar,
244
- };
245
- }
246
- else {
247
- throw new Error((0, lang_1.i18n)('config.utils.buildConfigFromEnvironment.invalidAuthType'));
248
- }
249
- return {
250
- accounts: [account],
251
- defaultAccount: accountId,
252
- httpTimeout,
253
- httpUseLocalhost,
254
- allowUsageTracking,
255
- defaultCmsPublishMode,
256
- };
257
- }
258
- exports.buildConfigFromEnvironment = buildConfigFromEnvironment;
259
- function getAccountIdentifierAndType(accountIdentifier) {
260
- const identifierAsNumber = typeof accountIdentifier === 'number'
261
- ? accountIdentifier
262
- : parseInt(accountIdentifier);
263
- const isId = !isNaN(identifierAsNumber);
264
- return {
265
- identifier: isId ? identifierAsNumber : accountIdentifier,
266
- identifierType: isId
267
- ? config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID
268
- : config_1.ACCOUNT_IDENTIFIERS.NAME,
269
- };
270
- }
271
- exports.getAccountIdentifierAndType = getAccountIdentifierAndType;
272
- function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier) {
273
- return accounts.find(account => account[identifierFieldName] === identifier);
274
- }
275
- exports.getConfigAccountByIdentifier = getConfigAccountByIdentifier;
276
- function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
277
- const { identifier, identifierType } = getAccountIdentifierAndType(accountIdentifier);
278
- return accounts.find(account => account[identifierType] === identifier);
279
- }
280
- exports.getConfigAccountByInferredIdentifier = getConfigAccountByInferredIdentifier;
281
- function getConfigAccountIndexById(accounts, id) {
282
- return accounts.findIndex(account => account.accountId === id);
283
- }
284
- exports.getConfigAccountIndexById = getConfigAccountIndexById;
285
- function isConfigAccountValid(account) {
286
- if (!account || typeof account !== 'object') {
287
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccount'));
288
- return false;
289
- }
290
- if (!account.accountId) {
291
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAccountId'));
292
- return false;
293
- }
294
- if (!account.authType) {
295
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAuthType', {
296
- accountId: account.accountId,
297
- }));
298
- return false;
299
- }
300
- let valid = false;
301
- if (account.authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
302
- valid =
303
- 'personalAccessKey' in account && Boolean(account.personalAccessKey);
304
- if (!valid) {
305
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingPersonalAccessKey', {
306
- accountId: account.accountId,
307
- }));
308
- }
309
- }
310
- if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
311
- valid = 'auth' in account && Boolean(account.auth);
312
- if (!valid) {
313
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingAuth', {
314
- accountId: account.accountId,
315
- }));
316
- }
317
- }
318
- if (account.authType === auth_1.API_KEY_AUTH_METHOD.value) {
319
- valid = 'apiKey' in account && Boolean(account.apiKey);
320
- if (!valid) {
321
- logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingApiKey', {
322
- accountId: account.accountId,
323
- }));
324
- }
325
- }
326
- return valid;
327
- }
328
- exports.isConfigAccountValid = isConfigAccountValid;