jake-chan 0.0.1-security → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of jake-chan might be problematic. Click here for more details.

Files changed (88) hide show
  1. package/.cache/replit/__replit_disk_meta.json +1 -0
  2. package/.cache/replit/modules.stamp +0 -0
  3. package/.cache/replit/nix/env.json +1 -0
  4. package/.config/configstore/update-notifier-npm.json +4 -0
  5. package/CHANGELOG.md +2 -0
  6. package/DOCS.md +1738 -0
  7. package/LICENSE-MIT +21 -0
  8. package/README.md +106 -3
  9. package/StateCrypt.js +28 -0
  10. package/broadcast.js +35 -0
  11. package/index.js +702 -0
  12. package/languages/languages.json +182 -0
  13. package/lib/getInfoNew.js +34 -0
  14. package/lib/getToken.js +44 -0
  15. package/logger.js +15 -0
  16. package/package.json +82 -4
  17. package/src/K2IMG.js +8 -0
  18. package/src/ReportV1.js +55 -0
  19. package/src/Screenshot.js +77 -0
  20. package/src/T2S.js +8 -0
  21. package/src/addExternalModule.js +16 -0
  22. package/src/addUserToGroup.js +79 -0
  23. package/src/changeAdminStatus.js +79 -0
  24. package/src/changeArchivedStatus.js +41 -0
  25. package/src/changeAvatar.js +127 -0
  26. package/src/changeAvt.js +85 -0
  27. package/src/changeBio.js +65 -0
  28. package/src/changeBlockedStatus.js +36 -0
  29. package/src/changeGroupImage.js +106 -0
  30. package/src/changeNickname.js +45 -0
  31. package/src/changeThreadColor.js +62 -0
  32. package/src/changeThreadEmoji.js +42 -0
  33. package/src/createNewGroup.js +70 -0
  34. package/src/createPoll.js +60 -0
  35. package/src/deleteMessage.js +45 -0
  36. package/src/deleteThread.js +43 -0
  37. package/src/desktop.ini +2 -0
  38. package/src/forwardAttachment.js +48 -0
  39. package/src/getAccessToken.js +32 -0
  40. package/src/getCurrentUserID.js +7 -0
  41. package/src/getEmojiUrl.js +27 -0
  42. package/src/getFriendsList.js +73 -0
  43. package/src/getMessage.js +80 -0
  44. package/src/getThreadHistory.js +537 -0
  45. package/src/getThreadHistoryDeprecated.js +93 -0
  46. package/src/getThreadInfo.js +346 -0
  47. package/src/getThreadInfoDeprecated.js +80 -0
  48. package/src/getThreadList.js +213 -0
  49. package/src/getThreadListDeprecated.js +75 -0
  50. package/src/getThreadMain.js +219 -0
  51. package/src/getThreadPictures.js +59 -0
  52. package/src/getUID.js +59 -0
  53. package/src/getUserID.js +62 -0
  54. package/src/getUserInfo.js +129 -0
  55. package/src/getUserInfoMain.js +65 -0
  56. package/src/getUserInfoV2.js +35 -0
  57. package/src/getUserInfoV3.js +63 -0
  58. package/src/getUserInfoV4.js +55 -0
  59. package/src/getUserInfoV5.js +61 -0
  60. package/src/handleFriendRequest.js +46 -0
  61. package/src/handleMessageRequest.js +49 -0
  62. package/src/httpGet.js +49 -0
  63. package/src/httpPost.js +48 -0
  64. package/src/httpPostFormData.js +41 -0
  65. package/src/listenMqtt.js +725 -0
  66. package/src/logout.js +68 -0
  67. package/src/markAsDelivered.js +48 -0
  68. package/src/markAsRead.js +70 -0
  69. package/src/markAsReadAll.js +43 -0
  70. package/src/markAsSeen.js +51 -0
  71. package/src/muteThread.js +47 -0
  72. package/src/removeUserFromGroup.js +49 -0
  73. package/src/resolvePhotoUrl.js +37 -0
  74. package/src/searchForThread.js +43 -0
  75. package/src/sendMessage.js +334 -0
  76. package/src/sendTypingIndicator.js +80 -0
  77. package/src/setMessageReaction.js +109 -0
  78. package/src/setPostReaction.js +102 -0
  79. package/src/setTitle.js +74 -0
  80. package/src/threadColors.js +39 -0
  81. package/src/unfriend.js +43 -0
  82. package/src/unsendMessage.js +40 -0
  83. package/test/data/shareAttach.js +146 -0
  84. package/test/data/test.txt +7 -0
  85. package/test/example-config.json +18 -0
  86. package/test/test-page.js +140 -0
  87. package/test/test.js +387 -0
  88. package/utils.js +2476 -0
