@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,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkCDGREQFE_js = require('./chunk-CDGREQFE.js');
|
|
4
4
|
var chunk7B52C2XE_js = require('./chunk-7B52C2XE.js');
|
|
5
5
|
var mitt = require('mitt');
|
|
6
6
|
require('event-target-polyfill');
|
|
@@ -12,49 +12,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
12
12
|
var mitt__default = /*#__PURE__*/_interopDefault(mitt);
|
|
13
13
|
var io__default = /*#__PURE__*/_interopDefault(io);
|
|
14
14
|
|
|
15
|
-
// src/types.ts
|
|
16
|
-
var NotificationStatus = /* @__PURE__ */ ((NotificationStatus2) => {
|
|
17
|
-
NotificationStatus2["READ"] = "read";
|
|
18
|
-
NotificationStatus2["SEEN"] = "seen";
|
|
19
|
-
NotificationStatus2["SNOOZED"] = "snoozed";
|
|
20
|
-
NotificationStatus2["UNREAD"] = "unread";
|
|
21
|
-
NotificationStatus2["UNSEEN"] = "unseen";
|
|
22
|
-
NotificationStatus2["UNSNOOZED"] = "unsnoozed";
|
|
23
|
-
return NotificationStatus2;
|
|
24
|
-
})(NotificationStatus || {});
|
|
25
|
-
var PreferenceLevel = /* @__PURE__ */ ((PreferenceLevel2) => {
|
|
26
|
-
PreferenceLevel2["GLOBAL"] = "global";
|
|
27
|
-
PreferenceLevel2["TEMPLATE"] = "template";
|
|
28
|
-
return PreferenceLevel2;
|
|
29
|
-
})(PreferenceLevel || {});
|
|
30
|
-
var ChannelType = /* @__PURE__ */ ((ChannelType2) => {
|
|
31
|
-
ChannelType2["IN_APP"] = "in_app";
|
|
32
|
-
ChannelType2["EMAIL"] = "email";
|
|
33
|
-
ChannelType2["SMS"] = "sms";
|
|
34
|
-
ChannelType2["CHAT"] = "chat";
|
|
35
|
-
ChannelType2["PUSH"] = "push";
|
|
36
|
-
return ChannelType2;
|
|
37
|
-
})(ChannelType || {});
|
|
38
|
-
var WebSocketEvent = /* @__PURE__ */ ((WebSocketEvent2) => {
|
|
39
|
-
WebSocketEvent2["RECEIVED"] = "notification_received";
|
|
40
|
-
WebSocketEvent2["UNREAD"] = "unread_count_changed";
|
|
41
|
-
WebSocketEvent2["UNSEEN"] = "unseen_count_changed";
|
|
42
|
-
return WebSocketEvent2;
|
|
43
|
-
})(WebSocketEvent || {});
|
|
44
|
-
var SeverityLevelEnum = /* @__PURE__ */ ((SeverityLevelEnum2) => {
|
|
45
|
-
SeverityLevelEnum2["HIGH"] = "high";
|
|
46
|
-
SeverityLevelEnum2["MEDIUM"] = "medium";
|
|
47
|
-
SeverityLevelEnum2["LOW"] = "low";
|
|
48
|
-
SeverityLevelEnum2["NONE"] = "none";
|
|
49
|
-
return SeverityLevelEnum2;
|
|
50
|
-
})(SeverityLevelEnum || {});
|
|
51
|
-
var WorkflowCriticalityEnum = /* @__PURE__ */ ((WorkflowCriticalityEnum2) => {
|
|
52
|
-
WorkflowCriticalityEnum2["CRITICAL"] = "critical";
|
|
53
|
-
WorkflowCriticalityEnum2["NON_CRITICAL"] = "nonCritical";
|
|
54
|
-
WorkflowCriticalityEnum2["ALL"] = "all";
|
|
55
|
-
return WorkflowCriticalityEnum2;
|
|
56
|
-
})(WorkflowCriticalityEnum || {});
|
|
57
|
-
|
|
58
15
|
// src/utils/arrays.ts
|
|
59
16
|
var arrayValuesEqual = (arr1, arr2) => {
|
|
60
17
|
if (arr1 === arr2) {
|
|
@@ -146,1098 +103,1197 @@ function checkNotificationMatchesFilter(notification, filter) {
|
|
|
146
103
|
return checkBasicFilters(notification, filter) && checkNotificationTagFilter(notification.tags, filter.tags) && checkNotificationDataFilter(notification.data, filter.data);
|
|
147
104
|
}
|
|
148
105
|
|
|
149
|
-
// src/
|
|
150
|
-
var
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
apiUrl = this.DEFAULT_BACKEND_URL,
|
|
159
|
-
userAgent = DEFAULT_USER_AGENT,
|
|
160
|
-
headers = {}
|
|
161
|
-
} = options || {};
|
|
162
|
-
this.apiVersion = apiVersion;
|
|
163
|
-
this.apiUrl = `${apiUrl}/${apiVersion}`;
|
|
164
|
-
this.headers = chunk7B52C2XE_js.__spreadValues({
|
|
165
|
-
"Novu-API-Version": "2024-06-26",
|
|
166
|
-
"Content-Type": "application/json",
|
|
167
|
-
"User-Agent": userAgent
|
|
168
|
-
}, headers);
|
|
169
|
-
}
|
|
170
|
-
setAuthorizationToken(token) {
|
|
171
|
-
this.headers.Authorization = `Bearer ${token}`;
|
|
172
|
-
}
|
|
173
|
-
setKeylessHeader(identifier) {
|
|
106
|
+
// src/subscriptions/subscription.ts
|
|
107
|
+
var _emitter, _inboxService, _cache, _useCache, _isStale;
|
|
108
|
+
var TopicSubscription = class {
|
|
109
|
+
constructor(subscription, emitter, inboxService, cache, useCache) {
|
|
110
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter);
|
|
111
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService);
|
|
112
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache);
|
|
113
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache);
|
|
114
|
+
chunk7B52C2XE_js.__privateAdd(this, _isStale, false);
|
|
174
115
|
var _a;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.
|
|
116
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter, emitter);
|
|
117
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService, inboxService);
|
|
118
|
+
chunk7B52C2XE_js.__privateSet(this, _cache, cache);
|
|
119
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache, useCache);
|
|
120
|
+
this.id = subscription.id;
|
|
121
|
+
this.identifier = subscription.identifier;
|
|
122
|
+
this.topicKey = subscription.topicKey;
|
|
123
|
+
this.preferences = (_a = subscription.preferences) == null ? void 0 : _a.map(
|
|
124
|
+
(pref) => new SubscriptionPreference(chunk7B52C2XE_js.__spreadValues({}, pref), chunk7B52C2XE_js.__privateGet(this, _emitter), chunk7B52C2XE_js.__privateGet(this, _inboxService), chunk7B52C2XE_js.__privateGet(this, _cache), chunk7B52C2XE_js.__privateGet(this, _useCache))
|
|
125
|
+
);
|
|
183
126
|
}
|
|
184
|
-
|
|
127
|
+
update(args) {
|
|
185
128
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
},
|
|
192
|
-
unwrapEnvelope
|
|
129
|
+
return updateSubscription({
|
|
130
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
131
|
+
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
132
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache),
|
|
133
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache),
|
|
134
|
+
args: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, args), { subscription: this })
|
|
193
135
|
});
|
|
194
136
|
});
|
|
195
137
|
}
|
|
196
|
-
|
|
138
|
+
updatePreference(args) {
|
|
197
139
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
140
|
+
if (chunk7B52C2XE_js.__privateGet(this, _isStale)) {
|
|
141
|
+
return {
|
|
142
|
+
error: new chunkCDGREQFE_js.NovuError("Cannot update a deleted subscription", new Error("Subscription is stale"))
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return updateSubscriptionPreference({
|
|
146
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
147
|
+
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
148
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache),
|
|
149
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache),
|
|
150
|
+
args: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, args), { subscriptionId: this.id })
|
|
205
151
|
});
|
|
206
152
|
});
|
|
207
153
|
}
|
|
208
|
-
|
|
154
|
+
bulkUpdatePreferences(args) {
|
|
209
155
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
156
|
+
if (chunk7B52C2XE_js.__privateGet(this, _isStale)) {
|
|
157
|
+
return {
|
|
158
|
+
error: new chunkCDGREQFE_js.NovuError("Cannot bulk update a deleted subscription", new Error("Subscription is stale"))
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return bulkUpdateSubscriptionPreference({
|
|
162
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
163
|
+
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
164
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache),
|
|
165
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache),
|
|
166
|
+
args: args.map((arg) => chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, arg), { subscriptionId: this.id }))
|
|
216
167
|
});
|
|
217
168
|
});
|
|
218
169
|
}
|
|
219
|
-
delete(
|
|
170
|
+
delete() {
|
|
220
171
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
body
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
doFetch(_0) {
|
|
231
|
-
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
232
|
-
path,
|
|
233
|
-
searchParams,
|
|
234
|
-
options,
|
|
235
|
-
unwrapEnvelope = true
|
|
236
|
-
}) {
|
|
237
|
-
const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
|
|
238
|
-
const reqInit = {
|
|
239
|
-
method: (options == null ? void 0 : options.method) || "GET",
|
|
240
|
-
headers: chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
|
|
241
|
-
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
242
|
-
};
|
|
243
|
-
const response = yield fetch(fullUrl, reqInit);
|
|
244
|
-
if (!response.ok) {
|
|
245
|
-
const errorData = yield response.json();
|
|
246
|
-
throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
|
|
247
|
-
}
|
|
248
|
-
if (response.status === 204) {
|
|
249
|
-
return void 0;
|
|
172
|
+
if (chunk7B52C2XE_js.__privateGet(this, _isStale)) {
|
|
173
|
+
return {
|
|
174
|
+
error: new chunkCDGREQFE_js.NovuError("Cannot delete an already deleted subscription", new Error("Subscription is stale"))
|
|
175
|
+
};
|
|
250
176
|
}
|
|
251
|
-
|
|
252
|
-
|
|
177
|
+
return deleteSubscription({
|
|
178
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
179
|
+
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
180
|
+
args: { subscription: this }
|
|
181
|
+
});
|
|
253
182
|
});
|
|
254
183
|
}
|
|
255
184
|
};
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return acc;
|
|
262
|
-
}, []).join("/").replace(/\/\?/, "?");
|
|
263
|
-
}
|
|
185
|
+
_emitter = new WeakMap();
|
|
186
|
+
_inboxService = new WeakMap();
|
|
187
|
+
_cache = new WeakMap();
|
|
188
|
+
_useCache = new WeakMap();
|
|
189
|
+
_isStale = new WeakMap();
|
|
264
190
|
|
|
265
|
-
// src/
|
|
266
|
-
var
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
defaultSchedule,
|
|
282
|
-
context
|
|
283
|
-
}) {
|
|
284
|
-
const response = yield chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
285
|
-
applicationIdentifier,
|
|
286
|
-
subscriberHash,
|
|
287
|
-
contextHash,
|
|
288
|
-
subscriber,
|
|
289
|
-
defaultSchedule,
|
|
290
|
-
context
|
|
191
|
+
// src/subscriptions/helpers.ts
|
|
192
|
+
var listSubscriptions = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
193
|
+
emitter,
|
|
194
|
+
apiService,
|
|
195
|
+
cache,
|
|
196
|
+
options,
|
|
197
|
+
args
|
|
198
|
+
}) {
|
|
199
|
+
try {
|
|
200
|
+
const { useCache, refetch } = options;
|
|
201
|
+
let data = useCache && !refetch ? cache.getAll(args) : void 0;
|
|
202
|
+
emitter.emit("subscriptions.list.pending", { args, data });
|
|
203
|
+
if (!data || refetch) {
|
|
204
|
+
const response = yield apiService.fetchSubscriptions(args.topicKey);
|
|
205
|
+
data = response.map((el) => {
|
|
206
|
+
return new TopicSubscription(chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, el), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
291
207
|
});
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return response;
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
fetchNotifications({
|
|
299
|
-
after,
|
|
300
|
-
archived,
|
|
301
|
-
limit = 10,
|
|
302
|
-
offset,
|
|
303
|
-
read: read2,
|
|
304
|
-
tags,
|
|
305
|
-
snoozed,
|
|
306
|
-
seen: seen2,
|
|
307
|
-
data,
|
|
308
|
-
severity
|
|
309
|
-
}) {
|
|
310
|
-
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
311
|
-
if (after) {
|
|
312
|
-
searchParams.append("after", after);
|
|
313
|
-
}
|
|
314
|
-
if (offset) {
|
|
315
|
-
searchParams.append("offset", `${offset}`);
|
|
316
|
-
}
|
|
317
|
-
if (tags) {
|
|
318
|
-
for (const tag of tags) {
|
|
319
|
-
searchParams.append("tags[]", tag);
|
|
208
|
+
if (useCache) {
|
|
209
|
+
cache.set(args, data);
|
|
210
|
+
data = cache.getAll(args);
|
|
320
211
|
}
|
|
321
212
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
213
|
+
emitter.emit("subscriptions.list.resolved", { args, data });
|
|
214
|
+
return { data };
|
|
215
|
+
} catch (error) {
|
|
216
|
+
emitter.emit("subscriptions.list.resolved", { args, error });
|
|
217
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to fetch subscriptions", error) };
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
var getSubscription = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
221
|
+
emitter,
|
|
222
|
+
apiService,
|
|
223
|
+
cache,
|
|
224
|
+
options,
|
|
225
|
+
args
|
|
226
|
+
}) {
|
|
227
|
+
try {
|
|
228
|
+
const { useCache, refetch } = options;
|
|
229
|
+
let data = useCache && !refetch ? cache.get(args) : void 0;
|
|
230
|
+
emitter.emit("subscription.get.pending", { args, data });
|
|
231
|
+
if (!data || refetch) {
|
|
232
|
+
const response = yield apiService.getSubscription(args.topicKey, args.identifier, args.workflowIds, args.tags);
|
|
233
|
+
if (!response) {
|
|
234
|
+
emitter.emit("subscription.get.resolved", { args, data: null });
|
|
235
|
+
return { data: null };
|
|
236
|
+
}
|
|
237
|
+
data = new TopicSubscription(chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, response), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
238
|
+
if (useCache) {
|
|
239
|
+
cache.setOne(args, data);
|
|
240
|
+
data = cache.get(args);
|
|
340
241
|
}
|
|
341
|
-
} else if (severity) {
|
|
342
|
-
searchParams.append("severity", severity);
|
|
343
242
|
}
|
|
344
|
-
|
|
243
|
+
emitter.emit("subscription.get.resolved", { args, data });
|
|
244
|
+
return { data };
|
|
245
|
+
} catch (error) {
|
|
246
|
+
emitter.emit("subscription.get.resolved", { args, error });
|
|
247
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to fetch subscription", error) };
|
|
345
248
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
249
|
+
});
|
|
250
|
+
var createSubscription = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
251
|
+
emitter,
|
|
252
|
+
apiService,
|
|
253
|
+
cache,
|
|
254
|
+
useCache,
|
|
255
|
+
args
|
|
256
|
+
}) {
|
|
257
|
+
var _a;
|
|
258
|
+
try {
|
|
259
|
+
emitter.emit("subscription.create.pending", { args });
|
|
260
|
+
const response = yield apiService.createSubscription({
|
|
261
|
+
identifier: (_a = args.identifier) != null ? _a : "",
|
|
262
|
+
name: args.name,
|
|
263
|
+
topicKey: args.topicKey,
|
|
264
|
+
topicName: args.topicName,
|
|
265
|
+
preferences: args.preferences
|
|
266
|
+
});
|
|
267
|
+
const subscription = new TopicSubscription(
|
|
268
|
+
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, response), { topicKey: args.topicKey }),
|
|
269
|
+
emitter,
|
|
270
|
+
apiService,
|
|
271
|
+
cache,
|
|
272
|
+
useCache
|
|
355
273
|
);
|
|
274
|
+
emitter.emit("subscription.create.resolved", { args, data: subscription });
|
|
275
|
+
return { data: subscription };
|
|
276
|
+
} catch (error) {
|
|
277
|
+
emitter.emit("subscription.create.resolved", { args, error });
|
|
278
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to create subscription", error) };
|
|
356
279
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return
|
|
383
|
-
tags,
|
|
384
|
-
data: data ? JSON.stringify(data) : void 0
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
archiveAllRead({ tags, data }) {
|
|
388
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
389
|
-
tags,
|
|
390
|
-
data: data ? JSON.stringify(data) : void 0
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
delete(notificationId) {
|
|
394
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
|
|
395
|
-
}
|
|
396
|
-
deleteAll({ tags, data }) {
|
|
397
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
|
|
398
|
-
tags,
|
|
399
|
-
data: data ? JSON.stringify(data) : void 0
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
markAsSeen({
|
|
403
|
-
notificationIds,
|
|
404
|
-
tags,
|
|
405
|
-
data
|
|
406
|
-
}) {
|
|
407
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/seen`, {
|
|
408
|
-
notificationIds,
|
|
409
|
-
tags,
|
|
410
|
-
data: data ? JSON.stringify(data) : void 0
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
seen(notificationId) {
|
|
414
|
-
return this.markAsSeen({ notificationIds: [notificationId] });
|
|
415
|
-
}
|
|
416
|
-
completeAction({
|
|
417
|
-
actionType,
|
|
418
|
-
notificationId
|
|
419
|
-
}) {
|
|
420
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
421
|
-
actionType
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
revertAction({
|
|
425
|
-
actionType,
|
|
426
|
-
notificationId
|
|
427
|
-
}) {
|
|
428
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
429
|
-
actionType
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
fetchPreferences({
|
|
433
|
-
tags,
|
|
434
|
-
severity,
|
|
435
|
-
criticality
|
|
436
|
-
}) {
|
|
437
|
-
const queryParams = new URLSearchParams();
|
|
438
|
-
if (tags) {
|
|
439
|
-
for (const tag of tags) {
|
|
440
|
-
queryParams.append("tags[]", tag);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
if (severity && Array.isArray(severity)) {
|
|
444
|
-
for (const el of severity) {
|
|
445
|
-
queryParams.append("severity[]", el);
|
|
446
|
-
}
|
|
447
|
-
} else if (severity) {
|
|
448
|
-
queryParams.append("severity", severity);
|
|
449
|
-
}
|
|
450
|
-
if (criticality) {
|
|
451
|
-
queryParams.append("criticality", criticality);
|
|
452
|
-
}
|
|
453
|
-
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
454
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
455
|
-
}
|
|
456
|
-
bulkUpdatePreferences(preferences) {
|
|
457
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
458
|
-
}
|
|
459
|
-
updateGlobalPreferences(preferences) {
|
|
460
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
|
|
461
|
-
}
|
|
462
|
-
updateWorkflowPreferences({
|
|
463
|
-
workflowId,
|
|
464
|
-
channels
|
|
465
|
-
}) {
|
|
466
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
|
|
467
|
-
}
|
|
468
|
-
fetchGlobalPreferences() {
|
|
469
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
|
|
470
|
-
}
|
|
471
|
-
triggerHelloWorldEvent() {
|
|
472
|
-
const payload = {
|
|
473
|
-
name: "hello-world",
|
|
474
|
-
to: {
|
|
475
|
-
subscriberId: "keyless-subscriber-id"
|
|
476
|
-
},
|
|
477
|
-
payload: {
|
|
478
|
-
subject: "Novu Keyless Environment",
|
|
479
|
-
body: "You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",
|
|
480
|
-
primaryActionText: "Obtain API Key",
|
|
481
|
-
primaryActionUrl: "https://go.novu.co/keyless",
|
|
482
|
-
secondaryActionText: "Explore Documentation",
|
|
483
|
-
secondaryActionUrl: "https://go.novu.co/keyless-docs"
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post("/inbox/events", payload);
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
_httpClient = new WeakMap();
|
|
490
|
-
var _mittEmitter;
|
|
491
|
-
var NovuEventEmitter = class {
|
|
492
|
-
constructor() {
|
|
493
|
-
chunk7B52C2XE_js.__privateAdd(this, _mittEmitter);
|
|
494
|
-
chunk7B52C2XE_js.__privateSet(this, _mittEmitter, mitt__default.default());
|
|
495
|
-
}
|
|
496
|
-
on(eventName, listener) {
|
|
497
|
-
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
498
|
-
return () => {
|
|
499
|
-
this.off(eventName, listener);
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
off(eventName, listener) {
|
|
503
|
-
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).off(eventName, listener);
|
|
504
|
-
}
|
|
505
|
-
emit(type, event) {
|
|
506
|
-
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).emit(type, event);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
_mittEmitter = new WeakMap();
|
|
510
|
-
|
|
511
|
-
// src/utils/errors.ts
|
|
512
|
-
var NovuError = class extends Error {
|
|
513
|
-
constructor(message, originalError) {
|
|
514
|
-
super(message);
|
|
515
|
-
this.originalError = originalError;
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
// src/notifications/helpers.ts
|
|
520
|
-
var read = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
521
|
-
emitter,
|
|
522
|
-
apiService,
|
|
523
|
-
args
|
|
524
|
-
}) {
|
|
525
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
526
|
-
args,
|
|
527
|
-
{
|
|
528
|
-
isRead: true,
|
|
529
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
530
|
-
isArchived: false,
|
|
531
|
-
archivedAt: void 0
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
emitter,
|
|
535
|
-
apiService
|
|
536
|
-
}
|
|
537
|
-
);
|
|
538
|
-
try {
|
|
539
|
-
emitter.emit("notification.read.pending", {
|
|
540
|
-
args,
|
|
541
|
-
data: optimisticValue
|
|
542
|
-
});
|
|
543
|
-
const response = yield apiService.read(notificationId);
|
|
544
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
545
|
-
emitter.emit("notification.read.resolved", { args, data: updatedNotification });
|
|
546
|
-
return { data: updatedNotification };
|
|
547
|
-
} catch (error) {
|
|
548
|
-
emitter.emit("notification.read.resolved", { args, error });
|
|
549
|
-
return { error: new NovuError("Failed to read notification", error) };
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
var unread = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
553
|
-
emitter,
|
|
554
|
-
apiService,
|
|
555
|
-
args
|
|
556
|
-
}) {
|
|
557
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
558
|
-
args,
|
|
559
|
-
{
|
|
560
|
-
isRead: false,
|
|
561
|
-
readAt: null,
|
|
562
|
-
isArchived: false,
|
|
563
|
-
archivedAt: void 0
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
emitter,
|
|
567
|
-
apiService
|
|
568
|
-
}
|
|
569
|
-
);
|
|
570
|
-
try {
|
|
571
|
-
emitter.emit("notification.unread.pending", {
|
|
572
|
-
args,
|
|
573
|
-
data: optimisticValue
|
|
574
|
-
});
|
|
575
|
-
const response = yield apiService.unread(notificationId);
|
|
576
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
577
|
-
emitter.emit("notification.unread.resolved", { args, data: updatedNotification });
|
|
578
|
-
return { data: updatedNotification };
|
|
579
|
-
} catch (error) {
|
|
580
|
-
emitter.emit("notification.unread.resolved", { args, error });
|
|
581
|
-
return { error: new NovuError("Failed to unread notification", error) };
|
|
280
|
+
});
|
|
281
|
+
var updateSubscription = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
282
|
+
emitter,
|
|
283
|
+
apiService,
|
|
284
|
+
cache,
|
|
285
|
+
useCache,
|
|
286
|
+
args
|
|
287
|
+
}) {
|
|
288
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
289
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
290
|
+
try {
|
|
291
|
+
emitter.emit("subscription.update.pending", {
|
|
292
|
+
args
|
|
293
|
+
});
|
|
294
|
+
const response = yield apiService.updateSubscription({
|
|
295
|
+
topicKey,
|
|
296
|
+
subscriptionId,
|
|
297
|
+
name: args.name,
|
|
298
|
+
preferences: args.preferences
|
|
299
|
+
});
|
|
300
|
+
const updatedSubscription = new TopicSubscription(chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, response), { topicKey }), emitter, apiService, cache, useCache);
|
|
301
|
+
emitter.emit("subscription.update.resolved", { args, data: updatedSubscription });
|
|
302
|
+
return { data: updatedSubscription };
|
|
303
|
+
} catch (error) {
|
|
304
|
+
emitter.emit("subscription.update.resolved", { args, error });
|
|
305
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to update subscription", error) };
|
|
582
306
|
}
|
|
583
307
|
});
|
|
584
|
-
var
|
|
308
|
+
var updateSubscriptionPreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
585
309
|
emitter,
|
|
586
310
|
apiService,
|
|
311
|
+
cache,
|
|
312
|
+
useCache,
|
|
587
313
|
args
|
|
588
314
|
}) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
{
|
|
592
|
-
isSeen: true
|
|
593
|
-
},
|
|
594
|
-
{
|
|
595
|
-
emitter,
|
|
596
|
-
apiService
|
|
597
|
-
}
|
|
598
|
-
);
|
|
315
|
+
var _a, _b;
|
|
316
|
+
const workflowId = "workflowId" in args ? args.workflowId : (_b = (_a = args.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id;
|
|
599
317
|
try {
|
|
600
|
-
emitter.emit("
|
|
318
|
+
emitter.emit("subscription.preference.update.pending", {
|
|
601
319
|
args,
|
|
602
|
-
data:
|
|
320
|
+
data: "preference" in args ? new SubscriptionPreference(
|
|
321
|
+
chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, args.preference), typeof args.value === "boolean" ? { enabled: args.value } : { condition: args.value }),
|
|
322
|
+
emitter,
|
|
323
|
+
apiService,
|
|
324
|
+
cache,
|
|
325
|
+
useCache
|
|
326
|
+
) : void 0
|
|
603
327
|
});
|
|
604
|
-
yield apiService.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
328
|
+
const response = yield apiService.updateSubscriptionPreference(chunk7B52C2XE_js.__spreadValues({
|
|
329
|
+
subscriptionId: args.subscriptionId,
|
|
330
|
+
workflowId
|
|
331
|
+
}, typeof args.value === "boolean" ? {
|
|
332
|
+
enabled: args.value,
|
|
333
|
+
email: args.value,
|
|
334
|
+
sms: args.value,
|
|
335
|
+
in_app: args.value,
|
|
336
|
+
chat: args.value,
|
|
337
|
+
push: args.value
|
|
338
|
+
} : { condition: args.value }));
|
|
339
|
+
const updatedSubscription = new SubscriptionPreference(chunk7B52C2XE_js.__spreadValues({}, response), emitter, apiService, cache, useCache);
|
|
340
|
+
emitter.emit("subscription.preference.update.resolved", { args, data: updatedSubscription });
|
|
341
|
+
return { data: updatedSubscription };
|
|
611
342
|
} catch (error) {
|
|
612
|
-
emitter.emit("
|
|
613
|
-
return { error: new NovuError("Failed to
|
|
343
|
+
emitter.emit("subscription.preference.update.resolved", { args, error });
|
|
344
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to update subscription", error) };
|
|
614
345
|
}
|
|
615
346
|
});
|
|
616
|
-
var
|
|
347
|
+
var bulkUpdateSubscriptionPreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
617
348
|
emitter,
|
|
618
349
|
apiService,
|
|
350
|
+
cache,
|
|
351
|
+
useCache,
|
|
619
352
|
args
|
|
620
353
|
}) {
|
|
621
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
622
|
-
args,
|
|
623
|
-
{
|
|
624
|
-
isArchived: true,
|
|
625
|
-
archivedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
626
|
-
isRead: true,
|
|
627
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
emitter,
|
|
631
|
-
apiService
|
|
632
|
-
}
|
|
633
|
-
);
|
|
634
354
|
try {
|
|
635
|
-
|
|
355
|
+
const optimisticallyUpdatedPreferences = args.map(
|
|
356
|
+
(arg) => "preference" in arg ? new SubscriptionPreference(
|
|
357
|
+
chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, arg.preference), typeof arg.value === "boolean" ? { enabled: arg.value } : { condition: arg.value }),
|
|
358
|
+
emitter,
|
|
359
|
+
apiService,
|
|
360
|
+
cache,
|
|
361
|
+
useCache
|
|
362
|
+
) : void 0
|
|
363
|
+
).filter((el) => el !== void 0);
|
|
364
|
+
emitter.emit("subscription.preferences.bulk_update.pending", {
|
|
636
365
|
args,
|
|
637
|
-
data:
|
|
366
|
+
data: optimisticallyUpdatedPreferences
|
|
638
367
|
});
|
|
639
|
-
const
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
return { error: new NovuError("Failed to archive notification", error) };
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
var unarchive = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
649
|
-
emitter,
|
|
650
|
-
apiService,
|
|
651
|
-
args
|
|
652
|
-
}) {
|
|
653
|
-
const { notificationId, optimisticValue } = getNotificationDetails(
|
|
654
|
-
args,
|
|
655
|
-
{
|
|
656
|
-
isArchived: false,
|
|
657
|
-
archivedAt: null,
|
|
658
|
-
isRead: true,
|
|
659
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
660
|
-
},
|
|
661
|
-
{
|
|
662
|
-
emitter,
|
|
663
|
-
apiService
|
|
664
|
-
}
|
|
665
|
-
);
|
|
666
|
-
try {
|
|
667
|
-
emitter.emit("notification.unarchive.pending", {
|
|
668
|
-
args,
|
|
669
|
-
data: optimisticValue
|
|
368
|
+
const preferencesToUpdate = args.map((arg) => {
|
|
369
|
+
var _a, _b, _c, _d, _e, _f;
|
|
370
|
+
return chunk7B52C2XE_js.__spreadValues({
|
|
371
|
+
subscriptionIdOrIdentifier: arg.subscriptionId,
|
|
372
|
+
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 : ""
|
|
373
|
+
}, 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 });
|
|
670
374
|
});
|
|
671
|
-
const response = yield apiService.
|
|
672
|
-
const
|
|
673
|
-
emitter.emit("
|
|
674
|
-
return { data:
|
|
375
|
+
const response = yield apiService.bulkUpdateSubscriptionPreferences(preferencesToUpdate);
|
|
376
|
+
const preferences = response.map((el) => new SubscriptionPreference(el, emitter, apiService, cache, useCache));
|
|
377
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, data: preferences });
|
|
378
|
+
return { data: preferences };
|
|
675
379
|
} catch (error) {
|
|
676
|
-
emitter.emit("
|
|
677
|
-
return { error: new NovuError("Failed to
|
|
380
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, error });
|
|
381
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to bulk update subscription preferences", error) };
|
|
678
382
|
}
|
|
679
383
|
});
|
|
680
|
-
var
|
|
384
|
+
var deleteSubscription = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
681
385
|
emitter,
|
|
682
386
|
apiService,
|
|
683
387
|
args
|
|
684
388
|
}) {
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
{
|
|
688
|
-
isSnoozed: true,
|
|
689
|
-
snoozedUntil: args.snoozeUntil
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
emitter,
|
|
693
|
-
apiService
|
|
694
|
-
}
|
|
695
|
-
);
|
|
389
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
390
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
696
391
|
try {
|
|
697
|
-
emitter.emit("
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
const response = yield apiService.snooze(notificationId, args.snoozeUntil);
|
|
702
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
703
|
-
emitter.emit("notification.snooze.resolved", { args, data: updatedNotification });
|
|
704
|
-
return { data: updatedNotification };
|
|
392
|
+
emitter.emit("subscription.delete.pending", { args });
|
|
393
|
+
yield apiService.deleteSubscription({ topicKey, subscriptionId });
|
|
394
|
+
emitter.emit("subscription.delete.resolved", { args });
|
|
395
|
+
return { data: void 0 };
|
|
705
396
|
} catch (error) {
|
|
706
|
-
emitter.emit("
|
|
707
|
-
return { error: new NovuError("Failed to
|
|
397
|
+
emitter.emit("subscription.delete.resolved", { args, error });
|
|
398
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to delete subscription", error) };
|
|
708
399
|
}
|
|
709
400
|
});
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
args,
|
|
729
|
-
data: optimisticValue
|
|
730
|
-
});
|
|
731
|
-
const response = yield apiService.unsnooze(notificationId);
|
|
732
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
733
|
-
emitter.emit("notification.unsnooze.resolved", { args, data: updatedNotification });
|
|
734
|
-
return { data: updatedNotification };
|
|
735
|
-
} catch (error) {
|
|
736
|
-
emitter.emit("notification.unsnooze.resolved", { args, error });
|
|
737
|
-
return { error: new NovuError("Failed to unsnooze notification", error) };
|
|
401
|
+
|
|
402
|
+
// src/subscriptions/subscription-preference.ts
|
|
403
|
+
var _emitter2, _inboxService2, _cache2, _useCache2;
|
|
404
|
+
var SubscriptionPreference = class {
|
|
405
|
+
constructor(preference, emitter, inboxService, cache, useCache) {
|
|
406
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter2);
|
|
407
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService2);
|
|
408
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache2);
|
|
409
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache2);
|
|
410
|
+
var _a;
|
|
411
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter2, emitter);
|
|
412
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService2, inboxService);
|
|
413
|
+
chunk7B52C2XE_js.__privateSet(this, _cache2, cache);
|
|
414
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache2, useCache);
|
|
415
|
+
this.enabled = preference.enabled;
|
|
416
|
+
this.condition = (_a = preference.condition) != null ? _a : void 0;
|
|
417
|
+
this.workflow = preference.workflow;
|
|
418
|
+
this.subscriptionId = preference.subscriptionId;
|
|
738
419
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
};
|
|
755
|
-
const { notificationId, optimisticValue } = getNotificationDetails(args, optimisticUpdate, {
|
|
756
|
-
emitter,
|
|
757
|
-
apiService
|
|
758
|
-
});
|
|
759
|
-
try {
|
|
760
|
-
emitter.emit("notification.complete_action.pending", {
|
|
761
|
-
args,
|
|
762
|
-
data: optimisticValue
|
|
420
|
+
update(args) {
|
|
421
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
422
|
+
var _a;
|
|
423
|
+
return updateSubscriptionPreference({
|
|
424
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter2),
|
|
425
|
+
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService2),
|
|
426
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache2),
|
|
427
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache2),
|
|
428
|
+
args: {
|
|
429
|
+
subscriptionId: this.subscriptionId,
|
|
430
|
+
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
431
|
+
value: args.value,
|
|
432
|
+
preference: this
|
|
433
|
+
}
|
|
434
|
+
});
|
|
763
435
|
});
|
|
764
|
-
const response = yield apiService.completeAction({ actionType, notificationId });
|
|
765
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
766
|
-
emitter.emit("notification.complete_action.resolved", { args, data: updatedNotification });
|
|
767
|
-
return { data: updatedNotification };
|
|
768
|
-
} catch (error) {
|
|
769
|
-
emitter.emit("notification.complete_action.resolved", { args, error });
|
|
770
|
-
return { error: new NovuError(`Failed to complete ${actionType} action on the notification`, error) };
|
|
771
436
|
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
437
|
+
};
|
|
438
|
+
_emitter2 = new WeakMap();
|
|
439
|
+
_inboxService2 = new WeakMap();
|
|
440
|
+
_cache2 = new WeakMap();
|
|
441
|
+
_useCache2 = new WeakMap();
|
|
442
|
+
|
|
443
|
+
// src/base-module.ts
|
|
444
|
+
var _callsQueue, _sessionError;
|
|
445
|
+
var BaseModule = class {
|
|
446
|
+
constructor({
|
|
447
|
+
inboxServiceInstance,
|
|
448
|
+
eventEmitterInstance
|
|
449
|
+
}) {
|
|
450
|
+
chunk7B52C2XE_js.__privateAdd(this, _callsQueue, []);
|
|
451
|
+
chunk7B52C2XE_js.__privateAdd(this, _sessionError);
|
|
452
|
+
this._emitter = eventEmitterInstance;
|
|
453
|
+
this._inboxService = inboxServiceInstance;
|
|
454
|
+
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
455
|
+
if (data) {
|
|
456
|
+
this.onSessionSuccess(data);
|
|
457
|
+
chunk7B52C2XE_js.__privateGet(this, _callsQueue).forEach((_0) => chunk7B52C2XE_js.__async(this, [_0], function* ({ fn, resolve }) {
|
|
458
|
+
resolve(yield fn());
|
|
459
|
+
}));
|
|
460
|
+
chunk7B52C2XE_js.__privateSet(this, _callsQueue, []);
|
|
461
|
+
} else if (error) {
|
|
462
|
+
this.onSessionError(error);
|
|
463
|
+
chunk7B52C2XE_js.__privateSet(this, _sessionError, error);
|
|
464
|
+
chunk7B52C2XE_js.__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
465
|
+
resolve({ error: new chunkCDGREQFE_js.NovuError("Failed to initialize session, please contact the support", error) });
|
|
466
|
+
});
|
|
467
|
+
chunk7B52C2XE_js.__privateSet(this, _callsQueue, []);
|
|
468
|
+
}
|
|
796
469
|
});
|
|
797
|
-
const response = yield apiService.revertAction({ actionType, notificationId });
|
|
798
|
-
const updatedNotification = new Notification(response, emitter, apiService);
|
|
799
|
-
emitter.emit("notification.revert_action.resolved", { args, data: updatedNotification });
|
|
800
|
-
return { data: updatedNotification };
|
|
801
|
-
} catch (error) {
|
|
802
|
-
emitter.emit("notification.revert_action.resolved", { args, error });
|
|
803
|
-
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
804
470
|
}
|
|
805
|
-
|
|
806
|
-
var getNotificationDetails = (args, update, dependencies) => {
|
|
807
|
-
if ("notification" in args) {
|
|
808
|
-
return {
|
|
809
|
-
notificationId: args.notification.id,
|
|
810
|
-
optimisticValue: new Notification(
|
|
811
|
-
chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, args.notification), update),
|
|
812
|
-
dependencies.emitter,
|
|
813
|
-
dependencies.apiService
|
|
814
|
-
)
|
|
815
|
-
};
|
|
816
|
-
} else {
|
|
817
|
-
return {
|
|
818
|
-
notificationId: args.notificationId
|
|
819
|
-
};
|
|
471
|
+
onSessionSuccess(_) {
|
|
820
472
|
}
|
|
821
|
-
|
|
822
|
-
var readAll = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
823
|
-
emitter,
|
|
824
|
-
inboxService,
|
|
825
|
-
notificationsCache,
|
|
826
|
-
tags,
|
|
827
|
-
data
|
|
828
|
-
}) {
|
|
829
|
-
try {
|
|
830
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
831
|
-
const optimisticNotifications = notifications.map(
|
|
832
|
-
(notification) => new Notification(
|
|
833
|
-
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
|
|
834
|
-
isRead: true,
|
|
835
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
836
|
-
isArchived: false,
|
|
837
|
-
archivedAt: void 0
|
|
838
|
-
}),
|
|
839
|
-
emitter,
|
|
840
|
-
inboxService
|
|
841
|
-
)
|
|
842
|
-
);
|
|
843
|
-
emitter.emit("notifications.read_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
844
|
-
yield inboxService.readAll({ tags, data });
|
|
845
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
846
|
-
return {};
|
|
847
|
-
} catch (error) {
|
|
848
|
-
emitter.emit("notifications.read_all.resolved", { args: { tags, data }, error });
|
|
849
|
-
return { error: new NovuError("Failed to read all notifications", error) };
|
|
473
|
+
onSessionError(_) {
|
|
850
474
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
})
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
(notification) => new Notification(
|
|
865
|
-
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
|
|
866
|
-
isSeen: true,
|
|
867
|
-
firstSeenAt: notification.firstSeenAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
868
|
-
}),
|
|
869
|
-
emitter,
|
|
870
|
-
inboxService
|
|
871
|
-
)
|
|
872
|
-
);
|
|
873
|
-
emitter.emit("notifications.seen_all.pending", {
|
|
874
|
-
args: { notificationIds, tags, data },
|
|
875
|
-
data: optimisticNotifications
|
|
876
|
-
});
|
|
877
|
-
yield inboxService.markAsSeen({ notificationIds, tags, data });
|
|
878
|
-
emitter.emit("notifications.seen_all.resolved", {
|
|
879
|
-
args: { notificationIds, tags, data },
|
|
880
|
-
data: optimisticNotifications
|
|
475
|
+
callWithSession(fn) {
|
|
476
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
477
|
+
if (this._inboxService.isSessionInitialized) {
|
|
478
|
+
return fn();
|
|
479
|
+
}
|
|
480
|
+
if (chunk7B52C2XE_js.__privateGet(this, _sessionError)) {
|
|
481
|
+
return Promise.resolve({
|
|
482
|
+
error: new chunkCDGREQFE_js.NovuError("Failed to initialize session, please contact the support", chunk7B52C2XE_js.__privateGet(this, _sessionError))
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
return new Promise((resolve, reject) => {
|
|
486
|
+
chunk7B52C2XE_js.__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
487
|
+
});
|
|
881
488
|
});
|
|
882
|
-
return {};
|
|
883
|
-
} catch (error) {
|
|
884
|
-
emitter.emit("notifications.seen_all.resolved", { args: { notificationIds, tags, data }, error });
|
|
885
|
-
return { error: new NovuError("Failed to mark all notifications as seen", error) };
|
|
886
489
|
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const optimisticNotifications = notifications.map(
|
|
898
|
-
(notification) => new Notification(
|
|
899
|
-
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), {
|
|
900
|
-
isRead: true,
|
|
901
|
-
readAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
902
|
-
isArchived: true,
|
|
903
|
-
archivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
904
|
-
}),
|
|
905
|
-
emitter,
|
|
906
|
-
inboxService
|
|
907
|
-
)
|
|
908
|
-
);
|
|
909
|
-
emitter.emit("notifications.archive_all.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
910
|
-
yield inboxService.archiveAll({ tags, data });
|
|
911
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
912
|
-
return {};
|
|
913
|
-
} catch (error) {
|
|
914
|
-
emitter.emit("notifications.archive_all.resolved", { args: { tags, data }, error });
|
|
915
|
-
return { error: new NovuError("Failed to archive all notifications", error) };
|
|
490
|
+
};
|
|
491
|
+
_callsQueue = new WeakMap();
|
|
492
|
+
_sessionError = new WeakMap();
|
|
493
|
+
|
|
494
|
+
// src/cache/in-memory-cache.ts
|
|
495
|
+
var _cache3;
|
|
496
|
+
var InMemoryCache = class {
|
|
497
|
+
constructor() {
|
|
498
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache3);
|
|
499
|
+
chunk7B52C2XE_js.__privateSet(this, _cache3, /* @__PURE__ */ new Map());
|
|
916
500
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
emitter,
|
|
920
|
-
inboxService,
|
|
921
|
-
notificationsCache,
|
|
922
|
-
tags,
|
|
923
|
-
data
|
|
924
|
-
}) {
|
|
925
|
-
try {
|
|
926
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data, read: true });
|
|
927
|
-
const optimisticNotifications = notifications.map(
|
|
928
|
-
(notification) => new Notification(
|
|
929
|
-
chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notification), { isArchived: true, archivedAt: (/* @__PURE__ */ new Date()).toISOString() }),
|
|
930
|
-
emitter,
|
|
931
|
-
inboxService
|
|
932
|
-
)
|
|
933
|
-
);
|
|
934
|
-
emitter.emit("notifications.archive_all_read.pending", { args: { tags, data }, data: optimisticNotifications });
|
|
935
|
-
yield inboxService.archiveAllRead({ tags, data });
|
|
936
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, data: optimisticNotifications });
|
|
937
|
-
return {};
|
|
938
|
-
} catch (error) {
|
|
939
|
-
emitter.emit("notifications.archive_all_read.resolved", { args: { tags, data }, error });
|
|
940
|
-
return { error: new NovuError("Failed to archive all read notifications", error) };
|
|
501
|
+
get(key) {
|
|
502
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache3).get(key);
|
|
941
503
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
emitter,
|
|
945
|
-
apiService,
|
|
946
|
-
args
|
|
947
|
-
}) {
|
|
948
|
-
const { notificationId } = getNotificationDetails(
|
|
949
|
-
args,
|
|
950
|
-
{},
|
|
951
|
-
{
|
|
952
|
-
emitter,
|
|
953
|
-
apiService
|
|
954
|
-
}
|
|
955
|
-
);
|
|
956
|
-
try {
|
|
957
|
-
emitter.emit("notification.delete.pending", {
|
|
958
|
-
args
|
|
959
|
-
});
|
|
960
|
-
yield apiService.delete(notificationId);
|
|
961
|
-
emitter.emit("notification.delete.resolved", { args });
|
|
962
|
-
return {};
|
|
963
|
-
} catch (error) {
|
|
964
|
-
emitter.emit("notification.delete.resolved", { args, error });
|
|
965
|
-
return { error: new NovuError("Failed to delete notification", error) };
|
|
504
|
+
getValues() {
|
|
505
|
+
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache3).values());
|
|
966
506
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
emitter,
|
|
970
|
-
inboxService,
|
|
971
|
-
notificationsCache,
|
|
972
|
-
tags,
|
|
973
|
-
data
|
|
974
|
-
}) {
|
|
975
|
-
try {
|
|
976
|
-
const notifications = notificationsCache.getUniqueNotifications({ tags, data });
|
|
977
|
-
emitter.emit("notifications.delete_all.pending", { args: { tags, data }, data: notifications });
|
|
978
|
-
yield inboxService.deleteAll({ tags, data });
|
|
979
|
-
emitter.emit("notifications.delete_all.resolved", { args: { tags, data } });
|
|
980
|
-
return {};
|
|
981
|
-
} catch (error) {
|
|
982
|
-
emitter.emit("notifications.delete_all.resolved", { args: { tags, data }, error });
|
|
983
|
-
return { error: new NovuError("Failed to delete all notifications", error) };
|
|
507
|
+
entries() {
|
|
508
|
+
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache3).entries());
|
|
984
509
|
}
|
|
985
|
-
|
|
510
|
+
keys() {
|
|
511
|
+
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache3).keys());
|
|
512
|
+
}
|
|
513
|
+
set(key, value) {
|
|
514
|
+
chunk7B52C2XE_js.__privateGet(this, _cache3).set(key, value);
|
|
515
|
+
}
|
|
516
|
+
remove(key) {
|
|
517
|
+
chunk7B52C2XE_js.__privateGet(this, _cache3).delete(key);
|
|
518
|
+
}
|
|
519
|
+
clear() {
|
|
520
|
+
chunk7B52C2XE_js.__privateGet(this, _cache3).clear();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
_cache3 = new WeakMap();
|
|
986
524
|
|
|
987
|
-
// src/
|
|
988
|
-
var
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
this
|
|
1005
|
-
this
|
|
1006
|
-
this
|
|
1007
|
-
this
|
|
1008
|
-
this
|
|
1009
|
-
this.
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
525
|
+
// src/cache/subscriptions-cache.ts
|
|
526
|
+
var getListCacheKey = (args) => {
|
|
527
|
+
return `list:${args.topicKey}`;
|
|
528
|
+
};
|
|
529
|
+
var getTopicKeyFromListCacheKey = (key) => {
|
|
530
|
+
return key.split(":")[1];
|
|
531
|
+
};
|
|
532
|
+
var getItemCacheKey = (args) => {
|
|
533
|
+
return `item:${args.topicKey}:${args.identifier}`;
|
|
534
|
+
};
|
|
535
|
+
var _emitter3, _cache4, _useCache3, _itemCache, _inboxService3;
|
|
536
|
+
var SubscriptionsCache = class {
|
|
537
|
+
constructor({
|
|
538
|
+
emitterInstance,
|
|
539
|
+
inboxServiceInstance,
|
|
540
|
+
useCache
|
|
541
|
+
}) {
|
|
542
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter3);
|
|
543
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache4);
|
|
544
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache3);
|
|
545
|
+
chunk7B52C2XE_js.__privateAdd(this, _itemCache);
|
|
546
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService3);
|
|
547
|
+
this.handleCreate = (subscription) => {
|
|
548
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
549
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
550
|
+
if (subscriptions) {
|
|
551
|
+
const updatedSubscriptions = [...subscriptions, subscription];
|
|
552
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
553
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
554
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).set(
|
|
558
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
559
|
+
subscription
|
|
560
|
+
);
|
|
561
|
+
};
|
|
562
|
+
this.handleUpdate = (subscription) => {
|
|
563
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
564
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
565
|
+
if (subscriptions) {
|
|
566
|
+
const updatedSubscriptions = subscriptions.map((el) => el.id === subscription.id ? subscription : el);
|
|
567
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
568
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
569
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).set(
|
|
573
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
574
|
+
subscription
|
|
575
|
+
);
|
|
576
|
+
};
|
|
577
|
+
this.handlePreferenceUpdate = (preference) => {
|
|
578
|
+
this.updateSubscriptionPreferences([preference]);
|
|
579
|
+
};
|
|
580
|
+
this.handleBulkPreferenceUpdate = (preferences) => {
|
|
581
|
+
this.updateSubscriptionPreferences(preferences);
|
|
582
|
+
};
|
|
583
|
+
this.updateSubscriptionPreferences = (updatedPreferences) => {
|
|
584
|
+
var _a;
|
|
585
|
+
const preferencesBySubscription = /* @__PURE__ */ new Map();
|
|
586
|
+
for (const pref of updatedPreferences) {
|
|
587
|
+
const existing = (_a = preferencesBySubscription.get(pref.subscriptionId)) != null ? _a : [];
|
|
588
|
+
existing.push(pref);
|
|
589
|
+
preferencesBySubscription.set(pref.subscriptionId, existing);
|
|
590
|
+
}
|
|
591
|
+
const allListKeys = chunk7B52C2XE_js.__privateGet(this, _cache4).keys();
|
|
592
|
+
for (const listKey of allListKeys) {
|
|
593
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
594
|
+
if (!subscriptions) continue;
|
|
595
|
+
let hasUpdates = false;
|
|
596
|
+
const updatedSubscriptions = subscriptions.map((subscription) => {
|
|
597
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
598
|
+
if (subscriptionPreferences) {
|
|
599
|
+
hasUpdates = true;
|
|
600
|
+
return this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
601
|
+
}
|
|
602
|
+
return subscription;
|
|
603
|
+
});
|
|
604
|
+
if (hasUpdates) {
|
|
605
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
606
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
607
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const allItemKeys = chunk7B52C2XE_js.__privateGet(this, _itemCache).keys();
|
|
612
|
+
for (const key of allItemKeys) {
|
|
613
|
+
const subscription = chunk7B52C2XE_js.__privateGet(this, _itemCache).get(key);
|
|
614
|
+
if (!subscription) continue;
|
|
615
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
616
|
+
if (subscriptionPreferences) {
|
|
617
|
+
const updatedSubscription = this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
618
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).set(key, updatedSubscription);
|
|
619
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscription.update.resolved", {
|
|
620
|
+
args: { subscription },
|
|
621
|
+
data: updatedSubscription
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
this.createUpdatedSubscription = (subscription, subscriptionPreferences) => {
|
|
627
|
+
var _a;
|
|
628
|
+
const updatedPreferences = (_a = subscription.preferences) == null ? void 0 : _a.map((pref) => {
|
|
629
|
+
const newPreference = subscriptionPreferences.find((el) => el.workflow.id === pref.workflow.id);
|
|
630
|
+
if (newPreference) {
|
|
631
|
+
return newPreference;
|
|
632
|
+
}
|
|
633
|
+
return pref;
|
|
634
|
+
});
|
|
635
|
+
return new TopicSubscription(
|
|
636
|
+
{
|
|
637
|
+
id: subscription.id,
|
|
638
|
+
identifier: subscription.identifier,
|
|
639
|
+
topicKey: subscription.topicKey,
|
|
640
|
+
preferences: updatedPreferences
|
|
641
|
+
},
|
|
642
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3),
|
|
643
|
+
chunk7B52C2XE_js.__privateGet(this, _inboxService3),
|
|
644
|
+
this,
|
|
645
|
+
chunk7B52C2XE_js.__privateGet(this, _useCache3)
|
|
646
|
+
);
|
|
647
|
+
};
|
|
648
|
+
this.handleDelete = (subscription) => {
|
|
649
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
650
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
651
|
+
if (subscriptions) {
|
|
652
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
653
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
654
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
655
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }));
|
|
659
|
+
};
|
|
660
|
+
this.handleDeleteById = (subscriptionId) => {
|
|
661
|
+
const allListKeys = chunk7B52C2XE_js.__privateGet(this, _cache4).keys();
|
|
662
|
+
for (const listKey of allListKeys) {
|
|
663
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
664
|
+
if (subscriptions) {
|
|
665
|
+
const subscription = subscriptions.find((el) => el.id === subscriptionId || el.identifier === subscriptionId);
|
|
666
|
+
if (subscription) {
|
|
667
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
668
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
669
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
670
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
671
|
+
});
|
|
672
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).remove(
|
|
673
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier })
|
|
674
|
+
);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const allItemKeys = chunk7B52C2XE_js.__privateGet(this, _itemCache).keys();
|
|
680
|
+
for (const key of allItemKeys) {
|
|
681
|
+
const subscription = chunk7B52C2XE_js.__privateGet(this, _itemCache).get(key);
|
|
682
|
+
if (subscription && (subscription.id === subscriptionId || subscription.identifier === subscriptionId)) {
|
|
683
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).remove(key);
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter3, emitterInstance);
|
|
689
|
+
chunk7B52C2XE_js.__privateSet(this, _cache4, new InMemoryCache());
|
|
690
|
+
chunk7B52C2XE_js.__privateSet(this, _itemCache, new InMemoryCache());
|
|
691
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService3, inboxServiceInstance);
|
|
692
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache3, useCache);
|
|
693
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.create.resolved", ({ data }) => {
|
|
694
|
+
if (data) {
|
|
695
|
+
this.handleCreate(data);
|
|
1026
696
|
}
|
|
1027
697
|
});
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1032
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1033
|
-
args: {
|
|
1034
|
-
notification: this
|
|
698
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.update.resolved", ({ data }) => {
|
|
699
|
+
if (data) {
|
|
700
|
+
this.handleUpdate(data);
|
|
1035
701
|
}
|
|
1036
702
|
});
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
args: {
|
|
1043
|
-
notification: this
|
|
703
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.delete.resolved", ({ args }) => {
|
|
704
|
+
if ("subscription" in args) {
|
|
705
|
+
this.handleDelete(args.subscription);
|
|
706
|
+
} else if ("subscriptionId" in args) {
|
|
707
|
+
this.handleDeleteById(args.subscriptionId);
|
|
1044
708
|
}
|
|
1045
709
|
});
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
710
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.preference.update.pending", ({ data }) => {
|
|
711
|
+
if (data) {
|
|
712
|
+
this.handlePreferenceUpdate(data);
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.preference.update.resolved", ({ data }) => {
|
|
716
|
+
if (data) {
|
|
717
|
+
this.handlePreferenceUpdate(data);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter3).on("subscription.preferences.bulk_update.resolved", ({ data }) => {
|
|
721
|
+
if (data && data.length > 0) {
|
|
722
|
+
this.handleBulkPreferenceUpdate(data);
|
|
1053
723
|
}
|
|
1054
724
|
});
|
|
1055
725
|
}
|
|
1056
|
-
|
|
1057
|
-
return
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
726
|
+
has(args) {
|
|
727
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache4).get(getListCacheKey(args)) !== void 0;
|
|
728
|
+
}
|
|
729
|
+
set(args, data) {
|
|
730
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).set(getListCacheKey(args), data);
|
|
731
|
+
for (const subscription of data) {
|
|
732
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).set(
|
|
733
|
+
getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }),
|
|
734
|
+
subscription
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
setOne(args, data) {
|
|
739
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).set(getItemCacheKey(args), data);
|
|
740
|
+
}
|
|
741
|
+
getAll(args) {
|
|
742
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache4).get(getListCacheKey(args));
|
|
743
|
+
}
|
|
744
|
+
get(args) {
|
|
745
|
+
return chunk7B52C2XE_js.__privateGet(this, _itemCache).get(getItemCacheKey(args));
|
|
746
|
+
}
|
|
747
|
+
invalidate(args) {
|
|
748
|
+
const listKey = getListCacheKey({ topicKey: args.topicKey });
|
|
749
|
+
const subscriptions = chunk7B52C2XE_js.__privateGet(this, _cache4).get(listKey);
|
|
750
|
+
if (subscriptions) {
|
|
751
|
+
for (const subscription of subscriptions) {
|
|
752
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }));
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).remove(listKey);
|
|
756
|
+
const allItemKeys = chunk7B52C2XE_js.__privateGet(this, _itemCache).keys();
|
|
757
|
+
for (const key of allItemKeys) {
|
|
758
|
+
if (key.startsWith(`item:${args.topicKey}:`)) {
|
|
759
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).remove(key);
|
|
1062
760
|
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
clearAll() {
|
|
764
|
+
chunk7B52C2XE_js.__privateGet(this, _cache4).clear();
|
|
765
|
+
chunk7B52C2XE_js.__privateGet(this, _itemCache).clear();
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
_emitter3 = new WeakMap();
|
|
769
|
+
_cache4 = new WeakMap();
|
|
770
|
+
_useCache3 = new WeakMap();
|
|
771
|
+
_itemCache = new WeakMap();
|
|
772
|
+
_inboxService3 = new WeakMap();
|
|
773
|
+
|
|
774
|
+
// src/subscriptions/subscriptions.ts
|
|
775
|
+
var _useCache4, _subscriber;
|
|
776
|
+
var Subscriptions = class extends BaseModule {
|
|
777
|
+
constructor({
|
|
778
|
+
useCache,
|
|
779
|
+
inboxServiceInstance,
|
|
780
|
+
eventEmitterInstance,
|
|
781
|
+
subscriber
|
|
782
|
+
}) {
|
|
783
|
+
super({
|
|
784
|
+
eventEmitterInstance,
|
|
785
|
+
inboxServiceInstance
|
|
786
|
+
});
|
|
787
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache4);
|
|
788
|
+
chunk7B52C2XE_js.__privateAdd(this, _subscriber);
|
|
789
|
+
this.cache = new SubscriptionsCache({
|
|
790
|
+
emitterInstance: this._emitter,
|
|
791
|
+
inboxServiceInstance: this._inboxService,
|
|
792
|
+
useCache
|
|
1063
793
|
});
|
|
794
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache4, useCache);
|
|
795
|
+
chunk7B52C2XE_js.__privateSet(this, _subscriber, subscriber);
|
|
1064
796
|
}
|
|
1065
|
-
|
|
1066
|
-
return
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
797
|
+
list(args, options) {
|
|
798
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
799
|
+
return this.callWithSession(
|
|
800
|
+
() => {
|
|
801
|
+
var _a;
|
|
802
|
+
return listSubscriptions({
|
|
803
|
+
emitter: this._emitter,
|
|
804
|
+
apiService: this._inboxService,
|
|
805
|
+
cache: this.cache,
|
|
806
|
+
options: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, options), {
|
|
807
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : chunk7B52C2XE_js.__privateGet(this, _useCache4)
|
|
808
|
+
}),
|
|
809
|
+
args
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
get(args, options) {
|
|
816
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
817
|
+
return this.callWithSession(
|
|
818
|
+
() => {
|
|
819
|
+
var _a, _b;
|
|
820
|
+
return getSubscription({
|
|
821
|
+
emitter: this._emitter,
|
|
822
|
+
apiService: this._inboxService,
|
|
823
|
+
cache: this.cache,
|
|
824
|
+
options: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, options), {
|
|
825
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : chunk7B52C2XE_js.__privateGet(this, _useCache4)
|
|
826
|
+
}),
|
|
827
|
+
args: chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, args), {
|
|
828
|
+
identifier: (_b = args.identifier) != null ? _b : chunkCDGREQFE_js.buildSubscriptionIdentifier({ topicKey: args.topicKey, subscriberId: chunk7B52C2XE_js.__privateGet(this, _subscriber).subscriberId })
|
|
829
|
+
})
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
create(args) {
|
|
836
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
837
|
+
return this.callWithSession(
|
|
838
|
+
() => createSubscription({
|
|
839
|
+
emitter: this._emitter,
|
|
840
|
+
apiService: this._inboxService,
|
|
841
|
+
cache: this.cache,
|
|
842
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache4),
|
|
843
|
+
args
|
|
844
|
+
})
|
|
845
|
+
);
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
update(args) {
|
|
849
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
850
|
+
return this.callWithSession(
|
|
851
|
+
() => updateSubscription({
|
|
852
|
+
emitter: this._emitter,
|
|
853
|
+
apiService: this._inboxService,
|
|
854
|
+
cache: this.cache,
|
|
855
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache4),
|
|
856
|
+
args
|
|
857
|
+
})
|
|
858
|
+
);
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
delete(args) {
|
|
862
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
863
|
+
return this.callWithSession(
|
|
864
|
+
() => deleteSubscription({
|
|
865
|
+
emitter: this._emitter,
|
|
866
|
+
apiService: this._inboxService,
|
|
867
|
+
args
|
|
868
|
+
})
|
|
869
|
+
);
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
_useCache4 = new WeakMap();
|
|
874
|
+
_subscriber = new WeakMap();
|
|
875
|
+
|
|
876
|
+
// src/api/http-client.ts
|
|
877
|
+
var DEFAULT_API_VERSION = "v1";
|
|
878
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.11.2-nightly.20251224.eb609546a3"}`;
|
|
879
|
+
var HttpClient = class {
|
|
880
|
+
constructor(options = {}) {
|
|
881
|
+
// Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
|
|
882
|
+
this.DEFAULT_BACKEND_URL = typeof window !== "undefined" && window.NOVU_LOCAL_BACKEND_URL || "https://api.novu.co";
|
|
883
|
+
const {
|
|
884
|
+
apiVersion = DEFAULT_API_VERSION,
|
|
885
|
+
apiUrl = this.DEFAULT_BACKEND_URL,
|
|
886
|
+
userAgent = DEFAULT_USER_AGENT,
|
|
887
|
+
headers = {}
|
|
888
|
+
} = options || {};
|
|
889
|
+
this.apiVersion = apiVersion;
|
|
890
|
+
this.apiUrl = `${apiUrl}/${apiVersion}`;
|
|
891
|
+
this.headers = chunk7B52C2XE_js.__spreadValues({
|
|
892
|
+
"Novu-API-Version": "2024-06-26",
|
|
893
|
+
"Content-Type": "application/json",
|
|
894
|
+
"User-Agent": userAgent
|
|
895
|
+
}, headers);
|
|
896
|
+
}
|
|
897
|
+
setAuthorizationToken(token) {
|
|
898
|
+
this.headers.Authorization = `Bearer ${token}`;
|
|
899
|
+
}
|
|
900
|
+
setKeylessHeader(identifier) {
|
|
901
|
+
var _a;
|
|
902
|
+
const keylessAppIdentifier = identifier || typeof window !== "undefined" && ((_a = window.localStorage) == null ? void 0 : _a.getItem("novu_keyless_application_identifier"));
|
|
903
|
+
if (!keylessAppIdentifier || !keylessAppIdentifier.startsWith("pk_keyless_")) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
this.headers["Novu-Application-Identifier"] = keylessAppIdentifier;
|
|
907
|
+
}
|
|
908
|
+
setHeaders(headers) {
|
|
909
|
+
this.headers = chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, this.headers), headers);
|
|
910
|
+
}
|
|
911
|
+
get(path, searchParams, unwrapEnvelope = true) {
|
|
912
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
913
|
+
return this.doFetch({
|
|
914
|
+
path,
|
|
915
|
+
searchParams,
|
|
916
|
+
options: {
|
|
917
|
+
method: "GET"
|
|
918
|
+
},
|
|
919
|
+
unwrapEnvelope
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
post(path, body, options) {
|
|
924
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
925
|
+
return this.doFetch({
|
|
926
|
+
path,
|
|
927
|
+
options: {
|
|
928
|
+
method: "POST",
|
|
929
|
+
body,
|
|
930
|
+
headers: options == null ? void 0 : options.headers
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
patch(path, body) {
|
|
936
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
937
|
+
return this.doFetch({
|
|
938
|
+
path,
|
|
939
|
+
options: {
|
|
940
|
+
method: "PATCH",
|
|
941
|
+
body
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
delete(path, body) {
|
|
947
|
+
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
948
|
+
return this.doFetch({
|
|
949
|
+
path,
|
|
950
|
+
options: {
|
|
951
|
+
method: "DELETE",
|
|
952
|
+
body
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
});
|
|
956
|
+
}
|
|
957
|
+
doFetch(_0) {
|
|
958
|
+
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
959
|
+
path,
|
|
960
|
+
searchParams,
|
|
961
|
+
options,
|
|
962
|
+
unwrapEnvelope = true
|
|
963
|
+
}) {
|
|
964
|
+
const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
|
|
965
|
+
const reqInit = {
|
|
966
|
+
method: (options == null ? void 0 : options.method) || "GET",
|
|
967
|
+
headers: chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
|
|
968
|
+
body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
|
|
969
|
+
};
|
|
970
|
+
const response = yield fetch(fullUrl, reqInit);
|
|
971
|
+
if (!response.ok) {
|
|
972
|
+
const errorData = yield response.json();
|
|
973
|
+
throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
|
|
974
|
+
}
|
|
975
|
+
if (response.status === 204) {
|
|
976
|
+
return void 0;
|
|
977
|
+
}
|
|
978
|
+
const res = yield response.json();
|
|
979
|
+
return unwrapEnvelope ? res.data : res;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
function combineUrl(...args) {
|
|
984
|
+
return args.reduce((acc, part) => {
|
|
985
|
+
if (part) {
|
|
986
|
+
acc.push(part.replace(new RegExp("(?<!https?:)\\/+", "g"), "/").replace(/^\/+|\/+$/g, ""));
|
|
987
|
+
}
|
|
988
|
+
return acc;
|
|
989
|
+
}, []).join("/").replace(/\/\?/, "?");
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// src/api/inbox-service.ts
|
|
993
|
+
var INBOX_ROUTE = "/inbox";
|
|
994
|
+
var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
|
|
995
|
+
var _httpClient;
|
|
996
|
+
var InboxService = class {
|
|
997
|
+
constructor(options = {}) {
|
|
998
|
+
this.isSessionInitialized = false;
|
|
999
|
+
chunk7B52C2XE_js.__privateAdd(this, _httpClient);
|
|
1000
|
+
chunk7B52C2XE_js.__privateSet(this, _httpClient, new HttpClient(options));
|
|
1001
|
+
}
|
|
1002
|
+
initializeSession(_0) {
|
|
1003
|
+
return chunk7B52C2XE_js.__async(this, arguments, function* ({
|
|
1004
|
+
applicationIdentifier,
|
|
1005
|
+
subscriberHash,
|
|
1006
|
+
contextHash,
|
|
1007
|
+
subscriber,
|
|
1008
|
+
defaultSchedule,
|
|
1009
|
+
context
|
|
1010
|
+
}) {
|
|
1011
|
+
const response = yield chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
|
|
1012
|
+
applicationIdentifier,
|
|
1013
|
+
subscriberHash,
|
|
1014
|
+
contextHash,
|
|
1015
|
+
subscriber,
|
|
1016
|
+
defaultSchedule,
|
|
1017
|
+
context
|
|
1018
|
+
});
|
|
1019
|
+
chunk7B52C2XE_js.__privateGet(this, _httpClient).setAuthorizationToken(response.token);
|
|
1020
|
+
chunk7B52C2XE_js.__privateGet(this, _httpClient).setKeylessHeader(response.applicationIdentifier);
|
|
1021
|
+
this.isSessionInitialized = true;
|
|
1022
|
+
return response;
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
fetchNotifications({
|
|
1026
|
+
after,
|
|
1027
|
+
archived,
|
|
1028
|
+
limit = 10,
|
|
1029
|
+
offset,
|
|
1030
|
+
read: read2,
|
|
1031
|
+
tags,
|
|
1032
|
+
snoozed,
|
|
1033
|
+
seen: seen2,
|
|
1034
|
+
data,
|
|
1035
|
+
severity
|
|
1036
|
+
}) {
|
|
1037
|
+
const searchParams = new URLSearchParams(`limit=${limit}`);
|
|
1038
|
+
if (after) {
|
|
1039
|
+
searchParams.append("after", after);
|
|
1040
|
+
}
|
|
1041
|
+
if (offset) {
|
|
1042
|
+
searchParams.append("offset", `${offset}`);
|
|
1043
|
+
}
|
|
1044
|
+
if (tags) {
|
|
1045
|
+
for (const tag of tags) {
|
|
1046
|
+
searchParams.append("tags[]", tag);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (read2 !== void 0) {
|
|
1050
|
+
searchParams.append("read", `${read2}`);
|
|
1051
|
+
}
|
|
1052
|
+
if (archived !== void 0) {
|
|
1053
|
+
searchParams.append("archived", `${archived}`);
|
|
1054
|
+
}
|
|
1055
|
+
if (snoozed !== void 0) {
|
|
1056
|
+
searchParams.append("snoozed", `${snoozed}`);
|
|
1057
|
+
}
|
|
1058
|
+
if (seen2 !== void 0) {
|
|
1059
|
+
searchParams.append("seen", `${seen2}`);
|
|
1060
|
+
}
|
|
1061
|
+
if (data !== void 0) {
|
|
1062
|
+
searchParams.append("data", JSON.stringify(data));
|
|
1063
|
+
}
|
|
1064
|
+
if (severity && Array.isArray(severity)) {
|
|
1065
|
+
for (const el of severity) {
|
|
1066
|
+
searchParams.append("severity[]", el);
|
|
1067
|
+
}
|
|
1068
|
+
} else if (severity) {
|
|
1069
|
+
searchParams.append("severity", severity);
|
|
1070
|
+
}
|
|
1071
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
|
|
1072
|
+
}
|
|
1073
|
+
count({
|
|
1074
|
+
filters
|
|
1075
|
+
}) {
|
|
1076
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(
|
|
1077
|
+
`${INBOX_NOTIFICATIONS_ROUTE}/count`,
|
|
1078
|
+
new URLSearchParams({
|
|
1079
|
+
filters: JSON.stringify(filters)
|
|
1080
|
+
}),
|
|
1081
|
+
false
|
|
1082
|
+
);
|
|
1083
|
+
}
|
|
1084
|
+
read(notificationId) {
|
|
1085
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
|
|
1086
|
+
}
|
|
1087
|
+
unread(notificationId) {
|
|
1088
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
|
|
1089
|
+
}
|
|
1090
|
+
archive(notificationId) {
|
|
1091
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
|
|
1092
|
+
}
|
|
1093
|
+
unarchive(notificationId) {
|
|
1094
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
|
|
1095
|
+
}
|
|
1096
|
+
snooze(notificationId, snoozeUntil) {
|
|
1097
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/snooze`, { snoozeUntil });
|
|
1098
|
+
}
|
|
1099
|
+
unsnooze(notificationId) {
|
|
1100
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unsnooze`);
|
|
1101
|
+
}
|
|
1102
|
+
readAll({ tags, data }) {
|
|
1103
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, {
|
|
1104
|
+
tags,
|
|
1105
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
archiveAll({ tags, data }) {
|
|
1109
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, {
|
|
1110
|
+
tags,
|
|
1111
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
archiveAllRead({ tags, data }) {
|
|
1115
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, {
|
|
1116
|
+
tags,
|
|
1117
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
delete(notificationId) {
|
|
1121
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).delete(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/delete`);
|
|
1122
|
+
}
|
|
1123
|
+
deleteAll({ tags, data }) {
|
|
1124
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/delete`, {
|
|
1125
|
+
tags,
|
|
1126
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
markAsSeen({
|
|
1130
|
+
notificationIds,
|
|
1131
|
+
tags,
|
|
1132
|
+
data
|
|
1133
|
+
}) {
|
|
1134
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/seen`, {
|
|
1135
|
+
notificationIds,
|
|
1136
|
+
tags,
|
|
1137
|
+
data: data ? JSON.stringify(data) : void 0
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
seen(notificationId) {
|
|
1141
|
+
return this.markAsSeen({ notificationIds: [notificationId] });
|
|
1142
|
+
}
|
|
1143
|
+
completeAction({
|
|
1144
|
+
actionType,
|
|
1145
|
+
notificationId
|
|
1146
|
+
}) {
|
|
1147
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
|
|
1148
|
+
actionType
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
revertAction({
|
|
1152
|
+
actionType,
|
|
1153
|
+
notificationId
|
|
1154
|
+
}) {
|
|
1155
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
|
|
1156
|
+
actionType
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
fetchPreferences({
|
|
1160
|
+
tags,
|
|
1161
|
+
severity,
|
|
1162
|
+
criticality
|
|
1163
|
+
}) {
|
|
1164
|
+
const queryParams = new URLSearchParams();
|
|
1165
|
+
if (tags) {
|
|
1166
|
+
for (const tag of tags) {
|
|
1167
|
+
queryParams.append("tags[]", tag);
|
|
1071
1168
|
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1077
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1078
|
-
args: {
|
|
1079
|
-
notification: this,
|
|
1080
|
-
snoozeUntil
|
|
1169
|
+
}
|
|
1170
|
+
if (severity && Array.isArray(severity)) {
|
|
1171
|
+
for (const el of severity) {
|
|
1172
|
+
queryParams.append("severity[]", el);
|
|
1081
1173
|
}
|
|
1082
|
-
})
|
|
1174
|
+
} else if (severity) {
|
|
1175
|
+
queryParams.append("severity", severity);
|
|
1176
|
+
}
|
|
1177
|
+
if (criticality) {
|
|
1178
|
+
queryParams.append("criticality", criticality);
|
|
1179
|
+
}
|
|
1180
|
+
const query = queryParams.size ? `?${queryParams.toString()}` : "";
|
|
1181
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
|
|
1083
1182
|
}
|
|
1084
|
-
|
|
1085
|
-
return
|
|
1086
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1087
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1088
|
-
args: { notification: this }
|
|
1089
|
-
});
|
|
1183
|
+
bulkUpdatePreferences(preferences) {
|
|
1184
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
1090
1185
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
throw new Error("Primary action is not available");
|
|
1094
|
-
}
|
|
1095
|
-
return completeAction({
|
|
1096
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1097
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1098
|
-
args: {
|
|
1099
|
-
notification: this
|
|
1100
|
-
},
|
|
1101
|
-
actionType: "primary" /* PRIMARY */
|
|
1102
|
-
});
|
|
1186
|
+
updateGlobalPreferences(preferences) {
|
|
1187
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, preferences);
|
|
1103
1188
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
return
|
|
1109
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1110
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1111
|
-
args: {
|
|
1112
|
-
notification: this
|
|
1113
|
-
},
|
|
1114
|
-
actionType: "secondary" /* SECONDARY */
|
|
1115
|
-
});
|
|
1189
|
+
updateWorkflowPreferences({
|
|
1190
|
+
workflowId,
|
|
1191
|
+
channels
|
|
1192
|
+
}) {
|
|
1193
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
|
|
1116
1194
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
throw new Error("Primary action is not available");
|
|
1120
|
-
}
|
|
1121
|
-
return revertAction({
|
|
1122
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1123
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1124
|
-
args: {
|
|
1125
|
-
notification: this
|
|
1126
|
-
},
|
|
1127
|
-
actionType: "primary" /* PRIMARY */
|
|
1128
|
-
});
|
|
1195
|
+
fetchGlobalPreferences() {
|
|
1196
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences/global`);
|
|
1129
1197
|
}
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter),
|
|
1136
|
-
apiService: chunk7B52C2XE_js.__privateGet(this, _inboxService),
|
|
1137
|
-
args: {
|
|
1138
|
-
notification: this
|
|
1198
|
+
triggerHelloWorldEvent() {
|
|
1199
|
+
const payload = {
|
|
1200
|
+
name: "hello-world",
|
|
1201
|
+
to: {
|
|
1202
|
+
subscriberId: "keyless-subscriber-id"
|
|
1139
1203
|
},
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1204
|
+
payload: {
|
|
1205
|
+
subject: "Novu Keyless Environment",
|
|
1206
|
+
body: "You're using a keyless demo environment. For full access to Novu features and cloud integration, obtain your API key.",
|
|
1207
|
+
primaryActionText: "Obtain API Key",
|
|
1208
|
+
primaryActionUrl: "https://go.novu.co/keyless",
|
|
1209
|
+
secondaryActionText: "Explore Documentation",
|
|
1210
|
+
secondaryActionUrl: "https://go.novu.co/keyless-docs"
|
|
1211
|
+
}
|
|
1147
1212
|
};
|
|
1213
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post("/inbox/events", payload);
|
|
1148
1214
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1215
|
+
fetchSubscriptions(topicKey) {
|
|
1216
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`);
|
|
1217
|
+
}
|
|
1218
|
+
getSubscription(topicKey, identifier, workflowIds, tags) {
|
|
1219
|
+
const searchParams = new URLSearchParams();
|
|
1220
|
+
if (workflowIds == null ? void 0 : workflowIds.length)
|
|
1221
|
+
for (const workflowIdentifier of workflowIds) searchParams.append("workflowIds", workflowIdentifier);
|
|
1222
|
+
if (tags == null ? void 0 : tags.length) for (const tag of tags) searchParams.append("tags", tag);
|
|
1223
|
+
const query = searchParams.size ? `?${searchParams.toString()}` : "";
|
|
1224
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${identifier}${query}`);
|
|
1225
|
+
}
|
|
1226
|
+
createSubscription({
|
|
1227
|
+
identifier,
|
|
1228
|
+
name,
|
|
1229
|
+
topicKey,
|
|
1230
|
+
topicName,
|
|
1231
|
+
preferences
|
|
1232
|
+
}) {
|
|
1233
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).post(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`, chunk7B52C2XE_js.__spreadValues(chunk7B52C2XE_js.__spreadValues({
|
|
1234
|
+
identifier,
|
|
1235
|
+
name
|
|
1236
|
+
}, topicName && { topic: { name: topicName } }), preferences !== void 0 && { preferences }));
|
|
1237
|
+
}
|
|
1238
|
+
updateSubscription({
|
|
1239
|
+
topicKey,
|
|
1240
|
+
subscriptionId,
|
|
1241
|
+
name,
|
|
1242
|
+
preferences
|
|
1243
|
+
}) {
|
|
1244
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`, chunk7B52C2XE_js.__spreadValues({
|
|
1245
|
+
name
|
|
1246
|
+
}, preferences !== void 0 && { preferences }));
|
|
1155
1247
|
}
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1248
|
+
updateSubscriptionPreference({
|
|
1249
|
+
subscriptionId,
|
|
1250
|
+
workflowId,
|
|
1251
|
+
enabled,
|
|
1252
|
+
condition,
|
|
1253
|
+
email,
|
|
1254
|
+
sms,
|
|
1255
|
+
in_app,
|
|
1256
|
+
chat,
|
|
1257
|
+
push
|
|
1166
1258
|
}) {
|
|
1167
|
-
chunk7B52C2XE_js.
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
resolve(yield fn());
|
|
1176
|
-
}));
|
|
1177
|
-
chunk7B52C2XE_js.__privateSet(this, _callsQueue, []);
|
|
1178
|
-
} else if (error) {
|
|
1179
|
-
this.onSessionError(error);
|
|
1180
|
-
chunk7B52C2XE_js.__privateSet(this, _sessionError, error);
|
|
1181
|
-
chunk7B52C2XE_js.__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
1182
|
-
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
1183
|
-
});
|
|
1184
|
-
chunk7B52C2XE_js.__privateSet(this, _callsQueue, []);
|
|
1185
|
-
}
|
|
1259
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/subscriptions/${subscriptionId}/preferences/${workflowId}`, {
|
|
1260
|
+
enabled,
|
|
1261
|
+
condition,
|
|
1262
|
+
email,
|
|
1263
|
+
sms,
|
|
1264
|
+
in_app,
|
|
1265
|
+
chat,
|
|
1266
|
+
push
|
|
1186
1267
|
});
|
|
1187
1268
|
}
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
onSessionError(_) {
|
|
1269
|
+
bulkUpdateSubscriptionPreferences(preferences) {
|
|
1270
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
1191
1271
|
}
|
|
1192
|
-
|
|
1193
|
-
return chunk7B52C2XE_js.
|
|
1194
|
-
if (this._inboxService.isSessionInitialized) {
|
|
1195
|
-
return fn();
|
|
1196
|
-
}
|
|
1197
|
-
if (chunk7B52C2XE_js.__privateGet(this, _sessionError)) {
|
|
1198
|
-
return Promise.resolve({
|
|
1199
|
-
error: new NovuError("Failed to initialize session, please contact the support", chunk7B52C2XE_js.__privateGet(this, _sessionError))
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
return new Promise((resolve, reject) => {
|
|
1203
|
-
chunk7B52C2XE_js.__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
1204
|
-
});
|
|
1205
|
-
});
|
|
1272
|
+
deleteSubscription({ topicKey, subscriptionId }) {
|
|
1273
|
+
return chunk7B52C2XE_js.__privateGet(this, _httpClient).delete(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`);
|
|
1206
1274
|
}
|
|
1207
1275
|
};
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
// src/cache/in-memory-cache.ts
|
|
1212
|
-
var _cache;
|
|
1213
|
-
var InMemoryCache = class {
|
|
1276
|
+
_httpClient = new WeakMap();
|
|
1277
|
+
var _mittEmitter;
|
|
1278
|
+
var NovuEventEmitter = class {
|
|
1214
1279
|
constructor() {
|
|
1215
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1216
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1217
|
-
}
|
|
1218
|
-
get(key) {
|
|
1219
|
-
return chunk7B52C2XE_js.__privateGet(this, _cache).get(key);
|
|
1220
|
-
}
|
|
1221
|
-
getValues() {
|
|
1222
|
-
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache).values());
|
|
1223
|
-
}
|
|
1224
|
-
entries() {
|
|
1225
|
-
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache).entries());
|
|
1226
|
-
}
|
|
1227
|
-
keys() {
|
|
1228
|
-
return Array.from(chunk7B52C2XE_js.__privateGet(this, _cache).keys());
|
|
1280
|
+
chunk7B52C2XE_js.__privateAdd(this, _mittEmitter);
|
|
1281
|
+
chunk7B52C2XE_js.__privateSet(this, _mittEmitter, mitt__default.default());
|
|
1229
1282
|
}
|
|
1230
|
-
|
|
1231
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1283
|
+
on(eventName, listener) {
|
|
1284
|
+
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).on(eventName, listener);
|
|
1285
|
+
return () => {
|
|
1286
|
+
this.off(eventName, listener);
|
|
1287
|
+
};
|
|
1232
1288
|
}
|
|
1233
|
-
|
|
1234
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1289
|
+
off(eventName, listener) {
|
|
1290
|
+
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).off(eventName, listener);
|
|
1235
1291
|
}
|
|
1236
|
-
|
|
1237
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1292
|
+
emit(type, event) {
|
|
1293
|
+
chunk7B52C2XE_js.__privateGet(this, _mittEmitter).emit(type, event);
|
|
1238
1294
|
}
|
|
1239
1295
|
};
|
|
1240
|
-
|
|
1296
|
+
_mittEmitter = new WeakMap();
|
|
1241
1297
|
|
|
1242
1298
|
// src/cache/notifications-cache.ts
|
|
1243
1299
|
var excludeEmpty = ({
|
|
@@ -1305,16 +1361,17 @@ var removeEvents = [
|
|
|
1305
1361
|
"notifications.archive_all_read.pending",
|
|
1306
1362
|
"notifications.delete_all.pending"
|
|
1307
1363
|
];
|
|
1308
|
-
var
|
|
1364
|
+
var _emitter4, _inboxService4, _cache5;
|
|
1309
1365
|
var NotificationsCache = class {
|
|
1310
|
-
constructor({ emitter }) {
|
|
1311
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1366
|
+
constructor({ emitter, inboxService }) {
|
|
1367
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter4);
|
|
1368
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService4);
|
|
1312
1369
|
/**
|
|
1313
1370
|
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
1314
1371
|
*/
|
|
1315
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1372
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache5);
|
|
1316
1373
|
this.updateNotification = (key, data) => {
|
|
1317
|
-
const notificationsResponse = chunk7B52C2XE_js.__privateGet(this,
|
|
1374
|
+
const notificationsResponse = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
|
|
1318
1375
|
if (!notificationsResponse) {
|
|
1319
1376
|
return false;
|
|
1320
1377
|
}
|
|
@@ -1324,11 +1381,11 @@ var NotificationsCache = class {
|
|
|
1324
1381
|
}
|
|
1325
1382
|
const updatedNotifications = [...notificationsResponse.notifications];
|
|
1326
1383
|
updatedNotifications[index] = data;
|
|
1327
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1384
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).set(key, chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
|
|
1328
1385
|
return true;
|
|
1329
1386
|
};
|
|
1330
1387
|
this.removeNotification = (key, data) => {
|
|
1331
|
-
const notificationsResponse = chunk7B52C2XE_js.__privateGet(this,
|
|
1388
|
+
const notificationsResponse = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
|
|
1332
1389
|
if (!notificationsResponse) {
|
|
1333
1390
|
return false;
|
|
1334
1391
|
}
|
|
@@ -1338,7 +1395,7 @@ var NotificationsCache = class {
|
|
|
1338
1395
|
}
|
|
1339
1396
|
const newNotifications = [...notificationsResponse.notifications];
|
|
1340
1397
|
newNotifications.splice(index, 1);
|
|
1341
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1398
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).set(key, chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, notificationsResponse), {
|
|
1342
1399
|
notifications: newNotifications
|
|
1343
1400
|
}));
|
|
1344
1401
|
return true;
|
|
@@ -1357,8 +1414,8 @@ var NotificationsCache = class {
|
|
|
1357
1414
|
notifications = [args.notification];
|
|
1358
1415
|
} else if ("notificationId" in args && args.notificationId) {
|
|
1359
1416
|
const foundNotifications = [];
|
|
1360
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1361
|
-
const cachedResponse = chunk7B52C2XE_js.__privateGet(this,
|
|
1417
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).keys().forEach((key) => {
|
|
1418
|
+
const cachedResponse = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
|
|
1362
1419
|
if (cachedResponse) {
|
|
1363
1420
|
const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
|
|
1364
1421
|
if (found) {
|
|
@@ -1373,7 +1430,7 @@ var NotificationsCache = class {
|
|
|
1373
1430
|
return;
|
|
1374
1431
|
}
|
|
1375
1432
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1376
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1433
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).keys().forEach((key) => {
|
|
1377
1434
|
notifications.forEach((notification) => {
|
|
1378
1435
|
let isNotificationFound = false;
|
|
1379
1436
|
if (remove) {
|
|
@@ -1388,26 +1445,27 @@ var NotificationsCache = class {
|
|
|
1388
1445
|
});
|
|
1389
1446
|
uniqueFilterKeys.forEach((key) => {
|
|
1390
1447
|
const notificationsResponse = this.getAggregated(getFilter(key));
|
|
1391
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1448
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
1392
1449
|
data: notificationsResponse
|
|
1393
1450
|
});
|
|
1394
1451
|
});
|
|
1395
1452
|
};
|
|
1396
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1453
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter4, emitter);
|
|
1454
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService4, inboxService);
|
|
1397
1455
|
updateEvents.forEach((event) => {
|
|
1398
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1456
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter4).on(event, this.handleNotificationEvent());
|
|
1399
1457
|
});
|
|
1400
1458
|
removeEvents.forEach((event) => {
|
|
1401
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1459
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter4).on(event, this.handleNotificationEvent({ remove: true }));
|
|
1402
1460
|
});
|
|
1403
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1461
|
+
chunk7B52C2XE_js.__privateSet(this, _cache5, new InMemoryCache());
|
|
1404
1462
|
}
|
|
1405
1463
|
getAggregated(filter) {
|
|
1406
|
-
const cacheKeys = chunk7B52C2XE_js.__privateGet(this,
|
|
1464
|
+
const cacheKeys = chunk7B52C2XE_js.__privateGet(this, _cache5).keys().filter((key) => {
|
|
1407
1465
|
const parsedFilter = getFilter(key);
|
|
1408
1466
|
return isSameFilter(parsedFilter, filter);
|
|
1409
1467
|
});
|
|
1410
|
-
return cacheKeys.map((key) => chunk7B52C2XE_js.__privateGet(this,
|
|
1468
|
+
return cacheKeys.map((key) => chunk7B52C2XE_js.__privateGet(this, _cache5).get(key)).reduce(
|
|
1411
1469
|
(acc, el) => {
|
|
1412
1470
|
if (!el) {
|
|
1413
1471
|
return acc;
|
|
@@ -1421,16 +1479,35 @@ var NotificationsCache = class {
|
|
|
1421
1479
|
{ hasMore: false, filter: {}, notifications: [] }
|
|
1422
1480
|
);
|
|
1423
1481
|
}
|
|
1482
|
+
get(args) {
|
|
1483
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache5).get(getCacheKey(args));
|
|
1484
|
+
}
|
|
1424
1485
|
has(args) {
|
|
1425
|
-
return chunk7B52C2XE_js.__privateGet(this,
|
|
1486
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache5).get(getCacheKey(args)) !== void 0;
|
|
1426
1487
|
}
|
|
1427
1488
|
set(args, data) {
|
|
1428
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1489
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).set(getCacheKey(args), data);
|
|
1490
|
+
}
|
|
1491
|
+
unshift(args, notification) {
|
|
1492
|
+
const cacheKey = getCacheKey(args);
|
|
1493
|
+
const cachedData = chunk7B52C2XE_js.__privateGet(this, _cache5).get(cacheKey) || {
|
|
1494
|
+
hasMore: false,
|
|
1495
|
+
filter: getFilter(cacheKey),
|
|
1496
|
+
notifications: []
|
|
1497
|
+
};
|
|
1498
|
+
const notificationInstance = chunkCDGREQFE_js.createNotification({
|
|
1499
|
+
notification: chunk7B52C2XE_js.__spreadValues({}, notification),
|
|
1500
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter4),
|
|
1501
|
+
inboxService: chunk7B52C2XE_js.__privateGet(this, _inboxService4)
|
|
1502
|
+
});
|
|
1503
|
+
this.update(args, chunk7B52C2XE_js.__spreadProps(chunk7B52C2XE_js.__spreadValues({}, cachedData), {
|
|
1504
|
+
notifications: [notificationInstance, ...cachedData.notifications]
|
|
1505
|
+
}));
|
|
1429
1506
|
}
|
|
1430
1507
|
update(args, data) {
|
|
1431
1508
|
this.set(args, data);
|
|
1432
1509
|
const notificationsResponse = this.getAggregated(getFilter(getCacheKey(args)));
|
|
1433
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1510
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
1434
1511
|
data: notificationsResponse
|
|
1435
1512
|
});
|
|
1436
1513
|
}
|
|
@@ -1456,12 +1533,12 @@ var NotificationsCache = class {
|
|
|
1456
1533
|
read: read2,
|
|
1457
1534
|
data
|
|
1458
1535
|
}) {
|
|
1459
|
-
const keys = chunk7B52C2XE_js.__privateGet(this,
|
|
1536
|
+
const keys = chunk7B52C2XE_js.__privateGet(this, _cache5).keys();
|
|
1460
1537
|
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
1461
1538
|
keys.forEach((key) => {
|
|
1462
1539
|
const filter = getFilter(key);
|
|
1463
1540
|
if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
|
|
1464
|
-
const value = chunk7B52C2XE_js.__privateGet(this,
|
|
1541
|
+
const value = chunk7B52C2XE_js.__privateGet(this, _cache5).get(key);
|
|
1465
1542
|
if (!value) {
|
|
1466
1543
|
return;
|
|
1467
1544
|
}
|
|
@@ -1473,22 +1550,23 @@ var NotificationsCache = class {
|
|
|
1473
1550
|
return Array.from(uniqueNotifications.values());
|
|
1474
1551
|
}
|
|
1475
1552
|
clear(filter) {
|
|
1476
|
-
const keys = chunk7B52C2XE_js.__privateGet(this,
|
|
1553
|
+
const keys = chunk7B52C2XE_js.__privateGet(this, _cache5).keys();
|
|
1477
1554
|
keys.forEach((key) => {
|
|
1478
1555
|
if (isSameFilter(getFilter(key), filter)) {
|
|
1479
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1556
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).remove(key);
|
|
1480
1557
|
}
|
|
1481
1558
|
});
|
|
1482
1559
|
}
|
|
1483
1560
|
clearAll() {
|
|
1484
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
1561
|
+
chunk7B52C2XE_js.__privateGet(this, _cache5).clear();
|
|
1485
1562
|
}
|
|
1486
1563
|
};
|
|
1487
|
-
|
|
1488
|
-
|
|
1564
|
+
_emitter4 = new WeakMap();
|
|
1565
|
+
_inboxService4 = new WeakMap();
|
|
1566
|
+
_cache5 = new WeakMap();
|
|
1489
1567
|
|
|
1490
1568
|
// src/notifications/notifications.ts
|
|
1491
|
-
var
|
|
1569
|
+
var _useCache5;
|
|
1492
1570
|
var Notifications = class extends BaseModule {
|
|
1493
1571
|
constructor({
|
|
1494
1572
|
useCache,
|
|
@@ -1499,14 +1577,12 @@ var Notifications = class extends BaseModule {
|
|
|
1499
1577
|
eventEmitterInstance,
|
|
1500
1578
|
inboxServiceInstance
|
|
1501
1579
|
});
|
|
1502
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1580
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache5);
|
|
1503
1581
|
this.cache = new NotificationsCache({
|
|
1504
|
-
emitter: eventEmitterInstance
|
|
1582
|
+
emitter: eventEmitterInstance,
|
|
1583
|
+
inboxService: inboxServiceInstance
|
|
1505
1584
|
});
|
|
1506
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1507
|
-
}
|
|
1508
|
-
get inboxService() {
|
|
1509
|
-
return this._inboxService;
|
|
1585
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache5, useCache);
|
|
1510
1586
|
}
|
|
1511
1587
|
list() {
|
|
1512
1588
|
return chunk7B52C2XE_js.__async(this, arguments, function* (_a = {}) {
|
|
@@ -1514,7 +1590,7 @@ var Notifications = class extends BaseModule {
|
|
|
1514
1590
|
return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1515
1591
|
const args = chunk7B52C2XE_js.__spreadValues({ limit }, restOptions);
|
|
1516
1592
|
try {
|
|
1517
|
-
const shouldUseCache = "useCache" in args ? args.useCache : chunk7B52C2XE_js.__privateGet(this,
|
|
1593
|
+
const shouldUseCache = "useCache" in args ? args.useCache : chunk7B52C2XE_js.__privateGet(this, _useCache5);
|
|
1518
1594
|
let data = shouldUseCache ? this.cache.getAll(args) : void 0;
|
|
1519
1595
|
this._emitter.emit("notifications.list.pending", { args, data });
|
|
1520
1596
|
if (!data) {
|
|
@@ -1524,7 +1600,7 @@ var Notifications = class extends BaseModule {
|
|
|
1524
1600
|
data = {
|
|
1525
1601
|
hasMore: response.hasMore,
|
|
1526
1602
|
filter: response.filter,
|
|
1527
|
-
notifications: response.data.map((el) => new Notification(el, this._emitter, this._inboxService))
|
|
1603
|
+
notifications: response.data.map((el) => new chunkCDGREQFE_js.Notification(el, this._emitter, this._inboxService))
|
|
1528
1604
|
};
|
|
1529
1605
|
if (shouldUseCache) {
|
|
1530
1606
|
this.cache.set(args, data);
|
|
@@ -1535,7 +1611,7 @@ var Notifications = class extends BaseModule {
|
|
|
1535
1611
|
return { data };
|
|
1536
1612
|
} catch (error) {
|
|
1537
1613
|
this._emitter.emit("notifications.list.resolved", { args, error });
|
|
1538
|
-
return { error: new NovuError("Failed to fetch notifications", error) };
|
|
1614
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to fetch notifications", error) };
|
|
1539
1615
|
}
|
|
1540
1616
|
}));
|
|
1541
1617
|
});
|
|
@@ -1557,7 +1633,7 @@ var Notifications = class extends BaseModule {
|
|
|
1557
1633
|
return { data };
|
|
1558
1634
|
} catch (error) {
|
|
1559
1635
|
this._emitter.emit("notifications.count.resolved", { args, error });
|
|
1560
|
-
return { error: new NovuError("Failed to count notifications", error) };
|
|
1636
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to count notifications", error) };
|
|
1561
1637
|
}
|
|
1562
1638
|
}));
|
|
1563
1639
|
});
|
|
@@ -1566,7 +1642,7 @@ var Notifications = class extends BaseModule {
|
|
|
1566
1642
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1567
1643
|
return this.callWithSession(
|
|
1568
1644
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1569
|
-
return read({
|
|
1645
|
+
return chunkCDGREQFE_js.read({
|
|
1570
1646
|
emitter: this._emitter,
|
|
1571
1647
|
apiService: this._inboxService,
|
|
1572
1648
|
args
|
|
@@ -1579,7 +1655,7 @@ var Notifications = class extends BaseModule {
|
|
|
1579
1655
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1580
1656
|
return this.callWithSession(
|
|
1581
1657
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1582
|
-
return unread({
|
|
1658
|
+
return chunkCDGREQFE_js.unread({
|
|
1583
1659
|
emitter: this._emitter,
|
|
1584
1660
|
apiService: this._inboxService,
|
|
1585
1661
|
args
|
|
@@ -1592,7 +1668,7 @@ var Notifications = class extends BaseModule {
|
|
|
1592
1668
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1593
1669
|
return this.callWithSession(
|
|
1594
1670
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1595
|
-
return seen({
|
|
1671
|
+
return chunkCDGREQFE_js.seen({
|
|
1596
1672
|
emitter: this._emitter,
|
|
1597
1673
|
apiService: this._inboxService,
|
|
1598
1674
|
args
|
|
@@ -1605,7 +1681,7 @@ var Notifications = class extends BaseModule {
|
|
|
1605
1681
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1606
1682
|
return this.callWithSession(
|
|
1607
1683
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1608
|
-
return archive({
|
|
1684
|
+
return chunkCDGREQFE_js.archive({
|
|
1609
1685
|
emitter: this._emitter,
|
|
1610
1686
|
apiService: this._inboxService,
|
|
1611
1687
|
args
|
|
@@ -1618,7 +1694,7 @@ var Notifications = class extends BaseModule {
|
|
|
1618
1694
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1619
1695
|
return this.callWithSession(
|
|
1620
1696
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1621
|
-
return unarchive({
|
|
1697
|
+
return chunkCDGREQFE_js.unarchive({
|
|
1622
1698
|
emitter: this._emitter,
|
|
1623
1699
|
apiService: this._inboxService,
|
|
1624
1700
|
args
|
|
@@ -1631,7 +1707,7 @@ var Notifications = class extends BaseModule {
|
|
|
1631
1707
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1632
1708
|
return this.callWithSession(
|
|
1633
1709
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1634
|
-
return deleteNotification({
|
|
1710
|
+
return chunkCDGREQFE_js.deleteNotification({
|
|
1635
1711
|
emitter: this._emitter,
|
|
1636
1712
|
apiService: this._inboxService,
|
|
1637
1713
|
args
|
|
@@ -1644,7 +1720,7 @@ var Notifications = class extends BaseModule {
|
|
|
1644
1720
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1645
1721
|
return this.callWithSession(
|
|
1646
1722
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1647
|
-
return snooze({
|
|
1723
|
+
return chunkCDGREQFE_js.snooze({
|
|
1648
1724
|
emitter: this._emitter,
|
|
1649
1725
|
apiService: this._inboxService,
|
|
1650
1726
|
args
|
|
@@ -1657,7 +1733,7 @@ var Notifications = class extends BaseModule {
|
|
|
1657
1733
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1658
1734
|
return this.callWithSession(
|
|
1659
1735
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1660
|
-
return unsnooze({
|
|
1736
|
+
return chunkCDGREQFE_js.unsnooze({
|
|
1661
1737
|
emitter: this._emitter,
|
|
1662
1738
|
apiService: this._inboxService,
|
|
1663
1739
|
args
|
|
@@ -1670,7 +1746,7 @@ var Notifications = class extends BaseModule {
|
|
|
1670
1746
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1671
1747
|
return this.callWithSession(
|
|
1672
1748
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1673
|
-
return completeAction({
|
|
1749
|
+
return chunkCDGREQFE_js.completeAction({
|
|
1674
1750
|
emitter: this._emitter,
|
|
1675
1751
|
apiService: this._inboxService,
|
|
1676
1752
|
args,
|
|
@@ -1684,7 +1760,7 @@ var Notifications = class extends BaseModule {
|
|
|
1684
1760
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1685
1761
|
return this.callWithSession(
|
|
1686
1762
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1687
|
-
return completeAction({
|
|
1763
|
+
return chunkCDGREQFE_js.completeAction({
|
|
1688
1764
|
emitter: this._emitter,
|
|
1689
1765
|
apiService: this._inboxService,
|
|
1690
1766
|
args,
|
|
@@ -1698,7 +1774,7 @@ var Notifications = class extends BaseModule {
|
|
|
1698
1774
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1699
1775
|
return this.callWithSession(
|
|
1700
1776
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1701
|
-
return revertAction({
|
|
1777
|
+
return chunkCDGREQFE_js.revertAction({
|
|
1702
1778
|
emitter: this._emitter,
|
|
1703
1779
|
apiService: this._inboxService,
|
|
1704
1780
|
args,
|
|
@@ -1712,7 +1788,7 @@ var Notifications = class extends BaseModule {
|
|
|
1712
1788
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1713
1789
|
return this.callWithSession(
|
|
1714
1790
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1715
|
-
return revertAction({
|
|
1791
|
+
return chunkCDGREQFE_js.revertAction({
|
|
1716
1792
|
emitter: this._emitter,
|
|
1717
1793
|
apiService: this._inboxService,
|
|
1718
1794
|
args,
|
|
@@ -1729,7 +1805,7 @@ var Notifications = class extends BaseModule {
|
|
|
1729
1805
|
} = {}) {
|
|
1730
1806
|
return this.callWithSession(
|
|
1731
1807
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1732
|
-
return readAll({
|
|
1808
|
+
return chunkCDGREQFE_js.readAll({
|
|
1733
1809
|
emitter: this._emitter,
|
|
1734
1810
|
inboxService: this._inboxService,
|
|
1735
1811
|
notificationsCache: this.cache,
|
|
@@ -1744,14 +1820,14 @@ var Notifications = class extends BaseModule {
|
|
|
1744
1820
|
return chunk7B52C2XE_js.__async(this, arguments, function* (args = {}) {
|
|
1745
1821
|
return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1746
1822
|
if ("notificationIds" in args) {
|
|
1747
|
-
return seenAll({
|
|
1823
|
+
return chunkCDGREQFE_js.seenAll({
|
|
1748
1824
|
emitter: this._emitter,
|
|
1749
1825
|
inboxService: this._inboxService,
|
|
1750
1826
|
notificationsCache: this.cache,
|
|
1751
1827
|
notificationIds: args.notificationIds
|
|
1752
1828
|
});
|
|
1753
1829
|
} else {
|
|
1754
|
-
return seenAll({
|
|
1830
|
+
return chunkCDGREQFE_js.seenAll({
|
|
1755
1831
|
emitter: this._emitter,
|
|
1756
1832
|
inboxService: this._inboxService,
|
|
1757
1833
|
notificationsCache: this.cache,
|
|
@@ -1769,7 +1845,7 @@ var Notifications = class extends BaseModule {
|
|
|
1769
1845
|
} = {}) {
|
|
1770
1846
|
return this.callWithSession(
|
|
1771
1847
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1772
|
-
return archiveAll({
|
|
1848
|
+
return chunkCDGREQFE_js.archiveAll({
|
|
1773
1849
|
emitter: this._emitter,
|
|
1774
1850
|
inboxService: this._inboxService,
|
|
1775
1851
|
notificationsCache: this.cache,
|
|
@@ -1784,7 +1860,7 @@ var Notifications = class extends BaseModule {
|
|
|
1784
1860
|
return chunk7B52C2XE_js.__async(this, arguments, function* ({ tags, data } = {}) {
|
|
1785
1861
|
return this.callWithSession(
|
|
1786
1862
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1787
|
-
return archiveAllRead({
|
|
1863
|
+
return chunkCDGREQFE_js.archiveAllRead({
|
|
1788
1864
|
emitter: this._emitter,
|
|
1789
1865
|
inboxService: this._inboxService,
|
|
1790
1866
|
notificationsCache: this.cache,
|
|
@@ -1802,7 +1878,7 @@ var Notifications = class extends BaseModule {
|
|
|
1802
1878
|
} = {}) {
|
|
1803
1879
|
return this.callWithSession(
|
|
1804
1880
|
() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
1805
|
-
return deleteAll({
|
|
1881
|
+
return chunkCDGREQFE_js.deleteAll({
|
|
1806
1882
|
emitter: this._emitter,
|
|
1807
1883
|
inboxService: this._inboxService,
|
|
1808
1884
|
notificationsCache: this.cache,
|
|
@@ -1826,10 +1902,10 @@ var Notifications = class extends BaseModule {
|
|
|
1826
1902
|
});
|
|
1827
1903
|
}
|
|
1828
1904
|
};
|
|
1829
|
-
|
|
1905
|
+
_useCache5 = new WeakMap();
|
|
1830
1906
|
|
|
1831
1907
|
// src/preferences/schedule.ts
|
|
1832
|
-
var
|
|
1908
|
+
var _emitter5, _apiService, _cache6, _useCache6;
|
|
1833
1909
|
var Schedule = class {
|
|
1834
1910
|
constructor(schedule, {
|
|
1835
1911
|
emitterInstance,
|
|
@@ -1837,14 +1913,14 @@ var Schedule = class {
|
|
|
1837
1913
|
cache,
|
|
1838
1914
|
useCache
|
|
1839
1915
|
}) {
|
|
1840
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1916
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter5);
|
|
1841
1917
|
chunk7B52C2XE_js.__privateAdd(this, _apiService);
|
|
1842
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1843
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1844
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1918
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache6);
|
|
1919
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache6);
|
|
1920
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter5, emitterInstance);
|
|
1845
1921
|
chunk7B52C2XE_js.__privateSet(this, _apiService, inboxServiceInstance);
|
|
1846
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1847
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1922
|
+
chunk7B52C2XE_js.__privateSet(this, _cache6, cache);
|
|
1923
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache6, useCache);
|
|
1848
1924
|
this.isEnabled = schedule.isEnabled;
|
|
1849
1925
|
this.weeklySchedule = schedule.weeklySchedule;
|
|
1850
1926
|
}
|
|
@@ -1853,10 +1929,10 @@ var Schedule = class {
|
|
|
1853
1929
|
var _a;
|
|
1854
1930
|
const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
|
|
1855
1931
|
return updateSchedule({
|
|
1856
|
-
emitter: chunk7B52C2XE_js.__privateGet(this,
|
|
1932
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter5),
|
|
1857
1933
|
apiService: chunk7B52C2XE_js.__privateGet(this, _apiService),
|
|
1858
|
-
cache: chunk7B52C2XE_js.__privateGet(this,
|
|
1859
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
1934
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache6),
|
|
1935
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache6),
|
|
1860
1936
|
args: chunk7B52C2XE_js.__spreadValues({
|
|
1861
1937
|
isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
|
|
1862
1938
|
}, hasWeeklySchedule && {
|
|
@@ -1866,13 +1942,13 @@ var Schedule = class {
|
|
|
1866
1942
|
});
|
|
1867
1943
|
}
|
|
1868
1944
|
};
|
|
1869
|
-
|
|
1945
|
+
_emitter5 = new WeakMap();
|
|
1870
1946
|
_apiService = new WeakMap();
|
|
1871
|
-
|
|
1872
|
-
|
|
1947
|
+
_cache6 = new WeakMap();
|
|
1948
|
+
_useCache6 = new WeakMap();
|
|
1873
1949
|
|
|
1874
1950
|
// src/preferences/preference.ts
|
|
1875
|
-
var
|
|
1951
|
+
var _emitter6, _apiService2, _cache7, _scheduleCache, _useCache7;
|
|
1876
1952
|
var Preference = class {
|
|
1877
1953
|
constructor(preference, {
|
|
1878
1954
|
emitterInstance,
|
|
@@ -1881,16 +1957,16 @@ var Preference = class {
|
|
|
1881
1957
|
scheduleCache,
|
|
1882
1958
|
useCache
|
|
1883
1959
|
}) {
|
|
1884
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1960
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter6);
|
|
1885
1961
|
chunk7B52C2XE_js.__privateAdd(this, _apiService2);
|
|
1886
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1962
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache7);
|
|
1887
1963
|
chunk7B52C2XE_js.__privateAdd(this, _scheduleCache);
|
|
1888
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
1889
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1964
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache7);
|
|
1965
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter6, emitterInstance);
|
|
1890
1966
|
chunk7B52C2XE_js.__privateSet(this, _apiService2, inboxServiceInstance);
|
|
1891
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1967
|
+
chunk7B52C2XE_js.__privateSet(this, _cache7, cache);
|
|
1892
1968
|
chunk7B52C2XE_js.__privateSet(this, _scheduleCache, scheduleCache);
|
|
1893
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
1969
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache7, useCache);
|
|
1894
1970
|
this.level = preference.level;
|
|
1895
1971
|
this.enabled = preference.enabled;
|
|
1896
1972
|
this.channels = preference.channels;
|
|
@@ -1906,11 +1982,11 @@ var Preference = class {
|
|
|
1906
1982
|
}) {
|
|
1907
1983
|
var _a;
|
|
1908
1984
|
return updatePreference({
|
|
1909
|
-
emitter: chunk7B52C2XE_js.__privateGet(this,
|
|
1985
|
+
emitter: chunk7B52C2XE_js.__privateGet(this, _emitter6),
|
|
1910
1986
|
apiService: chunk7B52C2XE_js.__privateGet(this, _apiService2),
|
|
1911
|
-
cache: chunk7B52C2XE_js.__privateGet(this,
|
|
1987
|
+
cache: chunk7B52C2XE_js.__privateGet(this, _cache7),
|
|
1912
1988
|
scheduleCache: chunk7B52C2XE_js.__privateGet(this, _scheduleCache),
|
|
1913
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
1989
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache7),
|
|
1914
1990
|
args: {
|
|
1915
1991
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1916
1992
|
channels: channels || channelPreferences,
|
|
@@ -1919,11 +1995,11 @@ var Preference = class {
|
|
|
1919
1995
|
});
|
|
1920
1996
|
}
|
|
1921
1997
|
};
|
|
1922
|
-
|
|
1998
|
+
_emitter6 = new WeakMap();
|
|
1923
1999
|
_apiService2 = new WeakMap();
|
|
1924
|
-
|
|
2000
|
+
_cache7 = new WeakMap();
|
|
1925
2001
|
_scheduleCache = new WeakMap();
|
|
1926
|
-
|
|
2002
|
+
_useCache7 = new WeakMap();
|
|
1927
2003
|
|
|
1928
2004
|
// src/preferences/helpers.ts
|
|
1929
2005
|
var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
@@ -1971,7 +2047,7 @@ var updatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function*
|
|
|
1971
2047
|
return { data: preference };
|
|
1972
2048
|
} catch (error) {
|
|
1973
2049
|
emitter.emit("preference.update.resolved", { args, error });
|
|
1974
|
-
return { error: new NovuError("Failed to update preference", error) };
|
|
2050
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to update preference", error) };
|
|
1975
2051
|
}
|
|
1976
2052
|
});
|
|
1977
2053
|
var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
@@ -1984,7 +2060,7 @@ var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], functi
|
|
|
1984
2060
|
}) {
|
|
1985
2061
|
const globalPreference = args.find((arg) => "preference" in arg && arg.preference.level === "global" /* GLOBAL */);
|
|
1986
2062
|
if (globalPreference) {
|
|
1987
|
-
return { error: new NovuError("Global preference is not supported in bulk update", "") };
|
|
2063
|
+
return { error: new chunkCDGREQFE_js.NovuError("Global preference is not supported in bulk update", "") };
|
|
1988
2064
|
}
|
|
1989
2065
|
try {
|
|
1990
2066
|
const optimisticallyUpdatedPreferences = args.map(
|
|
@@ -2025,7 +2101,7 @@ var bulkUpdatePreference = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], functi
|
|
|
2025
2101
|
return { data: preferences };
|
|
2026
2102
|
} catch (error) {
|
|
2027
2103
|
emitter.emit("preferences.bulk_update.resolved", { args, error });
|
|
2028
|
-
return { error: new NovuError("Failed to bulk update preferences", error) };
|
|
2104
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to bulk update preferences", error) };
|
|
2029
2105
|
}
|
|
2030
2106
|
});
|
|
2031
2107
|
var optimisticUpdateWorkflowPreferences = ({
|
|
@@ -2115,12 +2191,12 @@ var updateSchedule = (_0) => chunk7B52C2XE_js.__async(void 0, [_0], function* ({
|
|
|
2115
2191
|
return { data: updatedSchedule };
|
|
2116
2192
|
} catch (error) {
|
|
2117
2193
|
emitter.emit("preference.schedule.update.resolved", { args, error });
|
|
2118
|
-
return { error: new NovuError("Failed to update preference", error) };
|
|
2194
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to update preference", error) };
|
|
2119
2195
|
}
|
|
2120
2196
|
});
|
|
2121
2197
|
|
|
2122
2198
|
// src/preferences/preference-schedule.ts
|
|
2123
|
-
var
|
|
2199
|
+
var _useCache8;
|
|
2124
2200
|
var PreferenceSchedule = class extends BaseModule {
|
|
2125
2201
|
constructor({
|
|
2126
2202
|
cache,
|
|
@@ -2132,16 +2208,16 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2132
2208
|
eventEmitterInstance,
|
|
2133
2209
|
inboxServiceInstance
|
|
2134
2210
|
});
|
|
2135
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2211
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache8);
|
|
2136
2212
|
this.cache = cache;
|
|
2137
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2213
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache8, useCache);
|
|
2138
2214
|
}
|
|
2139
2215
|
get() {
|
|
2140
2216
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
2141
2217
|
return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
2142
2218
|
var _a, _b;
|
|
2143
2219
|
try {
|
|
2144
|
-
let data = chunk7B52C2XE_js.__privateGet(this,
|
|
2220
|
+
let data = chunk7B52C2XE_js.__privateGet(this, _useCache8) ? this.cache.getAll() : void 0;
|
|
2145
2221
|
this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
|
|
2146
2222
|
if (!data) {
|
|
2147
2223
|
const globalPreference = yield this._inboxService.fetchGlobalPreferences();
|
|
@@ -2154,10 +2230,10 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2154
2230
|
emitterInstance: this._emitter,
|
|
2155
2231
|
inboxServiceInstance: this._inboxService,
|
|
2156
2232
|
cache: this.cache,
|
|
2157
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
2233
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache8)
|
|
2158
2234
|
}
|
|
2159
2235
|
);
|
|
2160
|
-
if (chunk7B52C2XE_js.__privateGet(this,
|
|
2236
|
+
if (chunk7B52C2XE_js.__privateGet(this, _useCache8)) {
|
|
2161
2237
|
this.cache.set(data);
|
|
2162
2238
|
data = this.cache.getAll();
|
|
2163
2239
|
}
|
|
@@ -2181,14 +2257,14 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
2181
2257
|
emitter: this._emitter,
|
|
2182
2258
|
apiService: this._inboxService,
|
|
2183
2259
|
cache: this.cache,
|
|
2184
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
2260
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache8),
|
|
2185
2261
|
args
|
|
2186
2262
|
})
|
|
2187
2263
|
);
|
|
2188
2264
|
});
|
|
2189
2265
|
}
|
|
2190
2266
|
};
|
|
2191
|
-
|
|
2267
|
+
_useCache8 = new WeakMap();
|
|
2192
2268
|
|
|
2193
2269
|
// src/cache/preferences-cache.ts
|
|
2194
2270
|
var updateEvents2 = [
|
|
@@ -2211,13 +2287,13 @@ var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).r
|
|
|
2211
2287
|
var getCacheKey2 = ({ tags, severity }) => {
|
|
2212
2288
|
return JSON.stringify(excludeEmpty2({ tags, severity }));
|
|
2213
2289
|
};
|
|
2214
|
-
var
|
|
2290
|
+
var _emitter7, _cache8;
|
|
2215
2291
|
var PreferencesCache = class {
|
|
2216
2292
|
constructor({ emitterInstance }) {
|
|
2217
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2218
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2293
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter7);
|
|
2294
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache8);
|
|
2219
2295
|
this.updatePreference = (key, data) => {
|
|
2220
|
-
const preferences = chunk7B52C2XE_js.__privateGet(this,
|
|
2296
|
+
const preferences = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key);
|
|
2221
2297
|
if (!preferences) {
|
|
2222
2298
|
return false;
|
|
2223
2299
|
}
|
|
@@ -2232,11 +2308,11 @@ var PreferencesCache = class {
|
|
|
2232
2308
|
}
|
|
2233
2309
|
const updatedPreferences = [...preferences];
|
|
2234
2310
|
updatedPreferences[index] = data;
|
|
2235
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2311
|
+
chunk7B52C2XE_js.__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
2236
2312
|
return true;
|
|
2237
2313
|
};
|
|
2238
2314
|
this.updatePreferenceSchedule = (key, data) => {
|
|
2239
|
-
const preferences = chunk7B52C2XE_js.__privateGet(this,
|
|
2315
|
+
const preferences = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key);
|
|
2240
2316
|
if (!preferences) {
|
|
2241
2317
|
return false;
|
|
2242
2318
|
}
|
|
@@ -2246,7 +2322,7 @@ var PreferencesCache = class {
|
|
|
2246
2322
|
}
|
|
2247
2323
|
const updatedPreferences = [...preferences];
|
|
2248
2324
|
updatedPreferences[index].schedule = data;
|
|
2249
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2325
|
+
chunk7B52C2XE_js.__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
2250
2326
|
return true;
|
|
2251
2327
|
};
|
|
2252
2328
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -2254,19 +2330,19 @@ var PreferencesCache = class {
|
|
|
2254
2330
|
if (!data) {
|
|
2255
2331
|
return;
|
|
2256
2332
|
}
|
|
2257
|
-
const cacheKeys = chunk7B52C2XE_js.__privateGet(this,
|
|
2333
|
+
const cacheKeys = chunk7B52C2XE_js.__privateGet(this, _cache8).keys();
|
|
2258
2334
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2259
2335
|
for (const key of cacheKeys) {
|
|
2260
2336
|
const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
|
|
2261
|
-
const updatedPreference = chunk7B52C2XE_js.__privateGet(this,
|
|
2337
|
+
const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key);
|
|
2262
2338
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2263
2339
|
continue;
|
|
2264
2340
|
}
|
|
2265
2341
|
uniqueFilterKeys.add(key);
|
|
2266
2342
|
}
|
|
2267
2343
|
for (const key of uniqueFilterKeys) {
|
|
2268
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2269
|
-
data: (_a = chunk7B52C2XE_js.__privateGet(this,
|
|
2344
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2345
|
+
data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
2270
2346
|
});
|
|
2271
2347
|
}
|
|
2272
2348
|
};
|
|
@@ -2276,10 +2352,10 @@ var PreferencesCache = class {
|
|
|
2276
2352
|
}
|
|
2277
2353
|
const preferences = Array.isArray(data) ? data : [data];
|
|
2278
2354
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2279
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2355
|
+
chunk7B52C2XE_js.__privateGet(this, _cache8).keys().forEach((key) => {
|
|
2280
2356
|
preferences.forEach((preference) => {
|
|
2281
2357
|
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
2282
|
-
const updatedPreference = chunk7B52C2XE_js.__privateGet(this,
|
|
2358
|
+
const updatedPreference = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key);
|
|
2283
2359
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
2284
2360
|
return;
|
|
2285
2361
|
}
|
|
@@ -2288,37 +2364,37 @@ var PreferencesCache = class {
|
|
|
2288
2364
|
});
|
|
2289
2365
|
uniqueFilterKeys.forEach((key) => {
|
|
2290
2366
|
var _a;
|
|
2291
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2292
|
-
data: (_a = chunk7B52C2XE_js.__privateGet(this,
|
|
2367
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2368
|
+
data: (_a = chunk7B52C2XE_js.__privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
2293
2369
|
});
|
|
2294
2370
|
});
|
|
2295
2371
|
};
|
|
2296
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2372
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter7, emitterInstance);
|
|
2297
2373
|
for (const event of updateEvents2) {
|
|
2298
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2374
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter7).on(event, this.handlePreferenceEvent);
|
|
2299
2375
|
}
|
|
2300
2376
|
for (const event of scheduleUpdateEvents) {
|
|
2301
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2377
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter7).on(event, this.handleScheduleEvent);
|
|
2302
2378
|
}
|
|
2303
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2379
|
+
chunk7B52C2XE_js.__privateSet(this, _cache8, new InMemoryCache());
|
|
2304
2380
|
}
|
|
2305
2381
|
has(args) {
|
|
2306
|
-
return chunk7B52C2XE_js.__privateGet(this,
|
|
2382
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache8).get(getCacheKey2(args)) !== void 0;
|
|
2307
2383
|
}
|
|
2308
2384
|
set(args, data) {
|
|
2309
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2385
|
+
chunk7B52C2XE_js.__privateGet(this, _cache8).set(getCacheKey2(args), data);
|
|
2310
2386
|
}
|
|
2311
2387
|
getAll(args) {
|
|
2312
2388
|
if (this.has(args)) {
|
|
2313
|
-
return chunk7B52C2XE_js.__privateGet(this,
|
|
2389
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache8).get(getCacheKey2(args));
|
|
2314
2390
|
}
|
|
2315
2391
|
}
|
|
2316
2392
|
clearAll() {
|
|
2317
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2393
|
+
chunk7B52C2XE_js.__privateGet(this, _cache8).clear();
|
|
2318
2394
|
}
|
|
2319
2395
|
};
|
|
2320
|
-
|
|
2321
|
-
|
|
2396
|
+
_emitter7 = new WeakMap();
|
|
2397
|
+
_cache8 = new WeakMap();
|
|
2322
2398
|
|
|
2323
2399
|
// src/cache/schedule-cache.ts
|
|
2324
2400
|
var updateEvents3 = [
|
|
@@ -2328,17 +2404,17 @@ var updateEvents3 = [
|
|
|
2328
2404
|
var getCacheKey3 = () => {
|
|
2329
2405
|
return "schedule";
|
|
2330
2406
|
};
|
|
2331
|
-
var
|
|
2407
|
+
var _emitter8, _cache9;
|
|
2332
2408
|
var ScheduleCache = class {
|
|
2333
2409
|
constructor({ emitterInstance }) {
|
|
2334
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2335
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2410
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter8);
|
|
2411
|
+
chunk7B52C2XE_js.__privateAdd(this, _cache9);
|
|
2336
2412
|
this.updateScheduleInCache = (key, data) => {
|
|
2337
|
-
const schedule = chunk7B52C2XE_js.__privateGet(this,
|
|
2413
|
+
const schedule = chunk7B52C2XE_js.__privateGet(this, _cache9).get(key);
|
|
2338
2414
|
if (!schedule) {
|
|
2339
2415
|
return false;
|
|
2340
2416
|
}
|
|
2341
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2417
|
+
chunk7B52C2XE_js.__privateGet(this, _cache9).set(key, data);
|
|
2342
2418
|
return true;
|
|
2343
2419
|
};
|
|
2344
2420
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -2346,47 +2422,47 @@ var ScheduleCache = class {
|
|
|
2346
2422
|
return;
|
|
2347
2423
|
}
|
|
2348
2424
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
2349
|
-
const keys = chunk7B52C2XE_js.__privateGet(this,
|
|
2425
|
+
const keys = chunk7B52C2XE_js.__privateGet(this, _cache9).keys();
|
|
2350
2426
|
for (const key of keys) {
|
|
2351
2427
|
const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
|
|
2352
|
-
const updatedSchedule = chunk7B52C2XE_js.__privateGet(this,
|
|
2428
|
+
const updatedSchedule = chunk7B52C2XE_js.__privateGet(this, _cache9).get(key);
|
|
2353
2429
|
if (!hasUpdatedSchedule || !updatedSchedule) {
|
|
2354
2430
|
continue;
|
|
2355
2431
|
}
|
|
2356
2432
|
uniqueFilterKeys.add(key);
|
|
2357
2433
|
}
|
|
2358
2434
|
for (const key of uniqueFilterKeys) {
|
|
2359
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2360
|
-
data: chunk7B52C2XE_js.__privateGet(this,
|
|
2435
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter8).emit("preference.schedule.get.updated", {
|
|
2436
|
+
data: chunk7B52C2XE_js.__privateGet(this, _cache9).get(key)
|
|
2361
2437
|
});
|
|
2362
2438
|
}
|
|
2363
2439
|
};
|
|
2364
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2440
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter8, emitterInstance);
|
|
2365
2441
|
for (const event of updateEvents3) {
|
|
2366
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2442
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter8).on(event, this.handleScheduleEvent);
|
|
2367
2443
|
}
|
|
2368
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2444
|
+
chunk7B52C2XE_js.__privateSet(this, _cache9, new InMemoryCache());
|
|
2369
2445
|
}
|
|
2370
2446
|
has() {
|
|
2371
|
-
return chunk7B52C2XE_js.__privateGet(this,
|
|
2447
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache9).get(getCacheKey3()) !== void 0;
|
|
2372
2448
|
}
|
|
2373
2449
|
set(data) {
|
|
2374
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2450
|
+
chunk7B52C2XE_js.__privateGet(this, _cache9).set(getCacheKey3(), data);
|
|
2375
2451
|
}
|
|
2376
2452
|
getAll() {
|
|
2377
2453
|
if (this.has()) {
|
|
2378
|
-
return chunk7B52C2XE_js.__privateGet(this,
|
|
2454
|
+
return chunk7B52C2XE_js.__privateGet(this, _cache9).get(getCacheKey3());
|
|
2379
2455
|
}
|
|
2380
2456
|
}
|
|
2381
2457
|
clearAll() {
|
|
2382
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2458
|
+
chunk7B52C2XE_js.__privateGet(this, _cache9).clear();
|
|
2383
2459
|
}
|
|
2384
2460
|
};
|
|
2385
|
-
|
|
2386
|
-
|
|
2461
|
+
_emitter8 = new WeakMap();
|
|
2462
|
+
_cache9 = new WeakMap();
|
|
2387
2463
|
|
|
2388
2464
|
// src/preferences/preferences.ts
|
|
2389
|
-
var
|
|
2465
|
+
var _useCache9;
|
|
2390
2466
|
var Preferences = class extends BaseModule {
|
|
2391
2467
|
constructor({
|
|
2392
2468
|
useCache,
|
|
@@ -2397,14 +2473,14 @@ var Preferences = class extends BaseModule {
|
|
|
2397
2473
|
eventEmitterInstance,
|
|
2398
2474
|
inboxServiceInstance
|
|
2399
2475
|
});
|
|
2400
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2476
|
+
chunk7B52C2XE_js.__privateAdd(this, _useCache9);
|
|
2401
2477
|
this.cache = new PreferencesCache({
|
|
2402
2478
|
emitterInstance: this._emitter
|
|
2403
2479
|
});
|
|
2404
2480
|
this.scheduleCache = new ScheduleCache({
|
|
2405
2481
|
emitterInstance: this._emitter
|
|
2406
2482
|
});
|
|
2407
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2483
|
+
chunk7B52C2XE_js.__privateSet(this, _useCache9, useCache);
|
|
2408
2484
|
this.schedule = new PreferenceSchedule({
|
|
2409
2485
|
cache: this.scheduleCache,
|
|
2410
2486
|
useCache,
|
|
@@ -2417,7 +2493,7 @@ var Preferences = class extends BaseModule {
|
|
|
2417
2493
|
return this.callWithSession(() => chunk7B52C2XE_js.__async(this, null, function* () {
|
|
2418
2494
|
var _a;
|
|
2419
2495
|
try {
|
|
2420
|
-
let data = chunk7B52C2XE_js.__privateGet(this,
|
|
2496
|
+
let data = chunk7B52C2XE_js.__privateGet(this, _useCache9) ? this.cache.getAll(args) : void 0;
|
|
2421
2497
|
this._emitter.emit("preferences.list.pending", { args, data });
|
|
2422
2498
|
if (!data) {
|
|
2423
2499
|
const response = yield this._inboxService.fetchPreferences({
|
|
@@ -2431,10 +2507,10 @@ var Preferences = class extends BaseModule {
|
|
|
2431
2507
|
inboxServiceInstance: this._inboxService,
|
|
2432
2508
|
cache: this.cache,
|
|
2433
2509
|
scheduleCache: this.scheduleCache,
|
|
2434
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
2510
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache9)
|
|
2435
2511
|
})
|
|
2436
2512
|
);
|
|
2437
|
-
if (chunk7B52C2XE_js.__privateGet(this,
|
|
2513
|
+
if (chunk7B52C2XE_js.__privateGet(this, _useCache9)) {
|
|
2438
2514
|
this.cache.set(args, data);
|
|
2439
2515
|
data = this.cache.getAll(args);
|
|
2440
2516
|
}
|
|
@@ -2456,7 +2532,7 @@ var Preferences = class extends BaseModule {
|
|
|
2456
2532
|
apiService: this._inboxService,
|
|
2457
2533
|
cache: this.cache,
|
|
2458
2534
|
scheduleCache: this.scheduleCache,
|
|
2459
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
2535
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache9),
|
|
2460
2536
|
args
|
|
2461
2537
|
})
|
|
2462
2538
|
);
|
|
@@ -2470,14 +2546,14 @@ var Preferences = class extends BaseModule {
|
|
|
2470
2546
|
apiService: this._inboxService,
|
|
2471
2547
|
cache: this.cache,
|
|
2472
2548
|
scheduleCache: this.scheduleCache,
|
|
2473
|
-
useCache: chunk7B52C2XE_js.__privateGet(this,
|
|
2549
|
+
useCache: chunk7B52C2XE_js.__privateGet(this, _useCache9),
|
|
2474
2550
|
args
|
|
2475
2551
|
})
|
|
2476
2552
|
);
|
|
2477
2553
|
});
|
|
2478
2554
|
}
|
|
2479
2555
|
};
|
|
2480
|
-
|
|
2556
|
+
_useCache9 = new WeakMap();
|
|
2481
2557
|
|
|
2482
2558
|
// src/utils/is-browser.ts
|
|
2483
2559
|
function isBrowser() {
|
|
@@ -2485,14 +2561,14 @@ function isBrowser() {
|
|
|
2485
2561
|
}
|
|
2486
2562
|
|
|
2487
2563
|
// src/session/session.ts
|
|
2488
|
-
var
|
|
2564
|
+
var _emitter9, _inboxService5, _options;
|
|
2489
2565
|
var Session = class {
|
|
2490
2566
|
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
2491
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2492
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2567
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter9);
|
|
2568
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService5);
|
|
2493
2569
|
chunk7B52C2XE_js.__privateAdd(this, _options);
|
|
2494
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2495
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2570
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter9, eventEmitterInstance);
|
|
2571
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService5, inboxServiceInstance);
|
|
2496
2572
|
chunk7B52C2XE_js.__privateSet(this, _options, options);
|
|
2497
2573
|
}
|
|
2498
2574
|
get applicationIdentifier() {
|
|
@@ -2563,8 +2639,8 @@ var Session = class {
|
|
|
2563
2639
|
} else {
|
|
2564
2640
|
this.handleApplicationIdentifier("delete");
|
|
2565
2641
|
}
|
|
2566
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2567
|
-
const response = yield chunk7B52C2XE_js.__privateGet(this,
|
|
2642
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("session.initialize.pending", { args: chunk7B52C2XE_js.__privateGet(this, _options) });
|
|
2643
|
+
const response = yield chunk7B52C2XE_js.__privateGet(this, _inboxService5).initializeSession({
|
|
2568
2644
|
applicationIdentifier: finalApplicationIdentifier,
|
|
2569
2645
|
subscriberHash,
|
|
2570
2646
|
contextHash,
|
|
@@ -2581,15 +2657,15 @@ var Session = class {
|
|
|
2581
2657
|
if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
|
|
2582
2658
|
this.handleApplicationIdentifier("delete");
|
|
2583
2659
|
}
|
|
2584
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2660
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), data: response });
|
|
2585
2661
|
} catch (error) {
|
|
2586
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2662
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: chunk7B52C2XE_js.__privateGet(this, _options), error });
|
|
2587
2663
|
}
|
|
2588
2664
|
});
|
|
2589
2665
|
}
|
|
2590
2666
|
};
|
|
2591
|
-
|
|
2592
|
-
|
|
2667
|
+
_emitter9 = new WeakMap();
|
|
2668
|
+
_inboxService5 = new WeakMap();
|
|
2593
2669
|
_options = new WeakMap();
|
|
2594
2670
|
var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
|
|
2595
2671
|
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
@@ -2682,7 +2758,7 @@ var mapToNotification = ({
|
|
|
2682
2758
|
severity
|
|
2683
2759
|
});
|
|
2684
2760
|
};
|
|
2685
|
-
var _token,
|
|
2761
|
+
var _token, _emitter10, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
|
|
2686
2762
|
var PartySocketClient = class extends BaseModule {
|
|
2687
2763
|
constructor({
|
|
2688
2764
|
socketUrl,
|
|
@@ -2695,15 +2771,15 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2695
2771
|
});
|
|
2696
2772
|
chunk7B52C2XE_js.__privateAdd(this, _PartySocketClient_instances);
|
|
2697
2773
|
chunk7B52C2XE_js.__privateAdd(this, _token);
|
|
2698
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
2774
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter10);
|
|
2699
2775
|
chunk7B52C2XE_js.__privateAdd(this, _partySocket);
|
|
2700
2776
|
chunk7B52C2XE_js.__privateAdd(this, _socketUrl);
|
|
2701
2777
|
chunk7B52C2XE_js.__privateAdd(this, _notificationReceived, (event) => {
|
|
2702
2778
|
try {
|
|
2703
2779
|
const data = JSON.parse(event.data);
|
|
2704
2780
|
if (data.event === "notification_received" /* RECEIVED */) {
|
|
2705
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2706
|
-
result: new Notification(mapToNotification(data.data.message), chunk7B52C2XE_js.__privateGet(this,
|
|
2781
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit(NOTIFICATION_RECEIVED, {
|
|
2782
|
+
result: new chunkCDGREQFE_js.Notification(mapToNotification(data.data.message), chunk7B52C2XE_js.__privateGet(this, _emitter10), this._inboxService)
|
|
2707
2783
|
});
|
|
2708
2784
|
}
|
|
2709
2785
|
} catch (error) {
|
|
@@ -2714,7 +2790,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2714
2790
|
try {
|
|
2715
2791
|
const data = JSON.parse(event.data);
|
|
2716
2792
|
if (data.event === "unseen_count_changed" /* UNSEEN */) {
|
|
2717
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2793
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit(UNSEEN_COUNT_CHANGED, {
|
|
2718
2794
|
result: data.data.unseenCount
|
|
2719
2795
|
});
|
|
2720
2796
|
}
|
|
@@ -2725,7 +2801,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2725
2801
|
try {
|
|
2726
2802
|
const data = JSON.parse(event.data);
|
|
2727
2803
|
if (data.event === "unread_count_changed" /* UNREAD */) {
|
|
2728
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2804
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit(UNREAD_COUNT_CHANGED, {
|
|
2729
2805
|
result: data.data.counts
|
|
2730
2806
|
});
|
|
2731
2807
|
}
|
|
@@ -2750,7 +2826,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2750
2826
|
} catch (error) {
|
|
2751
2827
|
}
|
|
2752
2828
|
});
|
|
2753
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
2829
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter10, eventEmitterInstance);
|
|
2754
2830
|
chunk7B52C2XE_js.__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
2755
2831
|
}
|
|
2756
2832
|
onSessionSuccess({ token }) {
|
|
@@ -2777,7 +2853,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2777
2853
|
}
|
|
2778
2854
|
};
|
|
2779
2855
|
_token = new WeakMap();
|
|
2780
|
-
|
|
2856
|
+
_emitter10 = new WeakMap();
|
|
2781
2857
|
_partySocket = new WeakMap();
|
|
2782
2858
|
_socketUrl = new WeakMap();
|
|
2783
2859
|
_notificationReceived = new WeakMap();
|
|
@@ -2791,15 +2867,15 @@ initializeSocket_fn = function() {
|
|
|
2791
2867
|
return;
|
|
2792
2868
|
}
|
|
2793
2869
|
const args = { socketUrl: chunk7B52C2XE_js.__privateGet(this, _socketUrl) };
|
|
2794
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2870
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit("socket.connect.pending", { args });
|
|
2795
2871
|
const url = new URL(chunk7B52C2XE_js.__privateGet(this, _socketUrl));
|
|
2796
2872
|
url.searchParams.set("token", chunk7B52C2XE_js.__privateGet(this, _token));
|
|
2797
2873
|
chunk7B52C2XE_js.__privateSet(this, _partySocket, new partysocket.WebSocket(url.toString()));
|
|
2798
2874
|
chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("open", () => {
|
|
2799
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2875
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit("socket.connect.resolved", { args });
|
|
2800
2876
|
});
|
|
2801
2877
|
chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("error", (error) => {
|
|
2802
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2878
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter10).emit("socket.connect.resolved", { args, error });
|
|
2803
2879
|
});
|
|
2804
2880
|
chunk7B52C2XE_js.__privateGet(this, _partySocket).addEventListener("message", chunk7B52C2XE_js.__privateGet(this, _handleMessage));
|
|
2805
2881
|
});
|
|
@@ -2810,7 +2886,7 @@ handleConnectSocket_fn = function() {
|
|
|
2810
2886
|
yield chunk7B52C2XE_js.__privateMethod(this, _PartySocketClient_instances, initializeSocket_fn).call(this);
|
|
2811
2887
|
return {};
|
|
2812
2888
|
} catch (error) {
|
|
2813
|
-
return { error: new NovuError("Failed to initialize the PartySocket", error) };
|
|
2889
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to initialize the PartySocket", error) };
|
|
2814
2890
|
}
|
|
2815
2891
|
});
|
|
2816
2892
|
};
|
|
@@ -2822,7 +2898,7 @@ handleDisconnectSocket_fn = function() {
|
|
|
2822
2898
|
chunk7B52C2XE_js.__privateSet(this, _partySocket, void 0);
|
|
2823
2899
|
return {};
|
|
2824
2900
|
} catch (error) {
|
|
2825
|
-
return { error: new NovuError("Failed to disconnect from the PartySocket", error) };
|
|
2901
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to disconnect from the PartySocket", error) };
|
|
2826
2902
|
}
|
|
2827
2903
|
});
|
|
2828
2904
|
};
|
|
@@ -2917,7 +2993,7 @@ var mapToNotification2 = ({
|
|
|
2917
2993
|
severity
|
|
2918
2994
|
});
|
|
2919
2995
|
};
|
|
2920
|
-
var _token2,
|
|
2996
|
+
var _token2, _emitter11, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
|
|
2921
2997
|
var Socket = class extends BaseModule {
|
|
2922
2998
|
constructor({
|
|
2923
2999
|
socketUrl,
|
|
@@ -2930,25 +3006,25 @@ var Socket = class extends BaseModule {
|
|
|
2930
3006
|
});
|
|
2931
3007
|
chunk7B52C2XE_js.__privateAdd(this, _Socket_instances);
|
|
2932
3008
|
chunk7B52C2XE_js.__privateAdd(this, _token2);
|
|
2933
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
3009
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter11);
|
|
2934
3010
|
chunk7B52C2XE_js.__privateAdd(this, _socketIo);
|
|
2935
3011
|
chunk7B52C2XE_js.__privateAdd(this, _socketUrl2);
|
|
2936
3012
|
chunk7B52C2XE_js.__privateAdd(this, _notificationReceived2, ({ message }) => {
|
|
2937
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
2938
|
-
result: new Notification(mapToNotification2(message), chunk7B52C2XE_js.__privateGet(this,
|
|
3013
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit(NOTIFICATION_RECEIVED2, {
|
|
3014
|
+
result: new chunkCDGREQFE_js.Notification(mapToNotification2(message), chunk7B52C2XE_js.__privateGet(this, _emitter11), this._inboxService)
|
|
2939
3015
|
});
|
|
2940
3016
|
});
|
|
2941
3017
|
chunk7B52C2XE_js.__privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
|
|
2942
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3018
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit(UNSEEN_COUNT_CHANGED2, {
|
|
2943
3019
|
result: unseenCount
|
|
2944
3020
|
});
|
|
2945
3021
|
});
|
|
2946
3022
|
chunk7B52C2XE_js.__privateAdd(this, _unreadCountChanged2, ({ counts }) => {
|
|
2947
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3023
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit(UNREAD_COUNT_CHANGED2, {
|
|
2948
3024
|
result: counts
|
|
2949
3025
|
});
|
|
2950
3026
|
});
|
|
2951
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
3027
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter11, eventEmitterInstance);
|
|
2952
3028
|
chunk7B52C2XE_js.__privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
|
|
2953
3029
|
}
|
|
2954
3030
|
onSessionSuccess({ token }) {
|
|
@@ -2975,7 +3051,7 @@ var Socket = class extends BaseModule {
|
|
|
2975
3051
|
}
|
|
2976
3052
|
};
|
|
2977
3053
|
_token2 = new WeakMap();
|
|
2978
|
-
|
|
3054
|
+
_emitter11 = new WeakMap();
|
|
2979
3055
|
_socketIo = new WeakMap();
|
|
2980
3056
|
_socketUrl2 = new WeakMap();
|
|
2981
3057
|
_notificationReceived2 = new WeakMap();
|
|
@@ -2989,7 +3065,7 @@ initializeSocket_fn2 = function() {
|
|
|
2989
3065
|
return;
|
|
2990
3066
|
}
|
|
2991
3067
|
const args = { socketUrl: chunk7B52C2XE_js.__privateGet(this, _socketUrl2) };
|
|
2992
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3068
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit("socket.connect.pending", { args });
|
|
2993
3069
|
chunk7B52C2XE_js.__privateSet(this, _socketIo, io__default.default(chunk7B52C2XE_js.__privateGet(this, _socketUrl2), {
|
|
2994
3070
|
reconnectionDelayMax: 1e4,
|
|
2995
3071
|
transports: ["websocket"],
|
|
@@ -2998,10 +3074,10 @@ initializeSocket_fn2 = function() {
|
|
|
2998
3074
|
}
|
|
2999
3075
|
}));
|
|
3000
3076
|
chunk7B52C2XE_js.__privateGet(this, _socketIo).on("connect", () => {
|
|
3001
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3077
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit("socket.connect.resolved", { args });
|
|
3002
3078
|
});
|
|
3003
3079
|
chunk7B52C2XE_js.__privateGet(this, _socketIo).on("connect_error", (error) => {
|
|
3004
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3080
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter11).emit("socket.connect.resolved", { args, error });
|
|
3005
3081
|
});
|
|
3006
3082
|
(_a = chunk7B52C2XE_js.__privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, chunk7B52C2XE_js.__privateGet(this, _notificationReceived2));
|
|
3007
3083
|
(_b = chunk7B52C2XE_js.__privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, chunk7B52C2XE_js.__privateGet(this, _unseenCountChanged2));
|
|
@@ -3014,7 +3090,7 @@ handleConnectSocket_fn2 = function() {
|
|
|
3014
3090
|
yield chunk7B52C2XE_js.__privateMethod(this, _Socket_instances, initializeSocket_fn2).call(this);
|
|
3015
3091
|
return {};
|
|
3016
3092
|
} catch (error) {
|
|
3017
|
-
return { error: new NovuError("Failed to initialize the socket", error) };
|
|
3093
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to initialize the socket", error) };
|
|
3018
3094
|
}
|
|
3019
3095
|
});
|
|
3020
3096
|
};
|
|
@@ -3026,7 +3102,7 @@ handleDisconnectSocket_fn2 = function() {
|
|
|
3026
3102
|
chunk7B52C2XE_js.__privateSet(this, _socketIo, void 0);
|
|
3027
3103
|
return {};
|
|
3028
3104
|
} catch (error) {
|
|
3029
|
-
return { error: new NovuError("Failed to disconnect from the socket", error) };
|
|
3105
|
+
return { error: new chunkCDGREQFE_js.NovuError("Failed to disconnect from the socket", error) };
|
|
3030
3106
|
}
|
|
3031
3107
|
});
|
|
3032
3108
|
};
|
|
@@ -3075,57 +3151,66 @@ function createSocket({
|
|
|
3075
3151
|
}
|
|
3076
3152
|
|
|
3077
3153
|
// src/novu.ts
|
|
3078
|
-
var
|
|
3154
|
+
var _emitter12, _session, _inboxService6, _options2;
|
|
3079
3155
|
var Novu = class {
|
|
3080
3156
|
constructor(options) {
|
|
3081
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
3157
|
+
chunk7B52C2XE_js.__privateAdd(this, _emitter12);
|
|
3082
3158
|
chunk7B52C2XE_js.__privateAdd(this, _session);
|
|
3083
|
-
chunk7B52C2XE_js.__privateAdd(this,
|
|
3084
|
-
|
|
3085
|
-
|
|
3159
|
+
chunk7B52C2XE_js.__privateAdd(this, _inboxService6);
|
|
3160
|
+
chunk7B52C2XE_js.__privateAdd(this, _options2);
|
|
3161
|
+
var _a, _b, _c;
|
|
3162
|
+
chunk7B52C2XE_js.__privateSet(this, _options2, options);
|
|
3163
|
+
chunk7B52C2XE_js.__privateSet(this, _inboxService6, new InboxService({
|
|
3086
3164
|
apiUrl: options.apiUrl || options.backendUrl,
|
|
3087
3165
|
userAgent: options.__userAgent
|
|
3088
3166
|
}));
|
|
3089
|
-
chunk7B52C2XE_js.__privateSet(this,
|
|
3167
|
+
chunk7B52C2XE_js.__privateSet(this, _emitter12, new NovuEventEmitter());
|
|
3168
|
+
const subscriber = chunkCDGREQFE_js.buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber });
|
|
3090
3169
|
chunk7B52C2XE_js.__privateSet(this, _session, new Session(
|
|
3091
3170
|
{
|
|
3092
3171
|
applicationIdentifier: options.applicationIdentifier || "",
|
|
3093
3172
|
subscriberHash: options.subscriberHash,
|
|
3094
|
-
subscriber
|
|
3173
|
+
subscriber,
|
|
3095
3174
|
defaultSchedule: options.defaultSchedule,
|
|
3096
3175
|
context: options.context,
|
|
3097
3176
|
contextHash: options.contextHash
|
|
3098
3177
|
},
|
|
3099
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3100
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3178
|
+
chunk7B52C2XE_js.__privateGet(this, _inboxService6),
|
|
3179
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter12)
|
|
3101
3180
|
));
|
|
3102
3181
|
chunk7B52C2XE_js.__privateGet(this, _session).initialize();
|
|
3103
3182
|
this.notifications = new Notifications({
|
|
3104
3183
|
useCache: (_a = options.useCache) != null ? _a : true,
|
|
3105
|
-
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3106
|
-
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3184
|
+
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService6),
|
|
3185
|
+
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter12)
|
|
3107
3186
|
});
|
|
3108
3187
|
this.preferences = new Preferences({
|
|
3109
3188
|
useCache: (_b = options.useCache) != null ? _b : true,
|
|
3110
|
-
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3111
|
-
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3189
|
+
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService6),
|
|
3190
|
+
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter12)
|
|
3191
|
+
});
|
|
3192
|
+
this.subscriptions = new Subscriptions({
|
|
3193
|
+
subscriber,
|
|
3194
|
+
useCache: (_c = options.useCache) != null ? _c : true,
|
|
3195
|
+
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService6),
|
|
3196
|
+
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter12)
|
|
3112
3197
|
});
|
|
3113
3198
|
this.socket = createSocket({
|
|
3114
3199
|
socketUrl: options.socketUrl,
|
|
3115
|
-
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3116
|
-
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this,
|
|
3200
|
+
eventEmitterInstance: chunk7B52C2XE_js.__privateGet(this, _emitter12),
|
|
3201
|
+
inboxServiceInstance: chunk7B52C2XE_js.__privateGet(this, _inboxService6)
|
|
3117
3202
|
});
|
|
3118
3203
|
this.on = (eventName, listener) => {
|
|
3119
3204
|
if (this.socket.isSocketEvent(eventName)) {
|
|
3120
3205
|
this.socket.connect();
|
|
3121
3206
|
}
|
|
3122
|
-
const cleanup = chunk7B52C2XE_js.__privateGet(this,
|
|
3207
|
+
const cleanup = chunk7B52C2XE_js.__privateGet(this, _emitter12).on(eventName, listener);
|
|
3123
3208
|
return () => {
|
|
3124
3209
|
cleanup();
|
|
3125
3210
|
};
|
|
3126
3211
|
};
|
|
3127
3212
|
this.off = (eventName, listener) => {
|
|
3128
|
-
chunk7B52C2XE_js.__privateGet(this,
|
|
3213
|
+
chunk7B52C2XE_js.__privateGet(this, _emitter12).off(eventName, listener);
|
|
3129
3214
|
};
|
|
3130
3215
|
}
|
|
3131
3216
|
get applicationIdentifier() {
|
|
@@ -3137,9 +3222,21 @@ var Novu = class {
|
|
|
3137
3222
|
get context() {
|
|
3138
3223
|
return chunk7B52C2XE_js.__privateGet(this, _session).context;
|
|
3139
3224
|
}
|
|
3225
|
+
get options() {
|
|
3226
|
+
return chunk7B52C2XE_js.__privateGet(this, _options2);
|
|
3227
|
+
}
|
|
3140
3228
|
get contextKey() {
|
|
3141
|
-
return
|
|
3229
|
+
return chunkCDGREQFE_js.buildContextKey(chunk7B52C2XE_js.__privateGet(this, _session).context);
|
|
3230
|
+
}
|
|
3231
|
+
clearCache() {
|
|
3232
|
+
this.notifications.cache.clearAll();
|
|
3233
|
+
this.preferences.cache.clearAll();
|
|
3234
|
+
this.preferences.scheduleCache.clearAll();
|
|
3235
|
+
this.subscriptions.cache.clearAll();
|
|
3142
3236
|
}
|
|
3237
|
+
/**
|
|
3238
|
+
* @deprecated
|
|
3239
|
+
*/
|
|
3143
3240
|
changeSubscriber(options) {
|
|
3144
3241
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
3145
3242
|
yield chunk7B52C2XE_js.__privateGet(this, _session).initialize({
|
|
@@ -3150,13 +3247,16 @@ var Novu = class {
|
|
|
3150
3247
|
context: chunk7B52C2XE_js.__privateGet(this, _session).context,
|
|
3151
3248
|
contextHash: chunk7B52C2XE_js.__privateGet(this, _session).contextHash
|
|
3152
3249
|
});
|
|
3153
|
-
this.
|
|
3250
|
+
this.clearCache();
|
|
3154
3251
|
const disconnectResult = yield this.socket.disconnect();
|
|
3155
3252
|
if (!disconnectResult.error) {
|
|
3156
3253
|
yield this.socket.connect();
|
|
3157
3254
|
}
|
|
3158
3255
|
});
|
|
3159
3256
|
}
|
|
3257
|
+
/**
|
|
3258
|
+
* @deprecated
|
|
3259
|
+
*/
|
|
3160
3260
|
changeContext(options) {
|
|
3161
3261
|
return chunk7B52C2XE_js.__async(this, null, function* () {
|
|
3162
3262
|
const currentSubscriber = chunk7B52C2XE_js.__privateGet(this, _session).subscriber;
|
|
@@ -3171,7 +3271,7 @@ var Novu = class {
|
|
|
3171
3271
|
context: options.context,
|
|
3172
3272
|
contextHash: options.contextHash
|
|
3173
3273
|
});
|
|
3174
|
-
this.
|
|
3274
|
+
this.clearCache();
|
|
3175
3275
|
const disconnectResult = yield this.socket.disconnect();
|
|
3176
3276
|
if (!disconnectResult.error) {
|
|
3177
3277
|
yield this.socket.connect();
|
|
@@ -3179,18 +3279,15 @@ var Novu = class {
|
|
|
3179
3279
|
});
|
|
3180
3280
|
}
|
|
3181
3281
|
};
|
|
3182
|
-
|
|
3282
|
+
_emitter12 = new WeakMap();
|
|
3183
3283
|
_session = new WeakMap();
|
|
3184
|
-
|
|
3284
|
+
_inboxService6 = new WeakMap();
|
|
3285
|
+
_options2 = new WeakMap();
|
|
3185
3286
|
|
|
3186
|
-
exports.ChannelType = ChannelType;
|
|
3187
3287
|
exports.DEFAULT_API_VERSION = DEFAULT_API_VERSION;
|
|
3188
|
-
exports.NotificationStatus = NotificationStatus;
|
|
3189
3288
|
exports.Novu = Novu;
|
|
3190
|
-
exports.
|
|
3191
|
-
exports.
|
|
3192
|
-
exports.WebSocketEvent = WebSocketEvent;
|
|
3193
|
-
exports.WorkflowCriticalityEnum = WorkflowCriticalityEnum;
|
|
3289
|
+
exports.SubscriptionPreference = SubscriptionPreference;
|
|
3290
|
+
exports.TopicSubscription = TopicSubscription;
|
|
3194
3291
|
exports.areSeveritiesEqual = areSeveritiesEqual;
|
|
3195
3292
|
exports.areTagsEqual = areTagsEqual;
|
|
3196
3293
|
exports.checkNotificationDataFilter = checkNotificationDataFilter;
|