@kevisual/cnb 0.0.57 → 0.0.58

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.
@@ -0,0 +1,2 @@
1
+ import './list.ts'
2
+ import './org.ts'
@@ -0,0 +1,137 @@
1
+ import { createSkill } from '@kevisual/router';
2
+ import { z } from 'zod';
3
+ import { app, cnbManager } from '../../app.ts';
4
+
5
+ // 获取当前用户顶层组织列表
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'list-top-groups',
9
+ description: '获取当前用户拥有权限的顶层组织列表',
10
+ middleware: ['auth'],
11
+ metadata: {
12
+ tags: ['opencode'],
13
+ ...createSkill({
14
+ skill: 'list-top-groups',
15
+ title: '获取顶层组织列表',
16
+ args: {
17
+ page: z.number().optional().describe('分页页码,默认: 1'),
18
+ page_size: z.number().optional().describe('分页每页大小,默认: 10'),
19
+ search: z.string().optional().describe('搜索过滤组织名称'),
20
+ role: z.enum(['Guest', 'Reporter', 'Developer', 'Master', 'Owner']).optional().describe('按角色过滤'),
21
+ },
22
+ summary: '获取当前用户拥有权限的顶层组织列表',
23
+ })
24
+ }
25
+ }).define(async (ctx) => {
26
+ const cnb = await cnbManager.getContext(ctx);
27
+ const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
28
+ const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
29
+ const search = ctx.query?.search;
30
+ const role = ctx.query?.role;
31
+
32
+ const res = await cnb.org.listTopGroups({ page, page_size, search, role });
33
+ ctx.forward(res);
34
+ }).addTo(app);
35
+
36
+ // 获取指定组织下的子组织列表
37
+ app.route({
38
+ path: 'cnb',
39
+ key: 'list-groups',
40
+ description: '获取指定组织下的子组织列表',
41
+ middleware: ['auth'],
42
+ metadata: {
43
+ tags: ['opencode'],
44
+ ...createSkill({
45
+ skill: 'list-groups',
46
+ title: '获取子组织列表',
47
+ args: {
48
+ slug: z.string().describe('组织路径,如 my-org'),
49
+ page: z.number().optional().describe('分页页码,默认: 1'),
50
+ page_size: z.number().optional().describe('分页每页大小,默认: 10'),
51
+ access: z.number().optional().describe('访问权限级别'),
52
+ },
53
+ summary: '获取指定组织下拥有权限的子组织列表',
54
+ })
55
+ }
56
+ }).define(async (ctx) => {
57
+ const cnb = await cnbManager.getContext(ctx);
58
+ const slug = ctx.query?.slug;
59
+ const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
60
+ const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
61
+ const access = ctx.query?.access ? Number(ctx.query.access) : undefined;
62
+
63
+ if (!slug) {
64
+ ctx.throw(400, '缺少参数 slug');
65
+ }
66
+
67
+ const res = await cnb.org.listGroups(slug, { page, page_size, access });
68
+ ctx.forward(res);
69
+ }).addTo(app);
70
+
71
+ // 获取指定组织下的子组织列表(不带权限过滤)
72
+ app.route({
73
+ path: 'cnb',
74
+ key: 'list-subgroups',
75
+ description: '获取指定组织下的子组织列表(不带权限过滤)',
76
+ middleware: ['auth'],
77
+ metadata: {
78
+ tags: ['opencode'],
79
+ ...createSkill({
80
+ skill: 'list-subgroups',
81
+ title: '获取子组织列表',
82
+ args: {
83
+ slug: z.string().describe('组织路径,如 my-org'),
84
+ search: z.string().optional().describe('搜索过滤子组织名称'),
85
+ page: z.number().optional().describe('分页页码,默认: 1'),
86
+ page_size: z.number().optional().describe('分页每页大小,默认: 10'),
87
+ },
88
+ summary: '获取指定组织下的子组织列表',
89
+ })
90
+ }
91
+ }).define(async (ctx) => {
92
+ const cnb = await cnbManager.getContext(ctx);
93
+ const slug = ctx.query?.slug;
94
+ const search = ctx.query?.search;
95
+ const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
96
+ const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
97
+
98
+ if (!slug) {
99
+ ctx.throw(400, '缺少参数 slug');
100
+ }
101
+
102
+ const res = await cnb.org.listSubgroups(slug, { search, page, page_size });
103
+ ctx.forward(res);
104
+ }).addTo(app);
105
+
106
+ // 获取指定用户拥有权限的组织列表
107
+ app.route({
108
+ path: 'cnb',
109
+ key: 'get-groups-by-username',
110
+ description: '获取指定用户拥有权限的组织列表',
111
+ middleware: ['auth'],
112
+ metadata: {
113
+ tags: [],
114
+ skill: 'get-groups-by-username',
115
+ title: '获取用户的组织列表',
116
+ args: {
117
+ username: z.string().describe('用户名'),
118
+ search: z.string().optional().describe('搜索过滤组织名称'),
119
+ page: z.number().optional().describe('分页页码,默认: 1'),
120
+ page_size: z.number().optional().describe('分页每页大小,默认: 10'),
121
+ },
122
+ summary: '获取指定用户拥有权限的组织列表',
123
+ }
124
+ }).define(async (ctx) => {
125
+ const cnb = await cnbManager.getContext(ctx);
126
+ const username = ctx.query?.username;
127
+ const search = ctx.query?.search;
128
+ const page = ctx.query?.page ? Number(ctx.query.page) : undefined;
129
+ const page_size = ctx.query?.page_size ? Number(ctx.query.page_size) : undefined;
130
+
131
+ if (!username) {
132
+ ctx.throw(400, '缺少参数 username');
133
+ }
134
+
135
+ const res = await cnb.org.getGroupsByUsername(username, { search, page, page_size });
136
+ ctx.forward(res);
137
+ }).addTo(app);
@@ -0,0 +1,241 @@
1
+ import { createSkill } from '@kevisual/router';
2
+ import { z } from 'zod';
3
+ import { app, cnbManager } from '../../app.ts';
4
+
5
+ // 创建组织
6
+ app.route({
7
+ path: 'cnb',
8
+ key: 'create-organization',
9
+ description: '创建新组织',
10
+ middleware: ['auth'],
11
+ metadata: {
12
+ tags: ['opencode'],
13
+ skill: 'create-organization',
14
+ title: '创建组织',
15
+ args: {
16
+ path: z.string().describe('组织路径'),
17
+ description: z.string().optional().describe('组织描述'),
18
+ bind_domain: z.string().optional().describe('根组织绑定的域名'),
19
+ remark: z.string().optional().describe('组织展示名称'),
20
+ },
21
+ summary: '创建一个新组织',
22
+ }
23
+ }).define(async (ctx) => {
24
+ const cnb = await cnbManager.getContext(ctx);
25
+ const path = ctx.query?.path;
26
+ const description = ctx.query?.description;
27
+ const bind_domain = ctx.query?.bind_domain;
28
+ const remark = ctx.query?.remark;
29
+
30
+ if (!path) {
31
+ ctx.throw(400, '缺少参数 path');
32
+ }
33
+
34
+ const res = await cnb.org.create({ path, description, bind_domain, remark });
35
+ ctx.forward(res);
36
+ }).addTo(app);
37
+
38
+ // 获取组织信息
39
+ app.route({
40
+ path: 'cnb',
41
+ key: 'get-organization',
42
+ description: '获取组织信息',
43
+ middleware: ['auth'],
44
+ metadata: {
45
+ tags: ['opencode'],
46
+ ...createSkill({
47
+ skill: 'get-organization',
48
+ title: '获取组织信息',
49
+ args: {
50
+ group: z.string().describe('组织路径'),
51
+ },
52
+ summary: '获取指定组织的信息',
53
+ })
54
+ }
55
+ }).define(async (ctx) => {
56
+ const cnb = await cnbManager.getContext(ctx);
57
+ const group = ctx.query?.group;
58
+
59
+ if (!group) {
60
+ ctx.throw(400, '缺少参数 group');
61
+ }
62
+
63
+ const res = await cnb.org.getGroup(group);
64
+ ctx.forward(res);
65
+ }).addTo(app);
66
+
67
+ // 更新组织信息
68
+ app.route({
69
+ path: 'cnb',
70
+ key: 'update-organization',
71
+ description: '更新组织信息',
72
+ middleware: ['auth'],
73
+ metadata: {
74
+ tags: ['opencode'],
75
+ ...createSkill({
76
+ skill: 'update-organization',
77
+ title: '更新组织信息',
78
+ args: {
79
+ group: z.string().describe('组织路径'),
80
+ description: z.string().optional().describe('组织描述'),
81
+ remark: z.string().optional().describe('组织展示名称'),
82
+ site: z.string().optional().describe('组织网站'),
83
+ email: z.string().optional().describe('组织联系邮箱'),
84
+ domain: z.string().optional().describe('绑定的域名'),
85
+ wechat_mp: z.string().optional().describe('微信公众号'),
86
+ },
87
+ summary: '更新组织信息,包括描述、展示名称、网站、邮箱等',
88
+ })
89
+ }
90
+ }).define(async (ctx) => {
91
+ const cnb = await cnbManager.getContext(ctx);
92
+ const group = ctx.query?.group;
93
+ const description = ctx.query?.description;
94
+ const remark = ctx.query?.remark;
95
+ const site = ctx.query?.site;
96
+ const email = ctx.query?.email;
97
+ const domain = ctx.query?.domain;
98
+ const wechat_mp = ctx.query?.wechat_mp;
99
+
100
+ if (!group) {
101
+ ctx.throw(400, '缺少参数 group');
102
+ }
103
+
104
+ const res = await cnb.org.updateGroup(group, { description, remark, site, email, domain, wechat_mp });
105
+ ctx.forward(res);
106
+ }).addTo(app);
107
+
108
+ // 删除组织
109
+ app.route({
110
+ path: 'cnb',
111
+ key: 'delete-organization',
112
+ description: '删除组织',
113
+ middleware: ['auth'],
114
+ metadata: {
115
+ skill: 'delete-organization',
116
+ title: '删除组织',
117
+ args: {
118
+ group: z.string().describe('组织路径'),
119
+ identityTicket: z.string().optional().describe('微信身份验证票据'),
120
+ },
121
+ summary: '删除指定组织',
122
+ }
123
+ }).define(async (ctx) => {
124
+ const cnb = await cnbManager.getContext(ctx);
125
+ const group = ctx.query?.group;
126
+ const identityTicket = ctx.query?.identityTicket;
127
+
128
+ if (!group) {
129
+ ctx.throw(400, '缺少参数 group');
130
+ }
131
+
132
+ const res = await cnb.org.deleteGroup(group, identityTicket);
133
+ ctx.forward(res);
134
+ }).addTo(app);
135
+
136
+ // 转移组织
137
+ app.route({
138
+ path: 'cnb',
139
+ key: 'transfer-organization',
140
+ description: '转移组织',
141
+ middleware: ['auth'],
142
+ metadata: {
143
+ skill: 'transfer-organization',
144
+ title: '转移组织',
145
+ args: {
146
+ group: z.string().describe('组织路径'),
147
+ source: z.string().describe('源组织路径'),
148
+ target: z.string().describe('目标组织路径'),
149
+ },
150
+ summary: '将组织从源路径转移到目标路径',
151
+ }
152
+ }).define(async (ctx) => {
153
+ const cnb = await cnbManager.getContext(ctx);
154
+ const group = ctx.query?.group;
155
+ const source = ctx.query?.source;
156
+ const target = ctx.query?.target;
157
+
158
+ if (!group || !source || !target) {
159
+ ctx.throw(400, '缺少参数 group, source 或 target');
160
+ }
161
+
162
+ const res = await cnb.org.transfer(group, { source, target });
163
+ ctx.forward(res);
164
+ }).addTo(app);
165
+
166
+ // 获取组织设置
167
+ app.route({
168
+ path: 'cnb',
169
+ key: 'get-organization-setting',
170
+ description: '获取组织配置详情',
171
+ middleware: ['auth'],
172
+ metadata: {
173
+ tags: ['opencode'],
174
+ ...createSkill({
175
+ skill: 'get-organization-setting',
176
+ title: '获取组织设置',
177
+ args: {
178
+ slug: z.string().describe('组织路径'),
179
+ },
180
+ summary: '获取指定组织的配置详情,包括可见性设置、邮箱验证等',
181
+ })
182
+ }
183
+ }).define(async (ctx) => {
184
+ const cnb = await cnbManager.getContext(ctx);
185
+ const slug = ctx.query?.slug;
186
+
187
+ if (!slug) {
188
+ ctx.throw(400, '缺少参数 slug');
189
+ }
190
+
191
+ const res = await cnb.org.getSetting(slug);
192
+ ctx.forward(res);
193
+ }).addTo(app);
194
+
195
+ // 更新组织设置
196
+ app.route({
197
+ path: 'cnb',
198
+ key: 'update-organization-setting',
199
+ description: '更新组织配置',
200
+ middleware: ['auth'],
201
+ metadata: {
202
+ tags: ['opencode'],
203
+ ...createSkill({
204
+ skill: 'update-organization-setting',
205
+ title: '更新组织设置',
206
+ args: {
207
+ slug: z.string().describe('组织路径'),
208
+ hide_members: z.number().optional().describe('是否对外隐藏组织成员,0 - 否, 1 - 是'),
209
+ hide_sub_groups: z.number().optional().describe('是否对外隐藏子组织,0 - 否, 1 - 是'),
210
+ show_private_repo_watermark: z.number().optional().describe('是否对外显示私有仓库水印,0 - 否, 1 - 是'),
211
+ group_protection: z.number().optional().describe('组织保护开关,0 - 关闭,1 - 打开'),
212
+ email_verification: z.array(z.string()).optional().describe('限制指定邮箱认证才能加入'),
213
+ values: z.string().optional().describe('组织设置值,多个选项用逗号拼接'),
214
+ },
215
+ summary: '更新组织配置,包括成员可见性、子组织可见性、水印等',
216
+ })
217
+ }
218
+ }).define(async (ctx) => {
219
+ const cnb = await cnbManager.getContext(ctx);
220
+ const slug = ctx.query?.slug;
221
+ const hide_members = ctx.query?.hide_members ? Number(ctx.query.hide_members) : undefined;
222
+ const hide_sub_groups = ctx.query?.hide_sub_groups ? Number(ctx.query.hide_sub_groups) : undefined;
223
+ const show_private_repo_watermark = ctx.query?.show_private_repo_watermark ? Number(ctx.query.show_private_repo_watermark) : undefined;
224
+ const group_protection = ctx.query?.group_protection ? Number(ctx.query.group_protection) : undefined;
225
+ const email_verification = ctx.query?.email_verification;
226
+ const values = ctx.query?.values;
227
+
228
+ if (!slug) {
229
+ ctx.throw(400, '缺少参数 slug');
230
+ }
231
+
232
+ const res = await cnb.org.updateSetting(slug, {
233
+ hide_members,
234
+ hide_sub_groups,
235
+ show_private_repo_watermark,
236
+ group_protection,
237
+ email_verification,
238
+ values,
239
+ });
240
+ ctx.forward(res);
241
+ }).addTo(app);
package/dist/cli.js CHANGED
@@ -25325,6 +25325,83 @@ class PackageManagement extends CNBCore {
25325
25325
  });
