GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — org plan check and endpoints auto update in cli config · contentstack/cli@ab0efb9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .talismanrc
  • packages
    • contentstack-config
      • src
        • commands/config/set
          • region.ts
        • interfaces
          • index.ts
        • utils
          • region-handler.ts
      • test/unit/commands
        • region.test.ts
    • contentstack-utilities
      • package.json
      • src
        • feature-status
          • resolve-auth-host.ts
          • types.ts
        • index.ts
        • region-endpoints.ts
        • region-refresh.ts
      • test/unit
        • region-endpoints.test.ts
        • region-refresh.test.ts
        • resolve-auth-host.test.ts
    • contentstack
      • package.json
      • src/hooks
        • init
          • region-refresh.ts
        • prerun
          • plan-guard.ts
  • pnpm-lock.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.talismanrc‎

Copy file name to clipboard
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
3-
checksum: dd5f6ad633313054c21fa0e24645a25dca360f12f21b877472f514d848340ac6
3+
checksum: 6a2d0b32643423b7b3b5f3a5afab2db85f7cdd734c63128ddda5c7400065b83b
44
- filename: packages/contentstack-utilities/src/message-handler.ts
55
checksum: e7221e8413005b9efe3a230cd91aff130850976addc41c0acb10745a56ec3245
66
- filename: packages/contentstack-auth/src/commands/auth/tokens/list.ts
77
checksum: cff2456db5a6eb9c056096e5b08d4737ad4507386f9998f9182d3acab8be868d
88
- filename: packages/contentstack/README.md
99
checksum: 4aec6271d09ee38452460140b1d8da338df15c6ed765544246c00417d179dba5
10+
- filename: packages/contentstack-utilities/src/feature-status/build-auth-headers.ts
11+
checksum: 9360dfbce41aa9c8a62889f4821c37fc222b04b8b1c552d1dfbcd8f2854d49e0
12+
- filename: packages/contentstack/src/hooks/prerun/plan-guard.ts
13+
checksum: 74eeb5c98e9ae48bf6f2918e75a7cfca23915396ffdd177b8716acba35c287da
14+
- filename: packages/contentstack-config/src/utils/region-handler.ts
15+
checksum: 1dcf8b8991d172db535792116999f2ea98d8d529c64fa436088dbecdb4516fb9
16+
- filename: packages/contentstack-utilities/test/unit/region-endpoints.test.ts
17+
checksum: fe37fa11a72d154e6bfeef38a18039c68cf3cc4446183cb012596ad8c7ea5083
18+
- filename: packages/contentstack-config/test/unit/commands/region.test.ts
19+
checksum: 334e2a8c63338137cbf38b1fbabc73638b3ea1c30996318a1bd88392bf7687ed
20+
- filename: packages/contentstack-utilities/src/region-endpoints.ts
21+
checksum: 78902404db884ddc9ad812c4db3f410a52de2c895c2021733edc939d273030fb
22+
- filename: packages/contentstack-utilities/test/unit/resolve-auth-host.test.ts
23+
checksum: 19557d2905561d3dda94ebd68af342ecc646d2b5bbce3c1552bb9aea90f4bbbc
24+
- filename: packages/contentstack-utilities/test/unit/region-refresh.test.ts
25+
checksum: 1edac51f260df3ce28b538146e607d77742daed2364c25b4a922853b99f6d912
1026
version: '1.0'
Collapse file

‎packages/contentstack-config/src/commands/config/set/region.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-config/src/commands/config/set/region.ts
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,17 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
132132
launchHubUrl,
133133
composableStudioUrl,
134134
csAssetsUrl,
135-
authUrl,
135+
endpoints: {
136+
contentManagement: cma,
137+
contentDelivery: cda,
138+
application: uiHost,
139+
developerHub: developerHubUrl,
140+
launch: launchHubUrl,
141+
personalizeManagement: personalizeUrl,
142+
composableStudio: composableStudioUrl,
143+
assetManagement: csAssetsUrl,
144+
auth: authUrl,
145+
},
136146
};
137147
customRegion = regionHandler.setCustomRegion(customRegion);
138148
await authHandler.setConfigData('logout'); //Todo: Handle this logout flow well through logout command call
@@ -145,7 +155,7 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
145155
cliux.success(`Launch URL: ${customRegion.launchHubUrl}`);
146156
cliux.success(`Studio URL: ${customRegion.composableStudioUrl}`);
147157
cliux.success(`Contentstack Assets URL: ${customRegion.csAssetsUrl}`);
148-
cliux.success(`Auth API URL: ${customRegion.authUrl}`);
158+
cliux.success(`Auth API URL: ${customRegion.endpoints?.auth}`);
149159
} catch (error) {
150160
handleAndLogError(error, { ...this.contextDetails, module: 'config-set-region' });
151161
}
Collapse file

