@aws-amplify/notifications 2.0.31-unstable.b1dec5a.0 → 2.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/cjs/pushNotifications/providers/pinpoint/apis/identifyUser.native.js +4 -0
  2. package/dist/cjs/pushNotifications/providers/pinpoint/apis/identifyUser.native.js.map +1 -1
  3. package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js +19 -10
  4. package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js.map +1 -1
  5. package/dist/cjs/pushNotifications/providers/pinpoint/utils/index.js +5 -1
  6. package/dist/cjs/pushNotifications/providers/pinpoint/utils/index.js.map +1 -1
  7. package/dist/cjs/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.js +31 -0
  8. package/dist/cjs/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.js.map +1 -0
  9. package/dist/esm/pushNotifications/providers/pinpoint/apis/identifyUser.native.mjs +6 -1
  10. package/dist/esm/pushNotifications/providers/pinpoint/apis/identifyUser.native.mjs.map +1 -1
  11. package/dist/esm/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.mjs +20 -10
  12. package/dist/esm/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.mjs.map +1 -1
  13. package/dist/esm/pushNotifications/providers/pinpoint/types/index.d.ts +1 -1
  14. package/dist/esm/pushNotifications/providers/pinpoint/types/pushNotifications.d.ts +6 -0
  15. package/dist/esm/pushNotifications/providers/pinpoint/utils/index.d.ts +1 -0
  16. package/dist/esm/pushNotifications/providers/pinpoint/utils/index.mjs +1 -0
  17. package/dist/esm/pushNotifications/providers/pinpoint/utils/index.mjs.map +1 -1
  18. package/dist/esm/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.d.ts +4 -0
  19. package/dist/esm/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.mjs +28 -0
  20. package/dist/esm/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.mjs.map +1 -0
  21. package/package.json +104 -104
  22. package/src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts +13 -2
  23. package/src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts +22 -12
  24. package/src/pushNotifications/providers/pinpoint/types/index.ts +5 -1
  25. package/src/pushNotifications/providers/pinpoint/types/pushNotifications.ts +9 -0
  26. package/src/pushNotifications/providers/pinpoint/utils/index.ts +5 -0
  27. package/src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.ts +38 -0