25326
25326
  }
25327
25327
  }
25328
+ // src/org/index.ts
25329
+ class Organization extends CNBCore {
25330
+ constructor(options) {
25331
+ super(options);
25332
+ }
25333
+ create(params) {
25334
+ return this.post({
25335
+ url: "/groups",
25336
+ data: params
25337
+ });
25338
+ }
25339
+ listTopGroups(params) {
25340
+ return this.get({
25341
+ url: "/user/groups",
25342
+ params
25343
+ });
25344
+ }
25345
+ listGroups(slug, params) {
25346
+ return this.get({
25347
+ url: `/user/groups/${slug}`,
25348
+ params
25349
+ });
25350
+ }
25351
+ getGroupsByUsername(username, params) {
25352
+ return this.get({
25353
+ url: `/users/${username}/groups`,
25354
+ params
25355
+ });
25356
+ }
25357
+ getGroup(group) {
25358
+ return this.get({
25359
+ url: `/${group}`
25360
+ });
25361
+ }
25362
+ updateGroup(group, params) {
25363
+ return this.put({
25364
+ url: `/${group}`,
25365
+ data: params
25366
+ });
25367
+ }
25368
+ deleteGroup(group, identityTicket) {
25369
+ return this.delete({
25370
+ url: `/${group}`,
25371
+ headers: identityTicket ? { "x-cnb-identity-ticket": identityTicket } : undefined
25372
+ });
25373
+ }
25374
+ transfer(group, params) {
25375
+ return this.post({
25376
+ url: `/${group}/-/transfer`,
25377
+ data: params
25378
+ });
25379
+ }
25380
+ uploadLogo(group, params) {
25381
+ return this.post({
25382
+ url: `/${group}/-/upload/logos`,
25383
+ data: params
25384
+ });
25385
+ }
25386
+ getSetting(slug) {
25387
+ return this.get({
25388
+ url: `/${slug}/-/settings`
25389
+ });
25390
+ }
25391
+ updateSetting(slug, params) {
25392
+ return this.put({
25393
+ url: `/${slug}/-/settings`,
25394
+ data: params
25395
+ });
25396
+ }
25397
+ listSubgroups(slug, params) {
25398
+ return this.get({
25399
+ url: `/${slug}/-/sub-groups`,
25400
+ params
25401
+ });
25402
+ }
25403
+ }
25404
+
25328
25405
  // src/index.ts
