@openclaw/zalouser 2026.3.13 → 2026.5.1-beta.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.
Files changed (67) hide show
  1. package/README.md +4 -3
  2. package/api.ts +9 -0
  3. package/channel-plugin-api.ts +3 -0
  4. package/contract-api.ts +2 -0
  5. package/doctor-contract-api.ts +1 -0
  6. package/index.ts +29 -24
  7. package/openclaw.plugin.json +288 -1
  8. package/package.json +38 -11
  9. package/runtime-api.ts +67 -0
  10. package/secret-contract-api.ts +4 -0
  11. package/setup-entry.ts +9 -0
  12. package/setup-plugin-api.ts +2 -0
  13. package/src/accounts.runtime.ts +1 -0
  14. package/src/accounts.test-mocks.ts +7 -3
  15. package/src/accounts.test.ts +53 -1
  16. package/src/accounts.ts +38 -24
  17. package/src/channel-api.ts +20 -0
  18. package/src/channel.adapters.ts +390 -0
  19. package/src/channel.directory.test.ts +47 -40
  20. package/src/channel.runtime.ts +12 -0
  21. package/src/channel.sendpayload.test.ts +41 -23
  22. package/src/channel.setup.test.ts +33 -0
  23. package/src/channel.setup.ts +12 -0
  24. package/src/channel.test.ts +231 -20
  25. package/src/channel.ts +176 -685
  26. package/src/config-schema.ts +5 -5
  27. package/src/directory.ts +54 -0
  28. package/src/doctor-contract.ts +156 -0
  29. package/src/doctor.test.ts +77 -0
  30. package/src/doctor.ts +37 -0
  31. package/src/group-policy.test.ts +4 -4
  32. package/src/group-policy.ts +4 -2
  33. package/src/monitor.account-scope.test.ts +2 -1
  34. package/src/monitor.group-gating.test.ts +162 -8
  35. package/src/monitor.ts +233 -173
  36. package/src/probe.ts +3 -2
  37. package/src/qr-temp-file.ts +1 -1
  38. package/src/reaction.ts +5 -2
  39. package/src/runtime.ts +6 -3
  40. package/src/security-audit.test.ts +80 -0
  41. package/src/security-audit.ts +71 -0
  42. package/src/send.test.ts +2 -2
  43. package/src/send.ts +3 -3
  44. package/src/session-route.ts +121 -0
  45. package/src/setup-core.ts +33 -0
  46. package/src/setup-surface.test.ts +363 -0
  47. package/src/setup-surface.ts +470 -0
  48. package/src/setup-test-helpers.ts +42 -0
  49. package/src/shared.ts +92 -0
  50. package/src/status-issues.test.ts +1 -13
  51. package/src/status-issues.ts +8 -2
  52. package/src/test-helpers.ts +1 -1
  53. package/src/text-styles.test.ts +1 -1
  54. package/src/text-styles.ts +5 -2
  55. package/src/tool.test.ts +66 -3
  56. package/src/tool.ts +76 -14
  57. package/src/types.ts +3 -3
  58. package/src/zalo-js.credentials.test.ts +465 -0
  59. package/src/zalo-js.test-mocks.ts +89 -0
  60. package/src/zalo-js.ts +491 -274
  61. package/src/zca-client.test.ts +24 -0
  62. package/src/zca-client.ts +24 -58
  63. package/src/zca-constants.ts +55 -0
  64. package/test-api.ts +21 -0
  65. package/tsconfig.json +16 -0
  66. package/CHANGELOG.md +0 -107
  67. package/src/onboarding.ts +0 -340
