@aws-amplify/notifications 2.0.21-unstable.a254bb6.0 → 2.0.22-unstable.bd1fefd.0

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 (24) hide show
  1. package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js +7 -7
  2. package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js.map +1 -1
  3. package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js +3 -27
  4. package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js.map +1 -1
  5. package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js +50 -0
  6. package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js.map +1 -0
  7. package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js +4 -1
  8. package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js.map +1 -1
  9. package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs +5 -4
  10. package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs.map +1 -1
  11. package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.d.ts +1 -2
  12. package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs +7 -27
  13. package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs.map +1 -1
  14. package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.d.ts +13 -0
  15. package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs +46 -0
  16. package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs.map +1 -0
  17. package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.d.ts +1 -0
  18. package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs +1 -0
  19. package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs.map +1 -1
  20. package/package.json +5 -5
  21. package/src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts +14 -11
  22. package/src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts +6 -34
  23. package/src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.ts +52 -0
  24. package/src/inAppMessaging/providers/pinpoint/utils/index.ts +4 -0
@@ -5,13 +5,12 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.dispatchEvent = void 0;
7
7
  const tslib_1 = require("tslib");
8
- const utils_1 = require("../utils");
9
8
  const flatten_js_1 = tslib_1.__importDefault(require("lodash/flatten.js"));
10
9
  const core_1 = require("@aws-amplify/core");
11
10
  const eventListeners_1 = require("../../../../eventListeners");
12
11
  const errors_1 = require("../../../errors");
13
- const setConflictHandler_1 = require("./setConflictHandler");
14
- const utils_2 = require("../../../utils");
12
+ const utils_1 = require("../../../utils");
13
+ const utils_2 = require("../utils");
15
14
  /**
16
15
  * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using
17
16
  * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display
@@ -40,14 +39,15 @@ const utils_2 = require("../../../utils");
40
39
  * ```
41
40
  */