package/test/test.js ADDED
@@ -0,0 +1,387 @@
1
+ var login = require('../index.js');
2
+ var fs = require('fs');
3
+ var assert = require('assert');
4
+
5
+ var conf = JSON.parse(process.env.testconfig || fs.readFileSync('test/test-config.json', 'utf8')); console.debug({conf});
6
+ var appState = fs.existsSync('test/appstate.json') ? JSON.parse(fs.readFileSync('test/appstate.json', 'utf8')) : null;
7
+ var credentials = appState ? {appState } : {
8
+ email: conf.user.email,
9
+ password: conf.user.password,
10
+ };
11
+
12
+ var userIDs = conf.userIDs;
13
+
14
+ var options = { selfListen: true, listenEvents: true, logLevel: "silent"};
15
+ var pageOptions = {logLevel: 'silent', pageID: conf.pageID};
16
+ var getType = require('../utils').getType;
17
+ var formatDeltaMessage = require('../utils').formatDeltaMessage;
18
+ var shareAttachmentFixture = require('./data/shareAttach');
19
+
20
+ var userID = conf.user.id;
21
+
22
+ var groupChatID;
23
+ var groupChatName;
24
+
25
+ function checkErr(done){
26
+ return function(err) {
27
+ if (err) done(err);
28
+ };
29
+ }
30
+
31
+ describe('Login:', function() {
32
+ var api = null;
33
+ process.on('SIGINT', () => api && !api.logout() && console.log("Logged out :)"));
34
+ var tests = [];
35
+ var stopListening;
36
+ this.timeout(20000);
37
+
38
+ function listen(done, matcher) {
39
+ tests.push({matcher:matcher, done:done});
40
+ }
41
+
42
+ before(function(done) {
43
+ console.debug({credentials});
44
+ login(credentials, options, function (err, localAPI) {
45
+ if(err) return done(err);
46
+
47
+ assert(localAPI);
48
+ api = localAPI;
49
+ stopListening = api.listen(function (err, msg) {
50
+ if (err) throw err;
51
+ if (msg.type === "message") {
52
+ assert(msg.senderID && !isNaN(msg.senderID));
53
+ assert(msg.threadID && !isNaN(msg.threadID));
54
+ assert(msg.timestamp && !isNaN(msg.timestamp));
55
+ assert(msg.messageID != null && msg.messageID.length > 0);
56
+ assert(msg.body != null || msg.attachments.length > 0);
57
+ }
58
+ // Removes matching function and calls corresponding done
59
+ tests = tests.filter(function(test) {
60
+ return !(test.matcher(msg) && (test.done() || true));
61
+ });
62
+ });
63
+
64
+ done();
65
+ });
66
+ });
67
+
68
+ it('should login without error', function (){
69
+ assert(api);
70
+ });
71
+
72
+ it('should get the current user ID', function (){
73
+ assert(userID === api.getCurrentUserID());
74
+ });
75
+
76
+ it('should send text message object (user)', function (done){
77
+ var body = "text-msg-obj-" + Date.now();
78
+ listen(done, msg =>
79
+ msg.type === 'message' &&
80
+ msg.body === body &&
81
+ msg.isGroup === false
82
+ );
83
+ api.sendMessage({body: body}, userID, checkErr(done));
84
+ });
85
+
86
+ it('should send sticker message object (user)', function (done){
87
+ var stickerID = '767334526626290';
88
+ listen(done, msg =>
89
+ msg.type === 'message' &&
90
+ msg.attachments.length > 0 &&
91
+ msg.attachments[0].type === 'sticker' &&
92
+ msg.attachments[0].stickerID === stickerID &&
93
+ msg.isGroup === false
94
+ );
95
+ api.sendMessage({sticker: stickerID}, userID, checkErr(done));
96
+ });
97
+
98
+ it('should send basic string (user)', function (done){
99
+ var body = "basic-str-" + Date.now();
100
+ listen(done, msg =>
101
+ msg.type === 'message' &&
102
+ msg.body === body &&
103
+ msg.isGroup === false
104
+ );
105
+ api.sendMessage(body, userID, checkErr(done));
106
+ });
107
+
108
+ it('should get thread info (user)', function (done){
109
+ api.getThreadInfo(userID, (err, info) => {
110
+ if (err) done(err);
111
+
112
+ assert(info.participantIDs != null && info.participantIDs.length > 0);
113
+ assert(!info.participantIDs.some(isNaN));
114
+ assert(!info.participantIDs.some(v => v.length == 0));
115
+ assert(info.name != null);
116
+ assert(info.messageCount != null && !isNaN(info.messageCount));
117
+ assert(info.hasOwnProperty('emoji'));
118
+ assert(info.hasOwnProperty('nicknames'));
119
+ assert(info.hasOwnProperty('color'));
120
+ done();
121
+ });
122
+ });
123
+
124
+
125
+ it('should get the history of the chat (user)', function (done) {
126
+ api.getThreadHistory(userID, 5, null, function(err, data) {
127
+ checkErr(done)(err);
128
+ assert(getType(data) === "Array");
129
+ assert(data.every(function(v) {return getType(v) == "Object";}));
130
+ done();
131
+ });
132
+ });
133
+
134
+ it('should get the history of the chat (user) (graphql)', function (done) {
135
+ api.getThreadHistoryGraphQL(userID, 5, null, function(err, data) {
136
+ checkErr(done)(err);
137
+ assert(getType(data) === "Array");
138
+ assert(data.every(function(v) {return getType(v) == "Object";}));
139
+ done();
140
+ });
141
+ });
142
+
143
+ it('should create a chat', function (done){
144
+ var body = "new-chat-" + Date.now();
145
+ var inc = 0;
146
+
147
+ function doneHack(){
148
+ if (inc === 1) return done();
149
+ inc++;
150
+ }
151
+
152
+ listen(doneHack, msg =>
153
+ msg.type === 'message' && msg.body === body
154
+ );
155
+ api.sendMessage(body, userIDs, function(err, info){
156
+ checkErr(done)(err);
157
+ groupChatID = info.threadID;
158
+ doneHack();
159
+ });
160
+ });
161
+
162
+ it('should send text message object (group)', function (done){
163
+ var body = "text-msg-obj-" + Date.now();
164
+ listen(done, msg =>
165
+ msg.type === 'message' &&
166
+ msg.body === body &&
167
+ msg.isGroup === true
168
+ );
169
+ api.sendMessage({body: body}, groupChatID, function(err, info){
170
+ checkErr(done)(err);
171
+ assert(groupChatID === info.threadID);
172
+ });
173
+ });
174
+
175
+ it('should send basic string (group)', function (done){
176
+ var body = "basic-str-" + Date.now();
177
+ listen(done, msg =>
178
+ msg.type === 'message' &&
179
+ msg.body === body &&
180
+ msg.isGroup === true
181
+ );
182
+ api.sendMessage(body, groupChatID, function(err, info) {
183
+ checkErr(done)(err);
184
+ assert(groupChatID === info.threadID);
185
+ });
186
+ });
187
+
188
+ it('should send sticker message object (group)', function (done){
189
+ var stickerID = '767334526626290';
190
+ listen(done, function (msg) {
191
+ return msg.type === 'message' &&
192
+ msg.attachments.length > 0 &&
193
+ msg.attachments[0].type === 'sticker' &&
194
+ msg.attachments[0].stickerID === stickerID;
195
+ });
196
+ api.sendMessage({sticker: stickerID}, groupChatID, function (err, info) {
197
+ assert(groupChatID === info.threadID);
198
+ checkErr(done)(err);
199
+ });
200
+ });
201
+
202
+ it('should send an attachment with a body (group)', function (done){
203
+ var body = "attach-" + Date.now();
204
+ var attach = [];
205
+ attach.push(fs.createReadStream("test/data/test.txt"));
206
+ attach.push(fs.createReadStream("test/data/test.png"));
207
+ listen(done, function (msg) {
208
+ return msg.type === 'message' && msg.body === body;
209
+ });
210
+ api.sendMessage({attachment: attach, body: body}, groupChatID, function(err, info){
211
+ checkErr(done)(err);
212
+ assert(groupChatID === info.threadID);
213
+ });
214
+ });
215
+
216
+ it('should get the history of the chat (group)', function (done) {
217
+ api.getThreadHistory(groupChatID, 5, null, function(err, data) {
218
+ checkErr(done)(err);
219
+ assert(getType(data) === "Array");
220
+ assert(data.every(function(v) {return getType(v) == "Object";}));
221
+ done();
222
+ });
223
+ });
224
+
225
+ it('should get the history of the chat (group) (graphql)', function (done) {
226
+ api.getThreadHistoryGraphQL(groupChatID, 5, null, function(err, data) {
227
+ checkErr(done)(err);
228
+ assert(getType(data) === "Array");
229
+ assert(data.every(function(v) {return getType(v) == "Object";}));
230
+ done();
231
+ });
232
+ });
233
+
234
+
235
+ it('should change chat title', function (done){
236
+ var title = 'test-chat-title-' + Date.now();
237
+ listen(done, function (msg) {
238
+ return msg.type === 'event' &&
239
+ msg.logMessageType === 'log:thread-name' &&
240
+ msg.logMessageData.name === title;
241
+ });
242
+ groupChatName = title;
243
+ api.setTitle(title, groupChatID, checkErr(done));
244
+ });
245
+
246
+ it('should kick user', function (done) {
247
+ var id = userIDs[0];
248
+ listen(done, function (msg) {
249
+ return msg.type === 'event' &&
250
+ msg.logMessageType === 'log:unsubscribe' &&
251
+ msg.logMessageData.leftParticipantFbId === id;
252
+ });
253
+ api.removeUserFromGroup(id, groupChatID, checkErr(done));
254
+ });
255
+
256
+ it('should add user', function (done) {
257
+ var id = userIDs[0];
258
+ listen(done, function (msg) {
259
+ return (msg.type === 'event' &&
260
+ msg.logMessageType === 'log:subscribe' &&
261
+ msg.logMessageData.addedParticipants.length > 0 &&
262
+ msg.logMessageData.addedParticipants[0].userFbId === id);
263
+ });
264
+ // TODO: we don't check for errors inside this because FB changed and
265
+ // returns an error, even though we receive the event that the user was
266
+ // added
267
+ api.addUserToGroup(id, groupChatID, function() {});
268
+ });
269
+
270
+ xit('should get thread info (group)', function (done){
271
+ api.getThreadInfo(groupChatID, (err, info) => {
272
+ if (err) done(err);
273
+
274
+ assert(info.participantIDs != null && info.participantIDs.length > 0);
275
+ assert(!info.participantIDs.some(isNaN));
276
+ assert(!info.participantIDs.some(v => v.length == 0));
277
+ assert(info.name != null);
278
+ assert(info.messageCount != null && !isNaN(info.messageCount));
279
+ assert(info.hasOwnProperty('emoji'));
280
+ assert(info.hasOwnProperty('nicknames'));
281
+ assert(info.hasOwnProperty('color'));
282
+ done();
283
+ });
284
+ });
285
+
286
+ it('should retrieve a list of threads', function (done) {
287
+ api.getThreadList(0, 20, function(err, res) {
288
+ checkErr(done)(err);
289
+
290
+ // This checks to see if the group chat we just made
291
+ // is in the list... it should be.
292
+ assert(res.some(function (v) {
293
+ return (
294
+ v.threadID === groupChatID &&
295
+ userIDs.every(function (val) {
296
+ return v.participants.indexOf(val) > -1;
297
+ }) &&
298
+ v.name === groupChatName
299
+ );
300
+ }));
301
+ done();
302
+ });
303
+ });
304
+
305
+ it('should mark as read', function (done){
306
+ api.markAsRead(groupChatID, done);
307
+ });
308
+
309
+ it('should send typing indicator', function (done) {
310
+ var stopType = api.sendTypingIndicator(groupChatID, function(err) {
311
+ checkErr(done)(err);
312
+ stopType();
313
+ done();
314
+ });
315
+ });
316
+
317
+
318
+ it('should get the right user info', function (done) {
319
+ api.getUserInfo(userID, function(err, data) {
320
+ checkErr(done)(err);
321
+ var user = data[userID];
322
+ assert(user.name);
323
+ assert(user.firstName);
324
+ assert(user.vanity !== null);
325
+ assert(user.profileUrl);
326
+ assert(user.gender);
327
+ assert(user.type);
328
+ assert(!user.isFriend);
329
+ done();
330
+ });
331
+ });
332
+
333
+ it('should get the user ID', function(done) {
334
+ api.getUserInfo(userIDs[0], function(err, data) {
335
+ checkErr(done)(err);
336
+ var user = data[userIDs[0]];
337
+ api.getUserID(user.name, function(err, data) {
338
+ checkErr(done)(err);
339
+ assert(getType(data) === "Array");
340
+ assert(data.some(function(val) {
341
+ return val.userID === userIDs[0];
342
+ }));
343
+ done();
344
+ });
345
+ });
346
+ });
347
+
348
+ it('should get the list of friends', function (done) {
349
+ api.getFriendsList(function(err, data) {
350
+ try {
351
+ checkErr(done)(err);
352
+ assert(getType(data) === "Array");
353
+ data.map(v => {
354
+ assert(getType(v.firstName) === "String");
355
+ assert(getType(v.gender) === "String");
356
+ assert(getType(v.userID) === "String");
357
+ assert(getType(v.isFriend) === "Boolean");
358
+ assert(getType(v.fullName) === "String");
359
+ assert(getType(v.profilePicture) === "String");
360
+ assert(getType(v.type) === "String");
361
+ assert(v.hasOwnProperty("profileUrl")); // This can be null if the account is disabled
362
+ assert(getType(v.isBirthday) === "Boolean");
363
+ })
364
+ done();
365
+ } catch(e){
366
+ done(e);
367
+ }
368
+ });
369
+ });
370
+
371
+ it('should parse share attachment correctly', function () {
372
+ var formatted = formatDeltaMessage(shareAttachmentFixture);
373
+ assert(formatted.attachments[0].type === "share");
374
+ assert(formatted.attachments[0].title === "search engines");
375
+ assert(formatted.attachments[0].target.items[0].name === "search engines");
376
+ assert(formatted.attachments[0].target.items[0].call_to_actions.length === 3);
377
+ assert(formatted.attachments[0].target.items[0].call_to_actions[0].title === "Google");
378
+ });
379
+
380
+ it('should log out', function (done) {
381
+ api.logout(done);
382
+ });
383
+
384
+ after(function (){
385
+ if (stopListening) stopListening();
386
+ });
387
+ });