@@ -0,0 +1,465 @@
1
+ import { lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { withEnvAsync } from "openclaw/plugin-sdk/test-env";
5
+ import { beforeEach, describe, expect, it, vi } from "vitest";
6
+ import type { API, Credentials, LoginQRCallbackEvent } from "./zca-client.js";
7
+ import { LoginQRCallbackEventType } from "./zca-constants.js";
8
+
9
+ const createZaloMock = vi.hoisted(() => vi.fn());
10
+ const TEST_MTIME_TICK_MS = 20;
11
+
12
+ vi.mock("./zca-client.js", () => ({
13
+ createZalo: createZaloMock,
14
+ TextStyle: { Indent: 9 },
15
+ }));
16
+
17
+ import {
18
+ checkZaloAuthenticated,
19
+ listZaloFriends,
20
+ sendZaloLink,
21
+ sendZaloReaction,
22
+ startZaloQrLogin,
23
+ waitForZaloQrLogin,
24
+ } from "./zalo-js.js";
25
+
26
+ type StoredCredentialFile = {
27
+ imei: string;
28
+ cookie: Credentials["cookie"];
29
+ userAgent: string;
30
+ language?: string;
31
+ createdAt?: string;
32
+ lastUsedAt?: string;
33
+ };
34
+
35
+ function credentialPath(stateDir: string, profile: string): string {
36
+ const trimmed = profile.trim().toLowerCase();
37
+ const filename =
38
+ !trimmed || trimmed === "default"
39
+ ? "credentials.json"
40
+ : `credentials-${encodeURIComponent(trimmed)}.json`;
41
+ return path.join(stateDir, "credentials", "zalouser", filename);
42
+ }
43
+
44
+ async function readStoredCredentials(
45
+ stateDir: string,
46
+ profile: string,
47
+ ): Promise<StoredCredentialFile> {
48
+ return JSON.parse(
49
+ await readFile(credentialPath(stateDir, profile), "utf8"),
50
+ ) as StoredCredentialFile;
51
+ }
52
+
53
+ async function waitForMtimeTick(): Promise<void> {
54
+ await new Promise((resolve) => setTimeout(resolve, TEST_MTIME_TICK_MS));
55
+ }
56
+
57
+ function createMockApi(params: {
58
+ imei: string;
59
+ userAgent: string;
60
+ language?: string;
61
+ cookies: unknown[] | (() => unknown[]);
62
+ getAllFriends?: API["getAllFriends"];
63
+ }): API {
64
+ return {
65
+ getContext: () => ({
66
+ imei: params.imei,
67
+ userAgent: params.userAgent,
68
+ language: params.language,
69
+ }),
70
+ getCookie: () => ({
71
+ toJSON: () => ({
72
+ cookies: typeof params.cookies === "function" ? params.cookies() : params.cookies,
73
+ }),
74
+ }),
75
+ fetchAccountInfo: async () => ({
76
+ userId: "user-1",
77
+ username: "user-1",
78
+ displayName: "Zalo User",
79
+ zaloName: "Zalo User",
80
+ avatar: "",
81
+ }),
82
+ getAllFriends: params.getAllFriends ?? vi.fn(async () => []),
83
+ listener: {
84
+ on: vi.fn(),
85
+ off: vi.fn(),
86
+ start: vi.fn(),
87
+ stop: vi.fn(),
88
+ },
89
+ } as unknown as API;
90
+ }
91
+
92
+ describe("zalouser credential persistence", () => {
93
+ beforeEach(() => {
94
+ createZaloMock.mockReset();
95
+ });
96
+
97
+ it("persists the final API cookie jar after QR login", async () => {
98
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
99
+ const profile = "qr-refresh";
100
+ const callbackCookie = [{ key: "zpsid", value: "callback", domain: "chat.zalo.me" }];
101
+ const refreshedCookie = [{ key: "zpsid", value: "refreshed", domain: "chat.zalo.me" }];
102
+ const api = createMockApi({
103
+ imei: "api-imei",
104
+ userAgent: "api-user-agent",
105
+ language: "vi",
106
+ cookies: refreshedCookie,
107
+ });
108
+
109
+ createZaloMock.mockResolvedValueOnce({
110
+ loginQR: async (_options: unknown, callback?: (event: LoginQRCallbackEvent) => unknown) => {
111
+ callback?.({
112
+ type: LoginQRCallbackEventType.QRCodeGenerated,
113
+ data: {
114
+ code: "qr-code",
115
+ image: "data:image/png;base64,abc123",
116
+ },
117
+ actions: {
118
+ saveToFile: vi.fn(async () => undefined),
119
+ retry: vi.fn(),
120
+ abort: vi.fn(),
121
+ },
122
+ });
123
+ callback?.({
124
+ type: LoginQRCallbackEventType.GotLoginInfo,
125
+ data: {
126
+ cookie: callbackCookie,
127
+ imei: "callback-imei",
128
+ userAgent: "callback-user-agent",
129
+ },
130
+ actions: null,
131
+ });
132
+ return api;
133
+ },
134
+ });
135
+
136
+ try {
137
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
138
+ await startZaloQrLogin({ profile, timeoutMs: 1000 });
139
+
140
+ await expect(waitForZaloQrLogin({ profile, timeoutMs: 1000 })).resolves.toMatchObject({
141
+ connected: true,
142
+ });
143
+
144
+ const stored = await readStoredCredentials(stateDir, profile);
145
+ expect(stored).toMatchObject({
146
+ imei: "api-imei",
147
+ userAgent: "api-user-agent",
148
+ language: "vi",
149
+ });
150
+ expect(stored.cookie).toEqual(refreshedCookie);
151
+ });
152
+ } finally {
153
+ await rm(stateDir, { recursive: true, force: true });
154
+ }
155
+ });
156
+
157
+ it("rewrites restored sessions with cookies refreshed by zca-js login", async () => {
158
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
159
+ const profile = "restore-refresh";
160
+ const storedCookie = [{ key: "zpsid", value: "stored", domain: "chat.zalo.me" }];
161
+ const refreshedCookie = [{ key: "zpsid", value: "refreshed", domain: "chat.zalo.me" }];
162
+ const filePath = credentialPath(stateDir, profile);
163
+ await mkdir(path.dirname(filePath), { recursive: true });
164
+ await writeFile(
165
+ filePath,
166
+ JSON.stringify(
167
+ {
168
+ imei: "stored-imei",
169
+ cookie: storedCookie,
170
+ userAgent: "stored-user-agent",
171
+ createdAt: "2026-04-01T00:00:00.000Z",
172
+ },
173
+ null,
174
+ 2,
175
+ ),
176
+ );
177
+
178
+ const api = createMockApi({
179
+ imei: "stored-imei",
180
+ userAgent: "stored-user-agent",
181
+ language: "vi",
182
+ cookies: refreshedCookie,
183
+ });
184
+ const login = vi.fn(async () => api);
185
+ createZaloMock.mockResolvedValueOnce({ login });
186
+
187
+ try {
188
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
189
+ await expect(checkZaloAuthenticated(profile)).resolves.toBe(true);
190
+
191
+ expect(login).toHaveBeenCalledWith({
192
+ imei: "stored-imei",
193
+ cookie: storedCookie,
194
+ userAgent: "stored-user-agent",
195
+ language: undefined,
196
+ });
197
+ const stored = await readStoredCredentials(stateDir, profile);
198
+ expect(stored.cookie).toEqual(refreshedCookie);
199
+ expect(stored.createdAt).toBe("2026-04-01T00:00:00.000Z");
200
+ expect(stored.lastUsedAt).toEqual(expect.any(String));
201
+ });
202
+ } finally {
203
+ await rm(stateDir, { recursive: true, force: true });
204
+ }
205
+ });
206
+
207
+ it("persists cookie changes after a successful API call", async () => {
208
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
209
+ const profile = "api-refresh";
210
+ const storedCookie: unknown[] = [{ key: "zpsid", value: "stored", domain: "chat.zalo.me" }];
211
+ const loginCookie: unknown[] = [{ key: "zpsid", value: "login", domain: "chat.zalo.me" }];
212
+ const refreshedCookie: unknown[] = [
213
+ { key: "zpsid", value: "api-refreshed", domain: "chat.zalo.me" },
214
+ ];
215
+ const filePath = credentialPath(stateDir, profile);
216
+ await mkdir(path.dirname(filePath), { recursive: true });
217
+ await writeFile(
218
+ filePath,
219
+ JSON.stringify(
220
+ {
221
+ imei: "stored-imei",
222
+ cookie: storedCookie,
223
+ userAgent: "stored-user-agent",
224
+ createdAt: "2026-04-01T00:00:00.000Z",
225
+ },
226
+ null,
227
+ 2,
228
+ ),
229
+ );
230
+
231
+ let currentCookie = loginCookie;
232
+ const api = createMockApi({
233
+ imei: "stored-imei",
234
+ userAgent: "stored-user-agent",
235
+ language: "vi",
236
+ cookies: () => currentCookie,
237
+ getAllFriends: vi.fn(async () => {
238
+ currentCookie = refreshedCookie;
239
+ return [
240
+ {
241
+ userId: "friend-1",
242
+ username: "friend-1",
243
+ displayName: "Friend One",
244
+ zaloName: "Friend One",
245
+ avatar: "",
246
+ },
247
+ ];
248
+ }),
249
+ });
250
+ createZaloMock.mockResolvedValueOnce({ login: vi.fn(async () => api) });
251
+
252
+ try {
253
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
254
+ await expect(listZaloFriends(profile)).resolves.toEqual([
255
+ {
256
+ userId: "friend-1",
257
+ displayName: "Friend One",
258
+ avatar: undefined,
259
+ },
260
+ ]);
261
+
262
+ const stored = await readStoredCredentials(stateDir, profile);
263
+ expect(stored.cookie).toEqual(refreshedCookie);
264
+ expect(stored.createdAt).toBe("2026-04-01T00:00:00.000Z");
265
+ expect(stored.lastUsedAt).toEqual(expect.any(String));
266
+ });
267
+ } finally {
268
+ await rm(stateDir, { recursive: true, force: true });
269
+ }
270
+ });
271
+
272
+ it("does not rewrite credentials when the live cookie jar only reorders cookies", async () => {
273
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
274
+ const profile = "api-stable";
275
+ const cookieA: unknown[] = [
276
+ { key: "zpsid", value: "same", domain: "chat.zalo.me" },
277
+ { key: "zpw", value: "same-secondary", domain: "chat.zalo.me" },
278
+ ];
279
+ const cookieB = [...cookieA].toReversed();
280
+ const filePath = credentialPath(stateDir, profile);
281
+ await mkdir(path.dirname(filePath), { recursive: true });
282
+ await writeFile(
283
+ filePath,
284
+ JSON.stringify(
285
+ {
286
+ imei: "stored-imei",
287
+ cookie: cookieA,
288
+ userAgent: "stored-user-agent",
289
+ createdAt: "2026-04-01T00:00:00.000Z",
290
+ },
291
+ null,
292
+ 2,
293
+ ),
294
+ );
295
+
296
+ let currentCookie = cookieA;
297
+ const api = createMockApi({
298
+ imei: "stored-imei",
299
+ userAgent: "stored-user-agent",
300
+ language: "vi",
301
+ cookies: () => currentCookie,
302
+ getAllFriends: vi.fn(async () => []),
303
+ });
304
+ createZaloMock.mockResolvedValueOnce({ login: vi.fn(async () => api) });
305
+
306
+ try {
307
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
308
+ await expect(listZaloFriends(profile)).resolves.toEqual([]);
309
+ const firstRaw = await readFile(filePath, "utf8");
310
+ const firstMtimeMs = (await stat(filePath)).mtimeMs;
311
+
312
+ currentCookie = cookieB;
313
+ await waitForMtimeTick();
314
+
315
+ await expect(listZaloFriends(profile)).resolves.toEqual([]);
316
+ expect(await readFile(filePath, "utf8")).toBe(firstRaw);
317
+ expect((await stat(filePath)).mtimeMs).toBe(firstMtimeMs);
318
+ });
319
+ } finally {
320
+ await rm(stateDir, { recursive: true, force: true });
321
+ }
322
+ });
323
+
324
+ it("keeps reaction sends non-throwing when session restore fails", async () => {
325
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
326
+
327
+ try {
328
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
329
+ await expect(
330
+ sendZaloReaction({
331
+ profile: "missing-session",
332
+ threadId: "thread-1",
333
+ msgId: "msg-1",
334
+ cliMsgId: "cli-1",
335
+ emoji: "like",
336
+ }),
337
+ ).resolves.toMatchObject({
338
+ ok: false,
339
+ error: expect.stringContaining("No saved Zalo session"),
340
+ });
341
+ });
342
+ } finally {
343
+ await rm(stateDir, { recursive: true, force: true });
344
+ }
345
+ });
346
+
347
+ it("keeps link sends non-throwing when session restore fails", async () => {
348
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
349
+
350
+ try {
351
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
352
+ await expect(
353
+ sendZaloLink("thread-1", "https://example.com", {
354
+ profile: "missing-session",
355
+ }),
356
+ ).resolves.toMatchObject({
357
+ ok: false,
358
+ error: expect.stringContaining("No saved Zalo session"),
359
+ });
360
+ });
361
+ } finally {
362
+ await rm(stateDir, { recursive: true, force: true });
363
+ }
364
+ });
365
+
366
+ it.skipIf(process.platform === "win32")(
367
+ "writes credentials with private permissions",
368
+ async () => {
369
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
370
+ const profile = "private-mode";
371
+ const api = createMockApi({
372
+ imei: "api-imei",
373
+ userAgent: "api-user-agent",
374
+ cookies: [{ key: "zpsid", value: "private", domain: "chat.zalo.me" }],
375
+ });
376
+
377
+ createZaloMock.mockResolvedValueOnce({
378
+ loginQR: async (_options: unknown, callback?: (event: LoginQRCallbackEvent) => unknown) => {
379
+ callback?.({
380
+ type: LoginQRCallbackEventType.QRCodeGenerated,
381
+ data: {
382
+ code: "qr-code",
383
+ image: "data:image/png;base64,abc123",
384
+ },
385
+ actions: {
386
+ saveToFile: vi.fn(async () => undefined),
387
+ retry: vi.fn(),
388
+ abort: vi.fn(),
389
+ },
390
+ });
391
+ return api;
392
+ },
393
+ });
394
+
395
+ try {
396
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
397
+ await startZaloQrLogin({ profile, timeoutMs: 1000 });
398
+ await expect(waitForZaloQrLogin({ profile, timeoutMs: 1000 })).resolves.toMatchObject({
399
+ connected: true,
400
+ });
401
+
402
+ const filePath = credentialPath(stateDir, profile);
403
+ const dirMode = (await stat(path.dirname(filePath))).mode & 0o777;
404
+ const fileMode = (await stat(filePath)).mode & 0o777;
405
+ expect(dirMode).toBe(0o700);
406
+ expect(fileMode).toBe(0o600);
407
+ });
408
+ } finally {
409
+ await rm(stateDir, { recursive: true, force: true });
410
+ }
411
+ },
412
+ );
413
+
414
+ it.skipIf(process.platform === "win32")(
415
+ "refuses to write credentials through a symlinked file",
416
+ async () => {
417
+ const stateDir = await mkdtemp(path.join(os.tmpdir(), "openclaw-zalouser-credentials-"));
418
+ const profile = "symlink-target";
419
+ const filePath = credentialPath(stateDir, profile);
420
+ const targetPath = path.join(stateDir, "outside.json");
421
+ const api = createMockApi({
422
+ imei: "api-imei",
423
+ userAgent: "api-user-agent",
424
+ cookies: [{ key: "zpsid", value: "symlink", domain: "chat.zalo.me" }],
425
+ });
426
+
427
+ await mkdir(path.dirname(filePath), { recursive: true });
428
+ await writeFile(targetPath, "sentinel", "utf8");
429
+ await symlink(targetPath, filePath);
430
+
431
+ createZaloMock.mockResolvedValueOnce({
432
+ loginQR: async (_options: unknown, callback?: (event: LoginQRCallbackEvent) => unknown) => {
433
+ callback?.({
434
+ type: LoginQRCallbackEventType.QRCodeGenerated,
435
+ data: {
436
+ code: "qr-code",
437
+ image: "data:image/png;base64,abc123",
438
+ },
439
+ actions: {
440
+ saveToFile: vi.fn(async () => undefined),
441
+ retry: vi.fn(),
442
+ abort: vi.fn(),
443
+ },
444
+ });
445
+ return api;
446
+ },
447
+ });
448
+
449
+ try {
450
+ await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
451
+ const started = await startZaloQrLogin({ profile, timeoutMs: 1000 });
452
+ const waited = await waitForZaloQrLogin({ profile, timeoutMs: 1000 });
453
+ expect(`${started.message} ${waited.message}`).toContain(
454
+ "Refusing to write Zalo credentials to symlinked path",
455
+ );
456
+ });
457
+
458
+ expect(await readFile(targetPath, "utf8")).toBe("sentinel");
459
+ expect((await lstat(filePath)).isSymbolicLink()).toBe(true);
460
+ } finally {
461
+ await rm(stateDir, { recursive: true, force: true });
462
+ }
463
+ },
464
+ );
465
+ });
@@ -0,0 +1,89 @@
1
+ import { vi, type Mock } from "vitest";
2
+
3
+ type ZaloJsModule = typeof import("./zalo-js.js");
4
+ type ZaloJsMocks = {
5
+ checkZaloAuthenticatedMock: Mock<ZaloJsModule["checkZaloAuthenticated"]>;
6
+ getZaloUserInfoMock: Mock<ZaloJsModule["getZaloUserInfo"]>;
7
+ listZaloFriendsMock: Mock<ZaloJsModule["listZaloFriends"]>;
8
+ listZaloFriendsMatchingMock: Mock<ZaloJsModule["listZaloFriendsMatching"]>;
9
+ listZaloGroupMembersMock: Mock<ZaloJsModule["listZaloGroupMembers"]>;
10
+ listZaloGroupsMock: Mock<ZaloJsModule["listZaloGroups"]>;
11
+ listZaloGroupsMatchingMock: Mock<ZaloJsModule["listZaloGroupsMatching"]>;
12
+ logoutZaloProfileMock: Mock<ZaloJsModule["logoutZaloProfile"]>;
13
+ resolveZaloAllowFromEntriesMock: Mock<ZaloJsModule["resolveZaloAllowFromEntries"]>;
14
+ resolveZaloGroupContextMock: Mock<ZaloJsModule["resolveZaloGroupContext"]>;
15
+ resolveZaloGroupsByEntriesMock: Mock<ZaloJsModule["resolveZaloGroupsByEntries"]>;
16
+ startZaloListenerMock: Mock<ZaloJsModule["startZaloListener"]>;
17
+ startZaloQrLoginMock: Mock<ZaloJsModule["startZaloQrLogin"]>;
18
+ waitForZaloQrLoginMock: Mock<ZaloJsModule["waitForZaloQrLogin"]>;
19
+ };
20
+
21
+ const zaloJsMocks = vi.hoisted(
22
+ (): ZaloJsMocks => ({
23
+ checkZaloAuthenticatedMock: vi.fn(async () => false),
24
+ getZaloUserInfoMock: vi.fn(async () => null),
25
+ listZaloFriendsMock: vi.fn(async () => []),
26
+ listZaloFriendsMatchingMock: vi.fn(async () => []),
27
+ listZaloGroupMembersMock: vi.fn(async () => []),
28
+ listZaloGroupsMock: vi.fn(async () => []),
29
+ listZaloGroupsMatchingMock: vi.fn(async () => []),
30
+ logoutZaloProfileMock: vi.fn(async () => ({
31
+ cleared: true,
32
+ loggedOut: true,
33
+ message: "Logged out and cleared local session.",
34
+ })),
35
+ resolveZaloAllowFromEntriesMock: vi.fn(async ({ entries }: { entries: string[] }) =>
36
+ entries.map((entry) => ({ input: entry, resolved: true, id: entry, note: undefined })),
37
+ ),
38
+ resolveZaloGroupContextMock: vi.fn(async (_profile, groupId) => ({
39
+ groupId,
40
+ name: undefined,
41
+ members: [],
42
+ })),
43
+ resolveZaloGroupsByEntriesMock: vi.fn(async ({ entries }: { entries: string[] }) =>
44
+ entries.map((entry) => ({ input: entry, resolved: true, id: entry, note: undefined })),
45
+ ),
46
+ startZaloListenerMock: vi.fn(async () => ({ stop: vi.fn() })),
47
+ startZaloQrLoginMock: vi.fn(async () => ({
48
+ message: "qr pending",
49
+ qrDataUrl: undefined,
50
+ })),
51
+ waitForZaloQrLoginMock: vi.fn(async () => ({
52
+ connected: false,
53
+ message: "login pending",
54
+ })),
55
+ }),
56
+ );
57
+
58
+ export const checkZaloAuthenticatedMock = zaloJsMocks.checkZaloAuthenticatedMock;
59
+ export const getZaloUserInfoMock = zaloJsMocks.getZaloUserInfoMock;
60
+ export const listZaloFriendsMock = zaloJsMocks.listZaloFriendsMock;
61
+ export const listZaloFriendsMatchingMock = zaloJsMocks.listZaloFriendsMatchingMock;
62
+ export const listZaloGroupMembersMock = zaloJsMocks.listZaloGroupMembersMock;
63
+ export const listZaloGroupsMock = zaloJsMocks.listZaloGroupsMock;
64
+ export const listZaloGroupsMatchingMock = zaloJsMocks.listZaloGroupsMatchingMock;
65
+ export const logoutZaloProfileMock = zaloJsMocks.logoutZaloProfileMock;
66
+ export const resolveZaloAllowFromEntriesMock = zaloJsMocks.resolveZaloAllowFromEntriesMock;
67
+ export const resolveZaloGroupContextMock = zaloJsMocks.resolveZaloGroupContextMock;
68
+ export const resolveZaloGroupsByEntriesMock = zaloJsMocks.resolveZaloGroupsByEntriesMock;
69
+ export const startZaloListenerMock: Mock<ZaloJsModule["startZaloListener"]> =
70
+ zaloJsMocks.startZaloListenerMock;
71
+ export const startZaloQrLoginMock = zaloJsMocks.startZaloQrLoginMock;
72
+ export const waitForZaloQrLoginMock = zaloJsMocks.waitForZaloQrLoginMock;
73
+
74
+ vi.mock("./zalo-js.js", () => ({
75
+ checkZaloAuthenticated: checkZaloAuthenticatedMock,
76
+ getZaloUserInfo: getZaloUserInfoMock,
77
+ listZaloFriends: listZaloFriendsMock,
78
+ listZaloFriendsMatching: listZaloFriendsMatchingMock,
79
+ listZaloGroupMembers: listZaloGroupMembersMock,
80
+ listZaloGroups: listZaloGroupsMock,
81
+ listZaloGroupsMatching: listZaloGroupsMatchingMock,
82
+ logoutZaloProfile: logoutZaloProfileMock,
83
+ resolveZaloAllowFromEntries: resolveZaloAllowFromEntriesMock,
84
+ resolveZaloGroupContext: resolveZaloGroupContextMock,
85
+ resolveZaloGroupsByEntries: resolveZaloGroupsByEntriesMock,
86
+ startZaloListener: startZaloListenerMock,
87
+ startZaloQrLogin: startZaloQrLoginMock,
88
+ waitForZaloQrLogin: waitForZaloQrLoginMock,
89
+ }));