@logto/connector-aws-ses 1.1.2 → 1.2.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.
@@ -1,3220 +0,0 @@
1
- import 'os';
2
- import 'path';
3
- import 'crypto';
4
- import 'fs';
5
- import { aw as collectBodyString, j as getSmithyContext, n as normalizeProvider, r as resolveAwsSdkSigV4Config, k as resolveEndpoint, m as customEndpointFunctions, o as awsEndpointFunctions, q as fromBase64, t as toBase64, A as AwsSdkSigV4Signer, u as NoOpLogger, p as parseUrl, v as fromUtf8, w as toUtf8, x as emitWarningIfUnsupportedVersion, y as emitWarningIfUnsupportedVersion$1, z as calculateBodyLength, B as defaultUserAgent, i as loadConfig, D as NODE_MAX_ATTEMPT_CONFIG_OPTIONS, E as NODE_REGION_CONFIG_FILE_OPTIONS, F as NODE_REGION_CONFIG_OPTIONS, N as NodeHttpHandler, G as NODE_RETRY_MODE_CONFIG_OPTIONS, I as DEFAULT_RETRY_MODE, J as Hash, h as streamCollector, K as NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, L as NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, M as resolveDefaultsModeConfig, O as loadConfigsForDefaultMode, Q as getDefaultExtensionConfiguration, R as getHttpHandlerExtensionConfiguration, S as resolveAwsRegionExtensionConfiguration, T as resolveDefaultRuntimeConfig, U as resolveHttpHandlerRuntimeConfig, V as getAwsRegionExtensionConfiguration, W as Client, X as resolveRegionConfig, Y as resolveEndpointConfig, Z as resolveRetryConfig, _ as resolveUserAgentConfig, $ as getRetryPlugin, a0 as getContentLengthPlugin, a1 as getHostHeaderPlugin, a2 as getLoggerPlugin, a3 as getRecursionDetectionPlugin, a4 as getUserAgentPlugin, a5 as getHttpAuthSchemeEndpointRuleSetPlugin, a6 as getHttpSigningPlugin, a7 as DefaultIdentityProviderConfig, a8 as resolveHostHeaderConfig, a9 as ServiceException, ak as decorateServiceException, aj as expectString, ax as strictParseInt32, ab as expectNonNull, ai as withBaseException, H as HttpRequest, ay as extendedEncodeURIComponent, am as Command, an as getSerdePlugin, ao as getEndpointPlugin } from './index-s7VGoewj.js';
6
- import 'buffer';
7
- import 'stream';
8
- import 'http';
9
- import 'https';
10
- import 'http2';
11
- import 'util';
12
- import { N as NoAuthSigner, S as SENSITIVE_STRING } from './noAuth-NfiqQHEa.js';
13
- import { a as parseRfc3339DateTimeWithOffset } from './date-utils-vaX2R5qo.js';
14
-
15
- const getValueFromTextNode = (obj) => {
16
- const textNodeName = "#text";
17
- for (const key in obj) {
18
- if (obj.hasOwnProperty(key) && obj[key][textNodeName] !== undefined) {
19
- obj[key] = obj[key][textNodeName];
20
- }
21
- else if (typeof obj[key] === "object" && obj[key] !== null) {
22
- obj[key] = getValueFromTextNode(obj[key]);
23
- }
24
- }
25
- return obj;
26
- };
27
-
28
- var validator$2 = {};
29
-
30
- var util$3 = {};
31
-
32
- (function (exports) {
33
-
34
- const nameStartChar = ':A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
35
- const nameChar = nameStartChar + '\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
36
- const nameRegexp = '[' + nameStartChar + '][' + nameChar + ']*';
37
- const regexName = new RegExp('^' + nameRegexp + '$');
38
-
39
- const getAllMatches = function(string, regex) {
40
- const matches = [];
41
- let match = regex.exec(string);
42
- while (match) {
43
- const allmatches = [];
44
- allmatches.startIndex = regex.lastIndex - match[0].length;
45
- const len = match.length;
46
- for (let index = 0; index < len; index++) {
47
- allmatches.push(match[index]);
48
- }
49
- matches.push(allmatches);
50
- match = regex.exec(string);
51
- }
52
- return matches;
53
- };
54
-
55
- const isName = function(string) {
56
- const match = regexName.exec(string);
57
- return !(match === null || typeof match === 'undefined');
58
- };
59
-
60
- exports.isExist = function(v) {
61
- return typeof v !== 'undefined';
62
- };
63
-
64
- exports.isEmptyObject = function(obj) {
65
- return Object.keys(obj).length === 0;
66
- };
67
-
68
- /**
69
- * Copy all the properties of a into b.
70
- * @param {*} target
71
- * @param {*} a
72
- */
73
- exports.merge = function(target, a, arrayMode) {
74
- if (a) {
75
- const keys = Object.keys(a); // will return an array of own properties
76
- const len = keys.length; //don't make it inline
77
- for (let i = 0; i < len; i++) {
78
- if (arrayMode === 'strict') {
79
- target[keys[i]] = [ a[keys[i]] ];
80
- } else {
81
- target[keys[i]] = a[keys[i]];
82
- }
83
- }
84
- }
85
- };
86
- /* exports.merge =function (b,a){
87
- return Object.assign(b,a);
88
- } */
89
-
90
- exports.getValue = function(v) {
91
- if (exports.isExist(v)) {
92
- return v;
93
- } else {
94
- return '';
95
- }
96
- };
97
-
98
- // const fakeCall = function(a) {return a;};
99
- // const fakeCallNoReturn = function() {};
100
-
101
- exports.isName = isName;
102
- exports.getAllMatches = getAllMatches;
103
- exports.nameRegexp = nameRegexp;
104
- } (util$3));
105
-
106
- const util$2 = util$3;
107
-
108
- const defaultOptions$2 = {
109
- allowBooleanAttributes: false, //A tag can have attributes without any value
110
- unpairedTags: []
111
- };
112
-
113
- //const tagsPattern = new RegExp("<\\/?([\\w:\\-_\.]+)\\s*\/?>","g");
114
- validator$2.validate = function (xmlData, options) {
115
- options = Object.assign({}, defaultOptions$2, options);
116
-
117
- //xmlData = xmlData.replace(/(\r\n|\n|\r)/gm,"");//make it single line
118
- //xmlData = xmlData.replace(/(^\s*<\?xml.*?\?>)/g,"");//Remove XML starting tag
119
- //xmlData = xmlData.replace(/(<!DOCTYPE[\s\w\"\.\/\-\:]+(\[.*\])*\s*>)/g,"");//Remove DOCTYPE
120
- const tags = [];
121
- let tagFound = false;
122
-
123
- //indicates that the root tag has been closed (aka. depth 0 has been reached)
124
- let reachedRoot = false;
125
-
126
- if (xmlData[0] === '\ufeff') {
127
- // check for byte order mark (BOM)
128
- xmlData = xmlData.substr(1);
129
- }
130
-
131
- for (let i = 0; i < xmlData.length; i++) {
132
-
133
- if (xmlData[i] === '<' && xmlData[i+1] === '?') {
134
- i+=2;
135
- i = readPI(xmlData,i);
136
- if (i.err) return i;
137
- }else if (xmlData[i] === '<') {
138
- //starting of tag
139
- //read until you reach to '>' avoiding any '>' in attribute value
140
- let tagStartPos = i;
141
- i++;
142
-
143
- if (xmlData[i] === '!') {
144
- i = readCommentAndCDATA(xmlData, i);
145
- continue;
146
- } else {
147
- let closingTag = false;
148
- if (xmlData[i] === '/') {
149
- //closing tag
150
- closingTag = true;
151
- i++;
152
- }
153
- //read tagname
154
- let tagName = '';
155
- for (; i < xmlData.length &&
156
- xmlData[i] !== '>' &&
157
- xmlData[i] !== ' ' &&
158
- xmlData[i] !== '\t' &&
159
- xmlData[i] !== '\n' &&
160
- xmlData[i] !== '\r'; i++
161
- ) {
162
- tagName += xmlData[i];
163
- }
164
- tagName = tagName.trim();
165
- //console.log(tagName);
166
-
167
- if (tagName[tagName.length - 1] === '/') {
168
- //self closing tag without attributes
169
- tagName = tagName.substring(0, tagName.length - 1);
170
- //continue;
171
- i--;
172
- }
173
- if (!validateTagName(tagName)) {
174
- let msg;
175
- if (tagName.trim().length === 0) {
176
- msg = "Invalid space after '<'.";
177
- } else {
178
- msg = "Tag '"+tagName+"' is an invalid name.";
179
- }
180
- return getErrorObject('InvalidTag', msg, getLineNumberForPosition(xmlData, i));
181
- }
182
-
183
- const result = readAttributeStr(xmlData, i);
184
- if (result === false) {
185
- return getErrorObject('InvalidAttr', "Attributes for '"+tagName+"' have open quote.", getLineNumberForPosition(xmlData, i));
186
- }
187
- let attrStr = result.value;
188
- i = result.index;
189
-
190
- if (attrStr[attrStr.length - 1] === '/') {
191
- //self closing tag
192
- const attrStrStart = i - attrStr.length;
193
- attrStr = attrStr.substring(0, attrStr.length - 1);
194
- const isValid = validateAttributeString(attrStr, options);
195
- if (isValid === true) {
196
- tagFound = true;
197
- //continue; //text may presents after self closing tag
198
- } else {
199
- //the result from the nested function returns the position of the error within the attribute
200
- //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
201
- //this gives us the absolute index in the entire xml, which we can use to find the line at last
202
- return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
203
- }
204
- } else if (closingTag) {
205
- if (!result.tagClosed) {
206
- return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
207
- } else if (attrStr.trim().length > 0) {
208
- return getErrorObject('InvalidTag', "Closing tag '"+tagName+"' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
209
- } else {
210
- const otg = tags.pop();
211
- if (tagName !== otg.tagName) {
212
- let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
213
- return getErrorObject('InvalidTag',
214
- "Expected closing tag '"+otg.tagName+"' (opened in line "+openPos.line+", col "+openPos.col+") instead of closing tag '"+tagName+"'.",
215
- getLineNumberForPosition(xmlData, tagStartPos));
216
- }
217
-
218
- //when there are no more tags, we reached the root level.
219
- if (tags.length == 0) {
220
- reachedRoot = true;
221
- }
222
- }
223
- } else {
224
- const isValid = validateAttributeString(attrStr, options);
225
- if (isValid !== true) {
226
- //the result from the nested function returns the position of the error within the attribute
227
- //in order to get the 'true' error line, we need to calculate the position where the attribute begins (i - attrStr.length) and then add the position within the attribute
228
- //this gives us the absolute index in the entire xml, which we can use to find the line at last
229
- return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
230
- }
231
-
232
- //if the root level has been reached before ...
233
- if (reachedRoot === true) {
234
- return getErrorObject('InvalidXml', 'Multiple possible root nodes found.', getLineNumberForPosition(xmlData, i));
235
- } else if(options.unpairedTags.indexOf(tagName) !== -1); else {
236
- tags.push({tagName, tagStartPos});
237
- }
238
- tagFound = true;
239
- }
240
-
241
- //skip tag text value
242
- //It may include comments and CDATA value
243
- for (i++; i < xmlData.length; i++) {
244
- if (xmlData[i] === '<') {
245
- if (xmlData[i + 1] === '!') {
246
- //comment or CADATA
247
- i++;
248
- i = readCommentAndCDATA(xmlData, i);
249
- continue;
250
- } else if (xmlData[i+1] === '?') {
251
- i = readPI(xmlData, ++i);
252
- if (i.err) return i;
253
- } else {
254
- break;
255
- }
256
- } else if (xmlData[i] === '&') {
257
- const afterAmp = validateAmpersand(xmlData, i);
258
- if (afterAmp == -1)
259
- return getErrorObject('InvalidChar', "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
260
- i = afterAmp;
261
- }else {
262
- if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
263
- return getErrorObject('InvalidXml', "Extra text at the end", getLineNumberForPosition(xmlData, i));
264
- }
265
- }
266
- } //end of reading tag text value
267
- if (xmlData[i] === '<') {
268
- i--;
269
- }
270
- }
271
- } else {
272
- if ( isWhiteSpace(xmlData[i])) {
273
- continue;
274
- }
275
- return getErrorObject('InvalidChar', "char '"+xmlData[i]+"' is not expected.", getLineNumberForPosition(xmlData, i));
276
- }
277
- }
278
-
279
- if (!tagFound) {
280
- return getErrorObject('InvalidXml', 'Start tag expected.', 1);
281
- }else if (tags.length == 1) {
282
- return getErrorObject('InvalidTag', "Unclosed tag '"+tags[0].tagName+"'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
283
- }else if (tags.length > 0) {
284
- return getErrorObject('InvalidXml', "Invalid '"+
285
- JSON.stringify(tags.map(t => t.tagName), null, 4).replace(/\r?\n/g, '')+
286
- "' found.", {line: 1, col: 1});
287
- }
288
-
289
- return true;
290
- };
291
-
292
- function isWhiteSpace(char){
293
- return char === ' ' || char === '\t' || char === '\n' || char === '\r';
294
- }
295
- /**
296
- * Read Processing insstructions and skip
297
- * @param {*} xmlData
298
- * @param {*} i
299
- */
300
- function readPI(xmlData, i) {
301
- const start = i;
302
- for (; i < xmlData.length; i++) {
303
- if (xmlData[i] == '?' || xmlData[i] == ' ') {
304
- //tagname
305
- const tagname = xmlData.substr(start, i - start);
306
- if (i > 5 && tagname === 'xml') {
307
- return getErrorObject('InvalidXml', 'XML declaration allowed only at the start of the document.', getLineNumberForPosition(xmlData, i));
308
- } else if (xmlData[i] == '?' && xmlData[i + 1] == '>') {
309
- //check if valid attribut string
310
- i++;
311
- break;
312
- } else {
313
- continue;
314
- }
315
- }
316
- }
317
- return i;
318
- }
319
-
320
- function readCommentAndCDATA(xmlData, i) {
321
- if (xmlData.length > i + 5 && xmlData[i + 1] === '-' && xmlData[i + 2] === '-') {
322
- //comment
323
- for (i += 3; i < xmlData.length; i++) {
324
- if (xmlData[i] === '-' && xmlData[i + 1] === '-' && xmlData[i + 2] === '>') {
325
- i += 2;
326
- break;
327
- }
328
- }
329
- } else if (
330
- xmlData.length > i + 8 &&
331
- xmlData[i + 1] === 'D' &&
332
- xmlData[i + 2] === 'O' &&
333
- xmlData[i + 3] === 'C' &&
334
- xmlData[i + 4] === 'T' &&
335
- xmlData[i + 5] === 'Y' &&
336
- xmlData[i + 6] === 'P' &&
337
- xmlData[i + 7] === 'E'
338
- ) {
339
- let angleBracketsCount = 1;
340
- for (i += 8; i < xmlData.length; i++) {
341
- if (xmlData[i] === '<') {
342
- angleBracketsCount++;
343
- } else if (xmlData[i] === '>') {
344
- angleBracketsCount--;
345
- if (angleBracketsCount === 0) {
346
- break;
347
- }
348
- }
349
- }
350
- } else if (
351
- xmlData.length > i + 9 &&
352
- xmlData[i + 1] === '[' &&
353
- xmlData[i + 2] === 'C' &&
354
- xmlData[i + 3] === 'D' &&
355
- xmlData[i + 4] === 'A' &&
356
- xmlData[i + 5] === 'T' &&
357
- xmlData[i + 6] === 'A' &&
358
- xmlData[i + 7] === '['
359
- ) {
360
- for (i += 8; i < xmlData.length; i++) {
361
- if (xmlData[i] === ']' && xmlData[i + 1] === ']' && xmlData[i + 2] === '>') {
362
- i += 2;
363
- break;
364
- }
365
- }
366
- }
367
-
368
- return i;
369
- }
370
-
371
- const doubleQuote = '"';
372
- const singleQuote = "'";
373
-
374
- /**
375
- * Keep reading xmlData until '<' is found outside the attribute value.
376
- * @param {string} xmlData
377
- * @param {number} i
378
- */
379
- function readAttributeStr(xmlData, i) {
380
- let attrStr = '';
381
- let startChar = '';
382
- let tagClosed = false;
383
- for (; i < xmlData.length; i++) {
384
- if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
385
- if (startChar === '') {
386
- startChar = xmlData[i];
387
- } else if (startChar !== xmlData[i]) ; else {
388
- startChar = '';
389
- }
390
- } else if (xmlData[i] === '>') {
391
- if (startChar === '') {
392
- tagClosed = true;
393
- break;
394
- }
395
- }
396
- attrStr += xmlData[i];
397
- }
398
- if (startChar !== '') {
399
- return false;
400
- }
401
-
402
- return {
403
- value: attrStr,
404
- index: i,
405
- tagClosed: tagClosed
406
- };
407
- }
408
-
409
- /**
410
- * Select all the attributes whether valid or invalid.
411
- */
412
- const validAttrStrRegxp = new RegExp('(\\s*)([^\\s=]+)(\\s*=)?(\\s*([\'"])(([\\s\\S])*?)\\5)?', 'g');
413
-
414
- //attr, ="sd", a="amit's", a="sd"b="saf", ab cd=""
415
-
416
- function validateAttributeString(attrStr, options) {
417
- //console.log("start:"+attrStr+":end");
418
-
419
- //if(attrStr.trim().length === 0) return true; //empty string
420
-
421
- const matches = util$2.getAllMatches(attrStr, validAttrStrRegxp);
422
- const attrNames = {};
423
-
424
- for (let i = 0; i < matches.length; i++) {
425
- if (matches[i][1].length === 0) {
426
- //nospace before attribute name: a="sd"b="saf"
427
- return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' has no space in starting.", getPositionFromMatch(matches[i]))
428
- } else if (matches[i][3] !== undefined && matches[i][4] === undefined) {
429
- return getErrorObject('InvalidAttr', "Attribute '"+matches[i][2]+"' is without value.", getPositionFromMatch(matches[i]));
430
- } else if (matches[i][3] === undefined && !options.allowBooleanAttributes) {
431
- //independent attribute: ab
432
- return getErrorObject('InvalidAttr', "boolean attribute '"+matches[i][2]+"' is not allowed.", getPositionFromMatch(matches[i]));
433
- }
434
- /* else if(matches[i][6] === undefined){//attribute without value: ab=
435
- return { err: { code:"InvalidAttr",msg:"attribute " + matches[i][2] + " has no value assigned."}};
436
- } */
437
- const attrName = matches[i][2];
438
- if (!validateAttrName(attrName)) {
439
- return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is an invalid name.", getPositionFromMatch(matches[i]));
440
- }
441
- if (!attrNames.hasOwnProperty(attrName)) {
442
- //check for duplicate attribute.
443
- attrNames[attrName] = 1;
444
- } else {
445
- return getErrorObject('InvalidAttr', "Attribute '"+attrName+"' is repeated.", getPositionFromMatch(matches[i]));
446
- }
447
- }
448
-
449
- return true;
450
- }
451
-
452
- function validateNumberAmpersand(xmlData, i) {
453
- let re = /\d/;
454
- if (xmlData[i] === 'x') {
455
- i++;
456
- re = /[\da-fA-F]/;
457
- }
458
- for (; i < xmlData.length; i++) {
459
- if (xmlData[i] === ';')
460
- return i;
461
- if (!xmlData[i].match(re))
462
- break;
463
- }
464
- return -1;
465
- }
466
-
467
- function validateAmpersand(xmlData, i) {
468
- // https://www.w3.org/TR/xml/#dt-charref
469
- i++;
470
- if (xmlData[i] === ';')
471
- return -1;
472
- if (xmlData[i] === '#') {
473
- i++;
474
- return validateNumberAmpersand(xmlData, i);
475
- }
476
- let count = 0;
477
- for (; i < xmlData.length; i++, count++) {
478
- if (xmlData[i].match(/\w/) && count < 20)
479
- continue;
480
- if (xmlData[i] === ';')
481
- break;
482
- return -1;
483
- }
484
- return i;
485
- }
486
-
487
- function getErrorObject(code, message, lineNumber) {
488
- return {
489
- err: {
490
- code: code,
491
- msg: message,
492
- line: lineNumber.line || lineNumber,
493
- col: lineNumber.col,
494
- },
495
- };
496
- }
497
-
498
- function validateAttrName(attrName) {
499
- return util$2.isName(attrName);
500
- }
501
-
502
- // const startsWithXML = /^xml/i;
503
-
504
- function validateTagName(tagname) {
505
- return util$2.isName(tagname) /* && !tagname.match(startsWithXML) */;
506
- }
507
-
508
- //this function returns the line number for the character at the given index
509
- function getLineNumberForPosition(xmlData, index) {
510
- const lines = xmlData.substring(0, index).split(/\r?\n/);
511
- return {
512
- line: lines.length,
513
-
514
- // column number is last line's length + 1, because column numbering starts at 1:
515
- col: lines[lines.length - 1].length + 1
516
- };
517
- }
518
-
519
- //this function returns the position of the first character of match within attrStr
520
- function getPositionFromMatch(match) {
521
- return match.startIndex + match[1].length;
522
- }
523
-
524
- var OptionsBuilder = {};
525
-
526
- const defaultOptions$1 = {
527
- preserveOrder: false,
528
- attributeNamePrefix: '@_',
529
- attributesGroupName: false,
530
- textNodeName: '#text',
531
- ignoreAttributes: true,
532
- removeNSPrefix: false, // remove NS from tag name or attribute name if true
533
- allowBooleanAttributes: false, //a tag can have attributes without any value
534
- //ignoreRootElement : false,
535
- parseTagValue: true,
536
- parseAttributeValue: false,
537
- trimValues: true, //Trim string values of tag and attributes
538
- cdataPropName: false,
539
- numberParseOptions: {
540
- hex: true,
541
- leadingZeros: true,
542
- eNotation: true
543
- },
544
- tagValueProcessor: function(tagName, val) {
545
- return val;
546
- },
547
- attributeValueProcessor: function(attrName, val) {
548
- return val;
549
- },
550
- stopNodes: [], //nested tags will not be parsed even for errors
551
- alwaysCreateTextNode: false,
552
- isArray: () => false,
553
- commentPropName: false,
554
- unpairedTags: [],
555
- processEntities: true,
556
- htmlEntities: false,
557
- ignoreDeclaration: false,
558
- ignorePiTags: false,
559
- transformTagName: false,
560
- transformAttributeName: false,
561
- updateTag: function(tagName, jPath, attrs){
562
- return tagName
563
- },
564
- // skipEmptyListItem: false
565
- };
566
-
567
- const buildOptions$1 = function(options) {
568
- return Object.assign({}, defaultOptions$1, options);
569
- };
570
-
571
- OptionsBuilder.buildOptions = buildOptions$1;
572
- OptionsBuilder.defaultOptions = defaultOptions$1;
573
-
574
- class XmlNode{
575
- constructor(tagname) {
576
- this.tagname = tagname;
577
- this.child = []; //nested tags, text, cdata, comments in order
578
- this[":@"] = {}; //attributes map
579
- }
580
- add(key,val){
581
- // this.child.push( {name : key, val: val, isCdata: isCdata });
582
- if(key === "__proto__") key = "#__proto__";
583
- this.child.push( {[key]: val });
584
- }
585
- addChild(node) {
586
- if(node.tagname === "__proto__") node.tagname = "#__proto__";
587
- if(node[":@"] && Object.keys(node[":@"]).length > 0){
588
- this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
589
- }else {
590
- this.child.push( { [node.tagname]: node.child });
591
- }
592
- };
593
- }
594
-
595
- var xmlNode$1 = XmlNode;
596
-
597
- const util$1 = util$3;
598
-
599
- //TODO: handle comments
600
- function readDocType$1(xmlData, i){
601
-
602
- const entities = {};
603
- if( xmlData[i + 3] === 'O' &&
604
- xmlData[i + 4] === 'C' &&
605
- xmlData[i + 5] === 'T' &&
606
- xmlData[i + 6] === 'Y' &&
607
- xmlData[i + 7] === 'P' &&
608
- xmlData[i + 8] === 'E')
609
- {
610
- i = i+9;
611
- let angleBracketsCount = 1;
612
- let hasBody = false, comment = false;
613
- let exp = "";
614
- for(;i<xmlData.length;i++){
615
- if (xmlData[i] === '<' && !comment) { //Determine the tag type
616
- if( hasBody && isEntity(xmlData, i)){
617
- i += 7;
618
- [entityName, val,i] = readEntityExp(xmlData,i+1);
619
- if(val.indexOf("&") === -1) //Parameter entities are not supported
620
- entities[ validateEntityName(entityName) ] = {
621
- regx : RegExp( `&${entityName};`,"g"),
622
- val: val
623
- };
624
- }
625
- else if( hasBody && isElement(xmlData, i)) i += 8;//Not supported
626
- else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported
627
- else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported
628
- else if( isComment) comment = true;
629
- else throw new Error("Invalid DOCTYPE");
630
-
631
- angleBracketsCount++;
632
- exp = "";
633
- } else if (xmlData[i] === '>') { //Read tag content
634
- if(comment){
635
- if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
636
- comment = false;
637
- angleBracketsCount--;
638
- }
639
- }else {
640
- angleBracketsCount--;
641
- }
642
- if (angleBracketsCount === 0) {
643
- break;
644
- }
645
- }else if( xmlData[i] === '['){
646
- hasBody = true;
647
- }else {
648
- exp += xmlData[i];
649
- }
650
- }
651
- if(angleBracketsCount !== 0){
652
- throw new Error(`Unclosed DOCTYPE`);
653
- }
654
- }else {
655
- throw new Error(`Invalid Tag instead of DOCTYPE`);
656
- }
657
- return {entities, i};
658
- }
659
-
660
- function readEntityExp(xmlData,i){
661
- //External entities are not supported
662
- // <!ENTITY ext SYSTEM "http://normal-website.com" >
663
-
664
- //Parameter entities are not supported
665
- // <!ENTITY entityname "&anotherElement;">
666
-
667
- //Internal entities are supported
668
- // <!ENTITY entityname "replacement text">
669
-
670
- //read EntityName
671
- let entityName = "";
672
- for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) {
673
- // if(xmlData[i] === " ") continue;
674
- // else
675
- entityName += xmlData[i];
676
- }
677
- entityName = entityName.trim();
678
- if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
679
-
680
- //read Entity Value
681
- const startChar = xmlData[i++];
682
- let val = "";
683
- for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {
684
- val += xmlData[i];
685
- }
686
- return [entityName, val, i];
687
- }
688
-
689
- function isComment(xmlData, i){
690
- if(xmlData[i+1] === '!' &&
691
- xmlData[i+2] === '-' &&
692
- xmlData[i+3] === '-') return true
693
- return false
694
- }
695
- function isEntity(xmlData, i){
696
- if(xmlData[i+1] === '!' &&
697
- xmlData[i+2] === 'E' &&
698
- xmlData[i+3] === 'N' &&
699
- xmlData[i+4] === 'T' &&
700
- xmlData[i+5] === 'I' &&
701
- xmlData[i+6] === 'T' &&
702
- xmlData[i+7] === 'Y') return true
703
- return false
704
- }
705
- function isElement(xmlData, i){
706
- if(xmlData[i+1] === '!' &&
707
- xmlData[i+2] === 'E' &&
708
- xmlData[i+3] === 'L' &&
709
- xmlData[i+4] === 'E' &&
710
- xmlData[i+5] === 'M' &&
711
- xmlData[i+6] === 'E' &&
712
- xmlData[i+7] === 'N' &&
713
- xmlData[i+8] === 'T') return true
714
- return false
715
- }
716
-
717
- function isAttlist(xmlData, i){
718
- if(xmlData[i+1] === '!' &&
719
- xmlData[i+2] === 'A' &&
720
- xmlData[i+3] === 'T' &&
721
- xmlData[i+4] === 'T' &&
722
- xmlData[i+5] === 'L' &&
723
- xmlData[i+6] === 'I' &&
724
- xmlData[i+7] === 'S' &&
725
- xmlData[i+8] === 'T') return true
726
- return false
727
- }
728
- function isNotation(xmlData, i){
729
- if(xmlData[i+1] === '!' &&
730
- xmlData[i+2] === 'N' &&
731
- xmlData[i+3] === 'O' &&
732
- xmlData[i+4] === 'T' &&
733
- xmlData[i+5] === 'A' &&
734
- xmlData[i+6] === 'T' &&
735
- xmlData[i+7] === 'I' &&
736
- xmlData[i+8] === 'O' &&
737
- xmlData[i+9] === 'N') return true
738
- return false
739
- }
740
-
741
- function validateEntityName(name){
742
- if (util$1.isName(name))
743
- return name;
744
- else
745
- throw new Error(`Invalid entity name ${name}`);
746
- }
747
-
748
- var DocTypeReader = readDocType$1;
749
-
750
- const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
751
- const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
752
- // const octRegex = /0x[a-z0-9]+/;
753
- // const binRegex = /0x[a-z0-9]+/;
754
-
755
-
756
- //polyfill
757
- if (!Number.parseInt && window.parseInt) {
758
- Number.parseInt = window.parseInt;
759
- }
760
- if (!Number.parseFloat && window.parseFloat) {
761
- Number.parseFloat = window.parseFloat;
762
- }
763
-
764
-
765
- const consider = {
766
- hex : true,
767
- leadingZeros: true,
768
- decimalPoint: "\.",
769
- eNotation: true
770
- //skipLike: /regex/
771
- };
772
-
773
- function toNumber$1(str, options = {}){
774
- // const options = Object.assign({}, consider);
775
- // if(opt.leadingZeros === false){
776
- // options.leadingZeros = false;
777
- // }else if(opt.hex === false){
778
- // options.hex = false;
779
- // }
780
-
781
- options = Object.assign({}, consider, options );
782
- if(!str || typeof str !== "string" ) return str;
783
-
784
- let trimmedStr = str.trim();
785
- // if(trimmedStr === "0.0") return 0;
786
- // else if(trimmedStr === "+0.0") return 0;
787
- // else if(trimmedStr === "-0.0") return -0;
788
-
789
- if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
790
- else if (options.hex && hexRegex.test(trimmedStr)) {
791
- return Number.parseInt(trimmedStr, 16);
792
- // } else if (options.parseOct && octRegex.test(str)) {
793
- // return Number.parseInt(val, 8);
794
- // }else if (options.parseBin && binRegex.test(str)) {
795
- // return Number.parseInt(val, 2);
796
- }else {
797
- //separate negative sign, leading zeros, and rest number
798
- const match = numRegex.exec(trimmedStr);
799
- if(match){
800
- const sign = match[1];
801
- const leadingZeros = match[2];
802
- let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
803
- //trim ending zeros for floating number
804
-
805
- const eNotation = match[4] || match[6];
806
- if(!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".") return str; //-0123
807
- else if(!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".") return str; //0123
808
- else {//no leading zeros or leading zeros are allowed
809
- const num = Number(trimmedStr);
810
- const numStr = "" + num;
811
- if(numStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
812
- if(options.eNotation) return num;
813
- else return str;
814
- }else if(eNotation){ //given number has enotation
815
- if(options.eNotation) return num;
816
- else return str;
817
- }else if(trimmedStr.indexOf(".") !== -1){ //floating number
818
- // const decimalPart = match[5].substr(1);
819
- // const intPart = trimmedStr.substr(0,trimmedStr.indexOf("."));
820
-
821
-
822
- // const p = numStr.indexOf(".");
823
- // const givenIntPart = numStr.substr(0,p);
824
- // const givenDecPart = numStr.substr(p+1);
825
- if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
826
- else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
827
- else if( sign && numStr === "-"+numTrimmedByZeros) return num;
828
- else return str;
829
- }
830
-
831
- if(leadingZeros){
832
- // if(numTrimmedByZeros === numStr){
833
- // if(options.leadingZeros) return num;
834
- // else return str;
835
- // }else return str;
836
- if(numTrimmedByZeros === numStr) return num;
837
- else if(sign+numTrimmedByZeros === numStr) return num;
838
- else return str;
839
- }
840
-
841
- if(trimmedStr === numStr) return num;
842
- else if(trimmedStr === sign+numStr) return num;
843
- // else{
844
- // //number with +/- sign
845
- // trimmedStr.test(/[-+][0-9]);
846
-
847
- // }
848
- return str;
849
- }
850
- // else if(!eNotation && trimmedStr && trimmedStr !== Number(trimmedStr) ) return str;
851
-
852
- }else { //non-numeric string
853
- return str;
854
- }
855
- }
856
- }
857
-
858
- /**
859
- *
860
- * @param {string} numStr without leading zeros
861
- * @returns
862
- */
863
- function trimZeros(numStr){
864
- if(numStr && numStr.indexOf(".") !== -1){//float
865
- numStr = numStr.replace(/0+$/, ""); //remove ending zeros
866
- if(numStr === ".") numStr = "0";
867
- else if(numStr[0] === ".") numStr = "0"+numStr;
868
- else if(numStr[numStr.length-1] === ".") numStr = numStr.substr(0,numStr.length-1);
869
- return numStr;
870
- }
871
- return numStr;
872
- }
873
- var strnum = toNumber$1;
874
-
875
- ///@ts-check
876
-
877
- const util = util$3;
878
- const xmlNode = xmlNode$1;
879
- const readDocType = DocTypeReader;
880
- const toNumber = strnum;
881
-
882
- '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
883
- .replace(/NAME/g, util.nameRegexp);
884
-
885
- //const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
886
- //const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
887
-
888
- let OrderedObjParser$1 = class OrderedObjParser{
889
- constructor(options){
890
- this.options = options;
891
- this.currentNode = null;
892
- this.tagsNodeStack = [];
893
- this.docTypeEntities = {};
894
- this.lastEntities = {
895
- "apos" : { regex: /&(apos|#39|#x27);/g, val : "'"},
896
- "gt" : { regex: /&(gt|#62|#x3E);/g, val : ">"},
897
- "lt" : { regex: /&(lt|#60|#x3C);/g, val : "<"},
898
- "quot" : { regex: /&(quot|#34|#x22);/g, val : "\""},
899
- };
900
- this.ampEntity = { regex: /&(amp|#38|#x26);/g, val : "&"};
901
- this.htmlEntities = {
902
- "space": { regex: /&(nbsp|#160);/g, val: " " },
903
- // "lt" : { regex: /&(lt|#60);/g, val: "<" },
904
- // "gt" : { regex: /&(gt|#62);/g, val: ">" },
905
- // "amp" : { regex: /&(amp|#38);/g, val: "&" },
906
- // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
907
- // "apos" : { regex: /&(apos|#39);/g, val: "'" },
908
- "cent" : { regex: /&(cent|#162);/g, val: "¢" },
909
- "pound" : { regex: /&(pound|#163);/g, val: "£" },
910
- "yen" : { regex: /&(yen|#165);/g, val: "¥" },
911
- "euro" : { regex: /&(euro|#8364);/g, val: "€" },
912
- "copyright" : { regex: /&(copy|#169);/g, val: "©" },
913
- "reg" : { regex: /&(reg|#174);/g, val: "®" },
914
- "inr" : { regex: /&(inr|#8377);/g, val: "₹" },
915
- };
916
- this.addExternalEntities = addExternalEntities;
917
- this.parseXml = parseXml;
918
- this.parseTextData = parseTextData;
919
- this.resolveNameSpace = resolveNameSpace;
920
- this.buildAttributesMap = buildAttributesMap;
921
- this.isItStopNode = isItStopNode;
922
- this.replaceEntitiesValue = replaceEntitiesValue$1;
923
- this.readStopNodeData = readStopNodeData;
924
- this.saveTextToParentTag = saveTextToParentTag;
925
- this.addChild = addChild;
926
- }
927
-
928
- };
929
-
930
- function addExternalEntities(externalEntities){
931
- const entKeys = Object.keys(externalEntities);
932
- for (let i = 0; i < entKeys.length; i++) {
933
- const ent = entKeys[i];
934
- this.lastEntities[ent] = {
935
- regex: new RegExp("&"+ent+";","g"),
936
- val : externalEntities[ent]
937
- };
938
- }
939
- }
940
-
941
- /**
942
- * @param {string} val
943
- * @param {string} tagName
944
- * @param {string} jPath
945
- * @param {boolean} dontTrim
946
- * @param {boolean} hasAttributes
947
- * @param {boolean} isLeafNode
948
- * @param {boolean} escapeEntities
949
- */
950
- function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
951
- if (val !== undefined) {
952
- if (this.options.trimValues && !dontTrim) {
953
- val = val.trim();
954
- }
955
- if(val.length > 0){
956
- if(!escapeEntities) val = this.replaceEntitiesValue(val);
957
-
958
- const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
959
- if(newval === null || newval === undefined){
960
- //don't parse
961
- return val;
962
- }else if(typeof newval !== typeof val || newval !== val){
963
- //overwrite
964
- return newval;
965
- }else if(this.options.trimValues){
966
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
967
- }else {
968
- const trimmedVal = val.trim();
969
- if(trimmedVal === val){
970
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
971
- }else {
972
- return val;
973
- }
974
- }
975
- }
976
- }
977
- }
978
-
979
- function resolveNameSpace(tagname) {
980
- if (this.options.removeNSPrefix) {
981
- const tags = tagname.split(':');
982
- const prefix = tagname.charAt(0) === '/' ? '/' : '';
983
- if (tags[0] === 'xmlns') {
984
- return '';
985
- }
986
- if (tags.length === 2) {
987
- tagname = prefix + tags[1];
988
- }
989
- }
990
- return tagname;
991
- }
992
-
993
- //TODO: change regex to capture NS
994
- //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
995
- const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
996
-
997
- function buildAttributesMap(attrStr, jPath, tagName) {
998
- if (!this.options.ignoreAttributes && typeof attrStr === 'string') {
999
- // attrStr = attrStr.replace(/\r?\n/g, ' ');
1000
- //attrStr = attrStr || attrStr.trim();
1001
-
1002
- const matches = util.getAllMatches(attrStr, attrsRegx);
1003
- const len = matches.length; //don't make it inline
1004
- const attrs = {};
1005
- for (let i = 0; i < len; i++) {
1006
- const attrName = this.resolveNameSpace(matches[i][1]);
1007
- let oldVal = matches[i][4];
1008
- let aName = this.options.attributeNamePrefix + attrName;
1009
- if (attrName.length) {
1010
- if (this.options.transformAttributeName) {
1011
- aName = this.options.transformAttributeName(aName);
1012
- }
1013
- if(aName === "__proto__") aName = "#__proto__";
1014
- if (oldVal !== undefined) {
1015
- if (this.options.trimValues) {
1016
- oldVal = oldVal.trim();
1017
- }
1018
- oldVal = this.replaceEntitiesValue(oldVal);
1019
- const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
1020
- if(newVal === null || newVal === undefined){
1021
- //don't parse
1022
- attrs[aName] = oldVal;
1023
- }else if(typeof newVal !== typeof oldVal || newVal !== oldVal){
1024
- //overwrite
1025
- attrs[aName] = newVal;
1026
- }else {
1027
- //parse
1028
- attrs[aName] = parseValue(
1029
- oldVal,
1030
- this.options.parseAttributeValue,
1031
- this.options.numberParseOptions
1032
- );
1033
- }
1034
- } else if (this.options.allowBooleanAttributes) {
1035
- attrs[aName] = true;
1036
- }
1037
- }
1038
- }
1039
- if (!Object.keys(attrs).length) {
1040
- return;
1041
- }
1042
- if (this.options.attributesGroupName) {
1043
- const attrCollection = {};
1044
- attrCollection[this.options.attributesGroupName] = attrs;
1045
- return attrCollection;
1046
- }
1047
- return attrs
1048
- }
1049
- }
1050
-
1051
- const parseXml = function(xmlData) {
1052
- xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
1053
- const xmlObj = new xmlNode('!xml');
1054
- let currentNode = xmlObj;
1055
- let textData = "";
1056
- let jPath = "";
1057
- for(let i=0; i< xmlData.length; i++){//for each char in XML data
1058
- const ch = xmlData[i];
1059
- if(ch === '<'){
1060
- // const nextIndex = i+1;
1061
- // const _2ndChar = xmlData[nextIndex];
1062
- if( xmlData[i+1] === '/') {//Closing Tag
1063
- const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
1064
- let tagName = xmlData.substring(i+2,closeIndex).trim();
1065
-
1066
- if(this.options.removeNSPrefix){
1067
- const colonIndex = tagName.indexOf(":");
1068
- if(colonIndex !== -1){
1069
- tagName = tagName.substr(colonIndex+1);
1070
- }
1071
- }
1072
-
1073
- if(this.options.transformTagName) {
1074
- tagName = this.options.transformTagName(tagName);
1075
- }
1076
-
1077
- if(currentNode){
1078
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
1079
- }
1080
-
1081
- //check if last tag of nested tag was unpaired tag
1082
- const lastTagName = jPath.substring(jPath.lastIndexOf(".")+1);
1083
- if(tagName && this.options.unpairedTags.indexOf(tagName) !== -1 ){
1084
- throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
1085
- }
1086
- let propIndex = 0;
1087
- if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){
1088
- propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1);
1089
- this.tagsNodeStack.pop();
1090
- }else {
1091
- propIndex = jPath.lastIndexOf(".");
1092
- }
1093
- jPath = jPath.substring(0, propIndex);
1094
-
1095
- currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope
1096
- textData = "";
1097
- i = closeIndex;
1098
- } else if( xmlData[i+1] === '?') {
1099
-
1100
- let tagData = readTagExp(xmlData,i, false, "?>");
1101
- if(!tagData) throw new Error("Pi Tag is not closed.");
1102
-
1103
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
1104
- if( (this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags);else {
1105
-
1106
- const childNode = new xmlNode(tagData.tagName);
1107
- childNode.add(this.options.textNodeName, "");
1108
-
1109
- if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
1110
- childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
1111
- }
1112
- this.addChild(currentNode, childNode, jPath);
1113
-
1114
- }
1115
-
1116
-
1117
- i = tagData.closeIndex + 1;
1118
- } else if(xmlData.substr(i + 1, 3) === '!--') {
1119
- const endIndex = findClosingIndex(xmlData, "-->", i+4, "Comment is not closed.");
1120
- if(this.options.commentPropName){
1121
- const comment = xmlData.substring(i + 4, endIndex - 2);
1122
-
1123
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
1124
-
1125
- currentNode.add(this.options.commentPropName, [ { [this.options.textNodeName] : comment } ]);
1126
- }
1127
- i = endIndex;
1128
- } else if( xmlData.substr(i + 1, 2) === '!D') {
1129
- const result = readDocType(xmlData, i);
1130
- this.docTypeEntities = result.entities;
1131
- i = result.i;
1132
- }else if(xmlData.substr(i + 1, 2) === '![') {
1133
- const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
1134
- const tagExp = xmlData.substring(i + 9,closeIndex);
1135
-
1136
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
1137
-
1138
- //cdata should be set even if it is 0 length string
1139
- if(this.options.cdataPropName){
1140
- // let val = this.parseTextData(tagExp, this.options.cdataPropName, jPath + "." + this.options.cdataPropName, true, false, true);
1141
- // if(!val) val = "";
1142
- currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
1143
- }else {
1144
- let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
1145
- if(val == undefined) val = "";
1146
- currentNode.add(this.options.textNodeName, val);
1147
- }
1148
-
1149
- i = closeIndex + 2;
1150
- }else {//Opening tag
1151
- let result = readTagExp(xmlData,i, this.options.removeNSPrefix);
1152
- let tagName= result.tagName;
1153
- let tagExp = result.tagExp;
1154
- let attrExpPresent = result.attrExpPresent;
1155
- let closeIndex = result.closeIndex;
1156
-
1157
- if (this.options.transformTagName) {
1158
- tagName = this.options.transformTagName(tagName);
1159
- }
1160
-
1161
- //save text as child node
1162
- if (currentNode && textData) {
1163
- if(currentNode.tagname !== '!xml'){
1164
- //when nested tag is found
1165
- textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
1166
- }
1167
- }
1168
-
1169
- //check if last tag was unpaired tag
1170
- const lastTag = currentNode;
1171
- if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){
1172
- currentNode = this.tagsNodeStack.pop();
1173
- jPath = jPath.substring(0, jPath.lastIndexOf("."));
1174
- }
1175
- if(tagName !== xmlObj.tagname){
1176
- jPath += jPath ? "." + tagName : tagName;
1177
- }
1178
- if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) { //TODO: namespace
1179
- let tagContent = "";
1180
- //self-closing tag
1181
- if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
1182
- i = result.closeIndex;
1183
- }
1184
- //unpaired tag
1185
- else if(this.options.unpairedTags.indexOf(tagName) !== -1){
1186
- i = result.closeIndex;
1187
- }
1188
- //normal tag
1189
- else {
1190
- //read until closing tag is found
1191
- const result = this.readStopNodeData(xmlData, tagName, closeIndex + 1);
1192
- if(!result) throw new Error(`Unexpected end of ${tagName}`);
1193
- i = result.i;
1194
- tagContent = result.tagContent;
1195
- }
1196
-
1197
- const childNode = new xmlNode(tagName);
1198
- if(tagName !== tagExp && attrExpPresent){
1199
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
1200
- }
1201
- if(tagContent) {
1202
- tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
1203
- }
1204
-
1205
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
1206
- childNode.add(this.options.textNodeName, tagContent);
1207
-
1208
- this.addChild(currentNode, childNode, jPath);
1209
- }else {
1210
- //selfClosing tag
1211
- if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
1212
- if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
1213
- tagName = tagName.substr(0, tagName.length - 1);
1214
- tagExp = tagName;
1215
- }else {
1216
- tagExp = tagExp.substr(0, tagExp.length - 1);
1217
- }
1218
-
1219
- if(this.options.transformTagName) {
1220
- tagName = this.options.transformTagName(tagName);
1221
- }
1222
-
1223
- const childNode = new xmlNode(tagName);
1224
- if(tagName !== tagExp && attrExpPresent){
1225
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
1226
- }
1227
- this.addChild(currentNode, childNode, jPath);
1228
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
1229
- }
1230
- //opening tag
1231
- else {
1232
- const childNode = new xmlNode( tagName);
1233
- this.tagsNodeStack.push(currentNode);
1234
-
1235
- if(tagName !== tagExp && attrExpPresent){
1236
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
1237
- }
1238
- this.addChild(currentNode, childNode, jPath);
1239
- currentNode = childNode;
1240
- }
1241
- textData = "";
1242
- i = closeIndex;
1243
- }
1244
- }
1245
- }else {
1246
- textData += xmlData[i];
1247
- }
1248
- }
1249
- return xmlObj.child;
1250
- };
1251
-
1252
- function addChild(currentNode, childNode, jPath){
1253
- const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
1254
- if(result === false);else if(typeof result === "string"){
1255
- childNode.tagname = result;
1256
- currentNode.addChild(childNode);
1257
- }else {
1258
- currentNode.addChild(childNode);
1259
- }
1260
- }
1261
-
1262
- const replaceEntitiesValue$1 = function(val){
1263
-
1264
- if(this.options.processEntities){
1265
- for(let entityName in this.docTypeEntities){
1266
- const entity = this.docTypeEntities[entityName];
1267
- val = val.replace( entity.regx, entity.val);
1268
- }
1269
- for(let entityName in this.lastEntities){
1270
- const entity = this.lastEntities[entityName];
1271
- val = val.replace( entity.regex, entity.val);
1272
- }
1273
- if(this.options.htmlEntities){
1274
- for(let entityName in this.htmlEntities){
1275
- const entity = this.htmlEntities[entityName];
1276
- val = val.replace( entity.regex, entity.val);
1277
- }
1278
- }
1279
- val = val.replace( this.ampEntity.regex, this.ampEntity.val);
1280
- }
1281
- return val;
1282
- };
1283
- function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
1284
- if (textData) { //store previously collected data as textNode
1285
- if(isLeafNode === undefined) isLeafNode = Object.keys(currentNode.child).length === 0;
1286
-
1287
- textData = this.parseTextData(textData,
1288
- currentNode.tagname,
1289
- jPath,
1290
- false,
1291
- currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
1292
- isLeafNode);
1293
-
1294
- if (textData !== undefined && textData !== "")
1295
- currentNode.add(this.options.textNodeName, textData);
1296
- textData = "";
1297
- }
1298
- return textData;
1299
- }
1300
-
1301
- //TODO: use jPath to simplify the logic
1302
- /**
1303
- *
1304
- * @param {string[]} stopNodes
1305
- * @param {string} jPath
1306
- * @param {string} currentTagName
1307
- */
1308
- function isItStopNode(stopNodes, jPath, currentTagName){
1309
- const allNodesExp = "*." + currentTagName;
1310
- for (const stopNodePath in stopNodes) {
1311
- const stopNodeExp = stopNodes[stopNodePath];
1312
- if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
1313
- }
1314
- return false;
1315
- }
1316
-
1317
- /**
1318
- * Returns the tag Expression and where it is ending handling single-double quotes situation
1319
- * @param {string} xmlData
1320
- * @param {number} i starting index
1321
- * @returns
1322
- */
1323
- function tagExpWithClosingIndex(xmlData, i, closingChar = ">"){
1324
- let attrBoundary;
1325
- let tagExp = "";
1326
- for (let index = i; index < xmlData.length; index++) {
1327
- let ch = xmlData[index];
1328
- if (attrBoundary) {
1329
- if (ch === attrBoundary) attrBoundary = "";//reset
1330
- } else if (ch === '"' || ch === "'") {
1331
- attrBoundary = ch;
1332
- } else if (ch === closingChar[0]) {
1333
- if(closingChar[1]){
1334
- if(xmlData[index + 1] === closingChar[1]){
1335
- return {
1336
- data: tagExp,
1337
- index: index
1338
- }
1339
- }
1340
- }else {
1341
- return {
1342
- data: tagExp,
1343
- index: index
1344
- }
1345
- }
1346
- } else if (ch === '\t') {
1347
- ch = " ";
1348
- }
1349
- tagExp += ch;
1350
- }
1351
- }
1352
-
1353
- function findClosingIndex(xmlData, str, i, errMsg){
1354
- const closingIndex = xmlData.indexOf(str, i);
1355
- if(closingIndex === -1){
1356
- throw new Error(errMsg)
1357
- }else {
1358
- return closingIndex + str.length - 1;
1359
- }
1360
- }
1361
-
1362
- function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
1363
- const result = tagExpWithClosingIndex(xmlData, i+1, closingChar);
1364
- if(!result) return;
1365
- let tagExp = result.data;
1366
- const closeIndex = result.index;
1367
- const separatorIndex = tagExp.search(/\s/);
1368
- let tagName = tagExp;
1369
- let attrExpPresent = true;
1370
- if(separatorIndex !== -1){//separate tag name and attributes expression
1371
- tagName = tagExp.substr(0, separatorIndex).replace(/\s\s*$/, '');
1372
- tagExp = tagExp.substr(separatorIndex + 1);
1373
- }
1374
-
1375
- if(removeNSPrefix){
1376
- const colonIndex = tagName.indexOf(":");
1377
- if(colonIndex !== -1){
1378
- tagName = tagName.substr(colonIndex+1);
1379
- attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
1380
- }
1381
- }
1382
-
1383
- return {
1384
- tagName: tagName,
1385
- tagExp: tagExp,
1386
- closeIndex: closeIndex,
1387
- attrExpPresent: attrExpPresent,
1388
- }
1389
- }
1390
- /**
1391
- * find paired tag for a stop node
1392
- * @param {string} xmlData
1393
- * @param {string} tagName
1394
- * @param {number} i
1395
- */
1396
- function readStopNodeData(xmlData, tagName, i){
1397
- const startIndex = i;
1398
- // Starting at 1 since we already have an open tag
1399
- let openTagCount = 1;
1400
-
1401
- for (; i < xmlData.length; i++) {
1402
- if( xmlData[i] === "<"){
1403
- if (xmlData[i+1] === "/") {//close tag
1404
- const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
1405
- let closeTagName = xmlData.substring(i+2,closeIndex).trim();
1406
- if(closeTagName === tagName){
1407
- openTagCount--;
1408
- if (openTagCount === 0) {
1409
- return {
1410
- tagContent: xmlData.substring(startIndex, i),
1411
- i : closeIndex
1412
- }
1413
- }
1414
- }
1415
- i=closeIndex;
1416
- } else if(xmlData[i+1] === '?') {
1417
- const closeIndex = findClosingIndex(xmlData, "?>", i+1, "StopNode is not closed.");
1418
- i=closeIndex;
1419
- } else if(xmlData.substr(i + 1, 3) === '!--') {
1420
- const closeIndex = findClosingIndex(xmlData, "-->", i+3, "StopNode is not closed.");
1421
- i=closeIndex;
1422
- } else if(xmlData.substr(i + 1, 2) === '![') {
1423
- const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
1424
- i=closeIndex;
1425
- } else {
1426
- const tagData = readTagExp(xmlData, i, '>');
1427
-
1428
- if (tagData) {
1429
- const openTagName = tagData && tagData.tagName;
1430
- if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
1431
- openTagCount++;
1432
- }
1433
- i=tagData.closeIndex;
1434
- }
1435
- }
1436
- }
1437
- }//end for loop
1438
- }
1439
-
1440
- function parseValue(val, shouldParse, options) {
1441
- if (shouldParse && typeof val === 'string') {
1442
- //console.log(options)
1443
- const newval = val.trim();
1444
- if(newval === 'true' ) return true;
1445
- else if(newval === 'false' ) return false;
1446
- else return toNumber(val, options);
1447
- } else {
1448
- if (util.isExist(val)) {
1449
- return val;
1450
- } else {
1451
- return '';
1452
- }
1453
- }
1454
- }
1455
-
1456
-
1457
- var OrderedObjParser_1 = OrderedObjParser$1;
1458
-
1459
- var node2json = {};
1460
-
1461
- /**
1462
- *
1463
- * @param {array} node
1464
- * @param {any} options
1465
- * @returns
1466
- */
1467
- function prettify$1(node, options){
1468
- return compress( node, options);
1469
- }
1470
-
1471
- /**
1472
- *
1473
- * @param {array} arr
1474
- * @param {object} options
1475
- * @param {string} jPath
1476
- * @returns object
1477
- */
1478
- function compress(arr, options, jPath){
1479
- let text;
1480
- const compressedObj = {};
1481
- for (let i = 0; i < arr.length; i++) {
1482
- const tagObj = arr[i];
1483
- const property = propName$1(tagObj);
1484
- let newJpath = "";
1485
- if(jPath === undefined) newJpath = property;
1486
- else newJpath = jPath + "." + property;
1487
-
1488
- if(property === options.textNodeName){
1489
- if(text === undefined) text = tagObj[property];
1490
- else text += "" + tagObj[property];
1491
- }else if(property === undefined){
1492
- continue;
1493
- }else if(tagObj[property]){
1494
-
1495
- let val = compress(tagObj[property], options, newJpath);
1496
- const isLeaf = isLeafTag(val, options);
1497
-
1498
- if(tagObj[":@"]){
1499
- assignAttributes( val, tagObj[":@"], newJpath, options);
1500
- }else if(Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode){
1501
- val = val[options.textNodeName];
1502
- }else if(Object.keys(val).length === 0){
1503
- if(options.alwaysCreateTextNode) val[options.textNodeName] = "";
1504
- else val = "";
1505
- }
1506
-
1507
- if(compressedObj[property] !== undefined && compressedObj.hasOwnProperty(property)) {
1508
- if(!Array.isArray(compressedObj[property])) {
1509
- compressedObj[property] = [ compressedObj[property] ];
1510
- }
1511
- compressedObj[property].push(val);
1512
- }else {
1513
- //TODO: if a node is not an array, then check if it should be an array
1514
- //also determine if it is a leaf node
1515
- if (options.isArray(property, newJpath, isLeaf )) {
1516
- compressedObj[property] = [val];
1517
- }else {
1518
- compressedObj[property] = val;
1519
- }
1520
- }
1521
- }
1522
-
1523
- }
1524
- // if(text && text.length > 0) compressedObj[options.textNodeName] = text;
1525
- if(typeof text === "string"){
1526
- if(text.length > 0) compressedObj[options.textNodeName] = text;
1527
- }else if(text !== undefined) compressedObj[options.textNodeName] = text;
1528
- return compressedObj;
1529
- }
1530
-
1531
- function propName$1(obj){
1532
- const keys = Object.keys(obj);
1533
- for (let i = 0; i < keys.length; i++) {
1534
- const key = keys[i];
1535
- if(key !== ":@") return key;
1536
- }
1537
- }
1538
-
1539
- function assignAttributes(obj, attrMap, jpath, options){
1540
- if (attrMap) {
1541
- const keys = Object.keys(attrMap);
1542
- const len = keys.length; //don't make it inline
1543
- for (let i = 0; i < len; i++) {
1544
- const atrrName = keys[i];
1545
- if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
1546
- obj[atrrName] = [ attrMap[atrrName] ];
1547
- } else {
1548
- obj[atrrName] = attrMap[atrrName];
1549
- }
1550
- }
1551
- }
1552
- }
1553
-
1554
- function isLeafTag(obj, options){
1555
- const { textNodeName } = options;
1556
- const propCount = Object.keys(obj).length;
1557
-
1558
- if (propCount === 0) {
1559
- return true;
1560
- }
1561
-
1562
- if (
1563
- propCount === 1 &&
1564
- (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)
1565
- ) {
1566
- return true;
1567
- }
1568
-
1569
- return false;
1570
- }
1571
- node2json.prettify = prettify$1;
1572
-
1573
- const { buildOptions} = OptionsBuilder;
1574
- const OrderedObjParser = OrderedObjParser_1;
1575
- const { prettify} = node2json;
1576
- const validator$1 = validator$2;
1577
-
1578
- let XMLParser$1 = class XMLParser{
1579
-
1580
- constructor(options){
1581
- this.externalEntities = {};
1582
- this.options = buildOptions(options);
1583
-
1584
- }
1585
- /**
1586
- * Parse XML dats to JS object
1587
- * @param {string|Buffer} xmlData
1588
- * @param {boolean|Object} validationOption
1589
- */
1590
- parse(xmlData,validationOption){
1591
- if(typeof xmlData === "string");else if( xmlData.toString){
1592
- xmlData = xmlData.toString();
1593
- }else {
1594
- throw new Error("XML data is accepted in String or Bytes[] form.")
1595
- }
1596
- if( validationOption){
1597
- if(validationOption === true) validationOption = {}; //validate with default options
1598
-
1599
- const result = validator$1.validate(xmlData, validationOption);
1600
- if (result !== true) {
1601
- throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )
1602
- }
1603
- }
1604
- const orderedObjParser = new OrderedObjParser(this.options);
1605
- orderedObjParser.addExternalEntities(this.externalEntities);
1606
- const orderedResult = orderedObjParser.parseXml(xmlData);
1607
- if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;
1608
- else return prettify(orderedResult, this.options);
1609
- }
1610
-
1611
- /**
1612
- * Add Entity which is not by default supported by this library
1613
- * @param {string} key
1614
- * @param {string} value
1615
- */
1616
- addEntity(key, value){
1617
- if(value.indexOf("&") !== -1){
1618
- throw new Error("Entity value can't have '&'")
1619
- }else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
1620
- throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'")
1621
- }else if(value === "&"){
1622
- throw new Error("An entity with value '&' is not permitted");
1623
- }else {
1624
- this.externalEntities[key] = value;
1625
- }
1626
- }
1627
- };
1628
-
1629
- var XMLParser_1 = XMLParser$1;
1630
-
1631
- const EOL = "\n";
1632
-
1633
- /**
1634
- *
1635
- * @param {array} jArray
1636
- * @param {any} options
1637
- * @returns
1638
- */
1639
- function toXml(jArray, options) {
1640
- let indentation = "";
1641
- if (options.format && options.indentBy.length > 0) {
1642
- indentation = EOL;
1643
- }
1644
- return arrToStr(jArray, options, "", indentation);
1645
- }
1646
-
1647
- function arrToStr(arr, options, jPath, indentation) {
1648
- let xmlStr = "";
1649
- let isPreviousElementTag = false;
1650
-
1651
- for (let i = 0; i < arr.length; i++) {
1652
- const tagObj = arr[i];
1653
- const tagName = propName(tagObj);
1654
- let newJPath = "";
1655
- if (jPath.length === 0) newJPath = tagName;
1656
- else newJPath = `${jPath}.${tagName}`;
1657
-
1658
- if (tagName === options.textNodeName) {
1659
- let tagText = tagObj[tagName];
1660
- if (!isStopNode(newJPath, options)) {
1661
- tagText = options.tagValueProcessor(tagName, tagText);
1662
- tagText = replaceEntitiesValue(tagText, options);
1663
- }
1664
- if (isPreviousElementTag) {
1665
- xmlStr += indentation;
1666
- }
1667
- xmlStr += tagText;
1668
- isPreviousElementTag = false;
1669
- continue;
1670
- } else if (tagName === options.cdataPropName) {
1671
- if (isPreviousElementTag) {
1672
- xmlStr += indentation;
1673
- }
1674
- xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
1675
- isPreviousElementTag = false;
1676
- continue;
1677
- } else if (tagName === options.commentPropName) {
1678
- xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
1679
- isPreviousElementTag = true;
1680
- continue;
1681
- } else if (tagName[0] === "?") {
1682
- const attStr = attr_to_str(tagObj[":@"], options);
1683
- const tempInd = tagName === "?xml" ? "" : indentation;
1684
- let piTextNodeName = tagObj[tagName][0][options.textNodeName];
1685
- piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
1686
- xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
1687
- isPreviousElementTag = true;
1688
- continue;
1689
- }
1690
- let newIdentation = indentation;
1691
- if (newIdentation !== "") {
1692
- newIdentation += options.indentBy;
1693
- }
1694
- const attStr = attr_to_str(tagObj[":@"], options);
1695
- const tagStart = indentation + `<${tagName}${attStr}`;
1696
- const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
1697
- if (options.unpairedTags.indexOf(tagName) !== -1) {
1698
- if (options.suppressUnpairedNode) xmlStr += tagStart + ">";
1699
- else xmlStr += tagStart + "/>";
1700
- } else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
1701
- xmlStr += tagStart + "/>";
1702
- } else if (tagValue && tagValue.endsWith(">")) {
1703
- xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
1704
- } else {
1705
- xmlStr += tagStart + ">";
1706
- if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
1707
- xmlStr += indentation + options.indentBy + tagValue + indentation;
1708
- } else {
1709
- xmlStr += tagValue;
1710
- }
1711
- xmlStr += `</${tagName}>`;
1712
- }
1713
- isPreviousElementTag = true;
1714
- }
1715
-
1716
- return xmlStr;
1717
- }
1718
-
1719
- function propName(obj) {
1720
- const keys = Object.keys(obj);
1721
- for (let i = 0; i < keys.length; i++) {
1722
- const key = keys[i];
1723
- if (key !== ":@") return key;
1724
- }
1725
- }
1726
-
1727
- function attr_to_str(attrMap, options) {
1728
- let attrStr = "";
1729
- if (attrMap && !options.ignoreAttributes) {
1730
- for (let attr in attrMap) {
1731
- let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
1732
- attrVal = replaceEntitiesValue(attrVal, options);
1733
- if (attrVal === true && options.suppressBooleanAttributes) {
1734
- attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
1735
- } else {
1736
- attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
1737
- }
1738
- }
1739
- }
1740
- return attrStr;
1741
- }
1742
-
1743
- function isStopNode(jPath, options) {
1744
- jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
1745
- let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
1746
- for (let index in options.stopNodes) {
1747
- if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName) return true;
1748
- }
1749
- return false;
1750
- }
1751
-
1752
- function replaceEntitiesValue(textValue, options) {
1753
- if (textValue && textValue.length > 0 && options.processEntities) {
1754
- for (let i = 0; i < options.entities.length; i++) {
1755
- const entity = options.entities[i];
1756
- textValue = textValue.replace(entity.regex, entity.val);
1757
- }
1758
- }
1759
- return textValue;
1760
- }
1761
- var orderedJs2Xml = toXml;
1762
-
1763
- //parse Empty Node as self closing node
1764
- const buildFromOrderedJs = orderedJs2Xml;
1765
-
1766
- const defaultOptions = {
1767
- attributeNamePrefix: '@_',
1768
- attributesGroupName: false,
1769
- textNodeName: '#text',
1770
- ignoreAttributes: true,
1771
- cdataPropName: false,
1772
- format: false,
1773
- indentBy: ' ',
1774
- suppressEmptyNode: false,
1775
- suppressUnpairedNode: true,
1776
- suppressBooleanAttributes: true,
1777
- tagValueProcessor: function(key, a) {
1778
- return a;
1779
- },
1780
- attributeValueProcessor: function(attrName, a) {
1781
- return a;
1782
- },
1783
- preserveOrder: false,
1784
- commentPropName: false,
1785
- unpairedTags: [],
1786
- entities: [
1787
- { regex: new RegExp("&", "g"), val: "&amp;" },//it must be on top
1788
- { regex: new RegExp(">", "g"), val: "&gt;" },
1789
- { regex: new RegExp("<", "g"), val: "&lt;" },
1790
- { regex: new RegExp("\'", "g"), val: "&apos;" },
1791
- { regex: new RegExp("\"", "g"), val: "&quot;" }
1792
- ],
1793
- processEntities: true,
1794
- stopNodes: [],
1795
- // transformTagName: false,
1796
- // transformAttributeName: false,
1797
- oneListGroup: false
1798
- };
1799
-
1800
- function Builder(options) {
1801
- this.options = Object.assign({}, defaultOptions, options);
1802
- if (this.options.ignoreAttributes || this.options.attributesGroupName) {
1803
- this.isAttribute = function(/*a*/) {
1804
- return false;
1805
- };
1806
- } else {
1807
- this.attrPrefixLen = this.options.attributeNamePrefix.length;
1808
- this.isAttribute = isAttribute;
1809
- }
1810
-
1811
- this.processTextOrObjNode = processTextOrObjNode;
1812
-
1813
- if (this.options.format) {
1814
- this.indentate = indentate;
1815
- this.tagEndChar = '>\n';
1816
- this.newLine = '\n';
1817
- } else {
1818
- this.indentate = function() {
1819
- return '';
1820
- };
1821
- this.tagEndChar = '>';
1822
- this.newLine = '';
1823
- }
1824
- }
1825
-
1826
- Builder.prototype.build = function(jObj) {
1827
- if(this.options.preserveOrder){
1828
- return buildFromOrderedJs(jObj, this.options);
1829
- }else {
1830
- if(Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1){
1831
- jObj = {
1832
- [this.options.arrayNodeName] : jObj
1833
- };
1834
- }
1835
- return this.j2x(jObj, 0).val;
1836
- }
1837
- };
1838
-
1839
- Builder.prototype.j2x = function(jObj, level) {
1840
- let attrStr = '';
1841
- let val = '';
1842
- for (let key in jObj) {
1843
- if (typeof jObj[key] === 'undefined') ; else if (jObj[key] === null) {
1844
- if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
1845
- else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
1846
- // val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
1847
- } else if (jObj[key] instanceof Date) {
1848
- val += this.buildTextValNode(jObj[key], key, '', level);
1849
- } else if (typeof jObj[key] !== 'object') {
1850
- //premitive type
1851
- const attr = this.isAttribute(key);
1852
- if (attr) {
1853
- attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
1854
- }else {
1855
- //tag value
1856
- if (key === this.options.textNodeName) {
1857
- let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
1858
- val += this.replaceEntitiesValue(newval);
1859
- } else {
1860
- val += this.buildTextValNode(jObj[key], key, '', level);
1861
- }
1862
- }
1863
- } else if (Array.isArray(jObj[key])) {
1864
- //repeated nodes
1865
- const arrLen = jObj[key].length;
1866
- let listTagVal = "";
1867
- for (let j = 0; j < arrLen; j++) {
1868
- const item = jObj[key][j];
1869
- if (typeof item === 'undefined') ; else if (item === null) {
1870
- if(key[0] === "?") val += this.indentate(level) + '<' + key + '?' + this.tagEndChar;
1871
- else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
1872
- // val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
1873
- } else if (typeof item === 'object') {
1874
- if(this.options.oneListGroup ){
1875
- listTagVal += this.j2x(item, level + 1).val;
1876
- }else {
1877
- listTagVal += this.processTextOrObjNode(item, key, level);
1878
- }
1879
- } else {
1880
- listTagVal += this.buildTextValNode(item, key, '', level);
1881
- }
1882
- }
1883
- if(this.options.oneListGroup){
1884
- listTagVal = this.buildObjectNode(listTagVal, key, '', level);
1885
- }
1886
- val += listTagVal;
1887
- } else {
1888
- //nested node
1889
- if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
1890
- const Ks = Object.keys(jObj[key]);
1891
- const L = Ks.length;
1892
- for (let j = 0; j < L; j++) {
1893
- attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
1894
- }
1895
- } else {
1896
- val += this.processTextOrObjNode(jObj[key], key, level);
1897
- }
1898
- }
1899
- }
1900
- return {attrStr: attrStr, val: val};
1901
- };
1902
-
1903
- Builder.prototype.buildAttrPairStr = function(attrName, val){
1904
- val = this.options.attributeValueProcessor(attrName, '' + val);
1905
- val = this.replaceEntitiesValue(val);
1906
- if (this.options.suppressBooleanAttributes && val === "true") {
1907
- return ' ' + attrName;
1908
- } else return ' ' + attrName + '="' + val + '"';
1909
- };
1910
-
1911
- function processTextOrObjNode (object, key, level) {
1912
- const result = this.j2x(object, level + 1);
1913
- if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
1914
- return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
1915
- } else {
1916
- return this.buildObjectNode(result.val, key, result.attrStr, level);
1917
- }
1918
- }
1919
-
1920
- Builder.prototype.buildObjectNode = function(val, key, attrStr, level) {
1921
- if(val === ""){
1922
- if(key[0] === "?") return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
1923
- else {
1924
- return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
1925
- }
1926
- }else {
1927
-
1928
- let tagEndExp = '</' + key + this.tagEndChar;
1929
- let piClosingChar = "";
1930
-
1931
- if(key[0] === "?") {
1932
- piClosingChar = "?";
1933
- tagEndExp = "";
1934
- }
1935
-
1936
- if (attrStr && val.indexOf('<') === -1) {
1937
- return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );
1938
- } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
1939
- return this.indentate(level) + `<!--${val}-->` + this.newLine;
1940
- }else {
1941
- return (
1942
- this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
1943
- val +
1944
- this.indentate(level) + tagEndExp );
1945
- }
1946
- }
1947
- };
1948
-
1949
- Builder.prototype.closeTag = function(key){
1950
- let closeTag = "";
1951
- if(this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
1952
- if(!this.options.suppressUnpairedNode) closeTag = "/";
1953
- }else if(this.options.suppressEmptyNode){ //empty
1954
- closeTag = "/";
1955
- }else {
1956
- closeTag = `></${key}`;
1957
- }
1958
- return closeTag;
1959
- };
1960
-
1961
- Builder.prototype.buildTextValNode = function(val, key, attrStr, level) {
1962
- if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
1963
- return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
1964
- }else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
1965
- return this.indentate(level) + `<!--${val}-->` + this.newLine;
1966
- }else if(key[0] === "?") {//PI tag
1967
- return this.indentate(level) + '<' + key + attrStr+ '?' + this.tagEndChar;
1968
- }else {
1969
- let textValue = this.options.tagValueProcessor(key, val);
1970
- textValue = this.replaceEntitiesValue(textValue);
1971
-
1972
- if( textValue === ''){
1973
- return this.indentate(level) + '<' + key + attrStr + this.closeTag(key) + this.tagEndChar;
1974
- }else {
1975
- return this.indentate(level) + '<' + key + attrStr + '>' +
1976
- textValue +
1977
- '</' + key + this.tagEndChar;
1978
- }
1979
- }
1980
- };
1981
-
1982
- Builder.prototype.replaceEntitiesValue = function(textValue){
1983
- if(textValue && textValue.length > 0 && this.options.processEntities){
1984
- for (let i=0; i<this.options.entities.length; i++) {
1985
- const entity = this.options.entities[i];
1986
- textValue = textValue.replace(entity.regex, entity.val);
1987
- }
1988
- }
1989
- return textValue;
1990
- };
1991
-
1992
- function indentate(level) {
1993
- return this.options.indentBy.repeat(level);
1994
- }
1995
-
1996
- function isAttribute(name /*, options*/) {
1997
- if (name.startsWith(this.options.attributeNamePrefix)) {
1998
- return name.substr(this.attrPrefixLen);
1999
- } else {
2000
- return false;
2001
- }
2002
- }
2003
-
2004
- var json2xml = Builder;
2005
-
2006
- const validator = validator$2;
2007
- const XMLParser = XMLParser_1;
2008
- const XMLBuilder = json2xml;
2009
-
2010
- var fxp = {
2011
- XMLParser: XMLParser,
2012
- XMLValidator: validator,
2013
- XMLBuilder: XMLBuilder
2014
- };
2015
-
2016
- const parseXmlBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
2017
- if (encoded.length) {
2018
- const parser = new fxp.XMLParser({
2019
- attributeNamePrefix: "",
2020
- htmlEntities: true,
2021
- ignoreAttributes: false,
2022
- ignoreDeclaration: true,
2023
- parseTagValue: false,
2024
- trimValues: false,
2025
- tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
2026
- });
2027
- parser.addEntity("#xD", "\r");
2028
- parser.addEntity("#10", "\n");
2029
- let parsedObj;
2030
- try {
2031
- parsedObj = parser.parse(encoded, true);
2032
- }
2033
- catch (e) {
2034
- if (e && typeof e === "object") {
2035
- Object.defineProperty(e, "$responseBodyText", {
2036
- value: encoded,
2037
- });
2038
- }
2039
- throw e;
2040
- }
2041
- const textNodeName = "#text";
2042
- const key = Object.keys(parsedObj)[0];
2043
- const parsedObjToReturn = parsedObj[key];
2044
- if (parsedObjToReturn[textNodeName]) {
2045
- parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
2046
- delete parsedObjToReturn[textNodeName];
2047
- }
2048
- return getValueFromTextNode(parsedObjToReturn);
2049
- }
2050
- return {};
2051
- });
2052
- const parseXmlErrorBody = async (errorBody, context) => {
2053
- const value = await parseXmlBody(errorBody, context);
2054
- if (value.Error) {
2055
- value.Error.message = value.Error.message ?? value.Error.Message;
2056
- }
2057
- return value;
2058
- };
2059
-
2060
- const defaultSTSHttpAuthSchemeParametersProvider = async (config, context, input) => {
2061
- return {
2062
- operation: getSmithyContext(context).operation,
2063
- region: (await normalizeProvider(config.region)()) ||
2064
- (() => {
2065
- throw new Error("expected `region` to be configured for `aws.auth#sigv4`");
2066
- })(),
2067
- };
2068
- };
2069
- function createAwsAuthSigv4HttpAuthOption(authParameters) {
2070
- return {
2071
- schemeId: "aws.auth#sigv4",
2072
- signingProperties: {
2073
- name: "sts",
2074
- region: authParameters.region,
2075
- },
2076
- propertiesExtractor: (config, context) => ({
2077
- signingProperties: {
2078
- config,
2079
- context,
2080
- },
2081
- }),
2082
- };
2083
- }
2084
- function createSmithyApiNoAuthHttpAuthOption(authParameters) {
2085
- return {
2086
- schemeId: "smithy.api#noAuth",
2087
- };
2088
- }
2089
- const defaultSTSHttpAuthSchemeProvider = (authParameters) => {
2090
- const options = [];
2091
- switch (authParameters.operation) {
2092
- case "AssumeRoleWithSAML": {
2093
- options.push(createSmithyApiNoAuthHttpAuthOption());
2094
- break;
2095
- }
2096
- case "AssumeRoleWithWebIdentity": {
2097
- options.push(createSmithyApiNoAuthHttpAuthOption());
2098
- break;
2099
- }
2100
- default: {
2101
- options.push(createAwsAuthSigv4HttpAuthOption(authParameters));
2102
- }
2103
- }
2104
- return options;
2105
- };
2106
- const resolveStsAuthConfig = (input) => ({
2107
- ...input,
2108
- stsClientCtor: STSClient,
2109
- });
2110
- const resolveHttpAuthSchemeConfig = (config) => {
2111
- const config_0 = resolveStsAuthConfig(config);
2112
- const config_1 = resolveAwsSdkSigV4Config(config_0);
2113
- return {
2114
- ...config_1,
2115
- };
2116
- };
2117
-
2118
- const resolveClientEndpointParameters = (options) => {
2119
- return {
2120
- ...options,
2121
- useDualstackEndpoint: options.useDualstackEndpoint ?? false,
2122
- useFipsEndpoint: options.useFipsEndpoint ?? false,
2123
- useGlobalEndpoint: options.useGlobalEndpoint ?? false,
2124
- defaultSigningName: "sts",
2125
- };
2126
- };
2127
- const commonParams = {
2128
- UseGlobalEndpoint: { type: "builtInParams", name: "useGlobalEndpoint" },
2129
- UseFIPS: { type: "builtInParams", name: "useFipsEndpoint" },
2130
- Endpoint: { type: "builtInParams", name: "endpoint" },
2131
- Region: { type: "builtInParams", name: "region" },
2132
- UseDualStack: { type: "builtInParams", name: "useDualstackEndpoint" },
2133
- };
2134
-
2135
- var name = "@aws-sdk/client-sts";
2136
- var description = "AWS SDK for JavaScript Sts Client for Node.js, Browser and React Native";
2137
- var version = "3.556.0";
2138
- var scripts = {
2139
- build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
2140
- "build:cjs": "node ../../scripts/compilation/inline client-sts",
2141
- "build:es": "tsc -p tsconfig.es.json",
2142
- "build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
2143
- "build:types": "rimraf ./dist-types tsconfig.types.tsbuildinfo && tsc -p tsconfig.types.json",
2144
- "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
2145
- clean: "rimraf ./dist-* && rimraf *.tsbuildinfo",
2146
- "extract:docs": "api-extractor run --local",
2147
- "generate:client": "node ../../scripts/generate-clients/single-service --solo sts",
2148
- test: "yarn test:unit",
2149
- "test:unit": "jest"
2150
- };
2151
- var main = "./dist-cjs/index.js";
2152
- var types = "./dist-types/index.d.ts";
2153
- var module = "./dist-es/index.js";
2154
- var sideEffects = false;
2155
- var dependencies = {
2156
- "@aws-crypto/sha256-browser": "3.0.0",
2157
- "@aws-crypto/sha256-js": "3.0.0",
2158
- "@aws-sdk/core": "3.556.0",
2159
- "@aws-sdk/middleware-host-header": "3.535.0",
2160
- "@aws-sdk/middleware-logger": "3.535.0",
2161
- "@aws-sdk/middleware-recursion-detection": "3.535.0",
2162
- "@aws-sdk/middleware-user-agent": "3.540.0",
2163
- "@aws-sdk/region-config-resolver": "3.535.0",
2164
- "@aws-sdk/types": "3.535.0",
2165
- "@aws-sdk/util-endpoints": "3.540.0",
2166
- "@aws-sdk/util-user-agent-browser": "3.535.0",
2167
- "@aws-sdk/util-user-agent-node": "3.535.0",
2168
- "@smithy/config-resolver": "^2.2.0",
2169
- "@smithy/core": "^1.4.2",
2170
- "@smithy/fetch-http-handler": "^2.5.0",
2171
- "@smithy/hash-node": "^2.2.0",
2172
- "@smithy/invalid-dependency": "^2.2.0",
2173
- "@smithy/middleware-content-length": "^2.2.0",
2174
- "@smithy/middleware-endpoint": "^2.5.1",
2175
- "@smithy/middleware-retry": "^2.3.1",
2176
- "@smithy/middleware-serde": "^2.3.0",
2177
- "@smithy/middleware-stack": "^2.2.0",
2178
- "@smithy/node-config-provider": "^2.3.0",
2179
- "@smithy/node-http-handler": "^2.5.0",
2180
- "@smithy/protocol-http": "^3.3.0",
2181
- "@smithy/smithy-client": "^2.5.1",
2182
- "@smithy/types": "^2.12.0",
2183
- "@smithy/url-parser": "^2.2.0",
2184
- "@smithy/util-base64": "^2.3.0",
2185
- "@smithy/util-body-length-browser": "^2.2.0",
2186
- "@smithy/util-body-length-node": "^2.3.0",
2187
- "@smithy/util-defaults-mode-browser": "^2.2.1",
2188
- "@smithy/util-defaults-mode-node": "^2.3.1",
2189
- "@smithy/util-endpoints": "^1.2.0",
2190
- "@smithy/util-middleware": "^2.2.0",
2191
- "@smithy/util-retry": "^2.2.0",
2192
- "@smithy/util-utf8": "^2.3.0",
2193
- tslib: "^2.6.2"
2194
- };
2195
- var devDependencies = {
2196
- "@smithy/service-client-documentation-generator": "^2.2.0",
2197
- "@tsconfig/node14": "1.0.3",
2198
- "@types/node": "^14.14.31",
2199
- concurrently: "7.0.0",
2200
- "downlevel-dts": "0.10.1",
2201
- rimraf: "3.0.2",
2202
- typescript: "~4.9.5"
2203
- };
2204
- var engines = {
2205
- node: ">=14.0.0"
2206
- };
2207
- var typesVersions = {
2208
- "<4.0": {
2209
- "dist-types/*": [
2210
- "dist-types/ts3.4/*"
2211
- ]
2212
- }
2213
- };
2214
- var files = [
2215
- "dist-*/**"
2216
- ];
2217
- var author = {
2218
- name: "AWS SDK for JavaScript Team",
2219
- url: "https://aws.amazon.com/javascript/"
2220
- };
2221
- var license = "Apache-2.0";
2222
- var peerDependencies = {
2223
- "@aws-sdk/credential-provider-node": "^3.556.0"
2224
- };
2225
- var browser = {
2226
- "./dist-es/runtimeConfig": "./dist-es/runtimeConfig.browser"
2227
- };
2228
- var homepage = "https://github.com/aws/aws-sdk-js-v3/tree/main/clients/client-sts";
2229
- var repository = {
2230
- type: "git",
2231
- url: "https://github.com/aws/aws-sdk-js-v3.git",
2232
- directory: "clients/client-sts"
2233
- };
2234
- var packageInfo = {
2235
- name: name,
2236
- description: description,
2237
- version: version,
2238
- scripts: scripts,
2239
- main: main,
2240
- types: types,
2241
- module: module,
2242
- sideEffects: sideEffects,
2243
- dependencies: dependencies,
2244
- devDependencies: devDependencies,
2245
- engines: engines,
2246
- typesVersions: typesVersions,
2247
- files: files,
2248
- author: author,
2249
- license: license,
2250
- peerDependencies: peerDependencies,
2251
- browser: browser,
2252
- "react-native": {
2253
- "./dist-es/runtimeConfig": "./dist-es/runtimeConfig.native"
2254
- },
2255
- homepage: homepage,
2256
- repository: repository
2257
- };
2258
-
2259
- const defaultProvider = ((input) => {
2260
- return () => import('./index-Dh6q8yRM.js').then(({ defaultProvider }) => defaultProvider(input)());
2261
- });
2262
-
2263
- const F = "required", G = "type", H = "fn", I = "argv", J = "ref";
2264
- const a = false, b = true, c = "booleanEquals", d = "stringEquals", e = "sigv4", f = "sts", g = "us-east-1", h = "endpoint", i = "https://sts.{Region}.{PartitionResult#dnsSuffix}", j = "tree", k = "error", l = "getAttr", m = { [F]: false, [G]: "String" }, n = { [F]: true, "default": false, [G]: "Boolean" }, o = { [J]: "Endpoint" }, p = { [H]: "isSet", [I]: [{ [J]: "Region" }] }, q = { [J]: "Region" }, r = { [H]: "aws.partition", [I]: [q], "assign": "PartitionResult" }, s = { [J]: "UseFIPS" }, t = { [J]: "UseDualStack" }, u = { "url": "https://sts.amazonaws.com", "properties": { "authSchemes": [{ "name": e, "signingName": f, "signingRegion": g }] }, "headers": {} }, v = {}, w = { "conditions": [{ [H]: d, [I]: [q, "aws-global"] }], [h]: u, [G]: h }, x = { [H]: c, [I]: [s, true] }, y = { [H]: c, [I]: [t, true] }, z = { [H]: l, [I]: [{ [J]: "PartitionResult" }, "supportsFIPS"] }, A = { [J]: "PartitionResult" }, B = { [H]: c, [I]: [true, { [H]: l, [I]: [A, "supportsDualStack"] }] }, C = [{ [H]: "isSet", [I]: [o] }], D = [x], E = [y];
2265
- const _data = { version: "1.0", parameters: { Region: m, UseDualStack: n, UseFIPS: n, Endpoint: m, UseGlobalEndpoint: n }, rules: [{ conditions: [{ [H]: c, [I]: [{ [J]: "UseGlobalEndpoint" }, b] }, { [H]: "not", [I]: C }, p, r, { [H]: c, [I]: [s, a] }, { [H]: c, [I]: [t, a] }], rules: [{ conditions: [{ [H]: d, [I]: [q, "ap-northeast-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "ap-south-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "ap-southeast-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "ap-southeast-2"] }], endpoint: u, [G]: h }, w, { conditions: [{ [H]: d, [I]: [q, "ca-central-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "eu-central-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "eu-north-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "eu-west-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "eu-west-2"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "eu-west-3"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "sa-east-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, g] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "us-east-2"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "us-west-1"] }], endpoint: u, [G]: h }, { conditions: [{ [H]: d, [I]: [q, "us-west-2"] }], endpoint: u, [G]: h }, { endpoint: { url: i, properties: { authSchemes: [{ name: e, signingName: f, signingRegion: "{Region}" }] }, headers: v }, [G]: h }], [G]: j }, { conditions: C, rules: [{ conditions: D, error: "Invalid Configuration: FIPS and custom endpoint are not supported", [G]: k }, { conditions: E, error: "Invalid Configuration: Dualstack and custom endpoint are not supported", [G]: k }, { endpoint: { url: o, properties: v, headers: v }, [G]: h }], [G]: j }, { conditions: [p], rules: [{ conditions: [r], rules: [{ conditions: [x, y], rules: [{ conditions: [{ [H]: c, [I]: [b, z] }, B], rules: [{ endpoint: { url: "https://sts-fips.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: v, headers: v }, [G]: h }], [G]: j }, { error: "FIPS and DualStack are enabled, but this partition does not support one or both", [G]: k }], [G]: j }, { conditions: D, rules: [{ conditions: [{ [H]: c, [I]: [z, b] }], rules: [{ conditions: [{ [H]: d, [I]: [{ [H]: l, [I]: [A, "name"] }, "aws-us-gov"] }], endpoint: { url: "https://sts.{Region}.amazonaws.com", properties: v, headers: v }, [G]: h }, { endpoint: { url: "https://sts-fips.{Region}.{PartitionResult#dnsSuffix}", properties: v, headers: v }, [G]: h }], [G]: j }, { error: "FIPS is enabled but this partition does not support FIPS", [G]: k }], [G]: j }, { conditions: E, rules: [{ conditions: [B], rules: [{ endpoint: { url: "https://sts.{Region}.{PartitionResult#dualStackDnsSuffix}", properties: v, headers: v }, [G]: h }], [G]: j }, { error: "DualStack is enabled but this partition does not support DualStack", [G]: k }], [G]: j }, w, { endpoint: { url: i, properties: v, headers: v }, [G]: h }], [G]: j }], [G]: j }, { error: "Invalid Configuration: Missing Region", [G]: k }] };
2266
- const ruleSet = _data;
2267
-
2268
- const defaultEndpointResolver = (endpointParams, context = {}) => {
2269
- return resolveEndpoint(ruleSet, {
2270
- endpointParams: endpointParams,
2271
- logger: context.logger,
2272
- });
2273
- };
2274
- customEndpointFunctions.aws = awsEndpointFunctions;
2275
-
2276
- const getRuntimeConfig$1 = (config) => {
2277
- return {
2278
- apiVersion: "2011-06-15",
2279
- base64Decoder: config?.base64Decoder ?? fromBase64,
2280
- base64Encoder: config?.base64Encoder ?? toBase64,
2281
- disableHostPrefix: config?.disableHostPrefix ?? false,
2282
- endpointProvider: config?.endpointProvider ?? defaultEndpointResolver,
2283
- extensions: config?.extensions ?? [],
2284
- httpAuthSchemeProvider: config?.httpAuthSchemeProvider ?? defaultSTSHttpAuthSchemeProvider,
2285
- httpAuthSchemes: config?.httpAuthSchemes ?? [
2286
- {
2287
- schemeId: "aws.auth#sigv4",
2288
- identityProvider: (ipc) => ipc.getIdentityProvider("aws.auth#sigv4"),
2289
- signer: new AwsSdkSigV4Signer(),
2290
- },
2291
- {
2292
- schemeId: "smithy.api#noAuth",
2293
- identityProvider: (ipc) => ipc.getIdentityProvider("smithy.api#noAuth") || (async () => ({})),
2294
- signer: new NoAuthSigner(),
2295
- },
2296
- ],
2297
- logger: config?.logger ?? new NoOpLogger(),
2298
- serviceId: config?.serviceId ?? "STS",
2299
- urlParser: config?.urlParser ?? parseUrl,
2300
- utf8Decoder: config?.utf8Decoder ?? fromUtf8,
2301
- utf8Encoder: config?.utf8Encoder ?? toUtf8,
2302
- };
2303
- };
2304
-
2305
- const getRuntimeConfig = (config) => {
2306
- emitWarningIfUnsupportedVersion(process.version);
2307
- const defaultsMode = resolveDefaultsModeConfig(config);
2308
- const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
2309
- const clientSharedValues = getRuntimeConfig$1(config);
2310
- emitWarningIfUnsupportedVersion$1(process.version);
2311
- return {
2312
- ...clientSharedValues,
2313
- ...config,
2314
- runtime: "node",
2315
- defaultsMode,
2316
- bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
2317
- credentialDefaultProvider: config?.credentialDefaultProvider ?? defaultProvider,
2318
- defaultUserAgentProvider: config?.defaultUserAgentProvider ??
2319
- defaultUserAgent({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
2320
- httpAuthSchemes: config?.httpAuthSchemes ?? [
2321
- {
2322
- schemeId: "aws.auth#sigv4",
2323
- identityProvider: (ipc) => ipc.getIdentityProvider("aws.auth#sigv4") ||
2324
- (async (idProps) => await defaultProvider(idProps?.__config || {})()),
2325
- signer: new AwsSdkSigV4Signer(),
2326
- },
2327
- {
2328
- schemeId: "smithy.api#noAuth",
2329
- identityProvider: (ipc) => ipc.getIdentityProvider("smithy.api#noAuth") || (async () => ({})),
2330
- signer: new NoAuthSigner(),
2331
- },
2332
- ],
2333
- maxAttempts: config?.maxAttempts ?? loadConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
2334
- region: config?.region ?? loadConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
2335
- requestHandler: NodeHttpHandler.create(config?.requestHandler ?? defaultConfigProvider),
2336
- retryMode: config?.retryMode ??
2337
- loadConfig({
2338
- ...NODE_RETRY_MODE_CONFIG_OPTIONS,
2339
- default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
2340
- }),
2341
- sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
2342
- streamCollector: config?.streamCollector ?? streamCollector,
2343
- useDualstackEndpoint: config?.useDualstackEndpoint ?? loadConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
2344
- useFipsEndpoint: config?.useFipsEndpoint ?? loadConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS),
2345
- };
2346
- };
2347
-
2348
- const getHttpAuthExtensionConfiguration = (runtimeConfig) => {
2349
- const _httpAuthSchemes = runtimeConfig.httpAuthSchemes;
2350
- let _httpAuthSchemeProvider = runtimeConfig.httpAuthSchemeProvider;
2351
- let _credentials = runtimeConfig.credentials;
2352
- return {
2353
- setHttpAuthScheme(httpAuthScheme) {
2354
- const index = _httpAuthSchemes.findIndex((scheme) => scheme.schemeId === httpAuthScheme.schemeId);
2355
- if (index === -1) {
2356
- _httpAuthSchemes.push(httpAuthScheme);
2357
- }
2358
- else {
2359
- _httpAuthSchemes.splice(index, 1, httpAuthScheme);
2360
- }
2361
- },
2362
- httpAuthSchemes() {
2363
- return _httpAuthSchemes;
2364
- },
2365
- setHttpAuthSchemeProvider(httpAuthSchemeProvider) {
2366
- _httpAuthSchemeProvider = httpAuthSchemeProvider;
2367
- },
2368
- httpAuthSchemeProvider() {
2369
- return _httpAuthSchemeProvider;
2370
- },
2371
- setCredentials(credentials) {
2372
- _credentials = credentials;
2373
- },
2374
- credentials() {
2375
- return _credentials;
2376
- },
2377
- };
2378
- };
2379
- const resolveHttpAuthRuntimeConfig = (config) => {
2380
- return {
2381
- httpAuthSchemes: config.httpAuthSchemes(),
2382
- httpAuthSchemeProvider: config.httpAuthSchemeProvider(),
2383
- credentials: config.credentials(),
2384
- };
2385
- };
2386
-
2387
- const asPartial = (t) => t;
2388
- const resolveRuntimeExtensions = (runtimeConfig, extensions) => {
2389
- const extensionConfiguration = {
2390
- ...asPartial(getAwsRegionExtensionConfiguration(runtimeConfig)),
2391
- ...asPartial(getDefaultExtensionConfiguration(runtimeConfig)),
2392
- ...asPartial(getHttpHandlerExtensionConfiguration(runtimeConfig)),
2393
- ...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)),
2394
- };
2395
- extensions.forEach((extension) => extension.configure(extensionConfiguration));
2396
- return {
2397
- ...runtimeConfig,
2398
- ...resolveAwsRegionExtensionConfiguration(extensionConfiguration),
2399
- ...resolveDefaultRuntimeConfig(extensionConfiguration),
2400
- ...resolveHttpHandlerRuntimeConfig(extensionConfiguration),
2401
- ...resolveHttpAuthRuntimeConfig(extensionConfiguration),
2402
- };
2403
- };
2404
-
2405
- class STSClient extends Client {
2406
- constructor(...[configuration]) {
2407
- const _config_0 = getRuntimeConfig(configuration || {});
2408
- const _config_1 = resolveClientEndpointParameters(_config_0);
2409
- const _config_2 = resolveRegionConfig(_config_1);
2410
- const _config_3 = resolveEndpointConfig(_config_2);
2411
- const _config_4 = resolveRetryConfig(_config_3);
2412
- const _config_5 = resolveHostHeaderConfig(_config_4);
2413
- const _config_6 = resolveUserAgentConfig(_config_5);
2414
- const _config_7 = resolveHttpAuthSchemeConfig(_config_6);
2415
- const _config_8 = resolveRuntimeExtensions(_config_7, configuration?.extensions || []);
2416
- super(_config_8);
2417
- this.config = _config_8;
2418
- this.middlewareStack.use(getRetryPlugin(this.config));
2419
- this.middlewareStack.use(getContentLengthPlugin(this.config));
2420
- this.middlewareStack.use(getHostHeaderPlugin(this.config));
2421
- this.middlewareStack.use(getLoggerPlugin(this.config));
2422
- this.middlewareStack.use(getRecursionDetectionPlugin(this.config));
2423
- this.middlewareStack.use(getUserAgentPlugin(this.config));
2424
- this.middlewareStack.use(getHttpAuthSchemeEndpointRuleSetPlugin(this.config, {
2425
- httpAuthSchemeParametersProvider: this.getDefaultHttpAuthSchemeParametersProvider(),
2426
- identityProviderConfigProvider: this.getIdentityProviderConfigProvider(),
2427
- }));
2428
- this.middlewareStack.use(getHttpSigningPlugin(this.config));
2429
- }
2430
- destroy() {
2431
- super.destroy();
2432
- }
2433
- getDefaultHttpAuthSchemeParametersProvider() {
2434
- return defaultSTSHttpAuthSchemeParametersProvider;
2435
- }
2436
- getIdentityProviderConfigProvider() {
2437
- return async (config) => new DefaultIdentityProviderConfig({
2438
- "aws.auth#sigv4": config.credentials,
2439
- });
2440
- }
2441
- }
2442
-
2443
- class STSServiceException extends ServiceException {
2444
- constructor(options) {
2445
- super(options);
2446
- Object.setPrototypeOf(this, STSServiceException.prototype);
2447
- }
2448
- }
2449
-
2450
- class ExpiredTokenException extends STSServiceException {
2451
- constructor(opts) {
2452
- super({
2453
- name: "ExpiredTokenException",
2454
- $fault: "client",
2455
- ...opts,
2456
- });
2457
- this.name = "ExpiredTokenException";
2458
- this.$fault = "client";
2459
- Object.setPrototypeOf(this, ExpiredTokenException.prototype);
2460
- }
2461
- }
2462
- class MalformedPolicyDocumentException extends STSServiceException {
2463
- constructor(opts) {
2464
- super({
2465
- name: "MalformedPolicyDocumentException",
2466
- $fault: "client",
2467
- ...opts,
2468
- });
2469
- this.name = "MalformedPolicyDocumentException";
2470
- this.$fault = "client";
2471
- Object.setPrototypeOf(this, MalformedPolicyDocumentException.prototype);
2472
- }
2473
- }
2474
- class PackedPolicyTooLargeException extends STSServiceException {
2475
- constructor(opts) {
2476
- super({
2477
- name: "PackedPolicyTooLargeException",
2478
- $fault: "client",
2479
- ...opts,
2480
- });
2481
- this.name = "PackedPolicyTooLargeException";
2482
- this.$fault = "client";
2483
- Object.setPrototypeOf(this, PackedPolicyTooLargeException.prototype);
2484
- }
2485
- }
2486
- class RegionDisabledException extends STSServiceException {
2487
- constructor(opts) {
2488
- super({
2489
- name: "RegionDisabledException",
2490
- $fault: "client",
2491
- ...opts,
2492
- });
2493
- this.name = "RegionDisabledException";
2494
- this.$fault = "client";
2495
- Object.setPrototypeOf(this, RegionDisabledException.prototype);
2496
- }
2497
- }
2498
- class IDPRejectedClaimException extends STSServiceException {
2499
- constructor(opts) {
2500
- super({
2501
- name: "IDPRejectedClaimException",
2502
- $fault: "client",
2503
- ...opts,
2504
- });
2505
- this.name = "IDPRejectedClaimException";
2506
- this.$fault = "client";
2507
- Object.setPrototypeOf(this, IDPRejectedClaimException.prototype);
2508
- }
2509
- }
2510
- class InvalidIdentityTokenException extends STSServiceException {
2511
- constructor(opts) {
2512
- super({
2513
- name: "InvalidIdentityTokenException",
2514
- $fault: "client",
2515
- ...opts,
2516
- });
2517
- this.name = "InvalidIdentityTokenException";
2518
- this.$fault = "client";
2519
- Object.setPrototypeOf(this, InvalidIdentityTokenException.prototype);
2520
- }
2521
- }
2522
- class IDPCommunicationErrorException extends STSServiceException {
2523
- constructor(opts) {
2524
- super({
2525
- name: "IDPCommunicationErrorException",
2526
- $fault: "client",
2527
- ...opts,
2528
- });
2529
- this.name = "IDPCommunicationErrorException";
2530
- this.$fault = "client";
2531
- Object.setPrototypeOf(this, IDPCommunicationErrorException.prototype);
2532
- }
2533
- }
2534
- class InvalidAuthorizationMessageException extends STSServiceException {
2535
- constructor(opts) {
2536
- super({
2537
- name: "InvalidAuthorizationMessageException",
2538
- $fault: "client",
2539
- ...opts,
2540
- });
2541
- this.name = "InvalidAuthorizationMessageException";
2542
- this.$fault = "client";
2543
- Object.setPrototypeOf(this, InvalidAuthorizationMessageException.prototype);
2544
- }
2545
- }
2546
- const CredentialsFilterSensitiveLog = (obj) => ({
2547
- ...obj,
2548
- ...(obj.SecretAccessKey && { SecretAccessKey: SENSITIVE_STRING }),
2549
- });
2550
- const AssumeRoleResponseFilterSensitiveLog = (obj) => ({
2551
- ...obj,
2552
- ...(obj.Credentials && { Credentials: CredentialsFilterSensitiveLog(obj.Credentials) }),
2553
- });
2554
- const AssumeRoleWithWebIdentityRequestFilterSensitiveLog = (obj) => ({
2555
- ...obj,
2556
- ...(obj.WebIdentityToken && { WebIdentityToken: SENSITIVE_STRING }),
2557
- });
2558
- const AssumeRoleWithWebIdentityResponseFilterSensitiveLog = (obj) => ({
2559
- ...obj,
2560
- ...(obj.Credentials && { Credentials: CredentialsFilterSensitiveLog(obj.Credentials) }),
2561
- });
2562
-
2563
- const se_AssumeRoleCommand = async (input, context) => {
2564
- const headers = SHARED_HEADERS;
2565
- let body;
2566
- body = buildFormUrlencodedString({
2567
- ...se_AssumeRoleRequest(input),
2568
- [_A]: _AR,
2569
- [_V]: _,
2570
- });
2571
- return buildHttpRpcRequest(context, headers, "/", undefined, body);
2572
- };
2573
- const se_AssumeRoleWithWebIdentityCommand = async (input, context) => {
2574
- const headers = SHARED_HEADERS;
2575
- let body;
2576
- body = buildFormUrlencodedString({
2577
- ...se_AssumeRoleWithWebIdentityRequest(input),
2578
- [_A]: _ARWWI,
2579
- [_V]: _,
2580
- });
2581
- return buildHttpRpcRequest(context, headers, "/", undefined, body);
2582
- };
2583
- const de_AssumeRoleCommand = async (output, context) => {
2584
- if (output.statusCode >= 300) {
2585
- return de_CommandError(output, context);
2586
- }
2587
- const data = await parseXmlBody(output.body, context);
2588
- let contents = {};
2589
- contents = de_AssumeRoleResponse(data.AssumeRoleResult);
2590
- const response = {
2591
- $metadata: deserializeMetadata(output),
2592
- ...contents,
2593
- };
2594
- return response;
2595
- };
2596
- const de_AssumeRoleWithWebIdentityCommand = async (output, context) => {
2597
- if (output.statusCode >= 300) {
2598
- return de_CommandError(output, context);
2599
- }
2600
- const data = await parseXmlBody(output.body, context);
2601
- let contents = {};
2602
- contents = de_AssumeRoleWithWebIdentityResponse(data.AssumeRoleWithWebIdentityResult);
2603
- const response = {
2604
- $metadata: deserializeMetadata(output),
2605
- ...contents,
2606
- };
2607
- return response;
2608
- };
2609
- const de_CommandError = async (output, context) => {
2610
- const parsedOutput = {
2611
- ...output,
2612
- body: await parseXmlErrorBody(output.body, context),
2613
- };
2614
- const errorCode = loadQueryErrorCode(output, parsedOutput.body);
2615
- switch (errorCode) {
2616
- case "ExpiredTokenException":
2617
- case "com.amazonaws.sts#ExpiredTokenException":
2618
- throw await de_ExpiredTokenExceptionRes(parsedOutput);
2619
- case "MalformedPolicyDocument":
2620
- case "com.amazonaws.sts#MalformedPolicyDocumentException":
2621
- throw await de_MalformedPolicyDocumentExceptionRes(parsedOutput);
2622
- case "PackedPolicyTooLarge":
2623
- case "com.amazonaws.sts#PackedPolicyTooLargeException":
2624
- throw await de_PackedPolicyTooLargeExceptionRes(parsedOutput);
2625
- case "RegionDisabledException":
2626
- case "com.amazonaws.sts#RegionDisabledException":
2627
- throw await de_RegionDisabledExceptionRes(parsedOutput);
2628
- case "IDPRejectedClaim":
2629
- case "com.amazonaws.sts#IDPRejectedClaimException":
2630
- throw await de_IDPRejectedClaimExceptionRes(parsedOutput);
2631
- case "InvalidIdentityToken":
2632
- case "com.amazonaws.sts#InvalidIdentityTokenException":
2633
- throw await de_InvalidIdentityTokenExceptionRes(parsedOutput);
2634
- case "IDPCommunicationError":
2635
- case "com.amazonaws.sts#IDPCommunicationErrorException":
2636
- throw await de_IDPCommunicationErrorExceptionRes(parsedOutput);
2637
- case "InvalidAuthorizationMessageException":
2638
- case "com.amazonaws.sts#InvalidAuthorizationMessageException":
2639
- throw await de_InvalidAuthorizationMessageExceptionRes(parsedOutput);
2640
- default:
2641
- const parsedBody = parsedOutput.body;
2642
- return throwDefaultError({
2643
- output,
2644
- parsedBody: parsedBody.Error,
2645
- errorCode,
2646
- });
2647
- }
2648
- };
2649
- const de_ExpiredTokenExceptionRes = async (parsedOutput, context) => {
2650
- const body = parsedOutput.body;
2651
- const deserialized = de_ExpiredTokenException(body.Error);
2652
- const exception = new ExpiredTokenException({
2653
- $metadata: deserializeMetadata(parsedOutput),
2654
- ...deserialized,
2655
- });
2656
- return decorateServiceException(exception, body);
2657
- };
2658
- const de_IDPCommunicationErrorExceptionRes = async (parsedOutput, context) => {
2659
- const body = parsedOutput.body;
2660
- const deserialized = de_IDPCommunicationErrorException(body.Error);
2661
- const exception = new IDPCommunicationErrorException({
2662
- $metadata: deserializeMetadata(parsedOutput),
2663
- ...deserialized,
2664
- });
2665
- return decorateServiceException(exception, body);
2666
- };
2667
- const de_IDPRejectedClaimExceptionRes = async (parsedOutput, context) => {
2668
- const body = parsedOutput.body;
2669
- const deserialized = de_IDPRejectedClaimException(body.Error);
2670
- const exception = new IDPRejectedClaimException({
2671
- $metadata: deserializeMetadata(parsedOutput),
2672
- ...deserialized,
2673
- });
2674
- return decorateServiceException(exception, body);
2675
- };
2676
- const de_InvalidAuthorizationMessageExceptionRes = async (parsedOutput, context) => {
2677
- const body = parsedOutput.body;
2678
- const deserialized = de_InvalidAuthorizationMessageException(body.Error);
2679
- const exception = new InvalidAuthorizationMessageException({
2680
- $metadata: deserializeMetadata(parsedOutput),
2681
- ...deserialized,
2682
- });
2683
- return decorateServiceException(exception, body);
2684
- };
2685
- const de_InvalidIdentityTokenExceptionRes = async (parsedOutput, context) => {
2686
- const body = parsedOutput.body;
2687
- const deserialized = de_InvalidIdentityTokenException(body.Error);
2688
- const exception = new InvalidIdentityTokenException({
2689
- $metadata: deserializeMetadata(parsedOutput),
2690
- ...deserialized,
2691
- });
2692
- return decorateServiceException(exception, body);
2693
- };
2694
- const de_MalformedPolicyDocumentExceptionRes = async (parsedOutput, context) => {
2695
- const body = parsedOutput.body;
2696
- const deserialized = de_MalformedPolicyDocumentException(body.Error);
2697
- const exception = new MalformedPolicyDocumentException({
2698
- $metadata: deserializeMetadata(parsedOutput),
2699
- ...deserialized,
2700
- });
2701
- return decorateServiceException(exception, body);
2702
- };
2703
- const de_PackedPolicyTooLargeExceptionRes = async (parsedOutput, context) => {
2704
- const body = parsedOutput.body;
2705
- const deserialized = de_PackedPolicyTooLargeException(body.Error);
2706
- const exception = new PackedPolicyTooLargeException({
2707
- $metadata: deserializeMetadata(parsedOutput),
2708
- ...deserialized,
2709
- });
2710
- return decorateServiceException(exception, body);
2711
- };
2712
- const de_RegionDisabledExceptionRes = async (parsedOutput, context) => {
2713
- const body = parsedOutput.body;
2714
- const deserialized = de_RegionDisabledException(body.Error);
2715
- const exception = new RegionDisabledException({
2716
- $metadata: deserializeMetadata(parsedOutput),
2717
- ...deserialized,
2718
- });
2719
- return decorateServiceException(exception, body);
2720
- };
2721
- const se_AssumeRoleRequest = (input, context) => {
2722
- const entries = {};
2723
- if (input[_RA] != null) {
2724
- entries[_RA] = input[_RA];
2725
- }
2726
- if (input[_RSN] != null) {
2727
- entries[_RSN] = input[_RSN];
2728
- }
2729
- if (input[_PA] != null) {
2730
- const memberEntries = se_policyDescriptorListType(input[_PA]);
2731
- if (input[_PA]?.length === 0) {
2732
- entries.PolicyArns = [];
2733
- }
2734
- Object.entries(memberEntries).forEach(([key, value]) => {
2735
- const loc = `PolicyArns.${key}`;
2736
- entries[loc] = value;
2737
- });
2738
- }
2739
- if (input[_P] != null) {
2740
- entries[_P] = input[_P];
2741
- }
2742
- if (input[_DS] != null) {
2743
- entries[_DS] = input[_DS];
2744
- }
2745
- if (input[_T] != null) {
2746
- const memberEntries = se_tagListType(input[_T]);
2747
- if (input[_T]?.length === 0) {
2748
- entries.Tags = [];
2749
- }
2750
- Object.entries(memberEntries).forEach(([key, value]) => {
2751
- const loc = `Tags.${key}`;
2752
- entries[loc] = value;
2753
- });
2754
- }
2755
- if (input[_TTK] != null) {
2756
- const memberEntries = se_tagKeyListType(input[_TTK]);
2757
- if (input[_TTK]?.length === 0) {
2758
- entries.TransitiveTagKeys = [];
2759
- }
2760
- Object.entries(memberEntries).forEach(([key, value]) => {
2761
- const loc = `TransitiveTagKeys.${key}`;
2762
- entries[loc] = value;
2763
- });
2764
- }
2765
- if (input[_EI] != null) {
2766
- entries[_EI] = input[_EI];
2767
- }
2768
- if (input[_SN] != null) {
2769
- entries[_SN] = input[_SN];
2770
- }
2771
- if (input[_TC] != null) {
2772
- entries[_TC] = input[_TC];
2773
- }
2774
- if (input[_SI] != null) {
2775
- entries[_SI] = input[_SI];
2776
- }
2777
- if (input[_PC] != null) {
2778
- const memberEntries = se_ProvidedContextsListType(input[_PC]);
2779
- if (input[_PC]?.length === 0) {
2780
- entries.ProvidedContexts = [];
2781
- }
2782
- Object.entries(memberEntries).forEach(([key, value]) => {
2783
- const loc = `ProvidedContexts.${key}`;
2784
- entries[loc] = value;
2785
- });
2786
- }
2787
- return entries;
2788
- };
2789
- const se_AssumeRoleWithWebIdentityRequest = (input, context) => {
2790
- const entries = {};
2791
- if (input[_RA] != null) {
2792
- entries[_RA] = input[_RA];
2793
- }
2794
- if (input[_RSN] != null) {
2795
- entries[_RSN] = input[_RSN];
2796
- }
2797
- if (input[_WIT] != null) {
2798
- entries[_WIT] = input[_WIT];
2799
- }
2800
- if (input[_PI] != null) {
2801
- entries[_PI] = input[_PI];
2802
- }
2803
- if (input[_PA] != null) {
2804
- const memberEntries = se_policyDescriptorListType(input[_PA]);
2805
- if (input[_PA]?.length === 0) {
2806
- entries.PolicyArns = [];
2807
- }
2808
- Object.entries(memberEntries).forEach(([key, value]) => {
2809
- const loc = `PolicyArns.${key}`;
2810
- entries[loc] = value;
2811
- });
2812
- }
2813
- if (input[_P] != null) {
2814
- entries[_P] = input[_P];
2815
- }
2816
- if (input[_DS] != null) {
2817
- entries[_DS] = input[_DS];
2818
- }
2819
- return entries;
2820
- };
2821
- const se_policyDescriptorListType = (input, context) => {
2822
- const entries = {};
2823
- let counter = 1;
2824
- for (const entry of input) {
2825
- if (entry === null) {
2826
- continue;
2827
- }
2828
- const memberEntries = se_PolicyDescriptorType(entry);
2829
- Object.entries(memberEntries).forEach(([key, value]) => {
2830
- entries[`member.${counter}.${key}`] = value;
2831
- });
2832
- counter++;
2833
- }
2834
- return entries;
2835
- };
2836
- const se_PolicyDescriptorType = (input, context) => {
2837
- const entries = {};
2838
- if (input[_a] != null) {
2839
- entries[_a] = input[_a];
2840
- }
2841
- return entries;
2842
- };
2843
- const se_ProvidedContext = (input, context) => {
2844
- const entries = {};
2845
- if (input[_PAro] != null) {
2846
- entries[_PAro] = input[_PAro];
2847
- }
2848
- if (input[_CA] != null) {
2849
- entries[_CA] = input[_CA];
2850
- }
2851
- return entries;
2852
- };
2853
- const se_ProvidedContextsListType = (input, context) => {
2854
- const entries = {};
2855
- let counter = 1;
2856
- for (const entry of input) {
2857
- if (entry === null) {
2858
- continue;
2859
- }
2860
- const memberEntries = se_ProvidedContext(entry);
2861
- Object.entries(memberEntries).forEach(([key, value]) => {
2862
- entries[`member.${counter}.${key}`] = value;
2863
- });
2864
- counter++;
2865
- }
2866
- return entries;
2867
- };
2868
- const se_Tag = (input, context) => {
2869
- const entries = {};
2870
- if (input[_K] != null) {
2871
- entries[_K] = input[_K];
2872
- }
2873
- if (input[_Va] != null) {
2874
- entries[_Va] = input[_Va];
2875
- }
2876
- return entries;
2877
- };
2878
- const se_tagKeyListType = (input, context) => {
2879
- const entries = {};
2880
- let counter = 1;
2881
- for (const entry of input) {
2882
- if (entry === null) {
2883
- continue;
2884
- }
2885
- entries[`member.${counter}`] = entry;
2886
- counter++;
2887
- }
2888
- return entries;
2889
- };
2890
- const se_tagListType = (input, context) => {
2891
- const entries = {};
2892
- let counter = 1;
2893
- for (const entry of input) {
2894
- if (entry === null) {
2895
- continue;
2896
- }
2897
- const memberEntries = se_Tag(entry);
2898
- Object.entries(memberEntries).forEach(([key, value]) => {
2899
- entries[`member.${counter}.${key}`] = value;
2900
- });
2901
- counter++;
2902
- }
2903
- return entries;
2904
- };
2905
- const de_AssumedRoleUser = (output, context) => {
2906
- const contents = {};
2907
- if (output[_ARI] != null) {
2908
- contents[_ARI] = expectString(output[_ARI]);
2909
- }
2910
- if (output[_Ar] != null) {
2911
- contents[_Ar] = expectString(output[_Ar]);
2912
- }
2913
- return contents;
2914
- };
2915
- const de_AssumeRoleResponse = (output, context) => {
2916
- const contents = {};
2917
- if (output[_C] != null) {
2918
- contents[_C] = de_Credentials(output[_C]);
2919
- }
2920
- if (output[_ARU] != null) {
2921
- contents[_ARU] = de_AssumedRoleUser(output[_ARU]);
2922
- }
2923
- if (output[_PPS] != null) {
2924
- contents[_PPS] = strictParseInt32(output[_PPS]);
2925
- }
2926
- if (output[_SI] != null) {
2927
- contents[_SI] = expectString(output[_SI]);
2928
- }
2929
- return contents;
2930
- };
2931
- const de_AssumeRoleWithWebIdentityResponse = (output, context) => {
2932
- const contents = {};
2933
- if (output[_C] != null) {
2934
- contents[_C] = de_Credentials(output[_C]);
2935
- }
2936
- if (output[_SFWIT] != null) {
2937
- contents[_SFWIT] = expectString(output[_SFWIT]);
2938
- }
2939
- if (output[_ARU] != null) {
2940
- contents[_ARU] = de_AssumedRoleUser(output[_ARU]);
2941
- }
2942
- if (output[_PPS] != null) {
2943
- contents[_PPS] = strictParseInt32(output[_PPS]);
2944
- }
2945
- if (output[_Pr] != null) {
2946
- contents[_Pr] = expectString(output[_Pr]);
2947
- }
2948
- if (output[_Au] != null) {
2949
- contents[_Au] = expectString(output[_Au]);
2950
- }
2951
- if (output[_SI] != null) {
2952
- contents[_SI] = expectString(output[_SI]);
2953
- }
2954
- return contents;
2955
- };
2956
- const de_Credentials = (output, context) => {
2957
- const contents = {};
2958
- if (output[_AKI] != null) {
2959
- contents[_AKI] = expectString(output[_AKI]);
2960
- }
2961
- if (output[_SAK] != null) {
2962
- contents[_SAK] = expectString(output[_SAK]);
2963
- }
2964
- if (output[_STe] != null) {
2965
- contents[_STe] = expectString(output[_STe]);
2966
- }
2967
- if (output[_E] != null) {
2968
- contents[_E] = expectNonNull(parseRfc3339DateTimeWithOffset(output[_E]));
2969
- }
2970
- return contents;
2971
- };
2972
- const de_ExpiredTokenException = (output, context) => {
2973
- const contents = {};
2974
- if (output[_m] != null) {
2975
- contents[_m] = expectString(output[_m]);
2976
- }
2977
- return contents;
2978
- };
2979
- const de_IDPCommunicationErrorException = (output, context) => {
2980
- const contents = {};
2981
- if (output[_m] != null) {
2982
- contents[_m] = expectString(output[_m]);
2983
- }
2984
- return contents;
2985
- };
2986
- const de_IDPRejectedClaimException = (output, context) => {
2987
- const contents = {};
2988
- if (output[_m] != null) {
2989
- contents[_m] = expectString(output[_m]);
2990
- }
2991
- return contents;
2992
- };
2993
- const de_InvalidAuthorizationMessageException = (output, context) => {
2994
- const contents = {};
2995
- if (output[_m] != null) {
2996
- contents[_m] = expectString(output[_m]);
2997
- }
2998
- return contents;
2999
- };
3000
- const de_InvalidIdentityTokenException = (output, context) => {
3001
- const contents = {};
3002
- if (output[_m] != null) {
3003
- contents[_m] = expectString(output[_m]);
3004
- }
3005
- return contents;
3006
- };
3007
- const de_MalformedPolicyDocumentException = (output, context) => {
3008
- const contents = {};
3009
- if (output[_m] != null) {
3010
- contents[_m] = expectString(output[_m]);
3011
- }
3012
- return contents;
3013
- };
3014
- const de_PackedPolicyTooLargeException = (output, context) => {
3015
- const contents = {};
3016
- if (output[_m] != null) {
3017
- contents[_m] = expectString(output[_m]);
3018
- }
3019
- return contents;
3020
- };
3021
- const de_RegionDisabledException = (output, context) => {
3022
- const contents = {};
3023
- if (output[_m] != null) {
3024
- contents[_m] = expectString(output[_m]);
3025
- }
3026
- return contents;
3027
- };
3028
- const deserializeMetadata = (output) => ({
3029
- httpStatusCode: output.statusCode,
3030
- requestId: output.headers["x-amzn-requestid"] ?? output.headers["x-amzn-request-id"] ?? output.headers["x-amz-request-id"],
3031
- extendedRequestId: output.headers["x-amz-id-2"],
3032
- cfId: output.headers["x-amz-cf-id"],
3033
- });
3034
- const throwDefaultError = withBaseException(STSServiceException);
3035
- const buildHttpRpcRequest = async (context, headers, path, resolvedHostname, body) => {
3036
- const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
3037
- const contents = {
3038
- protocol,
3039
- hostname,
3040
- port,
3041
- method: "POST",
3042
- path: basePath.endsWith("/") ? basePath.slice(0, -1) + path : basePath + path,
3043
- headers,
3044
- };
3045
- if (resolvedHostname !== undefined) {
3046
- contents.hostname = resolvedHostname;
3047
- }
3048
- if (body !== undefined) {
3049
- contents.body = body;
3050
- }
3051
- return new HttpRequest(contents);
3052
- };
3053
- const SHARED_HEADERS = {
3054
- "content-type": "application/x-www-form-urlencoded",
3055
- };
3056
- const _ = "2011-06-15";
3057
- const _A = "Action";
3058
- const _AKI = "AccessKeyId";
3059
- const _AR = "AssumeRole";
3060
- const _ARI = "AssumedRoleId";
3061
- const _ARU = "AssumedRoleUser";
3062
- const _ARWWI = "AssumeRoleWithWebIdentity";
3063
- const _Ar = "Arn";
3064
- const _Au = "Audience";
3065
- const _C = "Credentials";
3066
- const _CA = "ContextAssertion";
3067
- const _DS = "DurationSeconds";
3068
- const _E = "Expiration";
3069
- const _EI = "ExternalId";
3070
- const _K = "Key";
3071
- const _P = "Policy";
3072
- const _PA = "PolicyArns";
3073
- const _PAro = "ProviderArn";
3074
- const _PC = "ProvidedContexts";
3075
- const _PI = "ProviderId";
3076
- const _PPS = "PackedPolicySize";
3077
- const _Pr = "Provider";
3078
- const _RA = "RoleArn";
3079
- const _RSN = "RoleSessionName";
3080
- const _SAK = "SecretAccessKey";
3081
- const _SFWIT = "SubjectFromWebIdentityToken";
3082
- const _SI = "SourceIdentity";
3083
- const _SN = "SerialNumber";
3084
- const _STe = "SessionToken";
3085
- const _T = "Tags";
3086
- const _TC = "TokenCode";
3087
- const _TTK = "TransitiveTagKeys";
3088
- const _V = "Version";
3089
- const _Va = "Value";
3090
- const _WIT = "WebIdentityToken";
3091
- const _a = "arn";
3092
- const _m = "message";
3093
- const buildFormUrlencodedString = (formEntries) => Object.entries(formEntries)
3094
- .map(([key, value]) => extendedEncodeURIComponent(key) + "=" + extendedEncodeURIComponent(value))
3095
- .join("&");
3096
- const loadQueryErrorCode = (output, data) => {
3097
- if (data.Error?.Code !== undefined) {
3098
- return data.Error.Code;
3099
- }
3100
- if (output.statusCode == 404) {
3101
- return "NotFound";
3102
- }
3103
- };
3104
-
3105
- class AssumeRoleCommand extends Command
3106
- .classBuilder()
3107
- .ep({
3108
- ...commonParams,
3109
- })
3110
- .m(function (Command, cs, config, o) {
3111
- return [
3112
- getSerdePlugin(config, this.serialize, this.deserialize),
3113
- getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
3114
- ];
3115
- })
3116
- .s("AWSSecurityTokenServiceV20110615", "AssumeRole", {})
3117
- .n("STSClient", "AssumeRoleCommand")
3118
- .f(void 0, AssumeRoleResponseFilterSensitiveLog)
3119
- .ser(se_AssumeRoleCommand)
3120
- .de(de_AssumeRoleCommand)
3121
- .build() {
3122
- }
3123
-
3124
- class AssumeRoleWithWebIdentityCommand extends Command
3125
- .classBuilder()
3126
- .ep({
3127
- ...commonParams,
3128
- })
3129
- .m(function (Command, cs, config, o) {
3130
- return [
3131
- getSerdePlugin(config, this.serialize, this.deserialize),
3132
- getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
3133
- ];
3134
- })
3135
- .s("AWSSecurityTokenServiceV20110615", "AssumeRoleWithWebIdentity", {})
3136
- .n("STSClient", "AssumeRoleWithWebIdentityCommand")
3137
- .f(AssumeRoleWithWebIdentityRequestFilterSensitiveLog, AssumeRoleWithWebIdentityResponseFilterSensitiveLog)
3138
- .ser(se_AssumeRoleWithWebIdentityCommand)
3139
- .de(de_AssumeRoleWithWebIdentityCommand)
3140
- .build() {
3141
- }
3142
-
3143
- const ASSUME_ROLE_DEFAULT_REGION = "us-east-1";
3144
- const resolveRegion = async (_region, _parentRegion, credentialProviderLogger) => {
3145
- const region = typeof _region === "function" ? await _region() : _region;
3146
- const parentRegion = typeof _parentRegion === "function" ? await _parentRegion() : _parentRegion;
3147
- credentialProviderLogger?.debug?.("@aws-sdk/client-sts::resolveRegion", "accepting first of:", `${region} (provider)`, `${parentRegion} (parent client)`, `${ASSUME_ROLE_DEFAULT_REGION} (STS default)`);
3148
- return region ?? parentRegion ?? ASSUME_ROLE_DEFAULT_REGION;
3149
- };
3150
- const getDefaultRoleAssumer$1 = (stsOptions, stsClientCtor) => {
3151
- let stsClient;
3152
- let closureSourceCreds;
3153
- return async (sourceCreds, params) => {
3154
- closureSourceCreds = sourceCreds;
3155
- if (!stsClient) {
3156
- const { logger = stsOptions?.parentClientConfig?.logger, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger, } = stsOptions;
3157
- const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger);
3158
- stsClient = new stsClientCtor({
3159
- credentialDefaultProvider: () => async () => closureSourceCreds,
3160
- region: resolvedRegion,
3161
- requestHandler: requestHandler,
3162
- logger: logger,
3163
- });
3164
- }
3165
- const { Credentials } = await stsClient.send(new AssumeRoleCommand(params));
3166
- if (!Credentials || !Credentials.AccessKeyId || !Credentials.SecretAccessKey) {
3167
- throw new Error(`Invalid response from STS.assumeRole call with role ${params.RoleArn}`);
3168
- }
3169
- return {
3170
- accessKeyId: Credentials.AccessKeyId,
3171
- secretAccessKey: Credentials.SecretAccessKey,
3172
- sessionToken: Credentials.SessionToken,
3173
- expiration: Credentials.Expiration,
3174
- credentialScope: Credentials.CredentialScope,
3175
- };
3176
- };
3177
- };
3178
- const getDefaultRoleAssumerWithWebIdentity$1 = (stsOptions, stsClientCtor) => {
3179
- let stsClient;
3180
- return async (params) => {
3181
- if (!stsClient) {
3182
- const { logger = stsOptions?.parentClientConfig?.logger, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger, } = stsOptions;
3183
- const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger);
3184
- stsClient = new stsClientCtor({
3185
- region: resolvedRegion,
3186
- requestHandler: requestHandler,
3187
- logger: logger,
3188
- });
3189
- }
3190
- const { Credentials } = await stsClient.send(new AssumeRoleWithWebIdentityCommand(params));
3191
- if (!Credentials || !Credentials.AccessKeyId || !Credentials.SecretAccessKey) {
3192
- throw new Error(`Invalid response from STS.assumeRoleWithWebIdentity call with role ${params.RoleArn}`);
3193
- }
3194
- return {
3195
- accessKeyId: Credentials.AccessKeyId,
3196
- secretAccessKey: Credentials.SecretAccessKey,
3197
- sessionToken: Credentials.SessionToken,
3198
- expiration: Credentials.Expiration,
3199
- credentialScope: Credentials.CredentialScope,
3200
- };
3201
- };
3202
- };
3203
-
3204
- const getCustomizableStsClientCtor = (baseCtor, customizations) => {
3205
- if (!customizations)
3206
- return baseCtor;
3207
- else
3208
- return class CustomizableSTSClient extends baseCtor {
3209
- constructor(config) {
3210
- super(config);
3211
- for (const customization of customizations) {
3212
- this.middlewareStack.use(customization);
3213
- }
3214
- }
3215
- };
3216
- };
3217
- const getDefaultRoleAssumer = (stsOptions = {}, stsPlugins) => getDefaultRoleAssumer$1(stsOptions, getCustomizableStsClientCtor(STSClient, stsPlugins));
3218
- const getDefaultRoleAssumerWithWebIdentity = (stsOptions = {}, stsPlugins) => getDefaultRoleAssumerWithWebIdentity$1(stsOptions, getCustomizableStsClientCtor(STSClient, stsPlugins));
3219
-
3220
- export { getDefaultRoleAssumerWithWebIdentity as a, getDefaultRoleAssumer as g };