@openclaw/zalouser 2026.3.12 → 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 +14 -0
  15. package/src/accounts.test.ts +53 -1
  16. package/src/accounts.ts +52 -37
  17. package/src/channel-api.ts +20 -0
  18. package/src/channel.adapters.ts +390 -0
  19. package/src/channel.directory.test.ts +48 -61
  20. package/src/channel.runtime.ts +12 -0
  21. package/src/channel.sendpayload.test.ts +42 -37
  22. package/src/channel.setup.test.ts +33 -0
  23. package/src/channel.setup.ts +12 -0
  24. package/src/channel.test.ts +258 -56
  25. package/src/channel.ts +176 -692
  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 +4 -10
  34. package/src/monitor.group-gating.test.ts +319 -190
  35. package/src/monitor.ts +233 -182
  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 +5 -17
  51. package/src/status-issues.ts +18 -30
  52. package/src/test-helpers.ts +26 -0
  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 -101
  67. package/src/onboarding.ts +0 -340
@@ -3,12 +3,12 @@ import {
3
3
  buildCatchallMultiAccountChannelSchema,
4
4
  DmPolicySchema,
5
5
  GroupPolicySchema,
6
- } from "openclaw/plugin-sdk/compat";
7
- import { MarkdownConfigSchema, ToolPolicySchema } from "openclaw/plugin-sdk/zalouser";
8
- import { z } from "zod";
6
+ MarkdownConfigSchema,
7
+ ToolPolicySchema,
8
+ } from "openclaw/plugin-sdk/channel-config-schema";
9
+ import { z } from "openclaw/plugin-sdk/zod";
9
10
 
