@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.
- package/api/github.d.ts +0 -1
- package/api/projects.d.ts +0 -1
- package/config/CLIConfiguration.d.ts +65 -0
- package/config/CLIConfiguration.js +509 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +100 -0
- package/config/configUtils.d.ts +5 -0
- package/config/configUtils.js +87 -0
- package/config/config_DEPRECATED.d.ts +76 -0
- package/config/config_DEPRECATED.js +693 -0
- package/config/environment.d.ts +2 -0
- package/config/environment.js +60 -0
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +41 -25
- package/config/index.js +236 -248
- package/config/migrate.d.ts +20 -0
- package/config/migrate.js +150 -0
- package/constants/config.d.ts +7 -24
- package/constants/config.js +13 -25
- package/constants/environments.d.ts +11 -0
- package/constants/environments.js +12 -1
- package/http/getAxiosConfig.js +1 -7
- package/http/index.js +19 -23
- package/lang/en.json +81 -67
- package/lib/archive.d.ts +0 -1
- package/lib/cms/themes.js +1 -3
- package/lib/environment.d.ts +1 -1
- package/lib/github.d.ts +0 -1
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +16 -8
- package/lib/personalAccessKey.d.ts +2 -2
- package/lib/personalAccessKey.js +30 -39
- package/lib/trackUsage.js +3 -6
- package/models/OAuth2Manager.d.ts +4 -3
- package/models/OAuth2Manager.js +29 -20
- package/package.json +4 -3
- package/types/Accounts.d.ts +109 -20
- package/types/Config.d.ts +24 -11
- package/types/Http.d.ts +0 -1
- package/utils/accounts.d.ts +4 -0
- package/utils/accounts.js +28 -0
- package/config/defaultAccountOverride.d.ts +0 -2
- package/config/defaultAccountOverride.js +0 -57
- package/config/utils.d.ts +0 -70
- package/config/utils.js +0 -328
package/lib/personalAccessKey.js
CHANGED
|
@@ -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';
|
|
@@ -35,30 +36,30 @@ async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMEN
|
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
exports.getAccessToken = getAccessToken;
|
|
38
|
-
async function refreshAccessToken(
|
|
39
|
-
const { personalAccessKey, env, accountId } = account;
|
|
39
|
+
async function refreshAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
|
|
40
40
|
const accessTokenResponse = await getAccessToken(personalAccessKey, env, accountId);
|
|
41
41
|
const { accessToken, expiresAt } = accessTokenResponse;
|
|
42
|
-
(0, config_1.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
const config = (0, config_1.getAccountConfig)(accountId);
|
|
43
|
+
(0, config_1.updateAccountConfig)({
|
|
44
|
+
env,
|
|
45
|
+
...config,
|
|
46
|
+
accountId,
|
|
47
|
+
tokenInfo: {
|
|
48
|
+
accessToken,
|
|
49
|
+
expiresAt: expiresAt,
|
|
49
50
|
},
|
|
50
51
|
});
|
|
52
|
+
(0, config_1.writeConfig)();
|
|
51
53
|
return accessTokenResponse;
|
|
52
54
|
}
|
|
53
|
-
async function getNewAccessToken(
|
|
54
|
-
const
|
|
55
|
-
const key = getRefreshKey(personalAccessKey, auth.tokenInfo.expiresAt);
|
|
55
|
+
async function getNewAccessToken(accountId, personalAccessKey, expiresAt, env) {
|
|
56
|
+
const key = getRefreshKey(personalAccessKey, expiresAt);
|
|
56
57
|
if (refreshRequests.has(key)) {
|
|
57
58
|
return refreshRequests.get(key);
|
|
58
59
|
}
|
|
59
60
|
let accessTokenResponse;
|
|
60
61
|
try {
|
|
61
|
-
const refreshAccessPromise = refreshAccessToken(
|
|
62
|
+
const refreshAccessPromise = refreshAccessToken(personalAccessKey, env, accountId);
|
|
62
63
|
if (key) {
|
|
63
64
|
refreshRequests.set(key, refreshAccessPromise);
|
|
64
65
|
}
|
|
@@ -73,37 +74,28 @@ async function getNewAccessToken(account) {
|
|
|
73
74
|
return accessTokenResponse;
|
|
74
75
|
}
|
|
75
76
|
async function getNewAccessTokenByAccountId(accountId) {
|
|
76
|
-
const account = (0, config_1.
|
|
77
|
+
const account = (0, config_1.getAccountConfig)(accountId);
|
|
77
78
|
if (!account) {
|
|
78
79
|
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
accountId,
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
const accessTokenResponse = await getNewAccessToken(account);
|
|
81
|
+
const { auth, personalAccessKey, env } = account;
|
|
82
|
+
const accessTokenResponse = await getNewAccessToken(accountId, personalAccessKey, auth?.tokenInfo?.expiresAt, env);
|
|
86
83
|
return accessTokenResponse;
|
|
87
84
|
}
|
|
88
85
|
async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
|
|
89
|
-
const account = (0, config_1.
|
|
86
|
+
const account = (0, config_1.getAccountConfig)(accountId);
|
|
90
87
|
if (!account) {
|
|
91
88
|
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
|
|
95
|
-
accountId,
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
const { auth } = account;
|
|
90
|
+
const { auth, personalAccessKey, env } = account;
|
|
99
91
|
const authTokenInfo = auth && auth.tokenInfo;
|
|
100
92
|
const authDataExists = authTokenInfo && auth?.tokenInfo?.accessToken;
|
|
101
93
|
if (!authDataExists ||
|
|
102
94
|
forceRefresh ||
|
|
103
95
|
(0, moment_1.default)().add(5, 'minutes').isAfter((0, moment_1.default)(authTokenInfo.expiresAt))) {
|
|
104
|
-
return getNewAccessToken(
|
|
96
|
+
return getNewAccessToken(accountId, personalAccessKey, authTokenInfo && authTokenInfo.expiresAt, env).then(tokenInfo => tokenInfo.accessToken);
|
|
105
97
|
}
|
|
106
|
-
return auth
|
|
98
|
+
return auth?.tokenInfo?.accessToken;
|
|
107
99
|
}
|
|
108
100
|
exports.accessTokenForPersonalAccessKey = accessTokenForPersonalAccessKey;
|
|
109
101
|
async function enabledFeaturesForPersonalAccessKey(accountId) {
|
|
@@ -121,10 +113,7 @@ async function authorizedScopesForPortalAndUser(accountId) {
|
|
|
121
113
|
exports.authorizedScopesForPortalAndUser = authorizedScopesForPortalAndUser;
|
|
122
114
|
async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
123
115
|
const { portalId, accessToken, expiresAt, accountType } = token;
|
|
124
|
-
const
|
|
125
|
-
? (0, config_1.getConfigAccountByName)(name)
|
|
126
|
-
: (0, config_1.getConfigDefaultAccount)();
|
|
127
|
-
const accountEnv = env || account.env;
|
|
116
|
+
const accountEnv = env || (0, config_1.getEnv)(name);
|
|
128
117
|
let parentAccountId;
|
|
129
118
|
try {
|
|
130
119
|
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
|
|
@@ -157,19 +146,21 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
157
146
|
}
|
|
158
147
|
logger_1.logger.debug(err);
|
|
159
148
|
}
|
|
160
|
-
const updatedAccount = {
|
|
149
|
+
const updatedAccount = (0, config_1.updateAccountConfig)({
|
|
161
150
|
accountId: portalId,
|
|
162
151
|
accountType,
|
|
163
152
|
personalAccessKey,
|
|
164
|
-
name
|
|
153
|
+
name,
|
|
165
154
|
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
166
|
-
|
|
155
|
+
tokenInfo: { accessToken, expiresAt },
|
|
167
156
|
parentAccountId,
|
|
168
157
|
env: accountEnv,
|
|
169
|
-
};
|
|
170
|
-
(
|
|
158
|
+
});
|
|
159
|
+
if (!CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
160
|
+
(0, config_1.writeConfig)();
|
|
161
|
+
}
|
|
171
162
|
if (makeDefault && name) {
|
|
172
|
-
(0, config_1.
|
|
163
|
+
(0, config_1.updateDefaultAccount)(name);
|
|
173
164
|
}
|
|
174
165
|
return updatedAccount;
|
|
175
166
|
}
|
package/lib/trackUsage.js
CHANGED
|
@@ -11,7 +11,6 @@ const http_1 = require("../http");
|
|
|
11
11
|
const config_1 = require("../config");
|
|
12
12
|
const fileMapper_1 = require("../api/fileMapper");
|
|
13
13
|
const lang_1 = require("../utils/lang");
|
|
14
|
-
const environment_1 = require("./environment");
|
|
15
14
|
const i18nKey = 'lib.trackUsage';
|
|
16
15
|
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
17
16
|
const usageEvent = {
|
|
@@ -36,8 +35,8 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
36
35
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.invalidEvent`, { eventName }));
|
|
37
36
|
}
|
|
38
37
|
const path = `${fileMapper_1.FILE_MAPPER_API_PATH}/${analyticsEndpoint}`;
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
38
|
+
const accountConfig = accountId && (0, config_1.getAccountConfig)(accountId);
|
|
39
|
+
if (accountConfig && accountConfig.authType === 'personalaccesskey') {
|
|
41
40
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
|
|
42
41
|
try {
|
|
43
42
|
await http_1.http.post(accountId, {
|
|
@@ -51,9 +50,7 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
51
50
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
|
-
const env = accountId
|
|
55
|
-
? (0, config_1.getConfigAccountEnvironment)(accountId)
|
|
56
|
-
: (0, environment_1.getValidEnv)();
|
|
53
|
+
const env = (0, config_1.getEnv)(accountId);
|
|
57
54
|
const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
|
|
58
55
|
env,
|
|
59
56
|
url: path,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FlatAccountFields, OAuth2ManagerAccountConfig, WriteTokenInfoFunction, RefreshTokenResponse, ExchangeProof } from '../types/Accounts';
|
|
2
2
|
export declare class OAuth2Manager {
|
|
3
|
-
account:
|
|
3
|
+
account: OAuth2ManagerAccountConfig;
|
|
4
4
|
writeTokenInfo?: WriteTokenInfoFunction;
|
|
5
5
|
refreshTokenRequest: Promise<RefreshTokenResponse> | null;
|
|
6
|
-
constructor(account:
|
|
6
|
+
constructor(account: OAuth2ManagerAccountConfig, writeTokenInfo?: WriteTokenInfoFunction);
|
|
7
7
|
accessToken(): Promise<string | undefined>;
|
|
8
8
|
fetchAccessToken(exchangeProof: ExchangeProof): Promise<void>;
|
|
9
9
|
exchangeForTokens(exchangeProof: ExchangeProof): Promise<void>;
|
|
10
10
|
refreshAccessToken(): Promise<void>;
|
|
11
|
+
static fromConfig(accountConfig: FlatAccountFields, writeTokenInfo: WriteTokenInfoFunction): OAuth2Manager;
|
|
11
12
|
}
|
package/models/OAuth2Manager.js
CHANGED
|
@@ -9,6 +9,8 @@ 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("../config/getAccountIdentifier");
|
|
13
|
+
const auth_1 = require("../constants/auth");
|
|
12
14
|
const lang_1 = require("../utils/lang");
|
|
13
15
|
const i18nKey = 'models.OAuth2Manager';
|
|
14
16
|
class OAuth2Manager {
|
|
@@ -24,23 +26,23 @@ class OAuth2Manager {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
async accessToken() {
|
|
27
|
-
if (!this.account.
|
|
29
|
+
if (!this.account.tokenInfo?.refreshToken) {
|
|
28
30
|
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.missingRefreshToken`, {
|
|
29
|
-
accountId: this.account
|
|
31
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
30
32
|
}));
|
|
31
33
|
}
|
|
32
|
-
if (!this.account.
|
|
34
|
+
if (!this.account.tokenInfo?.accessToken ||
|
|
33
35
|
(0, moment_1.default)()
|
|
34
36
|
.add(5, 'minutes')
|
|
35
|
-
.isAfter((0, moment_1.default)(new Date(this.account.
|
|
37
|
+
.isAfter((0, moment_1.default)(new Date(this.account.tokenInfo.expiresAt || '')))) {
|
|
36
38
|
await this.refreshAccessToken();
|
|
37
39
|
}
|
|
38
|
-
return this.account.
|
|
40
|
+
return this.account.tokenInfo.accessToken;
|
|
39
41
|
}
|
|
40
42
|
async fetchAccessToken(exchangeProof) {
|
|
41
43
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.fetchingAccessToken`, {
|
|
42
|
-
accountId: this.account
|
|
43
|
-
clientId: this.account.
|
|
44
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
45
|
+
clientId: this.account.clientId || '',
|
|
44
46
|
}));
|
|
45
47
|
try {
|
|
46
48
|
const { data } = await (0, axios_1.default)({
|
|
@@ -51,20 +53,20 @@ class OAuth2Manager {
|
|
|
51
53
|
});
|
|
52
54
|
this.refreshTokenRequest = data;
|
|
53
55
|
const { refresh_token: refreshToken, access_token: accessToken, expires_in: expiresIn, } = data;
|
|
54
|
-
if (!this.account.
|
|
55
|
-
this.account.
|
|
56
|
+
if (!this.account.tokenInfo) {
|
|
57
|
+
this.account.tokenInfo = {};
|
|
56
58
|
}
|
|
57
|
-
this.account.
|
|
58
|
-
this.account.
|
|
59
|
-
this.account.
|
|
59
|
+
this.account.tokenInfo.refreshToken = refreshToken;
|
|
60
|
+
this.account.tokenInfo.accessToken = accessToken;
|
|
61
|
+
this.account.tokenInfo.expiresAt = (0, moment_1.default)()
|
|
60
62
|
.add(Math.round(parseInt(expiresIn) * 0.75), 'seconds')
|
|
61
63
|
.toString();
|
|
62
64
|
if (this.writeTokenInfo) {
|
|
63
65
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updatingTokenInfo`, {
|
|
64
|
-
accountId: this.account
|
|
65
|
-
clientId: this.account.
|
|
66
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
67
|
+
clientId: this.account.clientId || '',
|
|
66
68
|
}));
|
|
67
|
-
this.writeTokenInfo(this.account.
|
|
69
|
+
this.writeTokenInfo(this.account.tokenInfo);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
finally {
|
|
@@ -74,8 +76,8 @@ class OAuth2Manager {
|
|
|
74
76
|
async exchangeForTokens(exchangeProof) {
|
|
75
77
|
if (this.refreshTokenRequest) {
|
|
76
78
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.refreshingAccessToken`, {
|
|
77
|
-
accountId: this.account
|
|
78
|
-
clientId: this.account.
|
|
79
|
+
accountId: (0, getAccountIdentifier_1.getAccountIdentifier)(this.account),
|
|
80
|
+
clientId: this.account.clientId || '',
|
|
79
81
|
}));
|
|
80
82
|
await this.refreshTokenRequest;
|
|
81
83
|
}
|
|
@@ -86,11 +88,18 @@ class OAuth2Manager {
|
|
|
86
88
|
async refreshAccessToken() {
|
|
87
89
|
const refreshTokenProof = {
|
|
88
90
|
grant_type: 'refresh_token',
|
|
89
|
-
client_id: this.account.
|
|
90
|
-
client_secret: this.account.
|
|
91
|
-
refresh_token: this.account.
|
|
91
|
+
client_id: this.account.clientId,
|
|
92
|
+
client_secret: this.account.clientSecret,
|
|
93
|
+
refresh_token: this.account.tokenInfo?.refreshToken,
|
|
92
94
|
};
|
|
93
95
|
await this.exchangeForTokens(refreshTokenProof);
|
|
94
96
|
}
|
|
97
|
+
static fromConfig(accountConfig, writeTokenInfo) {
|
|
98
|
+
return new OAuth2Manager({
|
|
99
|
+
...accountConfig,
|
|
100
|
+
authType: auth_1.AUTH_METHODS.oauth.value,
|
|
101
|
+
...(accountConfig.auth || {}),
|
|
102
|
+
}, writeTokenInfo);
|
|
103
|
+
}
|
|
95
104
|
}
|
|
96
105
|
exports.OAuth2Manager = OAuth2Manager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2-experimental.0",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"./http": "./http/index.js",
|
|
51
51
|
"./http/*": "./http/*.js",
|
|
52
52
|
"./config/getAccountIdentifier": "./config/getAccountIdentifier.js",
|
|
53
|
+
"./config/migrate": "./config/migrate.js",
|
|
53
54
|
"./config": "./config/index.js",
|
|
54
55
|
"./constants/*": "./constants/*.js",
|
|
55
56
|
"./models/*": "./models/*.js",
|
|
@@ -57,13 +58,13 @@
|
|
|
57
58
|
},
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"address": "2.0.2",
|
|
60
|
-
"axios": "1.
|
|
61
|
+
"axios": "1.7.2",
|
|
61
62
|
"chalk": "2.4.2",
|
|
62
63
|
"chokidar": "3.6.0",
|
|
63
64
|
"content-disposition": "0.5.4",
|
|
64
65
|
"cors": "2.8.5",
|
|
65
66
|
"debounce": "1.2.1",
|
|
66
|
-
"express": "4.
|
|
67
|
+
"express": "4.19.2",
|
|
67
68
|
"extract-zip": "2.0.1",
|
|
68
69
|
"findup-sync": "5.0.0",
|
|
69
70
|
"fs-extra": "11.2.0",
|
package/types/Accounts.d.ts
CHANGED
|
@@ -2,20 +2,45 @@ import { HUBSPOT_ACCOUNT_TYPES } from '../constants/config';
|
|
|
2
2
|
import { CmsPublishMode } from './Files';
|
|
3
3
|
import { Environment } from './Config';
|
|
4
4
|
import { ValueOf } from './Utils';
|
|
5
|
-
import { PERSONAL_ACCESS_KEY_AUTH_METHOD, OAUTH_AUTH_METHOD, API_KEY_AUTH_METHOD } from '../constants/auth';
|
|
6
5
|
export type AuthType = 'personalaccesskey' | 'apikey' | 'oauth2';
|
|
7
|
-
interface
|
|
8
|
-
name
|
|
6
|
+
export interface CLIAccount_NEW {
|
|
7
|
+
name?: string;
|
|
9
8
|
accountId: number;
|
|
10
9
|
accountType?: AccountType;
|
|
11
10
|
defaultCmsPublishMode?: CmsPublishMode;
|
|
12
11
|
env: Environment;
|
|
13
|
-
authType
|
|
14
|
-
|
|
12
|
+
authType?: AuthType;
|
|
13
|
+
auth?: {
|
|
14
|
+
tokenInfo?: TokenInfo;
|
|
15
|
+
clientId?: string;
|
|
16
|
+
clientSecret?: string;
|
|
17
|
+
};
|
|
18
|
+
sandboxAccountType?: string | null;
|
|
19
|
+
parentAccountId?: number | null;
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
personalAccessKey?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CLIAccount_DEPRECATED {
|
|
24
|
+
name?: string;
|
|
25
|
+
portalId?: number;
|
|
26
|
+
defaultCmsPublishMode?: CmsPublishMode;
|
|
27
|
+
env: Environment;
|
|
28
|
+
accountType?: AccountType;
|
|
29
|
+
authType?: AuthType;
|
|
30
|
+
auth?: {
|
|
31
|
+
tokenInfo?: TokenInfo;
|
|
32
|
+
clientId?: string;
|
|
33
|
+
clientSecret?: string;
|
|
34
|
+
};
|
|
35
|
+
sandboxAccountType?: string | null;
|
|
36
|
+
parentAccountId?: number | null;
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
personalAccessKey?: string;
|
|
15
39
|
}
|
|
16
|
-
export type
|
|
40
|
+
export type CLIAccount = CLIAccount_NEW | CLIAccount_DEPRECATED;
|
|
41
|
+
export type GenericAccount = {
|
|
17
42
|
portalId?: number;
|
|
18
|
-
|
|
43
|
+
accountId?: number;
|
|
19
44
|
};
|
|
20
45
|
export type AccountType = ValueOf<typeof HUBSPOT_ACCOUNT_TYPES>;
|
|
21
46
|
export type TokenInfo = {
|
|
@@ -23,27 +48,60 @@ export type TokenInfo = {
|
|
|
23
48
|
expiresAt?: string;
|
|
24
49
|
refreshToken?: string;
|
|
25
50
|
};
|
|
26
|
-
export interface
|
|
27
|
-
authType:
|
|
51
|
+
export interface PersonalAccessKeyAccount_NEW extends CLIAccount_NEW {
|
|
52
|
+
authType: 'personalaccesskey';
|
|
53
|
+
personalAccessKey: string;
|
|
54
|
+
}
|
|
55
|
+
export interface PersonalAccessKeyAccount_DEPRECATED extends CLIAccount_DEPRECATED {
|
|
56
|
+
authType: 'personalaccesskey';
|
|
28
57
|
personalAccessKey: string;
|
|
58
|
+
}
|
|
59
|
+
export type PersonalAccessKeyAccount = PersonalAccessKeyAccount_NEW | PersonalAccessKeyAccount_DEPRECATED;
|
|
60
|
+
export interface OAuthAccount_NEW extends CLIAccount_NEW {
|
|
61
|
+
authType: 'oauth2';
|
|
29
62
|
auth: {
|
|
30
|
-
|
|
63
|
+
clientId?: string;
|
|
64
|
+
clientSecret?: string;
|
|
65
|
+
scopes?: Array<string>;
|
|
66
|
+
tokenInfo?: TokenInfo;
|
|
31
67
|
};
|
|
32
68
|
}
|
|
33
|
-
export interface
|
|
34
|
-
authType:
|
|
69
|
+
export interface OAuthAccount_DEPRECATED extends CLIAccount_DEPRECATED {
|
|
70
|
+
authType: 'oauth2';
|
|
35
71
|
auth: {
|
|
36
|
-
clientId
|
|
37
|
-
clientSecret
|
|
38
|
-
scopes
|
|
39
|
-
tokenInfo
|
|
72
|
+
clientId?: string;
|
|
73
|
+
clientSecret?: string;
|
|
74
|
+
scopes?: Array<string>;
|
|
75
|
+
tokenInfo?: TokenInfo;
|
|
40
76
|
};
|
|
41
77
|
}
|
|
42
|
-
export
|
|
43
|
-
|
|
78
|
+
export type OAuthAccount = OAuthAccount_NEW | OAuthAccount_DEPRECATED;
|
|
79
|
+
export interface APIKeyAccount_NEW extends CLIAccount_NEW {
|
|
80
|
+
authType: 'apikey';
|
|
44
81
|
apiKey: string;
|
|
45
82
|
}
|
|
46
|
-
export
|
|
83
|
+
export interface APIKeyAccount_DEPRECATED extends CLIAccount_DEPRECATED {
|
|
84
|
+
authType: 'apikey';
|
|
85
|
+
apiKey: string;
|
|
86
|
+
}
|
|
87
|
+
export type APIKeyAccount = APIKeyAccount_NEW | APIKeyAccount_DEPRECATED;
|
|
88
|
+
export interface FlatAccountFields_NEW extends CLIAccount_NEW {
|
|
89
|
+
tokenInfo?: TokenInfo;
|
|
90
|
+
clientId?: string;
|
|
91
|
+
clientSecret?: string;
|
|
92
|
+
scopes?: Array<string>;
|
|
93
|
+
apiKey?: string;
|
|
94
|
+
personalAccessKey?: string;
|
|
95
|
+
}
|
|
96
|
+
export interface FlatAccountFields_DEPRECATED extends CLIAccount_DEPRECATED {
|
|
97
|
+
tokenInfo?: TokenInfo;
|
|
98
|
+
clientId?: string;
|
|
99
|
+
clientSecret?: string;
|
|
100
|
+
scopes?: Array<string>;
|
|
101
|
+
apiKey?: string;
|
|
102
|
+
personalAccessKey?: string;
|
|
103
|
+
}
|
|
104
|
+
export type FlatAccountFields = FlatAccountFields_NEW | FlatAccountFields_DEPRECATED;
|
|
47
105
|
export type ScopeData = {
|
|
48
106
|
portalScopesInGroup: Array<string>;
|
|
49
107
|
userScopesInGroup: Array<string>;
|
|
@@ -79,6 +137,27 @@ export type EnabledFeaturesResponse = {
|
|
|
79
137
|
[key: string]: boolean;
|
|
80
138
|
};
|
|
81
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
|
+
};
|
|
82
161
|
export type AccessToken = {
|
|
83
162
|
portalId: number;
|
|
84
163
|
accessToken: string;
|
|
@@ -91,6 +170,17 @@ export type AccessToken = {
|
|
|
91
170
|
hubName: string;
|
|
92
171
|
accountType: ValueOf<typeof HUBSPOT_ACCOUNT_TYPES>;
|
|
93
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
|
+
};
|
|
94
184
|
export type WriteTokenInfoFunction = (tokenInfo: TokenInfo) => void;
|
|
95
185
|
export type RefreshTokenResponse = {
|
|
96
186
|
refresh_token: string;
|
|
@@ -103,4 +193,3 @@ export type ExchangeProof = {
|
|
|
103
193
|
client_secret?: string;
|
|
104
194
|
refresh_token?: string;
|
|
105
195
|
};
|
|
106
|
-
export {};
|
package/types/Config.d.ts
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
1
|
-
import { CONFIG_FLAGS } from '../constants/config';
|
|
2
1
|
import { ENVIRONMENTS } from '../constants/environments';
|
|
3
|
-
import {
|
|
2
|
+
import { CLIAccount_NEW, CLIAccount_DEPRECATED } from './Accounts';
|
|
4
3
|
import { CmsPublishMode } from './Files';
|
|
5
4
|
import { ValueOf } from './Utils';
|
|
6
|
-
export interface
|
|
7
|
-
accounts: Array<
|
|
5
|
+
export interface CLIConfig_NEW {
|
|
6
|
+
accounts: Array<CLIAccount_NEW>;
|
|
8
7
|
allowUsageTracking?: boolean;
|
|
9
|
-
defaultAccount?: number;
|
|
8
|
+
defaultAccount?: string | number;
|
|
9
|
+
defaultMode?: CmsPublishMode;
|
|
10
10
|
defaultCmsPublishMode?: CmsPublishMode;
|
|
11
11
|
httpTimeout?: number;
|
|
12
12
|
env?: Environment;
|
|
13
13
|
httpUseLocalhost?: boolean;
|
|
14
|
-
useCustomObjectHubfile?: boolean;
|
|
15
14
|
}
|
|
16
|
-
export
|
|
17
|
-
portals
|
|
18
|
-
|
|
15
|
+
export interface CLIConfig_DEPRECATED {
|
|
16
|
+
portals: Array<CLIAccount_DEPRECATED>;
|
|
17
|
+
allowUsageTracking?: boolean;
|
|
18
|
+
defaultPortal?: string | number;
|
|
19
19
|
defaultMode?: CmsPublishMode;
|
|
20
|
-
|
|
20
|
+
defaultCmsPublishMode?: CmsPublishMode;
|
|
21
|
+
httpTimeout?: number;
|
|
22
|
+
env?: Environment;
|
|
23
|
+
httpUseLocalhost?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export type CLIConfig = CLIConfig_NEW | CLIConfig_DEPRECATED;
|
|
21
26
|
export type Environment = ValueOf<typeof ENVIRONMENTS> | '';
|
|
27
|
+
export type EnvironmentConfigVariables = {
|
|
28
|
+
apiKey?: string;
|
|
29
|
+
clientId?: string;
|
|
30
|
+
clientSecret?: string;
|
|
31
|
+
personalAccessKey?: string;
|
|
32
|
+
accountId?: number;
|
|
33
|
+
refreshToken?: string;
|
|
34
|
+
env?: Environment;
|
|
35
|
+
};
|
|
22
36
|
export type GitInclusionResult = {
|
|
23
37
|
inGit: boolean;
|
|
24
38
|
configIgnored: boolean;
|
|
25
39
|
gitignoreFiles: Array<string>;
|
|
26
40
|
};
|
|
27
|
-
export type ConfigFlag = ValueOf<typeof CONFIG_FLAGS>;
|
package/types/Http.d.ts
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CLIAccount } from '../types/Accounts';
|
|
2
|
+
import { CLIConfig } from '../types/Config';
|
|
3
|
+
export declare function getAccounts(config?: CLIConfig | null): Array<CLIAccount>;
|
|
4
|
+
export declare function getDefaultAccount(config?: CLIConfig | null): string | number | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultAccount = exports.getAccounts = void 0;
|
|
4
|
+
function getAccounts(config) {
|
|
5
|
+
if (!config) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
else if (Object.hasOwn(config, 'portals')) {
|
|
9
|
+
return config.portals;
|
|
10
|
+
}
|
|
11
|
+
else if (Object.hasOwn(config, 'accounts')) {
|
|
12
|
+
return config.accounts;
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
exports.getAccounts = getAccounts;
|
|
17
|
+
function getDefaultAccount(config) {
|
|
18
|
+
if (!config) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
else if (Object.hasOwn(config, 'defaultPortal')) {
|
|
22
|
+
return config.defaultPortal;
|
|
23
|
+
}
|
|
24
|
+
else if (Object.hasOwn(config, 'defaultAccount')) {
|
|
25
|
+
return config.defaultAccount;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.getDefaultAccount = getDefaultAccount;
|
|
@@ -1,57 +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.getDefaultAccountOverrideFilePath = exports.getDefaultAccountOverrideAccountId = void 0;
|
|
7
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const path_1 = require("../lib/path");
|
|
10
|
-
const config_1 = require("../constants/config");
|
|
11
|
-
const lang_1 = require("../utils/lang");
|
|
12
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
13
|
-
const index_1 = require("./index");
|
|
14
|
-
const i18nKey = 'config.defaultAccountOverride';
|
|
15
|
-
function getDefaultAccountOverrideAccountId() {
|
|
16
|
-
const defaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath();
|
|
17
|
-
if (!defaultAccountOverrideFilePath) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
let source;
|
|
21
|
-
try {
|
|
22
|
-
source = fs_extra_1.default.readFileSync(defaultAccountOverrideFilePath, 'utf8');
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
throw new FileSystemError_1.FileSystemError({ cause: e }, {
|
|
26
|
-
filepath: defaultAccountOverrideFilePath,
|
|
27
|
-
operation: 'read',
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
const accountId = parseInt(source);
|
|
31
|
-
if (isNaN(accountId)) {
|
|
32
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.getDefaultAccountOverrideAccountId.errorHeader`, {
|
|
33
|
-
hsAccountFile: defaultAccountOverrideFilePath,
|
|
34
|
-
}), {
|
|
35
|
-
// TODO: This is improper use of cause, we should create a custom error class
|
|
36
|
-
cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
const accounts = (0, index_1.getAllConfigAccounts)();
|
|
40
|
-
const account = accounts?.find(account => account.accountId === accountId);
|
|
41
|
-
if (!account) {
|
|
42
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.getDefaultAccountOverrideAccountId.errorHeader`, {
|
|
43
|
-
hsAccountFile: defaultAccountOverrideFilePath,
|
|
44
|
-
}), {
|
|
45
|
-
// TODO: This is improper use of cause, we should create a custom error class
|
|
46
|
-
cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return account.accountId;
|
|
50
|
-
}
|
|
51
|
-
exports.getDefaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId;
|
|
52
|
-
function getDefaultAccountOverrideFilePath() {
|
|
53
|
-
return (0, findup_sync_1.default)([config_1.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME], {
|
|
54
|
-
cwd: (0, path_1.getCwd)(),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
exports.getDefaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath;
|