@kodelyth/zalouser 2026.5.39 → 2026.5.42

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 (106) hide show
  1. package/README.md +120 -0
  2. package/api.ts +9 -0
  3. package/channel-plugin-api.ts +3 -0
  4. package/contract-api.ts +2 -0
  5. package/dist/accounts-DOefD_if.js +66 -0
  6. package/dist/accounts.runtime-KT101uuu.js +2 -0
  7. package/dist/api-DSWT4Dh_.js +133 -0
  8. package/dist/api.js +7 -0
  9. package/dist/channel-pby_3Sur.js +602 -0
  10. package/dist/channel-plugin-api.js +2 -0
  11. package/dist/channel.runtime-0aJ2O7Y8.js +25 -0
  12. package/dist/channel.setup-CqyWwqcQ.js +9 -0
  13. package/dist/contract-api.js +3 -0
  14. package/dist/doctor-contract-B9EvrW0j.js +128 -0
  15. package/dist/doctor-contract-api.js +2 -0
  16. package/dist/index.js +27 -0
  17. package/dist/monitor-CVtrUqyW.js +708 -0
  18. package/dist/runtime-api.js +19 -0
  19. package/dist/secret-contract-api.js +5 -0
  20. package/dist/security-audit-D_rftvs-.js +34 -0
  21. package/dist/send-uRjUB8mG.js +542 -0
  22. package/dist/session-route-CalHiv1d.js +92 -0
  23. package/dist/setup-entry.js +11 -0
  24. package/dist/setup-plugin-api.js +2 -0
  25. package/dist/setup-surface-Cfj4GQlB.js +360 -0
  26. package/dist/shared-DjK0e2FC.js +160 -0
  27. package/dist/test-api.js +5 -0
  28. package/dist/zalo-js-B80cRyDF.js +1285 -0
  29. package/doctor-contract-api.ts +1 -0
  30. package/index.ts +34 -0
  31. package/klaw.plugin.json +3 -286
  32. package/package.json +4 -4
  33. package/runtime-api.ts +62 -0
  34. package/secret-contract-api.ts +4 -0
  35. package/setup-entry.ts +9 -0
  36. package/setup-plugin-api.ts +2 -0
  37. package/src/accounts.runtime.ts +1 -0
  38. package/src/accounts.test-mocks.ts +14 -0
  39. package/src/accounts.test.ts +298 -0
  40. package/src/accounts.ts +136 -0
  41. package/src/channel-api.ts +16 -0
  42. package/src/channel.adapters.ts +432 -0
  43. package/src/channel.directory.test.ts +59 -0
  44. package/src/channel.runtime.ts +12 -0
  45. package/src/channel.sendpayload.test.ts +311 -0
  46. package/src/channel.setup.test.ts +30 -0
  47. package/src/channel.setup.ts +12 -0
  48. package/src/channel.test.ts +424 -0
  49. package/src/channel.ts +221 -0
  50. package/src/config-schema.ts +33 -0
  51. package/src/directory.ts +54 -0
  52. package/src/doctor-contract.ts +156 -0
  53. package/src/doctor.test.ts +87 -0
  54. package/src/doctor.ts +37 -0
  55. package/src/group-policy.test.ts +61 -0
  56. package/src/group-policy.ts +83 -0
  57. package/src/message-sid.test.ts +66 -0
  58. package/src/message-sid.ts +80 -0
  59. package/src/monitor.account-scope.test.ts +122 -0
  60. package/src/monitor.group-gating.test.ts +967 -0
  61. package/src/monitor.send-mocks.ts +20 -0
  62. package/src/monitor.ts +1057 -0
  63. package/src/probe.test.ts +60 -0
  64. package/src/probe.ts +35 -0
  65. package/src/qr-temp-file.ts +19 -0
  66. package/src/reaction.test.ts +19 -0
  67. package/src/reaction.ts +32 -0
  68. package/src/runtime.ts +9 -0
  69. package/src/security-audit.test.ts +83 -0
  70. package/src/security-audit.ts +71 -0
  71. package/src/send-receipt.ts +31 -0
  72. package/src/send.test.ts +424 -0
  73. package/src/send.ts +280 -0
  74. package/src/session-route.ts +121 -0
  75. package/src/setup-core.ts +36 -0
  76. package/src/setup-surface.test.ts +367 -0
  77. package/src/setup-surface.ts +481 -0
  78. package/src/setup-test-helpers.ts +42 -0
  79. package/src/shared.ts +92 -0
  80. package/src/status-issues.test.ts +31 -0
  81. package/src/status-issues.ts +55 -0
  82. package/src/test-helpers.ts +26 -0
  83. package/src/text-styles.test.ts +203 -0
  84. package/src/text-styles.ts +540 -0
  85. package/src/tool.test.ts +212 -0
  86. package/src/tool.ts +200 -0
  87. package/src/types.ts +127 -0
  88. package/src/zalo-js.credentials.test.ts +465 -0
  89. package/src/zalo-js.test-mocks.ts +89 -0
  90. package/src/zalo-js.ts +1889 -0
  91. package/src/zca-client.test.ts +27 -0
  92. package/src/zca-client.ts +259 -0
  93. package/src/zca-constants.ts +55 -0
  94. package/src/zca-js-exports.d.ts +22 -0
  95. package/test-api.ts +21 -0
  96. package/tsconfig.json +16 -0
  97. package/api.js +0 -7
  98. package/channel-plugin-api.js +0 -7
  99. package/contract-api.js +0 -7
  100. package/doctor-contract-api.js +0 -7
  101. package/index.js +0 -7
  102. package/runtime-api.js +0 -7
  103. package/secret-contract-api.js +0 -7
  104. package/setup-entry.js +0 -7
  105. package/setup-plugin-api.js +0 -7
  106. package/test-api.js +0 -7
