在线 Access 插件
读取父 Skill 的 references/online-yaml-format.md。不要沿用代码版 @IsAccess、@AccessInput 装饰器和独立 TypeScript 文件。
输出结构
pluginType使用access。input中声明用户需要填写的授权字段。- 敏感字段在 input 中设置加密或密码类组件。
content中实现授权 class 和 API 方法。
content 模板
const { BaseAccess } = await _ctx.import("@certd/pipeline")
return class DemoAccess extends BaseAccess {
demoKeyId
demoKeySecret
async onTestRequest() {
await this.getDomainList({ searchKey: "" })
return "ok"
}
async getDomainList(req) {
this.logger.info("获取域名列表", { searchKey: req.searchKey })
const res = await this.ctx.http.request({
url: "https://api.example.com/domains",
method: "GET",
params: { keyword: req.searchKey },
})
if (res.error) {
throw new Error(`获取域名列表失败: ${res.message}`)
}
return {
total: res.data?.total || 0,
list: res.data?.list || [],
}
}
}
编写要求
- 统一使用
await _ctx.import(...)加载模块。 - 使用
_ctx.import("/@/...")通过绝对路径加载server/src/下的模块,/@代表server/src根路径。 - 需要记录模块加载信息时使用
_ctx.logger,访问执行日志使用this.logger。 - 返回继承
BaseAccess的 class,不使用装饰器。 - class 属性名必须与 YAML
input字段一致。 - 所有敏感授权值只通过
this和 Certd 授权上下文使用,不打印真实值。 onTestRequest应调用实际 API 方法并在失败时抛出异常。- 对外 API 方法应统一处理分页、错误和返回字段。
- 使用
this.logger或框架提供的 logger,禁止console.log。 - 一般将API接口方法封装到Access中,其他plugin调用access的方法当做client sdk使用