From c03c9a6cac24a17f5b37f99b430aaaa70f58a850 Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 18 Oct 2024 12:33:42 -0400 Subject: [PATCH] fix(util-user-agent-browser): make native interface consistent with browser (#6575) * fix(util-user-agent-browser): make native interface consistent with browser * test: fix unit test --- .../src/index.native.ts | 21 ++++++++++++++++--- packages/util-user-agent-browser/src/index.ts | 5 +---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/util-user-agent-browser/src/index.native.ts b/packages/util-user-agent-browser/src/index.native.ts index aca09d7ce7f33..a8a1ae0ea82e3 100644 --- a/packages/util-user-agent-browser/src/index.native.ts +++ b/packages/util-user-agent-browser/src/index.native.ts @@ -2,15 +2,19 @@ import { Provider, UserAgent } from "@smithy/types"; import { DefaultUserAgentOptions } from "./configurations"; +export interface PreviouslyResolved { + userAgentAppId: Provider; +} + /** * @internal * * Default provider to the user agent in ReactNative. It's a best effort to infer * the device information. It uses bowser library to detect the browser and virsion */ -export const defaultUserAgent = - ({ serviceId, clientVersion }: DefaultUserAgentOptions): Provider => - async () => { +export const createDefaultUserAgentProvider = + ({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config?: PreviouslyResolved) => Promise) => + async (config?: PreviouslyResolved) => { const sections: UserAgent = [ // sdk-metadata ["aws-sdk-js", clientVersion], @@ -30,5 +34,16 @@ export const defaultUserAgent = sections.push([`api/${serviceId}`, clientVersion]); } + const appId = await config?.userAgentAppId?.(); + if (appId) { + sections.push([`app/${appId}`]); + } + return sections; }; + +/** + * @internal + * @deprecated use createDefaultUserAgentProvider + */ +export const defaultUserAgent = createDefaultUserAgentProvider; diff --git a/packages/util-user-agent-browser/src/index.ts b/packages/util-user-agent-browser/src/index.ts index c3d0b23cdd422..8cc1af612b42e 100644 --- a/packages/util-user-agent-browser/src/index.ts +++ b/packages/util-user-agent-browser/src/index.ts @@ -14,7 +14,7 @@ export interface PreviouslyResolved { * the device information. It uses bowser library to detect the browser and version */ export const createDefaultUserAgentProvider = - ({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config: PreviouslyResolved) => Promise) => + ({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config?: PreviouslyResolved) => Promise) => async (config?: PreviouslyResolved) => { const parsedUA = typeof window !== "undefined" && window?.navigator?.userAgent @@ -49,10 +49,7 @@ export const createDefaultUserAgentProvider = }; /** - * * @internal - * * @deprecated use createDefaultUserAgentProvider - * */ export const defaultUserAgent = createDefaultUserAgentProvider;