@wireapp/api-client 22.2.0 → 22.3.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.
|
@@ -23,6 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.NotificationAPI = exports.NOTIFICATION_SIZE_MAXIMUM = void 0;
|
|
25
25
|
const axios_1 = __importDefault(require("axios"));
|
|
26
|
+
const http_1 = require("../../http");
|
|
26
27
|
exports.NOTIFICATION_SIZE_MAXIMUM = 10000;
|
|
27
28
|
class NotificationAPI {
|
|
28
29
|
constructor(client) {
|
|
@@ -70,9 +71,8 @@ class NotificationAPI {
|
|
|
70
71
|
* @see https://staging-nginz-https.zinfra.io/swagger-ui/#!/push/fetchNotifications
|
|
71
72
|
*/
|
|
72
73
|
async getAllNotifications(clientId, lastNotificationId) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var _a, _b, _c;
|
|
74
|
+
const getNotificationChunks = async (notificationList, currentClientId, currentNotificationId) => {
|
|
75
|
+
var _a, _b, _c, _d;
|
|
76
76
|
const defaultPayload = {
|
|
77
77
|
notifications: [],
|
|
78
78
|
time: '0',
|
|
@@ -84,14 +84,26 @@ class NotificationAPI {
|
|
|
84
84
|
payload = await this.getNotifications(currentClientId, exports.NOTIFICATION_SIZE_MAXIMUM, currentNotificationId);
|
|
85
85
|
}
|
|
86
86
|
catch (error) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
const isAxiosError = axios_1.default.isAxiosError(error);
|
|
88
|
+
//error with response body (before v3 API)
|
|
89
|
+
const isErrorWithNotifications = isAxiosError && ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.notifications);
|
|
90
|
+
//uuid parsing error
|
|
91
|
+
const isBadRequestError = isAxiosError && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.status) === http_1.StatusCode.BAD_REQUEST;
|
|
92
|
+
//notification was not found in the database,
|
|
93
|
+
const isNotFoundError = error instanceof http_1.BackendError && error.label === http_1.BackendErrorLabel.NOT_FOUND;
|
|
94
|
+
if (isBadRequestError || isNotFoundError) {
|
|
95
|
+
//we need to load all the notifications from the beginning (without 'since' param)
|
|
96
|
+
const payload = await getNotificationChunks(notificationList, currentClientId);
|
|
97
|
+
//we have to manually add missedNotification value since it won't be included when called without 'since' param
|
|
98
|
+
return Object.assign(Object.assign({}, payload), { missedNotification: currentNotificationId });
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
if (isErrorWithNotifications) {
|
|
101
|
+
hasMissedNotifications = true;
|
|
102
|
+
payload = Object.assign(Object.assign({}, defaultPayload), (_d = error.response) === null || _d === void 0 ? void 0 : _d.data);
|
|
103
|
+
}
|
|
104
|
+
//throw error for other BackendError type errors
|
|
105
|
+
if (!isAxiosError) {
|
|
106
|
+
throw Error;
|
|
95
107
|
}
|
|
96
108
|
}
|
|
97
109
|
const { notifications, has_more } = payload;
|
|
@@ -101,7 +113,7 @@ class NotificationAPI {
|
|
|
101
113
|
if (has_more) {
|
|
102
114
|
const lastNotification = notifications[notifications.length - 1];
|
|
103
115
|
if (lastNotification) {
|
|
104
|
-
return getNotificationChunks(currentClientId, lastNotification.id);
|
|
116
|
+
return getNotificationChunks(notificationList, currentClientId, lastNotification.id);
|
|
105
117
|
}
|
|
106
118
|
}
|
|
107
119
|
return {
|
|
@@ -109,7 +121,7 @@ class NotificationAPI {
|
|
|
109
121
|
missedNotification: hasMissedNotifications ? currentNotificationId : undefined,
|
|
110
122
|
};
|
|
111
123
|
};
|
|
112
|
-
return getNotificationChunks(clientId, lastNotificationId);
|
|
124
|
+
return getNotificationChunks([], clientId, lastNotificationId);
|
|
113
125
|
}
|
|
114
126
|
/**
|
|
115
127
|
* Fetch a notification by ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationAPI.js","sourceRoot":"","sources":["../../../src/notification/NotificationAPI/NotificationAPI.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;AAEH,kDAAgD;
|
|
1
|
+
{"version":3,"file":"NotificationAPI.js","sourceRoot":"","sources":["../../../src/notification/NotificationAPI/NotificationAPI.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;AAEH,kDAAgD;AAEhD,qCAAmF;AAGtE,QAAA,yBAAyB,GAAG,KAAK,CAAC;AAO/C,MAAa,eAAe;IAC1B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAOnD;;;OAGG;IACI,KAAK,CAAC,mBAAmB,CAAC,QAAiB;QAChD,MAAM,MAAM,GAAuB;YACjC,MAAM,EAAE,KAAK;YACb,MAAM,EAAE;gBACN,MAAM,EAAE,QAAQ;aACjB;YACD,GAAG,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,YAAY,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE;SACvE,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAe,MAAM,CAAC,CAAC;QAClE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,gBAAgB,CAC3B,QAAiB,EACjB,OAAe,iCAAyB,EACxC,KAAc;QAEd,MAAM,MAAM,GAAuB;YACjC,MAAM,EAAE,KAAK;YACb,MAAM,EAAE;gBACN,MAAM,EAAE,QAAQ;gBAChB,KAAK;gBACL,IAAI;aACL;YACD,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,YAAY;SACtC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAmB,MAAM,CAAC,CAAC;QACtE,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC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