@webex/webex-core 3.12.0-webex-services-ready.4 → 3.13.0-next.1
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/.repo-context.json +653 -0
- package/.sdd/manifest.json +605 -0
- package/AGENTS.md +209 -0
- package/dist/config.js +30 -0
- package/dist/config.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/interceptors/catalog-url.js +87 -0
- package/dist/interceptors/catalog-url.js.map +1 -0
- package/dist/interceptors/payload-transformer.js +25 -4
- package/dist/interceptors/payload-transformer.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +56 -1
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/services/service-catalog.js +102 -8
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +84 -48
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/service-catalog.js +8 -1
- package/dist/lib/services-v2/service-catalog.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +90 -50
- package/dist/lib/services-v2/services-v2.js.map +1 -1
- package/dist/lib/static-asset-loader.js +153 -0
- package/dist/lib/static-asset-loader.js.map +1 -0
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +11 -3
- package/dist/webex-core.js.map +1 -1
- package/docs/adr/index.md +32 -0
- package/docs/architecture.md +298 -0
- package/docs/getting-started.md +96 -0
- package/docs/index.md +55 -0
- package/docs/specs/README.md +76 -0
- package/package.json +13 -13
- package/schemas/repo-context.schema.json +796 -0
- package/src/config.js +32 -0
- package/src/docs/README.md +732 -0
- package/src/index.js +2 -0
- package/src/interceptors/catalog-url.js +66 -0
- package/src/interceptors/docs/README.md +658 -0
- package/src/interceptors/payload-transformer.js +23 -1
- package/src/lib/credentials/credentials.js +43 -0
- package/src/lib/credentials/docs/README.md +846 -0
- package/src/lib/services/docs/README.md +737 -0
- package/src/lib/services/service-catalog.js +106 -6
- package/src/lib/services/services.js +77 -32
- package/src/lib/services-v2/docs/README.md +751 -0
- package/src/lib/services-v2/service-catalog.ts +10 -1
- package/src/lib/services-v2/services-v2.ts +86 -33
- package/src/lib/static-asset-loader.ts +128 -0
- package/src/lib/storage/docs/README.md +646 -0
- package/src/webex-core.js +8 -0
- package/test/integration/spec/services/services.js +148 -113
- package/test/integration/spec/services-v2/services-v2.js +134 -99
- package/test/unit/spec/credentials/credentials.js +114 -1
- package/test/unit/spec/interceptors/catalog-url.js +224 -0
- package/test/unit/spec/interceptors/payload-transformer.js +119 -1
- package/test/unit/spec/services/service-catalog.js +275 -0
- package/test/unit/spec/services/services.js +161 -2
- package/test/unit/spec/services-v2/service-catalog.ts +41 -0
- package/test/unit/spec/services-v2/services-v2.ts +279 -2
- package/test/unit/spec/static-asset-loader.ts +224 -0
- package/test/unit/spec/webex-core.js +77 -1
|
@@ -6,6 +6,99 @@ import {union} from 'lodash';
|
|
|
6
6
|
import ServiceUrl from './service-url';
|
|
7
7
|
import {matchAllowedDomain, normalizeAllowedDomains} from '../domains';
|
|
8
8
|
|
|
9
|
+
// Catalog base URLs are a small, stable set, so their parsed origin/path is
|
|
10
|
+
// memoized to avoid repeated `new URL()` work when scanning the catalog on the
|
|
11
|
+
// request hot path.
|
|
12
|
+
const catalogUrlCache = new Map();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parse a catalog URL into the origin and normalized path used for matching,
|
|
16
|
+
* memoizing the result. Returns null when the URL is unparsable.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} catalogUrlString - The catalog URL to parse
|
|
19
|
+
* @returns {{origin: string, path: string} | null} - Parsed catalog URL, or null
|
|
20
|
+
*/
|
|
21
|
+
export function parseCatalogUrl(catalogUrlString) {
|
|
22
|
+
if (catalogUrlCache.has(catalogUrlString)) {
|
|
23
|
+
return catalogUrlCache.get(catalogUrlString);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let parsed = null;
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const catalogUrl = new URL(catalogUrlString);
|
|
30
|
+
|
|
31
|
+
// Normalize paths by removing trailing slashes (except root "/")
|
|
32
|
+
parsed = {origin: catalogUrl.origin, path: catalogUrl.pathname.replace(/\/$/, '') || '/'};
|
|
33
|
+
} catch {
|
|
34
|
+
parsed = null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
catalogUrlCache.set(catalogUrlString, parsed);
|
|
38
|
+
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Check if an already-parsed candidate URL matches a parsed catalog URL with
|
|
44
|
+
* proper origin validation. Allocates nothing, so it is safe to call in a tight
|
|
45
|
+
* loop over the whole catalog.
|
|
46
|
+
*
|
|
47
|
+
* @param {URL} candidateUrl - The parsed candidate URL to validate
|
|
48
|
+
* @param {{origin: string, path: string} | null} parsedCatalogUrl - The parsed catalog URL
|
|
49
|
+
* @returns {boolean} - True if the candidate URL is under the catalog URL's origin and path
|
|
50
|
+
*/
|
|
51
|
+
export function matchesParsedCatalogUrl(candidateUrl, parsedCatalogUrl) {
|
|
52
|
+
if (!candidateUrl || !parsedCatalogUrl) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Origins must match exactly (scheme + host + port)
|
|
57
|
+
if (candidateUrl.origin !== parsedCatalogUrl.origin) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const catalogPath = parsedCatalogUrl.path;
|
|
62
|
+
|
|
63
|
+
if (catalogPath === '/') {
|
|
64
|
+
// Root path matches everything under this origin
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const candidatePath = candidateUrl.pathname;
|
|
69
|
+
|
|
70
|
+
if (candidatePath.startsWith(catalogPath)) {
|
|
71
|
+
// Ensure we're at a path boundary, not mid-segment
|
|
72
|
+
// e.g., /api/v1 should match /api/v1/foo but not /api/v1extra
|
|
73
|
+
// nextChar is undefined for exact match, '/' for valid extension
|
|
74
|
+
const nextChar = candidatePath[catalogPath.length];
|
|
75
|
+
|
|
76
|
+
return nextChar === '/' || nextChar === undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Check if a candidate URL matches a catalog URL with proper origin validation.
|
|
84
|
+
* This prevents bypasses like https://trusted.example.attacker.com matching https://trusted.example
|
|
85
|
+
*
|
|
86
|
+
* @param {string} candidateUrlString - The URL to validate
|
|
87
|
+
* @param {string} catalogUrlString - The catalog URL to compare against
|
|
88
|
+
* @returns {boolean} - True if the candidate URL is under the catalog URL's origin and path
|
|
89
|
+
*/
|
|
90
|
+
export function matchesCatalogUrl(candidateUrlString, catalogUrlString) {
|
|
91
|
+
let candidateUrl;
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
candidateUrl = new URL(candidateUrlString);
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return matchesParsedCatalogUrl(candidateUrl, parseCatalogUrl(catalogUrlString));
|
|
100
|
+
}
|
|
101
|
+
|
|
9
102
|
/* eslint-disable no-underscore-dangle */
|
|
10
103
|
/**
|
|
11
104
|
* @class
|
|
@@ -246,20 +339,27 @@ const ServiceCatalog = AmpState.extend({
|
|
|
246
339
|
...this.serviceGroups.override,
|
|
247
340
|
];
|
|
248
341
|
|
|
342
|
+
// Invalid URLs cannot match any service
|
|
343
|
+
let candidateUrl;
|
|
344
|
+
|
|
345
|
+
try {
|
|
346
|
+
candidateUrl = new URL(url);
|
|
347
|
+
} catch {
|
|
348
|
+
return undefined;
|
|
349
|
+
}
|
|
350
|
+
|
|
249
351
|
return serviceUrls.find((serviceUrl) => {
|
|
250
|
-
// Check
|
|
251
|
-
if (
|
|
352
|
+
// Check if the URL matches the default URL with proper origin validation
|
|
353
|
+
if (matchesParsedCatalogUrl(candidateUrl, parseCatalogUrl(serviceUrl.defaultUrl))) {
|
|
252
354
|
return true;
|
|
253
355
|
}
|
|
254
356
|
|
|
255
|
-
//
|
|
256
|
-
// These are made by swapping the host of the default URL
|
|
257
|
-
// with that of an alternate host
|
|
357
|
+
// Check alternate URLs (built by swapping host with alternate hosts)
|
|
258
358
|
for (const host of serviceUrl.hosts) {
|
|
259
359
|
const alternateUrl = new URL(serviceUrl.defaultUrl);
|
|
260
360
|
alternateUrl.host = host.host;
|
|
261
361
|
|
|
262
|
-
if (
|
|
362
|
+
if (matchesParsedCatalogUrl(candidateUrl, parseCatalogUrl(alternateUrl.toString()))) {
|
|
263
363
|
return true;
|
|
264
364
|
}
|
|
265
365
|
}
|
|
@@ -261,13 +261,23 @@ const Services = WebexPlugin.extend({
|
|
|
261
261
|
},
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
|
-
* Checks if the current environment is an integration (INT) environment
|
|
265
|
-
*
|
|
264
|
+
* Checks if the current environment is an integration (INT) environment.
|
|
265
|
+
* Uses the explicit environment config when set, otherwise examines the u2c discovery URL.
|
|
266
266
|
* INT environments use discovery URLs containing 'intb' (e.g., u2c-intb.ciscospark.com).
|
|
267
267
|
* @returns {boolean} True if INT environment, false otherwise
|
|
268
268
|
*/
|
|
269
269
|
isIntegrationEnvironment() {
|
|
270
270
|
try {
|
|
271
|
+
const configuredEnvironment = this.webex?.config?.environment;
|
|
272
|
+
|
|
273
|
+
if (configuredEnvironment !== undefined) {
|
|
274
|
+
const isIntFromConfig = configuredEnvironment === 'integration';
|
|
275
|
+
|
|
276
|
+
this.logger.info(`services: isIntegrationEnvironment: ${isIntFromConfig} (config)`);
|
|
277
|
+
|
|
278
|
+
return isIntFromConfig;
|
|
279
|
+
}
|
|
280
|
+
|
|
271
281
|
const u2cUrl = this.webex?.config?.services?.discovery?.u2c || '';
|
|
272
282
|
const isInt = u2cUrl.includes('intb');
|
|
273
283
|
|
|
@@ -1103,9 +1113,16 @@ const Services = WebexPlugin.extend({
|
|
|
1103
1113
|
requestObject.headers = {authorization: token};
|
|
1104
1114
|
}
|
|
1105
1115
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1116
|
+
const sendRequest = () => this.request(requestObject);
|
|
1117
|
+
|
|
1118
|
+
const responsePromise = this.webex.internal.newMetrics
|
|
1119
|
+
? this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(
|
|
1120
|
+
sendRequest,
|
|
1121
|
+
'internal.get.u2c.time'
|
|
1122
|
+
)
|
|
1123
|
+
: sendRequest();
|
|
1124
|
+
|
|
1125
|
+
return responsePromise.then(({body}) => body);
|
|
1109
1126
|
},
|
|
1110
1127
|
|
|
1111
1128
|
/**
|
|
@@ -1418,6 +1435,28 @@ const Services = WebexPlugin.extend({
|
|
|
1418
1435
|
this.ready = true;
|
|
1419
1436
|
},
|
|
1420
1437
|
|
|
1438
|
+
/**
|
|
1439
|
+
* Build a promise that rejects once the catalog init timeout elapses. Race
|
|
1440
|
+
* this against catalog collection so a hung request never leaves
|
|
1441
|
+
* `services.ready` false forever - that would stall `webex.ready` and leave
|
|
1442
|
+
* consumers waiting on it indefinitely. Timeout is configurable via
|
|
1443
|
+
* `config.services.catalogInitTimeout` (defaults to 15s in config). Created
|
|
1444
|
+
* lazily so paths that skip catalog collection never schedule a stray timer.
|
|
1445
|
+
*
|
|
1446
|
+
* @private
|
|
1447
|
+
* @returns {Promise<never>}
|
|
1448
|
+
*/
|
|
1449
|
+
_makeInitTimeout() {
|
|
1450
|
+
const initTimeoutMs = this.webex.config?.services?.catalogInitTimeout;
|
|
1451
|
+
|
|
1452
|
+
return new Promise((_, reject) => {
|
|
1453
|
+
setTimeout(
|
|
1454
|
+
() => reject(new Error(`services: init timed out after ${initTimeoutMs}ms`)),
|
|
1455
|
+
initTimeoutMs
|
|
1456
|
+
);
|
|
1457
|
+
});
|
|
1458
|
+
},
|
|
1459
|
+
|
|
1421
1460
|
/**
|
|
1422
1461
|
* Initializer
|
|
1423
1462
|
*
|
|
@@ -1492,6 +1531,14 @@ const Services = WebexPlugin.extend({
|
|
|
1492
1531
|
} else {
|
|
1493
1532
|
const {email} = this.webex.config;
|
|
1494
1533
|
|
|
1534
|
+
if (this.webex.config?.services?.skipPreauthCatalogOnUnauthenticated === true) {
|
|
1535
|
+
this.logger.info(
|
|
1536
|
+
'services: skipping preauth catalog collection while unauthenticated as per the config'
|
|
1537
|
+
);
|
|
1538
|
+
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1495
1542
|
this.collectPreauthCatalog(email ? {email} : undefined).catch((error) => {
|
|
1496
1543
|
this.initFailed = true;
|
|
1497
1544
|
this.logger.error(
|
|
@@ -1526,25 +1573,12 @@ const Services = WebexPlugin.extend({
|
|
|
1526
1573
|
}
|
|
1527
1574
|
const {supertoken} = this.webex.credentials;
|
|
1528
1575
|
|
|
1529
|
-
// Race init against a hard timeout so a hung request never leaves
|
|
1530
|
-
// `services.ready` false forever - that would stall `webex.ready` and
|
|
1531
|
-
// leave consumers waiting on it indefinitely. Timeout is configurable via
|
|
1532
|
-
// `config.services.catalogInitTimeout` (defaults to 15s in config).
|
|
1533
|
-
const initTimeoutMs = this.webex.config?.services?.catalogInitTimeout;
|
|
1534
|
-
|
|
1535
|
-
const initServiceCatalogsTimeout = new Promise((_, reject) => {
|
|
1536
|
-
setTimeout(
|
|
1537
|
-
() => reject(new Error(`services: init timed out after ${initTimeoutMs}ms`)),
|
|
1538
|
-
initTimeoutMs
|
|
1539
|
-
);
|
|
1540
|
-
});
|
|
1541
|
-
|
|
1542
1576
|
// Validate if the supertoken exists.
|
|
1543
1577
|
if (supertoken && supertoken.access_token) {
|
|
1544
1578
|
// `initServiceCatalogs` marks the catalog ready internally once the
|
|
1545
1579
|
// postauth catalog is collected - even if it loses the timeout race
|
|
1546
|
-
//
|
|
1547
|
-
Promise.race([this.initServiceCatalogs(),
|
|
1580
|
+
// below, so a slow fetch still eventually flips `catalog.isReady`.
|
|
1581
|
+
Promise.race([this.initServiceCatalogs(), this._makeInitTimeout()])
|
|
1548
1582
|
.catch((error) => {
|
|
1549
1583
|
this.initFailed = true;
|
|
1550
1584
|
this.logger.error(
|
|
@@ -1555,18 +1589,6 @@ const Services = WebexPlugin.extend({
|
|
|
1555
1589
|
} else {
|
|
1556
1590
|
const {email} = this.webex.config;
|
|
1557
1591
|
|
|
1558
|
-
Promise.race([
|
|
1559
|
-
this.collectPreauthCatalog(email ? {email} : undefined),
|
|
1560
|
-
initServiceCatalogsTimeout,
|
|
1561
|
-
])
|
|
1562
|
-
.catch((error) => {
|
|
1563
|
-
this.initFailed = true;
|
|
1564
|
-
this.logger.error(
|
|
1565
|
-
`services: failed to init initial services when no credentials available, ${error?.message}`
|
|
1566
|
-
);
|
|
1567
|
-
})
|
|
1568
|
-
.finally(() => this._finalizeReady());
|
|
1569
|
-
|
|
1570
1592
|
// Handle fresh login: 'loaded' fires before OAuth completes, so listen
|
|
1571
1593
|
// for `canAuthorize` flipping true and then collect the postauth catalog.
|
|
1572
1594
|
this.listenToOnce(this.webex, 'change:canAuthorize', () => {
|
|
@@ -1579,6 +1601,29 @@ const Services = WebexPlugin.extend({
|
|
|
1579
1601
|
});
|
|
1580
1602
|
}
|
|
1581
1603
|
});
|
|
1604
|
+
|
|
1605
|
+
if (this.webex.config?.services?.skipPreauthCatalogOnUnauthenticated === true) {
|
|
1606
|
+
// Skip the preauth catalog fetch (it will be collected manually
|
|
1607
|
+
// later), but still finalize `services.ready` so `webex.ready` is not
|
|
1608
|
+
// stalled while unauthenticated. No timeout is created here so there
|
|
1609
|
+
// is no stray timer or unhandled rejection.
|
|
1610
|
+
this.logger.info(
|
|
1611
|
+
'services: skipping preauth catalog collection while unauthenticated as per the config'
|
|
1612
|
+
);
|
|
1613
|
+
this._finalizeReady();
|
|
1614
|
+
} else {
|
|
1615
|
+
Promise.race([
|
|
1616
|
+
this.collectPreauthCatalog(email ? {email} : undefined),
|
|
1617
|
+
this._makeInitTimeout(),
|
|
1618
|
+
])
|
|
1619
|
+
.catch((error) => {
|
|
1620
|
+
this.initFailed = true;
|
|
1621
|
+
this.logger.error(
|
|
1622
|
+
`services: failed to init initial services when no credentials available, ${error?.message}`
|
|
1623
|
+
);
|
|
1624
|
+
})
|
|
1625
|
+
.finally(() => this._finalizeReady());
|
|
1626
|
+
}
|
|
1582
1627
|
}
|
|
1583
1628
|
});
|
|
1584
1629
|
},
|