@kevisual/api 0.0.43 → 0.0.46

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.
@@ -1,45 +0,0 @@
1
- import { Query } from '@kevisual/query';
2
-
3
- /**
4
- * 配置查询
5
- * @updatedAt 2025-12-03 10:33:00
6
- */
7
-
8
- type QueryConfigOpts = {
9
- query?: Query;
10
- };
11
- type Config<T = any> = {
12
- id?: string;
13
- title?: string;
14
- key?: string;
15
- description?: string;
16
- data?: T;
17
- createdAt?: string;
18
- updatedAt?: string;
19
- };
20
- type UploadConfig = {
21
- key?: string;
22
- version?: string;
23
- };
24
- type PostOpts = {
25
- token?: string;
26
- payload?: Record<string, any>;
27
- };
28
- declare class QueryConfig {
29
- query: Query;
30
- constructor(opts?: QueryConfigOpts);
31
- post<T = Config>(data: any): Promise<any>;
32
- getItem({ id, key }: {
33
- id?: string;
34
- key?: string;
35
- }, opts?: PostOpts): Promise<any>;
36
- updateItem(data: Config, opts?: PostOpts): Promise<any>;
37
- deleteItem(data: {
38
- id?: string;
39
- key?: string;
40
- }, opts?: PostOpts): Promise<any>;
41
- listItems(opts?: PostOpts): Promise<any>;
42
- }
43
-
44
- export { QueryConfig };
45
- export type { Config, UploadConfig };
@@ -1,299 +0,0 @@
1
- // node_modules/.pnpm/@kevisual+query@0.0.39/node_modules/@kevisual/query/dist/query-browser.js
2
- var isTextForContentType = (contentType) => {
3
- if (!contentType)
4
- return false;
5
- const textTypes = ["text/", "xml", "html", "javascript", "css", "csv", "plain", "x-www-form-urlencoded", "md"];
6
- return textTypes.some((type) => contentType.includes(type));
7
- };
8
- var adapter = async (opts = {}, overloadOpts) => {
9
- const controller = new AbortController;
10
- const signal = controller.signal;
11
- const isPostFile = opts.isPostFile || false;
12
- let responseType = opts.responseType || "json";
13
- if (opts.isBlob) {
14
- responseType = "blob";
15
- } else if (opts.isText) {
16
- responseType = "text";
17
- }
18
- const timeout = opts.timeout || 60000 * 3;
19
- const timer = setTimeout(() => {
20
- controller.abort();
21
- }, timeout);
22
- let method = overloadOpts?.method || opts?.method || "POST";
23
- let headers = { ...opts?.headers, ...overloadOpts?.headers };
24
- let origin = "";
25
- let url;
26
- if (opts?.url?.startsWith("http")) {
27
- url = new URL(opts.url);
28
- } else {
29
- origin = window?.location?.origin || "http://localhost:51515";
30
- url = new URL(opts.url, origin);
31
- }
32
- const isGet = method === "GET";
33
- const oldSearchParams = url.searchParams;
34
- if (isGet) {
35
- let searchParams = new URLSearchParams({ ...Object.fromEntries(oldSearchParams), ...opts.body });
36
- url.search = searchParams.toString();
37
- } else {
38
- const params = {
39
- ...Object.fromEntries(oldSearchParams),
40
- ...opts.params
41
- };
42
- const searchParams = new URLSearchParams(params);
43
- if (typeof opts.body === "object" && opts.body !== null) {
44
- let body2 = opts.body || {};
45
- if (!params.path && body2?.path) {
46
- searchParams.set("path", body2.path);
47
- if (body2?.key) {
48
- searchParams.set("key", body2.key);
49
- }
50
- }
51
- }
52
- url.search = searchParams.toString();
53
- }
54
- let body = undefined;
55
- if (isGet) {
56
- body = undefined;
57
- } else if (isPostFile) {
58
- body = opts.body;
59
- } else {
60
- headers = {
61
- "Content-Type": "application/json",
62
- ...headers
63
- };
64
- body = JSON.stringify(opts.body);
65
- }
66
- return fetch(url, {
67
- method: method.toUpperCase(),
68
- signal,
69
- body,
70
- ...overloadOpts,
71
- headers
72
- }).then(async (response) => {
73
- const contentType = response.headers.get("Content-Type");
74
- if (responseType === "blob") {
75
- return await response.blob();
76
- }
77
- const isText = responseType === "text";
78
- const isJson = contentType && contentType.includes("application/json");
79
- if (isJson && !isText) {
80
- return await response.json();
81
- } else if (isTextForContentType(contentType)) {
82
- return {
83
- code: response.status,
84
- status: response.status,
85
- data: await response.text()
86
- };
87
- } else {
88
- return response;
89
- }
90
- }).catch((err) => {
91
- if (err.name === "AbortError") {
92
- return {
93
- code: 408,
94
- message: "请求超时"
95
- };
96
- }
97
- return {
98
- code: 500,
99
- message: err.message || "网络错误"
100
- };
101
- }).finally(() => {
102
- clearTimeout(timer);
103
- });
104
- };
105
- var wrapperError = ({ code, message }) => {
106
- const result = {
107
- code: code || 500,
108
- success: false,
109
- message: message || "api request error",
110
- showError: (fn) => {},
111
- noMsg: true
112
- };
113
- return result;
114
- };
115
-
116
- class Query {
117
- adapter;
118
- url;
119
- beforeRequest;
120
- afterResponse;
121
- headers;
122
- timeout;
123
- stop;
124
- qws;
125
- isClient = false;
126
- constructor(opts) {
127
- this.adapter = opts?.adapter || adapter;
128
- const defaultURL = opts?.isClient ? "/client/router" : "/api/router";
129
- this.url = opts?.url || defaultURL;
130
- this.headers = opts?.headers || {
131
- "Content-Type": "application/json"
132
- };
133
- this.timeout = opts?.timeout || 60000 * 3;
134
- if (opts.beforeRequest) {
135
- this.beforeRequest = opts.beforeRequest;
136
- } else {
137
- this.beforeRequest = async (opts2) => {
138
- const token = globalThis?.localStorage?.getItem("token");
139
- if (token) {
140
- opts2.headers = {
141
- ...opts2.headers,
142
- Authorization: `Bearer ${token}`
143
- };
144
- }
145
- return opts2;
146
- };
147
- }
148
- }
149
- setQueryWs(qws) {
150
- this.qws = qws;
151
- }
152
- setStop(stop) {
153
- this.stop = stop;
154
- }
155
- async get(params, options) {
156
- return this.post(params, options);
157
- }
158
- async post(body, options) {
159
- const url = options?.url || this.url;
160
- const { headers, adapter: adapter2, beforeRequest, afterResponse, timeout, ...rest } = options || {};
161
- const _headers = { ...this.headers, ...headers };
162
- const _adapter = adapter2 || this.adapter;
163
- const _beforeRequest = beforeRequest || this.beforeRequest;
164
- const _afterResponse = afterResponse || this.afterResponse;
165
- const _timeout = timeout || this.timeout;
166
- const req = {
167
- url,
168
- headers: _headers,
169
- body,
170
- timeout: _timeout,
171
- ...rest
172
- };
173
- try {
174
- if (_beforeRequest) {
175
- const res = await _beforeRequest(req);
176
- if (res === false) {
177
- return wrapperError({
178
- code: 500,
179
- message: "request is cancel",
180
- req
181
- });
182
- }
183
- }
184
- } catch (e) {
185
- console.error("request beforeFn error", e, req);
186
- return wrapperError({
187
- code: 500,
188
- message: "api request beforeFn error"
189
- });
190
- }
191
- if (this.stop && !options?.noStop) {
192
- const that = this;
193
- await new Promise((resolve) => {
194
- let timer = 0;
195
- const detect = setInterval(() => {
196
- if (!that.stop) {
197
- clearInterval(detect);
198
- resolve(true);
199
- }
200
- timer++;
201
- if (timer > 30) {
202
- console.error("request stop: timeout", req.url, timer);
203
- }
204
- }, 1000);
205
- });
206
- }
207
- return _adapter(req).then(async (res) => {
208
- try {
209
- if (_afterResponse) {
210
- return await _afterResponse(res, {
211
- req,
212
- res,
213
- fetch: adapter2
214
- });
215
- }
216
- return res;
217
- } catch (e) {
218
- console.error("request afterFn error", e, req);
219
- return wrapperError({
220
- code: 500,
221
- message: "api request afterFn error"
222
- });
223
- }
224
- });
225
- }
226
- before(fn) {
227
- this.beforeRequest = fn;
228
- }
229
- after(fn) {
230
- this.afterResponse = fn;
231
- }
232
- async fetchText(urlOrOptions, options) {
233
- let _options = { ...options };
234
- if (typeof urlOrOptions === "string" && !_options.url) {
235
- _options.url = urlOrOptions;
236
- }
237
- if (typeof urlOrOptions === "object") {
238
- _options = { ...urlOrOptions, ..._options };
239
- }
240
- const res = await adapter({
241
- method: "GET",
242
- ..._options,
243
- headers: {
244
- ...this.headers,
245
- ..._options?.headers || {}
246
- }
247
- });
248
- if (res && !res.code) {
249
- return {
250
- code: 200,
251
- data: res
252
- };
253
- }
254
- return res;
255
- }
256
- }
257
-
258
- // query/query-secret/query-secret.ts
259
- class QueryConfig {
260
- query;
261
- constructor(opts) {
262
- this.query = opts?.query || new Query;
263
- }
264
- async post(data) {
265
- return this.query.post({ path: "secret", ...data });
266
- }
267
- async getItem({ id, key }, opts) {
268
- return this.post({
269
- key: "get",
270
- data: {
271
- id,
272
- key
273
- },
274
- ...opts
275
- });
276
- }
277
- async updateItem(data, opts) {
278
- return this.post({
279
- key: "update",
280
- data,
281
- ...opts
282
- });
283
- }
284
- async deleteItem(data, opts) {
285
- return this.post({
286
- key: "delete",
287
- data
288
- });
289
- }
290
- async listItems(opts) {
291
- return this.post({
292
- key: "list",
293
- ...opts
294
- });
295
- }
296
- }
297
- export {
298
- QueryConfig
299
- };
@@ -1,12 +0,0 @@
1
- import { Query, BaseQuery, DataOpts } from '@kevisual/query/query';
2
-
3
- declare const shopDefine: any;
4
-
5
- declare class QueryShop<T extends Query = Query> extends BaseQuery<T> {
6
- constructor(opts?: {
7
- query: T;
8
- });
9
- getInstall(data: any, opts?: DataOpts): any;
10
- }
11
-
12
- export { QueryShop, shopDefine };