42
41
  async function dispatchEvent(input) {
43
- (0, utils_2.assertIsInitialized)();
42
+ (0, utils_1.assertIsInitialized)();
44
43
  try {
45
- const key = `${utils_1.PINPOINT_KEY_PREFIX}${utils_1.STORAGE_KEY_SUFFIX}`;
44
+ const key = `${utils_2.PINPOINT_KEY_PREFIX}${utils_2.STORAGE_KEY_SUFFIX}`;
46
45
  const cachedMessages = await core_1.defaultStorage.getItem(key);
47
- const messages = await (0, utils_1.processInAppMessages)(cachedMessages ? JSON.parse(cachedMessages) : [], input);
46
+ const messages = await (0, utils_2.processInAppMessages)(cachedMessages ? JSON.parse(cachedMessages) : [], input);
48
47
  const flattenedMessages = (0, flatten_js_1.default)(messages);
49
48
  if (flattenedMessages.length > 0) {
50
- (0, eventListeners_1.notifyEventListeners)('messageReceived', (0, setConflictHandler_1.conflictHandler)(flattenedMessages));
49
+ const conflictHandler = (0, utils_2.getConflictHandler)();
50
+ (0, eventListeners_1.notifyEventListeners)('messageReceived', conflictHandler(flattenedMessages));
51
51
  }
52
52
  }
53
53
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"dispatchEvent.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.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.dispatchEvent = void 0;\nconst tslib_1 = require(\"tslib\");\nconst utils_1 = require(\"../utils\");\nconst flatten_js_1 = tslib_1.__importDefault(require(\"lodash/flatten.js\"));\nconst core_1 = require(\"@aws-amplify/core\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst errors_1 = require(\"../../../errors\");\nconst setConflictHandler_1 = require(\"./setConflictHandler\");\nconst utils_2 = require(\"../../../utils\");\n/**\n * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using\n * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display\n * of the In-App message that meets the criteria.\n *\n * @remark\n * If an event would trigger multiple messages, the message closest to expiry will be chosen by default.\n * To change this behavior, you can use the {@link setConflictHandler} API to provide\n * your own logic for resolving message conflicts.\n *\n * @param input The input object that holds the event to be dispatched.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n *\n * @returns A promise that will resolve when the operation is complete.\n *\n * @example\n * ```ts\n * // Sync message before disptaching an event\n * await syncMessages();\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nasync function dispatchEvent(input) {\n (0, utils_2.assertIsInitialized)();\n try {\n const key = `${utils_1.PINPOINT_KEY_PREFIX}${utils_1.STORAGE_KEY_SUFFIX}`;\n const cachedMessages = await core_1.defaultStorage.getItem(key);\n const messages = await (0, utils_1.processInAppMessages)(cachedMessages ? JSON.parse(cachedMessages) : [], input);\n const flattenedMessages = (0, flatten_js_1.default)(messages);\n if (flattenedMessages.length > 0) {\n (0, eventListeners_1.notifyEventListeners)('messageReceived', (0, setConflictHandler_1.conflictHandler)(flattenedMessages));\n }\n }\n catch (error) {\n (0, errors_1.assertServiceError)(error);\n throw error;\n }\n}\nexports.dispatchEvent = dispatchEvent;\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,KAAK,CAAC,CAAC;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AACjC,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAC3E,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC/D,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC7D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,aAAa,CAAC,KAAK,EAAE;AACpC,IAAI,IAAI,OAAO,CAAC,mBAAmB,GAAG,CAAC;AACvC,IAAI,IAAI;AACR,QAAQ,MAAM,GAAG,GAAG,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAClF,QAAQ,MAAM,cAAc,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACxE,QAAQ,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,oBAAoB,EAAE,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;AAC1H,QAAQ,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACtE,QAAQ,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1C,YAAY,CAAC,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,iBAAiB,EAAE,CAAC,CAAC,EAAE,oBAAoB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC,CAAC;AACxI,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAChD,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
1
+ {"version":3,"file":"dispatchEvent.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.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.dispatchEvent = void 0;\nconst tslib_1 = require(\"tslib\");\nconst flatten_js_1 = tslib_1.__importDefault(require(\"lodash/flatten.js\"));\nconst core_1 = require(\"@aws-amplify/core\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst errors_1 = require(\"../../../errors\");\nconst utils_1 = require(\"../../../utils\");\nconst utils_2 = require(\"../utils\");\n/**\n * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using\n * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display\n * of the In-App message that meets the criteria.\n *\n * @remark\n * If an event would trigger multiple messages, the message closest to expiry will be chosen by default.\n * To change this behavior, you can use the {@link setConflictHandler} API to provide\n * your own logic for resolving message conflicts.\n *\n * @param input The input object that holds the event to be dispatched.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n *\n * @returns A promise that will resolve when the operation is complete.\n *\n * @example\n * ```ts\n * // Sync message before disptaching an event\n * await syncMessages();\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nasync function dispatchEvent(input) {\n (0, utils_1.assertIsInitialized)();\n try {\n const key = `${utils_2.PINPOINT_KEY_PREFIX}${utils_2.STORAGE_KEY_SUFFIX}`;\n const cachedMessages = await core_1.defaultStorage.getItem(key);\n const messages = await (0, utils_2.processInAppMessages)(cachedMessages ? JSON.parse(cachedMessages) : [], input);\n const flattenedMessages = (0, flatten_js_1.default)(messages);\n if (flattenedMessages.length > 0) {\n const conflictHandler = (0, utils_2.getConflictHandler)();\n (0, eventListeners_1.notifyEventListeners)('messageReceived', conflictHandler(flattenedMessages));\n }\n }\n catch (error) {\n (0, errors_1.assertServiceError)(error);\n throw error;\n }\n}\nexports.dispatchEvent = dispatchEvent;\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,KAAK,CAAC,CAAC;AAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,OA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C;AACtE,YAAY,CAAC,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,EAAE,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAC9G,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAChD,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
@@ -3,9 +3,9 @@
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.setConflictHandler = exports.conflictHandler = void 0;
6
+ exports.setConflictHandler = void 0;
7
7
  const utils_1 = require("../../../utils");
8
- exports.conflictHandler = defaultConflictHandler;
8
+ const utils_2 = require("../utils");
9
9
  /**
10
10
  * Set a conflict handler that will be used to resolve conflicts that may emerge
11
11
  * when matching events with synced messages.
@@ -40,31 +40,7 @@ exports.conflictHandler = defaultConflictHandler;
40
40
  */
41
41
  function setConflictHandler(input) {
42
42
  (0, utils_1.assertIsInitialized)();
43
- exports.conflictHandler = input;
43
+ (0, utils_2.setConflictHandler)(input);
44
44
  }
45
45
  exports.setConflictHandler = setConflictHandler;
46
- function defaultConflictHandler(messages) {
47
- // default behavior is to return the message closest to expiry
48
- // this function assumes that messages processed by providers already filters out expired messages
49
- const sorted = messages.sort((a, b) => {
50
- const endDateA = a.metadata?.endDate;
51
- const endDateB = b.metadata?.endDate;
52
- // if both message end dates are falsy or have the same date string, treat them as equal
53
- if (endDateA === endDateB) {
54
- return 0;
55
- }
56
- // if only message A has an end date, treat it as closer to expiry
57
- if (endDateA && !endDateB) {
58
- return -1;
59
- }
60
- // if only message B has an end date, treat it as closer to expiry
61
- if (!endDateA && endDateB) {
62
- return 1;
63
- }
64
- // otherwise, compare them
65
- return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
66
- });
67
- // always return the top sorted
68
- return sorted[0];
69
- }
70
46
  //# sourceMappingURL=setConflictHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"setConflictHandler.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.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.setConflictHandler = exports.conflictHandler = void 0;\nconst utils_1 = require(\"../../../utils\");\nexports.conflictHandler = defaultConflictHandler;\n/**\n * Set a conflict handler that will be used to resolve conflicts that may emerge\n * when matching events with synced messages.\n *\n * @remark\n * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for\n * any custom handling to take effect.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n *\n * @param input The input object that holds the conflict handler to be used.\n *\n * @example\n * ```ts\n * // Sync messages before dispatching an event\n * await syncMessages();\n *\n * // Example custom conflict handler\n * const myConflictHandler = (messages) => {\n * \t\t// Return a random message\n * \t\tconst randomIndex = Math.floor(Math.random() * messages.length);\n * \t\treturn messages[randomIndex];\n * };\n *\n * // Set the conflict handler\n * setConflictHandler(myConflictHandler);\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nfunction setConflictHandler(input) {\n (0, utils_1.assertIsInitialized)();\n exports.conflictHandler = input;\n}\nexports.setConflictHandler = setConflictHandler;\nfunction defaultConflictHandler(messages) {\n // default behavior is to return the message closest to expiry\n // this function assumes that messages processed by providers already filters out expired messages\n const sorted = messages.sort((a, b) => {\n const endDateA = a.metadata?.endDate;\n const endDateB = b.metadata?.endDate;\n // if both message end dates are falsy or have the same date string, treat them as equal\n if (endDateA === endDateB) {\n return 0;\n }\n // if only message A has an end date, treat it as closer to expiry\n if (endDateA && !endDateB) {\n return -1;\n }\n // if only message B has an end date, treat it as closer to expiry\n if (!endDateA && endDateB) {\n return 1;\n }\n // otherwise, compare them\n return new Date(endDateA) < new Date(endDateB) ? -1 : 1;\n });\n // always return the top sorted\n return sorted[0];\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,kBAAkB,GAAG,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AAC9D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,OAAO,CAAC,eAAe,GAAG,sBAAsB,CAAC;AACjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,KAAK,EAAE;AACnC,IAAI,IAAI,OAAO,CAAC,mBAAmB,GAAG,CAAC;AACvC,IAAI,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC;AACpC,CAAC;AACD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAChD,SAAS,sBAAsB,CAAC,QAAQ,EAAE;AAC1C;AACA;AACA,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;AAC3C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C;AACA,QAAQ,IAAI,QAAQ,KAAK,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,IAAI,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC,CAAC;AACtB,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE,KAAK,CAAC,CAAC;AACP;AACA,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACrB;;"}
1
+ {"version":3,"file":"setConflictHandler.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.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.setConflictHandler = void 0;\nconst utils_1 = require(\"../../../utils\");\nconst utils_2 = require(\"../utils\");\n/**\n * Set a conflict handler that will be used to resolve conflicts that may emerge\n * when matching events with synced messages.\n *\n * @remark\n * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for\n * any custom handling to take effect.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n *\n * @param input The input object that holds the conflict handler to be used.\n *\n * @example\n * ```ts\n * // Sync messages before dispatching an event\n * await syncMessages();\n *\n * // Example custom conflict handler\n * const myConflictHandler = (messages) => {\n * \t\t// Return a random message\n * \t\tconst randomIndex = Math.floor(Math.random() * messages.length);\n * \t\treturn messages[randomIndex];\n * };\n *\n * // Set the conflict handler\n * setConflictHandler(myConflictHandler);\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nfunction setConflictHandler(input) {\n (0, utils_1.assertIsInitialized)();\n (0, utils_2.setConflictHandler)(input);\n}\nexports.setConflictHandler = setConflictHandler;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,KAAK,EAAE;AACnC,IAAI,IAAI,OAAO,CAAC,mBAAmB,GAAG,CAAC;AACvC,IAAI,IAAI,OAAO,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AACD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;;"}
@@ -0,0 +1,50 @@
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.getConflictHandler = exports.setConflictHandler = void 0;
7
+ /**
8
+ * The default conflict handler. Can be overridden by `setConflictHandler`.
9
+ */
10
+ let conflictHandler = (messages) => {
11
+ // default behavior is to return the message closest to expiry
12
+ // this function assumes that messages processed by providers already filters out expired messages
13
+ const sorted = messages.sort((a, b) => {
14
+ const endDateA = a.metadata?.endDate;
15
+ const endDateB = b.metadata?.endDate;
16
+ // if both message end dates are falsy or have the same date string, treat them as equal
17
+ if (endDateA === endDateB) {
18
+ return 0;
19
+ }
20
+ // if only message A has an end date, treat it as closer to expiry
21
+ if (endDateA && !endDateB) {
22
+ return -1;
23
+ }
24
+ // if only message B has an end date, treat it as closer to expiry
25
+ if (!endDateA && endDateB) {
26
+ return 1;
27
+ }
28
+ // otherwise, compare them
29
+ return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
30
+ });
31
+ // always return the top sorted
32
+ return sorted[0];
33
+ };
34
+ /**
35
+ * Sets conflict handler.
36
+ *
37
+ * @internal
38
+ */
39
+ const setConflictHandler = (input) => {
40
+ conflictHandler = input;
41
+ };
42
+ exports.setConflictHandler = setConflictHandler;
43
+ /**
44
+ * Returns the current conflict handler.
45
+ *
46
+ * @internal
47
+ */
48
+ const getConflictHandler = () => conflictHandler;
49
+ exports.getConflictHandler = getConflictHandler;
50
+ //# sourceMappingURL=conflictHandlerManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conflictHandlerManager.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.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.getConflictHandler = exports.setConflictHandler = void 0;\n/**\n * The default conflict handler. Can be overridden by `setConflictHandler`.\n */\nlet conflictHandler = (messages) => {\n // default behavior is to return the message closest to expiry\n // this function assumes that messages processed by providers already filters out expired messages\n const sorted = messages.sort((a, b) => {\n const endDateA = a.metadata?.endDate;\n const endDateB = b.metadata?.endDate;\n // if both message end dates are falsy or have the same date string, treat them as equal\n if (endDateA === endDateB) {\n return 0;\n }\n // if only message A has an end date, treat it as closer to expiry\n if (endDateA && !endDateB) {\n return -1;\n }\n // if only message B has an end date, treat it as closer to expiry\n if (!endDateA && endDateB) {\n return 1;\n }\n // otherwise, compare them\n return new Date(endDateA) < new Date(endDateB) ? -1 : 1;\n });\n // always return the top sorted\n return sorted[0];\n};\n/**\n * Sets conflict handler.\n *\n * @internal\n */\nconst setConflictHandler = (input) => {\n conflictHandler = input;\n};\nexports.setConflictHandler = setConflictHandler;\n/**\n * Returns the current conflict handler.\n *\n * @internal\n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;AAChD;AACA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAC;AACjD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;;"}
@@ -3,7 +3,10 @@
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.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = exports.STORAGE_KEY_SUFFIX = exports.CHANNEL_TYPE = exports.CATEGORY = exports.PINPOINT_KEY_PREFIX = exports.getInAppMessagingUserAgentString = exports.resolveCredentials = exports.resolveConfig = void 0;
6
+ exports.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = exports.STORAGE_KEY_SUFFIX = exports.CHANNEL_TYPE = exports.CATEGORY = exports.PINPOINT_KEY_PREFIX = exports.getInAppMessagingUserAgentString = exports.resolveCredentials = exports.resolveConfig = exports.setConflictHandler = exports.getConflictHandler = void 0;
7
+ var conflictHandlerManager_1 = require("./conflictHandlerManager");
8
+ Object.defineProperty(exports, "getConflictHandler", { enumerable: true, get: function () { return conflictHandlerManager_1.getConflictHandler; } });
9
+ Object.defineProperty(exports, "setConflictHandler", { enumerable: true, get: function () { return conflictHandlerManager_1.setConflictHandler; } });
7
10
  var resolveConfig_1 = require("./resolveConfig");
8
11
  Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });
