1 | var __defProp = Object.defineProperty;
|
2 | var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3 | var __getOwnPropNames = Object.getOwnPropertyNames;
|
4 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5 | var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
6 | var __export = (target, all) => {
|
7 | for (var name in all)
|
8 | __defProp(target, name, { get: all[name], enumerable: true });
|
9 | };
|
10 | var __copyProps = (to, from, except, desc) => {
|
11 | if (from && typeof from === "object" || typeof from === "function") {
|
12 | for (let key of __getOwnPropNames(from))
|
13 | if (!__hasOwnProp.call(to, key) && key !== except)
|
14 | __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15 | }
|
16 | return to;
|
17 | };
|
18 | var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19 |
|
20 |
|
21 | var src_exports = {};
|
22 | __export(src_exports, {
|
23 | getUserAgentMiddlewareOptions: () => getUserAgentMiddlewareOptions,
|
24 | getUserAgentPlugin: () => getUserAgentPlugin,
|
25 | resolveUserAgentConfig: () => resolveUserAgentConfig,
|
26 | userAgentMiddleware: () => userAgentMiddleware
|
27 | });
|
28 | module.exports = __toCommonJS(src_exports);
|
29 |
|
30 |
|
31 | function resolveUserAgentConfig(input) {
|
32 | return {
|
33 | ...input,
|
34 | customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent
|
35 | };
|
36 | }
|
37 | __name(resolveUserAgentConfig, "resolveUserAgentConfig");
|
38 |
|
39 |
|
40 | var import_util_endpoints = require("@aws-sdk/util-endpoints");
|
41 | var import_protocol_http = require("@smithy/protocol-http");
|
42 |
|
43 |
|
44 | var USER_AGENT = "user-agent";
|
45 | var X_AMZ_USER_AGENT = "x-amz-user-agent";
|
46 | var SPACE = " ";
|
47 | var UA_NAME_SEPARATOR = "/";
|
48 | var UA_NAME_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w]/g;
|
49 | var UA_VALUE_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w\#]/g;
|
50 | var UA_ESCAPE_CHAR = "-";
|
51 |
|
52 |
|
53 | var userAgentMiddleware = __name((options) => (next, context) => async (args) => {
|
54 | var _a, _b;
|
55 | const { request } = args;
|
56 | if (!import_protocol_http.HttpRequest.isInstance(request))
|
57 | return next(args);
|
58 | const { headers } = request;
|
59 | const userAgent = ((_a = context == null ? void 0 : context.userAgent) == null ? void 0 : _a.map(escapeUserAgent)) || [];
|
60 | const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
|
61 | const customUserAgent = ((_b = options == null ? void 0 : options.customUserAgent) == null ? void 0 : _b.map(escapeUserAgent)) || [];
|
62 | const prefix = (0, import_util_endpoints.getUserAgentPrefix)();
|
63 | const sdkUserAgentValue = (prefix ? [prefix] : []).concat([...defaultUserAgent, ...userAgent, ...customUserAgent]).join(SPACE);
|
64 | const normalUAValue = [
|
65 | ...defaultUserAgent.filter((section) => section.startsWith("aws-sdk-")),
|
66 | ...customUserAgent
|
67 | ].join(SPACE);
|
68 | if (options.runtime !== "browser") {
|
69 | if (normalUAValue) {
|
70 | headers[X_AMZ_USER_AGENT] = headers[X_AMZ_USER_AGENT] ? `${headers[USER_AGENT]} ${normalUAValue}` : normalUAValue;
|
71 | }
|
72 | headers[USER_AGENT] = sdkUserAgentValue;
|
73 | } else {
|
74 | headers[X_AMZ_USER_AGENT] = sdkUserAgentValue;
|
75 | }
|
76 | return next({
|
77 | ...args,
|
78 | request
|
79 | });
|
80 | }, "userAgentMiddleware");
|
81 | var escapeUserAgent = __name((userAgentPair) => {
|
82 | var _a;
|
83 | const name = userAgentPair[0].split(UA_NAME_SEPARATOR).map((part) => part.replace(UA_NAME_ESCAPE_REGEX, UA_ESCAPE_CHAR)).join(UA_NAME_SEPARATOR);
|
84 | const version = (_a = userAgentPair[1]) == null ? void 0 : _a.replace(UA_VALUE_ESCAPE_REGEX, UA_ESCAPE_CHAR);
|
85 | const prefixSeparatorIndex = name.indexOf(UA_NAME_SEPARATOR);
|
86 | const prefix = name.substring(0, prefixSeparatorIndex);
|
87 | let uaName = name.substring(prefixSeparatorIndex + 1);
|
88 | if (prefix === "api") {
|
89 | uaName = uaName.toLowerCase();
|
90 | }
|
91 | return [prefix, uaName, version].filter((item) => item && item.length > 0).reduce((acc, item, index) => {
|
92 | switch (index) {
|
93 | case 0:
|
94 | return item;
|
95 | case 1:
|
96 | return `${acc}/${item}`;
|
97 | default:
|
98 | return `${acc}#${item}`;
|
99 | }
|
100 | }, "");
|
101 | }, "escapeUserAgent");
|
102 | var getUserAgentMiddlewareOptions = {
|
103 | name: "getUserAgentMiddleware",
|
104 | step: "build",
|
105 | priority: "low",
|
106 | tags: ["SET_USER_AGENT", "USER_AGENT"],
|
107 | override: true
|
108 | };
|
109 | var getUserAgentPlugin = __name((config) => ({
|
110 | applyToStack: (clientStack) => {
|
111 | clientStack.add(userAgentMiddleware(config), getUserAgentMiddlewareOptions);
|
112 | }
|
113 | }), "getUserAgentPlugin");
|
114 |
|
115 |
|
116 | 0 && (module.exports = {
|
117 | resolveUserAgentConfig,
|
118 | userAgentMiddleware,
|
119 | getUserAgentMiddlewareOptions,
|
120 | getUserAgentPlugin
|
121 | });
|
122 |
|