@contentstack/cli-utilities 1.18.5 → 1.19.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/lib/feature-status/build-auth-headers.d.ts +9 -0
- package/lib/feature-status/build-auth-headers.js +33 -0
- package/lib/feature-status/feature-status-handler.d.ts +3 -0
- package/lib/feature-status/feature-status-handler.js +37 -0
- package/lib/feature-status/feature-uids.d.ts +5 -0
- package/lib/feature-status/feature-uids.js +7 -0
- package/lib/feature-status/index.d.ts +5 -0
- package/lib/feature-status/index.js +13 -0
- package/lib/feature-status/resolve-auth-host.d.ts +8 -0
- package/lib/feature-status/resolve-auth-host.js +31 -0
- package/lib/feature-status/types.d.ts +21 -0
- package/lib/feature-status/types.js +2 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -1
- package/lib/region-endpoints.d.ts +25 -0
- package/lib/region-endpoints.js +39 -0
- package/lib/region-refresh.d.ts +9 -0
- package/lib/region-refresh.js +27 -0
- package/package.json +3 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAuthHeaders = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const config_handler_1 = tslib_1.__importDefault(require("../config-handler"));
|
|
6
|
+
function buildAuthHeaders(ctx) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
// 1. Management token takes priority (no 'Bearer' prefix — API contract)
|
|
9
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.managementToken) && (ctx === null || ctx === void 0 ? void 0 : ctx.apiKey)) {
|
|
10
|
+
return {
|
|
11
|
+
Authorization: ctx.managementToken,
|
|
12
|
+
api_key: ctx.apiKey,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
// 2. OAuth
|
|
16
|
+
const oauthToken = config_handler_1.default.get('oauthAccessToken');
|
|
17
|
+
if (oauthToken) {
|
|
18
|
+
return { Authorization: `Bearer ${oauthToken}` };
|
|
19
|
+
}
|
|
20
|
+
// 3. Authtoken + organization_uid
|
|
21
|
+
const authtoken = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.authToken) !== null && _a !== void 0 ? _a : config_handler_1.default.get('authtoken');
|
|
22
|
+
const orgUid = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.orgUid) !== null && _b !== void 0 ? _b : config_handler_1.default.get('oauthOrgUid');
|
|
23
|
+
if (authtoken && orgUid) {
|
|
24
|
+
return { authtoken, organization_uid: orgUid };
|
|
25
|
+
}
|
|
26
|
+
// 4. Authtoken + api_key
|
|
27
|
+
if (authtoken && (ctx === null || ctx === void 0 ? void 0 : ctx.apiKey)) {
|
|
28
|
+
return { authtoken, api_key: ctx.apiKey };
|
|
29
|
+
}
|
|
30
|
+
throw new Error('PLAN_CHECK: Cannot build auth headers — no valid credentials available. ' +
|
|
31
|
+
'Please log in or provide a management token alias.');
|
|
32
|
+
}
|
|
33
|
+
exports.buildAuthHeaders = buildAuthHeaders;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertFeatureEnabled = exports.isFeatureEnabled = void 0;
|
|
4
|
+
const http_client_1 = require("../http-client");
|
|
5
|
+
const resolve_auth_host_1 = require("./resolve-auth-host");
|
|
6
|
+
const build_auth_headers_1 = require("./build-auth-headers");
|
|
7
|
+
async function isFeatureEnabled(featureUid, ctx) {
|
|
8
|
+
const host = (0, resolve_auth_host_1.resolveAuthHost)(ctx);
|
|
9
|
+
const headers = (0, build_auth_headers_1.buildAuthHeaders)(ctx);
|
|
10
|
+
const client = new http_client_1.HttpClient();
|
|
11
|
+
client.baseUrl(host).headers(headers);
|
|
12
|
+
const res = await client.get(`/v1/feature-status?feature_uid=${encodeURIComponent(featureUid)}`);
|
|
13
|
+
if (res.status < 200 || res.status >= 300) {
|
|
14
|
+
throw new Error(`PLAN_CHECK: feature-status API returned ${res.status} for "${featureUid}".`);
|
|
15
|
+
}
|
|
16
|
+
return res.data;
|
|
17
|
+
}
|
|
18
|
+
exports.isFeatureEnabled = isFeatureEnabled;
|
|
19
|
+
async function assertFeatureEnabled(featureUid, ctx) {
|
|
20
|
+
let status;
|
|
21
|
+
try {
|
|
22
|
+
status = await isFeatureEnabled(featureUid, ctx);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw new Error(`Could not verify your plan for "${featureUid}". ` +
|
|
26
|
+
`This command requires a confirmed plan status to run. ` +
|
|
27
|
+
`Please retry; if the problem persists contact support. (${e.message})`);
|
|
28
|
+
}
|
|
29
|
+
if (!status.is_part_of_plan) {
|
|
30
|
+
throw new Error(`"${featureUid}" is not part of your current plan. Please upgrade your plan to use this feature.`);
|
|
31
|
+
}
|
|
32
|
+
if (status.status !== 'enabled') {
|
|
33
|
+
throw new Error(`"${featureUid}" is not enabled for your plan (status: ${status.status}).`);
|
|
34
|
+
}
|
|
35
|
+
return status;
|
|
36
|
+
}
|
|
37
|
+
exports.assertFeatureEnabled = assertFeatureEnabled;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertFeatureEnabled = exports.isFeatureEnabled = exports.buildAuthHeaders = exports.resolveAuthHost = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./feature-uids"), exports);
|
|
7
|
+
var resolve_auth_host_1 = require("./resolve-auth-host");
|
|
8
|
+
Object.defineProperty(exports, "resolveAuthHost", { enumerable: true, get: function () { return resolve_auth_host_1.resolveAuthHost; } });
|
|
9
|
+
var build_auth_headers_1 = require("./build-auth-headers");
|
|
10
|
+
Object.defineProperty(exports, "buildAuthHeaders", { enumerable: true, get: function () { return build_auth_headers_1.buildAuthHeaders; } });
|
|
11
|
+
var feature_status_handler_1 = require("./feature-status-handler");
|
|
12
|
+
Object.defineProperty(exports, "isFeatureEnabled", { enumerable: true, get: function () { return feature_status_handler_1.isFeatureEnabled; } });
|
|
13
|
+
Object.defineProperty(exports, "assertFeatureEnabled", { enumerable: true, get: function () { return feature_status_handler_1.assertFeatureEnabled; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAuthHost = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const config_handler_1 = tslib_1.__importDefault(require("../config-handler"));
|
|
6
|
+
// Mirrors config:set:region's own custom-region fallback (region.ts's transformUrl) —
|
|
7
|
+
// same heuristic, applied retroactively for a custom region that predates auth-api.
|
|
8
|
+
// Computed fresh on each call, never persisted back to config.
|
|
9
|
+
function deriveAuthFromCma(cma) {
|
|
10
|
+
let transformed = cma.replace('api', 'auth-api');
|
|
11
|
+
if (transformed.startsWith('http')) {
|
|
12
|
+
transformed = transformed.split('//')[1];
|
|
13
|
+
}
|
|
14
|
+
transformed = transformed.replace(/^dev\d+/, 'dev');
|
|
15
|
+
transformed = transformed.endsWith('io') ? transformed.replace('io', 'com') : transformed;
|
|
16
|
+
return `https://${transformed}`;
|
|
17
|
+
}
|
|
18
|
+
function resolveAuthHost(ctx) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const region = ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.region) !== null && _a !== void 0 ? _a : config_handler_1.default.get('region'));
|
|
21
|
+
let authUrl = (_b = region === null || region === void 0 ? void 0 : region.endpoints) === null || _b === void 0 ? void 0 : _b.auth;
|
|
22
|
+
if (!authUrl && (region === null || region === void 0 ? void 0 : region.cma)) {
|
|
23
|
+
authUrl = deriveAuthFromCma(region.cma);
|
|
24
|
+
}
|
|
25
|
+
if (!authUrl) {
|
|
26
|
+
throw new Error('PLAN_CHECK: Auth host is not configured for the current region. ' +
|
|
27
|
+
"Re-run `csdx config:set:region` to refresh region endpoints.");
|
|
28
|
+
}
|
|
29
|
+
return String(authUrl).replace(/\/$/, '');
|
|
30
|
+
}
|
|
31
|
+
exports.resolveAuthHost = resolveAuthHost;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface FeatureStatus {
|
|
2
|
+
org_uid: string;
|
|
3
|
+
feature_key: string;
|
|
4
|
+
status: 'enabled' | 'disabled' | string;
|
|
5
|
+
limit: number;
|
|
6
|
+
max_limit: number;
|
|
7
|
+
is_part_of_plan: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FeatureCtx {
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
orgUid?: string;
|
|
12
|
+
managementToken?: string;
|
|
13
|
+
authToken?: string;
|
|
14
|
+
region?: {
|
|
15
|
+
name?: string;
|
|
16
|
+
cma?: string;
|
|
17
|
+
endpoints?: {
|
|
18
|
+
auth?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -27,3 +27,6 @@ export { default as TablePrompt } from './inquirer-table-prompt';
|
|
|
27
27
|
export { Logger };
|
|
28
28
|
export { default as authenticationHandler } from './authentication-handler';
|
|
29
29
|
export { v2Logger as log, cliErrorHandler, handleAndLogError, getLogPath } from './logger/log';
|
|
30
|
+
export * from './feature-status';
|
|
31
|
+
export * from './region-endpoints';
|
|
32
|
+
export { refreshRegionEndpoints } from './region-refresh';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLogPath = exports.handleAndLogError = exports.cliErrorHandler = exports.log = exports.authenticationHandler = exports.Logger = exports.TablePrompt = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.marketplaceSDKInitiator = exports.MarketplaceSDKInitiator = exports.marketplaceSDKClient = exports.CLITable = exports.createLogContext = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.LoggerService = void 0;
|
|
3
|
+
exports.refreshRegionEndpoints = exports.getLogPath = exports.handleAndLogError = exports.cliErrorHandler = exports.log = exports.authenticationHandler = exports.Logger = exports.TablePrompt = exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Args = exports.marketplaceSDKInitiator = exports.MarketplaceSDKInitiator = exports.marketplaceSDKClient = exports.CLITable = exports.createLogContext = exports.Command = exports.flags = exports.args = exports.NodeCrypto = exports.printFlagDeprecation = exports.managementSDKInitiator = exports.managementSDKClient = exports.configHandler = exports.authHandler = exports.messageHandler = exports.CLIError = exports.cliux = exports.LoggerService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const logger_1 = tslib_1.__importDefault(require("./logger"));
|
|
6
6
|
exports.Logger = logger_1.default;
|
|
@@ -72,3 +72,7 @@ Object.defineProperty(exports, "log", { enumerable: true, get: function () { ret
|
|
|
72
72
|
Object.defineProperty(exports, "cliErrorHandler", { enumerable: true, get: function () { return log_1.cliErrorHandler; } });
|
|
73
73
|
Object.defineProperty(exports, "handleAndLogError", { enumerable: true, get: function () { return log_1.handleAndLogError; } });
|
|
74
74
|
Object.defineProperty(exports, "getLogPath", { enumerable: true, get: function () { return log_1.getLogPath; } });
|
|
75
|
+
tslib_1.__exportStar(require("./feature-status"), exports);
|
|
76
|
+
tslib_1.__exportStar(require("./region-endpoints"), exports);
|
|
77
|
+
var region_refresh_1 = require("./region-refresh");
|
|
78
|
+
Object.defineProperty(exports, "refreshRegionEndpoints", { enumerable: true, get: function () { return region_refresh_1.refreshRegionEndpoints; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface RegionEndpoints {
|
|
2
|
+
[key: string]: string;
|
|
3
|
+
}
|
|
4
|
+
export interface CanonicalRegion {
|
|
5
|
+
name: string;
|
|
6
|
+
cma: string;
|
|
7
|
+
cda: string;
|
|
8
|
+
uiHost: string;
|
|
9
|
+
developerHubUrl: string;
|
|
10
|
+
launchHubUrl: string;
|
|
11
|
+
personalizeUrl: string;
|
|
12
|
+
composableStudioUrl: string;
|
|
13
|
+
endpoints: RegionEndpoints;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolve the canonical endpoint set for a region name/alias via @contentstack/utils.
|
|
17
|
+
* Returns null when the name isn't a recognized region (e.g. a custom region name).
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveCanonicalEndpoints(name: string): RegionEndpoints | null;
|
|
20
|
+
/**
|
|
21
|
+
* Build a region object from a raw endpoints map, keeping the existing named
|
|
22
|
+
* fields (cma/cda/uiHost/...) plus a full raw `endpoints` passthrough so any
|
|
23
|
+
* future endpoint Contentstack adds is available without further code changes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildRegionFromEndpoints(name: string, endpoints: RegionEndpoints): CanonicalRegion;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRegionFromEndpoints = exports.resolveCanonicalEndpoints = void 0;
|
|
4
|
+
const utils_1 = require("@contentstack/utils");
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the canonical endpoint set for a region name/alias via @contentstack/utils.
|
|
7
|
+
* Returns null when the name isn't a recognized region (e.g. a custom region name).
|
|
8
|
+
*/
|
|
9
|
+
function resolveCanonicalEndpoints(name) {
|
|
10
|
+
try {
|
|
11
|
+
const endpoints = (0, utils_1.getContentstackEndpoint)(name);
|
|
12
|
+
if (!endpoints || typeof endpoints === 'string')
|
|
13
|
+
return null;
|
|
14
|
+
return endpoints;
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.resolveCanonicalEndpoints = resolveCanonicalEndpoints;
|
|
21
|
+
/**
|
|
22
|
+
* Build a region object from a raw endpoints map, keeping the existing named
|
|
23
|
+
* fields (cma/cda/uiHost/...) plus a full raw `endpoints` passthrough so any
|
|
24
|
+
* future endpoint Contentstack adds is available without further code changes.
|
|
25
|
+
*/
|
|
26
|
+
function buildRegionFromEndpoints(name, endpoints) {
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
cma: endpoints.contentManagement,
|
|
30
|
+
cda: endpoints.contentDelivery,
|
|
31
|
+
uiHost: endpoints.application,
|
|
32
|
+
developerHubUrl: endpoints.developerHub,
|
|
33
|
+
launchHubUrl: endpoints.launch,
|
|
34
|
+
personalizeUrl: endpoints.personalizeManagement,
|
|
35
|
+
composableStudioUrl: endpoints.composableStudio,
|
|
36
|
+
endpoints,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.buildRegionFromEndpoints = buildRegionFromEndpoints;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-heals the persisted region config on every CLI invocation so that
|
|
3
|
+
* customers who set their region on an older CLI version (before a field
|
|
4
|
+
* like authUrl existed) get it backfilled without re-running
|
|
5
|
+
* `csdx config:set:region`. Only named/built-in regions are touched — a
|
|
6
|
+
* custom region's name won't resolve via resolveCanonicalEndpoints, so it's
|
|
7
|
+
* left untouched. Never throws.
|
|
8
|
+
*/
|
|
9
|
+
export declare function refreshRegionEndpoints(): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refreshRegionEndpoints = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const config_handler_1 = tslib_1.__importDefault(require("./config-handler"));
|
|
6
|
+
const region_endpoints_1 = require("./region-endpoints");
|
|
7
|
+
/**
|
|
8
|
+
* Self-heals the persisted region config on every CLI invocation so that
|
|
9
|
+
* customers who set their region on an older CLI version (before a field
|
|
10
|
+
* like authUrl existed) get it backfilled without re-running
|
|
11
|
+
* `csdx config:set:region`. Only named/built-in regions are touched — a
|
|
12
|
+
* custom region's name won't resolve via resolveCanonicalEndpoints, so it's
|
|
13
|
+
* left untouched. Never throws.
|
|
14
|
+
*/
|
|
15
|
+
function refreshRegionEndpoints() {
|
|
16
|
+
const stored = config_handler_1.default.get('region');
|
|
17
|
+
if (!(stored === null || stored === void 0 ? void 0 : stored.name))
|
|
18
|
+
return;
|
|
19
|
+
const endpoints = (0, region_endpoints_1.resolveCanonicalEndpoints)(stored.name);
|
|
20
|
+
if (!endpoints)
|
|
21
|
+
return;
|
|
22
|
+
const merged = Object.assign(Object.assign({}, stored), (0, region_endpoints_1.buildRegionFromEndpoints)(stored.name, endpoints));
|
|
23
|
+
if (JSON.stringify(merged) !== JSON.stringify(stored)) {
|
|
24
|
+
config_handler_1.default.set('region', merged);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.refreshRegionEndpoints = refreshRegionEndpoints;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-utilities",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Utilities for contentstack projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@contentstack/management": "~1.30.1",
|
|
31
31
|
"@contentstack/marketplace-sdk": "^1.5.1",
|
|
32
|
+
"@contentstack/utils": "~1.9.1",
|
|
32
33
|
"@oclif/core": "^4.11.4",
|
|
33
34
|
"axios": "^1.16.1",
|
|
34
35
|
"chalk": "^4.1.2",
|
|
@@ -82,4 +83,4 @@
|
|
|
82
83
|
"ts-node": "^10.9.2",
|
|
83
84
|
"typescript": "^4.9.5"
|
|
84
85
|
}
|
|
85
|
-
}
|
|
86
|
+
}
|