9
12
  var resolveCredentials_1 = require("./resolveCredentials");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../../../src/inAppMessaging/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.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = exports.STORAGE_KEY_SUFFIX = exports.CHANNEL_TYPE = exports.CATEGORY = exports.PINPOINT_KEY_PREFIX = exports.getInAppMessagingUserAgentString = exports.resolveCredentials = exports.resolveConfig = void 0;\nvar resolveConfig_1 = require(\"./resolveConfig\");\nObject.defineProperty(exports, \"resolveConfig\", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });\nvar resolveCredentials_1 = require(\"./resolveCredentials\");\nObject.defineProperty(exports, \"resolveCredentials\", { enumerable: true, get: function () { return resolveCredentials_1.resolveCredentials; } });\nvar userAgent_1 = require(\"./userAgent\");\nObject.defineProperty(exports, \"getInAppMessagingUserAgentString\", { enumerable: true, get: function () { return userAgent_1.getInAppMessagingUserAgentString; } });\nvar constants_1 = require(\"./constants\");\nObject.defineProperty(exports, \"PINPOINT_KEY_PREFIX\", { enumerable: true, get: function () { return constants_1.PINPOINT_KEY_PREFIX; } });\nObject.defineProperty(exports, \"CATEGORY\", { enumerable: true, get: function () { return constants_1.CATEGORY; } });\nObject.defineProperty(exports, \"CHANNEL_TYPE\", { enumerable: true, get: function () { return constants_1.CHANNEL_TYPE; } });\nObject.defineProperty(exports, \"STORAGE_KEY_SUFFIX\", { enumerable: true, get: function () { return constants_1.STORAGE_KEY_SUFFIX; } });\nvar messageProcessingHelpers_1 = require(\"./messageProcessingHelpers\");\nObject.defineProperty(exports, \"processInAppMessages\", { enumerable: true, get: function () { return messageProcessingHelpers_1.processInAppMessages; } });\nObject.defineProperty(exports, \"sessionStateChangeHandler\", { enumerable: true, get: function () { return messageProcessingHelpers_1.sessionStateChangeHandler; } });\nObject.defineProperty(exports, \"incrementMessageCounts\", { enumerable: true, get: function () { return messageProcessingHelpers_1.incrementMessageCounts; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,C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AAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;AACpH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;AAC5H,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC;AACxI,IAAI,0BAA0B,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AACvE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,oBAAoB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3J,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,2BAA2B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,EAAE,CAAC,CAAC;AACrK,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,wBAAwB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,sBAAsB,CAAC,EAAE,EAAE,CAAC;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../../src/inAppMessaging/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.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = exports.STORAGE_KEY_SUFFIX = exports.CHANNEL_TYPE = exports.CATEGORY = exports.PINPOINT_KEY_PREFIX = exports.getInAppMessagingUserAgentString = exports.resolveCredentials = exports.resolveConfig = exports.setConflictHandler = exports.getConflictHandler = void 0;\nvar conflictHandlerManager_1 = require(\"./conflictHandlerManager\");\nObject.defineProperty(exports, \"getConflictHandler\", { enumerable: true, get: function () { return conflictHandlerManager_1.getConflictHandler; } });\nObject.defineProperty(exports, \"setConflictHandler\", { enumerable: true, get: function () { return conflictHandlerManager_1.setConflictHandler; } });\nvar resolveConfig_1 = require(\"./resolveConfig\");\nObject.defineProperty(exports, \"resolveConfig\", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });\nvar resolveCredentials_1 = require(\"./resolveCredentials\");\nObject.defineProperty(exports, \"resolveCredentials\", { enumerable: true, get: function () { return resolveCredentials_1.resolveCredentials; } });\nvar userAgent_1 = require(\"./userAgent\");\nObject.defineProperty(exports, \"getInAppMessagingUserAgentString\", { enumerable: true, get: function () { return userAgent_1.getInAppMessagingUserAgentString; } });\nvar constants_1 = require(\"./constants\");\nObject.defineProperty(exports, \"PINPOINT_KEY_PREFIX\", { enumerable: true, get: function () { return constants_1.PINPOINT_KEY_PREFIX; } });\nObject.defineProperty(exports, \"CATEGORY\", { enumerable: true, get: function () { return constants_1.CATEGORY; } });\nObject.defineProperty(exports, \"CHANNEL_TYPE\", { enumerable: true, get: function () { return constants_1.CHANNEL_TYPE; } });\nObject.defineProperty(exports, \"STORAGE_KEY_SUFFIX\", { enumerable: true, get: function () { return constants_1.STORAGE_KEY_SUFFIX; } });\nvar messageProcessingHelpers_1 = require(\"./messageProcessingHelpers\");\nObject.defineProperty(exports, \"processInAppMessages\", { enumerable: true, get: function () { return messageProcessingHelpers_1.processInAppMessages; } });\nObject.defineProperty(exports, \"sessionStateChangeHandler\", { enumerable: true, get: function () { return messageProcessingHelpers_1.sessionStateChangeHandler; } });\nObject.defineProperty(exports, \"incrementMessageCounts\", { enumerable: true, get: function () { return messageProcessingHelpers_1.incrementMessageCounts; } });\n"],"names":[],"m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C;AAC3J,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,2BAA2B,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,EAAE,CAAC,CAAC;AACrK,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,wBAAwB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,0BAA0B,CAAC,sBAAsB,CAAC,EAAE,EAAE,CAAC;;"}
