@novu/js 2.6.5 → 3.0.0-canary.0

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.
@@ -80,6 +80,229 @@ var areTagsEqual = (tags1, tags2) => {
80
80
  var isSameFilter = (filter1, filter2) => {
81
81
  return areTagsEqual(filter1.tags, filter2.tags) && filter1.read === filter2.read && filter1.archived === filter2.archived;
82
82
  };
83
+
84
+ // src/api/http-client.ts
85
+ var DEFAULT_API_VERSION = "v1";
86
+ var DEFAULT_BACKEND_URL = "https://api.novu.co";
87
+ var DEFAULT_USER_AGENT = `${"@novu/js"}@${"3.0.0-canary.0"}`;
88
+ var HttpClient = class {
89
+ constructor(options = {}) {
90
+ const {
91
+ apiVersion = DEFAULT_API_VERSION,
92
+ apiUrl = DEFAULT_BACKEND_URL,
93
+ userAgent = DEFAULT_USER_AGENT
94
+ } = options || {};
95
+ this.apiVersion = apiVersion;
96
+ this.apiUrl = `${apiUrl}/${this.apiVersion}`;
97
+ this.headers = {
98
+ "Novu-API-Version": "2024-06-26",
99
+ "Content-Type": "application/json",
100
+ "User-Agent": userAgent
101
+ };
102
+ }
103
+ setAuthorizationToken(token) {
104
+ this.headers.Authorization = `Bearer ${token}`;
105
+ }
106
+ setHeaders(headers) {
107
+ this.headers = __spreadValues(__spreadValues({}, this.headers), headers);
108
+ }
109
+ get(path, searchParams, unwrapEnvelope = true) {
110
+ return __async(this, null, function* () {
111
+ return this.doFetch({
112
+ path,
113
+ searchParams,
114
+ options: {
115
+ method: "GET"
116
+ },
117
+ unwrapEnvelope
118
+ });
119
+ });
120
+ }
121
+ post(path, body) {
122
+ return __async(this, null, function* () {
123
+ return this.doFetch({
124
+ path,
125
+ options: {
126
+ method: "POST",
127
+ body
128
+ }
129
+ });
130
+ });
131
+ }
132
+ patch(path, body) {
133
+ return __async(this, null, function* () {
134
+ return this.doFetch({
135
+ path,
136
+ options: {
137
+ method: "PATCH",
138
+ body
139
+ }
140
+ });
141
+ });
142
+ }
143
+ delete(path, body) {
144
+ return __async(this, null, function* () {
145
+ return this.doFetch({
146
+ path,
147
+ options: {
148
+ method: "DELETE",
149
+ body
150
+ }
151
+ });
152
+ });
153
+ }
154
+ doFetch(_0) {
155
+ return __async(this, arguments, function* ({
156
+ path,
157
+ searchParams,
158
+ options,
159
+ unwrapEnvelope = true
160
+ }) {
161
+ const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
162
+ const reqInit = {
163
+ method: (options == null ? void 0 : options.method) || "GET",
164
+ headers: __spreadValues(__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
165
+ body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
166
+ };
167
+ const response = yield fetch(fullUrl, reqInit);
168
+ if (!response.ok) {
169
+ const errorData = yield response.json();
170
+ throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
171
+ }
172
+ if (response.status === 204) {
173
+ return void 0;
174
+ }
175
+ const res = yield response.json();
176
+ return unwrapEnvelope ? res.data : res;
177
+ });
178
+ }
179
+ };
180
+ function combineUrl(...args) {
181
+ return args.reduce((acc, part) => {
182
+ if (part) {
183
+ acc.push(part.replace(new RegExp("(?<!https?:)\\/+", "g"), "/").replace(/^\/+|\/+$/g, ""));
184
+ }
185
+ return acc;
186
+ }, []).join("/").replace(/\/\?/, "?");
187
+ }
188
+
189
+ // src/api/inbox-service.ts
190
+ var INBOX_ROUTE = "/inbox";
191
+ var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
192
+ var _httpClient;
193
+ var InboxService = class {
194
+ constructor(options = {}) {
195
+ this.isSessionInitialized = false;
196
+ __privateAdd(this, _httpClient);
197
+ __privateSet(this, _httpClient, new HttpClient(options));
198
+ }
199
+ initializeSession(_0) {
200
+ return __async(this, arguments, function* ({
201
+ applicationIdentifier,
202
+ subscriberId,
203
+ subscriberHash
204
+ }) {
205
+ const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
206
+ applicationIdentifier,
207
+ subscriberId,
208
+ subscriberHash
209
+ });
210
+ __privateGet(this, _httpClient).setAuthorizationToken(response.token);
211
+ this.isSessionInitialized = true;
212
+ return response;
213
+ });
214
+ }
215
+ fetchNotifications({
216
+ after,
217
+ archived,
218
+ limit = 10,
219
+ offset,
220
+ read: read2,
221
+ tags
222
+ }) {
223
+ const searchParams = new URLSearchParams(`limit=${limit}`);
224
+ if (after) {
225
+ searchParams.append("after", after);
226
+ }
227
+ if (offset) {
228
+ searchParams.append("offset", `${offset}`);
229
+ }
230
+ if (tags) {
231
+ tags.forEach((tag) => searchParams.append("tags[]", tag));
232
+ }
233
+ if (read2 !== void 0) {
234
+ searchParams.append("read", `${read2}`);
235
+ }
236
+ if (archived !== void 0) {
237
+ searchParams.append("archived", `${archived}`);
238
+ }
239
+ return __privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
240
+ }
241
+ count({ filters }) {
242
+ return __privateGet(this, _httpClient).get(
243
+ `${INBOX_NOTIFICATIONS_ROUTE}/count`,
244
+ new URLSearchParams({
245
+ filters: JSON.stringify(filters)
246
+ }),
247
+ false
248
+ );
249
+ }
250
+ read(notificationId) {
251
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
252
+ }
253
+ unread(notificationId) {
254
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
255
+ }
256
+ archive(notificationId) {
257
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
258
+ }
259
+ unarchive(notificationId) {
260
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
261
+ }
262
+ readAll({ tags }) {
263
+ return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
264
+ }
265
+ archiveAll({ tags }) {
266
+ return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
267
+ }
268
+ archiveAllRead({ tags }) {
269
+ return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
270
+ }
271
+ completeAction({
272
+ actionType,
273
+ notificationId
274
+ }) {
275
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
276
+ actionType
277
+ });
278
+ }
279
+ revertAction({
280
+ actionType,
281
+ notificationId
282
+ }) {
283
+ return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
284
+ actionType
285
+ });
286
+ }
287
+ fetchPreferences(tags) {
288
+ const queryParams = new URLSearchParams();
289
+ if (tags) {
290
+ tags.forEach((tag) => queryParams.append("tags[]", tag));
291
+ }
292
+ const query = queryParams.size ? `?${queryParams.toString()}` : "";
293
+ return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
294
+ }
295
+ updateGlobalPreferences(channels) {
296
+ return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channels);
297
+ }
298
+ updateWorkflowPreferences({
299
+ workflowId,
300
+ channels
301
+ }) {
302
+ return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
303
+ }
304
+ };
305
+ _httpClient = new WeakMap();
83
306
  var _mittEmitter;
