@novu/js 3.11.0 → 3.11.2-nightly.20251224.eb609546a3
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-QQNKEWGC.js → chunk-C6V4UPCA.js} +1338 -1241
- package/dist/cjs/chunk-CDGREQFE.js +799 -0
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.js +38 -26
- package/dist/cjs/internal/index.d.ts +14 -2
- package/dist/cjs/internal/index.js +12 -4
- package/dist/cjs/novu-DxuaDf-Z.d.ts +192 -0
- package/dist/{esm/novu-DY-mm8Og.d.mts → cjs/novu-event-emitter-BOA_6GfJ.d.ts} +413 -162
- package/dist/cjs/themes/index.d.ts +11 -5
- package/dist/cjs/themes/index.js +17 -1
- package/dist/cjs/types-Buzm23uF.d.ts +836 -0
- package/dist/cjs/ui/index.d.ts +74 -7
- package/dist/cjs/ui/index.js +1836 -261
- package/dist/esm/{chunk-UM35OVAD.mjs → chunk-NF4ANB6D.mjs} +1308 -1207
- package/dist/esm/chunk-SWKDFXVR.mjs +770 -0
- package/dist/esm/index.d.mts +4 -4
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/internal/index.d.mts +14 -2
- package/dist/esm/internal/index.mjs +1 -1
- package/dist/esm/novu-DY8vwRGE.d.mts +192 -0
- package/dist/{cjs/novu-ThMWeiRt.d.ts → esm/novu-event-emitter-BOA_6GfJ.d.mts} +413 -162
- package/dist/esm/themes/index.d.mts +11 -5
- package/dist/esm/themes/index.mjs +16 -2
- package/dist/esm/types-xBjzv9ok.d.mts +836 -0
- package/dist/esm/ui/index.d.mts +74 -7
- package/dist/esm/ui/index.mjs +1833 -257
- package/dist/index.css +1 -1
- package/dist/novu.min.js +12 -12
- package/dist/novu.min.js.gz +0 -0
- package/package.json +18 -17
- package/dist/cjs/chunk-VWSQDNZX.js +0 -66
- package/dist/cjs/types-BM_9Xx5Z.d.ts +0 -220
- package/dist/cjs/types-BjANCN3c.d.ts +0 -537
- package/dist/esm/chunk-RZWQYM3H.mjs +0 -62
- package/dist/esm/types-BM_9Xx5Z.d.mts +0 -220
- package/dist/esm/types-C5eX1GmB.d.mts +0 -537
|
@@ -1,53 +1,10 @@
|
|
|
1
|
-
import { buildSubscriber, buildContextKey } from './chunk-
|
|
2
|
-
import { __privateAdd, __privateSet, __privateGet, __async,
|
|
1
|
+
import { NovuError, buildSubscriber, buildContextKey, buildSubscriptionIdentifier, Notification, read, unread, seen, archive, unarchive, deleteNotification, snooze, unsnooze, completeAction, revertAction, readAll, seenAll, archiveAll, archiveAllRead, deleteAll, createNotification } from './chunk-SWKDFXVR.mjs';
|
|
2
|
+
import { __privateAdd, __privateSet, __spreadValues, __privateGet, __async, __spreadProps, __objRest, __privateMethod } from './chunk-STZMOEWR.mjs';
|
|
3
3
|
import mitt from 'mitt';
|
|
4
4
|
import 'event-target-polyfill';
|
|
5
5
|
import { WebSocket } from 'partysocket';
|
|
6
6
|
import io from 'socket.io-client';
|
|
7
7
|
|
|
8
|
-
// src/types.ts
|
|
9
|
-
var NotificationStatus = /* @__PURE__ */ ((NotificationStatus2) => {
|
|
10
|
-
NotificationStatus2["READ"] = "read";
|
|
11
|
-
NotificationStatus2["SEEN"] = "seen";
|
|
12
|
-
NotificationStatus2["SNOOZED"] = "snoozed";
|
|
13
|
-
NotificationStatus2["UNREAD"] = "unread";
|
|
14
|
-
NotificationStatus2["UNSEEN"] = "unseen";
|
|
15
|
-
NotificationStatus2["UNSNOOZED"] = "unsnoozed";
|
|
16
|
-
return NotificationStatus2;
|
|
17
|
-
})(NotificationStatus || {});
|
|
18
|
-
var PreferenceLevel = /* @__PURE__ */ ((PreferenceLevel2) => {
|
|
19
|
-
PreferenceLevel2["GLOBAL"] = "global";
|
|
20
|
-
PreferenceLevel2["TEMPLATE"] = "template";
|
|
21
|
-
return PreferenceLevel2;
|
|
22
|
-
})(PreferenceLevel || {});
|
|
23
|
-
var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
|
|
24
|
-
ChannelType2["IN_APP"] = "in_app";
|
|
25
|
-
ChannelType2["EMAIL"] = "email";
|
|
26
|
-
ChannelType2["SMS"] = "sms";
|
|
27
|
-
ChannelType2["CHAT"] = "chat";
|
|
28
|
-
ChannelType2["PUSH"] = "push";
|
|
29
|
-
return ChannelType2;
|
|
30
|
-
})(ChannelType || {});
|
|
31
|
-
var WebSocketEvent = /* @__PURE__ */ ((WebSocketEvent2) => {
|
|
32
|
-
WebSocketEvent2["RECEIVED"] = "notification_received";
|
|
33
|
-
WebSocketEvent2["UNREAD"] = "unread_count_changed";
|
|
34
|
-
WebSocketEvent2["UNSEEN"] = "unseen_count_changed";
|
|
35
|
-
return WebSocketEvent2;
|
|
36
|
-
})(WebSocketEvent || {});
|
|
37
|
-
var SeverityLevelEnum = /* @__PURE__ */ ((SeverityLevelEnum2) => {
|
|
38
|
-
SeverityLevelEnum2["HIGH"] = "high";
|
|
39
|
-
SeverityLevelEnum2["MEDIUM"] = "medium";
|
|
40
|
-
SeverityLevelEnum2["LOW"] = "low";
|
|
41
|
-
SeverityLevelEnum2["NONE"] = "none";
|
|
42
|
-
return SeverityLevelEnum2;
|
|
43
|
-
})(SeverityLevelEnum || {});
|
|
44
|
-
var WorkflowCriticalityEnum = /* @__PURE__ */ ((WorkflowCriticalityEnum2) => {
|
|
45
|
-
WorkflowCriticalityEnum2["CRITICAL"] = "critical";
|
|
46
|
-
WorkflowCriticalityEnum2["NON_CRITICAL"] = "nonCritical";
|
|
47
|
-
WorkflowCriticalityEnum2["ALL"] = "all";
|
|
48
|
-
return WorkflowCriticalityEnum2;
|
|
49
|
-
})(WorkflowCriticalityEnum || {});
|
|
50
|
-
|
|
51
8
|
// src/utils/arrays.ts
|
|
52
9
|
var arrayValuesEqual = (arr1, arr2) => {
|
|
53
10
|
if (arr1 === arr2) {
|
|
@@ -139,1098 +96,1197 @@ function checkNotificationMatchesFilter(notification, filter) {
|
|
|
139
96
|
return checkBasicFilters(notification, filter) && checkNotificationTagFilter(notification.tags, filter.tags) && checkNotificationDataFilter(notification.data, filter.data);
|
|
140
97
|
}
|
|
141
98
|
|
|
142
|
-
// src/
|
|
143
|
-
var
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
apiUrl = this.DEFAULT_BACKEND_URL,
|
|
152
|
-
userAgent = DEFAULT_USER_AGENT,
|
|
153
|
-
headers = {}
|
|
154
|
-
} = options || {};
|
|
155
|
-
this.apiVersion = apiVersion;
|
|
156
|
-
this.apiUrl = `${apiUrl}/${apiVersion}`;
|
|
157
|
-
this.headers = __spreadValues({
|
|
158
|
-
"Novu-API-Version": "2024-06-26",
|
|
159
|
-
"Content-Type": "application/json",
|
|
160
|
-
"User-Agent": userAgent
|
|
161
|
-
}, headers);
|
|
162
|
-
}
|
|
163
|
-
setAuthorizationToken(token) {
|
|
164
|
-
this.headers.Authorization = `Bearer ${token}`;
|
|
165
|
-
}
|
|
166
|
-
setKeylessHeader(identifier) {
|
|
99
|
+
// src/subscriptions/subscription.ts
|
|
100
|
+
var _emitter, _inboxService, _cache, _useCache, _isStale;
|
|
101
|
+
var TopicSubscription = class {
|
|
102
|
+
constructor(subscription, emitter, inboxService, cache, useCache) {
|
|
103
|
+
__privateAdd(this, _emitter);
|
|
104
|
+
__privateAdd(this, _inboxService);
|
|
105
|
+
__privateAdd(this, _cache);
|
|
106
|
+
__privateAdd(this, _useCache);
|
|
107
|
+
__privateAdd(this, _isStale, false);
|
|
167
108
|
var _a;
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.
|
|
109
|
+
__privateSet(this, _emitter, emitter);
|
|
110
|
+
__privateSet(this, _inboxService, inboxService);
|
|
111
|
+
__privateSet(this, _cache, cache);
|
|
112
|
+
__privateSet(this, _useCache, useCache);
|
|
113
|
+
this.id = subscription.id;
|
|
114
|
+
this.identifier = subscription.identifier;
|
|
115
|
+
this.topicKey = subscription.topicKey;
|
|
116
|
+
this.preferences = (_a = subscription.preferences) == null ? void 0 : _a.map(
|
|
117
|
+
(pref) => new SubscriptionPreference(__spreadValues({}, pref), __privateGet(this, _emitter), __privateGet(this, _inboxService), __privateGet(this, _cache), __privateGet(this, _useCache))
|
|
118
|
+
);
|
|
176
119
|
}
|
|
177
|
-
|
|
120
|
+
update(args) {
|
|
178
121
|
return __async(this, null, function* () {
|
|
179
|
-
return
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
},
|
|
185
|
-
unwrapEnvelope
|
|
122
|
+
return updateSubscription({
|
|
123
|
+
emitter: __privateGet(this, _emitter),
|
|
124
|
+
apiService: __privateGet(this, _inboxService),
|
|
125
|
+
cache: __privateGet(this, _cache),
|
|
126
|
+
useCache: __privateGet(this, _useCache),
|
|
127
|
+
args: __spreadProps(__spreadValues({}, args), { subscription: this })
|
|
186
128
|
});
|
|
187
129
|
});
|
|
188
130
|
}
|
|
189
|
-
|
|
131
|
+
updatePreference(args) {
|
|
190
132
|
return __async(this, null, function* () {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
133
|
+
if (__privateGet(this, _isStale)) {
|
|
134
|
+
return {
|
|
135
|
+
error: new NovuError("Cannot update a deleted subscription", new Error("Subscription is stale"))
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return updateSubscriptionPreference({
|
|
139
|
+
emitter: __privateGet(this, _emitter),
|
|
140
|
+
apiService: __privateGet(this, _inboxService),
|
|
141
|
+
cache: __privateGet(this, _cache),
|
|
142
|
+
useCache: __privateGet(this, _useCache),
|
|
143
|
+
args: __spreadProps(__spreadValues({}, args), { subscriptionId: this.id })
|
|
198
144
|
});
|
|
199
145
|
});
|
|
200
146
|
}
|
|
201
|
-
|
|
147
|
+
bulkUpdatePreferences(args) {
|
|
202
148
|
return __async(this, null, function* () {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
149
|
+
if (__privateGet(this, _isStale)) {
|
|
150
|
+
return {
|
|
151
|
+
error: new NovuError("Cannot bulk update a deleted subscription", new Error("Subscription is stale"))
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return bulkUpdateSubscriptionPreference({
|
|
155
|
+
emitter: __privateGet(this, _emitter),
|
|
156
|
+
apiService: __privateGet(this, _inboxService),
|
|
157
|
+
cache: __privateGet(this, _cache),
|
|
158
|
+
useCache: __privateGet(this, _useCache),
|
|
159
|
+
args: args.map((arg) => __spreadProps(__spreadValues({}, arg), { subscriptionId: this.id }))
|
|
209
160
|
});
|
|
210
161
|
});
|
|
211
162
|
}
|
|
212
|
-
delete(
|
|
163
|
+
delete() {
|
|
213
164
|
return __async(this, null, function* () {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
body
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
doFetch(_0) {
|
|
224
|
-
return __async(this, arguments, function* ({
|
|
225
|
-
path,
|
|
226
|
-
searchParams,
|
|
227
|
-
options,
|
|
228
|
-
unwrapEnvelope = true
|
|
229
|
-
}) {
|
|
230
|
-
const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
|
|
231
|
-
const reqInit = {
|
|
232
|
-
method: (options == null ? void 0 : options.method) || "GET",
|
|
233
|
-
headers: __spreadValues(__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
|
|
234
|
-
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
235
|
-
};
|
|
236
|
-
const response = yield fetch(fullUrl, reqInit);
|
|
237
|
-
if (!response.ok) {
|
|
238
|
-
const errorData = yield response.json();
|
|
239
|
-
throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
|
|
240
|
-
}
|
|
241
|
-
if (response.status === 204) {
|
|
242
|
-
return void 0;
|
|
165
|
+
if (__privateGet(this, _isStale)) {
|
|
166
|
+
return {
|
|
167
|
+
error: new NovuError("Cannot delete an already deleted subscription", new Error("Subscription is stale"))
|
|
168
|
+
};
|
|
243
169
|
}
|
|
244
|
-
|
|
245
|
-
|
|
170
|
+
return deleteSubscription({
|
|
171
|
+
emitter: __privateGet(this, _emitter),
|
|
172
|
+
apiService: __privateGet(this, _inboxService),
|
|
173
|
+
args: { subscription: this }
|
|
174
|
+
});
|
|
246
175
|
});
|
|
247
176
|
}
|
|
248
177
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return acc;
|
|
255
|
-
}, []).join("/").replace(/\/\?/, "?");
|
|
256
|
-
}
|
|
178
|
+
_emitter = new WeakMap();
|
|
179
|
+
_inboxService = new WeakMap();
|
|
180
|
+
_cache = new WeakMap();
|
|
181
|
+
_useCache = new WeakMap();
|
|
182
|
+
_isStale = new WeakMap();
|
|
257
183
|
|
|
258
|
-
// src/
|
|
259
|
-
var
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
defaultSchedule,
|
|
275
|
-
context
|
|
276
|
-
}) {
|
|
277
|
-
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
278
|
-
applicationIdentifier,
|
|
279
|
-
subscriberHash,
|
|
280
|
-
contextHash,
|
|
281
|
-
subscriber,
|
|
282
|
-
defaultSchedule,
|
|
283
|
-
context
|
|
184
|
+
// src/subscriptions/helpers.ts
|
|
185
|
+
var listSubscriptions = (_0) => __async(void 0, [_0], function* ({
|
|
186
|
+
emitter,
|
|
187
|
+
apiService,
|
|
188
|
+
cache,
|
|
189
|
+
options,
|
|
190
|
+
args
|
|
191
|
+
}) {
|
|
192
|
+
try {
|
|
193
|
+
const { useCache, refetch } = options;
|
|
194
|
+
let data = useCache && !refetch ? cache.getAll(args) : void 0;
|
|
195
|
+
emitter.emit("subscriptions.list.pending", { args, data });
|
|
196
|
+
if (!data || refetch) {
|
|
197
|
+
const response = yield apiService.fetchSubscriptions(args.topicKey);
|
|
198
|
+
data = response.map((el) => {
|
|
199
|
+
return new TopicSubscription(__spreadProps(__spreadValues({}, el), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
284
200
|
});
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return response;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
fetchNotifications({
|
|
292
|
-
after,
|
|
293
|
-
archived,
|
|
294
|
-
limit = 10,
|
|
295
|
-
offset,
|
|
296
|
-
read: read2,
|
|
297
|
-
tags,
|
|
298
|
-
snoozed,
|
|
299
|
-
seen: seen2,
|
|
300
|
-
data,
|
|
301
|
-
severity
|
|
302
|
-
}) {
|
|
303
|
-
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
304
|
-
if (after) {
|
|
305
|
-
searchParams.append("after", after);
|
|
306
|
-
}
|
|
307
|
-
if (offset) {
|
|
308
|
-
searchParams.append("offset", `${offset}`);
|
|
309
|
-
}
|
|
310
|
-
if (tags) {
|
|
311
|
-
for (const tag of tags) {
|
|
312
|
-
searchParams.append("tags[]", tag);
|
|
201
|
+
if (useCache) {
|
|
202
|
+
cache.set(args, data);
|
|
203
|
+
data = cache.getAll(args);
|
|
313
204
|
}
|
|
314
205
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
206
|
+
emitter.emit("subscriptions.list.resolved", { args, data });
|
|
207
|
+
return { data };
|
|
208
|
+
} catch (error) {
|
|
209
|
+
emitter.emit("subscriptions.list.resolved", { args, error });
|
|
210
|
+
return { error: new NovuError("Failed to fetch subscriptions", error) };
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
var getSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
214
|
+
emitter,
|
|
215
|
+
apiService,
|
|
216
|
+
cache,
|
|
217
|
+
options,
|
|
218
|
+
args
|
|
219
|
+
}) {
|
|
220
|
+
try {
|
|
221
|
+
const { useCache, refetch } = options;
|
|
222
|
+
let data = useCache && !refetch ? cache.get(args) : void 0;
|
|
223
|
+
emitter.emit("subscription.get.pending", { args, data });
|
|
224
|
+
if (!data || refetch) {
|
|
225
|
+
const response = yield apiService.getSubscription(args.topicKey, args.identifier, args.workflowIds, args.tags);
|
|
226
|
+
if (!response) {
|
|
227
|
+
emitter.emit("subscription.get.resolved", { args, data: null });
|
|
228
|
+
return { data: null };
|
|
229
|
+
}
|
|
230
|
+
data = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
231
|
+
if (useCache) {
|
|
232
|
+
cache.setOne(args, data);
|
|
233
|
+
data = cache.get(args);
|
|
333
234
|
}
|
|
334
|
-
} else if (severity) {
|
|
335
|
-
searchParams.append("severity", severity);
|
|
336
235
|
}
|
|
337
|
-
|
|
236
|
+
emitter.emit("subscription.get.resolved", { args, data });
|
|
237
|
+
return { data };
|
|
238
|
+
} catch (error) {
|
|
239
|
+
emitter.emit("subscription.get.resolved", { args, error });
|
|
240
|
+
return { error: new NovuError("Failed to fetch subscription", error) };
|
|
338
241
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
242
|
+
});
|
|
243
|
+
var createSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
244
|
+
emitter,
|
|
245
|
+
apiService,
|
|
246
|
+
cache,
|
|
247
|
+
useCache,
|
|
248
|
+
args
|
|
249
|
+
}) {
|
|
250
|
+
var _a;
|
|
251
|
+
try {
|
|
252
|
+
emitter.emit("subscription.create.pending", { args });
|
|
253
|
+
const response = yield apiService.createSubscription({
|
|
254
|
+
identifier: (_a = args.identifier) != null ? _a : "",
|
|
255
|
+
name: args.name,
|
|
256
|
+
topicKey: args.topicKey,
|
|
257
|
+
topicName: args.topicName,
|
|
258
|
+
preferences: args.preferences
|
|
259
|
+
});
|
|
260
|
+
const subscription = new TopicSubscription(
|
|
261
|
+
__spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }),
|
|
262
|
+
emitter,
|
|
263
|
+
apiService,
|
|
264
|
+
cache,
|
|
265
|
+
useCache
|
|
348
266
|
);
|
|
267
|
+
emitter.emit("subscription.create.resolved", { args, data: subscription });
|
|
268
|
+
return { data: subscription };
|
|
269
|
+
} catch (error) {
|
|
270
|
+
emitter.emit("subscription.create.resolved", { args, error });
|
|
271
|
+
return { error: new NovuError("Failed to create subscription", error) };
|
|
349
272
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
return
|
|
376
|
-
tags,
|
|
377
|
-
data: data ? JSON.stringify(data) : void 0
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
archiveAllRead({ tags, data }) {
|
|
381
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
382
|
-
tags,
|
|
383
|
-
data: data ? JSON.stringify(data) : void 0
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
delete(notificationId) {
|
|
387
|
-
return __privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
|
|
388
|
-
}
|
|
389
|
-
deleteAll({ tags, data }) {
|
|
390
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
|
|
391
|
-
tags,
|
|
392
|
-
data: data ? JSON.stringify(data) : void 0
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
markAsSeen({
|
|
396
|
-
notificationIds,
|
|
397
|
-
tags,
|
|
398
|
-
data
|
|
399
|
-
}) {
|
|
400
|
-
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/seen`, {
|
|
401
|
-
notificationIds,
|
|
402
|
-
tags,
|
|
403
|
-
data: data ? JSON.stringify(data) : void 0
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
seen(notificationId) {
|
|
407
|
-
return this.markAsSeen({ notificationIds: [notificationId] });
|
|
408
|
-
}
|
|
409
|
-
completeAction({
|
|
410
|
-
actionType,
|
|
411
|
-
notificationId
|
|
412
|
-
}) {
|
|
413
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
414
|
-
actionType
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
revertAction({
|
|
418
|
-
actionType,
|
|
419
|
-
notificationId
|
|
420
|
-
}) {
|
|
421
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
422
|
-
actionType
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
fetchPreferences({
|
|
426
|
-
tags,
|
|
427
|
-
severity,
|
|
428
|
-
criticality
|
|
429
|
-
}) {
|
|
430
|
-
const queryParams = new URLSearchParams();
|
|
431
|
-
if (tags) {
|
|
432
|
-
for (const tag of tags) {
|
|
433
|
-
queryParams.append("tags[]", tag);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
if (severity && Array.isArray(severity)) {
|
|
437
|
-
for (const el of severity) {
|
|
438
|
-
queryParams.append("severity[]", el);
|
|
439
|
-
}
|
|
440
|
-
} else if (severity) {
|
|
441
|
-
queryParams.append("severity", severity);
|
|
442
|
-
}
|
|
443
|
-
if (criticality) {
|
|
444
|
-
queryParams.append("criticality", criticality);
|
|
445
|
-
}
|
|
446
|
-
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
447
|
-
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
448
|
-
}
|
|
449
|
-
bulkUpdatePreferences(preferences) {
|
|
450
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
451
|
-
}
|
|
452
|
-
updateGlobalPreferences(preferences) {
|
|
453
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
|
|
454
|
-
}
|
|
455
|
-
updateWorkflowPreferences({
|
|
456
|
-
workflowId,
|
|
457
|
-
channels
|
|
458
|
-
}) {
|
|
459
|
-
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
|
|
460
|
-
}
|
|
461
|
-
fetchGlobalPreferences() {
|
|
462
|
-
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
|
|
463
|
-
}
|
|
464
|
-
triggerHelloWorldEvent() {
|
|
465
|
-
const payload = {
|
|
466
|
-
name: "hello-world",
|
|
467
|
-
to: {
|
|
468
|
-
subscriberId: "keyless-subscriber-id"
|
|
469
|
-
},
|
|
470
|
-
payload: {
|
|
471
|
-
subject: "Novu Keyless Environment",
|
|
472
|
-
body: "You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",
|
|
473
|
-
primaryActionText: "Obtain API Key",
|
|
474
|
-
primaryActionUrl: "https://go.novu.co/keyless",
|
|
475
|
-
secondaryActionText: "Explore Documentation",
|
|
476
|
-
secondaryActionUrl: "https://go.novu.co/keyless-docs"
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
return __privateGet(this, _httpClient).post("/inbox/events", payload);
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
_httpClient = new WeakMap();
|
|
483
|
-
var _mittEmitter;
|
|
484
|
-
var NovuEventEmitter = class {
|
|
485
|
-
constructor() {
|
|
486
|
-
__privateAdd(this, _mittEmitter);
|
|
487
|
-
__privateSet(this, _mittEmitter, mitt());
|
|
488
|
-
}
|
|
489
|
-
on(eventName, listener) {
|
|
490
|
-
__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
491
|
-
return () => {
|
|
492
|
-
this.off(eventName, listener);
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
off(eventName, listener) {
|
|
496
|
-
__privateGet(this, _mittEmitter).off(eventName, listener);
|
|
497
|
-
}
|
|
498
|
-
emit(type, event) {
|
|
499
|
-
__privateGet(this, _mittEmitter).emit(type, event);
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
_mittEmitter = new WeakMap();
|
|
503
|
-
|
|
504
|
-
// src/utils/errors.ts
|
|
505
|
-
var NovuError = class extends Error {
|
|
506
|
-
constructor(message, originalError) {
|
|
507
|
-
super(message);
|
|
508
|
-
this.originalError = originalError;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
// src/notifications/helpers.ts
|
|
513
|
-
var read = (_0) => __async(void 0, [_0], function* ({
|
|
514
|
-
emitter,
|
|
515
|
-
apiService,
|
|
516
|
-
args
|
|
517
|
-
}) {
|
|
518
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
519
|
-
args,
|
|
520
|
-
{
|
|
521
|
-
isRead: true,
|
|
522
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
523
|
-
isArchived: false,
|
|
524
|
-
archivedAt: void 0
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
emitter,
|
|
528
|
-
apiService
|
|
529
|
-
}
|
|
530
|
-
);
|
|
531
|
-
try {
|
|
532
|
-
emitter.emit("notification.read.pending", {
|
|
533
|
-
args,
|
|
534
|
-
data: optimisticValue
|
|
535
|
-
});
|
|
536
|
-
const response = yield apiService.read(notificationId);
|
|
537
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
538
|
-
emitter.emit("notification.read.resolved", { args, data: updatedNotification });
|
|
539
|
-
return { data: updatedNotification };
|
|
540
|
-
} catch (error) {
|
|
541
|
-
emitter.emit("notification.read.resolved", { args, error });
|
|
542
|
-
return { error: new NovuError("Failed to read notification", error) };
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
var unread = (_0) => __async(void 0, [_0], function* ({
|
|
546
|
-
emitter,
|
|
547
|
-
apiService,
|
|
548
|
-
args
|
|
549
|
-
}) {
|
|
550
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
551
|
-
args,
|
|
552
|
-
{
|
|
553
|
-
isRead: false,
|
|
554
|
-
readAt: null,
|
|
555
|
-
isArchived: false,
|
|
556
|
-
archivedAt: void 0
|
|
557
|
-
},
|
|
558
|
-
{
|
|
559
|
-
emitter,
|
|
560
|
-
apiService
|
|
561
|
-
}
|
|
562
|
-
);
|
|
563
|
-
try {
|
|
564
|
-
emitter.emit("notification.unread.pending", {
|
|
565
|
-
args,
|
|
566
|
-
data: optimisticValue
|
|
567
|
-
});
|
|
568
|
-
const response = yield apiService.unread(notificationId);
|
|
569
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
570
|
-
emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
|
|
571
|
-
return { data: updatedNotification };
|
|
572
|
-
} catch (error) {
|
|
573
|
-
emitter.emit("notification.unread.resolved", { args, error });
|
|
574
|
-
return { error: new NovuError("Failed to unread notification", error) };
|
|
273
|
+
});
|
|
274
|
+
var updateSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
275
|
+
emitter,
|
|
276
|
+
apiService,
|
|
277
|
+
cache,
|
|
278
|
+
useCache,
|
|
279
|
+
args
|
|
280
|
+
}) {
|
|
281
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
282
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
283
|
+
try {
|
|
284
|
+
emitter.emit("subscription.update.pending", {
|
|
285
|
+
args
|
|
286
|
+
});
|
|
287
|
+
const response = yield apiService.updateSubscription({
|
|
288
|
+
topicKey,
|
|
289
|
+
subscriptionId,
|
|
290
|
+
name: args.name,
|
|
291
|
+
preferences: args.preferences
|
|
292
|
+
});
|
|
293
|
+
const updatedSubscription = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey }), emitter, apiService, cache, useCache);
|
|
294
|
+
emitter.emit("subscription.update.resolved", { args, data: updatedSubscription });
|
|
295
|
+
return { data: updatedSubscription };
|
|
296
|
+
} catch (error) {
|
|
297
|
+
emitter.emit("subscription.update.resolved", { args, error });
|
|
298
|
+
return { error: new NovuError("Failed to update subscription", error) };
|
|
575
299
|
}
|
|
576
300
|
});
|
|
577
|
-
var
|
|
301
|
+
var updateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
|
|
578
302
|
emitter,
|
|
579
303
|
apiService,
|
|
304
|
+
cache,
|
|
305
|
+
useCache,
|
|
580
306
|
args
|
|
581
307
|
}) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
{
|
|
585
|
-
isSeen: true
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
emitter,
|
|
589
|
-
apiService
|
|
590
|
-
}
|
|
591
|
-
);
|
|
308
|
+
var _a, _b;
|
|
309
|
+
const workflowId = "workflowId" in args ? args.workflowId : (_b = (_a = args.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id;
|
|
592
310
|
try {
|
|
593
|
-
emitter.emit("
|
|
311
|
+
emitter.emit("subscription.preference.update.pending", {
|
|
594
312
|
args,
|
|
595
|
-
data:
|
|
313
|
+
data: "preference" in args ? new SubscriptionPreference(
|
|
314
|
+
__spreadValues(__spreadValues({}, args.preference), typeof args.value === "boolean" ? { enabled: args.value } : { condition: args.value }),
|
|
315
|
+
emitter,
|
|
316
|
+
apiService,
|
|
317
|
+
cache,
|
|
318
|
+
useCache
|
|
319
|
+
) : void 0
|
|
596
320
|
});
|
|
597
|
-
yield apiService.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
321
|
+
const response = yield apiService.updateSubscriptionPreference(__spreadValues({
|
|
322
|
+
subscriptionId: args.subscriptionId,
|
|
323
|
+
workflowId
|
|
324
|
+
}, typeof args.value === "boolean" ? {
|
|
325
|
+
enabled: args.value,
|
|
326
|
+
email: args.value,
|
|
327
|
+
sms: args.value,
|
|
328
|
+
in_app: args.value,
|
|
329
|
+
chat: args.value,
|
|
330
|
+
push: args.value
|
|
331
|
+
} : { condition: args.value }));
|
|
332
|
+
const updatedSubscription = new SubscriptionPreference(__spreadValues({}, response), emitter, apiService, cache, useCache);
|
|
333
|
+
emitter.emit("subscription.preference.update.resolved", { args, data: updatedSubscription });
|
|
334
|
+
return { data: updatedSubscription };
|
|
604
335
|
} catch (error) {
|
|
605
|
-
emitter.emit("
|
|
606
|
-
return { error: new NovuError("Failed to
|
|
336
|
+
emitter.emit("subscription.preference.update.resolved", { args, error });
|
|
337
|
+
return { error: new NovuError("Failed to update subscription", error) };
|
|
607
338
|
}
|
|
608
339
|
});
|
|
609
|
-
var
|
|
340
|
+
var bulkUpdateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
|
|
610
341
|
emitter,
|
|
611
342
|
apiService,
|
|
343
|
+
cache,
|
|
344
|
+
useCache,
|
|
612
345
|
args
|
|
613
346
|
}) {
|
|
614
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
615
|
-
args,
|
|
616
|
-
{
|
|
617
|
-
isArchived: true,
|
|
618
|
-
archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
619
|
-
isRead: true,
|
|
620
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
621
|
-
},
|
|
622
|
-
{
|
|
623
|
-
emitter,
|
|
624
|
-
apiService
|
|
625
|
-
}
|
|
626
|
-
);
|
|
627
347
|
try {
|
|
628
|
-
|
|
348
|
+
const optimisticallyUpdatedPreferences = args.map(
|
|
349
|
+
(arg) => "preference" in arg ? new SubscriptionPreference(
|
|
350
|
+
__spreadValues(__spreadValues({}, arg.preference), typeof arg.value === "boolean" ? { enabled: arg.value } : { condition: arg.value }),
|
|
351
|
+
emitter,
|
|
352
|
+
apiService,
|
|
353
|
+
cache,
|
|
354
|
+
useCache
|
|
355
|
+
) : void 0
|
|
356
|
+
).filter((el) => el !== void 0);
|
|
357
|
+
emitter.emit("subscription.preferences.bulk_update.pending", {
|
|
629
358
|
args,
|
|
630
|
-
data:
|
|
359
|
+
data: optimisticallyUpdatedPreferences
|
|
631
360
|
});
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
return { error: new NovuError("Failed to archive notification", error) };
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
var unarchive = (_0) => __async(void 0, [_0], function* ({
|
|
642
|
-
emitter,
|
|
643
|
-
apiService,
|
|
644
|
-
args
|
|
645
|
-
}) {
|
|
646
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
647
|
-
args,
|
|
648
|
-
{
|
|
649
|
-
isArchived: false,
|
|
650
|
-
archivedAt: null,
|
|
651
|
-
isRead: true,
|
|
652
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
emitter,
|
|
656
|
-
apiService
|
|
657
|
-
}
|
|
658
|
-
);
|
|
659
|
-
try {
|
|
660
|
-
emitter.emit("notification.unarchive.pending", {
|
|
661
|
-
args,
|
|
662
|
-
data: optimisticValue
|
|
361
|
+
const preferencesToUpdate = args.map((arg) => {
|
|
362
|
+
var _a, _b, _c, _d, _e, _f;
|
|
363
|
+
return __spreadValues({
|
|
364
|
+
subscriptionIdOrIdentifier: arg.subscriptionId,
|
|
365
|
+
workflowId: "workflowId" in arg ? arg.workflowId : (_f = (_e = (_b = (_a = arg.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id) != null ? _e : (_d = (_c = arg.preference) == null ? void 0 : _c.workflow) == null ? void 0 : _d.identifier) != null ? _f : ""
|
|
366
|
+
}, typeof arg.value === "boolean" ? { enabled: arg.value, email: arg.value, sms: arg.value, in_app: arg.value, chat: arg.value, push: arg.value } : { condition: arg.value });
|
|
663
367
|
});
|
|
664
|
-
const response = yield apiService.
|
|
665
|
-
const
|
|
666
|
-
emitter.emit("
|
|
667
|
-
return { data:
|
|
368
|
+
const response = yield apiService.bulkUpdateSubscriptionPreferences(preferencesToUpdate);
|
|
369
|
+
const preferences = response.map((el) => new SubscriptionPreference(el, emitter, apiService, cache, useCache));
|
|
370
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, data: preferences });
|
|
371
|
+
return { data: preferences };
|
|
668
372
|
} catch (error) {
|
|
669
|
-
emitter.emit("
|
|
670
|
-
return { error: new NovuError("Failed to
|
|
373
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, error });
|
|
374
|
+
return { error: new NovuError("Failed to bulk update subscription preferences", error) };
|
|
671
375
|
}
|
|
672
376
|
});
|
|
673
|
-
var
|
|
377
|
+
var deleteSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
674
378
|
emitter,
|
|
675
379
|
apiService,
|
|
676
380
|
args
|
|
677
381
|
}) {
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
{
|
|
681
|
-
isSnoozed: true,
|
|
682
|
-
snoozedUntil: args.snoozeUntil
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
emitter,
|
|
686
|
-
apiService
|
|
687
|
-
}
|
|
688
|
-
);
|
|
382
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
383
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
689
384
|
try {
|
|
690
|
-
emitter.emit("
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
const response = yield apiService.snooze(notificationId, args.snoozeUntil);
|
|
695
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
696
|
-
emitter.emit("notification.snooze.resolved", { args, data: updatedNotification });
|
|
697
|
-
return { data: updatedNotification };
|
|
385
|
+
emitter.emit("subscription.delete.pending", { args });
|
|
386
|
+
yield apiService.deleteSubscription({ topicKey, subscriptionId });
|
|
387
|
+
emitter.emit("subscription.delete.resolved", { args });
|
|
388
|
+
return { data: void 0 };
|
|
698
389
|
} catch (error) {
|
|
699
|
-
emitter.emit("
|
|
700
|
-
return { error: new NovuError("Failed to
|
|
390
|
+
emitter.emit("subscription.delete.resolved", { args, error });
|
|
391
|
+
return { error: new NovuError("Failed to delete subscription", error) };
|
|
701
392
|
}
|
|
702
393
|
});
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
args,
|
|
722
|
-
data: optimisticValue
|
|
723
|
-
});
|
|
724
|
-
const response = yield apiService.unsnooze(notificationId);
|
|
725
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
726
|
-
emitter.emit("notification.unsnooze.resolved", { args, data: updatedNotification });
|
|
727
|
-
return { data: updatedNotification };
|
|
728
|
-
} catch (error) {
|
|
729
|
-
emitter.emit("notification.unsnooze.resolved", { args, error });
|
|
730
|
-
return { error: new NovuError("Failed to unsnooze notification", error) };
|
|
394
|
+
|
|
395
|
+
// src/subscriptions/subscription-preference.ts
|
|
396
|
+
var _emitter2, _inboxService2, _cache2, _useCache2;
|
|
397
|
+
var SubscriptionPreference = class {
|
|
398
|
+
constructor(preference, emitter, inboxService, cache, useCache) {
|
|
399
|
+
__privateAdd(this, _emitter2);
|
|
400
|
+
__privateAdd(this, _inboxService2);
|
|
401
|
+
__privateAdd(this, _cache2);
|
|
402
|
+
__privateAdd(this, _useCache2);
|
|
403
|
+
var _a;
|
|
404
|
+
__privateSet(this, _emitter2, emitter);
|
|
405
|
+
__privateSet(this, _inboxService2, inboxService);
|
|
406
|
+
__privateSet(this, _cache2, cache);
|
|
407
|
+
__privateSet(this, _useCache2, useCache);
|
|
408
|
+
this.enabled = preference.enabled;
|
|
409
|
+
this.condition = (_a = preference.condition) != null ? _a : void 0;
|
|
410
|
+
this.workflow = preference.workflow;
|
|
411
|
+
this.subscriptionId = preference.subscriptionId;
|
|
731
412
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
};
|
|
748
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
749
|
-
emitter,
|
|
750
|
-
apiService
|
|
751
|
-
});
|
|
752
|
-
try {
|
|
753
|
-
emitter.emit("notification.complete_action.pending", {
|
|
754
|
-
args,
|
|
755
|
-
data: optimisticValue
|
|
413
|
+
update(args) {
|
|
414
|
+
return __async(this, null, function* () {
|
|
415
|
+
var _a;
|
|
416
|
+
return updateSubscriptionPreference({
|
|
417
|
+
emitter: __privateGet(this, _emitter2),
|
|
418
|
+
apiService: __privateGet(this, _inboxService2),
|
|
419
|
+
cache: __privateGet(this, _cache2),
|
|
420
|
+
useCache: __privateGet(this, _useCache2),
|
|
421
|
+
args: {
|
|
422
|
+
subscriptionId: this.subscriptionId,
|
|
423
|
+
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
424
|
+
value: args.value,
|
|
425
|
+
preference: this
|
|
426
|
+
}
|
|
427
|
+
});
|
|
756
428
|
});
|
|
757
|
-
const response = yield apiService.completeAction({ actionType, notificationId });
|
|
758
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
759
|
-
emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
|
|
760
|
-
return { data: updatedNotification };
|
|
761
|
-
} catch (error) {
|
|
762
|
-
emitter.emit("notification.complete_action.resolved", { args, error });
|
|
763
|
-
return { error: new NovuError(`Failed to complete ${actionType} action on the notification`, error) };
|
|
764
429
|
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
430
|
+
};
|
|
431
|
+
_emitter2 = new WeakMap();
|
|
432
|
+
_inboxService2 = new WeakMap();
|
|
433
|
+
_cache2 = new WeakMap();
|
|
434
|
+
_useCache2 = new WeakMap();
|
|
435
|
+
|
|
436
|
+
// src/base-module.ts
|
|
437
|
+
var _callsQueue, _sessionError;
|
|
438
|
+
var BaseModule = class {
|
|
439
|
+
constructor({
|
|
440
|
+
inboxServiceInstance,
|
|
441
|
+
eventEmitterInstance
|
|
442
|
+
}) {
|
|
443
|
+
__privateAdd(this, _callsQueue, []);
|
|
444
|
+
__privateAdd(this, _sessionError);
|
|
445
|
+
this._emitter = eventEmitterInstance;
|
|
446
|
+
this._inboxService = inboxServiceInstance;
|
|
447
|
+
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
448
|
+
if (data) {
|
|
449
|
+
this.onSessionSuccess(data);
|
|
450
|
+
__privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
|
|
451
|
+
resolve(yield fn());
|
|
452
|
+
}));
|
|
453
|
+
__privateSet(this, _callsQueue, []);
|
|
454
|
+
} else if (error) {
|
|
455
|
+
this.onSessionError(error);
|
|
456
|
+
__privateSet(this, _sessionError, error);
|
|
457
|
+
__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
458
|
+
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
459
|
+
});
|
|
460
|
+
__privateSet(this, _callsQueue, []);
|
|
461
|
+
}
|
|
789
462
|
});
|
|
790
|
-
const response = yield apiService.revertAction({ actionType, notificationId });
|
|
791
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
792
|
-
emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
|
|
793
|
-
return { data: updatedNotification };
|
|
794
|
-
} catch (error) {
|
|
795
|
-
emitter.emit("notification.revert_action.resolved", { args, error });
|
|
796
|
-
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
797
463
|
}
|
|
798
|
-
|
|
799
|
-
var getNotificationDetails = (args, update, dependencies) => {
|
|
800
|
-
if ("notification" in args) {
|
|
801
|
-
return {
|
|
802
|
-
notificationId: args.notification.id,
|
|
803
|
-
optimisticValue: new Notification(
|
|
804
|
-
__spreadValues(__spreadValues({}, args.notification), update),
|
|
805
|
-
dependencies.emitter,
|
|
806
|
-
dependencies.apiService
|
|
807
|
-
)
|
|
808
|
-
};
|
|
809
|
-
} else {
|
|
810
|
-
return {
|
|
811
|
-
notificationId: args.notificationId
|
|
812
|
-
};
|
|
464
|
+
onSessionSuccess(_) {
|
|
813
465
|
}
|
|
814
|
-
|
|
815
|
-
var readAll = (_0) => __async(void 0, [_0], function* ({
|
|
816
|
-
emitter,
|
|
817
|
-
inboxService,
|
|
818
|
-
notificationsCache,
|
|
819
|
-
tags,
|
|
820
|
-
data
|
|
821
|
-
}) {
|
|
822
|
-
try {
|
|
823
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
824
|
-
const optimisticNotifications = notifications.map(
|
|
825
|
-
(notification) => new Notification(
|
|
826
|
-
__spreadProps(__spreadValues({}, notification), {
|
|
827
|
-
isRead: true,
|
|
828
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
829
|
-
isArchived: false,
|
|
830
|
-
archivedAt: void 0
|
|
831
|
-
}),
|
|
832
|
-
emitter,
|
|
833
|
-
inboxService
|
|
834
|
-
)
|
|
835
|
-
);
|
|
836
|
-
emitter.emit("notifications.read_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
837
|
-
yield inboxService.readAll({ tags, data });
|
|
838
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
839
|
-
return {};
|
|
840
|
-
} catch (error) {
|
|
841
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, error });
|
|
842
|
-
return { error: new NovuError("Failed to read all notifications", error) };
|
|
466
|
+
onSessionError(_) {
|
|
843
467
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
})
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
(notification) => new Notification(
|
|
858
|
-
__spreadProps(__spreadValues({}, notification), {
|
|
859
|
-
isSeen: true,
|
|
860
|
-
firstSeenAt: notification.firstSeenAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
861
|
-
}),
|
|
862
|
-
emitter,
|
|
863
|
-
inboxService
|
|
864
|
-
)
|
|
865
|
-
);
|
|
866
|
-
emitter.emit("notifications.seen_all.pending", {
|
|
867
|
-
args: { notificationIds, tags, data },
|
|
868
|
-
data: optimisticNotifications
|
|
869
|
-
});
|
|
870
|
-
yield inboxService.markAsSeen({ notificationIds, tags, data });
|
|
871
|
-
emitter.emit("notifications.seen_all.resolved", {
|
|
872
|
-
args: { notificationIds, tags, data },
|
|
873
|
-
data: optimisticNotifications
|
|
468
|
+
callWithSession(fn) {
|
|
469
|
+
return __async(this, null, function* () {
|
|
470
|
+
if (this._inboxService.isSessionInitialized) {
|
|
471
|
+
return fn();
|
|
472
|
+
}
|
|
473
|
+
if (__privateGet(this, _sessionError)) {
|
|
474
|
+
return Promise.resolve({
|
|
475
|
+
error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return new Promise((resolve, reject) => {
|
|
479
|
+
__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
480
|
+
});
|
|
874
481
|
});
|
|
875
|
-
return {};
|
|
876
|
-
} catch (error) {
|
|
877
|
-
emitter.emit("notifications.seen_all.resolved", { args: { notificationIds, tags, data }, error });
|
|
878
|
-
return { error: new NovuError("Failed to mark all notifications as seen", error) };
|
|
879
482
|
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
const optimisticNotifications = notifications.map(
|
|
891
|
-
(notification) => new Notification(
|
|
892
|
-
__spreadProps(__spreadValues({}, notification), {
|
|
893
|
-
isRead: true,
|
|
894
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
895
|
-
isArchived: true,
|
|
896
|
-
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
897
|
-
}),
|
|
898
|
-
emitter,
|
|
899
|
-
inboxService
|
|
900
|
-
)
|
|
901
|
-
);
|
|
902
|
-
emitter.emit("notifications.archive_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
903
|
-
yield inboxService.archiveAll({ tags, data });
|
|
904
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
905
|
-
return {};
|
|
906
|
-
} catch (error) {
|
|
907
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, error });
|
|
908
|
-
return { error: new NovuError("Failed to archive all notifications", error) };
|
|
483
|
+
};
|
|
484
|
+
_callsQueue = new WeakMap();
|
|
485
|
+
_sessionError = new WeakMap();
|
|
486
|
+
|
|
487
|
+
// src/cache/in-memory-cache.ts
|
|
488
|
+
var _cache3;
|
|
489
|
+
var InMemoryCache = class {
|
|
490
|
+
constructor() {
|
|
491
|
+
__privateAdd(this, _cache3);
|
|
492
|
+
__privateSet(this, _cache3, /* @__PURE__ */ new Map());
|
|
909
493
|
}
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
emitter,
|
|
913
|
-
inboxService,
|
|
914
|
-
notificationsCache,
|
|
915
|
-
tags,
|
|
916
|
-
data
|
|
917
|
-
}) {
|
|
918
|
-
try {
|
|
919
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data, read: true });
|
|
920
|
-
const optimisticNotifications = notifications.map(
|
|
921
|
-
(notification) => new Notification(
|
|
922
|
-
__spreadProps(__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
923
|
-
emitter,
|
|
924
|
-
inboxService
|
|
925
|
-
)
|
|
926
|
-
);
|
|
927
|
-
emitter.emit("notifications.archive_all_read.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
928
|
-
yield inboxService.archiveAllRead({ tags, data });
|
|
929
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
930
|
-
return {};
|
|
931
|
-
} catch (error) {
|
|
932
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, error });
|
|
933
|
-
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
494
|
+
get(key) {
|
|
495
|
+
return __privateGet(this, _cache3).get(key);
|
|
934
496
|
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
emitter,
|
|
938
|
-
apiService,
|
|
939
|
-
args
|
|
940
|
-
}) {
|
|
941
|
-
const { notificationId } = getNotificationDetails(
|
|
942
|
-
args,
|
|
943
|
-
{},
|
|
944
|
-
{
|
|
945
|
-
emitter,
|
|
946
|
-
apiService
|
|
947
|
-
}
|
|
948
|
-
);
|
|
949
|
-
try {
|
|
950
|
-
emitter.emit("notification.delete.pending", {
|
|
951
|
-
args
|
|
952
|
-
});
|
|
953
|
-
yield apiService.delete(notificationId);
|
|
954
|
-
emitter.emit("notification.delete.resolved", { args });
|
|
955
|
-
return {};
|
|
956
|
-
} catch (error) {
|
|
957
|
-
emitter.emit("notification.delete.resolved", { args, error });
|
|
958
|
-
return { error: new NovuError("Failed to delete notification", error) };
|
|
497
|
+
getValues() {
|
|
498
|
+
return Array.from(__privateGet(this, _cache3).values());
|
|
959
499
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
emitter,
|
|
963
|
-
inboxService,
|
|
964
|
-
notificationsCache,
|
|
965
|
-
tags,
|
|
966
|
-
data
|
|
967
|
-
}) {
|
|
968
|
-
try {
|
|
969
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
970
|
-
emitter.emit("notifications.delete_all.pending", { args: { tags, data }, data: notifications });
|
|
971
|
-
yield inboxService.deleteAll({ tags, data });
|
|
972
|
-
emitter.emit("notifications.delete_all.resolved", { args: { tags, data } });
|
|
973
|
-
return {};
|
|
974
|
-
} catch (error) {
|
|
975
|
-
emitter.emit("notifications.delete_all.resolved", { args: { tags, data }, error });
|
|
976
|
-
return { error: new NovuError("Failed to delete all notifications", error) };
|
|
500
|
+
entries() {
|
|
501
|
+
return Array.from(__privateGet(this, _cache3).entries());
|
|
977
502
|
}
|
|
978
|
-
|
|
503
|
+
keys() {
|
|
504
|
+
return Array.from(__privateGet(this, _cache3).keys());
|
|
505
|
+
}
|
|
506
|
+
set(key, value) {
|
|
507
|
+
__privateGet(this, _cache3).set(key, value);
|
|
508
|
+
}
|
|
509
|
+
remove(key) {
|
|
510
|
+
__privateGet(this, _cache3).delete(key);
|
|
511
|
+
}
|
|
512
|
+
clear() {
|
|
513
|
+
__privateGet(this, _cache3).clear();
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
_cache3 = new WeakMap();
|
|
979
517
|
|
|
980
|
-
// src/
|
|
981
|
-
var
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
this
|
|
998
|
-
this
|
|
999
|
-
this
|
|
1000
|
-
this
|
|
1001
|
-
this
|
|
1002
|
-
this.
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
518
|
+
// src/cache/subscriptions-cache.ts
|
|
519
|
+
var getListCacheKey = (args) => {
|
|
520
|
+
return `list:${args.topicKey}`;
|
|
521
|
+
};
|
|
522
|
+
var getTopicKeyFromListCacheKey = (key) => {
|
|
523
|
+
return key.split(":")[1];
|
|
524
|
+
};
|
|
525
|
+
var getItemCacheKey = (args) => {
|
|
526
|
+
return `item:${args.topicKey}:${args.identifier}`;
|
|
527
|
+
};
|
|
528
|
+
var _emitter3, _cache4, _useCache3, _itemCache, _inboxService3;
|
|
529
|
+
var SubscriptionsCache = class {
|
|
530
|
+
constructor({
|
|
531
|
+
emitterInstance,
|
|
532
|
+
inboxServiceInstance,
|
|
533
|
+
useCache
|
|
534
|
+
}) {
|
|
535
|
+
__privateAdd(this, _emitter3);
|
|
536
|
+
__privateAdd(this, _cache4);
|
|
537
|
+
__privateAdd(this, _useCache3);
|
|
538
|
+
__privateAdd(this, _itemCache);
|
|
539
|
+
__privateAdd(this, _inboxService3);
|
|
540
|
+
this.handleCreate = (subscription) => {
|
|
541
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
542
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
543
|
+
if (subscriptions) {
|
|
544
|
+
const updatedSubscriptions = [...subscriptions, subscription];
|
|
545
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
546
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
547
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
__privateGet(this, _itemCache).set(
|
|
551
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
552
|
+
subscription
|
|
553
|
+
);
|
|
554
|
+
};
|
|
555
|
+
this.handleUpdate = (subscription) => {
|
|
556
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
557
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
558
|
+
if (subscriptions) {
|
|
559
|
+
const updatedSubscriptions = subscriptions.map((el) => el.id === subscription.id ? subscription : el);
|
|
560
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
561
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
562
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
__privateGet(this, _itemCache).set(
|
|
566
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
567
|
+
subscription
|
|
568
|
+
);
|
|
569
|
+
};
|
|
570
|
+
this.handlePreferenceUpdate = (preference) => {
|
|
571
|
+
this.updateSubscriptionPreferences([preference]);
|
|
572
|
+
};
|
|
573
|
+
this.handleBulkPreferenceUpdate = (preferences) => {
|
|
574
|
+
this.updateSubscriptionPreferences(preferences);
|
|
575
|
+
};
|
|
576
|
+
this.updateSubscriptionPreferences = (updatedPreferences) => {
|
|
577
|
+
var _a;
|
|
578
|
+
const preferencesBySubscription = /* @__PURE__ */ new Map();
|
|
579
|
+
for (const pref of updatedPreferences) {
|
|
580
|
+
const existing = (_a = preferencesBySubscription.get(pref.subscriptionId)) != null ? _a : [];
|
|
581
|
+
existing.push(pref);
|
|
582
|
+
preferencesBySubscription.set(pref.subscriptionId, existing);
|
|
583
|
+
}
|
|
584
|
+
const allListKeys = __privateGet(this, _cache4).keys();
|
|
585
|
+
for (const listKey of allListKeys) {
|
|
586
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
587
|
+
if (!subscriptions) continue;
|
|
588
|
+
let hasUpdates = false;
|
|
589
|
+
const updatedSubscriptions = subscriptions.map((subscription) => {
|
|
590
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
591
|
+
if (subscriptionPreferences) {
|
|
592
|
+
hasUpdates = true;
|
|
593
|
+
return this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
594
|
+
}
|
|
595
|
+
return subscription;
|
|
596
|
+
});
|
|
597
|
+
if (hasUpdates) {
|
|
598
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
599
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
600
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
605
|
+
for (const key of allItemKeys) {
|
|
606
|
+
const subscription = __privateGet(this, _itemCache).get(key);
|
|
607
|
+
if (!subscription) continue;
|
|
608
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
609
|
+
if (subscriptionPreferences) {
|
|
610
|
+
const updatedSubscription = this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
611
|
+
__privateGet(this, _itemCache).set(key, updatedSubscription);
|
|
612
|
+
__privateGet(this, _emitter3).emit("subscription.update.resolved", {
|
|
613
|
+
args: { subscription },
|
|
614
|
+
data: updatedSubscription
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
this.createUpdatedSubscription = (subscription, subscriptionPreferences) => {
|
|
620
|
+
var _a;
|
|
621
|
+
const updatedPreferences = (_a = subscription.preferences) == null ? void 0 : _a.map((pref) => {
|
|
622
|
+
const newPreference = subscriptionPreferences.find((el) => el.workflow.id === pref.workflow.id);
|
|
623
|
+
if (newPreference) {
|
|
624
|
+
return newPreference;
|
|
625
|
+
}
|
|
626
|
+
return pref;
|
|
627
|
+
});
|
|
628
|
+
return new TopicSubscription(
|
|
629
|
+
{
|
|
630
|
+
id: subscription.id,
|
|
631
|
+
identifier: subscription.identifier,
|
|
632
|
+
topicKey: subscription.topicKey,
|
|
633
|
+
preferences: updatedPreferences
|
|
634
|
+
},
|
|
635
|
+
__privateGet(this, _emitter3),
|
|
636
|
+
__privateGet(this, _inboxService3),
|
|
637
|
+
this,
|
|
638
|
+
__privateGet(this, _useCache3)
|
|
639
|
+
);
|
|
640
|
+
};
|
|
641
|
+
this.handleDelete = (subscription) => {
|
|
642
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
643
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
644
|
+
if (subscriptions) {
|
|
645
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
646
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
647
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
648
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }));
|
|
652
|
+
};
|
|
653
|
+
this.handleDeleteById = (subscriptionId) => {
|
|
654
|
+
const allListKeys = __privateGet(this, _cache4).keys();
|
|
655
|
+
for (const listKey of allListKeys) {
|
|
656
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
657
|
+
if (subscriptions) {
|
|
658
|
+
const subscription = subscriptions.find((el) => el.id === subscriptionId || el.identifier === subscriptionId);
|
|
659
|
+
if (subscription) {
|
|
660
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
661
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
662
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
663
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
664
|
+
});
|
|
665
|
+
__privateGet(this, _itemCache).remove(
|
|
666
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier })
|
|
667
|
+
);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
673
|
+
for (const key of allItemKeys) {
|
|
674
|
+
const subscription = __privateGet(this, _itemCache).get(key);
|
|
675
|
+
if (subscription && (subscription.id === subscriptionId || subscription.identifier === subscriptionId)) {
|
|
676
|
+
__privateGet(this, _itemCache).remove(key);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
__privateSet(this, _emitter3, emitterInstance);
|
|
682
|
+
__privateSet(this, _cache4, new InMemoryCache());
|
|
683
|
+
__privateSet(this, _itemCache, new InMemoryCache());
|
|
684
|
+
__privateSet(this, _inboxService3, inboxServiceInstance);
|
|
685
|
+
__privateSet(this, _useCache3, useCache);
|
|
686
|
+
__privateGet(this, _emitter3).on("subscription.create.resolved", ({ data }) => {
|
|
687
|
+
if (data) {
|
|
688
|
+
this.handleCreate(data);
|
|
1019
689
|
}
|
|
1020
690
|
});
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
emitter: __privateGet(this, _emitter),
|
|
1025
|
-
apiService: __privateGet(this, _inboxService),
|
|
1026
|
-
args: {
|
|
1027
|
-
notification: this
|
|
691
|
+
__privateGet(this, _emitter3).on("subscription.update.resolved", ({ data }) => {
|
|
692
|
+
if (data) {
|
|
693
|
+
this.handleUpdate(data);
|
|
1028
694
|
}
|
|
1029
695
|
});
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
args: {
|
|
1036
|
-
notification: this
|
|
696
|
+
__privateGet(this, _emitter3).on("subscription.delete.resolved", ({ args }) => {
|
|
697
|
+
if ("subscription" in args) {
|
|
698
|
+
this.handleDelete(args.subscription);
|
|
699
|
+
} else if ("subscriptionId" in args) {
|
|
700
|
+
this.handleDeleteById(args.subscriptionId);
|
|
1037
701
|
}
|
|
1038
702
|
});
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
703
|
+
__privateGet(this, _emitter3).on("subscription.preference.update.pending", ({ data }) => {
|
|
704
|
+
if (data) {
|
|
705
|
+
this.handlePreferenceUpdate(data);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
__privateGet(this, _emitter3).on("subscription.preference.update.resolved", ({ data }) => {
|
|
709
|
+
if (data) {
|
|
710
|
+
this.handlePreferenceUpdate(data);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
__privateGet(this, _emitter3).on("subscription.preferences.bulk_update.resolved", ({ data }) => {
|
|
714
|
+
if (data && data.length > 0) {
|
|
715
|
+
this.handleBulkPreferenceUpdate(data);
|
|
1046
716
|
}
|
|
1047
717
|
});
|
|
1048
718
|
}
|
|
1049
|
-
|
|
1050
|
-
return
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
719
|
+
has(args) {
|
|
720
|
+
return __privateGet(this, _cache4).get(getListCacheKey(args)) !== void 0;
|
|
721
|
+
}
|
|
722
|
+
set(args, data) {
|
|
723
|
+
__privateGet(this, _cache4).set(getListCacheKey(args), data);
|
|
724
|
+
for (const subscription of data) {
|
|
725
|
+
__privateGet(this, _itemCache).set(
|
|
726
|
+
getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }),
|
|
727
|
+
subscription
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
setOne(args, data) {
|
|
732
|
+
__privateGet(this, _itemCache).set(getItemCacheKey(args), data);
|
|
733
|
+
}
|
|
734
|
+
getAll(args) {
|
|
735
|
+
return __privateGet(this, _cache4).get(getListCacheKey(args));
|
|
736
|
+
}
|
|
737
|
+
get(args) {
|
|
738
|
+
return __privateGet(this, _itemCache).get(getItemCacheKey(args));
|
|
739
|
+
}
|
|
740
|
+
invalidate(args) {
|
|
741
|
+
const listKey = getListCacheKey({ topicKey: args.topicKey });
|
|
742
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
743
|
+
if (subscriptions) {
|
|
744
|
+
for (const subscription of subscriptions) {
|
|
745
|
+
__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
__privateGet(this, _cache4).remove(listKey);
|
|
749
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
750
|
+
for (const key of allItemKeys) {
|
|
751
|
+
if (key.startsWith(`item:${args.topicKey}:`)) {
|
|
752
|
+
__privateGet(this, _itemCache).remove(key);
|
|
1055
753
|
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
clearAll() {
|
|
757
|
+
__privateGet(this, _cache4).clear();
|
|
758
|
+
__privateGet(this, _itemCache).clear();
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
_emitter3 = new WeakMap();
|
|
762
|
+
_cache4 = new WeakMap();
|
|
763
|
+
_useCache3 = new WeakMap();
|
|
764
|
+
_itemCache = new WeakMap();
|
|
765
|
+
_inboxService3 = new WeakMap();
|
|
766
|
+
|
|
767
|
+
// src/subscriptions/subscriptions.ts
|
|
768
|
+
var _useCache4, _subscriber;
|
|
769
|
+
var Subscriptions = class extends BaseModule {
|
|
770
|
+
constructor({
|
|
771
|
+
useCache,
|
|
772
|
+
inboxServiceInstance,
|
|
773
|
+
eventEmitterInstance,
|
|
774
|
+
subscriber
|
|
775
|
+
}) {
|
|
776
|
+
super({
|
|
777
|
+
eventEmitterInstance,
|
|
778
|
+
inboxServiceInstance
|
|
1056
779
|
});
|
|
780
|
+
__privateAdd(this, _useCache4);
|
|
781
|
+
__privateAdd(this, _subscriber);
|
|
782
|
+
this.cache = new SubscriptionsCache({
|
|
783
|
+
emitterInstance: this._emitter,
|
|
784
|
+
inboxServiceInstance: this._inboxService,
|
|
785
|
+
useCache
|
|
786
|
+
});
|
|
787
|
+
__privateSet(this, _useCache4, useCache);
|
|
788
|
+
__privateSet(this, _subscriber, subscriber);
|
|
1057
789
|
}
|
|
1058
|
-
|
|
1059
|
-
return
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
790
|
+
list(args, options) {
|
|
791
|
+
return __async(this, null, function* () {
|
|
792
|
+
return this.callWithSession(
|
|
793
|
+
() => {
|
|
794
|
+
var _a;
|
|
795
|
+
return listSubscriptions({
|
|
796
|
+
emitter: this._emitter,
|
|
797
|
+
apiService: this._inboxService,
|
|
798
|
+
cache: this.cache,
|
|
799
|
+
options: __spreadProps(__spreadValues({}, options), {
|
|
800
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
|
|
801
|
+
}),
|
|
802
|
+
args
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
get(args, options) {
|
|
809
|
+
return __async(this, null, function* () {
|
|
810
|
+
return this.callWithSession(
|
|
811
|
+
() => {
|
|
812
|
+
var _a, _b;
|
|
813
|
+
return getSubscription({
|
|
814
|
+
emitter: this._emitter,
|
|
815
|
+
apiService: this._inboxService,
|
|
816
|
+
cache: this.cache,
|
|
817
|
+
options: __spreadProps(__spreadValues({}, options), {
|
|
818
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
|
|
819
|
+
}),
|
|
820
|
+
args: __spreadProps(__spreadValues({}, args), {
|
|
821
|
+
identifier: (_b = args.identifier) != null ? _b : buildSubscriptionIdentifier({ topicKey: args.topicKey, subscriberId: __privateGet(this, _subscriber).subscriberId })
|
|
822
|
+
})
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
create(args) {
|
|
829
|
+
return __async(this, null, function* () {
|
|
830
|
+
return this.callWithSession(
|
|
831
|
+
() => createSubscription({
|
|
832
|
+
emitter: this._emitter,
|
|
833
|
+
apiService: this._inboxService,
|
|
834
|
+
cache: this.cache,
|
|
835
|
+
useCache: __privateGet(this, _useCache4),
|
|
836
|
+
args
|
|
837
|
+
})
|
|
838
|
+
);
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
update(args) {
|
|
842
|
+
return __async(this, null, function* () {
|
|
843
|
+
return this.callWithSession(
|
|
844
|
+
() => updateSubscription({
|
|
845
|
+
emitter: this._emitter,
|
|
846
|
+
apiService: this._inboxService,
|
|
847
|
+
cache: this.cache,
|
|
848
|
+
useCache: __privateGet(this, _useCache4),
|
|
849
|
+
args
|
|
850
|
+
})
|
|
851
|
+
);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
delete(args) {
|
|
855
|
+
return __async(this, null, function* () {
|
|
856
|
+
return this.callWithSession(
|
|
857
|
+
() => deleteSubscription({
|
|
858
|
+
emitter: this._emitter,
|
|
859
|
+
apiService: this._inboxService,
|
|
860
|
+
args
|
|
861
|
+
})
|
|
862
|
+
);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
_useCache4 = new WeakMap();
|
|
867
|
+
_subscriber = new WeakMap();
|
|
868
|
+
|
|
869
|
+
// src/api/http-client.ts
|
|
870
|
+
var DEFAULT_API_VERSION = "v1";
|
|
871
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.11.2-nightly.20251224.eb609546a3"}`;
|
|
872
|
+
var HttpClient = class {
|
|
873
|
+
constructor(options = {}) {
|
|
874
|
+
// Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
|
|
875
|
+
this.DEFAULT_BACKEND_URL = typeof window !== "undefined" && window.NOVU_LOCAL_BACKEND_URL || "https://api.novu.co";
|
|
876
|
+
const {
|
|
877
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
878
|
+
apiUrl = this.DEFAULT_BACKEND_URL,
|
|
879
|
+
userAgent = DEFAULT_USER_AGENT,
|
|
880
|
+
headers = {}
|
|
881
|
+
} = options || {};
|
|
882
|
+
this.apiVersion = apiVersion;
|
|
883
|
+
this.apiUrl = `${apiUrl}/${apiVersion}`;
|
|
884
|
+
this.headers = __spreadValues({
|
|
885
|
+
"Novu-API-Version": "2024-06-26",
|
|
886
|
+
"Content-Type": "application/json",
|
|
887
|
+
"User-Agent": userAgent
|
|
888
|
+
}, headers);
|
|
889
|
+
}
|
|
890
|
+
setAuthorizationToken(token) {
|
|
891
|
+
this.headers.Authorization = `Bearer ${token}`;
|
|
892
|
+
}
|
|
893
|
+
setKeylessHeader(identifier) {
|
|
894
|
+
var _a;
|
|
895
|
+
const keylessAppIdentifier = identifier || typeof window !== "undefined" && ((_a = window.localStorage) == null ? void 0 : _a.getItem("novu_keyless_application_identifier"));
|
|
896
|
+
if (!keylessAppIdentifier || !keylessAppIdentifier.startsWith("pk_keyless_")) {
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
this.headers["Novu-Application-Identifier"] = keylessAppIdentifier;
|
|
900
|
+
}
|
|
901
|
+
setHeaders(headers) {
|
|
902
|
+
this.headers = __spreadValues(__spreadValues({}, this.headers), headers);
|
|
903
|
+
}
|
|
904
|
+
get(path, searchParams, unwrapEnvelope = true) {
|
|
905
|
+
return __async(this, null, function* () {
|
|
906
|
+
return this.doFetch({
|
|
907
|
+
path,
|
|
908
|
+
searchParams,
|
|
909
|
+
options: {
|
|
910
|
+
method: "GET"
|
|
911
|
+
},
|
|
912
|
+
unwrapEnvelope
|
|
913
|
+
});
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
post(path, body, options) {
|
|
917
|
+
return __async(this, null, function* () {
|
|
918
|
+
return this.doFetch({
|
|
919
|
+
path,
|
|
920
|
+
options: {
|
|
921
|
+
method: "POST",
|
|
922
|
+
body,
|
|
923
|
+
headers: options == null ? void 0 : options.headers
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
patch(path, body) {
|
|
929
|
+
return __async(this, null, function* () {
|
|
930
|
+
return this.doFetch({
|
|
931
|
+
path,
|
|
932
|
+
options: {
|
|
933
|
+
method: "PATCH",
|
|
934
|
+
body
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
delete(path, body) {
|
|
940
|
+
return __async(this, null, function* () {
|
|
941
|
+
return this.doFetch({
|
|
942
|
+
path,
|
|
943
|
+
options: {
|
|
944
|
+
method: "DELETE",
|
|
945
|
+
body
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
doFetch(_0) {
|
|
951
|
+
return __async(this, arguments, function* ({
|
|
952
|
+
path,
|
|
953
|
+
searchParams,
|
|
954
|
+
options,
|
|
955
|
+
unwrapEnvelope = true
|
|
956
|
+
}) {
|
|
957
|
+
const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
|
|
958
|
+
const reqInit = {
|
|
959
|
+
method: (options == null ? void 0 : options.method) || "GET",
|
|
960
|
+
headers: __spreadValues(__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
|
|
961
|
+
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
962
|
+
};
|
|
963
|
+
const response = yield fetch(fullUrl, reqInit);
|
|
964
|
+
if (!response.ok) {
|
|
965
|
+
const errorData = yield response.json();
|
|
966
|
+
throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
|
|
967
|
+
}
|
|
968
|
+
if (response.status === 204) {
|
|
969
|
+
return void 0;
|
|
970
|
+
}
|
|
971
|
+
const res = yield response.json();
|
|
972
|
+
return unwrapEnvelope ? res.data : res;
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
function combineUrl(...args) {
|
|
977
|
+
return args.reduce((acc, part) => {
|
|
978
|
+
if (part) {
|
|
979
|
+
acc.push(part.replace(new RegExp("(?<!https?:)\\/+", "g"), "/").replace(/^\/+|\/+$/g, ""));
|
|
980
|
+
}
|
|
981
|
+
return acc;
|
|
982
|
+
}, []).join("/").replace(/\/\?/, "?");
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// src/api/inbox-service.ts
|
|
986
|
+
var INBOX_ROUTE = "/inbox";
|
|
987
|
+
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
988
|
+
var _httpClient;
|
|
989
|
+
var InboxService = class {
|
|
990
|
+
constructor(options = {}) {
|
|
991
|
+
this.isSessionInitialized = false;
|
|
992
|
+
__privateAdd(this, _httpClient);
|
|
993
|
+
__privateSet(this, _httpClient, new HttpClient(options));
|
|
994
|
+
}
|
|
995
|
+
initializeSession(_0) {
|
|
996
|
+
return __async(this, arguments, function* ({
|
|
997
|
+
applicationIdentifier,
|
|
998
|
+
subscriberHash,
|
|
999
|
+
contextHash,
|
|
1000
|
+
subscriber,
|
|
1001
|
+
defaultSchedule,
|
|
1002
|
+
context
|
|
1003
|
+
}) {
|
|
1004
|
+
const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
1005
|
+
applicationIdentifier,
|
|
1006
|
+
subscriberHash,
|
|
1007
|
+
contextHash,
|
|
1008
|
+
subscriber,
|
|
1009
|
+
defaultSchedule,
|
|
1010
|
+
context
|
|
1011
|
+
});
|
|
1012
|
+
__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
1013
|
+
__privateGet(this, _httpClient).setKeylessHeader(response.applicationIdentifier);
|
|
1014
|
+
this.isSessionInitialized = true;
|
|
1015
|
+
return response;
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
fetchNotifications({
|
|
1019
|
+
after,
|
|
1020
|
+
archived,
|
|
1021
|
+
limit = 10,
|
|
1022
|
+
offset,
|
|
1023
|
+
read: read2,
|
|
1024
|
+
tags,
|
|
1025
|
+
snoozed,
|
|
1026
|
+
seen: seen2,
|
|
1027
|
+
data,
|
|
1028
|
+
severity
|
|
1029
|
+
}) {
|
|
1030
|
+
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
1031
|
+
if (after) {
|
|
1032
|
+
searchParams.append("after", after);
|
|
1033
|
+
}
|
|
1034
|
+
if (offset) {
|
|
1035
|
+
searchParams.append("offset", `${offset}`);
|
|
1036
|
+
}
|
|
1037
|
+
if (tags) {
|
|
1038
|
+
for (const tag of tags) {
|
|
1039
|
+
searchParams.append("tags[]", tag);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
if (read2 !== void 0) {
|
|
1043
|
+
searchParams.append("read", `${read2}`);
|
|
1044
|
+
}
|
|
1045
|
+
if (archived !== void 0) {
|
|
1046
|
+
searchParams.append("archived", `${archived}`);
|
|
1047
|
+
}
|
|
1048
|
+
if (snoozed !== void 0) {
|
|
1049
|
+
searchParams.append("snoozed", `${snoozed}`);
|
|
1050
|
+
}
|
|
1051
|
+
if (seen2 !== void 0) {
|
|
1052
|
+
searchParams.append("seen", `${seen2}`);
|
|
1053
|
+
}
|
|
1054
|
+
if (data !== void 0) {
|
|
1055
|
+
searchParams.append("data", JSON.stringify(data));
|
|
1056
|
+
}
|
|
1057
|
+
if (severity && Array.isArray(severity)) {
|
|
1058
|
+
for (const el of severity) {
|
|
1059
|
+
searchParams.append("severity[]", el);
|
|
1060
|
+
}
|
|
1061
|
+
} else if (severity) {
|
|
1062
|
+
searchParams.append("severity", severity);
|
|
1063
|
+
}
|
|
1064
|
+
return __privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
|
|
1065
|
+
}
|
|
1066
|
+
count({
|
|
1067
|
+
filters
|
|
1068
|
+
}) {
|
|
1069
|
+
return __privateGet(this, _httpClient).get(
|
|
1070
|
+
`${INBOX_NOTIFICATIONS_ROUTE}/count`,
|
|
1071
|
+
new URLSearchParams({
|
|
1072
|
+
filters: JSON.stringify(filters)
|
|
1073
|
+
}),
|
|
1074
|
+
false
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
read(notificationId) {
|
|
1078
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
1079
|
+
}
|
|
1080
|
+
unread(notificationId) {
|
|
1081
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
1082
|
+
}
|
|
1083
|
+
archive(notificationId) {
|
|
1084
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
1085
|
+
}
|
|
1086
|
+
unarchive(notificationId) {
|
|
1087
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
1088
|
+
}
|
|
1089
|
+
snooze(notificationId, snoozeUntil) {
|
|
1090
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/snooze`, { snoozeUntil });
|
|
1091
|
+
}
|
|
1092
|
+
unsnooze(notificationId) {
|
|
1093
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unsnooze`);
|
|
1094
|
+
}
|
|
1095
|
+
readAll({ tags, data }) {
|
|
1096
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
1097
|
+
tags,
|
|
1098
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
archiveAll({ tags, data }) {
|
|
1102
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
1103
|
+
tags,
|
|
1104
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
archiveAllRead({ tags, data }) {
|
|
1108
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
1109
|
+
tags,
|
|
1110
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
delete(notificationId) {
|
|
1114
|
+
return __privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
|
|
1115
|
+
}
|
|
1116
|
+
deleteAll({ tags, data }) {
|
|
1117
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
|
|
1118
|
+
tags,
|
|
1119
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
markAsSeen({
|
|
1123
|
+
notificationIds,
|
|
1124
|
+
tags,
|
|
1125
|
+
data
|
|
1126
|
+
}) {
|
|
1127
|
+
return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/seen`, {
|
|
1128
|
+
notificationIds,
|
|
1129
|
+
tags,
|
|
1130
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
seen(notificationId) {
|
|
1134
|
+
return this.markAsSeen({ notificationIds: [notificationId] });
|
|
1135
|
+
}
|
|
1136
|
+
completeAction({
|
|
1137
|
+
actionType,
|
|
1138
|
+
notificationId
|
|
1139
|
+
}) {
|
|
1140
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
1141
|
+
actionType
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
revertAction({
|
|
1145
|
+
actionType,
|
|
1146
|
+
notificationId
|
|
1147
|
+
}) {
|
|
1148
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
1149
|
+
actionType
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
fetchPreferences({
|
|
1153
|
+
tags,
|
|
1154
|
+
severity,
|
|
1155
|
+
criticality
|
|
1156
|
+
}) {
|
|
1157
|
+
const queryParams = new URLSearchParams();
|
|
1158
|
+
if (tags) {
|
|
1159
|
+
for (const tag of tags) {
|
|
1160
|
+
queryParams.append("tags[]", tag);
|
|
1064
1161
|
}
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
emitter: __privateGet(this, _emitter),
|
|
1070
|
-
apiService: __privateGet(this, _inboxService),
|
|
1071
|
-
args: {
|
|
1072
|
-
notification: this,
|
|
1073
|
-
snoozeUntil
|
|
1162
|
+
}
|
|
1163
|
+
if (severity && Array.isArray(severity)) {
|
|
1164
|
+
for (const el of severity) {
|
|
1165
|
+
queryParams.append("severity[]", el);
|
|
1074
1166
|
}
|
|
1075
|
-
})
|
|
1167
|
+
} else if (severity) {
|
|
1168
|
+
queryParams.append("severity", severity);
|
|
1169
|
+
}
|
|
1170
|
+
if (criticality) {
|
|
1171
|
+
queryParams.append("criticality", criticality);
|
|
1172
|
+
}
|
|
1173
|
+
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
1174
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
1076
1175
|
}
|
|
1077
|
-
|
|
1078
|
-
return
|
|
1079
|
-
emitter: __privateGet(this, _emitter),
|
|
1080
|
-
apiService: __privateGet(this, _inboxService),
|
|
1081
|
-
args: { notification: this }
|
|
1082
|
-
});
|
|
1176
|
+
bulkUpdatePreferences(preferences) {
|
|
1177
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
1083
1178
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
throw new Error("Primary action is not available");
|
|
1087
|
-
}
|
|
1088
|
-
return completeAction({
|
|
1089
|
-
emitter: __privateGet(this, _emitter),
|
|
1090
|
-
apiService: __privateGet(this, _inboxService),
|
|
1091
|
-
args: {
|
|
1092
|
-
notification: this
|
|
1093
|
-
},
|
|
1094
|
-
actionType: "primary" /* PRIMARY */
|
|
1095
|
-
});
|
|
1179
|
+
updateGlobalPreferences(preferences) {
|
|
1180
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
|
|
1096
1181
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
return
|
|
1102
|
-
emitter: __privateGet(this, _emitter),
|
|
1103
|
-
apiService: __privateGet(this, _inboxService),
|
|
1104
|
-
args: {
|
|
1105
|
-
notification: this
|
|
1106
|
-
},
|
|
1107
|
-
actionType: "secondary" /* SECONDARY */
|
|
1108
|
-
});
|
|
1182
|
+
updateWorkflowPreferences({
|
|
1183
|
+
workflowId,
|
|
1184
|
+
channels
|
|
1185
|
+
}) {
|
|
1186
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
|
|
1109
1187
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
throw new Error("Primary action is not available");
|
|
1113
|
-
}
|
|
1114
|
-
return revertAction({
|
|
1115
|
-
emitter: __privateGet(this, _emitter),
|
|
1116
|
-
apiService: __privateGet(this, _inboxService),
|
|
1117
|
-
args: {
|
|
1118
|
-
notification: this
|
|
1119
|
-
},
|
|
1120
|
-
actionType: "primary" /* PRIMARY */
|
|
1121
|
-
});
|
|
1188
|
+
fetchGlobalPreferences() {
|
|
1189
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
|
|
1122
1190
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
emitter: __privateGet(this, _emitter),
|
|
1129
|
-
apiService: __privateGet(this, _inboxService),
|
|
1130
|
-
args: {
|
|
1131
|
-
notification: this
|
|
1191
|
+
triggerHelloWorldEvent() {
|
|
1192
|
+
const payload = {
|
|
1193
|
+
name: "hello-world",
|
|
1194
|
+
to: {
|
|
1195
|
+
subscriberId: "keyless-subscriber-id"
|
|
1132
1196
|
},
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1197
|
+
payload: {
|
|
1198
|
+
subject: "Novu Keyless Environment",
|
|
1199
|
+
body: "You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",
|
|
1200
|
+
primaryActionText: "Obtain API Key",
|
|
1201
|
+
primaryActionUrl: "https://go.novu.co/keyless",
|
|
1202
|
+
secondaryActionText: "Explore Documentation",
|
|
1203
|
+
secondaryActionUrl: "https://go.novu.co/keyless-docs"
|
|
1204
|
+
}
|
|
1140
1205
|
};
|
|
1206
|
+
return __privateGet(this, _httpClient).post("/inbox/events", payload);
|
|
1141
1207
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1208
|
+
fetchSubscriptions(topicKey) {
|
|
1209
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`);
|
|
1210
|
+
}
|
|
1211
|
+
getSubscription(topicKey, identifier, workflowIds, tags) {
|
|
1212
|
+
const searchParams = new URLSearchParams();
|
|
1213
|
+
if (workflowIds == null ? void 0 : workflowIds.length)
|
|
1214
|
+
for (const workflowIdentifier of workflowIds) searchParams.append("workflowIds", workflowIdentifier);
|
|
1215
|
+
if (tags == null ? void 0 : tags.length) for (const tag of tags) searchParams.append("tags", tag);
|
|
1216
|
+
const query = searchParams.size ? `?${searchParams.toString()}` : "";
|
|
1217
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${identifier}${query}`);
|
|
1218
|
+
}
|
|
1219
|
+
createSubscription({
|
|
1220
|
+
identifier,
|
|
1221
|
+
name,
|
|
1222
|
+
topicKey,
|
|
1223
|
+
topicName,
|
|
1224
|
+
preferences
|
|
1225
|
+
}) {
|
|
1226
|
+
return __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`, __spreadValues(__spreadValues({
|
|
1227
|
+
identifier,
|
|
1228
|
+
name
|
|
1229
|
+
}, topicName && { topic: { name: topicName } }), preferences !== void 0 && { preferences }));
|
|
1230
|
+
}
|
|
1231
|
+
updateSubscription({
|
|
1232
|
+
topicKey,
|
|
1233
|
+
subscriptionId,
|
|
1234
|
+
name,
|
|
1235
|
+
preferences
|
|
1236
|
+
}) {
|
|
1237
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`, __spreadValues({
|
|
1238
|
+
name
|
|
1239
|
+
}, preferences !== void 0 && { preferences }));
|
|
1148
1240
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1241
|
+
updateSubscriptionPreference({
|
|
1242
|
+
subscriptionId,
|
|
1243
|
+
workflowId,
|
|
1244
|
+
enabled,
|
|
1245
|
+
condition,
|
|
1246
|
+
email,
|
|
1247
|
+
sms,
|
|
1248
|
+
in_app,
|
|
1249
|
+
chat,
|
|
1250
|
+
push
|
|
1159
1251
|
}) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
resolve(yield fn());
|
|
1169
|
-
}));
|
|
1170
|
-
__privateSet(this, _callsQueue, []);
|
|
1171
|
-
} else if (error) {
|
|
1172
|
-
this.onSessionError(error);
|
|
1173
|
-
__privateSet(this, _sessionError, error);
|
|
1174
|
-
__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
1175
|
-
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
1176
|
-
});
|
|
1177
|
-
__privateSet(this, _callsQueue, []);
|
|
1178
|
-
}
|
|
1252
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/subscriptions/${subscriptionId}/preferences/${workflowId}`, {
|
|
1253
|
+
enabled,
|
|
1254
|
+
condition,
|
|
1255
|
+
email,
|
|
1256
|
+
sms,
|
|
1257
|
+
in_app,
|
|
1258
|
+
chat,
|
|
1259
|
+
push
|
|
1179
1260
|
});
|
|
1180
1261
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
onSessionError(_) {
|
|
1262
|
+
bulkUpdateSubscriptionPreferences(preferences) {
|
|
1263
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
1184
1264
|
}
|
|
1185
|
-
|
|
1186
|
-
return
|
|
1187
|
-
if (this._inboxService.isSessionInitialized) {
|
|
1188
|
-
return fn();
|
|
1189
|
-
}
|
|
1190
|
-
if (__privateGet(this, _sessionError)) {
|
|
1191
|
-
return Promise.resolve({
|
|
1192
|
-
error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
return new Promise((resolve, reject) => {
|
|
1196
|
-
__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
1197
|
-
});
|
|
1198
|
-
});
|
|
1265
|
+
deleteSubscription({ topicKey, subscriptionId }) {
|
|
1266
|
+
return __privateGet(this, _httpClient).delete(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`);
|
|
1199
1267
|
}
|
|
1200
1268
|
};
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
// src/cache/in-memory-cache.ts
|
|
1205
|
-
var _cache;
|
|
1206
|
-
var InMemoryCache = class {
|
|
1269
|
+
_httpClient = new WeakMap();
|
|
1270
|
+
var _mittEmitter;
|
|
1271
|
+
var NovuEventEmitter = class {
|
|
1207
1272
|
constructor() {
|
|
1208
|
-
__privateAdd(this,
|
|
1209
|
-
__privateSet(this,
|
|
1210
|
-
}
|
|
1211
|
-
get(key) {
|
|
1212
|
-
return __privateGet(this, _cache).get(key);
|
|
1213
|
-
}
|
|
1214
|
-
getValues() {
|
|
1215
|
-
return Array.from(__privateGet(this, _cache).values());
|
|
1216
|
-
}
|
|
1217
|
-
entries() {
|
|
1218
|
-
return Array.from(__privateGet(this, _cache).entries());
|
|
1219
|
-
}
|
|
1220
|
-
keys() {
|
|
1221
|
-
return Array.from(__privateGet(this, _cache).keys());
|
|
1273
|
+
__privateAdd(this, _mittEmitter);
|
|
1274
|
+
__privateSet(this, _mittEmitter, mitt());
|
|
1222
1275
|
}
|
|
1223
|
-
|
|
1224
|
-
__privateGet(this,
|
|
1276
|
+
on(eventName, listener) {
|
|
1277
|
+
__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
1278
|
+
return () => {
|
|
1279
|
+
this.off(eventName, listener);
|
|
1280
|
+
};
|
|
1225
1281
|
}
|
|
1226
|
-
|
|
1227
|
-
__privateGet(this,
|
|
1282
|
+
off(eventName, listener) {
|
|
1283
|
+
__privateGet(this, _mittEmitter).off(eventName, listener);
|
|
1228
1284
|
}
|
|
1229
|
-
|
|
1230
|
-
__privateGet(this,
|
|
1285
|
+
emit(type, event) {
|
|
1286
|
+
__privateGet(this, _mittEmitter).emit(type, event);
|
|
1231
1287
|
}
|
|
1232
1288
|
};
|
|
1233
|
-
|
|
1289
|
+
_mittEmitter = new WeakMap();
|
|
1234
1290
|
|
|
1235
1291
|
// src/cache/notifications-cache.ts
|
|
1236
1292
|
var excludeEmpty = ({
|
|
@@ -1298,16 +1354,17 @@ var removeEvents = [
|
|
|
1298
1354
|
"notifications.archive_all_read.pending",
|
|
1299
1355
|
"notifications.delete_all.pending"
|
|
1300
1356
|
];
|
|
1301
|
-
var
|
|
1357
|
+
var _emitter4, _inboxService4, _cache5;
|
|
1302
1358
|
var NotificationsCache = class {
|
|
1303
|
-
constructor({ emitter }) {
|
|
1304
|
-
__privateAdd(this,
|
|
1359
|
+
constructor({ emitter, inboxService }) {
|
|
1360
|
+
__privateAdd(this, _emitter4);
|
|
1361
|
+
__privateAdd(this, _inboxService4);
|
|
1305
1362
|
/**
|
|
1306
1363
|
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
1307
1364
|
*/
|
|
1308
|
-
__privateAdd(this,
|
|
1365
|
+
__privateAdd(this, _cache5);
|
|
1309
1366
|
this.updateNotification = (key, data) => {
|
|
1310
|
-
const notificationsResponse = __privateGet(this,
|
|
1367
|
+
const notificationsResponse = __privateGet(this, _cache5).get(key);
|
|
1311
1368
|
if (!notificationsResponse) {
|
|
1312
1369
|
return false;
|
|
1313
1370
|
}
|
|
@@ -1317,11 +1374,11 @@ var NotificationsCache = class {
|
|
|
1317
1374
|
}
|
|
1318
1375
|
const updatedNotifications = [...notificationsResponse.notifications];
|
|
1319
1376
|
updatedNotifications[index] = data;
|
|
1320
|
-
__privateGet(this,
|
|
1377
|
+
__privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
|
|
1321
1378
|
return true;
|
|
1322
1379
|
};
|
|
1323
1380
|
this.removeNotification = (key, data) => {
|
|
1324
|
-
const notificationsResponse = __privateGet(this,
|
|
1381
|
+
const notificationsResponse = __privateGet(this, _cache5).get(key);
|
|
1325
1382
|
if (!notificationsResponse) {
|
|
1326
1383
|
return false;
|
|
1327
1384
|
}
|
|
@@ -1331,7 +1388,7 @@ var NotificationsCache = class {
|
|
|
1331
1388
|
}
|
|
1332
1389
|
const newNotifications = [...notificationsResponse.notifications];
|
|
1333
1390
|
newNotifications.splice(index, 1);
|
|
1334
|
-
__privateGet(this,
|
|
1391
|
+
__privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), {
|
|
1335
1392
|
notifications: newNotifications
|
|
1336
1393
|
}));
|
|
1337
1394
|
return true;
|
|
@@ -1350,8 +1407,8 @@ var NotificationsCache = class {
|
|
|
1350
1407
|
notifications = [args.notification];
|
|
1351
1408
|
} else if ("notificationId" in args && args.notificationId) {
|
|
1352
1409
|
const foundNotifications = [];
|
|
1353
|
-
__privateGet(this,
|
|
1354
|
-
const cachedResponse = __privateGet(this,
|
|
1410
|
+
__privateGet(this, _cache5).keys().forEach((key) => {
|
|
1411
|
+
const cachedResponse = __privateGet(this, _cache5).get(key);
|
|
1355
1412
|
if (cachedResponse) {
|
|
1356
1413
|
const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
|
|
1357
1414
|
if (found) {
|
|
@@ -1366,7 +1423,7 @@ var NotificationsCache = class {
|
|
|
1366
1423
|
return;
|
|
1367
1424
|
}
|
|
1368
1425
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1369
|
-
__privateGet(this,
|
|
1426
|
+
__privateGet(this, _cache5).keys().forEach((key) => {
|
|
1370
1427
|
notifications.forEach((notification) => {
|
|
1371
1428
|
let isNotificationFound = false;
|
|
1372
1429
|
if (remove) {
|
|
@@ -1381,26 +1438,27 @@ var NotificationsCache = class {
|
|
|
1381
1438
|
});
|
|
1382
1439
|
uniqueFilterKeys.forEach((key) => {
|
|
1383
1440
|
const notificationsResponse = this.getAggregated(getFilter(key));
|
|
1384
|
-
__privateGet(this,
|
|
1441
|
+
__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
1385
1442
|
data: notificationsResponse
|
|
1386
1443
|
});
|
|
1387
1444
|
});
|
|
1388
1445
|
};
|
|
1389
|
-
__privateSet(this,
|
|
1446
|
+
__privateSet(this, _emitter4, emitter);
|
|
1447
|
+
__privateSet(this, _inboxService4, inboxService);
|
|
1390
1448
|
updateEvents.forEach((event) => {
|
|
1391
|
-
__privateGet(this,
|
|
1449
|
+
__privateGet(this, _emitter4).on(event, this.handleNotificationEvent());
|
|
1392
1450
|
});
|
|
1393
1451
|
removeEvents.forEach((event) => {
|
|
1394
|
-
__privateGet(this,
|
|
1452
|
+
__privateGet(this, _emitter4).on(event, this.handleNotificationEvent({ remove: true }));
|
|
1395
1453
|
});
|
|
1396
|
-
__privateSet(this,
|
|
1454
|
+
__privateSet(this, _cache5, new InMemoryCache());
|
|
1397
1455
|
}
|
|
1398
1456
|
getAggregated(filter) {
|
|
1399
|
-
const cacheKeys = __privateGet(this,
|
|
1457
|
+
const cacheKeys = __privateGet(this, _cache5).keys().filter((key) => {
|
|
1400
1458
|
const parsedFilter = getFilter(key);
|
|
1401
1459
|
return isSameFilter(parsedFilter, filter);
|
|
1402
1460
|
});
|
|
1403
|
-
return cacheKeys.map((key) => __privateGet(this,
|
|
1461
|
+
return cacheKeys.map((key) => __privateGet(this, _cache5).get(key)).reduce(
|
|
1404
1462
|
(acc, el) => {
|
|
1405
1463
|
if (!el) {
|
|
1406
1464
|
return acc;
|
|
@@ -1414,16 +1472,35 @@ var NotificationsCache = class {
|
|
|
1414
1472
|
{ hasMore: false, filter: {}, notifications: [] }
|
|
1415
1473
|
);
|
|
1416
1474
|
}
|
|
1475
|
+
get(args) {
|
|
1476
|
+
return __privateGet(this, _cache5).get(getCacheKey(args));
|
|
1477
|
+
}
|
|
1417
1478
|
has(args) {
|
|
1418
|
-
return __privateGet(this,
|
|
1479
|
+
return __privateGet(this, _cache5).get(getCacheKey(args)) !== void 0;
|
|
1419
1480
|
}
|
|
1420
1481
|
set(args, data) {
|
|
1421
|
-
__privateGet(this,
|
|
1482
|
+
__privateGet(this, _cache5).set(getCacheKey(args), data);
|
|
1483
|
+
}
|
|
1484
|
+
unshift(args, notification) {
|
|
1485
|
+
const cacheKey = getCacheKey(args);
|
|
1486
|
+
const cachedData = __privateGet(this, _cache5).get(cacheKey) || {
|
|
1487
|
+
hasMore: false,
|
|
1488
|
+
filter: getFilter(cacheKey),
|
|
1489
|
+
notifications: []
|
|
1490
|
+
};
|
|
1491
|
+
const notificationInstance = createNotification({
|
|
1492
|
+
notification: __spreadValues({}, notification),
|
|
1493
|
+
emitter: __privateGet(this, _emitter4),
|
|
1494
|
+
inboxService: __privateGet(this, _inboxService4)
|
|
1495
|
+
});
|
|
1496
|
+
this.update(args, __spreadProps(__spreadValues({}, cachedData), {
|
|
1497
|
+
notifications: [notificationInstance, ...cachedData.notifications]
|
|
1498
|
+
}));
|
|
1422
1499
|
}
|
|
1423
1500
|
update(args, data) {
|
|
1424
1501
|
this.set(args, data);
|
|
1425
1502
|
const notificationsResponse = this.getAggregated(getFilter(getCacheKey(args)));
|
|
1426
|
-
__privateGet(this,
|
|
1503
|
+
__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
1427
1504
|
data: notificationsResponse
|
|
1428
1505
|
});
|
|
1429
1506
|
}
|
|
@@ -1449,12 +1526,12 @@ var NotificationsCache = class {
|
|
|
1449
1526
|
read: read2,
|
|
1450
1527
|
data
|
|
1451
1528
|
}) {
|
|
1452
|
-
const keys = __privateGet(this,
|
|
1529
|
+
const keys = __privateGet(this, _cache5).keys();
|
|
1453
1530
|
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
1454
1531
|
keys.forEach((key) => {
|
|
1455
1532
|
const filter = getFilter(key);
|
|
1456
1533
|
if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
|
|
1457
|
-
const value = __privateGet(this,
|
|
1534
|
+
const value = __privateGet(this, _cache5).get(key);
|
|
1458
1535
|
if (!value) {
|
|
1459
1536
|
return;
|
|
1460
1537
|
}
|
|
@@ -1466,22 +1543,23 @@ var NotificationsCache = class {
|
|
|
1466
1543
|
return Array.from(uniqueNotifications.values());
|
|
1467
1544
|
}
|
|
1468
1545
|
clear(filter) {
|
|
1469
|
-
const keys = __privateGet(this,
|
|
1546
|
+
const keys = __privateGet(this, _cache5).keys();
|
|
1470
1547
|
keys.forEach((key) => {
|
|
1471
1548
|
if (isSameFilter(getFilter(key), filter)) {
|
|
1472
|
-
__privateGet(this,
|
|
1549
|
+
__privateGet(this, _cache5).remove(key);
|
|
1473
1550
|
}
|
|
1474
1551
|
});
|
|
1475
1552
|
}
|
|
1476
1553
|
clearAll() {
|
|
1477
|
-
__privateGet(this,
|
|
1554
|
+
__privateGet(this, _cache5).clear();
|
|
1478
1555
|
}
|
|
1479
1556
|
};
|
|
1480
|
-
|
|
1481
|
-
|
|
1557
|
+
_emitter4 = new WeakMap();
|
|
1558
|
+
_inboxService4 = new WeakMap();
|
|
1559
|
+
_cache5 = new WeakMap();
|
|
1482
1560
|
|
|
1483
1561
|
// src/notifications/notifications.ts
|
|
1484
|
-
var
|
|
1562
|
+
var _useCache5;
|
|
1485
1563
|
var Notifications = class extends BaseModule {
|
|
1486
1564
|
constructor({
|
|
1487
1565
|
useCache,
|
|
@@ -1492,14 +1570,12 @@ var Notifications = class extends BaseModule {
|
|
|
1492
1570
|
eventEmitterInstance,
|
|
1493
1571
|
inboxServiceInstance
|
|
1494
1572
|
});
|
|
1495
|
-
__privateAdd(this,
|
|
1573
|
+
__privateAdd(this, _useCache5);
|
|
1496
1574
|
this.cache = new NotificationsCache({
|
|
1497
|
-
emitter: eventEmitterInstance
|
|
1575
|
+
emitter: eventEmitterInstance,
|
|
1576
|
+
inboxService: inboxServiceInstance
|
|
1498
1577
|
});
|
|
1499
|
-
__privateSet(this,
|
|
1500
|
-
}
|
|
1501
|
-
get inboxService() {
|
|
1502
|
-
return this._inboxService;
|
|
1578
|
+
__privateSet(this, _useCache5, useCache);
|
|
1503
1579
|
}
|
|
1504
1580
|
list() {
|
|
1505
1581
|
return __async(this, arguments, function* (_a = {}) {
|
|
@@ -1507,7 +1583,7 @@ var Notifications = class extends BaseModule {
|
|
|
1507
1583
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
1508
1584
|
const args = __spreadValues({ limit }, restOptions);
|
|
1509
1585
|
try {
|
|
1510
|
-
const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this,
|
|
1586
|
+
const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this, _useCache5);
|
|
1511
1587
|
let data = shouldUseCache ? this.cache.getAll(args) : void 0;
|
|
1512
1588
|
this._emitter.emit("notifications.list.pending", { args, data });
|
|
1513
1589
|
if (!data) {
|
|
@@ -1819,10 +1895,10 @@ var Notifications = class extends BaseModule {
|
|
|
1819
1895
|
});
|
|
1820
1896
|
}
|
|
1821
1897
|
};
|
|
1822
|
-
|
|
1898
|
+
_useCache5 = new WeakMap();
|
|
1823
1899
|
|
|
1824
1900
|
// src/preferences/schedule.ts
|
|
1825
|
-
var
|
|
1901
|
+
var _emitter5, _apiService, _cache6, _useCache6;
|
|
1826
1902
|
var Schedule = class {
|
|
1827
1903
|
constructor(schedule, {
|
|
1828
1904
|
emitterInstance,
|
|
@@ -1830,14 +1906,14 @@ var Schedule = class {
|
|
|
1830
1906
|
cache,
|
|
1831
1907
|
useCache
|
|
1832
1908
|
}) {
|
|
1833
|
-
__privateAdd(this,
|
|
1909
|
+
__privateAdd(this, _emitter5);
|
|
1834
1910
|
__privateAdd(this, _apiService);
|
|
1835
|
-
__privateAdd(this,
|
|
1836
|
-
__privateAdd(this,
|
|
1837
|
-
__privateSet(this,
|
|
1911
|
+
__privateAdd(this, _cache6);
|
|
1912
|
+
__privateAdd(this, _useCache6);
|
|
1913
|
+
__privateSet(this, _emitter5, emitterInstance);
|
|
1838
1914
|
__privateSet(this, _apiService, inboxServiceInstance);
|
|
1839
|
-
__privateSet(this,
|
|
1840
|
-
__privateSet(this,
|
|
1915
|
+
__privateSet(this, _cache6, cache);
|
|
1916
|
+
__privateSet(this, _useCache6, useCache);
|
|
1841
1917
|
this.isEnabled = schedule.isEnabled;
|
|
1842
1918
|
this.weeklySchedule = schedule.weeklySchedule;
|
|
1843
1919
|
}
|
|
@@ -1846,10 +1922,10 @@ var Schedule = class {
|
|
|
1846
1922
|
var _a;
|
|
1847
1923
|
const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
|
|
1848
1924
|
return updateSchedule({
|
|
1849
|
-
emitter: __privateGet(this,
|
|
1925
|
+
emitter: __privateGet(this, _emitter5),
|
|
1850
1926
|
apiService: __privateGet(this, _apiService),
|
|
1851
|
-
cache: __privateGet(this,
|
|
1852
|
-
useCache: __privateGet(this,
|
|
1927
|
+
cache: __privateGet(this, _cache6),
|
|
1928
|
+
useCache: __privateGet(this, _useCache6),
|
|
1853
1929
|
args: __spreadValues({
|
|
1854
1930
|
isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
|
|
1855
1931
|
}, hasWeeklySchedule && {
|
|
@@ -1859,13 +1935,13 @@ var Schedule = class {
|
|
|
1859
1935
|
});
|
|
1860
1936
|
}
|
|
1861
1937
|
};
|
|
1862
|
-
|
|
1938
|
+
_emitter5 = new WeakMap();
|
|
1863
1939
|
_apiService = new WeakMap();
|
|
1864
|
-
|
|
1865
|
-
|
|
1940
|
+
_cache6 = new WeakMap();
|
|
1941
|
+
_useCache6 = new WeakMap();
|
|
1866
1942
|
|
|
1867
1943
|
// src/preferences/preference.ts
|
|
1868
|
-
var
|
|
1944
|
+
var _emitter6, _apiService2, _cache7, _scheduleCache, _useCache7;
|
|
1869
1945
|
var Preference = class {
|
|
1870
1946
|
constructor(preference, {
|
|
1871
1947
|
emitterInstance,
|
|
@@ -1874,16 +1950,16 @@ var Preference = class {
|
|
|
1874
1950
|
scheduleCache,
|
|
1875
1951
|
useCache
|
|
1876
1952
|
}) {
|
|
1877
|
-
__privateAdd(this,
|
|
1953
|
+
__privateAdd(this, _emitter6);
|
|
1878
1954
|
__privateAdd(this, _apiService2);
|
|
1879
|
-
__privateAdd(this,
|
|
1955
|
+
__privateAdd(this, _cache7);
|
|
1880
1956
|
__privateAdd(this, _scheduleCache);
|
|
1881
|
-
__privateAdd(this,
|
|
1882
|
-
__privateSet(this,
|
|
1957
|
+
__privateAdd(this, _useCache7);
|
|
1958
|
+
__privateSet(this, _emitter6, emitterInstance);
|
|
1883
1959
|
__privateSet(this, _apiService2, inboxServiceInstance);
|
|
1884
|
-
__privateSet(this,
|
|
1960
|
+
__privateSet(this, _cache7, cache);
|
|
1885
1961
|
__privateSet(this, _scheduleCache, scheduleCache);
|
|
1886
|
-
__privateSet(this,
|
|
1962
|
+
__privateSet(this, _useCache7, useCache);
|
|
1887
1963
|
this.level = preference.level;
|
|
1888
1964
|
this.enabled = preference.enabled;
|
|
1889
1965
|
this.channels = preference.channels;
|
|
@@ -1899,11 +1975,11 @@ var Preference = class {
|
|
|
1899
1975
|
}) {
|
|
1900
1976
|
var _a;
|
|
1901
1977
|
return updatePreference({
|
|
1902
|
-
emitter: __privateGet(this,
|
|
1978
|
+
emitter: __privateGet(this, _emitter6),
|
|
1903
1979
|
apiService: __privateGet(this, _apiService2),
|
|
1904
|
-
cache: __privateGet(this,
|
|
1980
|
+
cache: __privateGet(this, _cache7),
|
|
1905
1981
|
scheduleCache: __privateGet(this, _scheduleCache),
|
|
1906
|
-
useCache: __privateGet(this,
|
|
1982
|
+
useCache: __privateGet(this, _useCache7),
|
|
1907
1983
|
args: {
|
|
1908
1984
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1909
1985
|
channels: channels || channelPreferences,
|
|
@@ -1912,11 +1988,11 @@ var Preference = class {
|
|
|
1912
1988
|
});
|
|
1913
1989
|
}
|
|
1914
1990
|
};
|
|
1915
|
-
|
|
1991
|
+
_emitter6 = new WeakMap();
|
|
1916
1992
|
_apiService2 = new WeakMap();
|
|
1917
|
-
|
|
1993
|
+
_cache7 = new WeakMap();
|
|
1918
1994
|
_scheduleCache = new WeakMap();
|
|
1919
|
-
|
|
1995
|
+
_useCache7 = new WeakMap();
|
|
1920
1996
|
|
|
1921
1997
|
// src/preferences/helpers.ts
|
|
1922
1998
|
var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
@@ -2113,7 +2189,7 @@ var updateSchedule = (_0) => __async(void 0, [_0], function* ({
|
|
|
2113
2189
|
});
|
|
2114
2190
|
|
|
2115
2191
|
// src/preferences/preference-schedule.ts
|
|
2116
|
-
var
|
|
2192
|
+
var _useCache8;
|
|
2117
2193
|
var PreferenceSchedule = class extends BaseModule {
|
|
2118
2194
|
constructor({
|
|
2119
2195
|
cache,
|
|
@@ -2125,16 +2201,16 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2125
2201
|
eventEmitterInstance,
|
|
2126
2202
|
inboxServiceInstance
|
|
2127
2203
|
});
|
|
2128
|
-
__privateAdd(this,
|
|
2204
|
+
__privateAdd(this, _useCache8);
|
|
2129
2205
|
this.cache = cache;
|
|
2130
|
-
__privateSet(this,
|
|
2206
|
+
__privateSet(this, _useCache8, useCache);
|
|
2131
2207
|
}
|
|
2132
2208
|
get() {
|
|
2133
2209
|
return __async(this, null, function* () {
|
|
2134
2210
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
2135
2211
|
var _a, _b;
|
|
2136
2212
|
try {
|
|
2137
|
-
let data = __privateGet(this,
|
|
2213
|
+
let data = __privateGet(this, _useCache8) ? this.cache.getAll() : void 0;
|
|
2138
2214
|
this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
|
|
2139
2215
|
if (!data) {
|
|
2140
2216
|
const globalPreference = yield this._inboxService.fetchGlobalPreferences();
|
|
@@ -2147,10 +2223,10 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2147
2223
|
emitterInstance: this._emitter,
|
|
2148
2224
|
inboxServiceInstance: this._inboxService,
|
|
2149
2225
|
cache: this.cache,
|
|
2150
|
-
useCache: __privateGet(this,
|
|
2226
|
+
useCache: __privateGet(this, _useCache8)
|
|
2151
2227
|
}
|
|
2152
2228
|
);
|
|
2153
|
-
if (__privateGet(this,
|
|
2229
|
+
if (__privateGet(this, _useCache8)) {
|
|
2154
2230
|
this.cache.set(data);
|
|
2155
2231
|
data = this.cache.getAll();
|
|
2156
2232
|
}
|
|
@@ -2174,14 +2250,14 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2174
2250
|
emitter: this._emitter,
|
|
2175
2251
|
apiService: this._inboxService,
|
|
2176
2252
|
cache: this.cache,
|
|
2177
|
-
useCache: __privateGet(this,
|
|
2253
|
+
useCache: __privateGet(this, _useCache8),
|
|
2178
2254
|
args
|
|
2179
2255
|
})
|
|
2180
2256
|
);
|
|
2181
2257
|
});
|
|
2182
2258
|
}
|
|
2183
2259
|
};
|
|
2184
|
-
|
|
2260
|
+
_useCache8 = new WeakMap();
|
|
2185
2261
|
|
|
2186
2262
|
// src/cache/preferences-cache.ts
|
|
2187
2263
|
var updateEvents2 = [
|
|
@@ -2204,13 +2280,13 @@ var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).r
|
|
|
2204
2280
|
var getCacheKey2 = ({ tags, severity }) => {
|
|
2205
2281
|
return JSON.stringify(excludeEmpty2({ tags, severity }));
|
|
2206
2282
|
};
|
|
2207
|
-
var
|
|
2283
|
+
var _emitter7, _cache8;
|
|
2208
2284
|
var PreferencesCache = class {
|
|
2209
2285
|
constructor({ emitterInstance }) {
|
|
2210
|
-
__privateAdd(this,
|
|
2211
|
-
__privateAdd(this,
|
|
2286
|
+
__privateAdd(this, _emitter7);
|
|
2287
|
+
__privateAdd(this, _cache8);
|
|
2212
2288
|
this.updatePreference = (key, data) => {
|
|
2213
|
-
const preferences = __privateGet(this,
|
|
2289
|
+
const preferences = __privateGet(this, _cache8).get(key);
|
|
2214
2290
|
if (!preferences) {
|
|
2215
2291
|
return false;
|
|
2216
2292
|
}
|
|
@@ -2225,11 +2301,11 @@ var PreferencesCache = class {
|
|
|
2225
2301
|
}
|
|
2226
2302
|
const updatedPreferences = [...preferences];
|
|
2227
2303
|
updatedPreferences[index] = data;
|
|
2228
|
-
__privateGet(this,
|
|
2304
|
+
__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
2229
2305
|
return true;
|
|
2230
2306
|
};
|
|
2231
2307
|
this.updatePreferenceSchedule = (key, data) => {
|
|
2232
|
-
const preferences = __privateGet(this,
|
|
2308
|
+
const preferences = __privateGet(this, _cache8).get(key);
|
|
2233
2309
|
if (!preferences) {
|
|
2234
2310
|
return false;
|
|
2235
2311
|
}
|
|
@@ -2239,7 +2315,7 @@ var PreferencesCache = class {
|
|
|
2239
2315
|
}
|
|
2240
2316
|
const updatedPreferences = [...preferences];
|
|
2241
2317
|
updatedPreferences[index].schedule = data;
|
|
2242
|
-
__privateGet(this,
|
|
2318
|
+
__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
2243
2319
|
return true;
|
|
2244
2320
|
};
|
|
2245
2321
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -2247,19 +2323,19 @@ var PreferencesCache = class {
|
|
|
2247
2323
|
if (!data) {
|
|
2248
2324
|
return;
|
|
2249
2325
|
}
|
|
2250
|
-
const cacheKeys = __privateGet(this,
|
|
2326
|
+
const cacheKeys = __privateGet(this, _cache8).keys();
|
|
2251
2327
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2252
2328
|
for (const key of cacheKeys) {
|
|
2253
2329
|
const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
|
|
2254
|
-
const updatedPreference = __privateGet(this,
|
|
2330
|
+
const updatedPreference = __privateGet(this, _cache8).get(key);
|
|
2255
2331
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2256
2332
|
continue;
|
|
2257
2333
|
}
|
|
2258
2334
|
uniqueFilterKeys.add(key);
|
|
2259
2335
|
}
|
|
2260
2336
|
for (const key of uniqueFilterKeys) {
|
|
2261
|
-
__privateGet(this,
|
|
2262
|
-
data: (_a = __privateGet(this,
|
|
2337
|
+
__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2338
|
+
data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
2263
2339
|
});
|
|
2264
2340
|
}
|
|
2265
2341
|
};
|
|
@@ -2269,10 +2345,10 @@ var PreferencesCache = class {
|
|
|
2269
2345
|
}
|
|
2270
2346
|
const preferences = Array.isArray(data) ? data : [data];
|
|
2271
2347
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2272
|
-
__privateGet(this,
|
|
2348
|
+
__privateGet(this, _cache8).keys().forEach((key) => {
|
|
2273
2349
|
preferences.forEach((preference) => {
|
|
2274
2350
|
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
2275
|
-
const updatedPreference = __privateGet(this,
|
|
2351
|
+
const updatedPreference = __privateGet(this, _cache8).get(key);
|
|
2276
2352
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2277
2353
|
return;
|
|
2278
2354
|
}
|
|
@@ -2281,37 +2357,37 @@ var PreferencesCache = class {
|
|
|
2281
2357
|
});
|
|
2282
2358
|
uniqueFilterKeys.forEach((key) => {
|
|
2283
2359
|
var _a;
|
|
2284
|
-
__privateGet(this,
|
|
2285
|
-
data: (_a = __privateGet(this,
|
|
2360
|
+
__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2361
|
+
data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
2286
2362
|
});
|
|
2287
2363
|
});
|
|
2288
2364
|
};
|
|
2289
|
-
__privateSet(this,
|
|
2365
|
+
__privateSet(this, _emitter7, emitterInstance);
|
|
2290
2366
|
for (const event of updateEvents2) {
|
|
2291
|
-
__privateGet(this,
|
|
2367
|
+
__privateGet(this, _emitter7).on(event, this.handlePreferenceEvent);
|
|
2292
2368
|
}
|
|
2293
2369
|
for (const event of scheduleUpdateEvents) {
|
|
2294
|
-
__privateGet(this,
|
|
2370
|
+
__privateGet(this, _emitter7).on(event, this.handleScheduleEvent);
|
|
2295
2371
|
}
|
|
2296
|
-
__privateSet(this,
|
|
2372
|
+
__privateSet(this, _cache8, new InMemoryCache());
|
|
2297
2373
|
}
|
|
2298
2374
|
has(args) {
|
|
2299
|
-
return __privateGet(this,
|
|
2375
|
+
return __privateGet(this, _cache8).get(getCacheKey2(args)) !== void 0;
|
|
2300
2376
|
}
|
|
2301
2377
|
set(args, data) {
|
|
2302
|
-
__privateGet(this,
|
|
2378
|
+
__privateGet(this, _cache8).set(getCacheKey2(args), data);
|
|
2303
2379
|
}
|
|
2304
2380
|
getAll(args) {
|
|
2305
2381
|
if (this.has(args)) {
|
|
2306
|
-
return __privateGet(this,
|
|
2382
|
+
return __privateGet(this, _cache8).get(getCacheKey2(args));
|
|
2307
2383
|
}
|
|
2308
2384
|
}
|
|
2309
2385
|
clearAll() {
|
|
2310
|
-
__privateGet(this,
|
|
2386
|
+
__privateGet(this, _cache8).clear();
|
|
2311
2387
|
}
|
|
2312
2388
|
};
|
|
2313
|
-
|
|
2314
|
-
|
|
2389
|
+
_emitter7 = new WeakMap();
|
|
2390
|
+
_cache8 = new WeakMap();
|
|
2315
2391
|
|
|
2316
2392
|
// src/cache/schedule-cache.ts
|
|
2317
2393
|
var updateEvents3 = [
|
|
@@ -2321,17 +2397,17 @@ var updateEvents3 = [
|
|
|
2321
2397
|
var getCacheKey3 = () => {
|
|
2322
2398
|
return "schedule";
|
|
2323
2399
|
};
|
|
2324
|
-
var
|
|
2400
|
+
var _emitter8, _cache9;
|
|
2325
2401
|
var ScheduleCache = class {
|
|
2326
2402
|
constructor({ emitterInstance }) {
|
|
2327
|
-
__privateAdd(this,
|
|
2328
|
-
__privateAdd(this,
|
|
2403
|
+
__privateAdd(this, _emitter8);
|
|
2404
|
+
__privateAdd(this, _cache9);
|
|
2329
2405
|
this.updateScheduleInCache = (key, data) => {
|
|
2330
|
-
const schedule = __privateGet(this,
|
|
2406
|
+
const schedule = __privateGet(this, _cache9).get(key);
|
|
2331
2407
|
if (!schedule) {
|
|
2332
2408
|
return false;
|
|
2333
2409
|
}
|
|
2334
|
-
__privateGet(this,
|
|
2410
|
+
__privateGet(this, _cache9).set(key, data);
|
|
2335
2411
|
return true;
|
|
2336
2412
|
};
|
|
2337
2413
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -2339,47 +2415,47 @@ var ScheduleCache = class {
|
|
|
2339
2415
|
return;
|
|
2340
2416
|
}
|
|
2341
2417
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2342
|
-
const keys = __privateGet(this,
|
|
2418
|
+
const keys = __privateGet(this, _cache9).keys();
|
|
2343
2419
|
for (const key of keys) {
|
|
2344
2420
|
const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
|
|
2345
|
-
const updatedSchedule = __privateGet(this,
|
|
2421
|
+
const updatedSchedule = __privateGet(this, _cache9).get(key);
|
|
2346
2422
|
if (!hasUpdatedSchedule || !updatedSchedule) {
|
|
2347
2423
|
continue;
|
|
2348
2424
|
}
|
|
2349
2425
|
uniqueFilterKeys.add(key);
|
|
2350
2426
|
}
|
|
2351
2427
|
for (const key of uniqueFilterKeys) {
|
|
2352
|
-
__privateGet(this,
|
|
2353
|
-
data: __privateGet(this,
|
|
2428
|
+
__privateGet(this, _emitter8).emit("preference.schedule.get.updated", {
|
|
2429
|
+
data: __privateGet(this, _cache9).get(key)
|
|
2354
2430
|
});
|
|
2355
2431
|
}
|
|
2356
2432
|
};
|
|
2357
|
-
__privateSet(this,
|
|
2433
|
+
__privateSet(this, _emitter8, emitterInstance);
|
|
2358
2434
|
for (const event of updateEvents3) {
|
|
2359
|
-
__privateGet(this,
|
|
2435
|
+
__privateGet(this, _emitter8).on(event, this.handleScheduleEvent);
|
|
2360
2436
|
}
|
|
2361
|
-
__privateSet(this,
|
|
2437
|
+
__privateSet(this, _cache9, new InMemoryCache());
|
|
2362
2438
|
}
|
|
2363
2439
|
has() {
|
|
2364
|
-
return __privateGet(this,
|
|
2440
|
+
return __privateGet(this, _cache9).get(getCacheKey3()) !== void 0;
|
|
2365
2441
|
}
|
|
2366
2442
|
set(data) {
|
|
2367
|
-
__privateGet(this,
|
|
2443
|
+
__privateGet(this, _cache9).set(getCacheKey3(), data);
|
|
2368
2444
|
}
|
|
2369
2445
|
getAll() {
|
|
2370
2446
|
if (this.has()) {
|
|
2371
|
-
return __privateGet(this,
|
|
2447
|
+
return __privateGet(this, _cache9).get(getCacheKey3());
|
|
2372
2448
|
}
|
|
2373
2449
|
}
|
|
2374
2450
|
clearAll() {
|
|
2375
|
-
__privateGet(this,
|
|
2451
|
+
__privateGet(this, _cache9).clear();
|
|
2376
2452
|
}
|
|
2377
2453
|
};
|
|
2378
|
-
|
|
2379
|
-
|
|
2454
|
+
_emitter8 = new WeakMap();
|
|
2455
|
+
_cache9 = new WeakMap();
|
|
2380
2456
|
|
|
2381
2457
|
// src/preferences/preferences.ts
|
|
2382
|
-
var
|
|
2458
|
+
var _useCache9;
|
|
2383
2459
|
var Preferences = class extends BaseModule {
|
|
2384
2460
|
constructor({
|
|
2385
2461
|
useCache,
|
|
@@ -2390,14 +2466,14 @@ var Preferences = class extends BaseModule {
|
|
|
2390
2466
|
eventEmitterInstance,
|
|
2391
2467
|
inboxServiceInstance
|
|
2392
2468
|
});
|
|
2393
|
-
__privateAdd(this,
|
|
2469
|
+
__privateAdd(this, _useCache9);
|
|
2394
2470
|
this.cache = new PreferencesCache({
|
|
2395
2471
|
emitterInstance: this._emitter
|
|
2396
2472
|
});
|
|
2397
2473
|
this.scheduleCache = new ScheduleCache({
|
|
2398
2474
|
emitterInstance: this._emitter
|
|
2399
2475
|
});
|
|
2400
|
-
__privateSet(this,
|
|
2476
|
+
__privateSet(this, _useCache9, useCache);
|
|
2401
2477
|
this.schedule = new PreferenceSchedule({
|
|
2402
2478
|
cache: this.scheduleCache,
|
|
2403
2479
|
useCache,
|
|
@@ -2410,7 +2486,7 @@ var Preferences = class extends BaseModule {
|
|
|
2410
2486
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
2411
2487
|
var _a;
|
|
2412
2488
|
try {
|
|
2413
|
-
let data = __privateGet(this,
|
|
2489
|
+
let data = __privateGet(this, _useCache9) ? this.cache.getAll(args) : void 0;
|
|
2414
2490
|
this._emitter.emit("preferences.list.pending", { args, data });
|
|
2415
2491
|
if (!data) {
|
|
2416
2492
|
const response = yield this._inboxService.fetchPreferences({
|
|
@@ -2424,10 +2500,10 @@ var Preferences = class extends BaseModule {
|
|
|
2424
2500
|
inboxServiceInstance: this._inboxService,
|
|
2425
2501
|
cache: this.cache,
|
|
2426
2502
|
scheduleCache: this.scheduleCache,
|
|
2427
|
-
useCache: __privateGet(this,
|
|
2503
|
+
useCache: __privateGet(this, _useCache9)
|
|
2428
2504
|
})
|
|
2429
2505
|
);
|
|
2430
|
-
if (__privateGet(this,
|
|
2506
|
+
if (__privateGet(this, _useCache9)) {
|
|
2431
2507
|
this.cache.set(args, data);
|
|
2432
2508
|
data = this.cache.getAll(args);
|
|
2433
2509
|
}
|
|
@@ -2449,7 +2525,7 @@ var Preferences = class extends BaseModule {
|
|
|
2449
2525
|
apiService: this._inboxService,
|
|
2450
2526
|
cache: this.cache,
|
|
2451
2527
|
scheduleCache: this.scheduleCache,
|
|
2452
|
-
useCache: __privateGet(this,
|
|
2528
|
+
useCache: __privateGet(this, _useCache9),
|
|
2453
2529
|
args
|
|
2454
2530
|
})
|
|
2455
2531
|
);
|
|
@@ -2463,14 +2539,14 @@ var Preferences = class extends BaseModule {
|
|
|
2463
2539
|
apiService: this._inboxService,
|
|
2464
2540
|
cache: this.cache,
|
|
2465
2541
|
scheduleCache: this.scheduleCache,
|
|
2466
|
-
useCache: __privateGet(this,
|
|
2542
|
+
useCache: __privateGet(this, _useCache9),
|
|
2467
2543
|
args
|
|
2468
2544
|
})
|
|
2469
2545
|
);
|
|
2470
2546
|
});
|
|
2471
2547
|
}
|
|
2472
2548
|
};
|
|
2473
|
-
|
|
2549
|
+
_useCache9 = new WeakMap();
|
|
2474
2550
|
|
|
2475
2551
|
// src/utils/is-browser.ts
|
|
2476
2552
|
function isBrowser() {
|
|
@@ -2478,14 +2554,14 @@ function isBrowser() {
|
|
|
2478
2554
|
}
|
|
2479
2555
|
|
|
2480
2556
|
// src/session/session.ts
|
|
2481
|
-
var
|
|
2557
|
+
var _emitter9, _inboxService5, _options;
|
|
2482
2558
|
var Session = class {
|
|
2483
2559
|
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
2484
|
-
__privateAdd(this,
|
|
2485
|
-
__privateAdd(this,
|
|
2560
|
+
__privateAdd(this, _emitter9);
|
|
2561
|
+
__privateAdd(this, _inboxService5);
|
|
2486
2562
|
__privateAdd(this, _options);
|
|
2487
|
-
__privateSet(this,
|
|
2488
|
-
__privateSet(this,
|
|
2563
|
+
__privateSet(this, _emitter9, eventEmitterInstance);
|
|
2564
|
+
__privateSet(this, _inboxService5, inboxServiceInstance);
|
|
2489
2565
|
__privateSet(this, _options, options);
|
|
2490
2566
|
}
|
|
2491
2567
|
get applicationIdentifier() {
|
|
@@ -2556,8 +2632,8 @@ var Session = class {
|
|
|
2556
2632
|
} else {
|
|
2557
2633
|
this.handleApplicationIdentifier("delete");
|
|
2558
2634
|
}
|
|
2559
|
-
__privateGet(this,
|
|
2560
|
-
const response = yield __privateGet(this,
|
|
2635
|
+
__privateGet(this, _emitter9).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
2636
|
+
const response = yield __privateGet(this, _inboxService5).initializeSession({
|
|
2561
2637
|
applicationIdentifier: finalApplicationIdentifier,
|
|
2562
2638
|
subscriberHash,
|
|
2563
2639
|
contextHash,
|
|
@@ -2574,15 +2650,15 @@ var Session = class {
|
|
|
2574
2650
|
if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
|
|
2575
2651
|
this.handleApplicationIdentifier("delete");
|
|
2576
2652
|
}
|
|
2577
|
-
__privateGet(this,
|
|
2653
|
+
__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
2578
2654
|
} catch (error) {
|
|
2579
|
-
__privateGet(this,
|
|
2655
|
+
__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
2580
2656
|
}
|
|
2581
2657
|
});
|
|
2582
2658
|
}
|
|
2583
2659
|
};
|
|
2584
|
-
|
|
2585
|
-
|
|
2660
|
+
_emitter9 = new WeakMap();
|
|
2661
|
+
_inboxService5 = new WeakMap();
|
|
2586
2662
|
_options = new WeakMap();
|
|
2587
2663
|
var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
|
|
2588
2664
|
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
@@ -2675,7 +2751,7 @@ var mapToNotification = ({
|
|
|
2675
2751
|
severity
|
|
2676
2752
|
});
|
|
2677
2753
|
};
|
|
2678
|
-
var _token,
|
|
2754
|
+
var _token, _emitter10, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
|
|
2679
2755
|
var PartySocketClient = class extends BaseModule {
|
|
2680
2756
|
constructor({
|
|
2681
2757
|
socketUrl,
|
|
@@ -2688,15 +2764,15 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2688
2764
|
});
|
|
2689
2765
|
__privateAdd(this, _PartySocketClient_instances);
|
|
2690
2766
|
__privateAdd(this, _token);
|
|
2691
|
-
__privateAdd(this,
|
|
2767
|
+
__privateAdd(this, _emitter10);
|
|
2692
2768
|
__privateAdd(this, _partySocket);
|
|
2693
2769
|
__privateAdd(this, _socketUrl);
|
|
2694
2770
|
__privateAdd(this, _notificationReceived, (event) => {
|
|
2695
2771
|
try {
|
|
2696
2772
|
const data = JSON.parse(event.data);
|
|
2697
2773
|
if (data.event === "notification_received" /* RECEIVED */) {
|
|
2698
|
-
__privateGet(this,
|
|
2699
|
-
result: new Notification(mapToNotification(data.data.message), __privateGet(this,
|
|
2774
|
+
__privateGet(this, _emitter10).emit(NOTIFICATION_RECEIVED, {
|
|
2775
|
+
result: new Notification(mapToNotification(data.data.message), __privateGet(this, _emitter10), this._inboxService)
|
|
2700
2776
|
});
|
|
2701
2777
|
}
|
|
2702
2778
|
} catch (error) {
|
|
@@ -2707,7 +2783,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2707
2783
|
try {
|
|
2708
2784
|
const data = JSON.parse(event.data);
|
|
2709
2785
|
if (data.event === "unseen_count_changed" /* UNSEEN */) {
|
|
2710
|
-
__privateGet(this,
|
|
2786
|
+
__privateGet(this, _emitter10).emit(UNSEEN_COUNT_CHANGED, {
|
|
2711
2787
|
result: data.data.unseenCount
|
|
2712
2788
|
});
|
|
2713
2789
|
}
|
|
@@ -2718,7 +2794,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2718
2794
|
try {
|
|
2719
2795
|
const data = JSON.parse(event.data);
|
|
2720
2796
|
if (data.event === "unread_count_changed" /* UNREAD */) {
|
|
2721
|
-
__privateGet(this,
|
|
2797
|
+
__privateGet(this, _emitter10).emit(UNREAD_COUNT_CHANGED, {
|
|
2722
2798
|
result: data.data.counts
|
|
2723
2799
|
});
|
|
2724
2800
|
}
|
|
@@ -2743,7 +2819,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2743
2819
|
} catch (error) {
|
|
2744
2820
|
}
|
|
2745
2821
|
});
|
|
2746
|
-
__privateSet(this,
|
|
2822
|
+
__privateSet(this, _emitter10, eventEmitterInstance);
|
|
2747
2823
|
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
2748
2824
|
}
|
|
2749
2825
|
onSessionSuccess({ token }) {
|
|
@@ -2770,7 +2846,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2770
2846
|
}
|
|
2771
2847
|
};
|
|
2772
2848
|
_token = new WeakMap();
|
|
2773
|
-
|
|
2849
|
+
_emitter10 = new WeakMap();
|
|
2774
2850
|
_partySocket = new WeakMap();
|
|
2775
2851
|
_socketUrl = new WeakMap();
|
|
2776
2852
|
_notificationReceived = new WeakMap();
|
|
@@ -2784,15 +2860,15 @@ initializeSocket_fn = function() {
|
|
|
2784
2860
|
return;
|
|
2785
2861
|
}
|
|
2786
2862
|
const args = { socketUrl: __privateGet(this, _socketUrl) };
|
|
2787
|
-
__privateGet(this,
|
|
2863
|
+
__privateGet(this, _emitter10).emit("socket.connect.pending", { args });
|
|
2788
2864
|
const url = new URL(__privateGet(this, _socketUrl));
|
|
2789
2865
|
url.searchParams.set("token", __privateGet(this, _token));
|
|
2790
2866
|
__privateSet(this, _partySocket, new WebSocket(url.toString()));
|
|
2791
2867
|
__privateGet(this, _partySocket).addEventListener("open", () => {
|
|
2792
|
-
__privateGet(this,
|
|
2868
|
+
__privateGet(this, _emitter10).emit("socket.connect.resolved", { args });
|
|
2793
2869
|
});
|
|
2794
2870
|
__privateGet(this, _partySocket).addEventListener("error", (error) => {
|
|
2795
|
-
__privateGet(this,
|
|
2871
|
+
__privateGet(this, _emitter10).emit("socket.connect.resolved", { args, error });
|
|
2796
2872
|
});
|
|
2797
2873
|
__privateGet(this, _partySocket).addEventListener("message", __privateGet(this, _handleMessage));
|
|
2798
2874
|
});
|
|
@@ -2910,7 +2986,7 @@ var mapToNotification2 = ({
|
|
|
2910
2986
|
severity
|
|
2911
2987
|
});
|
|
2912
2988
|
};
|
|
2913
|
-
var _token2,
|
|
2989
|
+
var _token2, _emitter11, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
|
|
2914
2990
|
var Socket = class extends BaseModule {
|
|
2915
2991
|
constructor({
|
|
2916
2992
|
socketUrl,
|
|
@@ -2923,25 +2999,25 @@ var Socket = class extends BaseModule {
|
|
|
2923
2999
|
});
|
|
2924
3000
|
__privateAdd(this, _Socket_instances);
|
|
2925
3001
|
__privateAdd(this, _token2);
|
|
2926
|
-
__privateAdd(this,
|
|
3002
|
+
__privateAdd(this, _emitter11);
|
|
2927
3003
|
__privateAdd(this, _socketIo);
|
|
2928
3004
|
__privateAdd(this, _socketUrl2);
|
|
2929
3005
|
__privateAdd(this, _notificationReceived2, ({ message }) => {
|
|
2930
|
-
__privateGet(this,
|
|
2931
|
-
result: new Notification(mapToNotification2(message), __privateGet(this,
|
|
3006
|
+
__privateGet(this, _emitter11).emit(NOTIFICATION_RECEIVED2, {
|
|
3007
|
+
result: new Notification(mapToNotification2(message), __privateGet(this, _emitter11), this._inboxService)
|
|
2932
3008
|
});
|
|
2933
3009
|
});
|
|
2934
3010
|
__privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
|
|
2935
|
-
__privateGet(this,
|
|
3011
|
+
__privateGet(this, _emitter11).emit(UNSEEN_COUNT_CHANGED2, {
|
|
2936
3012
|
result: unseenCount
|
|
2937
3013
|
});
|
|
2938
3014
|
});
|
|
2939
3015
|
__privateAdd(this, _unreadCountChanged2, ({ counts }) => {
|
|
2940
|
-
__privateGet(this,
|
|
3016
|
+
__privateGet(this, _emitter11).emit(UNREAD_COUNT_CHANGED2, {
|
|
2941
3017
|
result: counts
|
|
2942
3018
|
});
|
|
2943
3019
|
});
|
|
2944
|
-
__privateSet(this,
|
|
3020
|
+
__privateSet(this, _emitter11, eventEmitterInstance);
|
|
2945
3021
|
__privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
|
|
2946
3022
|
}
|
|
2947
3023
|
onSessionSuccess({ token }) {
|
|
@@ -2968,7 +3044,7 @@ var Socket = class extends BaseModule {
|
|
|
2968
3044
|
}
|
|
2969
3045
|
};
|
|
2970
3046
|
_token2 = new WeakMap();
|
|
2971
|
-
|
|
3047
|
+
_emitter11 = new WeakMap();
|
|
2972
3048
|
_socketIo = new WeakMap();
|
|
2973
3049
|
_socketUrl2 = new WeakMap();
|
|
2974
3050
|
_notificationReceived2 = new WeakMap();
|
|
@@ -2982,7 +3058,7 @@ initializeSocket_fn2 = function() {
|
|
|
2982
3058
|
return;
|
|
2983
3059
|
}
|
|
2984
3060
|
const args = { socketUrl: __privateGet(this, _socketUrl2) };
|
|
2985
|
-
__privateGet(this,
|
|
3061
|
+
__privateGet(this, _emitter11).emit("socket.connect.pending", { args });
|
|
2986
3062
|
__privateSet(this, _socketIo, io(__privateGet(this, _socketUrl2), {
|
|
2987
3063
|
reconnectionDelayMax: 1e4,
|
|
2988
3064
|
transports: ["websocket"],
|
|
@@ -2991,10 +3067,10 @@ initializeSocket_fn2 = function() {
|
|
|
2991
3067
|
}
|
|
2992
3068
|
}));
|
|
2993
3069
|
__privateGet(this, _socketIo).on("connect", () => {
|
|
2994
|
-
__privateGet(this,
|
|
3070
|
+
__privateGet(this, _emitter11).emit("socket.connect.resolved", { args });
|
|
2995
3071
|
});
|
|
2996
3072
|
__privateGet(this, _socketIo).on("connect_error", (error) => {
|
|
2997
|
-
__privateGet(this,
|
|
3073
|
+
__privateGet(this, _emitter11).emit("socket.connect.resolved", { args, error });
|
|
2998
3074
|
});
|
|
2999
3075
|
(_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, __privateGet(this, _notificationReceived2));
|
|
3000
3076
|
(_b = __privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, __privateGet(this, _unseenCountChanged2));
|
|
@@ -3068,57 +3144,66 @@ function createSocket({
|
|
|
3068
3144
|
}
|
|
3069
3145
|
|
|
3070
3146
|
// src/novu.ts
|
|
3071
|
-
var
|
|
3147
|
+
var _emitter12, _session, _inboxService6, _options2;
|
|
3072
3148
|
var Novu = class {
|
|
3073
3149
|
constructor(options) {
|
|
3074
|
-
__privateAdd(this,
|
|
3150
|
+
__privateAdd(this, _emitter12);
|
|
3075
3151
|
__privateAdd(this, _session);
|
|
3076
|
-
__privateAdd(this,
|
|
3077
|
-
|
|
3078
|
-
|
|
3152
|
+
__privateAdd(this, _inboxService6);
|
|
3153
|
+
__privateAdd(this, _options2);
|
|
3154
|
+
var _a, _b, _c;
|
|
3155
|
+
__privateSet(this, _options2, options);
|
|
3156
|
+
__privateSet(this, _inboxService6, new InboxService({
|
|
3079
3157
|
apiUrl: options.apiUrl || options.backendUrl,
|
|
3080
3158
|
userAgent: options.__userAgent
|
|
3081
3159
|
}));
|
|
3082
|
-
__privateSet(this,
|
|
3160
|
+
__privateSet(this, _emitter12, new NovuEventEmitter());
|
|
3161
|
+
const subscriber = buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber });
|
|
3083
3162
|
__privateSet(this, _session, new Session(
|
|
3084
3163
|
{
|
|
3085
3164
|
applicationIdentifier: options.applicationIdentifier || "",
|
|
3086
3165
|
subscriberHash: options.subscriberHash,
|
|
3087
|
-
subscriber
|
|
3166
|
+
subscriber,
|
|
3088
3167
|
defaultSchedule: options.defaultSchedule,
|
|
3089
3168
|
context: options.context,
|
|
3090
3169
|
contextHash: options.contextHash
|
|
3091
3170
|
},
|
|
3092
|
-
__privateGet(this,
|
|
3093
|
-
__privateGet(this,
|
|
3171
|
+
__privateGet(this, _inboxService6),
|
|
3172
|
+
__privateGet(this, _emitter12)
|
|
3094
3173
|
));
|
|
3095
3174
|
__privateGet(this, _session).initialize();
|
|
3096
3175
|
this.notifications = new Notifications({
|
|
3097
3176
|
useCache: (_a = options.useCache) != null ? _a : true,
|
|
3098
|
-
inboxServiceInstance: __privateGet(this,
|
|
3099
|
-
eventEmitterInstance: __privateGet(this,
|
|
3177
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3178
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
3100
3179
|
});
|
|
3101
3180
|
this.preferences = new Preferences({
|
|
3102
3181
|
useCache: (_b = options.useCache) != null ? _b : true,
|
|
3103
|
-
inboxServiceInstance: __privateGet(this,
|
|
3104
|
-
eventEmitterInstance: __privateGet(this,
|
|
3182
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3183
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
3184
|
+
});
|
|
3185
|
+
this.subscriptions = new Subscriptions({
|
|
3186
|
+
subscriber,
|
|
3187
|
+
useCache: (_c = options.useCache) != null ? _c : true,
|
|
3188
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3189
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
3105
3190
|
});
|
|
3106
3191
|
this.socket = createSocket({
|
|
3107
3192
|
socketUrl: options.socketUrl,
|
|
3108
|
-
eventEmitterInstance: __privateGet(this,
|
|
3109
|
-
inboxServiceInstance: __privateGet(this,
|
|
3193
|
+
eventEmitterInstance: __privateGet(this, _emitter12),
|
|
3194
|
+
inboxServiceInstance: __privateGet(this, _inboxService6)
|
|
3110
3195
|
});
|
|
3111
3196
|
this.on = (eventName, listener) => {
|
|
3112
3197
|
if (this.socket.isSocketEvent(eventName)) {
|
|
3113
3198
|
this.socket.connect();
|
|
3114
3199
|
}
|
|
3115
|
-
const cleanup = __privateGet(this,
|
|
3200
|
+
const cleanup = __privateGet(this, _emitter12).on(eventName, listener);
|
|
3116
3201
|
return () => {
|
|
3117
3202
|
cleanup();
|
|
3118
3203
|
};
|
|
3119
3204
|
};
|
|
3120
3205
|
this.off = (eventName, listener) => {
|
|
3121
|
-
__privateGet(this,
|
|
3206
|
+
__privateGet(this, _emitter12).off(eventName, listener);
|
|
3122
3207
|
};
|
|
3123
3208
|
}
|
|
3124
3209
|
get applicationIdentifier() {
|
|
@@ -3130,9 +3215,21 @@ var Novu = class {
|
|
|
3130
3215
|
get context() {
|
|
3131
3216
|
return __privateGet(this, _session).context;
|
|
3132
3217
|
}
|
|
3218
|
+
get options() {
|
|
3219
|
+
return __privateGet(this, _options2);
|
|
3220
|
+
}
|
|
3133
3221
|
get contextKey() {
|
|
3134
3222
|
return buildContextKey(__privateGet(this, _session).context);
|
|
3135
3223
|
}
|
|
3224
|
+
clearCache() {
|
|
3225
|
+
this.notifications.cache.clearAll();
|
|
3226
|
+
this.preferences.cache.clearAll();
|
|
3227
|
+
this.preferences.scheduleCache.clearAll();
|
|
3228
|
+
this.subscriptions.cache.clearAll();
|
|
3229
|
+
}
|
|
3230
|
+
/**
|
|
3231
|
+
* @deprecated
|
|
3232
|
+
*/
|
|
3136
3233
|
changeSubscriber(options) {
|
|
3137
3234
|
return __async(this, null, function* () {
|
|
3138
3235
|
yield __privateGet(this, _session).initialize({
|
|
@@ -3143,13 +3240,16 @@ var Novu = class {
|
|
|
3143
3240
|
context: __privateGet(this, _session).context,
|
|
3144
3241
|
contextHash: __privateGet(this, _session).contextHash
|
|
3145
3242
|
});
|
|
3146
|
-
this.
|
|
3243
|
+
this.clearCache();
|
|
3147
3244
|
const disconnectResult = yield this.socket.disconnect();
|
|
3148
3245
|
if (!disconnectResult.error) {
|
|
3149
3246
|
yield this.socket.connect();
|
|
3150
3247
|
}
|
|
3151
3248
|
});
|
|
3152
3249
|
}
|
|
3250
|
+
/**
|
|
3251
|
+
* @deprecated
|
|
3252
|
+
*/
|
|
3153
3253
|
changeContext(options) {
|
|
3154
3254
|
return __async(this, null, function* () {
|
|
3155
3255
|
const currentSubscriber = __privateGet(this, _session).subscriber;
|
|
@@ -3164,7 +3264,7 @@ var Novu = class {
|
|
|
3164
3264
|
context: options.context,
|
|
3165
3265
|
contextHash: options.contextHash
|
|
3166
3266
|
});
|
|
3167
|
-
this.
|
|
3267
|
+
this.clearCache();
|
|
3168
3268
|
const disconnectResult = yield this.socket.disconnect();
|
|
3169
3269
|
if (!disconnectResult.error) {
|
|
3170
3270
|
yield this.socket.connect();
|
|
@@ -3172,8 +3272,9 @@ var Novu = class {
|
|
|
3172
3272
|
});
|
|
3173
3273
|
}
|
|
3174
3274
|
};
|
|
3175
|
-
|
|
3275
|
+
_emitter12 = new WeakMap();
|
|
3176
3276
|
_session = new WeakMap();
|
|
3177
|
-
|
|
3277
|
+
_inboxService6 = new WeakMap();
|
|
3278
|
+
_options2 = new WeakMap();
|
|
3178
3279
|
|
|
3179
|
-
export {
|
|
3280
|
+
export { DEFAULT_API_VERSION, Novu, SubscriptionPreference, TopicSubscription, areSeveritiesEqual, areTagsEqual, checkNotificationDataFilter, checkNotificationMatchesFilter, checkNotificationTagFilter, isBrowser, isSameFilter };
|