@cdklabs/cdk-ecs-codedeploy 0.0.258 → 0.0.259

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.jsii +3 -3
  2. package/lib/api-canary/index.js +1 -1
  3. package/lib/ecs-appspec/index.js +1 -1
  4. package/lib/ecs-deployment/index.js +1 -1
  5. package/lib/ecs-patterns/application-load-balanced-codedeployed-fargate-service.js +1 -1
  6. package/node_modules/@aws-sdk/client-codedeploy/dist-cjs/index.js +40 -80
  7. package/node_modules/@aws-sdk/client-codedeploy/dist-es/protocols/Aws_json1_1.js +1 -40
  8. package/node_modules/@aws-sdk/client-codedeploy/package.json +4 -4
  9. package/node_modules/@aws-sdk/client-sso/dist-cjs/index.js +6 -46
  10. package/node_modules/@aws-sdk/client-sso/dist-es/protocols/Aws_restJson1.js +1 -40
  11. package/node_modules/@aws-sdk/client-sso/package.json +2 -2
  12. package/node_modules/@aws-sdk/client-sso-oidc/dist-cjs/index.js +7 -47
  13. package/node_modules/@aws-sdk/client-sso-oidc/dist-es/protocols/Aws_restJson1.js +1 -40
  14. package/node_modules/@aws-sdk/client-sso-oidc/package.json +4 -4
  15. package/node_modules/@aws-sdk/client-sts/dist-cjs/index.js +10 -43
  16. package/node_modules/@aws-sdk/client-sts/dist-es/protocols/Aws_query.js +2 -34
  17. package/node_modules/@aws-sdk/client-sts/package.json +3 -4
  18. package/node_modules/@aws-sdk/core/CHANGELOG.md +19 -0
  19. package/node_modules/@aws-sdk/core/dist-cjs/index.js +126 -1
  20. package/node_modules/@aws-sdk/core/dist-cjs/protocols/common.js +1 -0
  21. package/node_modules/@aws-sdk/core/dist-cjs/protocols/json/parseJsonBody.js +1 -0
  22. package/node_modules/@aws-sdk/core/dist-cjs/protocols/xml/parseXmlBody.js +1 -0
  23. package/node_modules/@aws-sdk/core/dist-es/protocols/common.js +2 -0
  24. package/node_modules/@aws-sdk/core/dist-es/protocols/index.js +2 -0
  25. package/node_modules/@aws-sdk/core/dist-es/protocols/json/parseJsonBody.js +51 -0
  26. package/node_modules/@aws-sdk/core/dist-es/protocols/xml/parseXmlBody.js +57 -0
  27. package/node_modules/@aws-sdk/core/dist-types/protocols/common.d.ts +2 -0
  28. package/node_modules/@aws-sdk/core/dist-types/protocols/index.d.ts +2 -0
  29. package/node_modules/@aws-sdk/core/dist-types/protocols/json/parseJsonBody.d.ts +4 -0
  30. package/node_modules/@aws-sdk/core/dist-types/protocols/xml/parseXmlBody.d.ts +4 -0
  31. package/node_modules/@aws-sdk/core/dist-types/ts3.4/protocols/common.d.ts +5 -0
  32. package/node_modules/@aws-sdk/core/dist-types/ts3.4/protocols/index.d.ts +2 -0
  33. package/node_modules/@aws-sdk/core/dist-types/ts3.4/protocols/json/parseJsonBody.d.ts +13 -0
  34. package/node_modules/@aws-sdk/core/dist-types/ts3.4/protocols/xml/parseXmlBody.d.ts +13 -0
  35. package/node_modules/@aws-sdk/core/package.json +2 -1
  36. package/node_modules/@aws-sdk/core/src/protocols/common.ts +5 -0
  37. package/node_modules/@aws-sdk/core/src/protocols/index.ts +2 -0
  38. package/node_modules/@aws-sdk/core/src/protocols/json/parseJsonBody.ts +60 -0
  39. package/node_modules/@aws-sdk/core/src/protocols/xml/parseXmlBody.ts +64 -0
  40. package/node_modules/@aws-sdk/core/tsconfig.cjs.tsbuildinfo +1 -1
  41. package/node_modules/@aws-sdk/core/tsconfig.es.tsbuildinfo +1 -1
  42. package/node_modules/@aws-sdk/core/tsconfig.types.tsbuildinfo +1 -1
  43. package/node_modules/@aws-sdk/credential-provider-ini/package.json +4 -4
  44. package/node_modules/@aws-sdk/credential-provider-node/package.json +4 -4
  45. package/node_modules/@aws-sdk/credential-provider-sso/package.json +3 -3
  46. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +2 -2
  47. package/node_modules/@aws-sdk/token-providers/package.json +2 -2
  48. package/node_modules/@smithy/core/package.json +5 -5
  49. package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
  50. package/node_modules/@smithy/middleware-retry/package.json +2 -2
  51. package/node_modules/@smithy/middleware-serde/dist-types/deserializerMiddleware.d.ts +2 -4
  52. package/node_modules/@smithy/middleware-serde/dist-types/serdePlugin.d.ts +2 -3
  53. package/node_modules/@smithy/middleware-serde/dist-types/serializerMiddleware.d.ts +2 -4
  54. package/node_modules/@smithy/middleware-serde/dist-types/ts3.4/deserializerMiddleware.d.ts +2 -4
  55. package/node_modules/@smithy/middleware-serde/dist-types/ts3.4/serdePlugin.d.ts +2 -3
  56. package/node_modules/@smithy/middleware-serde/dist-types/ts3.4/serializerMiddleware.d.ts +2 -4
  57. package/node_modules/@smithy/middleware-serde/package.json +1 -1
  58. package/node_modules/@smithy/smithy-client/package.json +2 -2
  59. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
  60. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  61. package/package.json +2 -2
