@aws-amplify/notifications 2.0.22-unstable.f6055cb.0 → 2.0.22
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.
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js +7 -7
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js +27 -3
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js +1 -4
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs +4 -5
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.d.ts +2 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs +27 -7
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.d.ts +0 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs +0 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs.map +1 -1
- package/package.json +103 -103
- package/src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts +11 -14
- package/src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts +34 -6
- package/src/inAppMessaging/providers/pinpoint/utils/index.ts +0 -4
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js +0 -50
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js.map +0 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.d.ts +0 -13
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs +0 -46
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs.map +0 -1
- package/src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.ts +0 -52
|
@@ -5,12 +5,13 @@
|
|
|
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");
|
|
8
9
|
const flatten_js_1 = tslib_1.__importDefault(require("lodash/flatten.js"));
|
|
9
10
|
const core_1 = require("@aws-amplify/core");
|
|
10
11
|
const eventListeners_1 = require("../../../../eventListeners");
|
|
11
12
|
const errors_1 = require("../../../errors");
|
|
12
|
-
const
|
|
13
|
-
const utils_2 = require("
|
|
13
|
+
const setConflictHandler_1 = require("./setConflictHandler");
|
|
14
|
+
const utils_2 = require("../../../utils");
|
|
14
15
|
/**
|
|
15
16
|
* Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using
|
|
16
17
|
* {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display
|
|
@@ -39,15 +40,14 @@ const utils_2 = require("../utils");
|
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
42
|
async function dispatchEvent(input) {
|
|
42
|
-
(0,
|
|
43
|
+
(0, utils_2.assertIsInitialized)();
|
|
43
44
|
try {
|
|
44
|
-
const key = `${
|
|
45
|
+
const key = `${utils_1.PINPOINT_KEY_PREFIX}${utils_1.STORAGE_KEY_SUFFIX}`;
|
|
45
46
|
const cachedMessages = await core_1.defaultStorage.getItem(key);
|
|
46
|
-
const messages = await (0,
|
|
47
|
+
const messages = await (0, utils_1.processInAppMessages)(cachedMessages ? JSON.parse(cachedMessages) : [], input);
|
|
47
48
|
const flattenedMessages = (0, flatten_js_1.default)(messages);
|
|
48
49
|
if (flattenedMessages.length > 0) {
|
|
49
|
-
|
|
50
|
-
(0, eventListeners_1.notifyEventListeners)('messageReceived', conflictHandler(flattenedMessages));
|
|
50
|
+
(0, eventListeners_1.notifyEventListeners)('messageReceived', (0, setConflictHandler_1.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 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
|
|
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;;"}
|
|
@@ -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 = void 0;
|
|
6
|
+
exports.setConflictHandler = exports.conflictHandler = void 0;
|
|
7
7
|
const utils_1 = require("../../../utils");
|
|
8
|
-
|
|
8
|
+
exports.conflictHandler = defaultConflictHandler;
|
|
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,7 +40,31 @@ const utils_2 = require("../utils");
|
|
|
40
40
|
*/
|
|
41
41
|
function setConflictHandler(input) {
|
|
42
42
|
(0, utils_1.assertIsInitialized)();
|
|
43
|
-
|
|
43
|
+
exports.conflictHandler = 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
|
+
}
|
|
46
70
|
//# 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 = void 0;\nconst utils_1 = require(\"../../../utils\");\
|
|
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;;"}
|
|
@@ -3,10 +3,7 @@
|
|
|
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 =
|
|
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; } });
|
|
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;
|
|
10
7
|
var resolveConfig_1 = require("./resolveConfig");
|
|
11
8
|
Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });
|
|
12
9
|
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 =
|
|
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,CAAC,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC,gCAAgC,GAAG,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAChT,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,CAAC;AAClI,IAAI,oBAAoB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AAC3D,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAoB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,oBAAoB,CAAC,kBAAkB,CAAC,EAAE,EAAE,CAAC,CAAC;AACjJ,IAAI,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACzC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,kCAAkC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,gCAAgC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpK,IAAI,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACzC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,qBAAqB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,mBAAmB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC1I,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,WAAW,CAAC,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,13 +1,13 @@
|
|
|
1
|
-
import flatten from 'lodash/flatten.js';
|
|
2
1
|
import { defaultStorage } from '@aws-amplify/core';
|
|
3
|
-
import { notifyEventListeners } from '../../../../eventListeners/eventListeners.mjs';
|
|
4
2
|
import '@aws-amplify/core/internals/utils';
|
|
5
3
|
import '../../../errors/validation.mjs';
|
|
6
4
|
import { assertServiceError } from '../../../errors/assertServiceError.mjs';
|
|
7
|
-
import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
8
|
-
import { getConflictHandler } from '../utils/conflictHandlerManager.mjs';
|
|
9
5
|
import { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX } from '../utils/constants.mjs';
|
|
10
6
|
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,7 +46,6 @@ 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();
|
|
50
49
|
notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -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 flatten from 'lodash/flatten.js';\nimport { defaultStorage } from '@aws-amplify/core';\nimport { notifyEventListeners } from '../../../../eventListeners';\nimport { assertServiceError } from '../../../errors';\nimport {
|
|
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,4 +1,5 @@
|
|
|
1
|
-
import { SetConflictHandlerInput } from '../types';
|
|
1
|
+
import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
|
|
2
|
+
export declare let conflictHandler: InAppMessageConflictHandler;
|
|
2
3
|
/**
|
|
3
4
|
* Set a conflict handler that will be used to resolve conflicts that may emerge
|
|
4
5
|
* when matching events with synced messages.
|
|
@@ -1,12 +1,8 @@
|
|
|
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';
|
|
7
2
|
|
|
8
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
9
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
let conflictHandler = defaultConflictHandler;
|
|
10
6
|
/**
|
|
11
7
|
* Set a conflict handler that will be used to resolve conflicts that may emerge
|
|
12
8
|
* when matching events with synced messages.
|
|
@@ -41,8 +37,32 @@ import '../utils/messageProcessingHelpers.mjs';
|
|
|
41
37
|
*/
|
|
42
38
|
function setConflictHandler(input) {
|
|
43
39
|
assertIsInitialized();
|
|
44
|
-
|
|
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];
|
|
45
65
|
}
|
|
46
66
|
|
|
47
|
-
export { setConflictHandler };
|
|
67
|
+
export { conflictHandler, setConflictHandler };
|
|
48
68
|
//# 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';\
|
|
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,4 +1,3 @@
|
|
|
1
|
-
export { getConflictHandler, setConflictHandler } from './conflictHandlerManager.mjs';
|
|
2
1
|
export { resolveConfig } from './resolveConfig.mjs';
|
|
3
2
|
export { resolveCredentials } from './resolveCredentials.mjs';
|
|
4
3
|
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,105 +1,105 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
2
|
+
"name": "@aws-amplify/notifications",
|
|
3
|
+
"version": "2.0.22",
|
|
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 -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": "tslint 'src/**/*.ts' && npm run ts-coverage",
|
|
25
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88.21"
|
|
26
|
+
},
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
">=4.2": {
|
|
29
|
+
"in-app-messaging": [
|
|
30
|
+
"./dist/esm/inAppMessaging/index.d.ts"
|
|
31
|
+
],
|
|
32
|
+
"push-notifications": [
|
|
33
|
+
"./dist/esm/pushNotifications/providers/index.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"in-app-messaging/pinpoint": [
|
|
36
|
+
"./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts"
|
|
37
|
+
],
|
|
38
|
+
"push-notifications/pinpoint": [
|
|
39
|
+
"./dist/esm/pushNotifications/providers/pinpoint/index.d.ts"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"import": "./dist/esm/index.mjs",
|
|
46
|
+
"require": "./dist/cjs/index.js",
|
|
47
|
+
"react-native": "./src/index.ts"
|
|
48
|
+
},
|
|
49
|
+
"./in-app-messaging": {
|
|
50
|
+
"types": "./dist/esm/inAppMessaging/index.d.ts",
|
|
51
|
+
"import": "./dist/esm/inAppMessaging/index.mjs",
|
|
52
|
+
"require": "./dist/cjs/inAppMessaging/index.js",
|
|
53
|
+
"react-native": "./src/inAppMessaging/index.ts"
|
|
54
|
+
},
|
|
55
|
+
"./push-notifications": {
|
|
56
|
+
"types": "./dist/esm/pushNotifications/index.d.ts",
|
|
57
|
+
"import": "./dist/esm/pushNotifications/index.mjs",
|
|
58
|
+
"require": "./dist/cjs/pushNotifications/index.js",
|
|
59
|
+
"react-native": "./src/pushNotifications/index.ts"
|
|
60
|
+
},
|
|
61
|
+
"./in-app-messaging/pinpoint": {
|
|
62
|
+
"types": "./dist/esm/inAppMessaging/providers/pinpoint/index.d.ts",
|
|
63
|
+
"import": "./dist/esm/inAppMessaging/providers/pinpoint/index.mjs",
|
|
64
|
+
"require": "./dist/cjs/inAppMessaging/providers/pinpoint/index.js",
|
|
65
|
+
"react-native": "./src/inAppMessaging/providers/pinpoint/index.ts"
|
|
66
|
+
},
|
|
67
|
+
"./push-notifications/pinpoint": {
|
|
68
|
+
"types": "./dist/esm/pushNotifications/providers/pinpoint/index.d.ts",
|
|
69
|
+
"import": "./dist/esm/pushNotifications/providers/pinpoint/index.mjs",
|
|
70
|
+
"require": "./dist/cjs/pushNotifications/providers/pinpoint/index.js",
|
|
71
|
+
"react-native": "./src/pushNotifications/providers/pinpoint/index.ts"
|
|
72
|
+
},
|
|
73
|
+
"./package.json": "./package.json"
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
78
|
+
},
|
|
79
|
+
"author": "Amazon Web Services",
|
|
80
|
+
"license": "Apache-2.0",
|
|
81
|
+
"bugs": {
|
|
82
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
83
|
+
},
|
|
84
|
+
"homepage": "https://docs.amplify.aws/",
|
|
85
|
+
"files": [
|
|
86
|
+
"dist/cjs",
|
|
87
|
+
"dist/esm",
|
|
88
|
+
"src",
|
|
89
|
+
"in-app-messaging",
|
|
90
|
+
"push-notifications"
|
|
91
|
+
],
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"lodash": "^4.17.21",
|
|
94
|
+
"tslib": "^2.5.0"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@aws-amplify/core": "^6.0.0"
|
|
98
|
+
},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@aws-amplify/core": "6.0.22",
|
|
101
|
+
"@aws-amplify/react-native": "1.0.23",
|
|
102
|
+
"typescript": "5.0.2"
|
|
103
|
+
},
|
|
104
|
+
"gitHead": "080f8c11e9eb89cdcd29d78a2b4fe07c8c5b5404"
|
|
105
105
|
}
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import flatten from 'lodash/flatten.js';
|
|
5
|
-
import { defaultStorage } from '@aws-amplify/core';
|
|
6
|
-
|
|
7
|
-
import { notifyEventListeners } from '../../../../eventListeners';
|
|
8
|
-
import { assertServiceError } from '../../../errors';
|
|
9
|
-
import { InAppMessage } from '../../../types';
|
|
10
|
-
import { assertIsInitialized } from '../../../utils';
|
|
11
|
-
import { DispatchEventInput } from '../types';
|
|
12
4
|
import {
|
|
13
5
|
PINPOINT_KEY_PREFIX,
|
|
14
6
|
STORAGE_KEY_SUFFIX,
|
|
15
|
-
getConflictHandler,
|
|
16
7
|
processInAppMessages,
|
|
17
8
|
} from '../utils';
|
|
9
|
+
import { InAppMessage } from '../../../types';
|
|
10
|
+
import flatten from 'lodash/flatten.js';
|
|
11
|
+
import { defaultStorage } from '@aws-amplify/core';
|
|
12
|
+
import { notifyEventListeners } from '../../../../eventListeners';
|
|
13
|
+
import { assertServiceError } from '../../../errors';
|
|
14
|
+
import { DispatchEventInput } from '../types';
|
|
18
15
|
import { syncMessages } from './syncMessages';
|
|
19
|
-
import { setConflictHandler } from './setConflictHandler';
|
|
16
|
+
import { conflictHandler, setConflictHandler } from './setConflictHandler';
|
|
17
|
+
import { assertIsInitialized } from '../../../utils';
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using
|
|
@@ -29,13 +27,13 @@ import { setConflictHandler } from './setConflictHandler';
|
|
|
29
27
|
* your own logic for resolving message conflicts.
|
|
30
28
|
*
|
|
31
29
|
* @param input The input object that holds the event to be dispatched.
|
|
32
|
-
*
|
|
30
|
+
*
|
|
33
31
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
34
32
|
* configuration is incorrect, or if In App messaging hasn't been initialized.
|
|
35
33
|
* @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.
|
|
36
|
-
*
|
|
34
|
+
*
|
|
37
35
|
* @returns A promise that will resolve when the operation is complete.
|
|
38
|
-
*
|
|
36
|
+
*
|
|
39
37
|
* @example
|
|
40
38
|
* ```ts
|
|
41
39
|
* // Sync message before disptaching an event
|
|
@@ -56,7 +54,6 @@ export async function dispatchEvent(input: DispatchEventInput): Promise<void> {
|
|
|
56
54
|
);
|
|
57
55
|
const flattenedMessages = flatten(messages);
|
|
58
56
|
if (flattenedMessages.length > 0) {
|
|
59
|
-
const conflictHandler = getConflictHandler();
|
|
60
57
|
notifyEventListeners(
|
|
61
58
|
'messageReceived',
|
|
62
59
|
conflictHandler(flattenedMessages),
|
|
@@ -1,9 +1,12 @@
|
|
|
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';
|
|
4
5
|
import { assertIsInitialized } from '../../../utils';
|
|
5
|
-
import { SetConflictHandlerInput } from '../types';
|
|
6
|
-
|
|
6
|
+
import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
|
|
7
|
+
|
|
8
|
+
export let conflictHandler: InAppMessageConflictHandler =
|
|
9
|
+
defaultConflictHandler;
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Set a conflict handler that will be used to resolve conflicts that may emerge
|
|
@@ -12,12 +15,12 @@ import { setConflictHandler as setConflictHandlerInteral } from '../utils';
|
|
|
12
15
|
* @remark
|
|
13
16
|
* The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for
|
|
14
17
|
* any custom handling to take effect.
|
|
15
|
-
*
|
|
18
|
+
*
|
|
16
19
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
17
20
|
* configuration is incorrect, or if In App messaging hasn't been initialized.
|
|
18
|
-
*
|
|
21
|
+
*
|
|
19
22
|
* @param input The input object that holds the conflict handler to be used.
|
|
20
|
-
*
|
|
23
|
+
*
|
|
21
24
|
* @example
|
|
22
25
|
* ```ts
|
|
23
26
|
* // Sync messages before dispatching an event
|
|
@@ -39,5 +42,30 @@ import { setConflictHandler as setConflictHandlerInteral } from '../utils';
|
|
|
39
42
|
*/
|
|
40
43
|
export function setConflictHandler(input: SetConflictHandlerInput): void {
|
|
41
44
|
assertIsInitialized();
|
|
42
|
-
|
|
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];
|
|
43
71
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
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';
|
|
8
4
|
export { resolveConfig } from './resolveConfig';
|
|
9
5
|
export { resolveCredentials } from './resolveCredentials';
|
|
10
6
|
export { getInAppMessagingUserAgentString } from './userAgent';
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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 */\nconst getConflictHandler = () => conflictHandler;\nexports.getConflictHandler = getConflictHandler;\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,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACjE;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;AACA,MAAM,kBAAkB,GAAG,CAAC,KAAK,KAAK;AACtC,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,CAAC,CAAC;AACF,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA,MAAM,kBAAkB,GAAG,MAAM,eAAe,CAAC;AACjD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,52 +0,0 @@
|
|
|
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;
|