@novu/js 2.0.0-alpha.2 → 2.0.0-canary.1
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/chunk-2C4L4ZUQ.cjs +1473 -0
- package/dist/cjs/index.cjs +12 -12
- package/dist/cjs/ui/index.cjs +1227 -908
- package/dist/esm/chunk-Y6CIZNAK.mjs +1447 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/ui/index.mjs +1226 -908
- package/dist/index.css +1 -1
- package/dist/novu.min.js +7 -7
- package/dist/novu.min.js.gz +0 -0
- package/dist/types/novu.d.ts +1 -8
- package/dist/types/novu.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/ui/api/hooks/useNotifications.d.ts +2 -2
- package/dist/types/ui/api/hooks/useNotifications.d.ts.map +1 -1
- package/dist/types/ui/api/hooks/usePreferences.d.ts +1 -0
- package/dist/types/ui/api/hooks/usePreferences.d.ts.map +1 -1
- package/dist/types/ui/components/Inbox.d.ts +13 -0
- package/dist/types/ui/components/Inbox.d.ts.map +1 -1
- package/dist/types/ui/components/Notification/DefaultNotification.d.ts.map +1 -1
- package/dist/types/ui/components/Notification/NewMessagesCta.d.ts +1 -1
- package/dist/types/ui/components/Notification/NewMessagesCta.d.ts.map +1 -1
- package/dist/types/ui/components/Notification/Notification.d.ts.map +1 -1
- package/dist/types/ui/components/Notification/NotificationList.d.ts +1 -4
- package/dist/types/ui/components/Notification/NotificationList.d.ts.map +1 -1
- package/dist/types/ui/components/Notification/NotificationListSkeleton.d.ts.map +1 -1
- package/dist/types/ui/components/Renderer.d.ts +6 -13
- package/dist/types/ui/components/Renderer.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Header/ActionsContainer.d.ts +1 -1
- package/dist/types/ui/components/elements/Header/ActionsContainer.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Header/Header.d.ts +1 -1
- package/dist/types/ui/components/elements/Header/Header.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Header/PreferencesHeader.d.ts +1 -1
- package/dist/types/ui/components/elements/Header/PreferencesHeader.d.ts.map +1 -1
- package/dist/types/ui/components/elements/InboxStatus/InboxStatusDropdown.d.ts.map +1 -1
- package/dist/types/ui/components/elements/InboxStatus/constants.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Preferences/ChannelRow.d.ts +1 -0
- package/dist/types/ui/components/elements/Preferences/ChannelRow.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Preferences/Preferences.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Preferences/Switch.d.ts +1 -0
- package/dist/types/ui/components/elements/Preferences/Switch.d.ts.map +1 -1
- package/dist/types/ui/components/elements/Root.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Button.d.ts +1 -1
- package/dist/types/ui/components/primitives/Button.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownContent.d.ts +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownContent.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownItem.d.ts +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownItem.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownTrigger.d.ts +1 -1
- package/dist/types/ui/components/primitives/Dropdown/DropdownTrigger.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Dropdown/index.d.ts +5 -5
- package/dist/types/ui/components/primitives/Popover/PopoverContent.d.ts +1 -1
- package/dist/types/ui/components/primitives/Popover/PopoverContent.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Popover/PopoverTrigger.d.ts +1 -1
- package/dist/types/ui/components/primitives/Popover/PopoverTrigger.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Popover/index.d.ts +2 -2
- package/dist/types/ui/components/primitives/Skeleton.d.ts +1 -1
- package/dist/types/ui/components/primitives/Skeleton.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsContent.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsContent.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsList.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsList.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsRoot.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsRoot.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsTrigger.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tabs/TabsTrigger.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tabs/index.d.ts +4 -4
- package/dist/types/ui/components/primitives/Tooltip/TooltipContent.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tooltip/TooltipTrigger.d.ts +1 -1
- package/dist/types/ui/components/primitives/Tooltip/TooltipTrigger.d.ts.map +1 -1
- package/dist/types/ui/components/primitives/Tooltip/index.d.ts +5 -3
- package/dist/types/ui/components/primitives/Tooltip/index.d.ts.map +1 -1
- package/dist/types/ui/config/appearanceKeys.d.ts +2 -0
- package/dist/types/ui/config/appearanceKeys.d.ts.map +1 -0
- package/dist/types/ui/config/defaultLocalization.d.ts +2 -0
- package/dist/types/ui/config/defaultLocalization.d.ts.map +1 -1
- package/dist/types/ui/config/defaultVariables.d.ts +3 -0
- package/dist/types/ui/config/defaultVariables.d.ts.map +1 -0
- package/dist/types/ui/config/index.d.ts +3 -1
- package/dist/types/ui/config/index.d.ts.map +1 -1
- package/dist/types/ui/context/AppearanceContext.d.ts +1 -24
- package/dist/types/ui/context/AppearanceContext.d.ts.map +1 -1
- package/dist/types/ui/context/CountContext.d.ts.map +1 -1
- package/dist/types/ui/context/LocalizationContext.d.ts +1 -2
- package/dist/types/ui/context/LocalizationContext.d.ts.map +1 -1
- package/dist/types/ui/context/NovuContext.d.ts +2 -1
- package/dist/types/ui/context/NovuContext.d.ts.map +1 -1
- package/dist/types/ui/helpers/createDelayedLoading.d.ts +3 -0
- package/dist/types/ui/helpers/createDelayedLoading.d.ts.map +1 -0
- package/dist/types/ui/helpers/createInfiniteScroll.d.ts.map +1 -1
- package/dist/types/ui/helpers/useStyle.d.ts +1 -1
- package/dist/types/ui/helpers/useStyle.d.ts.map +1 -1
- package/dist/types/ui/helpers/utils.d.ts +1 -1
- package/dist/types/ui/helpers/utils.d.ts.map +1 -1
- package/dist/types/ui/icons/Archive.d.ts +2 -1
- package/dist/types/ui/icons/Archive.d.ts.map +1 -1
- package/dist/types/ui/icons/ArchiveRead.d.ts +2 -1
- package/dist/types/ui/icons/ArchiveRead.d.ts.map +1 -1
- package/dist/types/ui/icons/ArrowDropDown.d.ts +2 -1
- package/dist/types/ui/icons/ArrowDropDown.d.ts.map +1 -1
- package/dist/types/ui/icons/ArrowLeft.d.ts +2 -1
- package/dist/types/ui/icons/ArrowLeft.d.ts.map +1 -1
- package/dist/types/ui/icons/BellIcon.d.ts +2 -1
- package/dist/types/ui/icons/BellIcon.d.ts.map +1 -1
- package/dist/types/ui/icons/Chat.d.ts +2 -1
- package/dist/types/ui/icons/Chat.d.ts.map +1 -1
- package/dist/types/ui/icons/Check.d.ts +1 -1
- package/dist/types/ui/icons/Check.d.ts.map +1 -1
- package/dist/types/ui/icons/Dots.d.ts +3 -0
- package/dist/types/ui/icons/Dots.d.ts.map +1 -0
- package/dist/types/ui/icons/Email.d.ts +2 -1
- package/dist/types/ui/icons/Email.d.ts.map +1 -1
- package/dist/types/ui/icons/EmptyIcon.d.ts +2 -1
- package/dist/types/ui/icons/EmptyIcon.d.ts.map +1 -1
- package/dist/types/ui/icons/InApp.d.ts +2 -1
- package/dist/types/ui/icons/InApp.d.ts.map +1 -1
- package/dist/types/ui/icons/Inbox.d.ts +2 -1
- package/dist/types/ui/icons/Inbox.d.ts.map +1 -1
- package/dist/types/ui/icons/Lock.d.ts +2 -0
- package/dist/types/ui/icons/Lock.d.ts.map +1 -0
- package/dist/types/ui/icons/Novu.d.ts +2 -1
- package/dist/types/ui/icons/Novu.d.ts.map +1 -1
- package/dist/types/ui/icons/Push.d.ts +2 -1
- package/dist/types/ui/icons/Push.d.ts.map +1 -1
- package/dist/types/ui/icons/ReadAll.d.ts +2 -1
- package/dist/types/ui/icons/ReadAll.d.ts.map +1 -1
- package/dist/types/ui/icons/Settings.d.ts +2 -1
- package/dist/types/ui/icons/Settings.d.ts.map +1 -1
- package/dist/types/ui/icons/Sms.d.ts +2 -1
- package/dist/types/ui/icons/Sms.d.ts.map +1 -1
- package/dist/types/ui/icons/Unarchive.d.ts +2 -1
- package/dist/types/ui/icons/Unarchive.d.ts.map +1 -1
- package/dist/types/ui/icons/Unread.d.ts +2 -1
- package/dist/types/ui/icons/Unread.d.ts.map +1 -1
- package/dist/types/ui/icons/index.d.ts +2 -1
- package/dist/types/ui/icons/index.d.ts.map +1 -1
- package/dist/types/ui/index.d.ts +3 -3
- package/dist/types/ui/index.d.ts.map +1 -1
- package/dist/types/ui/novuUI.d.ts +2 -4
- package/dist/types/ui/novuUI.d.ts.map +1 -1
- package/dist/types/ui/themes/dark.d.ts +1 -1
- package/dist/types/ui/themes/dark.d.ts.map +1 -1
- package/dist/types/ui/types.d.ts +34 -14
- package/dist/types/ui/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/chunk-NETTDHV7.cjs +0 -1325
- package/dist/esm/chunk-63A6UD3T.mjs +0 -1307
- package/dist/types/ui/config/defaultAppearance.d.ts +0 -3
- package/dist/types/ui/config/defaultAppearance.d.ts.map +0 -1
- package/dist/types/ui/icons/DotsMenu.d.ts +0 -6
- package/dist/types/ui/icons/DotsMenu.d.ts.map +0 -1
|
@@ -0,0 +1,1473 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mitt = require('mitt');
|
|
4
|
+
var client = require('@novu/client');
|
|
5
|
+
var io = require('socket.io-client');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var mitt__default = /*#__PURE__*/_interopDefault(mitt);
|
|
10
|
+
var io__default = /*#__PURE__*/_interopDefault(io);
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __defProps = Object.defineProperties;
|
|
14
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
15
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
18
|
+
var __typeError = (msg) => {
|
|
19
|
+
throw TypeError(msg);
|
|
20
|
+
};
|
|
21
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
22
|
+
var __spreadValues = (a, b) => {
|
|
23
|
+
for (var prop in b || (b = {}))
|
|
24
|
+
if (__hasOwnProp.call(b, prop))
|
|
25
|
+
__defNormalProp(a, prop, b[prop]);
|
|
26
|
+
if (__getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
28
|
+
if (__propIsEnum.call(b, prop))
|
|
29
|
+
__defNormalProp(a, prop, b[prop]);
|
|
30
|
+
}
|
|
31
|
+
return a;
|
|
32
|
+
};
|
|
33
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
34
|
+
var __objRest = (source, exclude) => {
|
|
35
|
+
var target = {};
|
|
36
|
+
for (var prop in source)
|
|
37
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
38
|
+
target[prop] = source[prop];
|
|
39
|
+
if (source != null && __getOwnPropSymbols)
|
|
40
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
41
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
42
|
+
target[prop] = source[prop];
|
|
43
|
+
}
|
|
44
|
+
return target;
|
|
45
|
+
};
|
|
46
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
47
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
48
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
49
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
50
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
51
|
+
var __async = (__this, __arguments, generator) => {
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
var fulfilled = (value) => {
|
|
54
|
+
try {
|
|
55
|
+
step(generator.next(value));
|
|
56
|
+
} catch (e) {
|
|
57
|
+
reject(e);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var rejected = (value) => {
|
|
61
|
+
try {
|
|
62
|
+
step(generator.throw(value));
|
|
63
|
+
} catch (e) {
|
|
64
|
+
reject(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
68
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/types.ts
|
|
73
|
+
var NotificationStatus = /* @__PURE__ */ ((NotificationStatus2) => {
|
|
74
|
+
NotificationStatus2["READ"] = "read";
|
|
75
|
+
NotificationStatus2["SEEN"] = "seen";
|
|
76
|
+
NotificationStatus2["UNREAD"] = "unread";
|
|
77
|
+
NotificationStatus2["UNSEEN"] = "unseen";
|
|
78
|
+
return NotificationStatus2;
|
|
79
|
+
})(NotificationStatus || {});
|
|
80
|
+
var NotificationButton = /* @__PURE__ */ ((NotificationButton2) => {
|
|
81
|
+
NotificationButton2["PRIMARY"] = "primary";
|
|
82
|
+
NotificationButton2["SECONDARY"] = "secondary";
|
|
83
|
+
return NotificationButton2;
|
|
84
|
+
})(NotificationButton || {});
|
|
85
|
+
var NotificationActionStatus = /* @__PURE__ */ ((NotificationActionStatus2) => {
|
|
86
|
+
NotificationActionStatus2["PENDING"] = "pending";
|
|
87
|
+
NotificationActionStatus2["DONE"] = "done";
|
|
88
|
+
return NotificationActionStatus2;
|
|
89
|
+
})(NotificationActionStatus || {});
|
|
90
|
+
var CtaType = /* @__PURE__ */ ((CtaType2) => {
|
|
91
|
+
CtaType2["REDIRECT"] = "redirect";
|
|
92
|
+
return CtaType2;
|
|
93
|
+
})(CtaType || {});
|
|
94
|
+
var PreferenceLevel = /* @__PURE__ */ ((PreferenceLevel2) => {
|
|
95
|
+
PreferenceLevel2["GLOBAL"] = "global";
|
|
96
|
+
PreferenceLevel2["TEMPLATE"] = "template";
|
|
97
|
+
return PreferenceLevel2;
|
|
98
|
+
})(PreferenceLevel || {});
|
|
99
|
+
var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
|
|
100
|
+
ChannelType2["IN_APP"] = "in_app";
|
|
101
|
+
ChannelType2["EMAIL"] = "email";
|
|
102
|
+
ChannelType2["SMS"] = "sms";
|
|
103
|
+
ChannelType2["CHAT"] = "chat";
|
|
104
|
+
ChannelType2["PUSH"] = "push";
|
|
105
|
+
return ChannelType2;
|
|
106
|
+
})(ChannelType || {});
|
|
107
|
+
var PreferenceOverrideSource = /* @__PURE__ */ ((PreferenceOverrideSource2) => {
|
|
108
|
+
PreferenceOverrideSource2["SUBSCRIBER"] = "subscriber";
|
|
109
|
+
PreferenceOverrideSource2["TEMPLATE"] = "template";
|
|
110
|
+
PreferenceOverrideSource2["WORKFLOW_OVERRIDE"] = "workflowOverride";
|
|
111
|
+
return PreferenceOverrideSource2;
|
|
112
|
+
})(PreferenceOverrideSource || {});
|
|
113
|
+
var WebSocketEvent = /* @__PURE__ */ ((WebSocketEvent2) => {
|
|
114
|
+
WebSocketEvent2["RECEIVED"] = "notification_received";
|
|
115
|
+
WebSocketEvent2["UNREAD"] = "unread_count_changed";
|
|
116
|
+
WebSocketEvent2["UNSEEN"] = "unseen_count_changed";
|
|
117
|
+
return WebSocketEvent2;
|
|
118
|
+
})(WebSocketEvent || {});
|
|
119
|
+
var ActionTypeEnum = /* @__PURE__ */ ((ActionTypeEnum2) => {
|
|
120
|
+
ActionTypeEnum2["PRIMARY"] = "primary";
|
|
121
|
+
ActionTypeEnum2["SECONDARY"] = "secondary";
|
|
122
|
+
return ActionTypeEnum2;
|
|
123
|
+
})(ActionTypeEnum || {});
|
|
124
|
+
var PreferenceOverrideSourceEnum = /* @__PURE__ */ ((PreferenceOverrideSourceEnum2) => {
|
|
125
|
+
PreferenceOverrideSourceEnum2["SUBSCRIBER"] = "subscriber";
|
|
126
|
+
PreferenceOverrideSourceEnum2["TEMPLATE"] = "template";
|
|
127
|
+
PreferenceOverrideSourceEnum2["WORKFLOW_OVERRIDE"] = "workflowOverride";
|
|
128
|
+
return PreferenceOverrideSourceEnum2;
|
|
129
|
+
})(PreferenceOverrideSourceEnum || {});
|
|
130
|
+
var _instance, _mittEmitter;
|
|
131
|
+
var _NovuEventEmitter = class _NovuEventEmitter {
|
|
132
|
+
constructor() {
|
|
133
|
+
__privateAdd(this, _mittEmitter);
|
|
134
|
+
__privateSet(this, _mittEmitter, mitt__default.default());
|
|
135
|
+
}
|
|
136
|
+
static getInstance(options) {
|
|
137
|
+
if (options == null ? void 0 : options.recreate) {
|
|
138
|
+
__privateSet(_NovuEventEmitter, _instance, new _NovuEventEmitter());
|
|
139
|
+
}
|
|
140
|
+
return __privateGet(_NovuEventEmitter, _instance);
|
|
141
|
+
}
|
|
142
|
+
on(eventName, listener) {
|
|
143
|
+
__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
144
|
+
}
|
|
145
|
+
off(eventName, listener) {
|
|
146
|
+
__privateGet(this, _mittEmitter).off(eventName, listener);
|
|
147
|
+
}
|
|
148
|
+
emit(type, event) {
|
|
149
|
+
__privateGet(this, _mittEmitter).emit(type, event);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
_instance = new WeakMap();
|
|
153
|
+
_mittEmitter = new WeakMap();
|
|
154
|
+
__privateAdd(_NovuEventEmitter, _instance);
|
|
155
|
+
var NovuEventEmitter = _NovuEventEmitter;
|
|
156
|
+
|
|
157
|
+
// src/utils/errors.ts
|
|
158
|
+
var NovuError = class extends Error {
|
|
159
|
+
constructor(message, originalError) {
|
|
160
|
+
super(message);
|
|
161
|
+
this.originalError = originalError;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var NOVU_API_VERSION = "2024-06-26";
|
|
165
|
+
var INBOX_ROUTE = "/inbox";
|
|
166
|
+
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
167
|
+
var _httpClient;
|
|
168
|
+
var InboxService = class {
|
|
169
|
+
constructor(options = {}) {
|
|
170
|
+
this.isSessionInitialized = false;
|
|
171
|
+
__privateAdd(this, _httpClient);
|
|
172
|
+
__privateSet(this, _httpClient, new client.HttpClient(options));
|
|
173
|
+
__privateGet(this, _httpClient).updateHeaders({
|
|
174
|
+
"Novu-API-Version": NOVU_API_VERSION
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
initializeSession(_0) {
|
|
178
|
+
return __async(this, arguments, function* ({
|
|
179
|
+
applicationIdentifier,
|
|
180
|
+
subscriberId,
|
|
181
|
+
subscriberHash
|
|
182
|
+
}) {
|
|
183
|
+
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
184
|
+
applicationIdentifier,
|
|
185
|
+
subscriberId,
|
|
186
|
+
subscriberHash
|
|
187
|
+
});
|
|
188
|
+
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
189
|
+
this.isSessionInitialized = true;
|
|
190
|
+
return response;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
fetchNotifications({
|
|
194
|
+
after,
|
|
195
|
+
archived,
|
|
196
|
+
limit = 10,
|
|
197
|
+
offset,
|
|
198
|
+
read: read2,
|
|
199
|
+
tags
|
|
200
|
+
}) {
|
|
201
|
+
const queryParams = new URLSearchParams(`limit=${limit}`);
|
|
202
|
+
if (after) {
|
|
203
|
+
queryParams.append("after", after);
|
|
204
|
+
}
|
|
205
|
+
if (offset) {
|
|
206
|
+
queryParams.append("offset", `${offset}`);
|
|
207
|
+
}
|
|
208
|
+
if (tags) {
|
|
209
|
+
tags.forEach((tag) => queryParams.append("tags[]", tag));
|
|
210
|
+
}
|
|
211
|
+
if (read2 !== void 0) {
|
|
212
|
+
queryParams.append("read", `${read2}`);
|
|
213
|
+
}
|
|
214
|
+
if (archived !== void 0) {
|
|
215
|
+
queryParams.append("archived", `${archived}`);
|
|
216
|
+
}
|
|
217
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}?${queryParams.toString()}`);
|
|
218
|
+
}
|
|
219
|
+
count({ filters }) {
|
|
220
|
+
return __privateGet(this, _httpClient).getFullResponse(`${INBOX_NOTIFICATIONS_ROUTE}/count?filters=${JSON.stringify(filters)}`);
|
|
221
|
+
}
|
|
222
|
+
read(notificationId) {
|
|
223
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
224
|
+
}
|
|
225
|
+
unread(notificationId) {
|
|
226
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
227
|
+
}
|
|
228
|
+
archive(notificationId) {
|
|
229
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
230
|
+
}
|
|
231
|
+
unarchive(notificationId) {
|
|
232
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
233
|
+
}
|
|
234
|
+
readAll({ tags }) {
|
|
235
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
|
|
236
|
+
}
|
|
237
|
+
archiveAll({ tags }) {
|
|
238
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
|
|
239
|
+
}
|
|
240
|
+
archiveAllRead({ tags }) {
|
|
241
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
|
|
242
|
+
}
|
|
243
|
+
completeAction({
|
|
244
|
+
actionType,
|
|
245
|
+
notificationId
|
|
246
|
+
}) {
|
|
247
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
248
|
+
actionType
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
revertAction({
|
|
252
|
+
actionType,
|
|
253
|
+
notificationId
|
|
254
|
+
}) {
|
|
255
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
256
|
+
actionType
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
fetchPreferences() {
|
|
260
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences`);
|
|
261
|
+
}
|
|
262
|
+
updateGlobalPreferences(channelPreferences) {
|
|
263
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channelPreferences);
|
|
264
|
+
}
|
|
265
|
+
updateWorkflowPreferences({
|
|
266
|
+
workflowId,
|
|
267
|
+
channelPreferences
|
|
268
|
+
}) {
|
|
269
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channelPreferences);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
_httpClient = new WeakMap();
|
|
273
|
+
|
|
274
|
+
// src/utils/inbox-service-singleton.ts
|
|
275
|
+
var _instance2;
|
|
276
|
+
var _InboxServiceSingleton = class _InboxServiceSingleton {
|
|
277
|
+
static getInstance(options) {
|
|
278
|
+
const isNeedsToRecreate = !!options;
|
|
279
|
+
if (isNeedsToRecreate) {
|
|
280
|
+
__privateSet(_InboxServiceSingleton, _instance2, new InboxService(options));
|
|
281
|
+
}
|
|
282
|
+
return __privateGet(_InboxServiceSingleton, _instance2);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
_instance2 = new WeakMap();
|
|
286
|
+
__privateAdd(_InboxServiceSingleton, _instance2);
|
|
287
|
+
var InboxServiceSingleton = _InboxServiceSingleton;
|
|
288
|
+
|
|
289
|
+
// src/base-module.ts
|
|
290
|
+
var _callsQueue, _sessionError;
|
|
291
|
+
var BaseModule = class {
|
|
292
|
+
constructor() {
|
|
293
|
+
__privateAdd(this, _callsQueue, []);
|
|
294
|
+
__privateAdd(this, _sessionError);
|
|
295
|
+
this._emitter = NovuEventEmitter.getInstance();
|
|
296
|
+
this._inboxService = InboxServiceSingleton.getInstance();
|
|
297
|
+
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
298
|
+
if (data) {
|
|
299
|
+
this.onSessionSuccess(data);
|
|
300
|
+
__privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
|
|
301
|
+
resolve(yield fn());
|
|
302
|
+
}));
|
|
303
|
+
__privateSet(this, _callsQueue, []);
|
|
304
|
+
} else if (error) {
|
|
305
|
+
this.onSessionError(error);
|
|
306
|
+
__privateSet(this, _sessionError, error);
|
|
307
|
+
__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
308
|
+
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
309
|
+
});
|
|
310
|
+
__privateSet(this, _callsQueue, []);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
onSessionSuccess(_) {
|
|
315
|
+
}
|
|
316
|
+
onSessionError(_) {
|
|
317
|
+
}
|
|
318
|
+
callWithSession(fn) {
|
|
319
|
+
return __async(this, null, function* () {
|
|
320
|
+
if (this._inboxService.isSessionInitialized) {
|
|
321
|
+
return fn();
|
|
322
|
+
}
|
|
323
|
+
if (__privateGet(this, _sessionError)) {
|
|
324
|
+
return Promise.resolve({
|
|
325
|
+
error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return new Promise((resolve, reject) => __async(this, null, function* () {
|
|
329
|
+
__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
330
|
+
}));
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
_callsQueue = new WeakMap();
|
|
335
|
+
_sessionError = new WeakMap();
|
|
336
|
+
|
|
337
|
+
// src/notifications/notification.ts
|
|
338
|
+
var _emitter, _inboxService;
|
|
339
|
+
var Notification = class {
|
|
340
|
+
constructor(notification) {
|
|
341
|
+
__privateAdd(this, _emitter);
|
|
342
|
+
__privateAdd(this, _inboxService);
|
|
343
|
+
__privateSet(this, _emitter, NovuEventEmitter.getInstance());
|
|
344
|
+
__privateSet(this, _inboxService, InboxServiceSingleton.getInstance());
|
|
345
|
+
this.id = notification.id;
|
|
346
|
+
this.subject = notification.subject;
|
|
347
|
+
this.body = notification.body;
|
|
348
|
+
this.to = notification.to;
|
|
349
|
+
this.isRead = notification.isRead;
|
|
350
|
+
this.isArchived = notification.isArchived;
|
|
351
|
+
this.createdAt = notification.createdAt;
|
|
352
|
+
this.readAt = notification.readAt;
|
|
353
|
+
this.archivedAt = notification.archivedAt;
|
|
354
|
+
this.avatar = notification.avatar;
|
|
355
|
+
this.primaryAction = notification.primaryAction;
|
|
356
|
+
this.secondaryAction = notification.secondaryAction;
|
|
357
|
+
this.channelType = notification.channelType;
|
|
358
|
+
this.tags = notification.tags;
|
|
359
|
+
this.redirect = notification.redirect;
|
|
360
|
+
}
|
|
361
|
+
read() {
|
|
362
|
+
return read({
|
|
363
|
+
emitter: __privateGet(this, _emitter),
|
|
364
|
+
apiService: __privateGet(this, _inboxService),
|
|
365
|
+
args: {
|
|
366
|
+
notification: this
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
unread() {
|
|
371
|
+
return unread({
|
|
372
|
+
emitter: __privateGet(this, _emitter),
|
|
373
|
+
apiService: __privateGet(this, _inboxService),
|
|
374
|
+
args: {
|
|
375
|
+
notification: this
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
archive() {
|
|
380
|
+
return archive({
|
|
381
|
+
emitter: __privateGet(this, _emitter),
|
|
382
|
+
apiService: __privateGet(this, _inboxService),
|
|
383
|
+
args: {
|
|
384
|
+
notification: this
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
unarchive() {
|
|
389
|
+
return unarchive({
|
|
390
|
+
emitter: __privateGet(this, _emitter),
|
|
391
|
+
apiService: __privateGet(this, _inboxService),
|
|
392
|
+
args: {
|
|
393
|
+
notification: this
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
completePrimary() {
|
|
398
|
+
if (!this.primaryAction) {
|
|
399
|
+
throw new Error("Primary action is not available");
|
|
400
|
+
}
|
|
401
|
+
return completeAction({
|
|
402
|
+
emitter: __privateGet(this, _emitter),
|
|
403
|
+
apiService: __privateGet(this, _inboxService),
|
|
404
|
+
args: {
|
|
405
|
+
notification: this
|
|
406
|
+
},
|
|
407
|
+
actionType: "primary" /* PRIMARY */
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
completeSecondary() {
|
|
411
|
+
if (!this.primaryAction) {
|
|
412
|
+
throw new Error("Secondary action is not available");
|
|
413
|
+
}
|
|
414
|
+
return completeAction({
|
|
415
|
+
emitter: __privateGet(this, _emitter),
|
|
416
|
+
apiService: __privateGet(this, _inboxService),
|
|
417
|
+
args: {
|
|
418
|
+
notification: this
|
|
419
|
+
},
|
|
420
|
+
actionType: "secondary" /* SECONDARY */
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
revertPrimary() {
|
|
424
|
+
if (!this.primaryAction) {
|
|
425
|
+
throw new Error("Primary action is not available");
|
|
426
|
+
}
|
|
427
|
+
return revertAction({
|
|
428
|
+
emitter: __privateGet(this, _emitter),
|
|
429
|
+
apiService: __privateGet(this, _inboxService),
|
|
430
|
+
args: {
|
|
431
|
+
notification: this
|
|
432
|
+
},
|
|
433
|
+
actionType: "primary" /* PRIMARY */
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
revertSecondary() {
|
|
437
|
+
if (!this.primaryAction) {
|
|
438
|
+
throw new Error("Secondary action is not available");
|
|
439
|
+
}
|
|
440
|
+
return revertAction({
|
|
441
|
+
emitter: __privateGet(this, _emitter),
|
|
442
|
+
apiService: __privateGet(this, _inboxService),
|
|
443
|
+
args: {
|
|
444
|
+
notification: this
|
|
445
|
+
},
|
|
446
|
+
actionType: "secondary" /* SECONDARY */
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
on(eventName, listener) {
|
|
450
|
+
__privateGet(this, _emitter).on(eventName, listener);
|
|
451
|
+
}
|
|
452
|
+
off(eventName, listener) {
|
|
453
|
+
__privateGet(this, _emitter).off(eventName, listener);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
_emitter = new WeakMap();
|
|
457
|
+
_inboxService = new WeakMap();
|
|
458
|
+
|
|
459
|
+
// src/notifications/helpers.ts
|
|
460
|
+
var read = (_0) => __async(void 0, [_0], function* ({
|
|
461
|
+
emitter,
|
|
462
|
+
apiService,
|
|
463
|
+
args
|
|
464
|
+
}) {
|
|
465
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, {
|
|
466
|
+
isRead: true,
|
|
467
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
468
|
+
isArchived: false,
|
|
469
|
+
archivedAt: void 0
|
|
470
|
+
});
|
|
471
|
+
try {
|
|
472
|
+
emitter.emit("notification.read.pending", {
|
|
473
|
+
args,
|
|
474
|
+
data: optimisticValue
|
|
475
|
+
});
|
|
476
|
+
const response = yield apiService.read(notificationId);
|
|
477
|
+
const updatedNotification = new Notification(response);
|
|
478
|
+
emitter.emit("notification.read.resolved", { args, data: updatedNotification });
|
|
479
|
+
return { data: updatedNotification };
|
|
480
|
+
} catch (error) {
|
|
481
|
+
emitter.emit("notification.read.resolved", { args, error });
|
|
482
|
+
return { error: new NovuError("Failed to read notification", error) };
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
var unread = (_0) => __async(void 0, [_0], function* ({
|
|
486
|
+
emitter,
|
|
487
|
+
apiService,
|
|
488
|
+
args
|
|
489
|
+
}) {
|
|
490
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, {
|
|
491
|
+
isRead: false,
|
|
492
|
+
readAt: null,
|
|
493
|
+
isArchived: false,
|
|
494
|
+
archivedAt: void 0
|
|
495
|
+
});
|
|
496
|
+
try {
|
|
497
|
+
emitter.emit("notification.unread.pending", {
|
|
498
|
+
args,
|
|
499
|
+
data: optimisticValue
|
|
500
|
+
});
|
|
501
|
+
const response = yield apiService.unread(notificationId);
|
|
502
|
+
const updatedNotification = new Notification(response);
|
|
503
|
+
emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
|
|
504
|
+
return { data: updatedNotification };
|
|
505
|
+
} catch (error) {
|
|
506
|
+
emitter.emit("notification.unread.resolved", { args, error });
|
|
507
|
+
return { error: new NovuError("Failed to unread notification", error) };
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
var archive = (_0) => __async(void 0, [_0], function* ({
|
|
511
|
+
emitter,
|
|
512
|
+
apiService,
|
|
513
|
+
args
|
|
514
|
+
}) {
|
|
515
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, {
|
|
516
|
+
isArchived: true,
|
|
517
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
518
|
+
isRead: true,
|
|
519
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
520
|
+
});
|
|
521
|
+
try {
|
|
522
|
+
emitter.emit("notification.archive.pending", {
|
|
523
|
+
args,
|
|
524
|
+
data: optimisticValue
|
|
525
|
+
});
|
|
526
|
+
const response = yield apiService.archive(notificationId);
|
|
527
|
+
const updatedNotification = new Notification(response);
|
|
528
|
+
emitter.emit("notification.archive.resolved", { args, data: updatedNotification });
|
|
529
|
+
return { data: updatedNotification };
|
|
530
|
+
} catch (error) {
|
|
531
|
+
emitter.emit("notification.archive.resolved", { args, error });
|
|
532
|
+
return { error: new NovuError("Failed to archive notification", error) };
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
var unarchive = (_0) => __async(void 0, [_0], function* ({
|
|
536
|
+
emitter,
|
|
537
|
+
apiService,
|
|
538
|
+
args
|
|
539
|
+
}) {
|
|
540
|
+
const { notificationId, optimisticValue } = getNotificationDetails(args, {
|
|
541
|
+
isArchived: false,
|
|
542
|
+
archivedAt: null,
|
|
543
|
+
isRead: true,
|
|
544
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
545
|
+
});
|
|
546
|
+
try {
|
|
547
|
+
emitter.emit("notification.unarchive.pending", {
|
|
548
|
+
args,
|
|
549
|
+
data: optimisticValue
|
|
550
|
+
});
|
|
551
|
+
const response = yield apiService.unarchive(notificationId);
|
|
552
|
+
const updatedNotification = new Notification(response);
|
|
553
|
+
emitter.emit("notification.unarchive.resolved", { args, data: updatedNotification });
|
|
554
|
+
return { data: updatedNotification };
|
|
555
|
+
} catch (error) {
|
|
556
|
+
emitter.emit("notification.unarchive.resolved", { args, error });
|
|
557
|
+
return { error: new NovuError("Failed to unarchive notification", error) };
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
var completeAction = (_0) => __async(void 0, [_0], function* ({
|
|
561
|
+
emitter,
|
|
562
|
+
apiService,
|
|
563
|
+
args,
|
|
564
|
+
actionType
|
|
565
|
+
}) {
|
|
566
|
+
var _a, _b;
|
|
567
|
+
const optimisticAction = "notification" in args ? {
|
|
568
|
+
isCompleted: true,
|
|
569
|
+
label: (_b = (_a = args.notification.primaryAction) == null ? void 0 : _a.label) != null ? _b : ""
|
|
570
|
+
} : {
|
|
571
|
+
isCompleted: true,
|
|
572
|
+
label: ""
|
|
573
|
+
};
|
|
574
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
575
|
+
args,
|
|
576
|
+
actionType === "primary" /* PRIMARY */ ? {
|
|
577
|
+
primaryAction: optimisticAction
|
|
578
|
+
} : { secondaryAction: optimisticAction }
|
|
579
|
+
);
|
|
580
|
+
try {
|
|
581
|
+
emitter.emit("notification.complete_action.pending", {
|
|
582
|
+
args,
|
|
583
|
+
data: optimisticValue
|
|
584
|
+
});
|
|
585
|
+
const response = yield apiService.completeAction({ actionType, notificationId });
|
|
586
|
+
const updatedNotification = new Notification(response);
|
|
587
|
+
emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
|
|
588
|
+
return { data: updatedNotification };
|
|
589
|
+
} catch (error) {
|
|
590
|
+
emitter.emit("notification.complete_action.resolved", { args, error });
|
|
591
|
+
return { error: new NovuError(`Failed to complete ${actionType} action on the notification`, error) };
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
var revertAction = (_0) => __async(void 0, [_0], function* ({
|
|
595
|
+
emitter,
|
|
596
|
+
apiService,
|
|
597
|
+
args,
|
|
598
|
+
actionType
|
|
599
|
+
}) {
|
|
600
|
+
var _a, _b;
|
|
601
|
+
const optimisticAction = "notification" in args ? {
|
|
602
|
+
isCompleted: false,
|
|
603
|
+
label: (_b = (_a = args.notification.primaryAction) == null ? void 0 : _a.label) != null ? _b : ""
|
|
604
|
+
} : {
|
|
605
|
+
isCompleted: false,
|
|
606
|
+
label: ""
|
|
607
|
+
};
|
|
608
|
+
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
609
|
+
args,
|
|
610
|
+
actionType === "primary" /* PRIMARY */ ? {
|
|
611
|
+
primaryAction: optimisticAction
|
|
612
|
+
} : { secondaryAction: optimisticAction }
|
|
613
|
+
);
|
|
614
|
+
try {
|
|
615
|
+
emitter.emit("notification.revert_action.pending", {
|
|
616
|
+
args,
|
|
617
|
+
data: optimisticValue
|
|
618
|
+
});
|
|
619
|
+
const response = yield apiService.revertAction({ actionType, notificationId });
|
|
620
|
+
const updatedNotification = new Notification(response);
|
|
621
|
+
emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
|
|
622
|
+
return { data: updatedNotification };
|
|
623
|
+
} catch (error) {
|
|
624
|
+
emitter.emit("notification.revert_action.resolved", { args, error });
|
|
625
|
+
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
var getNotificationDetails = (args, update) => {
|
|
629
|
+
if ("notification" in args) {
|
|
630
|
+
return {
|
|
631
|
+
notificationId: args.notification.id,
|
|
632
|
+
optimisticValue: new Notification(__spreadValues(__spreadValues({}, args.notification), update))
|
|
633
|
+
};
|
|
634
|
+
} else {
|
|
635
|
+
return {
|
|
636
|
+
notificationId: args.notificationId
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
641
|
+
emitter,
|
|
642
|
+
inboxService,
|
|
643
|
+
notificationsCache,
|
|
644
|
+
tags
|
|
645
|
+
}) {
|
|
646
|
+
try {
|
|
647
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
648
|
+
const optimisticNotifications = notifications.map(
|
|
649
|
+
(notification) => new Notification(__spreadProps(__spreadValues({}, notification), {
|
|
650
|
+
isRead: true,
|
|
651
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
652
|
+
isArchived: false,
|
|
653
|
+
archivedAt: void 0
|
|
654
|
+
}))
|
|
655
|
+
);
|
|
656
|
+
emitter.emit("notifications.read_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
657
|
+
yield inboxService.readAll({ tags });
|
|
658
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
659
|
+
return {};
|
|
660
|
+
} catch (error) {
|
|
661
|
+
emitter.emit("notifications.read_all.resolved", { args: { tags }, error });
|
|
662
|
+
return { error: new NovuError("Failed to read all notifications", error) };
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
var archiveAll = (_0) => __async(void 0, [_0], function* ({
|
|
666
|
+
emitter,
|
|
667
|
+
inboxService,
|
|
668
|
+
notificationsCache,
|
|
669
|
+
tags
|
|
670
|
+
}) {
|
|
671
|
+
try {
|
|
672
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags });
|
|
673
|
+
const optimisticNotifications = notifications.map(
|
|
674
|
+
(notification) => new Notification(__spreadProps(__spreadValues({}, notification), {
|
|
675
|
+
isRead: true,
|
|
676
|
+
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
677
|
+
isArchived: true,
|
|
678
|
+
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
679
|
+
}))
|
|
680
|
+
);
|
|
681
|
+
emitter.emit("notifications.archive_all.pending", { args: { tags }, data: optimisticNotifications });
|
|
682
|
+
yield inboxService.archiveAll({ tags });
|
|
683
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags }, data: optimisticNotifications });
|
|
684
|
+
return {};
|
|
685
|
+
} catch (error) {
|
|
686
|
+
emitter.emit("notifications.archive_all.resolved", { args: { tags }, error });
|
|
687
|
+
return { error: new NovuError("Failed to archive all notifications", error) };
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
var archiveAllRead = (_0) => __async(void 0, [_0], function* ({
|
|
691
|
+
emitter,
|
|
692
|
+
inboxService,
|
|
693
|
+
notificationsCache,
|
|
694
|
+
tags
|
|
695
|
+
}) {
|
|
696
|
+
try {
|
|
697
|
+
const notifications = notificationsCache.getUniqueNotifications({ tags, read: true });
|
|
698
|
+
const optimisticNotifications = notifications.map(
|
|
699
|
+
(notification) => new Notification(__spreadProps(__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }))
|
|
700
|
+
);
|
|
701
|
+
emitter.emit("notifications.archive_all_read.pending", { args: { tags }, data: optimisticNotifications });
|
|
702
|
+
yield inboxService.archiveAllRead({ tags });
|
|
703
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, data: optimisticNotifications });
|
|
704
|
+
return {};
|
|
705
|
+
} catch (error) {
|
|
706
|
+
emitter.emit("notifications.archive_all_read.resolved", { args: { tags }, error });
|
|
707
|
+
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
// src/cache/in-memory-cache.ts
|
|
712
|
+
var _cache;
|
|
713
|
+
var InMemoryCache = class {
|
|
714
|
+
constructor() {
|
|
715
|
+
__privateAdd(this, _cache);
|
|
716
|
+
__privateSet(this, _cache, /* @__PURE__ */ new Map());
|
|
717
|
+
}
|
|
718
|
+
get(key) {
|
|
719
|
+
return __privateGet(this, _cache).get(key);
|
|
720
|
+
}
|
|
721
|
+
getValues() {
|
|
722
|
+
return Array.from(__privateGet(this, _cache).values());
|
|
723
|
+
}
|
|
724
|
+
entries() {
|
|
725
|
+
return Array.from(__privateGet(this, _cache).entries());
|
|
726
|
+
}
|
|
727
|
+
keys() {
|
|
728
|
+
return Array.from(__privateGet(this, _cache).keys());
|
|
729
|
+
}
|
|
730
|
+
set(key, value) {
|
|
731
|
+
__privateGet(this, _cache).set(key, value);
|
|
732
|
+
}
|
|
733
|
+
remove(key) {
|
|
734
|
+
__privateGet(this, _cache).delete(key);
|
|
735
|
+
}
|
|
736
|
+
clear() {
|
|
737
|
+
__privateGet(this, _cache).clear();
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
_cache = new WeakMap();
|
|
741
|
+
|
|
742
|
+
// src/utils/arrays.ts
|
|
743
|
+
var arrayValuesEqual = (arr1, arr2) => {
|
|
744
|
+
if (arr1 === arr2) {
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
if (!arr1 || !arr2) {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
if (arr1.length !== arr2.length) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
return arr1.every((value, index) => value === arr2[index]);
|
|
754
|
+
};
|
|
755
|
+
var areTagsEqual = (tags1, tags2) => {
|
|
756
|
+
return arrayValuesEqual(tags1, tags2) || !tags1 && (tags2 == null ? void 0 : tags2.length) === 0 || (tags1 == null ? void 0 : tags1.length) === 0 && !tags2;
|
|
757
|
+
};
|
|
758
|
+
var isSameFilter = (filter1, filter2) => {
|
|
759
|
+
return areTagsEqual(filter1.tags, filter2.tags) && filter1.read == filter2.read && filter1.archived == filter2.archived;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// src/cache/notifications-cache.ts
|
|
763
|
+
var excludeEmpty = ({ tags, read: read2, archived, limit, offset, after }) => Object.entries({ tags, read: read2, archived, limit, offset, after }).filter(([_, value]) => value !== null && value !== void 0 && !(Array.isArray(value) && value.length === 0)).reduce((acc, [key, value]) => {
|
|
764
|
+
acc[key] = value;
|
|
765
|
+
return acc;
|
|
766
|
+
}, {});
|
|
767
|
+
var getCacheKey = ({ tags, read: read2, archived, limit, offset, after }) => {
|
|
768
|
+
return JSON.stringify(excludeEmpty({ tags, read: read2, archived, limit, offset, after }));
|
|
769
|
+
};
|
|
770
|
+
var getFilterKey = ({ tags, read: read2, archived }) => {
|
|
771
|
+
return JSON.stringify(excludeEmpty({ tags, read: read2, archived }));
|
|
772
|
+
};
|
|
773
|
+
var getFilter = (key) => {
|
|
774
|
+
return JSON.parse(key);
|
|
775
|
+
};
|
|
776
|
+
var updateEvents = [
|
|
777
|
+
"notification.read.pending",
|
|
778
|
+
"notification.read.resolved",
|
|
779
|
+
"notification.unread.pending",
|
|
780
|
+
"notification.unread.resolved",
|
|
781
|
+
"notification.complete_action.pending",
|
|
782
|
+
"notification.complete_action.resolved",
|
|
783
|
+
"notification.revert_action.pending",
|
|
784
|
+
"notification.revert_action.resolved",
|
|
785
|
+
"notifications.read_all.pending",
|
|
786
|
+
"notifications.read_all.resolved"
|
|
787
|
+
];
|
|
788
|
+
var removeEvents = [
|
|
789
|
+
"notification.archive.pending",
|
|
790
|
+
"notification.unarchive.pending",
|
|
791
|
+
"notifications.archive_all.pending",
|
|
792
|
+
"notifications.archive_all_read.pending"
|
|
793
|
+
];
|
|
794
|
+
var _emitter2, _cache2;
|
|
795
|
+
var NotificationsCache = class {
|
|
796
|
+
constructor() {
|
|
797
|
+
__privateAdd(this, _emitter2);
|
|
798
|
+
/**
|
|
799
|
+
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
800
|
+
*/
|
|
801
|
+
__privateAdd(this, _cache2);
|
|
802
|
+
this.updateNotification = (key, data) => {
|
|
803
|
+
const notificationsResponse = __privateGet(this, _cache2).get(key);
|
|
804
|
+
if (!notificationsResponse) {
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
const index = notificationsResponse.notifications.findIndex((el) => el.id === data.id);
|
|
808
|
+
if (index === -1) {
|
|
809
|
+
return false;
|
|
810
|
+
}
|
|
811
|
+
const updatedNotifications = [...notificationsResponse.notifications];
|
|
812
|
+
updatedNotifications[index] = data;
|
|
813
|
+
__privateGet(this, _cache2).set(key, __spreadProps(__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
|
|
814
|
+
return true;
|
|
815
|
+
};
|
|
816
|
+
this.removeNotification = (key, data) => {
|
|
817
|
+
const notificationsResponse = __privateGet(this, _cache2).get(key);
|
|
818
|
+
if (!notificationsResponse) {
|
|
819
|
+
return false;
|
|
820
|
+
}
|
|
821
|
+
const index = notificationsResponse.notifications.findIndex((el) => el.id === data.id);
|
|
822
|
+
if (index === -1) {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
const newNotifications = [...notificationsResponse.notifications];
|
|
826
|
+
newNotifications.splice(index, 1);
|
|
827
|
+
__privateGet(this, _cache2).set(key, __spreadProps(__spreadValues({}, notificationsResponse), {
|
|
828
|
+
notifications: newNotifications
|
|
829
|
+
}));
|
|
830
|
+
return true;
|
|
831
|
+
};
|
|
832
|
+
this.handleNotificationEvent = ({ remove } = { remove: false }) => ({ data }) => {
|
|
833
|
+
if (!data) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const notifications = Array.isArray(data) ? data : [data];
|
|
837
|
+
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
838
|
+
__privateGet(this, _cache2).keys().forEach((key) => {
|
|
839
|
+
notifications.forEach((notification) => {
|
|
840
|
+
let isNotificationFound = false;
|
|
841
|
+
if (remove) {
|
|
842
|
+
isNotificationFound = this.removeNotification(key, notification);
|
|
843
|
+
} else {
|
|
844
|
+
isNotificationFound = this.updateNotification(key, notification);
|
|
845
|
+
}
|
|
846
|
+
if (isNotificationFound) {
|
|
847
|
+
uniqueFilterKeys.add(getFilterKey(getFilter(key)));
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
});
|
|
851
|
+
uniqueFilterKeys.forEach((key) => {
|
|
852
|
+
const notificationsResponse = this.getAggregated(getFilter(key));
|
|
853
|
+
__privateGet(this, _emitter2).emit("notifications.list.updated", {
|
|
854
|
+
data: notificationsResponse
|
|
855
|
+
});
|
|
856
|
+
});
|
|
857
|
+
};
|
|
858
|
+
__privateSet(this, _emitter2, NovuEventEmitter.getInstance());
|
|
859
|
+
updateEvents.forEach((event) => {
|
|
860
|
+
__privateGet(this, _emitter2).on(event, this.handleNotificationEvent());
|
|
861
|
+
});
|
|
862
|
+
removeEvents.forEach((event) => {
|
|
863
|
+
__privateGet(this, _emitter2).on(event, this.handleNotificationEvent({ remove: true }));
|
|
864
|
+
});
|
|
865
|
+
__privateSet(this, _cache2, new InMemoryCache());
|
|
866
|
+
}
|
|
867
|
+
has(args) {
|
|
868
|
+
return __privateGet(this, _cache2).get(getCacheKey(args)) !== void 0;
|
|
869
|
+
}
|
|
870
|
+
getAggregated(filter) {
|
|
871
|
+
const cacheKeys = __privateGet(this, _cache2).keys().filter((key) => {
|
|
872
|
+
const parsedFilter = getFilter(key);
|
|
873
|
+
return isSameFilter(parsedFilter, filter);
|
|
874
|
+
});
|
|
875
|
+
return cacheKeys.map((key) => __privateGet(this, _cache2).get(key)).reduce(
|
|
876
|
+
(acc, el) => {
|
|
877
|
+
if (!el) {
|
|
878
|
+
return acc;
|
|
879
|
+
}
|
|
880
|
+
return {
|
|
881
|
+
hasMore: el.hasMore,
|
|
882
|
+
filter: el.filter,
|
|
883
|
+
notifications: [...acc.notifications, ...el.notifications]
|
|
884
|
+
};
|
|
885
|
+
},
|
|
886
|
+
{ hasMore: false, filter: {}, notifications: [] }
|
|
887
|
+
);
|
|
888
|
+
}
|
|
889
|
+
set(args, data) {
|
|
890
|
+
__privateGet(this, _cache2).set(getCacheKey(args), data);
|
|
891
|
+
}
|
|
892
|
+
getAll(args) {
|
|
893
|
+
if (this.has(args)) {
|
|
894
|
+
return this.getAggregated({ tags: args.tags, read: args.read, archived: args.archived });
|
|
895
|
+
}
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Get unique notifications based on specified filter fields.
|
|
900
|
+
* The same tags can be applied to multiple filters which means that the same notification can be duplicated.
|
|
901
|
+
*/
|
|
902
|
+
getUniqueNotifications({ tags, read: read2 }) {
|
|
903
|
+
const keys = __privateGet(this, _cache2).keys();
|
|
904
|
+
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
905
|
+
keys.forEach((key) => {
|
|
906
|
+
const filter = getFilter(key);
|
|
907
|
+
if (areTagsEqual(tags, filter.tags)) {
|
|
908
|
+
const value = __privateGet(this, _cache2).get(key);
|
|
909
|
+
if (!value) {
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
value.notifications.filter((el) => typeof read2 === "undefined" || read2 === el.isRead).forEach((notification) => uniqueNotifications.set(notification.id, notification));
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
return Array.from(uniqueNotifications.values());
|
|
916
|
+
}
|
|
917
|
+
clear(filter) {
|
|
918
|
+
const keys = __privateGet(this, _cache2).keys();
|
|
919
|
+
keys.forEach((key) => {
|
|
920
|
+
if (isSameFilter(getFilter(key), filter)) {
|
|
921
|
+
__privateGet(this, _cache2).remove(key);
|
|
922
|
+
}
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
clearAll() {
|
|
926
|
+
__privateGet(this, _cache2).clear();
|
|
927
|
+
}
|
|
928
|
+
};
|
|
929
|
+
_emitter2 = new WeakMap();
|
|
930
|
+
_cache2 = new WeakMap();
|
|
931
|
+
|
|
932
|
+
// src/notifications/notifications.ts
|
|
933
|
+
var _useCache, _notificationsCache;
|
|
934
|
+
var Notifications = class extends BaseModule {
|
|
935
|
+
constructor({ useCache }) {
|
|
936
|
+
super();
|
|
937
|
+
__privateAdd(this, _useCache);
|
|
938
|
+
__privateAdd(this, _notificationsCache);
|
|
939
|
+
__privateSet(this, _notificationsCache, new NotificationsCache());
|
|
940
|
+
__privateSet(this, _useCache, useCache);
|
|
941
|
+
}
|
|
942
|
+
list() {
|
|
943
|
+
return __async(this, arguments, function* (_a = {}) {
|
|
944
|
+
var _b = _a, { limit = 10 } = _b, restOptions = __objRest(_b, ["limit"]);
|
|
945
|
+
return this.callWithSession(() => __async(this, null, function* () {
|
|
946
|
+
const args = __spreadValues({ limit }, restOptions);
|
|
947
|
+
try {
|
|
948
|
+
let data = __privateGet(this, _useCache) ? __privateGet(this, _notificationsCache).getAll(args) : void 0;
|
|
949
|
+
if (!data) {
|
|
950
|
+
const response = yield this._inboxService.fetchNotifications(__spreadValues({
|
|
951
|
+
limit
|
|
952
|
+
}, restOptions));
|
|
953
|
+
data = {
|
|
954
|
+
hasMore: response.hasMore,
|
|
955
|
+
filter: response.filter,
|
|
956
|
+
notifications: response.data.map((el) => new Notification(el))
|
|
957
|
+
};
|
|
958
|
+
if (__privateGet(this, _useCache)) {
|
|
959
|
+
__privateGet(this, _notificationsCache).set(args, data);
|
|
960
|
+
data = __privateGet(this, _notificationsCache).getAll(args);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
this._emitter.emit("notifications.list.resolved", { args, data });
|
|
964
|
+
return { data };
|
|
965
|
+
} catch (error) {
|
|
966
|
+
this._emitter.emit("notifications.list.resolved", { args, error });
|
|
967
|
+
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
968
|
+
}
|
|
969
|
+
}));
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
count(args) {
|
|
973
|
+
return __async(this, null, function* () {
|
|
974
|
+
return this.callWithSession(() => __async(this, null, function* () {
|
|
975
|
+
const filters = args && "filters" in args ? args.filters : [__spreadValues({}, args)];
|
|
976
|
+
try {
|
|
977
|
+
this._emitter.emit("notifications.count.pending", { args });
|
|
978
|
+
const response = yield this._inboxService.count({
|
|
979
|
+
filters
|
|
980
|
+
});
|
|
981
|
+
const data = args && "filters" in args ? { counts: response.data } : response.data[0];
|
|
982
|
+
this._emitter.emit("notifications.count.resolved", {
|
|
983
|
+
args,
|
|
984
|
+
data
|
|
985
|
+
});
|
|
986
|
+
return { data };
|
|
987
|
+
} catch (error) {
|
|
988
|
+
this._emitter.emit("notifications.count.resolved", { args, error });
|
|
989
|
+
return { error: new NovuError("Failed to count notifications", error) };
|
|
990
|
+
}
|
|
991
|
+
}));
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
read(args) {
|
|
995
|
+
return __async(this, null, function* () {
|
|
996
|
+
return this.callWithSession(
|
|
997
|
+
() => __async(this, null, function* () {
|
|
998
|
+
return read({
|
|
999
|
+
emitter: this._emitter,
|
|
1000
|
+
apiService: this._inboxService,
|
|
1001
|
+
args
|
|
1002
|
+
});
|
|
1003
|
+
})
|
|
1004
|
+
);
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
unread(args) {
|
|
1008
|
+
return __async(this, null, function* () {
|
|
1009
|
+
return this.callWithSession(
|
|
1010
|
+
() => __async(this, null, function* () {
|
|
1011
|
+
return unread({
|
|
1012
|
+
emitter: this._emitter,
|
|
1013
|
+
apiService: this._inboxService,
|
|
1014
|
+
args
|
|
1015
|
+
});
|
|
1016
|
+
})
|
|
1017
|
+
);
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
archive(args) {
|
|
1021
|
+
return __async(this, null, function* () {
|
|
1022
|
+
return this.callWithSession(
|
|
1023
|
+
() => __async(this, null, function* () {
|
|
1024
|
+
return archive({
|
|
1025
|
+
emitter: this._emitter,
|
|
1026
|
+
apiService: this._inboxService,
|
|
1027
|
+
args
|
|
1028
|
+
});
|
|
1029
|
+
})
|
|
1030
|
+
);
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
unarchive(args) {
|
|
1034
|
+
return __async(this, null, function* () {
|
|
1035
|
+
return this.callWithSession(
|
|
1036
|
+
() => __async(this, null, function* () {
|
|
1037
|
+
return unarchive({
|
|
1038
|
+
emitter: this._emitter,
|
|
1039
|
+
apiService: this._inboxService,
|
|
1040
|
+
args
|
|
1041
|
+
});
|
|
1042
|
+
})
|
|
1043
|
+
);
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
completePrimary(args) {
|
|
1047
|
+
return __async(this, null, function* () {
|
|
1048
|
+
return this.callWithSession(
|
|
1049
|
+
() => __async(this, null, function* () {
|
|
1050
|
+
return completeAction({
|
|
1051
|
+
emitter: this._emitter,
|
|
1052
|
+
apiService: this._inboxService,
|
|
1053
|
+
args,
|
|
1054
|
+
actionType: "primary" /* PRIMARY */
|
|
1055
|
+
});
|
|
1056
|
+
})
|
|
1057
|
+
);
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
completeSecondary(args) {
|
|
1061
|
+
return __async(this, null, function* () {
|
|
1062
|
+
return this.callWithSession(
|
|
1063
|
+
() => __async(this, null, function* () {
|
|
1064
|
+
return completeAction({
|
|
1065
|
+
emitter: this._emitter,
|
|
1066
|
+
apiService: this._inboxService,
|
|
1067
|
+
args,
|
|
1068
|
+
actionType: "secondary" /* SECONDARY */
|
|
1069
|
+
});
|
|
1070
|
+
})
|
|
1071
|
+
);
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
revertPrimary(args) {
|
|
1075
|
+
return __async(this, null, function* () {
|
|
1076
|
+
return this.callWithSession(
|
|
1077
|
+
() => __async(this, null, function* () {
|
|
1078
|
+
return revertAction({
|
|
1079
|
+
emitter: this._emitter,
|
|
1080
|
+
apiService: this._inboxService,
|
|
1081
|
+
args,
|
|
1082
|
+
actionType: "primary" /* PRIMARY */
|
|
1083
|
+
});
|
|
1084
|
+
})
|
|
1085
|
+
);
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
revertSecondary(args) {
|
|
1089
|
+
return __async(this, null, function* () {
|
|
1090
|
+
return this.callWithSession(
|
|
1091
|
+
() => __async(this, null, function* () {
|
|
1092
|
+
return revertAction({
|
|
1093
|
+
emitter: this._emitter,
|
|
1094
|
+
apiService: this._inboxService,
|
|
1095
|
+
args,
|
|
1096
|
+
actionType: "secondary" /* SECONDARY */
|
|
1097
|
+
});
|
|
1098
|
+
})
|
|
1099
|
+
);
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
readAll() {
|
|
1103
|
+
return __async(this, arguments, function* ({ tags } = {}) {
|
|
1104
|
+
return this.callWithSession(
|
|
1105
|
+
() => __async(this, null, function* () {
|
|
1106
|
+
return readAll({
|
|
1107
|
+
emitter: this._emitter,
|
|
1108
|
+
inboxService: this._inboxService,
|
|
1109
|
+
notificationsCache: __privateGet(this, _notificationsCache),
|
|
1110
|
+
tags
|
|
1111
|
+
});
|
|
1112
|
+
})
|
|
1113
|
+
);
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
archiveAll() {
|
|
1117
|
+
return __async(this, arguments, function* ({ tags } = {}) {
|
|
1118
|
+
return this.callWithSession(
|
|
1119
|
+
() => __async(this, null, function* () {
|
|
1120
|
+
return archiveAll({
|
|
1121
|
+
emitter: this._emitter,
|
|
1122
|
+
inboxService: this._inboxService,
|
|
1123
|
+
notificationsCache: __privateGet(this, _notificationsCache),
|
|
1124
|
+
tags
|
|
1125
|
+
});
|
|
1126
|
+
})
|
|
1127
|
+
);
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
archiveAllRead() {
|
|
1131
|
+
return __async(this, arguments, function* ({ tags } = {}) {
|
|
1132
|
+
return this.callWithSession(
|
|
1133
|
+
() => __async(this, null, function* () {
|
|
1134
|
+
return archiveAllRead({
|
|
1135
|
+
emitter: this._emitter,
|
|
1136
|
+
inboxService: this._inboxService,
|
|
1137
|
+
notificationsCache: __privateGet(this, _notificationsCache),
|
|
1138
|
+
tags
|
|
1139
|
+
});
|
|
1140
|
+
})
|
|
1141
|
+
);
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
clearCache({ filter } = {}) {
|
|
1145
|
+
if (filter) {
|
|
1146
|
+
return __privateGet(this, _notificationsCache).clear(filter != null ? filter : {});
|
|
1147
|
+
}
|
|
1148
|
+
return __privateGet(this, _notificationsCache).clearAll();
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
_useCache = new WeakMap();
|
|
1152
|
+
_notificationsCache = new WeakMap();
|
|
1153
|
+
|
|
1154
|
+
// src/session/session.ts
|
|
1155
|
+
var _emitter3, _inboxService2, _options;
|
|
1156
|
+
var Session = class {
|
|
1157
|
+
constructor(options) {
|
|
1158
|
+
__privateAdd(this, _emitter3);
|
|
1159
|
+
__privateAdd(this, _inboxService2);
|
|
1160
|
+
__privateAdd(this, _options);
|
|
1161
|
+
__privateSet(this, _emitter3, NovuEventEmitter.getInstance());
|
|
1162
|
+
__privateSet(this, _inboxService2, InboxServiceSingleton.getInstance());
|
|
1163
|
+
__privateSet(this, _options, options);
|
|
1164
|
+
}
|
|
1165
|
+
initialize() {
|
|
1166
|
+
return __async(this, null, function* () {
|
|
1167
|
+
try {
|
|
1168
|
+
const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
|
|
1169
|
+
__privateGet(this, _emitter3).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
1170
|
+
const response = yield __privateGet(this, _inboxService2).initializeSession({
|
|
1171
|
+
applicationIdentifier,
|
|
1172
|
+
subscriberId,
|
|
1173
|
+
subscriberHash
|
|
1174
|
+
});
|
|
1175
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1176
|
+
} catch (error) {
|
|
1177
|
+
__privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
_emitter3 = new WeakMap();
|
|
1183
|
+
_inboxService2 = new WeakMap();
|
|
1184
|
+
_options = new WeakMap();
|
|
1185
|
+
|
|
1186
|
+
// src/preferences/preference.ts
|
|
1187
|
+
var _emitter4, _apiService;
|
|
1188
|
+
var Preference = class {
|
|
1189
|
+
constructor(preference) {
|
|
1190
|
+
__privateAdd(this, _emitter4);
|
|
1191
|
+
__privateAdd(this, _apiService);
|
|
1192
|
+
__privateSet(this, _emitter4, NovuEventEmitter.getInstance());
|
|
1193
|
+
__privateSet(this, _apiService, InboxServiceSingleton.getInstance());
|
|
1194
|
+
this.level = preference.level;
|
|
1195
|
+
this.enabled = preference.enabled;
|
|
1196
|
+
this.channels = preference.channels;
|
|
1197
|
+
this.workflow = preference.workflow;
|
|
1198
|
+
}
|
|
1199
|
+
update({ channelPreferences }) {
|
|
1200
|
+
var _a;
|
|
1201
|
+
return updatePreference({
|
|
1202
|
+
emitter: __privateGet(this, _emitter4),
|
|
1203
|
+
apiService: __privateGet(this, _apiService),
|
|
1204
|
+
args: {
|
|
1205
|
+
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1206
|
+
channelPreferences,
|
|
1207
|
+
preference: {
|
|
1208
|
+
level: this.level,
|
|
1209
|
+
enabled: this.enabled,
|
|
1210
|
+
channels: this.channels,
|
|
1211
|
+
workflow: this.workflow
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
_emitter4 = new WeakMap();
|
|
1218
|
+
_apiService = new WeakMap();
|
|
1219
|
+
|
|
1220
|
+
// src/preferences/helpers.ts
|
|
1221
|
+
var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
1222
|
+
emitter,
|
|
1223
|
+
apiService,
|
|
1224
|
+
args
|
|
1225
|
+
}) {
|
|
1226
|
+
const { workflowId, channelPreferences } = args;
|
|
1227
|
+
try {
|
|
1228
|
+
emitter.emit("preferences.update.pending", {
|
|
1229
|
+
args,
|
|
1230
|
+
data: args.preference ? new Preference(__spreadProps(__spreadValues({}, args.preference), {
|
|
1231
|
+
channels: __spreadValues(__spreadValues({}, args.preference.channels), channelPreferences)
|
|
1232
|
+
})) : void 0
|
|
1233
|
+
});
|
|
1234
|
+
let response;
|
|
1235
|
+
if (workflowId) {
|
|
1236
|
+
response = yield apiService.updateWorkflowPreferences({ workflowId, channelPreferences });
|
|
1237
|
+
} else {
|
|
1238
|
+
response = yield apiService.updateGlobalPreferences(channelPreferences);
|
|
1239
|
+
}
|
|
1240
|
+
const preference = new Preference(response);
|
|
1241
|
+
emitter.emit("preferences.update.resolved", { args, data: preference });
|
|
1242
|
+
return { data: preference };
|
|
1243
|
+
} catch (error) {
|
|
1244
|
+
emitter.emit("preferences.update.resolved", { args, error });
|
|
1245
|
+
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
// src/preferences/preferences.ts
|
|
1250
|
+
var Preferences = class extends BaseModule {
|
|
1251
|
+
list() {
|
|
1252
|
+
return __async(this, null, function* () {
|
|
1253
|
+
return this.callWithSession(() => __async(this, null, function* () {
|
|
1254
|
+
try {
|
|
1255
|
+
this._emitter.emit("preferences.list.pending");
|
|
1256
|
+
const response = yield this._inboxService.fetchPreferences();
|
|
1257
|
+
const modifiedResponse = response.map((el) => new Preference(el));
|
|
1258
|
+
this._emitter.emit("preferences.list.resolved", { args: void 0, data: modifiedResponse });
|
|
1259
|
+
return { data: modifiedResponse };
|
|
1260
|
+
} catch (error) {
|
|
1261
|
+
this._emitter.emit("preferences.list.resolved", { args: void 0, error });
|
|
1262
|
+
throw error;
|
|
1263
|
+
}
|
|
1264
|
+
}));
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
update(args) {
|
|
1268
|
+
return __async(this, null, function* () {
|
|
1269
|
+
return this.callWithSession(
|
|
1270
|
+
() => __async(this, null, function* () {
|
|
1271
|
+
return updatePreference({ emitter: this._emitter, apiService: this._inboxService, args });
|
|
1272
|
+
})
|
|
1273
|
+
);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
|
|
1278
|
+
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
1279
|
+
var UNSEEN_COUNT_CHANGED = "notifications.unseen_count_changed";
|
|
1280
|
+
var UNREAD_COUNT_CHANGED = "notifications.unread_count_changed";
|
|
1281
|
+
var mapToNotification = ({
|
|
1282
|
+
_id,
|
|
1283
|
+
content,
|
|
1284
|
+
read: read2,
|
|
1285
|
+
archived,
|
|
1286
|
+
createdAt,
|
|
1287
|
+
lastReadDate,
|
|
1288
|
+
archivedAt,
|
|
1289
|
+
channel,
|
|
1290
|
+
subscriber,
|
|
1291
|
+
subject,
|
|
1292
|
+
avatar,
|
|
1293
|
+
cta,
|
|
1294
|
+
tags
|
|
1295
|
+
}) => {
|
|
1296
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1297
|
+
const to = {
|
|
1298
|
+
id: (_a = subscriber == null ? void 0 : subscriber._id) != null ? _a : "",
|
|
1299
|
+
firstName: subscriber == null ? void 0 : subscriber.firstName,
|
|
1300
|
+
lastName: subscriber == null ? void 0 : subscriber.lastName,
|
|
1301
|
+
avatar: subscriber == null ? void 0 : subscriber.avatar,
|
|
1302
|
+
subscriberId: (_b = subscriber == null ? void 0 : subscriber.subscriberId) != null ? _b : ""
|
|
1303
|
+
};
|
|
1304
|
+
const primaryCta = (_d = (_c = cta.action) == null ? void 0 : _c.buttons) == null ? void 0 : _d.find((button) => button.type === "primary" /* PRIMARY */);
|
|
1305
|
+
const secondaryCta = (_f = (_e = cta.action) == null ? void 0 : _e.buttons) == null ? void 0 : _f.find((button) => button.type === "secondary" /* SECONDARY */);
|
|
1306
|
+
const actionType = (_h = (_g = cta.action) == null ? void 0 : _g.result) == null ? void 0 : _h.type;
|
|
1307
|
+
const actionStatus = (_i = cta.action) == null ? void 0 : _i.status;
|
|
1308
|
+
return {
|
|
1309
|
+
id: _id,
|
|
1310
|
+
subject,
|
|
1311
|
+
body: content,
|
|
1312
|
+
to,
|
|
1313
|
+
isRead: read2,
|
|
1314
|
+
isArchived: archived,
|
|
1315
|
+
createdAt,
|
|
1316
|
+
readAt: lastReadDate,
|
|
1317
|
+
archivedAt,
|
|
1318
|
+
avatar,
|
|
1319
|
+
primaryAction: primaryCta && {
|
|
1320
|
+
label: primaryCta.content,
|
|
1321
|
+
isCompleted: actionType === "primary" /* PRIMARY */ && actionStatus === "done" /* DONE */
|
|
1322
|
+
},
|
|
1323
|
+
secondaryAction: secondaryCta && {
|
|
1324
|
+
label: secondaryCta.content,
|
|
1325
|
+
isCompleted: actionType === "secondary" /* SECONDARY */ && actionStatus === "done" /* DONE */
|
|
1326
|
+
},
|
|
1327
|
+
channelType: channel,
|
|
1328
|
+
tags,
|
|
1329
|
+
redirect: ((_j = cta.data) == null ? void 0 : _j.url) ? {
|
|
1330
|
+
url: cta.data.url
|
|
1331
|
+
} : void 0
|
|
1332
|
+
};
|
|
1333
|
+
};
|
|
1334
|
+
var _token, _emitter5, _socketIo, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _Socket_instances, initializeSocket_fn;
|
|
1335
|
+
var Socket = class extends BaseModule {
|
|
1336
|
+
constructor({ socketUrl }) {
|
|
1337
|
+
super();
|
|
1338
|
+
__privateAdd(this, _Socket_instances);
|
|
1339
|
+
__privateAdd(this, _token);
|
|
1340
|
+
__privateAdd(this, _emitter5);
|
|
1341
|
+
__privateAdd(this, _socketIo);
|
|
1342
|
+
__privateAdd(this, _socketUrl);
|
|
1343
|
+
__privateAdd(this, _notificationReceived, ({ message }) => {
|
|
1344
|
+
__privateGet(this, _emitter5).emit(NOTIFICATION_RECEIVED, {
|
|
1345
|
+
result: new Notification(mapToNotification(message))
|
|
1346
|
+
});
|
|
1347
|
+
});
|
|
1348
|
+
__privateAdd(this, _unseenCountChanged, ({ unseenCount }) => {
|
|
1349
|
+
__privateGet(this, _emitter5).emit(UNSEEN_COUNT_CHANGED, {
|
|
1350
|
+
result: unseenCount
|
|
1351
|
+
});
|
|
1352
|
+
});
|
|
1353
|
+
__privateAdd(this, _unreadCountChanged, ({ unreadCount }) => {
|
|
1354
|
+
__privateGet(this, _emitter5).emit(UNREAD_COUNT_CHANGED, {
|
|
1355
|
+
result: unreadCount
|
|
1356
|
+
});
|
|
1357
|
+
});
|
|
1358
|
+
__privateSet(this, _emitter5, NovuEventEmitter.getInstance());
|
|
1359
|
+
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
1360
|
+
}
|
|
1361
|
+
onSessionSuccess({ token }) {
|
|
1362
|
+
__privateSet(this, _token, token);
|
|
1363
|
+
}
|
|
1364
|
+
isSocketEvent(eventName) {
|
|
1365
|
+
return eventName === NOTIFICATION_RECEIVED || eventName === UNSEEN_COUNT_CHANGED || eventName === UNREAD_COUNT_CHANGED;
|
|
1366
|
+
}
|
|
1367
|
+
initialize() {
|
|
1368
|
+
if (__privateGet(this, _token)) {
|
|
1369
|
+
__privateMethod(this, _Socket_instances, initializeSocket_fn).call(this).catch((error) => {
|
|
1370
|
+
console.error(error);
|
|
1371
|
+
});
|
|
1372
|
+
return;
|
|
1373
|
+
}
|
|
1374
|
+
this.callWithSession(() => __async(this, null, function* () {
|
|
1375
|
+
__privateMethod(this, _Socket_instances, initializeSocket_fn).call(this).catch((error) => {
|
|
1376
|
+
console.error(error);
|
|
1377
|
+
});
|
|
1378
|
+
return {};
|
|
1379
|
+
}));
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
_token = new WeakMap();
|
|
1383
|
+
_emitter5 = new WeakMap();
|
|
1384
|
+
_socketIo = new WeakMap();
|
|
1385
|
+
_socketUrl = new WeakMap();
|
|
1386
|
+
_notificationReceived = new WeakMap();
|
|
1387
|
+
_unseenCountChanged = new WeakMap();
|
|
1388
|
+
_unreadCountChanged = new WeakMap();
|
|
1389
|
+
_Socket_instances = new WeakSet();
|
|
1390
|
+
initializeSocket_fn = function() {
|
|
1391
|
+
return __async(this, null, function* () {
|
|
1392
|
+
var _a, _b, _c;
|
|
1393
|
+
if (!!__privateGet(this, _socketIo)) {
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const args = { socketUrl: __privateGet(this, _socketUrl) };
|
|
1397
|
+
__privateGet(this, _emitter5).emit("socket.connect.pending", { args });
|
|
1398
|
+
__privateSet(this, _socketIo, io__default.default(__privateGet(this, _socketUrl), {
|
|
1399
|
+
reconnectionDelayMax: 1e4,
|
|
1400
|
+
transports: ["websocket"],
|
|
1401
|
+
query: {
|
|
1402
|
+
token: `${__privateGet(this, _token)}`
|
|
1403
|
+
}
|
|
1404
|
+
}));
|
|
1405
|
+
__privateGet(this, _socketIo).on("connect", () => {
|
|
1406
|
+
__privateGet(this, _emitter5).emit("socket.connect.resolved", { args });
|
|
1407
|
+
});
|
|
1408
|
+
__privateGet(this, _socketIo).on("connect_error", (error) => {
|
|
1409
|
+
__privateGet(this, _emitter5).emit("socket.connect.resolved", { args, error });
|
|
1410
|
+
});
|
|
1411
|
+
(_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, __privateGet(this, _notificationReceived));
|
|
1412
|
+
(_b = __privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, __privateGet(this, _unseenCountChanged));
|
|
1413
|
+
(_c = __privateGet(this, _socketIo)) == null ? void 0 : _c.on("unread_count_changed" /* UNREAD */, __privateGet(this, _unreadCountChanged));
|
|
1414
|
+
});
|
|
1415
|
+
};
|
|
1416
|
+
|
|
1417
|
+
// src/utils/config.ts
|
|
1418
|
+
var PRODUCTION_BACKEND_URL = "https://api.novu.co";
|
|
1419
|
+
|
|
1420
|
+
// src/novu.ts
|
|
1421
|
+
var _emitter6, _session, _socket;
|
|
1422
|
+
var Novu = class {
|
|
1423
|
+
constructor(options) {
|
|
1424
|
+
__privateAdd(this, _emitter6);
|
|
1425
|
+
__privateAdd(this, _session);
|
|
1426
|
+
__privateAdd(this, _socket);
|
|
1427
|
+
var _a, _b;
|
|
1428
|
+
InboxServiceSingleton.getInstance({ backendUrl: (_a = options.backendUrl) != null ? _a : PRODUCTION_BACKEND_URL });
|
|
1429
|
+
__privateSet(this, _emitter6, NovuEventEmitter.getInstance({ recreate: true }));
|
|
1430
|
+
__privateSet(this, _session, new Session({
|
|
1431
|
+
applicationIdentifier: options.applicationIdentifier,
|
|
1432
|
+
subscriberId: options.subscriberId,
|
|
1433
|
+
subscriberHash: options.subscriberHash
|
|
1434
|
+
}));
|
|
1435
|
+
__privateGet(this, _session).initialize();
|
|
1436
|
+
this.notifications = new Notifications({ useCache: (_b = options.useCache) != null ? _b : true });
|
|
1437
|
+
this.preferences = new Preferences();
|
|
1438
|
+
__privateSet(this, _socket, new Socket({ socketUrl: options.socketUrl }));
|
|
1439
|
+
}
|
|
1440
|
+
on(eventName, listener) {
|
|
1441
|
+
if (__privateGet(this, _socket).isSocketEvent(eventName)) {
|
|
1442
|
+
__privateGet(this, _socket).initialize();
|
|
1443
|
+
}
|
|
1444
|
+
__privateGet(this, _emitter6).on(eventName, listener);
|
|
1445
|
+
}
|
|
1446
|
+
off(eventName, listener) {
|
|
1447
|
+
__privateGet(this, _emitter6).off(eventName, listener);
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
_emitter6 = new WeakMap();
|
|
1451
|
+
_session = new WeakMap();
|
|
1452
|
+
_socket = new WeakMap();
|
|
1453
|
+
|
|
1454
|
+
exports.ActionTypeEnum = ActionTypeEnum;
|
|
1455
|
+
exports.ChannelType = ChannelType;
|
|
1456
|
+
exports.CtaType = CtaType;
|
|
1457
|
+
exports.NotificationActionStatus = NotificationActionStatus;
|
|
1458
|
+
exports.NotificationButton = NotificationButton;
|
|
1459
|
+
exports.NotificationStatus = NotificationStatus;
|
|
1460
|
+
exports.Novu = Novu;
|
|
1461
|
+
exports.PreferenceLevel = PreferenceLevel;
|
|
1462
|
+
exports.PreferenceOverrideSource = PreferenceOverrideSource;
|
|
1463
|
+
exports.PreferenceOverrideSourceEnum = PreferenceOverrideSourceEnum;
|
|
1464
|
+
exports.WebSocketEvent = WebSocketEvent;
|
|
1465
|
+
exports.__async = __async;
|
|
1466
|
+
exports.__objRest = __objRest;
|
|
1467
|
+
exports.__privateAdd = __privateAdd;
|
|
1468
|
+
exports.__privateGet = __privateGet;
|
|
1469
|
+
exports.__privateMethod = __privateMethod;
|
|
1470
|
+
exports.__privateSet = __privateSet;
|
|
1471
|
+
exports.__spreadProps = __spreadProps;
|
|
1472
|
+
exports.__spreadValues = __spreadValues;
|
|
1473
|
+
exports.isSameFilter = isSameFilter;
|