@webex/internal-plugin-device 2.59.2 → 2.59.3-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.eslintrc.js +6 -6
  2. package/README.md +80 -80
  3. package/babel.config.js +3 -3
  4. package/dist/config.js +27 -27
  5. package/dist/config.js.map +1 -1
  6. package/dist/constants.js.map +1 -1
  7. package/dist/device.js +226 -226
  8. package/dist/device.js.map +1 -1
  9. package/dist/features/feature-collection.js +14 -14
  10. package/dist/features/feature-collection.js.map +1 -1
  11. package/dist/features/feature-model.js +73 -73
  12. package/dist/features/feature-model.js.map +1 -1
  13. package/dist/features/features-model.js +28 -28
  14. package/dist/features/features-model.js.map +1 -1
  15. package/dist/features/index.js.map +1 -1
  16. package/dist/index.js +4 -4
  17. package/dist/index.js.map +1 -1
  18. package/dist/interceptors/device-url.js +8 -8
  19. package/dist/interceptors/device-url.js.map +1 -1
  20. package/dist/metrics.js.map +1 -1
  21. package/jest.config.js +3 -3
  22. package/package.json +17 -16
  23. package/process +1 -1
  24. package/src/config.js +60 -60
  25. package/src/constants.js +23 -23
  26. package/src/device.js +835 -835
  27. package/src/features/feature-collection.js +30 -30
  28. package/src/features/feature-model.js +189 -189
  29. package/src/features/features-model.js +96 -96
  30. package/src/features/index.js +5 -5
  31. package/src/index.js +29 -29
  32. package/src/interceptors/device-url.js +61 -61
  33. package/src/metrics.js +5 -5
  34. package/test/integration/spec/device.js +904 -904
  35. package/test/integration/spec/webex.js +42 -42
  36. package/test/unit/spec/device.js +409 -409
  37. package/test/unit/spec/features/feature-collection.js +24 -24
  38. package/test/unit/spec/features/feature-model.js +255 -255
  39. package/test/unit/spec/features/features-model.js +97 -97
  40. package/test/unit/spec/interceptors/device-url.js +215 -215
  41. package/test/unit/spec/wdm-dto.json +104 -104