@@ -1,13 +1,13 @@
1
+ import flatten from 'lodash/flatten.js';
1
2
  import { defaultStorage } from '@aws-amplify/core';
3
+ import { notifyEventListeners } from '../../../../eventListeners/eventListeners.mjs';
2
4
  import '@aws-amplify/core/internals/utils';
3
5
  import '../../../errors/validation.mjs';
4
6
  import { assertServiceError } from '../../../errors/assertServiceError.mjs';
7
+ import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
8
+ import { getConflictHandler } from '../utils/conflictHandlerManager.mjs';
5
9
  import { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX } from '../utils/constants.mjs';
6
10
  import { processInAppMessages } from '../utils/messageProcessingHelpers.mjs';
7
- import flatten from 'lodash/flatten.js';
8
- import { notifyEventListeners } from '../../../../eventListeners/eventListeners.mjs';
9
- import { conflictHandler } from './setConflictHandler.mjs';
10
- import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
11
11
 
12
12
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
13
13
  // SPDX-License-Identifier: Apache-2.0
@@ -46,6 +46,7 @@ async function dispatchEvent(input) {
46
46
  const messages = await processInAppMessages(cachedMessages ? JSON.parse(cachedMessages) : [], input);
47
47
  const flattenedMessages = flatten(messages);
48
48
  if (flattenedMessages.length > 0) {
49
+ const conflictHandler = getConflictHandler();
49
50
  notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));
