@aws-sdk/middleware-user-agent 3.662.0 → 3.666.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 +82 -4
- package/dist-es/check-features.js +17 -0
- package/dist-es/configurations.js +22 -0
- package/dist-es/encode-features.js +18 -0
- package/dist-es/user-agent-middleware.js +11 -1
- package/dist-types/check-features.d.ts +16 -0
- package/dist-types/configurations.d.ts +14 -1
- package/dist-types/encode-features.d.ts +5 -0
- package/dist-types/ts3.4/check-features.d.ts +12 -0
- package/dist-types/ts3.4/configurations.d.ts +5 -1
- package/dist-types/ts3.4/encode-features.d.ts +2 -0
- package/dist-types/ts3.4/user-agent-middleware.d.ts +2 -1
- package/dist-types/user-agent-middleware.d.ts +2 -1
- package/package.json +5 -3
package/dist-cjs/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
// src/index.ts
|
|
22
22
|
var src_exports = {};
|
|
23
23
|
__export(src_exports, {
|
|
24
|
+
DEFAULT_UA_APP_ID: () => DEFAULT_UA_APP_ID,
|
|
24
25
|
getUserAgentMiddlewareOptions: () => getUserAgentMiddlewareOptions,
|
|
25
26
|
getUserAgentPlugin: () => getUserAgentPlugin,
|
|
26
27
|
resolveUserAgentConfig: () => resolveUserAgentConfig,
|
|
@@ -29,10 +30,33 @@ __export(src_exports, {
|
|
|
29
30
|
module.exports = __toCommonJS(src_exports);
|
|
30
31
|
|
|
31
32
|
// src/configurations.ts
|
|
33
|
+
var import_core = require("@smithy/core");
|
|
34
|
+
var DEFAULT_UA_APP_ID = void 0;
|
|
35
|
+
function isValidUserAgentAppId(appId) {
|
|
36
|
+
if (appId === void 0) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return typeof appId === "string" && appId.length <= 50;
|
|
40
|
+
}
|
|
41
|
+
__name(isValidUserAgentAppId, "isValidUserAgentAppId");
|
|
32
42
|
function resolveUserAgentConfig(input) {
|
|
43
|
+
const normalizedAppIdProvider = (0, import_core.normalizeProvider)(input.userAgentAppId ?? DEFAULT_UA_APP_ID);
|
|
33
44
|
return {
|
|
34
45
|
...input,
|
|
35
|
-
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent
|
|
46
|
+
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent,
|
|
47
|
+
userAgentAppId: async () => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const appId = await normalizedAppIdProvider();
|
|
50
|
+
if (!isValidUserAgentAppId(appId)) {
|
|
51
|
+
const logger = ((_b = (_a = input.logger) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "NoOpLogger" || !input.logger ? console : input.logger;
|
|
52
|
+
if (typeof appId !== "string") {
|
|
53
|
+
logger == null ? void 0 : logger.warn("userAgentAppId must be a string or undefined.");
|
|
54
|
+
} else if (appId.length > 50) {
|
|
55
|
+
logger == null ? void 0 : logger.warn("The provided userAgentAppId exceeds the maximum length of 50 characters.");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return appId;
|
|
59
|
+
}
|
|
36
60
|
};
|
|
37
61
|
}
|
|
38
62
|
__name(resolveUserAgentConfig, "resolveUserAgentConfig");
|
|
@@ -41,6 +65,27 @@ __name(resolveUserAgentConfig, "resolveUserAgentConfig");
|
|
|
41
65
|
var import_util_endpoints = require("@aws-sdk/util-endpoints");
|
|
42
66
|
var import_protocol_http = require("@smithy/protocol-http");
|
|
43
67
|
|
|
68
|
+
// src/check-features.ts
|
|
69
|
+
var import_core2 = require("@aws-sdk/core");
|
|
70
|
+
async function checkFeatures(context, config, args) {
|
|
71
|
+
var _a;
|
|
72
|
+
const request = args.request;
|
|
73
|
+
if (typeof config.accountIdEndpointMode === "function") {
|
|
74
|
+
switch (await ((_a = config.accountIdEndpointMode) == null ? void 0 : _a.call(config))) {
|
|
75
|
+
case "disabled":
|
|
76
|
+
(0, import_core2.setFeature)(context, "ACCOUNT_ID_MODE_DISABLED", "Q");
|
|
77
|
+
break;
|
|
78
|
+
case "preferred":
|
|
79
|
+
(0, import_core2.setFeature)(context, "ACCOUNT_ID_MODE_PREFERRED", "P");
|
|
80
|
+
break;
|
|
81
|
+
case "required":
|
|
82
|
+
(0, import_core2.setFeature)(context, "ACCOUNT_ID_MODE_REQUIRED", "R");
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
__name(checkFeatures, "checkFeatures");
|
|
88
|
+
|
|
44
89
|
// src/constants.ts
|
|
45
90
|
var USER_AGENT = "user-agent";
|
|
46
91
|
var X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
@@ -50,16 +95,48 @@ var UA_NAME_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w]/g;
|
|
|
50
95
|
var UA_VALUE_ESCAPE_REGEX = /[^\!\$\%\&\'\*\+\-\.\^\_\`\|\~\d\w\#]/g;
|
|
51
96
|
var UA_ESCAPE_CHAR = "-";
|
|
52
97
|
|
|
98
|
+
// src/encode-features.ts
|
|
99
|
+
var BYTE_LIMIT = 1024;
|
|
100
|
+
function encodeFeatures(features) {
|
|
101
|
+
let buffer = "";
|
|
102
|
+
for (const key in features) {
|
|
103
|
+
const val = features[key];
|
|
104
|
+
if (buffer.length + val.length + 1 <= BYTE_LIMIT) {
|
|
105
|
+
if (buffer.length) {
|
|
106
|
+
buffer += "," + val;
|
|
107
|
+
} else {
|
|
108
|
+
buffer += val;
|
|
109
|
+
}
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return buffer;
|
|
115
|
+
}
|
|
116
|
+
__name(encodeFeatures, "encodeFeatures");
|
|
117
|
+
|
|
53
118
|
// src/user-agent-middleware.ts
|
|
54
119
|
var userAgentMiddleware = /* @__PURE__ */ __name((options) => (next, context) => async (args) => {
|
|
55
|
-
var _a, _b;
|
|
120
|
+
var _a, _b, _c, _d;
|
|
56
121
|
const { request } = args;
|
|
57
|
-
if (!import_protocol_http.HttpRequest.isInstance(request))
|
|
122
|
+
if (!import_protocol_http.HttpRequest.isInstance(request)) {
|
|
58
123
|
return next(args);
|
|
124
|
+
}
|
|
59
125
|
const { headers } = request;
|
|
60
126
|
const userAgent = ((_a = context == null ? void 0 : context.userAgent) == null ? void 0 : _a.map(escapeUserAgent)) || [];
|
|
61
127
|
const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent);
|
|
62
|
-
|
|
128
|
+
await checkFeatures(context, options, args);
|
|
129
|
+
const awsContext = context;
|
|
130
|
+
defaultUserAgent.push(
|
|
131
|
+
`m/${encodeFeatures(
|
|
132
|
+
Object.assign({}, (_b = context.__smithy_context) == null ? void 0 : _b.features, (_c = awsContext.__aws_sdk_context) == null ? void 0 : _c.features)
|
|
133
|
+
)}`
|
|
134
|
+
);
|
|
135
|
+
const customUserAgent = ((_d = options == null ? void 0 : options.customUserAgent) == null ? void 0 : _d.map(escapeUserAgent)) || [];
|
|
136
|
+
const appId = await options.userAgentAppId();
|
|
137
|
+
if (appId) {
|
|
138
|
+
defaultUserAgent.push(escapeUserAgent([`app/${appId}`]));
|
|
139
|
+
}
|
|
63
140
|
const prefix = (0, import_util_endpoints.getUserAgentPrefix)();
|
|
64
141
|
const sdkUserAgentValue = (prefix ? [prefix] : []).concat([...defaultUserAgent, ...userAgent, ...customUserAgent]).join(SPACE);
|
|
65
142
|
const normalUAValue = [
|
|
@@ -115,6 +192,7 @@ var getUserAgentPlugin = /* @__PURE__ */ __name((config) => ({
|
|
|
115
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
116
193
|
|
|
117
194
|
0 && (module.exports = {
|
|
195
|
+
DEFAULT_UA_APP_ID,
|
|
118
196
|
resolveUserAgentConfig,
|
|
119
197
|
userAgentMiddleware,
|
|
120
198
|
getUserAgentMiddlewareOptions,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { setFeature } from "@aws-sdk/core";
|
|
2
|
+
export async function checkFeatures(context, config, args) {
|
|
3
|
+
const request = args.request;
|
|
4
|
+
if (typeof config.accountIdEndpointMode === "function") {
|
|
5
|
+
switch (await config.accountIdEndpointMode?.()) {
|
|
6
|
+
case "disabled":
|
|
7
|
+
setFeature(context, "ACCOUNT_ID_MODE_DISABLED", "Q");
|
|
8
|
+
break;
|
|
9
|
+
case "preferred":
|
|
10
|
+
setFeature(context, "ACCOUNT_ID_MODE_PREFERRED", "P");
|
|
11
|
+
break;
|
|
12
|
+
case "required":
|
|
13
|
+
setFeature(context, "ACCOUNT_ID_MODE_REQUIRED", "R");
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,28 @@
|
|
|
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
|
+
}
|
|
1
9
|
export function resolveUserAgentConfig(input) {
|
|
10
|
+
const normalizedAppIdProvider = normalizeProvider(input.userAgentAppId ?? DEFAULT_UA_APP_ID);
|
|
2
11
|
return {
|
|
3
12
|
...input,
|
|
4
13
|
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.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
|
+
},
|
|
5
27
|
};
|
|
6
28
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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,14 +1,24 @@
|
|
|
1
1
|
import { getUserAgentPrefix } from "@aws-sdk/util-endpoints";
|
|
2
2
|
import { HttpRequest } from "@smithy/protocol-http";
|
|
3
|
+
import { checkFeatures } from "./check-features";
|
|
3
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";
|
|
4
6
|
export const userAgentMiddleware = (options) => (next, context) => async (args) => {
|
|
5
7
|
const { request } = args;
|
|
6
|
-
if (!HttpRequest.isInstance(request))
|
|
8
|
+
if (!HttpRequest.isInstance(request)) {
|
|
7
9
|
return next(args);
|
|
10
|
+
}
|
|
8
11
|
const { headers } = request;
|
|
9
12
|
const userAgent = context?.userAgent?.map(escapeUserAgent) || [];
|
|
10
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))}`);
|
|
11
17
|
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
|
|
18
|
+
const appId = await options.userAgentAppId();
|
|
19
|
+
if (appId) {
|
|
20
|
+
defaultUserAgent.push(escapeUserAgent([`app/${appId}`]));
|
|
21
|
+
}
|
|
12
22
|
const prefix = getUserAgentPrefix();
|
|
13
23
|
const sdkUserAgentValue = (prefix ? [prefix] : [])
|
|
14
24
|
.concat([...defaultUserAgent, ...userAgent, ...customUserAgent])
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AccountIdEndpointMode } from "@aws-sdk/core/account-id-endpoint";
|
|
2
|
+
import type { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
3
|
+
import type { BuildHandlerArguments, Provider } from "@smithy/types";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
type PreviouslyResolved = Partial<{
|
|
8
|
+
accountIdEndpointMode?: Provider<AccountIdEndpointMode>;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* Check for features that don't have a middleware activation site but
|
|
13
|
+
* may be detected on the context, client config, or request.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkFeatures(context: AwsHandlerExecutionContext, config: PreviouslyResolved, args: BuildHandlerArguments<any>): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Provider, UserAgent } from "@smithy/types";
|
|
1
|
+
import { Logger, Provider, UserAgent } from "@smithy/types";
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_UA_APP_ID: undefined;
|
|
2
6
|
/**
|
|
3
7
|
* @public
|
|
4
8
|
*/
|
|
@@ -7,10 +11,15 @@ export interface UserAgentInputConfig {
|
|
|
7
11
|
* The custom user agent header that would be appended to default one
|
|
8
12
|
*/
|
|
9
13
|
customUserAgent?: string | UserAgent;
|
|
14
|
+
/**
|
|
15
|
+
* The application ID used to identify the application.
|
|
16
|
+
*/
|
|
17
|
+
userAgentAppId?: string | undefined | Provider<string | undefined>;
|
|
10
18
|
}
|
|
11
19
|
interface PreviouslyResolved {
|
|
12
20
|
defaultUserAgentProvider: Provider<UserAgent>;
|
|
13
21
|
runtime: string;
|
|
22
|
+
logger?: Logger;
|
|
14
23
|
}
|
|
15
24
|
export interface UserAgentResolvedConfig {
|
|
16
25
|
/**
|
|
@@ -26,6 +35,10 @@ export interface UserAgentResolvedConfig {
|
|
|
26
35
|
* The runtime environment
|
|
27
36
|
*/
|
|
28
37
|
runtime: string;
|
|
38
|
+
/**
|
|
39
|
+
* Resolved value for input config {config.userAgentAppId}
|
|
40
|
+
*/
|
|
41
|
+
userAgentAppId: Provider<string | undefined>;
|
|
29
42
|
}
|
|
30
43
|
export declare function resolveUserAgentConfig<T>(input: T & PreviouslyResolved & UserAgentInputConfig): T & UserAgentResolvedConfig;
|
|
31
44
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AccountIdEndpointMode } from "@aws-sdk/core/account-id-endpoint";
|
|
2
|
+
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
3
|
+
import { BuildHandlerArguments, Provider } from "@smithy/types";
|
|
4
|
+
type PreviouslyResolved = Partial<{
|
|
5
|
+
accountIdEndpointMode?: Provider<AccountIdEndpointMode>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function checkFeatures(
|
|
8
|
+
context: AwsHandlerExecutionContext,
|
|
9
|
+
config: PreviouslyResolved,
|
|
10
|
+
args: BuildHandlerArguments<any>
|
|
11
|
+
): Promise<void>;
|
|
12
|
+
export {};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { Provider, UserAgent } from "@smithy/types";
|
|
1
|
+
import { Logger, Provider, UserAgent } from "@smithy/types";
|
|
2
|
+
export declare const DEFAULT_UA_APP_ID: undefined;
|
|
2
3
|
export interface UserAgentInputConfig {
|
|
3
4
|
customUserAgent?: string | UserAgent;
|
|
5
|
+
userAgentAppId?: string | undefined | Provider<string | undefined>;
|
|
4
6
|
}
|
|
5
7
|
interface PreviouslyResolved {
|
|
6
8
|
defaultUserAgentProvider: Provider<UserAgent>;
|
|
7
9
|
runtime: string;
|
|
10
|
+
logger?: Logger;
|
|
8
11
|
}
|
|
9
12
|
export interface UserAgentResolvedConfig {
|
|
10
13
|
defaultUserAgentProvider: Provider<UserAgent>;
|
|
11
14
|
customUserAgent?: UserAgent;
|
|
12
15
|
runtime: string;
|
|
16
|
+
userAgentAppId: Provider<string | undefined>;
|
|
13
17
|
}
|
|
14
18
|
export declare function resolveUserAgentConfig<T>(
|
|
15
19
|
input: T & PreviouslyResolved & UserAgentInputConfig
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
1
2
|
import {
|
|
2
3
|
AbsoluteLocation,
|
|
3
4
|
BuildHandler,
|
|
@@ -11,7 +12,7 @@ export declare const userAgentMiddleware: (
|
|
|
11
12
|
options: UserAgentResolvedConfig
|
|
12
13
|
) => <Output extends MetadataBearer>(
|
|
13
14
|
next: BuildHandler<any, any>,
|
|
14
|
-
context: HandlerExecutionContext
|
|
15
|
+
context: HandlerExecutionContext | AwsHandlerExecutionContext
|
|
15
16
|
) => BuildHandler<any, any>;
|
|
16
17
|
export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions &
|
|
17
18
|
AbsoluteLocation;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AwsHandlerExecutionContext } from "@aws-sdk/types";
|
|
1
2
|
import { AbsoluteLocation, BuildHandler, BuildHandlerOptions, HandlerExecutionContext, MetadataBearer, Pluggable } from "@smithy/types";
|
|
2
3
|
import { UserAgentResolvedConfig } from "./configurations";
|
|
3
4
|
/**
|
|
@@ -12,6 +13,6 @@ import { UserAgentResolvedConfig } from "./configurations";
|
|
|
12
13
|
* config or middleware setting the `userAgent` context to generate desired user
|
|
13
14
|
* agent.
|
|
14
15
|
*/
|
|
15
|
-
export declare const userAgentMiddleware: (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(next: BuildHandler<any, any>, context: HandlerExecutionContext) => BuildHandler<any, any>;
|
|
16
|
+
export declare const userAgentMiddleware: (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(next: BuildHandler<any, any>, context: HandlerExecutionContext | AwsHandlerExecutionContext) => BuildHandler<any, any>;
|
|
16
17
|
export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation;
|
|
17
18
|
export declare const getUserAgentPlugin: (config: UserAgentResolvedConfig) => Pluggable<any, any>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-user-agent",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.666.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",
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@aws-sdk/
|
|
26
|
-
"@aws-sdk/
|
|
25
|
+
"@aws-sdk/core": "3.666.0",
|
|
26
|
+
"@aws-sdk/types": "3.664.0",
|
|
27
|
+
"@aws-sdk/util-endpoints": "3.664.0",
|
|
28
|
+
"@smithy/core": "^2.4.8",
|
|
27
29
|
"@smithy/protocol-http": "^4.1.4",
|
|
28
30
|
"@smithy/types": "^3.5.0",
|
|
29
31
|
"tslib": "^2.6.2"
|