package/src/index.js CHANGED
@@ -1,29 +1,29 @@
1
- // Internal dependencies.
2
- // Need to import metrics plugin for the devices to send metrics on succes/failure registration
3
- import '@webex/internal-plugin-metrics';
4
- import {registerInternalPlugin} from '@webex/webex-core';
5
-
6
- // Plugin dependencies.
7
- import Device from './device';
8
- import {FeatureCollection, FeatureModel, FeaturesModel} from './features/index';
9
- import DeviceUrlInterceptor from './interceptors/device-url';
10
- import * as constants from './constants';
11
- import config from './config';
12
-
13
- registerInternalPlugin('device', Device, {
14
- config,
15
- interceptors: {
16
- DeviceUrlInterceptor: DeviceUrlInterceptor.create,
17
- },
18
- /**
19
- * Unregister the device in the case that the webex instance has logged out.
20
- *
21
- * @returns {Promise<undefined>}
22
- */
23
- onBeforeLogout() {
24
- return this.unregister();
25
- },
26
- });
27
-
28
- export {default} from './device';
29
- export {config, constants, DeviceUrlInterceptor, FeatureCollection, FeatureModel, FeaturesModel};
1
+ // Internal dependencies.
2
+ // Need to import metrics plugin for the devices to send metrics on succes/failure registration
3
+ import '@webex/internal-plugin-metrics';
4
+ import {registerInternalPlugin} from '@webex/webex-core';
5
+
6
+ // Plugin dependencies.
7
+ import Device from './device';
8
+ import {FeatureCollection, FeatureModel, FeaturesModel} from './features/index';
9
+ import DeviceUrlInterceptor from './interceptors/device-url';
10
+ import * as constants from './constants';
11
+ import config from './config';
12
+
13
+ registerInternalPlugin('device', Device, {
14
+ config,
15
+ interceptors: {
16
+ DeviceUrlInterceptor: DeviceUrlInterceptor.create,
17
+ },
18
+ /**
19
+ * Unregister the device in the case that the webex instance has logged out.
20
+ *
21
+ * @returns {Promise<undefined>}
22
+ */
23
+ onBeforeLogout() {
24
+ return this.unregister();
25
+ },
26
+ });
27
+
28
+ export {default} from './device';
29
+ export {config, constants, DeviceUrlInterceptor, FeatureCollection, FeatureModel, FeaturesModel};
@@ -1,61 +1,61 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {Interceptor} from '@webex/http-core';
6
- import {set} from 'lodash';
7
-
8
- import {CISCO_DEVICE_URL} from '../constants';
9
-
10
- /**
11
- * Adds 'cisco-device-url' header, as appropriate, to requests
12
- */
13
- export default class DeviceUrlInterceptor extends Interceptor {
14
- /**
15
- * @returns {DeviceUrlInterceptor}
16
- */
17
- static create() {
18
- /* eslint no-invalid-this: [0] */
19
- return new DeviceUrlInterceptor({webex: this});
20
- }
21
-
22
- /**
23
- * @see Interceptor#onRequest
24
- * @param {Object} options
25
- * @returns {Object}
26
- */
27
- onRequest(options) {
28
- const {headers, service, uri} = options;
29
- const {device, services} = this.webex.internal;
30
-
31
- // Check if header is already set before moving forward
32
- if (!device.url || (headers && CISCO_DEVICE_URL in headers && !!headers[CISCO_DEVICE_URL])) {
33
- return Promise.resolve(options);
34
- }
35
-
36
- // Wait for catalog and service to be defined.
37
- return services
38
- .waitForService({service, url: uri})
39
- .then((url) => {
40
- // Grab the service name with the url returned from waitForService
41
- const {name: serviceName} = services.getServiceFromUrl(url) || {};
42
- const invalidServices = ['idbroker', 'oauth', 'saml'];
43
-
44
- // Check if service is not one of the invalid services
45
- // Assign the url to the device header
46
- if (serviceName && !invalidServices.includes(serviceName)) {
47
- set(options, `headers['${CISCO_DEVICE_URL}']`, device.url);
48
- }
49
-
50
- return options;
51
- })
52
- .catch((error) => {
53
- // Validate that the error came from getServiceFromUrl
54
- if (error.message.match(/was not found after waiting/)) {
55
- return options;
56
- }
57
-
58
- return Promise.reject(error);
59
- });
60
- }
61
- }
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {Interceptor} from '@webex/http-core';
6
+ import {set} from 'lodash';
7
+
8
+ import {CISCO_DEVICE_URL} from '../constants';
9
+
10
+ /**
11
+ * Adds 'cisco-device-url' header, as appropriate, to requests
12
+ */
13
+ export default class DeviceUrlInterceptor extends Interceptor {
14
+ /**
15
+ * @returns {DeviceUrlInterceptor}
16
+ */
17
+ static create() {
18
+ /* eslint no-invalid-this: [0] */
19
+ return new DeviceUrlInterceptor({webex: this});
20
+ }
21
+
22
+ /**
23
+ * @see Interceptor#onRequest
24
+ * @param {Object} options
25
+ * @returns {Object}
26
+ */
27
+ onRequest(options) {
28
+ const {headers, service, uri} = options;
29
+ const {device, services} = this.webex.internal;
30
+
31
+ // Check if header is already set before moving forward
32
+ if (!device.url || (headers && CISCO_DEVICE_URL in headers && !!headers[CISCO_DEVICE_URL])) {
33
+ return Promise.resolve(options);
34
+ }
35
+
36
+ // Wait for catalog and service to be defined.
37
+ return services
38
+ .waitForService({service, url: uri})
39
+ .then((url) => {
40
+ // Grab the service name with the url returned from waitForService
41
+ const {name: serviceName} = services.getServiceFromUrl(url) || {};
42
+ const invalidServices = ['idbroker', 'oauth', 'saml'];
43
+
44
+ // Check if service is not one of the invalid services
45
+ // Assign the url to the device header
46
+ if (serviceName && !invalidServices.includes(serviceName)) {
47
+ set(options, `headers['${CISCO_DEVICE_URL}']`, device.url);
48
+ }
49
+
50
+ return options;
51
+ })
52
+ .catch((error) => {
53
+ // Validate that the error came from getServiceFromUrl
54
+ if (error.message.match(/was not found after waiting/)) {
55
+ return options;
56
+ }
57
+
58
+ return Promise.reject(error);
59
+ });
60
+ }
61
+ }
package/src/metrics.js CHANGED
@@ -1,5 +1,5 @@
1
- // Metric to do with WDM registration
2
- export default {
3
- JS_SDK_WDM_REGISTRATION_SUCCESSFUL: 'JS_SDK_WDM_REGISTRATION_SUCCESSFUL',
4
- JS_SDK_WDM_REGISTRATION_FAILED: 'JS_SDK_WDM_REGISTRATION_FAILED',
5
- };
1
+ // Metric to do with WDM registration
2
+ export default {
3
+ JS_SDK_WDM_REGISTRATION_SUCCESSFUL: 'JS_SDK_WDM_REGISTRATION_SUCCESSFUL',
4
+ JS_SDK_WDM_REGISTRATION_FAILED: 'JS_SDK_WDM_REGISTRATION_FAILED',
5
+ };