50
51
  }
51
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dispatchEvent.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX, processInAppMessages, } from '../utils';\nimport flatten from 'lodash/flatten.js';\nimport { defaultStorage } from '@aws-amplify/core';\nimport { notifyEventListeners } from '../../../../eventListeners';\nimport { assertServiceError } from '../../../errors';\nimport { conflictHandler } from './setConflictHandler';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using\n * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display\n * of the In-App message that meets the criteria.\n *\n * @remark\n * If an event would trigger multiple messages, the message closest to expiry will be chosen by default.\n * To change this behavior, you can use the {@link setConflictHandler} API to provide\n * your own logic for resolving message conflicts.\n *\n * @param input The input object that holds the event to be dispatched.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n *\n * @returns A promise that will resolve when the operation is complete.\n *\n * @example\n * ```ts\n * // Sync message before disptaching an event\n * await syncMessages();\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport async function dispatchEvent(input) {\n assertIsInitialized();\n try {\n const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;\n const cachedMessages = await defaultStorage.getItem(key);\n const messages = await processInAppMessages(cachedMessages ? JSON.parse(cachedMessages) : [], input);\n const flattenedMessages = flatten(messages);\n if (flattenedMessages.length > 0) {\n notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));\n }\n }\n catch (error) {\n assertServiceError(error);\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,aAAa,CAAC,KAAK,EAAE;AAC3C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,IAAI;AACR,QAAQ,MAAM,GAAG,GAAG,CAAC,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAClE,QAAQ,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAQ,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;AAC7G,QAAQ,MAAM,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACpD,QAAQ,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1C,YAAY,oBAAoB,CAAC,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACxF,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAClC,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"dispatchEvent.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport flatten from 'lodash/flatten.js';\nimport { defaultStorage } from '@aws-amplify/core';\nimport { notifyEventListeners } from '../../../../eventListeners';\nimport { assertServiceError } from '../../../errors';\nimport { assertIsInitialized } from '../../../utils';\nimport { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX, getConflictHandler, processInAppMessages, } from '../utils';\n/**\n * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using\n * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display\n * of the In-App message that meets the criteria.\n *\n * @remark\n * If an event would trigger multiple messages, the message closest to expiry will be chosen by default.\n * To change this behavior, you can use the {@link setConflictHandler} API to provide\n * your own logic for resolving message conflicts.\n *\n * @param input The input object that holds the event to be dispatched.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n *\n * @returns A promise that will resolve when the operation is complete.\n *\n * @example\n * ```ts\n * // Sync message before disptaching an event\n * await syncMessages();\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport async function dispatchEvent(input) {\n assertIsInitialized();\n try {\n const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;\n const cachedMessages = await defaultStorage.getItem(key);\n const messages = await processInAppMessages(cachedMessages ? JSON.parse(cachedMessages) : [], input);\n const flattenedMessages = flatten(messages);\n if (flattenedMessages.length > 0) {\n const conflictHandler = getConflictHandler();\n notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));\n }\n }\n catch (error) {\n assertServiceError(error);\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,aAAa,CAAC,KAAK,EAAE;AAC3C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,IAAI;AACR,QAAQ,MAAM,GAAG,GAAG,CAAC,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAClE,QAAQ,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAQ,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;AAC7G,QAAQ,MAAM,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACpD,QAAQ,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1C,YAAY,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;AACzD,YAAY,oBAAoB,CAAC,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACxF,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAClC,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL;;;;"}
@@ -1,5 +1,4 @@
1
- import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
2
- export declare let conflictHandler: InAppMessageConflictHandler;
1
+ import { SetConflictHandlerInput } from '../types';
3
2
  /**
4
3
  * Set a conflict handler that will be used to resolve conflicts that may emerge
5
4
  * when matching events with synced messages.
@@ -1,8 +1,12 @@
1
1
  import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
2
+ import { setConflictHandler as setConflictHandler$1 } from '../utils/conflictHandlerManager.mjs';
3
+ import '@aws-amplify/core';
4
+ import '@aws-amplify/core/internals/utils';
5
+ import '../../../errors/validation.mjs';
6
+ import '../utils/messageProcessingHelpers.mjs';
2
7
 
3
8
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
9
  // SPDX-License-Identifier: Apache-2.0
5
- let conflictHandler = defaultConflictHandler;
6
10
  /**
7
11
  * Set a conflict handler that will be used to resolve conflicts that may emerge
8
12
  * when matching events with synced messages.
@@ -37,32 +41,8 @@ let conflictHandler = defaultConflictHandler;
37
41
  */