@@ -27,6 +27,12 @@ __export(src_exports, {
27
27
  _toStr: () => _toStr,
28
28
  awsExpectUnion: () => awsExpectUnion,
29
29
  emitWarningIfUnsupportedVersion: () => emitWarningIfUnsupportedVersion,
30
+ loadRestJsonErrorCode: () => loadRestJsonErrorCode,
31
+ loadRestXmlErrorCode: () => loadRestXmlErrorCode,
32
+ parseJsonBody: () => parseJsonBody,
33
+ parseJsonErrorBody: () => parseJsonErrorBody,
34
+ parseXmlBody: () => parseXmlBody,
35
+ parseXmlErrorBody: () => parseXmlErrorBody,
30
36
  resolveAWSSDKSigV4Config: () => resolveAWSSDKSigV4Config,
31
37
  resolveAwsSdkSigV4Config: () => resolveAwsSdkSigV4Config
32
38
  });
@@ -305,6 +311,119 @@ var awsExpectUnion = /* @__PURE__ */ __name((value) => {
305
311
  }
306
312
  return (0, import_smithy_client.expectUnion)(value);
307
313
  }, "awsExpectUnion");
314
+
315
+ // src/protocols/common.ts
316
+
317
+ var collectBodyString = /* @__PURE__ */ __name((streamBody, context) => (0, import_smithy_client.collectBody)(streamBody, context).then((body) => context.utf8Encoder(body)), "collectBodyString");
318
+
319
+ // src/protocols/json/parseJsonBody.ts
320
+ var parseJsonBody = /* @__PURE__ */ __name((streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
321
+ if (encoded.length) {
322
+ try {
323
+ return JSON.parse(encoded);
324
+ } catch (e) {
325
+ if ((e == null ? void 0 : e.name) === "SyntaxError") {
326
+ Object.defineProperty(e, "$responseBodyText", {
327
+ value: encoded
328
+ });
329
+ }
330
+ throw e;
331
+ }
332
+ }
333
+ return {};
334
+ }), "parseJsonBody");
335
+ var parseJsonErrorBody = /* @__PURE__ */ __name(async (errorBody, context) => {
336
+ const value = await parseJsonBody(errorBody, context);
337
+ value.message = value.message ?? value.Message;
338
+ return value;
339
+ }, "parseJsonErrorBody");
340
+ var loadRestJsonErrorCode = /* @__PURE__ */ __name((output, data) => {
341
+ const findKey = /* @__PURE__ */ __name((object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()), "findKey");
342
+ const sanitizeErrorCode = /* @__PURE__ */ __name((rawValue) => {
343
+ let cleanValue = rawValue;
344
+ if (typeof cleanValue === "number") {
345
+ cleanValue = cleanValue.toString();
346
+ }
347
+ if (cleanValue.indexOf(",") >= 0) {
348
+ cleanValue = cleanValue.split(",")[0];
349
+ }
350
+ if (cleanValue.indexOf(":") >= 0) {
351
+ cleanValue = cleanValue.split(":")[0];
352
+ }
353
+ if (cleanValue.indexOf("#") >= 0) {
354
+ cleanValue = cleanValue.split("#")[1];
355
+ }
356
+ return cleanValue;
357
+ }, "sanitizeErrorCode");
358
+ const headerKey = findKey(output.headers, "x-amzn-errortype");
359
+ if (headerKey !== void 0) {
360
+ return sanitizeErrorCode(output.headers[headerKey]);
361
+ }
362
+ if (data.code !== void 0) {
363
+ return sanitizeErrorCode(data.code);
364
+ }
365
+ if (data["__type"] !== void 0) {
366
+ return sanitizeErrorCode(data["__type"]);
367
+ }
368
+ }, "loadRestJsonErrorCode");
369
+
370
+ // src/protocols/xml/parseXmlBody.ts
371
+
372
+ var import_fast_xml_parser = require("fast-xml-parser");
373
+ var parseXmlBody = /* @__PURE__ */ __name((streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
374
+ if (encoded.length) {
375
+ const parser = new import_fast_xml_parser.XMLParser({
376
+ attributeNamePrefix: "",
377
+ htmlEntities: true,
378
+ ignoreAttributes: false,
379
+ ignoreDeclaration: true,
380
+ parseTagValue: false,
381
+ trimValues: false,
382
+ tagValueProcessor: (_, val) => val.trim() === "" && val.includes("\n") ? "" : void 0
383
+ });
384
+ parser.addEntity("#xD", "\r");
385
+ parser.addEntity("#10", "\n");
386
+ let parsedObj;
387
+ try {
388
+ parsedObj = parser.parse(encoded);
389
+ } catch (e) {
390
+ if (e && typeof e === "object") {
391
+ Object.defineProperty(e, "$responseBodyText", {
392
+ value: encoded
393
+ });
394
+ }
395
+ throw e;
396
+ }
397
+ const textNodeName = "#text";
398
+ const key = Object.keys(parsedObj)[0];
399
+ const parsedObjToReturn = parsedObj[key];
400
+ if (parsedObjToReturn[textNodeName]) {
401
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
402
+ delete parsedObjToReturn[textNodeName];
403
+ }
404
+ return (0, import_smithy_client.getValueFromTextNode)(parsedObjToReturn);
405
+ }
406
+ return {};
407
+ }), "parseXmlBody");
408
+ var parseXmlErrorBody = /* @__PURE__ */ __name(async (errorBody, context) => {
409
+ const value = await parseXmlBody(errorBody, context);
410
+ if (value.Error) {
411
+ value.Error.message = value.Error.message ?? value.Error.Message;
412
+ }
413
+ return value;
414
+ }, "parseXmlErrorBody");
415
+ var loadRestXmlErrorCode = /* @__PURE__ */ __name((output, data) => {
416
+ var _a;
417
+ if (((_a = data == null ? void 0 : data.Error) == null ? void 0 : _a.Code) !== void 0) {
418
+ return data.Error.Code;
419
+ }
420
+ if ((data == null ? void 0 : data.Code) !== void 0) {
421
+ return data.Code;
422
+ }
423
+ if (output.statusCode == 404) {
424
+ return "NotFound";
425
+ }
426
+ }, "loadRestXmlErrorCode");
308
427
  // Annotate the CommonJS export names for ESM import in node:
309
428
 
310
429
  0 && (module.exports = {
@@ -316,6 +435,12 @@ var awsExpectUnion = /* @__PURE__ */ __name((value) => {
316
435
  _toStr,
317
436
  _toBool,
318
437
  _toNum,
319
- awsExpectUnion
438
+ awsExpectUnion,
439
+ parseJsonBody,
440
+ parseJsonErrorBody,
441
+ loadRestJsonErrorCode,
442
+ parseXmlBody,
443
+ parseXmlErrorBody,
444
+ loadRestXmlErrorCode
320
445
  });
321
446
 
@@ -0,0 +1 @@
1
+ module.exports = require("../index.js");
@@ -0,0 +1 @@
1
+ module.exports = require("../../index.js");
@@ -0,0 +1 @@
1
+ module.exports = require("../../index.js");
@@ -0,0 +1,2 @@
1
+ import { collectBody } from "@smithy/smithy-client";
2
+ export const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
@@ -1,2 +1,4 @@
1
1
  export * from "./coercing-serializers";
2
2
  export * from "./json/awsExpectUnion";
3
+ export * from "./json/parseJsonBody";
4
+ export * from "./xml/parseXmlBody";
@@ -0,0 +1,51 @@
1
+ import { collectBodyString } from "../common";
2
+ export const parseJsonBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
3
+ if (encoded.length) {
4
+ try {
5
+ return JSON.parse(encoded);
6
+ }
7
+ catch (e) {
8
+ if (e?.name === "SyntaxError") {
9
+ Object.defineProperty(e, "$responseBodyText", {
10
+ value: encoded,
11
+ });
12
+ }
13
+ throw e;
14
+ }
15
+ }
16
+ return {};
17
+ });
18
+ export const parseJsonErrorBody = async (errorBody, context) => {
19
+ const value = await parseJsonBody(errorBody, context);
20
+ value.message = value.message ?? value.Message;
21
+ return value;
22
+ };
23
+ export const loadRestJsonErrorCode = (output, data) => {
24
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
25
+ const sanitizeErrorCode = (rawValue) => {
26
+ let cleanValue = rawValue;
27
+ if (typeof cleanValue === "number") {
28
+ cleanValue = cleanValue.toString();
29
+ }
30
+ if (cleanValue.indexOf(",") >= 0) {
31
+ cleanValue = cleanValue.split(",")[0];
32
+ }
33
+ if (cleanValue.indexOf(":") >= 0) {
34
+ cleanValue = cleanValue.split(":")[0];
35
+ }
36
+ if (cleanValue.indexOf("#") >= 0) {
37
+ cleanValue = cleanValue.split("#")[1];
38
+ }
39
+ return cleanValue;
40
+ };
41
+ const headerKey = findKey(output.headers, "x-amzn-errortype");
42
+ if (headerKey !== undefined) {
43
+ return sanitizeErrorCode(output.headers[headerKey]);
44
+ }
45
+ if (data.code !== undefined) {
46
+ return sanitizeErrorCode(data.code);
47
+ }
48
+ if (data["__type"] !== undefined) {
49
+ return sanitizeErrorCode(data["__type"]);
50
+ }
51
+ };
@@ -0,0 +1,57 @@
1
+ import { getValueFromTextNode } from "@smithy/smithy-client";
2
+ import { XMLParser } from "fast-xml-parser";
3
+ import { collectBodyString } from "../common";
4
+ export const parseXmlBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
5
+ if (encoded.length) {
6
+ const parser = new XMLParser({
7
+ attributeNamePrefix: "",
8
+ htmlEntities: true,
9
+ ignoreAttributes: false,
10
+ ignoreDeclaration: true,
11
+ parseTagValue: false,
12
+ trimValues: false,
13
+ tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
14
+ });
15
+ parser.addEntity("#xD", "\r");
16
+ parser.addEntity("#10", "\n");
17
+ let parsedObj;
18
+ try {
19
+ parsedObj = parser.parse(encoded);
20
+ }
21
+ catch (e) {
22
+ if (e && typeof e === "object") {
23
+ Object.defineProperty(e, "$responseBodyText", {
24
+ value: encoded,
25
+ });
26
+ }
27
+ throw e;
28
+ }
29
+ const textNodeName = "#text";
30
+ const key = Object.keys(parsedObj)[0];
31
+ const parsedObjToReturn = parsedObj[key];
32
+ if (parsedObjToReturn[textNodeName]) {
33
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
34
+ delete parsedObjToReturn[textNodeName];
35
+ }
36
+ return getValueFromTextNode(parsedObjToReturn);
37
+ }
38
+ return {};
39
+ });
40
+ export const parseXmlErrorBody = async (errorBody, context) => {
41
+ const value = await parseXmlBody(errorBody, context);
42
+ if (value.Error) {
43
+ value.Error.message = value.Error.message ?? value.Error.Message;
44
+ }
45
+ return value;
46
+ };
47
+ export const loadRestXmlErrorCode = (output, data) => {
48
+ if (data?.Error?.Code !== undefined) {
49
+ return data.Error.Code;
50
+ }
51
+ if (data?.Code !== undefined) {
52
+ return data.Code;
53
+ }
54
+ if (output.statusCode == 404) {
55
+ return "NotFound";
56
+ }
57
+ };
@@ -0,0 +1,2 @@
1
+ import type { SerdeContext } from "@smithy/types";
2
+ export declare const collectBodyString: (streamBody: any, context: SerdeContext) => Promise<string>;
@@ -1,2 +1,4 @@
1
1
  export * from "./coercing-serializers";