25329
25406
  class CNB extends CNBCore {
25330
25407
  workspace;
@@ -25337,6 +25414,7 @@ class CNB extends CNBCore {
25337
25414
  ai;
25338
25415
  labels;
25339
25416
  packages;
25417
+ org;
25340
25418
  constructor(options) {
25341
25419
  super({ ...options, token: options.token, cookie: options.cookie, cnb: options.cnb });
25342
25420
  this.init(options);
@@ -25363,6 +25441,7 @@ class CNB extends CNBCore {
25363
25441
  registry: new RegistryPackage(options),
25364
25442
  package: new PackageManagement(options)
25365
25443
  };
25444
+ this.org = new Organization(options);
25366
25445
  }
25367
25446
  setToken(token) {
25368
25447
  this.token = token;
@@ -25376,6 +25455,7 @@ class CNB extends CNBCore {
25376
25455
  this.labels.issueLabel.token = token;
25377
25456
  this.packages.registry.token = token;
25378
25457
  this.packages.package.token = token;
25458
+ this.org.token = token;
25379
25459
  }
25380
25460
  setCookie(cookie) {
25381
25461
  this.cookie = cookie;
@@ -25389,6 +25469,7 @@ class CNB extends CNBCore {
25389
25469
  this.labels.issueLabel.cookie = cookie;
25390
25470
  this.packages.registry.cookie = cookie;
25391
25471
  this.packages.package.cookie = cookie;
25472
+ this.org.cookie = cookie;
25392
25473
  }
25393
25474
  getCNBVersion = getCNBVersion;
25394
25475
  }
package/dist/npc.js CHANGED
@@ -25359,6 +25359,83 @@ class PackageManagement extends CNBCore {
25359
25359
  });
25360
25360
  }
25361
25361
  }
