Skip to content

Commit

Permalink
fix(util-user-agent-browser): make native interface consistent with b…
Browse files Browse the repository at this point in the history
…rowser (#6575)

* fix(util-user-agent-browser): make native interface consistent with browser

* test: fix unit test
  • Loading branch information
kuhe authored Oct 18, 2024
1 parent a535403 commit c03c9a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 18 additions & 3 deletions packages/util-user-agent-browser/src/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { Provider, UserAgent } from "@smithy/types";

import { DefaultUserAgentOptions } from "./configurations";

export interface PreviouslyResolved {
userAgentAppId: Provider<string | undefined>;
}

/**
* @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<UserAgent> =>
async () => {
export const createDefaultUserAgentProvider =
({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config?: PreviouslyResolved) => Promise<UserAgent>) =>
async (config?: PreviouslyResolved) => {
const sections: UserAgent = [
// sdk-metadata
["aws-sdk-js", clientVersion],
Expand All @@ -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;
5 changes: 1 addition & 4 deletions packages/util-user-agent-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserAgent>) =>
({ serviceId, clientVersion }: DefaultUserAgentOptions): ((config?: PreviouslyResolved) => Promise<UserAgent>) =>
async (config?: PreviouslyResolved) => {
const parsedUA =
typeof window !== "undefined" && window?.navigator?.userAgent
Expand Down Expand Up @@ -49,10 +49,7 @@ export const createDefaultUserAgentProvider =
};

/**
*
* @internal
*
* @deprecated use createDefaultUserAgentProvider
*
*/
export const defaultUserAgent = createDefaultUserAgentProvider;

0 comments on commit c03c9a6

Please sign in to comment.