@novu/js 3.11.1 → 3.11.2-nightly.20251224.97b30e30dd
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-MKYWGA37.js → chunk-AFLPFCXM.js} +1069 -294
- package/dist/cjs/{chunk-WFVHYVDM.js → chunk-CDGREQFE.js} +6 -0
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +26 -14
- package/dist/cjs/internal/index.d.ts +8 -2
- package/dist/cjs/internal/index.js +9 -5
- package/dist/{esm/novu-3CfttQ8e.d.mts → cjs/novu-DxuaDf-Z.d.ts} +28 -1
- package/dist/{esm/novu-event-emitter-C7GZ7-r1.d.mts → cjs/novu-event-emitter-BOA_6GfJ.d.ts} +195 -1
- 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 -8
- package/dist/cjs/ui/index.js +1836 -261
- package/dist/esm/{chunk-76A4RQYD.mjs → chunk-GDLXUD4E.mjs} +1038 -265
- package/dist/esm/{chunk-GY4JXBST.mjs → chunk-SWKDFXVR.mjs} +6 -1
- package/dist/esm/index.d.mts +4 -3
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/internal/index.d.mts +8 -2
- package/dist/esm/internal/index.mjs +1 -1
- package/dist/{cjs/novu-CKWESYFZ.d.ts → esm/novu-DY8vwRGE.d.mts} +28 -1
- package/dist/{cjs/novu-event-emitter-C7GZ7-r1.d.ts → esm/novu-event-emitter-BOA_6GfJ.d.mts} +195 -1
- 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 -8
- 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 +2 -1
- package/dist/cjs/types-CeLsxWJg.d.ts +0 -537
- package/dist/esm/types-4YuozpWu.d.mts +0 -537
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildSubscriber, buildContextKey,
|
|
2
|
-
import { __privateAdd, __privateSet, __privateGet, __async,
|
|
1
|
+
import { NovuError, buildSubscriber, buildContextKey, buildSubscriptionIdentifier, Notification, read, unread, seen, archive, unarchive, deleteNotification, snooze, unsnooze, completeAction, revertAction, readAll, seenAll, archiveAll, archiveAllRead, deleteAll, createNotification } from './chunk-SWKDFXVR.mjs';
|
|
2
|
+
import { __privateAdd, __privateSet, __spreadValues, __privateGet, __async, __spreadProps, __objRest, __privateMethod } from './chunk-STZMOEWR.mjs';
|
|
3
3
|
import mitt from 'mitt';
|
|
4
4
|
import 'event-target-polyfill';
|
|
5
5
|
import { WebSocket } from 'partysocket';
|
|
@@ -96,9 +96,779 @@ function checkNotificationMatchesFilter(notification, filter) {
|
|
|
96
96
|
return checkBasicFilters(notification, filter) && checkNotificationTagFilter(notification.tags, filter.tags) && checkNotificationDataFilter(notification.data, filter.data);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// src/subscriptions/subscription.ts
|
|
100
|
+
var _emitter, _inboxService, _cache, _useCache, _isStale;
|
|
101
|
+
var TopicSubscription = class {
|
|
102
|
+
constructor(subscription, emitter, inboxService, cache, useCache) {
|
|
103
|
+
__privateAdd(this, _emitter);
|
|
104
|
+
__privateAdd(this, _inboxService);
|
|
105
|
+
__privateAdd(this, _cache);
|
|
106
|
+
__privateAdd(this, _useCache);
|
|
107
|
+
__privateAdd(this, _isStale, false);
|
|
108
|
+
var _a;
|
|
109
|
+
__privateSet(this, _emitter, emitter);
|
|
110
|
+
__privateSet(this, _inboxService, inboxService);
|
|
111
|
+
__privateSet(this, _cache, cache);
|
|
112
|
+
__privateSet(this, _useCache, useCache);
|
|
113
|
+
this.id = subscription.id;
|
|
114
|
+
this.identifier = subscription.identifier;
|
|
115
|
+
this.topicKey = subscription.topicKey;
|
|
116
|
+
this.preferences = (_a = subscription.preferences) == null ? void 0 : _a.map(
|
|
117
|
+
(pref) => new SubscriptionPreference(__spreadValues({}, pref), __privateGet(this, _emitter), __privateGet(this, _inboxService), __privateGet(this, _cache), __privateGet(this, _useCache))
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
update(args) {
|
|
121
|
+
return __async(this, null, function* () {
|
|
122
|
+
return updateSubscription({
|
|
123
|
+
emitter: __privateGet(this, _emitter),
|
|
124
|
+
apiService: __privateGet(this, _inboxService),
|
|
125
|
+
cache: __privateGet(this, _cache),
|
|
126
|
+
useCache: __privateGet(this, _useCache),
|
|
127
|
+
args: __spreadProps(__spreadValues({}, args), { subscription: this })
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
updatePreference(args) {
|
|
132
|
+
return __async(this, null, function* () {
|
|
133
|
+
if (__privateGet(this, _isStale)) {
|
|
134
|
+
return {
|
|
135
|
+
error: new NovuError("Cannot update a deleted subscription", new Error("Subscription is stale"))
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return updateSubscriptionPreference({
|
|
139
|
+
emitter: __privateGet(this, _emitter),
|
|
140
|
+
apiService: __privateGet(this, _inboxService),
|
|
141
|
+
cache: __privateGet(this, _cache),
|
|
142
|
+
useCache: __privateGet(this, _useCache),
|
|
143
|
+
args: __spreadProps(__spreadValues({}, args), { subscriptionId: this.id })
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
bulkUpdatePreferences(args) {
|
|
148
|
+
return __async(this, null, function* () {
|
|
149
|
+
if (__privateGet(this, _isStale)) {
|
|
150
|
+
return {
|
|
151
|
+
error: new NovuError("Cannot bulk update a deleted subscription", new Error("Subscription is stale"))
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return bulkUpdateSubscriptionPreference({
|
|
155
|
+
emitter: __privateGet(this, _emitter),
|
|
156
|
+
apiService: __privateGet(this, _inboxService),
|
|
157
|
+
cache: __privateGet(this, _cache),
|
|
158
|
+
useCache: __privateGet(this, _useCache),
|
|
159
|
+
args: args.map((arg) => __spreadProps(__spreadValues({}, arg), { subscriptionId: this.id }))
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
delete() {
|
|
164
|
+
return __async(this, null, function* () {
|
|
165
|
+
if (__privateGet(this, _isStale)) {
|
|
166
|
+
return {
|
|
167
|
+
error: new NovuError("Cannot delete an already deleted subscription", new Error("Subscription is stale"))
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return deleteSubscription({
|
|
171
|
+
emitter: __privateGet(this, _emitter),
|
|
172
|
+
apiService: __privateGet(this, _inboxService),
|
|
173
|
+
args: { subscription: this }
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
_emitter = new WeakMap();
|
|
179
|
+
_inboxService = new WeakMap();
|
|
180
|
+
_cache = new WeakMap();
|
|
181
|
+
_useCache = new WeakMap();
|
|
182
|
+
_isStale = new WeakMap();
|
|
183
|
+
|
|
184
|
+
// src/subscriptions/helpers.ts
|
|
185
|
+
var listSubscriptions = (_0) => __async(void 0, [_0], function* ({
|
|
186
|
+
emitter,
|
|
187
|
+
apiService,
|
|
188
|
+
cache,
|
|
189
|
+
options,
|
|
190
|
+
args
|
|
191
|
+
}) {
|
|
192
|
+
try {
|
|
193
|
+
const { useCache, refetch } = options;
|
|
194
|
+
let data = useCache && !refetch ? cache.getAll(args) : void 0;
|
|
195
|
+
emitter.emit("subscriptions.list.pending", { args, data });
|
|
196
|
+
if (!data || refetch) {
|
|
197
|
+
const response = yield apiService.fetchSubscriptions(args.topicKey);
|
|
198
|
+
data = response.map((el) => {
|
|
199
|
+
return new TopicSubscription(__spreadProps(__spreadValues({}, el), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
200
|
+
});
|
|
201
|
+
if (useCache) {
|
|
202
|
+
cache.set(args, data);
|
|
203
|
+
data = cache.getAll(args);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
emitter.emit("subscriptions.list.resolved", { args, data });
|
|
207
|
+
return { data };
|
|
208
|
+
} catch (error) {
|
|
209
|
+
emitter.emit("subscriptions.list.resolved", { args, error });
|
|
210
|
+
return { error: new NovuError("Failed to fetch subscriptions", error) };
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
var getSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
214
|
+
emitter,
|
|
215
|
+
apiService,
|
|
216
|
+
cache,
|
|
217
|
+
options,
|
|
218
|
+
args
|
|
219
|
+
}) {
|
|
220
|
+
try {
|
|
221
|
+
const { useCache, refetch } = options;
|
|
222
|
+
let data = useCache && !refetch ? cache.get(args) : void 0;
|
|
223
|
+
emitter.emit("subscription.get.pending", { args, data });
|
|
224
|
+
if (!data || refetch) {
|
|
225
|
+
const response = yield apiService.getSubscription(args.topicKey, args.identifier, args.workflowIds, args.tags);
|
|
226
|
+
if (!response) {
|
|
227
|
+
emitter.emit("subscription.get.resolved", { args, data: null });
|
|
228
|
+
return { data: null };
|
|
229
|
+
}
|
|
230
|
+
data = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }), emitter, apiService, cache, useCache);
|
|
231
|
+
if (useCache) {
|
|
232
|
+
cache.setOne(args, data);
|
|
233
|
+
data = cache.get(args);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
emitter.emit("subscription.get.resolved", { args, data });
|
|
237
|
+
return { data };
|
|
238
|
+
} catch (error) {
|
|
239
|
+
emitter.emit("subscription.get.resolved", { args, error });
|
|
240
|
+
return { error: new NovuError("Failed to fetch subscription", error) };
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
var createSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
244
|
+
emitter,
|
|
245
|
+
apiService,
|
|
246
|
+
cache,
|
|
247
|
+
useCache,
|
|
248
|
+
args
|
|
249
|
+
}) {
|
|
250
|
+
var _a;
|
|
251
|
+
try {
|
|
252
|
+
emitter.emit("subscription.create.pending", { args });
|
|
253
|
+
const response = yield apiService.createSubscription({
|
|
254
|
+
identifier: (_a = args.identifier) != null ? _a : "",
|
|
255
|
+
name: args.name,
|
|
256
|
+
topicKey: args.topicKey,
|
|
257
|
+
topicName: args.topicName,
|
|
258
|
+
preferences: args.preferences
|
|
259
|
+
});
|
|
260
|
+
const subscription = new TopicSubscription(
|
|
261
|
+
__spreadProps(__spreadValues({}, response), { topicKey: args.topicKey }),
|
|
262
|
+
emitter,
|
|
263
|
+
apiService,
|
|
264
|
+
cache,
|
|
265
|
+
useCache
|
|
266
|
+
);
|
|
267
|
+
emitter.emit("subscription.create.resolved", { args, data: subscription });
|
|
268
|
+
return { data: subscription };
|
|
269
|
+
} catch (error) {
|
|
270
|
+
emitter.emit("subscription.create.resolved", { args, error });
|
|
271
|
+
return { error: new NovuError("Failed to create subscription", error) };
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
var updateSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
275
|
+
emitter,
|
|
276
|
+
apiService,
|
|
277
|
+
cache,
|
|
278
|
+
useCache,
|
|
279
|
+
args
|
|
280
|
+
}) {
|
|
281
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
282
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
283
|
+
try {
|
|
284
|
+
emitter.emit("subscription.update.pending", {
|
|
285
|
+
args
|
|
286
|
+
});
|
|
287
|
+
const response = yield apiService.updateSubscription({
|
|
288
|
+
topicKey,
|
|
289
|
+
subscriptionId,
|
|
290
|
+
name: args.name,
|
|
291
|
+
preferences: args.preferences
|
|
292
|
+
});
|
|
293
|
+
const updatedSubscription = new TopicSubscription(__spreadProps(__spreadValues({}, response), { topicKey }), emitter, apiService, cache, useCache);
|
|
294
|
+
emitter.emit("subscription.update.resolved", { args, data: updatedSubscription });
|
|
295
|
+
return { data: updatedSubscription };
|
|
296
|
+
} catch (error) {
|
|
297
|
+
emitter.emit("subscription.update.resolved", { args, error });
|
|
298
|
+
return { error: new NovuError("Failed to update subscription", error) };
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
var updateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
|
|
302
|
+
emitter,
|
|
303
|
+
apiService,
|
|
304
|
+
cache,
|
|
305
|
+
useCache,
|
|
306
|
+
args
|
|
307
|
+
}) {
|
|
308
|
+
var _a, _b;
|
|
309
|
+
const workflowId = "workflowId" in args ? args.workflowId : (_b = (_a = args.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id;
|
|
310
|
+
try {
|
|
311
|
+
emitter.emit("subscription.preference.update.pending", {
|
|
312
|
+
args,
|
|
313
|
+
data: "preference" in args ? new SubscriptionPreference(
|
|
314
|
+
__spreadValues(__spreadValues({}, args.preference), typeof args.value === "boolean" ? { enabled: args.value } : { condition: args.value }),
|
|
315
|
+
emitter,
|
|
316
|
+
apiService,
|
|
317
|
+
cache,
|
|
318
|
+
useCache
|
|
319
|
+
) : void 0
|
|
320
|
+
});
|
|
321
|
+
const response = yield apiService.updateSubscriptionPreference(__spreadValues({
|
|
322
|
+
subscriptionId: args.subscriptionId,
|
|
323
|
+
workflowId
|
|
324
|
+
}, typeof args.value === "boolean" ? {
|
|
325
|
+
enabled: args.value,
|
|
326
|
+
email: args.value,
|
|
327
|
+
sms: args.value,
|
|
328
|
+
in_app: args.value,
|
|
329
|
+
chat: args.value,
|
|
330
|
+
push: args.value
|
|
331
|
+
} : { condition: args.value }));
|
|
332
|
+
const updatedSubscription = new SubscriptionPreference(__spreadValues({}, response), emitter, apiService, cache, useCache);
|
|
333
|
+
emitter.emit("subscription.preference.update.resolved", { args, data: updatedSubscription });
|
|
334
|
+
return { data: updatedSubscription };
|
|
335
|
+
} catch (error) {
|
|
336
|
+
emitter.emit("subscription.preference.update.resolved", { args, error });
|
|
337
|
+
return { error: new NovuError("Failed to update subscription", error) };
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
var bulkUpdateSubscriptionPreference = (_0) => __async(void 0, [_0], function* ({
|
|
341
|
+
emitter,
|
|
342
|
+
apiService,
|
|
343
|
+
cache,
|
|
344
|
+
useCache,
|
|
345
|
+
args
|
|
346
|
+
}) {
|
|
347
|
+
try {
|
|
348
|
+
const optimisticallyUpdatedPreferences = args.map(
|
|
349
|
+
(arg) => "preference" in arg ? new SubscriptionPreference(
|
|
350
|
+
__spreadValues(__spreadValues({}, arg.preference), typeof arg.value === "boolean" ? { enabled: arg.value } : { condition: arg.value }),
|
|
351
|
+
emitter,
|
|
352
|
+
apiService,
|
|
353
|
+
cache,
|
|
354
|
+
useCache
|
|
355
|
+
) : void 0
|
|
356
|
+
).filter((el) => el !== void 0);
|
|
357
|
+
emitter.emit("subscription.preferences.bulk_update.pending", {
|
|
358
|
+
args,
|
|
359
|
+
data: optimisticallyUpdatedPreferences
|
|
360
|
+
});
|
|
361
|
+
const preferencesToUpdate = args.map((arg) => {
|
|
362
|
+
var _a, _b, _c, _d, _e, _f;
|
|
363
|
+
return __spreadValues({
|
|
364
|
+
subscriptionIdOrIdentifier: arg.subscriptionId,
|
|
365
|
+
workflowId: "workflowId" in arg ? arg.workflowId : (_f = (_e = (_b = (_a = arg.preference) == null ? void 0 : _a.workflow) == null ? void 0 : _b.id) != null ? _e : (_d = (_c = arg.preference) == null ? void 0 : _c.workflow) == null ? void 0 : _d.identifier) != null ? _f : ""
|
|
366
|
+
}, typeof arg.value === "boolean" ? { enabled: arg.value, email: arg.value, sms: arg.value, in_app: arg.value, chat: arg.value, push: arg.value } : { condition: arg.value });
|
|
367
|
+
});
|
|
368
|
+
const response = yield apiService.bulkUpdateSubscriptionPreferences(preferencesToUpdate);
|
|
369
|
+
const preferences = response.map((el) => new SubscriptionPreference(el, emitter, apiService, cache, useCache));
|
|
370
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, data: preferences });
|
|
371
|
+
return { data: preferences };
|
|
372
|
+
} catch (error) {
|
|
373
|
+
emitter.emit("subscription.preferences.bulk_update.resolved", { args, error });
|
|
374
|
+
return { error: new NovuError("Failed to bulk update subscription preferences", error) };
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
var deleteSubscription = (_0) => __async(void 0, [_0], function* ({
|
|
378
|
+
emitter,
|
|
379
|
+
apiService,
|
|
380
|
+
args
|
|
381
|
+
}) {
|
|
382
|
+
const subscriptionId = "subscriptionId" in args ? args.subscriptionId : args.subscription.id;
|
|
383
|
+
const topicKey = "topicKey" in args ? args.topicKey : args.subscription.topicKey;
|
|
384
|
+
try {
|
|
385
|
+
emitter.emit("subscription.delete.pending", { args });
|
|
386
|
+
yield apiService.deleteSubscription({ topicKey, subscriptionId });
|
|
387
|
+
emitter.emit("subscription.delete.resolved", { args });
|
|
388
|
+
return { data: void 0 };
|
|
389
|
+
} catch (error) {
|
|
390
|
+
emitter.emit("subscription.delete.resolved", { args, error });
|
|
391
|
+
return { error: new NovuError("Failed to delete subscription", error) };
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// src/subscriptions/subscription-preference.ts
|
|
396
|
+
var _emitter2, _inboxService2, _cache2, _useCache2;
|
|
397
|
+
var SubscriptionPreference = class {
|
|
398
|
+
constructor(preference, emitter, inboxService, cache, useCache) {
|
|
399
|
+
__privateAdd(this, _emitter2);
|
|
400
|
+
__privateAdd(this, _inboxService2);
|
|
401
|
+
__privateAdd(this, _cache2);
|
|
402
|
+
__privateAdd(this, _useCache2);
|
|
403
|
+
var _a;
|
|
404
|
+
__privateSet(this, _emitter2, emitter);
|
|
405
|
+
__privateSet(this, _inboxService2, inboxService);
|
|
406
|
+
__privateSet(this, _cache2, cache);
|
|
407
|
+
__privateSet(this, _useCache2, useCache);
|
|
408
|
+
this.enabled = preference.enabled;
|
|
409
|
+
this.condition = (_a = preference.condition) != null ? _a : void 0;
|
|
410
|
+
this.workflow = preference.workflow;
|
|
411
|
+
this.subscriptionId = preference.subscriptionId;
|
|
412
|
+
}
|
|
413
|
+
update(args) {
|
|
414
|
+
return __async(this, null, function* () {
|
|
415
|
+
var _a;
|
|
416
|
+
return updateSubscriptionPreference({
|
|
417
|
+
emitter: __privateGet(this, _emitter2),
|
|
418
|
+
apiService: __privateGet(this, _inboxService2),
|
|
419
|
+
cache: __privateGet(this, _cache2),
|
|
420
|
+
useCache: __privateGet(this, _useCache2),
|
|
421
|
+
args: {
|
|
422
|
+
subscriptionId: this.subscriptionId,
|
|
423
|
+
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
424
|
+
value: args.value,
|
|
425
|
+
preference: this
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
_emitter2 = new WeakMap();
|
|
432
|
+
_inboxService2 = new WeakMap();
|
|
433
|
+
_cache2 = new WeakMap();
|
|
434
|
+
_useCache2 = new WeakMap();
|
|
435
|
+
|
|
436
|
+
// src/base-module.ts
|
|
437
|
+
var _callsQueue, _sessionError;
|
|
438
|
+
var BaseModule = class {
|
|
439
|
+
constructor({
|
|
440
|
+
inboxServiceInstance,
|
|
441
|
+
eventEmitterInstance
|
|
442
|
+
}) {
|
|
443
|
+
__privateAdd(this, _callsQueue, []);
|
|
444
|
+
__privateAdd(this, _sessionError);
|
|
445
|
+
this._emitter = eventEmitterInstance;
|
|
446
|
+
this._inboxService = inboxServiceInstance;
|
|
447
|
+
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
448
|
+
if (data) {
|
|
449
|
+
this.onSessionSuccess(data);
|
|
450
|
+
__privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
|
|
451
|
+
resolve(yield fn());
|
|
452
|
+
}));
|
|
453
|
+
__privateSet(this, _callsQueue, []);
|
|
454
|
+
} else if (error) {
|
|
455
|
+
this.onSessionError(error);
|
|
456
|
+
__privateSet(this, _sessionError, error);
|
|
457
|
+
__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
458
|
+
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
459
|
+
});
|
|
460
|
+
__privateSet(this, _callsQueue, []);
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
onSessionSuccess(_) {
|
|
465
|
+
}
|
|
466
|
+
onSessionError(_) {
|
|
467
|
+
}
|
|
468
|
+
callWithSession(fn) {
|
|
469
|
+
return __async(this, null, function* () {
|
|
470
|
+
if (this._inboxService.isSessionInitialized) {
|
|
471
|
+
return fn();
|
|
472
|
+
}
|
|
473
|
+
if (__privateGet(this, _sessionError)) {
|
|
474
|
+
return Promise.resolve({
|
|
475
|
+
error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return new Promise((resolve, reject) => {
|
|
479
|
+
__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
_callsQueue = new WeakMap();
|
|
485
|
+
_sessionError = new WeakMap();
|
|
486
|
+
|
|
487
|
+
// src/cache/in-memory-cache.ts
|
|
488
|
+
var _cache3;
|
|
489
|
+
var InMemoryCache = class {
|
|
490
|
+
constructor() {
|
|
491
|
+
__privateAdd(this, _cache3);
|
|
492
|
+
__privateSet(this, _cache3, /* @__PURE__ */ new Map());
|
|
493
|
+
}
|
|
494
|
+
get(key) {
|
|
495
|
+
return __privateGet(this, _cache3).get(key);
|
|
496
|
+
}
|
|
497
|
+
getValues() {
|
|
498
|
+
return Array.from(__privateGet(this, _cache3).values());
|
|
499
|
+
}
|
|
500
|
+
entries() {
|
|
501
|
+
return Array.from(__privateGet(this, _cache3).entries());
|
|
502
|
+
}
|
|
503
|
+
keys() {
|
|
504
|
+
return Array.from(__privateGet(this, _cache3).keys());
|
|
505
|
+
}
|
|
506
|
+
set(key, value) {
|
|
507
|
+
__privateGet(this, _cache3).set(key, value);
|
|
508
|
+
}
|
|
509
|
+
remove(key) {
|
|
510
|
+
__privateGet(this, _cache3).delete(key);
|
|
511
|
+
}
|
|
512
|
+
clear() {
|
|
513
|
+
__privateGet(this, _cache3).clear();
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
_cache3 = new WeakMap();
|
|
517
|
+
|
|
518
|
+
// src/cache/subscriptions-cache.ts
|
|
519
|
+
var getListCacheKey = (args) => {
|
|
520
|
+
return `list:${args.topicKey}`;
|
|
521
|
+
};
|
|
522
|
+
var getTopicKeyFromListCacheKey = (key) => {
|
|
523
|
+
return key.split(":")[1];
|
|
524
|
+
};
|
|
525
|
+
var getItemCacheKey = (args) => {
|
|
526
|
+
return `item:${args.topicKey}:${args.identifier}`;
|
|
527
|
+
};
|
|
528
|
+
var _emitter3, _cache4, _useCache3, _itemCache, _inboxService3;
|
|
529
|
+
var SubscriptionsCache = class {
|
|
530
|
+
constructor({
|
|
531
|
+
emitterInstance,
|
|
532
|
+
inboxServiceInstance,
|
|
533
|
+
useCache
|
|
534
|
+
}) {
|
|
535
|
+
__privateAdd(this, _emitter3);
|
|
536
|
+
__privateAdd(this, _cache4);
|
|
537
|
+
__privateAdd(this, _useCache3);
|
|
538
|
+
__privateAdd(this, _itemCache);
|
|
539
|
+
__privateAdd(this, _inboxService3);
|
|
540
|
+
this.handleCreate = (subscription) => {
|
|
541
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
542
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
543
|
+
if (subscriptions) {
|
|
544
|
+
const updatedSubscriptions = [...subscriptions, subscription];
|
|
545
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
546
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
547
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
__privateGet(this, _itemCache).set(
|
|
551
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
552
|
+
subscription
|
|
553
|
+
);
|
|
554
|
+
};
|
|
555
|
+
this.handleUpdate = (subscription) => {
|
|
556
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
557
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
558
|
+
if (subscriptions) {
|
|
559
|
+
const updatedSubscriptions = subscriptions.map((el) => el.id === subscription.id ? subscription : el);
|
|
560
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
561
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
562
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
__privateGet(this, _itemCache).set(
|
|
566
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }),
|
|
567
|
+
subscription
|
|
568
|
+
);
|
|
569
|
+
};
|
|
570
|
+
this.handlePreferenceUpdate = (preference) => {
|
|
571
|
+
this.updateSubscriptionPreferences([preference]);
|
|
572
|
+
};
|
|
573
|
+
this.handleBulkPreferenceUpdate = (preferences) => {
|
|
574
|
+
this.updateSubscriptionPreferences(preferences);
|
|
575
|
+
};
|
|
576
|
+
this.updateSubscriptionPreferences = (updatedPreferences) => {
|
|
577
|
+
var _a;
|
|
578
|
+
const preferencesBySubscription = /* @__PURE__ */ new Map();
|
|
579
|
+
for (const pref of updatedPreferences) {
|
|
580
|
+
const existing = (_a = preferencesBySubscription.get(pref.subscriptionId)) != null ? _a : [];
|
|
581
|
+
existing.push(pref);
|
|
582
|
+
preferencesBySubscription.set(pref.subscriptionId, existing);
|
|
583
|
+
}
|
|
584
|
+
const allListKeys = __privateGet(this, _cache4).keys();
|
|
585
|
+
for (const listKey of allListKeys) {
|
|
586
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
587
|
+
if (!subscriptions) continue;
|
|
588
|
+
let hasUpdates = false;
|
|
589
|
+
const updatedSubscriptions = subscriptions.map((subscription) => {
|
|
590
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
591
|
+
if (subscriptionPreferences) {
|
|
592
|
+
hasUpdates = true;
|
|
593
|
+
return this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
594
|
+
}
|
|
595
|
+
return subscription;
|
|
596
|
+
});
|
|
597
|
+
if (hasUpdates) {
|
|
598
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
599
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
600
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
605
|
+
for (const key of allItemKeys) {
|
|
606
|
+
const subscription = __privateGet(this, _itemCache).get(key);
|
|
607
|
+
if (!subscription) continue;
|
|
608
|
+
const subscriptionPreferences = preferencesBySubscription.get(subscription.id);
|
|
609
|
+
if (subscriptionPreferences) {
|
|
610
|
+
const updatedSubscription = this.createUpdatedSubscription(subscription, subscriptionPreferences);
|
|
611
|
+
__privateGet(this, _itemCache).set(key, updatedSubscription);
|
|
612
|
+
__privateGet(this, _emitter3).emit("subscription.update.resolved", {
|
|
613
|
+
args: { subscription },
|
|
614
|
+
data: updatedSubscription
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
this.createUpdatedSubscription = (subscription, subscriptionPreferences) => {
|
|
620
|
+
var _a;
|
|
621
|
+
const updatedPreferences = (_a = subscription.preferences) == null ? void 0 : _a.map((pref) => {
|
|
622
|
+
const newPreference = subscriptionPreferences.find((el) => el.workflow.id === pref.workflow.id);
|
|
623
|
+
if (newPreference) {
|
|
624
|
+
return newPreference;
|
|
625
|
+
}
|
|
626
|
+
return pref;
|
|
627
|
+
});
|
|
628
|
+
return new TopicSubscription(
|
|
629
|
+
{
|
|
630
|
+
id: subscription.id,
|
|
631
|
+
identifier: subscription.identifier,
|
|
632
|
+
topicKey: subscription.topicKey,
|
|
633
|
+
preferences: updatedPreferences
|
|
634
|
+
},
|
|
635
|
+
__privateGet(this, _emitter3),
|
|
636
|
+
__privateGet(this, _inboxService3),
|
|
637
|
+
this,
|
|
638
|
+
__privateGet(this, _useCache3)
|
|
639
|
+
);
|
|
640
|
+
};
|
|
641
|
+
this.handleDelete = (subscription) => {
|
|
642
|
+
const listKey = getListCacheKey({ topicKey: subscription.topicKey });
|
|
643
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
644
|
+
if (subscriptions) {
|
|
645
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
646
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
647
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
648
|
+
data: { topicKey: subscription.topicKey, subscriptions: updatedSubscriptions }
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier }));
|
|
652
|
+
};
|
|
653
|
+
this.handleDeleteById = (subscriptionId) => {
|
|
654
|
+
const allListKeys = __privateGet(this, _cache4).keys();
|
|
655
|
+
for (const listKey of allListKeys) {
|
|
656
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
657
|
+
if (subscriptions) {
|
|
658
|
+
const subscription = subscriptions.find((el) => el.id === subscriptionId || el.identifier === subscriptionId);
|
|
659
|
+
if (subscription) {
|
|
660
|
+
const updatedSubscriptions = subscriptions.filter((el) => el.id !== subscription.id);
|
|
661
|
+
__privateGet(this, _cache4).set(listKey, updatedSubscriptions);
|
|
662
|
+
__privateGet(this, _emitter3).emit("subscriptions.list.updated", {
|
|
663
|
+
data: { topicKey: getTopicKeyFromListCacheKey(listKey), subscriptions: updatedSubscriptions }
|
|
664
|
+
});
|
|
665
|
+
__privateGet(this, _itemCache).remove(
|
|
666
|
+
getItemCacheKey({ topicKey: subscription.topicKey, identifier: subscription.identifier })
|
|
667
|
+
);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
673
|
+
for (const key of allItemKeys) {
|
|
674
|
+
const subscription = __privateGet(this, _itemCache).get(key);
|
|
675
|
+
if (subscription && (subscription.id === subscriptionId || subscription.identifier === subscriptionId)) {
|
|
676
|
+
__privateGet(this, _itemCache).remove(key);
|
|
677
|
+
return;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
__privateSet(this, _emitter3, emitterInstance);
|
|
682
|
+
__privateSet(this, _cache4, new InMemoryCache());
|
|
683
|
+
__privateSet(this, _itemCache, new InMemoryCache());
|
|
684
|
+
__privateSet(this, _inboxService3, inboxServiceInstance);
|
|
685
|
+
__privateSet(this, _useCache3, useCache);
|
|
686
|
+
__privateGet(this, _emitter3).on("subscription.create.resolved", ({ data }) => {
|
|
687
|
+
if (data) {
|
|
688
|
+
this.handleCreate(data);
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
__privateGet(this, _emitter3).on("subscription.update.resolved", ({ data }) => {
|
|
692
|
+
if (data) {
|
|
693
|
+
this.handleUpdate(data);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
__privateGet(this, _emitter3).on("subscription.delete.resolved", ({ args }) => {
|
|
697
|
+
if ("subscription" in args) {
|
|
698
|
+
this.handleDelete(args.subscription);
|
|
699
|
+
} else if ("subscriptionId" in args) {
|
|
700
|
+
this.handleDeleteById(args.subscriptionId);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
__privateGet(this, _emitter3).on("subscription.preference.update.pending", ({ data }) => {
|
|
704
|
+
if (data) {
|
|
705
|
+
this.handlePreferenceUpdate(data);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
__privateGet(this, _emitter3).on("subscription.preference.update.resolved", ({ data }) => {
|
|
709
|
+
if (data) {
|
|
710
|
+
this.handlePreferenceUpdate(data);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
__privateGet(this, _emitter3).on("subscription.preferences.bulk_update.resolved", ({ data }) => {
|
|
714
|
+
if (data && data.length > 0) {
|
|
715
|
+
this.handleBulkPreferenceUpdate(data);
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
has(args) {
|
|
720
|
+
return __privateGet(this, _cache4).get(getListCacheKey(args)) !== void 0;
|
|
721
|
+
}
|
|
722
|
+
set(args, data) {
|
|
723
|
+
__privateGet(this, _cache4).set(getListCacheKey(args), data);
|
|
724
|
+
for (const subscription of data) {
|
|
725
|
+
__privateGet(this, _itemCache).set(
|
|
726
|
+
getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }),
|
|
727
|
+
subscription
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
setOne(args, data) {
|
|
732
|
+
__privateGet(this, _itemCache).set(getItemCacheKey(args), data);
|
|
733
|
+
}
|
|
734
|
+
getAll(args) {
|
|
735
|
+
return __privateGet(this, _cache4).get(getListCacheKey(args));
|
|
736
|
+
}
|
|
737
|
+
get(args) {
|
|
738
|
+
return __privateGet(this, _itemCache).get(getItemCacheKey(args));
|
|
739
|
+
}
|
|
740
|
+
invalidate(args) {
|
|
741
|
+
const listKey = getListCacheKey({ topicKey: args.topicKey });
|
|
742
|
+
const subscriptions = __privateGet(this, _cache4).get(listKey);
|
|
743
|
+
if (subscriptions) {
|
|
744
|
+
for (const subscription of subscriptions) {
|
|
745
|
+
__privateGet(this, _itemCache).remove(getItemCacheKey({ topicKey: args.topicKey, identifier: subscription.identifier }));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
__privateGet(this, _cache4).remove(listKey);
|
|
749
|
+
const allItemKeys = __privateGet(this, _itemCache).keys();
|
|
750
|
+
for (const key of allItemKeys) {
|
|
751
|
+
if (key.startsWith(`item:${args.topicKey}:`)) {
|
|
752
|
+
__privateGet(this, _itemCache).remove(key);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
clearAll() {
|
|
757
|
+
__privateGet(this, _cache4).clear();
|
|
758
|
+
__privateGet(this, _itemCache).clear();
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
_emitter3 = new WeakMap();
|
|
762
|
+
_cache4 = new WeakMap();
|
|
763
|
+
_useCache3 = new WeakMap();
|
|
764
|
+
_itemCache = new WeakMap();
|
|
765
|
+
_inboxService3 = new WeakMap();
|
|
766
|
+
|
|
767
|
+
// src/subscriptions/subscriptions.ts
|
|
768
|
+
var _useCache4, _subscriber;
|
|
769
|
+
var Subscriptions = class extends BaseModule {
|
|
770
|
+
constructor({
|
|
771
|
+
useCache,
|
|
772
|
+
inboxServiceInstance,
|
|
773
|
+
eventEmitterInstance,
|
|
774
|
+
subscriber
|
|
775
|
+
}) {
|
|
776
|
+
super({
|
|
777
|
+
eventEmitterInstance,
|
|
778
|
+
inboxServiceInstance
|
|
779
|
+
});
|
|
780
|
+
__privateAdd(this, _useCache4);
|
|
781
|
+
__privateAdd(this, _subscriber);
|
|
782
|
+
this.cache = new SubscriptionsCache({
|
|
783
|
+
emitterInstance: this._emitter,
|
|
784
|
+
inboxServiceInstance: this._inboxService,
|
|
785
|
+
useCache
|
|
786
|
+
});
|
|
787
|
+
__privateSet(this, _useCache4, useCache);
|
|
788
|
+
__privateSet(this, _subscriber, subscriber);
|
|
789
|
+
}
|
|
790
|
+
list(args, options) {
|
|
791
|
+
return __async(this, null, function* () {
|
|
792
|
+
return this.callWithSession(
|
|
793
|
+
() => {
|
|
794
|
+
var _a;
|
|
795
|
+
return listSubscriptions({
|
|
796
|
+
emitter: this._emitter,
|
|
797
|
+
apiService: this._inboxService,
|
|
798
|
+
cache: this.cache,
|
|
799
|
+
options: __spreadProps(__spreadValues({}, options), {
|
|
800
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
|
|
801
|
+
}),
|
|
802
|
+
args
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
get(args, options) {
|
|
809
|
+
return __async(this, null, function* () {
|
|
810
|
+
return this.callWithSession(
|
|
811
|
+
() => {
|
|
812
|
+
var _a, _b;
|
|
813
|
+
return getSubscription({
|
|
814
|
+
emitter: this._emitter,
|
|
815
|
+
apiService: this._inboxService,
|
|
816
|
+
cache: this.cache,
|
|
817
|
+
options: __spreadProps(__spreadValues({}, options), {
|
|
818
|
+
useCache: (_a = options == null ? void 0 : options.useCache) != null ? _a : __privateGet(this, _useCache4)
|
|
819
|
+
}),
|
|
820
|
+
args: __spreadProps(__spreadValues({}, args), {
|
|
821
|
+
identifier: (_b = args.identifier) != null ? _b : buildSubscriptionIdentifier({ topicKey: args.topicKey, subscriberId: __privateGet(this, _subscriber).subscriberId })
|
|
822
|
+
})
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
create(args) {
|
|
829
|
+
return __async(this, null, function* () {
|
|
830
|
+
return this.callWithSession(
|
|
831
|
+
() => createSubscription({
|
|
832
|
+
emitter: this._emitter,
|
|
833
|
+
apiService: this._inboxService,
|
|
834
|
+
cache: this.cache,
|
|
835
|
+
useCache: __privateGet(this, _useCache4),
|
|
836
|
+
args
|
|
837
|
+
})
|
|
838
|
+
);
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
update(args) {
|
|
842
|
+
return __async(this, null, function* () {
|
|
843
|
+
return this.callWithSession(
|
|
844
|
+
() => updateSubscription({
|
|
845
|
+
emitter: this._emitter,
|
|
846
|
+
apiService: this._inboxService,
|
|
847
|
+
cache: this.cache,
|
|
848
|
+
useCache: __privateGet(this, _useCache4),
|
|
849
|
+
args
|
|
850
|
+
})
|
|
851
|
+
);
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
delete(args) {
|
|
855
|
+
return __async(this, null, function* () {
|
|
856
|
+
return this.callWithSession(
|
|
857
|
+
() => deleteSubscription({
|
|
858
|
+
emitter: this._emitter,
|
|
859
|
+
apiService: this._inboxService,
|
|
860
|
+
args
|
|
861
|
+
})
|
|
862
|
+
);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
_useCache4 = new WeakMap();
|
|
867
|
+
_subscriber = new WeakMap();
|
|
868
|
+
|
|
99
869
|
// src/api/http-client.ts
|
|
100
870
|
var DEFAULT_API_VERSION = "v1";
|
|
101
|
-
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.11.
|
|
871
|
+
var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.11.2-nightly.20251224.97b30e30dd"}`;
|
|
102
872
|
var HttpClient = class {
|
|
103
873
|
constructor(options = {}) {
|
|
104
874
|
// Environment variable for local development that overrides the default API endpoint without affecting the Inbox DX
|
|
@@ -435,6 +1205,66 @@ var InboxService = class {
|
|
|
435
1205
|
};
|
|
436
1206
|
return __privateGet(this, _httpClient).post("/inbox/events", payload);
|
|
437
1207
|
}
|
|
1208
|
+
fetchSubscriptions(topicKey) {
|
|
1209
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`);
|
|
1210
|
+
}
|
|
1211
|
+
getSubscription(topicKey, identifier, workflowIds, tags) {
|
|
1212
|
+
const searchParams = new URLSearchParams();
|
|
1213
|
+
if (workflowIds == null ? void 0 : workflowIds.length)
|
|
1214
|
+
for (const workflowIdentifier of workflowIds) searchParams.append("workflowIds", workflowIdentifier);
|
|
1215
|
+
if (tags == null ? void 0 : tags.length) for (const tag of tags) searchParams.append("tags", tag);
|
|
1216
|
+
const query = searchParams.size ? `?${searchParams.toString()}` : "";
|
|
1217
|
+
return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${identifier}${query}`);
|
|
1218
|
+
}
|
|
1219
|
+
createSubscription({
|
|
1220
|
+
identifier,
|
|
1221
|
+
name,
|
|
1222
|
+
topicKey,
|
|
1223
|
+
topicName,
|
|
1224
|
+
preferences
|
|
1225
|
+
}) {
|
|
1226
|
+
return __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions`, __spreadValues(__spreadValues({
|
|
1227
|
+
identifier,
|
|
1228
|
+
name
|
|
1229
|
+
}, topicName && { topic: { name: topicName } }), preferences !== void 0 && { preferences }));
|
|
1230
|
+
}
|
|
1231
|
+
updateSubscription({
|
|
1232
|
+
topicKey,
|
|
1233
|
+
subscriptionId,
|
|
1234
|
+
name,
|
|
1235
|
+
preferences
|
|
1236
|
+
}) {
|
|
1237
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`, __spreadValues({
|
|
1238
|
+
name
|
|
1239
|
+
}, preferences !== void 0 && { preferences }));
|
|
1240
|
+
}
|
|
1241
|
+
updateSubscriptionPreference({
|
|
1242
|
+
subscriptionId,
|
|
1243
|
+
workflowId,
|
|
1244
|
+
enabled,
|
|
1245
|
+
condition,
|
|
1246
|
+
email,
|
|
1247
|
+
sms,
|
|
1248
|
+
in_app,
|
|
1249
|
+
chat,
|
|
1250
|
+
push
|
|
1251
|
+
}) {
|
|
1252
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/subscriptions/${subscriptionId}/preferences/${workflowId}`, {
|
|
1253
|
+
enabled,
|
|
1254
|
+
condition,
|
|
1255
|
+
email,
|
|
1256
|
+
sms,
|
|
1257
|
+
in_app,
|
|
1258
|
+
chat,
|
|
1259
|
+
push
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
bulkUpdateSubscriptionPreferences(preferences) {
|
|
1263
|
+
return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/bulk`, { preferences });
|
|
1264
|
+
}
|
|
1265
|
+
deleteSubscription({ topicKey, subscriptionId }) {
|
|
1266
|
+
return __privateGet(this, _httpClient).delete(`${INBOX_ROUTE}/topics/${topicKey}/subscriptions/${subscriptionId}`);
|
|
1267
|
+
}
|
|
438
1268
|
};
|
|
439
1269
|
_httpClient = new WeakMap();
|
|
440
1270
|
var _mittEmitter;
|
|
@@ -458,88 +1288,6 @@ var NovuEventEmitter = class {
|
|
|
458
1288
|
};
|
|
459
1289
|
_mittEmitter = new WeakMap();
|
|
460
1290
|
|
|
461
|
-
// src/base-module.ts
|
|
462
|
-
var _callsQueue, _sessionError;
|
|
463
|
-
var BaseModule = class {
|
|
464
|
-
constructor({
|
|
465
|
-
inboxServiceInstance,
|
|
466
|
-
eventEmitterInstance
|
|
467
|
-
}) {
|
|
468
|
-
__privateAdd(this, _callsQueue, []);
|
|
469
|
-
__privateAdd(this, _sessionError);
|
|
470
|
-
this._emitter = eventEmitterInstance;
|
|
471
|
-
this._inboxService = inboxServiceInstance;
|
|
472
|
-
this._emitter.on("session.initialize.resolved", ({ error, data }) => {
|
|
473
|
-
if (data) {
|
|
474
|
-
this.onSessionSuccess(data);
|
|
475
|
-
__privateGet(this, _callsQueue).forEach((_0) => __async(this, [_0], function* ({ fn, resolve }) {
|
|
476
|
-
resolve(yield fn());
|
|
477
|
-
}));
|
|
478
|
-
__privateSet(this, _callsQueue, []);
|
|
479
|
-
} else if (error) {
|
|
480
|
-
this.onSessionError(error);
|
|
481
|
-
__privateSet(this, _sessionError, error);
|
|
482
|
-
__privateGet(this, _callsQueue).forEach(({ resolve }) => {
|
|
483
|
-
resolve({ error: new NovuError("Failed to initialize session, please contact the support", error) });
|
|
484
|
-
});
|
|
485
|
-
__privateSet(this, _callsQueue, []);
|
|
486
|
-
}
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
onSessionSuccess(_) {
|
|
490
|
-
}
|
|
491
|
-
onSessionError(_) {
|
|
492
|
-
}
|
|
493
|
-
callWithSession(fn) {
|
|
494
|
-
return __async(this, null, function* () {
|
|
495
|
-
if (this._inboxService.isSessionInitialized) {
|
|
496
|
-
return fn();
|
|
497
|
-
}
|
|
498
|
-
if (__privateGet(this, _sessionError)) {
|
|
499
|
-
return Promise.resolve({
|
|
500
|
-
error: new NovuError("Failed to initialize session, please contact the support", __privateGet(this, _sessionError))
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
return new Promise((resolve, reject) => {
|
|
504
|
-
__privateGet(this, _callsQueue).push({ fn, resolve, reject });
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
_callsQueue = new WeakMap();
|
|
510
|
-
_sessionError = new WeakMap();
|
|
511
|
-
|
|
512
|
-
// src/cache/in-memory-cache.ts
|
|
513
|
-
var _cache;
|
|
514
|
-
var InMemoryCache = class {
|
|
515
|
-
constructor() {
|
|
516
|
-
__privateAdd(this, _cache);
|
|
517
|
-
__privateSet(this, _cache, /* @__PURE__ */ new Map());
|
|
518
|
-
}
|
|
519
|
-
get(key) {
|
|
520
|
-
return __privateGet(this, _cache).get(key);
|
|
521
|
-
}
|
|
522
|
-
getValues() {
|
|
523
|
-
return Array.from(__privateGet(this, _cache).values());
|
|
524
|
-
}
|
|
525
|
-
entries() {
|
|
526
|
-
return Array.from(__privateGet(this, _cache).entries());
|
|
527
|
-
}
|
|
528
|
-
keys() {
|
|
529
|
-
return Array.from(__privateGet(this, _cache).keys());
|
|
530
|
-
}
|
|
531
|
-
set(key, value) {
|
|
532
|
-
__privateGet(this, _cache).set(key, value);
|
|
533
|
-
}
|
|
534
|
-
remove(key) {
|
|
535
|
-
__privateGet(this, _cache).delete(key);
|
|
536
|
-
}
|
|
537
|
-
clear() {
|
|
538
|
-
__privateGet(this, _cache).clear();
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
_cache = new WeakMap();
|
|
542
|
-
|
|
543
1291
|
// src/cache/notifications-cache.ts
|
|
544
1292
|
var excludeEmpty = ({
|
|
545
1293
|
tags,
|
|
@@ -606,17 +1354,17 @@ var removeEvents = [
|
|
|
606
1354
|
"notifications.archive_all_read.pending",
|
|
607
1355
|
"notifications.delete_all.pending"
|
|
608
1356
|
];
|
|
609
|
-
var
|
|
1357
|
+
var _emitter4, _inboxService4, _cache5;
|
|
610
1358
|
var NotificationsCache = class {
|
|
611
1359
|
constructor({ emitter, inboxService }) {
|
|
612
|
-
__privateAdd(this,
|
|
613
|
-
__privateAdd(this,
|
|
1360
|
+
__privateAdd(this, _emitter4);
|
|
1361
|
+
__privateAdd(this, _inboxService4);
|
|
614
1362
|
/**
|
|
615
1363
|
* The key is the stringified notifications filter, the values are the paginated notifications.
|
|
616
1364
|
*/
|
|
617
|
-
__privateAdd(this,
|
|
1365
|
+
__privateAdd(this, _cache5);
|
|
618
1366
|
this.updateNotification = (key, data) => {
|
|
619
|
-
const notificationsResponse = __privateGet(this,
|
|
1367
|
+
const notificationsResponse = __privateGet(this, _cache5).get(key);
|
|
620
1368
|
if (!notificationsResponse) {
|
|
621
1369
|
return false;
|
|
622
1370
|
}
|
|
@@ -626,11 +1374,11 @@ var NotificationsCache = class {
|
|
|
626
1374
|
}
|
|
627
1375
|
const updatedNotifications = [...notificationsResponse.notifications];
|
|
628
1376
|
updatedNotifications[index] = data;
|
|
629
|
-
__privateGet(this,
|
|
1377
|
+
__privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), { notifications: updatedNotifications }));
|
|
630
1378
|
return true;
|
|
631
1379
|
};
|
|
632
1380
|
this.removeNotification = (key, data) => {
|
|
633
|
-
const notificationsResponse = __privateGet(this,
|
|
1381
|
+
const notificationsResponse = __privateGet(this, _cache5).get(key);
|
|
634
1382
|
if (!notificationsResponse) {
|
|
635
1383
|
return false;
|
|
636
1384
|
}
|
|
@@ -640,7 +1388,7 @@ var NotificationsCache = class {
|
|
|
640
1388
|
}
|
|
641
1389
|
const newNotifications = [...notificationsResponse.notifications];
|
|
642
1390
|
newNotifications.splice(index, 1);
|
|
643
|
-
__privateGet(this,
|
|
1391
|
+
__privateGet(this, _cache5).set(key, __spreadProps(__spreadValues({}, notificationsResponse), {
|
|
644
1392
|
notifications: newNotifications
|
|
645
1393
|
}));
|
|
646
1394
|
return true;
|
|
@@ -659,8 +1407,8 @@ var NotificationsCache = class {
|
|
|
659
1407
|
notifications = [args.notification];
|
|
660
1408
|
} else if ("notificationId" in args && args.notificationId) {
|
|
661
1409
|
const foundNotifications = [];
|
|
662
|
-
__privateGet(this,
|
|
663
|
-
const cachedResponse = __privateGet(this,
|
|
1410
|
+
__privateGet(this, _cache5).keys().forEach((key) => {
|
|
1411
|
+
const cachedResponse = __privateGet(this, _cache5).get(key);
|
|
664
1412
|
if (cachedResponse) {
|
|
665
1413
|
const found = cachedResponse.notifications.find((n) => n.id === args.notificationId);
|
|
666
1414
|
if (found) {
|
|
@@ -675,7 +1423,7 @@ var NotificationsCache = class {
|
|
|
675
1423
|
return;
|
|
676
1424
|
}
|
|
677
1425
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
678
|
-
__privateGet(this,
|
|
1426
|
+
__privateGet(this, _cache5).keys().forEach((key) => {
|
|
679
1427
|
notifications.forEach((notification) => {
|
|
680
1428
|
let isNotificationFound = false;
|
|
681
1429
|
if (remove) {
|
|
@@ -690,27 +1438,27 @@ var NotificationsCache = class {
|
|
|
690
1438
|
});
|
|
691
1439
|
uniqueFilterKeys.forEach((key) => {
|
|
692
1440
|
const notificationsResponse = this.getAggregated(getFilter(key));
|
|
693
|
-
__privateGet(this,
|
|
1441
|
+
__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
694
1442
|
data: notificationsResponse
|
|
695
1443
|
});
|
|
696
1444
|
});
|
|
697
1445
|
};
|
|
698
|
-
__privateSet(this,
|
|
699
|
-
__privateSet(this,
|
|
1446
|
+
__privateSet(this, _emitter4, emitter);
|
|
1447
|
+
__privateSet(this, _inboxService4, inboxService);
|
|
700
1448
|
updateEvents.forEach((event) => {
|
|
701
|
-
__privateGet(this,
|
|
1449
|
+
__privateGet(this, _emitter4).on(event, this.handleNotificationEvent());
|
|
702
1450
|
});
|
|
703
1451
|
removeEvents.forEach((event) => {
|
|
704
|
-
__privateGet(this,
|
|
1452
|
+
__privateGet(this, _emitter4).on(event, this.handleNotificationEvent({ remove: true }));
|
|
705
1453
|
});
|
|
706
|
-
__privateSet(this,
|
|
1454
|
+
__privateSet(this, _cache5, new InMemoryCache());
|
|
707
1455
|
}
|
|
708
1456
|
getAggregated(filter) {
|
|
709
|
-
const cacheKeys = __privateGet(this,
|
|
1457
|
+
const cacheKeys = __privateGet(this, _cache5).keys().filter((key) => {
|
|
710
1458
|
const parsedFilter = getFilter(key);
|
|
711
1459
|
return isSameFilter(parsedFilter, filter);
|
|
712
1460
|
});
|
|
713
|
-
return cacheKeys.map((key) => __privateGet(this,
|
|
1461
|
+
return cacheKeys.map((key) => __privateGet(this, _cache5).get(key)).reduce(
|
|
714
1462
|
(acc, el) => {
|
|
715
1463
|
if (!el) {
|
|
716
1464
|
return acc;
|
|
@@ -725,25 +1473,25 @@ var NotificationsCache = class {
|
|
|
725
1473
|
);
|
|
726
1474
|
}
|
|
727
1475
|
get(args) {
|
|
728
|
-
return __privateGet(this,
|
|
1476
|
+
return __privateGet(this, _cache5).get(getCacheKey(args));
|
|
729
1477
|
}
|
|
730
1478
|
has(args) {
|
|
731
|
-
return __privateGet(this,
|
|
1479
|
+
return __privateGet(this, _cache5).get(getCacheKey(args)) !== void 0;
|
|
732
1480
|
}
|
|
733
1481
|
set(args, data) {
|
|
734
|
-
__privateGet(this,
|
|
1482
|
+
__privateGet(this, _cache5).set(getCacheKey(args), data);
|
|
735
1483
|
}
|
|
736
1484
|
unshift(args, notification) {
|
|
737
1485
|
const cacheKey = getCacheKey(args);
|
|
738
|
-
const cachedData = __privateGet(this,
|
|
1486
|
+
const cachedData = __privateGet(this, _cache5).get(cacheKey) || {
|
|
739
1487
|
hasMore: false,
|
|
740
1488
|
filter: getFilter(cacheKey),
|
|
741
1489
|
notifications: []
|
|
742
1490
|
};
|
|
743
1491
|
const notificationInstance = createNotification({
|
|
744
1492
|
notification: __spreadValues({}, notification),
|
|
745
|
-
emitter: __privateGet(this,
|
|
746
|
-
inboxService: __privateGet(this,
|
|
1493
|
+
emitter: __privateGet(this, _emitter4),
|
|
1494
|
+
inboxService: __privateGet(this, _inboxService4)
|
|
747
1495
|
});
|
|
748
1496
|
this.update(args, __spreadProps(__spreadValues({}, cachedData), {
|
|
749
1497
|
notifications: [notificationInstance, ...cachedData.notifications]
|
|
@@ -752,7 +1500,7 @@ var NotificationsCache = class {
|
|
|
752
1500
|
update(args, data) {
|
|
753
1501
|
this.set(args, data);
|
|
754
1502
|
const notificationsResponse = this.getAggregated(getFilter(getCacheKey(args)));
|
|
755
|
-
__privateGet(this,
|
|
1503
|
+
__privateGet(this, _emitter4).emit("notifications.list.updated", {
|
|
756
1504
|
data: notificationsResponse
|
|
757
1505
|
});
|
|
758
1506
|
}
|
|
@@ -778,12 +1526,12 @@ var NotificationsCache = class {
|
|
|
778
1526
|
read: read2,
|
|
779
1527
|
data
|
|
780
1528
|
}) {
|
|
781
|
-
const keys = __privateGet(this,
|
|
1529
|
+
const keys = __privateGet(this, _cache5).keys();
|
|
782
1530
|
const uniqueNotifications = /* @__PURE__ */ new Map();
|
|
783
1531
|
keys.forEach((key) => {
|
|
784
1532
|
const filter = getFilter(key);
|
|
785
1533
|
if (areTagsEqual(tags, filter.tags) && areDataEqual(data, filter.data)) {
|
|
786
|
-
const value = __privateGet(this,
|
|
1534
|
+
const value = __privateGet(this, _cache5).get(key);
|
|
787
1535
|
if (!value) {
|
|
788
1536
|
return;
|
|
789
1537
|
}
|
|
@@ -795,23 +1543,23 @@ var NotificationsCache = class {
|
|
|
795
1543
|
return Array.from(uniqueNotifications.values());
|
|
796
1544
|
}
|
|
797
1545
|
clear(filter) {
|
|
798
|
-
const keys = __privateGet(this,
|
|
1546
|
+
const keys = __privateGet(this, _cache5).keys();
|
|
799
1547
|
keys.forEach((key) => {
|
|
800
1548
|
if (isSameFilter(getFilter(key), filter)) {
|
|
801
|
-
__privateGet(this,
|
|
1549
|
+
__privateGet(this, _cache5).remove(key);
|
|
802
1550
|
}
|
|
803
1551
|
});
|
|
804
1552
|
}
|
|
805
1553
|
clearAll() {
|
|
806
|
-
__privateGet(this,
|
|
1554
|
+
__privateGet(this, _cache5).clear();
|
|
807
1555
|
}
|
|
808
1556
|
};
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1557
|
+
_emitter4 = new WeakMap();
|
|
1558
|
+
_inboxService4 = new WeakMap();
|
|
1559
|
+
_cache5 = new WeakMap();
|
|
812
1560
|
|
|
813
1561
|
// src/notifications/notifications.ts
|
|
814
|
-
var
|
|
1562
|
+
var _useCache5;
|
|
815
1563
|
var Notifications = class extends BaseModule {
|
|
816
1564
|
constructor({
|
|
817
1565
|
useCache,
|
|
@@ -822,12 +1570,12 @@ var Notifications = class extends BaseModule {
|
|
|
822
1570
|
eventEmitterInstance,
|
|
823
1571
|
inboxServiceInstance
|
|
824
1572
|
});
|
|
825
|
-
__privateAdd(this,
|
|
1573
|
+
__privateAdd(this, _useCache5);
|
|
826
1574
|
this.cache = new NotificationsCache({
|
|
827
1575
|
emitter: eventEmitterInstance,
|
|
828
1576
|
inboxService: inboxServiceInstance
|
|
829
1577
|
});
|
|
830
|
-
__privateSet(this,
|
|
1578
|
+
__privateSet(this, _useCache5, useCache);
|
|
831
1579
|
}
|
|
832
1580
|
list() {
|
|
833
1581
|
return __async(this, arguments, function* (_a = {}) {
|
|
@@ -835,7 +1583,7 @@ var Notifications = class extends BaseModule {
|
|
|
835
1583
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
836
1584
|
const args = __spreadValues({ limit }, restOptions);
|
|
837
1585
|
try {
|
|
838
|
-
const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this,
|
|
1586
|
+
const shouldUseCache = "useCache" in args ? args.useCache : __privateGet(this, _useCache5);
|
|
839
1587
|
let data = shouldUseCache ? this.cache.getAll(args) : void 0;
|
|
840
1588
|
this._emitter.emit("notifications.list.pending", { args, data });
|
|
841
1589
|
if (!data) {
|
|
@@ -1147,10 +1895,10 @@ var Notifications = class extends BaseModule {
|
|
|
1147
1895
|
});
|
|
1148
1896
|
}
|
|
1149
1897
|
};
|
|
1150
|
-
|
|
1898
|
+
_useCache5 = new WeakMap();
|
|
1151
1899
|
|
|
1152
1900
|
// src/preferences/schedule.ts
|
|
1153
|
-
var
|
|
1901
|
+
var _emitter5, _apiService, _cache6, _useCache6;
|
|
1154
1902
|
var Schedule = class {
|
|
1155
1903
|
constructor(schedule, {
|
|
1156
1904
|
emitterInstance,
|
|
@@ -1158,14 +1906,14 @@ var Schedule = class {
|
|
|
1158
1906
|
cache,
|
|
1159
1907
|
useCache
|
|
1160
1908
|
}) {
|
|
1161
|
-
__privateAdd(this,
|
|
1909
|
+
__privateAdd(this, _emitter5);
|
|
1162
1910
|
__privateAdd(this, _apiService);
|
|
1163
|
-
__privateAdd(this,
|
|
1164
|
-
__privateAdd(this,
|
|
1165
|
-
__privateSet(this,
|
|
1911
|
+
__privateAdd(this, _cache6);
|
|
1912
|
+
__privateAdd(this, _useCache6);
|
|
1913
|
+
__privateSet(this, _emitter5, emitterInstance);
|
|
1166
1914
|
__privateSet(this, _apiService, inboxServiceInstance);
|
|
1167
|
-
__privateSet(this,
|
|
1168
|
-
__privateSet(this,
|
|
1915
|
+
__privateSet(this, _cache6, cache);
|
|
1916
|
+
__privateSet(this, _useCache6, useCache);
|
|
1169
1917
|
this.isEnabled = schedule.isEnabled;
|
|
1170
1918
|
this.weeklySchedule = schedule.weeklySchedule;
|
|
1171
1919
|
}
|
|
@@ -1174,10 +1922,10 @@ var Schedule = class {
|
|
|
1174
1922
|
var _a;
|
|
1175
1923
|
const hasWeeklySchedule = !!args.weeklySchedule || !!this.weeklySchedule;
|
|
1176
1924
|
return updateSchedule({
|
|
1177
|
-
emitter: __privateGet(this,
|
|
1925
|
+
emitter: __privateGet(this, _emitter5),
|
|
1178
1926
|
apiService: __privateGet(this, _apiService),
|
|
1179
|
-
cache: __privateGet(this,
|
|
1180
|
-
useCache: __privateGet(this,
|
|
1927
|
+
cache: __privateGet(this, _cache6),
|
|
1928
|
+
useCache: __privateGet(this, _useCache6),
|
|
1181
1929
|
args: __spreadValues({
|
|
1182
1930
|
isEnabled: (_a = args.isEnabled) != null ? _a : this.isEnabled
|
|
1183
1931
|
}, hasWeeklySchedule && {
|
|
@@ -1187,13 +1935,13 @@ var Schedule = class {
|
|
|
1187
1935
|
});
|
|
1188
1936
|
}
|
|
1189
1937
|
};
|
|
1190
|
-
|
|
1938
|
+
_emitter5 = new WeakMap();
|
|
1191
1939
|
_apiService = new WeakMap();
|
|
1192
|
-
|
|
1193
|
-
|
|
1940
|
+
_cache6 = new WeakMap();
|
|
1941
|
+
_useCache6 = new WeakMap();
|
|
1194
1942
|
|
|
1195
1943
|
// src/preferences/preference.ts
|
|
1196
|
-
var
|
|
1944
|
+
var _emitter6, _apiService2, _cache7, _scheduleCache, _useCache7;
|
|
1197
1945
|
var Preference = class {
|
|
1198
1946
|
constructor(preference, {
|
|
1199
1947
|
emitterInstance,
|
|
@@ -1202,16 +1950,16 @@ var Preference = class {
|
|
|
1202
1950
|
scheduleCache,
|
|
1203
1951
|
useCache
|
|
1204
1952
|
}) {
|
|
1205
|
-
__privateAdd(this,
|
|
1953
|
+
__privateAdd(this, _emitter6);
|
|
1206
1954
|
__privateAdd(this, _apiService2);
|
|
1207
|
-
__privateAdd(this,
|
|
1955
|
+
__privateAdd(this, _cache7);
|
|
1208
1956
|
__privateAdd(this, _scheduleCache);
|
|
1209
|
-
__privateAdd(this,
|
|
1210
|
-
__privateSet(this,
|
|
1957
|
+
__privateAdd(this, _useCache7);
|
|
1958
|
+
__privateSet(this, _emitter6, emitterInstance);
|
|
1211
1959
|
__privateSet(this, _apiService2, inboxServiceInstance);
|
|
1212
|
-
__privateSet(this,
|
|
1960
|
+
__privateSet(this, _cache7, cache);
|
|
1213
1961
|
__privateSet(this, _scheduleCache, scheduleCache);
|
|
1214
|
-
__privateSet(this,
|
|
1962
|
+
__privateSet(this, _useCache7, useCache);
|
|
1215
1963
|
this.level = preference.level;
|
|
1216
1964
|
this.enabled = preference.enabled;
|
|
1217
1965
|
this.channels = preference.channels;
|
|
@@ -1227,11 +1975,11 @@ var Preference = class {
|
|
|
1227
1975
|
}) {
|
|
1228
1976
|
var _a;
|
|
1229
1977
|
return updatePreference({
|
|
1230
|
-
emitter: __privateGet(this,
|
|
1978
|
+
emitter: __privateGet(this, _emitter6),
|
|
1231
1979
|
apiService: __privateGet(this, _apiService2),
|
|
1232
|
-
cache: __privateGet(this,
|
|
1980
|
+
cache: __privateGet(this, _cache7),
|
|
1233
1981
|
scheduleCache: __privateGet(this, _scheduleCache),
|
|
1234
|
-
useCache: __privateGet(this,
|
|
1982
|
+
useCache: __privateGet(this, _useCache7),
|
|
1235
1983
|
args: {
|
|
1236
1984
|
workflowId: (_a = this.workflow) == null ? void 0 : _a.id,
|
|
1237
1985
|
channels: channels || channelPreferences,
|
|
@@ -1240,11 +1988,11 @@ var Preference = class {
|
|
|
1240
1988
|
});
|
|
1241
1989
|
}
|
|
1242
1990
|
};
|
|
1243
|
-
|
|
1991
|
+
_emitter6 = new WeakMap();
|
|
1244
1992
|
_apiService2 = new WeakMap();
|
|
1245
|
-
|
|
1993
|
+
_cache7 = new WeakMap();
|
|
1246
1994
|
_scheduleCache = new WeakMap();
|
|
1247
|
-
|
|
1995
|
+
_useCache7 = new WeakMap();
|
|
1248
1996
|
|
|
1249
1997
|
// src/preferences/helpers.ts
|
|
1250
1998
|
var updatePreference = (_0) => __async(void 0, [_0], function* ({
|
|
@@ -1441,7 +2189,7 @@ var updateSchedule = (_0) => __async(void 0, [_0], function* ({
|
|
|
1441
2189
|
});
|
|
1442
2190
|
|
|
1443
2191
|
// src/preferences/preference-schedule.ts
|
|
1444
|
-
var
|
|
2192
|
+
var _useCache8;
|
|
1445
2193
|
var PreferenceSchedule = class extends BaseModule {
|
|
1446
2194
|
constructor({
|
|
1447
2195
|
cache,
|
|
@@ -1453,16 +2201,16 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
1453
2201
|
eventEmitterInstance,
|
|
1454
2202
|
inboxServiceInstance
|
|
1455
2203
|
});
|
|
1456
|
-
__privateAdd(this,
|
|
2204
|
+
__privateAdd(this, _useCache8);
|
|
1457
2205
|
this.cache = cache;
|
|
1458
|
-
__privateSet(this,
|
|
2206
|
+
__privateSet(this, _useCache8, useCache);
|
|
1459
2207
|
}
|
|
1460
2208
|
get() {
|
|
1461
2209
|
return __async(this, null, function* () {
|
|
1462
2210
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
1463
2211
|
var _a, _b;
|
|
1464
2212
|
try {
|
|
1465
|
-
let data = __privateGet(this,
|
|
2213
|
+
let data = __privateGet(this, _useCache8) ? this.cache.getAll() : void 0;
|
|
1466
2214
|
this._emitter.emit("preference.schedule.get.pending", { args: void 0, data });
|
|
1467
2215
|
if (!data) {
|
|
1468
2216
|
const globalPreference = yield this._inboxService.fetchGlobalPreferences();
|
|
@@ -1475,10 +2223,10 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
1475
2223
|
emitterInstance: this._emitter,
|
|
1476
2224
|
inboxServiceInstance: this._inboxService,
|
|
1477
2225
|
cache: this.cache,
|
|
1478
|
-
useCache: __privateGet(this,
|
|
2226
|
+
useCache: __privateGet(this, _useCache8)
|
|
1479
2227
|
}
|
|
1480
2228
|
);
|
|
1481
|
-
if (__privateGet(this,
|
|
2229
|
+
if (__privateGet(this, _useCache8)) {
|
|
1482
2230
|
this.cache.set(data);
|
|
1483
2231
|
data = this.cache.getAll();
|
|
1484
2232
|
}
|
|
@@ -1502,14 +2250,14 @@ var PreferenceSchedule = class extends BaseModule {
|
|
|
1502
2250
|
emitter: this._emitter,
|
|
1503
2251
|
apiService: this._inboxService,
|
|
1504
2252
|
cache: this.cache,
|
|
1505
|
-
useCache: __privateGet(this,
|
|
2253
|
+
useCache: __privateGet(this, _useCache8),
|
|
1506
2254
|
args
|
|
1507
2255
|
})
|
|
1508
2256
|
);
|
|
1509
2257
|
});
|
|
1510
2258
|
}
|
|
1511
2259
|
};
|
|
1512
|
-
|
|
2260
|
+
_useCache8 = new WeakMap();
|
|
1513
2261
|
|
|
1514
2262
|
// src/cache/preferences-cache.ts
|
|
1515
2263
|
var updateEvents2 = [
|
|
@@ -1532,13 +2280,13 @@ var excludeEmpty2 = ({ tags, severity }) => Object.entries({ tags, severity }).r
|
|
|
1532
2280
|
var getCacheKey2 = ({ tags, severity }) => {
|
|
1533
2281
|
return JSON.stringify(excludeEmpty2({ tags, severity }));
|
|
1534
2282
|
};
|
|
1535
|
-
var
|
|
2283
|
+
var _emitter7, _cache8;
|
|
1536
2284
|
var PreferencesCache = class {
|
|
1537
2285
|
constructor({ emitterInstance }) {
|
|
1538
|
-
__privateAdd(this,
|
|
1539
|
-
__privateAdd(this,
|
|
2286
|
+
__privateAdd(this, _emitter7);
|
|
2287
|
+
__privateAdd(this, _cache8);
|
|
1540
2288
|
this.updatePreference = (key, data) => {
|
|
1541
|
-
const preferences = __privateGet(this,
|
|
2289
|
+
const preferences = __privateGet(this, _cache8).get(key);
|
|
1542
2290
|
if (!preferences) {
|
|
1543
2291
|
return false;
|
|
1544
2292
|
}
|
|
@@ -1553,11 +2301,11 @@ var PreferencesCache = class {
|
|
|
1553
2301
|
}
|
|
1554
2302
|
const updatedPreferences = [...preferences];
|
|
1555
2303
|
updatedPreferences[index] = data;
|
|
1556
|
-
__privateGet(this,
|
|
2304
|
+
__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
1557
2305
|
return true;
|
|
1558
2306
|
};
|
|
1559
2307
|
this.updatePreferenceSchedule = (key, data) => {
|
|
1560
|
-
const preferences = __privateGet(this,
|
|
2308
|
+
const preferences = __privateGet(this, _cache8).get(key);
|
|
1561
2309
|
if (!preferences) {
|
|
1562
2310
|
return false;
|
|
1563
2311
|
}
|
|
@@ -1567,7 +2315,7 @@ var PreferencesCache = class {
|
|
|
1567
2315
|
}
|
|
1568
2316
|
const updatedPreferences = [...preferences];
|
|
1569
2317
|
updatedPreferences[index].schedule = data;
|
|
1570
|
-
__privateGet(this,
|
|
2318
|
+
__privateGet(this, _cache8).set(key, updatedPreferences);
|
|
1571
2319
|
return true;
|
|
1572
2320
|
};
|
|
1573
2321
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -1575,19 +2323,19 @@ var PreferencesCache = class {
|
|
|
1575
2323
|
if (!data) {
|
|
1576
2324
|
return;
|
|
1577
2325
|
}
|
|
1578
|
-
const cacheKeys = __privateGet(this,
|
|
2326
|
+
const cacheKeys = __privateGet(this, _cache8).keys();
|
|
1579
2327
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1580
2328
|
for (const key of cacheKeys) {
|
|
1581
2329
|
const hasUpdatedPreference = this.updatePreferenceSchedule(key, data);
|
|
1582
|
-
const updatedPreference = __privateGet(this,
|
|
2330
|
+
const updatedPreference = __privateGet(this, _cache8).get(key);
|
|
1583
2331
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1584
2332
|
continue;
|
|
1585
2333
|
}
|
|
1586
2334
|
uniqueFilterKeys.add(key);
|
|
1587
2335
|
}
|
|
1588
2336
|
for (const key of uniqueFilterKeys) {
|
|
1589
|
-
__privateGet(this,
|
|
1590
|
-
data: (_a = __privateGet(this,
|
|
2337
|
+
__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2338
|
+
data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
1591
2339
|
});
|
|
1592
2340
|
}
|
|
1593
2341
|
};
|
|
@@ -1597,10 +2345,10 @@ var PreferencesCache = class {
|
|
|
1597
2345
|
}
|
|
1598
2346
|
const preferences = Array.isArray(data) ? data : [data];
|
|
1599
2347
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1600
|
-
__privateGet(this,
|
|
2348
|
+
__privateGet(this, _cache8).keys().forEach((key) => {
|
|
1601
2349
|
preferences.forEach((preference) => {
|
|
1602
2350
|
const hasUpdatedPreference = this.updatePreference(key, preference);
|
|
1603
|
-
const updatedPreference = __privateGet(this,
|
|
2351
|
+
const updatedPreference = __privateGet(this, _cache8).get(key);
|
|
1604
2352
|
if (!hasUpdatedPreference || !updatedPreference) {
|
|
1605
2353
|
return;
|
|
1606
2354
|
}
|
|
@@ -1609,37 +2357,37 @@ var PreferencesCache = class {
|
|
|
1609
2357
|
});
|
|
1610
2358
|
uniqueFilterKeys.forEach((key) => {
|
|
1611
2359
|
var _a;
|
|
1612
|
-
__privateGet(this,
|
|
1613
|
-
data: (_a = __privateGet(this,
|
|
2360
|
+
__privateGet(this, _emitter7).emit("preferences.list.updated", {
|
|
2361
|
+
data: (_a = __privateGet(this, _cache8).get(key)) != null ? _a : []
|
|
1614
2362
|
});
|
|
1615
2363
|
});
|
|
1616
2364
|
};
|
|
1617
|
-
__privateSet(this,
|
|
2365
|
+
__privateSet(this, _emitter7, emitterInstance);
|
|
1618
2366
|
for (const event of updateEvents2) {
|
|
1619
|
-
__privateGet(this,
|
|
2367
|
+
__privateGet(this, _emitter7).on(event, this.handlePreferenceEvent);
|
|
1620
2368
|
}
|
|
1621
2369
|
for (const event of scheduleUpdateEvents) {
|
|
1622
|
-
__privateGet(this,
|
|
2370
|
+
__privateGet(this, _emitter7).on(event, this.handleScheduleEvent);
|
|
1623
2371
|
}
|
|
1624
|
-
__privateSet(this,
|
|
2372
|
+
__privateSet(this, _cache8, new InMemoryCache());
|
|
1625
2373
|
}
|
|
1626
2374
|
has(args) {
|
|
1627
|
-
return __privateGet(this,
|
|
2375
|
+
return __privateGet(this, _cache8).get(getCacheKey2(args)) !== void 0;
|
|
1628
2376
|
}
|
|
1629
2377
|
set(args, data) {
|
|
1630
|
-
__privateGet(this,
|
|
2378
|
+
__privateGet(this, _cache8).set(getCacheKey2(args), data);
|
|
1631
2379
|
}
|
|
1632
2380
|
getAll(args) {
|
|
1633
2381
|
if (this.has(args)) {
|
|
1634
|
-
return __privateGet(this,
|
|
2382
|
+
return __privateGet(this, _cache8).get(getCacheKey2(args));
|
|
1635
2383
|
}
|
|
1636
2384
|
}
|
|
1637
2385
|
clearAll() {
|
|
1638
|
-
__privateGet(this,
|
|
2386
|
+
__privateGet(this, _cache8).clear();
|
|
1639
2387
|
}
|
|
1640
2388
|
};
|
|
1641
|
-
|
|
1642
|
-
|
|
2389
|
+
_emitter7 = new WeakMap();
|
|
2390
|
+
_cache8 = new WeakMap();
|
|
1643
2391
|
|
|
1644
2392
|
// src/cache/schedule-cache.ts
|
|
1645
2393
|
var updateEvents3 = [
|
|
@@ -1649,17 +2397,17 @@ var updateEvents3 = [
|
|
|
1649
2397
|
var getCacheKey3 = () => {
|
|
1650
2398
|
return "schedule";
|
|
1651
2399
|
};
|
|
1652
|
-
var
|
|
2400
|
+
var _emitter8, _cache9;
|
|
1653
2401
|
var ScheduleCache = class {
|
|
1654
2402
|
constructor({ emitterInstance }) {
|
|
1655
|
-
__privateAdd(this,
|
|
1656
|
-
__privateAdd(this,
|
|
2403
|
+
__privateAdd(this, _emitter8);
|
|
2404
|
+
__privateAdd(this, _cache9);
|
|
1657
2405
|
this.updateScheduleInCache = (key, data) => {
|
|
1658
|
-
const schedule = __privateGet(this,
|
|
2406
|
+
const schedule = __privateGet(this, _cache9).get(key);
|
|
1659
2407
|
if (!schedule) {
|
|
1660
2408
|
return false;
|
|
1661
2409
|
}
|
|
1662
|
-
__privateGet(this,
|
|
2410
|
+
__privateGet(this, _cache9).set(key, data);
|
|
1663
2411
|
return true;
|
|
1664
2412
|
};
|
|
1665
2413
|
this.handleScheduleEvent = ({ data }) => {
|
|
@@ -1667,47 +2415,47 @@ var ScheduleCache = class {
|
|
|
1667
2415
|
return;
|
|
1668
2416
|
}
|
|
1669
2417
|
const uniqueFilterKeys = /* @__PURE__ */ new Set();
|
|
1670
|
-
const keys = __privateGet(this,
|
|
2418
|
+
const keys = __privateGet(this, _cache9).keys();
|
|
1671
2419
|
for (const key of keys) {
|
|
1672
2420
|
const hasUpdatedSchedule = this.updateScheduleInCache(key, data);
|
|
1673
|
-
const updatedSchedule = __privateGet(this,
|
|
2421
|
+
const updatedSchedule = __privateGet(this, _cache9).get(key);
|
|
1674
2422
|
if (!hasUpdatedSchedule || !updatedSchedule) {
|
|
1675
2423
|
continue;
|
|
1676
2424
|
}
|
|
1677
2425
|
uniqueFilterKeys.add(key);
|
|
1678
2426
|
}
|
|
1679
2427
|
for (const key of uniqueFilterKeys) {
|
|
1680
|
-
__privateGet(this,
|
|
1681
|
-
data: __privateGet(this,
|
|
2428
|
+
__privateGet(this, _emitter8).emit("preference.schedule.get.updated", {
|
|
2429
|
+
data: __privateGet(this, _cache9).get(key)
|
|
1682
2430
|
});
|
|
1683
2431
|
}
|
|
1684
2432
|
};
|
|
1685
|
-
__privateSet(this,
|
|
2433
|
+
__privateSet(this, _emitter8, emitterInstance);
|
|
1686
2434
|
for (const event of updateEvents3) {
|
|
1687
|
-
__privateGet(this,
|
|
2435
|
+
__privateGet(this, _emitter8).on(event, this.handleScheduleEvent);
|
|
1688
2436
|
}
|
|
1689
|
-
__privateSet(this,
|
|
2437
|
+
__privateSet(this, _cache9, new InMemoryCache());
|
|
1690
2438
|
}
|
|
1691
2439
|
has() {
|
|
1692
|
-
return __privateGet(this,
|
|
2440
|
+
return __privateGet(this, _cache9).get(getCacheKey3()) !== void 0;
|
|
1693
2441
|
}
|
|
1694
2442
|
set(data) {
|
|
1695
|
-
__privateGet(this,
|
|
2443
|
+
__privateGet(this, _cache9).set(getCacheKey3(), data);
|
|
1696
2444
|
}
|
|
1697
2445
|
getAll() {
|
|
1698
2446
|
if (this.has()) {
|
|
1699
|
-
return __privateGet(this,
|
|
2447
|
+
return __privateGet(this, _cache9).get(getCacheKey3());
|
|
1700
2448
|
}
|
|
1701
2449
|
}
|
|
1702
2450
|
clearAll() {
|
|
1703
|
-
__privateGet(this,
|
|
2451
|
+
__privateGet(this, _cache9).clear();
|
|
1704
2452
|
}
|
|
1705
2453
|
};
|
|
1706
|
-
|
|
1707
|
-
|
|
2454
|
+
_emitter8 = new WeakMap();
|
|
2455
|
+
_cache9 = new WeakMap();
|
|
1708
2456
|
|
|
1709
2457
|
// src/preferences/preferences.ts
|
|
1710
|
-
var
|
|
2458
|
+
var _useCache9;
|
|
1711
2459
|
var Preferences = class extends BaseModule {
|
|
1712
2460
|
constructor({
|
|
1713
2461
|
useCache,
|
|
@@ -1718,14 +2466,14 @@ var Preferences = class extends BaseModule {
|
|
|
1718
2466
|
eventEmitterInstance,
|
|
1719
2467
|
inboxServiceInstance
|
|
1720
2468
|
});
|
|
1721
|
-
__privateAdd(this,
|
|
2469
|
+
__privateAdd(this, _useCache9);
|
|
1722
2470
|
this.cache = new PreferencesCache({
|
|
1723
2471
|
emitterInstance: this._emitter
|
|
1724
2472
|
});
|
|
1725
2473
|
this.scheduleCache = new ScheduleCache({
|
|
1726
2474
|
emitterInstance: this._emitter
|
|
1727
2475
|
});
|
|
1728
|
-
__privateSet(this,
|
|
2476
|
+
__privateSet(this, _useCache9, useCache);
|
|
1729
2477
|
this.schedule = new PreferenceSchedule({
|
|
1730
2478
|
cache: this.scheduleCache,
|
|
1731
2479
|
useCache,
|
|
@@ -1738,7 +2486,7 @@ var Preferences = class extends BaseModule {
|
|
|
1738
2486
|
return this.callWithSession(() => __async(this, null, function* () {
|
|
1739
2487
|
var _a;
|
|
1740
2488
|
try {
|
|
1741
|
-
let data = __privateGet(this,
|
|
2489
|
+
let data = __privateGet(this, _useCache9) ? this.cache.getAll(args) : void 0;
|
|
1742
2490
|
this._emitter.emit("preferences.list.pending", { args, data });
|
|
1743
2491
|
if (!data) {
|
|
1744
2492
|
const response = yield this._inboxService.fetchPreferences({
|
|
@@ -1752,10 +2500,10 @@ var Preferences = class extends BaseModule {
|
|
|
1752
2500
|
inboxServiceInstance: this._inboxService,
|
|
1753
2501
|
cache: this.cache,
|
|
1754
2502
|
scheduleCache: this.scheduleCache,
|
|
1755
|
-
useCache: __privateGet(this,
|
|
2503
|
+
useCache: __privateGet(this, _useCache9)
|
|
1756
2504
|
})
|
|
1757
2505
|
);
|
|
1758
|
-
if (__privateGet(this,
|
|
2506
|
+
if (__privateGet(this, _useCache9)) {
|
|
1759
2507
|
this.cache.set(args, data);
|
|
1760
2508
|
data = this.cache.getAll(args);
|
|
1761
2509
|
}
|
|
@@ -1777,7 +2525,7 @@ var Preferences = class extends BaseModule {
|
|
|
1777
2525
|
apiService: this._inboxService,
|
|
1778
2526
|
cache: this.cache,
|
|
1779
2527
|
scheduleCache: this.scheduleCache,
|
|
1780
|
-
useCache: __privateGet(this,
|
|
2528
|
+
useCache: __privateGet(this, _useCache9),
|
|
1781
2529
|
args
|
|
1782
2530
|
})
|
|
1783
2531
|
);
|
|
@@ -1791,14 +2539,14 @@ var Preferences = class extends BaseModule {
|
|
|
1791
2539
|
apiService: this._inboxService,
|
|
1792
2540
|
cache: this.cache,
|
|
1793
2541
|
scheduleCache: this.scheduleCache,
|
|
1794
|
-
useCache: __privateGet(this,
|
|
2542
|
+
useCache: __privateGet(this, _useCache9),
|
|
1795
2543
|
args
|
|
1796
2544
|
})
|
|
1797
2545
|
);
|
|
1798
2546
|
});
|
|
1799
2547
|
}
|
|
1800
2548
|
};
|
|
1801
|
-
|
|
2549
|
+
_useCache9 = new WeakMap();
|
|
1802
2550
|
|
|
1803
2551
|
// src/utils/is-browser.ts
|
|
1804
2552
|
function isBrowser() {
|
|
@@ -1806,14 +2554,14 @@ function isBrowser() {
|
|
|
1806
2554
|
}
|
|
1807
2555
|
|
|
1808
2556
|
// src/session/session.ts
|
|
1809
|
-
var
|
|
2557
|
+
var _emitter9, _inboxService5, _options;
|
|
1810
2558
|
var Session = class {
|
|
1811
2559
|
constructor(options, inboxServiceInstance, eventEmitterInstance) {
|
|
1812
|
-
__privateAdd(this,
|
|
1813
|
-
__privateAdd(this,
|
|
2560
|
+
__privateAdd(this, _emitter9);
|
|
2561
|
+
__privateAdd(this, _inboxService5);
|
|
1814
2562
|
__privateAdd(this, _options);
|
|
1815
|
-
__privateSet(this,
|
|
1816
|
-
__privateSet(this,
|
|
2563
|
+
__privateSet(this, _emitter9, eventEmitterInstance);
|
|
2564
|
+
__privateSet(this, _inboxService5, inboxServiceInstance);
|
|
1817
2565
|
__privateSet(this, _options, options);
|
|
1818
2566
|
}
|
|
1819
2567
|
get applicationIdentifier() {
|
|
@@ -1884,8 +2632,8 @@ var Session = class {
|
|
|
1884
2632
|
} else {
|
|
1885
2633
|
this.handleApplicationIdentifier("delete");
|
|
1886
2634
|
}
|
|
1887
|
-
__privateGet(this,
|
|
1888
|
-
const response = yield __privateGet(this,
|
|
2635
|
+
__privateGet(this, _emitter9).emit("session.initialize.pending", { args: __privateGet(this, _options) });
|
|
2636
|
+
const response = yield __privateGet(this, _inboxService5).initializeSession({
|
|
1889
2637
|
applicationIdentifier: finalApplicationIdentifier,
|
|
1890
2638
|
subscriberHash,
|
|
1891
2639
|
contextHash,
|
|
@@ -1902,15 +2650,15 @@ var Session = class {
|
|
|
1902
2650
|
if (!((_f = response == null ? void 0 : response.applicationIdentifier) == null ? void 0 : _f.startsWith("pk_keyless_"))) {
|
|
1903
2651
|
this.handleApplicationIdentifier("delete");
|
|
1904
2652
|
}
|
|
1905
|
-
__privateGet(this,
|
|
2653
|
+
__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
|
|
1906
2654
|
} catch (error) {
|
|
1907
|
-
__privateGet(this,
|
|
2655
|
+
__privateGet(this, _emitter9).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
|
|
1908
2656
|
}
|
|
1909
2657
|
});
|
|
1910
2658
|
}
|
|
1911
2659
|
};
|
|
1912
|
-
|
|
1913
|
-
|
|
2660
|
+
_emitter9 = new WeakMap();
|
|
2661
|
+
_inboxService5 = new WeakMap();
|
|
1914
2662
|
_options = new WeakMap();
|
|
1915
2663
|
var PRODUCTION_SOCKET_URL = "wss://socket.novu.co";
|
|
1916
2664
|
var NOTIFICATION_RECEIVED = "notifications.notification_received";
|
|
@@ -2003,7 +2751,7 @@ var mapToNotification = ({
|
|
|
2003
2751
|
severity
|
|
2004
2752
|
});
|
|
2005
2753
|
};
|
|
2006
|
-
var _token,
|
|
2754
|
+
var _token, _emitter10, _partySocket, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _handleMessage, _PartySocketClient_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
|
|
2007
2755
|
var PartySocketClient = class extends BaseModule {
|
|
2008
2756
|
constructor({
|
|
2009
2757
|
socketUrl,
|
|
@@ -2016,15 +2764,15 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2016
2764
|
});
|
|
2017
2765
|
__privateAdd(this, _PartySocketClient_instances);
|
|
2018
2766
|
__privateAdd(this, _token);
|
|
2019
|
-
__privateAdd(this,
|
|
2767
|
+
__privateAdd(this, _emitter10);
|
|
2020
2768
|
__privateAdd(this, _partySocket);
|
|
2021
2769
|
__privateAdd(this, _socketUrl);
|
|
2022
2770
|
__privateAdd(this, _notificationReceived, (event) => {
|
|
2023
2771
|
try {
|
|
2024
2772
|
const data = JSON.parse(event.data);
|
|
2025
2773
|
if (data.event === "notification_received" /* RECEIVED */) {
|
|
2026
|
-
__privateGet(this,
|
|
2027
|
-
result: new Notification(mapToNotification(data.data.message), __privateGet(this,
|
|
2774
|
+
__privateGet(this, _emitter10).emit(NOTIFICATION_RECEIVED, {
|
|
2775
|
+
result: new Notification(mapToNotification(data.data.message), __privateGet(this, _emitter10), this._inboxService)
|
|
2028
2776
|
});
|
|
2029
2777
|
}
|
|
2030
2778
|
} catch (error) {
|
|
@@ -2035,7 +2783,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2035
2783
|
try {
|
|
2036
2784
|
const data = JSON.parse(event.data);
|
|
2037
2785
|
if (data.event === "unseen_count_changed" /* UNSEEN */) {
|
|
2038
|
-
__privateGet(this,
|
|
2786
|
+
__privateGet(this, _emitter10).emit(UNSEEN_COUNT_CHANGED, {
|
|
2039
2787
|
result: data.data.unseenCount
|
|
2040
2788
|
});
|
|
2041
2789
|
}
|
|
@@ -2046,7 +2794,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2046
2794
|
try {
|
|
2047
2795
|
const data = JSON.parse(event.data);
|
|
2048
2796
|
if (data.event === "unread_count_changed" /* UNREAD */) {
|
|
2049
|
-
__privateGet(this,
|
|
2797
|
+
__privateGet(this, _emitter10).emit(UNREAD_COUNT_CHANGED, {
|
|
2050
2798
|
result: data.data.counts
|
|
2051
2799
|
});
|
|
2052
2800
|
}
|
|
@@ -2071,7 +2819,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2071
2819
|
} catch (error) {
|
|
2072
2820
|
}
|
|
2073
2821
|
});
|
|
2074
|
-
__privateSet(this,
|
|
2822
|
+
__privateSet(this, _emitter10, eventEmitterInstance);
|
|
2075
2823
|
__privateSet(this, _socketUrl, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL);
|
|
2076
2824
|
}
|
|
2077
2825
|
onSessionSuccess({ token }) {
|
|
@@ -2098,7 +2846,7 @@ var PartySocketClient = class extends BaseModule {
|
|
|
2098
2846
|
}
|
|
2099
2847
|
};
|
|
2100
2848
|
_token = new WeakMap();
|
|
2101
|
-
|
|
2849
|
+
_emitter10 = new WeakMap();
|
|
2102
2850
|
_partySocket = new WeakMap();
|
|
2103
2851
|
_socketUrl = new WeakMap();
|
|
2104
2852
|
_notificationReceived = new WeakMap();
|
|
@@ -2112,15 +2860,15 @@ initializeSocket_fn = function() {
|
|
|
2112
2860
|
return;
|
|
2113
2861
|
}
|
|
2114
2862
|
const args = { socketUrl: __privateGet(this, _socketUrl) };
|
|
2115
|
-
__privateGet(this,
|
|
2863
|
+
__privateGet(this, _emitter10).emit("socket.connect.pending", { args });
|
|
2116
2864
|
const url = new URL(__privateGet(this, _socketUrl));
|
|
2117
2865
|
url.searchParams.set("token", __privateGet(this, _token));
|
|
2118
2866
|
__privateSet(this, _partySocket, new WebSocket(url.toString()));
|
|
2119
2867
|
__privateGet(this, _partySocket).addEventListener("open", () => {
|
|
2120
|
-
__privateGet(this,
|
|
2868
|
+
__privateGet(this, _emitter10).emit("socket.connect.resolved", { args });
|
|
2121
2869
|
});
|
|
2122
2870
|
__privateGet(this, _partySocket).addEventListener("error", (error) => {
|
|
2123
|
-
__privateGet(this,
|
|
2871
|
+
__privateGet(this, _emitter10).emit("socket.connect.resolved", { args, error });
|
|
2124
2872
|
});
|
|
2125
2873
|
__privateGet(this, _partySocket).addEventListener("message", __privateGet(this, _handleMessage));
|
|
2126
2874
|
});
|
|
@@ -2238,7 +2986,7 @@ var mapToNotification2 = ({
|
|
|
2238
2986
|
severity
|
|
2239
2987
|
});
|
|
2240
2988
|
};
|
|
2241
|
-
var _token2,
|
|
2989
|
+
var _token2, _emitter11, _socketIo, _socketUrl2, _notificationReceived2, _unseenCountChanged2, _unreadCountChanged2, _Socket_instances, initializeSocket_fn2, handleConnectSocket_fn2, handleDisconnectSocket_fn2;
|
|
2242
2990
|
var Socket = class extends BaseModule {
|
|
2243
2991
|
constructor({
|
|
2244
2992
|
socketUrl,
|
|
@@ -2251,25 +2999,25 @@ var Socket = class extends BaseModule {
|
|
|
2251
2999
|
});
|
|
2252
3000
|
__privateAdd(this, _Socket_instances);
|
|
2253
3001
|
__privateAdd(this, _token2);
|
|
2254
|
-
__privateAdd(this,
|
|
3002
|
+
__privateAdd(this, _emitter11);
|
|
2255
3003
|
__privateAdd(this, _socketIo);
|
|
2256
3004
|
__privateAdd(this, _socketUrl2);
|
|
2257
3005
|
__privateAdd(this, _notificationReceived2, ({ message }) => {
|
|
2258
|
-
__privateGet(this,
|
|
2259
|
-
result: new Notification(mapToNotification2(message), __privateGet(this,
|
|
3006
|
+
__privateGet(this, _emitter11).emit(NOTIFICATION_RECEIVED2, {
|
|
3007
|
+
result: new Notification(mapToNotification2(message), __privateGet(this, _emitter11), this._inboxService)
|
|
2260
3008
|
});
|
|
2261
3009
|
});
|
|
2262
3010
|
__privateAdd(this, _unseenCountChanged2, ({ unseenCount }) => {
|
|
2263
|
-
__privateGet(this,
|
|
3011
|
+
__privateGet(this, _emitter11).emit(UNSEEN_COUNT_CHANGED2, {
|
|
2264
3012
|
result: unseenCount
|
|
2265
3013
|
});
|
|
2266
3014
|
});
|
|
2267
3015
|
__privateAdd(this, _unreadCountChanged2, ({ counts }) => {
|
|
2268
|
-
__privateGet(this,
|
|
3016
|
+
__privateGet(this, _emitter11).emit(UNREAD_COUNT_CHANGED2, {
|
|
2269
3017
|
result: counts
|
|
2270
3018
|
});
|
|
2271
3019
|
});
|
|
2272
|
-
__privateSet(this,
|
|
3020
|
+
__privateSet(this, _emitter11, eventEmitterInstance);
|
|
2273
3021
|
__privateSet(this, _socketUrl2, socketUrl != null ? socketUrl : PRODUCTION_SOCKET_URL2);
|
|
2274
3022
|
}
|
|
2275
3023
|
onSessionSuccess({ token }) {
|
|
@@ -2296,7 +3044,7 @@ var Socket = class extends BaseModule {
|
|
|
2296
3044
|
}
|
|
2297
3045
|
};
|
|
2298
3046
|
_token2 = new WeakMap();
|
|
2299
|
-
|
|
3047
|
+
_emitter11 = new WeakMap();
|
|
2300
3048
|
_socketIo = new WeakMap();
|
|
2301
3049
|
_socketUrl2 = new WeakMap();
|
|
2302
3050
|
_notificationReceived2 = new WeakMap();
|
|
@@ -2310,7 +3058,7 @@ initializeSocket_fn2 = function() {
|
|
|
2310
3058
|
return;
|
|
2311
3059
|
}
|
|
2312
3060
|
const args = { socketUrl: __privateGet(this, _socketUrl2) };
|
|
2313
|
-
__privateGet(this,
|
|
3061
|
+
__privateGet(this, _emitter11).emit("socket.connect.pending", { args });
|
|
2314
3062
|
__privateSet(this, _socketIo, io(__privateGet(this, _socketUrl2), {
|
|
2315
3063
|
reconnectionDelayMax: 1e4,
|
|
2316
3064
|
transports: ["websocket"],
|
|
@@ -2319,10 +3067,10 @@ initializeSocket_fn2 = function() {
|
|
|
2319
3067
|
}
|
|
2320
3068
|
}));
|
|
2321
3069
|
__privateGet(this, _socketIo).on("connect", () => {
|
|
2322
|
-
__privateGet(this,
|
|
3070
|
+
__privateGet(this, _emitter11).emit("socket.connect.resolved", { args });
|
|
2323
3071
|
});
|
|
2324
3072
|
__privateGet(this, _socketIo).on("connect_error", (error) => {
|
|
2325
|
-
__privateGet(this,
|
|
3073
|
+
__privateGet(this, _emitter11).emit("socket.connect.resolved", { args, error });
|
|
2326
3074
|
});
|
|
2327
3075
|
(_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.on("notification_received" /* RECEIVED */, __privateGet(this, _notificationReceived2));
|
|
2328
3076
|
(_b = __privateGet(this, _socketIo)) == null ? void 0 : _b.on("unseen_count_changed" /* UNSEEN */, __privateGet(this, _unseenCountChanged2));
|
|
@@ -2396,57 +3144,66 @@ function createSocket({
|
|
|
2396
3144
|
}
|
|
2397
3145
|
|
|
2398
3146
|
// src/novu.ts
|
|
2399
|
-
var
|
|
3147
|
+
var _emitter12, _session, _inboxService6, _options2;
|
|
2400
3148
|
var Novu = class {
|
|
2401
3149
|
constructor(options) {
|
|
2402
|
-
__privateAdd(this,
|
|
3150
|
+
__privateAdd(this, _emitter12);
|
|
2403
3151
|
__privateAdd(this, _session);
|
|
2404
|
-
__privateAdd(this,
|
|
2405
|
-
|
|
2406
|
-
|
|
3152
|
+
__privateAdd(this, _inboxService6);
|
|
3153
|
+
__privateAdd(this, _options2);
|
|
3154
|
+
var _a, _b, _c;
|
|
3155
|
+
__privateSet(this, _options2, options);
|
|
3156
|
+
__privateSet(this, _inboxService6, new InboxService({
|
|
2407
3157
|
apiUrl: options.apiUrl || options.backendUrl,
|
|
2408
3158
|
userAgent: options.__userAgent
|
|
2409
3159
|
}));
|
|
2410
|
-
__privateSet(this,
|
|
3160
|
+
__privateSet(this, _emitter12, new NovuEventEmitter());
|
|
3161
|
+
const subscriber = buildSubscriber({ subscriberId: options.subscriberId, subscriber: options.subscriber });
|
|
2411
3162
|
__privateSet(this, _session, new Session(
|
|
2412
3163
|
{
|
|
2413
3164
|
applicationIdentifier: options.applicationIdentifier || "",
|
|
2414
3165
|
subscriberHash: options.subscriberHash,
|
|
2415
|
-
subscriber
|
|
3166
|
+
subscriber,
|
|
2416
3167
|
defaultSchedule: options.defaultSchedule,
|
|
2417
3168
|
context: options.context,
|
|
2418
3169
|
contextHash: options.contextHash
|
|
2419
3170
|
},
|
|
2420
|
-
__privateGet(this,
|
|
2421
|
-
__privateGet(this,
|
|
3171
|
+
__privateGet(this, _inboxService6),
|
|
3172
|
+
__privateGet(this, _emitter12)
|
|
2422
3173
|
));
|
|
2423
3174
|
__privateGet(this, _session).initialize();
|
|
2424
3175
|
this.notifications = new Notifications({
|
|
2425
3176
|
useCache: (_a = options.useCache) != null ? _a : true,
|
|
2426
|
-
inboxServiceInstance: __privateGet(this,
|
|
2427
|
-
eventEmitterInstance: __privateGet(this,
|
|
3177
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3178
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
2428
3179
|
});
|
|
2429
3180
|
this.preferences = new Preferences({
|
|
2430
3181
|
useCache: (_b = options.useCache) != null ? _b : true,
|
|
2431
|
-
inboxServiceInstance: __privateGet(this,
|
|
2432
|
-
eventEmitterInstance: __privateGet(this,
|
|
3182
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3183
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
3184
|
+
});
|
|
3185
|
+
this.subscriptions = new Subscriptions({
|
|
3186
|
+
subscriber,
|
|
3187
|
+
useCache: (_c = options.useCache) != null ? _c : true,
|
|
3188
|
+
inboxServiceInstance: __privateGet(this, _inboxService6),
|
|
3189
|
+
eventEmitterInstance: __privateGet(this, _emitter12)
|
|
2433
3190
|
});
|
|
2434
3191
|
this.socket = createSocket({
|
|
2435
3192
|
socketUrl: options.socketUrl,
|
|
2436
|
-
eventEmitterInstance: __privateGet(this,
|
|
2437
|
-
inboxServiceInstance: __privateGet(this,
|
|
3193
|
+
eventEmitterInstance: __privateGet(this, _emitter12),
|
|
3194
|
+
inboxServiceInstance: __privateGet(this, _inboxService6)
|
|
2438
3195
|
});
|
|
2439
3196
|
this.on = (eventName, listener) => {
|
|
2440
3197
|
if (this.socket.isSocketEvent(eventName)) {
|
|
2441
3198
|
this.socket.connect();
|
|
2442
3199
|
}
|
|
2443
|
-
const cleanup = __privateGet(this,
|
|
3200
|
+
const cleanup = __privateGet(this, _emitter12).on(eventName, listener);
|
|
2444
3201
|
return () => {
|
|
2445
3202
|
cleanup();
|
|
2446
3203
|
};
|
|
2447
3204
|
};
|
|
2448
3205
|
this.off = (eventName, listener) => {
|
|
2449
|
-
__privateGet(this,
|
|
3206
|
+
__privateGet(this, _emitter12).off(eventName, listener);
|
|
2450
3207
|
};
|
|
2451
3208
|
}
|
|
2452
3209
|
get applicationIdentifier() {
|
|
@@ -2458,9 +3215,21 @@ var Novu = class {
|
|
|
2458
3215
|
get context() {
|
|
2459
3216
|
return __privateGet(this, _session).context;
|
|
2460
3217
|
}
|
|
3218
|
+
get options() {
|
|
3219
|
+
return __privateGet(this, _options2);
|
|
3220
|
+
}
|
|
2461
3221
|
get contextKey() {
|
|
2462
3222
|
return buildContextKey(__privateGet(this, _session).context);
|
|
2463
3223
|
}
|
|
3224
|
+
clearCache() {
|
|
3225
|
+
this.notifications.cache.clearAll();
|
|
3226
|
+
this.preferences.cache.clearAll();
|
|
3227
|
+
this.preferences.scheduleCache.clearAll();
|
|
3228
|
+
this.subscriptions.cache.clearAll();
|
|
3229
|
+
}
|
|
3230
|
+
/**
|
|
3231
|
+
* @deprecated
|
|
3232
|
+
*/
|
|
2464
3233
|
changeSubscriber(options) {
|
|
2465
3234
|
return __async(this, null, function* () {
|
|
2466
3235
|
yield __privateGet(this, _session).initialize({
|
|
@@ -2471,13 +3240,16 @@ var Novu = class {
|
|
|
2471
3240
|
context: __privateGet(this, _session).context,
|
|
2472
3241
|
contextHash: __privateGet(this, _session).contextHash
|
|
2473
3242
|
});
|
|
2474
|
-
this.
|
|
3243
|
+
this.clearCache();
|
|
2475
3244
|
const disconnectResult = yield this.socket.disconnect();
|
|
2476
3245
|
if (!disconnectResult.error) {
|
|
2477
3246
|
yield this.socket.connect();
|
|
2478
3247
|
}
|
|
2479
3248
|
});
|
|
2480
3249
|
}
|
|
3250
|
+
/**
|
|
3251
|
+
* @deprecated
|
|
3252
|
+
*/
|
|
2481
3253
|
changeContext(options) {
|
|
2482
3254
|
return __async(this, null, function* () {
|
|
2483
3255
|
const currentSubscriber = __privateGet(this, _session).subscriber;
|
|
@@ -2492,7 +3264,7 @@ var Novu = class {
|
|
|
2492
3264
|
context: options.context,
|
|
2493
3265
|
contextHash: options.contextHash
|
|
2494
3266
|
});
|
|
2495
|
-
this.
|
|
3267
|
+
this.clearCache();
|
|
2496
3268
|
const disconnectResult = yield this.socket.disconnect();
|
|
2497
3269
|
if (!disconnectResult.error) {
|
|
2498
3270
|
yield this.socket.connect();
|
|
@@ -2500,8 +3272,9 @@ var Novu = class {
|
|
|
2500
3272
|
});
|
|
2501
3273
|
}
|
|
2502
3274
|
};
|
|
2503
|
-
|
|
3275
|
+
_emitter12 = new WeakMap();
|
|
2504
3276
|
_session = new WeakMap();
|
|
2505
|
-
|
|
3277
|
+
_inboxService6 = new WeakMap();
|
|
3278
|
+
_options2 = new WeakMap();
|
|
2506
3279
|
|
|
2507
|
-
export { DEFAULT_API_VERSION, Novu, areSeveritiesEqual, areTagsEqual, checkNotificationDataFilter, checkNotificationMatchesFilter, checkNotificationTagFilter, isBrowser, isSameFilter };
|
|
3280
|
+
export { DEFAULT_API_VERSION, Novu, SubscriptionPreference, TopicSubscription, areSeveritiesEqual, areTagsEqual, checkNotificationDataFilter, checkNotificationMatchesFilter, checkNotificationTagFilter, isBrowser, isSameFilter };
|