25362
+ // src/org/index.ts
25363
+ class Organization extends CNBCore {
25364
+ constructor(options) {
25365
+ super(options);
25366
+ }
25367
+ create(params) {
25368
+ return this.post({
25369
+ url: "/groups",
25370
+ data: params
25371
+ });
25372
+ }
25373
+ listTopGroups(params) {
25374
+ return this.get({
25375
+ url: "/user/groups",
25376
+ params
25377
+ });
25378
+ }
25379
+ listGroups(slug, params) {
25380
+ return this.get({
25381
+ url: `/user/groups/${slug}`,
25382
+ params
25383
+ });
25384
+ }
25385
+ getGroupsByUsername(username, params) {
25386
+ return this.get({
25387
+ url: `/users/${username}/groups`,
25388
+ params
25389
+ });
25390
+ }
25391
+ getGroup(group) {
25392
+ return this.get({
25393
+ url: `/${group}`
25394
+ });
25395
+ }
25396
+ updateGroup(group, params) {
25397
+ return this.put({
25398
+ url: `/${group}`,
25399
+ data: params
25400
+ });
25401
+ }
25402
+ deleteGroup(group, identityTicket) {
25403
+ return this.delete({
25404
+ url: `/${group}`,
25405
+ headers: identityTicket ? { "x-cnb-identity-ticket": identityTicket } : undefined
25406
+ });
25407
+ }
25408
+ transfer(group, params) {
25409
+ return this.post({
25410
+ url: `/${group}/-/transfer`,
25411
+ data: params
25412
+ });
25413
+ }
25414
+ uploadLogo(group, params) {
25415
+ return this.post({
25416
+ url: `/${group}/-/upload/logos`,
25417
+ data: params
25418
+ });
25419
+ }
25420
+ getSetting(slug) {
25421
+ return this.get({
25422
+ url: `/${slug}/-/settings`
25423
+ });
25424
+ }
25425
+ updateSetting(slug, params) {
25426
+ return this.put({
25427
+ url: `/${slug}/-/settings`,
25428
+ data: params
25429
+ });
25430
+ }
25431
+ listSubgroups(slug, params) {
25432
+ return this.get({
25433
+ url: `/${slug}/-/sub-groups`,
25434
+ params
25435
+ });
25436
+ }
25437
+ }
25438
+
25362
25439
  // src/index.ts
