@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.
- package/README.md +120 -0
- package/api.ts +9 -0
- package/channel-plugin-api.ts +3 -0
- package/contract-api.ts +2 -0
- package/dist/accounts-DOefD_if.js +66 -0
- package/dist/accounts.runtime-KT101uuu.js +2 -0
- package/dist/api-DSWT4Dh_.js +133 -0
- package/dist/api.js +7 -0
- package/dist/channel-pby_3Sur.js +602 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-0aJ2O7Y8.js +25 -0
- package/dist/channel.setup-CqyWwqcQ.js +9 -0
- package/dist/contract-api.js +3 -0
- package/dist/doctor-contract-B9EvrW0j.js +128 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/index.js +27 -0
- package/dist/monitor-CVtrUqyW.js +708 -0
- package/dist/runtime-api.js +19 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-audit-D_rftvs-.js +34 -0
- package/dist/send-uRjUB8mG.js +542 -0
- package/dist/session-route-CalHiv1d.js +92 -0
- package/dist/setup-entry.js +11 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-Cfj4GQlB.js +360 -0
- package/dist/shared-DjK0e2FC.js +160 -0
- package/dist/test-api.js +5 -0
- package/dist/zalo-js-B80cRyDF.js +1285 -0
- package/doctor-contract-api.ts +1 -0
- package/index.ts +34 -0
- package/klaw.plugin.json +3 -286
- package/package.json +4 -4
- package/runtime-api.ts +62 -0
- package/secret-contract-api.ts +4 -0
- package/setup-entry.ts +9 -0
- package/setup-plugin-api.ts +2 -0
- package/src/accounts.runtime.ts +1 -0
- package/src/accounts.test-mocks.ts +14 -0
- package/src/accounts.test.ts +298 -0
- package/src/accounts.ts +136 -0
- package/src/channel-api.ts +16 -0
- package/src/channel.adapters.ts +432 -0
- package/src/channel.directory.test.ts +59 -0
- package/src/channel.runtime.ts +12 -0
- package/src/channel.sendpayload.test.ts +311 -0
- package/src/channel.setup.test.ts +30 -0
- package/src/channel.setup.ts +12 -0
- package/src/channel.test.ts +424 -0
- package/src/channel.ts +221 -0
- package/src/config-schema.ts +33 -0
- package/src/directory.ts +54 -0
- package/src/doctor-contract.ts +156 -0
- package/src/doctor.test.ts +87 -0
- package/src/doctor.ts +37 -0
- package/src/group-policy.test.ts +61 -0
- package/src/group-policy.ts +83 -0
- package/src/message-sid.test.ts +66 -0
- package/src/message-sid.ts +80 -0
- package/src/monitor.account-scope.test.ts +122 -0
- package/src/monitor.group-gating.test.ts +967 -0
- package/src/monitor.send-mocks.ts +20 -0
- package/src/monitor.ts +1057 -0
- package/src/probe.test.ts +60 -0
- package/src/probe.ts +35 -0
- package/src/qr-temp-file.ts +19 -0
- package/src/reaction.test.ts +19 -0
- package/src/reaction.ts +32 -0
- package/src/runtime.ts +9 -0
- package/src/security-audit.test.ts +83 -0
- package/src/security-audit.ts +71 -0
- package/src/send-receipt.ts +31 -0
- package/src/send.test.ts +424 -0
- package/src/send.ts +280 -0
- package/src/session-route.ts +121 -0
- package/src/setup-core.ts +36 -0
- package/src/setup-surface.test.ts +367 -0
- package/src/setup-surface.ts +481 -0
- package/src/setup-test-helpers.ts +42 -0
- package/src/shared.ts +92 -0
- package/src/status-issues.test.ts +31 -0
- package/src/status-issues.ts +55 -0
- package/src/test-helpers.ts +26 -0
- package/src/text-styles.test.ts +203 -0
- package/src/text-styles.ts +540 -0
- package/src/tool.test.ts +212 -0
- package/src/tool.ts +200 -0
- package/src/types.ts +127 -0
- package/src/zalo-js.credentials.test.ts +465 -0
- package/src/zalo-js.test-mocks.ts +89 -0
- package/src/zalo-js.ts +1889 -0
- package/src/zca-client.test.ts +27 -0
- package/src/zca-client.ts +259 -0
- package/src/zca-constants.ts +55 -0
- package/src/zca-js-exports.d.ts +22 -0
- package/test-api.ts +21 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/contract-api.js +0 -7
- package/doctor-contract-api.js +0 -7
- package/index.js +0 -7
- package/runtime-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/setup-entry.js +0 -7
- package/setup-plugin-api.js +0 -7
- 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
|
+
});
|