@softtynet/zca-js 2.3.3 → 2.3.4

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.
Files changed (74) hide show
  1. package/README.md +63 -21
  2. package/dist/apis/auth/exportSession.d.ts +7 -0
  3. package/dist/apis/auth/exportSession.js +17 -0
  4. package/dist/apis/chat/getDirectMessageStatus.d.ts +14 -0
  5. package/dist/apis/chat/getDirectMessageStatus.js +52 -0
  6. package/dist/apis/chat/getSuggestedConversations.d.ts +5 -0
  7. package/dist/apis/chat/getSuggestedConversations.js +24 -0
  8. package/dist/apis/chat/updatePinConversations.d.ts +24 -0
  9. package/dist/apis/chat/updatePinConversations.js +40 -0
  10. package/dist/apis/friend/getFriendProfilesV2.d.ts +26 -0
  11. package/dist/apis/friend/getFriendProfilesV2.js +38 -0
  12. package/dist/apis/friend/getFriendsActivePCWeb.d.ts +6 -0
  13. package/dist/apis/friend/getFriendsActivePCWeb.js +15 -0
  14. package/dist/apis/friend/verifyFriend.d.ts +11 -0
  15. package/dist/apis/friend/verifyFriend.js +37 -0
  16. package/dist/apis/group/analyseGroup.d.ts +4 -0
  17. package/dist/apis/group/analyseGroup.js +28 -0
  18. package/dist/apis/group/checkQuotaCommunityMember.d.ts +6 -0
  19. package/dist/apis/group/checkQuotaCommunityMember.js +34 -0
  20. package/dist/apis/group/getE2eeGroupList.d.ts +7 -0
  21. package/dist/apis/group/getE2eeGroupList.js +15 -0
  22. package/dist/apis/group/getGroupCloudMessagePath.d.ts +19 -0
  23. package/dist/apis/group/getGroupCloudMessagePath.js +51 -0
  24. package/dist/apis/group/getMultiGroupCloudMessages.d.ts +5 -0
  25. package/dist/apis/group/getMultiGroupCloudMessages.js +29 -0
  26. package/dist/apis/media/getPersonalMedia.d.ts +8 -0
  27. package/dist/apis/media/getPersonalMedia.js +31 -0
  28. package/dist/apis/media/getPersonalMediaPreview.d.ts +3 -0
  29. package/dist/apis/media/getPersonalMediaPreview.js +24 -0
  30. package/dist/apis/media/removePersonalMedia.d.ts +9 -0
  31. package/dist/apis/media/removePersonalMedia.js +28 -0
  32. package/dist/apis.d.ts +45 -0
  33. package/dist/apis.js +75 -0
  34. package/dist/cjs/apis/auth/exportSession.cjs +22 -0
  35. package/dist/cjs/apis/chat/getDirectMessageStatus.cjs +58 -0
  36. package/dist/cjs/apis/chat/getSuggestedConversations.cjs +29 -0
  37. package/dist/cjs/apis/chat/updatePinConversations.cjs +45 -0
  38. package/dist/cjs/apis/friend/getFriendProfilesV2.cjs +43 -0
  39. package/dist/cjs/apis/friend/getFriendsActivePCWeb.cjs +20 -0
  40. package/dist/cjs/apis/friend/verifyFriend.cjs +42 -0
  41. package/dist/cjs/apis/group/analyseGroup.cjs +33 -0
  42. package/dist/cjs/apis/group/checkQuotaCommunityMember.cjs +39 -0
  43. package/dist/cjs/apis/group/getE2eeGroupList.cjs +20 -0
  44. package/dist/cjs/apis/group/getGroupChatHistory.cjs +8 -7
  45. package/dist/cjs/apis/group/getGroupCloudMessagePath.cjs +69 -0
  46. package/dist/cjs/apis/group/getGroupHistoryLegacy.cjs +7 -6
  47. package/dist/cjs/apis/group/getGroupMessageStatus.cjs +7 -6
  48. package/dist/cjs/apis/group/getMultiGroupCloudMessages.cjs +34 -0
  49. package/dist/cjs/apis/media/getPersonalMedia.cjs +36 -0
  50. package/dist/cjs/apis/media/getPersonalMediaPreview.cjs +29 -0
  51. package/dist/cjs/apis/media/removePersonalMedia.cjs +33 -0
  52. package/dist/cjs/apis.cjs +75 -0
  53. package/dist/cjs/constants/protocol.cjs +1 -1
  54. package/dist/cjs/context.cjs +20 -2
  55. package/dist/cjs/core/zcloud-client.cjs +1 -2
  56. package/dist/cjs/crypto/ws-cipher.cjs +66 -2
  57. package/dist/cjs/index.cjs +9 -2
  58. package/dist/cjs/realtime/listener.cjs +18 -6
  59. package/dist/cjs/update.cjs +10 -1
  60. package/dist/cjs/utils.cjs +21 -68
  61. package/dist/constants/protocol.d.ts +1 -1
  62. package/dist/constants/protocol.js +1 -1
  63. package/dist/context.d.ts +10 -0
  64. package/dist/context.js +20 -2
  65. package/dist/crypto/ws-cipher.d.ts +7 -0
  66. package/dist/crypto/ws-cipher.js +64 -2
  67. package/dist/index.d.ts +15 -0
  68. package/dist/realtime/listener.d.ts +1 -0
  69. package/dist/realtime/listener.js +18 -6
  70. package/dist/update.js +10 -1
  71. package/dist/utils.d.ts +0 -7
  72. package/dist/utils.js +15 -64
  73. package/index.d.ts +1 -1
  74. package/package.json +15 -5
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ var utils = require('../../utils.cjs');
4
+
5
+ const getE2eeGroupListFactory = utils.apiFactory()((api, _ctx, utils) => {
6
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getlg/e2ee`);
7
+ /**
8
+ * Lấy danh sách các nhóm đang bật mã hóa đầu cuối E2EE (command 12146)
9
+ *
10
+ * @throws {ZaloApiError}
11
+ */
12
+ return async function getE2eeGroupList() {
13
+ const response = await utils.request(serviceURL, {
14
+ method: "GET",
15
+ });
16
+ return utils.resolve(response);
17
+ };
18
+ });
19
+
20
+ exports.getE2eeGroupListFactory = getE2eeGroupListFactory;
@@ -15,10 +15,11 @@ require('../../models/Reminder.cjs');
15
15
  require('../../models/ZBusiness.cjs');
16
16
  require('../../models/SyncEvent.cjs');
17
17
  require('../../models/CallEvent.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
18
19
 
19
- const getGroupChatHistoryFactory = utils.apiFactory()((api, ctx, utils$1) => {
20
- const recentServiceURL = utils$1.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getrecentv2`);
21
- const oldServiceURL = utils$1.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getoldv2`);
20
+ const getGroupChatHistoryFactory = utils.apiFactory()((api, ctx, utils) => {
21
+ const recentServiceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getrecentv2`);
22
+ const oldServiceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getoldv2`);
22
23
  /**
23
24
  * Lấy lịch sử tin nhắn nhóm từ Zalo Cloud Message (hỗ trợ cả `/api/cm/getrecentv2` cmd 12506 và `/api/cm/getoldv2` cmd 12507)
24
25
  *
@@ -56,16 +57,16 @@ const getGroupChatHistoryFactory = utils.apiFactory()((api, ctx, utils$1) => {
56
57
  if (options.isOA) {
57
58
  params.isOA = 1;
58
59
  }
59
- const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
60
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
60
61
  if (!encryptedParams)
61
62
  throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
62
- const response = await utils$1.request(utils$1.makeURL(targetServiceURL, { params: encryptedParams, nretry: 0 }), {
63
+ const response = await utils.request(utils.makeURL(targetServiceURL, { params: encryptedParams, nretry: 0 }), {
63
64
  method: "GET",
64
65
  });
65
- lastPage = await utils$1.resolve(response, (result) => {
66
+ lastPage = await utils.resolve(response, (result) => {
66
67
  let data = result.data;
67
68
  if (typeof data === "string") {
68
- data = JSON.parse(utils.preParseJsonIds(data));
69
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
69
70
  }
70
71
  return data;
71
72
  });
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ require('../../models/AutoReply.cjs');
5
+ require('../../models/Bank.cjs');
6
+ require('../../models/Board.cjs');
7
+ require('../../models/Enum.cjs');
8
+ require('../../models/FriendEvent.cjs');
9
+ require('../../models/Group.cjs');
10
+ require('../../models/GroupEvent.cjs');
11
+ var Message = require('../../models/Message.cjs');
12
+ require('../../models/Reaction.cjs');
13
+ require('../../models/Reminder.cjs');
14
+ require('../../models/ZBusiness.cjs');
15
+ require('../../models/SyncEvent.cjs');
16
+ require('../../models/CallEvent.cjs');
17
+ var utils = require('../../utils.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
19
+
20
+ const getGroupCloudMessagePathFactory = utils.apiFactory()((api, ctx, utils) => {
21
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/getpath`);
22
+ /**
23
+ * Lấy chuỗi tin nhắn nhóm theo đường dẫn nhảy tới một tin nhắn cụ thể (`globalMsgId` / `rGlobalMsgId`) qua `/api/cm/getpath` (command 12504)
24
+ *
25
+ * @param options Cấu hình truy vấn đường dẫn tin nhắn nhóm
26
+ * @throws {ZaloApiError}
27
+ */
28
+ return async function getGroupCloudMessagePath(options) {
29
+ if (!options?.groupId) {
30
+ throw new ZaloApiError.ZaloApiError("Missing groupId");
31
+ }
32
+ const cleanGroupId = options.groupId.startsWith("g") ? options.groupId.slice(1) : options.groupId;
33
+ const params = {
34
+ groupId: cleanGroupId,
35
+ globalMsgId: options.globalMsgId,
36
+ count: options.count ?? 50,
37
+ reverse: typeof options.reverse === "boolean" ? (options.reverse ? 1 : 0) : (options.reverse ?? 0),
38
+ };
39
+ if (options.rGlobalMsgId !== undefined && options.rOwnerId) {
40
+ params.rGlobalMsgId = options.rGlobalMsgId;
41
+ params.rOwnerId = options.rOwnerId;
42
+ if (options.rClientMsgId !== undefined) {
43
+ params.rClientMsgId = options.rClientMsgId;
44
+ }
45
+ }
46
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
47
+ if (!encryptedParams) {
48
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
49
+ }
50
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams, nretry: 0 }), {
51
+ method: "GET",
52
+ });
53
+ return utils.resolve(response, (result) => {
54
+ let data = result.data;
55
+ if (typeof data === "string") {
56
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
57
+ }
58
+ const rawObj = (data && typeof data === "object" ? data : {});
59
+ const rawMsgs = Array.isArray(rawObj.groupMsgs) ? rawObj.groupMsgs : [];
60
+ const groupMsgs = rawMsgs.map((m) => new Message.GroupMessage(ctx.uid, m));
61
+ return {
62
+ ...rawObj,
63
+ groupMsgs,
64
+ };
65
+ });
66
+ };
67
+ });
68
+
69
+ exports.getGroupCloudMessagePathFactory = getGroupCloudMessagePathFactory;
@@ -15,9 +15,10 @@ require('../../models/ZBusiness.cjs');
15
15
  require('../../models/SyncEvent.cjs');
16
16
  require('../../models/CallEvent.cjs');
17
17
  var utils = require('../../utils.cjs');
18
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
18
19
 
19
- const getGroupHistoryLegacyFactory = utils.apiFactory()((api, ctx, utils$1) => {
20
- const serviceURL = utils$1.makeURL(`${api.zpwServiceMap.group[0]}/api/group/history`);
20
+ const getGroupHistoryLegacyFactory = utils.apiFactory()((api, ctx, utils) => {
21
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/history`);
21
22
  /**
22
23
  * Lấy lịch sử tin nhắn nhóm qua endpoint `/api/group/history` trên miền `group` (command 11240)
23
24
  *
@@ -34,18 +35,18 @@ const getGroupHistoryLegacyFactory = utils.apiFactory()((api, ctx, utils$1) => {
34
35
  grid: cleanGroupId,
35
36
  count,
36
37
  };
37
- const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
38
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
38
39
  if (!encryptedParams) {
39
40
  throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
40
41
  }
41
- const response = await utils$1.request(utils$1.makeURL(serviceURL, { params: encryptedParams }), {
42
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
42
43
  method: "GET",
43
44
  });
44
- return utils$1.resolve(response, (result) => {
45
+ return utils.resolve(response, (result) => {
45
46
  let data = result.data;
46
47
  if (typeof data === "string") {
47
48
  try {
48
- data = JSON.parse(utils.preParseJsonIds(data));
49
+ data = JSON.parse(wsCipher.preParseJsonIds(data));
49
50
  }
50
51
  catch {
51
52
  data = {};
@@ -2,9 +2,10 @@
2
2
 
3
3
  var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
4
  var utils = require('../../utils.cjs');
5
+ var wsCipher = require('../../crypto/ws-cipher.cjs');
5
6
 
6
- const getGroupMessageStatusFactory = utils.apiFactory()((api, _ctx, utils$1) => {
7
- const serviceURL = utils$1.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getStatusMsg`);
7
+ const getGroupMessageStatusFactory = utils.apiFactory()((api, _ctx, utils) => {
8
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group[0]}/api/group/getStatusMsg`);
8
9
  /**
9
10
  * Truy vấn trạng thái Đã nhận (`deliver`) và Đã xem (`seen`) tin nhắn của danh sách thành viên trong nhóm (command 12017)
10
11
  *
@@ -37,21 +38,21 @@ const getGroupMessageStatusFactory = utils.apiFactory()((api, _ctx, utils$1) =>
37
38
  data: queryData,
38
39
  }),
39
40
  };
40
- const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
41
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
41
42
  if (!encryptedParams) {
42
43
  throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
43
44
  }
44
- const response = await utils$1.request(serviceURL, {
45
+ const response = await utils.request(serviceURL, {
45
46
  method: "POST",
46
47
  body: new URLSearchParams({
47
48
  params: encryptedParams,
48
49
  }),
49
50
  });
50
- return utils$1.resolve(response, (result) => {
51
+ return utils.resolve(response, (result) => {
51
52
  let rawData = result.data;
52
53
  if (typeof rawData === "string" && rawData.length > 0) {
53
54
  try {
54
- const parsed = JSON.parse(utils.preParseJsonIds(rawData));
55
+ const parsed = JSON.parse(wsCipher.preParseJsonIds(rawData));
55
56
  if (parsed && typeof parsed === "object" && "data" in parsed && parsed.data) {
56
57
  rawData = parsed.data;
57
58
  }
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getMultiGroupCloudMessagesFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.group_cloud_message[0]}/api/cm/mget`);
8
+ /**
9
+ * Đồng bộ nhanh tin nhắn Cloud của nhiều nhóm cùng lúc theo danh sách `groupIds` (command 12503 - `syncCloudMsgFirstLogin`)
10
+ *
11
+ * @param groupIds Danh sách ID nhóm cần tải tin nhắn Cloud
12
+ * @param nretry Số lần thử lại (mặc định: `0`)
13
+ * @throws {ZaloApiError}
14
+ */
15
+ return async function getMultiGroupCloudMessages(groupIds, nretry = 0) {
16
+ if (!Array.isArray(groupIds) || groupIds.length === 0) {
17
+ throw new ZaloApiError.ZaloApiError("Missing groupIds");
18
+ }
19
+ const cleanGroupIds = groupIds.map((gid) => (gid.startsWith("g") ? gid.slice(1) : gid));
20
+ const params = {
21
+ groupIds: cleanGroupIds,
22
+ };
23
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
24
+ if (!encryptedParams) {
25
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
26
+ }
27
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams, nretry }), {
28
+ method: "GET",
29
+ });
30
+ return utils.resolve(response);
31
+ };
32
+ });
33
+
34
+ exports.getMultiGroupCloudMessagesFactory = getMultiGroupCloudMessagesFactory;
@@ -0,0 +1,36 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getPersonalMediaFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/list`);
8
+ /**
9
+ * Lấy danh sách Kho Lưu Trữ Ảnh/Video (`"media"`), File (`"file"`), hoặc Link (`"link"`) trong Cloud của tôi (Send2Me) (command 12220)
10
+ *
11
+ * @param options Tùy chọn truy vấn (`mediaType`, `limit`, `lastId`, `lastFetchId`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getPersonalMedia(options = {}) {
15
+ const params = {
16
+ media_type: options.mediaType ?? "media",
17
+ limit: options.limit ?? 20,
18
+ };
19
+ if (options.lastId !== undefined) {
20
+ params.last_id = options.lastId;
21
+ }
22
+ if (options.lastFetchId !== undefined && !Number.isNaN(options.lastFetchId)) {
23
+ params.lastFetchId = options.lastFetchId;
24
+ }
25
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
26
+ if (!encryptedParams) {
27
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
28
+ }
29
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
30
+ method: "GET",
31
+ });
32
+ return utils.resolve(response);
33
+ };
34
+ });
35
+
36
+ exports.getPersonalMediaFactory = getPersonalMediaFactory;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const getPersonalMediaPreviewFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/preview`);
8
+ /**
9
+ * Lấy danh sách xem trước nhanh Kho Lưu Trữ trong Cloud của tôi (Send2Me) (command 12221)
10
+ *
11
+ * @param limit Số lượng mục tối đa (mặc định: `50`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function getPersonalMediaPreview(limit = 50) {
15
+ const params = {
16
+ limit,
17
+ };
18
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
19
+ if (!encryptedParams) {
20
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
21
+ }
22
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
23
+ method: "POST",
24
+ });
25
+ return utils.resolve(response);
26
+ };
27
+ });
28
+
29
+ exports.getPersonalMediaPreviewFactory = getPersonalMediaPreviewFactory;
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var ZaloApiError = require('../../Errors/ZaloApiError.cjs');
4
+ var utils = require('../../utils.cjs');
5
+
6
+ const removePersonalMediaFactory = utils.apiFactory()((api, _ctx, utils) => {
7
+ const serviceURL = utils.makeURL(`${api.zpwServiceMap.media_store_send2me[0]}/api/media/oneone/remove`);
8
+ /**
9
+ * Xóa mục lưu trữ trong Kho Lưu Trữ Cloud của tôi (Send2Me) (command 12222)
10
+ *
11
+ * @param options Thông tin mục cần xóa (`mediaType`, `mediaId`)
12
+ * @throws {ZaloApiError}
13
+ */
14
+ return async function removePersonalMedia(options) {
15
+ if (!options?.mediaType || options.mediaId === undefined) {
16
+ throw new ZaloApiError.ZaloApiError("Missing mediaType or mediaId");
17
+ }
18
+ const params = {
19
+ media_type: options.mediaType,
20
+ media_id: options.mediaId,
21
+ };
22
+ const encryptedParams = utils.encodeAES(JSON.stringify(params));
23
+ if (!encryptedParams) {
24
+ throw new ZaloApiError.ZaloApiError("Failed to encrypt params");
25
+ }
26
+ const response = await utils.request(utils.makeURL(serviceURL, { params: encryptedParams }), {
27
+ method: "POST",
28
+ });
29
+ return utils.resolve(response);
30
+ };
31
+ });
32
+
33
+ exports.removePersonalMediaFactory = removePersonalMediaFactory;