@openclaw/zalouser 2026.5.2 → 2026.5.3-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 (95) hide show
  1. package/dist/accounts-C00IMUgd.js +63 -0
  2. package/dist/accounts.runtime-uG7S8cXT.js +2 -0
  3. package/dist/api-BRwdUWuS.js +139 -0
  4. package/dist/api.js +7 -0
  5. package/dist/channel-ou_w_2j-.js +484 -0
  6. package/dist/channel-plugin-api.js +2 -0
  7. package/dist/channel.runtime-C9WxiAiR.js +25 -0
  8. package/dist/channel.setup-CiDeBFrn.js +10 -0
  9. package/dist/contract-api.js +3 -0
  10. package/dist/doctor-contract-DgqHp8E2.js +128 -0
  11. package/dist/doctor-contract-api.js +2 -0
  12. package/dist/index.js +27 -0
  13. package/dist/monitor-Cg7K_s_s.js +705 -0
  14. package/dist/runtime-QNU7vLgI.js +106 -0
  15. package/dist/runtime-api.js +22 -0
  16. package/dist/secret-contract-api.js +5 -0
  17. package/dist/security-audit-BZLhil-V.js +34 -0
  18. package/dist/send-BsmySxe3.js +534 -0
  19. package/dist/session-route-C0-Xr8bt.js +92 -0
  20. package/dist/setup-core-CqipqY98.js +40 -0
  21. package/dist/setup-entry.js +11 -0
  22. package/dist/setup-plugin-api.js +2 -0
  23. package/dist/setup-surface-NCOuKu-l.js +359 -0
  24. package/dist/shared-DSy8aIUx.js +120 -0
  25. package/dist/test-api.js +5 -0
  26. package/dist/zalo-js-CHCUlY3c.js +1279 -0
  27. package/package.json +15 -6
  28. package/api.ts +0 -9
  29. package/channel-plugin-api.ts +0 -3
  30. package/contract-api.ts +0 -2
  31. package/doctor-contract-api.ts +0 -1
  32. package/index.ts +0 -34
  33. package/runtime-api.ts +0 -67
  34. package/secret-contract-api.ts +0 -4
  35. package/setup-entry.ts +0 -9
  36. package/setup-plugin-api.ts +0 -2
  37. package/src/accounts.runtime.ts +0 -1
  38. package/src/accounts.test-mocks.ts +0 -14
  39. package/src/accounts.test.ts +0 -266
  40. package/src/accounts.ts +0 -131
  41. package/src/channel-api.ts +0 -20
  42. package/src/channel.adapters.ts +0 -391
  43. package/src/channel.directory.test.ts +0 -59
  44. package/src/channel.runtime.ts +0 -12
  45. package/src/channel.sendpayload.test.ts +0 -172
  46. package/src/channel.setup.test.ts +0 -33
  47. package/src/channel.setup.ts +0 -12
  48. package/src/channel.test.ts +0 -377
  49. package/src/channel.ts +0 -219
  50. package/src/config-schema.ts +0 -33
  51. package/src/directory.ts +0 -54
  52. package/src/doctor-contract.ts +0 -156
  53. package/src/doctor.test.ts +0 -77
  54. package/src/doctor.ts +0 -37
  55. package/src/group-policy.test.ts +0 -61
  56. package/src/group-policy.ts +0 -83
  57. package/src/message-sid.test.ts +0 -66
  58. package/src/message-sid.ts +0 -80
  59. package/src/monitor.account-scope.test.ts +0 -107
  60. package/src/monitor.group-gating.test.ts +0 -816
  61. package/src/monitor.send-mocks.ts +0 -20
  62. package/src/monitor.ts +0 -1044
  63. package/src/probe.test.ts +0 -60
  64. package/src/probe.ts +0 -35
  65. package/src/qr-temp-file.ts +0 -22
  66. package/src/reaction.test.ts +0 -19
  67. package/src/reaction.ts +0 -32
  68. package/src/runtime.ts +0 -9
  69. package/src/security-audit.test.ts +0 -80
  70. package/src/security-audit.ts +0 -71
  71. package/src/send.test.ts +0 -395
  72. package/src/send.ts +0 -272
  73. package/src/session-route.ts +0 -121
  74. package/src/setup-core.ts +0 -33
  75. package/src/setup-surface.test.ts +0 -363
  76. package/src/setup-surface.ts +0 -470
  77. package/src/setup-test-helpers.ts +0 -42
  78. package/src/shared.ts +0 -92
  79. package/src/status-issues.test.ts +0 -31
  80. package/src/status-issues.ts +0 -58
  81. package/src/test-helpers.ts +0 -26
  82. package/src/text-styles.test.ts +0 -203
  83. package/src/text-styles.ts +0 -540
  84. package/src/tool.test.ts +0 -212
  85. package/src/tool.ts +0 -210
  86. package/src/types.ts +0 -125
  87. package/src/zalo-js.credentials.test.ts +0 -465
  88. package/src/zalo-js.test-mocks.ts +0 -89
  89. package/src/zalo-js.ts +0 -1911
  90. package/src/zca-client.test.ts +0 -24
  91. package/src/zca-client.ts +0 -259
  92. package/src/zca-constants.ts +0 -55
  93. package/src/zca-js-exports.d.ts +0 -22
  94. package/test-api.ts +0 -21
  95. package/tsconfig.json +0 -16
