@webex/webex-core 3.12.0 → 3.13.0-next.2
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/README.md +5 -2
- package/dist/config.js +45 -0
- package/dist/config.js.map +1 -1
- package/dist/credentials-config.js +12 -0
- package/dist/credentials-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 +23 -7
- package/dist/lib/batcher.js.map +1 -1
- package/dist/lib/credentials/credentials.js +103 -4
- package/dist/lib/credentials/credentials.js.map +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/domains.js +90 -0
- package/dist/lib/domains.js.map +1 -0
- package/dist/lib/services/service-catalog.js +108 -18
- package/dist/lib/services/service-catalog.js.map +1 -1
- package/dist/lib/services/services.js +242 -38
- package/dist/lib/services/services.js.map +1 -1
- package/dist/lib/services-v2/service-catalog.js +14 -13
- package/dist/lib/services-v2/service-catalog.js.map +1 -1
- package/dist/lib/services-v2/services-v2.js +255 -42
- 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 +49 -0
- package/src/credentials-config.js +13 -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/batcher.js +25 -10
- package/src/lib/credentials/credentials.js +93 -3
- package/src/lib/credentials/docs/README.md +846 -0
- package/src/lib/domains.ts +94 -0
- package/src/lib/services/docs/README.md +737 -0
- package/src/lib/services/service-catalog.js +112 -16
- package/src/lib/services/services.js +220 -22
- package/src/lib/services-v2/docs/README.md +751 -0
- package/src/lib/services-v2/service-catalog.ts +16 -12
- package/src/lib/services-v2/services-v2.ts +234 -24
- 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/fixtures/activation-email.ts +22 -0
- package/test/integration/spec/services/services.js +183 -112
- package/test/integration/spec/services-v2/services-v2.js +169 -98
- package/test/unit/spec/credentials/credentials.js +247 -3
- package/test/unit/spec/interceptors/auth.js +56 -0
- package/test/unit/spec/interceptors/catalog-url.js +224 -0
- package/test/unit/spec/interceptors/payload-transformer.js +119 -1
- package/test/unit/spec/lib/batcher.js +56 -0
- package/test/unit/spec/services/service-catalog.js +368 -11
- package/test/unit/spec/services/services.js +466 -2
- package/test/unit/spec/services-v2/service-catalog.ts +134 -11
- package/test/unit/spec/services-v2/services-v2.ts +588 -0
- package/test/unit/spec/static-asset-loader.ts +224 -0
- package/test/unit/spec/webex-core.js +77 -1
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
import 'jsdom-global/register';
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
import {StaticAssetLoader} from '@webex/webex-core';
|
|
8
|
+
|
|
9
|
+
describe('StaticAssetLoader', () => {
|
|
10
|
+
let webexRequestStub: sinon.SinonStub;
|
|
11
|
+
let webex: {request: sinon.SinonStub};
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
webexRequestStub = sinon.stub();
|
|
15
|
+
webex = {request: webexRequestStub};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
sinon.restore();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const createLoader = (baseUrl = '/assets/') =>
|
|
23
|
+
new StaticAssetLoader({baseUrl}, {parent: webex});
|
|
24
|
+
|
|
25
|
+
const resolveWith = (overrides: Record<string, any> = {}) => {
|
|
26
|
+
webexRequestStub.resolves({
|
|
27
|
+
statusCode: 200,
|
|
28
|
+
headers: {'content-type': 'application/octet-stream'},
|
|
29
|
+
body: new Uint8Array([0x01, 0x02, 0x03]).buffer,
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe('getUrl', () => {
|
|
35
|
+
it('joins the base url and asset name with a single slash', () => {
|
|
36
|
+
assert.equal(createLoader('/assets/').getUrl('file.dat'), '/assets/file.dat');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('strips leading slashes from the asset name', () => {
|
|
40
|
+
assert.equal(createLoader('/assets/').getUrl('///file.dat'), '/assets/file.dat');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('strips trailing slashes from the base url', () => {
|
|
44
|
+
assert.equal(createLoader('/assets///').getUrl('file.dat'), '/assets/file.dat');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('handles a base url without a trailing slash', () => {
|
|
48
|
+
assert.equal(createLoader('/assets').getUrl('file.dat'), '/assets/file.dat');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('requests the resolved asset url as a binary GET without auth or custom headers', async () => {
|
|
53
|
+
resolveWith();
|
|
54
|
+
|
|
55
|
+
await createLoader('/assets/').getBytes('/some-big-binary-file.dat');
|
|
56
|
+
|
|
57
|
+
sinon.assert.calledOnceWithExactly(webexRequestStub, {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
uri: '/assets/some-big-binary-file.dat',
|
|
60
|
+
responseType: 'buffer',
|
|
61
|
+
addAuthHeader: false,
|
|
62
|
+
headers: {
|
|
63
|
+
trackingid: null,
|
|
64
|
+
'spark-user-agent': null,
|
|
65
|
+
'cisco-no-http-redirect': null,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('rejects a successful response with an HTML content type', async () => {
|
|
71
|
+
webexRequestStub.resolves({
|
|
72
|
+
statusCode: 200,
|
|
73
|
+
headers: {'content-type': 'text/html; charset=utf-8'},
|
|
74
|
+
body: new ArrayBuffer(0),
|
|
75
|
+
});
|
|
76
|
+
const loader = new StaticAssetLoader({baseUrl: '/assets/'}, {parent: webex});
|
|
77
|
+
|
|
78
|
+
await assert.isRejected(
|
|
79
|
+
loader.getBytes('some-big-binary-file.dat'),
|
|
80
|
+
'Failed to fetch static asset /assets/some-big-binary-file.dat: unexpected HTML content type "text/html"'
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('detects an HTML response even when it has a binary content type', async () => {
|
|
85
|
+
const html = new TextEncoder().encode('\uFEFF \t<!doctype html><html>not found</html>');
|
|
86
|
+
|
|
87
|
+
webexRequestStub.resolves({
|
|
88
|
+
statusCode: 200,
|
|
89
|
+
headers: {'content-type': 'application/octet-stream'},
|
|
90
|
+
body: html.buffer,
|
|
91
|
+
});
|
|
92
|
+
const loader = new StaticAssetLoader({baseUrl: '/assets/'}, {parent: webex});
|
|
93
|
+
|
|
94
|
+
await assert.isRejected(
|
|
95
|
+
loader.getBytes('some-big-binary-file.dat'),
|
|
96
|
+
'Failed to fetch static asset /assets/some-big-binary-file.dat: response body looks like an HTML document'
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('returns bytes from a successful binary response', async () => {
|
|
101
|
+
const bytes = new Uint8Array([0x30, 0x01, 0x00]);
|
|
102
|
+
|
|
103
|
+
webexRequestStub.resolves({
|
|
104
|
+
statusCode: 200,
|
|
105
|
+
headers: {'content-type': 'application/octet-stream'},
|
|
106
|
+
body: bytes.buffer,
|
|
107
|
+
});
|
|
108
|
+
const loader = new StaticAssetLoader({baseUrl: '/assets/'}, {parent: webex});
|
|
109
|
+
|
|
110
|
+
assert.deepEqual(await loader.getBytes('some-big-binary-file.dat'), bytes);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('rejects a response with an application/xhtml+xml content type', async () => {
|
|
114
|
+
resolveWith({headers: {'content-type': 'application/xhtml+xml'}, body: new ArrayBuffer(0)});
|
|
115
|
+
|
|
116
|
+
await assert.isRejected(
|
|
117
|
+
createLoader().getBytes('some-big-binary-file.dat'),
|
|
118
|
+
'Failed to fetch static asset /assets/some-big-binary-file.dat: unexpected HTML content type "application/xhtml+xml"'
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('matches the HTML content type case-insensitively', async () => {
|
|
123
|
+
resolveWith({headers: {'content-type': 'TEXT/HTML; charset=UTF-8'}, body: new ArrayBuffer(0)});
|
|
124
|
+
|
|
125
|
+
await assert.isRejected(
|
|
126
|
+
createLoader().getBytes('some-big-binary-file.dat'),
|
|
127
|
+
'Failed to fetch static asset /assets/some-big-binary-file.dat: unexpected HTML content type "text/html"'
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('returns bytes when the response has no content-type header', async () => {
|
|
132
|
+
const bytes = new Uint8Array([0x10, 0x20, 0x30]);
|
|
133
|
+
|
|
134
|
+
resolveWith({headers: {}, body: bytes.buffer});
|
|
135
|
+
|
|
136
|
+
assert.deepEqual(await createLoader().getBytes('some-big-binary-file.dat'), bytes);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
[199, 300, 404, 503].forEach((statusCode) => {
|
|
140
|
+
it(`rejects a non-2xx (${statusCode}) response`, async () => {
|
|
141
|
+
resolveWith({statusCode});
|
|
142
|
+
|
|
143
|
+
await assert.isRejected(
|
|
144
|
+
createLoader().getBytes('some-big-binary-file.dat'),
|
|
145
|
+
`Failed to fetch static asset /assets/some-big-binary-file.dat: HTTP ${statusCode}`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('accepts a response at the upper 2xx boundary', async () => {
|
|
151
|
+
const bytes = new Uint8Array([0x0a, 0x0b]);
|
|
152
|
+
|
|
153
|
+
resolveWith({statusCode: 299, body: bytes.buffer});
|
|
154
|
+
|
|
155
|
+
assert.deepEqual(await createLoader().getBytes('some-big-binary-file.dat'), bytes);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('extracts bytes from a typed-array body with a non-zero byte offset', async () => {
|
|
159
|
+
const backing = new Uint8Array([0xaa, 0x01, 0x02, 0x03, 0xbb]);
|
|
160
|
+
const view = new Uint8Array(backing.buffer, 1, 3);
|
|
161
|
+
|
|
162
|
+
resolveWith({body: view});
|
|
163
|
+
|
|
164
|
+
assert.deepEqual(
|
|
165
|
+
await createLoader().getBytes('some-big-binary-file.dat'),
|
|
166
|
+
new Uint8Array([0x01, 0x02, 0x03])
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('rejects a response whose body is not binary data', async () => {
|
|
171
|
+
resolveWith({body: 'not binary'});
|
|
172
|
+
|
|
173
|
+
await assert.isRejected(
|
|
174
|
+
createLoader().getBytes('some-big-binary-file.dat'),
|
|
175
|
+
'Failed to fetch static asset /assets/some-big-binary-file.dat: response body is not binary data'
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('shares a single request between concurrent and repeated callers', async () => {
|
|
180
|
+
const bytes = new Uint8Array([0x05, 0x06, 0x07]);
|
|
181
|
+
|
|
182
|
+
resolveWith({body: bytes.buffer});
|
|
183
|
+
const loader = createLoader();
|
|
184
|
+
|
|
185
|
+
const [first, second] = await Promise.all([
|
|
186
|
+
loader.getBytes('some-big-binary-file.dat'),
|
|
187
|
+
loader.getBytes('some-big-binary-file.dat'),
|
|
188
|
+
]);
|
|
189
|
+
const third = await loader.getBytes('some-big-binary-file.dat');
|
|
190
|
+
|
|
191
|
+
assert.deepEqual(first, bytes);
|
|
192
|
+
assert.deepEqual(second, bytes);
|
|
193
|
+
assert.deepEqual(third, bytes);
|
|
194
|
+
sinon.assert.calledOnce(webexRequestStub);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('evicts a failed request so a later call retries', async () => {
|
|
198
|
+
const bytes = new Uint8Array([0x08, 0x09]);
|
|
199
|
+
|
|
200
|
+
webexRequestStub.onFirstCall().rejects(new Error('network down'));
|
|
201
|
+
webexRequestStub.onSecondCall().resolves({
|
|
202
|
+
statusCode: 200,
|
|
203
|
+
headers: {'content-type': 'application/octet-stream'},
|
|
204
|
+
body: bytes.buffer,
|
|
205
|
+
});
|
|
206
|
+
const loader = createLoader();
|
|
207
|
+
|
|
208
|
+
await assert.isRejected(loader.getBytes('some-big-binary-file.dat'), 'network down');
|
|
209
|
+
assert.deepEqual(await loader.getBytes('some-big-binary-file.dat'), bytes);
|
|
210
|
+
sinon.assert.calledTwice(webexRequestStub);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('returns an isolated copy that cannot mutate the cached asset', async () => {
|
|
214
|
+
resolveWith({body: new Uint8Array([0x01, 0x02, 0x03]).buffer});
|
|
215
|
+
const loader = createLoader();
|
|
216
|
+
|
|
217
|
+
const first = await loader.getBytes('some-big-binary-file.dat');
|
|
218
|
+
first[0] = 0xff;
|
|
219
|
+
const second = await loader.getBytes('some-big-binary-file.dat');
|
|
220
|
+
|
|
221
|
+
assert.deepEqual(second, new Uint8Array([0x01, 0x02, 0x03]));
|
|
222
|
+
sinon.assert.calledOnce(webexRequestStub);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -91,6 +91,30 @@ describe('Webex', () => {
|
|
|
91
91
|
assert.isFalse(webex.canAuthorize);
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
+
it('initializes network telemetry after applying the configured metrics options', async () => {
|
|
95
|
+
const configuredWebex = new WebexCore({
|
|
96
|
+
config: {
|
|
97
|
+
metrics: {
|
|
98
|
+
networkTelemetry: {
|
|
99
|
+
enabled: true,
|
|
100
|
+
intervalMs: 60 * 1_000,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
const submitClientMetrics = sinon
|
|
106
|
+
.stub(configuredWebex.internal.metrics, 'submitClientMetrics')
|
|
107
|
+
.resolves();
|
|
108
|
+
|
|
109
|
+
assert.exists(configuredWebex.internal.metrics.networkTelemetry);
|
|
110
|
+
configuredWebex.trigger('request:start', {service: 'hydra', resource: 'rooms'});
|
|
111
|
+
await configuredWebex.internal.metrics.flushNetworkTelemetry();
|
|
112
|
+
|
|
113
|
+
assert.calledOnce(submitClientMetrics);
|
|
114
|
+
|
|
115
|
+
await configuredWebex.internal.metrics.stopNetworkTelemetry();
|
|
116
|
+
});
|
|
117
|
+
|
|
94
118
|
[
|
|
95
119
|
'data',
|
|
96
120
|
'data.access_token',
|
|
@@ -179,7 +203,7 @@ describe('Webex', () => {
|
|
|
179
203
|
|
|
180
204
|
describe('initializes with interceptors', () => {
|
|
181
205
|
[
|
|
182
|
-
// 4 pre, 4 post, 10 remaining default = 18
|
|
206
|
+
// 4 pre (CatalogUrlInterceptor is opt-in), 4 post, 10 remaining default = 18
|
|
183
207
|
[
|
|
184
208
|
'defaults to existing interceptors if undefined',
|
|
185
209
|
undefined,
|
|
@@ -205,6 +229,58 @@ describe('Webex', () => {
|
|
|
205
229
|
'RateLimitInterceptor',
|
|
206
230
|
],
|
|
207
231
|
],
|
|
232
|
+
[
|
|
233
|
+
'does not include CatalogUrlInterceptor for a truthy non-boolean value',
|
|
234
|
+
{services: {validateCatalogUrls: 'true'}},
|
|
235
|
+
18,
|
|
236
|
+
[
|
|
237
|
+
'RequestTimingInterceptor',
|
|
238
|
+
'RequestEventInterceptor',
|
|
239
|
+
'WebexTrackingIdInterceptor',
|
|
240
|
+
'RateLimitInterceptor',
|
|
241
|
+
'ServiceInterceptor',
|
|
242
|
+
'UserAgentInterceptor',
|
|
243
|
+
'ProxyInterceptor',
|
|
244
|
+
'WebexUserAgentInterceptor',
|
|
245
|
+
'AuthInterceptor',
|
|
246
|
+
'PayloadTransformerInterceptor',
|
|
247
|
+
'RedirectInterceptor',
|
|
248
|
+
'DefaultOptionsInterceptor',
|
|
249
|
+
'HostMapInterceptor',
|
|
250
|
+
'ServerErrorInterceptor',
|
|
251
|
+
'HttpStatusInterceptor',
|
|
252
|
+
'NetworkTimingInterceptor',
|
|
253
|
+
'EmbargoInterceptor',
|
|
254
|
+
'RateLimitInterceptor',
|
|
255
|
+
],
|
|
256
|
+
],
|
|
257
|
+
// CatalogUrlInterceptor is opt-in via services.validateCatalogUrls
|
|
258
|
+
[
|
|
259
|
+
'includes CatalogUrlInterceptor when validateCatalogUrls is enabled',
|
|
260
|
+
{services: {validateCatalogUrls: true}},
|
|
261
|
+
19,
|
|
262
|
+
[
|
|
263
|
+
'RequestTimingInterceptor',
|
|
264
|
+
'RequestEventInterceptor',
|
|
265
|
+
'WebexTrackingIdInterceptor',
|
|
266
|
+
'RateLimitInterceptor',
|
|
267
|
+
'CatalogUrlInterceptor',
|
|
268
|
+
'ServiceInterceptor',
|
|
269
|
+
'UserAgentInterceptor',
|
|
270
|
+
'ProxyInterceptor',
|
|
271
|
+
'WebexUserAgentInterceptor',
|
|
272
|
+
'AuthInterceptor',
|
|
273
|
+
'PayloadTransformerInterceptor',
|
|
274
|
+
'RedirectInterceptor',
|
|
275
|
+
'DefaultOptionsInterceptor',
|
|
276
|
+
'HostMapInterceptor',
|
|
277
|
+
'ServerErrorInterceptor',
|
|
278
|
+
'HttpStatusInterceptor',
|
|
279
|
+
'NetworkTimingInterceptor',
|
|
280
|
+
'EmbargoInterceptor',
|
|
281
|
+
'RateLimitInterceptor',
|
|
282
|
+
],
|
|
283
|
+
],
|
|
208
284
|
[
|
|
209
285
|
'only adds PayloadTransformerInterceptor',
|
|
210
286
|
{interceptors: {PayloadTransformerInterceptor: PayloadTransformerInterceptor.create}},
|