@digipair/skill-s3 0.92.2 → 0.93.0-0

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 (47) hide show
  1. package/README.md +7 -0
  2. package/dist/index.cjs.js +22 -0
  3. package/dist/index.cjs10.js +1581 -0
  4. package/dist/index.cjs11.js +2639 -0
  5. package/dist/index.cjs2.js +25 -0
  6. package/dist/index.cjs3.js +39239 -0
  7. package/dist/index.cjs4.js +450 -0
  8. package/dist/index.cjs5.js +3698 -0
  9. package/dist/index.cjs6.js +433 -0
  10. package/dist/index.cjs7.js +706 -0
  11. package/dist/index.cjs8.js +1691 -0
  12. package/dist/index.cjs9.js +1515 -0
  13. package/dist/index.esm.js +13 -0
  14. package/dist/index.esm10.js +1577 -0
  15. package/dist/index.esm11.js +2619 -0
  16. package/dist/index.esm2.js +13 -0
  17. package/dist/index.esm3.js +39118 -0
  18. package/dist/index.esm4.js +447 -0
  19. package/dist/index.esm5.js +3676 -0
  20. package/dist/index.esm6.js +431 -0
  21. package/dist/index.esm7.js +704 -0
  22. package/dist/index.esm8.js +1689 -0
  23. package/dist/index.esm9.js +1504 -0
  24. package/dist/loadSso.cjs.js +2092 -0
  25. package/dist/loadSso.esm.js +2089 -0
  26. package/dist/noAuth.cjs.js +167 -0
  27. package/dist/noAuth.esm.js +165 -0
  28. package/dist/package.cjs.js +187 -0
  29. package/dist/package.esm.js +184 -0
  30. package/dist/parseJsonBody.cjs.js +257 -0
  31. package/dist/parseJsonBody.esm.js +252 -0
  32. package/dist/parseKnownFiles.cjs.js +250 -0
  33. package/dist/parseKnownFiles.esm.js +248 -0
  34. package/dist/src/index.d.ts +2 -0
  35. package/dist/src/index.d.ts.map +1 -0
  36. package/{libs/skill-s3 → dist}/src/lib/skill-s3.d.ts +1 -0
  37. package/dist/src/lib/skill-s3.d.ts.map +1 -0
  38. package/dist/src/lib/skill-s3.spec.d.ts +2 -0
  39. package/dist/src/lib/skill-s3.spec.d.ts.map +1 -0
  40. package/package.json +20 -6
  41. package/index.cjs.js +0 -72
  42. package/index.d.ts +0 -1
  43. package/index.esm.js +0 -65
  44. package/libs/skill-s3/src/index.d.ts +0 -1
  45. /package/{index.cjs.d.ts → dist/index.d.ts} +0 -0
  46. /package/{schema.fr.json → dist/schema.fr.json} +0 -0
  47. /package/{schema.json → dist/schema.json} +0 -0
