@jackwener/opencli 1.5.4 → 1.5.6
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 +27 -2
- package/README.zh-CN.md +36 -4
- package/dist/browser/daemon-client.d.ts +5 -1
- package/dist/browser/page.d.ts +6 -0
- package/dist/browser/page.js +15 -0
- package/dist/cli-manifest.json +1284 -67
- package/dist/cli.js +14 -14
- package/dist/clis/antigravity/serve.js +2 -2
- package/dist/clis/band/bands.d.ts +1 -0
- package/dist/clis/band/bands.js +72 -0
- package/dist/clis/band/mentions.d.ts +1 -0
- package/dist/clis/band/mentions.js +127 -0
- package/dist/clis/band/post.d.ts +1 -0
- package/dist/clis/band/post.js +175 -0
- package/dist/clis/band/posts.d.ts +1 -0
- package/dist/clis/band/posts.js +94 -0
- package/dist/clis/doubao/detail.d.ts +1 -0
- package/dist/clis/doubao/detail.js +33 -0
- package/dist/clis/doubao/detail.test.d.ts +1 -0
- package/dist/clis/doubao/detail.test.js +42 -0
- package/dist/clis/doubao/history.d.ts +1 -0
- package/dist/clis/doubao/history.js +28 -0
- package/dist/clis/doubao/history.test.d.ts +1 -0
- package/dist/clis/doubao/history.test.js +37 -0
- package/dist/clis/doubao/meeting-summary.d.ts +1 -0
- package/dist/clis/doubao/meeting-summary.js +39 -0
- package/dist/clis/doubao/meeting-transcript.d.ts +1 -0
- package/dist/clis/doubao/meeting-transcript.js +36 -0
- package/dist/clis/doubao/utils.d.ts +27 -0
- package/dist/clis/doubao/utils.js +317 -0
- package/dist/clis/doubao/utils.test.d.ts +1 -0
- package/dist/clis/doubao/utils.test.js +24 -0
- package/dist/clis/douyin/_shared/public-api.d.ts +33 -0
- package/dist/clis/douyin/_shared/public-api.js +29 -0
- package/dist/clis/douyin/user-videos.d.ts +5 -0
- package/dist/clis/douyin/user-videos.js +74 -0
- package/dist/clis/douyin/user-videos.test.d.ts +1 -0
- package/dist/clis/douyin/user-videos.test.js +108 -0
- package/dist/clis/ones/common.d.ts +32 -0
- package/dist/clis/ones/common.js +144 -0
- package/dist/clis/ones/enrich-tasks.d.ts +5 -0
- package/dist/clis/ones/enrich-tasks.js +37 -0
- package/dist/clis/ones/login.d.ts +1 -0
- package/dist/clis/ones/login.js +80 -0
- package/dist/clis/ones/logout.d.ts +1 -0
- package/dist/clis/ones/logout.js +17 -0
- package/dist/clis/ones/me.d.ts +1 -0
- package/dist/clis/ones/me.js +30 -0
- package/dist/clis/ones/my-tasks.d.ts +1 -0
- package/dist/clis/ones/my-tasks.js +120 -0
- package/dist/clis/ones/resolve-labels.d.ts +10 -0
- package/dist/clis/ones/resolve-labels.js +64 -0
- package/dist/clis/ones/task-helpers.d.ts +29 -0
- package/dist/clis/ones/task-helpers.js +212 -0
- package/dist/clis/ones/task-helpers.test.d.ts +1 -0
- package/dist/clis/ones/task-helpers.test.js +12 -0
- package/dist/clis/ones/task.d.ts +1 -0
- package/dist/clis/ones/task.js +66 -0
- package/dist/clis/ones/tasks.d.ts +1 -0
- package/dist/clis/ones/tasks.js +79 -0
- package/dist/clis/ones/token-info.d.ts +1 -0
- package/dist/clis/ones/token-info.js +42 -0
- package/dist/clis/ones/worklog.d.ts +11 -0
- package/dist/clis/ones/worklog.js +267 -0
- package/dist/clis/ones/worklog.test.d.ts +1 -0
- package/dist/clis/ones/worklog.test.js +20 -0
- package/dist/clis/sinafinance/rolling-news.d.ts +4 -0
- package/dist/clis/sinafinance/rolling-news.js +40 -0
- package/dist/clis/sinafinance/stock.d.ts +8 -0
- package/dist/clis/sinafinance/stock.js +117 -0
- package/dist/clis/spotify/spotify.d.ts +1 -0
- package/dist/clis/spotify/spotify.js +316 -0
- package/dist/clis/spotify/utils.d.ts +21 -0
- package/dist/clis/spotify/utils.js +66 -0
- package/dist/clis/spotify/utils.test.d.ts +1 -0
- package/dist/clis/spotify/utils.test.js +67 -0
- package/dist/clis/tieba/commands.test.d.ts +4 -0
- package/dist/clis/tieba/commands.test.js +79 -0
- package/dist/clis/tieba/hot.d.ts +1 -0
- package/dist/clis/tieba/hot.js +48 -0
- package/dist/clis/tieba/posts.d.ts +1 -0
- package/dist/clis/tieba/posts.js +85 -0
- package/dist/clis/tieba/read.d.ts +1 -0
- package/dist/clis/tieba/read.js +140 -0
- package/dist/clis/tieba/search.d.ts +1 -0
- package/dist/clis/tieba/search.js +108 -0
- package/dist/clis/tieba/utils.d.ts +101 -0
- package/dist/clis/tieba/utils.js +240 -0
- package/dist/clis/tieba/utils.test.d.ts +1 -0
- package/dist/clis/tieba/utils.test.js +290 -0
- package/dist/clis/weread/book.js +100 -13
- package/dist/clis/weread/commands.test.js +221 -0
- package/dist/clis/weread/private-api-regression.test.d.ts +1 -0
- package/dist/{weread-private-api-regression.test.js → clis/weread/private-api-regression.test.js} +92 -30
- package/dist/clis/weread/search-regression.test.d.ts +1 -0
- package/dist/clis/weread/search-regression.test.js +407 -0
- package/dist/clis/weread/search.js +143 -7
- package/dist/clis/weread/shelf.js +13 -95
- package/dist/clis/weread/utils.d.ts +46 -0
- package/dist/clis/weread/utils.js +214 -7
- package/dist/clis/weread/utils.test.js +71 -1
- package/dist/clis/xiaohongshu/publish.d.ts +1 -1
- package/dist/clis/xiaohongshu/publish.js +78 -31
- package/dist/clis/xiaohongshu/publish.test.js +66 -1
- package/dist/clis/xiaohongshu/user-helpers.d.ts +1 -0
- package/dist/clis/xiaohongshu/user-helpers.js +2 -0
- package/dist/clis/xiaohongshu/user-helpers.test.js +18 -0
- package/dist/clis/xueqiu/comments.d.ts +118 -0
- package/dist/clis/xueqiu/comments.js +354 -0
- package/dist/clis/xueqiu/comments.test.d.ts +1 -0
- package/dist/clis/xueqiu/comments.test.js +696 -0
- package/dist/clis/youtube/transcript.js +2 -4
- package/dist/clis/youtube/utils.d.ts +9 -0
- package/dist/clis/youtube/utils.js +67 -3
- package/dist/clis/youtube/utils.test.d.ts +1 -0
- package/dist/clis/youtube/utils.test.js +37 -0
- package/dist/clis/youtube/video.js +16 -15
- package/dist/clis/zsxq/dynamics.d.ts +1 -0
- package/dist/clis/zsxq/dynamics.js +47 -0
- package/dist/clis/zsxq/groups.d.ts +1 -0
- package/dist/clis/zsxq/groups.js +32 -0
- package/dist/clis/zsxq/search.d.ts +1 -0
- package/dist/clis/zsxq/search.js +43 -0
- package/dist/clis/zsxq/search.test.d.ts +1 -0
- package/dist/clis/zsxq/search.test.js +24 -0
- package/dist/clis/zsxq/topic.d.ts +1 -0
- package/dist/clis/zsxq/topic.js +47 -0
- package/dist/clis/zsxq/topic.test.d.ts +1 -0
- package/dist/clis/zsxq/topic.test.js +29 -0
- package/dist/clis/zsxq/topics.d.ts +1 -0
- package/dist/clis/zsxq/topics.js +25 -0
- package/dist/clis/zsxq/topics.test.d.ts +1 -0
- package/dist/clis/zsxq/topics.test.js +24 -0
- package/dist/clis/zsxq/utils.d.ts +97 -0
- package/dist/clis/zsxq/utils.js +230 -0
- package/dist/commanderAdapter.js +27 -4
- package/dist/commanderAdapter.test.js +39 -0
- package/dist/daemon.js +5 -4
- package/dist/errors.d.ts +29 -1
- package/dist/errors.js +49 -11
- package/dist/external-clis.yaml +17 -0
- package/dist/external.js +3 -3
- package/dist/main.js +2 -1
- package/dist/tui.js +2 -1
- package/dist/types.d.ts +5 -0
- package/docs/.vitepress/config.mts +3 -0
- package/docs/adapters/browser/band.md +63 -0
- package/docs/adapters/browser/ones.md +59 -0
- package/docs/adapters/browser/sinafinance.md +56 -6
- package/docs/adapters/browser/spotify.md +62 -0
- package/docs/adapters/browser/tieba.md +45 -0
- package/docs/adapters/browser/xueqiu.md +5 -0
- package/docs/adapters/browser/zsxq.md +49 -0
- package/docs/adapters/index.md +5 -2
- package/docs/adapters-doc/ones.md +32 -0
- package/extension/dist/background.js +1 -2
- package/extension/manifest.json +1 -1
- package/extension/package.json +1 -1
- package/extension/src/background.ts +17 -1
- package/extension/src/cdp.ts +42 -0
- package/extension/src/protocol.ts +5 -1
- package/package.json +1 -1
- package/scripts/postinstall.js +16 -0
- package/src/browser/daemon-client.ts +5 -1
- package/src/browser/page.ts +16 -0
- package/src/cli.ts +14 -14
- package/src/clis/antigravity/serve.ts +2 -2
- package/src/clis/band/bands.ts +76 -0
- package/src/clis/band/mentions.ts +134 -0
- package/src/clis/band/post.ts +187 -0
- package/src/clis/band/posts.ts +106 -0
- package/src/clis/doubao/detail.test.ts +53 -0
- package/src/clis/doubao/detail.ts +41 -0
- package/src/clis/doubao/history.test.ts +45 -0
- package/src/clis/doubao/history.ts +32 -0
- package/src/clis/doubao/meeting-summary.ts +53 -0
- package/src/clis/doubao/meeting-transcript.ts +48 -0
- package/src/clis/doubao/utils.test.ts +45 -0
- package/src/clis/doubao/utils.ts +371 -0
- package/src/clis/douyin/_shared/public-api.ts +84 -0
- package/src/clis/douyin/user-videos.test.ts +122 -0
- package/src/clis/douyin/user-videos.ts +101 -0
- package/src/clis/ones/common.ts +187 -0
- package/src/clis/ones/enrich-tasks.ts +47 -0
- package/src/clis/ones/login.ts +103 -0
- package/src/clis/ones/logout.ts +19 -0
- package/src/clis/ones/me.ts +34 -0
- package/src/clis/ones/my-tasks.ts +148 -0
- package/src/clis/ones/resolve-labels.ts +80 -0
- package/src/clis/ones/task-helpers.test.ts +14 -0
- package/src/clis/ones/task-helpers.ts +214 -0
- package/src/clis/ones/task.ts +79 -0
- package/src/clis/ones/tasks.ts +92 -0
- package/src/clis/ones/token-info.ts +46 -0
- package/src/clis/ones/worklog.test.ts +24 -0
- package/src/clis/ones/worklog.ts +306 -0
- package/src/clis/sinafinance/rolling-news.ts +42 -0
- package/src/clis/sinafinance/stock.ts +127 -0
- package/src/clis/spotify/spotify.ts +328 -0
- package/src/clis/spotify/utils.test.ts +87 -0
- package/src/clis/spotify/utils.ts +92 -0
- package/src/clis/tieba/commands.test.ts +86 -0
- package/src/clis/tieba/hot.ts +52 -0
- package/src/clis/tieba/posts.ts +108 -0
- package/src/clis/tieba/read.ts +158 -0
- package/src/clis/tieba/search.ts +119 -0
- package/src/clis/tieba/utils.test.ts +322 -0
- package/src/clis/tieba/utils.ts +348 -0
- package/src/clis/weread/book.ts +116 -13
- package/src/clis/weread/commands.test.ts +249 -0
- package/src/{weread-private-api-regression.test.ts → clis/weread/private-api-regression.test.ts} +108 -30
- package/src/clis/weread/search-regression.test.ts +440 -0
- package/src/clis/weread/search.ts +189 -9
- package/src/clis/weread/shelf.ts +20 -122
- package/src/clis/weread/utils.test.ts +81 -1
- package/src/clis/weread/utils.ts +264 -7
- package/src/clis/xiaohongshu/publish.test.ts +79 -1
- package/src/clis/xiaohongshu/publish.ts +84 -30
- package/src/clis/xiaohongshu/user-helpers.test.ts +23 -0
- package/src/clis/xiaohongshu/user-helpers.ts +4 -0
- package/src/clis/xueqiu/comments.test.ts +823 -0
- package/src/clis/xueqiu/comments.ts +461 -0
- package/src/clis/youtube/transcript.ts +2 -4
- package/src/clis/youtube/utils.test.ts +43 -0
- package/src/clis/youtube/utils.ts +69 -0
- package/src/clis/youtube/video.ts +16 -15
- package/src/clis/zsxq/dynamics.ts +60 -0
- package/src/clis/zsxq/groups.ts +41 -0
- package/src/clis/zsxq/search.test.ts +29 -0
- package/src/clis/zsxq/search.ts +54 -0
- package/src/clis/zsxq/topic.test.ts +34 -0
- package/src/clis/zsxq/topic.ts +68 -0
- package/src/clis/zsxq/topics.test.ts +29 -0
- package/src/clis/zsxq/topics.ts +36 -0
- package/src/clis/zsxq/utils.ts +351 -0
- package/src/commanderAdapter.test.ts +47 -0
- package/src/commanderAdapter.ts +26 -3
- package/src/daemon.ts +5 -4
- package/src/errors.ts +71 -10
- package/src/external-clis.yaml +17 -0
- package/src/external.ts +3 -3
- package/src/main.ts +2 -1
- package/src/tui.ts +2 -1
- package/src/types.ts +5 -0
- package/tests/e2e/band-auth.test.ts +20 -0
- package/tests/e2e/browser-auth-helpers.ts +18 -0
- package/tests/e2e/browser-auth.test.ts +35 -47
- package/tests/e2e/browser-public.test.ts +288 -0
- package/tests/e2e/management.test.ts +1 -1
- package/tests/e2e/plugin-management.test.ts +1 -1
- package/vitest.config.ts +1 -0
- package/SKILL.md +0 -879
- package/dist/weread-private-api-regression.test.d.ts +0 -1
- package/dist/weread-search-regression.test.d.ts +0 -1
- package/dist/weread-search-regression.test.js +0 -39
- package/src/weread-search-regression.test.ts +0 -44
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONES 旧版 Project API — 经 Browser Bridge 在已登录标签页内 fetch(携带 Cookie)。
|
|
3
|
+
* 文档:https://developer.ones.cn/zh-CN/docs/api/readme/
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { IPage } from '../../types.js';
|
|
7
|
+
import { CliError } from '../../errors.js';
|
|
8
|
+
|
|
9
|
+
export const API_PREFIX = '/project/api/project';
|
|
10
|
+
|
|
11
|
+
export function getOnesBaseUrl(): string {
|
|
12
|
+
const u = process.env.ONES_BASE_URL?.trim().replace(/\/+$/, '');
|
|
13
|
+
if (!u) {
|
|
14
|
+
throw new CliError(
|
|
15
|
+
'CONFIG',
|
|
16
|
+
'Missing ONES_BASE_URL',
|
|
17
|
+
'Set ONES_BASE_URL to your deployment origin, e.g. https://your-team.ones.cn (no trailing slash).',
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return u;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function onesApiUrl(apiPath: string): string {
|
|
24
|
+
const base = getOnesBaseUrl();
|
|
25
|
+
const p = apiPath.replace(/^\/+/, '');
|
|
26
|
+
return `${base}${API_PREFIX}/${p}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 打开 ONES 根地址,确保后续 fetch 与页面同源、带上登录 Cookie */
|
|
30
|
+
export async function gotoOnesHome(page: IPage): Promise<void> {
|
|
31
|
+
await page.goto(getOnesBaseUrl(), { waitUntil: 'load' });
|
|
32
|
+
await page.wait(2);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 在页面内发起请求。默认带 credentials;若设置了 ONES_USER_ID + ONES_AUTH_TOKEN,则附加文档要求的 Header(与纯 Cookie 二选一或并存,取决于部署)。
|
|
37
|
+
*/
|
|
38
|
+
function buildHeaders(auth: boolean, includeJsonContentType: boolean): Record<string, string> {
|
|
39
|
+
const ref = getOnesBaseUrl();
|
|
40
|
+
const out: Record<string, string> = { Referer: ref };
|
|
41
|
+
if (auth) {
|
|
42
|
+
const uid =
|
|
43
|
+
process.env.ONES_USER_ID?.trim() ||
|
|
44
|
+
process.env.ONES_USER_UUID?.trim() ||
|
|
45
|
+
process.env.Ones_User_Id?.trim();
|
|
46
|
+
const tok = process.env.ONES_AUTH_TOKEN?.trim() || process.env.Ones_Auth_Token?.trim();
|
|
47
|
+
if (uid && tok) {
|
|
48
|
+
out['Ones-User-Id'] = uid;
|
|
49
|
+
out['Ones-Auth-Token'] = tok;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (includeJsonContentType) out['Content-Type'] = 'application/json';
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function summarizeOnesError(status: number, body: unknown): string {
|
|
57
|
+
if (body && typeof body === 'object') {
|
|
58
|
+
const o = body as Record<string, unknown>;
|
|
59
|
+
const parts: string[] = [];
|
|
60
|
+
if (typeof o.type === 'string') parts.push(o.type);
|
|
61
|
+
if (typeof o.reason === 'string') parts.push(o.reason);
|
|
62
|
+
if (typeof o.errcode === 'string') parts.push(o.errcode);
|
|
63
|
+
if (typeof o.message === 'string') parts.push(o.message);
|
|
64
|
+
if (o.code !== undefined && o.code !== null) parts.push(`code=${String(o.code)}`);
|
|
65
|
+
if (parts.length) return parts.filter(Boolean).join(' · ');
|
|
66
|
+
}
|
|
67
|
+
return status === 401 ? 'Unauthorized' : `HTTP ${status}`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** ONES 部分接口 HTTP 200 但 body 仍为错误(如 reason: ServerError) */
|
|
71
|
+
function throwIfOnesPeekBusinessError(apiPath: string, parsed: unknown): void {
|
|
72
|
+
if (parsed === null || typeof parsed !== 'object') return;
|
|
73
|
+
const o = parsed as Record<string, unknown>;
|
|
74
|
+
if (Array.isArray(o.groups)) return;
|
|
75
|
+
const hasErr =
|
|
76
|
+
(typeof o.reason === 'string' && o.reason.length > 0) ||
|
|
77
|
+
(typeof o.errcode === 'string' && o.errcode.length > 0) ||
|
|
78
|
+
(typeof o.type === 'string' && o.type.length > 0);
|
|
79
|
+
if (!hasErr) return;
|
|
80
|
+
const detail = summarizeOnesError(200, parsed);
|
|
81
|
+
throw new CliError(
|
|
82
|
+
'FETCH_ERROR',
|
|
83
|
+
`ONES ${apiPath}: ${detail}`,
|
|
84
|
+
'若 query 不合法会返回 ServerError;可试 opencli ones tasks(空 must)或检查筛选器文档。响应全文可用 -v 或临时打日志。',
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function onesFetchInPageWithMeta(
|
|
89
|
+
page: IPage,
|
|
90
|
+
apiPath: string,
|
|
91
|
+
options: {
|
|
92
|
+
method?: string;
|
|
93
|
+
body?: string | null;
|
|
94
|
+
auth?: boolean;
|
|
95
|
+
skipGoto?: boolean;
|
|
96
|
+
} = {},
|
|
97
|
+
): Promise<{ ok: boolean; status: number; parsed: unknown }> {
|
|
98
|
+
if (!options.skipGoto) {
|
|
99
|
+
await gotoOnesHome(page);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const url = onesApiUrl(apiPath);
|
|
103
|
+
const method = (options.method ?? 'GET').toUpperCase();
|
|
104
|
+
const auth = options.auth !== false;
|
|
105
|
+
const body = options.body ?? null;
|
|
106
|
+
const includeCt = body !== null || method === 'POST' || method === 'PUT' || method === 'PATCH';
|
|
107
|
+
const headers = buildHeaders(auth, includeCt);
|
|
108
|
+
|
|
109
|
+
const urlJs = JSON.stringify(url);
|
|
110
|
+
const methodJs = JSON.stringify(method);
|
|
111
|
+
const headersJs = JSON.stringify(headers);
|
|
112
|
+
const bodyJs = body === null ? 'null' : JSON.stringify(body);
|
|
113
|
+
|
|
114
|
+
const raw = await page.evaluate(`
|
|
115
|
+
(async () => {
|
|
116
|
+
const url = ${urlJs};
|
|
117
|
+
const method = ${methodJs};
|
|
118
|
+
const headers = ${headersJs};
|
|
119
|
+
const body = ${bodyJs};
|
|
120
|
+
const init = {
|
|
121
|
+
method,
|
|
122
|
+
headers: { ...headers },
|
|
123
|
+
credentials: 'include',
|
|
124
|
+
};
|
|
125
|
+
if (body !== null) init.body = body;
|
|
126
|
+
const res = await fetch(url, init);
|
|
127
|
+
const text = await res.text();
|
|
128
|
+
let parsed = null;
|
|
129
|
+
try {
|
|
130
|
+
parsed = text ? JSON.parse(text) : null;
|
|
131
|
+
} catch {
|
|
132
|
+
parsed = text;
|
|
133
|
+
}
|
|
134
|
+
return { ok: res.ok, status: res.status, parsed };
|
|
135
|
+
})()
|
|
136
|
+
`);
|
|
137
|
+
|
|
138
|
+
return raw as { ok: boolean; status: number; parsed: unknown };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** 当前操作用户 8 位 uuid(Header 或 GET users/me) */
|
|
142
|
+
export async function resolveOnesUserUuid(page: IPage, opts?: { skipGoto?: boolean }): Promise<string> {
|
|
143
|
+
const fromEnv =
|
|
144
|
+
process.env.ONES_USER_ID?.trim() ||
|
|
145
|
+
process.env.ONES_USER_UUID?.trim() ||
|
|
146
|
+
process.env.Ones_User_Id?.trim();
|
|
147
|
+
if (fromEnv) return fromEnv;
|
|
148
|
+
|
|
149
|
+
const data = (await onesFetchInPage(page, 'users/me', { skipGoto: opts?.skipGoto })) as Record<string, unknown>;
|
|
150
|
+
const u = data.user && typeof data.user === 'object' ? (data.user as Record<string, unknown>) : data;
|
|
151
|
+
if (!u || typeof u.uuid !== 'string') {
|
|
152
|
+
throw new CliError(
|
|
153
|
+
'FETCH_ERROR',
|
|
154
|
+
'Could not read current user uuid from users/me',
|
|
155
|
+
'Set ONES_USER_ID or ensure Chrome is logged in; try: opencli ones me -f json',
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
return String(u.uuid);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export async function onesFetchInPage(
|
|
162
|
+
page: IPage,
|
|
163
|
+
apiPath: string,
|
|
164
|
+
options: {
|
|
165
|
+
method?: string;
|
|
166
|
+
body?: string | null;
|
|
167
|
+
auth?: boolean;
|
|
168
|
+
/** 已在 ONES 根页时设为 true,避免每条 API 都 goto+wait(显著提速) */
|
|
169
|
+
skipGoto?: boolean;
|
|
170
|
+
} = {},
|
|
171
|
+
): Promise<unknown> {
|
|
172
|
+
const r = await onesFetchInPageWithMeta(page, apiPath, options);
|
|
173
|
+
if (!r.ok) {
|
|
174
|
+
const detail = summarizeOnesError(r.status, r.parsed);
|
|
175
|
+
const hint =
|
|
176
|
+
r.status === 401
|
|
177
|
+
? '在 Chrome 中打开 ONES 并登录;或先执行 opencli ones login 后按提示 export ONES_USER_ID / ONES_AUTH_TOKEN;并确认 ONES_BASE_URL 与浏览器地址一致。'
|
|
178
|
+
: '检查 ONES_BASE_URL、VPN/内网,以及实例是否仍为 Project API 路径。';
|
|
179
|
+
throw new CliError('FETCH_ERROR', `ONES ${apiPath}: ${detail}`, hint);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (apiPath.includes('/filters/peek')) {
|
|
183
|
+
throwIfOnesPeekBusinessError(apiPath, r.parsed);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return r.parsed;
|
|
187
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* peek 列表只有轻量字段,用 batch tasks/info 补全 summary 等(ONES 文档 #7)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { IPage } from '../../types.js';
|
|
6
|
+
import { onesFetchInPage } from './common.js';
|
|
7
|
+
|
|
8
|
+
const BATCH_SIZE = 40;
|
|
9
|
+
|
|
10
|
+
export async function enrichPeekEntriesWithDetails(
|
|
11
|
+
page: IPage,
|
|
12
|
+
team: string,
|
|
13
|
+
entries: Record<string, unknown>[],
|
|
14
|
+
skipGoto: boolean,
|
|
15
|
+
): Promise<Record<string, unknown>[]> {
|
|
16
|
+
const ids = [...new Set(entries.map((e) => String(e.uuid ?? '').trim()).filter(Boolean))];
|
|
17
|
+
if (ids.length === 0) return entries;
|
|
18
|
+
|
|
19
|
+
const byId = new Map<string, Record<string, unknown>>();
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
for (let i = 0; i < ids.length; i += BATCH_SIZE) {
|
|
23
|
+
const slice = ids.slice(i, i + BATCH_SIZE);
|
|
24
|
+
const parsed = (await onesFetchInPage(page, `team/${team}/tasks/info`, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
body: JSON.stringify({ ids: slice }),
|
|
27
|
+
skipGoto,
|
|
28
|
+
})) as Record<string, unknown>;
|
|
29
|
+
|
|
30
|
+
const tasks = Array.isArray(parsed.tasks) ? (parsed.tasks as Record<string, unknown>[]) : [];
|
|
31
|
+
for (const t of tasks) {
|
|
32
|
+
const id = String(t.uuid ?? '');
|
|
33
|
+
if (id) byId.set(id, t);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} catch {
|
|
37
|
+
return entries;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (byId.size === 0) return entries;
|
|
41
|
+
|
|
42
|
+
return entries.map((e) => {
|
|
43
|
+
const id = String(e.uuid ?? '');
|
|
44
|
+
const full = id ? byId.get(id) : undefined;
|
|
45
|
+
return full ? { ...e, ...full } : e;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import { CliError } from '../../errors.js';
|
|
3
|
+
import { getOnesBaseUrl, onesFetchInPage } from './common.js';
|
|
4
|
+
|
|
5
|
+
cli({
|
|
6
|
+
site: 'ones',
|
|
7
|
+
name: 'login',
|
|
8
|
+
description:
|
|
9
|
+
'ONES Project API — login via Chrome Bridge (POST auth/login); stderr prints export hints for ONES_USER_ID / TOKEN',
|
|
10
|
+
domain: 'ones.cn',
|
|
11
|
+
strategy: Strategy.COOKIE,
|
|
12
|
+
browser: true,
|
|
13
|
+
navigateBefore: false,
|
|
14
|
+
args: [
|
|
15
|
+
{
|
|
16
|
+
name: 'email',
|
|
17
|
+
type: 'str',
|
|
18
|
+
required: false,
|
|
19
|
+
help: 'Account email (or set ONES_EMAIL)',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'phone',
|
|
23
|
+
type: 'str',
|
|
24
|
+
required: false,
|
|
25
|
+
help: 'Account phone (or set ONES_PHONE); ignored if email is set',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'password',
|
|
29
|
+
type: 'str',
|
|
30
|
+
required: false,
|
|
31
|
+
help: 'Password (or set ONES_PASSWORD)',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
columns: ['uuid', 'name', 'email', 'token_preview'],
|
|
35
|
+
|
|
36
|
+
func: async (page, kwargs) => {
|
|
37
|
+
const email = (kwargs.email as string | undefined)?.trim() || process.env.ONES_EMAIL?.trim();
|
|
38
|
+
const phone = (kwargs.phone as string | undefined)?.trim() || process.env.ONES_PHONE?.trim();
|
|
39
|
+
const password =
|
|
40
|
+
(kwargs.password as string | undefined) || process.env.ONES_PASSWORD || '';
|
|
41
|
+
|
|
42
|
+
if (!password) {
|
|
43
|
+
throw new CliError(
|
|
44
|
+
'CONFIG',
|
|
45
|
+
'Password required',
|
|
46
|
+
'Pass --password or set ONES_PASSWORD for non-interactive use.',
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (!email && !phone) {
|
|
50
|
+
throw new CliError(
|
|
51
|
+
'CONFIG',
|
|
52
|
+
'email or phone required',
|
|
53
|
+
'Pass --email or --phone (or set ONES_EMAIL / ONES_PHONE).',
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getOnesBaseUrl();
|
|
58
|
+
const bodyObj: Record<string, string> = { password };
|
|
59
|
+
if (email) bodyObj.email = email;
|
|
60
|
+
else bodyObj.phone = phone!;
|
|
61
|
+
|
|
62
|
+
const parsed = (await onesFetchInPage(page, 'auth/login', {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
body: JSON.stringify(bodyObj),
|
|
65
|
+
auth: false,
|
|
66
|
+
})) as Record<string, unknown>;
|
|
67
|
+
|
|
68
|
+
const user = parsed.user as Record<string, unknown> | undefined;
|
|
69
|
+
if (!user?.uuid || !user?.token) {
|
|
70
|
+
throw new CliError(
|
|
71
|
+
'FETCH_ERROR',
|
|
72
|
+
'ONES login response missing user.uuid or user.token',
|
|
73
|
+
'Your server build may differ from documented Project API.',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const uuid = String(user.uuid);
|
|
78
|
+
const token = String(user.token);
|
|
79
|
+
const name = String(user.name ?? '');
|
|
80
|
+
const em = String(user.email ?? '');
|
|
81
|
+
|
|
82
|
+
const base = getOnesBaseUrl();
|
|
83
|
+
console.error(
|
|
84
|
+
[
|
|
85
|
+
'',
|
|
86
|
+
'后续请求会优先使用当前 Chrome 会话 Cookie;若接口仍要求 Header,可 export:',
|
|
87
|
+
` export ONES_BASE_URL=${JSON.stringify(base)}`,
|
|
88
|
+
` export ONES_USER_ID=${JSON.stringify(uuid)}`,
|
|
89
|
+
` export ONES_AUTH_TOKEN=${JSON.stringify(token)}`,
|
|
90
|
+
'',
|
|
91
|
+
].join('\n'),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return [
|
|
95
|
+
{
|
|
96
|
+
uuid,
|
|
97
|
+
name,
|
|
98
|
+
email: em,
|
|
99
|
+
token_preview: token.length > 12 ? `${token.slice(0, 6)}…${token.slice(-4)}` : '***',
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
},
|
|
103
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import { onesFetchInPage } from './common.js';
|
|
3
|
+
|
|
4
|
+
cli({
|
|
5
|
+
site: 'ones',
|
|
6
|
+
name: 'logout',
|
|
7
|
+
description: 'ONES Project API — invalidate current token (GET auth/logout) via Chrome Bridge',
|
|
8
|
+
domain: 'ones.cn',
|
|
9
|
+
strategy: Strategy.COOKIE,
|
|
10
|
+
browser: true,
|
|
11
|
+
navigateBefore: false,
|
|
12
|
+
args: [],
|
|
13
|
+
columns: ['ok', 'detail'],
|
|
14
|
+
|
|
15
|
+
func: async (page) => {
|
|
16
|
+
await onesFetchInPage(page, 'auth/logout', { method: 'GET' });
|
|
17
|
+
return [{ ok: 'true', detail: 'Server logout ok; clear local ONES_AUTH_TOKEN if set.' }];
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import { CliError } from '../../errors.js';
|
|
3
|
+
import { onesFetchInPage } from './common.js';
|
|
4
|
+
|
|
5
|
+
cli({
|
|
6
|
+
site: 'ones',
|
|
7
|
+
name: 'me',
|
|
8
|
+
description: 'ONES Project API — current user (GET users/me) via Chrome Bridge',
|
|
9
|
+
domain: 'ones.cn',
|
|
10
|
+
strategy: Strategy.COOKIE,
|
|
11
|
+
browser: true,
|
|
12
|
+
navigateBefore: false,
|
|
13
|
+
args: [],
|
|
14
|
+
columns: ['uuid', 'name', 'email', 'phone', 'status'],
|
|
15
|
+
|
|
16
|
+
func: async (page) => {
|
|
17
|
+
const data = (await onesFetchInPage(page, 'users/me')) as Record<string, unknown>;
|
|
18
|
+
const u = data.user && typeof data.user === 'object' ? (data.user as Record<string, unknown>) : data;
|
|
19
|
+
|
|
20
|
+
if (!u || typeof u.uuid !== 'string') {
|
|
21
|
+
throw new CliError('FETCH_ERROR', 'Unexpected users/me response', 'See raw JSON with: opencli ones me -f json');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
uuid: String(u.uuid),
|
|
27
|
+
name: String(u.name ?? ''),
|
|
28
|
+
email: String(u.email ?? ''),
|
|
29
|
+
phone: String(u.phone ?? ''),
|
|
30
|
+
status: u.status != null ? String(u.status) : '',
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
import { CliError } from '../../errors.js';
|
|
3
|
+
import type { IPage } from '../../types.js';
|
|
4
|
+
import { gotoOnesHome, onesFetchInPage, resolveOnesUserUuid } from './common.js';
|
|
5
|
+
import { enrichPeekEntriesWithDetails } from './enrich-tasks.js';
|
|
6
|
+
import { resolveTaskListLabels } from './resolve-labels.js';
|
|
7
|
+
import {
|
|
8
|
+
defaultPeekBody,
|
|
9
|
+
flattenPeekGroups,
|
|
10
|
+
mapTaskEntry,
|
|
11
|
+
parsePeekLimit,
|
|
12
|
+
} from './task-helpers.js';
|
|
13
|
+
|
|
14
|
+
/** 文档示例里「负责人」常用 field004;与顶层 assign 在不同部署上二选一有效 */
|
|
15
|
+
function queryAssign(userUuid: string): Record<string, unknown> {
|
|
16
|
+
return { must: [{ equal: { assign: userUuid } }] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function queryAssignField004(userUuid: string): Record<string, unknown> {
|
|
20
|
+
return { must: [{ in: { 'field_values.field004': [userUuid] } }] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function queryOwner(userUuid: string): Record<string, unknown> {
|
|
24
|
+
return { must: [{ equal: { owner: userUuid } }] };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function dedupeByUuid(entries: Record<string, unknown>[]): Record<string, unknown>[] {
|
|
28
|
+
const seen = new Set<string>();
|
|
29
|
+
const out: Record<string, unknown>[] = [];
|
|
30
|
+
for (const e of entries) {
|
|
31
|
+
const id = String(e.uuid ?? '');
|
|
32
|
+
if (!id || seen.has(id)) continue;
|
|
33
|
+
seen.add(id);
|
|
34
|
+
out.push(e);
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function peekTasks(
|
|
40
|
+
page: IPage,
|
|
41
|
+
team: string,
|
|
42
|
+
query: Record<string, unknown>,
|
|
43
|
+
cap: number,
|
|
44
|
+
): Promise<Record<string, unknown>[]> {
|
|
45
|
+
const path = `team/${team}/filters/peek`;
|
|
46
|
+
const body = defaultPeekBody(query);
|
|
47
|
+
const parsed = (await onesFetchInPage(page, path, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
body: JSON.stringify(body),
|
|
50
|
+
skipGoto: true,
|
|
51
|
+
})) as Record<string, unknown>;
|
|
52
|
+
return flattenPeekGroups(parsed, cap);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
cli({
|
|
56
|
+
site: 'ones',
|
|
57
|
+
name: 'my-tasks',
|
|
58
|
+
description:
|
|
59
|
+
'ONES — my work items (filters/peek + strict must query). Default: assignee=me. Use --mode if your site uses field004 for assignee.',
|
|
60
|
+
domain: 'ones.cn',
|
|
61
|
+
strategy: Strategy.COOKIE,
|
|
62
|
+
browser: true,
|
|
63
|
+
navigateBefore: false,
|
|
64
|
+
args: [
|
|
65
|
+
{
|
|
66
|
+
name: 'team',
|
|
67
|
+
type: 'str',
|
|
68
|
+
required: false,
|
|
69
|
+
positional: true,
|
|
70
|
+
help: 'Team UUID from URL …/team/<uuid>/…, or set ONES_TEAM_UUID',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'limit',
|
|
74
|
+
type: 'int',
|
|
75
|
+
default: 100,
|
|
76
|
+
help: 'Max rows (default 100, max 500)',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: 'mode',
|
|
80
|
+
type: 'str',
|
|
81
|
+
default: 'assign',
|
|
82
|
+
choices: ['assign', 'field004', 'owner', 'both'],
|
|
83
|
+
help:
|
|
84
|
+
'assign=负责人(顶层 assign);field004=负责人(筛选器示例里的 field004);owner=创建者;both=负责人∪创建者(两次 peek 去重)',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
columns: ['title', 'status', 'project', 'uuid', 'updated', '工时'],
|
|
88
|
+
|
|
89
|
+
func: async (page, kwargs) => {
|
|
90
|
+
const team =
|
|
91
|
+
(kwargs.team as string | undefined)?.trim() ||
|
|
92
|
+
process.env.ONES_TEAM_UUID?.trim() ||
|
|
93
|
+
process.env.ONES_TEAM_ID?.trim();
|
|
94
|
+
if (!team) {
|
|
95
|
+
throw new CliError(
|
|
96
|
+
'CONFIG',
|
|
97
|
+
'team UUID required',
|
|
98
|
+
'Pass team from URL …/team/<team>/… or set ONES_TEAM_UUID.',
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const limit = parsePeekLimit(kwargs.limit, 100);
|
|
103
|
+
const mode = String(kwargs.mode ?? 'assign');
|
|
104
|
+
|
|
105
|
+
await gotoOnesHome(page);
|
|
106
|
+
const userUuid = await resolveOnesUserUuid(page, { skipGoto: true });
|
|
107
|
+
|
|
108
|
+
let entries: Record<string, unknown>[] = [];
|
|
109
|
+
|
|
110
|
+
if (mode === 'both') {
|
|
111
|
+
const cap = Math.min(500, limit * 2);
|
|
112
|
+
const asAssign = await peekTasks(page, team, queryAssign(userUuid), cap);
|
|
113
|
+
const asOwner = await peekTasks(page, team, queryOwner(userUuid), cap);
|
|
114
|
+
entries = dedupeByUuid([...asAssign, ...asOwner]).slice(0, limit);
|
|
115
|
+
} else {
|
|
116
|
+
const queryByMode = (): Record<string, unknown> => {
|
|
117
|
+
switch (mode) {
|
|
118
|
+
case 'field004':
|
|
119
|
+
return queryAssignField004(userUuid);
|
|
120
|
+
case 'owner':
|
|
121
|
+
return queryOwner(userUuid);
|
|
122
|
+
case 'assign':
|
|
123
|
+
default:
|
|
124
|
+
return queryAssign(userUuid);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const primary = queryByMode();
|
|
129
|
+
try {
|
|
130
|
+
entries = await peekTasks(page, team, primary, limit);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
const msg = e instanceof Error ? e.message : '';
|
|
133
|
+
const canFallback =
|
|
134
|
+
mode === 'assign' &&
|
|
135
|
+
(msg.includes('ServerError') || msg.includes('801') || msg.includes('Params is invalid'));
|
|
136
|
+
if (canFallback) {
|
|
137
|
+
entries = await peekTasks(page, team, queryAssignField004(userUuid), limit);
|
|
138
|
+
} else {
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const enriched = await enrichPeekEntriesWithDetails(page, team, entries, true);
|
|
145
|
+
const labels = await resolveTaskListLabels(page, team, enriched, true);
|
|
146
|
+
return enriched.map((e) => mapTaskEntry(e, labels));
|
|
147
|
+
},
|
|
148
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 把 status / project 的 uuid 解析为中文名(团队级接口各查一次或按批)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { IPage } from '../../types.js';
|
|
6
|
+
import { onesFetchInPage } from './common.js';
|
|
7
|
+
import { getTaskProjectRawId } from './task-helpers.js';
|
|
8
|
+
|
|
9
|
+
export async function loadTaskStatusLabels(
|
|
10
|
+
page: IPage,
|
|
11
|
+
team: string,
|
|
12
|
+
skipGoto: boolean,
|
|
13
|
+
): Promise<Map<string, string>> {
|
|
14
|
+
const map = new Map<string, string>();
|
|
15
|
+
try {
|
|
16
|
+
const parsed = (await onesFetchInPage(page, `team/${team}/task_statuses`, {
|
|
17
|
+
method: 'GET',
|
|
18
|
+
skipGoto,
|
|
19
|
+
})) as Record<string, unknown>;
|
|
20
|
+
const list = Array.isArray(parsed.task_statuses)
|
|
21
|
+
? (parsed.task_statuses as Record<string, unknown>[])
|
|
22
|
+
: [];
|
|
23
|
+
for (const s of list) {
|
|
24
|
+
const id = String(s.uuid ?? '');
|
|
25
|
+
const name = String(s.name ?? '');
|
|
26
|
+
if (id && name) map.set(id, name);
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
/* 降级为仅显示 uuid */
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PROJECT_INFO_CHUNK = 25;
|
|
35
|
+
|
|
36
|
+
export async function loadProjectLabels(
|
|
37
|
+
page: IPage,
|
|
38
|
+
team: string,
|
|
39
|
+
projectUuids: string[],
|
|
40
|
+
skipGoto: boolean,
|
|
41
|
+
): Promise<Map<string, string>> {
|
|
42
|
+
const map = new Map<string, string>();
|
|
43
|
+
const ids = [...new Set(projectUuids.filter(Boolean))];
|
|
44
|
+
if (ids.length === 0) return map;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
for (let i = 0; i < ids.length; i += PROJECT_INFO_CHUNK) {
|
|
48
|
+
const slice = ids.slice(i, i + PROJECT_INFO_CHUNK);
|
|
49
|
+
const q = slice.map(encodeURIComponent).join(',');
|
|
50
|
+
const path = `team/${team}/projects/info?ids=${q}`;
|
|
51
|
+
const parsed = (await onesFetchInPage(page, path, {
|
|
52
|
+
method: 'GET',
|
|
53
|
+
skipGoto,
|
|
54
|
+
})) as Record<string, unknown>;
|
|
55
|
+
const projects = Array.isArray(parsed.projects) ? (parsed.projects as Record<string, unknown>[]) : [];
|
|
56
|
+
for (const p of projects) {
|
|
57
|
+
const id = String(p.uuid ?? '');
|
|
58
|
+
const name = String(p.name ?? '');
|
|
59
|
+
if (id && name) map.set(id, name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
/* 降级 */
|
|
64
|
+
}
|
|
65
|
+
return map;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function resolveTaskListLabels(
|
|
69
|
+
page: IPage,
|
|
70
|
+
team: string,
|
|
71
|
+
entries: Record<string, unknown>[],
|
|
72
|
+
skipGoto: boolean,
|
|
73
|
+
): Promise<{ statusByUuid: Map<string, string>; projectByUuid: Map<string, string> }> {
|
|
74
|
+
const projectUuids = entries.map((e) => getTaskProjectRawId(e)).filter(Boolean);
|
|
75
|
+
const [statusByUuid, projectByUuid] = await Promise.all([
|
|
76
|
+
loadTaskStatusLabels(page, team, skipGoto),
|
|
77
|
+
loadProjectLabels(page, team, projectUuids, skipGoto),
|
|
78
|
+
]);
|
|
79
|
+
return { statusByUuid, projectByUuid };
|
|
80
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { parsePeekLimit } from './task-helpers.js';
|
|
3
|
+
|
|
4
|
+
describe('parsePeekLimit', () => {
|
|
5
|
+
it('returns the fallback when the input is not numeric', () => {
|
|
6
|
+
expect(parsePeekLimit('abc', 30)).toBe(30);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('clamps the input into the supported range', () => {
|
|
10
|
+
expect(parsePeekLimit('0', 30)).toBe(30);
|
|
11
|
+
expect(parsePeekLimit('999', 30)).toBe(500);
|
|
12
|
+
expect(parsePeekLimit('42', 30)).toBe(42);
|
|
13
|
+
});
|
|
14
|
+
});
|