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.
- package/dist/apis/loginQR.js +1 -0
- package/dist/apis/uploadProductPhoto.js +1 -1
- package/dist/cjs/apis/loginQR.cjs +1 -0
- package/dist/cjs/apis/uploadProductPhoto.cjs +1 -1
- package/dist/cjs/context.cjs +1 -1
- package/dist/cjs/utils.cjs +8 -6
- package/dist/cjs/zalo.cjs +3 -1
- package/dist/context.d.ts +3 -5
- package/dist/context.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/utils.js +8 -6
- package/dist/zalo.js +3 -1
- package/package.json +3 -1
package/dist/apis/loginQR.js
CHANGED
|
@@ -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.
|
|
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.
|
|
33
|
+
toid: ctx.serverInfo.send2me_id,
|
|
34
34
|
featureId: 1,
|
|
35
35
|
};
|
|
36
36
|
const encryptedParams = utils$1.encodeAES(JSON.stringify(params));
|
package/dist/cjs/context.cjs
CHANGED
package/dist/cjs/utils.cjs
CHANGED
|
@@ -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 =
|
|
268
|
-
for (const
|
|
269
|
-
const parsed = ToughCookie.Cookie.parse(cookie);
|
|
268
|
+
const splitCookies = setCookieParser.splitCookiesString(setCookieRaw);
|
|
269
|
+
for (const cookieStr of splitCookies) {
|
|
270
270
|
try {
|
|
271
|
-
|
|
272
|
-
|
|
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.
|
|
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
|
|
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 =
|
|
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
|
-
|
|
156
|
+
serverInfo: ServerInfo;
|
|
159
157
|
extraVer: ExtraVer;
|
|
160
158
|
};
|
|
161
159
|
export type ImageMetadataGetterResponse = {
|
package/dist/context.js
CHANGED
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
|
|
265
|
-
for (const
|
|
266
|
-
const parsed = Cookie.parse(cookie);
|
|
265
|
+
const splitCookies = splitCookiesString(setCookieRaw);
|
|
266
|
+
for (const cookieStr of splitCookies) {
|
|
267
267
|
try {
|
|
268
|
-
|
|
269
|
-
|
|
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.
|
|
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.
|
|
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",
|