@webex/webex-core 3.12.0-next.63 → 3.12.0-next.64
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/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/batcher.js +1 -1
- package/dist/lib/credentials/credentials.js +1 -1
- package/dist/lib/credentials/token.js +1 -1
- package/dist/lib/services/services.js +1 -1
- package/dist/lib/services-v2/services-v2.js +1 -1
- package/dist/lib/static-asset-loader.js +149 -0
- package/dist/lib/static-asset-loader.js.map +1 -0
- package/dist/plugins/logger.js +1 -1
- package/dist/webex-core.js +2 -2
- package/package.json +3 -3
- package/src/index.js +1 -0
- package/src/lib/static-asset-loader.ts +124 -0
- package/test/unit/spec/static-asset-loader.ts +224 -0
package/dist/index.js
CHANGED
|
@@ -194,6 +194,12 @@ _Object$defineProperty(exports, "StatelessWebexPlugin", {
|
|
|
194
194
|
return _statelessWebexPlugin.default;
|
|
195
195
|
}
|
|
196
196
|
});
|
|
197
|
+
_Object$defineProperty(exports, "StaticAssetLoader", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
get: function get() {
|
|
200
|
+
return _staticAssetLoader.default;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
197
203
|
_Object$defineProperty(exports, "StorageError", {
|
|
198
204
|
enumerable: true,
|
|
199
205
|
get: function get() {
|
|
@@ -320,6 +326,7 @@ var _webexCore = _interopRequireWildcard(require("./webex-core"));
|
|
|
320
326
|
var _webexHttpError = _interopRequireDefault(require("./lib/webex-http-error"));
|
|
321
327
|
var _statelessWebexPlugin = _interopRequireDefault(require("./lib/stateless-webex-plugin"));
|
|
322
328
|
var _webexPlugin = _interopRequireDefault(require("./lib/webex-plugin"));
|
|
329
|
+
var _staticAssetLoader = _interopRequireDefault(require("./lib/static-asset-loader"));
|
|
323
330
|
var _auth = _interopRequireDefault(require("./interceptors/auth"));
|
|
324
331
|
var _catalogUrl = _interopRequireDefault(require("./interceptors/catalog-url"));
|
|
325
332
|
var _networkTiming = _interopRequireDefault(require("./interceptors/network-timing"));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["require","_credentials","_services","_servicesV","_serviceConstants","_interopRequireWildcard","exports","serviceConstants","_storage","_webexCore","_webexHttpError","_interopRequireDefault","_statelessWebexPlugin","_webexPlugin","_auth","_catalogUrl","_networkTiming","_payloadTransformer","_redirect","_responseLogger","_requestEvent","_requestLogger","_requestTiming","_userAgent","_proxy","_webexTrackingId","_webexUserAgent","_rateLimit","_embargo","_defaultOptions","_hostmap","_service","_serverError","_batcher","_page","_config","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n *\n * Services is currently a part of webex-core due to how the contents of\n * the original internal-plugin-services needed to be accessed when webex-core\n * is initialized. As a plugin outside of webex-core, it would initialize after\n * credentials, causing all requests prior to its initialization to fail\n * federation requirements, and instead send requests to the environmentally-\n * assigned urls.\n */\n\nimport './plugins/logger';\nimport './lib/credentials';\nimport './lib/services';\n\nexport {Credentials, filterScope, grantErrors, sortScope, Token} from './lib/credentials';\n\nexport {\n ServiceCatalog,\n ServiceRegistry,\n ServiceState,\n Services,\n ServiceHost,\n ServiceUrl,\n} from './lib/services';\n\nexport {ServiceCatalogV2, ServicesV2, ServiceDetail} from './lib/services-v2';\nexport * as serviceConstants from './lib/constants';\nexport {\n makeWebexStore,\n makeWebexPluginStore,\n MemoryStoreAdapter,\n NotFoundError,\n persist,\n StorageError,\n waitForValue,\n} from './lib/storage';\n\nexport {default, registerPlugin, registerInternalPlugin} from './webex-core';\n\nexport {default as WebexHttpError} from './lib/webex-http-error';\nexport {default as StatelessWebexPlugin} from './lib/stateless-webex-plugin';\nexport {default as WebexPlugin} from './lib/webex-plugin';\nexport {default as AuthInterceptor} from './interceptors/auth';\nexport {default as CatalogUrlInterceptor} from './interceptors/catalog-url';\nexport {default as NetworkTimingInterceptor} from './interceptors/network-timing';\nexport {default as PayloadTransformerInterceptor} from './interceptors/payload-transformer';\nexport {default as RedirectInterceptor} from './interceptors/redirect';\nexport {default as ResponseLoggerInterceptor} from './interceptors/response-logger';\nexport {default as RequestEventInterceptor} from './interceptors/request-event';\nexport {default as RequestLoggerInterceptor} from './interceptors/request-logger';\nexport {default as RequestTimingInterceptor} from './interceptors/request-timing';\nexport {default as UserAgentInterceptor} from './interceptors/user-agent';\nexport {default as ProxyInterceptor} from './interceptors/proxy';\nexport {default as WebexTrackingIdInterceptor} from './interceptors/webex-tracking-id';\nexport {sequenceNumbers as webexTrackingIdSequenceNumbers} from './interceptors/webex-tracking-id';\nexport {default as WebexUserAgentInterceptor} from './interceptors/webex-user-agent';\nexport {default as RateLimitInterceptor} from './interceptors/rate-limit';\nexport {default as EmbargoInterceptor} from './interceptors/embargo';\nexport {default as DefaultOptionsInterceptor} from './interceptors/default-options';\nexport {default as HostMapInterceptor} from './lib/interceptors/hostmap';\nexport {default as ServiceInterceptor} from './lib/interceptors/service';\nexport {default as ServerErrorInterceptor} from './lib/interceptors/server-error';\n\nexport {default as Batcher} from './lib/batcher';\nexport {default as Page} from './lib/page';\nexport {default as config} from './config';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":["require","_credentials","_services","_servicesV","_serviceConstants","_interopRequireWildcard","exports","serviceConstants","_storage","_webexCore","_webexHttpError","_interopRequireDefault","_statelessWebexPlugin","_webexPlugin","_staticAssetLoader","_auth","_catalogUrl","_networkTiming","_payloadTransformer","_redirect","_responseLogger","_requestEvent","_requestLogger","_requestTiming","_userAgent","_proxy","_webexTrackingId","_webexUserAgent","_rateLimit","_embargo","_defaultOptions","_hostmap","_service","_serverError","_batcher","_page","_config","e","t","_WeakMap","r","n","__esModule","o","i","f","__proto__","default","_typeof","has","get","set","_t","hasOwnProperty","call","_Object$defineProperty","_Object$getOwnPropertyDescriptor"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n *\n * Services is currently a part of webex-core due to how the contents of\n * the original internal-plugin-services needed to be accessed when webex-core\n * is initialized. As a plugin outside of webex-core, it would initialize after\n * credentials, causing all requests prior to its initialization to fail\n * federation requirements, and instead send requests to the environmentally-\n * assigned urls.\n */\n\nimport './plugins/logger';\nimport './lib/credentials';\nimport './lib/services';\n\nexport {Credentials, filterScope, grantErrors, sortScope, Token} from './lib/credentials';\n\nexport {\n ServiceCatalog,\n ServiceRegistry,\n ServiceState,\n Services,\n ServiceHost,\n ServiceUrl,\n} from './lib/services';\n\nexport {ServiceCatalogV2, ServicesV2, ServiceDetail} from './lib/services-v2';\nexport * as serviceConstants from './lib/constants';\nexport {\n makeWebexStore,\n makeWebexPluginStore,\n MemoryStoreAdapter,\n NotFoundError,\n persist,\n StorageError,\n waitForValue,\n} from './lib/storage';\n\nexport {default, registerPlugin, registerInternalPlugin} from './webex-core';\n\nexport {default as WebexHttpError} from './lib/webex-http-error';\nexport {default as StatelessWebexPlugin} from './lib/stateless-webex-plugin';\nexport {default as WebexPlugin} from './lib/webex-plugin';\nexport {default as StaticAssetLoader} from './lib/static-asset-loader';\nexport {default as AuthInterceptor} from './interceptors/auth';\nexport {default as CatalogUrlInterceptor} from './interceptors/catalog-url';\nexport {default as NetworkTimingInterceptor} from './interceptors/network-timing';\nexport {default as PayloadTransformerInterceptor} from './interceptors/payload-transformer';\nexport {default as RedirectInterceptor} from './interceptors/redirect';\nexport {default as ResponseLoggerInterceptor} from './interceptors/response-logger';\nexport {default as RequestEventInterceptor} from './interceptors/request-event';\nexport {default as RequestLoggerInterceptor} from './interceptors/request-logger';\nexport {default as RequestTimingInterceptor} from './interceptors/request-timing';\nexport {default as UserAgentInterceptor} from './interceptors/user-agent';\nexport {default as ProxyInterceptor} from './interceptors/proxy';\nexport {default as WebexTrackingIdInterceptor} from './interceptors/webex-tracking-id';\nexport {sequenceNumbers as webexTrackingIdSequenceNumbers} from './interceptors/webex-tracking-id';\nexport {default as WebexUserAgentInterceptor} from './interceptors/webex-user-agent';\nexport {default as RateLimitInterceptor} from './interceptors/rate-limit';\nexport {default as EmbargoInterceptor} from './interceptors/embargo';\nexport {default as DefaultOptionsInterceptor} from './interceptors/default-options';\nexport {default as HostMapInterceptor} from './lib/interceptors/hostmap';\nexport {default as ServiceInterceptor} from './lib/interceptors/service';\nexport {default as ServerErrorInterceptor} from './lib/interceptors/server-error';\n\nexport {default as Batcher} from './lib/batcher';\nexport {default as Page} from './lib/page';\nexport {default as config} from './config';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWAA,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAaA,IAAAG,UAAA,GAAAH,OAAA;AAA8E,IAAAI,iBAAA,GAAAC,uBAAA,CAAAL,OAAA;AAAAM,OAAA,CAAAC,gBAAA,GAAAH,iBAAA;AAE9E,IAAAI,QAAA,GAAAR,OAAA;AAUA,IAAAS,UAAA,GAAAJ,uBAAA,CAAAL,OAAA;AAEA,IAAAU,eAAA,GAAAC,sBAAA,CAAAX,OAAA;AACA,IAAAY,qBAAA,GAAAD,sBAAA,CAAAX,OAAA;AACA,IAAAa,YAAA,GAAAF,sBAAA,CAAAX,OAAA;AACA,IAAA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A,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,gBAAAW,OAAA,CAAAX,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAM,GAAA,CAAAZ,CAAA,UAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,GAAAM,CAAA,CAAAQ,GAAA,CAAAd,CAAA,EAAAQ,CAAA,cAAAO,EAAA,IAAAf,CAAA,gBAAAe,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAe,EAAA,OAAAR,CAAA,IAAAD,CAAA,GAAAY,sBAAA,KAAAC,gCAAA,CAAAnB,CAAA,EAAAe,EAAA,OAAAR,CAAA,CAAAM,GAAA,IAAAN,CAAA,CAAAO,GAAA,IAAAR,CAAA,CAAAE,CAAA,EAAAO,EAAA,EAAAR,CAAA,IAAAC,CAAA,CAAAO,EAAA,IAAAf,CAAA,CAAAe,EAAA,WAAAP,CAAA,KAAAR,CAAA,EAAAC,CAAA","ignoreList":[]}
|
package/dist/lib/batcher.js
CHANGED
|
@@ -302,7 +302,7 @@ var Batcher = _webexPlugin.default.extend({
|
|
|
302
302
|
fingerprintResponse: function fingerprintResponse(item) {
|
|
303
303
|
throw new Error('fingerprintResponse() must be implemented');
|
|
304
304
|
},
|
|
305
|
-
version: "3.12.0-next.
|
|
305
|
+
version: "3.12.0-next.64"
|
|
306
306
|
});
|
|
307
307
|
var _default2 = exports.default = Batcher;
|
|
308
308
|
//# sourceMappingURL=batcher.js.map
|
|
@@ -655,7 +655,7 @@ var Credentials = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
655
655
|
this.refresh();
|
|
656
656
|
}
|
|
657
657
|
},
|
|
658
|
-
version: "3.12.0-next.
|
|
658
|
+
version: "3.12.0-next.64"
|
|
659
659
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "getUserToken", [_dec, _dec2], (0, _getOwnPropertyDescriptor.default)(_obj, "getUserToken"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "initialize", [_dec3], (0, _getOwnPropertyDescriptor.default)(_obj, "initialize"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "invalidate", [_common.oneFlight, _dec4], (0, _getOwnPropertyDescriptor.default)(_obj, "invalidate"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight, _dec5, _dec6], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), _obj));
|
|
660
660
|
var _default = exports.default = Credentials;
|
|
661
661
|
//# sourceMappingURL=credentials.js.map
|
|
@@ -532,7 +532,7 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
|
|
|
532
532
|
return res.body;
|
|
533
533
|
});
|
|
534
534
|
},
|
|
535
|
-
version: "3.12.0-next.
|
|
535
|
+
version: "3.12.0-next.64"
|
|
536
536
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "downscope", [_dec], (0, _getOwnPropertyDescriptor.default)(_obj, "downscope"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "refresh", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "refresh"), _obj), (0, _applyDecoratedDescriptor2.default)(_obj, "revoke", [_common.oneFlight], (0, _getOwnPropertyDescriptor.default)(_obj, "revoke"), _obj), _obj));
|
|
537
537
|
var _default = exports.default = Token;
|
|
538
538
|
//# sourceMappingURL=token.js.map
|
|
@@ -1641,7 +1641,7 @@ var Services = _webexPlugin.default.extend({
|
|
|
1641
1641
|
}, _callee6);
|
|
1642
1642
|
})));
|
|
1643
1643
|
},
|
|
1644
|
-
version: "3.12.0-next.
|
|
1644
|
+
version: "3.12.0-next.64"
|
|
1645
1645
|
});
|
|
1646
1646
|
/* eslint-enable no-underscore-dangle */
|
|
1647
1647
|
var _default = exports.default = Services;
|
|
@@ -1577,7 +1577,7 @@ var Services = _webexPlugin.default.extend({
|
|
|
1577
1577
|
}, _callee5);
|
|
1578
1578
|
})));
|
|
1579
1579
|
},
|
|
1580
|
-
version: "3.12.0-next.
|
|
1580
|
+
version: "3.12.0-next.64"
|
|
1581
1581
|
});
|
|
1582
1582
|
/* eslint-enable no-underscore-dangle */
|
|
1583
1583
|
var _default = exports.default = Services;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
|
|
4
|
+
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.default = void 0;
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
|
|
11
|
+
var _map = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/map"));
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
|
|
13
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
|
|
15
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
|
|
16
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
|
|
17
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
19
|
+
var _statelessWebexPlugin = _interopRequireDefault(require("./stateless-webex-plugin"));
|
|
20
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
21
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /*!
|
|
22
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
23
|
+
*/ // @ts-ignore
|
|
24
|
+
/**
|
|
25
|
+
* Detects an HTML document prefix in an otherwise successful binary asset response.
|
|
26
|
+
* @param {ArrayBuffer} buffer
|
|
27
|
+
* @returns {boolean}
|
|
28
|
+
*/
|
|
29
|
+
function looksLikeHtmlDocument(buffer) {
|
|
30
|
+
var prefix = new TextDecoder().decode(buffer.slice(0, 256)).trimStart();
|
|
31
|
+
return prefix.startsWith('<');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolves and downloads static assets for SDK plugins. Requests are shared between callers and
|
|
36
|
+
* cached after a successful response.
|
|
37
|
+
*/
|
|
38
|
+
var StaticAssetLoader = exports.default = /*#__PURE__*/function (_StatelessWebexPlugin) {
|
|
39
|
+
/**
|
|
40
|
+
* @param {Object} attrs
|
|
41
|
+
* @param {string} attrs.baseUrl - Base URL for the plugin's static assets.
|
|
42
|
+
* @param {Object} options
|
|
43
|
+
* @param {Object} [options.parent] - The parent Webex SDK instance.
|
|
44
|
+
*/
|
|
45
|
+
function StaticAssetLoader(attrs) {
|
|
46
|
+
var _this;
|
|
47
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
48
|
+
(0, _classCallCheck2.default)(this, StaticAssetLoader);
|
|
49
|
+
_this = _callSuper(this, StaticAssetLoader, [attrs, options]);
|
|
50
|
+
(0, _defineProperty2.default)(_this, "baseUrl", void 0);
|
|
51
|
+
(0, _defineProperty2.default)(_this, "assets", new _map.default());
|
|
52
|
+
_this.baseUrl = attrs.baseUrl.replace(/\/+$/, ''); // remove trailing slashes
|
|
53
|
+
return _this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the URL for an asset in the configured asset directory.
|
|
58
|
+
* @param {string} assetName
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
(0, _inherits2.default)(StaticAssetLoader, _StatelessWebexPlugin);
|
|
62
|
+
return (0, _createClass2.default)(StaticAssetLoader, [{
|
|
63
|
+
key: "getUrl",
|
|
64
|
+
value: function getUrl(assetName) {
|
|
65
|
+
return "".concat(this.baseUrl, "/").concat(assetName.replace(/^\/+/, '')); // regex removes leading slashes from the asset name
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Downloads an asset as bytes. Failed requests are evicted so a later call can retry.
|
|
70
|
+
* @param {string} assetName
|
|
71
|
+
* @returns {Promise<Uint8Array>}
|
|
72
|
+
*/
|
|
73
|
+
}, {
|
|
74
|
+
key: "getBytes",
|
|
75
|
+
value: (function () {
|
|
76
|
+
var _getBytes = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(assetName) {
|
|
77
|
+
var _this2 = this;
|
|
78
|
+
var url, asset, _t, _t2;
|
|
79
|
+
return _regenerator.default.wrap(function (_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
url = this.getUrl(assetName);
|
|
83
|
+
asset = this.assets.get(url);
|
|
84
|
+
if (!asset) {
|
|
85
|
+
// @ts-ignore - StatelessWebexPlugin exposes request from the parent Webex instance.
|
|
86
|
+
asset = this.request({
|
|
87
|
+
method: 'GET',
|
|
88
|
+
uri: url,
|
|
89
|
+
responseType: 'buffer',
|
|
90
|
+
// Assets may be hosted on a third-party CDN: never send the user's token, and suppress
|
|
91
|
+
// the SDK's custom headers so the request doesn't trigger a CORS preflight.
|
|
92
|
+
addAuthHeader: false,
|
|
93
|
+
headers: {
|
|
94
|
+
trackingid: null,
|
|
95
|
+
'spark-user-agent': null,
|
|
96
|
+
'cisco-no-http-redirect': null
|
|
97
|
+
}
|
|
98
|
+
}).then(function (response) {
|
|
99
|
+
var _response$headers, _response$headers$con;
|
|
100
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
101
|
+
throw new Error("Failed to fetch static asset ".concat(url, ": HTTP ").concat(response.statusCode));
|
|
102
|
+
}
|
|
103
|
+
var contentType = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : (_response$headers$con = _response$headers['content-type']) === null || _response$headers$con === void 0 ? void 0 : _response$headers$con.split(';')[0].trim().toLowerCase();
|
|
104
|
+
if (contentType === 'text/html' || contentType === 'application/xhtml+xml') {
|
|
105
|
+
throw new Error("Failed to fetch static asset ".concat(url, ": unexpected HTML content type \"").concat(contentType, "\""));
|
|
106
|
+
}
|
|
107
|
+
var responseBody = response.body;
|
|
108
|
+
var buffer;
|
|
109
|
+
if (responseBody instanceof ArrayBuffer) {
|
|
110
|
+
buffer = responseBody;
|
|
111
|
+
} else if (ArrayBuffer.isView(responseBody)) {
|
|
112
|
+
buffer = responseBody.buffer.slice(responseBody.byteOffset, responseBody.byteOffset + responseBody.byteLength);
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error("Failed to fetch static asset ".concat(url, ": response body is not binary data"));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Some static servers return an HTML fallback page with a successful status and a
|
|
118
|
+
// generic binary content type. Reject it before callers pass those bytes to modules
|
|
119
|
+
// that expect binary data, such as WASM.
|
|
120
|
+
if (looksLikeHtmlDocument(buffer)) {
|
|
121
|
+
throw new Error("Failed to fetch static asset ".concat(url, ": response body looks like an HTML document"));
|
|
122
|
+
}
|
|
123
|
+
return buffer;
|
|
124
|
+
}).catch(function (error) {
|
|
125
|
+
_this2.assets.delete(url);
|
|
126
|
+
throw error;
|
|
127
|
+
});
|
|
128
|
+
this.assets.set(url, asset);
|
|
129
|
+
}
|
|
130
|
+
_t = Uint8Array;
|
|
131
|
+
_context.next = 1;
|
|
132
|
+
return asset;
|
|
133
|
+
case 1:
|
|
134
|
+
_t2 = _context.sent.slice(0);
|
|
135
|
+
return _context.abrupt("return", new _t(_t2));
|
|
136
|
+
case 2:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee, this);
|
|
141
|
+
}));
|
|
142
|
+
function getBytes(_x) {
|
|
143
|
+
return _getBytes.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
return getBytes;
|
|
146
|
+
}())
|
|
147
|
+
}]);
|
|
148
|
+
}(_statelessWebexPlugin.default);
|
|
149
|
+
//# sourceMappingURL=static-asset-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_statelessWebexPlugin","_interopRequireDefault","require","_callSuper","t","o","e","_getPrototypeOf2","default","_possibleConstructorReturn2","_isNativeReflectConstruct","_Reflect$construct","constructor","apply","Boolean","prototype","valueOf","call","looksLikeHtmlDocument","buffer","prefix","TextDecoder","decode","slice","trimStart","startsWith","StaticAssetLoader","exports","_StatelessWebexPlugin","attrs","_this","options","arguments","length","undefined","_classCallCheck2","_defineProperty2","_map","baseUrl","replace","_inherits2","_createClass2","key","value","getUrl","assetName","concat","_getBytes","_asyncToGenerator2","_regenerator","mark","_callee","_this2","url","asset","_t","_t2","wrap","_context","prev","next","assets","get","request","method","uri","responseType","addAuthHeader","headers","trackingid","then","response","_response$headers","_response$headers$con","statusCode","Error","contentType","split","trim","toLowerCase","responseBody","body","ArrayBuffer","isView","byteOffset","byteLength","catch","error","delete","set","Uint8Array","sent","abrupt","stop","getBytes","_x","StatelessWebexPlugin"],"sources":["static-asset-loader.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.\n */\n\n// @ts-ignore\nimport StatelessWebexPlugin from './stateless-webex-plugin';\n\n/**\n * Detects an HTML document prefix in an otherwise successful binary asset response.\n * @param {ArrayBuffer} buffer\n * @returns {boolean}\n */\nfunction looksLikeHtmlDocument(buffer: ArrayBuffer): boolean {\n const prefix = new TextDecoder().decode(buffer.slice(0, 256)).trimStart();\n\n return prefix.startsWith('<');\n}\n\n/**\n * Resolves and downloads static assets for SDK plugins. Requests are shared between callers and\n * cached after a successful response.\n */\nexport default class StaticAssetLoader extends StatelessWebexPlugin {\n private readonly baseUrl: string;\n\n private readonly assets = new Map<string, Promise<ArrayBuffer>>();\n\n /**\n * @param {Object} attrs\n * @param {string} attrs.baseUrl - Base URL for the plugin's static assets.\n * @param {Object} options\n * @param {Object} [options.parent] - The parent Webex SDK instance.\n */\n constructor(attrs: {baseUrl: string}, options: {parent?: any} = {}) {\n super(attrs, options);\n this.baseUrl = attrs.baseUrl.replace(/\\/+$/, ''); // remove trailing slashes\n }\n\n /**\n * Returns the URL for an asset in the configured asset directory.\n * @param {string} assetName\n * @returns {string}\n */\n getUrl(assetName: string): string {\n return `${this.baseUrl}/${assetName.replace(/^\\/+/, '')}`; // regex removes leading slashes from the asset name\n }\n\n /**\n * Downloads an asset as bytes. Failed requests are evicted so a later call can retry.\n * @param {string} assetName\n * @returns {Promise<Uint8Array>}\n */\n async getBytes(assetName: string): Promise<Uint8Array> {\n const url = this.getUrl(assetName);\n let asset = this.assets.get(url);\n\n if (!asset) {\n // @ts-ignore - StatelessWebexPlugin exposes request from the parent Webex instance.\n asset = this.request({\n method: 'GET',\n uri: url,\n responseType: 'buffer',\n // Assets may be hosted on a third-party CDN: never send the user's token, and suppress\n // the SDK's custom headers so the request doesn't trigger a CORS preflight.\n addAuthHeader: false,\n headers: {\n trackingid: null,\n 'spark-user-agent': null,\n 'cisco-no-http-redirect': null,\n },\n })\n .then((response: any) => {\n if (response.statusCode < 200 || response.statusCode >= 300) {\n throw new Error(`Failed to fetch static asset ${url}: HTTP ${response.statusCode}`);\n }\n\n const contentType = response.headers?.['content-type']\n ?.split(';')[0]\n .trim()\n .toLowerCase();\n\n if (contentType === 'text/html' || contentType === 'application/xhtml+xml') {\n throw new Error(\n `Failed to fetch static asset ${url}: unexpected HTML content type \"${contentType}\"`\n );\n }\n\n const responseBody = response.body;\n let buffer: ArrayBuffer;\n\n if (responseBody instanceof ArrayBuffer) {\n buffer = responseBody;\n } else if (ArrayBuffer.isView(responseBody)) {\n buffer = responseBody.buffer.slice(\n responseBody.byteOffset,\n responseBody.byteOffset + responseBody.byteLength\n ) as ArrayBuffer;\n } else {\n throw new Error(\n `Failed to fetch static asset ${url}: response body is not binary data`\n );\n }\n\n // Some static servers return an HTML fallback page with a successful status and a\n // generic binary content type. Reject it before callers pass those bytes to modules\n // that expect binary data, such as WASM.\n if (looksLikeHtmlDocument(buffer)) {\n throw new Error(\n `Failed to fetch static asset ${url}: response body looks like an HTML document`\n );\n }\n\n return buffer;\n })\n .catch((error: Error) => {\n this.assets.delete(url);\n throw error;\n });\n this.assets.set(url, asset);\n }\n\n return new Uint8Array((await asset).slice(0));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAKA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4D,SAAAC,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,CAAAC,OAAA,EAAAH,CAAA,OAAAI,2BAAA,CAAAD,OAAA,EAAAJ,CAAA,EAAAM,yBAAA,KAAAC,kBAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,CAAAC,OAAA,EAAAJ,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAI,0BAAA,cAAAN,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC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AMkC,KAAK;gBACb,CAAC,CAAC;gBACJ,IAAI,CAAC1B,MAAM,CAAC4B,GAAG,CAACpC,GAAG,EAAEC,KAAK,CAAC;cAC7B;cAACC,EAAA,GAEUmC,UAAU;cAAAhC,QAAA,CAAAE,IAAA;cAAA,OAAQN,KAAK;YAAA;cAAAE,GAAA,GAAAE,QAAA,CAAAiC,IAAA,CAAEpE,KAAK,CAAC,CAAC;cAAA,OAAAmC,QAAA,CAAAkC,MAAA,eAAArC,EAAA,CAAAC,GAAA;YAAA;YAAA;cAAA,OAAAE,QAAA,CAAAmC,IAAA;UAAA;QAAA,GAAA1C,OAAA;MAAA,CAC5C;MAAA,SAtEK2C,QAAQA,CAAAC,EAAA;QAAA,OAAAhD,SAAA,CAAAlC,KAAA,OAAAmB,SAAA;MAAA;MAAA,OAAR8D,QAAQ;IAAA;EAAA;AAAA,EA9B+BE,6BAAoB","ignoreList":[]}
|
package/dist/plugins/logger.js
CHANGED
|
@@ -57,7 +57,7 @@ var Logger = _webexPlugin.default.extend({
|
|
|
57
57
|
info: wrapConsoleMethod('info'),
|
|
58
58
|
debug: wrapConsoleMethod('debug'),
|
|
59
59
|
trace: wrapConsoleMethod('trace'),
|
|
60
|
-
version: "3.12.0-next.
|
|
60
|
+
version: "3.12.0-next.64"
|
|
61
61
|
});
|
|
62
62
|
(0, _webexCore.registerPlugin)('logger', Logger);
|
|
63
63
|
var _default = exports.default = Logger;
|
package/dist/webex-core.js
CHANGED
|
@@ -98,7 +98,7 @@ var MAX_FILE_SIZE_IN_MB = 2048;
|
|
|
98
98
|
* @class
|
|
99
99
|
*/
|
|
100
100
|
var WebexCore = _ampersandState.default.extend((_obj = {
|
|
101
|
-
version: "3.12.0-next.
|
|
101
|
+
version: "3.12.0-next.64",
|
|
102
102
|
children: {
|
|
103
103
|
internal: _webexInternalCore.default
|
|
104
104
|
},
|
|
@@ -642,7 +642,7 @@ var WebexCore = _ampersandState.default.extend((_obj = {
|
|
|
642
642
|
});
|
|
643
643
|
}
|
|
644
644
|
}, (0, _applyDecoratedDescriptor2.default)(_obj, "_uploadPhaseUpload", [_common.retry], (0, _getOwnPropertyDescriptor.default)(_obj, "_uploadPhaseUpload"), _obj), _obj));
|
|
645
|
-
WebexCore.version = "3.12.0-next.
|
|
645
|
+
WebexCore.version = "3.12.0-next.64";
|
|
646
646
|
(0, _webexInternalCorePluginMixin.default)(_webexInternalCore.default, _config.default, interceptors);
|
|
647
647
|
(0, _webexCorePluginMixin.default)(WebexCore, _config.default, interceptors);
|
|
648
648
|
var _default = exports.default = WebexCore;
|
package/package.json
CHANGED
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"@sinonjs/fake-timers": "^6.0.1",
|
|
34
34
|
"@webex/babel-config-legacy": "0.0.0",
|
|
35
35
|
"@webex/eslint-config-legacy": "0.0.0",
|
|
36
|
-
"@webex/internal-plugin-device": "3.12.0-next.
|
|
36
|
+
"@webex/internal-plugin-device": "3.12.0-next.59",
|
|
37
37
|
"@webex/jest-config-legacy": "0.0.0",
|
|
38
38
|
"@webex/legacy-tools": "0.0.0",
|
|
39
|
-
"@webex/plugin-logger": "3.12.0-next.
|
|
39
|
+
"@webex/plugin-logger": "3.12.0-next.61",
|
|
40
40
|
"@webex/test-helper-chai": "3.12.0-next.9",
|
|
41
41
|
"@webex/test-helper-make-local-url": "3.12.0-next.9",
|
|
42
42
|
"@webex/test-helper-mocha": "3.12.0-next.9",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"test:style": "eslint ./src/**/*.*",
|
|
74
74
|
"test:unit": "webex-legacy-tools test --unit --runner jest"
|
|
75
75
|
},
|
|
76
|
-
"version": "3.12.0-next.
|
|
76
|
+
"version": "3.12.0-next.64"
|
|
77
77
|
}
|
package/src/index.js
CHANGED
|
@@ -41,6 +41,7 @@ export {default, registerPlugin, registerInternalPlugin} from './webex-core';
|
|
|
41
41
|
export {default as WebexHttpError} from './lib/webex-http-error';
|
|
42
42
|
export {default as StatelessWebexPlugin} from './lib/stateless-webex-plugin';
|
|
43
43
|
export {default as WebexPlugin} from './lib/webex-plugin';
|
|
44
|
+
export {default as StaticAssetLoader} from './lib/static-asset-loader';
|
|
44
45
|
export {default as AuthInterceptor} from './interceptors/auth';
|
|
45
46
|
export {default as CatalogUrlInterceptor} from './interceptors/catalog-url';
|
|
46
47
|
export {default as NetworkTimingInterceptor} from './interceptors/network-timing';
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
export default class StaticAssetLoader extends StatelessWebexPlugin {
|
|
24
|
+
private readonly baseUrl: string;
|
|
25
|
+
|
|
26
|
+
private readonly assets = new Map<string, Promise<ArrayBuffer>>();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {Object} attrs
|
|
30
|
+
* @param {string} attrs.baseUrl - Base URL for the plugin's static assets.
|
|
31
|
+
* @param {Object} options
|
|
32
|
+
* @param {Object} [options.parent] - The parent Webex SDK instance.
|
|
33
|
+
*/
|
|
34
|
+
constructor(attrs: {baseUrl: string}, options: {parent?: any} = {}) {
|
|
35
|
+
super(attrs, options);
|
|
36
|
+
this.baseUrl = attrs.baseUrl.replace(/\/+$/, ''); // remove trailing slashes
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns the URL for an asset in the configured asset directory.
|
|
41
|
+
* @param {string} assetName
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
getUrl(assetName: string): string {
|
|
45
|
+
return `${this.baseUrl}/${assetName.replace(/^\/+/, '')}`; // regex removes leading slashes from the asset name
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Downloads an asset as bytes. Failed requests are evicted so a later call can retry.
|
|
50
|
+
* @param {string} assetName
|
|
51
|
+
* @returns {Promise<Uint8Array>}
|
|
52
|
+
*/
|
|
53
|
+
async getBytes(assetName: string): Promise<Uint8Array> {
|
|
54
|
+
const url = this.getUrl(assetName);
|
|
55
|
+
let asset = this.assets.get(url);
|
|
56
|
+
|
|
57
|
+
if (!asset) {
|
|
58
|
+
// @ts-ignore - StatelessWebexPlugin exposes request from the parent Webex instance.
|
|
59
|
+
asset = this.request({
|
|
60
|
+
method: 'GET',
|
|
61
|
+
uri: url,
|
|
62
|
+
responseType: 'buffer',
|
|
63
|
+
// Assets may be hosted on a third-party CDN: never send the user's token, and suppress
|
|
64
|
+
// the SDK's custom headers so the request doesn't trigger a CORS preflight.
|
|
65
|
+
addAuthHeader: false,
|
|
66
|
+
headers: {
|
|
67
|
+
trackingid: null,
|
|
68
|
+
'spark-user-agent': null,
|
|
69
|
+
'cisco-no-http-redirect': null,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
.then((response: any) => {
|
|
73
|
+
if (response.statusCode < 200 || response.statusCode >= 300) {
|
|
74
|
+
throw new Error(`Failed to fetch static asset ${url}: HTTP ${response.statusCode}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const contentType = response.headers?.['content-type']
|
|
78
|
+
?.split(';')[0]
|
|
79
|
+
.trim()
|
|
80
|
+
.toLowerCase();
|
|
81
|
+
|
|
82
|
+
if (contentType === 'text/html' || contentType === 'application/xhtml+xml') {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Failed to fetch static asset ${url}: unexpected HTML content type "${contentType}"`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const responseBody = response.body;
|
|
89
|
+
let buffer: ArrayBuffer;
|
|
90
|
+
|
|
91
|
+
if (responseBody instanceof ArrayBuffer) {
|
|
92
|
+
buffer = responseBody;
|
|
93
|
+
} else if (ArrayBuffer.isView(responseBody)) {
|
|
94
|
+
buffer = responseBody.buffer.slice(
|
|
95
|
+
responseBody.byteOffset,
|
|
96
|
+
responseBody.byteOffset + responseBody.byteLength
|
|
97
|
+
) as ArrayBuffer;
|
|
98
|
+
} else {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Failed to fetch static asset ${url}: response body is not binary data`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Some static servers return an HTML fallback page with a successful status and a
|
|
105
|
+
// generic binary content type. Reject it before callers pass those bytes to modules
|
|
106
|
+
// that expect binary data, such as WASM.
|
|
107
|
+
if (looksLikeHtmlDocument(buffer)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Failed to fetch static asset ${url}: response body looks like an HTML document`
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return buffer;
|
|
114
|
+
})
|
|
115
|
+
.catch((error: Error) => {
|
|
116
|
+
this.assets.delete(url);
|
|
117
|
+
throw error;
|
|
118
|
+
});
|
|
119
|
+
this.assets.set(url, asset);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return new Uint8Array((await asset).slice(0));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -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
|
+
});
|