@webex/webex-core 3.0.0-beta.2 → 3.0.0-beta.21

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 (184) hide show
  1. package/dist/config.js +1 -11
  2. package/dist/config.js.map +1 -1
  3. package/dist/credentials-config.js +44 -64
  4. package/dist/credentials-config.js.map +1 -1
  5. package/dist/index.js +0 -76
  6. package/dist/index.js.map +1 -1
  7. package/dist/interceptors/auth.js +22 -55
  8. package/dist/interceptors/auth.js.map +1 -1
  9. package/dist/interceptors/default-options.js +0 -20
  10. package/dist/interceptors/default-options.js.map +1 -1
  11. package/dist/interceptors/embargo.js +0 -21
  12. package/dist/interceptors/embargo.js.map +1 -1
  13. package/dist/interceptors/network-timing.js +2 -21
  14. package/dist/interceptors/network-timing.js.map +1 -1
  15. package/dist/interceptors/payload-transformer.js +2 -22
  16. package/dist/interceptors/payload-transformer.js.map +1 -1
  17. package/dist/interceptors/rate-limit.js +25 -57
  18. package/dist/interceptors/rate-limit.js.map +1 -1
  19. package/dist/interceptors/redirect.js +4 -33
  20. package/dist/interceptors/redirect.js.map +1 -1
  21. package/dist/interceptors/request-event.js +3 -30
  22. package/dist/interceptors/request-event.js.map +1 -1
  23. package/dist/interceptors/request-logger.js +1 -30
  24. package/dist/interceptors/request-logger.js.map +1 -1
  25. package/dist/interceptors/request-timing.js +3 -22
  26. package/dist/interceptors/request-timing.js.map +1 -1
  27. package/dist/interceptors/response-logger.js +2 -31
  28. package/dist/interceptors/response-logger.js.map +1 -1
  29. package/dist/interceptors/user-agent.js +2 -29
  30. package/dist/interceptors/user-agent.js.map +1 -1
  31. package/dist/interceptors/webex-tracking-id.js +5 -28
  32. package/dist/interceptors/webex-tracking-id.js.map +1 -1
  33. package/dist/interceptors/webex-user-agent.js +5 -38
  34. package/dist/interceptors/webex-user-agent.js.map +1 -1
  35. package/dist/lib/batcher.js +3 -51
  36. package/dist/lib/batcher.js.map +1 -1
  37. package/dist/lib/credentials/credentials.js +39 -119
  38. package/dist/lib/credentials/credentials.js.map +1 -1
  39. package/dist/lib/credentials/grant-errors.js +0 -49
  40. package/dist/lib/credentials/grant-errors.js.map +1 -1
  41. package/dist/lib/credentials/index.js +1 -13
  42. package/dist/lib/credentials/index.js.map +1 -1
  43. package/dist/lib/credentials/scope.js +1 -7
  44. package/dist/lib/credentials/scope.js.map +1 -1
  45. package/dist/lib/credentials/token-collection.js +1 -7
  46. package/dist/lib/credentials/token-collection.js.map +1 -1
  47. package/dist/lib/credentials/token.js +39 -118
  48. package/dist/lib/credentials/token.js.map +1 -1
  49. package/dist/lib/page.js +13 -26
  50. package/dist/lib/page.js.map +1 -1
  51. package/dist/lib/services/constants.js +0 -2
  52. package/dist/lib/services/constants.js.map +1 -1
  53. package/dist/lib/services/index.js +1 -28
  54. package/dist/lib/services/index.js.map +1 -1
  55. package/dist/lib/services/interceptors/server-error.js +2 -23
  56. package/dist/lib/services/interceptors/server-error.js.map +1 -1
  57. package/dist/lib/services/interceptors/service.js +12 -34
  58. package/dist/lib/services/interceptors/service.js.map +1 -1
  59. package/dist/lib/services/metrics.js +0 -2
  60. package/dist/lib/services/metrics.js.map +1 -1
  61. package/dist/lib/services/service-catalog.js +10 -90
  62. package/dist/lib/services/service-catalog.js.map +1 -1
  63. package/dist/lib/services/service-fed-ramp.js +0 -2
  64. package/dist/lib/services/service-fed-ramp.js.map +1 -1
  65. package/dist/lib/services/service-host.js +47 -62
  66. package/dist/lib/services/service-host.js.map +1 -1
  67. package/dist/lib/services/service-registry.js +78 -90
  68. package/dist/lib/services/service-registry.js.map +1 -1
  69. package/dist/lib/services/service-state.js +3 -15
  70. package/dist/lib/services/service-state.js.map +1 -1
  71. package/dist/lib/services/service-url.js +4 -25
  72. package/dist/lib/services/service-url.js.map +1 -1
  73. package/dist/lib/services/services.js +122 -238
  74. package/dist/lib/services/services.js.map +1 -1
  75. package/dist/lib/stateless-webex-plugin.js +5 -28
  76. package/dist/lib/stateless-webex-plugin.js.map +1 -1
  77. package/dist/lib/storage/decorators.js +19 -62
  78. package/dist/lib/storage/decorators.js.map +1 -1
  79. package/dist/lib/storage/errors.js +0 -23
  80. package/dist/lib/storage/errors.js.map +1 -1
  81. package/dist/lib/storage/index.js +2 -16
  82. package/dist/lib/storage/index.js.map +1 -1
  83. package/dist/lib/storage/make-webex-plugin-store.js +11 -41
  84. package/dist/lib/storage/make-webex-plugin-store.js.map +1 -1
  85. package/dist/lib/storage/make-webex-store.js +8 -30
  86. package/dist/lib/storage/make-webex-store.js.map +1 -1
  87. package/dist/lib/storage/memory-store-adapter.js +1 -19
  88. package/dist/lib/storage/memory-store-adapter.js.map +1 -1
  89. package/dist/lib/webex-core-plugin-mixin.js +9 -29
  90. package/dist/lib/webex-core-plugin-mixin.js.map +1 -1
  91. package/dist/lib/webex-http-error.js +1 -31
  92. package/dist/lib/webex-http-error.js.map +1 -1
  93. package/dist/lib/webex-internal-core-plugin-mixin.js +9 -29
  94. package/dist/lib/webex-internal-core-plugin-mixin.js.map +1 -1
  95. package/dist/lib/webex-plugin.js +6 -40
  96. package/dist/lib/webex-plugin.js.map +1 -1
  97. package/dist/plugins/logger.js +3 -17
  98. package/dist/plugins/logger.js.map +1 -1
  99. package/dist/webex-core.js +79 -203
  100. package/dist/webex-core.js.map +1 -1
  101. package/dist/webex-internal-core.js +0 -10
  102. package/dist/webex-internal-core.js.map +1 -1
  103. package/package.json +14 -14
  104. package/src/config.js +9 -11
  105. package/src/credentials-config.js +110 -72
  106. package/src/index.js +4 -14
  107. package/src/interceptors/auth.js +36 -37
  108. package/src/interceptors/default-options.js +0 -1
  109. package/src/interceptors/embargo.js +1 -1
  110. package/src/interceptors/payload-transformer.js +1 -2
  111. package/src/interceptors/rate-limit.js +8 -5
  112. package/src/interceptors/redirect.js +14 -8
  113. package/src/interceptors/request-event.js +4 -8
  114. package/src/interceptors/request-logger.js +8 -5
  115. package/src/interceptors/response-logger.js +11 -8
  116. package/src/interceptors/user-agent.js +1 -2
  117. package/src/interceptors/webex-user-agent.js +3 -9
  118. package/src/lib/batcher.js +70 -69
  119. package/src/lib/credentials/credentials.js +112 -122
  120. package/src/lib/credentials/grant-errors.js +6 -7
  121. package/src/lib/credentials/index.js +1 -4
  122. package/src/lib/credentials/scope.js +1 -4
  123. package/src/lib/credentials/token-collection.js +1 -1
  124. package/src/lib/credentials/token.js +86 -80
  125. package/src/lib/page.js +10 -11
  126. package/src/lib/services/constants.js +3 -13
  127. package/src/lib/services/index.js +2 -2
  128. package/src/lib/services/interceptors/server-error.js +12 -7
  129. package/src/lib/services/interceptors/service.js +6 -5
  130. package/src/lib/services/metrics.js +1 -1
  131. package/src/lib/services/service-catalog.js +110 -100
  132. package/src/lib/services/service-fed-ramp.js +1 -2
  133. package/src/lib/services/service-host.js +10 -17
  134. package/src/lib/services/service-registry.js +69 -96
  135. package/src/lib/services/service-state.js +4 -6
  136. package/src/lib/services/service-url.js +24 -23
  137. package/src/lib/services/services.js +260 -251
  138. package/src/lib/stateless-webex-plugin.js +4 -2
  139. package/src/lib/storage/decorators.js +68 -66
  140. package/src/lib/storage/index.js +4 -6
  141. package/src/lib/storage/make-webex-plugin-store.js +34 -21
  142. package/src/lib/storage/make-webex-store.js +6 -7
  143. package/src/lib/storage/memory-store-adapter.js +3 -3
  144. package/src/lib/webex-core-plugin-mixin.js +10 -7
  145. package/src/lib/webex-http-error.js +7 -8
  146. package/src/lib/webex-internal-core-plugin-mixin.js +9 -6
  147. package/src/lib/webex-plugin.js +41 -34
  148. package/src/plugins/logger.js +8 -3
  149. package/src/webex-core.js +185 -116
  150. package/src/webex-internal-core.js +15 -9
  151. package/test/integration/spec/credentials/credentials.js +26 -30
  152. package/test/integration/spec/credentials/token.js +36 -33
  153. package/test/integration/spec/services/service-catalog.js +177 -156
  154. package/test/integration/spec/services/services.js +313 -304
  155. package/test/integration/spec/webex-core.js +98 -86
  156. package/test/unit/spec/_setup.js +26 -18
  157. package/test/unit/spec/credentials/credentials.js +189 -154
  158. package/test/unit/spec/credentials/token.js +94 -76
  159. package/test/unit/spec/interceptors/auth.js +291 -243
  160. package/test/unit/spec/interceptors/default-options.js +36 -24
  161. package/test/unit/spec/interceptors/embargo.js +32 -27
  162. package/test/unit/spec/interceptors/network-timing.js +2 -2
  163. package/test/unit/spec/interceptors/payload-transformer.js +61 -52
  164. package/test/unit/spec/interceptors/rate-limit.js +104 -75
  165. package/test/unit/spec/interceptors/redirect.js +22 -20
  166. package/test/unit/spec/interceptors/request-timing.js +18 -22
  167. package/test/unit/spec/interceptors/user-agent.js +28 -16
  168. package/test/unit/spec/interceptors/webex-tracking-id.js +14 -8
  169. package/test/unit/spec/interceptors/webex-user-agent.js +83 -37
  170. package/test/unit/spec/lib/batcher.js +36 -32
  171. package/test/unit/spec/lib/page.js +36 -32
  172. package/test/unit/spec/lib/webex-plugin.js +1 -1
  173. package/test/unit/spec/services/interceptors/server-error.js +67 -90
  174. package/test/unit/spec/services/interceptors/service.js +17 -28
  175. package/test/unit/spec/services/service-catalog.js +19 -27
  176. package/test/unit/spec/services/service-host.js +29 -26
  177. package/test/unit/spec/services/service-registry.js +128 -170
  178. package/test/unit/spec/services/service-state.js +13 -22
  179. package/test/unit/spec/services/service-url.js +24 -43
  180. package/test/unit/spec/services/services.js +85 -41
  181. package/test/unit/spec/storage/persist.js +6 -9
  182. package/test/unit/spec/storage/wait-for-value.js +22 -21
  183. package/test/unit/spec/webex-core.js +78 -57
  184. package/test/unit/spec/webex-internal-core.js +56 -31