@@ -1,156 +0,0 @@
1
- import type {
2
- ChannelDoctorConfigMutation,
3
- ChannelDoctorLegacyConfigRule,
4
- } from "openclaw/plugin-sdk/channel-contract";
5
- import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
6
-
7
- type ZalouserChannelsConfig = NonNullable<OpenClawConfig["channels"]>;
8
-
9
- function asObjectRecord(value: unknown): Record<string, unknown> | null {
10
- return value && typeof value === "object" && !Array.isArray(value)
11
- ? (value as Record<string, unknown>)
12
- : null;
13
- }
14
-
15
- function hasLegacyZalouserGroupAllowAlias(value: unknown): boolean {
16
- const group = asObjectRecord(value);
17
- return Boolean(group && typeof group.allow === "boolean");
18
- }
19
-
20
- function hasLegacyZalouserGroupAllowAliases(value: unknown): boolean {
21
- const groups = asObjectRecord(value);
22
- return Boolean(
23
- groups && Object.values(groups).some((group) => hasLegacyZalouserGroupAllowAlias(group)),
24
- );
25
- }
26
-
27
- function hasLegacyZalouserAccountGroupAllowAliases(value: unknown): boolean {
28
- const accounts = asObjectRecord(value);
29
- if (!accounts) {
30
- return false;
31
- }
32
- return Object.values(accounts).some((account) => {
33
- const accountRecord = asObjectRecord(account);
34
- return Boolean(accountRecord && hasLegacyZalouserGroupAllowAliases(accountRecord.groups));
35
- });
36
- }
37
-
38
- function normalizeZalouserGroupAllowAliases(params: {
39
- groups: Record<string, unknown>;
40
- pathPrefix: string;
41
- changes: string[];
42
- }): { groups: Record<string, unknown>; changed: boolean } {
43
- let changed = false;
44
- const nextGroups: Record<string, unknown> = { ...params.groups };
45
- for (const [groupId, groupValue] of Object.entries(params.groups)) {
46
- const group = asObjectRecord(groupValue);
47
- if (!group || typeof group.allow !== "boolean") {
48
- continue;
49
- }
50
- const nextGroup = { ...group };
51
- if (typeof nextGroup.enabled !== "boolean") {
52
- nextGroup.enabled = group.allow;
53
- }
54
- delete nextGroup.allow;
55
- nextGroups[groupId] = nextGroup;
56
- changed = true;
57
- params.changes.push(
58
- `Moved ${params.pathPrefix}.${groupId}.allow → ${params.pathPrefix}.${groupId}.enabled (${String(nextGroup.enabled)}).`,
59
- );
60
- }
61
- return { groups: nextGroups, changed };
62
- }
63
-
64
- function normalizeZalouserCompatibilityConfig(cfg: OpenClawConfig): ChannelDoctorConfigMutation {
65
- const channels = asObjectRecord(cfg.channels);
66
- const zalouser = asObjectRecord(channels?.zalouser);
67
- if (!zalouser) {
68
- return { config: cfg, changes: [] };
69
- }
70
-
71
- const changes: string[] = [];
72
- let updatedZalouser: Record<string, unknown> = zalouser;
73
- let changed = false;
74
-
75
- const groups = asObjectRecord(updatedZalouser.groups);
76
- if (groups) {
77
- const normalized = normalizeZalouserGroupAllowAliases({
78
- groups,
79
- pathPrefix: "channels.zalouser.groups",
80
- changes,
81
- });
82
- if (normalized.changed) {
83
- updatedZalouser = { ...updatedZalouser, groups: normalized.groups };
84
- changed = true;
85
- }
86
- }
87
-
88
- const accounts = asObjectRecord(updatedZalouser.accounts);
89
- if (accounts) {
90
- let accountsChanged = false;
91
- const nextAccounts: Record<string, unknown> = { ...accounts };
92
- for (const [accountId, accountValue] of Object.entries(accounts)) {
93
- const account = asObjectRecord(accountValue);
94
- if (!account) {
95
- continue;
96
- }
97
- const accountGroups = asObjectRecord(account.groups);
98
- if (!accountGroups) {
99
- continue;
100
- }
101
- const normalized = normalizeZalouserGroupAllowAliases({
102
- groups: accountGroups,
103
- pathPrefix: `channels.zalouser.accounts.${accountId}.groups`,
104
- changes,
105
- });
106
- if (!normalized.changed) {
107
- continue;
108
- }
109
- nextAccounts[accountId] = {
110
- ...account,
111
- groups: normalized.groups,
112
- };
113
- accountsChanged = true;
114
- }
115
- if (accountsChanged) {
116
- updatedZalouser = { ...updatedZalouser, accounts: nextAccounts };
117
- changed = true;
118
- }
119
- }
120
-
121
- if (!changed) {
122
- return { config: cfg, changes: [] };
123
- }
124
-
125
- return {
126
- config: {
127
- ...cfg,
128
- channels: {
129
- ...cfg.channels,
130
- zalouser: updatedZalouser as ZalouserChannelsConfig["zalouser"],
131
- },
132
- },
133
- changes,
134
- };
135
- }
136
-
137
- export const legacyConfigRules: ChannelDoctorLegacyConfigRule[] = [
138
- {
139
- path: ["channels", "zalouser", "groups"],
140
- message:
141
- 'channels.zalouser.groups.<id>.allow is legacy; use channels.zalouser.groups.<id>.enabled instead. Run "openclaw doctor --fix".',
142
- match: hasLegacyZalouserGroupAllowAliases,
143
- },
144
- {
145
- path: ["channels", "zalouser", "accounts"],
146
- message:
147
- 'channels.zalouser.accounts.<id>.groups.<id>.allow is legacy; use channels.zalouser.accounts.<id>.groups.<id>.enabled instead. Run "openclaw doctor --fix".',
148
- match: hasLegacyZalouserAccountGroupAllowAliases,
149
- },
150
- ];
151
-
152
- export function normalizeCompatibilityConfig(params: {
153
- cfg: OpenClawConfig;
154
- }): ChannelDoctorConfigMutation {
155
- return normalizeZalouserCompatibilityConfig(params.cfg);
156
- }
@@ -1,77 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { zalouserDoctor } from "./doctor.js";
3
-
4
- describe("zalouser doctor", () => {
5
- it("warns when mutable group names rely on disabled name matching", () => {
6
- expect(
7
- zalouserDoctor.collectMutableAllowlistWarnings?.({
8
- cfg: {
9
- channels: {
10
- zalouser: {
11
- groups: {
12
- "group:trusted": {
13
- enabled: true,
14
- },
15
- },
16
- },
17
- },
18
- } as never,
19
- }),
20
- ).toEqual(
21
- expect.arrayContaining([
22
- expect.stringContaining("mutable allowlist entry across zalouser"),
23
- expect.stringContaining("channels.zalouser.groups: group:trusted"),
24
- ]),
25
- );
26
- });
27
-
28
- it("normalizes legacy group allow aliases to enabled", () => {
29
- const normalize = zalouserDoctor.normalizeCompatibilityConfig;
30
- expect(normalize).toBeDefined();
31
- if (!normalize) {
32
- return;
33
- }
34
-
35
- const result = normalize({
36
- cfg: {
37
- channels: {
38
- zalouser: {
39
- groups: {
40
- "group:trusted": {
41
- allow: true,
42
- },
43
- },
44
- accounts: {
45
- work: {
46
- groups: {
47
- "group:legacy": {
48
- allow: false,
49
- },
50
- },
51
- },
52
- },
53
- },
54
- },
55
- } as never,
56
- });
57
-
58
- expect(result.config.channels?.zalouser?.groups?.["group:trusted"]).toEqual({
59
- enabled: true,
60
- });
61
- expect(
62
- (
63
- result.config.channels?.zalouser?.accounts?.work as
64
- | { groups?: Record<string, unknown> }
65
- | undefined
66
- )?.groups?.["group:legacy"],
67
- ).toEqual({
68
- enabled: false,
69
- });
70
- expect(result.changes).toEqual(
71
- expect.arrayContaining([
72
- "Moved channels.zalouser.groups.group:trusted.allow → channels.zalouser.groups.group:trusted.enabled (true).",
73
- "Moved channels.zalouser.accounts.work.groups.group:legacy.allow → channels.zalouser.accounts.work.groups.group:legacy.enabled (false).",
74
- ]),
75
- );
76
- });
77
- });
package/src/doctor.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { ChannelDoctorAdapter } from "openclaw/plugin-sdk/channel-contract";
2
- import { createDangerousNameMatchingMutableAllowlistWarningCollector } from "openclaw/plugin-sdk/channel-policy";
3
- import { legacyConfigRules, normalizeCompatibilityConfig } from "./doctor-contract.js";
4
- import { isZalouserMutableGroupEntry } from "./security-audit.js";
5
-
6
- function asObjectRecord(value: unknown): Record<string, unknown> | null {
7
- return value && typeof value === "object" && !Array.isArray(value)
8
- ? (value as Record<string, unknown>)
9
- : null;
10
- }
11
-
12
- const collectZalouserMutableAllowlistWarnings =
13
- createDangerousNameMatchingMutableAllowlistWarningCollector({
14
- channel: "zalouser",
15
- detector: isZalouserMutableGroupEntry,
16
- collectLists: (scope) => {
17
- const groups = asObjectRecord(scope.account.groups);
18
- return groups
19
- ? [
20
- {
21
- pathLabel: `${scope.prefix}.groups`,
22
- list: Object.keys(groups),
23
- },
24
- ]
25
- : [];
26
- },
27
- });
28
-
29
- export const zalouserDoctor: ChannelDoctorAdapter = {
30
- dmAllowFromMode: "topOnly",
31
- groupModel: "hybrid",
32
- groupAllowFromFallbackToAllowFrom: false,
33
- warnOnEmptyGroupSenderAllowlist: false,
34
- legacyConfigRules,
35
- normalizeCompatibilityConfig,
36
- collectMutableAllowlistWarnings: collectZalouserMutableAllowlistWarnings,
37
- };
@@ -1,61 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- buildZalouserGroupCandidates,
4
- findZalouserGroupEntry,
5
- isZalouserGroupEntryAllowed,
6
- normalizeZalouserGroupSlug,
7
- } from "./group-policy.js";
8
-
9
- describe("zalouser group policy helpers", () => {
10
- it("normalizes group slug names", () => {
11
- expect(normalizeZalouserGroupSlug(" Team Alpha ")).toBe("team-alpha");
12
- expect(normalizeZalouserGroupSlug("#Roadmap Updates")).toBe("roadmap-updates");
13
- });
14
-
15
- it("builds ordered candidates with optional aliases", () => {
16
- expect(
17
- buildZalouserGroupCandidates({
18
- groupId: "123",
19
- groupChannel: "chan-1",
20
- groupName: "Team Alpha",
21
- includeGroupIdAlias: true,
22
- }),
23
- ).toEqual(["123", "group:123", "chan-1", "Team Alpha", "team-alpha", "*"]);
24
- });
25
-
26
- it("builds id-only candidates when name matching is disabled", () => {
27
- expect(
28
- buildZalouserGroupCandidates({
29
- groupId: "123",
30
- groupChannel: "chan-1",
31
- groupName: "Team Alpha",
32
- includeGroupIdAlias: true,
33
- allowNameMatching: false,
34
- }),
35
- ).toEqual(["123", "group:123", "*"]);
36
- });
37
-
38
- it("finds the first matching group entry", () => {
39
- const groups = {
40
- "group:123": { enabled: true },
41
- "team-alpha": { requireMention: false },
42
- "*": { requireMention: true },
43
- };
44
- const entry = findZalouserGroupEntry(
45
- groups,
46
- buildZalouserGroupCandidates({
47
- groupId: "123",
48
- groupName: "Team Alpha",
49
- includeGroupIdAlias: true,
50
- }),
51
- );
52
- expect(entry).toEqual({ enabled: true });
53
- });
54
-
55
- it("evaluates allow/enable flags", () => {
56
- expect(isZalouserGroupEntryAllowed({ enabled: true })).toBe(true);
57
- expect(isZalouserGroupEntryAllowed({ allow: false } as never)).toBe(false);
58
- expect(isZalouserGroupEntryAllowed({ enabled: false })).toBe(false);
59
- expect(isZalouserGroupEntryAllowed(undefined)).toBe(false);
60
- });
61
- });
@@ -1,83 +0,0 @@
1
- import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
2
- import type { ZalouserGroupConfig } from "./types.js";
3
-
4
- type ZalouserGroups = Record<string, ZalouserGroupConfig>;
5
-
6
- function toGroupCandidate(value?: string | null): string {
7
- return value?.trim() ?? "";
8
- }
9
-
10
- export function normalizeZalouserGroupSlug(raw?: string | null): string {
11
- const trimmed = normalizeOptionalLowercaseString(raw) ?? "";
12
- if (!trimmed) {
13
- return "";
14
- }
15
- return trimmed
16
- .replace(/^#/, "")
17
- .replace(/[^a-z0-9]+/g, "-")
18
- .replace(/^-+|-+$/g, "");
19
- }
20
-
21
- export function buildZalouserGroupCandidates(params: {
22
- groupId?: string | null;
23
- groupChannel?: string | null;
24
- groupName?: string | null;
25
- includeGroupIdAlias?: boolean;
26
- includeWildcard?: boolean;
27
- allowNameMatching?: boolean;
28
- }): string[] {
29
- const seen = new Set<string>();
30
- const out: string[] = [];
31
- const push = (value?: string | null) => {
32
- const normalized = toGroupCandidate(value);
33
- if (!normalized || seen.has(normalized)) {
34
- return;
35
- }
36
- seen.add(normalized);
37
- out.push(normalized);
38
- };
39
-
40
- const groupId = toGroupCandidate(params.groupId);
41
- const groupChannel = toGroupCandidate(params.groupChannel);
42
- const groupName = toGroupCandidate(params.groupName);
43
-
44
- push(groupId);
45
- if (params.includeGroupIdAlias === true && groupId) {
46
- push(`group:${groupId}`);
47
- }
48
- if (params.allowNameMatching !== false) {
49
- push(groupChannel);
50
- push(groupName);
51
- if (groupName) {
52
- push(normalizeZalouserGroupSlug(groupName));
53
- }
54
- }
55
- if (params.includeWildcard !== false) {
56
- push("*");
57
- }
58
- return out;
59
- }
60
-
61
- export function findZalouserGroupEntry(
62
- groups: ZalouserGroups | undefined,
63
- candidates: string[],
64
- ): ZalouserGroupConfig | undefined {
65
- if (!groups) {
66
- return undefined;
67
- }
68
- for (const candidate of candidates) {
69
- const entry = groups[candidate];
70
- if (entry) {
71
- return entry;
72
- }
73
- }
74
- return undefined;
75
- }
76
-
77
- export function isZalouserGroupEntryAllowed(entry: ZalouserGroupConfig | undefined): boolean {
78
- if (!entry) {
79
- return false;
80
- }
81
- const legacyAllow = (entry as ZalouserGroupConfig & { allow?: unknown }).allow;
82
- return legacyAllow !== false && entry.enabled !== false;
83
- }
@@ -1,66 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- formatZalouserMessageSidFull,
4
- parseZalouserMessageSidFull,
5
- resolveZalouserMessageSid,
6
- resolveZalouserReactionMessageIds,
7
- } from "./message-sid.js";
8
-
9
- describe("zalouser message sid helpers", () => {
10
- it("parses MessageSidFull pairs", () => {
11
- expect(parseZalouserMessageSidFull("111:222")).toEqual({
12
- msgId: "111",
13
- cliMsgId: "222",
14
- });
15
- expect(parseZalouserMessageSidFull("111")).toBeNull();
16
- expect(parseZalouserMessageSidFull(undefined)).toBeNull();
17
- });
18
-
19
- it("resolves reaction ids from explicit params first", () => {
20
- expect(
21
- resolveZalouserReactionMessageIds({
22
- messageId: "m-1",
23
- cliMsgId: "c-1",
24
- currentMessageId: "x:y",
25
- }),
26
- ).toEqual({
27
- msgId: "m-1",
28
- cliMsgId: "c-1",
29
- });
30
- });
31
-
32
- it("resolves reaction ids from current message sid full", () => {
33
- expect(
34
- resolveZalouserReactionMessageIds({
35
- currentMessageId: "m-2:c-2",
36
- }),
37
- ).toEqual({
38
- msgId: "m-2",
39
- cliMsgId: "c-2",
40
- });
41
- });
42
-
43
- it("falls back to duplicated current id when no pair is available", () => {
44
- expect(
45
- resolveZalouserReactionMessageIds({
46
- currentMessageId: "solo",
47
- }),
48
- ).toEqual({
49
- msgId: "solo",
50
- cliMsgId: "solo",
51
- });
52
- });
53
-
54
- it("formats message sid fields for context payload", () => {
55
- expect(formatZalouserMessageSidFull({ msgId: "1", cliMsgId: "2" })).toBe("1:2");
56
- expect(formatZalouserMessageSidFull({ msgId: "1" })).toBe("1");
57
- expect(formatZalouserMessageSidFull({ cliMsgId: "2" })).toBe("2");
58
- expect(formatZalouserMessageSidFull({})).toBeUndefined();
59
- });
60
-
61
- it("resolves primary message sid with fallback timestamp", () => {
62
- expect(resolveZalouserMessageSid({ msgId: "1", cliMsgId: "2", fallback: "t" })).toBe("1");
63
- expect(resolveZalouserMessageSid({ cliMsgId: "2", fallback: "t" })).toBe("2");
64
- expect(resolveZalouserMessageSid({ fallback: "t" })).toBe("t");
65
- });
66
- });
@@ -1,80 +0,0 @@
1
- function toMessageSidPart(value?: string | number | null): string {
2
- if (typeof value === "string") {
3
- return value.trim();
4
- }
5
- if (typeof value === "number" && Number.isFinite(value)) {
6
- return String(Math.trunc(value));
7
- }
8
- return "";
9
- }
10
-
11
- export function parseZalouserMessageSidFull(
12
- value?: string | number | null,
13
- ): { msgId: string; cliMsgId: string } | null {
14
- const raw = toMessageSidPart(value);
15
- if (!raw) {
16
- return null;
17
- }
18
- const [msgIdPart, cliMsgIdPart] = raw.split(":").map((entry) => entry.trim());
19
- if (!msgIdPart || !cliMsgIdPart) {
20
- return null;
21
- }
22
- return { msgId: msgIdPart, cliMsgId: cliMsgIdPart };
23
- }
24
-
25
- export function resolveZalouserReactionMessageIds(params: {
26
- messageId?: string;
27
- cliMsgId?: string;
28
- currentMessageId?: string | number;
29
- }): { msgId: string; cliMsgId: string } | null {
30
- const explicitMessageId = toMessageSidPart(params.messageId);
31
- const explicitCliMsgId = toMessageSidPart(params.cliMsgId);
32
- if (explicitMessageId && explicitCliMsgId) {
33
- return { msgId: explicitMessageId, cliMsgId: explicitCliMsgId };
34
- }
35
-
36
- const parsedFromCurrent = parseZalouserMessageSidFull(params.currentMessageId);
37
- if (parsedFromCurrent) {
38
- return parsedFromCurrent;
39
- }
40
-
41
- const currentRaw = toMessageSidPart(params.currentMessageId);
42
- if (!currentRaw) {
43
- return null;
44
- }
45
- if (explicitMessageId && !explicitCliMsgId) {
46
- return { msgId: explicitMessageId, cliMsgId: currentRaw };
47
- }
48
- if (!explicitMessageId && explicitCliMsgId) {
49
- return { msgId: currentRaw, cliMsgId: explicitCliMsgId };
50
- }
51
- return { msgId: currentRaw, cliMsgId: currentRaw };
52
- }
53
-
54
- export function formatZalouserMessageSidFull(params: {
55
- msgId?: string | null;
56
- cliMsgId?: string | null;
57
- }): string | undefined {
58
- const msgId = toMessageSidPart(params.msgId);
59
- const cliMsgId = toMessageSidPart(params.cliMsgId);
60
- if (!msgId && !cliMsgId) {
61
- return undefined;
62
- }
63
- if (msgId && cliMsgId) {
64
- return `${msgId}:${cliMsgId}`;
65
- }
66
- return msgId || cliMsgId || undefined;
67
- }
68
-
69
- export function resolveZalouserMessageSid(params: {
70
- msgId?: string | null;
71
- cliMsgId?: string | null;
72
- fallback?: string | null;
73
- }): string | undefined {
74
- const msgId = toMessageSidPart(params.msgId);
75
- const cliMsgId = toMessageSidPart(params.cliMsgId);
76
- if (msgId || cliMsgId) {
77
- return msgId || cliMsgId;
78
- }
79
- return toMessageSidPart(params.fallback) || undefined;
80
- }
@@ -1,107 +0,0 @@
1
- import { describe, expect, it, vi } from "vitest";
2
- import type { OpenClawConfig, 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
- describe("zalouser monitor pairing account scoping", () => {
12
- it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
13
- const readAllowFromStore = vi.fn(
14
- async (
15
- channelOrParams:
16
- | string
17
- | {
18
- channel?: string;
19
- accountId?: string;
20
- },
21
- _env?: NodeJS.ProcessEnv,
22
- accountId?: string,
23
- ) => {
24
- const scopedAccountId =
25
- typeof channelOrParams === "object" && channelOrParams !== null
26
- ? channelOrParams.accountId
27
- : accountId;
28
- return scopedAccountId === "beta" ? [] : ["attacker"];
29
- },
30
- );
31
- const upsertPairingRequest = vi.fn(async () => ({ code: "PAIRME88", created: true }));
32
-
33
- setZalouserRuntime({
34
- logging: {
35
- shouldLogVerbose: () => false,
36
- },
37
- channel: {
38
- pairing: {
39
- readAllowFromStore,
40
- upsertPairingRequest,
41
- buildPairingReply: vi.fn(() => "pairing reply"),
42
- },
43
- commands: {
44
- shouldComputeCommandAuthorized: vi.fn(() => false),
45
- resolveCommandAuthorizedFromAuthorizers: vi.fn(() => false),
46
- isControlCommandMessage: vi.fn(() => false),
47
- },
48
- },
49
- } as unknown as PluginRuntime);
50
-
51
- const account: ResolvedZalouserAccount = {
52
- accountId: "beta",
53
- enabled: true,
54
- profile: "beta",
55
- authenticated: true,
56
- config: {
57
- dmPolicy: "pairing",
58
- allowFrom: [],
59
- },
60
- };
61
-
62
- const config: OpenClawConfig = {
63
- channels: {
64
- zalouser: {
65
- accounts: {
66
- alpha: { dmPolicy: "pairing", allowFrom: [] },
67
- beta: { dmPolicy: "pairing", allowFrom: [] },
68
- },
69
- },
70
- },
71
- };
72
-
73
- const message: ZaloInboundMessage = {
74
- threadId: "chat-1",
75
- isGroup: false,
76
- senderId: "attacker",
77
- senderName: "Attacker",
78
- groupName: undefined,
79
- timestampMs: Date.now(),
80
- msgId: "msg-1",
81
- content: "hello",
82
- raw: { source: "test" },
83
- };
84
-
85
- await __testing.processMessage({
86
- message,
87
- account,
88
- config,
89
- runtime: createZalouserRuntimeEnv(),
90
- });
91
-
92
- expect(readAllowFromStore).toHaveBeenCalledWith(
93
- expect.objectContaining({
94
- channel: "zalouser",
95
- accountId: "beta",
96
- }),
97
- );
98
- expect(upsertPairingRequest).toHaveBeenCalledWith(
99
- expect.objectContaining({
100
- channel: "zalouser",
101
- id: "attacker",
102
- accountId: "beta",
103
- }),
104
- );
105
- expect(sendMessageZalouserMock).toHaveBeenCalled();
106
- });
107
- });