api2key-base-sdk 0.1.1 → 0.1.3
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 +100 -131
- package/dist/admin/client.d.ts +159 -0
- package/dist/admin/client.js +211 -0
- package/dist/auth/client.d.ts +1 -0
- package/dist/core/client.d.ts +2 -0
- package/dist/core/client.js +11 -3
- package/dist/core/types.d.ts +277 -0
- package/dist/index.d.ts +27 -7
- package/dist/index.js +33 -8
- package/dist/orders/client.d.ts +16 -0
- package/dist/orders/client.js +24 -0
- package/dist/projects/client.d.ts +11 -1
- package/dist/projects/client.js +13 -2
- package/dist/user/api-keys-client.d.ts +19 -0
- package/dist/user/api-keys-client.js +30 -0
- package/dist/user/settings-client.d.ts +11 -0
- package/dist/user/settings-client.js +17 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,181 +1,150 @@
|
|
|
1
1
|
# api2key-base-sdk
|
|
2
2
|
|
|
3
|
-
`api2key-base-sdk`
|
|
3
|
+
`api2key-base-sdk` 是当前唯一保留的 SDK 入口,统一承载基础平台能力、项目运行时能力和后台管理客户端。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
适合放进所有新项目作为默认基础依赖。
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 当前边界
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
当前统一暴露:
|
|
10
10
|
|
|
11
|
-
1.
|
|
12
|
-
2.
|
|
13
|
-
3.
|
|
14
|
-
4.
|
|
15
|
-
5.
|
|
11
|
+
1. `auth`
|
|
12
|
+
2. `credits`
|
|
13
|
+
3. `apiKeys`
|
|
14
|
+
4. `settings`
|
|
15
|
+
5. `projects`
|
|
16
|
+
6. `orders`
|
|
17
|
+
7. `payment`
|
|
18
|
+
8. `ai`
|
|
19
|
+
9. `admin`
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
安装原则:
|
|
18
22
|
|
|
19
|
-
1.
|
|
20
|
-
2.
|
|
21
|
-
3.
|
|
22
|
-
4. 子项目容易误依赖平台内部实现,造成耦合失控
|
|
23
|
+
1. 所有新项目默认只安装 `api2key-base-sdk`
|
|
24
|
+
2. 后台项目也只安装 `api2key-base-sdk`
|
|
25
|
+
3. 单项目私有逻辑优先留在本地 facade,而不是再拆新的 SDK 包
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
## 暴露的客户端
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
当前 `api2key-base-sdk` 暴露以下客户端:
|
|
27
30
|
|
|
28
|
-
1.
|
|
29
|
-
2.
|
|
30
|
-
3.
|
|
31
|
-
4.
|
|
31
|
+
1. `auth`
|
|
32
|
+
2. `credits`
|
|
33
|
+
3. `apiKeys`
|
|
34
|
+
4. `settings`
|
|
35
|
+
5. `projects`
|
|
36
|
+
6. `orders`
|
|
37
|
+
7. `payment`
|
|
38
|
+
8. `ai`
|
|
39
|
+
9. `admin`
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
### 1. `auth`
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
负责稳定的用户认证能力。
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
2. 你有多个独立部署的业务项目,需要复用平台提供的公共能力
|
|
39
|
-
3. 你希望业务项目只关心自身业务逻辑,而不是重复实现认证、支付、积分、模型等底层接入
|
|
45
|
+
当前主要方法:
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
1. `login(input)`
|
|
48
|
+
2. `register(input)`
|
|
49
|
+
3. `me(accessToken?)`
|
|
50
|
+
4. `logout(accessToken?)`
|
|
42
51
|
|
|
43
|
-
|
|
52
|
+
### 2. `credits`
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
2. `projects`:项目商品、项目会员、项目权限相关接口
|
|
47
|
-
3. `payment`:支付创建与支付状态查询接口
|
|
48
|
-
4. `credits`:积分余额、流水、预扣、确认、取消、消费接口
|
|
49
|
-
5. `ai`:AI 模型列表与 AI 余额接口
|
|
54
|
+
负责稳定的积分账户与服务侧扣减能力。
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
当前主要方法包括:
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
1. Node.js 版本需要 `>=18`
|
|
60
|
-
2. 平台服务已经对外提供稳定的 `/api/v1` 路由
|
|
61
|
-
3. 你的业务项目可以拿到平台服务地址,以及所需的访问令牌或服务密钥
|
|
62
|
-
|
|
63
|
-
## 快速开始
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { createPlatformAClient } from 'api2key-base-sdk';
|
|
67
|
-
|
|
68
|
-
const platformA = createPlatformAClient({
|
|
69
|
-
baseUrl: process.env.PLATFORM_A_BASE_URL!,
|
|
70
|
-
getServiceSecret: () => process.env.PLATFORM_A_SERVICE_SECRET,
|
|
71
|
-
getProjectId: () => process.env.PLATFORM_A_PROJECT_ID,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const products = await platformA.projects.getProducts('project-b');
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
上面的示例做了三件事:
|
|
78
|
-
|
|
79
|
-
1. 指定平台基座服务地址 `baseUrl`
|
|
80
|
-
2. 提供服务间调用所需的密钥 `getServiceSecret`
|
|
81
|
-
3. 提供当前业务项目标识 `getProjectId`
|
|
82
|
-
|
|
83
|
-
然后就可以直接通过 `platformA.projects.getProducts('project-b')` 调用平台对外能力,而不需要在业务项目里重复拼接请求。
|
|
58
|
+
1. `getBalance(accessToken?)`
|
|
59
|
+
2. `getLedger(input)`(仅管理员账号可查询当前账户积分消耗流水,普通用户前台不应依赖)
|
|
60
|
+
3. `spend(input)`
|
|
61
|
+
4. `reserve(input)`
|
|
62
|
+
5. `confirm(id)`
|
|
63
|
+
6. `cancel(id)`
|
|
84
64
|
|
|
85
|
-
|
|
65
|
+
### 3. `apiKeys`
|
|
86
66
|
|
|
87
|
-
|
|
67
|
+
负责用户 API Key 生命周期管理。
|
|
88
68
|
|
|
89
|
-
|
|
90
|
-
2. `fetchImpl`:自定义 `fetch` 实现
|
|
91
|
-
3. `defaultHeaders`:默认请求头
|
|
92
|
-
4. `getAccessToken`:获取用户访问令牌
|
|
93
|
-
5. `getServiceSecret`:获取服务间调用密钥
|
|
94
|
-
6. `getProjectId`:获取当前项目标识
|
|
69
|
+
### 4. `settings`
|
|
95
70
|
|
|
96
|
-
|
|
71
|
+
负责用户级设置的读取与更新。
|
|
97
72
|
|
|
98
|
-
|
|
73
|
+
### 5. `projects / orders / payment / ai`
|
|
99
74
|
|
|
100
|
-
|
|
75
|
+
负责项目商品、会员、订单、支付、AI 等运行时能力。
|
|
101
76
|
|
|
102
|
-
|
|
77
|
+
### 6. `admin`
|
|
103
78
|
|
|
104
|
-
|
|
105
|
-
2. 注册
|
|
106
|
-
3. 获取当前用户信息
|
|
107
|
-
4. 退出登录
|
|
79
|
+
负责项目管理、产品管理、用户管理、会员管理、模型管理、后台积分操作等控制面能力。
|
|
108
80
|
|
|
109
|
-
|
|
81
|
+
## 适合哪些项目
|
|
110
82
|
|
|
111
|
-
|
|
83
|
+
适合:
|
|
112
84
|
|
|
113
|
-
1.
|
|
114
|
-
2.
|
|
115
|
-
3.
|
|
85
|
+
1. 所有新项目
|
|
86
|
+
2. 只需要登录、积分、用户设置、API Key 的项目
|
|
87
|
+
3. 需要一个长期稳定基础依赖的项目
|
|
116
88
|
|
|
117
|
-
|
|
89
|
+
适合同一个 SDK 内统一暴露所有共享客户端,但不适合把某个单项目专属兼容逻辑强行塞进共享包。
|
|
118
90
|
|
|
119
|
-
|
|
91
|
+
## 安装
|
|
120
92
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
### credits
|
|
125
|
-
|
|
126
|
-
用于积分体系接入,例如:
|
|
127
|
-
|
|
128
|
-
1. 查询余额
|
|
129
|
-
2. 查询流水
|
|
130
|
-
3. 预扣积分
|
|
131
|
-
4. 确认扣减
|
|
132
|
-
5. 取消预扣
|
|
133
|
-
6. 直接消费积分
|
|
134
|
-
|
|
135
|
-
### ai
|
|
93
|
+
```bash
|
|
94
|
+
npm install api2key-base-sdk
|
|
95
|
+
```
|
|
136
96
|
|
|
137
|
-
|
|
97
|
+
## 使用示例
|
|
138
98
|
|
|
139
|
-
|
|
140
|
-
|
|
99
|
+
```ts
|
|
100
|
+
import { createBasePlatformClient } from 'api2key-base-sdk';
|
|
141
101
|
|
|
142
|
-
|
|
102
|
+
const baseClient = createBasePlatformClient({
|
|
103
|
+
baseUrl: process.env.API2KEY_BASE_URL!,
|
|
104
|
+
getAccessToken: () => process.env.ACCESS_TOKEN,
|
|
105
|
+
getServiceSecret: () => process.env.SERVICE_SECRET,
|
|
106
|
+
});
|
|
143
107
|
|
|
144
|
-
|
|
108
|
+
const me = await baseClient.auth.me();
|
|
109
|
+
const credits = await baseClient.credits.getBalance();
|
|
145
110
|
|
|
146
|
-
|
|
147
|
-
|
|
111
|
+
const projectClient = createProjectPlatformClient({
|
|
112
|
+
baseUrl: process.env.API2KEY_BASE_URL!,
|
|
113
|
+
getAccessToken: () => process.env.ACCESS_TOKEN,
|
|
114
|
+
getProjectId: () => process.env.PROJECT_ID,
|
|
115
|
+
});
|
|
148
116
|
|
|
149
|
-
|
|
117
|
+
const adminClient = createAdminPlatformClient({
|
|
118
|
+
baseUrl: process.env.API2KEY_BASE_URL!,
|
|
119
|
+
getAccessToken: () => process.env.ADMIN_ACCESS_TOKEN,
|
|
120
|
+
});
|
|
150
121
|
|
|
151
|
-
|
|
122
|
+
const products = await projectClient.projects.getCatalogProducts(process.env.PROJECT_ID!);
|
|
123
|
+
const projects = await adminClient.admin.listProjects();
|
|
124
|
+
```
|
|
152
125
|
|
|
153
|
-
|
|
126
|
+
## 设计原则
|
|
154
127
|
|
|
155
|
-
1.
|
|
156
|
-
2.
|
|
157
|
-
3.
|
|
158
|
-
4. 平台升级时只需要升级 SDK,而不是逐个修改业务项目
|
|
128
|
+
1. 新项目默认只依赖这个包
|
|
129
|
+
2. 共享客户端统一收敛在一个包里
|
|
130
|
+
3. `api2key-base-api` 可以继续保持清晰的路由分层,而不需要在消费侧安装多个 SDK
|
|
159
131
|
|
|
160
|
-
##
|
|
132
|
+
## Agent 约定
|
|
161
133
|
|
|
162
|
-
|
|
134
|
+
后续 agent 在处理需求时,默认把这个包视为“稳定基础层”。
|
|
163
135
|
|
|
164
|
-
|
|
165
|
-
2. 通过 Git tag 触发自动发布
|
|
166
|
-
3. tag 格式为 `v*`
|
|
167
|
-
4. tag 里的版本号必须与 `package.json` 中的版本号一致
|
|
168
|
-
5. GitHub Actions 优先建议使用 npm trusted publishing;如果使用 `NPM_TOKEN`,则必须是启用了 `Bypass 2FA` 的 npm granular publish token
|
|
136
|
+
规则:
|
|
169
137
|
|
|
170
|
-
|
|
138
|
+
1. 如果需求属于共享客户端能力,优先在这里找
|
|
139
|
+
2. 后端路由边界仍按 base/project/admin 区分,不要因为 SDK 合并而改乱 API 归属
|
|
140
|
+
3. 如果新需求只服务单个项目,优先留在项目本地 facade
|
|
171
141
|
|
|
172
|
-
|
|
173
|
-
git tag v0.1.0
|
|
174
|
-
git push origin v0.1.0
|
|
175
|
-
```
|
|
142
|
+
## 兼容说明
|
|
176
143
|
|
|
177
|
-
|
|
144
|
+
当前仍保留 `createPlatformAClient` 作为过渡别名,它返回基础能力客户端。
|
|
178
145
|
|
|
179
|
-
|
|
146
|
+
建议新代码统一使用:
|
|
180
147
|
|
|
181
|
-
|
|
148
|
+
- `createBasePlatformClient`
|
|
149
|
+
- `createProjectPlatformClient`
|
|
150
|
+
- `createAdminPlatformClient`
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { PlatformHttpClient } from '../core/client';
|
|
2
|
+
import type { AdminConfigItem, AdminMembershipFilters, AdminMembershipRecord, AdminModelInput, AdminModelRecord, AdminOrderFilters, AdminOrderRecord, AdminProduct, AdminProductBackfillResult, AdminProductListResult, AdminProject, AdminProjectExportFormat, AdminUserCreditsSummary, AdminUserRecord, UpdateAdminUserInput } from '../core/types';
|
|
3
|
+
export declare class AdminClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: PlatformHttpClient);
|
|
6
|
+
listProjects(accessToken?: string): Promise<{
|
|
7
|
+
projects: AdminProject[];
|
|
8
|
+
}>;
|
|
9
|
+
createProject(input: {
|
|
10
|
+
name: string;
|
|
11
|
+
slug: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
logoUrl?: string;
|
|
14
|
+
settings?: Record<string, unknown>;
|
|
15
|
+
}, accessToken?: string): Promise<{
|
|
16
|
+
project: AdminProject;
|
|
17
|
+
}>;
|
|
18
|
+
updateProject(input: {
|
|
19
|
+
id: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
logoUrl?: string;
|
|
23
|
+
status?: 'active' | 'inactive';
|
|
24
|
+
settings?: Record<string, unknown>;
|
|
25
|
+
}, accessToken?: string): Promise<null>;
|
|
26
|
+
deleteProject(id: string, accessToken?: string): Promise<null>;
|
|
27
|
+
exportProject(id: string, format?: AdminProjectExportFormat, accessToken?: string): Promise<unknown>;
|
|
28
|
+
listProducts(projectId?: string, accessToken?: string): Promise<AdminProductListResult>;
|
|
29
|
+
createProduct(input: Omit<AdminProduct, 'id'>, accessToken?: string): Promise<AdminProduct>;
|
|
30
|
+
updateProduct(input: AdminProduct, accessToken?: string): Promise<AdminProduct>;
|
|
31
|
+
deleteProduct(id: string, accessToken?: string): Promise<null>;
|
|
32
|
+
backfillProductsProject(input: {
|
|
33
|
+
projectId: string;
|
|
34
|
+
productIds?: string[];
|
|
35
|
+
}, accessToken?: string): Promise<AdminProductBackfillResult>;
|
|
36
|
+
listMemberships(filters?: AdminMembershipFilters, accessToken?: string): Promise<{
|
|
37
|
+
memberships: AdminMembershipRecord[];
|
|
38
|
+
unboundUsers: Array<{
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
name: string | null;
|
|
42
|
+
role: string;
|
|
43
|
+
status: string;
|
|
44
|
+
currentProject: {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
slug: string;
|
|
48
|
+
} | null;
|
|
49
|
+
membershipCount: number;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
createMembership(input: {
|
|
53
|
+
scopeType: 'project' | 'global';
|
|
54
|
+
userId?: string;
|
|
55
|
+
email?: string;
|
|
56
|
+
projectId?: string;
|
|
57
|
+
role?: string;
|
|
58
|
+
tier: string;
|
|
59
|
+
status?: 'active' | 'expired' | 'cancelled';
|
|
60
|
+
credits?: number;
|
|
61
|
+
startDate?: number | null;
|
|
62
|
+
endDate?: number | null;
|
|
63
|
+
autoRenew?: boolean;
|
|
64
|
+
}, accessToken?: string): Promise<{
|
|
65
|
+
membershipId: string;
|
|
66
|
+
scopeType: 'project' | 'global';
|
|
67
|
+
}>;
|
|
68
|
+
updateMembership(input: {
|
|
69
|
+
id: string;
|
|
70
|
+
scopeType: 'project' | 'global';
|
|
71
|
+
projectId?: string;
|
|
72
|
+
role?: string;
|
|
73
|
+
tier?: string;
|
|
74
|
+
status?: 'active' | 'expired' | 'cancelled';
|
|
75
|
+
credits?: number;
|
|
76
|
+
startDate?: number | null;
|
|
77
|
+
endDate?: number | null;
|
|
78
|
+
autoRenew?: boolean;
|
|
79
|
+
}, accessToken?: string): Promise<{
|
|
80
|
+
id: string;
|
|
81
|
+
}>;
|
|
82
|
+
deleteMembership(id: string, scopeType: 'project' | 'global', accessToken?: string): Promise<null>;
|
|
83
|
+
listUsers(filters?: {
|
|
84
|
+
search?: string;
|
|
85
|
+
projectId?: string;
|
|
86
|
+
status?: 'active' | 'disabled' | 'banned';
|
|
87
|
+
limit?: number;
|
|
88
|
+
}, accessToken?: string): Promise<{
|
|
89
|
+
users: AdminUserRecord[];
|
|
90
|
+
}>;
|
|
91
|
+
updateUser(input: UpdateAdminUserInput, accessToken?: string): Promise<{
|
|
92
|
+
userId: string;
|
|
93
|
+
name?: string | null;
|
|
94
|
+
status?: string;
|
|
95
|
+
projectId: string | null;
|
|
96
|
+
membershipTier?: string | null;
|
|
97
|
+
membershipStatus?: string | null;
|
|
98
|
+
membershipCredits?: number;
|
|
99
|
+
creditsBalance?: number;
|
|
100
|
+
}>;
|
|
101
|
+
updateUserProject(input: {
|
|
102
|
+
userId: string;
|
|
103
|
+
projectId?: string | null;
|
|
104
|
+
}, accessToken?: string): Promise<{
|
|
105
|
+
userId: string;
|
|
106
|
+
projectId: string | null;
|
|
107
|
+
}>;
|
|
108
|
+
deleteUsers(userIds: string[], accessToken?: string): Promise<{
|
|
109
|
+
deleted: Array<{
|
|
110
|
+
id: string;
|
|
111
|
+
email: string;
|
|
112
|
+
}>;
|
|
113
|
+
skipped: Array<{
|
|
114
|
+
id: string;
|
|
115
|
+
email?: string | null;
|
|
116
|
+
reason: string;
|
|
117
|
+
}>;
|
|
118
|
+
}>;
|
|
119
|
+
listOrders(filters?: AdminOrderFilters, accessToken?: string): Promise<{
|
|
120
|
+
orders: AdminOrderRecord[];
|
|
121
|
+
}>;
|
|
122
|
+
getConfig(accessToken?: string): Promise<{
|
|
123
|
+
configs: AdminConfigItem[];
|
|
124
|
+
}>;
|
|
125
|
+
updateConfig(input: {
|
|
126
|
+
key: string;
|
|
127
|
+
value: string;
|
|
128
|
+
}, accessToken?: string): Promise<AdminConfigItem>;
|
|
129
|
+
grantCredits(input: {
|
|
130
|
+
userId: string;
|
|
131
|
+
amount: number;
|
|
132
|
+
description?: string;
|
|
133
|
+
taskId?: string;
|
|
134
|
+
}, accessToken?: string): Promise<{
|
|
135
|
+
balanceAfter: number;
|
|
136
|
+
idempotent?: boolean;
|
|
137
|
+
}>;
|
|
138
|
+
getUserCredits(userId: string, accessToken?: string): Promise<AdminUserCreditsSummary>;
|
|
139
|
+
listManagedModels(accessToken?: string): Promise<{
|
|
140
|
+
models: AdminModelRecord[];
|
|
141
|
+
warning?: string | null;
|
|
142
|
+
schemaReady?: boolean;
|
|
143
|
+
}>;
|
|
144
|
+
createManagedModel(input: AdminModelInput, accessToken?: string): Promise<{
|
|
145
|
+
model: AdminModelRecord;
|
|
146
|
+
}>;
|
|
147
|
+
updateManagedModel(id: string, input: Partial<AdminModelInput>, accessToken?: string): Promise<{
|
|
148
|
+
model: AdminModelRecord;
|
|
149
|
+
}>;
|
|
150
|
+
deleteManagedModel(id: string, accessToken?: string): Promise<void>;
|
|
151
|
+
bulkDeleteManagedModels(ids: string[], accessToken?: string): Promise<{
|
|
152
|
+
deletedCount: number;
|
|
153
|
+
}>;
|
|
154
|
+
importManagedModels(input: AdminModelInput[], accessToken?: string): Promise<{
|
|
155
|
+
models: AdminModelRecord[];
|
|
156
|
+
count: number;
|
|
157
|
+
}>;
|
|
158
|
+
flushManagedModelCache(accessToken?: string): Promise<void>;
|
|
159
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
export class AdminClient {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
listProjects(accessToken) {
|
|
6
|
+
return this.http.request('/api/v1/admin/projects', { accessToken });
|
|
7
|
+
}
|
|
8
|
+
createProject(input, accessToken) {
|
|
9
|
+
return this.http.request('/api/v1/admin/projects', {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: input,
|
|
12
|
+
accessToken,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
updateProject(input, accessToken) {
|
|
16
|
+
return this.http.request('/api/v1/admin/projects', {
|
|
17
|
+
method: 'PUT',
|
|
18
|
+
body: input,
|
|
19
|
+
accessToken,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
deleteProject(id, accessToken) {
|
|
23
|
+
return this.http.request('/api/v1/admin/projects', {
|
|
24
|
+
method: 'DELETE',
|
|
25
|
+
query: { id },
|
|
26
|
+
accessToken,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async exportProject(id, format = 'openapi', accessToken) {
|
|
30
|
+
const response = await this.http.requestRaw(`/api/v1/admin/projects/${id}/export`, {
|
|
31
|
+
query: { format },
|
|
32
|
+
accessToken,
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
const payload = await response.json().catch(() => null);
|
|
36
|
+
throw new Error(payload?.message ?? `Export failed with HTTP ${response.status}`);
|
|
37
|
+
}
|
|
38
|
+
const contentType = response.headers.get('Content-Type') ?? '';
|
|
39
|
+
if (contentType.includes('application/json')) {
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
return response.text();
|
|
43
|
+
}
|
|
44
|
+
listProducts(projectId, accessToken) {
|
|
45
|
+
return this.http.request('/api/v1/admin/products', {
|
|
46
|
+
query: { projectId },
|
|
47
|
+
accessToken,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
createProduct(input, accessToken) {
|
|
51
|
+
return this.http.request('/api/v1/admin/products', {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: input,
|
|
54
|
+
accessToken,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
updateProduct(input, accessToken) {
|
|
58
|
+
return this.http.request('/api/v1/admin/products', {
|
|
59
|
+
method: 'PUT',
|
|
60
|
+
body: input,
|
|
61
|
+
accessToken,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
deleteProduct(id, accessToken) {
|
|
65
|
+
return this.http.request('/api/v1/admin/products', {
|
|
66
|
+
method: 'DELETE',
|
|
67
|
+
query: { id },
|
|
68
|
+
accessToken,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
backfillProductsProject(input, accessToken) {
|
|
72
|
+
return this.http.request('/api/v1/admin/products/backfill-project', {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
body: input,
|
|
75
|
+
accessToken,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
listMemberships(filters = {}, accessToken) {
|
|
79
|
+
return this.http.request('/api/v1/admin/memberships', {
|
|
80
|
+
query: {
|
|
81
|
+
scope: filters.scope,
|
|
82
|
+
projectId: filters.projectId,
|
|
83
|
+
status: filters.status,
|
|
84
|
+
tier: filters.tier,
|
|
85
|
+
search: filters.search,
|
|
86
|
+
},
|
|
87
|
+
accessToken,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
createMembership(input, accessToken) {
|
|
91
|
+
return this.http.request('/api/v1/admin/memberships', {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
body: input,
|
|
94
|
+
accessToken,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
updateMembership(input, accessToken) {
|
|
98
|
+
return this.http.request('/api/v1/admin/memberships', {
|
|
99
|
+
method: 'PUT',
|
|
100
|
+
body: input,
|
|
101
|
+
accessToken,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
deleteMembership(id, scopeType, accessToken) {
|
|
105
|
+
return this.http.request('/api/v1/admin/memberships', {
|
|
106
|
+
method: 'DELETE',
|
|
107
|
+
query: { id, scopeType },
|
|
108
|
+
accessToken,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
listUsers(filters = {}, accessToken) {
|
|
112
|
+
return this.http.request('/api/v1/admin/users', {
|
|
113
|
+
query: filters,
|
|
114
|
+
accessToken,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
updateUser(input, accessToken) {
|
|
118
|
+
return this.http.request('/api/v1/admin/users', {
|
|
119
|
+
method: 'PUT',
|
|
120
|
+
body: input,
|
|
121
|
+
accessToken,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
updateUserProject(input, accessToken) {
|
|
125
|
+
return this.updateUser(input, accessToken);
|
|
126
|
+
}
|
|
127
|
+
deleteUsers(userIds, accessToken) {
|
|
128
|
+
return this.http.request('/api/v1/admin/users', {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
body: { userIds },
|
|
131
|
+
accessToken,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
listOrders(filters = {}, accessToken) {
|
|
135
|
+
return this.http.request('/api/v1/admin/orders', {
|
|
136
|
+
query: {
|
|
137
|
+
search: filters.search,
|
|
138
|
+
status: filters.status,
|
|
139
|
+
projectId: filters.projectId,
|
|
140
|
+
userId: filters.userId,
|
|
141
|
+
limit: filters.limit,
|
|
142
|
+
},
|
|
143
|
+
accessToken,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
getConfig(accessToken) {
|
|
147
|
+
return this.http.request('/api/v1/admin/config', { accessToken });
|
|
148
|
+
}
|
|
149
|
+
updateConfig(input, accessToken) {
|
|
150
|
+
return this.http.request('/api/v1/admin/config', {
|
|
151
|
+
method: 'PUT',
|
|
152
|
+
body: input,
|
|
153
|
+
accessToken,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
grantCredits(input, accessToken) {
|
|
157
|
+
return this.http.request('/api/v1/credits/admin/grant', {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
body: input,
|
|
160
|
+
accessToken,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
getUserCredits(userId, accessToken) {
|
|
164
|
+
return this.http.request(`/api/v1/credits/admin/users/${encodeURIComponent(userId)}`, {
|
|
165
|
+
accessToken,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
listManagedModels(accessToken) {
|
|
169
|
+
return this.http.request('/api/v1/admin/models', { accessToken });
|
|
170
|
+
}
|
|
171
|
+
createManagedModel(input, accessToken) {
|
|
172
|
+
return this.http.request('/api/v1/admin/models', {
|
|
173
|
+
method: 'POST',
|
|
174
|
+
body: input,
|
|
175
|
+
accessToken,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
updateManagedModel(id, input, accessToken) {
|
|
179
|
+
return this.http.request(`/api/v1/admin/models/${encodeURIComponent(id)}`, {
|
|
180
|
+
method: 'PUT',
|
|
181
|
+
body: input,
|
|
182
|
+
accessToken,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
deleteManagedModel(id, accessToken) {
|
|
186
|
+
return this.http.request(`/api/v1/admin/models/${encodeURIComponent(id)}`, {
|
|
187
|
+
method: 'DELETE',
|
|
188
|
+
accessToken,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
bulkDeleteManagedModels(ids, accessToken) {
|
|
192
|
+
return this.http.request('/api/v1/admin/models/delete', {
|
|
193
|
+
method: 'POST',
|
|
194
|
+
body: { ids },
|
|
195
|
+
accessToken,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
importManagedModels(input, accessToken) {
|
|
199
|
+
return this.http.request('/api/v1/admin/models/import', {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
body: input,
|
|
202
|
+
accessToken,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
flushManagedModelCache(accessToken) {
|
|
206
|
+
return this.http.request('/api/v1/admin/models/cache/flush', {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
accessToken,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
package/dist/auth/client.d.ts
CHANGED
package/dist/core/client.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export declare class PlatformHttpClient {
|
|
|
4
4
|
private readonly fetchImpl;
|
|
5
5
|
private readonly options;
|
|
6
6
|
constructor(options: PlatformClientOptions);
|
|
7
|
+
private send;
|
|
7
8
|
request<T>(path: string, requestOptions?: PlatformRequestOptions): Promise<T>;
|
|
9
|
+
requestRaw(path: string, requestOptions?: PlatformRequestOptions): Promise<Response>;
|
|
8
10
|
}
|
package/dist/core/client.js
CHANGED
|
@@ -15,9 +15,10 @@ export class PlatformHttpClient {
|
|
|
15
15
|
constructor(options) {
|
|
16
16
|
this.options = options;
|
|
17
17
|
this.baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
18
|
-
|
|
18
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
19
|
+
this.fetchImpl = fetchImpl.bind(globalThis);
|
|
19
20
|
}
|
|
20
|
-
async
|
|
21
|
+
async send(path, requestOptions = {}) {
|
|
21
22
|
const headers = new Headers(this.options.defaultHeaders);
|
|
22
23
|
headers.set('Content-Type', 'application/json');
|
|
23
24
|
if (requestOptions.headers) {
|
|
@@ -53,16 +54,23 @@ export class PlatformHttpClient {
|
|
|
53
54
|
const message = error instanceof Error ? error.message : 'Unknown transport error';
|
|
54
55
|
throw new PlatformTransportError(message);
|
|
55
56
|
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
async request(path, requestOptions = {}) {
|
|
60
|
+
const response = await this.send(path, requestOptions);
|
|
56
61
|
let payload = null;
|
|
57
62
|
try {
|
|
58
63
|
payload = (await response.json());
|
|
59
64
|
}
|
|
60
65
|
catch {
|
|
61
|
-
throw new PlatformTransportError(`Platform API returned a non-JSON response for ${url}`);
|
|
66
|
+
throw new PlatformTransportError(`Platform API returned a non-JSON response for ${response.url}`);
|
|
62
67
|
}
|
|
63
68
|
if (!response.ok) {
|
|
64
69
|
throw new PlatformApiError(payload.message, response.status, payload.code, payload.data);
|
|
65
70
|
}
|
|
66
71
|
return payload.data;
|
|
67
72
|
}
|
|
73
|
+
async requestRaw(path, requestOptions = {}) {
|
|
74
|
+
return this.send(path, requestOptions);
|
|
75
|
+
}
|
|
68
76
|
}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -28,6 +28,27 @@ export interface AuthUser {
|
|
|
28
28
|
avatar?: string | null;
|
|
29
29
|
role: 'user' | 'admin' | 'super_admin';
|
|
30
30
|
creditsBalance?: number;
|
|
31
|
+
projectId?: string | null;
|
|
32
|
+
projectName?: string | null;
|
|
33
|
+
projectSlug?: string | null;
|
|
34
|
+
membership?: {
|
|
35
|
+
tier: string;
|
|
36
|
+
power?: number;
|
|
37
|
+
endDate?: number | null;
|
|
38
|
+
} | null;
|
|
39
|
+
projectPermission?: {
|
|
40
|
+
id: string;
|
|
41
|
+
projectId: string;
|
|
42
|
+
projectName?: string | null;
|
|
43
|
+
projectSlug?: string | null;
|
|
44
|
+
role?: string | null;
|
|
45
|
+
tier?: string | null;
|
|
46
|
+
status?: string | null;
|
|
47
|
+
credits?: number;
|
|
48
|
+
startDate?: number | null;
|
|
49
|
+
endDate?: number | null;
|
|
50
|
+
autoRenew?: boolean;
|
|
51
|
+
} | null;
|
|
31
52
|
}
|
|
32
53
|
export interface AuthSession {
|
|
33
54
|
user: AuthUser;
|
|
@@ -44,6 +65,8 @@ export interface ProjectSummary {
|
|
|
44
65
|
export interface ProductSummary {
|
|
45
66
|
id: string;
|
|
46
67
|
projectId?: string | null;
|
|
68
|
+
projectName?: string | null;
|
|
69
|
+
projectSlug?: string | null;
|
|
47
70
|
name: string;
|
|
48
71
|
description?: string | null;
|
|
49
72
|
price: number;
|
|
@@ -52,6 +75,9 @@ export interface ProductSummary {
|
|
|
52
75
|
credits: number;
|
|
53
76
|
tier: string;
|
|
54
77
|
features: string[];
|
|
78
|
+
modelKeys?: string[];
|
|
79
|
+
models?: AiModelSummary[];
|
|
80
|
+
enabled?: boolean;
|
|
55
81
|
sortOrder?: number;
|
|
56
82
|
}
|
|
57
83
|
export interface MembershipView {
|
|
@@ -82,6 +108,32 @@ export interface CreditsLedgerItem {
|
|
|
82
108
|
description?: string | null;
|
|
83
109
|
created_at: number;
|
|
84
110
|
}
|
|
111
|
+
export interface UserApiKeyRecord {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
keyPrefix: string;
|
|
115
|
+
active: boolean;
|
|
116
|
+
lastUsedAt?: number | null;
|
|
117
|
+
createdAt: number;
|
|
118
|
+
updatedAt: number;
|
|
119
|
+
}
|
|
120
|
+
export interface UserApiKeySecret {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
keyPrefix: string;
|
|
124
|
+
secret: string;
|
|
125
|
+
createdAt: number;
|
|
126
|
+
}
|
|
127
|
+
export interface UserSettingDefinition {
|
|
128
|
+
label: string;
|
|
129
|
+
description: string;
|
|
130
|
+
defaultValue: string;
|
|
131
|
+
maxLength: number;
|
|
132
|
+
}
|
|
133
|
+
export interface UserSettingsPayload {
|
|
134
|
+
settings: Record<string, string>;
|
|
135
|
+
definitions?: Record<string, UserSettingDefinition>;
|
|
136
|
+
}
|
|
85
137
|
export interface PaymentCreateResponse {
|
|
86
138
|
paymentType: string;
|
|
87
139
|
orderNo: string;
|
|
@@ -104,6 +156,22 @@ export interface PaymentQueryResponse {
|
|
|
104
156
|
paidAt?: number | null;
|
|
105
157
|
};
|
|
106
158
|
}
|
|
159
|
+
export interface OrderSummary {
|
|
160
|
+
id: string;
|
|
161
|
+
productId?: string;
|
|
162
|
+
orderNo: string;
|
|
163
|
+
amount: number;
|
|
164
|
+
status: string;
|
|
165
|
+
productName?: string;
|
|
166
|
+
productTier?: string;
|
|
167
|
+
paymentMethod?: string | null;
|
|
168
|
+
createdAt?: number;
|
|
169
|
+
paidAt?: number | null;
|
|
170
|
+
}
|
|
171
|
+
export interface OrderDetail extends OrderSummary {
|
|
172
|
+
paymentIntentId?: string | null;
|
|
173
|
+
productDescription?: string | null;
|
|
174
|
+
}
|
|
107
175
|
export interface AiModelSummary {
|
|
108
176
|
key: string;
|
|
109
177
|
id: string;
|
|
@@ -119,3 +187,212 @@ export interface AiModelSummary {
|
|
|
119
187
|
outputPricing?: number;
|
|
120
188
|
locked?: boolean;
|
|
121
189
|
}
|
|
190
|
+
export interface AdminProject {
|
|
191
|
+
id: string;
|
|
192
|
+
name: string;
|
|
193
|
+
slug: string;
|
|
194
|
+
description?: string | null;
|
|
195
|
+
logoUrl?: string | null;
|
|
196
|
+
status: 'active' | 'inactive';
|
|
197
|
+
settings?: Record<string, unknown> | null;
|
|
198
|
+
createdAt: number;
|
|
199
|
+
updatedAt: number;
|
|
200
|
+
stats?: {
|
|
201
|
+
productCount: number;
|
|
202
|
+
userCount: number;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
export type AdminProjectExportFormat = 'openapi' | 'markdown';
|
|
206
|
+
export interface AdminProduct {
|
|
207
|
+
id: string;
|
|
208
|
+
projectId?: string | null;
|
|
209
|
+
name: string;
|
|
210
|
+
description?: string | null;
|
|
211
|
+
price?: number;
|
|
212
|
+
discount_price?: number | null;
|
|
213
|
+
duration_days?: number;
|
|
214
|
+
credits?: number;
|
|
215
|
+
tier?: string;
|
|
216
|
+
features?: string[];
|
|
217
|
+
enabled?: boolean;
|
|
218
|
+
sort_order?: number;
|
|
219
|
+
}
|
|
220
|
+
export interface AdminMembershipRecord {
|
|
221
|
+
id: string;
|
|
222
|
+
scopeType: 'project' | 'global';
|
|
223
|
+
role: string;
|
|
224
|
+
tier: string;
|
|
225
|
+
status: string;
|
|
226
|
+
credits: number;
|
|
227
|
+
startDate?: number | null;
|
|
228
|
+
endDate?: number | null;
|
|
229
|
+
autoRenew: boolean;
|
|
230
|
+
createdAt: number;
|
|
231
|
+
updatedAt: number;
|
|
232
|
+
user: {
|
|
233
|
+
id: string;
|
|
234
|
+
email: string;
|
|
235
|
+
name?: string | null;
|
|
236
|
+
role: string;
|
|
237
|
+
status: string;
|
|
238
|
+
};
|
|
239
|
+
project: {
|
|
240
|
+
id: string;
|
|
241
|
+
name: string;
|
|
242
|
+
slug: string;
|
|
243
|
+
status: string;
|
|
244
|
+
} | null;
|
|
245
|
+
}
|
|
246
|
+
export interface AdminMembershipFilters {
|
|
247
|
+
scope?: 'project' | 'global';
|
|
248
|
+
projectId?: string;
|
|
249
|
+
status?: string;
|
|
250
|
+
tier?: string;
|
|
251
|
+
search?: string;
|
|
252
|
+
}
|
|
253
|
+
export interface AdminUserRecord {
|
|
254
|
+
id: string;
|
|
255
|
+
email: string;
|
|
256
|
+
name?: string | null;
|
|
257
|
+
role: string;
|
|
258
|
+
status: string;
|
|
259
|
+
createdAt: number;
|
|
260
|
+
updatedAt: number;
|
|
261
|
+
currentProject: {
|
|
262
|
+
id: string;
|
|
263
|
+
name: string;
|
|
264
|
+
slug: string;
|
|
265
|
+
} | null;
|
|
266
|
+
globalMembership: {
|
|
267
|
+
id: string;
|
|
268
|
+
tier: string | null;
|
|
269
|
+
status: string | null;
|
|
270
|
+
credits: number;
|
|
271
|
+
startDate?: number | null;
|
|
272
|
+
endDate?: number | null;
|
|
273
|
+
autoRenew: boolean;
|
|
274
|
+
} | null;
|
|
275
|
+
selectedProjectPermission: {
|
|
276
|
+
id: string;
|
|
277
|
+
role: string | null;
|
|
278
|
+
tier: string | null;
|
|
279
|
+
status: string | null;
|
|
280
|
+
credits: number;
|
|
281
|
+
startDate?: number | null;
|
|
282
|
+
endDate?: number | null;
|
|
283
|
+
autoRenew: boolean;
|
|
284
|
+
project: {
|
|
285
|
+
id: string;
|
|
286
|
+
name: string;
|
|
287
|
+
slug: string;
|
|
288
|
+
} | null;
|
|
289
|
+
} | null;
|
|
290
|
+
projectPermissionCount: number;
|
|
291
|
+
credits: {
|
|
292
|
+
balance: number;
|
|
293
|
+
reserved: number;
|
|
294
|
+
totalEarned: number;
|
|
295
|
+
totalSpent: number;
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export interface AdminOrderRecord {
|
|
299
|
+
id: string;
|
|
300
|
+
orderNo: string;
|
|
301
|
+
amount: number;
|
|
302
|
+
currency: string;
|
|
303
|
+
status: string;
|
|
304
|
+
paymentMethod?: string | null;
|
|
305
|
+
paymentIntentId?: string | null;
|
|
306
|
+
createdAt: number;
|
|
307
|
+
updatedAt: number;
|
|
308
|
+
paidAt?: number | null;
|
|
309
|
+
product: {
|
|
310
|
+
id: string;
|
|
311
|
+
name: string;
|
|
312
|
+
tier?: string | null;
|
|
313
|
+
};
|
|
314
|
+
project: {
|
|
315
|
+
id: string;
|
|
316
|
+
name: string;
|
|
317
|
+
slug: string;
|
|
318
|
+
} | null;
|
|
319
|
+
user: {
|
|
320
|
+
id: string;
|
|
321
|
+
email: string;
|
|
322
|
+
name?: string | null;
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
export interface AdminOrderFilters {
|
|
326
|
+
search?: string;
|
|
327
|
+
status?: string;
|
|
328
|
+
projectId?: string;
|
|
329
|
+
userId?: string;
|
|
330
|
+
limit?: number;
|
|
331
|
+
}
|
|
332
|
+
export interface AdminConfigItem {
|
|
333
|
+
key: string;
|
|
334
|
+
value: string;
|
|
335
|
+
type?: string;
|
|
336
|
+
description?: string;
|
|
337
|
+
updated_at?: number;
|
|
338
|
+
}
|
|
339
|
+
export interface AdminUserCreditsSummary {
|
|
340
|
+
account: {
|
|
341
|
+
balance: number;
|
|
342
|
+
reserved: number;
|
|
343
|
+
total_earned: number;
|
|
344
|
+
total_spent: number;
|
|
345
|
+
};
|
|
346
|
+
recentLedger: CreditsLedgerItem[];
|
|
347
|
+
}
|
|
348
|
+
export interface AdminModelRecord {
|
|
349
|
+
id: string;
|
|
350
|
+
model_key: string;
|
|
351
|
+
model_id: string;
|
|
352
|
+
name: string;
|
|
353
|
+
provider: string;
|
|
354
|
+
model_type?: string | null;
|
|
355
|
+
min_tier?: string | null;
|
|
356
|
+
input_pricing: number;
|
|
357
|
+
output_pricing: number;
|
|
358
|
+
cache_ratio?: number | null;
|
|
359
|
+
enabled: number;
|
|
360
|
+
sort_order: number;
|
|
361
|
+
created_at?: number;
|
|
362
|
+
updated_at?: number;
|
|
363
|
+
}
|
|
364
|
+
export interface AdminModelInput {
|
|
365
|
+
model_key: string;
|
|
366
|
+
model_id: string;
|
|
367
|
+
name: string;
|
|
368
|
+
provider: string;
|
|
369
|
+
model_type?: string;
|
|
370
|
+
min_tier?: string;
|
|
371
|
+
input_pricing: number;
|
|
372
|
+
output_pricing: number;
|
|
373
|
+
cache_ratio?: number;
|
|
374
|
+
enabled?: number;
|
|
375
|
+
sort_order?: number;
|
|
376
|
+
}
|
|
377
|
+
export interface AdminProductListResult {
|
|
378
|
+
project: {
|
|
379
|
+
id: string;
|
|
380
|
+
name: string;
|
|
381
|
+
slug: string;
|
|
382
|
+
status: string;
|
|
383
|
+
} | null;
|
|
384
|
+
products: AdminProduct[];
|
|
385
|
+
}
|
|
386
|
+
export interface AdminProductBackfillResult {
|
|
387
|
+
updated: number;
|
|
388
|
+
}
|
|
389
|
+
export interface UpdateAdminUserInput {
|
|
390
|
+
userId: string;
|
|
391
|
+
name?: string | null;
|
|
392
|
+
status?: 'active' | 'disabled' | 'banned';
|
|
393
|
+
projectId?: string | null;
|
|
394
|
+
membershipTier?: string | null;
|
|
395
|
+
membershipStatus?: 'active' | 'expired' | 'cancelled';
|
|
396
|
+
membershipCredits?: number;
|
|
397
|
+
creditsBalance?: number;
|
|
398
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
|
+
import { AdminClient } from './admin/client';
|
|
2
|
+
import { AiClient } from './ai/client';
|
|
3
|
+
import { AuthClient } from './auth/client';
|
|
1
4
|
import { PlatformHttpClient } from './core/client';
|
|
2
5
|
import type { PlatformClientOptions } from './core/types';
|
|
3
|
-
import { AuthClient } from './auth/client';
|
|
4
|
-
import { ProjectsClient } from './projects/client';
|
|
5
6
|
import { CreditsClient } from './credits/client';
|
|
7
|
+
import { OrdersClient } from './orders/client';
|
|
6
8
|
import { PaymentClient } from './payment/client';
|
|
7
|
-
import {
|
|
9
|
+
import { ProjectsClient } from './projects/client';
|
|
10
|
+
import { UserApiKeysClient } from './user/api-keys-client';
|
|
11
|
+
import { UserSettingsClient } from './user/settings-client';
|
|
8
12
|
export * from './core/errors';
|
|
9
|
-
export
|
|
10
|
-
export declare class
|
|
13
|
+
export type { AdminConfigItem, AdminMembershipFilters, AdminMembershipRecord, AdminModelInput, AdminModelRecord, AdminOrderFilters, AdminOrderRecord, AdminProduct, AdminProductBackfillResult, AdminProductListResult, AdminProject, AdminProjectExportFormat, AdminUserCreditsSummary, AdminUserRecord, AiModelSummary, AuthSession, AuthUser, CreditsBalance, CreditsLedgerItem, MembershipView, OrderDetail, OrderSummary, PaymentCreateResponse, PaymentQueryResponse, PlatformClientOptions, PlatformEnvelope, PlatformRequestOptions, ProductSummary, ProjectSummary, UpdateAdminUserInput, UserApiKeyRecord, UserApiKeySecret, UserSettingDefinition, UserSettingsPayload, } from './core/types';
|
|
14
|
+
export declare class BasePlatformClient {
|
|
11
15
|
readonly http: PlatformHttpClient;
|
|
12
16
|
readonly auth: AuthClient;
|
|
13
|
-
readonly projects: ProjectsClient;
|
|
14
17
|
readonly credits: CreditsClient;
|
|
18
|
+
readonly apiKeys: UserApiKeysClient;
|
|
19
|
+
readonly settings: UserSettingsClient;
|
|
20
|
+
constructor(options: PlatformClientOptions);
|
|
21
|
+
}
|
|
22
|
+
export declare function createBasePlatformClient(options: PlatformClientOptions): BasePlatformClient;
|
|
23
|
+
export declare class ProjectPlatformClient {
|
|
24
|
+
readonly http: PlatformHttpClient;
|
|
25
|
+
readonly projects: ProjectsClient;
|
|
26
|
+
readonly orders: OrdersClient;
|
|
15
27
|
readonly payment: PaymentClient;
|
|
16
28
|
readonly ai: AiClient;
|
|
17
29
|
constructor(options: PlatformClientOptions);
|
|
18
30
|
}
|
|
19
|
-
export declare function
|
|
31
|
+
export declare function createProjectPlatformClient(options: PlatformClientOptions): ProjectPlatformClient;
|
|
32
|
+
export declare class AdminPlatformClient {
|
|
33
|
+
readonly http: PlatformHttpClient;
|
|
34
|
+
readonly admin: AdminClient;
|
|
35
|
+
constructor(options: PlatformClientOptions);
|
|
36
|
+
}
|
|
37
|
+
export declare function createAdminPlatformClient(options: PlatformClientOptions): AdminPlatformClient;
|
|
38
|
+
export { BasePlatformClient as PlatformAClient };
|
|
39
|
+
export declare const createPlatformAClient: typeof createBasePlatformClient;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AdminClient } from './admin/client';
|
|
2
|
+
import { AiClient } from './ai/client';
|
|
2
3
|
import { AuthClient } from './auth/client';
|
|
3
|
-
import {
|
|
4
|
+
import { PlatformHttpClient } from './core/client';
|
|
4
5
|
import { CreditsClient } from './credits/client';
|
|
6
|
+
import { OrdersClient } from './orders/client';
|
|
5
7
|
import { PaymentClient } from './payment/client';
|
|
6
|
-
import {
|
|
8
|
+
import { ProjectsClient } from './projects/client';
|
|
9
|
+
import { UserApiKeysClient } from './user/api-keys-client';
|
|
10
|
+
import { UserSettingsClient } from './user/settings-client';
|
|
7
11
|
export * from './core/errors';
|
|
8
|
-
export
|
|
9
|
-
export class PlatformAClient {
|
|
12
|
+
export class BasePlatformClient {
|
|
10
13
|
constructor(options) {
|
|
11
14
|
this.http = new PlatformHttpClient(options);
|
|
12
15
|
this.auth = new AuthClient(this.http);
|
|
13
|
-
this.projects = new ProjectsClient(this.http);
|
|
14
16
|
this.credits = new CreditsClient(this.http);
|
|
17
|
+
this.apiKeys = new UserApiKeysClient(this.http);
|
|
18
|
+
this.settings = new UserSettingsClient(this.http);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function createBasePlatformClient(options) {
|
|
22
|
+
return new BasePlatformClient(options);
|
|
23
|
+
}
|
|
24
|
+
export class ProjectPlatformClient {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.http = new PlatformHttpClient(options);
|
|
27
|
+
this.projects = new ProjectsClient(this.http);
|
|
28
|
+
this.orders = new OrdersClient(this.http);
|
|
15
29
|
this.payment = new PaymentClient(this.http);
|
|
16
30
|
this.ai = new AiClient(this.http);
|
|
17
31
|
}
|
|
18
32
|
}
|
|
19
|
-
export function
|
|
20
|
-
return new
|
|
33
|
+
export function createProjectPlatformClient(options) {
|
|
34
|
+
return new ProjectPlatformClient(options);
|
|
35
|
+
}
|
|
36
|
+
export class AdminPlatformClient {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.http = new PlatformHttpClient(options);
|
|
39
|
+
this.admin = new AdminClient(this.http);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function createAdminPlatformClient(options) {
|
|
43
|
+
return new AdminPlatformClient(options);
|
|
21
44
|
}
|
|
45
|
+
export { BasePlatformClient as PlatformAClient };
|
|
46
|
+
export const createPlatformAClient = createBasePlatformClient;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PlatformHttpClient } from '../core/client';
|
|
2
|
+
import type { OrderDetail, OrderSummary } from '../core/types';
|
|
3
|
+
export declare class OrdersClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: PlatformHttpClient);
|
|
6
|
+
create(input: {
|
|
7
|
+
productId: string;
|
|
8
|
+
accessToken?: string;
|
|
9
|
+
}): Promise<OrderSummary>;
|
|
10
|
+
list(accessToken?: string): Promise<{
|
|
11
|
+
orders: OrderSummary[];
|
|
12
|
+
}>;
|
|
13
|
+
get(orderId: string, accessToken?: string): Promise<{
|
|
14
|
+
order: OrderDetail;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class OrdersClient {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
create(input) {
|
|
6
|
+
return this.http.request('/api/v1/orders', {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
accessToken: input.accessToken,
|
|
9
|
+
body: {
|
|
10
|
+
productId: input.productId,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
list(accessToken) {
|
|
15
|
+
return this.http.request('/api/v1/orders', {
|
|
16
|
+
accessToken,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
get(orderId, accessToken) {
|
|
20
|
+
return this.http.request(`/api/v1/orders/${orderId}`, {
|
|
21
|
+
accessToken,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { PlatformHttpClient } from '../core/client';
|
|
2
2
|
import type { MembershipView, ProductSummary, ProjectSummary } from '../core/types';
|
|
3
|
+
type MembershipRequestOptions = {
|
|
4
|
+
accessToken?: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
};
|
|
3
7
|
export declare class ProjectsClient {
|
|
4
8
|
private readonly http;
|
|
5
9
|
constructor(http: PlatformHttpClient);
|
|
@@ -8,7 +12,12 @@ export declare class ProjectsClient {
|
|
|
8
12
|
products: ProductSummary[];
|
|
9
13
|
total?: number;
|
|
10
14
|
}>;
|
|
11
|
-
|
|
15
|
+
getCatalogProducts(projectId: string): Promise<{
|
|
16
|
+
project: ProjectSummary | null;
|
|
17
|
+
products: ProductSummary[];
|
|
18
|
+
total?: number;
|
|
19
|
+
}>;
|
|
20
|
+
getMembership(projectId: string, options?: string | MembershipRequestOptions): Promise<{
|
|
12
21
|
project: ProjectSummary;
|
|
13
22
|
membership: MembershipView;
|
|
14
23
|
}>;
|
|
@@ -20,3 +29,4 @@ export declare class ProjectsClient {
|
|
|
20
29
|
permissions?: unknown[];
|
|
21
30
|
}>;
|
|
22
31
|
}
|
|
32
|
+
export {};
|
package/dist/projects/client.js
CHANGED
|
@@ -5,8 +5,19 @@ export class ProjectsClient {
|
|
|
5
5
|
getProducts(projectId) {
|
|
6
6
|
return this.http.request(`/api/v1/projects/${projectId}/products`);
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
return this.http.request(
|
|
8
|
+
getCatalogProducts(projectId) {
|
|
9
|
+
return this.http.request('/api/v1/products', {
|
|
10
|
+
query: { projectId },
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
getMembership(projectId, options) {
|
|
14
|
+
const normalizedOptions = typeof options === 'string'
|
|
15
|
+
? { accessToken: options }
|
|
16
|
+
: (options ?? {});
|
|
17
|
+
return this.http.request(`/api/v1/projects/${projectId}/membership`, {
|
|
18
|
+
accessToken: normalizedOptions.accessToken,
|
|
19
|
+
headers: normalizedOptions.headers,
|
|
20
|
+
});
|
|
10
21
|
}
|
|
11
22
|
getPermissions(input) {
|
|
12
23
|
return this.http.request('/api/v1/user/project-permissions', {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PlatformHttpClient } from '../core/client';
|
|
2
|
+
import type { UserApiKeyRecord, UserApiKeySecret } from '../core/types';
|
|
3
|
+
export declare class UserApiKeysClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: PlatformHttpClient);
|
|
6
|
+
list(accessToken?: string): Promise<{
|
|
7
|
+
keys: UserApiKeyRecord[];
|
|
8
|
+
}>;
|
|
9
|
+
create(input: {
|
|
10
|
+
name?: string;
|
|
11
|
+
}, accessToken?: string): Promise<{
|
|
12
|
+
key: UserApiKeySecret;
|
|
13
|
+
}>;
|
|
14
|
+
update(id: string, input: {
|
|
15
|
+
name?: string;
|
|
16
|
+
active?: boolean;
|
|
17
|
+
}, accessToken?: string): Promise<null>;
|
|
18
|
+
delete(id: string, accessToken?: string): Promise<null>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class UserApiKeysClient {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
list(accessToken) {
|
|
6
|
+
return this.http.request('/api/v1/user/api-keys', {
|
|
7
|
+
accessToken,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
create(input, accessToken) {
|
|
11
|
+
return this.http.request('/api/v1/user/api-keys', {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
accessToken,
|
|
14
|
+
body: input,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
update(id, input, accessToken) {
|
|
18
|
+
return this.http.request(`/api/v1/user/api-keys/${encodeURIComponent(id)}`, {
|
|
19
|
+
method: 'PATCH',
|
|
20
|
+
accessToken,
|
|
21
|
+
body: input,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
delete(id, accessToken) {
|
|
25
|
+
return this.http.request(`/api/v1/user/api-keys/${encodeURIComponent(id)}`, {
|
|
26
|
+
method: 'DELETE',
|
|
27
|
+
accessToken,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PlatformHttpClient } from '../core/client';
|
|
2
|
+
import type { UserSettingsPayload } from '../core/types';
|
|
3
|
+
export declare class UserSettingsClient {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: PlatformHttpClient);
|
|
6
|
+
get(accessToken?: string): Promise<UserSettingsPayload>;
|
|
7
|
+
update(settings: Record<string, string | number | boolean>, accessToken?: string): Promise<{
|
|
8
|
+
updated: string[];
|
|
9
|
+
settings: Record<string, string>;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class UserSettingsClient {
|
|
2
|
+
constructor(http) {
|
|
3
|
+
this.http = http;
|
|
4
|
+
}
|
|
5
|
+
get(accessToken) {
|
|
6
|
+
return this.http.request('/api/v1/user/settings', {
|
|
7
|
+
accessToken,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
update(settings, accessToken) {
|
|
11
|
+
return this.http.request('/api/v1/user/settings', {
|
|
12
|
+
method: 'PUT',
|
|
13
|
+
accessToken,
|
|
14
|
+
body: settings,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|