@@ -1,55 +1,38 @@
1
1
  "use strict";
2
2
 
3
3
  var _typeof = require("@babel/runtime-corejs2/helpers/typeof");
4
-
5
- var _WeakMap = require("@babel/runtime-corejs2/core-js/weak-map");
6
-
7
- var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
8
-
4
+ var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
5
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
9
6
  var _Object$getOwnPropertyDescriptor2 = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
10
-
7
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
8
+ var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
9
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
10
+ var _WeakMap = require("@babel/runtime-corejs2/core-js/weak-map");
11
11
  var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
12
-
13
12
  _Object$defineProperty(exports, "__esModule", {
14
13
  value: true
15
14
  });
16
-
17
15
  exports.default = void 0;
18
-
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
19
17
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
20
-
21
18
  var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/applyDecoratedDescriptor"));
22
-
23
19
  var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
24
-
25
20
  var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
26
-
27
21
  var _apply = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/reflect/apply"));
28
-
29
22
  var _now = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/date/now"));
30
-
31
23
  var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor"));
32
-
33
24
  var _pick2 = _interopRequireDefault(require("lodash/pick"));
34
-
35
25
  var _common = require("@webex/common");
36
-
37
26
  var _commonTimers = require("@webex/common-timers");
38
-
39
27
  var _webexHttpError = _interopRequireDefault(require("../webex-http-error"));
40
-
41
28
  var _webexPlugin = _interopRequireDefault(require("../webex-plugin"));
42
-
43
29
  var _scope = require("./scope");
44
-
45
30
  var _grantErrors = _interopRequireWildcard(require("./grant-errors"));
46
-
47
31
  var _dec, _obj;
48
-
49
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
50
-
51
33
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor2; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor2(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
52
-
34
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return _Object$getOwnPropertyDescriptor2(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor2(source, key)); }); } return target; }
53
36
  /* eslint-disable camelcase */
54
37
 
55
38
  /**
@@ -62,24 +45,19 @@ function processGrantError(res) {
62
45
  if (res.statusCode !== 400) {
63
46
  return _promise.default.reject(res);
64
47
  }
65
-
66
48
  var ErrorConstructor = _grantErrors.default.select(res.body.error);
67
-
68
49
  if (ErrorConstructor === _grantErrors.OAuthError && res instanceof _webexHttpError.default) {
69
50
  return _promise.default.reject(res);
70
51
  }
71
-
72
52
  if (!ErrorConstructor) {
73
53
  return _promise.default.reject(res);
74
54
  }
75
-
76
55
  return _promise.default.reject(new ErrorConstructor(res._res || res));
77
56
  }
57
+
78
58
  /**
79
59
  * @class
80
60
  */
81
-
82
-
83
61
  var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
84
62
  keyFactory: function keyFactory(scope) {
85
63
  return scope;
@@ -101,7 +79,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
101
79
  return !!this.access_token && !this.isExpired;
102
80
  }
103
81
  },
