@hubspot/local-dev-lib 2.0.0 → 2.1.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/api/github.js CHANGED
@@ -8,15 +8,25 @@ const axios_1 = __importDefault(require("axios"));
8
8
  const getAxiosConfig_1 = require("../http/getAxiosConfig");
9
9
  const GITHUB_REPOS_API = 'https://api.github.com/repos';
10
10
  const GITHUB_RAW_CONTENT_API_PATH = 'https://raw.githubusercontent.com';
11
- const GITHUB_AUTH_HEADERS = {
12
- authorization: global && global.githubToken ? `Bearer ${global.githubToken}` : null,
13
- };
11
+ function getAdditionalHeaders() {
12
+ const headers = {};
13
+ if (global && global.githubToken) {
14
+ headers.authorization = `Bearer ${global.githubToken}`;
15
+ }
16
+ else if (process.env.GITHUB_TOKEN) {
17
+ headers.authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
18
+ }
19
+ return headers;
20
+ }
14
21
  // Returns information about the repo's releases. Defaults to "latest" if no tag is provided
15
22
  // https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-a-release-by-tag-name
16
23
  function fetchRepoReleaseData(repoPath, tag = '') {
17
24
  const URL = `${GITHUB_REPOS_API}/${repoPath}/releases`;
18
25
  return axios_1.default.get(`${URL}/${tag ? `tags/${tag}` : 'latest'}`, {
19
- headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...GITHUB_AUTH_HEADERS },
26
+ headers: {
27
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
28
+ ...getAdditionalHeaders(),
29
+ },
20
30
  });
21
31
  }
22
32
  exports.fetchRepoReleaseData = fetchRepoReleaseData;
@@ -25,21 +35,24 @@ exports.fetchRepoReleaseData = fetchRepoReleaseData;
25
35
  function fetchRepoAsZip(zipUrl) {
26
36
  return axios_1.default.get(zipUrl, {
27
37
  responseType: 'arraybuffer',
28
- headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...GITHUB_AUTH_HEADERS },
38
+ headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
29
39
  });
30
40
  }
31
41
  exports.fetchRepoAsZip = fetchRepoAsZip;
32
42
  // Returns the raw file contents via the raw.githubusercontent endpoint
33
43
  function fetchRepoFile(repoPath, filePath, ref) {
34
44
  return axios_1.default.get(`${GITHUB_RAW_CONTENT_API_PATH}/${repoPath}/${ref}/${filePath}`, {
35
- headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...GITHUB_AUTH_HEADERS },
45
+ headers: {
46
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
47
+ ...getAdditionalHeaders(),
48
+ },
36
49
  });
37
50
  }
38
51
  exports.fetchRepoFile = fetchRepoFile;
39
52
  // Returns the raw file contents via the raw.githubusercontent endpoint
40
53
  function fetchRepoFileByDownloadUrl(downloadUrl) {
41
54
  return axios_1.default.get(downloadUrl, {
42
- headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...GITHUB_AUTH_HEADERS },
55
+ headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...getAdditionalHeaders() },
43
56
  responseType: 'arraybuffer',
44
57
  });
45
58
  }
@@ -49,7 +62,10 @@ exports.fetchRepoFileByDownloadUrl = fetchRepoFileByDownloadUrl;
49
62
  function fetchRepoContents(repoPath, path, ref) {
50
63
  const refQuery = ref ? `?ref=${ref}` : '';
51
64
  return axios_1.default.get(`${GITHUB_REPOS_API}/${repoPath}/contents/${path}${refQuery}`, {
52
- headers: { ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(), ...GITHUB_AUTH_HEADERS },
65
+ headers: {
66
+ ...(0, getAxiosConfig_1.getDefaultUserAgentHeader)(),
67
+ ...getAdditionalHeaders(),
68
+ },
53
69
  });
54
70
  }
55
71
  exports.fetchRepoContents = fetchRepoContents;
package/api/hubdb.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AxiosPromise } from 'axios';
2
2
  import { QueryParams } from '../types/Http';
3
- import { CreateRowsResponse, FetchRowsResponse, Row, Schema, Table } from '../types/Hubdb';
3
+ import { CreateRowsResponse, FetchRowsResponse, Row, Schema, Table, FetchTablesResponse } from '../types/Hubdb';
4
+ export declare function fetchTables(accountId: number): AxiosPromise<FetchTablesResponse>;
4
5
  export declare function fetchTable(accountId: number, tableId: string): AxiosPromise<Table>;
