@webex/webex-core 3.12.0-next.7 → 3.12.0-next.70
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
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import {Interceptor} from '@webex/http-core';
|
|
6
6
|
|
|
7
|
+
const inboundTransformPromise = Symbol('inboundTransformPromise');
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* @class
|
|
9
11
|
*/
|
|
@@ -40,7 +42,27 @@ export default class PayloadTransformerInterceptor extends Interceptor {
|
|
|
40
42
|
return response;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
if (!this.webex.config.payloadTransformer.skipRepeatedInboundTransforms) {
|
|
46
|
+
return this.webex.transform('inbound', response);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (response[inboundTransformPromise]) {
|
|
50
|
+
return response[inboundTransformPromise];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const transformPromise = this.webex.transform('inbound', response).catch((error) => {
|
|
54
|
+
Reflect.deleteProperty(response, inboundTransformPromise);
|
|
55
|
+
|
|
56
|
+
throw error;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Store the in-flight promise so concurrent interceptor pipelines share the same transform.
|
|
60
|
+
Object.defineProperty(response, inboundTransformPromise, {
|
|
61
|
+
configurable: true,
|
|
62
|
+
value: transformPromise,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return transformPromise;
|
|
44
66
|
}
|
|
45
67
|
|
|
46
68
|
/**
|
package/src/lib/batcher.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {has} from 'lodash';
|
|
6
|
-
import {cappedDebounce, Defer
|
|
6
|
+
import {cappedDebounce, Defer} from '@webex/common';
|
|
7
7
|
|
|
8
8
|
import WebexPlugin from './webex-plugin';
|
|
9
9
|
import WebexHttpError from './webex-http-error';
|
|
@@ -59,13 +59,12 @@ const Batcher = WebexPlugin.extend({
|
|
|
59
59
|
this.deferreds.set(idx, defer);
|
|
60
60
|
this.prepareItem(item)
|
|
61
61
|
.then((req) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
62
|
+
// Attach cleanup handlers to the original deferred promise without
|
|
63
|
+
// creating an unobserved rejected chain.
|
|
64
|
+
defer.promise.then(
|
|
65
|
+
() => this.deferreds.delete(idx),
|
|
66
|
+
() => this.deferreds.delete(idx)
|
|
67
|
+
);
|
|
69
68
|
|
|
70
69
|
this.enqueue(req)
|
|
71
70
|
.then(() => this.bounce())
|
|
@@ -116,7 +115,19 @@ const Batcher = WebexPlugin.extend({
|
|
|
116
115
|
)
|
|
117
116
|
.catch((reason) => {
|
|
118
117
|
if (reason instanceof WebexHttpError) {
|
|
119
|
-
|
|
118
|
+
// Some batched requests (for example GET-based batches) do not
|
|
119
|
+
// have reason.options.body, so handleHttpError() may reject
|
|
120
|
+
// without failing queued deferreds. Fallback to rejecting each
|
|
121
|
+
// queued request to ensure caller promises settle.
|
|
122
|
+
return this.handleHttpError(reason).catch(() =>
|
|
123
|
+
Promise.all(
|
|
124
|
+
queue.map((item) =>
|
|
125
|
+
this.getDeferredForRequest(item).then((defer) => {
|
|
126
|
+
defer.reject(reason);
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
);
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
return Promise.all(
|
|
@@ -130,8 +141,12 @@ const Batcher = WebexPlugin.extend({
|
|
|
130
141
|
);
|
|
131
142
|
}).catch((reason) => {
|
|
132
143
|
this.logger.error(process.env.NODE_ENV === 'production' ? reason : reason.stack);
|
|
144
|
+
// executeQueue() is triggered via cappedDebounce(), which does not
|
|
145
|
+
// propagate promise chains. Re-throwing here causes global unhandled
|
|
146
|
+
// promise rejections even when request callers handle their own promise.
|
|
147
|
+
// Any known queued requests have already been failed above.
|
|
133
148
|
|
|
134
|
-
return
|
|
149
|
+
return undefined;
|
|
135
150
|
});
|
|
136
151
|
},
|
|
137
152
|
|
|
@@ -6,7 +6,7 @@ import querystring from 'querystring';
|
|
|
6
6
|
import url from 'url';
|
|
7
7
|
|
|
8
8
|
import jwt from 'jsonwebtoken';
|
|
9
|
-
import {base64, makeStateDataType, oneFlight, tap, whileInFlight} from '@webex/common';
|
|
9
|
+
import {base64, encodeState, makeStateDataType, oneFlight, tap, whileInFlight} from '@webex/common';
|
|
10
10
|
import {safeSetTimeout} from '@webex/common-timers';
|
|
11
11
|
import {clone, cloneDeep, isObject, isEmpty} from 'lodash';
|
|
12
12
|
|
|
@@ -109,7 +109,7 @@ const Credentials = WebexPlugin.extend({
|
|
|
109
109
|
*/
|
|
110
110
|
buildLoginUrl(options = {clientType: 'public'}) {
|
|
111
111
|
/* eslint-disable camelcase */
|
|
112
|
-
if (options.state && !isObject(options.state)) {
|
|
112
|
+
if (options.state !== undefined && !isObject(options.state)) {
|
|
113
113
|
throw new Error('if specified, `options.state` must be an object');
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -126,7 +126,7 @@ const Credentials = WebexPlugin.extend({
|
|
|
126
126
|
|
|
127
127
|
if (options.state) {
|
|
128
128
|
if (!isEmpty(options.state)) {
|
|
129
|
-
options.state =
|
|
129
|
+
options.state = encodeState(options.state);
|
|
130
130
|
} else {
|
|
131
131
|
delete options.state;
|
|
132
132
|
}
|
|
@@ -212,6 +212,96 @@ const Credentials = WebexPlugin.extend({
|
|
|
212
212
|
return fields[2];
|
|
213
213
|
},
|
|
214
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Extract the CI user ID [cis_uuid] from a provided token.
|
|
217
|
+
*
|
|
218
|
+
* @private
|
|
219
|
+
* @param {string} token - The access token to extract the user ID from.
|
|
220
|
+
* @throws {Error} - If the token cannot be parsed or does not contain a user ID.
|
|
221
|
+
* @returns {string} - The CI user ID.
|
|
222
|
+
*/
|
|
223
|
+
extractUserIdFromToken(token = '') {
|
|
224
|
+
// User tokens are JWT-like; the middle section holds a base64-encoded JSON payload.
|
|
225
|
+
const payload = JSON.parse(base64.decode(token.split('.')[1]));
|
|
226
|
+
|
|
227
|
+
if (!payload.cis_uuid) {
|
|
228
|
+
throw new Error('the provided token does not contain a user ID');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return payload.cis_uuid;
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get the CI user ID [cis_uuid] of the currently authenticated user.
|
|
236
|
+
*
|
|
237
|
+
* Checks the supertoken first, then falls back to any stored user tokens.
|
|
238
|
+
*
|
|
239
|
+
* @throws {Error} - If the user ID could not be determined from any token.
|
|
240
|
+
* @returns {string} - The CI user ID.
|
|
241
|
+
*/
|
|
242
|
+
getUserId() {
|
|
243
|
+
const tokens = [this.supertoken, ...this.userTokens.models];
|
|
244
|
+
|
|
245
|
+
for (const token of tokens) {
|
|
246
|
+
if (token && token.access_token) {
|
|
247
|
+
try {
|
|
248
|
+
return this.extractUserIdFromToken(token.access_token);
|
|
249
|
+
} catch {
|
|
250
|
+
// token wasn't parseable or lacked a user ID; try the next one
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
throw new Error('could not extract the user ID from any available token');
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Generates a Third-Party Login URL pointing at IdBroker's
|
|
260
|
+
* `/idb/ThirdPartyLogin` endpoint. Used by the social-provider sign-in
|
|
261
|
+
* flow (Google / Microsoft / Apple / ...).
|
|
262
|
+
*
|
|
263
|
+
* Mirrors `buildLoginUrl` / `buildLogoutUrl` — pure URL construction,
|
|
264
|
+
* no navigation side effects. Reads from `this.config.thirdPartyLoginUrl`,
|
|
265
|
+
* which is derived from `idbroker.url` in `credentials-config.js`.
|
|
266
|
+
*
|
|
267
|
+
* @instance
|
|
268
|
+
* @memberof Credentials
|
|
269
|
+
* @param {Object} options
|
|
270
|
+
* @param {string} options.oauth2provider - Provider name (`google`,
|
|
271
|
+
* `microsoft`, `apple`, ...). Required.
|
|
272
|
+
* @param {string} options.returnURL - URL IdBroker should send the user
|
|
273
|
+
* back to after the third-party hand-off. Required.
|
|
274
|
+
* @param {Object} [options.state] - Optional state object. When non-empty
|
|
275
|
+
* it is JSON-stringified and base64url-encoded, then emitted as the
|
|
276
|
+
* top-level `state` query param so IdBroker can echo it back unchanged
|
|
277
|
+
* on the callback (mirrors `buildLoginUrl`).
|
|
278
|
+
* @returns {string}
|
|
279
|
+
*/
|
|
280
|
+
buildThirdPartyLoginUrl(options = {}) {
|
|
281
|
+
const {oauth2provider, returnURL, state} = options;
|
|
282
|
+
|
|
283
|
+
if (!oauth2provider) {
|
|
284
|
+
throw new Error('`options.oauth2provider` is required');
|
|
285
|
+
}
|
|
286
|
+
if (!returnURL) {
|
|
287
|
+
throw new Error('`options.returnURL` is required');
|
|
288
|
+
}
|
|
289
|
+
if (state !== undefined && !isObject(state)) {
|
|
290
|
+
throw new Error('if specified, `options.state` must be an object');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const query = {
|
|
294
|
+
oauth2provider,
|
|
295
|
+
returnURL,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
if (state && !isEmpty(state)) {
|
|
299
|
+
query.state = encodeState(state);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return `${this.config.thirdPartyLoginUrl}?${querystring.stringify(query)}`;
|
|
303
|
+
},
|
|
304
|
+
|
|
215
305
|
/**
|
|
216
306
|
* Generates a Logout URL
|
|
217
307
|
* @instance
|