From 97562d0e428de931de784b2e16d8d5bf7e473d7b Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 18 Oct 2024 14:59:55 +0000 Subject: [PATCH 1/2] fix(util-user-agent-browser): make native interface consistent with browser --- .../src/index.native.ts | 21 ++++++++++++++++--- packages/util-user-agent-browser/src/index.ts | 3 --- 2 files changed, 18 insertions(+), 6 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..70d7c8d63d09f 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..23da2b52220ac 100644 --- a/packages/util-user-agent-browser/src/index.ts +++ b/packages/util-user-agent-browser/src/index.ts @@ -49,10 +49,7 @@ export const createDefaultUserAgentProvider = }; /** - * * @internal - * * @deprecated use createDefaultUserAgentProvider - * */ export const defaultUserAgent = createDefaultUserAgentProvider; From 61017cb1f172cdcb7d319f32299c24298e23b6a2 Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 18 Oct 2024 15:06:17 +0000 Subject: [PATCH 2/2] test: fix unit test --- packages/util-user-agent-browser/src/index.native.ts | 2 +- packages/util-user-agent-browser/src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/util-user-agent-browser/src/index.native.ts b/packages/util-user-agent-browser/src/index.native.ts index 70d7c8d63d09f..a8a1ae0ea82e3 100644 --- a/packages/util-user-agent-browser/src/index.native.ts +++ b/packages/util-user-agent-browser/src/index.native.ts @@ -13,7 +13,7 @@ export interface PreviouslyResolved { * the device information. It uses bowser library to detect the browser and virsion */ export const createDefaultUserAgentProvider = - ({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config: PreviouslyResolved) => Promise) => + ({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config?: PreviouslyResolved) => Promise) => async (config?: PreviouslyResolved) => { const sections: UserAgent = [ // sdk-metadata diff --git a/packages/util-user-agent-browser/src/index.ts b/packages/util-user-agent-browser/src/index.ts index 23da2b52220ac..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