@@ -14,6 +14,10 @@ const identifyUser = async ({ userId, userProfile, options, }) => {
14
14
  const { credentials, identityId } = await (0, utils_2.resolveCredentials)();
15
15
  const { appId, region } = (0, utils_3.resolveConfig)();
16
16
  const { address, optOut, userAttributes } = options ?? {};
17
+ if (!(await (0, pinpoint_1.getEndpointId)(appId, 'PushNotification'))) {
18
+ // if there is no cached endpoint id, wait for successful endpoint creation before continuing
19
+ await (0, utils_3.getInflightDeviceRegistration)();
20
+ }
17
21
  await (0, pinpoint_1.updateEndpoint)({
18
22
  address,
19
23
  channelType: (0, utils_3.getChannelType)(),
@@ -1 +1 @@
1
- {"version":3,"file":"identifyUser.native.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.identifyUser = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst errorHelpers_1 = require(\"../../../errors/errorHelpers\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst identifyUser = async ({ userId, userProfile, options, }) => {\n (0, errorHelpers_1.assertIsInitialized)();\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n const { address, optOut, userAttributes } = options ?? {};\n await (0, pinpoint_1.updateEndpoint)({\n address,\n channelType: (0, utils_3.getChannelType)(),\n optOut,\n appId,\n category: 'PushNotification',\n credentials,\n identityId,\n region,\n userAttributes,\n userId,\n userProfile,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.IdentifyUser),\n });\n};\nexports.identifyUser = identifyUser;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;AAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC7E,MAAM,cAAc,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,KAAK;AAClE,IAAI,IAAI,cAAc,CAAC,mBAAmB,GAAG,CAAC;AAC9C,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,OAAO,CAAC,kBAAkB,GAAG,CAAC;AAChF,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,CAAC;AAC3D,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;AAC9D,IAAI,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE;AACzC,QAAQ,OAAO;AACf,QAAQ,WAAW,EAAE,IAAI,OAAO,CAAC,cAAc,GAAG;AAClD,QAAQ,MAAM;AACd,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,MAAM;AACd,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,kCAAkC,EAAE,OAAO,CAAC,sBAAsB,CAAC,YAAY,CAAC;AACpH,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
1
+ {"version":3,"file":"identifyUser.native.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.identifyUser = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst errorHelpers_1 = require(\"../../../errors/errorHelpers\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst identifyUser = async ({ userId, userProfile, options, }) => {\n (0, errorHelpers_1.assertIsInitialized)();\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n const { address, optOut, userAttributes } = options ?? {};\n if (!(await (0, pinpoint_1.getEndpointId)(appId, 'PushNotification'))) {\n // if there is no cached endpoint id, wait for successful endpoint creation before continuing\n await (0, utils_3.getInflightDeviceRegistration)();\n }\n await (0, pinpoint_1.updateEndpoint)({\n address,\n channelType: (0, utils_3.getChannelType)(),\n optOut,\n appId,\n category: 'PushNotification',\n credentials,\n identityId,\n region,\n userAttributes,\n userId,\n userProfile,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString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AQ,MAAM;AACd,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,MAAM;AACd,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,kCAAkC,EAAE,OAAO,CAAC,sBAAsB,CAAC,YAAY,CAAC;AACpH,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,YAAY,GAAG,YAAY;;"}
@@ -130,15 +130,24 @@ const addAnalyticsListeners = () => {
130
130
  const registerDevice = async (address) => {
131
131
  const { credentials, identityId } = await (0, utils_2.resolveCredentials)();
132
132
  const { appId, region } = (0, utils_3.resolveConfig)();
133
- await (0, pinpoint_1.updateEndpoint)({
134
- address,
135
- appId,
136
- category: 'PushNotification',
137
- credentials,
138
- region,
139
- channelType: (0, utils_3.getChannelType)(),
140
- identityId,
141
- userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),
142
- });
133
+ try {
134
+ await (0, pinpoint_1.updateEndpoint)({
135
+ address,
136
+ appId,
137
+ category: 'PushNotification',
138
+ credentials,
139
+ region,
140
+ channelType: (0, utils_3.getChannelType)(),
141
+ identityId,
142
+ userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),
143
+ });
144
+ // always resolve inflight device registration promise here even though the promise is only awaited on by
145
+ // `identifyUser` when no endpoint is found in the cache
146
+ (0, utils_3.resolveInflightDeviceRegistration)();
147
+ }
148
+ catch (underlyingError) {
149
+ (0, utils_3.rejectInflightDeviceRegistration)(underlyingError);
150
+ throw underlyingError;
151
+ }
143
152
  };
144
153
  //# sourceMappingURL=initializePushNotifications.native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initializePushNotifications.native.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.initializePushNotifications = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = (0, react_native_1.loadAmplifyPushNotification)();\nconst logger = new core_1.ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nconst initializePushNotifications = () => {\n if ((0, utils_2.isInitialized)()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n (0, utils_2.initialize)();\n};\nexports.initializePushNotifications = initializePushNotifications;\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_resolve, reject) => {\n setTimeout(() => {\n reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));\n }, BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n (0, eventListeners_1.notifyEventListeners)('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n launchNotificationOpenedListener = undefined;\n })\n : undefined;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if ((0, utils_2.getToken)() === token) {\n return;\n }\n (0, utils_2.setToken)(token);\n (0, eventListeners_1.notifyEventListeners)('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n (0, eventListeners_1.addEventListener)('backgroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_background'));\n (0, eventListeners_1.addEventListener)('foregroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_foreground'));\n launchNotificationOpenedListenerRemover = (0, eventListeners_1.addEventListener)('launchNotificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // once we are done with it we can remove the listener\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n (0, eventListeners_1.addEventListener)('notificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n await (0, pinpoint_1.updateEndpoint)({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: (0, utils_3.getChannelType)(),\n identityId,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),\n });\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,KAAK,CAAC,CAAC;AAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,gDAAgD,CAAC,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../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.initializePushNotifications = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = (0, react_native_1.loadAmplifyPushNotification)();\nconst logger = new core_1.ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nconst initializePushNotifications = () => {\n if ((0, utils_2.isInitialized)()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n (0, utils_2.initialize)();\n};\nexports.initializePushNotifications = initializePushNotifications;\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_resolve, reject) => {\n setTimeout(() => {\n reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));\n }, BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n (0, eventListeners_1.notifyEventListeners)('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n launchNotificationOpenedListener = undefined;\n })\n : undefined;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if ((0, utils_2.getToken)() === token) {\n return;\n }\n (0, utils_2.setToken)(token);\n (0, eventListeners_1.notifyEventListeners)('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n (0, eventListeners_1.addEventListener)('backgroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_background'));\n (0, eventListeners_1.addEventListener)('foregroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_foreground'));\n launchNotificationOpenedListenerRemover = (0, eventListeners_1.addEventListener)('launchNotificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // once we are done with it we can remove the listener\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n (0, eventListeners_1.addEventListener)('notificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n try {\n await (0, pinpoint_1.updateEndpoint)({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: (0, utils_3.getChannelType)(),\n identityId,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),\n });\n // always resolve inflight device registration promise here even though the promise is only awaited on by\n // `identifyUser` when no endpoint is found in the cache\n (0, utils_3.resolveInflightDeviceRegistration)();\n }\n catch (underlyingError) {\n (0, utils_3.rejectInflightDeviceRegistration)(underlyingError);\n throw underlyingError;\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,O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WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,cAAc,GAAG;AACtD,YAAY,UAAU;AACtB,YAAY,cAAc,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,kCAAkC,EAAE,OAAO,CAAC,sBAAsB,CAAC,2BAA2B,CAAC;AACvI,SAAS,CAAC,CAAC;AACX;AACA;AACA,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,iCAAiC,GAAG,CAAC;AACzD,KAAK;AACL,IAAI,OAAO,eAAe,EAAE;AAC5B,QAAQ,IAAI,OAAO,CAAC,gCAAgC,EAAE,eAAe,CAAC,CAAC;AACvE,QAAQ,MAAM,eAAe,CAAC;AAC9B,KAAK;AACL,CAAC;;"}
@@ -3,13 +3,17 @@
3
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveConfig = exports.getChannelType = exports.getAnalyticsEvent = exports.createMessageEventRecorder = void 0;
6
+ exports.resolveConfig = exports.resolveInflightDeviceRegistration = exports.rejectInflightDeviceRegistration = exports.getInflightDeviceRegistration = exports.getChannelType = exports.getAnalyticsEvent = exports.createMessageEventRecorder = void 0;
7
7
  var createMessageEventRecorder_1 = require("./createMessageEventRecorder");
8
8
  Object.defineProperty(exports, "createMessageEventRecorder", { enumerable: true, get: function () { return createMessageEventRecorder_1.createMessageEventRecorder; } });
9
9
  var getAnalyticsEvent_1 = require("./getAnalyticsEvent");
10
10
  Object.defineProperty(exports, "getAnalyticsEvent", { enumerable: true, get: function () { return getAnalyticsEvent_1.getAnalyticsEvent; } });
11
11
  var getChannelType_1 = require("./getChannelType");
12
12
  Object.defineProperty(exports, "getChannelType", { enumerable: true, get: function () { return getChannelType_1.getChannelType; } });
13
+ var inflightDeviceRegistration_1 = require("./inflightDeviceRegistration");
14
+ Object.defineProperty(exports, "getInflightDeviceRegistration", { enumerable: true, get: function () { return inflightDeviceRegistration_1.getInflightDeviceRegistration; } });
15
+ Object.defineProperty(exports, "rejectInflightDeviceRegistration", { enumerable: true, get: function () { return inflightDeviceRegistration_1.rejectInflightDeviceRegistration; } });
16
+ Object.defineProperty(exports, "resolveInflightDeviceRegistration", { enumerable: true, get: function () { return inflightDeviceRegistration_1.resolveInflightDeviceRegistration; } });
13
17
  var resolveConfig_1 = require("./resolveConfig");
14
18
  Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });
15
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveConfig = exports.getChannelType = exports.getAnalyticsEvent = exports.createMessageEventRecorder = void 0;\nvar createMessageEventRecorder_1 = require(\"./createMessageEventRecorder\");\nObject.defineProperty(exports, \"createMessageEventRecorder\", { enumerable: true, get: function () { return createMessageEventRecorder_1.createMessageEventRecorder; } });\nvar getAnalyticsEvent_1 = require(\"./getAnalyticsEvent\");\nObject.defineProperty(exports, \"getAnalyticsEvent\", { enumerable: true, get: function () { return getAnalyticsEvent_1.getAnalyticsEvent; } });\nvar getChannelType_1 = require(\"./getChannelType\");\nObject.defineProperty(exports, \"getChannelType\", { enumerable: true, get: function () { return getChannelType_1.getChannelType; } });\nvar resolveConfig_1 = require(\"./resolveConfig\");\nObject.defineProperty(exports, \"resolveConfig\", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AACzH,IAAI,4BAA4B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC3E,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,4BAA4B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,4BAA4B,CAAC,0BAA0B,CAAC,EAAE,EAAE,CAAC,CAAC;AACzK,IAAI,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AACzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9I,IAAI,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACnD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC;AACrI,IAAI,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACjD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,eAAe,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveConfig = exports.resolveInflightDeviceRegistration = exports.rejectInflightDeviceRegistration = exports.getInflightDeviceRegistration = exports.getChannelType = exports.getAnalyticsEvent = exports.createMessageEventRecorder = void 0;\nvar createMessageEventRecorder_1 = require(\"./createMessageEventRecorder\");\nObject.defineProperty(exports, \"createMessageEventRecorder\", { enumerable: true, get: function () { return createMessageEventRecorder_1.createMessageEventRecorder; } });\nvar getAnalyticsEvent_1 = require(\"./getAnalyticsEvent\");\nObject.defineProperty(exports, \"getAnalyticsEvent\", { enumerable: true, get: function () { return getAnalyticsEvent_1.getAnalyticsEvent; } });\nvar getChannelType_1 = require(\"./getChannelType\");\nObject.defineProperty(exports, \"getChannelType\", { enumerable: true, get: function () { return getChannelType_1.getChannelType; } });\nvar inflightDeviceRegistration_1 = require(\"./inflightDeviceRegistration\");\nObject.defineProperty(exports, \"getInflightDeviceRegistration\", { enumerable: true, get: function () { return inflightDeviceRegistration_1.getInflightDeviceRegistration; } });\nObject.defineProperty(exports, \"rejectInflightDeviceRegistration\", { enumerable: true, get: function () { return inflightDeviceRegistration_1.rejectInflightDeviceRegistration; } });\nObject.defineProperty(exports, \"resolveInflightDeviceRegistration\", { enumerable: true, get: function () { return inflightDeviceRegistration_1.resolveInflightDeviceRegistration; } });\nvar resolveConfig_1 = require(\"./resolveConfig\");\nObject.defineProperty(exports, \"resolveConfig\", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,iCAAiC,GAAG,OAAO,CAAC,gCAAgC,GAAG,OAAO,CAAC,6BAA6B,GAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AACxP,IAAI,4BAA4B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC3E,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE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Ac,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,eAAe,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;;"}
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rejectInflightDeviceRegistration = exports.resolveInflightDeviceRegistration = exports.getInflightDeviceRegistration = void 0;
7
+ const errors_1 = require("../../../errors");
8
+ const inflightDeviceRegistrationResolver = {};
9
+ let inflightDeviceRegistration = new Promise((resolve, reject) => {
10
+ inflightDeviceRegistrationResolver.resolve = resolve;
11
+ inflightDeviceRegistrationResolver.reject = reject;
12
+ });
13
+ const getInflightDeviceRegistration = () => inflightDeviceRegistration;
14
+ exports.getInflightDeviceRegistration = getInflightDeviceRegistration;
15
+ const resolveInflightDeviceRegistration = () => {
16
+ inflightDeviceRegistrationResolver.resolve?.();
17
+ // release promise from memory
18
+ inflightDeviceRegistration = undefined;
19
+ };
20
+ exports.resolveInflightDeviceRegistration = resolveInflightDeviceRegistration;
21
+ const rejectInflightDeviceRegistration = (underlyingError) => {
22
+ inflightDeviceRegistrationResolver.reject?.(new errors_1.PushNotificationError({
23
+ name: 'DeviceRegistrationFailed',
24
+ message: 'Failed to register device for push notifications.',
25
+ underlyingError,
26
+ }));
27
+ // release promise from memory
28
+ inflightDeviceRegistration = undefined;
29
+ };
30
+ exports.rejectInflightDeviceRegistration = rejectInflightDeviceRegistration;
31
+ //# sourceMappingURL=inflightDeviceRegistration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflightDeviceRegistration.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.rejectInflightDeviceRegistration = exports.resolveInflightDeviceRegistration = exports.getInflightDeviceRegistration = void 0;\nconst errors_1 = require(\"../../../errors\");\nconst inflightDeviceRegistrationResolver = {};\nlet inflightDeviceRegistration = new Promise((resolve, reject) => {\n inflightDeviceRegistrationResolver.resolve = resolve;\n inflightDeviceRegistrationResolver.reject = reject;\n});\nconst getInflightDeviceRegistration = () => inflightDeviceRegistration;\nexports.getInflightDeviceRegistration = getInflightDeviceRegistration;\nconst resolveInflightDeviceRegistration = () => {\n inflightDeviceRegistrationResolver.resolve?.();\n // release promise from memory\n inflightDeviceRegistration = undefined;\n};\nexports.resolveInflightDeviceRegistration = resolveInflightDeviceRegistration;\nconst rejectInflightDeviceRegistration = (underlyingError) => {\n inflightDeviceRegistrationResolver.reject?.(new errors_1.PushNotificationError({\n name: 'DeviceRegistrationFailed',\n message: 'Failed to register device for push notifications.',\n underlyingError,\n }));\n // release promise from memory\n inflightDeviceRegistration = undefined;\n};\nexports.rejectInflightDeviceRegistration = rejectInflightDeviceRegistration;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gCAAgC,GAAG,OAAO,CAAC,iCAAiC,GAAG,OAAO,CAAC,6BAA6B,GAAG,KAAK,CAAC,CAAC;AACtI,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,IAAI,0BAA0B,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAClE,IAAI,kCAAkC,CAAC,OAAO,GAAG,OAAO,CAAC;AACzD,IAAI,kCAAkC,CAAC,MAAM,GAAG,MAAM,CAAC;AACvD,CAAC,CAAC,CAAC;AACH,MAAM,6BAA6B,GAAG,MAAM,0BAA0B,CAAC;AACvE,OAAO,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;AACtE,MAAM,iCAAiC,GAAG,MAAM;AAChD,IAAI,kCAAkC,CAAC,OAAO,IAAI,CAAC;AACnD;AACA,IAAI,0BAA0B,GAAG,SAAS,CAAC;AAC3C,CAAC,CAAC;AACF,OAAO,CAAC,iCAAiC,GAAG,iCAAiC,CAAC;AAC9E,MAAM,gCAAgC,GAAG,CAAC,eAAe,KAAK;AAC9D,IAAI,kCAAkC,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,qBAAqB,CAAC;AACnF,QAAQ,IAAI,EAAE,0BAA0B;AACxC,QAAQ,OAAO,EAAE,mDAAmD;AACpE,QAAQ,eAAe;AACvB,KAAK,CAAC,CAAC,CAAC;AACR;AACA,IAAI,0BAA0B,GAAG,SAAS,CAAC;AAC3C,CAAC,CAAC;AACF,OAAO,CAAC,gCAAgC,GAAG,gCAAgC;;"}
@@ -1,10 +1,11 @@
1
1
  import { PushNotificationAction } from '@aws-amplify/core/internals/utils';
2
- import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
2
+ import { getEndpointId, updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
3
3
  import { assertIsInitialized } from '../../../errors/errorHelpers.mjs';
4
4
  import { getPushNotificationUserAgentString } from '../../../utils/getPushNotificationUserAgentString.mjs';
5
5
  import { resolveCredentials } from '../../../utils/resolveCredentials.mjs';
6
6
  import '../utils/createMessageEventRecorder.mjs';
7
7
  import { getChannelType } from '../utils/getChannelType.mjs';
8
+ import { getInflightDeviceRegistration } from '../utils/inflightDeviceRegistration.mjs';
8
9
  import { resolveConfig } from '../utils/resolveConfig.mjs';
9
10
 
10
11
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -14,6 +15,10 @@ const identifyUser = async ({ userId, userProfile, options, }) => {
14
15
  const { credentials, identityId } = await resolveCredentials();
15
16
  const { appId, region } = resolveConfig();
16
17
  const { address, optOut, userAttributes } = options ?? {};
18
+ if (!(await getEndpointId(appId, 'PushNotification'))) {
19
+ // if there is no cached endpoint id, wait for successful endpoint creation before continuing
20
+ await getInflightDeviceRegistration();
21
+ }
17
22
  await updateEndpoint({
18
23
  address,
19
24
  channelType: getChannelType(),
@@ -1 +1 @@
1
- {"version":3,"file":"identifyUser.native.mjs","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PushNotificationAction } from '@aws-amplify/core/internals/utils';\nimport { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { assertIsInitialized } from '../../../errors/errorHelpers';\nimport { getPushNotificationUserAgentString, resolveCredentials, } from '../../../utils';\nimport { getChannelType, resolveConfig } from '../utils';\nexport const identifyUser = async ({ userId, userProfile, options, }) => {\n assertIsInitialized();\n const { credentials, identityId } = await resolveCredentials();\n const { appId, region } = resolveConfig();\n const { address, optOut, userAttributes } = options ?? {};\n await updateEndpoint({\n address,\n channelType: getChannelType(),\n optOut,\n appId,\n category: 'PushNotification',\n credentials,\n identityId,\n region,\n userAttributes,\n userId,\n userProfile,\n userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.IdentifyUser),\n });\n};\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AAMY,MAAC,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,KAAK;AACzE,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE,CAAC;AACnE,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;AAC9D,IAAI,MAAM,cAAc,CAAC;AACzB,QAAQ,OAAO;AACf,QAAQ,WAAW,EAAE,cAAc,EAAE;AACrC,QAAQ,MAAM;AACd,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,MAAM;AACd,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,kCAAkC,CAAC,sBAAsB,CAAC,YAAY,CAAC;AAC/F,KAAK,CAAC,CAAC;AACP;;;;"}
1
+ {"version":3,"file":"identifyUser.native.mjs","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PushNotificationAction } from '@aws-amplify/core/internals/utils';\nimport { getEndpointId, updateEndpoint, } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { assertIsInitialized } from '../../../errors/errorHelpers';\nimport { getPushNotificationUserAgentString, resolveCredentials, } from '../../../utils';\nimport { getChannelType, getInflightDeviceRegistration, resolveConfig, } from '../utils';\nexport const identifyUser = async ({ userId, userProfile, options, }) => {\n assertIsInitialized();\n const { credentials, identityId } = await resolveCredentials();\n const { appId, region } = resolveConfig();\n const { address, optOut, userAttributes } = options ?? {};\n if (!(await getEndpointId(appId, 'PushNotification'))) {\n // if there is no cached endpoint id, wait for successful endpoint creation before continuing\n await getInflightDeviceRegistration();\n }\n await updateEndpoint({\n address,\n channelType: getChannelType(),\n optOut,\n appId,\n category: 'PushNotification',\n credentials,\n identityId,\n region,\n userAttributes,\n userId,\n userProfile,\n userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.IdentifyUser),\n });\n};\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAMY,MAAC,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,GAAG,KAAK;AACzE,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE,CAAC;AACnE,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;AAC9D,IAAI,IAAI,EAAE,MAAM,aAAa,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE;AAC3D;AACA,QAAQ,MAAM,6BAA6B,EAAE,CAAC;AAC9C,KAAK;AACL,IAAI,MAAM,cAAc,CAAC;AACzB,QAAQ,OAAO;AACf,QAAQ,WAAW,EAAE,cAAc,EAAE;AACrC,QAAQ,MAAM;AACd,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,MAAM;AACd,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,kCAAkC,CAAC,sBAAsB,CAAC,YAAY,CAAC;AAC/F,KAAK,CAAC,CAAC;AACP;;;;"}
@@ -9,6 +9,7 @@ import { resolveCredentials } from '../../../utils/resolveCredentials.mjs';
9
9
  import { getToken, setToken } from '../../../utils/tokenManager.mjs';
10
10
  import { createMessageEventRecorder } from '../utils/createMessageEventRecorder.mjs';
11
11
  import { getChannelType } from '../utils/getChannelType.mjs';
12
+ import { resolveInflightDeviceRegistration, rejectInflightDeviceRegistration } from '../utils/inflightDeviceRegistration.mjs';
12
13
  import { resolveConfig } from '../utils/resolveConfig.mjs';
13
14
 
14
15
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -131,16 +132,25 @@ const addAnalyticsListeners = () => {
131
132
  const registerDevice = async (address) => {
132
133
  const { credentials, identityId } = await resolveCredentials();
133
134
  const { appId, region } = resolveConfig();
134
- await updateEndpoint({
135
- address,
136
- appId,
137
- category: 'PushNotification',
138
- credentials,
139
- region,
140
- channelType: getChannelType(),
141
- identityId,
142
- userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.InitializePushNotifications),
143
- });
135
+ try {
136
+ await updateEndpoint({
137
+ address,
138
+ appId,
139
+ category: 'PushNotification',
140
+ credentials,
141
+ region,
142
+ channelType: getChannelType(),
143
+ identityId,
144
+ userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.InitializePushNotifications),
145
+ });
146
+ // always resolve inflight device registration promise here even though the promise is only awaited on by
147
+ // `identifyUser` when no endpoint is found in the cache
148
+ resolveInflightDeviceRegistration();
149
+ }
150
+ catch (underlyingError) {
151
+ rejectInflightDeviceRegistration(underlyingError);
152
+ throw underlyingError;
153
+ }
144
154
  };
145
155
 
146
156
  export { initializePushNotifications };
@@ -1 +1 @@
1
- {"version":3,"file":"initializePushNotifications.native.mjs","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { PushNotificationAction } from '@aws-amplify/core/internals/utils';\nimport { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { loadAmplifyPushNotification } from '@aws-amplify/react-native';\nimport { addEventListener, notifyEventListeners, notifyEventListenersAndAwaitHandlers, } from '../../../../eventListeners';\nimport { getPushNotificationUserAgentString, getToken, initialize, isInitialized, resolveCredentials, setToken, } from '../../../utils';\nimport { createMessageEventRecorder, getChannelType, resolveConfig, } from '../utils';\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = loadAmplifyPushNotification();\nconst logger = new ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nexport const initializePushNotifications = () => {\n if (isInitialized()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n initialize();\n};\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await notifyEventListenersAndAwaitHandlers('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n notifyEventListenersAndAwaitHandlers('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_resolve, reject) => {\n setTimeout(() => {\n reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));\n }, BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n notifyEventListeners('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n notifyEventListeners('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n launchNotificationOpenedListener = undefined;\n })\n : undefined;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n notifyEventListeners('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if (getToken() === token) {\n return;\n }\n setToken(token);\n notifyEventListeners('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n addEventListener('backgroundMessageReceived', createMessageEventRecorder('received_background'));\n addEventListener('foregroundMessageReceived', createMessageEventRecorder('received_foreground'));\n launchNotificationOpenedListenerRemover = addEventListener('launchNotificationOpened', createMessageEventRecorder('opened_notification', \n // once we are done with it we can remove the listener\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n addEventListener('notificationOpened', createMessageEventRecorder('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await resolveCredentials();\n const { appId, region } = resolveConfig();\n await updateEndpoint({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: getChannelType(),\n identityId,\n userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.InitializePushNotifications),\n });\n};\n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AI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE,CAAC;AACnE,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9C,IAAI,MAAM,cAAc,CAAC;AACzB,QAAQ,OAAO;AACf,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,MAAM;AACd,QAAQ,WAAW,EAAE,cAAc,EAAE;AACrC,QAAQ,UAAU;AAClB,QAAQ,cAAc,EAAE,kCAAkC,CAAC,sBAAsB,CAAC,2BAA2B,CAAC;AAC9G,KAAK,CAAC,CAAC;AACP,CAAC;;;;"}
1
+ {"version":3,"file":"initializePushNotifications.native.mjs","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nimport { PushNotificationAction } from '@aws-amplify/core/internals/utils';\nimport { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { loadAmplifyPushNotification } from '@aws-amplify/react-native';\nimport { addEventListener, notifyEventListeners, notifyEventListenersAndAwaitHandlers, } from '../../../../eventListeners';\nimport { getPushNotificationUserAgentString, getToken, initialize, isInitialized, resolveCredentials, setToken, } from '../../../utils';\nimport { createMessageEventRecorder, getChannelType, rejectInflightDeviceRegistration, resolveConfig, resolveInflightDeviceRegistration, } from '../utils';\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = loadAmplifyPushNotification();\nconst logger = new ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nexport const initializePushNotifications = () => {\n if (isInitialized()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n initialize();\n};\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await notifyEventListenersAndAwaitHandlers('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n notifyEventListenersAndAwaitHandlers('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_resolve, reject) => {\n setTimeout(() => {\n reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));\n }, BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n notifyEventListeners('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n notifyEventListeners('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n launchNotificationOpenedListener = undefined;\n })\n : undefined;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n notifyEventListeners('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if (getToken() === token) {\n return;\n }\n setToken(token);\n notifyEventListeners('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n addEventListener('backgroundMessageReceived', createMessageEventRecorder('received_background'));\n addEventListener('foregroundMessageReceived', createMessageEventRecorder('received_foreground'));\n launchNotificationOpenedListenerRemover = addEventListener('launchNotificationOpened', createMessageEventRecorder('opened_notification', \n // once we are done with it we can remove the listener\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n addEventListener('notificationOpened', createMessageEventRecorder('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await resolveCredentials();\n const { appId, region } = resolveConfig();\n try {\n await updateEndpoint({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: getChannelType(),\n identityId,\n userAgentValue: getPushNotificationUserAgentString(PushNotificationAction.InitializePushNotifications),\n });\n // always resolve inflight device registration promise here even though the promise is only awaited on by\n // `identifyUser` when no endpoint is found in the cache\n resolveInflightDeviceRegistration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C;AACR,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,OAAO,KAAK;AAC1C,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE,CAAC;AACnE,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9C,IAAI,IAAI;AACR,QAAQ,MAAM,cAAc,CAAC;AAC7B,YAAY,OAAO;AACnB,YAAY,KAAK;AACjB,YAAY,QAAQ,EAAE,kBAAkB;AACxC,YAAY,WAAW;AACvB,YAAY,MAAM;AAClB,YAAY,WAAW,EAAE,cAAc,EAAE;AACzC,YAAY,UAAU;AACtB,YAAY,cAAc,EAAE,kCAAkC,CAAC,sBAAsB,CAAC,2BAA2B,CAAC;AAClH,SAAS,CAAC,CAAC;AACX;AACA;AACA,QAAQ,iCAAiC,EAAE,CAAC;AAC5C,KAAK;AACL,IAAI,OAAO,eAAe,EAAE;AAC5B,QAAQ,gCAAgC,CAAC,eAAe,CAAC,CAAC;AAC1D,QAAQ,MAAM,eAAe,CAAC;AAC9B,KAAK;AACL,CAAC;;;;"}
@@ -3,4 +3,4 @@ export { GetBadgeCount, GetLaunchNotification, GetPermissionStatus, IdentifyUser
3
3
  export { IdentifyUserInput, OnNotificationOpenedInput, OnNotificationReceivedInBackgroundInput, OnNotificationReceivedInForegroundInput, OnTokenReceivedInput, RequestPermissionsInput, SetBadgeCountInput, } from './inputs';
4
4
  export { GetLaunchNotificationOutput, GetPermissionStatusOutput, OnNotificationOpenedOutput, OnNotificationReceivedInBackgroundOutput, OnNotificationReceivedInForegroundOutput, OnTokenReceivedOutput, } from './outputs';
5
5
  export { IdentifyUserOptions } from './options';
6
- export { ChannelType } from './pushNotifications';
6
+ export { ChannelType, InflightDeviceRegistration, InflightDeviceRegistrationResolver, } from './pushNotifications';
@@ -1,2 +1,8 @@
1
1
  import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
2
+ import { PushNotificationError } from '../../../errors';
2
3
  export type ChannelType = Parameters<typeof updateEndpoint>[0]['channelType'];
4
+ export type InflightDeviceRegistration = Promise<void> | undefined;
5
+ export interface InflightDeviceRegistrationResolver {
6
+ resolve?(): void;
7
+ reject?(error: PushNotificationError): void;
8
+ }
@@ -1,4 +1,5 @@
1
1
  export { createMessageEventRecorder } from './createMessageEventRecorder';
2
2
  export { getAnalyticsEvent } from './getAnalyticsEvent';
3
3
  export { getChannelType } from './getChannelType';
4
+ export { getInflightDeviceRegistration, rejectInflightDeviceRegistration, resolveInflightDeviceRegistration, } from './inflightDeviceRegistration';
4
5
  export { resolveConfig } from './resolveConfig';
@@ -1,5 +1,6 @@
1
1
  export { createMessageEventRecorder } from './createMessageEventRecorder.mjs';
2
2
  export { getAnalyticsEvent } from './getAnalyticsEvent.mjs';
3
3
  export { getChannelType } from './getChannelType.mjs';
4
+ export { getInflightDeviceRegistration, rejectInflightDeviceRegistration, resolveInflightDeviceRegistration } from './inflightDeviceRegistration.mjs';
4
5
  export { resolveConfig } from './resolveConfig.mjs';
5
6
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,4 @@
1
+ import { InflightDeviceRegistration } from '../types';
2
+ export declare const getInflightDeviceRegistration: () => InflightDeviceRegistration;
3
+ export declare const resolveInflightDeviceRegistration: () => void;
4
+ export declare const rejectInflightDeviceRegistration: (underlyingError: unknown) => void;
@@ -0,0 +1,28 @@
1
+ import { PushNotificationError } from '../../../errors/PushNotificationError.mjs';
2
+ import '../../../errors/errorHelpers.mjs';
3
+
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ const inflightDeviceRegistrationResolver = {};
7
+ let inflightDeviceRegistration = new Promise((resolve, reject) => {
8
+ inflightDeviceRegistrationResolver.resolve = resolve;
9
+ inflightDeviceRegistrationResolver.reject = reject;
10
+ });
11
+ const getInflightDeviceRegistration = () => inflightDeviceRegistration;
12
+ const resolveInflightDeviceRegistration = () => {
13
+ inflightDeviceRegistrationResolver.resolve?.();
14
+ // release promise from memory
15
+ inflightDeviceRegistration = undefined;
16
+ };
17
+ const rejectInflightDeviceRegistration = (underlyingError) => {
18
+ inflightDeviceRegistrationResolver.reject?.(new PushNotificationError({
19
+ name: 'DeviceRegistrationFailed',
20
+ message: 'Failed to register device for push notifications.',
21
+ underlyingError,
22
+ }));
23
+ // release promise from memory
24
+ inflightDeviceRegistration = undefined;
25
+ };
26
+
27
+ export { getInflightDeviceRegistration, rejectInflightDeviceRegistration, resolveInflightDeviceRegistration };
28
+ //# sourceMappingURL=inflightDeviceRegistration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflightDeviceRegistration.mjs","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/inflightDeviceRegistration.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PushNotificationError } from '../../../errors';\nconst inflightDeviceRegistrationResolver = {};\nlet inflightDeviceRegistration = new Promise((resolve, reject) => {\n inflightDeviceRegistrationResolver.resolve = resolve;\n inflightDeviceRegistrationResolver.reject = reject;\n});\nexport const getInflightDeviceRegistration = () => inflightDeviceRegistration;\nexport const resolveInflightDeviceRegistration = () => {\n inflightDeviceRegistrationResolver.resolve?.();\n // release promise from memory\n inflightDeviceRegistration = undefined;\n};\nexport const rejectInflightDeviceRegistration = (underlyingError) => {\n inflightDeviceRegistrationResolver.reject?.(new PushNotificationError({\n name: 'DeviceRegistrationFailed',\n message: 'Failed to register device for push notifications.',\n underlyingError,\n }));\n // release promise from memory\n inflightDeviceRegistration = undefined;\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAEA,MAAM,kCAAkC,GAAG,EAAE,CAAC;AAC9C,IAAI,0BAA0B,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAClE,IAAI,kCAAkC,CAAC,OAAO,GAAG,OAAO,CAAC;AACzD,IAAI,kCAAkC,CAAC,MAAM,GAAG,MAAM,CAAC;AACvD,CAAC,CAAC,CAAC;AACS,MAAC,6BAA6B,GAAG,MAAM,2BAA2B;AAClE,MAAC,iCAAiC,GAAG,MAAM;AACvD,IAAI,kCAAkC,CAAC,OAAO,IAAI,CAAC;AACnD;AACA,IAAI,0BAA0B,GAAG,SAAS,CAAC;AAC3C,EAAE;AACU,MAAC,gCAAgC,GAAG,CAAC,eAAe,KAAK;AACrE,IAAI,kCAAkC,CAAC,MAAM,GAAG,IAAI,qBAAqB,CAAC;AAC1E,QAAQ,IAAI,EAAE,0BAA0B;AACxC,QAAQ,OAAO,EAAE,mDAAmD;AACpE,QAAQ,eAAe;AACvB,KAAK,CAAC,CAAC,CAAC;AACR;AACA,IAAI,0BAA0B,GAAG,SAAS,CAAC;AAC3C;;;;"}
package/package.json CHANGED
@@ -1,106 +1,106 @@
1
1
  {
2
- "name": "@aws-amplify/notifications",
3
- "version": "2.0.31-unstable.b1dec5a.0+b1dec5a",
4
- "description": "Notifications category of aws-amplify",
5
- "main": "./dist/cjs/index.js",
6
- "module": "./dist/esm/index.mjs",
7
- "react-native": "./src/index.ts",
8
- "typings": "./dist/esm/index.d.ts",
9
- "sideEffects": false,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "scripts": {
14
- "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
15
- "test:watch": "tslint 'src/**/*.ts' && jest -w 1 --watch",
16
- "build-with-test": "npm run clean && npm run build",
17
- "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
18
- "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
19
- "build:watch": "npm run build:esm-cjs -- --watch",
20
- "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
21
- "clean": "npm run clean:size && rimraf dist lib lib-esm",
22
- "clean:size": "rimraf dual-publish-tmp tmp*",
23
- "format": "echo \"Not implemented\"",
24
- "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
25
- "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
26
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
27
- },
28
- "typesVersions": {
29
- ">=4.2": {
30
- "in-app-messaging": [
31
- "./dist/esm/inAppMessaging/index.d.ts"
32
- ],
33
- "push-notifications": [
34
- "./dist/esm/pushNotifications/providers/index.d.ts"
35
- ],
36
- "in-app-messaging/pinpoint": [
37
- "./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts"
38
- ],
39
- "push-notifications/pinpoint": [
40
- "./dist/esm/pushNotifications/providers/pinpoint/index.d.ts"
41
- ]
42
- }
43
- },
44
- "exports": {
45
- ".": {
46
- "import": "./dist/esm/index.mjs",
47
- "require": "./dist/cjs/index.js",
48
- "react-native": "./src/index.ts"
49
- },
50
- "./in-app-messaging": {
51
- "types": "./dist/esm/inAppMessaging/index.d.ts",
52
- "import": "./dist/esm/inAppMessaging/index.mjs",
53
- "require": "./dist/cjs/inAppMessaging/index.js",
54
- "react-native": "./src/inAppMessaging/index.ts"
55
- },
56
- "./push-notifications": {
57
- "types": "./dist/esm/pushNotifications/index.d.ts",
58
- "import": "./dist/esm/pushNotifications/index.mjs",
59
- "require": "./dist/cjs/pushNotifications/index.js",
60
- "react-native": "./src/pushNotifications/index.ts"
61
- },
62
- "./in-app-messaging/pinpoint": {
63
- "types": "./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts",
64
- "import": "./dist/esm/inAppMessaging/providers/pinpoint/index.mjs",
65
- "require": "./dist/cjs/inAppMessaging/providers/pinpoint/index.js",
66
- "react-native": "./src/inAppMessaging/providers/pinpoint/index.ts"
67
- },
68
- "./push-notifications/pinpoint": {
69
- "types": "./dist/esm/pushNotifications/providers/pinpoint/index.d.ts",
70
- "import": "./dist/esm/pushNotifications/providers/pinpoint/index.mjs",
71
- "require": "./dist/cjs/pushNotifications/providers/pinpoint/index.js",
72
- "react-native": "./src/pushNotifications/providers/pinpoint/index.ts"
73
- },
74
- "./package.json": "./package.json"
75
- },
76
- "repository": {
77
- "type": "git",
78
- "url": "https://github.com/aws-amplify/amplify-js.git"
79
- },
80
- "author": "Amazon Web Services",
81
- "license": "Apache-2.0",
82
- "bugs": {
83
- "url": "https://github.com/aws/aws-amplify/issues"
84
- },
85
- "homepage": "https://docs.amplify.aws/",
86
- "files": [
87
- "dist/cjs",
88
- "dist/esm",
89
- "src",
90
- "in-app-messaging",
91
- "push-notifications"
92
- ],
93
- "dependencies": {
94
- "lodash": "^4.17.21",
95
- "tslib": "^2.5.0"
96
- },
97
- "peerDependencies": {
98
- "@aws-amplify/core": "6.2.1-unstable.b1dec5a.0+b1dec5a"
99
- },
100
- "devDependencies": {
101
- "@aws-amplify/core": "6.2.1-unstable.b1dec5a.0+b1dec5a",
102
- "@aws-amplify/react-native": "1.1.1-unstable.b1dec5a.0+b1dec5a",
103
- "typescript": "5.0.2"
104
- },
105
- "gitHead": "b1dec5a4872a308a0e84f402e0465208dbfdd0ca"
2
+ "name": "@aws-amplify/notifications",
3
+ "version": "2.0.31",
4
+ "description": "Notifications category of aws-amplify",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.mjs",
7
+ "react-native": "./src/index.ts",
8
+ "typings": "./dist/esm/index.d.ts",
9
+ "sideEffects": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
15
+ "test:watch": "jest -w 1 --watch",
16
+ "build-with-test": "npm run clean && npm run build",
17
+ "build:umd": "webpack && webpack --config ./webpack.config.dev.js",
18
+ "build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
19
+ "build:watch": "npm run build:esm-cjs -- --watch",
20
+ "build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
21
+ "clean": "npm run clean:size && rimraf dist lib lib-esm",
22
+ "clean:size": "rimraf dual-publish-tmp tmp*",
23
+ "format": "echo \"Not implemented\"",
24
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
25
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
26
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
27
+ },
28
+ "typesVersions": {
29
+ ">=4.2": {
30
+ "in-app-messaging": [
31
+ "./dist/esm/inAppMessaging/index.d.ts"
32
+ ],
33
+ "push-notifications": [
34
+ "./dist/esm/pushNotifications/providers/index.d.ts"
35
+ ],
36
+ "in-app-messaging/pinpoint": [
37
+ "./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts"
38
+ ],
39
+ "push-notifications/pinpoint": [
40
+ "./dist/esm/pushNotifications/providers/pinpoint/index.d.ts"
41
+ ]
42
+ }
43
+ },
44
+ "exports": {
45
+ ".": {
46
+ "import": "./dist/esm/index.mjs",
47
+ "require": "./dist/cjs/index.js",
48
+ "react-native": "./src/index.ts"
49
+ },
50
+ "./in-app-messaging": {
51
+ "types": "./dist/esm/inAppMessaging/index.d.ts",
52
+ "import": "./dist/esm/inAppMessaging/index.mjs",
53
+ "require": "./dist/cjs/inAppMessaging/index.js",
54
+ "react-native": "./src/inAppMessaging/index.ts"
55
+ },
56
+ "./push-notifications": {
57
+ "types": "./dist/esm/pushNotifications/index.d.ts",
58
+ "import": "./dist/esm/pushNotifications/index.mjs",
59
+ "require": "./dist/cjs/pushNotifications/index.js",
60
+ "react-native": "./src/pushNotifications/index.ts"
61
+ },
62
+ "./in-app-messaging/pinpoint": {
63
+ "types": "./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts",
64
+ "import": "./dist/esm/inAppMessaging/providers/pinpoint/index.mjs",
65
+ "require": "./dist/cjs/inAppMessaging/providers/pinpoint/index.js",
66
+ "react-native": "./src/inAppMessaging/providers/pinpoint/index.ts"
67
+ },
68
+ "./push-notifications/pinpoint": {
69
+ "types": "./dist/esm/pushNotifications/providers/pinpoint/index.d.ts",
70
+ "import": "./dist/esm/pushNotifications/providers/pinpoint/index.mjs",
71
+ "require": "./dist/cjs/pushNotifications/providers/pinpoint/index.js",
72
+ "react-native": "./src/pushNotifications/providers/pinpoint/index.ts"
73
+ },
74
+ "./package.json": "./package.json"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "https://github.com/aws-amplify/amplify-js.git"
79
+ },
80
+ "author": "Amazon Web Services",
81
+ "license": "Apache-2.0",
82
+ "bugs": {
83
+ "url": "https://github.com/aws/aws-amplify/issues"
84
+ },
85
+ "homepage": "https://docs.amplify.aws/",
86
+ "files": [
87
+ "dist/cjs",
88
+ "dist/esm",
89
+ "src",
90
+ "in-app-messaging",
91
+ "push-notifications"
92
+ ],
93
+ "dependencies": {
94
+ "lodash": "^4.17.21",
95
+ "tslib": "^2.5.0"
96
+ },
97
+ "peerDependencies": {
98
+ "@aws-amplify/core": "^6.1.0"
99
+ },
100
+ "devDependencies": {
101
+ "@aws-amplify/core": "6.2.1",
102
+ "@aws-amplify/react-native": "1.1.1",
103
+ "typescript": "5.0.2"
104
+ },
105
+ "gitHead": "7436f23bbc82e5021d6e550132e164adfa08de13"
106
106
  }
@@ -2,14 +2,21 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { PushNotificationAction } from '@aws-amplify/core/internals/utils';
5
- import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
5
+ import {
6
+ getEndpointId,
7
+ updateEndpoint,
8
+ } from '@aws-amplify/core/internals/providers/pinpoint';
6
9
 
7
10
  import { assertIsInitialized } from '../../../errors/errorHelpers';
8
11
  import {
9
12
  getPushNotificationUserAgentString,
10
13
  resolveCredentials,
11
14
  } from '../../../utils';
12
- import { getChannelType, resolveConfig } from '../utils';
15
+ import {
16
+ getChannelType,
17
+ getInflightDeviceRegistration,
18
+ resolveConfig,
19
+ } from '../utils';
13
20
  import { IdentifyUser } from '../types';
14
21
 
15
22
  export const identifyUser: IdentifyUser = async ({
@@ -21,6 +28,10 @@ export const identifyUser: IdentifyUser = async ({
21
28
  const { credentials, identityId } = await resolveCredentials();
22
29
  const { appId, region } = resolveConfig();
23
30
  const { address, optOut, userAttributes } = options ?? {};
31
+ if (!(await getEndpointId(appId, 'PushNotification'))) {
32
+ // if there is no cached endpoint id, wait for successful endpoint creation before continuing
33
+ await getInflightDeviceRegistration();
34
+ }
24
35
  await updateEndpoint({
25
36
  address,
26
37
  channelType: getChannelType(),
@@ -23,7 +23,9 @@ import {
23
23
  import {
24
24
  createMessageEventRecorder,
25
25
  getChannelType,
26
+ rejectInflightDeviceRegistration,
26
27
  resolveConfig,
28
+ resolveInflightDeviceRegistration,
27
29
  } from '../utils';
28
30
 
29
31
  const {
@@ -203,16 +205,24 @@ const addAnalyticsListeners = (): void => {
203
205
  const registerDevice = async (address: string): Promise<void> => {
204
206
  const { credentials, identityId } = await resolveCredentials();
205
207
  const { appId, region } = resolveConfig();
206
- await updateEndpoint({
207
- address,
208
- appId,
209
- category: 'PushNotification',
210
- credentials,
211
- region,
212
- channelType: getChannelType(),
213
- identityId,
214
- userAgentValue: getPushNotificationUserAgentString(
215
- PushNotificationAction.InitializePushNotifications,
216
- ),
217
- });
208
+ try {
209
+ await updateEndpoint({
210
+ address,
211
+ appId,
212
+ category: 'PushNotification',
213
+ credentials,
214
+ region,
215
+ channelType: getChannelType(),
216
+ identityId,
217
+ userAgentValue: getPushNotificationUserAgentString(
218
+ PushNotificationAction.InitializePushNotifications,
219
+ ),
220
+ });
221
+ // always resolve inflight device registration promise here even though the promise is only awaited on by
222
+ // `identifyUser` when no endpoint is found in the cache
223
+ resolveInflightDeviceRegistration();
224
+ } catch (underlyingError) {
225
+ rejectInflightDeviceRegistration(underlyingError);
226
+ throw underlyingError;
227
+ }
218
228
  };
@@ -37,4 +37,8 @@ export {
37
37
  OnTokenReceivedOutput,
38
38
  } from './outputs';
39
39
  export { IdentifyUserOptions } from './options';
40
- export { ChannelType } from './pushNotifications';
40
+ export {
41
+ ChannelType,
42
+ InflightDeviceRegistration,
43
+ InflightDeviceRegistrationResolver,
44
+ } from './pushNotifications';
@@ -3,4 +3,13 @@
3
3
 
4
4
  import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
5
5
 
6
+ import { PushNotificationError } from '../../../errors';
7
+
6
8
  export type ChannelType = Parameters<typeof updateEndpoint>[0]['channelType'];
9
+
10
+ export type InflightDeviceRegistration = Promise<void> | undefined;
11
+
12
+ export interface InflightDeviceRegistrationResolver {
13
+ resolve?(): void;
14
+ reject?(error: PushNotificationError): void;
15
+ }
@@ -4,4 +4,9 @@
4
4
  export { createMessageEventRecorder } from './createMessageEventRecorder';
5
5
  export { getAnalyticsEvent } from './getAnalyticsEvent';
6
6
  export { getChannelType } from './getChannelType';
7
+ export {
8
+ getInflightDeviceRegistration,
9
+ rejectInflightDeviceRegistration,
10
+ resolveInflightDeviceRegistration,
11
+ } from './inflightDeviceRegistration';
7
12
  export { resolveConfig } from './resolveConfig';
@@ -0,0 +1,38 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { PushNotificationError } from '../../../errors';
5
+ import {
6
+ InflightDeviceRegistration,
7
+ InflightDeviceRegistrationResolver,
8
+ } from '../types';
9
+
10
+ const inflightDeviceRegistrationResolver: InflightDeviceRegistrationResolver =
11
+ {};
12
+
13
+ let inflightDeviceRegistration: InflightDeviceRegistration = new Promise<void>(
14
+ (resolve, reject) => {
15
+ inflightDeviceRegistrationResolver.resolve = resolve;
16
+ inflightDeviceRegistrationResolver.reject = reject;
17
+ },
18
+ );
19
+
20
+ export const getInflightDeviceRegistration = () => inflightDeviceRegistration;
21
+
22
+ export const resolveInflightDeviceRegistration = () => {
23
+ inflightDeviceRegistrationResolver.resolve?.();
24
+ // release promise from memory
25
+ inflightDeviceRegistration = undefined;
26
+ };
27
+
28
+ export const rejectInflightDeviceRegistration = (underlyingError: unknown) => {
29
+ inflightDeviceRegistrationResolver.reject?.(
30
+ new PushNotificationError({
31
+ name: 'DeviceRegistrationFailed',
32
+ message: 'Failed to register device for push notifications.',
33
+ underlyingError,
34
+ }),
35
+ );
36
+ // release promise from memory
37
+ inflightDeviceRegistration = undefined;
38
+ };