@aws-sdk/middleware-user-agent 3.972.39 → 3.972.41
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 +5 -188
- package/dist-es/index.js +1 -2
- package/dist-types/index.d.ts +2 -2
- package/package.json +3 -21
- package/dist-es/check-features.js +0 -49
- package/dist-es/configurations.js +0 -28
- package/dist-es/constants.js +0 -7
- package/dist-es/encode-features.js +0 -18
- package/dist-es/user-agent-middleware.js +0 -82
- package/dist-types/check-features.d.ts +0 -20
- package/dist-types/configurations.d.ts +0 -44
- package/dist-types/constants.d.ts +0 -7
- package/dist-types/encode-features.d.ts +0 -5
- package/dist-types/ts3.4/check-features.d.ts +0 -20
- package/dist-types/ts3.4/configurations.d.ts +0 -21
- package/dist-types/ts3.4/constants.d.ts +0 -7
- package/dist-types/ts3.4/encode-features.d.ts +0 -2
- package/dist-types/ts3.4/index.d.ts +0 -2
- package/dist-types/ts3.4/user-agent-middleware.d.ts +0 -21
- package/dist-types/user-agent-middleware.d.ts +0 -18
package/dist-cjs/index.js
CHANGED
|
@@ -1,194 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var core = require('@smithy/core');
|
|
4
|
-
var utilEndpoints = require('@aws-sdk/util-endpoints');
|
|
5
|
-
var protocols = require('@smithy/core/protocols');
|
|
6
3
|
var client = require('@aws-sdk/core/client');
|
|
7
|
-
var retry = require('@smithy/core/retry');
|
|
8
4
|
|
|
9
|
-
const DEFAULT_UA_APP_ID = undefined;
|
|
10
|
-
function isValidUserAgentAppId(appId) {
|
|
11
|
-
if (appId === undefined) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
return typeof appId === "string" && appId.length <= 50;
|
|
15
|
-
}
|
|
16
|
-
function resolveUserAgentConfig(input) {
|
|
17
|
-
const normalizedAppIdProvider = core.normalizeProvider(input.userAgentAppId ?? DEFAULT_UA_APP_ID);
|
|
18
|
-
const { customUserAgent } = input;
|
|
19
|
-
return Object.assign(input, {
|
|
20
|
-
customUserAgent: typeof customUserAgent === "string" ? [[customUserAgent]] : customUserAgent,
|
|
21
|
-
userAgentAppId: async () => {
|
|
22
|
-
const appId = await normalizedAppIdProvider();
|
|
23
|
-
if (!isValidUserAgentAppId(appId)) {
|
|
24
|
-
const logger = input.logger?.constructor?.name === "NoOpLogger" || !input.logger ? console : input.logger;
|
|
25
|
-
if (typeof appId !== "string") {
|
|
26
|
-
logger?.warn("userAgentAppId must be a string or undefined.");
|
|
27
|
-
}
|
|
28
|
-
else if (appId.length > 50) {
|
|
29
|
-
logger?.warn("The provided userAgentAppId exceeds the maximum length of 50 characters.");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return appId;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
5
|
|
|
37
|
-
const ACCOUNT_ID_ENDPOINT_REGEX = /\d{12}\.ddb/;
|
|
38
|
-
async function checkFeatures(context, config, args) {
|
|
39
|
-
const request = args.request;
|
|
40
|
-
if (request?.headers?.["smithy-protocol"] === "rpc-v2-cbor") {
|
|
41
|
-
client.setFeature(context, "PROTOCOL_RPC_V2_CBOR", "M");
|
|
42
|
-
}
|
|
43
|
-
if (typeof config.retryStrategy === "function") {
|
|
44
|
-
const retryStrategy = await config.retryStrategy();
|
|
45
|
-
if (typeof retryStrategy.mode === "string") {
|
|
46
|
-
switch (retryStrategy.mode) {
|
|
47
|
-
case retry.RETRY_MODES.ADAPTIVE:
|
|
48
|
-
client.setFeature(context, "RETRY_MODE_ADAPTIVE", "F");
|
|
49
|
-
break;
|
|
50
|
-
case retry.RETRY_MODES.STANDARD:
|
|
51
|
-
client.setFeature(context, "RETRY_MODE_STANDARD", "E");
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (typeof config.accountIdEndpointMode === "function") {
|
|
57
|
-
const endpointV2 = context.endpointV2;
|
|
58
|
-
if (String(endpointV2?.url?.hostname).match(ACCOUNT_ID_ENDPOINT_REGEX)) {
|
|
59
|
-
client.setFeature(context, "ACCOUNT_ID_ENDPOINT", "O");
|
|
60
|
-
}
|
|
61
|
-
switch (await config.accountIdEndpointMode?.()) {
|
|
62
|
-
case "disabled":
|
|
63
|
-
client.setFeature(context, "ACCOUNT_ID_MODE_DISABLED", "Q");
|
|
64
|
-
break;
|
|
65
|
-
case "preferred":
|
|
66
|
-
client.setFeature(context, "ACCOUNT_ID_MODE_PREFERRED", "P");
|
|
67
|
-
break;
|
|
68
|
-
case "required":
|
|
69
|
-
client.setFeature(context, "ACCOUNT_ID_MODE_REQUIRED", "R");
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const identity = context.__smithy_context?.selectedHttpAuthScheme?.identity;
|
|
74
|
-
if (identity?.$source) {
|
|
75
|
-
const credentials = identity;
|
|
76
|
-
if (credentials.accountId) {
|
|
77
|
-
client.setFeature(context, "RESOLVED_ACCOUNT_ID", "T");
|
|
78
|
-
}
|
|
79
|
-
for (const [key, value] of Object.entries(credentials.$source ?? {})) {
|
|
80
|
-
client.setFeature(context, key, value);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
6
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const UA_VALUE_ESCAPE_REGEX = /[^!$%&'*+\-.^_`|~\w#]/g;
|
|
91
|
-
const UA_ESCAPE_CHAR = "-";
|
|
92
|
-
|
|
93
|
-
const BYTE_LIMIT = 1024;
|
|
94
|
-
function encodeFeatures(features) {
|
|
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;
|
|
108
|
-
}
|
|
109
|
-
return buffer;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const userAgentMiddleware = (options) => (next, context) => async (args) => {
|
|
113
|
-
const { request } = args;
|
|
114
|
-
if (!protocols.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}`]));
|
|
127
|
-
}
|
|
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;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
headers[X_AMZ_USER_AGENT] = sdkUserAgentValue;
|
|
146
|
-
}
|
|
147
|
-
return next({
|
|
148
|
-
...args,
|
|
149
|
-
request,
|
|
150
|
-
});
|
|
151
|
-
};
|
|
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
|
-
},
|
|
188
|
-
});
|
|
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;
|
|
7
|
+
exports.DEFAULT_UA_APP_ID = client.DEFAULT_UA_APP_ID;
|
|
8
|
+
exports.getUserAgentMiddlewareOptions = client.getUserAgentMiddlewareOptions;
|
|
9
|
+
exports.getUserAgentPlugin = client.getUserAgentPlugin;
|
|
10
|
+
exports.resolveUserAgentConfig = client.resolveUserAgentConfig;
|
|
11
|
+
exports.userAgentMiddleware = client.userAgentMiddleware;
|
package/dist-es/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./user-agent-middleware";
|
|
1
|
+
export { DEFAULT_UA_APP_ID, resolveUserAgentConfig, userAgentMiddleware, getUserAgentMiddlewareOptions, getUserAgentPlugin, } from "@aws-sdk/core/client";
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { DEFAULT_UA_APP_ID, resolveUserAgentConfig, userAgentMiddleware, getUserAgentMiddlewareOptions, getUserAgentPlugin, } from "@aws-sdk/core/client";
|
|
2
|
+
export type { UserAgentInputConfig, UserAgentResolvedConfig } from "@aws-sdk/core/client";
|
package/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-user-agent",
|
|
3
|
-
"version": "3.972.
|
|
3
|
+
"version": "3.972.41",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline middleware-user-agent",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
8
|
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
9
9
|
"build:types": "tsc -p tsconfig.types.json",
|
|
10
|
-
"
|
|
11
|
-
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
|
|
12
|
-
"test": "yarn g:vitest run",
|
|
13
|
-
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
|
|
14
|
-
"extract:docs": "api-extractor run --local",
|
|
15
|
-
"test:watch": "yarn g:vitest watch",
|
|
16
|
-
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
|
|
10
|
+
"clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo"
|
|
17
11
|
},
|
|
18
12
|
"main": "./dist-cjs/index.js",
|
|
19
13
|
"module": "./dist-es/index.js",
|
|
@@ -25,30 +19,18 @@
|
|
|
25
19
|
},
|
|
26
20
|
"license": "Apache-2.0",
|
|
27
21
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/core": "^3.974.
|
|
29
|
-
"@aws-sdk/types": "^3.973.8",
|
|
30
|
-
"@aws-sdk/util-endpoints": "^3.996.9",
|
|
31
|
-
"@smithy/core": "^3.24.1",
|
|
32
|
-
"@smithy/types": "^4.14.1",
|
|
22
|
+
"@aws-sdk/core": "^3.974.11",
|
|
33
23
|
"tslib": "^2.6.2"
|
|
34
24
|
},
|
|
35
25
|
"devDependencies": {
|
|
36
26
|
"@tsconfig/recommended": "1.0.1",
|
|
37
27
|
"concurrently": "7.0.0",
|
|
38
|
-
"downlevel-dts": "0.10.1",
|
|
39
28
|
"premove": "4.0.0",
|
|
40
29
|
"typescript": "~5.8.3"
|
|
41
30
|
},
|
|
42
31
|
"engines": {
|
|
43
32
|
"node": ">=20.0.0"
|
|
44
33
|
},
|
|
45
|
-
"typesVersions": {
|
|
46
|
-
"<4.5": {
|
|
47
|
-
"dist-types/*": [
|
|
48
|
-
"dist-types/ts3.4/*"
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
34
|
"files": [
|
|
53
35
|
"dist-*/**"
|
|
54
36
|
],
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { setFeature } from "@aws-sdk/core/client";
|
|
2
|
-
import { RETRY_MODES } from "@smithy/core/retry";
|
|
3
|
-
const ACCOUNT_ID_ENDPOINT_REGEX = /\d{12}\.ddb/;
|
|
4
|
-
export async function checkFeatures(context, config, args) {
|
|
5
|
-
const request = args.request;
|
|
6
|
-
if (request?.headers?.["smithy-protocol"] === "rpc-v2-cbor") {
|
|
7
|
-
setFeature(context, "PROTOCOL_RPC_V2_CBOR", "M");
|
|
8
|
-
}
|
|
9
|
-
if (typeof config.retryStrategy === "function") {
|
|
10
|
-
const retryStrategy = await config.retryStrategy();
|
|
11
|
-
if (typeof retryStrategy.mode === "string") {
|
|
12
|
-
switch (retryStrategy.mode) {
|
|
13
|
-
case RETRY_MODES.ADAPTIVE:
|
|
14
|
-
setFeature(context, "RETRY_MODE_ADAPTIVE", "F");
|
|
15
|
-
break;
|
|
16
|
-
case RETRY_MODES.STANDARD:
|
|
17
|
-
setFeature(context, "RETRY_MODE_STANDARD", "E");
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (typeof config.accountIdEndpointMode === "function") {
|
|
23
|
-
const endpointV2 = context.endpointV2;
|
|
24
|
-
if (String(endpointV2?.url?.hostname).match(ACCOUNT_ID_ENDPOINT_REGEX)) {
|
|
25
|
-
setFeature(context, "ACCOUNT_ID_ENDPOINT", "O");
|
|
26
|
-
}
|
|
27
|
-
switch (await config.accountIdEndpointMode?.()) {
|
|
28
|
-
case "disabled":
|
|
29
|
-
setFeature(context, "ACCOUNT_ID_MODE_DISABLED", "Q");
|
|
30
|
-
break;
|
|
31
|
-
case "preferred":
|
|
32
|
-
setFeature(context, "ACCOUNT_ID_MODE_PREFERRED", "P");
|
|
33
|
-
break;
|
|
34
|
-
case "required":
|
|
35
|
-
setFeature(context, "ACCOUNT_ID_MODE_REQUIRED", "R");
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const identity = context.__smithy_context?.selectedHttpAuthScheme?.identity;
|
|
40
|
-
if (identity?.$source) {
|
|
41
|
-
const credentials = identity;
|
|
42
|
-
if (credentials.accountId) {
|
|
43
|
-
setFeature(context, "RESOLVED_ACCOUNT_ID", "T");
|
|
44
|
-
}
|
|
45
|
-
for (const [key, value] of Object.entries(credentials.$source ?? {})) {
|
|
46
|
-
setFeature(context, key, value);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { normalizeProvider } from "@smithy/core";
|
|
2
|
-
export const DEFAULT_UA_APP_ID = undefined;
|
|
3
|
-
function isValidUserAgentAppId(appId) {
|
|
4
|
-
if (appId === undefined) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
return typeof appId === "string" && appId.length <= 50;
|
|
8
|
-
}
|
|
9
|
-
export function resolveUserAgentConfig(input) {
|
|
10
|
-
const normalizedAppIdProvider = normalizeProvider(input.userAgentAppId ?? DEFAULT_UA_APP_ID);
|
|
11
|
-
const { customUserAgent } = input;
|
|
12
|
-
return Object.assign(input, {
|
|
13
|
-
customUserAgent: typeof customUserAgent === "string" ? [[customUserAgent]] : customUserAgent,
|
|
14
|
-
userAgentAppId: async () => {
|
|
15
|
-
const appId = await normalizedAppIdProvider();
|
|
16
|
-
if (!isValidUserAgentAppId(appId)) {
|
|
17
|
-
const logger = input.logger?.constructor?.name === "NoOpLogger" || !input.logger ? console : input.logger;
|
|
18
|
-
if (typeof appId !== "string") {
|
|
19
|
-
logger?.warn("userAgentAppId must be a string or undefined.");
|
|
20
|
-
}
|
|
21
|
-
else if (appId.length > 50) {
|
|
22
|
-
logger?.warn("The provided userAgentAppId exceeds the maximum length of 50 characters.");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return appId;
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
}
|
package/dist-es/constants.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const USER_AGENT = "user-agent";
|
|
2
|
-
export const X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
3
|
-
export const SPACE = " ";
|
|
4
|
-
export const UA_NAME_SEPARATOR = "/";
|
|
5
|
-
export const UA_NAME_ESCAPE_REGEX = /[^!$%&'*+\-.^_`|~\w]/g;
|
|
6
|
-
export const UA_VALUE_ESCAPE_REGEX = /[^!$%&'*+\-.^_`|~\w#]/g;
|
|
7
|
-
export const UA_ESCAPE_CHAR = "-";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const BYTE_LIMIT = 1024;
|
|
2
|
-
export function encodeFeatures(features) {
|
|
3
|
-
let buffer = "";
|
|
4
|
-
for (const key in features) {
|
|
5
|
-
const val = features[key];
|
|
6
|
-
if (buffer.length + val.length + 1 <= BYTE_LIMIT) {
|
|
7
|
-
if (buffer.length) {
|
|
8
|
-
buffer += "," + val;
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
buffer += val;
|
|
12
|
-
}
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
return buffer;
|
|
18
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { getUserAgentPrefix } from "@aws-sdk/util-endpoints";
|
|
2
|
-
import { HttpRequest } from "@smithy/core/protocols";
|
|
3
|
-
import { checkFeatures } from "./check-features";
|
|
4
|
-
import { SPACE, UA_ESCAPE_CHAR, UA_NAME_ESCAPE_REGEX, UA_NAME_SEPARATOR, UA_VALUE_ESCAPE_REGEX, USER_AGENT, X_AMZ_USER_AGENT, } from "./constants";
|
|
5
|
-
import { encodeFeatures } from "./encode-features";
|
|
6
|
-
export const userAgentMiddleware = (options) => (next, context) => async (args) => {
|
|
7
|
-
const { request } = args;
|
|
8
|
-
if (!HttpRequest.isInstance(request)) {
|
|
9
|
-
return next(args);
|
|
10
|
-
}
|
|
11
|
-
const { headers } = request;
|
|
12
|
-
const userAgent = context?.userAgent?.map(escapeUserAgent) || [];
|
|
13
|
-
const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
|
|
14
|
-
await checkFeatures(context, options, args);
|
|
15
|
-
const awsContext = context;
|
|
16
|
-
defaultUserAgent.push(`m/${encodeFeatures(Object.assign({}, context.__smithy_context?.features, awsContext.__aws_sdk_context?.features))}`);
|
|
17
|
-
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
|
|
18
|
-
const appId = await options.userAgentAppId();
|
|
19
|
-
if (appId) {
|
|
20
|
-
defaultUserAgent.push(escapeUserAgent([`app`, `${appId}`]));
|
|
21
|
-
}
|
|
22
|
-
const prefix = getUserAgentPrefix();
|
|
23
|
-
const sdkUserAgentValue = (prefix ? [prefix] : [])
|
|
24
|
-
.concat([...defaultUserAgent, ...userAgent, ...customUserAgent])
|
|
25
|
-
.join(SPACE);
|
|
26
|
-
const normalUAValue = [
|
|
27
|
-
...defaultUserAgent.filter((section) => section.startsWith("aws-sdk-")),
|
|
28
|
-
...customUserAgent,
|
|
29
|
-
].join(SPACE);
|
|
30
|
-
if (options.runtime !== "browser") {
|
|
31
|
-
if (normalUAValue) {
|
|
32
|
-
headers[X_AMZ_USER_AGENT] = headers[X_AMZ_USER_AGENT]
|
|
33
|
-
? `${headers[USER_AGENT]} ${normalUAValue}`
|
|
34
|
-
: normalUAValue;
|
|
35
|
-
}
|
|
36
|
-
headers[USER_AGENT] = sdkUserAgentValue;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
headers[X_AMZ_USER_AGENT] = sdkUserAgentValue;
|
|
40
|
-
}
|
|
41
|
-
return next({
|
|
42
|
-
...args,
|
|
43
|
-
request,
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const escapeUserAgent = (userAgentPair) => {
|
|
47
|
-
const name = userAgentPair[0]
|
|
48
|
-
.split(UA_NAME_SEPARATOR)
|
|
49
|
-
.map((part) => part.replace(UA_NAME_ESCAPE_REGEX, UA_ESCAPE_CHAR))
|
|
50
|
-
.join(UA_NAME_SEPARATOR);
|
|
51
|
-
const version = userAgentPair[1]?.replace(UA_VALUE_ESCAPE_REGEX, UA_ESCAPE_CHAR);
|
|
52
|
-
const prefixSeparatorIndex = name.indexOf(UA_NAME_SEPARATOR);
|
|
53
|
-
const prefix = name.substring(0, prefixSeparatorIndex);
|
|
54
|
-
let uaName = name.substring(prefixSeparatorIndex + 1);
|
|
55
|
-
if (prefix === "api") {
|
|
56
|
-
uaName = uaName.toLowerCase();
|
|
57
|
-
}
|
|
58
|
-
return [prefix, uaName, version]
|
|
59
|
-
.filter((item) => item && item.length > 0)
|
|
60
|
-
.reduce((acc, item, index) => {
|
|
61
|
-
switch (index) {
|
|
62
|
-
case 0:
|
|
63
|
-
return item;
|
|
64
|
-
case 1:
|
|
65
|
-
return `${acc}/${item}`;
|
|
66
|
-
default:
|
|
67
|
-
return `${acc}#${item}`;
|
|
68
|
-
}
|
|
69
|
-
}, "");
|
|
70
|
-
};
|
|
71
|
-
export const getUserAgentMiddlewareOptions = {
|
|
72
|
-
name: "getUserAgentMiddleware",
|
|
73
|
-
step: "build",
|
|
74
|
-
priority: "low",
|
|
75
|
-
tags: ["SET_USER_AGENT", "USER_AGENT"],
|
|
76
|
-
override: true,
|
|
77
|
-
};
|
|
78
|
-
export const getUserAgentPlugin = (config) => ({
|
|
79
|
-
applyToStack: (clientStack) => {
|
|
80
|
-
clientStack.add(userAgentMiddleware(config), getUserAgentMiddlewareOptions);
|
|
81
|
-
},
|
|
82
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AccountIdEndpointMode } from "@aws-sdk/core/account-id-endpoint";
|
|
2
|
-
import type { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
3
|
-
import type { AwsCredentialIdentityProvider, BuildHandlerArguments, Provider } from "@smithy/types";
|
|
4
|
-
/**
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
type PreviouslyResolved = Partial<{
|
|
8
|
-
credentials?: AwsCredentialIdentityProvider;
|
|
9
|
-
accountIdEndpointMode?: Provider<AccountIdEndpointMode>;
|
|
10
|
-
retryStrategy?: Provider<{
|
|
11
|
-
mode?: string;
|
|
12
|
-
}>;
|
|
13
|
-
}>;
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
* Check for features that don't have a middleware activation site but
|
|
17
|
-
* may be detected on the context, client config, or request.
|
|
18
|
-
*/
|
|
19
|
-
export declare function checkFeatures(context: AwsHandlerExecutionContext, config: PreviouslyResolved, args: BuildHandlerArguments<any>): Promise<void>;
|
|
20
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Logger, Provider, UserAgent } from "@smithy/types";
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
*/
|
|
5
|
-
export declare const DEFAULT_UA_APP_ID: undefined;
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface UserAgentInputConfig {
|
|
10
|
-
/**
|
|
11
|
-
* The custom user agent header that would be appended to default one
|
|
12
|
-
*/
|
|
13
|
-
customUserAgent?: string | UserAgent;
|
|
14
|
-
/**
|
|
15
|
-
* The application ID used to identify the application.
|
|
16
|
-
*/
|
|
17
|
-
userAgentAppId?: string | undefined | Provider<string | undefined>;
|
|
18
|
-
}
|
|
19
|
-
interface PreviouslyResolved {
|
|
20
|
-
defaultUserAgentProvider: Provider<UserAgent>;
|
|
21
|
-
runtime: string;
|
|
22
|
-
logger?: Logger;
|
|
23
|
-
}
|
|
24
|
-
export interface UserAgentResolvedConfig {
|
|
25
|
-
/**
|
|
26
|
-
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header.
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
defaultUserAgentProvider: Provider<UserAgent>;
|
|
30
|
-
/**
|
|
31
|
-
* The custom user agent header that would be appended to default one
|
|
32
|
-
*/
|
|
33
|
-
customUserAgent?: UserAgent;
|
|
34
|
-
/**
|
|
35
|
-
* The runtime environment
|
|
36
|
-
*/
|
|
37
|
-
runtime: string;
|
|
38
|
-
/**
|
|
39
|
-
* Resolved value for input config {config.userAgentAppId}
|
|
40
|
-
*/
|
|
41
|
-
userAgentAppId: Provider<string | undefined>;
|
|
42
|
-
}
|
|
43
|
-
export declare function resolveUserAgentConfig<T>(input: T & PreviouslyResolved & UserAgentInputConfig): T & UserAgentResolvedConfig;
|
|
44
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const USER_AGENT = "user-agent";
|
|
2
|
-
export declare const X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
3
|
-
export declare const SPACE = " ";
|
|
4
|
-
export declare const UA_NAME_SEPARATOR = "/";
|
|
5
|
-
export declare const UA_NAME_ESCAPE_REGEX: RegExp;
|
|
6
|
-
export declare const UA_VALUE_ESCAPE_REGEX: RegExp;
|
|
7
|
-
export declare const UA_ESCAPE_CHAR = "-";
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AccountIdEndpointMode } from "@aws-sdk/core/account-id-endpoint";
|
|
2
|
-
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
3
|
-
import {
|
|
4
|
-
AwsCredentialIdentityProvider,
|
|
5
|
-
BuildHandlerArguments,
|
|
6
|
-
Provider,
|
|
7
|
-
} from "@smithy/types";
|
|
8
|
-
type PreviouslyResolved = Partial<{
|
|
9
|
-
credentials?: AwsCredentialIdentityProvider;
|
|
10
|
-
accountIdEndpointMode?: Provider<AccountIdEndpointMode>;
|
|
11
|
-
retryStrategy?: Provider<{
|
|
12
|
-
mode?: string;
|
|
13
|
-
}>;
|
|
14
|
-
}>;
|
|
15
|
-
export declare function checkFeatures(
|
|
16
|
-
context: AwsHandlerExecutionContext,
|
|
17
|
-
config: PreviouslyResolved,
|
|
18
|
-
args: BuildHandlerArguments<any>
|
|
19
|
-
): Promise<void>;
|
|
20
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Logger, Provider, UserAgent } from "@smithy/types";
|
|
2
|
-
export declare const DEFAULT_UA_APP_ID: undefined;
|
|
3
|
-
export interface UserAgentInputConfig {
|
|
4
|
-
customUserAgent?: string | UserAgent;
|
|
5
|
-
userAgentAppId?: string | undefined | Provider<string | undefined>;
|
|
6
|
-
}
|
|
7
|
-
interface PreviouslyResolved {
|
|
8
|
-
defaultUserAgentProvider: Provider<UserAgent>;
|
|
9
|
-
runtime: string;
|
|
10
|
-
logger?: Logger;
|
|
11
|
-
}
|
|
12
|
-
export interface UserAgentResolvedConfig {
|
|
13
|
-
defaultUserAgentProvider: Provider<UserAgent>;
|
|
14
|
-
customUserAgent?: UserAgent;
|
|
15
|
-
runtime: string;
|
|
16
|
-
userAgentAppId: Provider<string | undefined>;
|
|
17
|
-
}
|
|
18
|
-
export declare function resolveUserAgentConfig<T>(
|
|
19
|
-
input: T & PreviouslyResolved & UserAgentInputConfig
|
|
20
|
-
): T & UserAgentResolvedConfig;
|
|
21
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const USER_AGENT = "user-agent";
|
|
2
|
-
export declare const X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
3
|
-
export declare const SPACE = " ";
|
|
4
|
-
export declare const UA_NAME_SEPARATOR = "/";
|
|
5
|
-
export declare const UA_NAME_ESCAPE_REGEX: RegExp;
|
|
6
|
-
export declare const UA_VALUE_ESCAPE_REGEX: RegExp;
|
|
7
|
-
export declare const UA_ESCAPE_CHAR = "-";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
2
|
-
import {
|
|
3
|
-
AbsoluteLocation,
|
|
4
|
-
BuildHandler,
|
|
5
|
-
BuildHandlerOptions,
|
|
6
|
-
HandlerExecutionContext,
|
|
7
|
-
MetadataBearer,
|
|
8
|
-
Pluggable,
|
|
9
|
-
} from "@smithy/types";
|
|
10
|
-
import { UserAgentResolvedConfig } from "./configurations";
|
|
11
|
-
export declare const userAgentMiddleware: (
|
|
12
|
-
options: UserAgentResolvedConfig
|
|
13
|
-
) => <Output extends MetadataBearer>(
|
|
14
|
-
next: BuildHandler<any, any>,
|
|
15
|
-
context: HandlerExecutionContext | AwsHandlerExecutionContext
|
|
16
|
-
) => BuildHandler<any, any>;
|
|
17
|
-
export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions &
|
|
18
|
-
AbsoluteLocation;
|
|
19
|
-
export declare const getUserAgentPlugin: (
|
|
20
|
-
config: UserAgentResolvedConfig
|
|
21
|
-
) => Pluggable<any, any>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
2
|
-
import type { AbsoluteLocation, BuildHandler, BuildHandlerOptions, HandlerExecutionContext, MetadataBearer, Pluggable } from "@smithy/types";
|
|
3
|
-
import type { UserAgentResolvedConfig } from "./configurations";
|
|
4
|
-
/**
|
|
5
|
-
* Build user agent header sections from:
|
|
6
|
-
* 1. runtime-specific default user agent provider;
|
|
7
|
-
* 2. custom user agent from `customUserAgent` client config;
|
|
8
|
-
* 3. handler execution context set by internal SDK components;
|
|
9
|
-
* The built user agent will be set to `x-amz-user-agent` header for ALL the
|
|
10
|
-
* runtimes.
|
|
11
|
-
* Please note that any override to the `user-agent` or `x-amz-user-agent` header
|
|
12
|
-
* in the HTTP request is discouraged. Please use `customUserAgent` client
|
|
13
|
-
* config or middleware setting the `userAgent` context to generate desired user
|
|
14
|
-
* agent.
|
|
15
|
-
*/
|
|
16
|
-
export declare const userAgentMiddleware: (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(next: BuildHandler<any, any>, context: HandlerExecutionContext | AwsHandlerExecutionContext) => BuildHandler<any, any>;
|
|
17
|
-
export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation;
|
|
18
|
-
export declare const getUserAgentPlugin: (config: UserAgentResolvedConfig) => Pluggable<any, any>;
|