104
-
105
82
  /**
106
83
  * Indicates that this token can be downscoped. `true` iff
107
84
  * {@link config.credentials.client_id} is defined and if
@@ -122,7 +99,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
122
99
  return this.canAuthorize && !!this.config.client_id;
123
100
  }
124
101
  },
125
-
126
102
  /**
127
103
  * Indicates if this token can be refreshed. `true` iff
128
104
  * {@link Token@refresh_token} is defined and
@@ -143,11 +119,9 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
143
119
  if (_common.inBrowser) {
144
120
  return !!this.refresh_token && !!this.config.refreshCallback;
145
121
  }
146
-
147
122
  return !!this.refresh_token && !!this.config.client_secret;
148
123
  }
149
124
  },
150
-
151
125
  /**
152
126
  * Indicates if this `Token` is expired. `true` iff {@link Token#expires} is
153
127
  * defined and is less than {@link Date.now()}.
@@ -164,7 +138,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
164
138
  return !!this.expires && this._isExpired;
165
139
  }
166
140
  },
167
-
168
141
  /**
169
142
  * Cache for toString()
170
143
  * @instance
@@ -179,7 +152,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
179
152
  if (!this.access_token || !this.token_type) {
180
153
  return '';
181
154
  }
182
-
183
155
  return "".concat(this.token_type, " ").concat(this.access_token);
184
156
  }
185
157
  }
@@ -194,49 +166,42 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
194
166
  * @type {string}
195
167
  */
196
168
  scope: 'string',
197
-
198
169
  /**
199
170
  * @instance
200
171
  * @memberof Token
201
172
  * @type {string}
202
173
  */
203
174
  access_token: 'string',
204
-
205
175
  /**
206
176
  * @instance
207
177
  * @memberof Token
208
178
  * @type {number}
209
179
  */
210
180
  expires: 'number',
211
-
212
181
  /**
213
182
  * @instance
214
183
  * @memberof Token
215
184
  * @type {number}
216
185
  */
217
186
  expires_in: 'number',
218
-
219
187
  /**
220
188
  * @instance
221
189
  * @memberof Token
222
190
  * @type {string}
223
191
  */
224
192
  refresh_token: 'string',
225
-
226
193
  /**
227
194
  * @instance
228
195
  * @memberof Token
229
196
  * @type {number}
230
197
  */
231
198
  refresh_token_expires: 'number',
232
-
233
199
  /**
234
200
  * @instance
235
201
  * @memberof Token
236
202
  * @type {number}
237
203
  */
238
204
  refresh_token_expires_in: 'number',
239
-
240
205
  /**
241
206
  * @default "Bearer"
242
207
  * @instance
@@ -260,7 +225,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
260
225
  default: false,
261
226
  type: 'boolean'
262
227
  },
263
-
264
228
  /**
265
229
  * Handle to the previous token that we'll revoke when we refresh this
266
230
  * token. The idea is to keep allow two valid tokens when a refresh occurs;
@@ -276,7 +240,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
276
240
  type: 'state'
277
241
  }
278
242
  },
279
-
280
243
  /**
281
244
  * Uses this token to request a new Token with a subset of this Token's scopes
282
245
  * @instance
@@ -286,37 +249,32 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
286
249
  */
287
250
  downscope: function downscope(scope) {
288
251
  var _this = this;
289
-
290
252
  this.logger.info("token: downscoping token to ".concat(scope));
291
-
292
253
  if (this.isExpired) {
293
254
  this.logger.info('token: request received to downscope expired access_token');
294
255
  return _promise.default.reject(new Error('cannot downscope expired access token'));
295
256
  }
296
-
297
257
  if (!this.canDownscope) {
298
258
  if (this.config.client_id) {
299
259
  this.logger.info('token: request received to downscope invalid access_token');
300
260
  } else {
301
261
  this.logger.trace('token: cannot downscope without client_id');
302
262
  }
303
-
304
263
  return _promise.default.reject(new Error('cannot downscope access token'));
305
- } // Since we're going to use scope as the index in our token collection, it's
306
- // important scopes are always deterministically specified.
307
-
264
+ }
308
265
 
266
+ // Since we're going to use scope as the index in our token collection, it's
267
+ // important scopes are always deterministically specified.
309
268
  if (scope) {
310
269
  scope = (0, _scope.sortScope)(scope);
311
- } // Ideally, we could depend on the service to communicate this error, but
270
+ }
271
+
272
+ // Ideally, we could depend on the service to communicate this error, but
312
273
  // all we get is "invalid scope", which, to the lay person, implies
313
274
  // something wrong with *one* of the scopes, not the whole thing.
314
-
315
-
316
275
  if (scope === (0, _scope.sortScope)(this.config.scope)) {
317
276
  return _promise.default.reject(new Error('token: scope reduction requires a reduced scope'));
318
277
  }
319
-
320
278
  return this.webex.request({
321
279
  method: 'POST',
322
280
  uri: this.config.tokenUrl,
@@ -330,7 +288,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
330
288
  }
331
289
  }).then(function (res) {
332
290
  _this.logger.info("token: downscoped token to ".concat(scope));
333
-
334
291
  return new Token((0, _assign.default)(res.body, {
335
292
  scope: scope
336
293
  }), {
@@ -338,7 +295,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
338
295
  });
339
296
  });
340
297
  },
341
-
342
298
  /**
343
299
  * Initializer
344
300
  * @instance
@@ -350,21 +306,18 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
350
306
  */
351
307
  initialize: function initialize() {
352
308
  var _this2 = this;
353
-
354
309
  var attrs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
355
310
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
356
311
  (0, _apply.default)(_webexPlugin.default.prototype.initialize, this, [attrs, options]);
357
-
358
312
  if (typeof attrs === 'string') {
359
313
  this.access_token = attrs;
360
314
  }
361
-
362
315
  if (!this.access_token) {
363
316
  throw new Error('`access_token` is required');
364
- } // We don't want the derived property `isExpired` to need {cache:false}, so
365
- // we'll set up a timer the runs when this token should expire.
366
-
317
+ }
367
318
 
319
+ // We don't want the derived property `isExpired` to need {cache:false}, so
320
+ // we'll set up a timer the runs when this token should expire.
368
321
  if (this.expires) {
369
322
  if (this.expires < (0, _now.default)()) {
370
323
  this._isExpired = true;
@@ -375,7 +328,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
375
328
  }
376
329
  }
377
330
  },
378
-
379
331
  /**
380
332
  * Refreshes this Token. Relies on
381
333
  * {@link config.credentials.refreshCallback()}
@@ -385,21 +337,16 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
385
337
  */
386
338
  refresh: function refresh() {
387
339
  var _this3 = this;
388
-
389
340
  if (!this.canRefresh) {
390
341
  throw new Error('Not enough information available to refresh this access token');
391
342
  }
392
-
393
343
  var promise;
394
-
395
344
  if (_common.inBrowser) {
396
345
  if (!this.config.refreshCallback) {
397
346
  throw new Error('Cannot refresh access token without refreshCallback');
398
347
  }
399
-
400
348
  promise = _promise.default.resolve(this.config.refreshCallback(this.webex, this));
401
349
  }
402
-
403
350
  return (promise || this.webex.request({
404
351
  method: 'POST',
405
352
  uri: this.config.tokenUrl,
@@ -419,36 +366,29 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
419
366
  })).then(function (obj) {
420
367
  if (!obj) {
421
368
  throw new Error('token: refreshCallback() did not produce an object');
422
- } // If the authentication server did not send back a refresh token, copy
369
+ }
370
+ // If the authentication server did not send back a refresh token, copy
423
371
  // the current refresh token and related values to the response (note:
424
372
  // at time of implementation, CI never sends a new refresh token)
425
-
426
-
427
373
  if (!obj.refresh_token) {
428
374
  (0, _assign.default)(obj, (0, _pick2.default)(_this3, 'refresh_token', 'refresh_token_expires', 'refresh_token_expires_in'));
429
- } // If the new token is the same as the previous token, then we may have
430
- // found a bug in CI; log the details and reject the Promise
431
-
375
+ }
432
376
 
377
+ // If the new token is the same as the previous token, then we may have
378
+ // found a bug in CI; log the details and reject the Promise
433
379
  if (_this3.access_token === obj.access_token) {
434
- _this3.logger.error('token: new token matches current token'); // log the tokens if it is not production
435
-
436
-
380
+ _this3.logger.error('token: new token matches current token');
381
+ // log the tokens if it is not production
437
382
  if (process.env.NODE_ENV !== 'production') {
438
383
  _this3.logger.error('token: current token:', _this3.access_token);
439
-
440
384
  _this3.logger.error('token: new token:', obj.access_token);
441
385
  }
442
-
443
386
  return _promise.default.reject(new Error('new token matches current token'));
444
387
  }
445
-
446
388
  if (_this3.previousToken) {
447
389
  _this3.previousToken.revoke();
448
-
449
390
  _this3.unset('previousToken');
450
391
  }
451
-
452
392
  obj.previousToken = _this3;
453
393
  obj.scope = _this3.scope;
454
394
  return new Token(obj, {
@@ -456,7 +396,6 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
456
396
  });
457
397
  }).catch(processGrantError);