5
6
  export declare function createTable(accountId: number, schema: Schema): AxiosPromise<Table>;
6
7
  export declare function updateTable(accountId: number, tableId: string, schema: Schema): AxiosPromise<Table>;
package/api/hubdb.js CHANGED
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteRows = exports.fetchRows = exports.createRows = exports.deleteTable = exports.publishTable = exports.updateTable = exports.createTable = exports.fetchTable = void 0;
3
+ exports.deleteRows = exports.fetchRows = exports.createRows = exports.deleteTable = exports.publishTable = exports.updateTable = exports.createTable = exports.fetchTable = exports.fetchTables = void 0;
4
4
  const http_1 = require("../http");
5
5
  const HUBDB_API_PATH = 'cms/v3/hubdb';
6
+ function fetchTables(accountId) {
7
+ return http_1.http.get(accountId, {
8
+ url: `${HUBDB_API_PATH}/tables`,
9
+ });
10
+ }
11
+ exports.fetchTables = fetchTables;
6
12
  function fetchTable(accountId, tableId) {
7
13
  return http_1.http.get(accountId, {
8
14
  url: `${HUBDB_API_PATH}/tables/${tableId}`,
@@ -20,16 +20,17 @@ declare class _CLIConfiguration {
20
20
  getAccountId(nameOrId?: string | number): number | null;
21
21
  getDefaultAccount(): string | number | null;
22
22
  getResolvedDefaultAccountForCWD(nameOrId: string | number): CLIAccount_NEW | null;
23
- getConfigAccountIndex(accountId: number): number;
23
+ getAccountIndex(accountId: number): number;
24
24
  getConfigForAccount(accountId?: number): CLIAccount_NEW | null;
25
+ getConfigAccounts(): Array<CLIAccount_NEW> | null;
25
26
  isAccountInConfig(nameOrId: string | number): boolean;
26
27
  getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig_NEW;
27
28
  getEnv(nameOrId?: string | number): Environment;
28
- getAccountType(accountType?: AccountType, sandboxAccountType?: string | null): AccountType;
29
+ getAccountType(accountType?: AccountType | null, sandboxAccountType?: string | null): AccountType;
29
30
  /**
30
31
  * @throws {Error}
31
32
  */
32
- updateAccount(updatedAccountFields: Partial<FlatAccountFields_NEW>, writeUpdate?: boolean): FlatAccountFields_NEW | null;
33
+ addOrUpdateAccount(updatedAccountFields: Partial<FlatAccountFields_NEW>, writeUpdate?: boolean): FlatAccountFields_NEW | null;
33
34
  /**
34
35
  * @throws {Error}
35
36
  */
@@ -116,7 +116,7 @@ class _CLIConfiguration {
116
116
  return false;
117
117
  }
118
118
  if (accountConfig.name) {
119
- if (accountNamesMap[accountConfig.name]) {
119
+ if (accountNamesMap[accountConfig.name.toLowerCase()]) {
120
120
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountNames`, {
121
121
  accountName: accountConfig.name,
122
122
  }));
@@ -131,7 +131,7 @@ class _CLIConfiguration {
131
131
  accountNamesMap[accountConfig.name] = true;
132
132
  }
133
133
  if (!accountConfig.accountType) {
134
- this.updateAccount({
134
+ this.addOrUpdateAccount({
135
135
  ...accountConfig,
136
136
  accountId: accountConfig.accountId,
137
137
  accountType: this.getAccountType(undefined, accountConfig.sandboxAccountType),
@@ -194,19 +194,30 @@ class _CLIConfiguration {
194
194
  getResolvedDefaultAccountForCWD(nameOrId) {
195
195
  return this.getAccount(nameOrId);
196
196
  }
197
- getConfigAccountIndex(accountId) {
197
+ getAccountIndex(accountId) {
198
198
  return this.config
199
199
  ? this.config.accounts.findIndex(account => account.accountId === accountId)
200
200
  : -1;
201
201
  }
202
202
  getConfigForAccount(accountId) {
203
203
  if (this.config) {
204
- this.config.accounts.find(account => account.accountId === accountId) ||
205
- null;
204
+ return (this.config.accounts.find(account => account.accountId === accountId) ||
205
+ null);
206
+ }
207
+ return null;
208
+ }
209
+ getConfigAccounts() {
210
+ if (this.config) {
211
+ return this.config.accounts || null;
206
212
  }
207
213
  return null;
208
214
  }
209
215
  isAccountInConfig(nameOrId) {
216
+ if (typeof nameOrId === 'string') {
217
+ return (!!this.config &&
218
+ this.config.accounts &&
219
+ !!this.getAccountId(nameOrId.toLowerCase()));
220
+ }
210
221
  return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
211
222
  }
212
223
  getAndLoadConfigIfNeeded(options) {
@@ -246,7 +257,7 @@ class _CLIConfiguration {
246
257
  /**
247
258
  * @throws {Error}
248
259
  */
249
- updateAccount(updatedAccountFields, writeUpdate = true) {
260
+ addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
250
261
  const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
251
262
  if (!accountId) {
252
263
  throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
@@ -255,8 +266,11 @@ class _CLIConfiguration {
255
266
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
256
267
  return null;
257
268
  }
269
+ // Check whether the account is already listed in the config.yml file.
258
270
  const currentAccountConfig = this.getAccount(accountId);
271
+ // For accounts that are already in the config.yml file, sets the auth property.
259
272
  let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
273
+ // For accounts not already in the config.yml file, sets the auth property.
260
274
  if (clientId || clientSecret || scopes || tokenInfo) {
261
275
  auth = {
262
276
  ...(currentAccountConfig ? currentAccountConfig.auth : {}),
@@ -279,6 +293,7 @@ class _CLIConfiguration {
279
293
  }
280
294
  const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
281
295
  const updatedDefaultMode = defaultMode && defaultMode.toLowerCase();
296
+ const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
282
297
  safelyApplyUpdates('name', name);
283
298
  safelyApplyUpdates('env', updatedEnv);
284
299
  safelyApplyUpdates('accountId', accountId);
@@ -294,24 +309,29 @@ class _CLIConfiguration {
294
309
  safelyApplyUpdates('personalAccessKey', personalAccessKey);
295
310
  // Deprecating sandboxAccountType in favor of the more generic accountType
296
311
  safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
297
- safelyApplyUpdates('accountType', this.getAccountType(accountType, sandboxAccountType));
312
+ safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
298
313
  safelyApplyUpdates('parentAccountId', parentAccountId);
299
314
  const completedAccountConfig = nextAccountConfig;
315
+ if (!Object.hasOwn(this.config, 'accounts')) {
316
+ this.config.accounts = [];
317
+ }
300
318
  if (currentAccountConfig) {
301
319
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
302
320
  accountId,
303
321
  }));
304
- const index = this.getConfigAccountIndex(accountId);
305
- this.config.accounts[index] = completedAccountConfig;
306
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
307
- accountId,
308
- }));
309
- if (this.config.accounts) {
322
+ const index = this.getAccountIndex(accountId);
323
+ if (index < 0) {
310
324
  this.config.accounts.push(completedAccountConfig);
311
325
  }
312
326
  else {
313
- this.config.accounts = [completedAccountConfig];
327
+ this.config.accounts[index] = completedAccountConfig;
314
328
  }
329
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
330
+ accountId,
331
+ }));
332
+ }
333
+ else {
334
+ this.config.accounts.push(completedAccountConfig);
315
335
  }
316
336
  if (writeUpdate) {
317
337
  this.write();
@@ -350,7 +370,12 @@ class _CLIConfiguration {
350
370
  }));
351
371
  }
352
372
  if (accountId) {
353
- this.updateAccount({ accountId, name: newName, env: this.getEnv() });
373
+ this.addOrUpdateAccount({
374
+ accountId,
375
+ name: newName,
376
+ env: this.getEnv(),
377
+ accountType: accountConfigToRename.accountType,
378
+ });
354
379
  }
355
380
  if (accountConfigToRename.name === this.getDefaultAccount()) {
356
381
  this.updateDefaultAccount(newName);
@@ -374,7 +399,7 @@ class _CLIConfiguration {
374
399
  const accountConfig = this.getAccount(accountId);
375
400
  if (accountConfig) {
376
401
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
377
- const index = this.getConfigAccountIndex(accountId);
402
+ const index = this.getAccountIndex(accountId);
378
403
  this.config.accounts.splice(index, 1);
379
404
  if (this.getDefaultAccount() === accountConfig.name) {
380
405
  removedAccountIsDefault = true;
@@ -0,0 +1,2 @@
1
+ import { GenericAccount } from '../types/Accounts';
2
+ export declare function getAccountIdentifier(account?: GenericAccount | null): number | undefined;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccountIdentifier = void 0;
4
+ function getAccountIdentifier(account) {
5
+ if (!account) {
6
+ return undefined;
7
+ }
8
+ else if (Object.hasOwn(account, 'portalId')) {
9
+ return account.portalId;
10
+ }
11
+ else if (Object.hasOwn(account, 'accountId')) {
12
+ return account.accountId;
13
+ }
14
+ }
15
+ exports.getAccountIdentifier = getAccountIdentifier;
package/config/index.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import * as config_DEPRECATED from './config_DEPRECATED';
2
- import { CLIConfig } from '../types/Config';
2
+ import { CLIConfig_NEW, CLIConfig } from '../types/Config';
3
3
  import { CLIOptions, WriteConfigOptions } from '../types/CLIOptions';
4
- import { AccountType, CLIAccount, FlatAccountFields } from '../types/Accounts';
4
+ import { AccountType, CLIAccount, CLIAccount_NEW, CLIAccount_DEPRECATED, FlatAccountFields } from '../types/Accounts';
5
+ import { Mode } from '../types/Files';
5
6
  export declare function loadConfig(path: string, options?: CLIOptions): CLIConfig | null;
6
7
  export declare function getAndLoadConfigIfNeeded(options?: CLIOptions): Partial<CLIConfig> | null;
7
8
  export declare function validateConfig(): boolean;
8
9
  export declare function loadConfigFromEnvironment(): boolean;
9
10
  export declare function createEmptyConfigFile(options?: {
10
11
  path?: string;
11
- }, useRootConfig?: boolean): void;
12
+ }, useHiddenConfig?: boolean): void;
12
13
  export declare function deleteEmptyConfigFile(): void;
13
14
  export declare function getConfig(): CLIConfig | null;
14
15
  export declare function writeConfig(options?: WriteConfigOptions): void;
15
- export declare function getConfigPath(path?: string): string | null;
16
+ export declare function getConfigPath(path?: string, useHiddenConfig?: boolean): string | null;
17
+ export declare function configFileExists(useHiddenConfig?: boolean): boolean;
16
18
  export declare function getAccountConfig(accountId?: number): CLIAccount | null;
17
19
  export declare function accountNameExistsInConfig(name: string): boolean;
18
20
  export declare function updateAccountConfig(configOptions: Partial<FlatAccountFields>): FlatAccountFields | null;
@@ -28,12 +30,12 @@ export declare function isConfigFlagEnabled(flag: keyof CLIConfig): boolean;
28
30
  export declare function isTrackingAllowed(): boolean;
29
31
  export declare function getEnv(nameOrId?: string | number): import("../types/Config").Environment;
30
32
  export declare function getAccountType(accountType?: AccountType, sandboxAccountType?: string | null): AccountType;
31
- export declare const getConfigAccounts: typeof config_DEPRECATED.getConfigAccounts;
32
- export declare const getConfigDefaultAccount: typeof config_DEPRECATED.getConfigDefaultAccount;
33
+ export declare function getDefaultAccount(): string | number | null | undefined;
34
+ export declare function getAccounts(): Array<CLIAccount_NEW> | Array<CLIAccount_DEPRECATED> | null | undefined;
35
+ export declare function updateDefaultMode(mode: Mode): void | CLIConfig_NEW | null;
33
36
  export declare const getConfigAccountId: typeof config_DEPRECATED.getConfigAccountId;
34
37
  export declare const getOrderedAccount: typeof config_DEPRECATED.getOrderedAccount;
35
38
  export declare const getOrderedConfig: typeof config_DEPRECATED.getOrderedConfig;
36
39
  export declare const setConfig: typeof config_DEPRECATED.setConfig;
37
40
  export declare const setConfigPath: typeof config_DEPRECATED.setConfigPath;
38
41
  export declare const findConfig: typeof config_DEPRECATED.findConfig;
39
- export declare const updateDefaultMode: typeof config_DEPRECATED.updateDefaultMode;
package/config/index.js CHANGED
@@ -23,11 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.updateDefaultMode = exports.findConfig = exports.setConfigPath = exports.setConfig = exports.getOrderedConfig = exports.getOrderedAccount = exports.getConfigAccountId = exports.getConfigDefaultAccount = exports.getConfigAccounts = exports.getAccountType = exports.getEnv = exports.isTrackingAllowed = exports.isConfigFlagEnabled = exports.deleteConfigFile = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.deleteAccount = exports.removeSandboxAccountFromConfig = exports.getAccountId = exports.renameAccount = exports.updateDefaultAccount = exports.updateAccountConfig = exports.accountNameExistsInConfig = exports.getAccountConfig = exports.getConfigPath = exports.writeConfig = exports.getConfig = exports.deleteEmptyConfigFile = exports.createEmptyConfigFile = exports.loadConfigFromEnvironment = exports.validateConfig = exports.getAndLoadConfigIfNeeded = exports.loadConfig = void 0;
26
+ exports.findConfig = exports.setConfigPath = exports.setConfig = exports.getOrderedConfig = exports.getOrderedAccount = exports.getConfigAccountId = exports.updateDefaultMode = exports.getAccounts = exports.getDefaultAccount = exports.getAccountType = exports.getEnv = exports.isTrackingAllowed = exports.isConfigFlagEnabled = exports.deleteConfigFile = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.deleteAccount = exports.removeSandboxAccountFromConfig = exports.getAccountId = exports.renameAccount = exports.updateDefaultAccount = exports.updateAccountConfig = exports.accountNameExistsInConfig = exports.getAccountConfig = exports.configFileExists = exports.getConfigPath = exports.writeConfig = exports.getConfig = exports.deleteEmptyConfigFile = exports.createEmptyConfigFile = exports.loadConfigFromEnvironment = exports.validateConfig = exports.getAndLoadConfigIfNeeded = exports.loadConfig = void 0;
27
27
  const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
28
28
  const CLIConfiguration_1 = require("./CLIConfiguration");
29
29
  const configFile_1 = require("./configFile");
30
- const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
30
+ const getAccountIdentifier_1 = require("./getAccountIdentifier");
31
31
  // Use new config if it exists
32
32
  function loadConfig(path, options = {}) {
33
33
  // Attempt to load the root config
@@ -58,8 +58,8 @@ function loadConfigFromEnvironment() {
58
58
  return Boolean(config_DEPRECATED.loadConfigFromEnvironment());
59
59
  }
60
60
  exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
61
- function createEmptyConfigFile(options = {}, useRootConfig = false) {
62
- if (useRootConfig) {
61
+ function createEmptyConfigFile(options = {}, useHiddenConfig = false) {
62
+ if (useHiddenConfig) {
63
63
  CLIConfiguration_1.CLIConfiguration.write({ accounts: [] });
64
64
  }
65
65
  else {
@@ -93,13 +93,19 @@ function writeConfig(options = {}) {
93
93
  }
94
94
  }
95
95
  exports.writeConfig = writeConfig;
96
- function getConfigPath(path) {
97
- if (CLIConfiguration_1.CLIConfiguration.isActive()) {
96
+ function getConfigPath(path, useHiddenConfig = false) {
97
+ if (useHiddenConfig || CLIConfiguration_1.CLIConfiguration.isActive()) {
98
98
  return (0, configFile_1.getConfigFilePath)();
99
99
  }
100
100
  return config_DEPRECATED.getConfigPath(path);
101
101
  }
102
102
  exports.getConfigPath = getConfigPath;
103
+ function configFileExists(useHiddenConfig) {
104
+ return useHiddenConfig
105
+ ? (0, configFile_1.configFileExists)()
106
+ : Boolean(config_DEPRECATED.getConfigPath());
107
+ }
108
+ exports.configFileExists = configFileExists;
103
109
  function getAccountConfig(accountId) {
104
110
  if (CLIConfiguration_1.CLIConfiguration.isActive()) {
105
111
  return CLIConfiguration_1.CLIConfiguration.getConfigForAccount(accountId);
@@ -117,7 +123,7 @@ exports.accountNameExistsInConfig = accountNameExistsInConfig;
117
123
  function updateAccountConfig(configOptions) {
118
124
  const accountIdentifier = (0, getAccountIdentifier_1.getAccountIdentifier)(configOptions);
119
125
  if (CLIConfiguration_1.CLIConfiguration.isActive()) {
120
- return CLIConfiguration_1.CLIConfiguration.updateAccount({
126
+ return CLIConfiguration_1.CLIConfiguration.addOrUpdateAccount({
121
127
  ...configOptions,
122
128
  accountId: accountIdentifier,
123
129
  });
@@ -224,13 +230,31 @@ function getAccountType(accountType, sandboxAccountType) {
224
230
  return config_DEPRECATED.getAccountType(accountType, sandboxAccountType);
225
231
  }
226
232
  exports.getAccountType = getAccountType;
227
- // These functions are either not supported or have breaking changes with the new config setup
228
- exports.getConfigAccounts = config_DEPRECATED.getConfigAccounts;
229
- exports.getConfigDefaultAccount = config_DEPRECATED.getConfigDefaultAccount;
233
+ function getDefaultAccount() {
234
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
235
+ return CLIConfiguration_1.CLIConfiguration.getDefaultAccount();
236
+ }
237
+ return config_DEPRECATED.getConfigDefaultAccount();
238
+ }
239
+ exports.getDefaultAccount = getDefaultAccount;
240
+ function getAccounts() {
241
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
242
+ return CLIConfiguration_1.CLIConfiguration.getConfigAccounts();
243
+ }
244
+ return config_DEPRECATED.getConfigAccounts();
245
+ }
246
+ exports.getAccounts = getAccounts;
247
+ function updateDefaultMode(mode) {
248
+ if (CLIConfiguration_1.CLIConfiguration.isActive()) {
249
+ return CLIConfiguration_1.CLIConfiguration.updateDefaultMode(mode);
250
+ }
251
+ return config_DEPRECATED.updateDefaultMode(mode);
252
+ }
253
+ exports.updateDefaultMode = updateDefaultMode;
254
+ // These functions are not supported with the new config setup
230
255
  exports.getConfigAccountId = config_DEPRECATED.getConfigAccountId;
231
256
  exports.getOrderedAccount = config_DEPRECATED.getOrderedAccount;
232
257
  exports.getOrderedConfig = config_DEPRECATED.getOrderedConfig;
233
258
  exports.setConfig = config_DEPRECATED.setConfig;
234
259
  exports.setConfigPath = config_DEPRECATED.setConfigPath;
235
260
  exports.findConfig = config_DEPRECATED.findConfig;
236
- exports.updateDefaultMode = config_DEPRECATED.updateDefaultMode;
@@ -1,5 +1,5 @@
1
1
  export declare const DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = "hubspot.config.yml";
2
- export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hubspot";
2
+ export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hubspot-cli";
3
3
  export declare const HUBSPOT_CONFIGURATION_FILE = "config.yml";
4
4
  export declare const MIN_HTTP_TIMEOUT = 3000;
5
5
  export declare const HUBSPOT_ACCOUNT_TYPES: {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
4
4
  const lang_1 = require("../utils/lang");
5
5
  exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = 'hubspot.config.yml';
6
- exports.HUBSPOT_CONFIGURATION_FOLDER = '.hubspot';
6
+ exports.HUBSPOT_CONFIGURATION_FOLDER = '.hubspot-cli';
7
7
  exports.HUBSPOT_CONFIGURATION_FILE = 'config.yml';
8
8
  exports.MIN_HTTP_TIMEOUT = 3000;
9
9
  exports.HUBSPOT_ACCOUNT_TYPES = {
@@ -1,2 +1,8 @@
1
- import { FunctionInfo, FunctionOptions } from '../../types/Functions';
1
+ import { FunctionConfig, FunctionConfigInfo, FunctionInfo, FunctionOptions } from '../../types/Functions';
2
+ export declare function isObjectOrFunction(value: object): boolean;
3
+ export declare function createEndpoint(endpointMethod: string, filename: string): {
4
+ method: string;
5
+ file: string;
6
+ };
7
+ export declare function createConfig({ endpointPath, endpointMethod, functionFile, }: FunctionConfigInfo): FunctionConfig;
2
8
  export declare function createFunction(functionInfo: FunctionInfo, dest: string, options?: FunctionOptions): Promise<void>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createFunction = void 0;
6
+ exports.createFunction = exports.createConfig = exports.createEndpoint = exports.isObjectOrFunction = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const findup_sync_1 = __importDefault(require("findup-sync"));
@@ -17,12 +17,14 @@ function isObjectOrFunction(value) {
17
17
  const type = typeof value;
18
18
  return value != null && (type === 'object' || type === 'function');
19
19
  }
20
+ exports.isObjectOrFunction = isObjectOrFunction;
20
21
  function createEndpoint(endpointMethod, filename) {
21
22
  return {
22
23
  method: endpointMethod || 'GET',
23
24
  file: filename,
24
25
  };
25
26
  }
27
+ exports.createEndpoint = createEndpoint;
26
28
  function createConfig({ endpointPath, endpointMethod, functionFile, }) {
27
29
  return {
28
30
  runtime: 'nodejs18.x',
@@ -34,6 +36,7 @@ function createConfig({ endpointPath, endpointMethod, functionFile, }) {
34
36
  },
35
37
  };
36
38
  }
39
+ exports.createConfig = createConfig;
37
40
  function writeConfig(configFilePath, config) {
38
41
  const configJson = JSON.stringify(config, null, ' ');
39
42
  fs_extra_1.default.writeFileSync(configFilePath, configJson);
@@ -106,7 +106,7 @@ const updateFileContents = async (file, metaData, getInternalVersion) => {
106
106
  async function createModule(moduleDefinition, name, dest, getInternalVersion, options = {
107
107
  allowExistingDir: false,
108
108
  }) {
109
- const { moduleLabel, contentTypes, global, reactType: isReactModule, } = moduleDefinition;
109
+ const { moduleLabel, contentTypes, global, reactType: isReactModule, availableForNewContent, } = moduleDefinition;
110
110
  const moduleMetaData = {
111
111
  label: moduleLabel,
112
112
  css_assets: [],
@@ -118,7 +118,7 @@ async function createModule(moduleDefinition, name, dest, getInternalVersion, op
118
118
  other_assets: [],
119
119
  smart_type: 'NOT_SMART',
120
120
  tags: [],
121
- is_available_for_new_content: false,
121
+ is_available_for_new_content: availableForNewContent,
122
122
  };
123
123
  const folderName = name.endsWith('.module') ? name : `${name}.module`;
124
124
  const destPath = !isReactModule
package/lib/oauth.js CHANGED
@@ -4,7 +4,7 @@ exports.addOauthToAccountConfig = exports.getOauthManager = void 0;
4
4
  const OAuth2Manager_1 = require("../models/OAuth2Manager");
5
5
  const auth_1 = require("../constants/auth");
6
6
  const logger_1 = require("./logger");
7
- const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
7
+ const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
8
8
  const config_1 = require("../config");
9
9
  const lang_1 = require("../utils/lang");
10
10
  const i18nKey = 'lib.oauth';
@@ -13,6 +13,7 @@ const config_1 = require("../config");
13
13
  const config_2 = require("../constants/config");
14
14
  const developerTestAccounts_1 = require("../api/developerTestAccounts");
15
15
  const logger_1 = require("./logger");
16
+ const CLIConfiguration_1 = require("../config/CLIConfiguration");
16
17
  const lang_1 = require("../utils/lang");
17
18
  const errors_1 = require("../errors");
18
19
  const i18nKey = 'lib.personalAccessKey';
@@ -141,7 +142,7 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
141
142
  }
142
143
  logger_1.logger.debug(err);
143
144
  }
144
- const updatedConfig = (0, config_1.updateAccountConfig)({
145
+ const updatedAccount = (0, config_1.updateAccountConfig)({
145
146
  accountId: portalId,
146
147
  accountType,
147
148
  personalAccessKey,
@@ -151,10 +152,12 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
151
152
  parentAccountId,
152
153
  env: accountEnv,
153
154
  });
154
- (0, config_1.writeConfig)();
155
+ if (!CLIConfiguration_1.CLIConfiguration.isActive()) {
156
+ (0, config_1.writeConfig)();
157
+ }
155
158
  if (makeDefault && name) {
156
159
  (0, config_1.updateDefaultAccount)(name);
157
160
  }
158
- return updatedConfig;
161
+ return updatedAccount;
159
162
  }
160
163
  exports.updateConfigWithAccessToken = updateConfigWithAccessToken;
@@ -1,5 +1,6 @@
1
1
  import { RequestPortsData } from '../types/PortManager';
2
2
  export declare const BASE_URL: string;
3
+ export declare function isPortManagerServerRunning(): Promise<boolean>;
3
4
  export declare function startPortManagerServer(): Promise<void>;
4
5
  export declare function stopPortManagerServer(): Promise<void>;
5
6
  export declare function requestPorts(portData: Array<RequestPortsData>): Promise<{
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.BASE_URL = void 0;
6
+ exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.isPortManagerServerRunning = exports.BASE_URL = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const PortManagerServer_1 = require("../utils/PortManagerServer");
9
9
  const detectPort_1 = require("../utils/detectPort");
@@ -13,6 +13,7 @@ async function isPortManagerServerRunning() {
13
13
  const port = await (0, detectPort_1.detectPort)(ports_1.PORT_MANAGER_SERVER_PORT);
14
14
  return port !== ports_1.PORT_MANAGER_SERVER_PORT;
15
15
  }
16
+ exports.isPortManagerServerRunning = isPortManagerServerRunning;
16
17
  async function startPortManagerServer() {
17
18
  const isRunning = await isPortManagerServerRunning();
18
19
  if (!isRunning) {
@@ -9,7 +9,7 @@ const moment_1 = __importDefault(require("moment"));
9
9
  const urls_1 = require("../lib/urls");
10
10
  const environment_1 = require("../lib/environment");
11
11
  const logger_1 = require("../lib/logger");
12
- const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
12
+ const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
13
13
  const auth_1 = require("../constants/auth");
14
14
  const lang_1 = require("../utils/lang");
15
15
  const i18nKey = 'models.OAuth2Manager';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -53,6 +53,7 @@
53
53
  "./errors/*": "./errors/*.js",
54
54
  "./http": "./http/index.js",
55
55
  "./http/*": "./http/*.js",
56
+ "./config/getAccountIdentifier": "./config/getAccountIdentifier.js",
56
57
  "./config": "./config/index.js",
57
58
  "./constants/*": "./constants/*.js",
58
59
  "./models/*": "./models/*.js",
package/types/Hubdb.d.ts CHANGED
@@ -98,3 +98,12 @@ export type FetchRowsResponse = {
98
98
  };
99
99
  } | null;
100
100
  };
101
+ export type FetchTablesResponse = {
102
+ total: number;
103
+ results: Array<Table>;
104
+ paging?: {
105
+ next: {
106
+ after: string | null;
107
+ };
108
+ } | null;
109
+ };
@@ -12,4 +12,5 @@ export type ModuleDefinition = {
12
12
  moduleLabel: string;
13
13
  reactType: boolean;
14
14
  global: boolean;
15
+ availableForNewContent: boolean;
15
16
  };
@@ -1,5 +1,4 @@
1
- import { CLIAccount, GenericAccount } from '../types/Accounts';
1
+ import { CLIAccount } from '../types/Accounts';
2
2
  import { CLIConfig } from '../types/Config';
3
- export declare function getAccountIdentifier(account?: GenericAccount | null): number | undefined;
4
3
  export declare function getAccounts(config?: CLIConfig | null): Array<CLIAccount>;
5
4
  export declare function getDefaultAccount(config?: CLIConfig | null): string | number | undefined;
@@ -1,18 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDefaultAccount = exports.getAccounts = exports.getAccountIdentifier = void 0;
4
- function getAccountIdentifier(account) {
5
- if (!account) {
6
- return undefined;
7
- }
8
- else if (Object.hasOwn(account, 'portalId')) {
9
- return account.portalId;
10
- }
11
- else if (Object.hasOwn(account, 'accountId')) {
12
- return account.accountId;
13
- }
14
- }
15
- exports.getAccountIdentifier = getAccountIdentifier;
3
+ exports.getDefaultAccount = exports.getAccounts = void 0;
16
4
  function getAccounts(config) {
17
5
  if (!config) {
18
6
  return [];