@aws-sdk/middleware-user-agent
Advanced tools
Comparing version 3.662.0 to 3.664.0
@@ -24,2 +24,3 @@ "use strict"; | ||
__export(src_exports, { | ||
DEFAULT_UA_APP_ID: () => DEFAULT_UA_APP_ID, | ||
getUserAgentMiddlewareOptions: () => getUserAgentMiddlewareOptions, | ||
@@ -33,6 +34,29 @@ getUserAgentPlugin: () => getUserAgentPlugin, | ||
// src/configurations.ts | ||
var import_core = require("@smithy/core"); | ||
var DEFAULT_UA_APP_ID = void 0; | ||
function isValidUserAgentAppId(appId) { | ||
if (appId === void 0) { | ||
return true; | ||
} | ||
return typeof appId === "string" && appId.length <= 50; | ||
} | ||
__name(isValidUserAgentAppId, "isValidUserAgentAppId"); | ||
function resolveUserAgentConfig(input) { | ||
const normalizedAppIdProvider = (0, import_core.normalizeProvider)(input.userAgentAppId ?? DEFAULT_UA_APP_ID); | ||
return { | ||
...input, | ||
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent | ||
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent, | ||
userAgentAppId: async () => { | ||
var _a, _b; | ||
const appId = await normalizedAppIdProvider(); | ||
if (!isValidUserAgentAppId(appId)) { | ||
const logger = ((_b = (_a = input.logger) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "NoOpLogger" || !input.logger ? console : input.logger; | ||
if (typeof appId !== "string") { | ||
logger == null ? void 0 : logger.warn("userAgentAppId must be a string or undefined."); | ||
} else if (appId.length > 50) { | ||
logger == null ? void 0 : logger.warn("The provided userAgentAppId exceeds the maximum length of 50 characters."); | ||
} | ||
} | ||
return appId; | ||
} | ||
}; | ||
@@ -55,12 +79,43 @@ } | ||
// src/encode-features.ts | ||
var BYTE_LIMIT = 1024; | ||
function encodeFeatures(features) { | ||
let buffer = ""; | ||
for (const key in features) { | ||
const val = features[key]; | ||
if (buffer.length + val.length + 1 <= BYTE_LIMIT) { | ||
if (buffer.length) { | ||
buffer += "," + val; | ||
} else { | ||
buffer += val; | ||
} | ||
continue; | ||
} | ||
break; | ||
} | ||
return buffer; | ||
} | ||
__name(encodeFeatures, "encodeFeatures"); | ||
// src/user-agent-middleware.ts | ||
var userAgentMiddleware = /* @__PURE__ */ __name((options) => (next, context) => async (args) => { | ||
var _a, _b; | ||
var _a, _b, _c, _d; | ||
const { request } = args; | ||
if (!import_protocol_http.HttpRequest.isInstance(request)) | ||
if (!import_protocol_http.HttpRequest.isInstance(request)) { | ||
return next(args); | ||
} | ||
const { headers } = request; | ||
const userAgent = ((_a = context == null ? void 0 : context.userAgent) == null ? void 0 : _a.map(escapeUserAgent)) || []; | ||
const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent); | ||
const customUserAgent = ((_b = options == null ? void 0 : options.customUserAgent) == null ? void 0 : _b.map(escapeUserAgent)) || []; | ||
const awsContext = context; | ||
defaultUserAgent.push( | ||
`m/${encodeFeatures( | ||
Object.assign({}, (_b = context.__smithy_context) == null ? void 0 : _b.features, (_c = awsContext.__aws_sdk_context) == null ? void 0 : _c.features) | ||
)}` | ||
); | ||
const customUserAgent = ((_d = options == null ? void 0 : options.customUserAgent) == null ? void 0 : _d.map(escapeUserAgent)) || []; | ||
const appId = await options.userAgentAppId(); | ||
if (appId) { | ||
defaultUserAgent.push(escapeUserAgent([`app/${appId}`])); | ||
} | ||
const prefix = (0, import_util_endpoints.getUserAgentPrefix)(); | ||
@@ -121,2 +176,3 @@ const sdkUserAgentValue = (prefix ? [prefix] : []).concat([...defaultUserAgent, ...userAgent, ...customUserAgent]).join(SPACE); | ||
0 && (module.exports = { | ||
DEFAULT_UA_APP_ID, | ||
resolveUserAgentConfig, | ||
@@ -123,0 +179,0 @@ userAgentMiddleware, |
@@ -0,6 +1,28 @@ | ||
import { normalizeProvider } from "@smithy/core"; | ||
export const DEFAULT_UA_APP_ID = undefined; | ||
function isValidUserAgentAppId(appId) { | ||
if (appId === undefined) { | ||
return true; | ||
} | ||
return typeof appId === "string" && appId.length <= 50; | ||
} | ||
export function resolveUserAgentConfig(input) { | ||
const normalizedAppIdProvider = normalizeProvider(input.userAgentAppId ?? DEFAULT_UA_APP_ID); | ||
return { | ||
...input, | ||
customUserAgent: typeof input.customUserAgent === "string" ? [[input.customUserAgent]] : input.customUserAgent, | ||
userAgentAppId: async () => { | ||
const appId = await normalizedAppIdProvider(); | ||
if (!isValidUserAgentAppId(appId)) { | ||
const logger = input.logger?.constructor?.name === "NoOpLogger" || !input.logger ? console : input.logger; | ||
if (typeof appId !== "string") { | ||
logger?.warn("userAgentAppId must be a string or undefined."); | ||
} | ||
else if (appId.length > 50) { | ||
logger?.warn("The provided userAgentAppId exceeds the maximum length of 50 characters."); | ||
} | ||
} | ||
return appId; | ||
}, | ||
}; | ||
} |
import { getUserAgentPrefix } from "@aws-sdk/util-endpoints"; | ||
import { HttpRequest } from "@smithy/protocol-http"; | ||
import { SPACE, UA_ESCAPE_CHAR, UA_NAME_ESCAPE_REGEX, UA_NAME_SEPARATOR, UA_VALUE_ESCAPE_REGEX, USER_AGENT, X_AMZ_USER_AGENT, } from "./constants"; | ||
import { encodeFeatures } from "./encode-features"; | ||
export const userAgentMiddleware = (options) => (next, context) => async (args) => { | ||
const { request } = args; | ||
if (!HttpRequest.isInstance(request)) | ||
if (!HttpRequest.isInstance(request)) { | ||
return next(args); | ||
} | ||
const { headers } = request; | ||
const userAgent = context?.userAgent?.map(escapeUserAgent) || []; | ||
const defaultUserAgent = (await options.defaultUserAgentProvider()).map(escapeUserAgent); | ||
const awsContext = context; | ||
defaultUserAgent.push(`m/${encodeFeatures(Object.assign({}, context.__smithy_context?.features, awsContext.__aws_sdk_context?.features))}`); | ||
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || []; | ||
const appId = await options.userAgentAppId(); | ||
if (appId) { | ||
defaultUserAgent.push(escapeUserAgent([`app/${appId}`])); | ||
} | ||
const prefix = getUserAgentPrefix(); | ||
@@ -13,0 +21,0 @@ const sdkUserAgentValue = (prefix ? [prefix] : []) |
@@ -1,3 +0,7 @@ | ||
import { Provider, UserAgent } from "@smithy/types"; | ||
import { Logger, Provider, UserAgent } from "@smithy/types"; | ||
/** | ||
* @internal | ||
*/ | ||
export declare const DEFAULT_UA_APP_ID: undefined; | ||
/** | ||
* @public | ||
@@ -10,2 +14,6 @@ */ | ||
customUserAgent?: string | UserAgent; | ||
/** | ||
* The application ID used to identify the application. | ||
*/ | ||
userAgentAppId?: string | undefined | Provider<string | undefined>; | ||
} | ||
@@ -15,2 +23,3 @@ interface PreviouslyResolved { | ||
runtime: string; | ||
logger?: Logger; | ||
} | ||
@@ -31,4 +40,8 @@ export interface UserAgentResolvedConfig { | ||
runtime: string; | ||
/** | ||
* Resolved value for input config {config.userAgentAppId} | ||
*/ | ||
userAgentAppId: Provider<string | undefined>; | ||
} | ||
export declare function resolveUserAgentConfig<T>(input: T & PreviouslyResolved & UserAgentInputConfig): T & UserAgentResolvedConfig; | ||
export {}; |
@@ -1,4 +0,6 @@ | ||
import { Provider, UserAgent } from "@smithy/types"; | ||
import { Logger, Provider, UserAgent } from "@smithy/types"; | ||
export declare const DEFAULT_UA_APP_ID: undefined; | ||
export interface UserAgentInputConfig { | ||
customUserAgent?: string | UserAgent; | ||
userAgentAppId?: string | undefined | Provider<string | undefined>; | ||
} | ||
@@ -8,2 +10,3 @@ interface PreviouslyResolved { | ||
runtime: string; | ||
logger?: Logger; | ||
} | ||
@@ -14,2 +17,3 @@ export interface UserAgentResolvedConfig { | ||
runtime: string; | ||
userAgentAppId: Provider<string | undefined>; | ||
} | ||
@@ -16,0 +20,0 @@ export declare function resolveUserAgentConfig<T>( |
@@ -0,1 +1,2 @@ | ||
import { AwsHandlerExecutionContext } from "@aws-sdk/types"; | ||
import { | ||
@@ -14,3 +15,3 @@ AbsoluteLocation, | ||
next: BuildHandler<any, any>, | ||
context: HandlerExecutionContext | ||
context: HandlerExecutionContext | AwsHandlerExecutionContext | ||
) => BuildHandler<any, any>; | ||
@@ -17,0 +18,0 @@ export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions & |
@@ -0,1 +1,2 @@ | ||
import type { AwsHandlerExecutionContext } from "@aws-sdk/types"; | ||
import { AbsoluteLocation, BuildHandler, BuildHandlerOptions, HandlerExecutionContext, MetadataBearer, Pluggable } from "@smithy/types"; | ||
@@ -15,4 +16,4 @@ import { UserAgentResolvedConfig } from "./configurations"; | ||
*/ | ||
export declare const userAgentMiddleware: (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(next: BuildHandler<any, any>, context: HandlerExecutionContext) => BuildHandler<any, any>; | ||
export declare const userAgentMiddleware: (options: UserAgentResolvedConfig) => <Output extends MetadataBearer>(next: BuildHandler<any, any>, context: HandlerExecutionContext | AwsHandlerExecutionContext) => BuildHandler<any, any>; | ||
export declare const getUserAgentMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation; | ||
export declare const getUserAgentPlugin: (config: UserAgentResolvedConfig) => Pluggable<any, any>; |
{ | ||
"name": "@aws-sdk/middleware-user-agent", | ||
"version": "3.662.0", | ||
"version": "3.664.0", | ||
"scripts": { | ||
@@ -25,4 +25,5 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"dependencies": { | ||
"@aws-sdk/types": "3.662.0", | ||
"@aws-sdk/util-endpoints": "3.662.0", | ||
"@aws-sdk/types": "3.664.0", | ||
"@aws-sdk/util-endpoints": "3.664.0", | ||
"@smithy/core": "^2.4.7", | ||
"@smithy/protocol-http": "^4.1.4", | ||
@@ -29,0 +30,0 @@ "@smithy/types": "^3.5.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30523
19
435
6
+ Added@smithy/core@^2.4.7
+ Added@aws-sdk/types@3.664.0(transitive)
+ Added@aws-sdk/util-endpoints@3.664.0(transitive)
+ Added@smithy/abort-controller@3.1.5(transitive)
+ Added@smithy/core@2.4.8(transitive)
+ Added@smithy/fetch-http-handler@3.2.9(transitive)
+ Added@smithy/is-array-buffer@3.0.0(transitive)
+ Added@smithy/middleware-endpoint@3.1.4(transitive)
+ Added@smithy/middleware-retry@3.0.23(transitive)
+ Added@smithy/middleware-serde@3.0.7(transitive)
+ Added@smithy/middleware-stack@3.0.7(transitive)
+ Added@smithy/node-http-handler@3.2.4(transitive)
+ Added@smithy/querystring-builder@3.0.7(transitive)
+ Added@smithy/querystring-parser@3.0.7(transitive)
+ Added@smithy/service-error-classification@3.0.7(transitive)
+ Added@smithy/smithy-client@3.4.0(transitive)
+ Added@smithy/url-parser@3.0.7(transitive)
+ Added@smithy/util-base64@3.0.0(transitive)
+ Added@smithy/util-body-length-browser@3.0.0(transitive)
+ Added@smithy/util-buffer-from@3.0.0(transitive)
+ Added@smithy/util-hex-encoding@3.0.0(transitive)
+ Added@smithy/util-middleware@3.0.7(transitive)
+ Added@smithy/util-retry@3.0.7(transitive)
+ Added@smithy/util-stream@3.1.9(transitive)
+ Added@smithy/util-uri-escape@3.0.0(transitive)
+ Added@smithy/util-utf8@3.0.0(transitive)
+ Addeduuid@9.0.1(transitive)
- Removed@aws-sdk/types@3.662.0(transitive)
- Removed@aws-sdk/util-endpoints@3.662.0(transitive)
Updated@aws-sdk/types@3.664.0