@@ -0,0 +1,122 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+ import type { KlawConfig, PluginRuntime } from "../runtime-api.js";
3
+ import "./monitor.send-mocks.js";
4
+ import { testing } from "./monitor.js";
5
+ import "./zalo-js.test-mocks.js";
6
+ import { sendMessageZalouserMock } from "./monitor.send-mocks.js";
7
+ import { setZalouserRuntime } from "./runtime.js";
8
+ import { createZalouserRuntimeEnv } from "./test-helpers.js";
9
+ import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
10
+
11
+ function requireRecord(value: unknown, label: string): Record<string, unknown> {
12
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
13
+ throw new Error(`expected ${label} to be a record`);
14
+ }
15
+ return value as Record<string, unknown>;
16
+ }
17
+
18
+ describe("zalouser monitor pairing account scoping", () => {
19
+ it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
20
+ const readAllowFromStore = vi.fn(
21
+ async (
22
+ channelOrParams:
23
+ | string
24
+ | {
25
+ channel?: string;
26
+ accountId?: string;
27
+ },
28
+ _env?: NodeJS.ProcessEnv,
29
+ accountId?: string,
30
+ ) => {
31
+ const scopedAccountId =
32
+ typeof channelOrParams === "object" && channelOrParams !== null
33
+ ? channelOrParams.accountId
34
+ : accountId;
35
+ return scopedAccountId === "beta" ? [] : ["attacker"];
36
+ },
37
+ );
38
+ const upsertPairingRequest = vi.fn(
39
+ async (_params: { channel: string; id: string; accountId?: string }) => ({
40
+ code: "PAIRME88",
41
+ created: true,
42
+ }),
43
+ );
44
+
45
+ setZalouserRuntime({
46
+ logging: {
47
+ shouldLogVerbose: () => false,
48
+ },
49
+ channel: {
50
+ pairing: {
51
+ readAllowFromStore,
52
+ upsertPairingRequest,
53
+ buildPairingReply: vi.fn(() => "pairing reply"),
54
+ },
55
+ commands: {
56
+ shouldComputeCommandAuthorized: vi.fn(() => false),
57
+ resolveCommandAuthorizedFromAuthorizers: vi.fn(() => false),
58
+ isControlCommandMessage: vi.fn(() => false),
59
+ },
60
+ },
61
+ } as unknown as PluginRuntime);
62
+
63
+ const account: ResolvedZalouserAccount = {
64
+ accountId: "beta",
65
+ enabled: true,
66
+ profile: "beta",
67
+ authenticated: true,
68
+ config: {
69
+ dmPolicy: "pairing",
70
+ allowFrom: [],
71
+ },
72
+ };
73
+
74
+ const config: KlawConfig = {
75
+ channels: {
76
+ zalouser: {
77
+ accounts: {
78
+ alpha: { dmPolicy: "pairing", allowFrom: [] },
79
+ beta: { dmPolicy: "pairing", allowFrom: [] },
80
+ },
81
+ },
82
+ },
83
+ };
84
+
85
+ const message: ZaloInboundMessage = {
86
+ threadId: "chat-1",
87
+ isGroup: false,
88
+ senderId: "attacker",
89
+ senderName: "Attacker",
90
+ groupName: undefined,
91
+ timestampMs: Date.now(),
92
+ msgId: "msg-1",
93
+ content: "hello",
94
+ raw: { source: "test" },
95
+ };
96
+
97
+ await testing.processMessage({
98
+ message,
99
+ account,
100
+ config,
101
+ runtime: createZalouserRuntimeEnv(),
102
+ });
103
+
104
+ expect(readAllowFromStore).toHaveBeenCalledOnce();
105
+ const allowStoreParams = requireRecord(
106
+ readAllowFromStore.mock.calls[0]?.[0],
107
+ "allow store params",
108
+ );
109
+ expect(allowStoreParams.channel).toBe("zalouser");
110
+ expect(allowStoreParams.accountId).toBe("beta");
111
+
112
+ expect(upsertPairingRequest).toHaveBeenCalledOnce();
113
+ const pairingRequest = requireRecord(
114
+ upsertPairingRequest.mock.calls[0]?.[0],
115
+ "pairing request params",
116
+ );
117
+ expect(pairingRequest.channel).toBe("zalouser");
118
+ expect(pairingRequest.id).toBe("attacker");
119
+ expect(pairingRequest.accountId).toBe("beta");
120
+ expect(sendMessageZalouserMock).toHaveBeenCalled();
121
+ });
122
+ });