uapi-browser-sdk 0.1.12 → 0.1.13
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 +1 -1
- package/dist/internal/src/apis/ClipzyApi.d.ts +0 -12
- package/dist/internal/src/apis/ClipzyApi.js +15 -36
- package/dist/internal/src/apis/ConvertApi.d.ts +0 -8
- package/dist/internal/src/apis/ConvertApi.js +10 -24
- package/dist/internal/src/apis/DailyApi.d.ts +0 -4
- package/dist/internal/src/apis/DailyApi.js +5 -12
- package/dist/internal/src/apis/DefaultApi.d.ts +0 -20
- package/dist/internal/src/apis/DefaultApi.js +25 -60
- package/dist/internal/src/apis/GameApi.d.ts +0 -20
- package/dist/internal/src/apis/GameApi.js +25 -60
- package/dist/internal/src/apis/ImageApi.d.ts +0 -44
- package/dist/internal/src/apis/ImageApi.js +55 -132
- package/dist/internal/src/apis/MiscApi.d.ts +0 -60
- package/dist/internal/src/apis/MiscApi.js +75 -180
- package/dist/internal/src/apis/NetworkApi.d.ts +0 -40
- package/dist/internal/src/apis/NetworkApi.js +50 -120
- package/dist/internal/src/apis/PoemApi.d.ts +0 -4
- package/dist/internal/src/apis/PoemApi.js +5 -12
- package/dist/internal/src/apis/RandomApi.d.ts +0 -16
- package/dist/internal/src/apis/RandomApi.js +20 -48
- package/dist/internal/src/apis/SocialApi.d.ts +0 -32
- package/dist/internal/src/apis/SocialApi.js +40 -96
- package/dist/internal/src/apis/StatusApi.d.ts +0 -8
- package/dist/internal/src/apis/StatusApi.js +10 -24
- package/dist/internal/src/apis/TextApi.d.ts +0 -44
- package/dist/internal/src/apis/TextApi.js +55 -132
- package/dist/internal/src/apis/TranslateApi.d.ts +0 -16
- package/dist/internal/src/apis/TranslateApi.js +20 -48
- package/dist/internal/src/apis/WebParseApi.d.ts +0 -16
- package/dist/internal/src/apis/WebParseApi.js +20 -48
- package/dist/internal/src/models/GetMiscHolidayCalendar200ResponseHolidaysInner.d.ts +1 -1
- package/dist/internal/src/models/GetMiscWeather200Response.d.ts +1 -1
- package/dist/internal/src/models/PostAiTranslateRequest.d.ts +2 -2
- package/dist/internal/src/models/PostSearchAggregateRequest.d.ts +2 -2
- package/dist/internal/src/models/PostSensitiveWordAnalyze200ResponseResultsInner.d.ts +2 -2
- package/dist/internal/src/models/PostTextAesDecryptAdvancedRequest.d.ts +2 -2
- package/dist/internal/src/models/PostTextAesEncryptAdvancedRequest.d.ts +3 -3
- package/dist/internal/src/models/PostTextConvertRequest.d.ts +2 -2
- package/dist/internal/src/models/PostTranslateStream400Response.d.ts +1 -1
- package/dist/internal/src/runtime.js +0 -15
- package/dist/src/errors.d.ts +85 -0
- package/dist/src/errors.js +247 -0
- package/dist/src/index.d.ts +5 -6
- package/dist/src/index.js +9 -10
- package/internal/.openapi-generator/VERSION +1 -1
- package/internal/src/apis/ClipzyApi.ts +15 -39
- package/internal/src/apis/ConvertApi.ts +10 -26
- package/internal/src/apis/DailyApi.ts +5 -13
- package/internal/src/apis/DefaultApi.ts +25 -65
- package/internal/src/apis/GameApi.ts +25 -65
- package/internal/src/apis/ImageApi.ts +55 -143
- package/internal/src/apis/MiscApi.ts +75 -195
- package/internal/src/apis/NetworkApi.ts +50 -130
- package/internal/src/apis/PoemApi.ts +5 -13
- package/internal/src/apis/RandomApi.ts +20 -52
- package/internal/src/apis/SocialApi.ts +40 -104
- package/internal/src/apis/StatusApi.ts +10 -26
- package/internal/src/apis/TextApi.ts +55 -143
- package/internal/src/apis/TranslateApi.ts +20 -52
- package/internal/src/apis/WebParseApi.ts +20 -52
- package/internal/src/models/GetMiscHolidayCalendar200ResponseHolidaysInner.ts +1 -1
- package/internal/src/models/GetMiscWeather200Response.ts +1 -1
- package/internal/src/models/PostAiTranslateRequest.ts +2 -2
- package/internal/src/models/PostSearchAggregateRequest.ts +2 -2
- package/internal/src/models/PostSensitiveWordAnalyze200ResponseResultsInner.ts +2 -2
- package/internal/src/models/PostTextAesDecryptAdvancedRequest.ts +2 -2
- package/internal/src/models/PostTextAesEncryptAdvancedRequest.ts +3 -3
- package/internal/src/models/PostTextConvertRequest.ts +2 -2
- package/internal/src/models/PostTranslateStream400Response.ts +1 -1
- package/internal/src/runtime.ts +0 -18
- package/package.json +1 -1
- package/src/errors.ts +282 -0
- package/src/index.ts +12 -8
|
@@ -68,9 +68,10 @@ export interface PostWebTomarkdownAsyncRequest {
|
|
|
68
68
|
export class WebParseApi extends runtime.BaseAPI {
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* 提交了网页转 Markdown 任务后,想知道处理进度和结果?用这个接口来查询。 ## 功能概述 通过任务 ID 查询转换任务的当前状态、处理进度和最终结果。任务结果缓存 30 分钟,期间可重复查询。 ## 任务状态 | 状态 | 说明 | |------|------| | `pending` | 等待处理 | | `processing` | 处理中 | | `completed` | 已完成,可获取结果 | | `failed` | 失败 | | `timeout` | 超时(超过 60 秒) | > [!NOTE] > 建议每 2-5 秒轮询一次,当状态为 `completed`、`failed` 或 `timeout` 时停止轮询。
|
|
72
|
+
* 转换任务状态
|
|
72
73
|
*/
|
|
73
|
-
async
|
|
74
|
+
async getWebTomarkdownAsyncStatusRaw(requestParameters: GetWebTomarkdownAsyncStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebTomarkdownAsyncStatus200Response>> {
|
|
74
75
|
if (requestParameters['taskId'] == null) {
|
|
75
76
|
throw new runtime.RequiredError(
|
|
76
77
|
'taskId',
|
|
@@ -86,21 +87,12 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
86
87
|
let urlPath = `/web/tomarkdown/async/{task_id}`;
|
|
87
88
|
urlPath = urlPath.replace(`{${"task_id"}}`, encodeURIComponent(String(requestParameters['taskId'])));
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
const response = await this.request({
|
|
90
91
|
path: urlPath,
|
|
91
92
|
method: 'GET',
|
|
92
93
|
headers: headerParameters,
|
|
93
94
|
query: queryParameters,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 提交了网页转 Markdown 任务后,想知道处理进度和结果?用这个接口来查询。 ## 功能概述 通过任务 ID 查询转换任务的当前状态、处理进度和最终结果。任务结果缓存 30 分钟,期间可重复查询。 ## 任务状态 | 状态 | 说明 | |------|------| | `pending` | 等待处理 | | `processing` | 处理中 | | `completed` | 已完成,可获取结果 | | `failed` | 失败 | | `timeout` | 超时(超过 60 秒) | > [!NOTE] > 建议每 2-5 秒轮询一次,当状态为 `completed`、`failed` 或 `timeout` 时停止轮询。
|
|
99
|
-
* 转换任务状态
|
|
100
|
-
*/
|
|
101
|
-
async getWebTomarkdownAsyncStatusRaw(requestParameters: GetWebTomarkdownAsyncStatusRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebTomarkdownAsyncStatus200Response>> {
|
|
102
|
-
const requestOptions = await this.getWebTomarkdownAsyncStatusRequestOpts(requestParameters);
|
|
103
|
-
const response = await this.request(requestOptions, initOverrides);
|
|
95
|
+
}, initOverrides);
|
|
104
96
|
|
|
105
97
|
return new runtime.JSONApiResponse(response, (jsonValue) => GetWebTomarkdownAsyncStatus200ResponseFromJSON(jsonValue));
|
|
106
98
|
}
|
|
@@ -115,9 +107,10 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
115
107
|
}
|
|
116
108
|
|
|
117
109
|
/**
|
|
118
|
-
*
|
|
110
|
+
* 想批量获取一个网页上的所有图片链接?这个接口帮你搞定。 ## 功能概述 提供一个网页 URL,返回该页面中所有图片的链接列表。适合用于图片采集、素材下载等场景。
|
|
111
|
+
* 提取网页图片
|
|
119
112
|
*/
|
|
120
|
-
async
|
|
113
|
+
async getWebparseExtractimagesRaw(requestParameters: GetWebparseExtractimagesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebparseExtractimages200Response>> {
|
|
121
114
|
if (requestParameters['url'] == null) {
|
|
122
115
|
throw new runtime.RequiredError(
|
|
123
116
|
'url',
|
|
@@ -136,21 +129,12 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
136
129
|
|
|
137
130
|
let urlPath = `/webparse/extractimages`;
|
|
138
131
|
|
|
139
|
-
|
|
132
|
+
const response = await this.request({
|
|
140
133
|
path: urlPath,
|
|
141
134
|
method: 'GET',
|
|
142
135
|
headers: headerParameters,
|
|
143
136
|
query: queryParameters,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 想批量获取一个网页上的所有图片链接?这个接口帮你搞定。 ## 功能概述 提供一个网页 URL,返回该页面中所有图片的链接列表。适合用于图片采集、素材下载等场景。
|
|
149
|
-
* 提取网页图片
|
|
150
|
-
*/
|
|
151
|
-
async getWebparseExtractimagesRaw(requestParameters: GetWebparseExtractimagesRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebparseExtractimages200Response>> {
|
|
152
|
-
const requestOptions = await this.getWebparseExtractimagesRequestOpts(requestParameters);
|
|
153
|
-
const response = await this.request(requestOptions, initOverrides);
|
|
137
|
+
}, initOverrides);
|
|
154
138
|
|
|
155
139
|
return new runtime.JSONApiResponse(response, (jsonValue) => GetWebparseExtractimages200ResponseFromJSON(jsonValue));
|
|
156
140
|
}
|
|
@@ -165,9 +149,10 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
165
149
|
}
|
|
166
150
|
|
|
167
151
|
/**
|
|
168
|
-
*
|
|
152
|
+
* 想在应用里做链接预览卡片?这个接口帮你一键获取网页的标题、描述、图标等信息。 ## 功能概述 提供一个网页 URL,返回该页面的元数据,包括标题、描述、关键词、Favicon、Open Graph 信息等。非常适合用于生成链接预览卡片或做 SEO 分析。
|
|
153
|
+
* 提取网页元数据
|
|
169
154
|
*/
|
|
170
|
-
async
|
|
155
|
+
async getWebparseMetadataRaw(requestParameters: GetWebparseMetadataRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebparseMetadata200Response>> {
|
|
171
156
|
if (requestParameters['url'] == null) {
|
|
172
157
|
throw new runtime.RequiredError(
|
|
173
158
|
'url',
|
|
@@ -186,21 +171,12 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
186
171
|
|
|
187
172
|
let urlPath = `/webparse/metadata`;
|
|
188
173
|
|
|
189
|
-
|
|
174
|
+
const response = await this.request({
|
|
190
175
|
path: urlPath,
|
|
191
176
|
method: 'GET',
|
|
192
177
|
headers: headerParameters,
|
|
193
178
|
query: queryParameters,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 想在应用里做链接预览卡片?这个接口帮你一键获取网页的标题、描述、图标等信息。 ## 功能概述 提供一个网页 URL,返回该页面的元数据,包括标题、描述、关键词、Favicon、Open Graph 信息等。非常适合用于生成链接预览卡片或做 SEO 分析。
|
|
199
|
-
* 提取网页元数据
|
|
200
|
-
*/
|
|
201
|
-
async getWebparseMetadataRaw(requestParameters: GetWebparseMetadataRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<GetWebparseMetadata200Response>> {
|
|
202
|
-
const requestOptions = await this.getWebparseMetadataRequestOpts(requestParameters);
|
|
203
|
-
const response = await this.request(requestOptions, initOverrides);
|
|
179
|
+
}, initOverrides);
|
|
204
180
|
|
|
205
181
|
return new runtime.JSONApiResponse(response, (jsonValue) => GetWebparseMetadata200ResponseFromJSON(jsonValue));
|
|
206
182
|
}
|
|
@@ -215,9 +191,10 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
215
191
|
}
|
|
216
192
|
|
|
217
193
|
/**
|
|
218
|
-
*
|
|
194
|
+
* 想把一个网页的内容转成干净的 Markdown 文本?这个异步接口可以帮你搞定,特别适合处理大型或复杂的网页。 ## 功能概述 提交一个网页 URL,我们会自动抓取主体内容,剔除广告、导航栏等干扰元素,并转换为 Markdown 格式。同时会提取标题、作者、发布日期等元数据,生成 YAML Front Matter。 任务提交后会立即返回任务 ID,你可以用它来查询处理进度和结果。单个任务最长处理 60 秒,结果缓存 30 分钟。
|
|
195
|
+
* 网页转 Markdown
|
|
219
196
|
*/
|
|
220
|
-
async
|
|
197
|
+
async postWebTomarkdownAsyncRaw(requestParameters: PostWebTomarkdownAsyncRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PostWebTomarkdownAsync202Response>> {
|
|
221
198
|
if (requestParameters['url'] == null) {
|
|
222
199
|
throw new runtime.RequiredError(
|
|
223
200
|
'url',
|
|
@@ -236,21 +213,12 @@ export class WebParseApi extends runtime.BaseAPI {
|
|
|
236
213
|
|
|
237
214
|
let urlPath = `/web/tomarkdown/async`;
|
|
238
215
|
|
|
239
|
-
|
|
216
|
+
const response = await this.request({
|
|
240
217
|
path: urlPath,
|
|
241
218
|
method: 'POST',
|
|
242
219
|
headers: headerParameters,
|
|
243
220
|
query: queryParameters,
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 想把一个网页的内容转成干净的 Markdown 文本?这个异步接口可以帮你搞定,特别适合处理大型或复杂的网页。 ## 功能概述 提交一个网页 URL,我们会自动抓取主体内容,剔除广告、导航栏等干扰元素,并转换为 Markdown 格式。同时会提取标题、作者、发布日期等元数据,生成 YAML Front Matter。 任务提交后会立即返回任务 ID,你可以用它来查询处理进度和结果。单个任务最长处理 60 秒,结果缓存 30 分钟。
|
|
249
|
-
* 网页转 Markdown
|
|
250
|
-
*/
|
|
251
|
-
async postWebTomarkdownAsyncRaw(requestParameters: PostWebTomarkdownAsyncRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PostWebTomarkdownAsync202Response>> {
|
|
252
|
-
const requestOptions = await this.postWebTomarkdownAsyncRequestOpts(requestParameters);
|
|
253
|
-
const response = await this.request(requestOptions, initOverrides);
|
|
221
|
+
}, initOverrides);
|
|
254
222
|
|
|
255
223
|
return new runtime.JSONApiResponse(response, (jsonValue) => PostWebTomarkdownAsync202ResponseFromJSON(jsonValue));
|
|
256
224
|
}
|
|
@@ -33,7 +33,7 @@ export interface GetMiscHolidayCalendar200ResponseHolidaysInner {
|
|
|
33
33
|
name?: string;
|
|
34
34
|
/**
|
|
35
35
|
* 事件类型。
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof GetMiscHolidayCalendar200ResponseHolidaysInner
|
|
38
38
|
*/
|
|
39
39
|
type?: GetMiscHolidayCalendar200ResponseHolidaysInnerTypeEnum;
|
|
@@ -87,7 +87,7 @@ export interface GetMiscWeather200Response {
|
|
|
87
87
|
weather?: string;
|
|
88
88
|
/**
|
|
89
89
|
* 天气图标代码。请从[天气图标代码表](#enum-list)中查看所有可能的值。
|
|
90
|
-
* @type {
|
|
90
|
+
* @type {string}
|
|
91
91
|
* @memberof GetMiscWeather200Response
|
|
92
92
|
*/
|
|
93
93
|
weatherIcon?: GetMiscWeather200ResponseWeatherIconEnum;
|
|
@@ -33,13 +33,13 @@ export interface PostAiTranslateRequest {
|
|
|
33
33
|
sourceLang?: string;
|
|
34
34
|
/**
|
|
35
35
|
* 翻译风格,可选。支持casual(随意口语化)、professional(专业商务,默认)、academic(学术正式)、literary(文学艺术)。
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof PostAiTranslateRequest
|
|
38
38
|
*/
|
|
39
39
|
style?: PostAiTranslateRequestStyleEnum;
|
|
40
40
|
/**
|
|
41
41
|
* 翻译上下文场景,可选。支持general(通用,默认)、business(商务)、technical(技术)、medical(医疗)、legal(法律)、marketing(市场营销)、entertainment(娱乐)、education(教育)、news(新闻)。
|
|
42
|
-
* @type {
|
|
42
|
+
* @type {string}
|
|
43
43
|
* @memberof PostAiTranslateRequest
|
|
44
44
|
*/
|
|
45
45
|
context?: PostAiTranslateRequestContextEnum;
|
|
@@ -51,13 +51,13 @@ export interface PostSearchAggregateRequest {
|
|
|
51
51
|
timeoutMs?: number;
|
|
52
52
|
/**
|
|
53
53
|
* 排序方式
|
|
54
|
-
* @type {
|
|
54
|
+
* @type {string}
|
|
55
55
|
* @memberof PostSearchAggregateRequest
|
|
56
56
|
*/
|
|
57
57
|
sort?: PostSearchAggregateRequestSortEnum;
|
|
58
58
|
/**
|
|
59
59
|
* 时间范围过滤
|
|
60
|
-
* @type {
|
|
60
|
+
* @type {string}
|
|
61
61
|
* @memberof PostSearchAggregateRequest
|
|
62
62
|
*/
|
|
63
63
|
timeRange?: PostSearchAggregateRequestTimeRangeEnum;
|
|
@@ -27,13 +27,13 @@ export interface PostSensitiveWordAnalyze200ResponseResultsInner {
|
|
|
27
27
|
k?: string;
|
|
28
28
|
/**
|
|
29
29
|
*
|
|
30
|
-
* @type {
|
|
30
|
+
* @type {string}
|
|
31
31
|
* @memberof PostSensitiveWordAnalyze200ResponseResultsInner
|
|
32
32
|
*/
|
|
33
33
|
label?: PostSensitiveWordAnalyze200ResponseResultsInnerLabelEnum;
|
|
34
34
|
/**
|
|
35
35
|
*
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof PostSensitiveWordAnalyze200ResponseResultsInner
|
|
38
38
|
*/
|
|
39
39
|
category?: PostSensitiveWordAnalyze200ResponseResultsInnerCategoryEnum;
|
|
@@ -33,13 +33,13 @@ export interface PostTextAesDecryptAdvancedRequest {
|
|
|
33
33
|
key: string;
|
|
34
34
|
/**
|
|
35
35
|
* 加密模式(必须与加密时相同):GCM/CBC/ECB/CTR/OFB/CFB
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof PostTextAesDecryptAdvancedRequest
|
|
38
38
|
*/
|
|
39
39
|
mode: PostTextAesDecryptAdvancedRequestModeEnum;
|
|
40
40
|
/**
|
|
41
41
|
* 填充方式(可选,必须与加密时相同):PKCS7/ZERO/NONE。GCM模式默认为NONE
|
|
42
|
-
* @type {
|
|
42
|
+
* @type {string}
|
|
43
43
|
* @memberof PostTextAesDecryptAdvancedRequest
|
|
44
44
|
*/
|
|
45
45
|
padding?: PostTextAesDecryptAdvancedRequestPaddingEnum;
|
|
@@ -33,13 +33,13 @@ export interface PostTextAesEncryptAdvancedRequest {
|
|
|
33
33
|
key: string;
|
|
34
34
|
/**
|
|
35
35
|
* 加密模式:GCM/CBC/ECB/CTR/OFB/CFB(可选,默认GCM)
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof PostTextAesEncryptAdvancedRequest
|
|
38
38
|
*/
|
|
39
39
|
mode?: PostTextAesEncryptAdvancedRequestModeEnum;
|
|
40
40
|
/**
|
|
41
41
|
* 填充方式:PKCS7/ZERO/NONE(可选,默认PKCS7)
|
|
42
|
-
* @type {
|
|
42
|
+
* @type {string}
|
|
43
43
|
* @memberof PostTextAesEncryptAdvancedRequest
|
|
44
44
|
*/
|
|
45
45
|
padding?: PostTextAesEncryptAdvancedRequestPaddingEnum;
|
|
@@ -51,7 +51,7 @@ export interface PostTextAesEncryptAdvancedRequest {
|
|
|
51
51
|
iv?: string;
|
|
52
52
|
/**
|
|
53
53
|
* 输出格式:base64(默认)或hex
|
|
54
|
-
* @type {
|
|
54
|
+
* @type {string}
|
|
55
55
|
* @memberof PostTextAesEncryptAdvancedRequest
|
|
56
56
|
*/
|
|
57
57
|
outputFormat?: PostTextAesEncryptAdvancedRequestOutputFormatEnum;
|
|
@@ -27,13 +27,13 @@ export interface PostTextConvertRequest {
|
|
|
27
27
|
text: string;
|
|
28
28
|
/**
|
|
29
29
|
* 源格式类型
|
|
30
|
-
* @type {
|
|
30
|
+
* @type {string}
|
|
31
31
|
* @memberof PostTextConvertRequest
|
|
32
32
|
*/
|
|
33
33
|
from: PostTextConvertRequestFromEnum;
|
|
34
34
|
/**
|
|
35
35
|
* 目标格式类型
|
|
36
|
-
* @type {
|
|
36
|
+
* @type {string}
|
|
37
37
|
* @memberof PostTextConvertRequest
|
|
38
38
|
*/
|
|
39
39
|
to: PostTextConvertRequestToEnum;
|
package/internal/src/runtime.ts
CHANGED
|
@@ -261,12 +261,6 @@ export class ResponseError extends Error {
|
|
|
261
261
|
override name: "ResponseError" = "ResponseError";
|
|
262
262
|
constructor(public response: Response, msg?: string) {
|
|
263
263
|
super(msg);
|
|
264
|
-
|
|
265
|
-
// restore prototype chain
|
|
266
|
-
const actualProto = new.target.prototype;
|
|
267
|
-
if (Object.setPrototypeOf) {
|
|
268
|
-
Object.setPrototypeOf(this, actualProto);
|
|
269
|
-
}
|
|
270
264
|
}
|
|
271
265
|
}
|
|
272
266
|
|
|
@@ -274,12 +268,6 @@ export class FetchError extends Error {
|
|
|
274
268
|
override name: "FetchError" = "FetchError";
|
|
275
269
|
constructor(public cause: Error, msg?: string) {
|
|
276
270
|
super(msg);
|
|
277
|
-
|
|
278
|
-
// restore prototype chain
|
|
279
|
-
const actualProto = new.target.prototype;
|
|
280
|
-
if (Object.setPrototypeOf) {
|
|
281
|
-
Object.setPrototypeOf(this, actualProto);
|
|
282
|
-
}
|
|
283
271
|
}
|
|
284
272
|
}
|
|
285
273
|
|
|
@@ -287,12 +275,6 @@ export class RequiredError extends Error {
|
|
|
287
275
|
override name: "RequiredError" = "RequiredError";
|
|
288
276
|
constructor(public field: string, msg?: string) {
|
|
289
277
|
super(msg);
|
|
290
|
-
|
|
291
|
-
// restore prototype chain
|
|
292
|
-
const actualProto = new.target.prototype;
|
|
293
|
-
if (Object.setPrototypeOf) {
|
|
294
|
-
Object.setPrototypeOf(this, actualProto);
|
|
295
|
-
}
|
|
296
278
|
}
|
|
297
279
|
}
|
|
298
280
|
|
package/package.json
CHANGED
package/src/errors.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
export interface RateLimitPolicyEntry {
|
|
2
|
+
name: string
|
|
3
|
+
quota?: number
|
|
4
|
+
unit?: string
|
|
5
|
+
windowSeconds?: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface RateLimitStateEntry {
|
|
9
|
+
name: string
|
|
10
|
+
remaining?: number
|
|
11
|
+
unit?: string
|
|
12
|
+
resetAfterSeconds?: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ResponseMeta {
|
|
16
|
+
requestId?: string
|
|
17
|
+
retryAfterSeconds?: number
|
|
18
|
+
debitStatus?: string
|
|
19
|
+
creditsRequested?: number
|
|
20
|
+
creditsCharged?: number
|
|
21
|
+
creditsPricing?: string
|
|
22
|
+
activeQuotaBuckets?: number
|
|
23
|
+
stopOnEmpty?: boolean
|
|
24
|
+
rateLimitPolicyRaw?: string
|
|
25
|
+
rateLimitRaw?: string
|
|
26
|
+
rateLimitPolicies: Record<string, RateLimitPolicyEntry>
|
|
27
|
+
rateLimits: Record<string, RateLimitStateEntry>
|
|
28
|
+
balanceLimitCents?: number
|
|
29
|
+
balanceRemainingCents?: number
|
|
30
|
+
quotaLimitCredits?: number
|
|
31
|
+
quotaRemainingCredits?: number
|
|
32
|
+
visitorQuotaLimitCredits?: number
|
|
33
|
+
visitorQuotaRemainingCredits?: number
|
|
34
|
+
rawHeaders: Record<string, string>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class UapiError extends Error {
|
|
38
|
+
code: string
|
|
39
|
+
status: number
|
|
40
|
+
details?: unknown
|
|
41
|
+
payload?: unknown
|
|
42
|
+
meta?: ResponseMeta
|
|
43
|
+
|
|
44
|
+
constructor(code: string, status: number, message: string, details?: unknown, payload?: unknown, meta?: ResponseMeta) {
|
|
45
|
+
super(`[${status}] ${code}: ${message}`)
|
|
46
|
+
this.code = code
|
|
47
|
+
this.status = status
|
|
48
|
+
this.details = details
|
|
49
|
+
this.payload = payload
|
|
50
|
+
this.meta = meta
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class ApiErrorError extends UapiError {}
|
|
54
|
+
export class AvatarNotFoundError extends UapiError {}
|
|
55
|
+
export class ConversionFailedError extends UapiError {}
|
|
56
|
+
export class FileOpenErrorError extends UapiError {}
|
|
57
|
+
export class FileRequiredError extends UapiError {}
|
|
58
|
+
export class InsufficientCreditsError extends UapiError {}
|
|
59
|
+
export class InternalServerErrorError extends UapiError {}
|
|
60
|
+
export class InvalidParameterError extends UapiError {}
|
|
61
|
+
export class InvalidParamsError extends UapiError {}
|
|
62
|
+
export class NotFoundError extends UapiError {}
|
|
63
|
+
export class NoMatchError extends UapiError {}
|
|
64
|
+
export class NoTrackingDataError extends UapiError {}
|
|
65
|
+
export class PhoneInfoFailedError extends UapiError {}
|
|
66
|
+
export class RecognitionFailedError extends UapiError {}
|
|
67
|
+
export class RequestEntityTooLargeError extends UapiError {}
|
|
68
|
+
export class ServiceBusyError extends UapiError {}
|
|
69
|
+
export class TimezoneNotFoundError extends UapiError {}
|
|
70
|
+
export class UnauthorizedError extends UapiError {}
|
|
71
|
+
export class UnsupportedCarrierError extends UapiError {}
|
|
72
|
+
export class UnsupportedFormatError extends UapiError {}
|
|
73
|
+
export class VisitorMonthlyQuotaExhaustedError extends UapiError {}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function defaultCode(status: number): string {
|
|
77
|
+
switch (status) {
|
|
78
|
+
case 400:
|
|
79
|
+
return 'INVALID_PARAMETER'
|
|
80
|
+
case 401:
|
|
81
|
+
return 'UNAUTHORIZED'
|
|
82
|
+
case 402:
|
|
83
|
+
return 'INSUFFICIENT_CREDITS'
|
|
84
|
+
case 404:
|
|
85
|
+
return 'NOT_FOUND'
|
|
86
|
+
case 413:
|
|
87
|
+
return 'REQUEST_ENTITY_TOO_LARGE'
|
|
88
|
+
case 429:
|
|
89
|
+
return 'SERVICE_BUSY'
|
|
90
|
+
case 500:
|
|
91
|
+
return 'INTERNAL_SERVER_ERROR'
|
|
92
|
+
default:
|
|
93
|
+
return 'API_ERROR'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toHeaderMap(headers: Headers | Record<string, unknown> | undefined): Record<string, string> {
|
|
98
|
+
const out: Record<string, string> = {}
|
|
99
|
+
if (!headers) {
|
|
100
|
+
return out
|
|
101
|
+
}
|
|
102
|
+
if (typeof (headers as Headers).forEach === 'function') {
|
|
103
|
+
;(headers as Headers).forEach((value, key) => {
|
|
104
|
+
out[String(key).toLowerCase()] = String(value)
|
|
105
|
+
})
|
|
106
|
+
return out
|
|
107
|
+
}
|
|
108
|
+
for (const [rawKey, rawValue] of Object.entries(headers)) {
|
|
109
|
+
if (rawValue === undefined || rawValue === null) {
|
|
110
|
+
continue
|
|
111
|
+
}
|
|
112
|
+
out[String(rawKey).toLowerCase()] = String(rawValue)
|
|
113
|
+
}
|
|
114
|
+
return out
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function parseNumber(value?: string): number | undefined {
|
|
118
|
+
if (value === undefined) {
|
|
119
|
+
return undefined
|
|
120
|
+
}
|
|
121
|
+
const parsed = Number(value)
|
|
122
|
+
return Number.isFinite(parsed) ? parsed : undefined
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function parseBoolean(value?: string): boolean | undefined {
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
return undefined
|
|
128
|
+
}
|
|
129
|
+
const normalized = value.trim().toLowerCase()
|
|
130
|
+
if (normalized === 'true') {
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
if (normalized === 'false') {
|
|
134
|
+
return false
|
|
135
|
+
}
|
|
136
|
+
return undefined
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function unquote(value: string): string {
|
|
140
|
+
const trimmed = value.trim()
|
|
141
|
+
if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
|
|
142
|
+
return trimmed.slice(1, -1)
|
|
143
|
+
}
|
|
144
|
+
return trimmed
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function parseStructuredItems(raw?: string): Array<{ name: string; params: Record<string, string> }> {
|
|
148
|
+
if (!raw) {
|
|
149
|
+
return []
|
|
150
|
+
}
|
|
151
|
+
return raw
|
|
152
|
+
.split(',')
|
|
153
|
+
.map((item) => item.trim())
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
.map((item) => {
|
|
156
|
+
const segments = item.split(';').map((segment) => segment.trim()).filter(Boolean)
|
|
157
|
+
const [head, ...rest] = segments
|
|
158
|
+
const params: Record<string, string> = {}
|
|
159
|
+
for (const segment of rest) {
|
|
160
|
+
const eq = segment.indexOf('=')
|
|
161
|
+
if (eq <= 0) {
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
const key = segment.slice(0, eq).trim()
|
|
165
|
+
const value = unquote(segment.slice(eq + 1))
|
|
166
|
+
params[key] = value
|
|
167
|
+
}
|
|
168
|
+
return { name: unquote(head), params }
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function extractMetaFromHeaders(headers: Headers | Record<string, unknown> | undefined): ResponseMeta {
|
|
173
|
+
const rawHeaders = toHeaderMap(headers)
|
|
174
|
+
const rateLimitPolicies: Record<string, RateLimitPolicyEntry> = {}
|
|
175
|
+
const rateLimits: Record<string, RateLimitStateEntry> = {}
|
|
176
|
+
|
|
177
|
+
for (const item of parseStructuredItems(rawHeaders['ratelimit-policy'])) {
|
|
178
|
+
rateLimitPolicies[item.name] = {
|
|
179
|
+
name: item.name,
|
|
180
|
+
quota: parseNumber(item.params.q),
|
|
181
|
+
unit: item.params['uapi-unit'],
|
|
182
|
+
windowSeconds: parseNumber(item.params.w),
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const item of parseStructuredItems(rawHeaders['ratelimit'])) {
|
|
187
|
+
rateLimits[item.name] = {
|
|
188
|
+
name: item.name,
|
|
189
|
+
remaining: parseNumber(item.params.r),
|
|
190
|
+
unit: item.params['uapi-unit'],
|
|
191
|
+
resetAfterSeconds: parseNumber(item.params.t),
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
requestId: rawHeaders['x-request-id'],
|
|
197
|
+
retryAfterSeconds: parseNumber(rawHeaders['retry-after']),
|
|
198
|
+
debitStatus: rawHeaders['uapi-debit-status'],
|
|
199
|
+
creditsRequested: parseNumber(rawHeaders['uapi-credits-requested']),
|
|
200
|
+
creditsCharged: parseNumber(rawHeaders['uapi-credits-charged']),
|
|
201
|
+
creditsPricing: rawHeaders['uapi-credits-pricing'],
|
|
202
|
+
activeQuotaBuckets: parseNumber(rawHeaders['uapi-quota-active-buckets']),
|
|
203
|
+
stopOnEmpty: parseBoolean(rawHeaders['uapi-stop-on-empty']),
|
|
204
|
+
rateLimitPolicyRaw: rawHeaders['ratelimit-policy'],
|
|
205
|
+
rateLimitRaw: rawHeaders['ratelimit'],
|
|
206
|
+
rateLimitPolicies,
|
|
207
|
+
rateLimits,
|
|
208
|
+
balanceLimitCents: rateLimitPolicies['billing-balance']?.quota,
|
|
209
|
+
balanceRemainingCents: rateLimits['billing-balance']?.remaining,
|
|
210
|
+
quotaLimitCredits: rateLimitPolicies['billing-quota']?.quota,
|
|
211
|
+
quotaRemainingCredits: rateLimits['billing-quota']?.remaining,
|
|
212
|
+
visitorQuotaLimitCredits: rateLimitPolicies['visitor-quota']?.quota,
|
|
213
|
+
visitorQuotaRemainingCredits: rateLimits['visitor-quota']?.remaining,
|
|
214
|
+
rawHeaders,
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function pickDetails(body: unknown): unknown {
|
|
219
|
+
if (!body || typeof body !== 'object') {
|
|
220
|
+
return undefined
|
|
221
|
+
}
|
|
222
|
+
const payload = body as Record<string, unknown>
|
|
223
|
+
if (payload.details !== undefined) {
|
|
224
|
+
return payload.details
|
|
225
|
+
}
|
|
226
|
+
if (payload.quota !== undefined) {
|
|
227
|
+
return payload.quota
|
|
228
|
+
}
|
|
229
|
+
if (payload.docs !== undefined) {
|
|
230
|
+
return payload.docs
|
|
231
|
+
}
|
|
232
|
+
return undefined
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function mapError(res: Response, body: unknown): UapiError {
|
|
236
|
+
const payload = body && typeof body === 'object' ? (body as Record<string, unknown>) : undefined
|
|
237
|
+
const code = String(payload?.code || payload?.error || defaultCode(res.status)).toUpperCase()
|
|
238
|
+
const message =
|
|
239
|
+
(payload?.message as string | undefined) ||
|
|
240
|
+
(payload?.errMsg as string | undefined) ||
|
|
241
|
+
(typeof body === 'string' ? body : '') ||
|
|
242
|
+
res.statusText ||
|
|
243
|
+
'Request failed'
|
|
244
|
+
const meta = extractMetaFromHeaders(res.headers)
|
|
245
|
+
const table: Record<string, new (...args: any[]) => UapiError> = {
|
|
246
|
+
"API_ERROR": ApiErrorError,
|
|
247
|
+
"AVATAR_NOT_FOUND": AvatarNotFoundError,
|
|
248
|
+
"CONVERSION_FAILED": ConversionFailedError,
|
|
249
|
+
"FILE_OPEN_ERROR": FileOpenErrorError,
|
|
250
|
+
"FILE_REQUIRED": FileRequiredError,
|
|
251
|
+
"INSUFFICIENT_CREDITS": InsufficientCreditsError,
|
|
252
|
+
"INTERNAL_SERVER_ERROR": InternalServerErrorError,
|
|
253
|
+
"INVALID_PARAMETER": InvalidParameterError,
|
|
254
|
+
"INVALID_PARAMS": InvalidParamsError,
|
|
255
|
+
"NOT_FOUND": NotFoundError,
|
|
256
|
+
"NO_MATCH": NoMatchError,
|
|
257
|
+
"NO_TRACKING_DATA": NoTrackingDataError,
|
|
258
|
+
"PHONE_INFO_FAILED": PhoneInfoFailedError,
|
|
259
|
+
"RECOGNITION_FAILED": RecognitionFailedError,
|
|
260
|
+
"REQUEST_ENTITY_TOO_LARGE": RequestEntityTooLargeError,
|
|
261
|
+
"SERVICE_BUSY": ServiceBusyError,
|
|
262
|
+
"TIMEZONE_NOT_FOUND": TimezoneNotFoundError,
|
|
263
|
+
"UNAUTHORIZED": UnauthorizedError,
|
|
264
|
+
"UNSUPPORTED_CARRIER": UnsupportedCarrierError,
|
|
265
|
+
"UNSUPPORTED_FORMAT": UnsupportedFormatError,
|
|
266
|
+
"VISITOR_MONTHLY_QUOTA_EXHAUSTED": VisitorMonthlyQuotaExhaustedError,
|
|
267
|
+
}
|
|
268
|
+
const fallback =
|
|
269
|
+
res.status === 401
|
|
270
|
+
? UnauthorizedError
|
|
271
|
+
: res.status === 402
|
|
272
|
+
? InsufficientCreditsError
|
|
273
|
+
: res.status === 404
|
|
274
|
+
? NotFoundError
|
|
275
|
+
: res.status === 429
|
|
276
|
+
? ServiceBusyError
|
|
277
|
+
: res.status >= 500
|
|
278
|
+
? InternalServerErrorError
|
|
279
|
+
: UapiError
|
|
280
|
+
const Ctor = table[code] || fallback
|
|
281
|
+
return new Ctor(code, res.status, message, pickDetails(payload), payload ?? body, meta)
|
|
282
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type * as Internal from '../internal/src/index.js'
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
super(`${status} ${code}`)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
2
|
+
import { UapiError, type ResponseMeta, extractMetaFromHeaders, mapError } from './errors.js'
|
|
3
|
+
export { UapiError, mapError, extractMetaFromHeaders } from './errors.js'
|
|
4
|
+
export type { RateLimitPolicyEntry, RateLimitStateEntry, ResponseMeta } from './errors.js'
|
|
8
5
|
export type GetClipzyGetResponse =
|
|
9
6
|
Internal.GetClipzyGet200Response
|
|
10
7
|
export interface GetClipzyGetArgs {
|
|
@@ -798,6 +795,7 @@ export interface PostSearchAggregateArgs {
|
|
|
798
795
|
export class UapiClient {
|
|
799
796
|
private baseURL: string
|
|
800
797
|
private token?: string
|
|
798
|
+
private _lastResponseMeta?: ResponseMeta
|
|
801
799
|
readonly clipzyZaiXianJianTieBan: ClipzyZaiXianJianTieBanApi
|
|
802
800
|
readonly "Clipzy 在线剪贴板": ClipzyZaiXianJianTieBanApi
|
|
803
801
|
readonly convert: ConvertApi
|
|
@@ -884,6 +882,10 @@ export class UapiClient {
|
|
|
884
882
|
this["智能搜索"] = zhiNengSouSuo
|
|
885
883
|
}
|
|
886
884
|
|
|
885
|
+
get lastResponseMeta(): ResponseMeta | undefined {
|
|
886
|
+
return this._lastResponseMeta
|
|
887
|
+
}
|
|
888
|
+
|
|
887
889
|
async _request(
|
|
888
890
|
method: string,
|
|
889
891
|
path: string,
|
|
@@ -914,9 +916,11 @@ export class UapiClient {
|
|
|
914
916
|
try {
|
|
915
917
|
data = await res.json()
|
|
916
918
|
} catch {}
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
+
const mapped = mapError(res, data)
|
|
920
|
+
this._lastResponseMeta = mapped.meta
|
|
921
|
+
throw mapped
|
|
919
922
|
}
|
|
923
|
+
this._lastResponseMeta = extractMetaFromHeaders(res.headers)
|
|
920
924
|
if (responseKind === 'arrayBuffer') {
|
|
921
925
|
return res.arrayBuffer()
|
|
922
926
|
}
|