From fcf5480531ead56f31a476a2a9b65324a9ecf58f Mon Sep 17 00:00:00 2001 From: Caleb Pollman Date: Mon, 20 Dec 2021 09:54:24 -0800 Subject: [PATCH] chore(in-app-messaging): merge in-app-messaging/staging to in-app-messaging/main (#9365) * chore(in-app-message): In app messaging/add unit tests (#9253) * chore: Add unit tests * Add licensing to top of analytics test * Fixed typo * Addressed PR feedback * Remove quiet time test Co-authored-by: Chris Fang * fix(@aws-amplify/datastore): consecutive saves with timestamps (#9298) * chore: preparing release * chore(release): Publish [ci skip] - @aws-amplify/ui-angular@1.0.36 - @aws-amplify/ui-components@1.9.7 - @aws-amplify/ui-react@1.2.27 - @aws-amplify/ui-storybook@2.0.27 - @aws-amplify/ui-vue@1.1.21 - @aws-amplify/ui@2.0.4 - @aws-amplify/analytics@5.1.7 - @aws-amplify/api-graphql@2.2.16 - @aws-amplify/api-rest@2.0.27 - @aws-amplify/api@4.0.27 - @aws-amplify/auth@4.3.17 - aws-amplify-angular@6.0.27 - aws-amplify-react@5.1.10 - aws-amplify-vue@2.1.6 - aws-amplify@4.3.9 - @aws-amplify/cache@4.0.29 - @aws-amplify/core@4.3.9 - @aws-amplify/datastore-storage-adapter@1.2.1 - @aws-amplify/datastore@3.7.1 - @aws-amplify/geo@1.1.9 - @aws-amplify/interactions@4.0.27 - @aws-amplify/predictions@4.0.27 - @aws-amplify/pubsub@4.2.3 - @aws-amplify/pushnotification@4.3.6 - @aws-amplify/storage@4.4.10 - @aws-amplify/xr@3.0.27 * chore(release): update version.ts [ci skip] * fix(@aws-amplify/amplify-ui): change private property to false in package.json (#9303) Resolving an issue with installing the library * chore: preparing release * fix(@aws-amplify/amplify-ui): remove private prop from package.json (#9304) * fix(@aws-amplify/amplify-ui): change private property to false in package.json * fix(@aws-amplify/amplify-ui): remove private property from package.json Co-authored-by: Francisco Rodriguez * fix(@aws-amplify/amplify-ui): remove private prop from package.json (#9304) * fix(@aws-amplify/amplify-ui): change private property to false in package.json * fix(@aws-amplify/amplify-ui): remove private property from package.json Co-authored-by: Francisco Rodriguez * chore(release): Publish [ci skip] - @aws-amplify/ui-angular@1.0.37 - @aws-amplify/ui-components@1.9.8 - @aws-amplify/ui-react@1.2.28 - @aws-amplify/ui-storybook@2.0.28 - @aws-amplify/ui-vue@1.1.22 - @aws-amplify/ui@2.0.5 - @aws-amplify/analytics@5.1.8 - @aws-amplify/api-graphql@2.2.17 - @aws-amplify/api-rest@2.0.28 - @aws-amplify/api@4.0.28 - @aws-amplify/auth@4.3.18 - aws-amplify-angular@6.0.28 - aws-amplify-react@5.1.11 - aws-amplify@4.3.10 - @aws-amplify/cache@4.0.30 - @aws-amplify/core@4.3.10 - @aws-amplify/datastore-storage-adapter@1.2.2 - @aws-amplify/datastore@3.7.2 - @aws-amplify/geo@1.1.10 - @aws-amplify/interactions@4.0.28 - @aws-amplify/predictions@4.0.28 - @aws-amplify/pubsub@4.2.4 - @aws-amplify/pushnotification@4.3.7 - @aws-amplify/storage@4.4.11 - @aws-amplify/xr@3.0.28 * chore(release): update version.ts [ci skip] * fix(@aws-amplify/datastore): fixes observeQuery in local-only mode (#9300) * feat(in-app-messaging): Add web support for session cap (#9308) * feat(in-app-messaging): Add web support for session cap * Add undefined check for document Co-authored-by: Chris Fang * fix(@aws-amplify/pushnotification): make eligible variables final (#9301) Co-authored-by: Manoj NB Co-authored-by: Caleb Pollman * fix(@aws-amplify/aws-amplify-react-native): fix dev build for Windows (#9341) * fix(@aws-amplify/api-graphql): Fix webpack build (#9358) * chore: preparing release * chore(release): Publish [ci skip] - @aws-amplify/ui-angular@1.0.38 - @aws-amplify/ui-components@1.9.9 - @aws-amplify/ui-react@1.2.29 - @aws-amplify/ui-storybook@2.0.29 - @aws-amplify/ui-vue@1.1.23 - @aws-amplify/analytics@5.1.9 - @aws-amplify/api-graphql@2.2.18 - @aws-amplify/api-rest@2.0.29 - @aws-amplify/api@4.0.29 - @aws-amplify/auth@4.3.19 - aws-amplify-angular@6.0.29 - aws-amplify-react-native@6.0.2 - aws-amplify-react@5.1.12 - aws-amplify@4.3.11 - @aws-amplify/cache@4.0.31 - @aws-amplify/core@4.3.11 - @aws-amplify/datastore-storage-adapter@1.2.3 - @aws-amplify/datastore@3.7.3 - @aws-amplify/geo@1.1.11 - @aws-amplify/interactions@4.0.29 - @aws-amplify/predictions@4.0.29 - @aws-amplify/pubsub@4.2.5 - @aws-amplify/pushnotification@4.3.8 - @aws-amplify/storage@4.4.12 - @aws-amplify/xr@3.0.29 * chore(release): update version.ts [ci skip] * chore(in-app-messaging): upgrade internal dependency versions and notifications version (#9364) Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com> Co-authored-by: Chris Fang Co-authored-by: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Co-authored-by: aws-amplify-bot Co-authored-by: Nick Arocho <16296496+nickarocho@users.noreply.github.com> Co-authored-by: Nick Arocho Co-authored-by: Francisco Rodriguez Co-authored-by: ManojNB Co-authored-by: Manoj NB Co-authored-by: David McAfee Co-authored-by: Katie Goines --- packages/amplify-ui-angular/CHANGELOG.md | 12 + packages/amplify-ui-angular/package.json | 4 +- packages/amplify-ui-components/CHANGELOG.md | 12 + packages/amplify-ui-components/package.json | 4 +- packages/amplify-ui-react/CHANGELOG.md | 12 + packages/amplify-ui-react/package.json | 4 +- packages/amplify-ui-storybook/CHANGELOG.md | 12 + packages/amplify-ui-storybook/package.json | 4 +- packages/amplify-ui-vue/CHANGELOG.md | 12 + packages/amplify-ui-vue/package.json | 4 +- packages/amplify-ui/CHANGELOG.md | 15 +- packages/amplify-ui/package.json | 3 +- packages/analytics/CHANGELOG.md | 12 + .../__tests__/Analytics-unit-test.ts | 77 ++-- packages/analytics/package.json | 6 +- packages/api-graphql/CHANGELOG.md | 14 + packages/api-graphql/package.json | 14 +- packages/api-rest/CHANGELOG.md | 12 + packages/api-rest/package.json | 4 +- packages/api/CHANGELOG.md | 12 + packages/api/package.json | 6 +- packages/auth/CHANGELOG.md | 12 + packages/auth/package.json | 6 +- packages/aws-amplify-angular/CHANGELOG.md | 12 + packages/aws-amplify-angular/package.json | 6 +- .../aws-amplify-react-native/.eslintrc.js | 2 +- .../aws-amplify-react-native/CHANGELOG.md | 6 + .../aws-amplify-react-native/package.json | 4 +- packages/aws-amplify-react/CHANGELOG.md | 12 + packages/aws-amplify-react/package.json | 4 +- packages/aws-amplify-vue/CHANGELOG.md | 35 +- packages/aws-amplify-vue/package.json | 4 +- packages/aws-amplify/CHANGELOG.md | 12 + packages/aws-amplify/package.json | 30 +- packages/cache/CHANGELOG.md | 12 + packages/cache/package.json | 4 +- packages/core/CHANGELOG.md | 14 + packages/core/package.json | 2 +- packages/core/src/Platform/version.ts | 2 +- .../datastore-storage-adapter/CHANGELOG.md | 12 + .../datastore-storage-adapter/package.json | 6 +- packages/datastore/CHANGELOG.md | 17 + packages/datastore/__tests__/outbox.test.ts | 9 +- packages/datastore/package.json | 10 +- packages/datastore/src/datastore/datastore.ts | 60 +-- packages/datastore/src/sync/outbox.ts | 75 +++- packages/geo/CHANGELOG.md | 12 + packages/geo/package.json | 4 +- packages/interactions/CHANGELOG.md | 12 + packages/interactions/package.json | 4 +- packages/notifications/__mocks__/data.ts | 238 +++++++++++ packages/notifications/__mocks__/mocks.ts | 32 ++ .../InAppMessaging/InAppMessaging.test.ts | 386 ++++++++++++++++++ .../AWSPinpointProvider/index.test.ts | 355 ++++++++++++++++ .../AWSPinpointProvider/utils.test.ts | 341 ++++++++++++++++ .../InAppMessaging/eventListeners.test.ts | 109 +++++ .../__tests__/Notifications.test.ts | 51 +++ packages/notifications/package.json | 8 +- .../SessionTracker/SessionTracker.ts | 69 +++- packages/predictions/CHANGELOG.md | 12 + packages/predictions/package.json | 6 +- packages/pubsub/CHANGELOG.md | 14 + packages/pubsub/package.json | 10 +- packages/pushnotification/CHANGELOG.md | 14 + .../RNPushNotificationMessagingService.java | 4 +- packages/pushnotification/package.json | 4 +- packages/storage/CHANGELOG.md | 12 + packages/storage/package.json | 4 +- packages/xr/CHANGELOG.md | 12 + packages/xr/package.json | 4 +- 70 files changed, 2133 insertions(+), 207 deletions(-) create mode 100644 packages/notifications/__mocks__/data.ts create mode 100644 packages/notifications/__mocks__/mocks.ts create mode 100644 packages/notifications/__tests__/InAppMessaging/InAppMessaging.test.ts create mode 100644 packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/index.test.ts create mode 100644 packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/utils.test.ts create mode 100644 packages/notifications/__tests__/InAppMessaging/eventListeners.test.ts create mode 100644 packages/notifications/__tests__/Notifications.test.ts diff --git a/packages/amplify-ui-angular/CHANGELOG.md b/packages/amplify-ui-angular/CHANGELOG.md index 9d2514a2b6d..aa0894ebea9 100644 --- a/packages/amplify-ui-angular/CHANGELOG.md +++ b/packages/amplify-ui-angular/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.0.38](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-angular@1.0.37...@aws-amplify/ui-angular@1.0.38) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/ui-angular + +## [1.0.37](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-angular@1.0.36...@aws-amplify/ui-angular@1.0.37) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/ui-angular + +## [1.0.36](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-angular@1.0.35...@aws-amplify/ui-angular@1.0.36) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/ui-angular + ## [1.0.35](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-angular@1.0.34...@aws-amplify/ui-angular@1.0.35) (2021-11-18) **Note:** Version bump only for package @aws-amplify/ui-angular diff --git a/packages/amplify-ui-angular/package.json b/packages/amplify-ui-angular/package.json index 9ded868b0dc..82d427183a7 100644 --- a/packages/amplify-ui-angular/package.json +++ b/packages/amplify-ui-angular/package.json @@ -1,7 +1,7 @@ { "name": "@aws-amplify/ui-angular", "private": "true", - "version": "1.0.35", + "version": "1.0.38", "description": "Angular specific wrapper for @aws-amplify/ui-components", "publishConfig": { "access": "public" @@ -32,7 +32,7 @@ "dist/" ], "dependencies": { - "@aws-amplify/ui-components": "1.9.6" + "@aws-amplify/ui-components": "1.9.9" }, "devDependencies": { "@angular/compiler-cli": "^7.2.1", diff --git a/packages/amplify-ui-components/CHANGELOG.md b/packages/amplify-ui-components/CHANGELOG.md index 58e923e52db..7420005615e 100644 --- a/packages/amplify-ui-components/CHANGELOG.md +++ b/packages/amplify-ui-components/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.9.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-components@1.9.8...@aws-amplify/ui-components@1.9.9) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/ui-components + +## [1.9.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-components@1.9.7...@aws-amplify/ui-components@1.9.8) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/ui-components + +## [1.9.7](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-components@1.9.6...@aws-amplify/ui-components@1.9.7) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/ui-components + ## [1.9.6](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-components@1.9.5...@aws-amplify/ui-components@1.9.6) (2021-11-18) **Note:** Version bump only for package @aws-amplify/ui-components diff --git a/packages/amplify-ui-components/package.json b/packages/amplify-ui-components/package.json index 87773ea6fd7..2ff4f91bc32 100644 --- a/packages/amplify-ui-components/package.json +++ b/packages/amplify-ui-components/package.json @@ -1,7 +1,7 @@ { "name": "@aws-amplify/ui-components", "private": "true", - "version": "1.9.6", + "version": "1.9.9", "description": "Core Amplify UI Component Library", "module": "dist/index.mjs", "main": "dist/index.js", @@ -43,7 +43,7 @@ "uuid": "^8.2.0" }, "devDependencies": { - "@aws-amplify/auth": "4.3.16", + "@aws-amplify/auth": "4.3.19", "@stencil/angular-output-target": "^0.0.2", "@stencil/core": "1.15.0", "@stencil/eslint-plugin": "0.2.1", diff --git a/packages/amplify-ui-react/CHANGELOG.md b/packages/amplify-ui-react/CHANGELOG.md index 33595386750..8f1120095e2 100644 --- a/packages/amplify-ui-react/CHANGELOG.md +++ b/packages/amplify-ui-react/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.2.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-react@1.2.28...@aws-amplify/ui-react@1.2.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/ui-react + +## [1.2.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-react@1.2.27...@aws-amplify/ui-react@1.2.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/ui-react + +## [1.2.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-react@1.2.26...@aws-amplify/ui-react@1.2.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/ui-react + ## [1.2.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-react@1.2.25...@aws-amplify/ui-react@1.2.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/ui-react diff --git a/packages/amplify-ui-react/package.json b/packages/amplify-ui-react/package.json index 976d9dd8abc..97f3b1bafe4 100755 --- a/packages/amplify-ui-react/package.json +++ b/packages/amplify-ui-react/package.json @@ -2,7 +2,7 @@ "name": "@aws-amplify/ui-react", "private": "true", "sideEffects": false, - "version": "1.2.26", + "version": "1.2.29", "description": "React specific wrapper for @aws-amplify/ui-components", "publishConfig": { "access": "public" @@ -33,7 +33,7 @@ "typescript": "^3.3.4000" }, "dependencies": { - "@aws-amplify/ui-components": "1.9.6" + "@aws-amplify/ui-components": "1.9.9" }, "peerDependencies": { "react": ">= 16.7.0", diff --git a/packages/amplify-ui-storybook/CHANGELOG.md b/packages/amplify-ui-storybook/CHANGELOG.md index 718b2e5a44b..09178e4fde3 100644 --- a/packages/amplify-ui-storybook/CHANGELOG.md +++ b/packages/amplify-ui-storybook/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-storybook@2.0.28...@aws-amplify/ui-storybook@2.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/ui-storybook + +## [2.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-storybook@2.0.27...@aws-amplify/ui-storybook@2.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/ui-storybook + +## [2.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-storybook@2.0.26...@aws-amplify/ui-storybook@2.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/ui-storybook + ## [2.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-storybook@2.0.25...@aws-amplify/ui-storybook@2.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/ui-storybook diff --git a/packages/amplify-ui-storybook/package.json b/packages/amplify-ui-storybook/package.json index 72118529a0a..61ee0f56ca6 100644 --- a/packages/amplify-ui-storybook/package.json +++ b/packages/amplify-ui-storybook/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/ui-storybook", - "version": "2.0.26", + "version": "2.0.29", "private": true, "dependencies": { "@aws-amplify/ui-react": "0.2.38", @@ -10,7 +10,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", - "aws-amplify": "4.3.8", + "aws-amplify": "4.3.11", "react": "^16.12.0", "react-app-polyfill": "^1.0.6", "react-dom": "^16.12.0", diff --git a/packages/amplify-ui-vue/CHANGELOG.md b/packages/amplify-ui-vue/CHANGELOG.md index 353319b6c22..fb6038f83d6 100644 --- a/packages/amplify-ui-vue/CHANGELOG.md +++ b/packages/amplify-ui-vue/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.23](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-vue@1.1.22...@aws-amplify/ui-vue@1.1.23) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/ui-vue + +## [1.1.22](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-vue@1.1.21...@aws-amplify/ui-vue@1.1.22) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/ui-vue + +## [1.1.21](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-vue@1.1.20...@aws-amplify/ui-vue@1.1.21) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/ui-vue + ## [1.1.20](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui-vue@1.1.19...@aws-amplify/ui-vue@1.1.20) (2021-11-18) **Note:** Version bump only for package @aws-amplify/ui-vue diff --git a/packages/amplify-ui-vue/package.json b/packages/amplify-ui-vue/package.json index d6fb002f80a..29d8e97334e 100644 --- a/packages/amplify-ui-vue/package.json +++ b/packages/amplify-ui-vue/package.json @@ -2,7 +2,7 @@ "name": "@aws-amplify/ui-vue", "private": "true", "sideEffects": true, - "version": "1.1.20", + "version": "1.1.23", "description": "Vue specific wrapper for @aws-amplify/ui-components", "publishConfig": { "access": "public" @@ -18,7 +18,7 @@ "url": "https://github.com/aws-amplify/amplify-js.git" }, "dependencies": { - "@aws-amplify/ui-components": "1.9.6" + "@aws-amplify/ui-components": "1.9.9" }, "devDependencies": { "rimraf": "^3.0.2" diff --git a/packages/amplify-ui/CHANGELOG.md b/packages/amplify-ui/CHANGELOG.md index 2e6fd1bea8a..efa3abf93ae 100644 --- a/packages/amplify-ui/CHANGELOG.md +++ b/packages/amplify-ui/CHANGELOG.md @@ -3,21 +3,24 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. -## [2.0.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.2...@aws-amplify/ui@2.0.3) (2021-05-14) - -**Note:** Version bump only for package @aws-amplify/ui - +## [2.0.5](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.4...@aws-amplify/ui@2.0.5) (2021-12-03) +### Bug Fixes +- **@aws-amplify/amplify-ui:** change private property to false in package.json ([#9303](https://github.com/aws-amplify/amplify-js/issues/9303)) ([454be65](https://github.com/aws-amplify/amplify-js/commit/454be65da7e071540447c13e12fa81032922fd28)) +- **@aws-amplify/amplify-ui:** remove private prop from package.json ([#9304](https://github.com/aws-amplify/amplify-js/issues/9304)) ([66626c2](https://github.com/aws-amplify/amplify-js/commit/66626c2f21df0a27f33309b120de072206ac0001)) - -## [2.0.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.1...@aws-amplify/ui@2.0.2) (2020-04-02) +## [2.0.4](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.3...@aws-amplify/ui@2.0.4) (2021-12-02) **Note:** Version bump only for package @aws-amplify/ui +## [2.0.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.2...@aws-amplify/ui@2.0.3) (2021-05-14) +**Note:** Version bump only for package @aws-amplify/ui +## [2.0.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@2.0.1...@aws-amplify/ui@2.0.2) (2020-04-02) +**Note:** Version bump only for package @aws-amplify/ui ## [2.0.1](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/ui@1.1.6...@aws-amplify/ui@2.0.1) (2020-03-31) diff --git a/packages/amplify-ui/package.json b/packages/amplify-ui/package.json index cb8aba2aa68..b67e1c044d5 100644 --- a/packages/amplify-ui/package.json +++ b/packages/amplify-ui/package.json @@ -1,7 +1,6 @@ { "name": "@aws-amplify/ui", - "private": "true", - "version": "2.0.3", + "version": "2.0.5", "main": "dist/aws-amplify-ui.js", "types": "lib/index.d.ts", "publishConfig": { diff --git a/packages/analytics/CHANGELOG.md b/packages/analytics/CHANGELOG.md index 45e6e07a4d2..eff95712fe9 100644 --- a/packages/analytics/CHANGELOG.md +++ b/packages/analytics/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.1.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/analytics@5.1.8...@aws-amplify/analytics@5.1.9) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/analytics + +## [5.1.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/analytics@5.1.7...@aws-amplify/analytics@5.1.8) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/analytics + +## [5.1.7](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/analytics@5.1.6...@aws-amplify/analytics@5.1.7) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/analytics + ## [5.1.6](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/analytics@5.1.5...@aws-amplify/analytics@5.1.6) (2021-11-18) **Note:** Version bump only for package @aws-amplify/analytics diff --git a/packages/analytics/__tests__/Analytics-unit-test.ts b/packages/analytics/__tests__/Analytics-unit-test.ts index 7239ed3a8d0..4a0d18c45de 100644 --- a/packages/analytics/__tests__/Analytics-unit-test.ts +++ b/packages/analytics/__tests__/Analytics-unit-test.ts @@ -1,34 +1,25 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ jest.mock('../src/vendor/dom-utils', () => { return { delegate: jest.fn(), }; }); -import { - ClientDevice, - Parser, - ConsoleLogger as Logger, - Credentials, -} from '@aws-amplify/core'; -import { AnalyticsOptions, EventAttributes, EventMetrics } from '../src/types'; +import { ClientDevice, Parser, Hub } from '@aws-amplify/core'; import { AnalyticsClass as Analytics } from '../src/Analytics'; import AWSAnalyticsProvider from '../src/Providers/AWSPinpointProvider'; -const options: AnalyticsOptions = { - appId: 'appId', - platform: 'platform', - clientId: 'clientId', - region: 'region', -}; - -const credentials = { - accessKeyId: 'accessKeyId', - sessionToken: 'sessionToken', - secretAccessKey: 'secretAccessKey', - identityId: 'identityId', - authenticated: true, -}; - jest.useFakeTimers(); const record_spyon = jest @@ -37,7 +28,12 @@ const record_spyon = jest return handlers.resolve(); }); +const hubSpy = jest.spyOn(Hub, 'dispatch'); + describe('Analytics test', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); describe('configure test', () => { test('happy case with default parser', () => { const analytics = new Analytics(); @@ -83,6 +79,16 @@ describe('Analytics test', () => { analytics.configure({ mock: 'value' }); await analytics.startSession(); + expect(hubSpy).toBeCalledWith( + 'analytics', + { + event: 'record', + data: { name: '_session.start' }, + message: 'Recording Analytics session start event', + }, + 'Analytics', + expect.anything() + ); expect(record_spyon).toBeCalled(); }); }); @@ -95,6 +101,16 @@ describe('Analytics test', () => { analytics.configure({ mock: 'value' }); await analytics.stopSession(); + expect(hubSpy).toBeCalledWith( + 'analytics', + { + event: 'record', + data: { name: '_session.stop' }, + message: 'Recording Analytics session stop event', + }, + 'Analytics', + expect.anything() + ); expect(record_spyon).toBeCalled(); }); }); @@ -105,12 +121,23 @@ describe('Analytics test', () => { const provider = new AWSAnalyticsProvider(); analytics.addPluggable(provider); analytics.configure({ mock: 'value' }); - - await analytics.record({ + const event = { name: 'event', attributes: 'attributes', metrics: 'metrics', - }); + }; + + await analytics.record(event); + expect(hubSpy).toBeCalledWith( + 'analytics', + { + event: 'record', + data: event, + message: 'Recording Analytics event', + }, + 'Analytics', + expect.anything() + ); expect(record_spyon).toBeCalled(); }); }); diff --git a/packages/analytics/package.json b/packages/analytics/package.json index 3d9219287a0..632389bc1ec 100644 --- a/packages/analytics/package.json +++ b/packages/analytics/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/analytics", - "version": "5.1.6", + "version": "5.1.9", "description": "Analytics category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -43,8 +43,8 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", "@aws-sdk/client-firehose": "3.6.1", "@aws-sdk/client-kinesis": "3.6.1", "@aws-sdk/client-personalize-events": "3.6.1", diff --git a/packages/api-graphql/CHANGELOG.md b/packages/api-graphql/CHANGELOG.md index 0c8cb36cea8..dd76489fd99 100644 --- a/packages/api-graphql/CHANGELOG.md +++ b/packages/api-graphql/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.2.18](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-graphql@2.2.17...@aws-amplify/api-graphql@2.2.18) (2021-12-16) + +### Bug Fixes + +- **@aws-amplify/api-graphql:** Fix webpack build ([#9358](https://github.com/aws-amplify/amplify-js/issues/9358)) ([73587d7](https://github.com/aws-amplify/amplify-js/commit/73587d78fc4feba39d5a527bfe2c790935653fd3)) + +## [2.2.17](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-graphql@2.2.16...@aws-amplify/api-graphql@2.2.17) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/api-graphql + +## [2.2.16](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-graphql@2.2.15...@aws-amplify/api-graphql@2.2.16) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/api-graphql + ## [2.2.15](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-graphql@2.2.14...@aws-amplify/api-graphql@2.2.15) (2021-11-18) **Note:** Version bump only for package @aws-amplify/api-graphql diff --git a/packages/api-graphql/package.json b/packages/api-graphql/package.json index f2d40e2c869..c86f956b9e0 100644 --- a/packages/api-graphql/package.json +++ b/packages/api-graphql/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/api-graphql", - "version": "2.2.15", + "version": "2.2.18", "description": "Api-graphql category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -44,12 +44,12 @@ "@types/zen-observable": "^0.8.0" }, "dependencies": { - "@aws-amplify/api-rest": "2.0.26", - "@aws-amplify/auth": "4.3.16", - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", - "@aws-amplify/pubsub": "4.2.2", - "graphql": "14.5.0", + "@aws-amplify/api-rest": "2.0.29", + "@aws-amplify/auth": "4.3.19", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", + "@aws-amplify/pubsub": "4.2.5", + "graphql": "15.8.0", "uuid": "^3.2.1", "zen-observable-ts": "0.8.19" }, diff --git a/packages/api-rest/CHANGELOG.md b/packages/api-rest/CHANGELOG.md index 92f7240b06f..a71d9183849 100644 --- a/packages/api-rest/CHANGELOG.md +++ b/packages/api-rest/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-rest@2.0.28...@aws-amplify/api-rest@2.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/api-rest + +## [2.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-rest@2.0.27...@aws-amplify/api-rest@2.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/api-rest + +## [2.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-rest@2.0.26...@aws-amplify/api-rest@2.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/api-rest + ## [2.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api-rest@2.0.25...@aws-amplify/api-rest@2.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/api-rest diff --git a/packages/api-rest/package.json b/packages/api-rest/package.json index 1a975230a94..42a88a200dd 100644 --- a/packages/api-rest/package.json +++ b/packages/api-rest/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/api-rest", - "version": "2.0.26", + "version": "2.0.29", "description": "Api-rest category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,7 +41,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8", + "@aws-amplify/core": "4.3.11", "axios": "0.21.4" }, "jest": { diff --git a/packages/api/CHANGELOG.md b/packages/api/CHANGELOG.md index b6918826462..67f15a4dd31 100644 --- a/packages/api/CHANGELOG.md +++ b/packages/api/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api@4.0.28...@aws-amplify/api@4.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/api + +## [4.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api@4.0.27...@aws-amplify/api@4.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/api + +## [4.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api@4.0.26...@aws-amplify/api@4.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/api + ## [4.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/api@4.0.25...@aws-amplify/api@4.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/api diff --git a/packages/api/package.json b/packages/api/package.json index eeb3aeec7bc..0d0cc713d76 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/api", - "version": "4.0.26", + "version": "4.0.29", "description": "Api category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -51,8 +51,8 @@ "@types/zen-observable": "^0.8.0" }, "dependencies": { - "@aws-amplify/api-graphql": "2.2.15", - "@aws-amplify/api-rest": "2.0.26" + "@aws-amplify/api-graphql": "2.2.18", + "@aws-amplify/api-rest": "2.0.29" }, "jest": { "globals": { diff --git a/packages/auth/CHANGELOG.md b/packages/auth/CHANGELOG.md index ba7aeb32686..d4ba1614c5e 100644 --- a/packages/auth/CHANGELOG.md +++ b/packages/auth/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.3.19](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.18...@aws-amplify/auth@4.3.19) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/auth + +## [4.3.18](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.17...@aws-amplify/auth@4.3.18) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/auth + +## [4.3.17](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.16...@aws-amplify/auth@4.3.17) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/auth + ## [4.3.16](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/auth@4.3.15...@aws-amplify/auth@4.3.16) (2021-11-18) **Note:** Version bump only for package @aws-amplify/auth diff --git a/packages/auth/package.json b/packages/auth/package.json index a35823274b6..69ba0502fdb 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/auth", - "version": "4.3.16", + "version": "4.3.19", "description": "Auth category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,8 +41,8 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", "amazon-cognito-identity-js": "5.2.3", "crypto-js": "^4.1.1" }, diff --git a/packages/aws-amplify-angular/CHANGELOG.md b/packages/aws-amplify-angular/CHANGELOG.md index 5448e5875d6..cfb3581f528 100644 --- a/packages/aws-amplify-angular/CHANGELOG.md +++ b/packages/aws-amplify-angular/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [6.0.29](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-angular@6.0.28...aws-amplify-angular@6.0.29) (2021-12-16) + +**Note:** Version bump only for package aws-amplify-angular + +## [6.0.28](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-angular@6.0.27...aws-amplify-angular@6.0.28) (2021-12-03) + +**Note:** Version bump only for package aws-amplify-angular + +## [6.0.27](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-angular@6.0.26...aws-amplify-angular@6.0.27) (2021-12-02) + +**Note:** Version bump only for package aws-amplify-angular + ## [6.0.26](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-angular@6.0.25...aws-amplify-angular@6.0.26) (2021-11-18) **Note:** Version bump only for package aws-amplify-angular diff --git a/packages/aws-amplify-angular/package.json b/packages/aws-amplify-angular/package.json index afc87ddcec7..ba5260a52ae 100644 --- a/packages/aws-amplify-angular/package.json +++ b/packages/aws-amplify-angular/package.json @@ -1,7 +1,7 @@ { "name": "aws-amplify-angular", "private": "true", - "version": "6.0.26", + "version": "6.0.29", "description": "AWS Amplify Angular Components", "main": "bundles/aws-amplify-angular.umd.js", "module": "dist/index.js", @@ -40,7 +40,7 @@ "@types/zen-observable": "^0.5.3", "angular2-template-loader": "^0.6.2", "awesome-typescript-loader": "^4.0.1", - "aws-amplify": "4.3.8", + "aws-amplify": "4.3.11", "babel-core": "^6.26.3", "babel-plugin-lodash": "^3.3.4", "babel-preset-env": "^1.7.0", @@ -69,7 +69,7 @@ "zone.js": "^0.8.26" }, "dependencies": { - "@aws-amplify/ui": "2.0.3", + "@aws-amplify/ui": "2.0.5", "rxjs-compat": "^6.2.1" }, "peerDependencies": { diff --git a/packages/aws-amplify-react-native/.eslintrc.js b/packages/aws-amplify-react-native/.eslintrc.js index fdd7b5b5b43..5ad6a01b872 100644 --- a/packages/aws-amplify-react-native/.eslintrc.js +++ b/packages/aws-amplify-react-native/.eslintrc.js @@ -71,7 +71,7 @@ module.exports = { object: true, }, ], - 'prettier/prettier': ['error'], + 'prettier/prettier': ['error', {'endOfLine': 'auto'}], 'react/jsx-props-no-spreading': 'off', 'react/jsx-wrap-multilines': ['error', { declaration: 'ignore' }], 'react/no-array-index-key': 'off', diff --git a/packages/aws-amplify-react-native/CHANGELOG.md b/packages/aws-amplify-react-native/CHANGELOG.md index 94f284ac12c..c99f9487bb5 100644 --- a/packages/aws-amplify-react-native/CHANGELOG.md +++ b/packages/aws-amplify-react-native/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [6.0.2](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react-native@6.0.1...aws-amplify-react-native@6.0.2) (2021-12-16) + +### Bug Fixes + +- **@aws-amplify/aws-amplify-react-native:** fix dev build for Windows ([#9341](https://github.com/aws-amplify/amplify-js/issues/9341)) ([5c8496f](https://github.com/aws-amplify/amplify-js/commit/5c8496fe8b448f19ebba8911e8f1c3d498b9ade7)) + ## [6.0.1](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react-native@5.0.5...aws-amplify-react-native@6.0.1) (2021-11-12) ### Bug Fixes diff --git a/packages/aws-amplify-react-native/package.json b/packages/aws-amplify-react-native/package.json index 671a6472bf3..6625e968664 100644 --- a/packages/aws-amplify-react-native/package.json +++ b/packages/aws-amplify-react-native/package.json @@ -1,6 +1,6 @@ { "name": "aws-amplify-react-native", - "version": "6.0.1", + "version": "6.0.2", "description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.", "main": "dist/index.js", "scripts": { @@ -16,7 +16,7 @@ "lint": "eslint src" }, "devDependencies": { - "@aws-amplify/notifications": "0.1.0", + "@aws-amplify/notifications": "0.2.0", "@babel/cli": "^7.15.7", "@babel/core": "7.15.5", "@babel/preset-env": "7.15.6", diff --git a/packages/aws-amplify-react/CHANGELOG.md b/packages/aws-amplify-react/CHANGELOG.md index 6e3d596ba42..d9022d94d50 100644 --- a/packages/aws-amplify-react/CHANGELOG.md +++ b/packages/aws-amplify-react/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [5.1.12](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react@5.1.11...aws-amplify-react@5.1.12) (2021-12-16) + +**Note:** Version bump only for package aws-amplify-react + +## [5.1.11](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react@5.1.10...aws-amplify-react@5.1.11) (2021-12-03) + +**Note:** Version bump only for package aws-amplify-react + +## [5.1.10](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react@5.1.9...aws-amplify-react@5.1.10) (2021-12-02) + +**Note:** Version bump only for package aws-amplify-react + ## [5.1.9](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-react@5.1.8...aws-amplify-react@5.1.9) (2021-11-18) **Note:** Version bump only for package aws-amplify-react diff --git a/packages/aws-amplify-react/package.json b/packages/aws-amplify-react/package.json index 8f41b32dc13..ac6b39ce23f 100644 --- a/packages/aws-amplify-react/package.json +++ b/packages/aws-amplify-react/package.json @@ -1,7 +1,7 @@ { "name": "aws-amplify-react", "private": "true", - "version": "5.1.9", + "version": "5.1.12", "description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -39,7 +39,7 @@ "@types/enzyme-adapter-react-16": "^1.0.3", "@types/react": "^16.0.41", "@types/react-dom": "^16.0.11", - "aws-amplify": "4.3.8", + "aws-amplify": "4.3.11", "enzyme": "^3.1.0", "enzyme-adapter-react-16": "^1.0.3", "enzyme-to-json": "^3.2.1", diff --git a/packages/aws-amplify-vue/CHANGELOG.md b/packages/aws-amplify-vue/CHANGELOG.md index 7ebd9e06da5..f0d19aa8618 100644 --- a/packages/aws-amplify-vue/CHANGELOG.md +++ b/packages/aws-amplify-vue/CHANGELOG.md @@ -3,62 +3,39 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. -## [2.1.5](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.4...aws-amplify-vue@2.1.5) (2021-01-29) +## [2.1.6](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.5...aws-amplify-vue@2.1.6) (2021-12-02) **Note:** Version bump only for package aws-amplify-vue +## [2.1.5](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.4...aws-amplify-vue@2.1.5) (2021-01-29) - - +**Note:** Version bump only for package aws-amplify-vue ## [2.1.4](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.3...aws-amplify-vue@2.1.4) (2021-01-07) **Note:** Version bump only for package aws-amplify-vue - - - - ## [2.1.3](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.2...aws-amplify-vue@2.1.3) (2020-10-29) - ### Bug Fixes -* rewrite "forget password" to "forgot password" ([#7009](https://github.com/aws-amplify/amplify-js/issues/7009)) ([fd989e4](https://github.com/aws-amplify/amplify-js/commit/fd989e405a7bc024f780cc7df552ebd489e0be60)), closes [#6921](https://github.com/aws-amplify/amplify-js/issues/6921) - - - - +- rewrite "forget password" to "forgot password" ([#7009](https://github.com/aws-amplify/amplify-js/issues/7009)) ([fd989e4](https://github.com/aws-amplify/amplify-js/commit/fd989e405a7bc024f780cc7df552ebd489e0be60)), closes [#6921](https://github.com/aws-amplify/amplify-js/issues/6921) ## [2.1.2](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.1...aws-amplify-vue@2.1.2) (2020-07-27) - ### Bug Fixes -* **@aws-amplify/interactions:** fix interactions v3 bugs and refactor type ([#6381](https://github.com/aws-amplify/amplify-js/issues/6381)) ([8c6fb4a](https://github.com/aws-amplify/amplify-js/commit/8c6fb4aefa60b36ed33d89c431e743f674119bde)) - - - - +- **@aws-amplify/interactions:** fix interactions v3 bugs and refactor type ([#6381](https://github.com/aws-amplify/amplify-js/issues/6381)) ([8c6fb4a](https://github.com/aws-amplify/amplify-js/commit/8c6fb4aefa60b36ed33d89c431e743f674119bde)) ## [2.1.1](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@2.1.0...aws-amplify-vue@2.1.1) (2020-04-02) **Note:** Version bump only for package aws-amplify-vue - - - - # [2.1.0](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@1.1.4...aws-amplify-vue@2.1.0) (2020-03-31) - ### Features -* **@aws-amplify/storage:** S3 upload progress reporting and multipart upload ([#4558](https://github.com/aws-amplify/amplify-js/issues/4558)) ([64b0bec](https://github.com/aws-amplify/amplify-js/commit/64b0bec958c7d31b1b82208e397b3013a98de625)), closes [#4404](https://github.com/aws-amplify/amplify-js/issues/4404) [#4474](https://github.com/aws-amplify/amplify-js/issues/4474) - - - - +- **@aws-amplify/storage:** S3 upload progress reporting and multipart upload ([#4558](https://github.com/aws-amplify/amplify-js/issues/4558)) ([64b0bec](https://github.com/aws-amplify/amplify-js/commit/64b0bec958c7d31b1b82208e397b3013a98de625)), closes [#4404](https://github.com/aws-amplify/amplify-js/issues/4404) [#4474](https://github.com/aws-amplify/amplify-js/issues/4474) ## [1.1.4](https://github.com/aws-amplify/amplify-js/compare/aws-amplify-vue@1.1.2...aws-amplify-vue@1.1.4) (2020-02-07) diff --git a/packages/aws-amplify-vue/package.json b/packages/aws-amplify-vue/package.json index 0bab2ab7aa8..088c2e173f3 100644 --- a/packages/aws-amplify-vue/package.json +++ b/packages/aws-amplify-vue/package.json @@ -1,7 +1,7 @@ { "name": "aws-amplify-vue", - "private": "true", - "version": "2.1.5", + "private": "true", + "version": "2.1.6", "license": "Apache-2.0", "author": "Amazon Web Services", "scripts": { diff --git a/packages/aws-amplify/CHANGELOG.md b/packages/aws-amplify/CHANGELOG.md index 844b91a266d..556a83089c4 100644 --- a/packages/aws-amplify/CHANGELOG.md +++ b/packages/aws-amplify/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.3.11](https://github.com/aws-amplify/amplify-js/compare/aws-amplify@4.3.10...aws-amplify@4.3.11) (2021-12-16) + +**Note:** Version bump only for package aws-amplify + +## [4.3.10](https://github.com/aws-amplify/amplify-js/compare/aws-amplify@4.3.9...aws-amplify@4.3.10) (2021-12-03) + +**Note:** Version bump only for package aws-amplify + +## [4.3.9](https://github.com/aws-amplify/amplify-js/compare/aws-amplify@4.3.8...aws-amplify@4.3.9) (2021-12-02) + +**Note:** Version bump only for package aws-amplify + ## [4.3.8](https://github.com/aws-amplify/amplify-js/compare/aws-amplify@4.3.7...aws-amplify@4.3.8) (2021-11-18) **Note:** Version bump only for package aws-amplify diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index be96adf0741..bf729bae926 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -1,6 +1,6 @@ { "name": "aws-amplify", - "version": "4.3.8", + "version": "4.3.11", "description": "AWS Amplify is a JavaScript library for Frontend and mobile developers building cloud-enabled applications.", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -34,20 +34,20 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/analytics": "5.1.6", - "@aws-amplify/api": "4.0.26", - "@aws-amplify/auth": "4.3.16", - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", - "@aws-amplify/datastore": "3.7.0", - "@aws-amplify/geo": "1.1.8", - "@aws-amplify/interactions": "4.0.26", - "@aws-amplify/notifications": "0.1.0", - "@aws-amplify/predictions": "4.0.26", - "@aws-amplify/pubsub": "4.2.2", - "@aws-amplify/storage": "4.4.9", - "@aws-amplify/ui": "2.0.3", - "@aws-amplify/xr": "3.0.26" + "@aws-amplify/analytics": "5.1.9", + "@aws-amplify/api": "4.0.29", + "@aws-amplify/auth": "4.3.19", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", + "@aws-amplify/datastore": "3.7.3", + "@aws-amplify/geo": "1.1.11", + "@aws-amplify/interactions": "4.0.29", + "@aws-amplify/notifications": "0.2.0", + "@aws-amplify/predictions": "4.0.29", + "@aws-amplify/pubsub": "4.2.5", + "@aws-amplify/storage": "4.4.12", + "@aws-amplify/ui": "2.0.5", + "@aws-amplify/xr": "3.0.29" }, "jest": { "globals": { diff --git a/packages/cache/CHANGELOG.md b/packages/cache/CHANGELOG.md index 1ac9570c15c..55ab28e6482 100644 --- a/packages/cache/CHANGELOG.md +++ b/packages/cache/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.31](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/cache@4.0.30...@aws-amplify/cache@4.0.31) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/cache + +## [4.0.30](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/cache@4.0.29...@aws-amplify/cache@4.0.30) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/cache + +## [4.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/cache@4.0.28...@aws-amplify/cache@4.0.29) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/cache + ## [4.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/cache@4.0.27...@aws-amplify/cache@4.0.28) (2021-11-18) **Note:** Version bump only for package @aws-amplify/cache diff --git a/packages/cache/package.json b/packages/cache/package.json index 12e1323a813..5868cc27dfd 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/cache", - "version": "4.0.28", + "version": "4.0.31", "description": "Cache category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -44,7 +44,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8" + "@aws-amplify/core": "4.3.11" }, "jest": { "globals": { diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 61867a8cdf3..9cbf173803a 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.3.11](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.10...@aws-amplify/core@4.3.11) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/core + +## [4.3.10](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.9...@aws-amplify/core@4.3.10) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/core + +## [4.3.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.8...@aws-amplify/core@4.3.9) (2021-12-02) + +### Bug Fixes + +- **@aws-amplify/core:** Use undefined for default sequence token with CloudWatch logging ([#9181](https://github.com/aws-amplify/amplify-js/issues/9181)) ([6f217aa](https://github.com/aws-amplify/amplify-js/commit/6f217aa89e672fc4665816756994e6245b19227e)) + ## [4.3.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.7...@aws-amplify/core@4.3.8) (2021-11-18) **Note:** Version bump only for package @aws-amplify/core diff --git a/packages/core/package.json b/packages/core/package.json index 61010eef7f5..433ba72736a 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/core", - "version": "4.3.8", + "version": "4.3.11", "description": "Core category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", diff --git a/packages/core/src/Platform/version.ts b/packages/core/src/Platform/version.ts index 246227f479c..08a0bc7fe45 100644 --- a/packages/core/src/Platform/version.ts +++ b/packages/core/src/Platform/version.ts @@ -1,2 +1,2 @@ // generated by genversion -export const version = '4.3.8'; +export const version = '4.3.11'; diff --git a/packages/datastore-storage-adapter/CHANGELOG.md b/packages/datastore-storage-adapter/CHANGELOG.md index dd21f575a4e..bb624ddb794 100644 --- a/packages/datastore-storage-adapter/CHANGELOG.md +++ b/packages/datastore-storage-adapter/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.2.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore-storage-adapter@1.2.2...@aws-amplify/datastore-storage-adapter@1.2.3) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/datastore-storage-adapter + +## [1.2.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore-storage-adapter@1.2.1...@aws-amplify/datastore-storage-adapter@1.2.2) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/datastore-storage-adapter + +## [1.2.1](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore-storage-adapter@1.2.0...@aws-amplify/datastore-storage-adapter@1.2.1) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/datastore-storage-adapter + # [1.2.0](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore-storage-adapter@1.1.13...@aws-amplify/datastore-storage-adapter@1.2.0) (2021-11-18) ### Features diff --git a/packages/datastore-storage-adapter/package.json b/packages/datastore-storage-adapter/package.json index ddb604dd40b..c48bfa90676 100644 --- a/packages/datastore-storage-adapter/package.json +++ b/packages/datastore-storage-adapter/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/datastore-storage-adapter", - "version": "1.2.0", + "version": "1.2.3", "description": "SQLite storage adapter for Amplify DataStore ", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -34,8 +34,8 @@ }, "homepage": "https://aws-amplify.github.io/", "devDependencies": { - "@aws-amplify/core": "4.3.8", - "@aws-amplify/datastore": "3.7.0", + "@aws-amplify/core": "4.3.11", + "@aws-amplify/datastore": "3.7.3", "react-native-sqlite-storage": "5.0.0" }, "jest": { diff --git a/packages/datastore/CHANGELOG.md b/packages/datastore/CHANGELOG.md index 4be3652f909..938af0976c7 100644 --- a/packages/datastore/CHANGELOG.md +++ b/packages/datastore/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.7.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore@3.7.2...@aws-amplify/datastore@3.7.3) (2021-12-16) + +### Bug Fixes + +- **@aws-amplify/datastore:** fixes observeQuery in local-only mode ([#9300](https://github.com/aws-amplify/amplify-js/issues/9300)) ([b0b57fb](https://github.com/aws-amplify/amplify-js/commit/b0b57fb1ba81d8ad190c4e67efb878ef4c6a2344)) + +## [3.7.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore@3.7.1...@aws-amplify/datastore@3.7.2) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/datastore + +## [3.7.1](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore@3.7.0...@aws-amplify/datastore@3.7.1) (2021-12-02) + +### Bug Fixes + +- **@aws-amplify/datastore:** belongsTo bug ([#9268](https://github.com/aws-amplify/amplify-js/issues/9268)) ([5106639](https://github.com/aws-amplify/amplify-js/commit/510663981a32443b79dd065ca075b664ca8bdff6)) +- **@aws-amplify/datastore:** consecutive saves with timestamps ([#9298](https://github.com/aws-amplify/amplify-js/issues/9298)) ([807dea0](https://github.com/aws-amplify/amplify-js/commit/807dea0acae8389854560ca73b035ecbf220d040)) + # [3.7.0](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/datastore@3.6.1...@aws-amplify/datastore@3.7.0) (2021-11-18) ### Features diff --git a/packages/datastore/__tests__/outbox.test.ts b/packages/datastore/__tests__/outbox.test.ts index 9636553ddf5..d51363bb1e7 100644 --- a/packages/datastore/__tests__/outbox.test.ts +++ b/packages/datastore/__tests__/outbox.test.ts @@ -142,6 +142,8 @@ describe('Outbox tests', () => { _version: (updatedModel1 as any)._version + 1, // increment version like we would expect coming back from AppSync _lastChangedAt: Date.now(), _deleted: false, + createdAt: '2021-11-30T20:51:00.250Z', + updatedAt: '2021-11-30T20:52:00.250Z', }; await Storage.runExclusive(async s => { @@ -166,6 +168,8 @@ describe('Outbox tests', () => { _version: inProgressData._version + 1, // increment version like we would expect coming back from AppSync _lastChangedAt: Date.now(), _deleted: false, + createdAt: '2021-11-30T20:51:00.250Z', + updatedAt: '2021-11-30T20:52:00.250Z', }; await processMutationResponse( @@ -320,9 +324,8 @@ async function instantiateOutbox(): Promise { Storage = DataStore.storage; anyStorage = Storage; - const namespaceResolver = anyStorage.storage.namespaceResolver.bind( - anyStorage - ); + const namespaceResolver = + anyStorage.storage.namespaceResolver.bind(anyStorage); ({ modelInstanceCreator } = anyStorage.storage); diff --git a/packages/datastore/package.json b/packages/datastore/package.json index 78dbda68046..c4af1e56650 100644 --- a/packages/datastore/package.json +++ b/packages/datastore/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/datastore", - "version": "3.7.0", + "version": "3.7.3", "description": "AppSyncLocal support for aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -48,10 +48,10 @@ "fake-indexeddb": "3.0.0" }, "dependencies": { - "@aws-amplify/api": "4.0.26", - "@aws-amplify/auth": "4.3.16", - "@aws-amplify/core": "4.3.8", - "@aws-amplify/pubsub": "4.2.2", + "@aws-amplify/api": "4.0.29", + "@aws-amplify/auth": "4.3.19", + "@aws-amplify/core": "4.3.11", + "@aws-amplify/pubsub": "4.2.5", "amazon-cognito-identity-js": "5.2.3", "idb": "5.0.6", "immer": "9.0.6", diff --git a/packages/datastore/src/datastore/datastore.ts b/packages/datastore/src/datastore/datastore.ts index d50c8b34aa9..00b319b29ca 100644 --- a/packages/datastore/src/datastore/datastore.ts +++ b/packages/datastore/src/datastore/datastore.ts @@ -119,7 +119,7 @@ const isValidModelConstructor = ( return isModelConstructor(obj) && modelNamespaceMap.has(obj); }; -const namespaceResolver: NamespaceResolver = (modelConstructor) => +const namespaceResolver: NamespaceResolver = modelConstructor => modelNamespaceMap.get(modelConstructor); // exporting syncClasses for testing outbox.test.ts @@ -164,7 +164,7 @@ const initSchema = (userSchema: Schema) => { version: userSchema.version, }; - Object.keys(schema.namespaces).forEach((namespace) => { + Object.keys(schema.namespaces).forEach(namespace => { const [relations, keys] = establishRelationAndKeys( schema.namespaces[namespace] ); @@ -174,17 +174,17 @@ const initSchema = (userSchema: Schema) => { const modelAssociations = new Map(); - Object.values(schema.namespaces[namespace].models).forEach((model) => { + Object.values(schema.namespaces[namespace].models).forEach(model => { const connectedModels: string[] = []; Object.values(model.fields) .filter( - (field) => + field => field.association && field.association.connectionType === 'BELONGS_TO' && (field.type).model !== model.name ) - .forEach((field) => + .forEach(field => connectedModels.push((field.type).model) ); @@ -208,12 +208,12 @@ const initSchema = (userSchema: Schema) => { for (const modelName of Array.from(modelAssociations.keys())) { const parents = modelAssociations.get(modelName); - if (parents.every((x) => result.has(x))) { + if (parents.every(x => result.has(x))) { result.set(modelName, parents); } } - Array.from(result.keys()).forEach((x) => modelAssociations.delete(x)); + Array.from(result.keys()).forEach(x => modelAssociations.delete(x)); } schema.namespaces[namespace].modelTopologicalOrdering = result; @@ -222,9 +222,9 @@ const initSchema = (userSchema: Schema) => { return userClasses; }; -const createTypeClasses: (namespace: SchemaNamespace) => TypeConstructorMap = ( - namespace -) => { +const createTypeClasses: ( + namespace: SchemaNamespace +) => TypeConstructorMap = namespace => { const classes: TypeConstructorMap = {}; Object.entries(namespace.models).forEach(([modelName, modelDefinition]) => { @@ -305,12 +305,12 @@ const validateModelFields = if ( !isNullOrUndefined(v) && - (<[]>v).some((e) => + (<[]>v).some(e => isNullOrUndefined(e) ? isRequired : typeof e !== jsType ) ) { const elemTypes = (<[]>v) - .map((e) => (e === null ? 'null' : typeof e)) + .map(e => (e === null ? 'null' : typeof e)) .join(','); throw new Error( @@ -319,7 +319,7 @@ const validateModelFields = } if (validateScalar && !isNullOrUndefined(v)) { - const validationStatus = (<[]>v).map((e) => { + const validationStatus = (<[]>v).map(e => { if (!isNullOrUndefined(e)) { return validateScalar(e); } else if (isNullOrUndefined(e) && !isRequired) { @@ -329,7 +329,7 @@ const validateModelFields = } }); - if (!validationStatus.every((s) => s)) { + if (!validationStatus.every(s => s)) { throw new Error( `All elements in the ${name} array should be of type ${type}, validation failed for one or more elements. ${v}` ); @@ -455,7 +455,7 @@ const createModelClass = ( let patches; const model = produce( source, - (draft) => { + draft => { fn(>(draft as unknown)); draft.id = source.id; const modelValidator = validateModelFields(modelDefinition); @@ -465,7 +465,7 @@ const createModelClass = ( modelValidator(k, parsedValue); }); }, - (p) => (patches = p) + p => (patches = p) ); if (patches.length) { @@ -480,7 +480,7 @@ const createModelClass = ( // to gain access to `modelInstanceCreator` and `clazz` for persisting IDs from server to client. static fromJSON(json: T | T[]) { if (Array.isArray(json)) { - return json.map((init) => this.fromJSON(init)); + return json.map(init => this.fromJSON(init)); } const instance = modelInstanceCreator(clazz, json); @@ -508,7 +508,7 @@ const checkReadOnlyPropertyOnCreate = ( const modelKeys = Object.keys(draft); const { fields } = modelDefinition; - modelKeys.forEach((key) => { + modelKeys.forEach(key => { if (fields[key] && fields[key].isReadOnly) { throw new Error(`${key} is read-only.`); } @@ -519,7 +519,7 @@ const checkReadOnlyPropertyOnUpdate = ( patches: Patch[], modelDefinition: SchemaModel ) => { - const patchArray = patches.map((p) => [p.path[0], p.value]); + const patchArray = patches.map(p => [p.path[0], p.value]); const { fields } = modelDefinition; patchArray.forEach(([key, val]) => { @@ -611,10 +611,10 @@ async function checkSchemaVersion( const modelDefinition = schema.namespaces[DATASTORE].models.Setting; - await storage.runExclusive(async (s) => { + await storage.runExclusive(async s => { const [schemaVersionSetting] = await s.query( Setting, - ModelPredicateCreator.createFromExisting(modelDefinition, (c) => + ModelPredicateCreator.createFromExisting(modelDefinition, c => // @ts-ignore Argument of type '"eq"' is not assignable to parameter of type 'never'. c.key('eq', SETTING_SCHEMA_VERSION) ), @@ -774,7 +774,7 @@ class DataStore { data, }); }, - error: (err) => { + error: err => { logger.warn('Sync error', err); this.initReject(); }, @@ -901,7 +901,7 @@ class DataStore { condition ); - const [savedModel] = await this.storage.runExclusive(async (s) => { + const [savedModel] = await this.storage.runExclusive(async s => { await s.save(model, producedCondition, undefined, patchesTuple); return s.query( @@ -1119,7 +1119,7 @@ class DataStore { ); } - return new Observable>((observer) => { + return new Observable>(observer => { let handle: ZenObservable.Subscription; (async () => { @@ -1150,7 +1150,7 @@ class DataStore { criteria?: ProducerModelPredicate | typeof PredicateAll, options?: ObserveQueryOptions ): Observable> => { - return new Observable>((observer) => { + return new Observable>(observer => { const items = new Map(); const itemsChanged = new Map(); let deletedItemIds: string[] = []; @@ -1175,7 +1175,7 @@ class DataStore { (async () => { try { // first, query and return any locally-available records - (await this.query(model, criteria, sortOptions)).forEach((item) => + (await this.query(model, criteria, sortOptions)).forEach(item => items.set(item.id, item) ); @@ -1195,7 +1195,7 @@ class DataStore { itemsChanged.set(element.id, element); } - const isSynced = this.sync.getModelSyncedStatus(model); + const isSynced = this.sync?.getModelSyncedStatus(model) ?? false; const limit = itemsChanged.size - deletedItemIds.length >= this.syncPageSize; @@ -1217,7 +1217,7 @@ class DataStore { // TODO: abstract this function into a util file to be able to write better unit tests const generateSnapshot = (): DataStoreSnapshot => { - const isSynced = this.sync.getModelSyncedStatus(model); + const isSynced = this.sync?.getModelSyncedStatus(model) ?? false; const itemsArray = [ ...Array.from(items.values()), ...Array.from(itemsChanged.values()), @@ -1228,10 +1228,10 @@ class DataStore { } items.clear(); - itemsArray.forEach((item) => items.set(item.id, item)); + itemsArray.forEach(item => items.set(item.id, item)); // remove deleted items from the final result set - deletedItemIds.forEach((id) => items.delete(id)); + deletedItemIds.forEach(id => items.delete(id)); return { items: Array.from(items.values()), diff --git a/packages/datastore/src/sync/outbox.ts b/packages/datastore/src/sync/outbox.ts index 52205ea58df..f5167595591 100644 --- a/packages/datastore/src/sync/outbox.ts +++ b/packages/datastore/src/sync/outbox.ts @@ -12,7 +12,7 @@ import { PersistentModelConstructor, QueryOne, } from '../types'; -import { SYNC, valuesEqual } from '../util'; +import { USER, SYNC, valuesEqual } from '../util'; import { TransformerMutationType } from './utils'; // TODO: Persist deleted ids @@ -31,9 +31,8 @@ class MutationEventOutbox { mutationEvent: MutationEvent ): Promise { storage.runExclusive(async s => { - const mutationEventModelDefinition = this.schema.namespaces[SYNC].models[ - 'MutationEvent' - ]; + const mutationEventModelDefinition = + this.schema.namespaces[SYNC].models['MutationEvent']; const predicate = ModelPredicateCreator.createFromExisting( mutationEventModelDefinition, @@ -124,8 +123,8 @@ class MutationEventOutbox { storage: StorageFacade, model: T ): Promise { - const mutationEventModelDefinition = this.schema.namespaces[SYNC].models - .MutationEvent; + const mutationEventModelDefinition = + this.schema.namespaces[SYNC].models.MutationEvent; const mutationEvents = await storage.query( this.MutationEvent, @@ -161,7 +160,9 @@ class MutationEventOutbox { return; } - const { _version, _lastChangedAt, _deleted, ...incomingData } = record; + const { _version, _lastChangedAt, _deleted, ..._incomingData } = record; + const incomingData = this.removeTimestampFields(head.model, _incomingData); + const data = JSON.parse(head.data); if (!data) { @@ -172,8 +173,9 @@ class MutationEventOutbox { _version: __version, _lastChangedAt: __lastChangedAt, _deleted: __deleted, - ...outgoingData + ..._outgoingData } = data; + const outgoingData = this.removeTimestampFields(head.model, _outgoingData); // Don't sync the version when the data in the response does not match the data // in the request, i.e., when there's a handled conflict @@ -181,9 +183,8 @@ class MutationEventOutbox { return; } - const mutationEventModelDefinition = this.schema.namespaces[SYNC].models[ - 'MutationEvent' - ]; + const mutationEventModelDefinition = + this.schema.namespaces[SYNC].models['MutationEvent']; const predicate = ModelPredicateCreator.createFromExisting( mutationEventModelDefinition, @@ -222,13 +223,8 @@ class MutationEventOutbox { previous: MutationEvent, current: MutationEvent ): MutationEvent { - const { - _version, - id, - _lastChangedAt, - _deleted, - ...previousData - } = JSON.parse(previous.data); + const { _version, id, _lastChangedAt, _deleted, ...previousData } = + JSON.parse(previous.data); const { id: __id, @@ -252,6 +248,49 @@ class MutationEventOutbox { data, }); } + + /* + if a model is using custom timestamp fields + the custom field names will be stored in the model attributes + + e.g. + "attributes": [ + { + "type": "model", + "properties": { + "timestamps": { + "createdAt": "createdOn", + "updatedAt": "updatedOn" + } + } + } + ] + */ + private removeTimestampFields( + model: string, + record: PersistentModel + ): PersistentModel { + const CREATED_AT_DEFAULT_KEY = 'createdAt'; + const UPDATED_AT_DEFAULT_KEY = 'updatedAt'; + + let createdTimestampKey = CREATED_AT_DEFAULT_KEY; + let updatedTimestampKey = UPDATED_AT_DEFAULT_KEY; + + const modelAttributes = this.schema.namespaces[USER].models[ + model + ].attributes?.find(attr => attr.type === 'model'); + const timestampFieldsMap = modelAttributes?.properties?.timestamps; + + if (timestampFieldsMap) { + createdTimestampKey = timestampFieldsMap[CREATED_AT_DEFAULT_KEY]; + updatedTimestampKey = timestampFieldsMap[UPDATED_AT_DEFAULT_KEY]; + } + + delete (record as Record)[createdTimestampKey]; + delete (record as Record)[updatedTimestampKey]; + + return record; + } } export { MutationEventOutbox }; diff --git a/packages/geo/CHANGELOG.md b/packages/geo/CHANGELOG.md index 1343f11055f..7517a05bbdd 100644 --- a/packages/geo/CHANGELOG.md +++ b/packages/geo/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.1.11](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/geo@1.1.10...@aws-amplify/geo@1.1.11) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/geo + +## [1.1.10](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/geo@1.1.9...@aws-amplify/geo@1.1.10) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/geo + +## [1.1.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/geo@1.1.8...@aws-amplify/geo@1.1.9) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/geo + ## [1.1.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/geo@1.1.7...@aws-amplify/geo@1.1.8) (2021-11-18) ### Bug Fixes diff --git a/packages/geo/package.json b/packages/geo/package.json index 486b088e4f1..2f547e8fba0 100644 --- a/packages/geo/package.json +++ b/packages/geo/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/geo", - "version": "1.1.8", + "version": "1.1.11", "description": "Geo category for aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,7 +41,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8", + "@aws-amplify/core": "4.3.11", "@aws-sdk/client-location": "3.41.0", "camelcase-keys": "6.2.2" }, diff --git a/packages/interactions/CHANGELOG.md b/packages/interactions/CHANGELOG.md index 3e478b68248..7672a811721 100644 --- a/packages/interactions/CHANGELOG.md +++ b/packages/interactions/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.28...@aws-amplify/interactions@4.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/interactions + +## [4.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.27...@aws-amplify/interactions@4.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/interactions + +## [4.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.26...@aws-amplify/interactions@4.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/interactions + ## [4.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/interactions@4.0.25...@aws-amplify/interactions@4.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/interactions diff --git a/packages/interactions/package.json b/packages/interactions/package.json index f8e0409901d..32020730aea 100644 --- a/packages/interactions/package.json +++ b/packages/interactions/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/interactions", - "version": "4.0.26", + "version": "4.0.29", "description": "Interactions category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,7 +41,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8", + "@aws-amplify/core": "4.3.11", "@aws-sdk/client-lex-runtime-service": "3.6.1" }, "jest": { diff --git a/packages/notifications/__mocks__/data.ts b/packages/notifications/__mocks__/data.ts new file mode 100644 index 00000000000..1b7d8023aae --- /dev/null +++ b/packages/notifications/__mocks__/data.ts @@ -0,0 +1,238 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { + Alignment, + ButtonAction, + DimensionType, + FilterType, + InAppMessageCampaign as PinpointInAppMessage, +} from '@aws-sdk/client-pinpoint'; +import { + InAppMessage, + InAppMessagingEvent, + UserInfo, +} from '../src/InAppMessaging'; +import { NotificationsConfig } from '../src'; + +export const credentials = { + accessKeyId: 'access-key-id', + sessionToken: 'session-token', + secretAccessKey: 'secret-access-key', + identityId: 'identity-id', + authenticated: true, +}; + +export const awsPinpointConfig = { + appId: 'pinpoint-project-id', + region: 'us-west-2', +}; + +export const inAppMessagingConfig = { + AWSPinpoint: awsPinpointConfig, +}; + +export const notificationsConfig = { + InAppMessaging: inAppMessagingConfig, +}; + +export const adhocConfig: NotificationsConfig = { + Notifications: { + InAppMessaging: { + AWSPinpoint: { + appId: 'another-pinpoint-project-id', + region: 'us-east-1', + }, + }, + }, +}; + +export const awsConfig = { + mobileHubProperty: '', + AnotherCategory: {}, + Notifications: notificationsConfig, +}; + +export const simpleEvent: InAppMessagingEvent = { name: 'foo' }; + +export const simpleMessages = [{ id: 'foo' }, { id: 'bar' }]; + +export const closestExpiryMessage: InAppMessage = { + id: 'closest-expiry', + layout: 'CAROUSEL', + content: [], + metadata: { + endDate: '2021-01-01T00:00:00Z', + }, +}; + +export const customHandledMessage: InAppMessage = { + id: 'custom-handled', + layout: 'MIDDLE_BANNER', + content: [], + metadata: { + endDate: '2021-03-01T00:00:00Z', + }, +}; + +export const inAppMessages: InAppMessage[] = [ + { + id: 'top-banner', + layout: 'TOP_BANNER', + content: [], + metadata: { + endDate: '2021-02-01T00:00:00Z', + treatmentId: 'T1', + }, + }, + { + id: 'no-end-date-1', + layout: 'MIDDLE_BANNER', + content: [], + }, + { ...customHandledMessage }, + { + id: 'bottom-banner', + layout: 'BOTTOM_BANNER', + content: [], + metadata: { + endDate: '2021-02-01T00:00:00Z', + }, + }, + { ...closestExpiryMessage }, + { + id: 'no-end-date-2', + layout: 'MIDDLE_BANNER', + content: [], + }, +]; + +export const pinpointInAppMessage: PinpointInAppMessage = { + CampaignId: 'uuid-1', + InAppMessage: { + Content: [ + { + BackgroundColor: '#FFFF88', + BodyConfig: { + Alignment: Alignment.LEFT, + Body: 'Body content', + TextColor: '#FF8888', + }, + HeaderConfig: { + Alignment: Alignment.CENTER, + Header: 'Header content', + TextColor: '#88FF88', + }, + ImageUrl: 'http://image.url', + PrimaryBtn: { + DefaultConfig: { + BackgroundColor: '#8888FF', + BorderRadius: 4, + ButtonAction: ButtonAction.CLOSE, + Link: null, + Text: 'Close button', + TextColor: '#FF88FF', + }, + }, + SecondaryBtn: { + DefaultConfig: { + BackgroundColor: '#88FFFF', + BorderRadius: 4, + ButtonAction: ButtonAction.LINK, + Link: 'http://link.url', + Text: 'Link button', + TextColor: '#FFFFFF', + }, + }, + }, + ], + Layout: 'TOP_BANNER', + CustomConfig: { foo: 'bar' }, + }, + Priority: 3, + Schedule: { + EndDate: '2021-01-01T00:00:00Z', + EventFilter: { + FilterType: FilterType.SYSTEM, + Dimensions: { + Attributes: {}, + EventType: { + DimensionType: DimensionType.INCLUSIVE, + Values: ['clicked', 'swiped'], + }, + Metrics: {}, + }, + }, + QuietTime: { + End: null, + Start: null, + }, + }, + SessionCap: 0, + DailyCap: 0, + TotalCap: 0, + TreatmentId: 'T1', +}; + +export const extractedContent = [ + { + body: { + content: 'Body content', + style: { color: '#FF8888', textAlign: 'left' }, + }, + container: { style: { backgroundColor: '#FFFF88' } }, + header: { + content: 'Header content', + style: { color: '#88FF88', textAlign: 'center' }, + }, + image: { src: 'http://image.url' }, + primaryButton: { + action: 'CLOSE', + style: { backgroundColor: '#8888FF', borderRadius: 4, color: '#FF88FF' }, + title: 'Close button', + url: null, + }, + secondaryButton: { + action: 'LINK', + style: { backgroundColor: '#88FFFF', borderRadius: 4, color: '#FFFFFF' }, + title: 'Link button', + url: 'http://link.url', + }, + }, +]; + +export const extractedMetadata = { + customData: { foo: 'bar' }, + endDate: '2021-01-01T00:00:00Z', + priority: 3, + treatmentId: 'T1', +}; + +export const userId = 'user-id'; + +export const userInfo: UserInfo = { + attributes: { + hobbies: ['shuffleboard', 'jousting'], + }, +}; + +export const pinpointEndpointPayload = { + ApplicationId: awsPinpointConfig.appId, + EndpointRequest: expect.objectContaining({ + Attributes: userInfo.attributes, + ChannelType: 'IN_APP', + User: { + UserAttributes: userInfo.attributes, + UserId: userId, + }, + }), +}; diff --git a/packages/notifications/__mocks__/mocks.ts b/packages/notifications/__mocks__/mocks.ts new file mode 100644 index 00000000000..cfe3aad77e2 --- /dev/null +++ b/packages/notifications/__mocks__/mocks.ts @@ -0,0 +1,32 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +export const mockHub = { + listen: jest.fn(), +}; + +export const mockInAppMessagingProvider = { + configure: jest.fn(), + getCategory: jest.fn(), + getInAppMessages: jest.fn(), + getProviderName: jest.fn(), + getSubCategory: jest.fn(), + identifyUser: jest.fn(), + processInAppMessages: jest.fn(), +}; + +export const mockStorage = { + getItem: jest.fn(), + removeItem: jest.fn(), + setItem: jest.fn(), + sync: jest.fn(), +}; diff --git a/packages/notifications/__tests__/InAppMessaging/InAppMessaging.test.ts b/packages/notifications/__tests__/InAppMessaging/InAppMessaging.test.ts new file mode 100644 index 00000000000..53ab1c04252 --- /dev/null +++ b/packages/notifications/__tests__/InAppMessaging/InAppMessaging.test.ts @@ -0,0 +1,386 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { + ConsoleLogger, + Hub, + HubCallback, + HubCapsule, + StorageHelper, +} from '@aws-amplify/core'; + +import InAppMessaging, { + InAppMessageInteractionEvent, +} from '../../src/InAppMessaging'; +import { + addMessageInteractionEventListener, + notifyMessageInteractionEventListeners, +} from '../../src/InAppMessaging/eventListeners'; + +import { + closestExpiryMessage, + customHandledMessage, + inAppMessagingConfig, + inAppMessages, + simpleEvent, + simpleMessages, + userId, + userInfo, +} from '../../__mocks__/data'; +import { mockInAppMessagingProvider, mockStorage } from '../../__mocks__/mocks'; + +jest.mock('@aws-amplify/core'); +jest.mock('../../src/InAppMessaging/eventListeners'); + +const PROVIDER_NAME = 'InAppMessagingProvider'; + +const getStorageSpy = jest.spyOn(StorageHelper.prototype, 'getStorage'); +const loggerDebugSpy = jest.spyOn(ConsoleLogger.prototype, 'debug'); +const loggerErrorSpy = jest.spyOn(ConsoleLogger.prototype, 'error'); +const hubSpy = jest.spyOn(Hub, 'listen'); + +describe('InAppMessaging', () => { + let inAppMessaging: InAppMessaging; + beforeEach(() => { + jest.clearAllMocks(); + getStorageSpy.mockReturnValue(mockStorage); + inAppMessaging = new InAppMessaging(); + inAppMessaging.addPluggable(mockInAppMessagingProvider); + mockInAppMessagingProvider.getCategory.mockReturnValue('Notifications'); + mockInAppMessagingProvider.getInAppMessages.mockReturnValue(simpleMessages); + mockInAppMessagingProvider.getProviderName.mockReturnValue(PROVIDER_NAME); + mockInAppMessagingProvider.getSubCategory.mockReturnValue('InAppMessaging'); + }); + + test('returns the correct module name', () => { + expect(inAppMessaging.getModuleName()).toBe('InAppMessaging'); + }); + + describe('Pluggables', () => { + test('can be added', () => { + expect(mockInAppMessagingProvider.configure).toBeCalled(); + }); + + test('can be gotten', () => { + expect(inAppMessaging.getPluggable(PROVIDER_NAME)).not.toBeNull(); + }); + + test('can be removed', () => { + inAppMessaging.removePluggable(PROVIDER_NAME); + + expect(inAppMessaging.getPluggable(PROVIDER_NAME)).toBeNull(); + }); + + test('cannot be removed if not found', () => { + inAppMessaging.removePluggable('InvalidProvider'); + + expect(loggerDebugSpy).toBeCalledWith( + expect.stringContaining('InvalidProvider') + ); + }); + + test('cannot be added if duplicate', () => { + expect(() => { + inAppMessaging.addPluggable(mockInAppMessagingProvider); + }).toThrow(/has already been added/); + }); + + test('cannot be added if invalid', () => { + inAppMessaging.removePluggable(PROVIDER_NAME); + mockInAppMessagingProvider.configure.mockClear(); + mockInAppMessagingProvider.getSubCategory.mockReturnValue( + 'InvalidSubCategory' + ); + + expect(mockInAppMessagingProvider.configure).not.toBeCalled(); + }); + }); + + describe('configure', () => { + test('can be called without input', () => { + const config = inAppMessaging.configure(); + + expect(config).toMatchObject({}); + }); + + test('attaches a storage helper to the config', () => { + const config = inAppMessaging.configure(inAppMessagingConfig); + + expect(config).toStrictEqual({ + ...inAppMessagingConfig, + storage: mockStorage, + }); + }); + + test('adds a Hub listener for analytics record events', () => { + const recordCapsule = { + payload: { + event: 'record', + data: simpleEvent, + }, + } as HubCapsule; + const configuredCapsule = { + payload: { + event: 'configured', + }, + } as HubCapsule; + const dispatchEventSpy = jest.spyOn(inAppMessaging, 'dispatchEvent'); + hubSpy.mockImplementation((channel, callback) => { + expect(channel).toBe('analytics'); + const analyticsListener = callback as HubCallback; + // simulate analytics events by calling the registered callback directly + analyticsListener(recordCapsule); + analyticsListener(configuredCapsule); + return () => {}; + }); + + inAppMessaging.configure(); + + expect(hubSpy).toBeCalled(); + expect(dispatchEventSpy).toBeCalledTimes(1); + }); + + test('does not listen to analytics events if `listenForAnalyticsEvents` is false', () => { + inAppMessaging.configure({ listenForAnalyticsEvents: false }); + + expect(hubSpy).not.toBeCalled(); + }); + }); + + describe('syncMessages', () => { + test('Gets in-app messages from added providers and stores them', async () => { + await inAppMessaging.syncMessages(); + + expect(mockStorage.setItem).toBeCalledWith( + expect.stringContaining(PROVIDER_NAME), + JSON.stringify(simpleMessages) + ); + }); + + test('only tries to store messages if there are messages to store', async () => { + mockInAppMessagingProvider.getInAppMessages.mockReturnValue(null); + + await inAppMessaging.syncMessages(); + + expect(mockStorage.setItem).not.toBeCalled(); + }); + + test('rejects if there is a failure getting messages', async () => { + mockInAppMessagingProvider.getInAppMessages.mockImplementation(() => { + throw new Error(); + }); + + await expect(inAppMessaging.syncMessages()).rejects.toStrictEqual( + expect.any(Error) + ); + + expect(mockStorage.setItem).not.toBeCalled(); + }); + + test('logs error if storage sync fails', async () => { + mockStorage.sync.mockImplementation(() => { + throw new Error(); + }); + + await inAppMessaging.syncMessages(); + + expect(loggerErrorSpy).toBeCalledWith( + expect.stringContaining('Failed to sync'), + expect.any(Error) + ); + }); + + test('logs error if storage save fails', async () => { + mockStorage.setItem.mockImplementation(() => { + throw new Error(); + }); + + await inAppMessaging.syncMessages(); + + expect(loggerErrorSpy).toBeCalledWith( + expect.stringContaining('Failed to store'), + expect.any(Error) + ); + }); + }); + + describe('clearMessages', () => { + test('clears in-app messages from store', async () => { + await inAppMessaging.clearMessages(); + + expect(mockStorage.removeItem).toBeCalledWith( + expect.stringContaining(PROVIDER_NAME) + ); + }); + + test('logs error if storage remove fails', async () => { + mockStorage.removeItem.mockImplementation(() => { + throw new Error(); + }); + + await inAppMessaging.clearMessages(); + + expect(loggerErrorSpy).toBeCalledWith( + expect.stringContaining('Failed to remove'), + expect.any(Error) + ); + }); + }); + + describe('dispatchEvent', () => { + test('gets in-app messages from store and notifies listeners', async () => { + const [message] = inAppMessages; + mockInAppMessagingProvider.processInAppMessages.mockReturnValue([ + message, + ]); + mockStorage.getItem.mockReturnValue(JSON.stringify(simpleMessages)); + + await inAppMessaging.dispatchEvent(simpleEvent); + + expect(mockInAppMessagingProvider.processInAppMessages).toBeCalledWith( + simpleMessages, + simpleEvent + ); + expect(notifyMessageInteractionEventListeners).toBeCalledWith( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + }); + + test('does not notify listeners if no messages are returned', async () => { + mockInAppMessagingProvider.processInAppMessages.mockReturnValue([]); + mockStorage.getItem.mockReturnValue(JSON.stringify(simpleMessages)); + + await inAppMessaging.dispatchEvent(simpleEvent); + + expect(notifyMessageInteractionEventListeners).not.toBeCalled(); + }); + + test('logs error if storage retrieval fails', async () => { + mockStorage.getItem.mockImplementation(() => { + throw new Error(); + }); + + await inAppMessaging.dispatchEvent(simpleEvent); + + expect(loggerErrorSpy).toBeCalledWith( + expect.stringContaining('Failed to retrieve'), + expect.any(Error) + ); + }); + }); + + describe('identifyUser', () => { + test('identifies users with pluggables', async () => { + await inAppMessaging.identifyUser(userId, userInfo); + + expect(mockInAppMessagingProvider.identifyUser).toBeCalledWith( + userId, + userInfo + ); + }); + + test('rejects if there is a failure identifying user', async () => { + mockInAppMessagingProvider.identifyUser.mockImplementation(() => { + throw new Error(); + }); + + await expect( + inAppMessaging.identifyUser(userId, userInfo) + ).rejects.toStrictEqual(expect.any(Error)); + }); + }); + + describe('Interaction events', () => { + const handler = jest.fn(); + test('can be listened to by onMessageReceived', () => { + inAppMessaging.onMessageReceived(handler); + + expect(addMessageInteractionEventListener).toBeCalledWith( + handler, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + }); + + test('can be listened to by onMessageDisplayed', () => { + inAppMessaging.onMessageDisplayed(handler); + + expect(addMessageInteractionEventListener).toBeCalledWith( + handler, + InAppMessageInteractionEvent.MESSAGE_DISPLAYED + ); + }); + + test('can be listened to by onMessageDismissed', () => { + inAppMessaging.onMessageDismissed(handler); + + expect(addMessageInteractionEventListener).toBeCalledWith( + handler, + InAppMessageInteractionEvent.MESSAGE_DISMISSED + ); + }); + + test('can be listened to by onMessageActionTaken', () => { + inAppMessaging.onMessageActionTaken(handler); + + expect(addMessageInteractionEventListener).toBeCalledWith( + handler, + InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN + ); + }); + + test('can be notified by notifyMessageInteraction', () => { + const [message] = inAppMessages; + + inAppMessaging.notifyMessageInteraction( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + + expect(notifyMessageInteractionEventListeners).toBeCalledWith( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + }); + }); + + describe('Conflict handling', () => { + test('has a default implementation', async () => { + mockInAppMessagingProvider.processInAppMessages.mockReturnValue( + inAppMessages + ); + + await inAppMessaging.dispatchEvent(simpleEvent); + + expect(notifyMessageInteractionEventListeners).toBeCalledWith( + closestExpiryMessage, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + }); + + test('can be customized through setConflictHandler', async () => { + const customConflictHandler = messages => + messages.find(message => message.id === 'custom-handled'); + mockInAppMessagingProvider.processInAppMessages.mockReturnValue( + inAppMessages + ); + + inAppMessaging.setConflictHandler(customConflictHandler); + await inAppMessaging.dispatchEvent(simpleEvent); + + expect(notifyMessageInteractionEventListeners).toBeCalledWith( + customHandledMessage, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + }); + }); +}); diff --git a/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/index.test.ts b/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/index.test.ts new file mode 100644 index 00000000000..109c33ab672 --- /dev/null +++ b/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/index.test.ts @@ -0,0 +1,355 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { Credentials, StorageHelper } from '@aws-amplify/core'; +import { PinpointClient } from '@aws-sdk/client-pinpoint'; +import cloneDeep from 'lodash/cloneDeep'; + +import * as eventListeners from '../../../../src/InAppMessaging/eventListeners'; +import { + InAppMessage, + InAppMessageInteractionEvent, +} from '../../../../src/InAppMessaging'; +import { AWSPinpointProvider } from '../../../../src/InAppMessaging/Providers'; +import * as utils from '../../../../src/InAppMessaging/Providers/AWSPinpointProvider/utils'; + +import { + awsPinpointConfig, + credentials, + pinpointEndpointPayload, + pinpointInAppMessage, + simpleEvent, + userId, + userInfo, +} from '../../../../__mocks__/data'; +import { mockStorage } from '../../../../__mocks__/mocks'; + +jest.mock('@aws-amplify/core'); +jest.mock('@aws-sdk/client-pinpoint'); +jest.mock('../../../../src/InAppMessaging/eventListeners'); +jest.mock('../../../../src/InAppMessaging/Providers/AWSPinpointProvider/utils'); +jest.mock( + '../../../../src/InAppMessaging/SessionTracker/SessionTracker', + () => ({ + __esModule: true, + default: jest.fn(() => ({ + start: jest.fn(), + })), + }) +); + +const getStorageSpy = jest.spyOn(StorageHelper.prototype, 'getStorage'); +const credentialsGetSpy = jest.spyOn(Credentials, 'get'); +const credentialsShearSpy = jest.spyOn(Credentials, 'shear'); +const matchesEventTypeSpy = jest.spyOn(utils, 'matchesEventType'); +const matchesAttributesSpy = jest.spyOn(utils, 'matchesAttributes'); +const matchesMetricsSpy = jest.spyOn(utils, 'matchesMetrics'); +const isBeforeEndDateSpy = jest.spyOn(utils, 'isBeforeEndDate'); +const addListenerSpy = jest.spyOn( + eventListeners, + 'addMessageInteractionEventListener' +); +const clientSendSpy = jest.spyOn(PinpointClient.prototype, 'send') as jest.Mock; + +describe('AWSPinpoint InAppMessaging Provider', () => { + let provider: AWSPinpointProvider; + const { logger } = utils; + let mockStorageMemory = {}; + beforeAll(() => { + mockStorage.setItem.mockImplementation((key, val) => { + mockStorageMemory[key] = val; + }); + mockStorage.getItem.mockImplementation(key => mockStorageMemory[key]); + }); + beforeEach(() => { + jest.clearAllMocks(); + getStorageSpy.mockReturnValue(mockStorage); + credentialsGetSpy.mockResolvedValue(credentials); + credentialsShearSpy.mockImplementation(credentials => credentials); + mockStorageMemory = {}; + provider = new AWSPinpointProvider(); + }); + + test('returns the correct category name', () => { + expect(provider.getCategory()).toBe('Notifications'); + }); + + test('returns the correct sub-category name', () => { + expect(provider.getSubCategory()).toBe('InAppMessaging'); + }); + + test('returns the correct provider name', () => { + expect(provider.getProviderName()).toBe('AWSPinpoint'); + }); + + describe('configure', () => { + test('can be called without input', () => { + const config = provider.configure(); + + expect(config).toMatchObject({}); + }); + + test('attaches a storage helper to the config', () => { + const config = provider.configure(awsPinpointConfig); + + expect(config).toStrictEqual({ + ...awsPinpointConfig, + storage: mockStorage, + }); + }); + }); + + describe('getInAppMessages', () => { + const messages = [cloneDeep(pinpointInAppMessage)]; + beforeEach(() => { + provider.configure(awsPinpointConfig); + }); + + test('gets in-app messages from Pinpoint', async () => { + clientSendSpy.mockResolvedValueOnce(null).mockResolvedValueOnce({ + InAppMessagesResponse: { + InAppMessageCampaigns: messages, + }, + }); + + expect(await provider.getInAppMessages()).toStrictEqual(messages); + }); + + test('throws an error if credentials are empty', async () => { + credentialsGetSpy.mockResolvedValue(null); + + await expect(provider.getInAppMessages()).rejects.toThrow(); + + expect(logger.debug).toBeCalledWith('no credentials found'); + }); + + test('throws an error on credentials get failure', async () => { + credentialsGetSpy.mockImplementation(() => { + throw new Error(); + }); + + await expect(provider.getInAppMessages()).rejects.toThrow(); + + expect(logger.error).toBeCalledWith( + expect.stringContaining('Error getting credentials'), + expect.any(Error) + ); + }); + + test('throws an error on client failure', async () => { + clientSendSpy.mockImplementationOnce(() => { + throw new Error(); + }); + + await expect(provider.getInAppMessages()).rejects.toThrow(); + + expect(logger.error).toBeCalledWith( + expect.stringContaining('Error getting in-app messages'), + expect.any(Error) + ); + }); + }); + + describe('processInAppMessages', () => { + const messages = [ + cloneDeep(pinpointInAppMessage), + { ...cloneDeep(pinpointInAppMessage), CampaignId: 'uuid-2', Priority: 3 }, + { ...cloneDeep(pinpointInAppMessage), CampaignId: 'uuid-3', Priority: 1 }, + { ...cloneDeep(pinpointInAppMessage), CampaignId: 'uuid-4', Priority: 2 }, + ]; + beforeEach(() => { + matchesEventTypeSpy.mockReturnValue(true); + matchesAttributesSpy.mockReturnValue(true); + matchesMetricsSpy.mockReturnValue(true); + isBeforeEndDateSpy.mockReturnValue(true); + }); + + test('filters in-app messages from Pinpoint by criteria', async () => { + matchesEventTypeSpy.mockReturnValueOnce(false); + matchesAttributesSpy.mockReturnValueOnce(false); + matchesMetricsSpy.mockReturnValueOnce(false); + const [result] = await provider.processInAppMessages( + messages, + simpleEvent + ); + + expect(result.id).toBe('uuid-4'); + }); + + test('filters in-app messages from Pinpoint by criteria', async () => { + const [result] = await provider.processInAppMessages( + messages, + simpleEvent + ); + + expect(result.id).toBe('uuid-3'); + }); + }); + + describe('identifyUser', () => { + beforeEach(() => { + provider.configure(awsPinpointConfig); + }); + + test('updates Pinpoint endpoint', async () => { + await provider.identifyUser(userId, userInfo); + + expect(logger.debug).toBeCalledWith( + 'updating endpoint', + expect.objectContaining(pinpointEndpointPayload) + ); + expect(clientSendSpy).toBeCalled(); + }); + + test('throws an error on client failure', async () => { + clientSendSpy.mockImplementationOnce(() => { + throw new Error(); + }); + + await expect(provider.identifyUser(userId, userInfo)).rejects.toThrow(); + + expect(logger.error).toBeCalledWith( + expect.stringContaining('Error identifying user'), + expect.any(Error) + ); + }); + }); + + describe('Display caps', () => { + let notify; + const displayedMessage: InAppMessage = { + id: 'uuid-1', + layout: 'TOP_BANNER', + content: [], + }; + beforeAll(() => { + matchesEventTypeSpy.mockReturnValue(true); + matchesAttributesSpy.mockReturnValue(true); + matchesMetricsSpy.mockReturnValue(true); + isBeforeEndDateSpy.mockReturnValue(true); + addListenerSpy.mockImplementation((handleEvent, event) => { + if (event === InAppMessageInteractionEvent.MESSAGE_DISPLAYED) { + notify = handleEvent; + } + return { handleEvent, remove: jest.fn() }; + }); + }); + + test('messages stop being processed if session cap is met', async () => { + expect(getStorageSpy).toBeCalled(); + + provider.configure(awsPinpointConfig); + const message = cloneDeep(pinpointInAppMessage); + message.SessionCap = 1; + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(1); + + notify(displayedMessage); + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(0); + }); + + test('messages stop being processed if daily cap is met', async () => { + expect(getStorageSpy).toBeCalled(); + + provider.configure(awsPinpointConfig); + const message = cloneDeep(pinpointInAppMessage); + message.DailyCap = 1; + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(1); + + notify(displayedMessage); + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(0); + }); + + test('messages stop being processed if total cap is met', async () => { + expect(getStorageSpy).toBeCalled(); + + provider.configure(awsPinpointConfig); + const message = cloneDeep(pinpointInAppMessage); + message.TotalCap = 1; + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(1); + + notify(displayedMessage); + + expect( + await provider.processInAppMessages([message], simpleEvent) + ).toHaveLength(0); + }); + + test('session caps are tracked per message', async () => { + expect(getStorageSpy).toBeCalled(); + + provider.configure(awsPinpointConfig); + const firstMessage = cloneDeep(pinpointInAppMessage); + firstMessage.SessionCap = 1; + const secondMessage = { + ...cloneDeep(pinpointInAppMessage), + CampaignId: 'uuid-2', + }; + secondMessage.SessionCap = 1; + const messages = [firstMessage, secondMessage]; + + expect( + await provider.processInAppMessages(messages, simpleEvent) + ).toHaveLength(2); + + notify(displayedMessage); + + expect( + await provider.processInAppMessages(messages, simpleEvent) + ).toHaveLength(1); + + notify({ ...displayedMessage, id: 'uuid-2' }); + + expect( + await provider.processInAppMessages(messages, simpleEvent) + ).toHaveLength(0); + }); + + test('daily caps are tracked across messages', async () => { + expect(getStorageSpy).toBeCalled(); + + provider.configure(awsPinpointConfig); + const firstMessage = cloneDeep(pinpointInAppMessage); + firstMessage.DailyCap = 1; + const secondMessage = { + ...cloneDeep(pinpointInAppMessage), + CampaignId: 'uuid-2', + }; + secondMessage.DailyCap = 1; + const messages = [firstMessage, secondMessage]; + + expect( + await provider.processInAppMessages(messages, simpleEvent) + ).toHaveLength(2); + + notify(displayedMessage); + + expect( + await provider.processInAppMessages(messages, simpleEvent) + ).toHaveLength(0); + }); + }); +}); diff --git a/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/utils.test.ts b/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/utils.test.ts new file mode 100644 index 00000000000..147c3badb62 --- /dev/null +++ b/packages/notifications/__tests__/InAppMessaging/Providers/AWSPinpointProvider/utils.test.ts @@ -0,0 +1,341 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { InAppMessageCampaign as PinpointInAppMessage } from '@aws-sdk/client-pinpoint'; +import { Amplify, ConsoleLogger, Hub } from '@aws-amplify/core'; +import cloneDeep from 'lodash/cloneDeep'; + +import { InAppMessagingEvent } from '../../../../src/InAppMessaging'; +import { AWSPinpointMessageEvent } from '../../../../src/InAppMessaging/Providers/AWSPinpointProvider/types'; +import { + clearMemo, + dispatchInAppMessagingEvent, + extractContent, + extractMetadata, + getStartOfDay, + isBeforeEndDate, + isQuietTime, + matchesAttributes, + matchesEventType, + matchesMetrics, + recordAnalyticsEvent, +} from '../../../../src/InAppMessaging/Providers/AWSPinpointProvider/utils'; + +import { + inAppMessages, + extractedContent, + extractedMetadata, + pinpointInAppMessage, +} from '../../../../__mocks__/data'; + +jest.mock('@aws-amplify/core'); + +const HOUR_IN_MS = 1000 * 60 * 60; + +const loggerDebugSpy = jest.spyOn(ConsoleLogger.prototype, 'debug'); + +describe('AWSPinpoint InAppMessaging Provider Utils', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test('dispatchInAppMessagingEvent dispatches Hub event', () => { + const event = 'foo'; + const data = { bar: 'baz' }; + const message = 'qux'; + + dispatchInAppMessagingEvent(event, data, message); + + expect(Hub.dispatch).toBeCalledWith( + 'inAppMessaging', + { event, data, message }, + 'InAppMessaging', + expect.anything() // expect.any(Symbol) is fixed in a later Jest version + ); + }); + + describe('recordAnalyticsEvent', () => { + Amplify.Analytics = { record: jest.fn() }; + const [message] = inAppMessages; + + test('records an analytics event', () => { + Amplify.Analytics = { record: jest.fn() }; + + recordAnalyticsEvent(AWSPinpointMessageEvent.MESSAGE_DISPLAYED, message); + + expect(Amplify.Analytics.record).toBeCalledWith({ + name: AWSPinpointMessageEvent.MESSAGE_DISPLAYED, + attributes: { + campaign_id: 'top-banner', + delivery_type: 'IN_APP_MESSAGE', + treatment_id: 'T1', + }, + }); + }); + + test('does not try to record an event without a message', () => { + recordAnalyticsEvent(AWSPinpointMessageEvent.MESSAGE_DISPLAYED, null); + + expect(loggerDebugSpy).toBeCalledWith( + expect.stringContaining('Unable to record') + ); + expect(Amplify.Analytics.record).not.toBeCalled(); + }); + + test('does not try to record an event without a message', () => { + Amplify.Analytics = null; + + recordAnalyticsEvent(AWSPinpointMessageEvent.MESSAGE_DISPLAYED, message); + + expect(loggerDebugSpy).toBeCalledWith( + expect.stringContaining('module is not registered') + ); + }); + }); + + test('getStartOfDay returns a date string for the start of day', () => { + const dateString = getStartOfDay(); + const date = new Date(dateString); + + expect(date.getHours()).toBe(0); + expect(date.getMinutes()).toBe(0); + expect(date.getSeconds()).toBe(0); + expect(date.getMilliseconds()).toBe(0); + }); + + describe('matchesEventType', () => { + let message: PinpointInAppMessage; + beforeEach(() => { + message = cloneDeep(pinpointInAppMessage); + clearMemo(); + }); + + test('checks if an event name matches a Pinpoint message', () => { + const clickEvent: InAppMessagingEvent = { name: 'clicked' }; + const swipeEvent: InAppMessagingEvent = { name: 'swiped' }; + const dragEvent: InAppMessagingEvent = { name: 'dragged' }; + + expect(matchesEventType(message, clickEvent)).toBe(true); + expect(matchesEventType(message, swipeEvent)).toBe(true); + expect(matchesEventType(message, dragEvent)).toBe(false); + }); + + test('memoizes matches', () => { + const clickEvent: InAppMessagingEvent = { name: 'clicked' }; + message.Schedule.EventFilter.Dimensions.EventType.Values = ['clicked']; + + expect(matchesEventType(message, clickEvent)).toBe(true); + + // This is a contrived way of validating the memo logic and should never happen in practice + message.Schedule.EventFilter.Dimensions.EventType.Values = []; + + expect(matchesEventType(message, clickEvent)).toBe(true); + + clearMemo(); + + expect(matchesEventType(message, clickEvent)).toBe(false); + }); + }); + + describe('matchesAttributes', () => { + let message: PinpointInAppMessage; + beforeEach(() => { + message = cloneDeep(pinpointInAppMessage); + clearMemo(); + }); + + test('checks if event attributes matches a Pinpoint message', () => { + const matchingEvent: InAppMessagingEvent = { + name: 'action.taken', + attributes: { + favoriteFood: 'pizza', + favoriteAnimal: 'dog', + favoriteHobby: 'skydiving', + }, + }; + const nonMatchingEvent: InAppMessagingEvent = { + name: 'action.taken', + attributes: { + favoriteFood: 'pizza', + favoriteAnimal: 'monkey', + }, + }; + const missingAttributesEvent: InAppMessagingEvent = { + name: 'action.taken', + attributes: { favoriteFood: 'sushi' }, + }; + const noAttributesEvent: InAppMessagingEvent = { name: 'action.taken' }; + + // Everything matches if there are no attributes on the message + expect(matchesAttributes(message, matchingEvent)).toBe(true); + expect(matchesAttributes(message, nonMatchingEvent)).toBe(true); + expect(matchesAttributes(message, missingAttributesEvent)).toBe(true); + expect(matchesAttributes(message, noAttributesEvent)).toBe(true); + + clearMemo(); + + message.Schedule.EventFilter.Dimensions.Attributes = { + favoriteFood: { Values: ['pizza', 'sushi'] }, + favoriteAnimal: { Values: ['dog', 'giraffe'] }, + }; + + expect(matchesAttributes(message, matchingEvent)).toBe(true); + expect(matchesAttributes(message, nonMatchingEvent)).toBe(false); + expect(matchesAttributes(message, missingAttributesEvent)).toBe(false); + expect(matchesAttributes(message, noAttributesEvent)).toBe(false); + }); + + test('memoizes matches', () => { + const event: InAppMessagingEvent = { + name: 'action.taken', + attributes: { favoriteFood: 'sushi' }, + }; + message.Schedule.EventFilter.Dimensions.Attributes = { + favoriteFood: { Values: ['pizza', 'sushi'] }, + }; + + expect(matchesAttributes(message, event)).toBe(true); + + // This is a contrived way of validating the memo logic and should never happen in practice + message.Schedule.EventFilter.Dimensions.Attributes = { + favoriteFood: { Values: ['pizza'] }, + }; + + expect(matchesAttributes(message, event)).toBe(true); + + clearMemo(); + + expect(matchesAttributes(message, event)).toBe(false); + }); + }); + + describe('matchesMetrics', () => { + let message: PinpointInAppMessage; + beforeEach(() => { + message = cloneDeep(pinpointInAppMessage); + clearMemo(); + }); + + test('checks if event metrics matches a Pinpoint message', () => { + const matchingEvent: InAppMessagingEvent = { + name: 'action.taken', + metrics: { + lotSize: 2000, + yearBuilt: 2000, + bedrooms: 3, + bathrooms: 2, + listPrice: 600000, + viewed: 300, + }, + }; + const nonMatchingEvent: InAppMessagingEvent = { + name: 'action.taken', + metrics: { + lotSize: 2000, + yearBuilt: 2000, + bedrooms: 3, + bathrooms: 2, + listPrice: 700000, + }, + }; + const missingMetricsEvent: InAppMessagingEvent = { + name: 'action.taken', + metrics: { + lotSize: 2000, + yearBuilt: 2000, + }, + }; + const noMetricsEvent: InAppMessagingEvent = { name: 'action.taken' }; + + // Everything matches if there are no metrics on the message + expect(matchesMetrics(message, matchingEvent)).toBe(true); + expect(matchesMetrics(message, nonMatchingEvent)).toBe(true); + expect(matchesMetrics(message, missingMetricsEvent)).toBe(true); + expect(matchesMetrics(message, noMetricsEvent)).toBe(true); + + clearMemo(); + + message.Schedule.EventFilter.Dimensions.Metrics = { + lotSize: { ComparisonOperator: 'GREATER_THAN', Value: 1000 }, + yearBuilt: { ComparisonOperator: 'EQUAL', Value: 2000 }, + bedrooms: { ComparisonOperator: 'LESS_THAN_OR_EQUAL', Value: 3 }, + bathrooms: { ComparisonOperator: 'GREATER_THAN_OR_EQUAL', Value: 1 }, + listPrice: { ComparisonOperator: 'LESS_THAN', Value: 700000 }, + }; + + expect(matchesMetrics(message, matchingEvent)).toBe(true); + expect(matchesMetrics(message, nonMatchingEvent)).toBe(false); + expect(matchesMetrics(message, missingMetricsEvent)).toBe(false); + expect(matchesMetrics(message, noMetricsEvent)).toBe(false); + + clearMemo(); + + message.Schedule.EventFilter.Dimensions.Metrics = { + lotSize: { ComparisonOperator: 'GREATER_OR_LESS_THAN', Value: 1000 }, + }; + + expect(matchesMetrics(message, matchingEvent)).toBe(false); + }); + + test('memoizes matches', () => { + const event: InAppMessagingEvent = { + name: 'action.taken', + metrics: { lotSize: 2000 }, + }; + message.Schedule.EventFilter.Dimensions.Metrics = { + lotSize: { ComparisonOperator: 'GREATER_THAN', Value: 1000 }, + }; + + expect(matchesMetrics(message, event)).toBe(true); + + // This is a contrived way of validating the memo logic and should never happen in practice + message.Schedule.EventFilter.Dimensions.Metrics = { + lotSize: { ComparisonOperator: 'LESS_THAN', Value: 1000 }, + }; + + expect(matchesMetrics(message, event)).toBe(true); + + clearMemo(); + + expect(matchesMetrics(message, event)).toBe(false); + }); + }); + + test('isBeforeEndDate checks if a message is still not yet at its end', () => { + const message = cloneDeep(pinpointInAppMessage); + + expect(isBeforeEndDate(message)).toBe(false); + + // Set the end date to 24 hours from now + message.Schedule.EndDate = new Date( + new Date().getTime() + HOUR_IN_MS * 24 + ).toISOString(); + + expect(isBeforeEndDate(message)).toBe(true); + + message.Schedule.EndDate = null; + + expect(isBeforeEndDate(message)).toBe(true); + }); + + test('extractContent extracts Pinpoint content into a normalized shape', () => { + const message = cloneDeep(pinpointInAppMessage); + + expect(extractContent(message)).toStrictEqual(extractedContent); + }); + + test('extractMetadata extracts Pinpoint metadata into a flat object', () => { + const message = cloneDeep(pinpointInAppMessage); + + expect(extractMetadata(message)).toStrictEqual(extractedMetadata); + }); +}); diff --git a/packages/notifications/__tests__/InAppMessaging/eventListeners.test.ts b/packages/notifications/__tests__/InAppMessaging/eventListeners.test.ts new file mode 100644 index 00000000000..94b8adca63d --- /dev/null +++ b/packages/notifications/__tests__/InAppMessaging/eventListeners.test.ts @@ -0,0 +1,109 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { InAppMessageInteractionEvent } from '../../src/InAppMessaging'; +import { inAppMessages } from '../../__mocks__/data'; + +describe('Interaction event listeners', () => { + const messageReceivedHandler = jest.fn(); + const messageDisplayedHandler = jest.fn(); + const messageDismissedHandler = jest.fn(); + const messageActionTakenHandler = jest.fn(); + const [message] = inAppMessages; + let addMessageInteractionEventListener, + notifyMessageInteractionEventListeners; + beforeEach(() => { + jest.resetModules(); + jest.clearAllMocks(); + ({ + addMessageInteractionEventListener, + notifyMessageInteractionEventListeners, + } = require('../../src/InAppMessaging/eventListeners')); + }); + + test('can be added', () => { + const listener = addMessageInteractionEventListener( + messageReceivedHandler, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + + expect(listener).toBeDefined(); + }); + + test('can be notified', () => { + addMessageInteractionEventListener( + messageReceivedHandler, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + notifyMessageInteractionEventListeners( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + + expect(messageReceivedHandler).toBeCalled(); + }); + + test('can be removed', () => { + const listener = addMessageInteractionEventListener( + messageReceivedHandler, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + + listener.remove(); + notifyMessageInteractionEventListeners( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + + expect(messageReceivedHandler).not.toBeCalled(); + }); + + test('can be added in multiples', () => { + addMessageInteractionEventListener( + messageDisplayedHandler, + InAppMessageInteractionEvent.MESSAGE_DISPLAYED + ); + addMessageInteractionEventListener( + messageDisplayedHandler, + InAppMessageInteractionEvent.MESSAGE_DISPLAYED + ); + addMessageInteractionEventListener( + messageDismissedHandler, + InAppMessageInteractionEvent.MESSAGE_DISMISSED + ); + addMessageInteractionEventListener( + messageActionTakenHandler, + InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN + ); + notifyMessageInteractionEventListeners( + message, + InAppMessageInteractionEvent.MESSAGE_RECEIVED + ); + notifyMessageInteractionEventListeners( + message, + InAppMessageInteractionEvent.MESSAGE_DISPLAYED + ); + notifyMessageInteractionEventListeners( + message, + InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN + ); + + // no listener added + expect(messageReceivedHandler).toBeCalledTimes(0); + // two listeners added + expect(messageDisplayedHandler).toBeCalledTimes(2); + // listener added but not notified + expect(messageDismissedHandler).toBeCalledTimes(0); + // one listener added + expect(messageActionTakenHandler).toBeCalledTimes(1); + }); +}); diff --git a/packages/notifications/__tests__/Notifications.test.ts b/packages/notifications/__tests__/Notifications.test.ts new file mode 100644 index 00000000000..d0cddf362e4 --- /dev/null +++ b/packages/notifications/__tests__/Notifications.test.ts @@ -0,0 +1,51 @@ +/* + * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with + * the License. A copy of the License is located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + */ +import { Amplify } from '@aws-amplify/core'; +import Notifications from '../src/Notifications'; +import { adhocConfig, awsConfig, notificationsConfig } from '../__mocks__/data'; + +jest.mock('@aws-amplify/core'); + +describe('Notifications', () => { + test('registers with Amplify', () => { + expect(Amplify.register).toBeCalledWith(Notifications); + }); + + test('returns the correct module name', () => { + expect(Notifications.getModuleName()).toBe('Notifications'); + }); + + test('is constructed with InAppMessaging', () => { + expect(Notifications.InAppMessaging).toBeDefined(); + }); + + describe('configure', () => { + test('can be called without input', () => { + const config = Notifications.configure(); + + expect(config).toStrictEqual({}); + }); + + test('works with aws-exports', () => { + const config = Notifications.configure(awsConfig); + + expect(config).toStrictEqual(notificationsConfig); + }); + + test('works with adhoc config', () => { + const config = Notifications.configure(adhocConfig); + + expect(config).toStrictEqual(adhocConfig.Notifications); + }); + }); +}); diff --git a/packages/notifications/package.json b/packages/notifications/package.json index d223532a1e8..00ff29fbdd3 100644 --- a/packages/notifications/package.json +++ b/packages/notifications/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/notifications", - "version": "0.1.0", + "version": "0.2.0", "description": "Notifications category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -16,7 +16,7 @@ "access": "public" }, "scripts": { - "test": "tslint 'src/**/*.ts' && jest -w 1 --coverage --passWithNoTests", + "test": "tslint 'src/**/*.ts' && jest -w 1 --coverage", "test:watch": "tslint 'src/**/*.ts' && jest -w 1 --watch", "build-with-test": "npm run clean && npm test && tsc && webpack", "build:cjs": "node ./build es5 && webpack && webpack --config ./webpack.config.dev.js", @@ -42,8 +42,8 @@ }, "homepage": "https://docs.amplify.aws/", "dependencies": { - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", "@aws-sdk/client-pinpoint": "^3.33.0", "lodash": "^4.17.21", "uuid": "^3.2.1" diff --git a/packages/notifications/src/InAppMessaging/SessionTracker/SessionTracker.ts b/packages/notifications/src/InAppMessaging/SessionTracker/SessionTracker.ts index 1df49ece6df..fb96654dc89 100644 --- a/packages/notifications/src/InAppMessaging/SessionTracker/SessionTracker.ts +++ b/packages/notifications/src/InAppMessaging/SessionTracker/SessionTracker.ts @@ -10,12 +10,71 @@ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions * and limitations under the License. */ - +import { ConsoleLogger as Logger } from '@aws-amplify/core'; import noop from 'lodash/noop'; -import { SessionStateChangeHandler, SessionTrackerInterface } from './types'; +import { + SessionState, + SessionStateChangeHandler, + SessionTrackerInterface, +} from './types'; + +// Per https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API +let hidden: string; +let visibilityChange: string; + +if (document) { + if (typeof document.hidden !== 'undefined') { + hidden = 'hidden'; + visibilityChange = 'visibilitychange'; + } else if (typeof document['msHidden'] !== 'undefined') { + hidden = 'msHidden'; + visibilityChange = 'msvisibilitychange'; + } else if (typeof document['webkitHidden'] !== 'undefined') { + hidden = 'webkitHidden'; + visibilityChange = 'webkitvisibilitychange'; + } +} + +const logger = new Logger('InAppMessagingSessionTracker'); export default class SessionTracker implements SessionTrackerInterface { - constructor(sessionStateChangeHandler: SessionStateChangeHandler = noop) {} - start = noop as SessionTrackerInterface['start']; - end = noop as SessionTrackerInterface['end']; + private sessionStateChangeHandler: SessionStateChangeHandler; + + constructor(sessionStateChangeHandler: SessionStateChangeHandler = noop) { + this.sessionStateChangeHandler = sessionStateChangeHandler; + } + + start = (): SessionState => { + document?.addEventListener(visibilityChange, this.visibilityChangeHandler); + return this.getSessionState(); + }; + + end = (): SessionState => { + document?.removeEventListener( + visibilityChange, + this.visibilityChangeHandler + ); + return this.getSessionState(); + }; + + private getSessionState = (): SessionState => { + if (document && !document[hidden]) { + return 'started'; + } + // If, for any reason, document is undefined the session will never start + return 'ended'; + }; + + private visibilityChangeHandler = () => { + if (!document) { + return; + } + if (document[hidden]) { + logger.debug('App is now hidden'); + this.sessionStateChangeHandler('ended'); + } else { + logger.debug('App is now visible'); + this.sessionStateChangeHandler('started'); + } + }; } diff --git a/packages/predictions/CHANGELOG.md b/packages/predictions/CHANGELOG.md index 20529f8412e..553ffa8458f 100644 --- a/packages/predictions/CHANGELOG.md +++ b/packages/predictions/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.28...@aws-amplify/predictions@4.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/predictions + +## [4.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.27...@aws-amplify/predictions@4.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/predictions + +## [4.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.26...@aws-amplify/predictions@4.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/predictions + ## [4.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/predictions@4.0.25...@aws-amplify/predictions@4.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/predictions diff --git a/packages/predictions/package.json b/packages/predictions/package.json index 850801bd54b..62ab7b2eb40 100644 --- a/packages/predictions/package.json +++ b/packages/predictions/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/predictions", - "version": "4.0.26", + "version": "4.0.29", "description": "Machine learning category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -40,8 +40,8 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8", - "@aws-amplify/storage": "4.4.9", + "@aws-amplify/core": "4.3.11", + "@aws-amplify/storage": "4.4.12", "@aws-sdk/client-comprehend": "3.6.1", "@aws-sdk/client-polly": "3.6.1", "@aws-sdk/client-rekognition": "3.6.1", diff --git a/packages/pubsub/CHANGELOG.md b/packages/pubsub/CHANGELOG.md index 6dd90035e64..22a7801f01e 100644 --- a/packages/pubsub/CHANGELOG.md +++ b/packages/pubsub/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.2.5](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.2.4...@aws-amplify/pubsub@4.2.5) (2021-12-16) + +### Bug Fixes + +- **@aws-amplify/api-graphql:** Fix webpack build ([#9358](https://github.com/aws-amplify/amplify-js/issues/9358)) ([73587d7](https://github.com/aws-amplify/amplify-js/commit/73587d78fc4feba39d5a527bfe2c790935653fd3)) + +## [4.2.4](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.2.3...@aws-amplify/pubsub@4.2.4) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/pubsub + +## [4.2.3](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.2.2...@aws-amplify/pubsub@4.2.3) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/pubsub + ## [4.2.2](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pubsub@4.2.1...@aws-amplify/pubsub@4.2.2) (2021-11-18) **Note:** Version bump only for package @aws-amplify/pubsub diff --git a/packages/pubsub/package.json b/packages/pubsub/package.json index ccd5beb5114..7f891a3ba56 100644 --- a/packages/pubsub/package.json +++ b/packages/pubsub/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/pubsub", - "version": "4.2.2", + "version": "4.2.5", "description": "Pubsub category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -45,10 +45,10 @@ "cpx": "^1.5.0" }, "dependencies": { - "@aws-amplify/auth": "4.3.16", - "@aws-amplify/cache": "4.0.28", - "@aws-amplify/core": "4.3.8", - "graphql": "14.0.0", + "@aws-amplify/auth": "4.3.19", + "@aws-amplify/cache": "4.0.31", + "@aws-amplify/core": "4.3.11", + "graphql": "15.8.0", "paho-mqtt": "^1.1.0", "uuid": "^3.2.1", "zen-observable-ts": "0.8.19" diff --git a/packages/pushnotification/CHANGELOG.md b/packages/pushnotification/CHANGELOG.md index 197a7ffb27f..64edd591e50 100644 --- a/packages/pushnotification/CHANGELOG.md +++ b/packages/pushnotification/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.3.8](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pushnotification@4.3.7...@aws-amplify/pushnotification@4.3.8) (2021-12-16) + +### Bug Fixes + +- **@aws-amplify/pushnotification:** make eligible variables final ([#9301](https://github.com/aws-amplify/amplify-js/issues/9301)) ([ae11b53](https://github.com/aws-amplify/amplify-js/commit/ae11b53f837fe13fca52cae771a4cba06306bc0b)) + +## [4.3.7](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pushnotification@4.3.6...@aws-amplify/pushnotification@4.3.7) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/pushnotification + +## [4.3.6](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pushnotification@4.3.5...@aws-amplify/pushnotification@4.3.6) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/pushnotification + ## [4.3.5](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/pushnotification@4.3.4...@aws-amplify/pushnotification@4.3.5) (2021-11-18) **Note:** Version bump only for package @aws-amplify/pushnotification diff --git a/packages/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java b/packages/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java index 9b3551d5f80..e9e4cb55942 100644 --- a/packages/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java +++ b/packages/pushnotification/android/src/main/java/com/amazonaws/amplify/pushnotification/RNPushNotificationMessagingService.java @@ -71,7 +71,7 @@ public void onMessageReceived(RemoteMessage remoteMessage) { handler.post(new Runnable() { public void run() { // Construct and load our normal React JS code bundle - ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager(); + final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager(); ReactContext context = mReactInstanceManager.getCurrentReactContext(); // If it's constructed, send a notification if (context != null) { @@ -186,7 +186,7 @@ public void onNewToken(String refreshedToken) { handler.post(new Runnable() { public void run() { // Construct and load our normal React code bundle - ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager(); + final ReactInstanceManager mReactInstanceManager = ((ReactApplication) getApplication()).getReactNativeHost().getReactInstanceManager(); ReactContext context = mReactInstanceManager.getCurrentReactContext(); // If it's constructed, send a notification if (context != null) { diff --git a/packages/pushnotification/package.json b/packages/pushnotification/package.json index 226a2ae90c8..98e45f9c502 100644 --- a/packages/pushnotification/package.json +++ b/packages/pushnotification/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/pushnotification", - "version": "4.3.5", + "version": "4.3.8", "description": "Push notifications category of aws-amplify", "main": "./lib/index.js", "module": "./lib/index.js", @@ -46,7 +46,7 @@ "webpack": "^3.5.5" }, "dependencies": { - "@aws-amplify/core": "4.3.8", + "@aws-amplify/core": "4.3.11", "@react-native-community/push-notification-ios": "1.0.3" }, "peerdependencies": { diff --git a/packages/storage/CHANGELOG.md b/packages/storage/CHANGELOG.md index b46910fdc20..f1057bd912a 100644 --- a/packages/storage/CHANGELOG.md +++ b/packages/storage/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.4.12](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/storage@4.4.11...@aws-amplify/storage@4.4.12) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/storage + +## [4.4.11](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/storage@4.4.10...@aws-amplify/storage@4.4.11) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/storage + +## [4.4.10](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/storage@4.4.9...@aws-amplify/storage@4.4.10) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/storage + ## [4.4.9](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/storage@4.4.8...@aws-amplify/storage@4.4.9) (2021-11-18) **Note:** Version bump only for package @aws-amplify/storage diff --git a/packages/storage/package.json b/packages/storage/package.json index a4cee4729ad..d1adea81061 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/storage", - "version": "4.4.9", + "version": "4.4.12", "description": "Storage category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,7 +41,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8", + "@aws-amplify/core": "4.3.11", "@aws-sdk/client-s3": "3.6.1", "@aws-sdk/s3-request-presigner": "3.6.1", "@aws-sdk/util-create-request": "3.6.1", diff --git a/packages/xr/CHANGELOG.md b/packages/xr/CHANGELOG.md index 8b746cad492..eea0f74e4f2 100644 --- a/packages/xr/CHANGELOG.md +++ b/packages/xr/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [3.0.29](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/xr@3.0.28...@aws-amplify/xr@3.0.29) (2021-12-16) + +**Note:** Version bump only for package @aws-amplify/xr + +## [3.0.28](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/xr@3.0.27...@aws-amplify/xr@3.0.28) (2021-12-03) + +**Note:** Version bump only for package @aws-amplify/xr + +## [3.0.27](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/xr@3.0.26...@aws-amplify/xr@3.0.27) (2021-12-02) + +**Note:** Version bump only for package @aws-amplify/xr + ## [3.0.26](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/xr@3.0.25...@aws-amplify/xr@3.0.26) (2021-11-18) **Note:** Version bump only for package @aws-amplify/xr diff --git a/packages/xr/package.json b/packages/xr/package.json index 3e0334f0177..75f8927fde1 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@aws-amplify/xr", - "version": "3.0.26", + "version": "3.0.29", "description": "XR category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js", @@ -41,7 +41,7 @@ }, "homepage": "https://aws-amplify.github.io/", "dependencies": { - "@aws-amplify/core": "4.3.8" + "@aws-amplify/core": "4.3.11" }, "jest": { "globals": {