Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading