zalo-toolkit 1.0.6 → 1.0.8

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.
@@ -267,6 +267,7 @@ export async function handleWaitingConfirm(ctx, version, code) {
267
267
  throw new ZaloApiError('Không thể lấy thông tin tài khoản');
268
268
  if (!userInfo.data.logged)
269
269
  throw new ZaloApiError('Không thể đăng nhập');
270
+ console.log('test', ctx.cookie.toJSON().cookies);
270
271
  return {
271
272
  cookies: ctx.cookie.toJSON().cookies,
272
273
  userInfo: userInfo.data.info,
@@ -27,7 +27,7 @@ export const uploadProductPhotoFactory = apiFactory()((api, ctx, utils) => {
27
27
  totalSize: fileSize,
28
28
  imei: ctx.imei,
29
29
  chunkId: 1,
30
- toid: ctx.loginInfo.send2me_id,
30
+ toid: ctx.serverInfo.send2me_id,
31
31
  featureId: 1,
32
32
  };
33
33
  const encryptedParams = utils.encodeAES(JSON.stringify(params));
@@ -270,6 +270,7 @@ async function handleWaitingConfirm(ctx, version, code) {
270
270
  throw new ZaloApiError.ZaloApiError('Không thể lấy thông tin tài khoản');
271
271
  if (!userInfo.data.logged)
272
272
  throw new ZaloApiError.ZaloApiError('Không thể đăng nhập');
273
+ console.log('test', ctx.cookie.toJSON().cookies);
273
274
  return {
274
275
  cookies: ctx.cookie.toJSON().cookies,
275
276
  userInfo: userInfo.data.info,
@@ -30,7 +30,7 @@ const uploadProductPhotoFactory = utils.apiFactory()((api, ctx, utils$1) => {
30
30
  totalSize: fileSize,
31
31
  imei: ctx.imei,
32
32
  chunkId: 1,
33
- toid: ctx.loginInfo.send2me_id,
33
+ toid: ctx.serverInfo.send2me_id,
34
34
  featureId: 1,
35
35
  };
36
36
  const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
@@ -16,7 +16,7 @@ const createContext = (apiType = 30, apiVersion = 665) => ({
16
16
  API_TYPE: apiType,
17
17
  API_VERSION: apiVersion,
18
18
  options: {
19
- selfListen: false,
19
+ selfListen: true,
20
20
  checkUpdate: true,
21
21
  logging: true,
22
22
  polyfill: global.fetch,
@@ -7,12 +7,13 @@ require('node:fs');
7
7
  var path = require('node:path');
8
8
  var pako = require('pako');
9
9
  var SparkMD5 = require('spark-md5');
10
- var ToughCookie = require('tough-cookie');
11
10
  var sharp = require('sharp');
12
11
  var context = require('./context.cjs');
13
12
  var ZaloApiError = require('./Errors/ZaloApiError.cjs');
14
13
  var FriendEvent = require('./models/FriendEvent.cjs');
15
14
  var GroupEvent = require('./models/GroupEvent.cjs');
15
+ var ToughCookie = require('tough-cookie');
16
+ var setCookieParser = require('set-cookie-parser');
16
17
 
17
18
  // export const isBun = typeof Bun !== "undefined";
18
19
  function hasOwn(obj, key) {
@@ -264,12 +265,13 @@ async function request(ctx, url, options, raw = false) {
264
265
  const response = await ctx.options.polyfill(url, _options);
265
266
  const setCookieRaw = response.headers.get('set-cookie');
266
267
  if (setCookieRaw && !raw) {
267
- const splitCookies = setCookieRaw.split(', ');
268
- for (const cookie of splitCookies) {
269
- const parsed = ToughCookie.Cookie.parse(cookie);
268
+ const splitCookies = setCookieParser.splitCookiesString(setCookieRaw);
269
+ for (const cookieStr of splitCookies) {
270
270
  try {
271
- if (parsed)
272
- await ctx.cookie.setCookie(parsed, parsed.domain != 'zalo.me' ? `https://${parsed.domain}` : origin);
271
+ const parsed = ToughCookie.Cookie.parse(cookieStr);
272
+ if (parsed) {
273
+ await ctx.cookie.setCookie(cookieStr, parsed.domain != 'zalo.me' ? `https://${parsed.domain}` : origin);
274
+ }
273
275
  }
274
276
  catch (error) {
275
277
  logger(ctx).error(error);
package/dist/cjs/zalo.cjs CHANGED
@@ -86,7 +86,7 @@ class Zalo {
86
86
  ctx.uid = loginInfo.uid;
87
87
  ctx.settings = serverInfo.setttings || serverInfo.settings;
88
88
  ctx.extraVer = serverInfo.extra_ver;
89
- ctx.loginInfo = loginInfo;
89
+ ctx.serverInfo = serverInfo;
90
90
  if (!context.isContextSession(ctx))
91
91
  throw new ZaloApiError.ZaloApiError('Khởi tạo ngữ cảnh thất bại.');
92
92
  utils.logger(ctx).info('Logged in as', loginInfo.uid);
@@ -116,7 +116,9 @@ class Zalo {
116
116
  }
117
117
  async waitingConfirm(props) {
118
118
  const { ctx, loginVersion, code, imei, getPreviousImei } = props;
119
+ console.log(props);
119
120
  const loginQRResult = await loginQR.handleWaitingConfirm(ctx, loginVersion, code);
121
+ console.log(loginQRResult);
120
122
  if (!loginQRResult || !(ctx === null || ctx === void 0 ? void 0 : ctx.userAgent))
121
123
  return null;
122
124
  return this.loginCookie({
package/dist/context.d.ts CHANGED
@@ -67,7 +67,7 @@ export interface OnlineConfigs {
67
67
  enable_active_deactive_v2: boolean;
68
68
  send_active_to_keep_live: boolean;
69
69
  }
70
- export type LoginInfo = {
70
+ export type ServerInfo = {
71
71
  [key: string]: any;
72
72
  haspcclient: number;
73
73
  public_ip: string;
@@ -116,8 +116,6 @@ export type LoginInfo = {
116
116
  group_e2e: string[];
117
117
  quick_message: string[];
118
118
  };
119
- };
120
- export type ServerInfo = {
121
119
  config_pages: {
122
120
  zalo_page: string;
123
121
  };
@@ -132,7 +130,7 @@ export type ExtraVer = {
132
130
  ver_sticker_cate_list: number;
133
131
  block_friend: string;
134
132
  };
135
- export type ZPWServiceMap = LoginInfo['zpw_service_map_v3'];
133
+ export type ZPWServiceMap = ServerInfo['zpw_service_map_v3'];
136
134
  export type AppContextBase = {
137
135
  uid: string;
138
136
  imei: string;
@@ -155,7 +153,7 @@ export type AppContextBase = {
155
153
  time_deactive: number;
156
154
  };
157
155
  };
158
- loginInfo: LoginInfo;
156
+ serverInfo: ServerInfo;
159
157
  extraVer: ExtraVer;
160
158
  };
161
159
  export type ImageMetadataGetterResponse = {
package/dist/context.js CHANGED
@@ -14,7 +14,7 @@ export const createContext = (apiType = 30, apiVersion = 665) => ({
14
14
  API_TYPE: apiType,
15
15
  API_VERSION: apiVersion,
16
16
  options: {
17
- selfListen: false,
17
+ selfListen: true,
18
18
  checkUpdate: true,
19
19
  logging: true,
20
20
  polyfill: global.fetch,
package/dist/index.d.ts CHANGED
@@ -137,6 +137,7 @@ export type { CustomAPICallback, CustomAPIProps } from './apis/custom.js';
137
137
  export type { Listener } from './apis/listen.js';
138
138
  export type { ForwardMessageOptions, ForwardMessageRecipient } from './apis/forwardMessage.js';
139
139
  export type { ForwardAttachmentOptions } from './apis/forwardAttachment.js';
140
+ export type { IRecommItem } from './apis/getRecommendFriends.js';
140
141
  export { CloseReason } from './models/Listen.js';
141
142
  export { ReviewPendingMemberRequestStatus } from './apis/reviewPendingMemberRequest.js';
142
143
  export { TextStyle, Urgency } from './apis/sendMessage.js';
package/dist/utils.js CHANGED
@@ -5,12 +5,13 @@ import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import pako from 'pako';
7
7
  import SparkMD5 from 'spark-md5';
8
- import { Cookie, CookieJar } from 'tough-cookie';
9
8
  import sharp from 'sharp';
10
9
  import { isContextSession } from './context.js';
11
10
  import { ZaloApiError } from './Errors/index.js';
12
11
  import { FriendEventType } from './models/FriendEvent.js';
13
12
  import { GroupEventType } from './models/GroupEvent.js';
13
+ import { Cookie, CookieJar } from 'tough-cookie';
14
+ import { splitCookiesString } from 'set-cookie-parser';
14
15
  // export const isBun = typeof Bun !== "undefined";
15
16
  export function hasOwn(obj, key) {
16
17
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -261,12 +262,13 @@ export async function request(ctx, url, options, raw = false) {
261
262
  const response = await ctx.options.polyfill(url, _options);
262
263
  const setCookieRaw = response.headers.get('set-cookie');
263
264
  if (setCookieRaw && !raw) {
264
- const splitCookies = setCookieRaw.split(', ');
265
- for (const cookie of splitCookies) {
266
- const parsed = Cookie.parse(cookie);
265
+ const splitCookies = splitCookiesString(setCookieRaw);
266
+ for (const cookieStr of splitCookies) {
267
267
  try {
268
- if (parsed)
269
- await ctx.cookie.setCookie(parsed, parsed.domain != 'zalo.me' ? `https://${parsed.domain}` : origin);
268
+ const parsed = Cookie.parse(cookieStr);
269
+ if (parsed) {
270
+ await ctx.cookie.setCookie(cookieStr, parsed.domain != 'zalo.me' ? `https://${parsed.domain}` : origin);
271
+ }
270
272
  }
271
273
  catch (error) {
272
274
  logger(ctx).error(error);
package/dist/zalo.js CHANGED
@@ -64,7 +64,7 @@ export class Zalo {
64
64
  ctx.uid = loginInfo.uid;
65
65
  ctx.settings = serverInfo.setttings || serverInfo.settings;
66
66
  ctx.extraVer = serverInfo.extra_ver;
67
- ctx.loginInfo = loginInfo;
67
+ ctx.serverInfo = serverInfo;
68
68
  if (!isContextSession(ctx))
69
69
  throw new ZaloApiError('Khởi tạo ngữ cảnh thất bại.');
70
70
  logger(ctx).info('Logged in as', loginInfo.uid);
@@ -94,7 +94,9 @@ export class Zalo {
94
94
  }
95
95
  async waitingConfirm(props) {
96
96
  const { ctx, loginVersion, code, imei, getPreviousImei } = props;
97
+ console.log(props);
97
98
  const loginQRResult = await handleWaitingConfirm(ctx, loginVersion, code);
99
+ console.log(loginQRResult);
98
100
  if (!loginQRResult || !(ctx === null || ctx === void 0 ? void 0 : ctx.userAgent))
99
101
  return null;
100
102
  return this.loginCookie({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zalo-toolkit",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Unofficial Zalo API for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -37,6 +37,7 @@
37
37
  "@types/lodash": "^4.17.20",
38
38
  "@types/node": "^24.10.0",
39
39
  "@types/pako": "^2.0.4",
40
+ "@types/set-cookie-parser": "^2.4.10",
40
41
  "@types/spark-md5": "^3.0.5",
41
42
  "@types/ws": "^8.18.1",
42
43
  "rimraf": "^6.1.2",
@@ -53,6 +54,7 @@
53
54
  "lodash": "^4.17.21",
54
55
  "moment": "^2.30.1",
55
56
  "pako": "^2.1.0",
57
+ "set-cookie-parser": "^2.7.2",
56
58
  "sharp": "^0.34.5",
57
59
  "spark-md5": "^3.0.2",
58
60
  "tough-cookie": "^6.0.0",