38
42
  function setConflictHandler(input) {
39
43
  assertIsInitialized();
40
- conflictHandler = input;
41
- }
42
- function defaultConflictHandler(messages) {
43
- // default behavior is to return the message closest to expiry
44
- // this function assumes that messages processed by providers already filters out expired messages
45
- const sorted = messages.sort((a, b) => {
46
- const endDateA = a.metadata?.endDate;
47
- const endDateB = b.metadata?.endDate;
48
- // if both message end dates are falsy or have the same date string, treat them as equal
49
- if (endDateA === endDateB) {
50
- return 0;
51
- }
52
- // if only message A has an end date, treat it as closer to expiry
53
- if (endDateA && !endDateB) {
54
- return -1;
55
- }
56
- // if only message B has an end date, treat it as closer to expiry
57
- if (!endDateA && endDateB) {
58
- return 1;
59
- }
60
- // otherwise, compare them
61
- return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
62
- });
63
- // always return the top sorted
64
- return sorted[0];
44
+ setConflictHandler$1(input);
65
45
  }
66
46
 
67
- export { conflictHandler, setConflictHandler };
47
+ export { setConflictHandler };
68
48
  //# sourceMappingURL=setConflictHandler.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setConflictHandler.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertIsInitialized } from '../../../utils';\nexport let conflictHandler = defaultConflictHandler;\n/**\n * Set a conflict handler that will be used to resolve conflicts that may emerge\n * when matching events with synced messages.\n *\n * @remark\n * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for\n * any custom handling to take effect.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n *\n * @param input The input object that holds the conflict handler to be used.\n *\n * @example\n * ```ts\n * // Sync messages before dispatching an event\n * await syncMessages();\n *\n * // Example custom conflict handler\n * const myConflictHandler = (messages) => {\n * \t\t// Return a random message\n * \t\tconst randomIndex = Math.floor(Math.random() * messages.length);\n * \t\treturn messages[randomIndex];\n * };\n *\n * // Set the conflict handler\n * setConflictHandler(myConflictHandler);\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport function setConflictHandler(input) {\n assertIsInitialized();\n conflictHandler = input;\n}\nfunction defaultConflictHandler(messages) {\n // default behavior is to return the message closest to expiry\n // this function assumes that messages processed by providers already filters out expired messages\n const sorted = messages.sort((a, b) => {\n const endDateA = a.metadata?.endDate;\n const endDateB = b.metadata?.endDate;\n // if both message end dates are falsy or have the same date string, treat them as equal\n if (endDateA === endDateB) {\n return 0;\n }\n // if only message A has an end date, treat it as closer to expiry\n if (endDateA && !endDateB) {\n return -1;\n }\n // if only message B has an end date, treat it as closer to expiry\n if (!endDateA && endDateB) {\n return 1;\n }\n // otherwise, compare them\n return new Date(endDateA) < new Date(endDateB) ? -1 : 1;\n });\n // always return the top sorted\n return sorted[0];\n}\n"],"names":[],"mappings":";;AAAA;AACA;AAEU,IAAC,eAAe,GAAG,uBAAuB;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,CAAC;AACD,SAAS,sBAAsB,CAAC,QAAQ,EAAE;AAC1C;AACA;AACA,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;AAC3C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C;AACA,QAAQ,IAAI,QAAQ,KAAK,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,IAAI,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC,CAAC;AACtB,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE,KAAK,CAAC,CAAC;AACP;AACA,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACrB;;;;"}
