@seayoo-io/combo-sdk-node 0.1.6 → 0.1.8
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/const.d.ts +1 -1
- package/dist/index.cjs +31 -15
- package/dist/index.js +30 -14
- package/dist/notify/index.d.ts +10 -6
- package/dist/request/inc/main.d.ts +17 -17
- package/dist/request/inc/retry.d.ts +2 -2
- package/dist/request/inc/type.d.ts +1 -1
- package/dist/utils/base.d.ts +4 -0
- package/dist/utils/http.d.ts +1 -1
- package/package.json +9 -8
package/dist/const.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var http = require('
|
|
3
|
-
var https = require('
|
|
1
|
+
var os = require('os');
|
|
2
|
+
var http = require('http');
|
|
3
|
+
var https = require('https');
|
|
4
4
|
var crypto = require('crypto');
|
|
5
5
|
var jsonwebtoken = require('jsonwebtoken');
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
|
12
12
|
/** SDK 名称 */
|
|
13
13
|
const SDKName = "combo-sdk-node";
|
|
14
14
|
/** SDK 版本,在编译前会被动态替换 */
|
|
15
|
-
const SDKVersion = "0.1.
|
|
15
|
+
const SDKVersion = "0.1.8";
|
|
16
16
|
/**
|
|
17
17
|
* 世游支持的服务端点列表
|
|
18
18
|
*/
|
|
@@ -57,7 +57,7 @@ exports.IdP = void 0;
|
|
|
57
57
|
})(exports.IdP || (exports.IdP = {}));
|
|
58
58
|
|
|
59
59
|
function getUserAgent(game) {
|
|
60
|
-
return `${SDKName}/${SDKVersion} game/${game} node/${process.version} os/${
|
|
60
|
+
return `${SDKName}/${SDKVersion} game/${game} node/${process.version} os/${os.platform()} arch/${os.arch()}`;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const urlReg = /^(?:https?:)?\/\/.+/i;
|
|
@@ -121,7 +121,24 @@ function getFullURL(url, baseURL = "") {
|
|
|
121
121
|
* @param url 要检查的 url,如果是自适应协议 //... 则会添加当前页面的协议信息,否则添加域名和协议信息
|
|
122
122
|
*/
|
|
123
123
|
function fillUrl(url) {
|
|
124
|
-
|
|
124
|
+
if (isFullURL(url, true)) {
|
|
125
|
+
if (url.startsWith("http")) {
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
|
+
return ("location" in globalThis ? location.protocol : "https:") + url;
|
|
129
|
+
}
|
|
130
|
+
return ("location" in globalThis ? location.origin + "/" : "http://127.0.0.1/") + url.replace(/^\/+/, "");
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 简版 Object.fromEntries
|
|
134
|
+
*/
|
|
135
|
+
function fromEntries(kv) {
|
|
136
|
+
return kv.reduce((result, [key, value]) => {
|
|
137
|
+
if (key) {
|
|
138
|
+
result[key] = value || "";
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
}, {});
|
|
125
142
|
}
|
|
126
143
|
function parseJSON(str, typeGuard) {
|
|
127
144
|
try {
|
|
@@ -287,7 +304,7 @@ function parseRawAuthHeader(authString, prefix) {
|
|
|
287
304
|
if (!authString || !authString.startsWith(prefix + " ")) {
|
|
288
305
|
return null;
|
|
289
306
|
}
|
|
290
|
-
return
|
|
307
|
+
return fromEntries(authString.substring(prefix.length + 1).split(",").map(kvs => {
|
|
291
308
|
const kv = kvs.split("=");
|
|
292
309
|
if (kv.length !== 2) {
|
|
293
310
|
return null;
|
|
@@ -534,7 +551,7 @@ function handleResponse(res, url, config, options) {
|
|
|
534
551
|
const result = {
|
|
535
552
|
...analyseResponse(res.status, res.statusText, res.body, config.get("responseRule"), options == null ? void 0 : options.responseRule),
|
|
536
553
|
status: res.status,
|
|
537
|
-
headers:
|
|
554
|
+
headers: fromEntries(Object.entries(res.headers || {}).map(([key, value]) => [key.toLowerCase(), value]))
|
|
538
555
|
};
|
|
539
556
|
// 全局处理响应结果 (浅复制,防止被修改,同时保留修改 result.data 的可能性)
|
|
540
557
|
(_config$get2 = config.get("responseHandler")) == null || _config$get2({
|
|
@@ -558,15 +575,14 @@ async function convertOptions(url, config, options) {
|
|
|
558
575
|
const opt = Object.assign({
|
|
559
576
|
method: "GET"
|
|
560
577
|
}, options);
|
|
561
|
-
const
|
|
562
|
-
const method = isFormMode ? "POST" : opt.method;
|
|
578
|
+
const method = opt.method;
|
|
563
579
|
if (method === "GET" || method === "HEAD" || method === "DELETE") {
|
|
564
580
|
if (opt.body !== undefined) {
|
|
565
581
|
console.warn("request body is invalid with method get, head, delete");
|
|
566
582
|
delete opt.body;
|
|
567
583
|
}
|
|
568
584
|
}
|
|
569
|
-
const headers = Object.assign(
|
|
585
|
+
const headers = Object.assign({
|
|
570
586
|
"Content-Type": "application/json;charset=utf-8"
|
|
571
587
|
}, opt.headers);
|
|
572
588
|
const p = opt.params || {};
|
|
@@ -621,7 +637,7 @@ function convertBody(body) {
|
|
|
621
637
|
if (!body) {
|
|
622
638
|
return;
|
|
623
639
|
}
|
|
624
|
-
if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof
|
|
640
|
+
if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof URLSearchParams || typeof body === "string") {
|
|
625
641
|
return body;
|
|
626
642
|
}
|
|
627
643
|
return JSON.stringify(body);
|
|
@@ -655,7 +671,7 @@ const coreNodeRequest = async function (url, config, options) {
|
|
|
655
671
|
}
|
|
656
672
|
const isHeadRequest = opt.method === "HEAD";
|
|
657
673
|
return new Promise(resolve => {
|
|
658
|
-
const req = client.request(iURL, {
|
|
674
|
+
const req = client.request(iURL.toString(), {
|
|
659
675
|
headers: opt.headers,
|
|
660
676
|
method: opt.method,
|
|
661
677
|
timeout: opt.timeout > 0 ? opt.timeout : undefined
|
|
@@ -663,7 +679,7 @@ const coreNodeRequest = async function (url, config, options) {
|
|
|
663
679
|
const resbody = [];
|
|
664
680
|
res.on("data", chunk => resbody.push(chunk));
|
|
665
681
|
res.on("end", () => {
|
|
666
|
-
const headers =
|
|
682
|
+
const headers = fromEntries(Object.entries(res.headers).map(([key, value]) => {
|
|
667
683
|
return [key.toLowerCase(), Array.isArray(value) ? value.join(",") : value];
|
|
668
684
|
}));
|
|
669
685
|
resolve({
|
|
@@ -1155,7 +1171,7 @@ function isNotificationRequestBody(data) {
|
|
|
1155
1171
|
*
|
|
1156
1172
|
* 另有 express 和 koa2 版本的处理函数可以使用。
|
|
1157
1173
|
*
|
|
1158
|
-
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody
|
|
1174
|
+
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody 字符串以核验签名
|
|
1159
1175
|
*/
|
|
1160
1176
|
function getNotificationHandler(config, handler) {
|
|
1161
1177
|
verifyConfig(config);
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { platform, arch } from '
|
|
2
|
-
import http from '
|
|
3
|
-
import https from '
|
|
1
|
+
import { platform, arch } from 'os';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import https from 'https';
|
|
4
4
|
import { createHash, createHmac } from 'crypto';
|
|
5
5
|
import { verify } from 'jsonwebtoken';
|
|
6
6
|
|
|
7
7
|
/** SDK 名称 */
|
|
8
8
|
const SDKName = "combo-sdk-node";
|
|
9
9
|
/** SDK 版本,在编译前会被动态替换 */
|
|
10
|
-
const SDKVersion = "0.1.
|
|
10
|
+
const SDKVersion = "0.1.8";
|
|
11
11
|
/**
|
|
12
12
|
* 世游支持的服务端点列表
|
|
13
13
|
*/
|
|
@@ -116,7 +116,24 @@ function getFullURL(url, baseURL = "") {
|
|
|
116
116
|
* @param url 要检查的 url,如果是自适应协议 //... 则会添加当前页面的协议信息,否则添加域名和协议信息
|
|
117
117
|
*/
|
|
118
118
|
function fillUrl(url) {
|
|
119
|
-
|
|
119
|
+
if (isFullURL(url, true)) {
|
|
120
|
+
if (url.startsWith("http")) {
|
|
121
|
+
return url;
|
|
122
|
+
}
|
|
123
|
+
return ("location" in globalThis ? location.protocol : "https:") + url;
|
|
124
|
+
}
|
|
125
|
+
return ("location" in globalThis ? location.origin + "/" : "http://127.0.0.1/") + url.replace(/^\/+/, "");
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 简版 Object.fromEntries
|
|
129
|
+
*/
|
|
130
|
+
function fromEntries(kv) {
|
|
131
|
+
return kv.reduce((result, [key, value]) => {
|
|
132
|
+
if (key) {
|
|
133
|
+
result[key] = value || "";
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}, {});
|
|
120
137
|
}
|
|
121
138
|
function parseJSON(str, typeGuard) {
|
|
122
139
|
try {
|
|
@@ -282,7 +299,7 @@ function parseRawAuthHeader(authString, prefix) {
|
|
|
282
299
|
if (!authString || !authString.startsWith(prefix + " ")) {
|
|
283
300
|
return null;
|
|
284
301
|
}
|
|
285
|
-
return
|
|
302
|
+
return fromEntries(authString.substring(prefix.length + 1).split(",").map(kvs => {
|
|
286
303
|
const kv = kvs.split("=");
|
|
287
304
|
if (kv.length !== 2) {
|
|
288
305
|
return null;
|
|
@@ -529,7 +546,7 @@ function handleResponse(res, url, config, options) {
|
|
|
529
546
|
const result = {
|
|
530
547
|
...analyseResponse(res.status, res.statusText, res.body, config.get("responseRule"), options == null ? void 0 : options.responseRule),
|
|
531
548
|
status: res.status,
|
|
532
|
-
headers:
|
|
549
|
+
headers: fromEntries(Object.entries(res.headers || {}).map(([key, value]) => [key.toLowerCase(), value]))
|
|
533
550
|
};
|
|
534
551
|
// 全局处理响应结果 (浅复制,防止被修改,同时保留修改 result.data 的可能性)
|
|
535
552
|
(_config$get2 = config.get("responseHandler")) == null || _config$get2({
|
|
@@ -553,15 +570,14 @@ async function convertOptions(url, config, options) {
|
|
|
553
570
|
const opt = Object.assign({
|
|
554
571
|
method: "GET"
|
|
555
572
|
}, options);
|
|
556
|
-
const
|
|
557
|
-
const method = isFormMode ? "POST" : opt.method;
|
|
573
|
+
const method = opt.method;
|
|
558
574
|
if (method === "GET" || method === "HEAD" || method === "DELETE") {
|
|
559
575
|
if (opt.body !== undefined) {
|
|
560
576
|
console.warn("request body is invalid with method get, head, delete");
|
|
561
577
|
delete opt.body;
|
|
562
578
|
}
|
|
563
579
|
}
|
|
564
|
-
const headers = Object.assign(
|
|
580
|
+
const headers = Object.assign({
|
|
565
581
|
"Content-Type": "application/json;charset=utf-8"
|
|
566
582
|
}, opt.headers);
|
|
567
583
|
const p = opt.params || {};
|
|
@@ -616,7 +632,7 @@ function convertBody(body) {
|
|
|
616
632
|
if (!body) {
|
|
617
633
|
return;
|
|
618
634
|
}
|
|
619
|
-
if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof
|
|
635
|
+
if (body instanceof Blob || body instanceof ArrayBuffer || body instanceof URLSearchParams || typeof body === "string") {
|
|
620
636
|
return body;
|
|
621
637
|
}
|
|
622
638
|
return JSON.stringify(body);
|
|
@@ -650,7 +666,7 @@ const coreNodeRequest = async function (url, config, options) {
|
|
|
650
666
|
}
|
|
651
667
|
const isHeadRequest = opt.method === "HEAD";
|
|
652
668
|
return new Promise(resolve => {
|
|
653
|
-
const req = client.request(iURL, {
|
|
669
|
+
const req = client.request(iURL.toString(), {
|
|
654
670
|
headers: opt.headers,
|
|
655
671
|
method: opt.method,
|
|
656
672
|
timeout: opt.timeout > 0 ? opt.timeout : undefined
|
|
@@ -658,7 +674,7 @@ const coreNodeRequest = async function (url, config, options) {
|
|
|
658
674
|
const resbody = [];
|
|
659
675
|
res.on("data", chunk => resbody.push(chunk));
|
|
660
676
|
res.on("end", () => {
|
|
661
|
-
const headers =
|
|
677
|
+
const headers = fromEntries(Object.entries(res.headers).map(([key, value]) => {
|
|
662
678
|
return [key.toLowerCase(), Array.isArray(value) ? value.join(",") : value];
|
|
663
679
|
}));
|
|
664
680
|
resolve({
|
|
@@ -1150,7 +1166,7 @@ function isNotificationRequestBody(data) {
|
|
|
1150
1166
|
*
|
|
1151
1167
|
* 另有 express 和 koa2 版本的处理函数可以使用。
|
|
1152
1168
|
*
|
|
1153
|
-
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody
|
|
1169
|
+
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody 字符串以核验签名
|
|
1154
1170
|
*/
|
|
1155
1171
|
function getNotificationHandler(config, handler) {
|
|
1156
1172
|
verifyConfig(config);
|
package/dist/notify/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { type SDKBaseConfig } from "../utils";
|
|
2
2
|
import { type NotificationHandler } from "./types";
|
|
3
3
|
import type { ParameterizedContext, Next } from "koa";
|
|
4
|
-
import type { IncomingMessage, ServerResponse } from "
|
|
4
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
5
5
|
import type { Request as ExpressRequest, Response as ExpressResponse, NextFunction as ExpressNextFunction } from "express";
|
|
6
6
|
/**
|
|
7
7
|
* 获取一个处理函数用于接收 Seayoo Server 推送过来的消息通知
|
|
8
8
|
*
|
|
9
9
|
* 另有 express 和 koa2 版本的处理函数可以使用。
|
|
10
10
|
*
|
|
11
|
-
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody
|
|
11
|
+
* 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody 字符串以核验签名
|
|
12
12
|
*/
|
|
13
13
|
export declare function getNotificationHandler(config: SDKBaseConfig, handler: NotificationHandler): (req: IncomingMessage, res: ServerResponse, rawBodyString?: string) => Promise<void>;
|
|
14
14
|
/**
|
|
@@ -22,13 +22,15 @@ export declare function getNotificationHandler(config: SDKBaseConfig, handler: N
|
|
|
22
22
|
*
|
|
23
23
|
* https://cloud.tencent.com/developer/ask/sof/110062928
|
|
24
24
|
*/
|
|
25
|
-
export declare function getNotificationHandlerForExpress(config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest
|
|
25
|
+
export declare function getNotificationHandlerForExpress(config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest & {
|
|
26
|
+
rawBody?: string;
|
|
27
|
+
}, res: ExpressResponse) => Promise<void>;
|
|
26
28
|
/**
|
|
27
29
|
* 获取基于 express 的中间件用于接收 Seayoo Server 推送过来的消息通知
|
|
28
30
|
*
|
|
29
31
|
* 需要先于 body-parse 等类似插件加载
|
|
30
32
|
*/
|
|
31
|
-
export declare function getNotificationMiddlewareForExpress(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest, res:
|
|
33
|
+
export declare function getNotificationMiddlewareForExpress(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest, res: ServerResponse, next: ExpressNextFunction) => Promise<void>;
|
|
32
34
|
/**
|
|
33
35
|
* 获取基于 koa2 的处理函数用于接收 Seayoo Server 推送过来的消息通知
|
|
34
36
|
*
|
|
@@ -36,10 +38,12 @@ export declare function getNotificationMiddlewareForExpress(paths: string | stri
|
|
|
36
38
|
*
|
|
37
39
|
* 如果 koa 使用全局的 koa-body 或类似插件,将需要做额外的处理以获取原始请求的内容 rawBody 以用以计算签名
|
|
38
40
|
*/
|
|
39
|
-
export declare function getNotificationHandlerForKoa(config: SDKBaseConfig, handler: NotificationHandler): (ctx: ParameterizedContext
|
|
41
|
+
export declare function getNotificationHandlerForKoa(config: SDKBaseConfig, handler: NotificationHandler): (ctx: Pick<ParameterizedContext, "req" | "res"> & {
|
|
42
|
+
rawBody?: string;
|
|
43
|
+
}) => Promise<void>;
|
|
40
44
|
/**
|
|
41
45
|
* 获取基于 koa2 的中间件用于接收 Seayoo Server 推送过来的消息通知
|
|
42
46
|
*
|
|
43
47
|
* 需要先于 koa-body 等类似插件加载
|
|
44
48
|
*/
|
|
45
|
-
export declare function getNotificationMiddlewareForKoa(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (ctx: ParameterizedContext, next: Next) => Promise<void>;
|
|
49
|
+
export declare function getNotificationMiddlewareForKoa(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (ctx: Pick<ParameterizedContext, "method" | "path" | "req" | "res">, next: Next) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TypeGuardParam, IRequestOptions, IRequestGlobalConfig,
|
|
1
|
+
import type { TypeGuardParam, IRequestOptions, IRequestGlobalConfig, IResponseResult, NetRequestAgent } from "./type";
|
|
2
2
|
type RequestBody = NonNullable<IRequestOptions["body"]>;
|
|
3
3
|
/** 工具函数主类 */
|
|
4
4
|
export declare class NetRequestHandler {
|
|
@@ -25,36 +25,36 @@ export declare class NetRequestHandler {
|
|
|
25
25
|
/**
|
|
26
26
|
* 发送一个 HEAD 请求,并且不处理响应 body
|
|
27
27
|
*/
|
|
28
|
-
head(url: string, options?: IRequestOptions):
|
|
28
|
+
head(url: string, options?: IRequestOptions): Promise<IResponseResult>;
|
|
29
29
|
/**
|
|
30
30
|
* 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景
|
|
31
31
|
*/
|
|
32
|
-
get(url: string):
|
|
33
|
-
get(url: string, typeGard: null, options?: IRequestOptions):
|
|
34
|
-
get<T>(url: string, typeGard: TypeGuardParam<T>, options?: IRequestOptions):
|
|
32
|
+
get(url: string): Promise<IResponseResult>;
|
|
33
|
+
get(url: string, typeGard: null, options?: IRequestOptions): Promise<IResponseResult>;
|
|
34
|
+
get<T>(url: string, typeGard: TypeGuardParam<T>, options?: IRequestOptions): Promise<IResponseResult<T | null>>;
|
|
35
35
|
/**
|
|
36
36
|
* 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
|
|
37
37
|
*/
|
|
38
|
-
post(url: string, data: RequestBody):
|
|
39
|
-
post(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions):
|
|
40
|
-
post<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions):
|
|
38
|
+
post(url: string, data: RequestBody): Promise<IResponseResult>;
|
|
39
|
+
post(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions): Promise<IResponseResult>;
|
|
40
|
+
post<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions): Promise<IResponseResult<T | null>>;
|
|
41
41
|
/**
|
|
42
42
|
* 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
|
|
43
43
|
*/
|
|
44
|
-
del(url: string):
|
|
45
|
-
del(url: string, typeGard: null, options?: IRequestOptions):
|
|
46
|
-
del<T>(url: string, typeGard: TypeGuardParam<T>, options?: IRequestOptions):
|
|
44
|
+
del(url: string): Promise<IResponseResult>;
|
|
45
|
+
del(url: string, typeGard: null, options?: IRequestOptions): Promise<IResponseResult>;
|
|
46
|
+
del<T>(url: string, typeGard: TypeGuardParam<T>, options?: IRequestOptions): Promise<IResponseResult<T | null>>;
|
|
47
47
|
/**
|
|
48
48
|
* 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
|
|
49
49
|
*/
|
|
50
|
-
put(url: string, data: RequestBody):
|
|
51
|
-
put(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions):
|
|
52
|
-
put<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions):
|
|
50
|
+
put(url: string, data: RequestBody): Promise<IResponseResult>;
|
|
51
|
+
put(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions): Promise<IResponseResult>;
|
|
52
|
+
put<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions): Promise<IResponseResult<T | null>>;
|
|
53
53
|
/**
|
|
54
54
|
* 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
|
|
55
55
|
*/
|
|
56
|
-
patch(url: string, data: RequestBody):
|
|
57
|
-
patch(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions):
|
|
58
|
-
patch<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions):
|
|
56
|
+
patch(url: string, data: RequestBody): Promise<IResponseResult>;
|
|
57
|
+
patch(url: string, data: RequestBody, typeGard: null, options?: IRequestOptions): Promise<IResponseResult>;
|
|
58
|
+
patch<T>(url: string, data: RequestBody, typeGard: TypeGuardParam<T>, options?: IRequestOptions): Promise<IResponseResult<T | null>>;
|
|
59
59
|
}
|
|
60
60
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NetRequestCoreFn, IRequestOptions } from "./type";
|
|
1
|
+
import { NetRequestCoreFn, IRequestOptions, IRequestBaseResponse } from "./type";
|
|
2
2
|
import type { RequestGlobalConfig } from "./config";
|
|
3
|
-
export declare function retryRequest(agent: NetRequestCoreFn, url: string, config: RequestGlobalConfig, options?: IRequestOptions, _try?: number):
|
|
3
|
+
export declare function retryRequest(agent: NetRequestCoreFn, url: string, config: RequestGlobalConfig, options?: IRequestOptions, _try?: number): Promise<IRequestBaseResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RequestGlobalConfig } from "./config";
|
|
2
2
|
import type { MaybePromise, TypeGuard, TypeGuardFn } from "../../utils";
|
|
3
|
-
export type IBaseRequestBody = Blob | ArrayBuffer |
|
|
3
|
+
export type IBaseRequestBody = Blob | ArrayBuffer | URLSearchParams | string;
|
|
4
4
|
/** 通用网络请求工具的基本配置 */
|
|
5
5
|
export interface IBaseRequestOptions {
|
|
6
6
|
/** 网络请求方法,默认 GET */
|
package/dist/utils/base.d.ts
CHANGED
|
@@ -34,6 +34,10 @@ export declare function isJsonLike(text: string): boolean;
|
|
|
34
34
|
* @param baseURL 可选 baseURL
|
|
35
35
|
*/
|
|
36
36
|
export declare function getFullURL(url: string, baseURL?: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* 简版 Object.fromEntries
|
|
39
|
+
*/
|
|
40
|
+
export declare function fromEntries(kv: [string, string | undefined][]): Record<string, string>;
|
|
37
41
|
/**
|
|
38
42
|
* JSON.parse的扩展,格式化错误则返回 null,第二个参数为可选 typeGuard
|
|
39
43
|
*/
|
package/dist/utils/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { IncomingMessage, ServerResponse } from "
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from "http";
|
|
3
3
|
export declare function readBody(req: IncomingMessage, backup?: string): Promise<string>;
|
|
4
4
|
export declare function done(res: ServerResponse, statusCode: number, message?: string): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-io/combo-sdk-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Combo SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"pub": "pnpm type-check && pnpm lint:fix && vitest run && pnpm build && npm publish"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">=12"
|
|
31
31
|
},
|
|
32
32
|
"simple-git-hooks": {
|
|
33
33
|
"pre-commit": "pnpm lint && pnpm type-check"
|
|
@@ -44,19 +44,20 @@
|
|
|
44
44
|
"@types/express": "^4.17.21",
|
|
45
45
|
"@types/jsonwebtoken": "^9.0.5",
|
|
46
46
|
"@types/koa": "^2.13.12",
|
|
47
|
-
"@types/node": "
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
49
|
-
"@typescript-eslint/parser": "^6.
|
|
47
|
+
"@types/node": "12.0.0",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
|
49
|
+
"@typescript-eslint/parser": "^6.18.1",
|
|
50
50
|
"eslint": "^8.56.0",
|
|
51
51
|
"eslint-config-prettier": "^9.1.0",
|
|
52
52
|
"eslint-plugin-prettier": "^5.1.2",
|
|
53
53
|
"lint-staged": "^15.2.0",
|
|
54
54
|
"microbundle": "^0.15.1",
|
|
55
|
-
"msw": "^2.0.
|
|
55
|
+
"msw": "^2.0.12",
|
|
56
56
|
"rimraf": "^5.0.5",
|
|
57
57
|
"simple-git-hooks": "^2.9.0",
|
|
58
|
-
"typescript": "
|
|
59
|
-
"
|
|
58
|
+
"typescript": "5.2.2",
|
|
59
|
+
"vite": "^3.2.7",
|
|
60
|
+
"vitest": "^0.34.6"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"jsonwebtoken": "^9.0.2"
|