25363
25440
  class CNB extends CNBCore {
25364
25441
  workspace;
@@ -25371,6 +25448,7 @@ class CNB extends CNBCore {
25371
25448
  ai;
25372
25449
  labels;
25373
25450
  packages;
25451
+ org;
25374
25452
  constructor(options) {
25375
25453
  super({ ...options, token: options.token, cookie: options.cookie, cnb: options.cnb });
25376
25454
  this.init(options);
@@ -25397,6 +25475,7 @@ class CNB extends CNBCore {
25397
25475
  registry: new RegistryPackage(options),
25398
25476
  package: new PackageManagement(options)
25399
25477
  };
25478
+ this.org = new Organization(options);
25400
25479
  }
25401
25480
  setToken(token) {
25402
25481
  this.token = token;
@@ -25410,6 +25489,7 @@ class CNB extends CNBCore {
25410
25489
  this.labels.issueLabel.token = token;
25411
25490
  this.packages.registry.token = token;
25412
25491
  this.packages.package.token = token;
25492
+ this.org.token = token;
25413
25493
  }
25414
25494
  setCookie(cookie) {
25415
25495
  this.cookie = cookie;
@@ -25423,6 +25503,7 @@ class CNB extends CNBCore {
25423
25503
  this.labels.issueLabel.cookie = cookie;
25424
25504
  this.packages.registry.cookie = cookie;
25425
25505
  this.packages.package.cookie = cookie;
25506
+ this.org.cookie = cookie;
25426
25507
  }
25427
25508
  getCNBVersion = getCNBVersion;
25428
25509
  }