1
+ {"version":3,"file":"setConflictHandler.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertIsInitialized } from '../../../utils';\nimport { setConflictHandler as setConflictHandlerInteral } from '../utils';\n/**\n * Set a conflict handler that will be used to resolve conflicts that may emerge\n * when matching events with synced messages.\n *\n * @remark\n * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for\n * any custom handling to take effect.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n *\n * @param input The input object that holds the conflict handler to be used.\n *\n * @example\n * ```ts\n * // Sync messages before dispatching an event\n * await syncMessages();\n *\n * // Example custom conflict handler\n * const myConflictHandler = (messages) => {\n * \t\t// Return a random message\n * \t\tconst randomIndex = Math.floor(Math.random() * messages.length);\n * \t\treturn messages[randomIndex];\n * };\n *\n * // Set the conflict handler\n * setConflictHandler(myConflictHandler);\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport function setConflictHandler(input) {\n assertIsInitialized();\n setConflictHandlerInteral(input);\n}\n"],"names":["setConflictHandlerInteral"],"mappings":";;;;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAIA,oBAAyB,CAAC,KAAK,CAAC,CAAC;AACrC;;;;"}
@@ -0,0 +1,13 @@
1
+ import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
2
+ /**
3
+ * Sets conflict handler.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare const setConflictHandler: (input: SetConflictHandlerInput) => void;
8
+ /**
9
+ * Returns the current conflict handler.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare const getConflictHandler: () => InAppMessageConflictHandler;
@@ -0,0 +1,46 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * The default conflict handler. Can be overridden by `setConflictHandler`.
5
+ */
6
+ let conflictHandler = (messages) => {
7
+ // default behavior is to return the message closest to expiry
8
+ // this function assumes that messages processed by providers already filters out expired messages
9
+ const sorted = messages.sort((a, b) => {
10
+ const endDateA = a.metadata?.endDate;
11
+ const endDateB = b.metadata?.endDate;
12
+ // if both message end dates are falsy or have the same date string, treat them as equal
13
+ if (endDateA === endDateB) {
14
+ return 0;
15
+ }
16
+ // if only message A has an end date, treat it as closer to expiry
17
+ if (endDateA && !endDateB) {
18
+ return -1;
19
+ }
20
+ // if only message B has an end date, treat it as closer to expiry
21
+ if (!endDateA && endDateB) {
22
+ return 1;
23
+ }
24
+ // otherwise, compare them
25
+ return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
26
+ });
27
+ // always return the top sorted
28
+ return sorted[0];
29
+ };
30
+ /**
31
+ * Sets conflict handler.
32
+ *
33
+ * @internal
34
+ */
35
+ const setConflictHandler = (input) => {
36
+ conflictHandler = input;
37
+ };
38
+ /**
39
+ * Returns the current conflict handler.
40
+ *
41
+ * @internal
42
+ */
43
+ const getConflictHandler = () => conflictHandler;
44
+
45
+ export { getConflictHandler, setConflictHandler };
46
+ //# sourceMappingURL=conflictHandlerManager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conflictHandlerManager.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * The default conflict handler. Can be overridden by `setConflictHandler`.\n */\nlet conflictHandler = (messages) => {\n // default behavior is to return the message closest to expiry\n // this function assumes that messages processed by providers already filters out expired messages\n const sorted = messages.sort((a, b) => {\n const endDateA = a.metadata?.endDate;\n const endDateB = b.metadata?.endDate;\n // if both message end dates are falsy or have the same date string, treat them as equal\n if (endDateA === endDateB) {\n return 0;\n }\n // if only message A has an end date, treat it as closer to expiry\n if (endDateA && !endDateB) {\n return -1;\n }\n // if only message B has an end date, treat it as closer to expiry\n if (!endDateA && endDateB) {\n return 1;\n }\n // otherwise, compare them\n return new Date(endDateA) < new Date(endDateB) ? -1 : 1;\n });\n // always return the top sorted\n return sorted[0];\n};\n/**\n * Sets conflict handler.\n *\n * @internal\n */\nexport const setConflictHandler = (input) => {\n conflictHandler = input;\n};\n/**\n * Returns the current conflict handler.\n *\n * @internal\n */\nexport const getConflictHandler = () => conflictHandler;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,IAAI,eAAe,GAAG,CAAC,QAAQ,KAAK;AACpC;AACA;AACA,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;AAC3C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC;AAC7C;AACA,QAAQ,IAAI,QAAQ,KAAK,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,IAAI,QAAQ,IAAI,CAAC,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC,CAAC;AACtB,SAAS;AACT;AACA,QAAQ,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE;AACnC,YAAY,OAAO,CAAC,CAAC;AACrB,SAAS;AACT;AACA,QAAQ,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE,KAAK,CAAC,CAAC;AACP;AACA,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,KAAK,KAAK;AAC7C,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,EAAE;AACF;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,MAAM;;;;"}
@@ -1,3 +1,4 @@
1
+ export { getConflictHandler, setConflictHandler, } from './conflictHandlerManager';
1
2
  export { resolveConfig } from './resolveConfig';
2
3
  export { resolveCredentials } from './resolveCredentials';
3
4
  export { getInAppMessagingUserAgentString } from './userAgent';
@@ -1,3 +1,4 @@
1
+ export { getConflictHandler, setConflictHandler } from './conflictHandlerManager.mjs';
1
2
  export { resolveConfig } from './resolveConfig.mjs';
2
3
  export { resolveCredentials } from './resolveCredentials.mjs';
3
4
  export { getInAppMessagingUserAgentString } from './userAgent.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/notifications",
3
- "version": "2.0.21-unstable.a254bb6.0+a254bb6",
3
+ "version": "2.0.22-unstable.bd1fefd.0+bd1fefd",
4
4
  "description": "Notifications category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -94,12 +94,12 @@
94
94
  "tslib": "^2.5.0"
95
95
  },
96
96
  "peerDependencies": {
97
- "@aws-amplify/core": "6.0.21-unstable.a254bb6.0+a254bb6"
97
+ "@aws-amplify/core": "6.0.22-unstable.bd1fefd.0+bd1fefd"
98
98
  },
99
99
  "devDependencies": {
100
- "@aws-amplify/core": "6.0.21-unstable.a254bb6.0+a254bb6",
101
- "@aws-amplify/react-native": "1.0.21-unstable.a254bb6.0+a254bb6",
100
+ "@aws-amplify/core": "6.0.22-unstable.bd1fefd.0+bd1fefd",
101
+ "@aws-amplify/react-native": "1.0.23-unstable.bd1fefd.0+bd1fefd",
102
102
  "typescript": "5.0.2"
103
103
  },
104
- "gitHead": "a254bb6c976630e9adba78a56eb7aad434a53b96"
104
+ "gitHead": "bd1fefd8c1540be2949ea70d5d9b21917455533e"
105
105
  }
@@ -1,20 +1,22 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import {
5
- PINPOINT_KEY_PREFIX,
6
- STORAGE_KEY_SUFFIX,
7
- processInAppMessages,
8
- } from '../utils';
9
- import { InAppMessage } from '../../../types';
10
4
  import flatten from 'lodash/flatten.js';
11
5
  import { defaultStorage } from '@aws-amplify/core';
6
+
12
7
  import { notifyEventListeners } from '../../../../eventListeners';
13
8
  import { assertServiceError } from '../../../errors';
9
+ import { InAppMessage } from '../../../types';
10
+ import { assertIsInitialized } from '../../../utils';
14
11
  import { DispatchEventInput } from '../types';
12
+ import {
13
+ PINPOINT_KEY_PREFIX,
14
+ STORAGE_KEY_SUFFIX,
15
+ getConflictHandler,
16
+ processInAppMessages,
17
+ } from '../utils';
15
18
  import { syncMessages } from './syncMessages';
