@leaflow/sdk 0.0.0-dev.113.g5d6fb99
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/dist/account/v1/index.d.ts +38 -0
- package/dist/account/v1/index.js +5 -0
- package/dist/account/v1/schema.d.ts +866 -0
- package/dist/account/v1/schema.js +5 -0
- package/dist/assistant/v1/index.d.ts +68 -0
- package/dist/assistant/v1/index.js +5 -0
- package/dist/assistant/v1/schema.d.ts +1884 -0
- package/dist/assistant/v1/schema.js +5 -0
- package/dist/canopy/v1/index.d.ts +36 -0
- package/dist/canopy/v1/index.js +5 -0
- package/dist/canopy/v1/schema.d.ts +1100 -0
- package/dist/canopy/v1/schema.js +5 -0
- package/dist/compute/v1/index.d.ts +200 -0
- package/dist/compute/v1/index.js +5 -0
- package/dist/compute/v1/schema.d.ts +4439 -0
- package/dist/compute/v1/schema.js +5 -0
- package/dist/gen/account/v1/schema.d.ts +866 -0
- package/dist/gen/account/v1/schema.js +5 -0
- package/dist/gen/assistant/v1/schema.d.ts +1884 -0
- package/dist/gen/assistant/v1/schema.js +5 -0
- package/dist/gen/canopy/v1/schema.d.ts +1100 -0
- package/dist/gen/canopy/v1/schema.js +5 -0
- package/dist/gen/compute/v1/schema.d.ts +4439 -0
- package/dist/gen/compute/v1/schema.js +5 -0
- package/dist/gen/iam/v1/schema.d.ts +1230 -0
- package/dist/gen/iam/v1/schema.js +5 -0
- package/dist/gen/monitoring/v1/schema.d.ts +2291 -0
- package/dist/gen/monitoring/v1/schema.js +5 -0
- package/dist/gen/tunnel/v1/schema.d.ts +845 -0
- package/dist/gen/tunnel/v1/schema.js +5 -0
- package/dist/iam/v1/index.d.ts +56 -0
- package/dist/iam/v1/index.js +5 -0
- package/dist/iam/v1/schema.d.ts +1230 -0
- package/dist/iam/v1/schema.js +5 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/monitoring/v1/index.d.ts +80 -0
- package/dist/monitoring/v1/index.js +5 -0
- package/dist/monitoring/v1/schema.d.ts +2291 -0
- package/dist/monitoring/v1/schema.js +5 -0
- package/dist/src/client.d.ts +57 -0
- package/dist/src/client.js +41 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +1 -0
- package/dist/tunnel/v1/index.d.ts +34 -0
- package/dist/tunnel/v1/index.js +5 -0
- package/dist/tunnel/v1/schema.d.ts +845 -0
- package/dist/tunnel/v1/schema.js +5 -0
- package/package.json +73 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { paths as AccountPaths } from "../gen/account/v1/schema.js";
|
|
2
|
+
import type { paths as AssistantPaths } from "../gen/assistant/v1/schema.js";
|
|
3
|
+
import type { paths as CanopyPaths } from "../gen/canopy/v1/schema.js";
|
|
4
|
+
import type { paths as ComputePaths } from "../gen/compute/v1/schema.js";
|
|
5
|
+
import type { paths as IamPaths } from "../gen/iam/v1/schema.js";
|
|
6
|
+
import type { paths as MonitoringPaths } from "../gen/monitoring/v1/schema.js";
|
|
7
|
+
import type { paths as TunnelPaths } from "../gen/tunnel/v1/schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* 令牌怎么拿到。
|
|
10
|
+
*
|
|
11
|
+
* 是个函数而不是一个字符串:项目令牌会过期,而它没有刷新接口——过期之后要拿账号令牌重新换一张
|
|
12
|
+
* (见 account.exchangeProjectToken)。传字符串的话,那次续期要调用方自己想起来重建整个
|
|
13
|
+
* 客户端,而忘了的表现是「用着用着就全是 401」。
|
|
14
|
+
*/
|
|
15
|
+
export type TokenSource = string | (() => string | Promise<string>);
|
|
16
|
+
export interface ClientOptions {
|
|
17
|
+
/** 网关地址,比如 https://api.leaflow.net */
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
/**
|
|
20
|
+
* 项目令牌。它同时说明当前用户和当前项目,所以**这里不传 projectId**——
|
|
21
|
+
* 当前项目由令牌断言,接口路径上也没有这个参数。要换项目就换一张令牌。
|
|
22
|
+
*/
|
|
23
|
+
token: TokenSource;
|
|
24
|
+
fetch?: typeof globalThis.fetch;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 账号 API 用的是**另一张令牌**,所以它有自己的入口。
|
|
28
|
+
*
|
|
29
|
+
* 账号令牌来自 auth.leaflow.net 的登录,只说明你是谁、不带任何项目;项目令牌是拿它去 IAM
|
|
30
|
+
* 换的。两者混用的表现是 401,而错误信息说不清是哪一张不对——分成两个入口之后,调用方在写
|
|
31
|
+
* 代码那一刻就得选对。
|
|
32
|
+
*/
|
|
33
|
+
export interface AccountClientOptions {
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
/** 账号令牌 */
|
|
36
|
+
token: TokenSource;
|
|
37
|
+
fetch?: typeof globalThis.fetch;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 一个项目令牌,七个服务。
|
|
41
|
+
*
|
|
42
|
+
* 每个服务是一个独立的客户端,各自认自己那份 schema —— 类型不跨服务共享。这不是为了整齐:
|
|
43
|
+
* compute 和 tunnel 各有一个 OperationLogResource,它们是两个不同的类型,合进一个命名空间
|
|
44
|
+
* 之后先声明的那个会盖掉另一个,而盖掉不报错。
|
|
45
|
+
*/
|
|
46
|
+
export declare function createClient(options: ClientOptions): {
|
|
47
|
+
assistant: import("openapi-fetch").Client<AssistantPaths, `${string}/${string}`>;
|
|
48
|
+
canopy: import("openapi-fetch").Client<CanopyPaths, `${string}/${string}`>;
|
|
49
|
+
compute: import("openapi-fetch").Client<ComputePaths, `${string}/${string}`>;
|
|
50
|
+
iam: import("openapi-fetch").Client<IamPaths, `${string}/${string}`>;
|
|
51
|
+
monitoring: import("openapi-fetch").Client<MonitoringPaths, `${string}/${string}`>;
|
|
52
|
+
tunnel: import("openapi-fetch").Client<TunnelPaths, `${string}/${string}`>;
|
|
53
|
+
};
|
|
54
|
+
/** 账号 API:注册、账号本身、我参与了哪些项目、换取项目令牌。 */
|
|
55
|
+
export declare function createAccountClient(options: AccountClientOptions): import("openapi-fetch").Client<AccountPaths, `${string}/${string}`>;
|
|
56
|
+
export type LeaflowClient = ReturnType<typeof createClient>;
|
|
57
|
+
export type AccountClient = ReturnType<typeof createAccountClient>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import createFetchClient, {} from "openapi-fetch";
|
|
2
|
+
async function resolveToken(source) {
|
|
3
|
+
return typeof source === "string" ? source : await source();
|
|
4
|
+
}
|
|
5
|
+
function authorization(source) {
|
|
6
|
+
return {
|
|
7
|
+
async onRequest({ request }) {
|
|
8
|
+
request.headers.set("Authorization", `Bearer ${await resolveToken(source)}`);
|
|
9
|
+
return request;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function build(options) {
|
|
14
|
+
const client = createFetchClient({
|
|
15
|
+
baseUrl: options.baseUrl,
|
|
16
|
+
fetch: options.fetch,
|
|
17
|
+
});
|
|
18
|
+
client.use(authorization(options.token));
|
|
19
|
+
return client;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 一个项目令牌,七个服务。
|
|
23
|
+
*
|
|
24
|
+
* 每个服务是一个独立的客户端,各自认自己那份 schema —— 类型不跨服务共享。这不是为了整齐:
|
|
25
|
+
* compute 和 tunnel 各有一个 OperationLogResource,它们是两个不同的类型,合进一个命名空间
|
|
26
|
+
* 之后先声明的那个会盖掉另一个,而盖掉不报错。
|
|
27
|
+
*/
|
|
28
|
+
export function createClient(options) {
|
|
29
|
+
return {
|
|
30
|
+
assistant: build(options),
|
|
31
|
+
canopy: build(options),
|
|
32
|
+
compute: build(options),
|
|
33
|
+
iam: build(options),
|
|
34
|
+
monitoring: build(options),
|
|
35
|
+
tunnel: build(options),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** 账号 API:注册、账号本身、我参与了哪些项目、换取项目令牌。 */
|
|
39
|
+
export function createAccountClient(options) {
|
|
40
|
+
return build(options);
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createClient, createAccountClient } from "./client.js";
|
|
2
|
+
export type { AccountClient, AccountClientOptions, ClientOptions, LeaflowClient, TokenSource, } from "./client.js";
|
|
3
|
+
export type { paths as AccountPaths, components as AccountTypes } from "../gen/account/v1/schema.js";
|
|
4
|
+
export type { paths as AssistantPaths, components as AssistantTypes } from "../gen/assistant/v1/schema.js";
|
|
5
|
+
export type { paths as CanopyPaths, components as CanopyTypes } from "../gen/canopy/v1/schema.js";
|
|
6
|
+
export type { paths as ComputePaths, components as ComputeTypes } from "../gen/compute/v1/schema.js";
|
|
7
|
+
export type { paths as IamPaths, components as IamTypes } from "../gen/iam/v1/schema.js";
|
|
8
|
+
export type { paths as MonitoringPaths, components as MonitoringTypes } from "../gen/monitoring/v1/schema.js";
|
|
9
|
+
export type { paths as TunnelPaths, components as TunnelTypes } from "../gen/tunnel/v1/schema.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createClient, createAccountClient } from "./client.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type { paths, components, operations, webhooks } from "./schema.js";
|
|
2
|
+
import type { operations } from "./schema.js";
|
|
3
|
+
/** `GET /api/v1/operation-logs` 成功时的响应体。 */
|
|
4
|
+
export type ListTunnelOperationLogsResult = operations["list-tunnel-operation-logs"]["responses"][200]["content"]["application/json"];
|
|
5
|
+
/** `GET /api/v1/plans` 成功时的响应体。 */
|
|
6
|
+
export type ListTunnelPlansResult = operations["list-tunnel-plans"]["responses"][200]["content"]["application/json"];
|
|
7
|
+
/** `DELETE /api/v1/tunnel` 成功时的响应体。 */
|
|
8
|
+
export type CloseTunnelResult = operations["close-tunnel"]["responses"][200]["content"]["application/json"];
|
|
9
|
+
/** `GET /api/v1/tunnel` 成功时的响应体。 */
|
|
10
|
+
export type GetTunnelResult = operations["get-tunnel"]["responses"][200]["content"]["application/json"];
|
|
11
|
+
/** `PATCH /api/v1/tunnel` 成功时的响应体。 */
|
|
12
|
+
export type UpdateTunnelProfileResult = operations["update-tunnel-profile"]["responses"][200]["content"]["application/json"];
|
|
13
|
+
/** `PATCH /api/v1/tunnel` 的请求体。 */
|
|
14
|
+
export type UpdateTunnelProfileBody = NonNullable<operations["update-tunnel-profile"]["requestBody"]>["content"]["application/json"];
|
|
15
|
+
/** `POST /api/v1/tunnel` 成功时的响应体。 */
|
|
16
|
+
export type OpenTunnelResult = operations["open-tunnel"]["responses"][201]["content"]["application/json"];
|
|
17
|
+
/** `POST /api/v1/tunnel` 的请求体。 */
|
|
18
|
+
export type OpenTunnelBody = NonNullable<operations["open-tunnel"]["requestBody"]>["content"]["application/json"];
|
|
19
|
+
/** `POST /api/v1/tunnel/actions` 成功时的响应体。 */
|
|
20
|
+
export type ActOnTunnelResult = operations["act-on-tunnel"]["responses"][200]["content"]["application/json"];
|
|
21
|
+
/** `POST /api/v1/tunnel/actions` 的请求体。 */
|
|
22
|
+
export type ActOnTunnelBody = NonNullable<operations["act-on-tunnel"]["requestBody"]>["content"]["application/json"];
|
|
23
|
+
/** `PUT /api/v1/tunnel/plan` 成功时的响应体。 */
|
|
24
|
+
export type ChangeTunnelPlanResult = operations["change-tunnel-plan"]["responses"][200]["content"]["application/json"];
|
|
25
|
+
/** `PUT /api/v1/tunnel/plan` 的请求体。 */
|
|
26
|
+
export type ChangeTunnelPlanBody = NonNullable<operations["change-tunnel-plan"]["requestBody"]>["content"]["application/json"];
|
|
27
|
+
/** `GET /api/v1/tunnel/subscription` 成功时的响应体。 */
|
|
28
|
+
export type GetTunnelSubscriptionResult = operations["get-tunnel-subscription"]["responses"][200]["content"]["application/json"];
|
|
29
|
+
/** `POST /api/v1/tunnel/subscription/rotate` 成功时的响应体。 */
|
|
30
|
+
export type RotateTunnelSubscriptionResult = operations["rotate-tunnel-subscription"]["responses"][200]["content"]["application/json"];
|
|
31
|
+
/** `GET /api/v1/tunnel/usage` 成功时的响应体。 */
|
|
32
|
+
export type GetTunnelUsageResult = operations["get-tunnel-usage"]["responses"][200]["content"]["application/json"];
|
|
33
|
+
/** `GET /api/v1/tunnel/usage/series` 成功时的响应体。 */
|
|
34
|
+
export type ListTunnelUsageSeriesResult = operations["list-tunnel-usage-series"]["responses"][200]["content"]["application/json"];
|