2
2
  export * from "./json/awsExpectUnion";
3
+ export * from "./json/parseJsonBody";
4
+ export * from "./xml/parseXmlBody";
@@ -0,0 +1,4 @@
1
+ import type { HttpResponse, SerdeContext } from "@smithy/types";
2
+ export declare const parseJsonBody: (streamBody: any, context: SerdeContext) => any;
3
+ export declare const parseJsonErrorBody: (errorBody: any, context: SerdeContext) => Promise<any>;
4
+ export declare const loadRestJsonErrorCode: (output: HttpResponse, data: any) => string | undefined;
@@ -0,0 +1,4 @@
1
+ import type { HttpResponse, SerdeContext } from "@smithy/types";
2
+ export declare const parseXmlBody: (streamBody: any, context: SerdeContext) => any;
3
+ export declare const parseXmlErrorBody: (errorBody: any, context: SerdeContext) => Promise<any>;
4
+ export declare const loadRestXmlErrorCode: (output: HttpResponse, data: any) => string | undefined;
@@ -0,0 +1,5 @@
1
+ import { SerdeContext } from "@smithy/types";
2
+ export declare const collectBodyString: (
3
+ streamBody: any,
4
+ context: SerdeContext
5
+ ) => Promise<string>;
@@ -1,2 +1,4 @@
1
1
  export * from "./coercing-serializers";
2
2
  export * from "./json/awsExpectUnion";
3
+ export * from "./json/parseJsonBody";
4
+ export * from "./xml/parseXmlBody";
@@ -0,0 +1,13 @@
1
+ import { HttpResponse, SerdeContext } from "@smithy/types";
2
+ export declare const parseJsonBody: (
3
+ streamBody: any,
4
+ context: SerdeContext
5
+ ) => any;
6
+ export declare const parseJsonErrorBody: (
7
+ errorBody: any,
8
+ context: SerdeContext
9
+ ) => Promise<any>;
10
+ export declare const loadRestJsonErrorCode: (
11
+ output: HttpResponse,
12
+ data: any
13
+ ) => string | undefined;
@@ -0,0 +1,13 @@
1
+ import { HttpResponse, SerdeContext } from "@smithy/types";
2
+ export declare const parseXmlBody: (
3
+ streamBody: any,
4
+ context: SerdeContext
5
+ ) => any;
6
+ export declare const parseXmlErrorBody: (
7
+ errorBody: any,
8
+ context: SerdeContext
9
+ ) => Promise<any>;
10
+ export declare const loadRestXmlErrorCode: (
11
+ output: HttpResponse,
12
+ data: any
13
+ ) => string | undefined;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/core",
3
- "version": "3.525.0",
3
+ "version": "3.529.1",
4
4
  "description": "Core functions & classes shared by multiple AWS SDK clients",
5
5
  "scripts": {
6
6
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
@@ -30,6 +30,7 @@
30
30
  "@smithy/signature-v4": "^2.1.3",
31
31
  "@smithy/smithy-client": "^2.4.2",
32
32
  "@smithy/types": "^2.10.1",
33
+ "fast-xml-parser": "4.2.5",
33
34
  "tslib": "^2.5.0"
34
35
  },
