@aws-sdk/middleware-user-agent 3.901.0 → 3.907.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.
- package/dist-cjs/index.js +170 -203
- package/package.json +2 -2
package/dist-cjs/index.js
CHANGED
|
@@ -1,227 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
20
2
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
getUserAgentMiddlewareOptions: () => getUserAgentMiddlewareOptions,
|
|
26
|
-
getUserAgentPlugin: () => getUserAgentPlugin,
|
|
27
|
-
resolveUserAgentConfig: () => resolveUserAgentConfig,
|
|
28
|
-
userAgentMiddleware: () => userAgentMiddleware
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var core = require('@smithy/core');
|
|
4
|
+
var utilEndpoints = require('@aws-sdk/util-endpoints');
|
|
5
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
6
|
+
var core$1 = require('@aws-sdk/core');
|
|
31
7
|
|
|
32
|
-
|
|
33
|
-
var import_core = require("@smithy/core");
|
|
34
|
-
var DEFAULT_UA_APP_ID = void 0;
|
|
8
|
+
const DEFAULT_UA_APP_ID = undefined;
|
|
35
9
|
function isValidUserAgentAppId(appId) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
10
|
+
if (appId === undefined) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return typeof appId === "string" && appId.length <= 50;
|
|
40
14
|
}
|
|
41
|
-
__name(isValidUserAgentAppId, "isValidUserAgentAppId");
|
|
42
15
|
function resolveUserAgentConfig(input) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
16
|
+
const normalizedAppIdProvider = core.normalizeProvider(input.userAgentAppId ?? DEFAULT_UA_APP_ID);
|
|
17
|
+
const { customUserAgent } = input;
|
|
18
|
+
return Object.assign(input, {
|
|
19
|
+
customUserAgent: typeof customUserAgent === "string" ? [[customUserAgent]] : customUserAgent,
|
|
20
|
+
userAgentAppId: async () => {
|
|
21
|
+
const appId = await normalizedAppIdProvider();
|
|
22
|
+
if (!isValidUserAgentAppId(appId)) {
|
|
23
|
+
const logger = input.logger?.constructor?.name === "NoOpLogger" || !input.logger ? console : input.logger;
|
|
24
|
+
if (typeof appId !== "string") {
|
|
25
|
+
logger?.warn("userAgentAppId must be a string or undefined.");
|
|
26
|
+
}
|
|
27
|
+
else if (appId.length > 50) {
|
|
28
|
+
logger?.warn("The provided userAgentAppId exceeds the maximum length of 50 characters.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return appId;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
60
34
|
}
|
|
61
|
-
__name(resolveUserAgentConfig, "resolveUserAgentConfig");
|
|
62
|
-
|
|
63
|
-
// src/user-agent-middleware.ts
|
|
64
|
-
var import_util_endpoints = require("@aws-sdk/util-endpoints");
|
|
65
|
-
var import_protocol_http = require("@smithy/protocol-http");
|
|
66
35
|
|
|
67
|
-
|
|
68
|
-
var import_core2 = require("@aws-sdk/core");
|
|
69
|
-
var ACCOUNT_ID_ENDPOINT_REGEX = /\d{12}\.ddb/;
|
|
36
|
+
const ACCOUNT_ID_ENDPOINT_REGEX = /\d{12}\.ddb/;
|
|
70
37
|
async function checkFeatures(context, config, args) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
if (typeof config.retryStrategy === "function") {
|
|
76
|
-
const retryStrategy = await config.retryStrategy();
|
|
77
|
-
if (typeof retryStrategy.acquireInitialRetryToken === "function") {
|
|
78
|
-
if (retryStrategy.constructor?.name?.includes("Adaptive")) {
|
|
79
|
-
(0, import_core2.setFeature)(context, "RETRY_MODE_ADAPTIVE", "F");
|
|
80
|
-
} else {
|
|
81
|
-
(0, import_core2.setFeature)(context, "RETRY_MODE_STANDARD", "E");
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
(0, import_core2.setFeature)(context, "RETRY_MODE_LEGACY", "D");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (typeof config.accountIdEndpointMode === "function") {
|
|
88
|
-
const endpointV2 = context.endpointV2;
|
|
89
|
-
if (String(endpointV2?.url?.hostname).match(ACCOUNT_ID_ENDPOINT_REGEX)) {
|
|
90
|
-
(0, import_core2.setFeature)(context, "ACCOUNT_ID_ENDPOINT", "O");
|
|
38
|
+
const request = args.request;
|
|
39
|
+
if (request?.headers?.["smithy-protocol"] === "rpc-v2-cbor") {
|
|
40
|
+
core$1.setFeature(context, "PROTOCOL_RPC_V2_CBOR", "M");
|
|
91
41
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
42
|
+
if (typeof config.retryStrategy === "function") {
|
|
43
|
+
const retryStrategy = await config.retryStrategy();
|
|
44
|
+
if (typeof retryStrategy.acquireInitialRetryToken === "function") {
|
|
45
|
+
if (retryStrategy.constructor?.name?.includes("Adaptive")) {
|
|
46
|
+
core$1.setFeature(context, "RETRY_MODE_ADAPTIVE", "F");
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
core$1.setFeature(context, "RETRY_MODE_STANDARD", "E");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
core$1.setFeature(context, "RETRY_MODE_LEGACY", "D");
|
|
54
|
+
}
|
|
102
55
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
56
|
+
if (typeof config.accountIdEndpointMode === "function") {
|
|
57
|
+
const endpointV2 = context.endpointV2;
|
|
58
|
+
if (String(endpointV2?.url?.hostname).match(ACCOUNT_ID_ENDPOINT_REGEX)) {
|
|
59
|
+
core$1.setFeature(context, "ACCOUNT_ID_ENDPOINT", "O");
|
|
60
|
+
}
|
|
61
|
+
switch (await config.accountIdEndpointMode?.()) {
|
|
62
|
+
case "disabled":
|
|
63
|
+
core$1.setFeature(context, "ACCOUNT_ID_MODE_DISABLED", "Q");
|
|
64
|
+
break;
|
|
65
|
+
case "preferred":
|
|
66
|
+
core$1.setFeature(context, "ACCOUNT_ID_MODE_PREFERRED", "P");
|
|
67
|
+
break;
|
|
68
|
+
case "required":
|
|
69
|
+
core$1.setFeature(context, "ACCOUNT_ID_MODE_REQUIRED", "R");
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
109
72
|
}
|
|
110
|
-
|
|
111
|
-
|
|
73
|
+
const identity = context.__smithy_context?.selectedHttpAuthScheme?.identity;
|
|
74
|
+
if (identity?.$source) {
|
|
75
|
+
const credentials = identity;
|
|
76
|
+
if (credentials.accountId) {
|
|
77
|
+
core$1.setFeature(context, "RESOLVED_ACCOUNT_ID", "T");
|
|
78
|
+
}
|
|
79
|
+
for (const [key, value] of Object.entries(credentials.$source ?? {})) {
|
|
80
|
+
core$1.setFeature(context, key, value);
|
|
81
|
+
}
|
|
112
82
|
}
|
|
113
|
-
}
|
|
114
83
|
}
|
|
115
|
-
__name(checkFeatures, "checkFeatures");
|
|
116
84
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var UA_ESCAPE_CHAR = "-";
|
|
85
|
+
const USER_AGENT = "user-agent";
|
|
86
|
+
const X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
87
|
+
const SPACE = " ";
|
|
88
|
+
const UA_NAME_SEPARATOR = "/";
|
|
89
|
+
const UA_NAME_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w]/g;
|
|
90
|
+
const UA_VALUE_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w\#]/g;
|
|
91
|
+
const UA_ESCAPE_CHAR = "-";
|
|
125
92
|
|
|
126
|
-
|
|
127
|
-
var BYTE_LIMIT = 1024;
|
|
93
|
+
const BYTE_LIMIT = 1024;
|
|
128
94
|
function encodeFeatures(features) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
95
|
+
let buffer = "";
|
|
96
|
+
for (const key in features) {
|
|
97
|
+
const val = features[key];
|
|
98
|
+
if (buffer.length + val.length + 1 <= BYTE_LIMIT) {
|
|
99
|
+
if (buffer.length) {
|
|
100
|
+
buffer += "," + val;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
buffer += val;
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
139
108
|
}
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
return buffer;
|
|
109
|
+
return buffer;
|
|
143
110
|
}
|
|
144
|
-
__name(encodeFeatures, "encodeFeatures");
|
|
145
111
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
|
|
163
|
-
const appId = await options.userAgentAppId();
|
|
164
|
-
if (appId) {
|
|
165
|
-
defaultUserAgent.push(escapeUserAgent([`app/${appId}`]));
|
|
166
|
-
}
|
|
167
|
-
const prefix = (0, import_util_endpoints.getUserAgentPrefix)();
|
|
168
|
-
const sdkUserAgentValue = (prefix ? [prefix] : []).concat([...defaultUserAgent, ...userAgent, ...customUserAgent]).join(SPACE);
|
|
169
|
-
const normalUAValue = [
|
|
170
|
-
...defaultUserAgent.filter((section) => section.startsWith("aws-sdk-")),
|
|
171
|
-
...customUserAgent
|
|
172
|
-
].join(SPACE);
|
|
173
|
-
if (options.runtime !== "browser") {
|
|
174
|
-
if (normalUAValue) {
|
|
175
|
-
headers[X_AMZ_USER_AGENT] = headers[X_AMZ_USER_AGENT] ? `${headers[USER_AGENT]} ${normalUAValue}` : normalUAValue;
|
|
112
|
+
const userAgentMiddleware = (options) => (next, context) => async (args) => {
|
|
113
|
+
const { request } = args;
|
|
114
|
+
if (!protocolHttp.HttpRequest.isInstance(request)) {
|
|
115
|
+
return next(args);
|
|
116
|
+
}
|
|
117
|
+
const { headers } = request;
|
|
118
|
+
const userAgent = context?.userAgent?.map(escapeUserAgent) || [];
|
|
119
|
+
const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
|
|
120
|
+
await checkFeatures(context, options, args);
|
|
121
|
+
const awsContext = context;
|
|
122
|
+
defaultUserAgent.push(`m/${encodeFeatures(Object.assign({}, context.__smithy_context?.features, awsContext.__aws_sdk_context?.features))}`);
|
|
123
|
+
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
|
|
124
|
+
const appId = await options.userAgentAppId();
|
|
125
|
+
if (appId) {
|
|
126
|
+
defaultUserAgent.push(escapeUserAgent([`app/${appId}`]));
|
|
176
127
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (prefix === "api") {
|
|
193
|
-
uaName = uaName.toLowerCase();
|
|
194
|
-
}
|
|
195
|
-
return [prefix, uaName, version].filter((item) => item && item.length > 0).reduce((acc, item, index) => {
|
|
196
|
-
switch (index) {
|
|
197
|
-
case 0:
|
|
198
|
-
return item;
|
|
199
|
-
case 1:
|
|
200
|
-
return `${acc}/${item}`;
|
|
201
|
-
default:
|
|
202
|
-
return `${acc}#${item}`;
|
|
128
|
+
const prefix = utilEndpoints.getUserAgentPrefix();
|
|
129
|
+
const sdkUserAgentValue = (prefix ? [prefix] : [])
|
|
130
|
+
.concat([...defaultUserAgent, ...userAgent, ...customUserAgent])
|
|
131
|
+
.join(SPACE);
|
|
132
|
+
const normalUAValue = [
|
|
133
|
+
...defaultUserAgent.filter((section) => section.startsWith("aws-sdk-")),
|
|
134
|
+
...customUserAgent,
|
|
135
|
+
].join(SPACE);
|
|
136
|
+
if (options.runtime !== "browser") {
|
|
137
|
+
if (normalUAValue) {
|
|
138
|
+
headers[X_AMZ_USER_AGENT] = headers[X_AMZ_USER_AGENT]
|
|
139
|
+
? `${headers[USER_AGENT]} ${normalUAValue}`
|
|
140
|
+
: normalUAValue;
|
|
141
|
+
}
|
|
142
|
+
headers[USER_AGENT] = sdkUserAgentValue;
|
|
203
143
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
override: true
|
|
144
|
+
else {
|
|
145
|
+
headers[X_AMZ_USER_AGENT] = sdkUserAgentValue;
|
|
146
|
+
}
|
|
147
|
+
return next({
|
|
148
|
+
...args,
|
|
149
|
+
request,
|
|
150
|
+
});
|
|
212
151
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
152
|
+
const escapeUserAgent = (userAgentPair) => {
|
|
153
|
+
const name = userAgentPair[0]
|
|
154
|
+
.split(UA_NAME_SEPARATOR)
|
|
155
|
+
.map((part) => part.replace(UA_NAME_ESCAPE_REGEX, UA_ESCAPE_CHAR))
|
|
156
|
+
.join(UA_NAME_SEPARATOR);
|
|
157
|
+
const version = userAgentPair[1]?.replace(UA_VALUE_ESCAPE_REGEX, UA_ESCAPE_CHAR);
|
|
158
|
+
const prefixSeparatorIndex = name.indexOf(UA_NAME_SEPARATOR);
|
|
159
|
+
const prefix = name.substring(0, prefixSeparatorIndex);
|
|
160
|
+
let uaName = name.substring(prefixSeparatorIndex + 1);
|
|
161
|
+
if (prefix === "api") {
|
|
162
|
+
uaName = uaName.toLowerCase();
|
|
163
|
+
}
|
|
164
|
+
return [prefix, uaName, version]
|
|
165
|
+
.filter((item) => item && item.length > 0)
|
|
166
|
+
.reduce((acc, item, index) => {
|
|
167
|
+
switch (index) {
|
|
168
|
+
case 0:
|
|
169
|
+
return item;
|
|
170
|
+
case 1:
|
|
171
|
+
return `${acc}/${item}`;
|
|
172
|
+
default:
|
|
173
|
+
return `${acc}#${item}`;
|
|
174
|
+
}
|
|
175
|
+
}, "");
|
|
176
|
+
};
|
|
177
|
+
const getUserAgentMiddlewareOptions = {
|
|
178
|
+
name: "getUserAgentMiddleware",
|
|
179
|
+
step: "build",
|
|
180
|
+
priority: "low",
|
|
181
|
+
tags: ["SET_USER_AGENT", "USER_AGENT"],
|
|
182
|
+
override: true,
|
|
183
|
+
};
|
|
184
|
+
const getUserAgentPlugin = (config) => ({
|
|
185
|
+
applyToStack: (clientStack) => {
|
|
186
|
+
clientStack.add(userAgentMiddleware(config), getUserAgentMiddlewareOptions);
|
|
187
|
+
},
|
|
226
188
|
});
|
|
227
189
|
|
|
190
|
+
exports.DEFAULT_UA_APP_ID = DEFAULT_UA_APP_ID;
|
|
191
|
+
exports.getUserAgentMiddlewareOptions = getUserAgentMiddlewareOptions;
|
|
192
|
+
exports.getUserAgentPlugin = getUserAgentPlugin;
|
|
193
|
+
exports.resolveUserAgentConfig = resolveUserAgentConfig;
|
|
194
|
+
exports.userAgentMiddleware = userAgentMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-user-agent",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.907.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline middleware-user-agent",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/core": "3.
|
|
28
|
+
"@aws-sdk/core": "3.907.0",
|
|
29
29
|
"@aws-sdk/types": "3.901.0",
|
|
30
30
|
"@aws-sdk/util-endpoints": "3.901.0",
|
|
31
31
|
"@smithy/core": "^3.14.0",
|