@@ -0,0 +1,1577 @@
1
+ import { P as ProviderError, I as IniSectionType, k as CONFIG_PREFIX_SEPARATOR, m as slurpFile, n as getConfigFilepath, o as parseIni, q as getSSOTokenFilepath, r as getSSOTokenFromFile, h as getProfileName, C as CredentialsProviderError, s as setCredentialFeature } from './index.esm3.js';
2
+ import 'os';
3
+ import 'path';
4
+ import 'crypto';
5
+ import { p as parseKnownFiles } from './parseKnownFiles.esm.js';
6
+ import { promises } from 'fs';
7
+ import 'buffer';
8
+ import 'stream';
9
+ import 'node:stream';
10
+ import 'http';
11
+ import 'https';
12
+ import 'http2';
13
+ import 'zlib';
14
+ import 'process';
15
+
16
+ function _assert_this_initialized(self) {
17
+ if (self === void 0) {
18
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
19
+ }
20
+ return self;
21
+ }
22
+ function _class_call_check(instance, Constructor) {
23
+ if (!(instance instanceof Constructor)) {
24
+ throw new TypeError("Cannot call a class as a function");
25
+ }
26
+ }
27
+ function _get_prototype_of(o) {
28
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
29
+ return o.__proto__ || Object.getPrototypeOf(o);
30
+ };
31
+ return _get_prototype_of(o);
32
+ }
33
+ function _inherits(subClass, superClass) {
34
+ if (typeof superClass !== "function" && superClass !== null) {
35
+ throw new TypeError("Super expression must either be null or a function");
36
+ }
37
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
38
+ constructor: {
39
+ value: subClass,
40
+ writable: true,
41
+ configurable: true
42
+ }
43
+ });
44
+ if (superClass) _set_prototype_of(subClass, superClass);
45
+ }
46
+ function _possible_constructor_return(self, call) {
47
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
48
+ return call;
49
+ }
50
+ return _assert_this_initialized(self);
51
+ }
52
+ function _set_prototype_of(o, p) {
53
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
54
+ o.__proto__ = p;
55
+ return o;
56
+ };
57
+ return _set_prototype_of(o, p);
58
+ }
59
+ function _type_of(obj) {
60
+ "@swc/helpers - typeof";
61
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
62
+ }
63
+ function _is_native_reflect_construct() {
64
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
65
+ if (Reflect.construct.sham) return false;
66
+ if (typeof Proxy === "function") return true;
67
+ try {
68
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
69
+ return true;
70
+ } catch (e) {
71
+ return false;
72
+ }
73
+ }
74
+ function _create_super(Derived) {
75
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
76
+ return function _createSuperInternal() {
77
+ var Super = _get_prototype_of(Derived), result;
78
+ if (hasNativeReflectConstruct) {
79
+ var NewTarget = _get_prototype_of(this).constructor;
80
+ result = Reflect.construct(Super, arguments, NewTarget);
81
+ } else {
82
+ result = Super.apply(this, arguments);
83
+ }
84
+ return _possible_constructor_return(this, result);
85
+ };
86
+ }
87
+ var TokenProviderError = /*#__PURE__*/ function(ProviderError) {
88
+ _inherits(TokenProviderError, ProviderError);
89
+ var _super = _create_super(TokenProviderError);
90
+ function TokenProviderError(message) {
91
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
92
+ _class_call_check(this, TokenProviderError);
93
+ var _this;
94
+ _this = _super.call(this, message, options);
95
+ _this.name = "TokenProviderError";
96
+ Object.setPrototypeOf(_assert_this_initialized(_this), TokenProviderError.prototype);
97
+ return _this;
98
+ }
99
+ return TokenProviderError;
100
+ }(ProviderError);
101
+
102
+ function _array_like_to_array(arr, len) {
103
+ if (len == null || len > arr.length) len = arr.length;
104
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
105
+ return arr2;
106
+ }
107
+ function _array_with_holes(arr) {
108
+ if (Array.isArray(arr)) return arr;
109
+ }
110
+ function _define_property$2(obj, key, value) {
111
+ if (key in obj) {
112
+ Object.defineProperty(obj, key, {
113
+ value: value,
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true
117
+ });
118
+ } else {
119
+ obj[key] = value;
120
+ }
121
+ return obj;
122
+ }
123
+ function _iterable_to_array_limit(arr, i) {
124
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
125
+ if (_i == null) return;
126
+ var _arr = [];
127
+ var _n = true;
128
+ var _d = false;
129
+ var _s, _e;
130
+ try {
131
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
132
+ _arr.push(_s.value);
133
+ if (i && _arr.length === i) break;
134
+ }
135
+ } catch (err) {
136
+ _d = true;
137
+ _e = err;
138
+ } finally{
139
+ try {
140
+ if (!_n && _i["return"] != null) _i["return"]();
141
+ } finally{
142
+ if (_d) throw _e;
143
+ }
144
+ }
145
+ return _arr;
146
+ }
147
+ function _non_iterable_rest() {
148
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
149
+ }
150
+ function _object_spread$2(target) {
151
+ for(var i = 1; i < arguments.length; i++){
152
+ var source = arguments[i] != null ? arguments[i] : {};
153
+ var ownKeys = Object.keys(source);
154
+ if (typeof Object.getOwnPropertySymbols === "function") {
155
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
156
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
157
+ }));
158
+ }
159
+ ownKeys.forEach(function(key) {
160
+ _define_property$2(target, key, source[key]);
161
+ });
162
+ }
163
+ return target;
164
+ }
165
+ function ownKeys$1(object, enumerableOnly) {
166
+ var keys = Object.keys(object);
167
+ if (Object.getOwnPropertySymbols) {
168
+ var symbols = Object.getOwnPropertySymbols(object);
169
+ keys.push.apply(keys, symbols);
170
+ }
171
+ return keys;
172
+ }
173
+ function _object_spread_props$1(target, source) {
174
+ source = source != null ? source : {};
175
+ if (Object.getOwnPropertyDescriptors) {
176
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
177
+ } else {
178
+ ownKeys$1(Object(source)).forEach(function(key) {
179
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
180
+ });
181
+ }
182
+ return target;
183
+ }
184
+ function _sliced_to_array(arr, i) {
185
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
186
+ }
187
+ function _unsupported_iterable_to_array(o, minLen) {
188
+ if (!o) return;
189
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
190
+ var n = Object.prototype.toString.call(o).slice(8, -1);
191
+ if (n === "Object" && o.constructor) n = o.constructor.name;
192
+ if (n === "Map" || n === "Set") return Array.from(n);
193
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
194
+ }
195
+ var getSsoSessionData = function(data) {
196
+ return Object.entries(data).filter(function(param) {
197
+ var _param = _sliced_to_array(param, 1), key = _param[0];
198
+ return key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR);
199
+ }).reduce(function(acc, param) {
200
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
201
+ return _object_spread_props$1(_object_spread$2({}, acc), _define_property$2({}, key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1), value));
202
+ }, {});
203
+ };
204
+
205
+ function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
206
+ try {
207
+ var info = gen[key](arg);
208
+ var value = info.value;
209
+ } catch (error) {
210
+ reject(error);
211
+ return;
212
+ }
213
+ if (info.done) {
214
+ resolve(value);
215
+ } else {
216
+ Promise.resolve(value).then(_next, _throw);
217
+ }
218
+ }
219
+ function _async_to_generator$5(fn) {
220
+ return function() {
221
+ var self = this, args = arguments;
222
+ return new Promise(function(resolve, reject) {
223
+ var gen = fn.apply(self, args);
224
+ function _next(value) {
225
+ asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
226
+ }
227
+ function _throw(err) {
228
+ asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
229
+ }
230
+ _next(undefined);
231
+ });
232
+ };
233
+ }
234
+ function _ts_generator$5(thisArg, body) {
235
+ var f, y, t, g, _ = {
236
+ label: 0,
237
+ sent: function() {
238
+ if (t[0] & 1) throw t[1];
239
+ return t[1];
240
+ },
241
+ trys: [],
242
+ ops: []
243
+ };
244
+ return g = {
245
+ next: verb(0),
246
+ "throw": verb(1),
247
+ "return": verb(2)
248
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
249
+ return this;
250
+ }), g;
251
+ function verb(n) {
252
+ return function(v) {
253
+ return step([
254
+ n,
255
+ v
256
+ ]);
257
+ };
258
+ }
259
+ function step(op) {
260
+ if (f) throw new TypeError("Generator is already executing.");
261
+ while(_)try {
262
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
263
+ if (y = 0, t) op = [
264
+ op[0] & 2,
265
+ t.value
266
+ ];
267
+ switch(op[0]){
268
+ case 0:
269
+ case 1:
270
+ t = op;
271
+ break;
272
+ case 4:
273
+ _.label++;
274
+ return {
275
+ value: op[1],
276
+ done: false
277
+ };
278
+ case 5:
279
+ _.label++;
280
+ y = op[1];
281
+ op = [
282
+ 0
283
+ ];
284
+ continue;
285
+ case 7:
286
+ op = _.ops.pop();
287
+ _.trys.pop();
288
+ continue;
289
+ default:
290
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
291
+ _ = 0;
292
+ continue;
293
+ }
294
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
295
+ _.label = op[1];
296
+ break;
297
+ }
298
+ if (op[0] === 6 && _.label < t[1]) {
299
+ _.label = t[1];
300
+ t = op;
301
+ break;
302
+ }
303
+ if (t && _.label < t[2]) {
304
+ _.label = t[2];
305
+ _.ops.push(op);
306
+ break;
307
+ }
308
+ if (t[2]) _.ops.pop();
309
+ _.trys.pop();
310
+ continue;
311
+ }
312
+ op = body.call(thisArg, _);
313
+ } catch (e) {
314
+ op = [
315
+ 6,
316
+ e
317
+ ];
318
+ y = 0;
319
+ } finally{
320
+ f = t = 0;
321
+ }
322
+ if (op[0] & 5) throw op[1];
323
+ return {
324
+ value: op[0] ? op[1] : void 0,
325
+ done: true
326
+ };
327
+ }
328
+ }
329
+ var swallowError = function() {
330
+ return {};
331
+ };
332
+ var loadSsoSessionData = function() {
333
+ var _ref = _async_to_generator$5(function() {
334
+ var init, _init_configFilepath;
335
+ var _arguments = arguments;
336
+ return _ts_generator$5(this, function(_state) {
337
+ init = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
338
+ return [
339
+ 2,
340
+ slurpFile((_init_configFilepath = init.configFilepath) !== null && _init_configFilepath !== void 0 ? _init_configFilepath : getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError)
341
+ ];
342
+ });
343
+ });
344
+ return function loadSsoSessionData() {
345
+ return _ref.apply(this, arguments);
346
+ };
347
+ }();
348
+
349
+ var isSsoProfile = function(arg) {
350
+ return arg && (typeof arg.sso_start_url === "string" || typeof arg.sso_account_id === "string" || typeof arg.sso_session === "string" || typeof arg.sso_region === "string" || typeof arg.sso_role_name === "string");
351
+ };
352
+
353
+ var EXPIRE_WINDOW_MS = 5 * 60 * 1000;
354
+ var REFRESH_MESSAGE = "To refresh this SSO session run 'aws sso login' with the corresponding profile.";
355
+
356
+ function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
357
+ try {
358
+ var info = gen[key](arg);
359
+ var value = info.value;
360
+ } catch (error) {
361
+ reject(error);
362
+ return;
363
+ }
364
+ if (info.done) {
365
+ resolve(value);
366
+ } else {
367
+ Promise.resolve(value).then(_next, _throw);
368
+ }
369
+ }
370
+ function _async_to_generator$4(fn) {
371
+ return function() {
372
+ var self = this, args = arguments;
373
+ return new Promise(function(resolve, reject) {
374
+ var gen = fn.apply(self, args);
375
+ function _next(value) {
376
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
377
+ }
378
+ function _throw(err) {
379
+ asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
380
+ }
381
+ _next(undefined);
382
+ });
383
+ };
384
+ }
385
+ function _ts_generator$4(thisArg, body) {
386
+ var f, y, t, g, _ = {
387
+ label: 0,
388
+ sent: function() {
389
+ if (t[0] & 1) throw t[1];
390
+ return t[1];
391
+ },
392
+ trys: [],
393
+ ops: []
394
+ };
395
+ return g = {
396
+ next: verb(0),
397
+ "throw": verb(1),
398
+ "return": verb(2)
399
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
400
+ return this;
401
+ }), g;
402
+ function verb(n) {
403
+ return function(v) {
404
+ return step([
405
+ n,
406
+ v
407
+ ]);
408
+ };
409
+ }
410
+ function step(op) {
411
+ if (f) throw new TypeError("Generator is already executing.");
412
+ while(_)try {
413
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
414
+ if (y = 0, t) op = [
415
+ op[0] & 2,
416
+ t.value
417
+ ];
418
+ switch(op[0]){
419
+ case 0:
420
+ case 1:
421
+ t = op;
422
+ break;
423
+ case 4:
424
+ _.label++;
425
+ return {
426
+ value: op[1],
427
+ done: false
428
+ };
429
+ case 5:
430
+ _.label++;
431
+ y = op[1];
432
+ op = [
433
+ 0
434
+ ];
435
+ continue;
436
+ case 7:
437
+ op = _.ops.pop();
438
+ _.trys.pop();
439
+ continue;
440
+ default:
441
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
442
+ _ = 0;
443
+ continue;
444
+ }
445
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
446
+ _.label = op[1];
447
+ break;
448
+ }
449
+ if (op[0] === 6 && _.label < t[1]) {
450
+ _.label = t[1];
451
+ t = op;
452
+ break;
453
+ }
454
+ if (t && _.label < t[2]) {
455
+ _.label = t[2];
456
+ _.ops.push(op);
457
+ break;
458
+ }
459
+ if (t[2]) _.ops.pop();
460
+ _.trys.pop();
461
+ continue;
462
+ }
463
+ op = body.call(thisArg, _);
464
+ } catch (e) {
465
+ op = [
466
+ 6,
467
+ e
468
+ ];
469
+ y = 0;
470
+ } finally{
471
+ f = t = 0;
472
+ }
473
+ if (op[0] & 5) throw op[1];
474
+ return {
475
+ value: op[0] ? op[1] : void 0,
476
+ done: true
477
+ };
478
+ }
479
+ }
480
+ var getSsoOidcClient = function() {
481
+ var _ref = _async_to_generator$4(function(ssoRegion) {
482
+ var init, _init_clientConfig, _init_clientConfig1, _init_parentClientConfig, SSOOIDCClient, _init_clientConfig2, _init_clientConfig_logger, ssoOidcClient;
483
+ var _arguments = arguments;
484
+ return _ts_generator$4(this, function(_state) {
485
+ switch(_state.label){
486
+ case 0:
487
+ init = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
488
+ return [
489
+ 4,
490
+ import('./index.esm11.js')
491
+ ];
492
+ case 1:
493
+ SSOOIDCClient = _state.sent().SSOOIDCClient;
494
+ ssoOidcClient = new SSOOIDCClient(Object.assign({}, (_init_clientConfig2 = init.clientConfig) !== null && _init_clientConfig2 !== void 0 ? _init_clientConfig2 : {}, {
495
+ region: ssoRegion !== null && ssoRegion !== void 0 ? ssoRegion : (_init_clientConfig = init.clientConfig) === null || _init_clientConfig === void 0 ? void 0 : _init_clientConfig.region,
496
+ logger: (_init_clientConfig_logger = (_init_clientConfig1 = init.clientConfig) === null || _init_clientConfig1 === void 0 ? void 0 : _init_clientConfig1.logger) !== null && _init_clientConfig_logger !== void 0 ? _init_clientConfig_logger : (_init_parentClientConfig = init.parentClientConfig) === null || _init_parentClientConfig === void 0 ? void 0 : _init_parentClientConfig.logger
497
+ }));
498
+ return [
499
+ 2,
500
+ ssoOidcClient
501
+ ];
502
+ }
503
+ });
504
+ });
505
+ return function getSsoOidcClient(ssoRegion) {
506
+ return _ref.apply(this, arguments);
507
+ };
508
+ }();
509
+
510
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
511
+ try {
512
+ var info = gen[key](arg);
513
+ var value = info.value;
514
+ } catch (error) {
515
+ reject(error);
516
+ return;
517
+ }
518
+ if (info.done) {
519
+ resolve(value);
520
+ } else {
521
+ Promise.resolve(value).then(_next, _throw);
522
+ }
523
+ }
524
+ function _async_to_generator$3(fn) {
525
+ return function() {
526
+ var self = this, args = arguments;
527
+ return new Promise(function(resolve, reject) {
528
+ var gen = fn.apply(self, args);
529
+ function _next(value) {
530
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
531
+ }
532
+ function _throw(err) {
533
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
534
+ }
535
+ _next(undefined);
536
+ });
537
+ };
538
+ }
539
+ function _ts_generator$3(thisArg, body) {
540
+ var f, y, t, g, _ = {
541
+ label: 0,
542
+ sent: function() {
543
+ if (t[0] & 1) throw t[1];
544
+ return t[1];
545
+ },
546
+ trys: [],
547
+ ops: []
548
+ };
549
+ return g = {
550
+ next: verb(0),
551
+ "throw": verb(1),
552
+ "return": verb(2)
553
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
554
+ return this;
555
+ }), g;
556
+ function verb(n) {
557
+ return function(v) {
558
+ return step([
559
+ n,
560
+ v
561
+ ]);
562
+ };
563
+ }
564
+ function step(op) {
565
+ if (f) throw new TypeError("Generator is already executing.");
566
+ while(_)try {
567
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
568
+ if (y = 0, t) op = [
569
+ op[0] & 2,
570
+ t.value
571
+ ];
572
+ switch(op[0]){
573
+ case 0:
574
+ case 1:
575
+ t = op;
576
+ break;
577
+ case 4:
578
+ _.label++;
579
+ return {
580
+ value: op[1],
581
+ done: false
582
+ };
583
+ case 5:
584
+ _.label++;
585
+ y = op[1];
586
+ op = [
587
+ 0
588
+ ];
589
+ continue;
590
+ case 7:
591
+ op = _.ops.pop();
592
+ _.trys.pop();
593
+ continue;
594
+ default:
595
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
596
+ _ = 0;
597
+ continue;
598
+ }
599
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
600
+ _.label = op[1];
601
+ break;
602
+ }
603
+ if (op[0] === 6 && _.label < t[1]) {
604
+ _.label = t[1];
605
+ t = op;
606
+ break;
607
+ }
608
+ if (t && _.label < t[2]) {
609
+ _.label = t[2];
610
+ _.ops.push(op);
611
+ break;
612
+ }
613
+ if (t[2]) _.ops.pop();
614
+ _.trys.pop();
615
+ continue;
616
+ }
617
+ op = body.call(thisArg, _);
618
+ } catch (e) {
619
+ op = [
620
+ 6,
621
+ e
622
+ ];
623
+ y = 0;
624
+ } finally{
625
+ f = t = 0;
626
+ }
627
+ if (op[0] & 5) throw op[1];
628
+ return {
629
+ value: op[0] ? op[1] : void 0,
630
+ done: true
631
+ };
632
+ }
633
+ }
634
+ var getNewSsoOidcToken = function() {
635
+ var _ref = _async_to_generator$3(function(ssoToken, ssoRegion) {
636
+ var init, CreateTokenCommand, ssoOidcClient;
637
+ var _arguments = arguments;
638
+ return _ts_generator$3(this, function(_state) {
639
+ switch(_state.label){
640
+ case 0:
641
+ init = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
642
+ return [
643
+ 4,
644
+ import('./index.esm11.js')
645
+ ];
646
+ case 1:
647
+ CreateTokenCommand = _state.sent().CreateTokenCommand;
648
+ return [
649
+ 4,
650
+ getSsoOidcClient(ssoRegion, init)
651
+ ];
652
+ case 2:
653
+ ssoOidcClient = _state.sent();
654
+ return [
655
+ 2,
656
+ ssoOidcClient.send(new CreateTokenCommand({
657
+ clientId: ssoToken.clientId,
658
+ clientSecret: ssoToken.clientSecret,
659
+ refreshToken: ssoToken.refreshToken,
660
+ grantType: "refresh_token"
661
+ }))
662
+ ];
663
+ }
664
+ });
665
+ });
666
+ return function getNewSsoOidcToken(ssoToken, ssoRegion) {
667
+ return _ref.apply(this, arguments);
668
+ };
669
+ }();
670
+
671
+ var validateTokenExpiry = function(token) {
672
+ if (token.expiration && token.expiration.getTime() < Date.now()) {
673
+ throw new TokenProviderError("Token is expired. ".concat(REFRESH_MESSAGE), false);
674
+ }
675
+ };
676
+
677
+ var validateTokenKey = function(key, value) {
678
+ var forRefresh = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
679
+ if (typeof value === "undefined") {
680
+ throw new TokenProviderError("Value not present for '".concat(key, "' in SSO Token").concat(forRefresh ? ". Cannot refresh" : "", ". ").concat(REFRESH_MESSAGE), false);
681
+ }
682
+ };
683
+
684
+ var writeFile = promises.writeFile;
685
+ var writeSSOTokenToFile = function(id, ssoToken) {
686
+ var tokenFilepath = getSSOTokenFilepath(id);
687
+ var tokenString = JSON.stringify(ssoToken, null, 2);
688
+ return writeFile(tokenFilepath, tokenString);
689
+ };
690
+
691
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
692
+ try {
693
+ var info = gen[key](arg);
694
+ var value = info.value;
695
+ } catch (error) {
696
+ reject(error);
697
+ return;
698
+ }
699
+ if (info.done) {
700
+ resolve(value);
701
+ } else {
702
+ Promise.resolve(value).then(_next, _throw);
703
+ }
704
+ }
705
+ function _async_to_generator$2(fn) {
706
+ return function() {
707
+ var self = this, args = arguments;
708
+ return new Promise(function(resolve, reject) {
709
+ var gen = fn.apply(self, args);
710
+ function _next(value) {
711
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
712
+ }
713
+ function _throw(err) {
714
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
715
+ }
716
+ _next(undefined);
717
+ });
718
+ };
719
+ }
720
+ function _define_property$1(obj, key, value) {
721
+ if (key in obj) {
722
+ Object.defineProperty(obj, key, {
723
+ value: value,
724
+ enumerable: true,
725
+ configurable: true,
726
+ writable: true
727
+ });
728
+ } else {
729
+ obj[key] = value;
730
+ }
731
+ return obj;
732
+ }
733
+ function _object_spread$1(target) {
734
+ for(var i = 1; i < arguments.length; i++){
735
+ var source = arguments[i] != null ? arguments[i] : {};
736
+ var ownKeys = Object.keys(source);
737
+ if (typeof Object.getOwnPropertySymbols === "function") {
738
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
739
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
740
+ }));
741
+ }
742
+ ownKeys.forEach(function(key) {
743
+ _define_property$1(target, key, source[key]);
744
+ });
745
+ }
746
+ return target;
747
+ }
748
+ function ownKeys(object, enumerableOnly) {
749
+ var keys = Object.keys(object);
750
+ if (Object.getOwnPropertySymbols) {
751
+ var symbols = Object.getOwnPropertySymbols(object);
752
+ keys.push.apply(keys, symbols);
753
+ }
754
+ return keys;
755
+ }
756
+ function _object_spread_props(target, source) {
757
+ source = source != null ? source : {};
758
+ if (Object.getOwnPropertyDescriptors) {
759
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
760
+ } else {
761
+ ownKeys(Object(source)).forEach(function(key) {
762
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
763
+ });
764
+ }
765
+ return target;
766
+ }
767
+ function _ts_generator$2(thisArg, body) {
768
+ var f, y, t, g, _ = {
769
+ label: 0,
770
+ sent: function() {
771
+ if (t[0] & 1) throw t[1];
772
+ return t[1];
773
+ },
774
+ trys: [],
775
+ ops: []
776
+ };
777
+ return g = {
778
+ next: verb(0),
779
+ "throw": verb(1),
780
+ "return": verb(2)
781
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
782
+ return this;
783
+ }), g;
784
+ function verb(n) {
785
+ return function(v) {
786
+ return step([
787
+ n,
788
+ v
789
+ ]);
790
+ };
791
+ }
792
+ function step(op) {
793
+ if (f) throw new TypeError("Generator is already executing.");
794
+ while(_)try {
795
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
796
+ if (y = 0, t) op = [
797
+ op[0] & 2,
798
+ t.value
799
+ ];
800
+ switch(op[0]){
801
+ case 0:
802
+ case 1:
803
+ t = op;
804
+ break;
805
+ case 4:
806
+ _.label++;
807
+ return {
808
+ value: op[1],
809
+ done: false
810
+ };
811
+ case 5:
812
+ _.label++;
813
+ y = op[1];
814
+ op = [
815
+ 0
816
+ ];
817
+ continue;
818
+ case 7:
819
+ op = _.ops.pop();
820
+ _.trys.pop();
821
+ continue;
822
+ default:
823
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
824
+ _ = 0;
825
+ continue;
826
+ }
827
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
828
+ _.label = op[1];
829
+ break;
830
+ }
831
+ if (op[0] === 6 && _.label < t[1]) {
832
+ _.label = t[1];
833
+ t = op;
834
+ break;
835
+ }
836
+ if (t && _.label < t[2]) {
837
+ _.label = t[2];
838
+ _.ops.push(op);
839
+ break;
840
+ }
841
+ if (t[2]) _.ops.pop();
842
+ _.trys.pop();
843
+ continue;
844
+ }
845
+ op = body.call(thisArg, _);
846
+ } catch (e) {
847
+ op = [
848
+ 6,
849
+ e
850
+ ];
851
+ y = 0;
852
+ } finally{
853
+ f = t = 0;
854
+ }
855
+ if (op[0] & 5) throw op[1];
856
+ return {
857
+ value: op[0] ? op[1] : void 0,
858
+ done: true
859
+ };
860
+ }
861
+ }
862
+ var lastRefreshAttemptTime = new Date(0);
863
+ var fromSso = function() {
864
+ var _init = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
865
+ return /*#__PURE__*/ _async_to_generator$2(function() {
866
+ var callerClientConfig, _init_logger, init, profiles, _init_profile, profileName, profile, ssoSessionName, ssoSessions, ssoSession, _i, _iter, ssoSessionRequiredKey, ssoRegion, ssoToken, accessToken, expiresAt, existingToken, newSsoOidcToken, newTokenExpiration;
867
+ var _arguments = arguments;
868
+ return _ts_generator$2(this, function(_state) {
869
+ switch(_state.label){
870
+ case 0:
871
+ callerClientConfig = (_arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}).callerClientConfig;
872
+ init = _object_spread_props(_object_spread$1({}, _init), {
873
+ parentClientConfig: _object_spread$1({}, callerClientConfig, _init.parentClientConfig)
874
+ });
875
+ (_init_logger = init.logger) === null || _init_logger === void 0 ? void 0 : _init_logger.debug("@aws-sdk/token-providers - fromSso");
876
+ return [
877
+ 4,
878
+ parseKnownFiles(init)
879
+ ];
880
+ case 1:
881
+ profiles = _state.sent();
882
+ profileName = getProfileName({
883
+ profile: (_init_profile = init.profile) !== null && _init_profile !== void 0 ? _init_profile : callerClientConfig === null || callerClientConfig === void 0 ? void 0 : callerClientConfig.profile
884
+ });
885
+ profile = profiles[profileName];
886
+ if (!profile) {
887
+ throw new TokenProviderError("Profile '".concat(profileName, "' could not be found in shared credentials file."), false);
888
+ } else if (!profile["sso_session"]) {
889
+ throw new TokenProviderError("Profile '".concat(profileName, "' is missing required property 'sso_session'."));
890
+ }
891
+ ssoSessionName = profile["sso_session"];
892
+ return [
893
+ 4,
894
+ loadSsoSessionData(init)
895
+ ];
896
+ case 2:
897
+ ssoSessions = _state.sent();
898
+ ssoSession = ssoSessions[ssoSessionName];
899
+ if (!ssoSession) {
900
+ throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' could not be found in shared credentials file."), false);
901
+ }
902
+ for(_i = 0, _iter = [
903
+ "sso_start_url",
904
+ "sso_region"
905
+ ]; _i < _iter.length; _i++){
906
+ ssoSessionRequiredKey = _iter[_i];
907
+ if (!ssoSession[ssoSessionRequiredKey]) {
908
+ throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' is missing required property '").concat(ssoSessionRequiredKey, "'."), false);
909
+ }
910
+ }
911
+ ssoSession["sso_start_url"];
912
+ ssoRegion = ssoSession["sso_region"];
913
+ _state.label = 3;
914
+ case 3:
915
+ _state.trys.push([
916
+ 3,
917
+ 5,
918
+ ,
919
+ 6
920
+ ]);
921
+ return [
922
+ 4,
923
+ getSSOTokenFromFile(ssoSessionName)
924
+ ];
925
+ case 4:
926
+ ssoToken = _state.sent();
927
+ return [
928
+ 3,
929
+ 6
930
+ ];
931
+ case 5:
932
+ _state.sent();
933
+ throw new TokenProviderError("The SSO session token associated with profile=".concat(profileName, " was not found or is invalid. ").concat(REFRESH_MESSAGE), false);
934
+ case 6:
935
+ validateTokenKey("accessToken", ssoToken.accessToken);
936
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
937
+ accessToken = ssoToken.accessToken, expiresAt = ssoToken.expiresAt;
938
+ existingToken = {
939
+ token: accessToken,
940
+ expiration: new Date(expiresAt)
941
+ };
942
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
943
+ return [
944
+ 2,
945
+ existingToken
946
+ ];
947
+ }
948
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
949
+ validateTokenExpiry(existingToken);
950
+ return [
951
+ 2,
952
+ existingToken
953
+ ];
954
+ }
955
+ validateTokenKey("clientId", ssoToken.clientId, true);
956
+ validateTokenKey("clientSecret", ssoToken.clientSecret, true);
957
+ validateTokenKey("refreshToken", ssoToken.refreshToken, true);
958
+ _state.label = 7;
959
+ case 7:
960
+ _state.trys.push([
961
+ 7,
962
+ 13,
963
+ ,
964
+ 14
965
+ ]);
966
+ lastRefreshAttemptTime.setTime(Date.now());
967
+ return [
968
+ 4,
969
+ getNewSsoOidcToken(ssoToken, ssoRegion, init)
970
+ ];
971
+ case 8:
972
+ newSsoOidcToken = _state.sent();
973
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
974
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
975
+ newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
976
+ _state.label = 9;
977
+ case 9:
978
+ _state.trys.push([
979
+ 9,
980
+ 11,
981
+ ,
982
+ 12
983
+ ]);
984
+ return [
985
+ 4,
986
+ writeSSOTokenToFile(ssoSessionName, _object_spread_props(_object_spread$1({}, ssoToken), {
987
+ accessToken: newSsoOidcToken.accessToken,
988
+ expiresAt: newTokenExpiration.toISOString(),
989
+ refreshToken: newSsoOidcToken.refreshToken
990
+ }))
991
+ ];
992
+ case 10:
993
+ _state.sent();
994
+ return [
995
+ 3,
996
+ 12
997
+ ];
998
+ case 11:
999
+ _state.sent();
1000
+ return [
1001
+ 3,
1002
+ 12
1003
+ ];
1004
+ case 12:
1005
+ return [
1006
+ 2,
1007
+ {
1008
+ token: newSsoOidcToken.accessToken,
1009
+ expiration: newTokenExpiration
1010
+ }
1011
+ ];
1012
+ case 13:
1013
+ _state.sent();
1014
+ validateTokenExpiry(existingToken);
1015
+ return [
1016
+ 2,
1017
+ existingToken
1018
+ ];
1019
+ case 14:
1020
+ return [
1021
+ 2
1022
+ ];
1023
+ }
1024
+ });
1025
+ });
1026
+ };
1027
+
1028
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1029
+ try {
1030
+ var info = gen[key](arg);
1031
+ var value = info.value;
1032
+ } catch (error) {
1033
+ reject(error);
1034
+ return;
1035
+ }
1036
+ if (info.done) {
1037
+ resolve(value);
1038
+ } else {
1039
+ Promise.resolve(value).then(_next, _throw);
1040
+ }
1041
+ }
1042
+ function _async_to_generator$1(fn) {
1043
+ return function() {
1044
+ var self = this, args = arguments;
1045
+ return new Promise(function(resolve, reject) {
1046
+ var gen = fn.apply(self, args);
1047
+ function _next(value) {
1048
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1049
+ }
1050
+ function _throw(err) {
1051
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1052
+ }
1053
+ _next(undefined);
1054
+ });
1055
+ };
1056
+ }
1057
+ function _define_property(obj, key, value) {
1058
+ if (key in obj) {
1059
+ Object.defineProperty(obj, key, {
1060
+ value: value,
1061
+ enumerable: true,
1062
+ configurable: true,
1063
+ writable: true
1064
+ });
1065
+ } else {
1066
+ obj[key] = value;
1067
+ }
1068
+ return obj;
1069
+ }
1070
+ function _object_spread(target) {
1071
+ for(var i = 1; i < arguments.length; i++){
1072
+ var source = arguments[i] != null ? arguments[i] : {};
1073
+ var ownKeys = Object.keys(source);
1074
+ if (typeof Object.getOwnPropertySymbols === "function") {
1075
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1076
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1077
+ }));
1078
+ }
1079
+ ownKeys.forEach(function(key) {
1080
+ _define_property(target, key, source[key]);
1081
+ });
1082
+ }
1083
+ return target;
1084
+ }
1085
+ function _ts_generator$1(thisArg, body) {
1086
+ var f, y, t, g, _ = {
1087
+ label: 0,
1088
+ sent: function() {
1089
+ if (t[0] & 1) throw t[1];
1090
+ return t[1];
1091
+ },
1092
+ trys: [],
1093
+ ops: []
1094
+ };
1095
+ return g = {
1096
+ next: verb(0),
1097
+ "throw": verb(1),
1098
+ "return": verb(2)
1099
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1100
+ return this;
1101
+ }), g;
1102
+ function verb(n) {
1103
+ return function(v) {
1104
+ return step([
1105
+ n,
1106
+ v
1107
+ ]);
1108
+ };
1109
+ }
1110
+ function step(op) {
1111
+ if (f) throw new TypeError("Generator is already executing.");
1112
+ while(_)try {
1113
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1114
+ if (y = 0, t) op = [
1115
+ op[0] & 2,
1116
+ t.value
1117
+ ];
1118
+ switch(op[0]){
1119
+ case 0:
1120
+ case 1:
1121
+ t = op;
1122
+ break;
1123
+ case 4:
1124
+ _.label++;
1125
+ return {
1126
+ value: op[1],
1127
+ done: false
1128
+ };
1129
+ case 5:
1130
+ _.label++;
1131
+ y = op[1];
1132
+ op = [
1133
+ 0
1134
+ ];
1135
+ continue;
1136
+ case 7:
1137
+ op = _.ops.pop();
1138
+ _.trys.pop();
1139
+ continue;
1140
+ default:
1141
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1142
+ _ = 0;
1143
+ continue;
1144
+ }
1145
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1146
+ _.label = op[1];
1147
+ break;
1148
+ }
1149
+ if (op[0] === 6 && _.label < t[1]) {
1150
+ _.label = t[1];
1151
+ t = op;
1152
+ break;
1153
+ }
1154
+ if (t && _.label < t[2]) {
1155
+ _.label = t[2];
1156
+ _.ops.push(op);
1157
+ break;
1158
+ }
1159
+ if (t[2]) _.ops.pop();
1160
+ _.trys.pop();
1161
+ continue;
1162
+ }
1163
+ op = body.call(thisArg, _);
1164
+ } catch (e) {
1165
+ op = [
1166
+ 6,
1167
+ e
1168
+ ];
1169
+ y = 0;
1170
+ } finally{
1171
+ f = t = 0;
1172
+ }
1173
+ if (op[0] & 5) throw op[1];
1174
+ return {
1175
+ value: op[0] ? op[1] : void 0,
1176
+ done: true
1177
+ };
1178
+ }
1179
+ }
1180
+ var SHOULD_FAIL_CREDENTIAL_CHAIN = false;
1181
+ var resolveSSOCredentials = function() {
1182
+ var _ref = _async_to_generator$1(function(param) {
1183
+ var ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, clientConfig, parentClientConfig, profile, logger, token, refreshMessage, _token, e, accessToken, _ref, SSOClient, GetRoleCredentialsCommand, _clientConfig_logger, _clientConfig_region, sso, ssoResp, e2, tmp, _ref1, accessKeyId, secretAccessKey, sessionToken, expiration, credentialScope, accountId, credentials;
1184
+ return _ts_generator$1(this, function(_state) {
1185
+ switch(_state.label){
1186
+ case 0:
1187
+ ssoStartUrl = param.ssoStartUrl, ssoSession = param.ssoSession, ssoAccountId = param.ssoAccountId, ssoRegion = param.ssoRegion, ssoRoleName = param.ssoRoleName, ssoClient = param.ssoClient, clientConfig = param.clientConfig, parentClientConfig = param.parentClientConfig, profile = param.profile, logger = param.logger;
1188
+ refreshMessage = "To refresh this SSO session run aws sso login with the corresponding profile.";
1189
+ if (!ssoSession) return [
1190
+ 3,
1191
+ 5
1192
+ ];
1193
+ _state.label = 1;
1194
+ case 1:
1195
+ _state.trys.push([
1196
+ 1,
1197
+ 3,
1198
+ ,
1199
+ 4
1200
+ ]);
1201
+ return [
1202
+ 4,
1203
+ fromSso({
1204
+ profile: profile
1205
+ })()
1206
+ ];
1207
+ case 2:
1208
+ _token = _state.sent();
1209
+ token = {
1210
+ accessToken: _token.token,
1211
+ expiresAt: new Date(_token.expiration).toISOString()
1212
+ };
1213
+ return [
1214
+ 3,
1215
+ 4
1216
+ ];
1217
+ case 3:
1218
+ e = _state.sent();
1219
+ throw new CredentialsProviderError(e.message, {
1220
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1221
+ logger: logger
1222
+ });
1223
+ case 4:
1224
+ return [
1225
+ 3,
1226
+ 8
1227
+ ];
1228
+ case 5:
1229
+ _state.trys.push([
1230
+ 5,
1231
+ 7,
1232
+ ,
1233
+ 8
1234
+ ]);
1235
+ return [
1236
+ 4,
1237
+ getSSOTokenFromFile(ssoStartUrl)
1238
+ ];
1239
+ case 6:
1240
+ token = _state.sent();
1241
+ return [
1242
+ 3,
1243
+ 8
1244
+ ];
1245
+ case 7:
1246
+ _state.sent();
1247
+ throw new CredentialsProviderError("The SSO session associated with this profile is invalid. ".concat(refreshMessage), {
1248
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1249
+ logger: logger
1250
+ });
1251
+ case 8:
1252
+ if (new Date(token.expiresAt).getTime() - Date.now() <= 0) {
1253
+ throw new CredentialsProviderError("The SSO session associated with this profile has expired. ".concat(refreshMessage), {
1254
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1255
+ logger: logger
1256
+ });
1257
+ }
1258
+ accessToken = token.accessToken;
1259
+ return [
1260
+ 4,
1261
+ import('./loadSso.esm.js')
1262
+ ];
1263
+ case 9:
1264
+ _ref = _state.sent(), SSOClient = _ref.SSOClient, GetRoleCredentialsCommand = _ref.GetRoleCredentialsCommand;
1265
+ sso = ssoClient || new SSOClient(Object.assign({}, clientConfig !== null && clientConfig !== void 0 ? clientConfig : {}, {
1266
+ logger: (_clientConfig_logger = clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.logger) !== null && _clientConfig_logger !== void 0 ? _clientConfig_logger : parentClientConfig === null || parentClientConfig === void 0 ? void 0 : parentClientConfig.logger,
1267
+ region: (_clientConfig_region = clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.region) !== null && _clientConfig_region !== void 0 ? _clientConfig_region : ssoRegion
1268
+ }));
1269
+ _state.label = 10;
1270
+ case 10:
1271
+ _state.trys.push([
1272
+ 10,
1273
+ 12,
1274
+ ,
1275
+ 13
1276
+ ]);
1277
+ return [
1278
+ 4,
1279
+ sso.send(new GetRoleCredentialsCommand({
1280
+ accountId: ssoAccountId,
1281
+ roleName: ssoRoleName,
1282
+ accessToken: accessToken
1283
+ }))
1284
+ ];
1285
+ case 11:
1286
+ ssoResp = _state.sent();
1287
+ return [
1288
+ 3,
1289
+ 13
1290
+ ];
1291
+ case 12:
1292
+ e2 = _state.sent();
1293
+ throw new CredentialsProviderError(e2, {
1294
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1295
+ logger: logger
1296
+ });
1297
+ case 13:
1298
+ tmp = ssoResp.roleCredentials, _ref1 = tmp === void 0 ? {} : tmp, accessKeyId = _ref1.accessKeyId, secretAccessKey = _ref1.secretAccessKey, sessionToken = _ref1.sessionToken, expiration = _ref1.expiration, credentialScope = _ref1.credentialScope, accountId = _ref1.accountId;
1299
+ if (!accessKeyId || !secretAccessKey || !sessionToken || !expiration) {
1300
+ throw new CredentialsProviderError("SSO returns an invalid temporary credential.", {
1301
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1302
+ logger: logger
1303
+ });
1304
+ }
1305
+ credentials = _object_spread({
1306
+ accessKeyId: accessKeyId,
1307
+ secretAccessKey: secretAccessKey,
1308
+ sessionToken: sessionToken,
1309
+ expiration: new Date(expiration)
1310
+ }, credentialScope && {
1311
+ credentialScope: credentialScope
1312
+ }, accountId && {
1313
+ accountId: accountId
1314
+ });
1315
+ if (ssoSession) {
1316
+ setCredentialFeature(credentials, "CREDENTIALS_SSO", "s");
1317
+ } else {
1318
+ setCredentialFeature(credentials, "CREDENTIALS_SSO_LEGACY", "u");
1319
+ }
1320
+ return [
1321
+ 2,
1322
+ credentials
1323
+ ];
1324
+ }
1325
+ });
1326
+ });
1327
+ return function resolveSSOCredentials(_) {
1328
+ return _ref.apply(this, arguments);
1329
+ };
1330
+ }();
1331
+
1332
+ var validateSsoProfile = function(profile, logger) {
1333
+ var sso_start_url = profile.sso_start_url, sso_account_id = profile.sso_account_id, sso_region = profile.sso_region, sso_role_name = profile.sso_role_name;
1334
+ if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
1335
+ throw new CredentialsProviderError('Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", ' + '"sso_region", "sso_role_name", "sso_start_url". Got '.concat(Object.keys(profile).join(", "), "\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html"), {
1336
+ tryNextLink: false,
1337
+ logger: logger
1338
+ });
1339
+ }
1340
+ return profile;
1341
+ };
1342
+
1343
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1344
+ try {
1345
+ var info = gen[key](arg);
1346
+ var value = info.value;
1347
+ } catch (error) {
1348
+ reject(error);
1349
+ return;
1350
+ }
1351
+ if (info.done) {
1352
+ resolve(value);
1353
+ } else {
1354
+ Promise.resolve(value).then(_next, _throw);
1355
+ }
1356
+ }
1357
+ function _async_to_generator(fn) {
1358
+ return function() {
1359
+ var self = this, args = arguments;
1360
+ return new Promise(function(resolve, reject) {
1361
+ var gen = fn.apply(self, args);
1362
+ function _next(value) {
1363
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1364
+ }
1365
+ function _throw(err) {
1366
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1367
+ }
1368
+ _next(undefined);
1369
+ });
1370
+ };
1371
+ }
1372
+ function _ts_generator(thisArg, body) {
1373
+ var f, y, t, g, _ = {
1374
+ label: 0,
1375
+ sent: function() {
1376
+ if (t[0] & 1) throw t[1];
1377
+ return t[1];
1378
+ },
1379
+ trys: [],
1380
+ ops: []
1381
+ };
1382
+ return g = {
1383
+ next: verb(0),
1384
+ "throw": verb(1),
1385
+ "return": verb(2)
1386
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1387
+ return this;
1388
+ }), g;
1389
+ function verb(n) {
1390
+ return function(v) {
1391
+ return step([
1392
+ n,
1393
+ v
1394
+ ]);
1395
+ };
1396
+ }
1397
+ function step(op) {
1398
+ if (f) throw new TypeError("Generator is already executing.");
1399
+ while(_)try {
1400
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1401
+ if (y = 0, t) op = [
1402
+ op[0] & 2,
1403
+ t.value
1404
+ ];
1405
+ switch(op[0]){
1406
+ case 0:
1407
+ case 1:
1408
+ t = op;
1409
+ break;
1410
+ case 4:
1411
+ _.label++;
1412
+ return {
1413
+ value: op[1],
1414
+ done: false
1415
+ };
1416
+ case 5:
1417
+ _.label++;
1418
+ y = op[1];
1419
+ op = [
1420
+ 0
1421
+ ];
1422
+ continue;
1423
+ case 7:
1424
+ op = _.ops.pop();
1425
+ _.trys.pop();
1426
+ continue;
1427
+ default:
1428
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1429
+ _ = 0;
1430
+ continue;
1431
+ }
1432
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1433
+ _.label = op[1];
1434
+ break;
1435
+ }
1436
+ if (op[0] === 6 && _.label < t[1]) {
1437
+ _.label = t[1];
1438
+ t = op;
1439
+ break;
1440
+ }
1441
+ if (t && _.label < t[2]) {
1442
+ _.label = t[2];
1443
+ _.ops.push(op);
1444
+ break;
1445
+ }
1446
+ if (t[2]) _.ops.pop();
1447
+ _.trys.pop();
1448
+ continue;
1449
+ }
1450
+ op = body.call(thisArg, _);
1451
+ } catch (e) {
1452
+ op = [
1453
+ 6,
1454
+ e
1455
+ ];
1456
+ y = 0;
1457
+ } finally{
1458
+ f = t = 0;
1459
+ }
1460
+ if (op[0] & 5) throw op[1];
1461
+ return {
1462
+ value: op[0] ? op[1] : void 0,
1463
+ done: true
1464
+ };
1465
+ }
1466
+ }
1467
+ var fromSSO = function() {
1468
+ var init = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1469
+ return /*#__PURE__*/ _async_to_generator(function() {
1470
+ var callerClientConfig, _init_logger, ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession, ssoClient, _init_profile, profileName, profiles, profile, ssoSessions, session, conflictMsg, _validateSsoProfile, sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session;
1471
+ var _arguments = arguments;
1472
+ return _ts_generator(this, function(_state) {
1473
+ switch(_state.label){
1474
+ case 0:
1475
+ callerClientConfig = (_arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}).callerClientConfig;
1476
+ (_init_logger = init.logger) === null || _init_logger === void 0 ? void 0 : _init_logger.debug("@aws-sdk/credential-provider-sso - fromSSO");
1477
+ ssoStartUrl = init.ssoStartUrl, ssoAccountId = init.ssoAccountId, ssoRegion = init.ssoRegion, ssoRoleName = init.ssoRoleName, ssoSession = init.ssoSession;
1478
+ ssoClient = init.ssoClient;
1479
+ profileName = getProfileName({
1480
+ profile: (_init_profile = init.profile) !== null && _init_profile !== void 0 ? _init_profile : callerClientConfig === null || callerClientConfig === void 0 ? void 0 : callerClientConfig.profile
1481
+ });
1482
+ if (!(!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession)) return [
1483
+ 3,
1484
+ 4
1485
+ ];
1486
+ return [
1487
+ 4,
1488
+ parseKnownFiles(init)
1489
+ ];
1490
+ case 1:
1491
+ profiles = _state.sent();
1492
+ profile = profiles[profileName];
1493
+ if (!profile) {
1494
+ throw new CredentialsProviderError("Profile ".concat(profileName, " was not found."), {
1495
+ logger: init.logger
1496
+ });
1497
+ }
1498
+ if (!isSsoProfile(profile)) {
1499
+ throw new CredentialsProviderError("Profile ".concat(profileName, " is not configured with SSO credentials."), {
1500
+ logger: init.logger
1501
+ });
1502
+ }
1503
+ if (!(profile === null || profile === void 0 ? void 0 : profile.sso_session)) return [
1504
+ 3,
1505
+ 3
1506
+ ];
1507
+ return [
1508
+ 4,
1509
+ loadSsoSessionData(init)
1510
+ ];
1511
+ case 2:
1512
+ ssoSessions = _state.sent();
1513
+ session = ssoSessions[profile.sso_session];
1514
+ conflictMsg = " configurations in profile ".concat(profileName, " and sso-session ").concat(profile.sso_session);
1515
+ if (ssoRegion && ssoRegion !== session.sso_region) {
1516
+ throw new CredentialsProviderError("Conflicting SSO region" + conflictMsg, {
1517
+ tryNextLink: false,
1518
+ logger: init.logger
1519
+ });
1520
+ }
1521
+ if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
1522
+ throw new CredentialsProviderError("Conflicting SSO start_url" + conflictMsg, {
1523
+ tryNextLink: false,
1524
+ logger: init.logger
1525
+ });
1526
+ }
1527
+ profile.sso_region = session.sso_region;
1528
+ profile.sso_start_url = session.sso_start_url;
1529
+ _state.label = 3;
1530
+ case 3:
1531
+ _validateSsoProfile = validateSsoProfile(profile, init.logger), sso_start_url = _validateSsoProfile.sso_start_url, sso_account_id = _validateSsoProfile.sso_account_id, sso_region = _validateSsoProfile.sso_region, sso_role_name = _validateSsoProfile.sso_role_name, sso_session = _validateSsoProfile.sso_session;
1532
+ return [
1533
+ 2,
1534
+ resolveSSOCredentials({
1535
+ ssoStartUrl: sso_start_url,
1536
+ ssoSession: sso_session,
1537
+ ssoAccountId: sso_account_id,
1538
+ ssoRegion: sso_region,
1539
+ ssoRoleName: sso_role_name,
1540
+ ssoClient: ssoClient,
1541
+ clientConfig: init.clientConfig,
1542
+ parentClientConfig: init.parentClientConfig,
1543
+ profile: profileName
1544
+ })
1545
+ ];
1546
+ case 4:
1547
+ if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
1548
+ throw new CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " + '"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"', {
1549
+ tryNextLink: false,
1550
+ logger: init.logger
1551
+ });
1552
+ } else {
1553
+ return [
1554
+ 2,
1555
+ resolveSSOCredentials({
1556
+ ssoStartUrl: ssoStartUrl,
1557
+ ssoSession: ssoSession,
1558
+ ssoAccountId: ssoAccountId,
1559
+ ssoRegion: ssoRegion,
1560
+ ssoRoleName: ssoRoleName,
1561
+ ssoClient: ssoClient,
1562
+ clientConfig: init.clientConfig,
1563
+ parentClientConfig: init.parentClientConfig,
1564
+ profile: profileName
1565
+ })
1566
+ ];
1567
+ }
1568
+ case 5:
1569
+ return [
1570
+ 2
1571
+ ];
1572
+ }
1573
+ });
1574
+ });
1575
+ };
1576
+
1577
+ export { fromSSO, isSsoProfile, validateSsoProfile };