Skip to content

Commit

Permalink
chore: Sync console-preview with next/main (#12289)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblanc authored Oct 13, 2023
2 parents a1c533e + 3056fe4 commit 23dc225
Show file tree
Hide file tree
Showing 225 changed files with 6,968 additions and 6,811 deletions.
66 changes: 51 additions & 15 deletions .github/integ-config/integ-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ tests:
# sample_name: owner-custom-field-default
# spec: owner-custom-field-default
# browser: *minimal_browser_list
# - test_name: integ_datastore_auth_v2-owner-based-default
# desc: 'DataStore Auth CLI v2'
# framework: react
# category: datastore
# sample_name: v2/owner-based-default-v2
# spec: owner-based-default
# browser: *minimal_browser_list
- test_name: integ_datastore_auth_v2-owner-based-default
desc: 'DataStore Auth CLI v2'
framework: react
category: datastore
sample_name: v2/owner-based-default-v2
spec: owner-based-default
browser: *minimal_browser_list
# - test_name: integ_datastore_auth_v2-static-user-pool-groups-default
# desc: 'DataStore Auth CLI v2'
# framework: react
Expand Down Expand Up @@ -565,6 +565,42 @@ tests:
# Temp fix:
browser: *minimal_browser_list

- test_name: integ_react_analytics_personalize_auth
desc: 'Test record API for Personalize with authenticated user'
framework: react
category: analytics
sample_name: [personalize-test]
spec: personalize
# Temp fix:
browser: *minimal_browser_list

- test_name: integ_react_analytics_personalize_unauth
desc: 'Test record API for Personalize with guest user'
framework: react
category: analytics
sample_name: [personalize-test]
spec: personalize-unauth
# Temp fix:
browser: *minimal_browser_list

- test_name: integ_react_analytics_kinesis_data_firehose_auth
desc: 'Test record API for KDF with authenticated user'
framework: react
category: analytics
sample_name: [kinesis-firehose-test]
spec: kinesis-firehose
# Temp fix:
browser: *minimal_browser_list

- test_name: integ_react_analytics_kinesis_data_firehose_unauth
desc: 'Test record API for KDF with guest user'
framework: react
category: analytics
sample_name: [kinesis-firehose-test]
spec: kinesis-firehose-unauth
# Temp fix:
browser: *minimal_browser_list

# GEO
# - test_name: integ_react_geo_display_map
# desc: 'Display Map'
Expand Down Expand Up @@ -661,14 +697,14 @@ tests:
# spec: reconnection
# # Firefox doesn't support network state management in cypress
# browser: [chrome]
# - test_name: integ_react_api_reconnect
# desc: 'PubSub - Reconnection for API'
# framework: react
# category: pubsub
# sample_name: [reconnection-api]
# spec: reconnection
# # Firefox doesn't support network state management in cypress
# browser: [chrome]
- test_name: integ_react_api_reconnect
desc: 'PubSub - Reconnection for API'
framework: react
category: pubsub
sample_name: [reconnection-api]
spec: reconnection
# Firefox doesn't support network state management in cypress
browser: [chrome]

# STORAGE
- test_name: integ_react_storage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Cache, BrowserStorageCache } from '@aws-amplify/core';
import { isBrowser } from '@aws-amplify/core/internals/utils';
import { Cache } from '@aws-amplify/core';
import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
import {
resolveCachedSession,
updateCachedSession,
Expand All @@ -11,11 +11,14 @@ import {
jest.mock('@aws-amplify/core');
jest.mock('@aws-amplify/core/internals/utils');

const mockAmplifyUuid = amplifyUuid as jest.Mock;

describe('Analytics service provider Personalize utils: cachedSession', () => {
const sessionIdCacheKey = '_awsct_sid.personalize';
const userIdCacheKey = '_awsct_uid.personalize';
const mockCache = Cache as jest.Mocked<typeof BrowserStorageCache>;
const mockCache = Cache as jest.Mocked<typeof Cache>;
const mockIsBrowser = isBrowser as jest.Mock;
const mockUuid = 'b2bd676e-bc6b-40f4-bd86-1e31a07f7d10';

const mockSession = {
sessionId: 'sessionId0',
Expand All @@ -30,6 +33,7 @@ describe('Analytics service provider Personalize utils: cachedSession', () => {
beforeEach(() => {
mockCache.getItem.mockImplementation(key => mockCachedStorage[key]);
mockIsBrowser.mockReturnValue(false);
mockAmplifyUuid.mockReturnValue(mockUuid);
});

afterEach(() => {
Expand All @@ -38,16 +42,16 @@ describe('Analytics service provider Personalize utils: cachedSession', () => {
mockCache.setItem.mockReset();
});

it('resolve cached session from Cache', () => {
const result = resolveCachedSession('trackingId0');
it('resolve cached session from Cache', async () => {
const result = await resolveCachedSession();
expect(result).toStrictEqual(mockSession);
});

it('create a new session if there is no cache', () => {
mockCache.getItem.mockImplementation(() => undefined);
const result = resolveCachedSession('trackingId0');
it('create a new session if there is no cache', async () => {
mockCache.getItem.mockImplementation(async () => undefined);
const result = await resolveCachedSession();
expect(result.sessionId).not.toBe(mockSession.sessionId);
expect(result.sessionId.length).toBeGreaterThan(0);
expect(result.sessionId).toEqual(mockUuid);
expect(result.userId).toBe(undefined);
});

Expand Down
2 changes: 0 additions & 2 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
],
"dependencies": {
"tslib": "^2.5.0",
"uuid": "^9.0.0",
"@aws-sdk/client-kinesis": "3.398.0",
"@aws-sdk/client-firehose": "3.398.0",
"@aws-sdk/client-personalize-events": "3.398.0",
Expand All @@ -105,7 +104,6 @@
"devDependencies": {
"@aws-amplify/core": "6.0.0",
"@aws-sdk/types": "3.398.0",
"@types/uuid": "^9.0.0",
"typescript": "5.0.2"
},
"jest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { EventBufferConfig } from '../../../utils';
import { KinesisStream } from '../../../types';
import { Credentials } from '@aws-sdk/types';
import { AWSCredentials } from '@aws-amplify/core/internals/utils';

export type KinesisFirehoseBufferEvent = KinesisStream & {
event: Uint8Array;
Expand All @@ -13,7 +13,7 @@ export type KinesisFirehoseBufferEvent = KinesisStream & {

export type KinesisFirehoseEventBufferConfig = EventBufferConfig & {
region: string;
credentials: Credentials;
credentials: AWSCredentials;
identityId?: string;
resendLimit?: number;
userAgentValue?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/src/providers/kinesis/types/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AWSCredentials } from '@aws-amplify/core/internals/utils';
import { EventBufferConfig } from '../../../utils';
import { Credentials } from '@aws-sdk/types';
import { KinesisShard } from '../../../types';

export type KinesisBufferEvent = KinesisShard & {
Expand All @@ -13,7 +13,7 @@ export type KinesisBufferEvent = KinesisShard & {

export type KinesisEventBufferConfig = EventBufferConfig & {
region: string;
credentials: Credentials;
credentials: AWSCredentials;
identityId?: string;
resendLimit?: number;
userAgentValue?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/analytics/src/providers/personalize/apis/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const record = ({
const { region, trackingId, bufferSize, flushSize, flushInterval } =
resolveConfig();
resolveCredentials()
.then(({ credentials, identityId }) => {
.then(async ({ credentials, identityId }) => {
const timestamp = Date.now();
const { sessionId: cachedSessionId, userId: cachedUserId } =
resolveCachedSession(trackingId);
await resolveCachedSession();
if (eventType === IDENTIFY_EVENT_TYPE) {
updateCachedSession(
typeof properties.userId === 'string' ? properties.userId : '',
Expand All @@ -54,7 +54,7 @@ export const record = ({
}

const { sessionId: updatedSessionId, userId: updatedUserId } =
resolveCachedSession(trackingId);
await resolveCachedSession();

const eventBuffer = getEventBuffer({
region,
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/src/providers/personalize/types/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { PersonalizeEvent } from './';
import { EventBufferConfig } from '../../../utils';
import { Credentials } from '@aws-sdk/types';
import { AWSCredentials } from '@aws-amplify/core/internals/utils';

export type PersonalizeBufferEvent = {
trackingId: string;
Expand All @@ -15,7 +15,7 @@ export type PersonalizeBufferEvent = {

export type PersonalizeBufferConfig = EventBufferConfig & {
region: string;
credentials: Credentials;
credentials: AWSCredentials;
identityId?: string;
userAgentValue?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Cache } from '@aws-amplify/core';
import { isBrowser } from '@aws-amplify/core/internals/utils';
import { v4 as uuid } from 'uuid';
import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';

const PERSONALIZE_CACHE_USERID = '_awsct_uid';
const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
Expand All @@ -27,14 +26,16 @@ const setCache = (key: string, value: unknown) => {
});
};

export const resolveCachedSession = (trackingId: string) => {
let sessionId: string | undefined = getCache(PERSONALIZE_CACHE_SESSIONID);
export const resolveCachedSession = async () => {
let sessionId: string | undefined = await getCache(
PERSONALIZE_CACHE_SESSIONID
);
if (!sessionId) {
sessionId = uuid();
sessionId = amplifyUuid();
setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
}

const userId: string | undefined = getCache(PERSONALIZE_CACHE_USERID);
const userId: string | undefined = await getCache(PERSONALIZE_CACHE_USERID);

return {
sessionId,
Expand All @@ -58,7 +59,7 @@ export const updateCachedSession = (
!!currentSessionId && !currentUserId && !!newUserId;

if (isRequireNewSession) {
const newSessionId = uuid();
const newSessionId = amplifyUuid();
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
setCache(PERSONALIZE_CACHE_USERID, newUserId);
} else if (isRequireUpdateSession) {
Expand Down
Loading

0 comments on commit 23dc225

Please sign in to comment.