458
398
  },
459
-
460
399
  /**
461
400
  * Revokes this token and unsets its local properties
462
401
  * @instance
@@ -465,28 +404,25 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
465
404
  */
466
405
  revoke: function revoke() {
467
406
  var _this4 = this;
468
-
469
407
  if (this.isExpired) {
470
408
  this.logger.info('token: already expired, not making making revocation request');
471
409
  return _promise.default.resolve();
472
410
  }
473
-
474
411
  if (!this.canAuthorize) {
475
412
  this.logger.info('token: no longer valid, not making revocation request');
476
413
  return _promise.default.resolve();
477
- } // FIXME we need to use the user token revocation endpoint to revoke a token
414
+ }
415
+
416
+ // FIXME we need to use the user token revocation endpoint to revoke a token
478
417
  // without a client_secret, but it doesn't current support using a token to
479
418
  // revoke itself
480
419
  // Note: I'm not making a canRevoke property because there should be changes
481
420
  // coming to the user token revocation endpoint that allow us to do this
482
421
  // correctly.
483
-
484
-
485
422
  if (!this.config.client_secret) {
486
423
  this.logger.info('token: no client secret available, not making revocation request');
487
424
  return _promise.default.resolve();
488
425
  }
489
-
490
426
  this.logger.info('token: revoking access token');
491
427
  return this.webex.request({
492
428
  method: 'POST',
@@ -503,46 +439,37 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
503
439
  shouldRefreshAccessToken: false
504
440
  }).then(function () {
505
441
  _this4.unset(['access_token', 'expires', 'expires_in', 'token_type']);
506
-
507
442
  _this4.logger.info('token: access token revoked');
508
443
  }).catch(processGrantError);
509
444
  },
