@nextclaw/channel-plugin-feishu 0.2.15 → 0.2.16
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/package.json +1 -1
- package/src/accounts.test.ts +10 -0
- package/src/accounts.ts +10 -10
package/package.json
CHANGED
package/src/accounts.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
|
+
listFeishuAccountIds,
|
|
3
4
|
resolveDefaultFeishuAccountId,
|
|
4
5
|
resolveDefaultFeishuAccountSelection,
|
|
5
6
|
resolveFeishuAccount,
|
|
@@ -56,6 +57,15 @@ function expectUnresolvedEnvSecretRefError(key: string) {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
describe("resolveDefaultFeishuAccountId", () => {
|
|
60
|
+
it("falls back safely when channel config is missing", () => {
|
|
61
|
+
expect(listFeishuAccountIds(undefined)).toEqual(["default"]);
|
|
62
|
+
expect(resolveDefaultFeishuAccountId(undefined)).toBe("default");
|
|
63
|
+
expect(resolveDefaultFeishuAccountSelection(undefined)).toEqual({
|
|
64
|
+
accountId: "default",
|
|
65
|
+
source: "mapped-default",
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
59
69
|
it("prefers channels.feishu.defaultAccount when configured", () => {
|
|
60
70
|
const cfg = {
|
|
61
71
|
channels: {
|
package/src/accounts.ts
CHANGED
|
@@ -12,8 +12,8 @@ import type {
|
|
|
12
12
|
/**
|
|
13
13
|
* List all configured account IDs from the accounts field.
|
|
14
14
|
*/
|
|
15
|
-
function listConfiguredAccountIds(cfg
|
|
16
|
-
const accounts = (cfg
|
|
15
|
+
function listConfiguredAccountIds(cfg?: ClawdbotConfig): string[] {
|
|
16
|
+
const accounts = (cfg?.channels?.feishu as FeishuConfig | undefined)?.accounts;
|
|
17
17
|
if (!accounts || typeof accounts !== "object") {
|
|
18
18
|
return [];
|
|
19
19
|
}
|
|
@@ -24,7 +24,7 @@ function listConfiguredAccountIds(cfg: ClawdbotConfig): string[] {
|
|
|
24
24
|
* List all Feishu account IDs.
|
|
25
25
|
* If no accounts are configured, returns [DEFAULT_ACCOUNT_ID] for backward compatibility.
|
|
26
26
|
*/
|
|
27
|
-
export function listFeishuAccountIds(cfg
|
|
27
|
+
export function listFeishuAccountIds(cfg?: ClawdbotConfig): string[] {
|
|
28
28
|
const ids = listConfiguredAccountIds(cfg);
|
|
29
29
|
if (ids.length === 0) {
|
|
30
30
|
// Backward compatibility: no accounts configured, use default
|
|
@@ -36,11 +36,11 @@ export function listFeishuAccountIds(cfg: ClawdbotConfig): string[] {
|
|
|
36
36
|
/**
|
|
37
37
|
* Resolve the default account selection and its source.
|
|
38
38
|
*/
|
|
39
|
-
export function resolveDefaultFeishuAccountSelection(cfg
|
|
39
|
+
export function resolveDefaultFeishuAccountSelection(cfg?: ClawdbotConfig): {
|
|
40
40
|
accountId: string;
|
|
41
41
|
source: FeishuDefaultAccountSelectionSource;
|
|
42
42
|
} {
|
|
43
|
-
const preferredRaw = (cfg
|
|
43
|
+
const preferredRaw = (cfg?.channels?.feishu as FeishuConfig | undefined)?.defaultAccount?.trim();
|
|
44
44
|
const preferred = preferredRaw ? normalizeAccountId(preferredRaw) : undefined;
|
|
45
45
|
if (preferred) {
|
|
46
46
|
return {
|
|
@@ -64,7 +64,7 @@ export function resolveDefaultFeishuAccountSelection(cfg: ClawdbotConfig): {
|
|
|
64
64
|
/**
|
|
65
65
|
* Resolve the default account ID.
|
|
66
66
|
*/
|
|
67
|
-
export function resolveDefaultFeishuAccountId(cfg
|
|
67
|
+
export function resolveDefaultFeishuAccountId(cfg?: ClawdbotConfig): string {
|
|
68
68
|
return resolveDefaultFeishuAccountSelection(cfg).accountId;
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -72,10 +72,10 @@ export function resolveDefaultFeishuAccountId(cfg: ClawdbotConfig): string {
|
|
|
72
72
|
* Get the raw account-specific config.
|
|
73
73
|
*/
|
|
74
74
|
function resolveAccountConfig(
|
|
75
|
-
cfg: ClawdbotConfig,
|
|
75
|
+
cfg: ClawdbotConfig | undefined,
|
|
76
76
|
accountId: string,
|
|
77
77
|
): FeishuAccountConfig | undefined {
|
|
78
|
-
const accounts = (cfg
|
|
78
|
+
const accounts = (cfg?.channels?.feishu as FeishuConfig | undefined)?.accounts;
|
|
79
79
|
if (!accounts || typeof accounts !== "object") {
|
|
80
80
|
return undefined;
|
|
81
81
|
}
|
|
@@ -86,8 +86,8 @@ function resolveAccountConfig(
|
|
|
86
86
|
* Merge top-level config with account-specific config.
|
|
87
87
|
* Account-specific fields override top-level fields.
|
|
88
88
|
*/
|
|
89
|
-
function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): FeishuConfig {
|
|
90
|
-
const feishuCfg = cfg
|
|
89
|
+
function mergeFeishuAccountConfig(cfg: ClawdbotConfig | undefined, accountId: string): FeishuConfig {
|
|
90
|
+
const feishuCfg = cfg?.channels?.feishu as FeishuConfig | undefined;
|
|
91
91
|
|
|
92
92
|
// Extract base config (exclude accounts field to avoid recursion)
|
|
93
93
|
const { accounts: _ignored, defaultAccount: _ignoredDefaultAccount, ...base } = feishuCfg ?? {};
|