@rocket.chat/ddp-client 0.0.2-rc.0 → 0.0.2-rc.2
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/CHANGELOG.md +15 -0
- package/dist/ClientStream.d.ts +27 -0
- package/dist/ClientStream.d.ts.map +1 -0
- package/dist/ClientStream.js +154 -0
- package/dist/ClientStream.js.map +1 -0
- package/dist/Connection.d.ts +55 -0
- package/dist/Connection.d.ts.map +1 -0
- package/dist/Connection.js +124 -0
- package/dist/Connection.js.map +1 -0
- package/dist/DDPDispatcher.d.ts +23 -0
- package/dist/DDPDispatcher.d.ts.map +1 -0
- package/dist/DDPDispatcher.js +82 -0
- package/dist/DDPDispatcher.js.map +1 -0
- package/dist/DDPSDK.d.ts +54 -0
- package/dist/DDPSDK.d.ts.map +1 -0
- package/dist/DDPSDK.js +126 -0
- package/dist/DDPSDK.js.map +1 -0
- package/dist/MinimalDDPClient.d.ts +80 -0
- package/dist/MinimalDDPClient.d.ts.map +1 -0
- package/dist/MinimalDDPClient.js +170 -0
- package/dist/MinimalDDPClient.js.map +1 -0
- package/dist/TimeoutControl.d.ts +26 -0
- package/dist/TimeoutControl.d.ts.map +1 -0
- package/dist/TimeoutControl.js +55 -0
- package/dist/TimeoutControl.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy/RocketchatSDKLegacy.d.ts +107 -0
- package/dist/legacy/RocketchatSDKLegacy.d.ts.map +1 -0
- package/dist/legacy/RocketchatSDKLegacy.js +219 -0
- package/dist/legacy/RocketchatSDKLegacy.js.map +1 -0
- package/dist/legacy/types/SDKLegacy.d.ts +105 -0
- package/dist/legacy/types/SDKLegacy.d.ts.map +1 -0
- package/dist/legacy/types/SDKLegacy.js +3 -0
- package/dist/legacy/types/SDKLegacy.js.map +1 -0
- package/dist/livechat/LivechatClientImpl.d.ts +117 -0
- package/dist/livechat/LivechatClientImpl.d.ts.map +1 -0
- package/dist/livechat/LivechatClientImpl.js +275 -0
- package/dist/livechat/LivechatClientImpl.js.map +1 -0
- package/dist/livechat/types/LivechatSDK.d.ts +61 -0
- package/dist/livechat/types/LivechatSDK.d.ts.map +1 -0
- package/dist/livechat/types/LivechatSDK.js +3 -0
- package/dist/livechat/types/LivechatSDK.js.map +1 -0
- package/dist/types/Account.d.ts +39 -0
- package/dist/types/Account.d.ts.map +1 -0
- package/dist/types/Account.js +70 -0
- package/dist/types/Account.js.map +1 -0
- package/dist/types/ClientStream.d.ts +113 -0
- package/dist/types/ClientStream.d.ts.map +1 -0
- package/dist/types/ClientStream.js +3 -0
- package/dist/types/ClientStream.js.map +1 -0
- package/dist/types/DDPClient.d.ts +112 -0
- package/dist/types/DDPClient.d.ts.map +1 -0
- package/dist/types/DDPClient.js +3 -0
- package/dist/types/DDPClient.js.map +1 -0
- package/dist/types/IncomingPayload.d.ts +9 -0
- package/dist/types/IncomingPayload.d.ts.map +1 -0
- package/dist/types/IncomingPayload.js +3 -0
- package/dist/types/IncomingPayload.js.map +1 -0
- package/dist/types/OutgoingPayload.d.ts +9 -0
- package/dist/types/OutgoingPayload.d.ts.map +1 -0
- package/dist/types/OutgoingPayload.js +3 -0
- package/dist/types/OutgoingPayload.js.map +1 -0
- package/dist/types/RemoveListener.d.ts +2 -0
- package/dist/types/RemoveListener.d.ts.map +1 -0
- package/dist/types/RemoveListener.js +3 -0
- package/dist/types/RemoveListener.js.map +1 -0
- package/dist/types/SDK.d.ts +14 -0
- package/dist/types/SDK.d.ts.map +1 -0
- package/dist/types/SDK.js +3 -0
- package/dist/types/SDK.js.map +1 -0
- package/dist/types/Subscription.d.ts +12 -0
- package/dist/types/Subscription.d.ts.map +1 -0
- package/dist/types/Subscription.js +3 -0
- package/dist/types/Subscription.js.map +1 -0
- package/dist/types/connectionPayloads.d.ts +29 -0
- package/dist/types/connectionPayloads.d.ts.map +1 -0
- package/dist/types/connectionPayloads.js +3 -0
- package/dist/types/connectionPayloads.js.map +1 -0
- package/dist/types/heartbeatsPayloads.d.ts +23 -0
- package/dist/types/heartbeatsPayloads.d.ts.map +1 -0
- package/dist/types/heartbeatsPayloads.js +3 -0
- package/dist/types/heartbeatsPayloads.js.map +1 -0
- package/dist/types/methods.d.ts +13 -0
- package/dist/types/methods.d.ts.map +1 -0
- package/dist/types/methods.js +3 -0
- package/dist/types/methods.js.map +1 -0
- package/dist/types/methodsPayloads.d.ts +43 -0
- package/dist/types/methodsPayloads.d.ts.map +1 -0
- package/dist/types/methodsPayloads.js +3 -0
- package/dist/types/methodsPayloads.js.map +1 -0
- package/dist/types/publicationPayloads.d.ts +110 -0
- package/dist/types/publicationPayloads.d.ts.map +1 -0
- package/dist/types/publicationPayloads.js +3 -0
- package/dist/types/publicationPayloads.js.map +1 -0
- package/dist/types/streams.d.ts +571 -0
- package/dist/types/streams.d.ts.map +1 -0
- package/dist/types/streams.js +3 -0
- package/dist/types/streams.js.map +1 -0
- package/dist/wrapOnceEventIntoPromise.d.ts +13 -0
- package/dist/wrapOnceEventIntoPromise.d.ts.map +1 -0
- package/dist/wrapOnceEventIntoPromise.js +27 -0
- package/dist/wrapOnceEventIntoPromise.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LivechatClientImpl = void 0;
|
|
13
|
+
const emitter_1 = require("@rocket.chat/emitter");
|
|
14
|
+
const api_client_1 = require("@rocket.chat/api-client");
|
|
15
|
+
const DDPSDK_1 = require("../DDPSDK");
|
|
16
|
+
const DDPDispatcher_1 = require("../DDPDispatcher");
|
|
17
|
+
const ClientStream_1 = require("../ClientStream");
|
|
18
|
+
const Connection_1 = require("../Connection");
|
|
19
|
+
const Account_1 = require("../types/Account");
|
|
20
|
+
const TimeoutControl_1 = require("../TimeoutControl");
|
|
21
|
+
class LivechatClientImpl extends DDPSDK_1.DDPSDK {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.credentials = { token: this.token };
|
|
25
|
+
this.ev = new emitter_1.Emitter();
|
|
26
|
+
}
|
|
27
|
+
subscribeRoom(rid) {
|
|
28
|
+
return Promise.all([
|
|
29
|
+
this.onRoomMessage(rid, (...args) => this.ev.emit('message', args)),
|
|
30
|
+
this.onRoomTyping(rid, (...args) => this.ev.emit('typing', args)),
|
|
31
|
+
this.onRoomDeleteMessage(rid, (...args) => this.ev.emit('delete', args)),
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
onMessage(cb) {
|
|
35
|
+
return this.ev.on('message', (args) => cb(...args));
|
|
36
|
+
}
|
|
37
|
+
onTyping(cb) {
|
|
38
|
+
return this.ev.on('typing', (args) => args[1] && cb(args[0], args[1]));
|
|
39
|
+
}
|
|
40
|
+
onRoomMessage(rid, cb) {
|
|
41
|
+
return this.stream('room-messages', [rid, { token: this.token, visitorToken: this.token }], cb).stop;
|
|
42
|
+
}
|
|
43
|
+
onRoomTyping(rid, cb) {
|
|
44
|
+
return this.stream('notify-room', [`${rid}/typing`, { token: this.token, visitorToken: this.token }], cb).stop;
|
|
45
|
+
}
|
|
46
|
+
onRoomDeleteMessage(rid, cb) {
|
|
47
|
+
return this.stream('notify-room', [`${rid}/deleteMessage`, { token: this.token, visitorToken: this.token }], cb).stop;
|
|
48
|
+
}
|
|
49
|
+
onAgentChange(rid, cb) {
|
|
50
|
+
return this.stream('livechat-room', [rid, { token: this.token, visitorToken: this.token }], (data) => {
|
|
51
|
+
if (data.type === 'agentData') {
|
|
52
|
+
cb(data.data);
|
|
53
|
+
}
|
|
54
|
+
}).stop;
|
|
55
|
+
}
|
|
56
|
+
onAgentStatusChange(rid, cb) {
|
|
57
|
+
return this.stream('livechat-room', [rid, { token: this.token, visitorToken: this.token }], (data) => {
|
|
58
|
+
if (data.type === 'agentStatus') {
|
|
59
|
+
cb(data.status);
|
|
60
|
+
}
|
|
61
|
+
}).stop;
|
|
62
|
+
}
|
|
63
|
+
onQueuePositionChange(rid, cb) {
|
|
64
|
+
return this.stream('livechat-room', rid, (data) => {
|
|
65
|
+
if (data.type === 'queueData') {
|
|
66
|
+
cb(data.data);
|
|
67
|
+
}
|
|
68
|
+
}).stop;
|
|
69
|
+
}
|
|
70
|
+
onVisitorChange(rid, cb) {
|
|
71
|
+
return this.stream('livechat-room', [rid, { token: this.token, visitorToken: this.token }], (data) => {
|
|
72
|
+
if (data.type === 'visitorData') {
|
|
73
|
+
cb(data.visitor);
|
|
74
|
+
}
|
|
75
|
+
}).stop;
|
|
76
|
+
}
|
|
77
|
+
notifyVisitorTyping(rid, username, typing) {
|
|
78
|
+
return this.client.callAsync('stream-notify-room', `${rid}/typing`, username, typing);
|
|
79
|
+
}
|
|
80
|
+
notifyCallDeclined(rid) {
|
|
81
|
+
return this.client.callAsync('stream-notify-room', `${rid}/call`, 'decline');
|
|
82
|
+
}
|
|
83
|
+
// API GETTERS
|
|
84
|
+
config(params) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const { config } = yield this.rest.get('/v1/livechat/config', params);
|
|
87
|
+
return config;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
room(params) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
if (!this.token) {
|
|
93
|
+
throw new Error('Invalid token');
|
|
94
|
+
}
|
|
95
|
+
const result = yield this.rest.get('/v1/livechat/room', Object.assign(Object.assign({}, params), { token: this.token }));
|
|
96
|
+
// TODO: On major version bump, normalize the return of /v1/livechat/room
|
|
97
|
+
function isRoomObject(room) {
|
|
98
|
+
return room.room !== undefined;
|
|
99
|
+
}
|
|
100
|
+
if (isRoomObject(result)) {
|
|
101
|
+
return result.room;
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
visitor(params) {
|
|
107
|
+
if (!this.token) {
|
|
108
|
+
throw new Error('Invalid token');
|
|
109
|
+
}
|
|
110
|
+
const endpoint = `/v1/livechat/visitor/${this.token}`;
|
|
111
|
+
return this.rest.get(endpoint, params);
|
|
112
|
+
}
|
|
113
|
+
nextAgent(params) {
|
|
114
|
+
if (!this.token) {
|
|
115
|
+
throw new Error('Invalid token');
|
|
116
|
+
}
|
|
117
|
+
return this.rest.get(`/v1/livechat/agent.next/${this.token}`, params);
|
|
118
|
+
}
|
|
119
|
+
agent(rid) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
if (!this.token) {
|
|
122
|
+
throw new Error('Invalid token');
|
|
123
|
+
}
|
|
124
|
+
const { agent } = yield this.rest.get(`/v1/livechat/agent.info/${rid}/${this.token}`);
|
|
125
|
+
return agent;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
message(id, params) {
|
|
129
|
+
if (!this.token) {
|
|
130
|
+
throw new Error('Invalid token');
|
|
131
|
+
}
|
|
132
|
+
return this.rest.get(`/v1/livechat/message/${id}`, Object.assign(Object.assign({}, params), { token: this.token }));
|
|
133
|
+
}
|
|
134
|
+
loadMessages(rid, params) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
if (!this.token) {
|
|
137
|
+
throw new Error('Invalid token');
|
|
138
|
+
}
|
|
139
|
+
const { messages } = yield this.rest.get(`/v1/livechat/messages.history/${rid}`, Object.assign(Object.assign({}, params), { token: this.token }));
|
|
140
|
+
return messages;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
// API POST
|
|
144
|
+
transferChat({ rid, department, }) {
|
|
145
|
+
if (!this.token) {
|
|
146
|
+
throw new Error('Invalid token');
|
|
147
|
+
}
|
|
148
|
+
return this.rest.post('/v1/livechat/room.transfer', { rid, token: this.token, department });
|
|
149
|
+
}
|
|
150
|
+
grantVisitor(guest) {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const result = yield this.rest.post('/v1/livechat/visitor', guest);
|
|
153
|
+
this.token = result === null || result === void 0 ? void 0 : result.visitor.token;
|
|
154
|
+
return result;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
login(guest) {
|
|
158
|
+
return this.grantVisitor(guest);
|
|
159
|
+
}
|
|
160
|
+
closeChat({ rid }) {
|
|
161
|
+
if (!this.token) {
|
|
162
|
+
throw new Error('Invalid token');
|
|
163
|
+
}
|
|
164
|
+
return this.rest.post('/v1/livechat/room.close', { rid, token: this.token });
|
|
165
|
+
}
|
|
166
|
+
chatSurvey(params) {
|
|
167
|
+
if (!this.token) {
|
|
168
|
+
throw new Error('Invalid token');
|
|
169
|
+
}
|
|
170
|
+
return this.rest.post('/v1/livechat/room.survey', { rid: params.rid, token: this.token, data: params.data });
|
|
171
|
+
}
|
|
172
|
+
updateCallStatus(callStatus, rid, callId) {
|
|
173
|
+
if (!this.token) {
|
|
174
|
+
throw new Error('Invalid token');
|
|
175
|
+
}
|
|
176
|
+
return this.rest.post('/v1/livechat/visitor.callStatus', { token: this.token, callStatus, rid, callId });
|
|
177
|
+
}
|
|
178
|
+
sendMessage(params) {
|
|
179
|
+
if (!this.token) {
|
|
180
|
+
throw new Error('Invalid token');
|
|
181
|
+
}
|
|
182
|
+
return this.rest.post('/v1/livechat/message', Object.assign(Object.assign({}, params), { token: this.token }));
|
|
183
|
+
}
|
|
184
|
+
sendOfflineMessage(params) {
|
|
185
|
+
return this.rest.post('/v1/livechat/offline.message', params);
|
|
186
|
+
}
|
|
187
|
+
sendVisitorNavigation(params) {
|
|
188
|
+
return this.rest.post('/v1/livechat/page.visited', params);
|
|
189
|
+
}
|
|
190
|
+
requestTranscript(email, { rid }) {
|
|
191
|
+
if (!this.token) {
|
|
192
|
+
throw new Error('Invalid token');
|
|
193
|
+
}
|
|
194
|
+
return this.rest.post('/v1/livechat/transcript', { token: this.token, rid, email });
|
|
195
|
+
}
|
|
196
|
+
sendCustomField(params) {
|
|
197
|
+
return this.rest.post('/v1/livechat/custom.field', params);
|
|
198
|
+
}
|
|
199
|
+
sendCustomFields(params) {
|
|
200
|
+
return this.rest.post('/v1/livechat/custom.fields', params);
|
|
201
|
+
}
|
|
202
|
+
updateVisitorStatus(newStatus) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
if (!this.token) {
|
|
205
|
+
throw new Error('Invalid token');
|
|
206
|
+
}
|
|
207
|
+
const { status } = yield this.rest.post('/v1/livechat/visitor.status', { token: this.token, status: newStatus });
|
|
208
|
+
return status;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
uploadFile(rid, file) {
|
|
212
|
+
if (!this.token) {
|
|
213
|
+
throw new Error('Invalid token');
|
|
214
|
+
}
|
|
215
|
+
if (!file) {
|
|
216
|
+
throw new Error('Invalid file');
|
|
217
|
+
}
|
|
218
|
+
return new Promise((resolve, reject) => {
|
|
219
|
+
if (!this.token) {
|
|
220
|
+
return reject(new Error('Invalid token'));
|
|
221
|
+
}
|
|
222
|
+
return this.rest.upload(`/v1/livechat/upload/${rid}`, { file }, {
|
|
223
|
+
load: resolve,
|
|
224
|
+
error: reject,
|
|
225
|
+
}, { headers: { 'x-visitor-token': this.token } });
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
sendUiInteraction(payload, appId) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
if (!this.token) {
|
|
231
|
+
throw new Error('Invalid token');
|
|
232
|
+
}
|
|
233
|
+
return this.rest.post(`/apps/ui.interaction/${appId}`, payload, { headers: { 'x-visitor-token': this.token } });
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
// API DELETE
|
|
237
|
+
deleteMessage(id, { rid }) {
|
|
238
|
+
if (!this.token) {
|
|
239
|
+
throw new Error('Invalid token');
|
|
240
|
+
}
|
|
241
|
+
return this.rest.delete(`/v1/livechat/message/${id}`, { rid, token: this.token });
|
|
242
|
+
}
|
|
243
|
+
deleteVisitor() {
|
|
244
|
+
if (!this.token) {
|
|
245
|
+
throw new Error('Invalid token');
|
|
246
|
+
}
|
|
247
|
+
return this.rest.delete(`/v1/livechat/visitor/${this.token}`);
|
|
248
|
+
}
|
|
249
|
+
// API PUT
|
|
250
|
+
editMessage(id, params) {
|
|
251
|
+
return this.rest.put(`/v1/livechat/message/${id}`, params);
|
|
252
|
+
}
|
|
253
|
+
unsubscribeAll() {
|
|
254
|
+
const subscriptions = Array.from(this.client.subscriptions.keys());
|
|
255
|
+
return Promise.all(subscriptions.map((subscription) => this.client.unsubscribe(subscription)));
|
|
256
|
+
}
|
|
257
|
+
static create(url, retryOptions = { retryCount: 3, retryTime: 10000 }) {
|
|
258
|
+
// TODO: Decide what to do with the EJSON objects
|
|
259
|
+
const ddp = new DDPDispatcher_1.DDPDispatcher();
|
|
260
|
+
const connection = Connection_1.ConnectionImpl.create(url, WebSocket, ddp, retryOptions);
|
|
261
|
+
const stream = new ClientStream_1.ClientStreamImpl(ddp, ddp);
|
|
262
|
+
const account = new Account_1.AccountImpl(stream);
|
|
263
|
+
const timeoutControl = TimeoutControl_1.TimeoutControl.create(ddp, connection);
|
|
264
|
+
const rest = new api_client_1.RestClient({ baseUrl: url.replace(/^ws/, 'http') });
|
|
265
|
+
const sdk = new LivechatClientImpl(connection, stream, account, timeoutControl, rest);
|
|
266
|
+
connection.on('connected', () => {
|
|
267
|
+
Object.entries(stream.subscriptions).forEach(([, sub]) => {
|
|
268
|
+
ddp.subscribeWithId(sub.id, sub.name, sub.params);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
return sdk;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
exports.LivechatClientImpl = LivechatClientImpl;
|
|
275
|
+
//# sourceMappingURL=LivechatClientImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivechatClientImpl.js","sourceRoot":"","sources":["../../src/livechat/LivechatClientImpl.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA+C;AAC/C,wDAAqD;AAKrD,sCAAmC;AAEnC,oDAAiD;AACjD,kDAAmD;AACnD,8CAA+C;AAC/C,8CAA+C;AAC/C,sDAAmD;AA6BnD,MAAa,kBAAmB,SAAQ,eAAM;IAA9C;;QAGiB,gBAAW,GAAuB,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAEhE,OAAE,GAAG,IAAI,iBAAO,EAIpB,CAAC;IAoVN,CAAC;IAlVA,aAAa,CAAC,GAAW;QACxB,OAAO,OAAO,CAAC,GAAG,CAAC;YAClB,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACnE,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACjE,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;SACxE,CAAC,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,EAAoE;QAC7E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AAE,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE;QAC5E,iDAAiD;QACjD,MAAM,GAAG,GAAG,IAAI,6BAAa,EAAE,CAAC;QAEhC,MAAM,UAAU,GAAG,2BAAc,CAAC,MAAM,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;QAE5E,MAAM,MAAM,GAAG,IAAI,+BAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAE9C,MAAM,OAAO,GAAG,IAAI,qBAAW,CAAC,MAAM,CAAC,CAAC;QAExC,MAAM,cAAc,GAAG,+BAAc,CAAC,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAE9D,MAAM,IAAI,GAAG,IAAI,uBAAU,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAErE,MAAM,GAAG,GAAG,IAAI,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;QAEtF,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YAC/B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE;gBACxD,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,CAAC;IACZ,CAAC;CACD;AA7VD,gDA6VC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Serialized } from '@rocket.chat/core-typings';
|
|
2
|
+
import type { OperationParams, OperationResult } from '@rocket.chat/rest-typings';
|
|
3
|
+
import type { StreamerCallbackArgs } from '../../types/streams';
|
|
4
|
+
export type LivechatRoomEvents<T> = StreamerCallbackArgs<'livechat-room', `${string}`> extends [infer A] ? A extends {
|
|
5
|
+
type: T;
|
|
6
|
+
data: unknown;
|
|
7
|
+
} ? A['data'] : A extends {
|
|
8
|
+
type: T;
|
|
9
|
+
status: unknown;
|
|
10
|
+
} ? A['status'] : A extends {
|
|
11
|
+
type: T;
|
|
12
|
+
visitor: unknown;
|
|
13
|
+
} ? A['visitor'] : never : never;
|
|
14
|
+
export interface LivechatStream {
|
|
15
|
+
notifyVisitorTyping(rid: string, username: string, typing: boolean): Promise<unknown>;
|
|
16
|
+
notifyCallDeclined(rid: string): Promise<unknown>;
|
|
17
|
+
subscribeRoom(rid: string): Promise<any>;
|
|
18
|
+
onMessage(cb: (...args: StreamerCallbackArgs<'room-messages', string>) => void): () => void;
|
|
19
|
+
onTyping(cb: (...args: StreamerCallbackArgs<'notify-room', `${string}/typing`>) => void): () => void;
|
|
20
|
+
onRoomMessage(rid: string, cb: (...args: StreamerCallbackArgs<'room-messages', string>) => void): () => void;
|
|
21
|
+
onRoomTyping(rid: string, cb: (...args: StreamerCallbackArgs<'notify-room', `${string}/typing`>) => void): () => void;
|
|
22
|
+
onRoomDeleteMessage(rid: string, cb: (...args: StreamerCallbackArgs<'notify-room', `${string}/deleteMessage`>) => void): () => void;
|
|
23
|
+
onAgentChange(rid: string, cb: (args: LivechatRoomEvents<'agentData'>) => void): () => void;
|
|
24
|
+
onAgentStatusChange(rid: string, cb: (args: LivechatRoomEvents<'agentStatus'>) => void): () => void;
|
|
25
|
+
onQueuePositionChange(rid: string, cb: (args: LivechatRoomEvents<'queueData' | 'agentData'>) => void): () => void;
|
|
26
|
+
onVisitorChange(rid: string, cb: (data: LivechatRoomEvents<'visitorData'>) => void): () => void;
|
|
27
|
+
}
|
|
28
|
+
export interface LivechatEndpoints {
|
|
29
|
+
config(args: OperationParams<'GET', '/v1/livechat/config'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/config'>['config']>>;
|
|
30
|
+
room(args: OperationParams<'GET', '/v1/livechat/room'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/room'>>>;
|
|
31
|
+
visitor(args: OperationParams<'GET', '/v1/livechat/visitor/:token'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/visitor/:token'>>>;
|
|
32
|
+
nextAgent(args: OperationParams<'GET', '/v1/livechat/agent.next/:token'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/agent.next/:token'>>>;
|
|
33
|
+
agent(rid: string): Promise<Serialized<OperationResult<'GET', '/v1/livechat/agent.info/:rid/:token'>['agent']>>;
|
|
34
|
+
message(id: string, args: OperationParams<'GET', '/v1/livechat/message/:_id'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/message/:_id'>>>;
|
|
35
|
+
loadMessages(rid: string, args: OperationParams<'GET', '/v1/livechat/messages.history/:rid'>): Promise<Serialized<OperationResult<'GET', '/v1/livechat/messages.history/:rid'>['messages']>>;
|
|
36
|
+
transferChat(args: OperationParams<'POST', '/v1/livechat/room.transfer'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/room.transfer'>>>;
|
|
37
|
+
grantVisitor(guest: OperationParams<'POST', '/v1/livechat/visitor'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/visitor'>>>;
|
|
38
|
+
login(guest: OperationParams<'POST', '/v1/livechat/visitor'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/visitor'>>>;
|
|
39
|
+
closeChat(args: {
|
|
40
|
+
rid: string;
|
|
41
|
+
}): Promise<Serialized<OperationResult<'POST', '/v1/livechat/room.close'>>>;
|
|
42
|
+
chatSurvey(args: OperationParams<'POST', '/v1/livechat/room.survey'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/room.survey'>>>;
|
|
43
|
+
updateVisitorStatus(status: string): Promise<Serialized<OperationResult<'POST', '/v1/livechat/visitor.status'>['status']>>;
|
|
44
|
+
updateCallStatus(callStatus: string, rid: string, callId: string): Promise<Serialized<OperationResult<'POST', '/v1/livechat/visitor.callStatus'>>>;
|
|
45
|
+
sendMessage(args: OperationParams<'POST', '/v1/livechat/message'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/message'>>>;
|
|
46
|
+
sendOfflineMessage(args: OperationParams<'POST', '/v1/livechat/offline.message'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/offline.message'>>>;
|
|
47
|
+
sendVisitorNavigation(args: OperationParams<'POST', '/v1/livechat/page.visited'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/page.visited'>>>;
|
|
48
|
+
requestTranscript(email: string, { rid }: {
|
|
49
|
+
rid: string;
|
|
50
|
+
}): Promise<Serialized<OperationResult<'POST', '/v1/livechat/transcript'>>>;
|
|
51
|
+
sendCustomField(params: OperationParams<'POST', '/v1/livechat/custom.field'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/custom.field'>>>;
|
|
52
|
+
sendCustomFields(params: OperationParams<'POST', '/v1/livechat/custom.fields'>): Promise<Serialized<OperationResult<'POST', '/v1/livechat/custom.fields'>>>;
|
|
53
|
+
uploadFile(rid: string, file: File): Promise<ProgressEvent<EventTarget>>;
|
|
54
|
+
deleteMessage(id: string, { rid }: {
|
|
55
|
+
rid: string;
|
|
56
|
+
}): Promise<Serialized<OperationResult<'DELETE', '/v1/livechat/message/:_id'>>>;
|
|
57
|
+
deleteVisitor(args: OperationParams<'DELETE', '/v1/livechat/visitor/:token'>): Promise<void>;
|
|
58
|
+
editMessage(id: string, args: OperationParams<'PUT', '/v1/livechat/message/:_id'>): Promise<Serialized<OperationResult<'PUT', '/v1/livechat/message/:_id'>>>;
|
|
59
|
+
sendUiInteraction(payload: OperationParams<'POST', '/apps/ui.interaction/:id'>, appId: string): Promise<Serialized<OperationResult<'POST', '/apps/ui.interaction/:id'>>>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=LivechatSDK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivechatSDK.d.ts","sourceRoot":"","sources":["../../../src/livechat/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C,CAAC,CAAC;IAE5E,iBAAiB,CAChB,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,0BAA0B,CAAC,EAC5D,KAAK,EAAE,MAAM,GACX,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;CAC5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LivechatSDK.js","sourceRoot":"","sources":["../../../src/livechat/types/LivechatSDK.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Emitter } from '@rocket.chat/emitter';
|
|
2
|
+
import type { ClientStream } from './ClientStream';
|
|
3
|
+
export interface Account extends Emitter<{
|
|
4
|
+
uid: string | undefined;
|
|
5
|
+
user: Record<string, unknown> | undefined;
|
|
6
|
+
}> {
|
|
7
|
+
uid?: string;
|
|
8
|
+
user?: Record<string, unknown>;
|
|
9
|
+
loginWithPassword(username: string, password: string): Promise<void>;
|
|
10
|
+
loginWithToken(token: string): Promise<{
|
|
11
|
+
id: string;
|
|
12
|
+
token: string;
|
|
13
|
+
tokenExpires: Date;
|
|
14
|
+
}>;
|
|
15
|
+
logout(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class AccountImpl extends Emitter<{
|
|
18
|
+
uid: string | undefined;
|
|
19
|
+
user: {
|
|
20
|
+
id: string;
|
|
21
|
+
username: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
tokenExpires?: Date;
|
|
24
|
+
};
|
|
25
|
+
}> implements Account {
|
|
26
|
+
private readonly client;
|
|
27
|
+
uid?: string;
|
|
28
|
+
user?: {
|
|
29
|
+
id: string;
|
|
30
|
+
username: string;
|
|
31
|
+
token?: string;
|
|
32
|
+
tokenExpires?: Date;
|
|
33
|
+
};
|
|
34
|
+
constructor(client: ClientStream);
|
|
35
|
+
loginWithPassword(username: string, password: string): Promise<void>;
|
|
36
|
+
loginWithToken(token: string): Promise<any>;
|
|
37
|
+
logout(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=Account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../../src/types/Account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,OAChB,SAAQ,OAAO,CAAC;IACf,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;CAC1C,CAAC;IACF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QACtC,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,IAAI,CAAC;KACnB,CAAC,CAAC;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,qBAAa,WACZ,SAAQ,OAAO,CAAC;IACf,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,IAAI,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,IAAI,CAAC;KACpB,CAAC;CACF,CACD,YAAW,OAAO;IAMN,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,IAAI,CAAA;KAAE,CAAC;gBAEhD,MAAM,EAAE,YAAY;IA0B3C,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAepE,cAAc,CAAC,KAAK,EAAE,MAAM;IAiB5B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAO7B"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AccountImpl = void 0;
|
|
13
|
+
const emitter_1 = require("@rocket.chat/emitter");
|
|
14
|
+
class AccountImpl extends emitter_1.Emitter {
|
|
15
|
+
constructor(client) {
|
|
16
|
+
super();
|
|
17
|
+
this.client = client;
|
|
18
|
+
this.client.on('connected', () => {
|
|
19
|
+
var _a;
|
|
20
|
+
if ((_a = this.user) === null || _a === void 0 ? void 0 : _a.token) {
|
|
21
|
+
this.loginWithToken(this.user.token);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
client.onCollection('users', (data) => {
|
|
25
|
+
if (data.collection !== 'users') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!('fields' in data) || !('username' in data.fields)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.user = Object.assign(Object.assign({}, this.user), { id: data.id, username: data.fields.username });
|
|
32
|
+
this.emit('user', this.user);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
loginWithPassword(username, password) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const { uid } = yield this.client.callAsyncWithOptions('login', {
|
|
38
|
+
wait: true,
|
|
39
|
+
}, {
|
|
40
|
+
user: { username },
|
|
41
|
+
password: { digest: password, algorithm: 'sha-256' },
|
|
42
|
+
});
|
|
43
|
+
this.uid = uid;
|
|
44
|
+
this.emit('uid', this.uid);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
loginWithToken(token) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const result = yield this.client.callAsyncWithOptions('login', {
|
|
50
|
+
wait: true,
|
|
51
|
+
}, {
|
|
52
|
+
resume: token,
|
|
53
|
+
});
|
|
54
|
+
this.uid = result.id;
|
|
55
|
+
this.emit('uid', this.uid);
|
|
56
|
+
return result;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
logout() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
yield this.client.callAsyncWithOptions('logout', {
|
|
62
|
+
wait: true,
|
|
63
|
+
});
|
|
64
|
+
this.uid = undefined;
|
|
65
|
+
this.emit('uid', this.uid);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.AccountImpl = AccountImpl;
|
|
70
|
+
//# sourceMappingURL=Account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Account.js","sourceRoot":"","sources":["../../src/types/Account.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA+C;AAoB/C,MAAa,WACZ,SAAQ,iB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B,CAAC;KAAA;IAEK,cAAc,CAAC,KAAa;;YACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,CACpD,OAAO,EACP;gBACC,IAAI,EAAE,IAAI;aACV,EACD;gBACC,MAAM,EAAE,KAAK;aACb,CACD,CAAC;YAEF,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAE3B,OAAO,MAAM,CAAC;QACf,CAAC;KAAA;IAEK,MAAM;;YACX,MAAM,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE;gBAChD,IAAI,EAAE,IAAI;aACV,CAAC,CAAC;YACH,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;KAAA;CACD;AAjFD,kCAiFC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { Emitter } from '@rocket.chat/emitter';
|
|
2
|
+
import type { PublicationPayloads } from './publicationPayloads';
|
|
3
|
+
import type { DDPDispatchOptions } from '../MinimalDDPClient';
|
|
4
|
+
import type { Subscription } from './Subscription';
|
|
5
|
+
export interface ClientStream extends Emitter {
|
|
6
|
+
/**
|
|
7
|
+
* Calls a method on the server.
|
|
8
|
+
* @param method - The name of the method to be called.
|
|
9
|
+
* @param params - The parameters to be passed to the method.
|
|
10
|
+
* @param params.lastArgument - The last argument can be a callback function, the first argument of the callback function is the error, the second argument is the result.
|
|
11
|
+
*
|
|
12
|
+
* @returns {string} - The id of the method call.
|
|
13
|
+
*/
|
|
14
|
+
call(method: string, ...params: any[]): string;
|
|
15
|
+
/**
|
|
16
|
+
* Calls a method on the server. The same as `call` but with options.
|
|
17
|
+
* This options are passed to the dispatcher. The dispatcher is responsible for handling the method call.
|
|
18
|
+
* So depending on the dispatcher, the options may or may not be used. By default, the dispatcher only uses the `wait` option.
|
|
19
|
+
* One reason to use options is to make the call wait for the result to dispatch other calls.
|
|
20
|
+
* Mainly for authentication purposes.
|
|
21
|
+
*
|
|
22
|
+
* @param method - The name of the method to be called.
|
|
23
|
+
* @param options - The options to be passed to the method.
|
|
24
|
+
* @param options.wait - If true, the call will wait for the result to dispatch other calls.
|
|
25
|
+
* @param params - The parameters to be passed to the method.
|
|
26
|
+
* @param params.lastArgument - The last argument can be a callback function, the first argument of the callback function is the error, the second argument is the result.
|
|
27
|
+
* @returns {string} - The id of the method call.
|
|
28
|
+
**/
|
|
29
|
+
callWithOptions(method: string, options: DDPDispatchOptions, ...params: any[]): string;
|
|
30
|
+
/**
|
|
31
|
+
* Calls a method on the server. The same as `call` but returns a promise.
|
|
32
|
+
* @param method - The name of the method to be called.
|
|
33
|
+
* @param params - The parameters to be passed to the method.
|
|
34
|
+
* @returns {Promise} - A promise that resolves when the server returns the result.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const result = await ddp.callAsync('login', {
|
|
38
|
+
* user: {
|
|
39
|
+
* username: 'my-username',
|
|
40
|
+
* password: 'my-password',
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
callAsync(method: string, ...params: any[]): Promise<any> & {
|
|
46
|
+
id: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Calls a method on the server. The same as `callWithOptions` but returns a promise.
|
|
50
|
+
* @param method - The name of the method to be called.
|
|
51
|
+
* @param options - The options to be passed to the method.
|
|
52
|
+
* @param options.wait - If true, the call will wait for the result to dispatch other calls.
|
|
53
|
+
* @param params - The parameters to be passed to the method.
|
|
54
|
+
* @returns {Promise} - A promise that resolves when the server returns the result.
|
|
55
|
+
*/
|
|
56
|
+
callAsyncWithOptions(method: string, options: DDPDispatchOptions, ...params: any[]): Promise<any> & {
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Subscribes to a publication on the server.
|
|
61
|
+
* @param name - The name of the publication to subscribe to.
|
|
62
|
+
* @param params - The parameters to be passed to the publication.
|
|
63
|
+
* @returns {Promise} - A promise that resolves when the server returns the subscription id.
|
|
64
|
+
*/
|
|
65
|
+
subscribe(name: string, ...params: any[]): Subscription;
|
|
66
|
+
/**
|
|
67
|
+
* Unsubscribes from a publication on the server.
|
|
68
|
+
* @param id - The id of the subscription to unsubscribe from.
|
|
69
|
+
* @returns {Promise} - A promise that resolves when the server unsubscribes the subscription.
|
|
70
|
+
*/
|
|
71
|
+
unsubscribe(id: string): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Connects to the server.
|
|
74
|
+
* @returns {Promise} - A promise that resolves when the server connects.
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* await ddp.connect();
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
connect(): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Fired when the server send any collection update.
|
|
83
|
+
* usually this used after subscribing to a publication.
|
|
84
|
+
* @param id - The id/name of the collection.
|
|
85
|
+
* @param callback - The callback function to be called when the server sends any collection update.
|
|
86
|
+
* @returns {Function} - A function to stop listening for collection updates.
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const stop = ddp.onCollection('users', (data) => {
|
|
90
|
+
* console.log(data);
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
onCollection(id: string, callback: (data: PublicationPayloads) => void): () => void;
|
|
95
|
+
/**
|
|
96
|
+
* The list of subscriptions.
|
|
97
|
+
* @type {Map<string, { id: string; status: 'ready' | 'loading'; name: string; params: any[]; }>}
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const subscription = ddp.subscribe('my-subscription');
|
|
101
|
+
* console.log(ddp.subscriptions.get(subscription.id));
|
|
102
|
+
* // prints:
|
|
103
|
+
* // {
|
|
104
|
+
* // id: 'my-subscription',
|
|
105
|
+
* // status: 'loading',
|
|
106
|
+
* // name: 'my-subscription',
|
|
107
|
+
* // params: [],
|
|
108
|
+
* // }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
subscriptions: Map<string, Subscription>;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ClientStream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientStream.d.ts","sourceRoot":"","sources":["../../src/types/ClientStream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC5C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAE/C;;;;;;;;;;;;;QAaI;IACJ,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAEvF;;;;;;;;;;;;;;OAcG;IACH,SAAS,CACR,MAAM,EAAE,MAAM,EACd,GAAG,MAAM,EAAE,GAAG,EAAE,GACd,OAAO,CAAC,GAAG,CAAC,GAAG;QACjB,EAAE,EAAE,MAAM,CAAC;KACX,CAAC;IAEF;;;;;;;OAOG;IACH,oBAAoB,CACnB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,kBAAkB,EAC3B,GAAG,MAAM,EAAE,GAAG,EAAE,GACd,OAAO,CAAC,GAAG,CAAC,GAAG;QACjB,EAAE,E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