@webex/webex-core 3.12.0-webex-services-ready.4 → 3.13.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/.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
|
@@ -4,6 +4,7 @@ import {union} from 'lodash';
|
|
|
4
4
|
import ServiceDetail from './service-detail';
|
|
5
5
|
import {IServiceDetail, ServiceGroup} from './types';
|
|
6
6
|
import {matchAllowedDomain, normalizeAllowedDomains} from '../domains';
|
|
7
|
+
import {matchesParsedCatalogUrl, parseCatalogUrl} from '../services/service-catalog';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @class
|
|
@@ -199,9 +200,17 @@ const ServiceCatalog = AmpState.extend({
|
|
|
199
200
|
findServiceDetailFromUrl(url: string): IServiceDetail | undefined {
|
|
200
201
|
const serviceDetails = this._getAllServiceDetails();
|
|
201
202
|
|
|
203
|
+
let candidateUrl: URL;
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
candidateUrl = new URL(url);
|
|
207
|
+
} catch {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
202
211
|
return serviceDetails.find(({serviceUrls}) => {
|
|
203
212
|
for (const serviceUrl of serviceUrls) {
|
|
204
|
-
if (
|
|
213
|
+
if (matchesParsedCatalogUrl(candidateUrl, parseCatalogUrl(serviceUrl.baseUrl))) {
|
|
205
214
|
return true;
|
|
206
215
|
}
|
|
207
216
|
}
|
|
@@ -7,6 +7,7 @@ import METRICS from '../metrics';
|
|
|
7
7
|
import ServiceCatalog from './service-catalog';
|
|
8
8
|
import fedRampServices from './service-fed-ramp';
|
|
9
9
|
import {COMMERCIAL_ALLOWED_DOMAINS} from '../constants';
|
|
10
|
+
import {matchesCatalogUrl} from '../services/service-catalog';
|
|
10
11
|
import {
|
|
11
12
|
ActiveServices,
|
|
12
13
|
IServiceCatalog,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
ServiceHostmap,
|
|
16
17
|
ServiceGroup,
|
|
17
18
|
ServiceHost,
|
|
19
|
+
ServiceUrl,
|
|
18
20
|
SelectionMeta,
|
|
19
21
|
} from './types';
|
|
20
22
|
|
|
@@ -216,13 +218,23 @@ const Services = WebexPlugin.extend({
|
|
|
216
218
|
},
|
|
217
219
|
|
|
218
220
|
/**
|
|
219
|
-
* Checks if the current environment is an integration (INT) environment
|
|
220
|
-
*
|
|
221
|
+
* Checks if the current environment is an integration (INT) environment.
|
|
222
|
+
* Uses the explicit environment config when set, otherwise examines the u2c discovery URL.
|
|
221
223
|
* INT environments use discovery URLs containing 'intb' (e.g., u2c-intb.ciscospark.com).
|
|
222
224
|
* @returns {boolean} True if INT environment, false otherwise
|
|
223
225
|
*/
|
|
224
226
|
isIntegrationEnvironment(): boolean {
|
|
225
227
|
try {
|
|
228
|
+
const configuredEnvironment = this.webex?.config?.environment;
|
|
229
|
+
|
|
230
|
+
if (configuredEnvironment !== undefined) {
|
|
231
|
+
const isIntFromConfig = configuredEnvironment === 'integration';
|
|
232
|
+
|
|
233
|
+
this.logger.info(`services: isIntegrationEnvironment: ${isIntFromConfig} (config)`);
|
|
234
|
+
|
|
235
|
+
return isIntFromConfig;
|
|
236
|
+
}
|
|
237
|
+
|
|
226
238
|
const u2cUrl = this.webex?.config?.services?.discovery?.u2c || '';
|
|
227
239
|
const isInt = u2cUrl.includes('intb');
|
|
228
240
|
|
|
@@ -988,7 +1000,9 @@ const Services = WebexPlugin.extend({
|
|
|
988
1000
|
|
|
989
1001
|
const priorityUrl = service.get();
|
|
990
1002
|
const defaultUrl = new URL(
|
|
991
|
-
service.serviceUrls.find((serviceUrl) =>
|
|
1003
|
+
service.serviceUrls.find((serviceUrl: ServiceUrl) =>
|
|
1004
|
+
matchesCatalogUrl(url, serviceUrl.baseUrl)
|
|
1005
|
+
).baseUrl
|
|
992
1006
|
).href;
|
|
993
1007
|
|
|
994
1008
|
return {
|
|
@@ -1257,9 +1271,16 @@ const Services = WebexPlugin.extend({
|
|
|
1257
1271
|
requestObject.headers = {authorization: token};
|
|
1258
1272
|
}
|
|
1259
1273
|
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1274
|
+
const sendRequest = () => this.request(requestObject);
|
|
1275
|
+
|
|
1276
|
+
const responsePromise = this.webex.internal.newMetrics
|
|
1277
|
+
? this.webex.internal.newMetrics.callDiagnosticLatencies.measureLatency(
|
|
1278
|
+
sendRequest,
|
|
1279
|
+
'internal.get.u2c.time'
|
|
1280
|
+
)
|
|
1281
|
+
: sendRequest();
|
|
1282
|
+
|
|
1283
|
+
return responsePromise.then(({body}) => this._formatReceivedHostmap(body || {}));
|
|
1263
1284
|
},
|
|
1264
1285
|
|
|
1265
1286
|
/**
|
|
@@ -1275,7 +1296,10 @@ const Services = WebexPlugin.extend({
|
|
|
1275
1296
|
// Validate that the services configuration exists.
|
|
1276
1297
|
if (services) {
|
|
1277
1298
|
if (fedramp) {
|
|
1278
|
-
services.discovery =
|
|
1299
|
+
services.discovery = {
|
|
1300
|
+
...fedRampServices,
|
|
1301
|
+
u2c: services.discovery?.u2c || fedRampServices.u2c,
|
|
1302
|
+
};
|
|
1279
1303
|
}
|
|
1280
1304
|
// Check for discovery services.
|
|
1281
1305
|
if (services.discovery) {
|
|
@@ -1388,6 +1412,28 @@ const Services = WebexPlugin.extend({
|
|
|
1388
1412
|
this.ready = true;
|
|
1389
1413
|
},
|
|
1390
1414
|
|
|
1415
|
+
/**
|
|
1416
|
+
* Build a promise that rejects once the catalog init timeout elapses. Race
|
|
1417
|
+
* this against catalog collection so a hung request never leaves
|
|
1418
|
+
* `services.ready` false forever - that would stall `webex.ready` and leave
|
|
1419
|
+
* consumers waiting on it indefinitely. Timeout is configurable via
|
|
1420
|
+
* `config.services.catalogInitTimeout` (defaults to 15s in config). Created
|
|
1421
|
+
* lazily so paths that skip catalog collection never schedule a stray timer.
|
|
1422
|
+
*
|
|
1423
|
+
* @private
|
|
1424
|
+
* @returns {Promise<never>}
|
|
1425
|
+
*/
|
|
1426
|
+
_makeInitTimeout(): Promise<never> {
|
|
1427
|
+
const initTimeoutMs = this.webex.config?.services?.catalogInitTimeout;
|
|
1428
|
+
|
|
1429
|
+
return new Promise<never>((_, reject) => {
|
|
1430
|
+
setTimeout(
|
|
1431
|
+
() => reject(new Error(`services: init timed out after ${initTimeoutMs}ms`)),
|
|
1432
|
+
initTimeoutMs
|
|
1433
|
+
);
|
|
1434
|
+
});
|
|
1435
|
+
},
|
|
1436
|
+
|
|
1391
1437
|
/**
|
|
1392
1438
|
* Initializer
|
|
1393
1439
|
*
|
|
@@ -1455,6 +1501,14 @@ const Services = WebexPlugin.extend({
|
|
|
1455
1501
|
} else {
|
|
1456
1502
|
const {email} = this.webex.config;
|
|
1457
1503
|
|
|
1504
|
+
if (this.webex.config?.services?.skipPreauthCatalogOnUnauthenticated === true) {
|
|
1505
|
+
this.logger.info(
|
|
1506
|
+
'services: skipping preauth catalog collection while unauthenticated as per the config'
|
|
1507
|
+
);
|
|
1508
|
+
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1458
1512
|
this.collectPreauthCatalog(email ? {email} : undefined).catch((error) => {
|
|
1459
1513
|
this.initFailed = true;
|
|
1460
1514
|
this.logger.error(
|
|
@@ -1489,24 +1543,12 @@ const Services = WebexPlugin.extend({
|
|
|
1489
1543
|
}
|
|
1490
1544
|
const {supertoken} = this.webex.credentials;
|
|
1491
1545
|
|
|
1492
|
-
// Race init against a hard timeout so a hung request never leaves
|
|
1493
|
-
// `services.ready` false forever - that would stall `webex.ready` and
|
|
1494
|
-
// leave consumers waiting on it indefinitely. Timeout is configurable via
|
|
1495
|
-
// `config.services.catalogInitTimeout` (defaults to 15s in config).
|
|
1496
|
-
const initTimeoutMs = this.webex.config?.services?.catalogInitTimeout;
|
|
1497
|
-
const initServiceCatalogsTimeout = new Promise<never>((_, reject) => {
|
|
1498
|
-
setTimeout(
|
|
1499
|
-
() => reject(new Error(`services: init timed out after ${initTimeoutMs}ms`)),
|
|
1500
|
-
initTimeoutMs
|
|
1501
|
-
);
|
|
1502
|
-
});
|
|
1503
|
-
|
|
1504
1546
|
// Validate if the supertoken exists.
|
|
1505
1547
|
if (supertoken && supertoken.access_token) {
|
|
1506
1548
|
// `initServiceCatalogs` marks the catalog ready internally once the
|
|
1507
1549
|
// postauth catalog is collected - even if it loses the timeout race
|
|
1508
|
-
//
|
|
1509
|
-
Promise.race([this.initServiceCatalogs(),
|
|
1550
|
+
// below, so a slow fetch still eventually flips `catalog.isReady`.
|
|
1551
|
+
Promise.race([this.initServiceCatalogs(), this._makeInitTimeout()])
|
|
1510
1552
|
.catch((error) => {
|
|
1511
1553
|
this.initFailed = true;
|
|
1512
1554
|
this.logger.error(
|
|
@@ -1517,18 +1559,6 @@ const Services = WebexPlugin.extend({
|
|
|
1517
1559
|
} else {
|
|
1518
1560
|
const {email} = this.webex.config;
|
|
1519
1561
|
|
|
1520
|
-
Promise.race([
|
|
1521
|
-
this.collectPreauthCatalog(email ? {email} : undefined),
|
|
1522
|
-
initServiceCatalogsTimeout,
|
|
1523
|
-
])
|
|
1524
|
-
.catch((error) => {
|
|
1525
|
-
this.initFailed = true;
|
|
1526
|
-
this.logger.error(
|
|
1527
|
-
`services: failed to init initial services when no credentials available, ${error?.message}`
|
|
1528
|
-
);
|
|
1529
|
-
})
|
|
1530
|
-
.finally(() => this._finalizeReady());
|
|
1531
|
-
|
|
1532
1562
|
// Handle fresh login: 'loaded' fires before OAuth completes, so listen
|
|
1533
1563
|
// for `canAuthorize` flipping true and then collect the postauth catalog.
|
|
1534
1564
|
this.listenToOnce(this.webex, 'change:canAuthorize', () => {
|
|
@@ -1541,6 +1571,29 @@ const Services = WebexPlugin.extend({
|
|
|
1541
1571
|
});
|
|
1542
1572
|
}
|
|
1543
1573
|
});
|
|
1574
|
+
|
|
1575
|
+
if (this.webex.config?.services?.skipPreauthCatalogOnUnauthenticated === true) {
|
|
1576
|
+
// Skip the preauth catalog fetch (it will be collected manually
|
|
1577
|
+
// later), but still finalize `services.ready` so `webex.ready` is not
|
|
1578
|
+
// stalled while unauthenticated. No timeout is created here so there
|
|
1579
|
+
// is no stray timer or unhandled rejection.
|
|
1580
|
+
this.logger.info(
|
|
1581
|
+
'services: skipping preauth catalog collection while unauthenticated as per the config'
|
|
1582
|
+
);
|
|
1583
|
+
this._finalizeReady();
|
|
1584
|
+
} else {
|
|
1585
|
+
Promise.race([
|
|
1586
|
+
this.collectPreauthCatalog(email ? {email} : undefined),
|
|
1587
|
+
this._makeInitTimeout(),
|
|
1588
|
+
])
|
|
1589
|
+
.catch((error) => {
|
|
1590
|
+
this.initFailed = true;
|
|
1591
|
+
this.logger.error(
|
|
1592
|
+
`services: failed to init initial services when no credentials available, ${error?.message}`
|
|
1593
|
+
);
|
|
1594
|
+
})
|
|
1595
|
+
.finally(() => this._finalizeReady());
|
|
1596
|
+
}
|
|
1544
1597
|
}
|
|
1545
1598
|
});
|
|
1546
1599
|
},
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import StatelessWebexPlugin from './stateless-webex-plugin';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Detects an HTML document prefix in an otherwise successful binary asset response.
|
|
10
|
+
* @param {ArrayBuffer} buffer
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
function looksLikeHtmlDocument(buffer: ArrayBuffer): boolean {
|
|
14
|
+
const prefix = new TextDecoder().decode(buffer.slice(0, 256)).trimStart();
|
|
15
|
+
|
|
16
|
+
return prefix.startsWith('<');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Resolves and downloads static assets for SDK plugins. Requests are shared between callers and
|
|
21
|
+
* cached after a successful response.
|
|
22
|
+
*
|
|
23
|
+
* IMPORTANT: When adding assets, ensure that their names are unique and versioned to avoid caching issues.
|
|
24
|
+
* Example: 'e2ee-0.0.1.wasm' instead of 'e2ee.wasm'
|
|
25
|
+
* or use content-based hashing in the filename to ensure uniqueness.
|
|
26
|
+
*/
|
|
27
|
+
export default class StaticAssetLoader extends StatelessWebexPlugin {
|
|
28
|
+
private readonly baseUrl: string;
|
|
29
|
+
|
|
30
|
+
private readonly assets = new Map<string, Promise<ArrayBuffer>>();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Object} attrs
|
|
34
|
+
* @param {string} attrs.baseUrl - Base URL for the plugin's static assets.
|
|
35
|
+
* @param {Object} options
|
|
36
|
+
* @param {Object} [options.parent] - The parent Webex SDK instance.
|
|
37
|
+
*/
|
|
38
|
+
constructor(attrs: {baseUrl: string}, options: {parent?: any} = {}) {
|
|
39
|
+
super(attrs, options);
|
|
40
|
+
this.baseUrl = attrs.baseUrl.replace(/\/+$/, ''); // remove trailing slashes
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the URL for an asset in the configured asset directory.
|
|
45
|
+
* @param {string} assetName
|
|
46
|
+
* @returns {string}
|
|
47
|
+
*/
|
|
48
|
+
getUrl(assetName: string): string {
|
|
49
|
+
return `${this.baseUrl}/${assetName.replace(/^\/+/, '')}`; // regex removes leading slashes from the asset name
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Downloads an asset as bytes. Failed requests are evicted so a later call can retry.
|
|
54
|
+
* @param {string} assetName
|
|
55
|
+
* @returns {Promise<Uint8Array>}
|
|
56
|
+
*/
|
|
57
|
+
async getBytes(assetName: string): Promise<Uint8Array> {
|
|
58
|
+
const url = this.getUrl(assetName);
|
|
59
|
+
let asset = this.assets.get(url);
|
|
60
|
+
|
|
61
|
+
if (!asset) {
|
|
62
|
+
// @ts-ignore - StatelessWebexPlugin exposes request from the parent Webex instance.
|
|
63
|
+
asset = this.request({
|
|
64
|
+
method: 'GET',
|
|
65
|
+
uri: url,
|
|
66
|
+
responseType: 'buffer',
|
|
67
|
+
// Assets may be hosted on a third-party CDN: never send the user's token, and suppress
|
|
68
|
+
// the SDK's custom headers so the request doesn't trigger a CORS preflight.
|
|
69
|
+
addAuthHeader: false,
|
|
70
|
+
headers: {
|
|
71
|
+
trackingid: null,
|
|
72
|
+
'spark-user-agent': null,
|
|
73
|
+
'cisco-no-http-redirect': null,
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
.then((response: any) => {
|
|
77
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
78
|
+
throw new Error(`Failed to fetch static asset ${url}: HTTP ${response.statusCode}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const contentType = response.headers?.['content-type']
|
|
82
|
+
?.split(';')[0]
|
|
83
|
+
.trim()
|
|
84
|
+
.toLowerCase();
|
|
85
|
+
|
|
86
|
+
if (contentType === 'text/html' || contentType === 'application/xhtml+xml') {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Failed to fetch static asset ${url}: unexpected HTML content type "${contentType}"`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const responseBody = response.body;
|
|
93
|
+
let buffer: ArrayBuffer;
|
|
94
|
+
|
|
95
|
+
if (responseBody instanceof ArrayBuffer) {
|
|
96
|
+
buffer = responseBody;
|
|
97
|
+
} else if (ArrayBuffer.isView(responseBody)) {
|
|
98
|
+
buffer = responseBody.buffer.slice(
|
|
99
|
+
responseBody.byteOffset,
|
|
100
|
+
responseBody.byteOffset + responseBody.byteLength
|
|
101
|
+
) as ArrayBuffer;
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Failed to fetch static asset ${url}: response body is not binary data`
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Some static servers return an HTML fallback page with a successful status and a
|
|
109
|
+
// generic binary content type. Reject it before callers pass those bytes to modules
|
|
110
|
+
// that expect binary data, such as WASM.
|
|
111
|
+
if (looksLikeHtmlDocument(buffer)) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Failed to fetch static asset ${url}: response body looks like an HTML document`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return buffer;
|
|
118
|
+
})
|
|
119
|
+
.catch((error: Error) => {
|
|
120
|
+
this.assets.delete(url);
|
|
121
|
+
throw error;
|
|
122
|
+
});
|
|
123
|
+
this.assets.set(url, asset);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return new Uint8Array((await asset).slice(0));
|
|
127
|
+
}
|
|
128
|
+
}
|