10
11
  const groupConfigSchema = z.object({
11
- allow: z.boolean().optional(),
12
12
  enabled: z.boolean().optional(),
13
13
  requireMention: z.boolean().optional(),
14
14
  tools: ToolPolicySchema,
@@ -24,7 +24,7 @@ const zalouserAccountSchema = z.object({
24
24
  allowFrom: AllowFromListSchema,
25
25
  historyLimit: z.number().int().min(0).optional(),
26
26
  groupAllowFrom: AllowFromListSchema,
27
- groupPolicy: GroupPolicySchema.optional(),
27
+ groupPolicy: GroupPolicySchema.optional().default("allowlist"),
28
28
  groups: z.object({}).catchall(groupConfigSchema).optional(),
29
29
  messagePrefix: z.string().optional(),
30
30
  responsePrefix: z.string().optional(),
@@ -0,0 +1,54 @@
1
+ import { resolveZalouserAccountSync } from "./accounts.js";
2
+ import type { ChannelDirectoryEntry, OpenClawConfig } from "./channel-api.js";
3
+ import { parseZalouserDirectoryGroupId } from "./session-route.js";
4
+
5
+ type ZalouserDirectoryDeps = {
6
+ listZaloGroupMembers: (
7
+ profile: string,
8
+ groupId: string,
9
+ ) => Promise<
10
+ Array<{
11
+ userId: string;
12
+ displayName?: string | null;
13
+ avatar?: string | null;
14
+ }>
15
+ >;
16
+ };
17
+
18
+ function mapUser(params: {
19
+ id: string;
20
+ name?: string | null;
21
+ avatarUrl?: string | null;
22
+ raw?: unknown;
23
+ }): ChannelDirectoryEntry {
24
+ return {
25
+ kind: "user",
26
+ id: params.id,
27
+ name: params.name ?? undefined,
28
+ avatarUrl: params.avatarUrl ?? undefined,
29
+ raw: params.raw,
30
+ };
31
+ }
32
+
33
+ export async function listZalouserDirectoryGroupMembers(
34
+ params: {
35
+ cfg: OpenClawConfig;
36
+ accountId?: string;
37
+ groupId: string;
38
+ limit?: number;
39
+ },
40
+ deps: ZalouserDirectoryDeps,
41
+ ) {
42
+ const account = resolveZalouserAccountSync({ cfg: params.cfg, accountId: params.accountId });
43
+ const normalizedGroupId = parseZalouserDirectoryGroupId(params.groupId);
44
+ const members = await deps.listZaloGroupMembers(account.profile, normalizedGroupId);
45
+ const rows = members.map((member) =>
46
+ mapUser({
47
+ id: member.userId,
48
+ name: member.displayName,
49
+ avatarUrl: member.avatar ?? null,
50
+ raw: member,
51
+ }),
52
+ );
53
+ return typeof params.limit === "number" && params.limit > 0 ? rows.slice(0, params.limit) : rows;
54
+ }
@@ -0,0 +1,156 @@
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
+ }
@@ -0,0 +1,77 @@
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 ADDED
@@ -0,0 +1,37 @@
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
+ };
@@ -37,7 +37,7 @@ describe("zalouser group policy helpers", () => {
37
37
 
38
38
  it("finds the first matching group entry", () => {
39
39
  const groups = {
40
- "group:123": { allow: true },
40
+ "group:123": { enabled: true },
41
41
  "team-alpha": { requireMention: false },
42
42
  "*": { requireMention: true },
43
43
  };
@@ -49,12 +49,12 @@ describe("zalouser group policy helpers", () => {
49
49
  includeGroupIdAlias: true,
50
50
  }),
51
51
  );
52
- expect(entry).toEqual({ allow: true });
52
+ expect(entry).toEqual({ enabled: true });
53
53
  });
54
54
 
55
55
  it("evaluates allow/enable flags", () => {
56
- expect(isZalouserGroupEntryAllowed({ allow: true, enabled: true })).toBe(true);
57
- expect(isZalouserGroupEntryAllowed({ allow: false })).toBe(false);
56
+ expect(isZalouserGroupEntryAllowed({ enabled: true })).toBe(true);
57
+ expect(isZalouserGroupEntryAllowed({ allow: false } as never)).toBe(false);
58
58
  expect(isZalouserGroupEntryAllowed({ enabled: false })).toBe(false);
59
59
  expect(isZalouserGroupEntryAllowed(undefined)).toBe(false);
60
60
  });
@@ -1,3 +1,4 @@
1
+ import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
1
2
  import type { ZalouserGroupConfig } from "./types.js";
2
3
 
3
4
  type ZalouserGroups = Record<string, ZalouserGroupConfig>;
@@ -7,7 +8,7 @@ function toGroupCandidate(value?: string | null): string {
7
8
  }
8
9
 
9
10
  export function normalizeZalouserGroupSlug(raw?: string | null): string {
10
- const trimmed = raw?.trim().toLowerCase() ?? "";
11
+ const trimmed = normalizeOptionalLowercaseString(raw) ?? "";
11
12
  if (!trimmed) {
12
13
  return "";
13
14
  }
@@ -77,5 +78,6 @@ export function isZalouserGroupEntryAllowed(entry: ZalouserGroupConfig | undefin
77
78
  if (!entry) {
78
79
  return false;
79
80
  }
80
- return entry.allow !== false && entry.enabled !== false;
81
+ const legacyAllow = (entry as ZalouserGroupConfig & { allow?: unknown }).allow;
82
+ return legacyAllow !== false && entry.enabled !== false;
81
83
  }
@@ -1,9 +1,11 @@
1
- import type { OpenClawConfig, PluginRuntime, RuntimeEnv } from "openclaw/plugin-sdk/zalouser";
2
1
  import { describe, expect, it, vi } from "vitest";
2
+ import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
3
3
  import "./monitor.send-mocks.js";
4
4
  import { __testing } from "./monitor.js";
5
+ import "./zalo-js.test-mocks.js";
5
6
  import { sendMessageZalouserMock } from "./monitor.send-mocks.js";
6
7
  import { setZalouserRuntime } from "./runtime.js";
8
+ import { createZalouserRuntimeEnv } from "./test-helpers.js";
7
9
  import type { ResolvedZalouserAccount, ZaloInboundMessage } from "./types.js";
8
10
 
9
11
  describe("zalouser monitor pairing account scoping", () => {
@@ -80,19 +82,11 @@ describe("zalouser monitor pairing account scoping", () => {
80
82
  raw: { source: "test" },
81
83
  };
82
84
 
83
- const runtime: RuntimeEnv = {
84
- log: vi.fn(),
85
- error: vi.fn(),
86
- exit: ((code: number): never => {
87
- throw new Error(`exit ${code}`);
88
- }) as RuntimeEnv["exit"],
89
- };
90
-
91
85
  await __testing.processMessage({
92
86
  message,
93
87
  account,
94
88
  config,
95
- runtime,
89
+ runtime: createZalouserRuntimeEnv(),
96
90
  });
97
91
 
98
92
  expect(readAllowFromStore).toHaveBeenCalledWith(