35
36
  "devDependencies": {
@@ -0,0 +1,5 @@
1
+ import { collectBody } from "@smithy/smithy-client";
2
+ import type { HttpResponse, SerdeContext } from "@smithy/types";
3
+
4
+ export const collectBodyString = (streamBody: any, context: SerdeContext): Promise<string> =>
5
+ collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
@@ -1,2 +1,4 @@
1
1
  export * from "./coercing-serializers";
2
2
  export * from "./json/awsExpectUnion";
3
+ export * from "./json/parseJsonBody";
4
+ export * from "./xml/parseXmlBody";
@@ -0,0 +1,60 @@
1
+ import type { HttpResponse, SerdeContext } from "@smithy/types";
2
+
3
+ import { collectBodyString } from "../common";
4
+
5
+ export const parseJsonBody = (streamBody: any, context: SerdeContext): any =>
6
+ collectBodyString(streamBody, context).then((encoded) => {
7
+ if (encoded.length) {
8
+ try {
9
+ return JSON.parse(encoded);
10
+ } catch (e: any) {
11
+ if (e?.name === "SyntaxError") {
12
+ Object.defineProperty(e, "$responseBodyText", {
13
+ value: encoded,
14
+ });
15
+ }
16
+ throw e;
17
+ }
18
+ }
19
+ return {};
20
+ });
21
+
22
+ export const parseJsonErrorBody = async (errorBody: any, context: SerdeContext) => {
23
+ const value = await parseJsonBody(errorBody, context);
24
+ value.message = value.message ?? value.Message;
25
+ return value;
26
+ };
27
+
28
+ export const loadRestJsonErrorCode = (output: HttpResponse, data: any): string | undefined => {
29
+ const findKey = (object: any, key: string) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
30
+
31
+ const sanitizeErrorCode = (rawValue: string | number): string => {
32
+ let cleanValue = rawValue;
33
+ if (typeof cleanValue === "number") {
34
+ cleanValue = cleanValue.toString();
35
+ }
36
+ if (cleanValue.indexOf(",") >= 0) {
37
+ cleanValue = cleanValue.split(",")[0];
38
+ }
39
+ if (cleanValue.indexOf(":") >= 0) {
40
+ cleanValue = cleanValue.split(":")[0];
41
+ }
42
+ if (cleanValue.indexOf("#") >= 0) {
43
+ cleanValue = cleanValue.split("#")[1];
44
+ }
45
+ return cleanValue;
46
+ };
47
+
48
+ const headerKey = findKey(output.headers, "x-amzn-errortype");
49
+ if (headerKey !== undefined) {
50
+ return sanitizeErrorCode(output.headers[headerKey]);
51
+ }
52
+
53
+ if (data.code !== undefined) {
54
+ return sanitizeErrorCode(data.code);
55
+ }
56
+
57
+ if (data["__type"] !== undefined) {
58
+ return sanitizeErrorCode(data["__type"]);
59
+ }
60
+ };
@@ -0,0 +1,64 @@
1
+ import { getValueFromTextNode } from "@smithy/smithy-client";
2
+ import type { HttpResponse, SerdeContext } from "@smithy/types";
3
+ import { XMLParser } from "fast-xml-parser";
4
+
5
+ import { collectBodyString } from "../common";
6
+
7
+ export const parseXmlBody = (streamBody: any, context: SerdeContext): any =>
8
+ collectBodyString(streamBody, context).then((encoded) => {
9
+ if (encoded.length) {
10
+ const parser = new XMLParser({
11
+ attributeNamePrefix: "",
12
+ htmlEntities: true,
13
+ ignoreAttributes: false,
14
+ ignoreDeclaration: true,
15
+ parseTagValue: false,
16
+ trimValues: false,
17
+ tagValueProcessor: (_: any, val: any) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
18
+ });
19
+ parser.addEntity("#xD", "\r");
20
+ parser.addEntity("#10", "\n");
21
+
22
+ let parsedObj;
23
+ try {
24
+ parsedObj = parser.parse(encoded);
25
+ } catch (e: any) {
26
+ if (e && typeof e === "object") {
27
+ Object.defineProperty(e, "$responseBodyText", {
28
+ value: encoded,
29
+ });
30
+ }
31
+ throw e;
32
+ }
33
+
34
+ const textNodeName = "#text";
35
+ const key = Object.keys(parsedObj)[0];
36
+ const parsedObjToReturn = parsedObj[key];
37
+ if (parsedObjToReturn[textNodeName]) {
38
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
39
+ delete parsedObjToReturn[textNodeName];
40
+ }
41
+ return getValueFromTextNode(parsedObjToReturn);
42
+ }
43
+ return {};
44
+ });
45
+
46
+ export const parseXmlErrorBody = async (errorBody: any, context: SerdeContext) => {
47
+ const value = await parseXmlBody(errorBody, context);
48
+ if (value.Error) {
49
+ value.Error.message = value.Error.message ?? value.Error.Message;
50
+ }
51
+ return value;
52
+ };
53
+
54
+ export const loadRestXmlErrorCode = (output: HttpResponse, data: any): string | undefined => {
55
+ if (data?.Error?.Code !== undefined) {
56
+ return data.Error.Code;
57
+ }
58
+ if (data?.Code !== undefined) {
59
+ return data.Code;
60
+ }
61
+ if (output.statusCode == 404) {
62
+ return "NotFound";
63
+ }
64
+ };