@wireapp/api-client 27.67.1 → 27.69.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.
- package/lib/Config.d.ts +1 -1
- package/lib/Config.js +1 -1
- package/lib/auth/AccessTokenStore.d.ts +13 -3
- package/lib/auth/AccessTokenStore.d.ts.map +1 -1
- package/lib/auth/AccessTokenStore.js +33 -10
- package/lib/cells/CellsAPI.d.ts +3 -2
- package/lib/cells/CellsAPI.d.ts.map +1 -1
- package/lib/cells/CellsAPI.js +28 -7
- package/lib/cells/CellsStorage/S3Service.d.ts +6 -2
- package/lib/cells/CellsStorage/S3Service.d.ts.map +1 -1
- package/lib/cells/CellsStorage/S3Service.js +22 -8
- package/lib/demo/http401.js +1 -1
- package/lib/http/HttpClient.js +6 -6
- package/lib/notification/ConsumableNotification.d.ts +75 -48
- package/lib/notification/ConsumableNotification.d.ts.map +1 -1
- package/lib/notification/ConsumableNotification.js +11 -10
- package/lib/notification/NotificationAPI/NotificationsAPI.mocks.js +1 -1
- package/lib/tcp/AcknowledgeEvent.types.d.ts +0 -1
- package/lib/tcp/AcknowledgeEvent.types.d.ts.map +1 -1
- package/lib/tcp/AcknowledgeEvent.types.js +0 -1
- package/lib/tcp/WebSocketClient.d.ts +3 -3
- package/lib/tcp/WebSocketClient.d.ts.map +1 -1
- package/lib/tcp/WebSocketClient.js +25 -11
- package/package.json +2 -2
package/lib/Config.d.ts
CHANGED
package/lib/Config.js
CHANGED
|
@@ -9,15 +9,25 @@ export interface AccessTokenStore {
|
|
|
9
9
|
export declare class AccessTokenStore extends EventEmitter {
|
|
10
10
|
private readonly logger;
|
|
11
11
|
static readonly TOPIC: typeof TOPIC;
|
|
12
|
-
|
|
12
|
+
accessTokenData?: AccessTokenData;
|
|
13
13
|
/**
|
|
14
14
|
* The date at which the token will be invalid. This value should be use with a grain of salt as there might be some time shift between browser and server time
|
|
15
15
|
* It is suggested to add an error margin
|
|
16
16
|
*/
|
|
17
17
|
tokenExpirationDate?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Marker token used when opening a new WebSocket connection.
|
|
20
|
+
* It is used to know we have processed all notifications up to this marker,
|
|
21
|
+
* any notifications received after the marker is returned from websocket
|
|
22
|
+
* are considered live notifications
|
|
23
|
+
* @note This is a random token generated by the client.
|
|
24
|
+
*/
|
|
25
|
+
markerToken?: string;
|
|
18
26
|
constructor();
|
|
19
|
-
delete()
|
|
20
|
-
updateToken(accessToken: AccessTokenData)
|
|
27
|
+
delete: () => Promise<void>;
|
|
28
|
+
updateToken: (accessToken: AccessTokenData) => Promise<AccessTokenData>;
|
|
29
|
+
getNextMarkerToken: () => string;
|
|
30
|
+
getAccessToken: () => string | undefined;
|
|
21
31
|
}
|
|
22
32
|
export {};
|
|
23
33
|
//# sourceMappingURL=AccessTokenStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessTokenStore.d.ts","sourceRoot":"","sources":["../../src/auth/AccessTokenStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AccessTokenStore.d.ts","sourceRoot":"","sources":["../../src/auth/AccessTokenStore.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AAIpC,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAEzC,aAAK,KAAK;IACR,oBAAoB,gDAAgD;CACrE;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,oBAAoB,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI,CAAC;CAC/F;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IAExC,gBAAuB,KAAK,eAAS;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IACzC;;;OAGG;IACI,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAEpC;;;;;;OAMG;IACI,WAAW,CAAC,EAAE,MAAM,CAAC;;IAQrB,MAAM,QAAa,OAAO,CAAC,IAAI,CAAC,CAKrC;IAEK,WAAW,gBAAuB,eAAe,KAAG,OAAO,CAAC,eAAe,CAAC,CAQjF;IAEK,kBAAkB,QAAO,MAAM,CAKpC;IAEK,cAAc,QAAO,MAAM,GAAG,SAAS,CAM5C;CACH"}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.AccessTokenStore = void 0;
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
22
23
|
const events_1 = require("events");
|
|
23
24
|
const commons_1 = require("@wireapp/commons");
|
|
24
25
|
var TOPIC;
|
|
@@ -28,29 +29,51 @@ var TOPIC;
|
|
|
28
29
|
class AccessTokenStore extends events_1.EventEmitter {
|
|
29
30
|
logger;
|
|
30
31
|
static TOPIC = TOPIC;
|
|
31
|
-
|
|
32
|
+
accessTokenData;
|
|
32
33
|
/**
|
|
33
34
|
* The date at which the token will be invalid. This value should be use with a grain of salt as there might be some time shift between browser and server time
|
|
34
35
|
* It is suggested to add an error margin
|
|
35
36
|
*/
|
|
36
37
|
tokenExpirationDate;
|
|
38
|
+
/**
|
|
39
|
+
* Marker token used when opening a new WebSocket connection.
|
|
40
|
+
* It is used to know we have processed all notifications up to this marker,
|
|
41
|
+
* any notifications received after the marker is returned from websocket
|
|
42
|
+
* are considered live notifications
|
|
43
|
+
* @note This is a random token generated by the client.
|
|
44
|
+
*/
|
|
45
|
+
markerToken;
|
|
37
46
|
constructor() {
|
|
38
47
|
super();
|
|
39
48
|
this.logger = commons_1.LogFactory.getLogger('@wireapp/api-client/AccessTokenStore');
|
|
40
49
|
}
|
|
41
|
-
async
|
|
50
|
+
delete = async () => {
|
|
42
51
|
this.logger.log('Deleting local access token');
|
|
43
|
-
this.
|
|
52
|
+
this.accessTokenData = undefined;
|
|
44
53
|
this.tokenExpirationDate = undefined;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
this.markerToken = undefined;
|
|
55
|
+
};
|
|
56
|
+
updateToken = async (accessToken) => {
|
|
57
|
+
if (this.accessTokenData !== accessToken) {
|
|
48
58
|
this.logger.log('Saving local access token');
|
|
49
59
|
this.tokenExpirationDate = Date.now() + accessToken.expires_in * 1000;
|
|
50
|
-
this.
|
|
51
|
-
this.emit(AccessTokenStore.TOPIC.ACCESS_TOKEN_REFRESH, this.
|
|
60
|
+
this.accessTokenData = accessToken;
|
|
61
|
+
this.emit(AccessTokenStore.TOPIC.ACCESS_TOKEN_REFRESH, this.accessTokenData);
|
|
52
62
|
}
|
|
53
|
-
return this.
|
|
54
|
-
}
|
|
63
|
+
return this.accessTokenData;
|
|
64
|
+
};
|
|
65
|
+
getNextMarkerToken = () => {
|
|
66
|
+
const newMarkerToken = (0, uuid_1.v4)();
|
|
67
|
+
this.logger.info('Generated new marker token:', newMarkerToken, 'Previous marker token:', this.markerToken);
|
|
68
|
+
this.markerToken = newMarkerToken;
|
|
69
|
+
return this.markerToken;
|
|
70
|
+
};
|
|
71
|
+
getAccessToken = () => {
|
|
72
|
+
if (this.accessTokenData && this.tokenExpirationDate && this.tokenExpirationDate > Date.now()) {
|
|
73
|
+
return this.accessTokenData.access_token;
|
|
74
|
+
}
|
|
75
|
+
this.logger.warn('Access token is not set or has expired');
|
|
76
|
+
return undefined;
|
|
77
|
+
};
|
|
55
78
|
}
|
|
56
79
|
exports.AccessTokenStore = AccessTokenStore;
|
package/lib/cells/CellsAPI.d.ts
CHANGED
|
@@ -5,12 +5,12 @@ import { HttpClient } from '../http';
|
|
|
5
5
|
export type SortDirection = 'asc' | 'desc';
|
|
6
6
|
interface CellsConfig {
|
|
7
7
|
pydio: {
|
|
8
|
-
apiKey
|
|
8
|
+
apiKey?: string;
|
|
9
9
|
segment: string;
|
|
10
10
|
url: string;
|
|
11
11
|
};
|
|
12
12
|
s3: {
|
|
13
|
-
apiKey
|
|
13
|
+
apiKey?: string;
|
|
14
14
|
bucket: string;
|
|
15
15
|
endpoint: string;
|
|
16
16
|
region: string;
|
|
@@ -30,6 +30,7 @@ export declare class CellsAPI {
|
|
|
30
30
|
httpClient?: HttpClient;
|
|
31
31
|
storageService?: CellsStorage;
|
|
32
32
|
}): void;
|
|
33
|
+
private getHttpClient;
|
|
33
34
|
uploadNodeDraft({ uuid, versionId, path, file, autoRename, progressCallback, abortController, }: {
|
|
34
35
|
uuid: string;
|
|
35
36
|
versionId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellsAPI.d.ts","sourceRoot":"","sources":["../../src/cells/CellsAPI.ts"],"names":[],"mappings":"AAmBA,OAAO,EAGL,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,YAAY,EAAC,MAAM,6BAA6B,CAAC;AAGzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AAEnC,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"CellsAPI.d.ts","sourceRoot":"","sources":["../../src/cells/CellsAPI.ts"],"names":[],"mappings":"AAmBA,OAAO,EAGL,uBAAuB,EACvB,yBAAyB,EACzB,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAC,YAAY,EAAC,MAAM,6BAA6B,CAAC;AAGzD,OAAO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
|
|
40
40
|
initialize({ cellsConfig, httpClient, storageService, }) {
|
|
41
|
-
const http = httpClient ||
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
urls: { ...this.httpClientConfig.urls, rest: cellsConfig.pydio.url + cellsConfig.pydio.segment },
|
|
45
|
-
headers: { ...this.httpClientConfig.headers, Authorization: `Bearer ${cellsConfig.pydio.apiKey}` },
|
|
46
|
-
}, this.accessTokenStore);
|
|
47
|
-
this.storageService = storageService || new S3Service_1.S3Service(cellsConfig.s3);
|
|
41
|
+
const http = httpClient || this.getHttpClient({ cellsConfig });
|
|
42
|
+
this.storageService =
|
|
43
|
+
storageService || new S3Service_1.S3Service({ config: cellsConfig.s3, getAccessToken: this.accessTokenStore.getAccessToken });
|
|
48
44
|
this.client = new cells_sdk_ts_1.NodeServiceApi(undefined, undefined, http.client);
|
|
49
45
|
}
|
|
46
|
+
getHttpClient({ cellsConfig }) {
|
|
47
|
+
const baseHttpClientConfig = {
|
|
48
|
+
...this.httpClientConfig,
|
|
49
|
+
urls: { ...this.httpClientConfig.urls, rest: cellsConfig.pydio.url + cellsConfig.pydio.segment },
|
|
50
|
+
headers: { ...this.httpClientConfig.headers },
|
|
51
|
+
};
|
|
52
|
+
if (cellsConfig.pydio.apiKey) {
|
|
53
|
+
return new http_1.HttpClient({
|
|
54
|
+
...baseHttpClientConfig,
|
|
55
|
+
headers: { ...baseHttpClientConfig.headers, Authorization: `Bearer ${cellsConfig.pydio.apiKey}` },
|
|
56
|
+
}, this.accessTokenStore);
|
|
57
|
+
}
|
|
58
|
+
const http = new http_1.HttpClient(baseHttpClientConfig, this.accessTokenStore);
|
|
59
|
+
// Add axios interceptor to automatically add Authorization header to every request
|
|
60
|
+
// Althouht the HttpClient handles the authorization already (see _sendRequest), as we pass a custom axios instance to the NodeServiceApi, we need to add it manually
|
|
61
|
+
http.client.interceptors.request.use(config => {
|
|
62
|
+
const accessToken = this.accessTokenStore.getAccessToken();
|
|
63
|
+
if (accessToken) {
|
|
64
|
+
config.headers = config.headers || {};
|
|
65
|
+
config.headers.Authorization = `Bearer ${accessToken}`;
|
|
66
|
+
}
|
|
67
|
+
return config;
|
|
68
|
+
});
|
|
69
|
+
return http;
|
|
70
|
+
}
|
|
50
71
|
async uploadNodeDraft({ uuid, versionId, path, file, autoRename = true, progressCallback, abortController, }) {
|
|
51
72
|
if (!this.client || !this.storageService) {
|
|
52
73
|
throw new Error(CONFIGURATION_ERROR);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CellsStorage } from './CellsStorage';
|
|
2
2
|
interface S3ServiceConfig {
|
|
3
|
-
apiKey
|
|
3
|
+
apiKey?: string;
|
|
4
4
|
bucket: string;
|
|
5
5
|
endpoint: string;
|
|
6
6
|
region: string;
|
|
@@ -10,7 +10,11 @@ export declare const PART_SIZE: number;
|
|
|
10
10
|
export declare class S3Service implements CellsStorage {
|
|
11
11
|
private client;
|
|
12
12
|
private bucket;
|
|
13
|
-
|
|
13
|
+
private getAccessToken;
|
|
14
|
+
constructor({ config, getAccessToken }: {
|
|
15
|
+
config: S3ServiceConfig;
|
|
16
|
+
getAccessToken: () => string | undefined;
|
|
17
|
+
});
|
|
14
18
|
putObject({ path, file, metadata, progressCallback, abortController, }: {
|
|
15
19
|
path: string;
|
|
16
20
|
file: File;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"S3Service.d.ts","sourceRoot":"","sources":["../../../src/cells/CellsStorage/S3Service.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAC,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAE/D,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"S3Service.d.ts","sourceRoot":"","sources":["../../../src/cells/CellsStorage/S3Service.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAC,YAAY,EAAoB,MAAM,gBAAgB,CAAC;AAE/D,UAAU,eAAe;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,cAAc,IAAI,CAAC;AAChC,eAAO,MAAM,SAAS,QAAmB,CAAC;AAE1C,qBAAa,SAAU,YAAW,YAAY;IAC5C,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAA2B;gBAErC,EAAC,MAAM,EAAE,cAAc,EAAC,EAAE;QAAC,MAAM,EAAE,eAAe,CAAC;QAAC,cAAc,EAAE,MAAM,MAAM,GAAG,SAAS,CAAA;KAAC;IA6BnG,SAAS,CAAC,EACd,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,gBAAgB,EAChB,eAAe,GAChB,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,IAAI,CAAC;QACX,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;QAC9C,eAAe,CAAC,EAAE,eAAe,CAAC;KACnC,GAAG,OAAO,CAAC,IAAI,CAAC;CA2ClB"}
|
|
@@ -27,16 +27,30 @@ exports.PART_SIZE = 10 * 1024 * 1024; // 10MB
|
|
|
27
27
|
class S3Service {
|
|
28
28
|
client;
|
|
29
29
|
bucket;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
getAccessToken;
|
|
31
|
+
constructor({ config, getAccessToken }) {
|
|
32
|
+
this.bucket = config.bucket;
|
|
33
|
+
this.getAccessToken = getAccessToken;
|
|
32
34
|
this.client = new client_s3_1.S3Client({
|
|
33
|
-
endpoint,
|
|
35
|
+
endpoint: config.endpoint,
|
|
34
36
|
forcePathStyle: true,
|
|
35
|
-
region,
|
|
36
|
-
credentials: async () =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
region: config.region,
|
|
38
|
+
credentials: async () => {
|
|
39
|
+
if (config.apiKey) {
|
|
40
|
+
return {
|
|
41
|
+
accessKeyId: config.apiKey,
|
|
42
|
+
secretAccessKey: 'gatewaysecret',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const accessToken = this.getAccessToken();
|
|
46
|
+
if (!accessToken) {
|
|
47
|
+
throw new Error('No access token available for S3 authentication');
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
accessKeyId: accessToken,
|
|
51
|
+
secretAccessKey: 'gatewaysecret',
|
|
52
|
+
};
|
|
53
|
+
},
|
|
40
54
|
requestChecksumCalculation: 'WHEN_REQUIRED',
|
|
41
55
|
});
|
|
42
56
|
}
|
package/lib/demo/http401.js
CHANGED
|
@@ -21,7 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
const initClient_1 = require("./initClient");
|
|
22
22
|
(async () => {
|
|
23
23
|
const apiClient = await (0, initClient_1.initClient)();
|
|
24
|
-
apiClient['accessTokenStore'].
|
|
24
|
+
apiClient['accessTokenStore'].accessTokenData.access_token = 'invalid';
|
|
25
25
|
await apiClient.api.conversation.getConversationList();
|
|
26
26
|
})().catch(error => {
|
|
27
27
|
console.error(error);
|
package/lib/http/HttpClient.js
CHANGED
|
@@ -124,9 +124,9 @@ class HttpClient extends events_1.EventEmitter {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
async _sendRequest({ config, isFirstTry = true, abortController }) {
|
|
127
|
-
if (this.accessTokenStore.
|
|
127
|
+
if (this.accessTokenStore.accessTokenData) {
|
|
128
128
|
// TODO: remove tokenAsParam
|
|
129
|
-
const { token_type, access_token } = this.accessTokenStore.
|
|
129
|
+
const { token_type, access_token } = this.accessTokenStore.accessTokenData;
|
|
130
130
|
config.headers = {
|
|
131
131
|
...config.headers,
|
|
132
132
|
Authorization: `${token_type} ${access_token}`,
|
|
@@ -153,7 +153,7 @@ class HttpClient extends events_1.EventEmitter {
|
|
|
153
153
|
};
|
|
154
154
|
return this._sendRequest({ config, isFirstTry: false, abortController });
|
|
155
155
|
};
|
|
156
|
-
const hasAccessToken = !!this.accessTokenStore?.
|
|
156
|
+
const hasAccessToken = !!this.accessTokenStore?.accessTokenData;
|
|
157
157
|
if (axios_1.default.isAxiosError(error) && error.response?.status === http_1.StatusCode.UNAUTHORIZED) {
|
|
158
158
|
return retryWithTokenRefresh();
|
|
159
159
|
}
|
|
@@ -201,8 +201,8 @@ class HttpClient extends events_1.EventEmitter {
|
|
|
201
201
|
}
|
|
202
202
|
async refreshAccessToken() {
|
|
203
203
|
let expiredAccessToken;
|
|
204
|
-
if (this.accessTokenStore.
|
|
205
|
-
expiredAccessToken = this.accessTokenStore.
|
|
204
|
+
if (this.accessTokenStore.accessTokenData?.access_token) {
|
|
205
|
+
expiredAccessToken = this.accessTokenStore.accessTokenData;
|
|
206
206
|
}
|
|
207
207
|
const accessToken = await this.postAccess(expiredAccessToken);
|
|
208
208
|
this.logger.info(`Received updated access token. It will expire in "${accessToken.expires_in}" seconds.`, obfuscation_1.ObfuscationUtil.obfuscateAccessToken(accessToken));
|
|
@@ -229,7 +229,7 @@ class HttpClient extends events_1.EventEmitter {
|
|
|
229
229
|
* @param {string} clientId - id of the client with which the new login session will be associated
|
|
230
230
|
*/
|
|
231
231
|
async associateClientWithSession(clientId) {
|
|
232
|
-
const storedToken = this.accessTokenStore.
|
|
232
|
+
const storedToken = this.accessTokenStore.accessTokenData;
|
|
233
233
|
const newToken = await this.postAccess(storedToken, clientId);
|
|
234
234
|
return this.accessTokenStore.updateToken(newToken);
|
|
235
235
|
}
|
|
@@ -7,12 +7,40 @@ import { BackendEvent } from '../event';
|
|
|
7
7
|
export declare enum ConsumableEvent {
|
|
8
8
|
EVENT = "event",
|
|
9
9
|
MISSED = "notifications_missed",
|
|
10
|
-
|
|
10
|
+
SYNCHRONIZATION = "synchronization"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Notification type for synchronization messages sent by the server
|
|
14
|
+
* to indicate the end of the message queue at the time of connection.
|
|
15
|
+
*
|
|
16
|
+
* This message is **only included** if the client initiated the WebSocket
|
|
17
|
+
* connection using a `sync_marker` query parameter.
|
|
18
|
+
* @TODO when BackendEvent is typed in zod use:
|
|
19
|
+
* export type ConsumableNotificationSynchronization = z.infer<typeof ConsumableNotificationSynchronization>;
|
|
20
|
+
*/
|
|
21
|
+
export interface ConsumableNotificationSynchronization {
|
|
22
|
+
/**
|
|
23
|
+
* Always set to "synchronization" to distinguish from other message types.
|
|
24
|
+
*/
|
|
25
|
+
type: ConsumableEvent.SYNCHRONIZATION;
|
|
26
|
+
data: {
|
|
27
|
+
/**
|
|
28
|
+
* Unique delivery tag assigned by the server for this synchronization message.
|
|
29
|
+
* Must be acknowledged once processed to allow server-side cleanup.
|
|
30
|
+
*/
|
|
31
|
+
delivery_tag: number;
|
|
32
|
+
/**
|
|
33
|
+
* Unique identifier (UUID) that matches the `sync_marker` value the client provided
|
|
34
|
+
* during the WebSocket connection initiation. Used to ensure the message
|
|
35
|
+
* corresponds to the current synchronization session.
|
|
36
|
+
*/
|
|
37
|
+
marker_id: string;
|
|
38
|
+
};
|
|
11
39
|
}
|
|
12
40
|
/**
|
|
13
41
|
* Notification type received when the client has missed messages due to being offline too long.
|
|
14
42
|
* Requires a full re-sync before consuming more notifications.
|
|
15
|
-
* TODO
|
|
43
|
+
* @TODO when BackendEvent is typed in zod use:
|
|
16
44
|
* export type ConsumableNotificationMissed = z.infer<typeof ConsumableNotificationMissedSchema>;
|
|
17
45
|
*/
|
|
18
46
|
export interface ConsumableNotificationMissed {
|
|
@@ -21,7 +49,7 @@ export interface ConsumableNotificationMissed {
|
|
|
21
49
|
/**
|
|
22
50
|
* Notification type for actual backend events, contains one or more event payloads.
|
|
23
51
|
* Includes a delivery tag for acknowledgment.
|
|
24
|
-
* TODO
|
|
52
|
+
* @TODO when BackendEvent is typed in zod use:
|
|
25
53
|
* export type ConsumableNotificationEvent = z.infer<typeof ConsumableNotificationEventSchema>;
|
|
26
54
|
*/
|
|
27
55
|
export interface ConsumableNotificationEvent {
|
|
@@ -34,27 +62,41 @@ export interface ConsumableNotificationEvent {
|
|
|
34
62
|
};
|
|
35
63
|
};
|
|
36
64
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Notification sent after connecting to indicate current number of messages queued.
|
|
39
|
-
* TODO: when BackendEvent is typed in zod use:
|
|
40
|
-
* export type ConsumableNotificationMessageCount = z.infer<typeof ConsumableNotificationMessageCountSchema>;
|
|
41
|
-
*/
|
|
42
|
-
export interface ConsumableNotificationMessageCount {
|
|
43
|
-
type: ConsumableEvent.MESSAGE_COUNT;
|
|
44
|
-
data: {
|
|
45
|
-
count: number;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
65
|
/**
|
|
49
66
|
* Union of all valid notification types supported by the WebSocket backend.
|
|
50
|
-
* TODO
|
|
67
|
+
* @TODO when BackendEvent is typed in zod use:
|
|
51
68
|
* export const ConsumableNotificationSchema = z.discriminatedUnion('type', [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
69
|
+
* ConsumableNotificationMissedSchema,
|
|
70
|
+
* ConsumableNotificationEventSchema,
|
|
71
|
+
*. ConsumableNotificationSynchronization
|
|
72
|
+
* ]);
|
|
56
73
|
*/
|
|
57
|
-
export type ConsumableNotification = ConsumableNotificationMissed | ConsumableNotificationEvent |
|
|
74
|
+
export type ConsumableNotification = ConsumableNotificationMissed | ConsumableNotificationEvent | ConsumableNotificationSynchronization;
|
|
75
|
+
export declare const ConsumableNotificationSynchronizationSchema: z.ZodObject<{
|
|
76
|
+
type: z.ZodLiteral<ConsumableEvent.SYNCHRONIZATION>;
|
|
77
|
+
data: z.ZodObject<{
|
|
78
|
+
delivery_tag: z.ZodNumber;
|
|
79
|
+
marker_id: z.ZodString;
|
|
80
|
+
}, "strip", z.ZodTypeAny, {
|
|
81
|
+
delivery_tag: number;
|
|
82
|
+
marker_id: string;
|
|
83
|
+
}, {
|
|
84
|
+
delivery_tag: number;
|
|
85
|
+
marker_id: string;
|
|
86
|
+
}>;
|
|
87
|
+
}, "strip", z.ZodTypeAny, {
|
|
88
|
+
type: ConsumableEvent.SYNCHRONIZATION;
|
|
89
|
+
data: {
|
|
90
|
+
delivery_tag: number;
|
|
91
|
+
marker_id: string;
|
|
92
|
+
};
|
|
93
|
+
}, {
|
|
94
|
+
type: ConsumableEvent.SYNCHRONIZATION;
|
|
95
|
+
data: {
|
|
96
|
+
delivery_tag: number;
|
|
97
|
+
marker_id: string;
|
|
98
|
+
};
|
|
99
|
+
}>;
|
|
58
100
|
export declare const ConsumableNotificationMissedSchema: z.ZodObject<{
|
|
59
101
|
type: z.ZodLiteral<ConsumableEvent.MISSED>;
|
|
60
102
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -108,26 +150,6 @@ export declare const ConsumableNotificationEventSchema: z.ZodObject<{
|
|
|
108
150
|
delivery_tag: number;
|
|
109
151
|
};
|
|
110
152
|
}>;
|
|
111
|
-
export declare const ConsumableNotificationMessageCountSchema: z.ZodObject<{
|
|
112
|
-
type: z.ZodLiteral<ConsumableEvent.MESSAGE_COUNT>;
|
|
113
|
-
data: z.ZodObject<{
|
|
114
|
-
count: z.ZodNumber;
|
|
115
|
-
}, "strip", z.ZodTypeAny, {
|
|
116
|
-
count: number;
|
|
117
|
-
}, {
|
|
118
|
-
count: number;
|
|
119
|
-
}>;
|
|
120
|
-
}, "strip", z.ZodTypeAny, {
|
|
121
|
-
type: ConsumableEvent.MESSAGE_COUNT;
|
|
122
|
-
data: {
|
|
123
|
-
count: number;
|
|
124
|
-
};
|
|
125
|
-
}, {
|
|
126
|
-
type: ConsumableEvent.MESSAGE_COUNT;
|
|
127
|
-
data: {
|
|
128
|
-
count: number;
|
|
129
|
-
};
|
|
130
|
-
}>;
|
|
131
153
|
export declare const ConsumableNotificationSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
132
154
|
type: z.ZodLiteral<ConsumableEvent.MISSED>;
|
|
133
155
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -180,23 +202,28 @@ export declare const ConsumableNotificationSchema: z.ZodDiscriminatedUnion<"type
|
|
|
180
202
|
delivery_tag: number;
|
|
181
203
|
};
|
|
182
204
|
}>, z.ZodObject<{
|
|
183
|
-
type: z.ZodLiteral<ConsumableEvent.
|
|
205
|
+
type: z.ZodLiteral<ConsumableEvent.SYNCHRONIZATION>;
|
|
184
206
|
data: z.ZodObject<{
|
|
185
|
-
|
|
207
|
+
delivery_tag: z.ZodNumber;
|
|
208
|
+
marker_id: z.ZodString;
|
|
186
209
|
}, "strip", z.ZodTypeAny, {
|
|
187
|
-
|
|
210
|
+
delivery_tag: number;
|
|
211
|
+
marker_id: string;
|
|
188
212
|
}, {
|
|
189
|
-
|
|
213
|
+
delivery_tag: number;
|
|
214
|
+
marker_id: string;
|
|
190
215
|
}>;
|
|
191
216
|
}, "strip", z.ZodTypeAny, {
|
|
192
|
-
type: ConsumableEvent.
|
|
217
|
+
type: ConsumableEvent.SYNCHRONIZATION;
|
|
193
218
|
data: {
|
|
194
|
-
|
|
219
|
+
delivery_tag: number;
|
|
220
|
+
marker_id: string;
|
|
195
221
|
};
|
|
196
222
|
}, {
|
|
197
|
-
type: ConsumableEvent.
|
|
223
|
+
type: ConsumableEvent.SYNCHRONIZATION;
|
|
198
224
|
data: {
|
|
199
|
-
|
|
225
|
+
delivery_tag: number;
|
|
226
|
+
marker_id: string;
|
|
200
227
|
};
|
|
201
228
|
}>]>;
|
|
202
229
|
//# sourceMappingURL=ConsumableNotification.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConsumableNotification.d.ts","sourceRoot":"","sources":["../../src/notification/ConsumableNotification.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,MAAM,yBAAyB;IAC/B,
|
|
1
|
+
{"version":3,"file":"ConsumableNotification.d.ts","sourceRoot":"","sources":["../../src/notification/ConsumableNotification.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC;;;GAGG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,MAAM,yBAAyB;IAC/B,eAAe,oBAAoB;CACpC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,qCAAqC;IACpD;;OAEG;IACH,IAAI,EAAE,eAAe,CAAC,eAAe,CAAC;IAEtC,IAAI,EAAE;QACJ;;;WAGG;QACH,YAAY,EAAE,MAAM,CAAC;QAErB;;;;WAIG;QACH,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC;CAC9B;AAED;;;;;GAKG;AACH,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,eAAe,CAAC,KAAK,CAAC;IAC5B,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE;YACL,EAAE,EAAE,MAAM,CAAC;YACX,OAAO,EAAE,YAAY,EAAE,CAAC;SACzB,CAAC;KACH,CAAC;CACH;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,sBAAsB,GAC9B,4BAA4B,GAC5B,2BAA2B,GAC3B,qCAAqC,CAAC;AAO1C,eAAO,MAAM,2CAA2C;;;;;;;;;;;;;;;;;;;;;;;;EAMtD,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;EAE7C,CAAC;AAEH,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM5C,CAAC;AAEH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,CAAC"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.ConsumableNotificationSchema = exports.
|
|
21
|
+
exports.ConsumableNotificationSchema = exports.ConsumableNotificationEventSchema = exports.ConsumableNotificationMissedSchema = exports.ConsumableNotificationSynchronizationSchema = exports.ConsumableEvent = void 0;
|
|
22
22
|
const zod_1 = require("zod");
|
|
23
23
|
/**
|
|
24
24
|
* Enum of all possible consumable notification types received via WebSocket.
|
|
@@ -28,11 +28,18 @@ var ConsumableEvent;
|
|
|
28
28
|
(function (ConsumableEvent) {
|
|
29
29
|
ConsumableEvent["EVENT"] = "event";
|
|
30
30
|
ConsumableEvent["MISSED"] = "notifications_missed";
|
|
31
|
-
ConsumableEvent["
|
|
31
|
+
ConsumableEvent["SYNCHRONIZATION"] = "synchronization";
|
|
32
32
|
})(ConsumableEvent || (exports.ConsumableEvent = ConsumableEvent = {}));
|
|
33
33
|
const BackendEventSchema = zod_1.z.object({
|
|
34
34
|
id: zod_1.z.string(),
|
|
35
|
-
payload: zod_1.z.array(zod_1.z.unknown()), // TODO
|
|
35
|
+
payload: zod_1.z.array(zod_1.z.unknown()), // @TODO Replace `z.unknown()` with BackendEvent schema when available
|
|
36
|
+
});
|
|
37
|
+
exports.ConsumableNotificationSynchronizationSchema = zod_1.z.object({
|
|
38
|
+
type: zod_1.z.literal(ConsumableEvent.SYNCHRONIZATION),
|
|
39
|
+
data: zod_1.z.object({
|
|
40
|
+
delivery_tag: zod_1.z.number(),
|
|
41
|
+
marker_id: zod_1.z.string(),
|
|
42
|
+
}),
|
|
36
43
|
});
|
|
37
44
|
exports.ConsumableNotificationMissedSchema = zod_1.z.object({
|
|
38
45
|
type: zod_1.z.literal(ConsumableEvent.MISSED),
|
|
@@ -44,14 +51,8 @@ exports.ConsumableNotificationEventSchema = zod_1.z.object({
|
|
|
44
51
|
event: BackendEventSchema,
|
|
45
52
|
}),
|
|
46
53
|
});
|
|
47
|
-
exports.ConsumableNotificationMessageCountSchema = zod_1.z.object({
|
|
48
|
-
type: zod_1.z.literal(ConsumableEvent.MESSAGE_COUNT),
|
|
49
|
-
data: zod_1.z.object({
|
|
50
|
-
count: zod_1.z.number(),
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
54
|
exports.ConsumableNotificationSchema = zod_1.z.discriminatedUnion('type', [
|
|
54
55
|
exports.ConsumableNotificationMissedSchema,
|
|
55
56
|
exports.ConsumableNotificationEventSchema,
|
|
56
|
-
exports.
|
|
57
|
+
exports.ConsumableNotificationSynchronizationSchema,
|
|
57
58
|
]);
|
|
@@ -24,7 +24,7 @@ const http_1 = require("../../http");
|
|
|
24
24
|
const domain = 'https://test.zinfra.io';
|
|
25
25
|
const testConfig = { urls: { rest: domain, ws: '', name: 'test' } };
|
|
26
26
|
const mockedAccessTokenStore = {
|
|
27
|
-
|
|
27
|
+
accessTokenData: {
|
|
28
28
|
access_token: 'iJCRCjc8oROO-dkrkqCXOade997oa8Jhbz6awMUQPBQo80VenWqp_oNvfY6AnU5BxEsd' +
|
|
29
29
|
'DPOBfBP-uz_b0gAKBQ==.v=1.k=1.d=1498600993.t=a.l=.u=aaf9a833-ef30-4c2' +
|
|
30
30
|
'2-86a0-9adc8a15b3b4.c=15037015562284012115',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcknowledgeEvent.types.d.ts","sourceRoot":"","sources":["../../src/tcp/AcknowledgeEvent.types.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,oBAAY,eAAe;IACzB,GAAG,QAAQ;IACX,
|
|
1
|
+
{"version":3,"file":"AcknowledgeEvent.types.d.ts","sourceRoot":"","sources":["../../src/tcp/AcknowledgeEvent.types.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,oBAAY,eAAe;IACzB,GAAG,QAAQ;IACX,aAAa,kBAAkB;CAChC"}
|
|
@@ -22,6 +22,5 @@ exports.AcknowledgeType = void 0;
|
|
|
22
22
|
var AcknowledgeType;
|
|
23
23
|
(function (AcknowledgeType) {
|
|
24
24
|
AcknowledgeType["ACK"] = "ack";
|
|
25
|
-
AcknowledgeType["ACK_MESSAGE_COUNT"] = "ack_message_count";
|
|
26
25
|
AcknowledgeType["ACK_FULL_SYNC"] = "ack_full_sync";
|
|
27
26
|
})(AcknowledgeType || (exports.AcknowledgeType = AcknowledgeType = {}));
|
|
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
import { WEBSOCKET_STATE } from './ReconnectingWebsocket';
|
|
4
4
|
import { InvalidTokenError, MissingCookieError } from '../auth/';
|
|
5
5
|
import { HttpClient } from '../http/';
|
|
6
|
-
import { ConsumableNotification, ConsumableNotificationEvent } from '../notification/ConsumableNotification';
|
|
6
|
+
import { ConsumableNotification, ConsumableNotificationEvent, ConsumableNotificationSynchronization } from '../notification/ConsumableNotification';
|
|
7
7
|
declare enum TOPIC {
|
|
8
8
|
ON_ERROR = "WebSocketClient.TOPIC.ON_ERROR",
|
|
9
9
|
ON_INVALID_TOKEN = "WebSocketClient.TOPIC.ON_INVALID_TOKEN",
|
|
@@ -67,9 +67,9 @@ export declare class WebSocketClient extends EventEmitter {
|
|
|
67
67
|
*/
|
|
68
68
|
readonly lock: () => void;
|
|
69
69
|
isLocked(): boolean;
|
|
70
|
-
|
|
70
|
+
buildWebSocketUrl(): string;
|
|
71
71
|
acknowledgeMissedNotification(): void;
|
|
72
|
-
|
|
72
|
+
acknowledgeConsumableNotificationSynchronization(notification: ConsumableNotificationSynchronization): void;
|
|
73
73
|
acknowledgeNotification(notification: ConsumableNotificationEvent): void;
|
|
74
74
|
}
|
|
75
75
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../../src/tcp/WebSocketClient.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AAKpC,OAAO,EAAwB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAE/E,OAAO,EAAC,iBAAiB,EAA8B,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAE3F,OAAO,EAAC,UAAU,EAAe,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,sBAAsB,EACtB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"WebSocketClient.d.ts","sourceRoot":"","sources":["../../src/tcp/WebSocketClient.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AAKpC,OAAO,EAAwB,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAE/E,OAAO,EAAC,iBAAiB,EAA8B,kBAAkB,EAAC,MAAM,UAAU,CAAC;AAE3F,OAAO,EAAC,UAAU,EAAe,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAE3B,qCAAqC,EACtC,MAAM,wCAAwC,CAAC;AAEhD,aAAK,KAAK;IACR,QAAQ,mCAAmC;IAC3C,gBAAgB,2CAA2C;IAC3D,UAAU,qCAAqC;I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,aAAa;IAOrB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAOxB;IAEF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAItB;IAEF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAM1B;IAEF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;IAEF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAItB;IAEF;;;;;;;;;;;OAWG;IACI,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS,GAAG,eAAe;YAmB3D,kBAAkB;IA8BzB,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAMxC;;;;OAIG;IACH,SAAgB,MAAM,aAOpB;IAEF;;;;;OAKG;IACH,SAAgB,IAAI,aAGlB;IAEK,QAAQ,IAAI,OAAO;IAInB,iBAAiB,IAAI,MAAM;IAsC3B,6BAA6B;IAQ7B,gDAAgD,CAAC,YAAY,EAAE,qCAAqC;IAYpG,uBAAuB,CAAC,YAAY,EAAE,2BAA2B;CAgBzE"}
|
|
@@ -186,21 +186,31 @@ class WebSocketClient extends events_1.EventEmitter {
|
|
|
186
186
|
return this.isSocketLocked;
|
|
187
187
|
}
|
|
188
188
|
buildWebSocketUrl() {
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
|
|
189
|
+
const { accessTokenStore: { getAccessToken, getNextMarkerToken }, } = this.client;
|
|
190
|
+
const accessToken = getAccessToken?.() ?? '';
|
|
191
|
+
const markerToken = getNextMarkerToken?.();
|
|
192
|
+
if (!accessToken) {
|
|
192
193
|
this.logger.warn('Reconnecting WebSocket with unset token');
|
|
193
194
|
}
|
|
194
195
|
if (!this.versionPrefix) {
|
|
195
|
-
throw new Error('
|
|
196
|
+
throw new Error('Missing backend API version: cannot establish WebSocket connection');
|
|
196
197
|
}
|
|
197
|
-
|
|
198
|
+
const queryParams = new URLSearchParams({
|
|
199
|
+
access_token: accessToken,
|
|
200
|
+
});
|
|
201
|
+
if (markerToken) {
|
|
202
|
+
queryParams.append('sync_marker', markerToken);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @note If no client ID is given, then the WebSocket connection
|
|
206
|
+
* will receive all notifications for all clients of the connected user
|
|
207
|
+
*/
|
|
198
208
|
if (this.clientId) {
|
|
199
|
-
|
|
200
|
-
// of the connected user
|
|
201
|
-
url += `&client=${this.clientId}`;
|
|
209
|
+
queryParams.append('client', this.clientId);
|
|
202
210
|
}
|
|
203
|
-
|
|
211
|
+
const queryString = queryParams.toString();
|
|
212
|
+
this.logger.info(`WebSocket URL: ${this.baseUrl}${this.versionPrefix}/events?${queryString}`);
|
|
213
|
+
return `${this.baseUrl}${this.versionPrefix}/events?${queryString}`;
|
|
204
214
|
}
|
|
205
215
|
acknowledgeMissedNotification() {
|
|
206
216
|
const jsonEvent = JSON.stringify({
|
|
@@ -208,9 +218,13 @@ class WebSocketClient extends events_1.EventEmitter {
|
|
|
208
218
|
});
|
|
209
219
|
this.socket.send(jsonEvent);
|
|
210
220
|
}
|
|
211
|
-
|
|
221
|
+
acknowledgeConsumableNotificationSynchronization(notification) {
|
|
212
222
|
const jsonEvent = JSON.stringify({
|
|
213
|
-
type: AcknowledgeEvent_types_1.AcknowledgeType.
|
|
223
|
+
type: AcknowledgeEvent_types_1.AcknowledgeType.ACK,
|
|
224
|
+
data: {
|
|
225
|
+
multiple: false,
|
|
226
|
+
delivery_tag: notification.data.delivery_tag,
|
|
227
|
+
},
|
|
214
228
|
});
|
|
215
229
|
this.socket.send(jsonEvent);
|
|
216
230
|
}
|
package/package.json
CHANGED