510
445
  set: function set() {
511
446
  // eslint-disable-next-line prefer-const
512
447
  var _this$_filterSetParam = this._filterSetParameters.apply(this, arguments),
513
- _this$_filterSetParam2 = (0, _slicedToArray2.default)(_this$_filterSetParam, 2),
514
- attrs = _this$_filterSetParam2[0],
515
- options = _this$_filterSetParam2[1];
516
-
448
+ _this$_filterSetParam2 = (0, _slicedToArray2.default)(_this$_filterSetParam, 2),
449
+ attrs = _this$_filterSetParam2[0],
450
+ options = _this$_filterSetParam2[1];
517
451
  if (!attrs.token_type && attrs.access_token && attrs.access_token.includes(' ')) {
518
452
  var _attrs$access_token$s = attrs.access_token.split(' '),
519
- _attrs$access_token$s2 = (0, _slicedToArray2.default)(_attrs$access_token$s, 2),
520
- token_type = _attrs$access_token$s2[0],
521
- access_token = _attrs$access_token$s2[1];
522
-
523
- attrs = (0, _assign.default)({}, attrs, {
453
+ _attrs$access_token$s2 = (0, _slicedToArray2.default)(_attrs$access_token$s, 2),
454
+ token_type = _attrs$access_token$s2[0],
455
+ access_token = _attrs$access_token$s2[1];
456
+ attrs = _objectSpread(_objectSpread({}, attrs), {}, {
524
457
  access_token: access_token,
525
458
  token_type: token_type
526
459
  });
527
460
  }
528
-
529
461
  var now = (0, _now.default)();
530
-
531
462
  if (!attrs.expires && attrs.expires_in) {
532
463
  attrs.expires = now + attrs.expires_in * 1000;
533
464
  }
534
-
535
465
  if (!attrs.refresh_token_expires && attrs.refresh_token_expires_in) {
536
466
  attrs.refresh_token_expires = now + attrs.refresh_token_expires_in * 1000;
537
467
  }
538
-
539
468
  if (attrs.scope) {
540
469
  attrs.scope = (0, _scope.sortScope)(attrs.scope);
541
470
  }
542
-
543
471
  return (0, _apply.default)(_webexPlugin.default.prototype.set, this, [attrs, options]);
544
472
  },
545
-
546
473
  /**
547
474
  * Renders the token object as an HTTP Header Value
548
475
  * @instance
@@ -554,10 +481,8 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
554
481
  if (!this._string) {
555
482
  throw new Error('cannot stringify Token');
556
483
  }
557
-
558
484
  return this._string;
559
485
  },
560
-
561
486
  /**
562
487
  * Uses a non-producation api to return information about this token. This
563
488
  * method is primarily for tests and will throw if NODE_ENV === production
@@ -568,11 +493,9 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
568
493
  */
569
494
  validate: function validate() {
570
495
  var _this5 = this;
571
-
572
496
  if (process.env.NODE_ENV === 'production') {
573
497
  throw new Error('Token#validate() must not be used in production');
574
498
  }
575
-
576
499
  return this.webex.request({
577
500
  method: 'POST',
578
501
  service: 'conversation',
@@ -584,12 +507,11 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
584
507
  if ('statusCode' in reason) {
585
508
  return _promise.default.reject(reason);
586
509
  }
510
+ _this5.logger.info("REMINDER: If you're investigating a network error here, it's normal");
587
511
 
588
- _this5.logger.info('REMINDER: If you\'re investigating a network error here, it\'s normal'); // If we got an error that isn't a WebexHttpError, assume the problem is
512
+ // If we got an error that isn't a WebexHttpError, assume the problem is
589
513
  // that we don't have the wdm plugin loaded and service/resource isn't
590
514
  // a valid means of identifying a request.
591
-
592
-
593
515
  var convApi = process.env.CONVERSATION_SERVICE || process.env.CONVERSATION_SERVICE_URL || 'https://conv-a.wbx2.com/conversation/api/v1';
594
516
  return _this5.webex.request({
595
517
  method: 'POST',
@@ -605,9 +527,8 @@ var Token = _webexPlugin.default.extend((_dec = (0, _common.oneFlight)({
605
527
  return res.body;
606
528
  });
607
529
  },
608
- version: "3.0.0-beta.2"
530
+ version: "3.0.0-beta.21"
609
531
  }, ((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)));
610
-
611
532
  var _default = Token;
612
533
  exports.default = _default;
613
534
  //# sourceMappingURL=token.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["processGrantError","res","statusCode","reject","ErrorConstructor","grantErrors","select","body","error","OAuthError","WebexHttpError","_res","Token","WebexPlugin","extend","oneFlight","keyFactory","scope","derived","canAuthorize","deps","fn","access_token","isExpired","canDownscope","config","client_id","canRefresh","inBrowser","refresh_token","refreshCallback","client_secret","expires","_isExpired","_string","token_type","namespace","props","expires_in","refresh_token_expires","refresh_token_expires_in","default","type","session","previousToken","downscope","logger","info","Error","trace","sortScope","webex","request","method","uri","tokenUrl","addAuthHeader","form","grant_type","token","self_contained_token","then","parent","initialize","attrs","options","prototype","safeSetTimeout","refresh","promise","resolve","redirect_uri","auth","user","pass","sendImmediately","shouldRefreshAccessToken","obj","process","env","NODE_ENV","revoke","unset","catch","revokeUrl","token_type_hint","set","_filterSetParameters","includes","split","now","toString","validate","service","resource","reason","convApi","CONVERSATION_SERVICE","CONVERSATION_SERVICE_URL","headers","authorization"],"sources":["token.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {pick} from 'lodash';\nimport {inBrowser, oneFlight} from '@webex/common';\nimport {safeSetTimeout} from '@webex/common-timers';\n\nimport WebexHttpError from '../webex-http-error';\nimport WebexPlugin from '../webex-plugin';\n\nimport {sortScope} from './scope';\nimport grantErrors, {OAuthError} from './grant-errors';\n\n/* eslint-disable camelcase */\n\n/**\n * Parse response from CI and converts to structured error when appropriate\n * @param {WebexHttpError} res\n * @private\n * @returns {GrantError}\n */\nfunction processGrantError(res) {\n if (res.statusCode !== 400) {\n return Promise.reject(res);\n }\n\n const ErrorConstructor = grantErrors.select(res.body.error);\n\n if (ErrorConstructor === OAuthError && res instanceof WebexHttpError) {\n return Promise.reject(res);\n }\n if (!ErrorConstructor) {\n return Promise.reject(res);\n }\n\n return Promise.reject(new ErrorConstructor(res._res || res));\n}\n\n/**\n * @class\n */\nconst Token = WebexPlugin.extend({\n derived: {\n /**\n * Indicates if this token can be used in an auth header. `true` iff\n * {@link Token#access_token} is defined and {@link Token#isExpired} is\n * false.\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canAuthorize: {\n deps: ['access_token', 'isExpired'],\n fn() {\n return !!this.access_token && !this.isExpired;\n }\n },\n\n /**\n * Indicates that this token can be downscoped. `true` iff\n * {@link config.credentials.client_id} is defined and if\n * {@link Token#canAuthorize} is true\n *\n * Note: since {@link config} is not evented, we can't listen for changes to\n * {@link config.credentials.client_id}. As such,\n * {@link config.credentials.client_id} must always be set before\n * instantiating a {@link Token}\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canDownscope: {\n deps: ['canAuthorize'],\n fn() {\n return this.canAuthorize && !!this.config.client_id;\n }\n },\n\n /**\n * Indicates if this token can be refreshed. `true` iff\n * {@link Token@refresh_token} is defined and\n * {@link config.credentials.refreshCallback()} is defined\n *\n * Note: since {@link config} is not evented, we can't listen for changes to\n * {@link config.credentials.refreshCallback()}. As such,\n * {@link config.credentials.refreshCallback()} must always be set before\n * instantiating a {@link Token}\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canRefresh: {\n deps: ['refresh_token'],\n fn() {\n if (inBrowser) {\n return !!this.refresh_token && !!this.config.refreshCallback;\n }\n\n return !!this.refresh_token && !!this.config.client_secret;\n }\n },\n\n /**\n * Indicates if this `Token` is expired. `true` iff {@link Token#expires} is\n * defined and is less than {@link Date.now()}.\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n isExpired: {\n deps: ['expires', '_isExpired'],\n fn() {\n // in order to avoid setting `cache:false`, we'll use a private property\n // and a timer rather than comparing to `Date.now()`;\n return !!this.expires && this._isExpired;\n }\n },\n\n /**\n * Cache for toString()\n * @instance\n * @memberof Token\n * @private\n * @readonly\n * @type {string}\n */\n _string: {\n deps: ['access_token', 'token_type'],\n fn() {\n if (!this.access_token || !this.token_type) {\n return '';\n }\n\n return `${this.token_type} ${this.access_token}`;\n }\n }\n },\n\n namespace: 'Credentials',\n\n props: {\n /**\n * Used for indexing in the credentials userTokens collection\n * @instance\n * @memberof Token\n * @private\n * @type {string}\n */\n scope: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {string}\n */\n access_token: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n expires: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n expires_in: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {string}\n */\n refresh_token: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n refresh_token_expires: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n refresh_token_expires_in: 'number',\n /**\n * @default \"Bearer\"\n * @instance\n * @memberof Token\n * @type {string}\n */\n token_type: {\n default: 'Bearer',\n type: 'string'\n }\n },\n\n session: {\n /**\n * Used by {@link Token#isExpired} to avoid doing a Date comparison.\n * @instance\n * @memberof Token\n * @private\n * @type {boolean}\n */\n _isExpired: {\n default: false,\n type: 'boolean'\n },\n /**\n * Handle to the previous token that we'll revoke when we refresh this\n * token. The idea is to keep allow two valid tokens when a refresh occurs;\n * we don't want revoke a token that's in the middle of being used, so when\n * we do a token refresh, we won't revoke the token being refreshed, but\n * we'll revoke the previous one.\n * @instance\n * @memberof Token\n * @private\n * @type {Object}\n */\n previousToken: {\n type: 'state'\n }\n },\n\n @oneFlight({\n keyFactory(scope) {\n return scope;\n }\n })\n /**\n * Uses this token to request a new Token with a subset of this Token's scopes\n * @instance\n * @memberof Token\n * @param {string} scope\n * @returns {Promise<Token>}\n */\n downscope(scope) {\n this.logger.info(`token: downscoping token to ${scope}`);\n\n if (this.isExpired) {\n this.logger.info('token: request received to downscope expired access_token');\n\n return Promise.reject(new Error('cannot downscope expired access token'));\n }\n\n if (!this.canDownscope) {\n if (this.config.client_id) {\n this.logger.info('token: request received to downscope invalid access_token');\n }\n else {\n this.logger.trace('token: cannot downscope without client_id');\n }\n\n return Promise.reject(new Error('cannot downscope access token'));\n }\n\n // Since we're going to use scope as the index in our token collection, it's\n // important scopes are always deterministically specified.\n if (scope) {\n scope = sortScope(scope);\n }\n\n // Ideally, we could depend on the service to communicate this error, but\n // all we get is \"invalid scope\", which, to the lay person, implies\n // something wrong with *one* of the scopes, not the whole thing.\n if (scope === sortScope(this.config.scope)) {\n return Promise.reject(new Error('token: scope reduction requires a reduced scope'));\n }\n\n return this.webex.request({\n method: 'POST',\n uri: this.config.tokenUrl,\n addAuthHeader: false,\n form: {\n grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',\n token: this.access_token,\n scope,\n client_id: this.config.client_id,\n self_contained_token: true\n }\n })\n .then((res) => {\n this.logger.info(`token: downscoped token to ${scope}`);\n\n return new Token(Object.assign(res.body, {scope}), {parent: this.parent});\n });\n },\n\n /**\n * Initializer\n * @instance\n * @memberof Token\n * @param {Object} [attrs={}]\n * @param {Object} [options={}]\n * @see {@link WebexPlugin#initialize()}\n * @returns {Token}\n */\n initialize(attrs = {}, options = {}) {\n Reflect.apply(WebexPlugin.prototype.initialize, this, [attrs, options]);\n\n if (typeof attrs === 'string') {\n this.access_token = attrs;\n }\n\n if (!this.access_token) {\n throw new Error('`access_token` is required');\n }\n\n // We don't want the derived property `isExpired` to need {cache:false}, so\n // we'll set up a timer the runs when this token should expire.\n if (this.expires) {\n if (this.expires < Date.now()) {\n this._isExpired = true;\n }\n else {\n safeSetTimeout(() => {\n this._isExpired = true;\n }, this.expires - Date.now());\n }\n }\n },\n\n @oneFlight\n /**\n * Refreshes this Token. Relies on\n * {@link config.credentials.refreshCallback()}\n * @instance\n * @memberof Token\n * @returns {Promise<Token>}\n */\n refresh() {\n if (!this.canRefresh) {\n throw new Error('Not enough information available to refresh this access token');\n }\n\n let promise;\n\n if (inBrowser) {\n if (!this.config.refreshCallback) {\n throw new Error('Cannot refresh access token without refreshCallback');\n }\n\n promise = Promise.resolve(this.config.refreshCallback(this.webex, this));\n }\n\n return (promise || this.webex.request({\n method: 'POST',\n uri: this.config.tokenUrl,\n form: {\n grant_type: 'refresh_token',\n redirect_uri: this.config.redirect_uri,\n refresh_token: this.refresh_token\n },\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true\n },\n shouldRefreshAccessToken: false\n })\n .then((res) => res.body))\n .then((obj) => {\n if (!obj) {\n throw new Error('token: refreshCallback() did not produce an object');\n }\n // If the authentication server did not send back a refresh token, copy\n // the current refresh token and related values to the response (note:\n // at time of implementation, CI never sends a new refresh token)\n if (!obj.refresh_token) {\n Object.assign(obj, pick(this, 'refresh_token', 'refresh_token_expires', 'refresh_token_expires_in'));\n }\n\n // If the new token is the same as the previous token, then we may have\n // found a bug in CI; log the details and reject the Promise\n if (this.access_token === obj.access_token) {\n this.logger.error('token: new token matches current token');\n // log the tokens if it is not production\n if (process.env.NODE_ENV !== 'production') {\n this.logger.error('token: current token:', this.access_token);\n this.logger.error('token: new token:', obj.access_token);\n }\n\n return Promise.reject(new Error('new token matches current token'));\n }\n\n if (this.previousToken) {\n this.previousToken.revoke();\n this.unset('previousToken');\n }\n\n obj.previousToken = this;\n obj.scope = this.scope;\n\n return new Token(obj, {parent: this.parent});\n })\n .catch(processGrantError);\n },\n\n @oneFlight\n /**\n * Revokes this token and unsets its local properties\n * @instance\n * @memberof Token\n * @returns {Promise}\n */\n revoke() {\n if (this.isExpired) {\n this.logger.info('token: already expired, not making making revocation request');\n\n return Promise.resolve();\n }\n\n if (!this.canAuthorize) {\n this.logger.info('token: no longer valid, not making revocation request');\n\n return Promise.resolve();\n }\n\n // FIXME we need to use the user token revocation endpoint to revoke a token\n // without a client_secret, but it doesn't current support using a token to\n // revoke itself\n // Note: I'm not making a canRevoke property because there should be changes\n // coming to the user token revocation endpoint that allow us to do this\n // correctly.\n if (!this.config.client_secret) {\n this.logger.info('token: no client secret available, not making revocation request');\n\n return Promise.resolve();\n }\n\n this.logger.info('token: revoking access token');\n\n return this.webex.request({\n method: 'POST',\n uri: this.config.revokeUrl,\n form: {\n token: this.access_token,\n token_type_hint: 'access_token'\n },\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true\n },\n shouldRefreshAccessToken: false\n })\n .then(() => {\n this.unset([\n 'access_token',\n 'expires',\n 'expires_in',\n 'token_type'\n ]);\n this.logger.info('token: access token revoked');\n })\n .catch(processGrantError);\n },\n\n set(...args) {\n // eslint-disable-next-line prefer-const\n let [attrs, options] = this._filterSetParameters(...args);\n\n if (!attrs.token_type && attrs.access_token && attrs.access_token.includes(' ')) {\n const [token_type, access_token] = attrs.access_token.split(' ');\n\n attrs = Object.assign({}, attrs, {access_token, token_type});\n }\n const now = Date.now();\n\n if (!attrs.expires && attrs.expires_in) {\n attrs.expires = now + attrs.expires_in * 1000;\n }\n\n if (!attrs.refresh_token_expires && attrs.refresh_token_expires_in) {\n attrs.refresh_token_expires = now + attrs.refresh_token_expires_in * 1000;\n }\n\n if (attrs.scope) {\n attrs.scope = sortScope(attrs.scope);\n }\n\n return Reflect.apply(WebexPlugin.prototype.set, this, [attrs, options]);\n },\n\n /**\n * Renders the token object as an HTTP Header Value\n * @instance\n * @memberof Token\n * @returns {string}\n * @see {@link Object#toString()}\n */\n toString() {\n if (!this._string) {\n throw new Error('cannot stringify Token');\n }\n\n return this._string;\n },\n\n /**\n * Uses a non-producation api to return information about this token. This\n * method is primarily for tests and will throw if NODE_ENV === production\n * @instance\n * @memberof Token\n * @private\n * @returns {Promise}\n */\n validate() {\n if (process.env.NODE_ENV === 'production') {\n throw new Error('Token#validate() must not be used in production');\n }\n\n return this.webex.request({\n method: 'POST',\n service: 'conversation',\n resource: 'users/validateAuthToken',\n body: {\n token: this.access_token\n }\n })\n .catch((reason) => {\n if ('statusCode' in reason) {\n return Promise.reject(reason);\n }\n this.logger.info('REMINDER: If you\\'re investigating a network error here, it\\'s normal');\n\n // If we got an error that isn't a WebexHttpError, assume the problem is\n // that we don't have the wdm plugin loaded and service/resource isn't\n // a valid means of identifying a request.\n const convApi = process.env.CONVERSATION_SERVICE || process.env.CONVERSATION_SERVICE_URL || 'https://conv-a.wbx2.com/conversation/api/v1';\n\n return this.webex.request({\n method: 'POST',\n uri: `${convApi}/users/validateAuthToken`,\n body: {\n token: this.access_token\n },\n headers: {\n authorization: `Bearer ${this.access_token}`\n }\n });\n })\n .then((res) => res.body);\n }\n});\n\nexport default Token;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;;;;;;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAT,CAA2BC,GAA3B,EAAgC;EAC9B,IAAIA,GAAG,CAACC,UAAJ,KAAmB,GAAvB,EAA4B;IAC1B,OAAO,iBAAQC,MAAR,CAAeF,GAAf,CAAP;EACD;;EAED,IAAMG,gBAAgB,GAAGC,oBAAA,CAAYC,MAAZ,CAAmBL,GAAG,CAACM,IAAJ,CAASC,KAA5B,CAAzB;;EAEA,IAAIJ,gBAAgB,KAAKK,uBAArB,IAAmCR,GAAG,YAAYS,uBAAtD,EAAsE;IACpE,OAAO,iBAAQP,MAAR,CAAeF,GAAf,CAAP;EACD;;EACD,IAAI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B;QAC1B,OAAO,iBAAQ5F,MAAR,CAAe4F,MAAf,CAAP;MACD;;MACD,MAAI,CAACjD,MAAL,CAAYC,IAAZ,CAAiB,uEAAjB,EAJiB,CAMjB;MACA;MACA;;;MACA,IAAMiD,OAAO,GAAGlB,OAAO,CAACC,GAAR,CAAYkB,oBAAZ,IAAoCnB,OAAO,CAACC,GAAR,CAAYmB,wBAAhD,IAA4E,6CAA5F;MAEA,OAAO,MAAI,CAAC/C,KAAL,CAAWC,OAAX,CAAmB;QACxBC,MAAM,EAAE,MADgB;QAExBC,GAAG,YAAK0C,OAAL,6BAFqB;QAGxBzF,IAAI,EAAE;UACJoD,KAAK,EAAE,MAAI,CAACrC;QADR,CAHkB;QAMxB6E,OAAO,EAAE;UACPC,aAAa,mBAAY,MAAI,CAAC9E,YAAjB;QADN;MANe,CAAnB,CAAP;IAUD,CA7BI,EA8BJuC,IA9BI,CA8BC,UAAC5D,GAAD;MAAA,OAASA,GAAG,CAACM,IAAb;IAAA,CA9BD,CAAP;EA+BD,CA3f8B;EAAA;AAAA,CAAnB,kMA8RXQ,iBA9RW,4HA0WXA,iBA1WW,0EAAd;;eA8feH,K"}
1
+ {"version":3,"names":["processGrantError","res","statusCode","reject","ErrorConstructor","grantErrors","select","body","error","OAuthError","WebexHttpError","_res","Token","WebexPlugin","extend","oneFlight","keyFactory","scope","derived","canAuthorize","deps","fn","access_token","isExpired","canDownscope","config","client_id","canRefresh","inBrowser","refresh_token","refreshCallback","client_secret","expires","_isExpired","_string","token_type","namespace","props","expires_in","refresh_token_expires","refresh_token_expires_in","default","type","session","previousToken","downscope","logger","info","Error","trace","sortScope","webex","request","method","uri","tokenUrl","addAuthHeader","form","grant_type","token","self_contained_token","then","parent","initialize","attrs","options","prototype","safeSetTimeout","refresh","promise","resolve","redirect_uri","auth","user","pass","sendImmediately","shouldRefreshAccessToken","obj","process","env","NODE_ENV","revoke","unset","catch","revokeUrl","token_type_hint","set","_filterSetParameters","includes","split","now","toString","validate","service","resource","reason","convApi","CONVERSATION_SERVICE","CONVERSATION_SERVICE_URL","headers","authorization"],"sources":["token.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {pick} from 'lodash';\nimport {inBrowser, oneFlight} from '@webex/common';\nimport {safeSetTimeout} from '@webex/common-timers';\n\nimport WebexHttpError from '../webex-http-error';\nimport WebexPlugin from '../webex-plugin';\n\nimport {sortScope} from './scope';\nimport grantErrors, {OAuthError} from './grant-errors';\n\n/* eslint-disable camelcase */\n\n/**\n * Parse response from CI and converts to structured error when appropriate\n * @param {WebexHttpError} res\n * @private\n * @returns {GrantError}\n */\nfunction processGrantError(res) {\n if (res.statusCode !== 400) {\n return Promise.reject(res);\n }\n\n const ErrorConstructor = grantErrors.select(res.body.error);\n\n if (ErrorConstructor === OAuthError && res instanceof WebexHttpError) {\n return Promise.reject(res);\n }\n if (!ErrorConstructor) {\n return Promise.reject(res);\n }\n\n return Promise.reject(new ErrorConstructor(res._res || res));\n}\n\n/**\n * @class\n */\nconst Token = WebexPlugin.extend({\n derived: {\n /**\n * Indicates if this token can be used in an auth header. `true` iff\n * {@link Token#access_token} is defined and {@link Token#isExpired} is\n * false.\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canAuthorize: {\n deps: ['access_token', 'isExpired'],\n fn() {\n return !!this.access_token && !this.isExpired;\n },\n },\n\n /**\n * Indicates that this token can be downscoped. `true` iff\n * {@link config.credentials.client_id} is defined and if\n * {@link Token#canAuthorize} is true\n *\n * Note: since {@link config} is not evented, we can't listen for changes to\n * {@link config.credentials.client_id}. As such,\n * {@link config.credentials.client_id} must always be set before\n * instantiating a {@link Token}\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canDownscope: {\n deps: ['canAuthorize'],\n fn() {\n return this.canAuthorize && !!this.config.client_id;\n },\n },\n\n /**\n * Indicates if this token can be refreshed. `true` iff\n * {@link Token@refresh_token} is defined and\n * {@link config.credentials.refreshCallback()} is defined\n *\n * Note: since {@link config} is not evented, we can't listen for changes to\n * {@link config.credentials.refreshCallback()}. As such,\n * {@link config.credentials.refreshCallback()} must always be set before\n * instantiating a {@link Token}\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n canRefresh: {\n deps: ['refresh_token'],\n fn() {\n if (inBrowser) {\n return !!this.refresh_token && !!this.config.refreshCallback;\n }\n\n return !!this.refresh_token && !!this.config.client_secret;\n },\n },\n\n /**\n * Indicates if this `Token` is expired. `true` iff {@link Token#expires} is\n * defined and is less than {@link Date.now()}.\n * @instance\n * @memberof Token\n * @readonly\n * @type {boolean}\n */\n isExpired: {\n deps: ['expires', '_isExpired'],\n fn() {\n // in order to avoid setting `cache:false`, we'll use a private property\n // and a timer rather than comparing to `Date.now()`;\n return !!this.expires && this._isExpired;\n },\n },\n\n /**\n * Cache for toString()\n * @instance\n * @memberof Token\n * @private\n * @readonly\n * @type {string}\n */\n _string: {\n deps: ['access_token', 'token_type'],\n fn() {\n if (!this.access_token || !this.token_type) {\n return '';\n }\n\n return `${this.token_type} ${this.access_token}`;\n },\n },\n },\n\n namespace: 'Credentials',\n\n props: {\n /**\n * Used for indexing in the credentials userTokens collection\n * @instance\n * @memberof Token\n * @private\n * @type {string}\n */\n scope: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {string}\n */\n access_token: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n expires: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n expires_in: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {string}\n */\n refresh_token: 'string',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n refresh_token_expires: 'number',\n /**\n * @instance\n * @memberof Token\n * @type {number}\n */\n refresh_token_expires_in: 'number',\n /**\n * @default \"Bearer\"\n * @instance\n * @memberof Token\n * @type {string}\n */\n token_type: {\n default: 'Bearer',\n type: 'string',\n },\n },\n\n session: {\n /**\n * Used by {@link Token#isExpired} to avoid doing a Date comparison.\n * @instance\n * @memberof Token\n * @private\n * @type {boolean}\n */\n _isExpired: {\n default: false,\n type: 'boolean',\n },\n /**\n * Handle to the previous token that we'll revoke when we refresh this\n * token. The idea is to keep allow two valid tokens when a refresh occurs;\n * we don't want revoke a token that's in the middle of being used, so when\n * we do a token refresh, we won't revoke the token being refreshed, but\n * we'll revoke the previous one.\n * @instance\n * @memberof Token\n * @private\n * @type {Object}\n */\n previousToken: {\n type: 'state',\n },\n },\n\n @oneFlight({\n keyFactory(scope) {\n return scope;\n },\n })\n /**\n * Uses this token to request a new Token with a subset of this Token's scopes\n * @instance\n * @memberof Token\n * @param {string} scope\n * @returns {Promise<Token>}\n */\n downscope(scope) {\n this.logger.info(`token: downscoping token to ${scope}`);\n\n if (this.isExpired) {\n this.logger.info('token: request received to downscope expired access_token');\n\n return Promise.reject(new Error('cannot downscope expired access token'));\n }\n\n if (!this.canDownscope) {\n if (this.config.client_id) {\n this.logger.info('token: request received to downscope invalid access_token');\n } else {\n this.logger.trace('token: cannot downscope without client_id');\n }\n\n return Promise.reject(new Error('cannot downscope access token'));\n }\n\n // Since we're going to use scope as the index in our token collection, it's\n // important scopes are always deterministically specified.\n if (scope) {\n scope = sortScope(scope);\n }\n\n // Ideally, we could depend on the service to communicate this error, but\n // all we get is \"invalid scope\", which, to the lay person, implies\n // something wrong with *one* of the scopes, not the whole thing.\n if (scope === sortScope(this.config.scope)) {\n return Promise.reject(new Error('token: scope reduction requires a reduced scope'));\n }\n\n return this.webex\n .request({\n method: 'POST',\n uri: this.config.tokenUrl,\n addAuthHeader: false,\n form: {\n grant_type: 'urn:cisco:oauth:grant-type:scope-reduction',\n token: this.access_token,\n scope,\n client_id: this.config.client_id,\n self_contained_token: true,\n },\n })\n .then((res) => {\n this.logger.info(`token: downscoped token to ${scope}`);\n\n return new Token(Object.assign(res.body, {scope}), {parent: this.parent});\n });\n },\n\n /**\n * Initializer\n * @instance\n * @memberof Token\n * @param {Object} [attrs={}]\n * @param {Object} [options={}]\n * @see {@link WebexPlugin#initialize()}\n * @returns {Token}\n */\n initialize(attrs = {}, options = {}) {\n Reflect.apply(WebexPlugin.prototype.initialize, this, [attrs, options]);\n\n if (typeof attrs === 'string') {\n this.access_token = attrs;\n }\n\n if (!this.access_token) {\n throw new Error('`access_token` is required');\n }\n\n // We don't want the derived property `isExpired` to need {cache:false}, so\n // we'll set up a timer the runs when this token should expire.\n if (this.expires) {\n if (this.expires < Date.now()) {\n this._isExpired = true;\n } else {\n safeSetTimeout(() => {\n this._isExpired = true;\n }, this.expires - Date.now());\n }\n }\n },\n\n @oneFlight\n /**\n * Refreshes this Token. Relies on\n * {@link config.credentials.refreshCallback()}\n * @instance\n * @memberof Token\n * @returns {Promise<Token>}\n */\n refresh() {\n if (!this.canRefresh) {\n throw new Error('Not enough information available to refresh this access token');\n }\n\n let promise;\n\n if (inBrowser) {\n if (!this.config.refreshCallback) {\n throw new Error('Cannot refresh access token without refreshCallback');\n }\n\n promise = Promise.resolve(this.config.refreshCallback(this.webex, this));\n }\n\n return (\n promise ||\n this.webex\n .request({\n method: 'POST',\n uri: this.config.tokenUrl,\n form: {\n grant_type: 'refresh_token',\n redirect_uri: this.config.redirect_uri,\n refresh_token: this.refresh_token,\n },\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true,\n },\n shouldRefreshAccessToken: false,\n })\n .then((res) => res.body)\n )\n .then((obj) => {\n if (!obj) {\n throw new Error('token: refreshCallback() did not produce an object');\n }\n // If the authentication server did not send back a refresh token, copy\n // the current refresh token and related values to the response (note:\n // at time of implementation, CI never sends a new refresh token)\n if (!obj.refresh_token) {\n Object.assign(\n obj,\n pick(this, 'refresh_token', 'refresh_token_expires', 'refresh_token_expires_in')\n );\n }\n\n // If the new token is the same as the previous token, then we may have\n // found a bug in CI; log the details and reject the Promise\n if (this.access_token === obj.access_token) {\n this.logger.error('token: new token matches current token');\n // log the tokens if it is not production\n if (process.env.NODE_ENV !== 'production') {\n this.logger.error('token: current token:', this.access_token);\n this.logger.error('token: new token:', obj.access_token);\n }\n\n return Promise.reject(new Error('new token matches current token'));\n }\n\n if (this.previousToken) {\n this.previousToken.revoke();\n this.unset('previousToken');\n }\n\n obj.previousToken = this;\n obj.scope = this.scope;\n\n return new Token(obj, {parent: this.parent});\n })\n .catch(processGrantError);\n },\n\n @oneFlight\n /**\n * Revokes this token and unsets its local properties\n * @instance\n * @memberof Token\n * @returns {Promise}\n */\n revoke() {\n if (this.isExpired) {\n this.logger.info('token: already expired, not making making revocation request');\n\n return Promise.resolve();\n }\n\n if (!this.canAuthorize) {\n this.logger.info('token: no longer valid, not making revocation request');\n\n return Promise.resolve();\n }\n\n // FIXME we need to use the user token revocation endpoint to revoke a token\n // without a client_secret, but it doesn't current support using a token to\n // revoke itself\n // Note: I'm not making a canRevoke property because there should be changes\n // coming to the user token revocation endpoint that allow us to do this\n // correctly.\n if (!this.config.client_secret) {\n this.logger.info('token: no client secret available, not making revocation request');\n\n return Promise.resolve();\n }\n\n this.logger.info('token: revoking access token');\n\n return this.webex\n .request({\n method: 'POST',\n uri: this.config.revokeUrl,\n form: {\n token: this.access_token,\n token_type_hint: 'access_token',\n },\n auth: {\n user: this.config.client_id,\n pass: this.config.client_secret,\n sendImmediately: true,\n },\n shouldRefreshAccessToken: false,\n })\n .then(() => {\n this.unset(['access_token', 'expires', 'expires_in', 'token_type']);\n this.logger.info('token: access token revoked');\n })\n .catch(processGrantError);\n },\n\n set(...args) {\n // eslint-disable-next-line prefer-const\n let [attrs, options] = this._filterSetParameters(...args);\n\n if (!attrs.token_type && attrs.access_token && attrs.access_token.includes(' ')) {\n const [token_type, access_token] = attrs.access_token.split(' ');\n\n attrs = {...attrs, access_token, token_type};\n }\n const now = Date.now();\n\n if (!attrs.expires && attrs.expires_in) {\n attrs.expires = now + attrs.expires_in * 1000;\n }\n\n if (!attrs.refresh_token_expires && attrs.refresh_token_expires_in) {\n attrs.refresh_token_expires = now + attrs.refresh_token_expires_in * 1000;\n }\n\n if (attrs.scope) {\n attrs.scope = sortScope(attrs.scope);\n }\n\n return Reflect.apply(WebexPlugin.prototype.set, this, [attrs, options]);\n },\n\n /**\n * Renders the token object as an HTTP Header Value\n * @instance\n * @memberof Token\n * @returns {string}\n * @see {@link Object#toString()}\n */\n toString() {\n if (!this._string) {\n throw new Error('cannot stringify Token');\n }\n\n return this._string;\n },\n\n /**\n * Uses a non-producation api to return information about this token. This\n * method is primarily for tests and will throw if NODE_ENV === production\n * @instance\n * @memberof Token\n * @private\n * @returns {Promise}\n */\n validate() {\n if (process.env.NODE_ENV === 'production') {\n throw new Error('Token#validate() must not be used in production');\n }\n\n return this.webex\n .request({\n method: 'POST',\n service: 'conversation',\n resource: 'users/validateAuthToken',\n body: {\n token: this.access_token,\n },\n })\n .catch((reason) => {\n if ('statusCode' in reason) {\n return Promise.reject(reason);\n }\n this.logger.info(\"REMINDER: If you're investigating a network error here, it's normal\");\n\n // If we got an error that isn't a WebexHttpError, assume the problem is\n // that we don't have the wdm plugin loaded and service/resource isn't\n // a valid means of identifying a request.\n const convApi =\n process.env.CONVERSATION_SERVICE ||\n process.env.CONVERSATION_SERVICE_URL ||\n 'https://conv-a.wbx2.com/conversation/api/v1';\n\n return this.webex.request({\n method: 'POST',\n uri: `${convApi}/users/validateAuthToken`,\n body: {\n token: this.access_token,\n },\n headers: {\n authorization: `Bearer ${this.access_token}`,\n },\n });\n })\n .then((res) => res.body);\n },\n});\n\nexport default Token;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKA;AACA;AAEA;AACA;AAEA;AACA;AAAuD;AAAA;AAAA;AAAA;AAAA;AAEvD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,iBAAiB,CAACC,GAAG,EAAE;EAC9B,IAAIA,GAAG,CAACC,UAAU,KAAK,GAAG,EAAE;IAC1B,OAAO,iBAAQC,MAAM,CAACF,GAAG,CAAC;EAC5B;EAEA,IAAMG,gBAAgB,GAAGC,oBAAW,CAACC,MAAM,CA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