@hubspot/local-dev-lib 0.5.0-experimental.14 → 0.5.0-experimental.16

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/config/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ACCOUNT_IDENTIFIERS } from '../constants/config';
2
2
  import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config';
3
- import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
3
+ import { HubSpotConfigAccount } from '../types/Accounts';
4
4
  import { ValueOf } from '../types/Utils';
5
5
  export declare function getLocalConfigDefaultFilePath(): string;
6
6
  export declare function getConfigPathEnvironmentVariables(): {
@@ -10,57 +10,10 @@ export declare function getConfigPathEnvironmentVariables(): {
10
10
  export declare function doesConfigFileExistAtPath(path: string): boolean;
11
11
  export declare function readConfigFile(configPath: string): string;
12
12
  export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
13
- export declare function formatConfigForWrite(config: HubSpotConfig): {
14
- accounts: ({
15
- personalAccessKey: string;
16
- auth: {
17
- tokenInfo: TokenInfo;
18
- };
19
- accountType?: AccountType | undefined;
20
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
21
- parentAccountId?: number | undefined;
22
- name: string;
23
- accountId: number;
24
- env: import("../types/Config").Environment;
25
- authType: "apikey" | "oauth2" | "personalaccesskey";
26
- } | {
27
- auth: {
28
- clientId: string;
29
- clientSecret: string;
30
- scopes: string[];
31
- tokenInfo: TokenInfo;
32
- };
33
- accountType?: AccountType | undefined;
34
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
35
- parentAccountId?: number | undefined;
36
- name: string;
37
- accountId: number;
38
- env: import("../types/Config").Environment;
39
- authType: "apikey" | "oauth2" | "personalaccesskey";
40
- } | {
41
- apiKey: string;
42
- accountType?: AccountType | undefined;
43
- defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
44
- parentAccountId?: number | undefined;
45
- name: string;
46
- accountId: number;
47
- env: import("../types/Config").Environment;
48
- authType: "apikey" | "oauth2" | "personalaccesskey";
49
- })[];
50
- allowAutoUpdates?: boolean | undefined;
51
- defaultMode?: import("../types/Files").CmsPublishMode | undefined;
52
- env?: import("../types/Config").Environment | undefined;
53
- httpUseLocalhost?: boolean | undefined;
54
- autoOpenBrowser?: boolean | undefined;
55
- useCustomObjectHubfile?: boolean | undefined;
56
- flags?: string[] | undefined;
57
- defaultCmsPublishMode: import("../types/Files").CmsPublishMode | undefined;
58
- httpTimeout: number | undefined;
59
- allowUsageTracking: boolean | undefined;
60
- defaultAccount?: number | undefined;
61
- };
13
+ export declare function formatConfigForWrite(config: HubSpotConfig): HubSpotConfig;
62
14
  export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
63
15
  export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
16
+ export declare function convertToDeprecatedConfig(config: HubSpotConfig): Partial<HubSpotConfig> & Partial<DeprecatedHubSpotConfigFields>;
64
17
  export declare function parseConfig(configSource: string, configPath: string): HubSpotConfig;
65
18
  export declare function buildConfigFromEnvironment(): HubSpotConfig;
66
19
  export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
package/config/utils.js CHANGED
@@ -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.handleConfigFileSystemError = exports.validateConfigAccount = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
6
+ exports.handleConfigFileSystemError = exports.validateConfigAccount = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.convertToDeprecatedConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const js_yaml_1 = __importDefault(require("js-yaml"));
9
9
  const config_1 = require("../constants/config");
@@ -91,20 +91,26 @@ function formatConfigForWrite(config) {
91
91
  ...rest,
92
92
  accounts: accounts.map(account => {
93
93
  const { name, accountId, env, authType, ...rest } = account;
94
- return {
94
+ const orderedAccount = {
95
95
  name,
96
96
  accountId,
97
97
  env,
98
98
  authType,
99
99
  ...rest,
100
+ // using ...rest messes with the typing
100
101
  };
102
+ return removeUndefinedFieldsFromConfigAccount(orderedAccount);
101
103
  }),
102
104
  };
103
- return removeUndefinedFieldsFromConfigAccount(orderedConfig);
105
+ return orderedConfig;
104
106
  }
105
107
  exports.formatConfigForWrite = formatConfigForWrite;
106
108
  function writeConfigFile(config, configPath) {
107
- const source = js_yaml_1.default.dump(formatConfigForWrite(config));
109
+ const formattedConfig = formatConfigForWrite(config);
110
+ const configToWrite = configPath == config_1.GLOBAL_CONFIG_PATH
111
+ ? formattedConfig
112
+ : convertToDeprecatedConfig(formattedConfig);
113
+ const source = js_yaml_1.default.dump(configToWrite);
108
114
  try {
109
115
  fs_extra_1.default.ensureFileSync(configPath);
110
116
  fs_extra_1.default.writeFileSync(configPath, source);
@@ -160,6 +166,30 @@ function normalizeParsedConfig(parsedConfig) {
160
166
  return parsedConfig;
161
167
  }
162
168
  exports.normalizeParsedConfig = normalizeParsedConfig;
169
+ function convertToDeprecatedConfig(config) {
170
+ const deprecatedConfig = structuredClone(config);
171
+ if (config.defaultAccount) {
172
+ const defaultAccount = getConfigAccountByIdentifier(config.accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, config.defaultAccount);
173
+ if (defaultAccount) {
174
+ deprecatedConfig.defaultPortal = defaultAccount.name;
175
+ delete deprecatedConfig.defaultAccount;
176
+ }
177
+ }
178
+ const portals = config.accounts.map(account => {
179
+ if (account.accountId) {
180
+ const deprecatedAccount = structuredClone(account);
181
+ deprecatedAccount.portalId = account.accountId;
182
+ // @ts-expect-error deleting accountId is intential since using deprecated config format
183
+ delete deprecatedAccount.accountId;
184
+ return deprecatedAccount;
185
+ }
186
+ return account;
187
+ });
188
+ deprecatedConfig.portals = portals;
189
+ delete deprecatedConfig.accounts;
190
+ return deprecatedConfig;
191
+ }
192
+ exports.convertToDeprecatedConfig = convertToDeprecatedConfig;
163
193
  function parseConfig(configSource, configPath) {
164
194
  let parsedYaml;
165
195
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/local-dev-lib",
3
- "version": "0.5.0-experimental.14",
3
+ "version": "0.5.0-experimental.16",
4
4
  "description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,11 +11,11 @@
11
11
  "access": "public"
12
12
  },
13
13
  "scripts": {
14
- "build": "ts-node ./scripts/build.ts",
14
+ "build": "tsx ./scripts/build.ts",
15
15
  "lint": "eslint --max-warnings=0 . && prettier . --check",
16
16
  "local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
17
17
  "prettier:write": "prettier . --write",
18
- "release": "ts-node ./scripts/release.ts release",
18
+ "release": "tsx ./scripts/release.ts release",
19
19
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ./node_modules/.bin/jest"
20
20
  },
21
21
  "license": "Apache-2.0",
@@ -39,7 +39,7 @@
39
39
  "jest": "^29.5.0",
40
40
  "open": "^8.4.2",
41
41
  "ts-jest": "^29.0.5",
42
- "ts-node": "^10.9.2",
42
+ "tsx": "^4.20.6",
43
43
  "typescript": "^4.9.5",
44
44
  "yargs": "^17.7.2"
45
45
  },