84
307
  var NovuEventEmitter = class {
85
308
  constructor() {
@@ -1022,38 +1245,6 @@ var Notifications = class extends BaseModule {
1022
1245
  };
1023
1246
  _useCache = new WeakMap();
1024
1247
 
1025
- // src/session/session.ts
1026
- var _emitter3, _inboxService2, _options;
1027
- var Session = class {
1028
- constructor(options, inboxServiceInstance, eventEmitterInstance) {
1029
- __privateAdd(this, _emitter3);
1030
- __privateAdd(this, _inboxService2);
1031
- __privateAdd(this, _options);
1032
- __privateSet(this, _emitter3, eventEmitterInstance);
1033
- __privateSet(this, _inboxService2, inboxServiceInstance);
1034
- __privateSet(this, _options, options);
1035
- }
1036
- initialize() {
1037
- return __async(this, null, function* () {
1038
- try {
1039
- const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
1040
- __privateGet(this, _emitter3).emit("session.initialize.pending", { args: __privateGet(this, _options) });
1041
- const response = yield __privateGet(this, _inboxService2).initializeSession({
1042
- applicationIdentifier,
1043
- subscriberId,
1044
- subscriberHash
1045
- });
1046
- __privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
1047
- } catch (error) {
1048
- __privateGet(this, _emitter3).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
1049
- }
1050
- });
1051
- }
1052
- };
1053
- _emitter3 = new WeakMap();
1054
- _inboxService2 = new WeakMap();
1055
- _options = new WeakMap();
1056
-
1057
1248
  // src/preferences/helpers.ts
1058
1249
  var updatePreference = (_0) => __async(void 0, [_0], function* ({
1059
1250
  emitter,
@@ -1137,7 +1328,7 @@ var optimisticUpdateWorkflowPreferences = ({
1137
1328
  };
1138
1329
 
1139
1330
  // src/preferences/preference.ts
1140
- var _emitter4, _apiService, _cache3, _useCache2;
1331
+ var _emitter3, _apiService, _cache3, _useCache2;
1141
1332
  var Preference = class {
1142
1333
  constructor(preference, {
1143
1334
  emitterInstance,
@@ -1145,11 +1336,11 @@ var Preference = class {
1145
1336
  cache,
1146
1337
  useCache
1147
1338
  }) {
1148
- __privateAdd(this, _emitter4);
1339
+ __privateAdd(this, _emitter3);
1149
1340
  __privateAdd(this, _apiService);
1150
1341
  __privateAdd(this, _cache3);
1151
1342
  __privateAdd(this, _useCache2);
1152
- __privateSet(this, _emitter4, emitterInstance);
1343
+ __privateSet(this, _emitter3, emitterInstance);
1153
1344
  __privateSet(this, _apiService, inboxServiceInstance);
1154
1345
  __privateSet(this, _cache3, cache);
1155
1346
  __privateSet(this, _useCache2, useCache);
@@ -1160,12 +1351,12 @@ var Preference = class {
1160
1351
  }
1161
1352
  update({
1162
1353
  channels,
1163
- // @deprecated use channels instead
1354
+ /** @deprecated Use channels instead */
1164
1355
  channelPreferences
1165
1356
  }) {
1166
1357
  var _a;
1167
1358
  return updatePreference({
1168
- emitter: __privateGet(this, _emitter4),
1359
+ emitter: __privateGet(this, _emitter3),
1169
1360
  apiService: __privateGet(this, _apiService),
1170
1361
  cache: __privateGet(this, _cache3),
1171
1362
  useCache: __privateGet(this, _useCache2),
@@ -1182,7 +1373,7 @@ var Preference = class {
1182
1373
  });
1183
1374
  }
1184
1375
  };
1185
- _emitter4 = new WeakMap();
1376
+ _emitter3 = new WeakMap();
1186
1377
  _apiService = new WeakMap();
1187
1378
  _cache3 = new WeakMap();
1188
1379
  _useCache2 = new WeakMap();
@@ -1199,10 +1390,10 @@ var excludeEmpty2 = ({ tags }) => Object.entries({ tags }).reduce((acc, [key, va
1199
1390
  var getCacheKey2 = ({ tags }) => {
1200
1391
  return JSON.stringify(excludeEmpty2({ tags }));
1201
1392
  };
1202
- var _emitter5, _cache4;
1393
+ var _emitter4, _cache4;
1203
1394
  var PreferencesCache = class {
1204
1395
  constructor({ emitterInstance }) {
1205
- __privateAdd(this, _emitter5);
1396
+ __privateAdd(this, _emitter4);
1206
1397
  __privateAdd(this, _cache4);
1207
1398
  this.updatePreference = (key, data) => {
1208
1399
  const preferences = __privateGet(this, _cache4).get(key);
@@ -1233,14 +1424,14 @@ var PreferencesCache = class {
1233
1424
  if (!hasUpdatedPreference || !updatedPreference) {
1234
1425
  return;
1235
1426
  }
1236
- __privateGet(this, _emitter5).emit("preferences.list.updated", {
1427
+ __privateGet(this, _emitter4).emit("preferences.list.updated", {
1237
1428
  data: updatedPreference
1238
1429
  });
1239
1430
  });
1240
1431
  };
1241
- __privateSet(this, _emitter5, emitterInstance);
1432
+ __privateSet(this, _emitter4, emitterInstance);
1242
1433
  updateEvents2.forEach((event) => {
1243
- __privateGet(this, _emitter5).on(event, this.handlePreferenceEvent);
1434
+ __privateGet(this, _emitter4).on(event, this.handlePreferenceEvent);
1244
1435
  });
1245
1436
  __privateSet(this, _cache4, new InMemoryCache());
1246
1437
  }
@@ -1259,7 +1450,7 @@ var PreferencesCache = class {
1259
1450
  __privateGet(this, _cache4).clear();
1260
1451
  }
1261
1452
  };
1262
- _emitter5 = new WeakMap();
1453
+ _emitter4 = new WeakMap();
1263
1454
  _cache4 = new WeakMap();
1264
1455
 
1265
1456
  // src/preferences/preferences.ts
@@ -1312,7 +1503,39 @@ var Preferences = class extends BaseModule {
1312
1503
  }
1313
1504
  };
1314
1505
  _useCache3 = new WeakMap();
1315
- var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
1506
+
1507
+ // src/session/session.ts
1508
+ var _emitter5, _inboxService2, _options;
1509
+ var Session = class {
1510
+ constructor(options, inboxServiceInstance, eventEmitterInstance) {
1511
+ __privateAdd(this, _emitter5);
1512
+ __privateAdd(this, _inboxService2);
1513
+ __privateAdd(this, _options);
1514
+ __privateSet(this, _emitter5, eventEmitterInstance);
1515
+ __privateSet(this, _inboxService2, inboxServiceInstance);
1516
+ __privateSet(this, _options, options);
1517
+ }
1518
+ initialize() {
1519
+ return __async(this, null, function* () {
1520
+ try {
1521
+ const { applicationIdentifier, subscriberId, subscriberHash } = __privateGet(this, _options);
1522
+ __privateGet(this, _emitter5).emit("session.initialize.pending", { args: __privateGet(this, _options) });
1523
+ const response = yield __privateGet(this, _inboxService2).initializeSession({
1524
+ applicationIdentifier,
1525
+ subscriberId,
1526
+ subscriberHash
1527
+ });
1528
+ __privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), data: response });
1529
+ } catch (error) {
1530
+ __privateGet(this, _emitter5).emit("session.initialize.resolved", { args: __privateGet(this, _options), error });
1531
+ }
1532
+ });
1533
+ }
1534
+ };
1535
+ _emitter5 = new WeakMap();
1536
+ _inboxService2 = new WeakMap();
1537
+ _options = new WeakMap();
1538
+ var PRODUCTION_SOCKET_URL = "https://ws.novu.co";
1316
1539
  var NOTIFICATION_RECEIVED = "notifications.notification_received";
1317
1540
  var UNSEEN_COUNT_CHANGED = "notifications.unseen_count_changed";
1318
1541
  var UNREAD_COUNT_CHANGED = "notifications.unread_count_changed";
@@ -1380,7 +1603,7 @@ var mapToNotification = ({
1380
1603
  data
1381
1604
  };
1382
1605
  };
1383
- var _token, _emitter6, _socketIo, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _Socket_instances, initializeSocket_fn;
1606
+ var _token, _emitter6, _socketIo, _socketUrl, _notificationReceived, _unseenCountChanged, _unreadCountChanged, _Socket_instances, initializeSocket_fn, handleConnectSocket_fn, handleDisconnectSocket_fn;
1384
1607
  var Socket = class extends BaseModule {
1385
1608
  constructor({
1386
1609
  socketUrl,
@@ -1420,19 +1643,21 @@ var Socket = class extends BaseModule {
1420
1643
  isSocketEvent(eventName) {
1421
1644
  return eventName === NOTIFICATION_RECEIVED || eventName === UNSEEN_COUNT_CHANGED || eventName === UNREAD_COUNT_CHANGED;
1422
1645
  }
1423
- initialize() {
1424
- if (__privateGet(this, _token)) {
1425
- __privateMethod(this, _Socket_instances, initializeSocket_fn).call(this).catch((error) => {
1426
- console.error(error);
1427
- });
1428
- return;
1429
- }
1430
- this.callWithSession(() => __async(this, null, function* () {
1431
- __privateMethod(this, _Socket_instances, initializeSocket_fn).call(this).catch((error) => {
1432
- console.error(error);
1433
- });
1434
- return {};
1435
- }));
1646
+ connect() {
1647
+ return __async(this, null, function* () {
1648
+ if (__privateGet(this, _token)) {
1649
+ return __privateMethod(this, _Socket_instances, handleConnectSocket_fn).call(this);
1650
+ }
1651
+ return this.callWithSession(__privateMethod(this, _Socket_instances, handleConnectSocket_fn).bind(this));
1652
+ });
1653
+ }
1654
+ disconnect() {
1655
+ return __async(this, null, function* () {
1656
+ if (__privateGet(this, _socketIo)) {
1657
+ return __privateMethod(this, _Socket_instances, handleDisconnectSocket_fn).call(this);
1658
+ }
1659
+ return this.callWithSession(__privateMethod(this, _Socket_instances, handleDisconnectSocket_fn).bind(this));
1660
+ });
1436
1661
  }
1437
1662
  };
1438
1663
  _token = new WeakMap();
@@ -1469,232 +1694,35 @@ initializeSocket_fn = function() {
1469
1694
  (_c = __privateGet(this, _socketIo)) == null ? void 0 : _c.on("unread_count_changed" /* UNREAD */, __privateGet(this, _unreadCountChanged));
1470
1695
  });
1471
1696
  };
1472
-
1473
- // src/api/http-client.ts
1474
- var DEFAULT_API_VERSION = "v1";
1475
- var DEFAULT_BACKEND_URL = "https://api.novu.co";
1476
- var DEFAULT_USER_AGENT = `${"@novu/js"}@${"2.6.5"}`;
1477
- var HttpClient = class {
1478
- constructor(options = {}) {
1479
- const {
1480
- apiVersion = DEFAULT_API_VERSION,
1481
- apiUrl = DEFAULT_BACKEND_URL,
1482
- userAgent = DEFAULT_USER_AGENT
1483
- } = options || {};
1484
- this.apiVersion = apiVersion;
1485
- this.apiUrl = `${apiUrl}/${this.apiVersion}`;
1486
- this.headers = {
1487
- "Novu-API-Version": "2024-06-26",
1488
- "Content-Type": "application/json",
1489
- "User-Agent": userAgent
1490
- };
1491
- }
1492
- setAuthorizationToken(token) {
1493
- this.headers.Authorization = `Bearer ${token}`;
1494
- }
1495
- setHeaders(headers) {
1496
- this.headers = __spreadValues(__spreadValues({}, this.headers), headers);
1497
- }
1498
- get(path, searchParams, unwrapEnvelope = true) {
1499
- return __async(this, null, function* () {
1500
- return this.doFetch({
1501
- path,
1502
- searchParams,
1503
- options: {
1504
- method: "GET"
1505
- },
1506
- unwrapEnvelope
1507
- });
1508
- });
1509
- }
1510
- post(path, body) {
1511
- return __async(this, null, function* () {
1512
- return this.doFetch({
1513
- path,
1514
- options: {
1515
- method: "POST",
1516
- body
1517
- }
1518
- });
1519
- });
1520
- }
1521
- patch(path, body) {
1522
- return __async(this, null, function* () {
1523
- return this.doFetch({
1524
- path,
1525
- options: {
1526
- method: "PATCH",
1527
- body
1528
- }
1529
- });
1530
- });
1531
- }
1532
- delete(path, body) {
1533
- return __async(this, null, function* () {
1534
- return this.doFetch({
1535
- path,
1536
- options: {
1537
- method: "DELETE",
1538
- body
1539
- }
1540
- });
1541
- });
1542
- }
1543
- doFetch(_0) {
1544
- return __async(this, arguments, function* ({
1545
- path,
1546
- searchParams,
1547
- options,
1548
- unwrapEnvelope = true
1549
- }) {
1550
- const fullUrl = combineUrl(this.apiUrl, path, searchParams ? `?${searchParams.toString()}` : "");
1551
- const reqInit = {
1552
- method: (options == null ? void 0 : options.method) || "GET",
1553
- headers: __spreadValues(__spreadValues({}, this.headers), (options == null ? void 0 : options.headers) || {}),
1554
- body: (options == null ? void 0 : options.body) ? JSON.stringify(options.body) : void 0
1555
- };
1556
- const response = yield fetch(fullUrl, reqInit);
1557
- if (!response.ok) {
1558
- const errorData = yield response.json();
1559
- throw new Error(`${this.headers["User-Agent"]} error. Status: ${response.status}, Message: ${errorData.message}`);
1560
- }
1561
- if (response.status === 204) {
1562
- return void 0;
1563
- }
1564
- const res = yield response.json();
1565
- return unwrapEnvelope ? res.data : res;
1566
- });
1567
- }
1568
- };
1569
- function combineUrl(...args) {
1570
- return args.map((part) => part.replace(/^\/+|\/+$/g, "")).join("/");
1571
- }
1572
-
1573
- // src/api/inbox-service.ts
1574
- var INBOX_ROUTE = "/inbox";
1575
- var INBOX_NOTIFICATIONS_ROUTE = `${INBOX_ROUTE}/notifications`;
1576
- var _httpClient;
1577
- var InboxService = class {
1578
- constructor(options = {}) {
1579
- this.isSessionInitialized = false;
1580
- __privateAdd(this, _httpClient);
1581
- __privateSet(this, _httpClient, new HttpClient(options));
1582
- }
1583
- initializeSession(_0) {
1584
- return __async(this, arguments, function* ({
1585
- applicationIdentifier,
1586
- subscriberId,
1587
- subscriberHash
1588
- }) {
1589
- const response = yield __privateGet(this, _httpClient).post(`${INBOX_ROUTE}/session`, {
1590
- applicationIdentifier,
1591
- subscriberId,
1592
- subscriberHash
1593
- });
1594
- __privateGet(this, _httpClient).setAuthorizationToken(response.token);
1595
- this.isSessionInitialized = true;
1596
- return response;
1597
- });
1598
- }
1599
- fetchNotifications({
1600
- after,
1601
- archived,
1602
- limit = 10,
1603
- offset,
1604
- read: read2,
1605
- tags
1606
- }) {
1607
- const searchParams = new URLSearchParams(`limit=${limit}`);
1608
- if (after) {
1609
- searchParams.append("after", after);
1610
- }
1611
- if (offset) {
1612
- searchParams.append("offset", `${offset}`);
1613
- }
1614
- if (tags) {
1615
- tags.forEach((tag) => searchParams.append("tags[]", tag));
1616
- }
1617
- if (read2 !== void 0) {
1618
- searchParams.append("read", `${read2}`);
1619
- }
1620
- if (archived !== void 0) {
1621
- searchParams.append("archived", `${archived}`);
1697
+ handleConnectSocket_fn = function() {
1698
+ return __async(this, null, function* () {
1699
+ try {
1700
+ yield __privateMethod(this, _Socket_instances, initializeSocket_fn).call(this);
1701
+ return {};
1702
+ } catch (error) {
1703
+ return { error: new NovuError("Failed to initialize the socket", error) };
1622
1704
  }
1623
- return __privateGet(this, _httpClient).get(INBOX_NOTIFICATIONS_ROUTE, searchParams, false);
1624
- }
1625
- count({ filters }) {
1626
- return __privateGet(this, _httpClient).get(
1627
- `${INBOX_NOTIFICATIONS_ROUTE}/count`,
1628
- new URLSearchParams({
1629
- filters: JSON.stringify(filters)
1630
- }),
1631
- false
1632
- );
1633
- }
1634
- read(notificationId) {
1635
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/read`);
1636
- }
1637
- unread(notificationId) {
1638
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unread`);
1639
- }
1640
- archive(notificationId) {
1641
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/archive`);
1642
- }
1643
- unarchive(notificationId) {
1644
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/unarchive`);
1645
- }
1646
- readAll({ tags }) {
1647
- return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read`, { tags });
1648
- }
1649
- archiveAll({ tags }) {
1650
- return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/archive`, { tags });
1651
- }
1652
- archiveAllRead({ tags }) {
1653
- return __privateGet(this, _httpClient).post(`${INBOX_NOTIFICATIONS_ROUTE}/read-archive`, { tags });
1654
- }
1655
- completeAction({
1656
- actionType,
1657
- notificationId
1658
- }) {
1659
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/complete`, {
1660
- actionType
1661
- });
1662
- }
1663
- revertAction({
1664
- actionType,
1665
- notificationId
1666
- }) {
1667
- return __privateGet(this, _httpClient).patch(`${INBOX_NOTIFICATIONS_ROUTE}/${notificationId}/revert`, {
1668
- actionType
1669
- });
1670
- }
1671
- fetchPreferences(tags) {
1672
- const queryParams = new URLSearchParams();
1673
- if (tags) {
1674
- tags.forEach((tag) => queryParams.append("tags[]", tag));
1705
+ });
1706
+ };
1707
+ handleDisconnectSocket_fn = function() {
1708
+ return __async(this, null, function* () {
1709
+ var _a;
1710
+ try {
1711
+ (_a = __privateGet(this, _socketIo)) == null ? void 0 : _a.disconnect();
1712
+ __privateSet(this, _socketIo, void 0);
1713
+ return {};
1714
+ } catch (error) {
1715
+ return { error: new NovuError("Failed to disconnect from the socket", error) };
1675
1716
  }
1676
- const query = queryParams.size ? `?${queryParams.toString()}` : "";
1677
- return __privateGet(this, _httpClient).get(`${INBOX_ROUTE}/preferences${query}`);
1678
- }
1679
- updateGlobalPreferences(channels) {
1680
- return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences`, channels);
1681
- }
1682
- updateWorkflowPreferences({
1683
- workflowId,
1684
- channels
1685
- }) {
1686
- return __privateGet(this, _httpClient).patch(`${INBOX_ROUTE}/preferences/${workflowId}`, channels);
1687
- }
1717
+ });
1688
1718
  };
1689
- _httpClient = new WeakMap();
1690
1719
 
1691
1720
  // src/novu.ts
1692
- var _emitter7, _session, _socket, _inboxService3;
1721
+ var _emitter7, _session, _inboxService3;
1693
1722
  var Novu = class {
1694
1723
  constructor(options) {
1695
1724
  __privateAdd(this, _emitter7);
1696
1725
  __privateAdd(this, _session);
1697
- __privateAdd(this, _socket);
1698
1726
  __privateAdd(this, _inboxService3);
1699
1727
  var _a, _b;
1700
1728
  __privateSet(this, _inboxService3, new InboxService({
@@ -1722,14 +1750,14 @@ var Novu = class {
1722
1750
  inboxServiceInstance: __privateGet(this, _inboxService3),
1723
1751
  eventEmitterInstance: __privateGet(this, _emitter7)
1724
1752
  });
1725
- __privateSet(this, _socket, new Socket({
1753
+ this.socket = new Socket({
1726
1754
  socketUrl: options.socketUrl,
1727
1755
  eventEmitterInstance: __privateGet(this, _emitter7),
1728
1756
  inboxServiceInstance: __privateGet(this, _inboxService3)
1729
- }));
1757
+ });
1730
1758
  this.on = (eventName, listener) => {
1731
- if (__privateGet(this, _socket).isSocketEvent(eventName)) {
1732
- __privateGet(this, _socket).initialize();
1759
+ if (this.socket.isSocketEvent(eventName)) {
1760
+ this.socket.connect();
1733
1761
  }
1734
1762
  const cleanup = __privateGet(this, _emitter7).on(eventName, listener);
1735
1763
  return () => {
@@ -1743,7 +1771,6 @@ var Novu = class {
1743
1771
  };
1744
1772
  _emitter7 = new WeakMap();
1745
1773
  _session = new WeakMap();
1746
- _socket = new WeakMap();
1747
1774
  _inboxService3 = new WeakMap();
1748
1775
 
1749
1776
  export { ActionTypeEnum, ChannelType, CtaType, NotificationActionStatus, NotificationButton, NotificationStatus, Novu, PreferenceLevel, PreferenceOverrideSource, PreferenceOverrideSourceEnum, WebSocketEvent, areTagsEqual, isSameFilter };