‎packages/contentstack-config/src/interfaces/index.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-config/src/interfaces/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface Region {
2020
launchHubUrl: string;
2121
composableStudioUrl: string;
2222
csAssetsUrl?: string;
23-
authUrl?: string;
23+
endpoints?: Record<string, string>;
2424
}
2525

2626
export interface Limit {
Collapse file

‎packages/contentstack-config/src/utils/region-handler.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-config/src/utils/region-handler.ts
+20-37Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { configHandler } from '@contentstack/cli-utilities';
2-
import { getContentstackEndpoint } from '@contentstack/utils';
1+
import { configHandler, resolveCanonicalEndpoints, buildRegionFromEndpoints } from '@contentstack/cli-utilities';
32
import { Region, RegionsMap } from '../interfaces';
43

54
function validURL(str) {
@@ -23,29 +22,10 @@ function validURL(str) {
2322
* @returns {object} Region object with all necessary URLs
2423
*/
2524
function getRegionObject(regionKey: string): Region {
26-
try {
27-
// getContentstackEndpoint handles all aliases defined in regions.json
28-
const endpoints = getContentstackEndpoint(regionKey) as any;
29-
30-
if (typeof endpoints === 'string') {
31-
throw new Error('Invalid endpoint response');
32-
}
33-
34-
return {
35-
name: regionKey,
36-
cma: endpoints.contentManagement,
37-
cda: endpoints.contentDelivery,
38-
uiHost: endpoints.application,
39-
developerHubUrl: endpoints.developerHub,
40-
launchHubUrl: endpoints.launch,
41-
personalizeUrl: endpoints.personalizeManagement,
42-
composableStudioUrl: endpoints.composableStudio,
43-
csAssetsUrl: endpoints.assetManagement,
44-
authUrl: endpoints.auth,
45-
};
46-
} catch {
47-
return null;
48-
}
25+
// resolveCanonicalEndpoints handles all aliases defined in regions.json
26+
const endpoints = resolveCanonicalEndpoints(regionKey);
27+
if (!endpoints) return null;
28+
return buildRegionFromEndpoints(regionKey, endpoints) as Region;
4929
}
5030

5131
/**
@@ -148,20 +128,23 @@ class UserConfig {
148128
* @returns { object } JSON object with only valid keys for region
149129
*/
150130
sanitizeRegionObject(regionObject) {
151-
const sanitizedRegion = {
152-
cma: regionObject.cma,
153-
cda: regionObject.cda,
154-
uiHost: regionObject.uiHost,
155-
name: regionObject.name,
156-
developerHubUrl: regionObject['developerHubUrl'],
157-
personalizeUrl: regionObject['personalizeUrl'],
158-
launchHubUrl: regionObject['launchHubUrl'],
159-
composableStudioUrl: regionObject['composableStudioUrl'],
160-
csAssetsUrl: regionObject['csAssetsUrl'],
161-
authUrl: regionObject['authUrl'],
131+
// endpoints is the single source of truth — every friendly field (cma, cda, ...,
132+
// auth, csAssetsUrl) is derived from it below via buildRegionFromEndpoints, same
133+
// as named regions. Falls back to synthesizing endpoints from the individual raw
134+
// fields when the caller didn't supply one directly.
135+
const endpoints = regionObject['endpoints'] ?? {
136+
contentManagement: regionObject.cma,
137+
contentDelivery: regionObject.cda,
138+
application: regionObject.uiHost,
139+
developerHub: regionObject['developerHubUrl'],
140+
launch: regionObject['launchHubUrl'],
141+
personalizeManagement: regionObject['personalizeUrl'],
142+
composableStudio: regionObject['composableStudioUrl'],
143+
assetManagement: regionObject['csAssetsUrl'],
144+
auth: regionObject['authUrl'],
162145
};
163146

164-
return sanitizedRegion;
147+
return buildRegionFromEndpoints(regionObject.name, endpoints);
165148
}
166149
}
167150

Collapse file

‎packages/contentstack-config/test/unit/commands/region.test.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-config/test/unit/commands/region.test.ts
+81-1Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,87 @@ describe('Region command', function () {
313313
csAssetsUrl: 'https://custom-asset-management.com',
314314
};
315315
const result = UserConfig.setCustomRegion(customRegion);
316-
expect(result).to.deep.equal(customRegion);
316+
expect(result.cma).to.equal(customRegion.cma);
317+
expect(result.cda).to.equal(customRegion.cda);
318+
expect(result.uiHost).to.equal(customRegion.uiHost);
319+
expect(result.name).to.equal(customRegion.name);
320+
expect(result.developerHubUrl).to.equal(customRegion.developerHubUrl);
321+
expect(result.personalizeUrl).to.equal(customRegion.personalizeUrl);
322+
expect(result.launchHubUrl).to.equal(customRegion.launchHubUrl);
323+
expect(result.composableStudioUrl).to.equal(customRegion.composableStudioUrl);
324+
});
325+
326+
it('should include a matching endpoints object for a custom region without an auth host', function () {
327+
const customRegion = {
328+
cma: 'https://custom-cma.com',
329+
cda: 'https://custom-cda.com',
330+
uiHost: 'https://custom-ui.com',
331+
name: 'Custom Region',
332+
developerHubUrl: 'https://custom-developer-hub.com',
333+
personalizeUrl: 'https://custom-personalize.com',
334+
launchHubUrl: 'https://custom-launch.com',
335+
composableStudioUrl: 'https://custom-composable-studio.com',
336+
};
337+
const result = UserConfig.setCustomRegion(customRegion);
338+
expect(result.endpoints).to.deep.equal({
339+
contentManagement: customRegion.cma,
340+
contentDelivery: customRegion.cda,
341+
application: customRegion.uiHost,
342+
developerHub: customRegion.developerHubUrl,
343+
launch: customRegion.launchHubUrl,
344+
personalizeManagement: customRegion.personalizeUrl,
345+
composableStudio: customRegion.composableStudioUrl,
346+
assetManagement: undefined,
347+
auth: undefined,
348+
});
349+
});
350+
351+
it('should preserve an explicitly supplied endpoints object for a custom region', function () {
352+
const endpoints = {
353+
contentManagement: 'https://custom-cma.com',
354+
contentDelivery: 'https://custom-cda.com',
355+
application: 'https://custom-ui.com',
356+
auth: 'https://custom-auth.com',
357+
};
358+
const customRegion = {
359+
cma: 'https://custom-cma.com',
360+
cda: 'https://custom-cda.com',
361+
uiHost: 'https://custom-ui.com',
362+
name: 'Custom Region',
363+
endpoints,
364+
};
365+
const result = UserConfig.setCustomRegion(customRegion);
366+
expect(result.cma).to.equal(endpoints.contentManagement);
367+
expect(result.cda).to.equal(endpoints.contentDelivery);
368+
expect(result.uiHost).to.equal(endpoints.application);
369+
expect(result.endpoints).to.deep.equal(endpoints);
370+
});
371+
372+
it('should not fall back to a stale legacy authUrl input once endpoints.auth is supplied', function () {
373+
// endpoints is the single source of truth: a stale/mismatched top-level
374+
// authUrl on the raw input is never used — only endpoints.auth matters.
375+
const customRegion = {
376+
cma: 'https://custom-cma.com',
377+
cda: 'https://custom-cda.com',
378+
uiHost: 'https://custom-ui.com',
379+
name: 'Custom Region',
380+
authUrl: 'https://stale-auth.com',
381+
endpoints: {
382+
contentManagement: 'https://custom-cma.com',
383+
contentDelivery: 'https://custom-cda.com',
384+
application: 'https://custom-ui.com',
385+
auth: 'https://correct-auth.com',
386+
},
387+
};
388+
const result = UserConfig.setCustomRegion(customRegion);
389+
expect(result.endpoints.auth).to.equal('https://correct-auth.com');
390+
});
391+
392+
it('should include the full endpoints passthrough (incl. auth) for named regions', function () {
393+
const result = UserConfig.setRegion('NA');
394+
expect(result.endpoints).to.be.an('object');
395+
expect(result.endpoints.auth).to.equal('https://auth-api.contentstack.com');
396+
expect(result.endpoints.contentManagement).to.equal(result.cma);
317397
});
318398

319399
it('should sanitize region object to only include valid properties', function () {
Collapse file

‎packages/contentstack-utilities/package.json‎

Copy file name to clipboardExpand all lines: packages/contentstack-utilities/package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"dependencies": {
3131
"@contentstack/management": "~1.30.3",
3232
"@contentstack/marketplace-sdk": "^1.5.2",
33+
"@contentstack/utils": "~1.9.1",
3334
"@oclif/core": "^4.11.4",
3435
"axios": "^1.16.1",
3536
"chalk": "^5.6.2",
Collapse file

‎packages/contentstack-utilities/src/feature-status/resolve-auth-host.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-utilities/src/feature-status/resolve-auth-host.ts
+23-3Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
import configHandler from '../config-handler';
22

3-
export function resolveAuthHost(ctx?: { region?: { authUrl?: string } }): string {
4-
const region = (ctx?.region ?? configHandler.get('region')) as { authUrl?: string } | undefined;
5-
const authUrl = region?.authUrl;
3+
// Mirrors config:set:region's own custom-region fallback (region.ts's transformUrl) —
4+
// same heuristic, applied retroactively for a custom region that predates auth-api.
5+
// Computed fresh on each call, never persisted back to config.
6+
function deriveAuthFromCma(cma: string): string {
7+
let transformed = cma.replace('api', 'auth-api');
8+
if (transformed.startsWith('http')) {
9+
transformed = transformed.split('//')[1];
10+
}
11+
transformed = transformed.replace(/^dev\d+/, 'dev');
12+
transformed = transformed.endsWith('io') ? transformed.replace('io', 'com') : transformed;
13+
return `https://${transformed}`;
14+
}
15+
16+
export function resolveAuthHost(ctx?: { region?: { endpoints?: { auth?: string }; cma?: string } }): string {
17+
const region = (ctx?.region ?? configHandler.get('region')) as
18+
| { endpoints?: { auth?: string }; cma?: string }
19+
| undefined;
20+
21+
let authUrl = region?.endpoints?.auth;
22+
if (!authUrl && region?.cma) {
23+
authUrl = deriveAuthFromCma(region.cma);
24+
}
25+
626
if (!authUrl) {
727
throw new Error(
828
'PLAN_CHECK: Auth host is not configured for the current region. ' +
Collapse file

‎packages/contentstack-utilities/src/feature-status/types.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-utilities/src/feature-status/types.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export interface FeatureCtx {
1212
orgUid?: string;
1313
managementToken?: string;
1414
authToken?: string;
15-
region?: { authUrl?: string; name?: string; cma?: string };
15+
region?: { name?: string; cma?: string; endpoints?: { auth?: string } };
1616
}
Collapse file

‎packages/contentstack-utilities/src/index.ts‎

Copy file name to clipboardExpand all lines: packages/contentstack-utilities/src/index.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,6 @@ export {
9191
DefaultProgressStrategy
9292
} from './progress-summary';
9393

94-
export * from './feature-status';
94+
export * from './feature-status';
95+
export * from './region-endpoints';
96+
export { refreshRegionEndpoints } from './region-refresh';
Collapse file

‎packages/contentstack-utilities/src/region-endpoints.ts‎

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { getContentstackEndpoint } from '@contentstack/utils';
2+
3+
export interface RegionEndpoints {
4+
[key: string]: string;
5+
}
6+
7+
export interface CanonicalRegion {
8+
name: string;
9+
cma: string;
10+
cda: string;
11+
uiHost: string;
12+
developerHubUrl: string;
13+
launchHubUrl: string;
14+
personalizeUrl: string;
15+
composableStudioUrl: string;
16+
csAssetsUrl?: string;
17+
endpoints: RegionEndpoints;
18+
}
19+
20+
/**
21+
* Resolve the canonical endpoint set for a region name/alias via @contentstack/utils.
22+
* Returns null when the name isn't a recognized region (e.g. a custom region name).
23+
*/
24+
export function resolveCanonicalEndpoints(name: string): RegionEndpoints | null {
25+
try {
26+
const endpoints = getContentstackEndpoint(name) as unknown;
27+
if (!endpoints || typeof endpoints === 'string') return null;
28+
return endpoints as RegionEndpoints;
29+
} catch {
30+
return null;
31+
}
32+
}
33+
34+
/**
35+
* Build a region object from a raw endpoints map, keeping the existing named
36+
* fields (cma/cda/uiHost/...) plus a full raw `endpoints` passthrough so any
37+
* future endpoint Contentstack adds is available without further code changes.
38+
*/
39+
export function buildRegionFromEndpoints(name: string, endpoints: RegionEndpoints): CanonicalRegion {
40+
return {
41+
name,
42+
cma: endpoints.contentManagement,
43+
cda: endpoints.contentDelivery,
44+
uiHost: endpoints.application,
45+
developerHubUrl: endpoints.developerHub,
46+
launchHubUrl: endpoints.launch,
47+
personalizeUrl: endpoints.personalizeManagement,
48+
composableStudioUrl: endpoints.composableStudio,
49+
csAssetsUrl: endpoints.assetManagement,
50+
endpoints,
51+
};
52+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.