Skip to content

Commit

Permalink
Revert "chore: add data plane tracking (#4563)" (#4577)
Browse files Browse the repository at this point in the history
This reverts commit 4278849.
  • Loading branch information
calebpollman authored Oct 24, 2023
1 parent e4a261a commit 60f0c1c
Show file tree
Hide file tree
Showing 6 changed files with 577 additions and 255 deletions.
24 changes: 23 additions & 1 deletion packages/ui/src/helpers/authenticator/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getTotpCodeURL, isValidEmail, trimValues } from '../utils';
import {
configureComponent,
getTotpCodeURL,
isValidEmail,
trimValues,
} from '../utils';

import * as AuthModule from '@aws-amplify/auth';

Expand Down Expand Up @@ -58,6 +63,23 @@ describe('trimValues', () => {
});
});

describe('configureComponent', () => {
it('appends package name and version to Cognito user agent', () => {
const appendToCognitoUserAgentSpy = jest.spyOn(
AuthModule,
'appendToCognitoUserAgent'
);
const packageName = '@aws-amplify/ui-react';
const version = '3.5.10';

configureComponent({ packageName, version });

expect(appendToCognitoUserAgentSpy).toHaveBeenCalledWith(
`${packageName}/${version}`
);
});
});

describe('isValidEmail', () => {
it('should return true for a valid email address', () => {
expect(isValidEmail('test@example.com')).toBe(true);
Expand Down
12 changes: 11 additions & 1 deletion packages/ui/src/helpers/authenticator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { Hub } from '@aws-amplify/core';
// import { appendToCognitoUserAgent } from '@aws-amplify/auth';
import { waitFor } from 'xstate/lib/waitFor.js';

import {
Expand All @@ -14,7 +15,16 @@ import {
} from '../../types';
import { ALLOWED_SPECIAL_CHARACTERS, emailRegex } from './constants';
import { getActorState } from './actor';
import { isFunction } from '../../utils';
import { isFunction, noop as appendToCognitoUserAgent } from '../../utils';

type ConfigureOptions = { packageName: string; version: string };
export const configureComponent = ({
packageName,
version,
}: ConfigureOptions) => {
// "@aws-amplify/ui-react" + "/" + "3.5.10"
appendToCognitoUserAgent(`${packageName}/${version}`);
};

// replaces all characters in a string with '*', except for the first and last char
export const censorAllButFirstAndLast = (value: string): string => {
Expand Down
138 changes: 0 additions & 138 deletions packages/ui/src/utils/setUserAgent/__tests__/setUserAgent.test.ts

This file was deleted.

62 changes: 7 additions & 55 deletions packages/ui/src/utils/setUserAgent/constants.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,24 @@
import {
AuthUserAgentInput,
GeoUserAgentInput,
InAppMessagingUserAgentInput,
StorageUserAgentInput,
setCustomUserAgent,
SetCustomUserAgentInput,
AuthAction,
GeoAction,
InAppMessagingAction,
StorageAction,
Category,
} from '@aws-amplify/core/internals/utils';

// replace type once Category input types are available
export const ACCOUNT_SETTINGS_INPUT_BASE: Omit<
AuthUserAgentInput,
SetCustomUserAgentInput,
'additionalDetails'
> = {
apis: [AuthAction.DeleteUser, AuthAction.UpdatePassword],
category: Category.Auth,
};

export const AUTHENTICATOR_INPUT_BASE: Omit<
AuthUserAgentInput,
'additionalDetails'
> = {
apis: [
AuthAction.SignUp,
AuthAction.ConfirmSignUp,
AuthAction.ResendSignUpCode,
AuthAction.SignIn,
AuthAction.ConfirmSignIn,
AuthAction.FetchUserAttributes,
AuthAction.SignOut,
AuthAction.ResetPassword,
AuthAction.ConfirmResetPassword,
AuthAction.SignInWithRedirect,
],
category: Category.Auth,
};

// replace type once Category input types are available
export const IN_APP_MESSAGING_INPUT_BASE: Omit<
InAppMessagingUserAgentInput,
SetCustomUserAgentInput,
'additionalDetails'
> = {
apis: [InAppMessagingAction.NotifyMessageInteraction],
apis: undefined, // TODO
category: Category.InAppMessaging,
};

export const LOCATION_SEARCH_INPUT_BASE: Omit<
GeoUserAgentInput,
'additionalDetails'
> = {
category: Category.Geo,
apis: [
GeoAction.SearchByText,
GeoAction.SearchForSuggestions,
GeoAction.SearchByPlaceId,
],
};

export const MAP_VIEW_INPUT_BASE: Omit<GeoUserAgentInput, 'additionalDetails'> =
{
category: Category.Geo,
apis: [],
};

export const STORAGE_MANAGER_INPUT_BASE: Omit<
StorageUserAgentInput,
'additionalDetails'
> = {
apis: [StorageAction.UploadData],
category: Category.Storage,
};
74 changes: 18 additions & 56 deletions packages/ui/src/utils/setUserAgent/setUserAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,33 @@ import {

import {
ACCOUNT_SETTINGS_INPUT_BASE,
AUTHENTICATOR_INPUT_BASE,
IN_APP_MESSAGING_INPUT_BASE,
LOCATION_SEARCH_INPUT_BASE,
MAP_VIEW_INPUT_BASE,
STORAGE_MANAGER_INPUT_BASE,
} from './constants';

// public packages only, exclude internal packages e.g. 'react-core', 'ui'
export type PackageName =
type PackageName =
| 'angular'
| 'react'
| 'react-auth'
| 'react-geo'
| 'react-liveness'
| 'react-native'
| 'react-native-auth'
| 'react-notifications'
| 'react-storage'
| 'vue';

export type ComponentName =
type ComponentName =
| 'AccountSettings'
| 'Authenticator'
| 'ChangePassword'
| 'DeleteUser'
| 'FaceLivenessDetector'
| 'InAppMessaging'
| 'FaceLivenessDetector'
| 'LocationSearch'
| 'MapView'
| 'StorageManager'
| 'StorageImage';
| 'MapView';

// semver notation
export type Version = `${string}.${string}.${string}`;
type Version = `${string}.${string}.${string}`;

export interface SetUserAgentOptions {
interface SetUserAgentOptions {
componentName: ComponentName;
packageName: PackageName;
version: Version;
Expand All @@ -60,56 +52,26 @@ export const setUserAgent = ({
packageName,
version,
}: SetUserAgentOptions): (() => void) => {
const packageData: [string, string] = [`ui-${packageName}`, version];

let input: SetCustomUserAgentInput | undefined;

const additionalDetails: SetCustomUserAgentInput['additionalDetails'] = [
[componentName],
[`ui-${packageName}`, version],
];

switch (componentName) {
case 'Authenticator': {
input = {
...AUTHENTICATOR_INPUT_BASE,
additionalDetails: [[componentName], packageData],
};
break;
}
case 'ChangePassword':
case 'DeleteUser': {
input = {
...ACCOUNT_SETTINGS_INPUT_BASE,
additionalDetails: [['AccountSettings'], packageData],
};
case 'AccountSettings': {
// remove cast when Category input types are available
input = ACCOUNT_SETTINGS_INPUT_BASE as SetCustomUserAgentInput;
break;
}
case 'InAppMessaging': {
input = {
...IN_APP_MESSAGING_INPUT_BASE,
additionalDetails: [[componentName], packageData],
};
break;
}
case 'LocationSearch': {
input = {
...LOCATION_SEARCH_INPUT_BASE,
additionalDetails: [[componentName], packageData],
};
break;
}
case 'MapView': {
input = {
...MAP_VIEW_INPUT_BASE,
additionalDetails: [[componentName], packageData],
};
break;
}
case 'StorageManager': {
input = {
...STORAGE_MANAGER_INPUT_BASE,
additionalDetails: [[componentName], packageData],
};
// remove cast when Category input types are available
input = IN_APP_MESSAGING_INPUT_BASE as SetCustomUserAgentInput;
break;
}
default:
break;
}
return setCustomUserAgent(input);
return setCustomUserAgent({ ...input, additionalDetails });
};
Loading

0 comments on commit 60f0c1c

Please sign in to comment.