16
- import { conflictHandler, setConflictHandler } from './setConflictHandler';
17
- import { assertIsInitialized } from '../../../utils';
19
+ import { setConflictHandler } from './setConflictHandler';
18
20
 
19
21
  /**
20
22
  * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using
@@ -27,13 +29,13 @@ import { assertIsInitialized } from '../../../utils';
27
29
  * your own logic for resolving message conflicts.
28
30
  *
29
31
  * @param input The input object that holds the event to be dispatched.
30
- *
32
+ *
31
33
  * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
32
34
  * configuration is incorrect, or if In App messaging hasn't been initialized.
33
35
  * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.
34
- *
36
+ *
35
37
  * @returns A promise that will resolve when the operation is complete.
36
- *
38
+ *
37
39
  * @example
38
40
  * ```ts
39
41
  * // Sync message before disptaching an event
@@ -54,6 +56,7 @@ export async function dispatchEvent(input: DispatchEventInput): Promise<void> {
54
56
  );
55
57
  const flattenedMessages = flatten(messages);
56
58
  if (flattenedMessages.length > 0) {
59
+ const conflictHandler = getConflictHandler();
57
60
  notifyEventListeners(
58
61
  'messageReceived',
59
62
  conflictHandler(flattenedMessages),
@@ -1,12 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { InAppMessage } from '../../../types';
5
4
  import { assertIsInitialized } from '../../../utils';
6
- import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
7
-
8
- export let conflictHandler: InAppMessageConflictHandler =
9
- defaultConflictHandler;
5
+ import { SetConflictHandlerInput } from '../types';
6
+ import { setConflictHandler as setConflictHandlerInteral } from '../utils';
10
7
 
11
8
  /**
12
9
  * Set a conflict handler that will be used to resolve conflicts that may emerge
@@ -15,12 +12,12 @@ export let conflictHandler: InAppMessageConflictHandler =
15
12
  * @remark
16
13
  * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for
17
14
  * any custom handling to take effect.
18
- *
15
+ *
19
16
  * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
20
17
  * configuration is incorrect, or if In App messaging hasn't been initialized.
21
- *
18
+ *
22
19
  * @param input The input object that holds the conflict handler to be used.
23
- *
20
+ *
24
21
  * @example
25
22
  * ```ts
26
23
  * // Sync messages before dispatching an event
@@ -42,30 +39,5 @@ export let conflictHandler: InAppMessageConflictHandler =
42
39
  */
43
40
  export function setConflictHandler(input: SetConflictHandlerInput): void {
44
41
  assertIsInitialized();
45
- conflictHandler = input;
46
- }
47
-
48
- function defaultConflictHandler(messages: InAppMessage[]): InAppMessage {
49
- // default behavior is to return the message closest to expiry
50
- // this function assumes that messages processed by providers already filters out expired messages
51
- const sorted = messages.sort((a, b) => {
52
- const endDateA = a.metadata?.endDate;
53
- const endDateB = b.metadata?.endDate;
54
- // if both message end dates are falsy or have the same date string, treat them as equal
55
- if (endDateA === endDateB) {
56
- return 0;
57
- }
58
- // if only message A has an end date, treat it as closer to expiry
59
- if (endDateA && !endDateB) {
60
- return -1;
61
- }
62
- // if only message B has an end date, treat it as closer to expiry
63
- if (!endDateA && endDateB) {
64
- return 1;
65
- }
66
- // otherwise, compare them
67
- return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
68
- });
69
- // always return the top sorted
70
- return sorted[0];
42
+ setConflictHandlerInteral(input);
71
43
  }
@@ -0,0 +1,52 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { InAppMessage } from '../../../types';
5
+ import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
6
+
7
+ /**
8
+ * The default conflict handler. Can be overridden by `setConflictHandler`.
9
+ */
10
+ let conflictHandler: InAppMessageConflictHandler = (
11
+ messages: InAppMessage[],
12
+ ): InAppMessage => {
13
+ // default behavior is to return the message closest to expiry
14
+ // this function assumes that messages processed by providers already filters out expired messages
15
+ const sorted = messages.sort((a, b) => {
16
+ const endDateA = a.metadata?.endDate;
17
+ const endDateB = b.metadata?.endDate;
18
+ // if both message end dates are falsy or have the same date string, treat them as equal
19
+ if (endDateA === endDateB) {
20
+ return 0;
21
+ }
22
+ // if only message A has an end date, treat it as closer to expiry
23
+ if (endDateA && !endDateB) {
24
+ return -1;
25
+ }
26
+ // if only message B has an end date, treat it as closer to expiry
27
+ if (!endDateA && endDateB) {
28
+ return 1;
29
+ }
30
+ // otherwise, compare them
31
+ return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
32
+ });
33
+ // always return the top sorted
34
+ return sorted[0];
35
+ };
36
+
37
+ /**
38
+ * Sets conflict handler.
39
+ *
40
+ * @internal
41
+ */
42
+ export const setConflictHandler = (input: SetConflictHandlerInput): void => {
43
+ conflictHandler = input;
44
+ };
45
+
46
+ /**
47
+ * Returns the current conflict handler.
48
+ *
49
+ * @internal
50
+ */
51
+ export const getConflictHandler = (): InAppMessageConflictHandler =>
52
+ conflictHandler;
@@ -1,6 +1,10 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ export {
5
+ getConflictHandler,
6
+ setConflictHandler,
7
+ } from './conflictHandlerManager';
4
8
  export { resolveConfig } from './resolveConfig';
5
9
  export { resolveCredentials } from './resolveCredentials';
6
10
  export { getInAppMessagingUserAgentString } from './userAgent';