@seayoo-io/combo-sdk-node 1.6.0 → 1.8.1
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 +71 -56
- package/dist/index.cjs +1448 -1585
- package/dist/index.d.cts +848 -0
- package/dist/index.d.ts +848 -15
- package/dist/index.js +1418 -1581
- package/package.json +40 -24
- package/dist/api/index.d.ts +0 -55
- package/dist/api/types.d.ts +0 -87
- package/dist/api/ua.d.ts +0 -1
- package/dist/const.d.ts +0 -143
- package/dist/gm/index.d.ts +0 -51
- package/dist/gm/types.d.ts +0 -58
- package/dist/gm/utils.d.ts +0 -31
- package/dist/notify/index.d.ts +0 -49
- package/dist/notify/msgRefund.d.ts +0 -20
- package/dist/notify/msgShipOrder.d.ts +0 -26
- package/dist/notify/types.d.ts +0 -49
- package/dist/request/inc/cache.d.ts +0 -10
- package/dist/request/inc/config.d.ts +0 -12
- package/dist/request/inc/guard.d.ts +0 -3
- package/dist/request/inc/main.d.ts +0 -60
- package/dist/request/inc/option.d.ts +0 -10
- package/dist/request/inc/request.d.ts +0 -7
- package/dist/request/inc/response.d.ts +0 -3
- package/dist/request/inc/retry.d.ts +0 -3
- package/dist/request/inc/rule.d.ts +0 -12
- package/dist/request/inc/type.d.ts +0 -181
- package/dist/request/index.d.ts +0 -4
- package/dist/utils/base.d.ts +0 -46
- package/dist/utils/config.d.ts +0 -17
- package/dist/utils/gcm.d.ts +0 -9
- package/dist/utils/http.d.ts +0 -6
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/signer.d.ts +0 -34
- package/dist/utils/types.d.ts +0 -18
- package/dist/verify/ads.d.ts +0 -21
- package/dist/verify/id.d.ts +0 -78
- package/dist/verify/index.d.ts +0 -23
- package/vitest.config.ts +0 -10
package/dist/notify/types.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { isShipOrderPayload, type ShipOrderNotification } from "./msgShipOrder";
|
|
2
|
-
import { isRefundPayload, type RefundNotification } from "./msgRefund";
|
|
3
|
-
import type { MaybePromise } from "../utils";
|
|
4
|
-
/**
|
|
5
|
-
* 通知类型枚举
|
|
6
|
-
*/
|
|
7
|
-
export declare const enum NotificationType {
|
|
8
|
-
/**
|
|
9
|
-
* 世游服务端会在订单状态变更为已支付时,向游戏侧推送发货通知。
|
|
10
|
-
*
|
|
11
|
-
* 游戏侧需要在收到通知后,根据通知中的订单信息,发货给用户:
|
|
12
|
-
*
|
|
13
|
-
* - 如果游戏内发货成功,则应当返回 void 或 Promise<void>
|
|
14
|
-
* - 如果游戏内发货出现错误,则应当 throw Error。世游服务端会在稍后重试推送发货通知。
|
|
15
|
-
*/
|
|
16
|
-
ShipOrder = "ship_order",
|
|
17
|
-
/**
|
|
18
|
-
* 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
|
|
19
|
-
*/
|
|
20
|
-
Refund = "refund"
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 通知类型对应的 payload
|
|
24
|
-
*/
|
|
25
|
-
export interface ENotificationPayload {
|
|
26
|
-
[NotificationType.ShipOrder]: ShipOrderNotification;
|
|
27
|
-
[NotificationType.Refund]: RefundNotification;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 自定义通知处理函数
|
|
31
|
-
*
|
|
32
|
-
* 每种消息类型对应不同的 payload 以及返回值具体可以查看类型定义
|
|
33
|
-
*/
|
|
34
|
-
export type NotificationHandler = {
|
|
35
|
-
<T extends NotificationType>(type: T, payload: ENotificationPayload[T]): MaybePromise<void>;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* 消息处理分发配置
|
|
39
|
-
*/
|
|
40
|
-
export declare const messageDataGuards: {
|
|
41
|
-
readonly ship_order: {
|
|
42
|
-
readonly guard: typeof isShipOrderPayload;
|
|
43
|
-
readonly message: "ShipOrder Data Format Error";
|
|
44
|
-
};
|
|
45
|
-
readonly refund: {
|
|
46
|
-
readonly guard: typeof isRefundPayload;
|
|
47
|
-
readonly message: "Refund Data Format Error";
|
|
48
|
-
};
|
|
49
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** 为 get 请求并发而设计的缓冲工具 */
|
|
2
|
-
export declare class Cache<T = unknown> {
|
|
3
|
-
private ttl;
|
|
4
|
-
private cache;
|
|
5
|
-
constructor(ttl?: number);
|
|
6
|
-
getKey(url: string, param?: Record<string, unknown>): string;
|
|
7
|
-
updateTTL(ttl: number): void;
|
|
8
|
-
get(key: string): Promise<T> | null;
|
|
9
|
-
set(key: string, action: Promise<T>): void;
|
|
10
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type SomeRequired } from "../../utils";
|
|
2
|
-
import type { IRequestGlobalConfig } from "./type";
|
|
3
|
-
export declare class RequestGlobalConfig {
|
|
4
|
-
private config;
|
|
5
|
-
constructor(config?: IRequestGlobalConfig);
|
|
6
|
-
set(config: Partial<IRequestGlobalConfig>): void;
|
|
7
|
-
get<T extends keyof IRequestGlobalConfig>(key: T): SomeRequired<IRequestGlobalConfig, "timeout" | "maxRetry" | "retryInterval" | "baseURL" | "responseRule" | "cacheTTL" | "retryResolve">[T];
|
|
8
|
-
/** 基于 baseURL 返回完整的 url 地址, 如果 url 地址以 / 开头则表示忽略 baseURL 的值 */
|
|
9
|
-
getFullUrl(url: string): string;
|
|
10
|
-
/** 提示消息 */
|
|
11
|
-
showMessage(isError: boolean, message: string | false): void;
|
|
12
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { IResponseResult, TypeGuardParam } from "./type";
|
|
2
|
-
import type { RequestGlobalConfig } from "./config";
|
|
3
|
-
export declare function checkTypedDataResult<T>(url: string, result: IResponseResult, config: RequestGlobalConfig, typeGard: TypeGuardParam<T> | null): IResponseResult<T | null | unknown>;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { TypeGuardParam, IRequestOptions, IRequestGlobalConfig, IResponseResult, NetRequestAgent } from "./type";
|
|
2
|
-
type RequestBody = NonNullable<IRequestOptions["body"]>;
|
|
3
|
-
/** 工具函数主类 */
|
|
4
|
-
export declare class NetRequestHandler {
|
|
5
|
-
private agent;
|
|
6
|
-
private config;
|
|
7
|
-
private cache;
|
|
8
|
-
constructor(agent: NetRequestAgent, config?: IRequestGlobalConfig);
|
|
9
|
-
/**
|
|
10
|
-
* 执行网络请求
|
|
11
|
-
*/
|
|
12
|
-
private exec;
|
|
13
|
-
/**
|
|
14
|
-
* 检查响应的数据类型
|
|
15
|
-
*/
|
|
16
|
-
private guard;
|
|
17
|
-
/**
|
|
18
|
-
* 修改默认请求配置: baesURL / timeout / credentials / errorHandler / messageHandler / responseHandler / logHandler / responseRule
|
|
19
|
-
*/
|
|
20
|
-
setConfig(config: IRequestGlobalConfig): void;
|
|
21
|
-
/**
|
|
22
|
-
* 读取默认的请求配置
|
|
23
|
-
*/
|
|
24
|
-
getConfig<T extends keyof IRequestGlobalConfig>(key: T): import("../../utils").SomeRequired<IRequestGlobalConfig, "timeout" | "maxRetry" | "retryInterval" | "baseURL" | "responseRule" | "cacheTTL" | "retryResolve">[T];
|
|
25
|
-
/**
|
|
26
|
-
* 发送一个 HEAD 请求,并且不处理响应 body
|
|
27
|
-
*/
|
|
28
|
-
head(url: string, options?: IRequestOptions): Promise<IResponseResult>;
|
|
29
|
-
/**
|
|
30
|
-
* 发送一个 GET 请求,请求自带 500ms 缓冲控制以应对并发场景
|
|
31
|
-
*/
|
|
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
|
-
/**
|
|
36
|
-
* 发送一个 POST 请求,可选 typeGuard 用于检查数据类型
|
|
37
|
-
*/
|
|
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
|
-
/**
|
|
42
|
-
* 发送一个 DELETE 请求,可选 typeGuard 用于检查数据类型
|
|
43
|
-
*/
|
|
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
|
-
/**
|
|
48
|
-
* 发送一个 PUT 请求,可选 typeGuard 用于检查数据类型
|
|
49
|
-
*/
|
|
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
|
-
/**
|
|
54
|
-
* 发送一个 PATCH 请求,可选 typeGuard 用于检查数据类型
|
|
55
|
-
*/
|
|
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
|
-
}
|
|
60
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { IBaseRequestOptions, IBaseRequestBody } from "./type";
|
|
2
|
-
import type { RequestGlobalConfig } from "./config";
|
|
3
|
-
type FixedRequestOptions = Omit<Required<IBaseRequestOptions>, "params" | "body"> & {
|
|
4
|
-
url: string;
|
|
5
|
-
params: Record<string, string>;
|
|
6
|
-
body: ReturnType<typeof convertBody>;
|
|
7
|
-
};
|
|
8
|
-
export declare function convertOptions(url: string, config: RequestGlobalConfig, options?: IBaseRequestOptions): Promise<FixedRequestOptions>;
|
|
9
|
-
declare function convertBody(body: IBaseRequestOptions["body"]): IBaseRequestBody | undefined;
|
|
10
|
-
export {};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { RequestGlobalConfig } from "./config";
|
|
2
|
-
import type { IRequestOptions, IResponseResult, IRequestBaseResponse } from "./type";
|
|
3
|
-
export declare function handleResponse(res: IRequestBaseResponse, url: string, config: RequestGlobalConfig, options?: IRequestOptions): IResponseResult;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { NetRequestCoreFn, IRequestOptions, IRequestBaseResponse } from "./type";
|
|
2
|
-
import type { RequestGlobalConfig } from "./config";
|
|
3
|
-
export declare function retryRequest(agent: NetRequestCoreFn, url: string, config: RequestGlobalConfig, options?: IRequestOptions, _try?: number): Promise<IRequestBaseResponse>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { IResponseResult, IResponseRule } from "./type";
|
|
2
|
-
type ResponseInfo = Pick<IResponseResult, "ok" | "code" | "data" | "message">;
|
|
3
|
-
/**
|
|
4
|
-
* 分析响应内容中的错误信息和数据
|
|
5
|
-
*/
|
|
6
|
-
export declare function analyseResponse(status: number, statusText: string, responseText: string, globalRule: IResponseRule, rule?: IResponseRule): ResponseInfo;
|
|
7
|
-
/**
|
|
8
|
-
* 将 Response Rules 转化成为自然描述语言
|
|
9
|
-
*/
|
|
10
|
-
export declare const getResponseRulesDescription: (rules: IResponseRule) => string;
|
|
11
|
-
export declare function statusOK(status: number): boolean;
|
|
12
|
-
export {};
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import type { RequestGlobalConfig } from "./config";
|
|
2
|
-
import type { MaybePromise, TypeGuard, TypeGuardFn } from "../../utils";
|
|
3
|
-
export type IBaseRequestBody = URLSearchParams | string;
|
|
4
|
-
/** 通用网络请求工具的基本配置 */
|
|
5
|
-
export interface IBaseRequestOptions {
|
|
6
|
-
/** 网络请求方法,默认 GET */
|
|
7
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
|
|
8
|
-
/** 自定义 header 头 */
|
|
9
|
-
headers?: Record<string, string>;
|
|
10
|
-
/** url 参数 */
|
|
11
|
-
params?: Record<string, unknown>;
|
|
12
|
-
/** 发送的 body 内容,method 为 GET / HEAD / DELETE 时无效 */
|
|
13
|
-
body?: IBaseRequestBody | object | unknown[];
|
|
14
|
-
/** 请求超时设置,单位 ms */
|
|
15
|
-
timeout?: number;
|
|
16
|
-
}
|
|
17
|
-
/** 重试请求的配置参数,暂不支持全局配置 */
|
|
18
|
-
export interface IRetryRequestOptions {
|
|
19
|
-
/** 错误时重试的次数,不能超过 10 次 */
|
|
20
|
-
maxRetry?: number;
|
|
21
|
-
/** 重试策略:默认 network,可选 status */
|
|
22
|
-
retryResolve?: ERetryResolve;
|
|
23
|
-
/** 两次重试的间隔,如果设置时间,则单位 ms,或者设置函数返回等待的时间(单位ms),默认 1000,最小 100,函数参数 retryIndex 从 1 开始 */
|
|
24
|
-
retryInterval?: number | ((retryIndex: number) => number);
|
|
25
|
-
}
|
|
26
|
-
export interface IOtherRequestOptions {
|
|
27
|
-
/** 如果设置为 false 则关闭通用提示,设置函数可以自定义提示,函数返回 falsly 则不提示 */
|
|
28
|
-
message?: false | ((result: IResponseResult, method: string, url: string, defaultMessage: string) => string | false);
|
|
29
|
-
/** 自定义 ajax response 解析策略 */
|
|
30
|
-
responseRule?: IResponseRule;
|
|
31
|
-
}
|
|
32
|
-
/** 对外工具接口的请求配置 */
|
|
33
|
-
export type IRequestOptions = IBaseRequestOptions & IRetryRequestOptions & IOtherRequestOptions;
|
|
34
|
-
/** 全局默认配置 */
|
|
35
|
-
export type IRequestGlobalConfig = {
|
|
36
|
-
/**
|
|
37
|
-
* 设置全局 url 基础路径,必须要以 / 开头 或者完整的 api 地址,比如 /api 或 https://api.server.com/path
|
|
38
|
-
*/
|
|
39
|
-
baseURL?: string;
|
|
40
|
-
/** 用于 get 请求的缓存时长,单位 ms,建议不小于 100 */
|
|
41
|
-
cacheTTL?: number;
|
|
42
|
-
/** 全局 request 处理函数,headers 和 params 为引用型数据可直接修改,如果返回字符串,则替换原来的 url 进行请求 */
|
|
43
|
-
requestTransformer?: null | ((request: {
|
|
44
|
-
headers: Record<string, string>;
|
|
45
|
-
params: Record<string, string>;
|
|
46
|
-
method: string;
|
|
47
|
-
/** 要请求的地址,不包含 params 参数 */
|
|
48
|
-
url: string;
|
|
49
|
-
body?: IBaseRequestBody;
|
|
50
|
-
}) => MaybePromise<void | string>);
|
|
51
|
-
/** 全局错误处理函数,仅仅在 statusCode 错误时触发 */
|
|
52
|
-
errorHandler?: null | ((status: number, method: string, url: string) => void);
|
|
53
|
-
/** 全局响应处理函数,任意状态都会触发 */
|
|
54
|
-
responseHandler?: null | ((result: IResponseResult, method: string, url: string) => void);
|
|
55
|
-
/** 全局消息提示函数 */
|
|
56
|
-
messageHandler?: null | ((isError: boolean, message: string) => void);
|
|
57
|
-
/** 全局日志打印函数 */
|
|
58
|
-
logHandler?: null | ((data: IRequestLog) => void);
|
|
59
|
-
} & Pick<IBaseRequestOptions, "timeout"> & IRetryRequestOptions & IOtherRequestOptions;
|
|
60
|
-
/**
|
|
61
|
-
* 失败重试策略:
|
|
62
|
-
* network 仅仅网络错误时重试;
|
|
63
|
-
* status 当网络错误或者 http状态码错误时重试;
|
|
64
|
-
*/
|
|
65
|
-
export type ERetryResolve = "network" | "status";
|
|
66
|
-
/** 响应内容解析规则配置 */
|
|
67
|
-
export interface IResponseRule {
|
|
68
|
-
/** http失败时 (status <200 || status >= 400) 解析策略 */
|
|
69
|
-
failed: {
|
|
70
|
-
/** 解析方式,如果解析方式为 json,则可以进一步指定错误消息字段 */
|
|
71
|
-
resolve: "json" | "body";
|
|
72
|
-
/** 解析错误消息的状态字段,仅在 resolve 为 json 时有效,有值的话会替换 response 的 code */
|
|
73
|
-
statusField?: string;
|
|
74
|
-
/** 解析错误消息的字段,仅在 resolve 为 json 时有效 */
|
|
75
|
-
messageField?: string | string[];
|
|
76
|
-
};
|
|
77
|
-
/** http成功时 (200 <= status < 400) 解析策略 */
|
|
78
|
-
ok: {
|
|
79
|
-
/**
|
|
80
|
-
* http成功响应时,响应内容解析策略
|
|
81
|
-
*
|
|
82
|
-
* - json
|
|
83
|
-
*
|
|
84
|
-
* 此时 response body 被格式化为 json,并根据后续配置进一步读取自定义状态和数据字段等信息
|
|
85
|
-
*
|
|
86
|
-
* - body
|
|
87
|
-
*
|
|
88
|
-
* 此时 reponse body 被格式化为 json 并作为接口返回的数据使用,如果格式化失败,则返回 body 本身的字符串
|
|
89
|
-
*/
|
|
90
|
-
resolve: "json" | "body";
|
|
91
|
-
/** 表示自定义状态的字段名 */
|
|
92
|
-
statusField?: string;
|
|
93
|
-
/** 自定义状态成功时的取值 */
|
|
94
|
-
statusOKValue?: string;
|
|
95
|
-
/** 数据字段名,仅在自定义状态成功时有效 */
|
|
96
|
-
dataField?: string;
|
|
97
|
-
/** 消息字段名,仅在自定义状态失败时有效 */
|
|
98
|
-
messageField?: string | string[];
|
|
99
|
-
/** 忽略特定的消息内容,如果可能是多个值,则设置为数组 */
|
|
100
|
-
ignoreMessage?: string | string[];
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
/** 通用网络请求工具返回的内容 */
|
|
104
|
-
export interface IRequestBaseResponse {
|
|
105
|
-
/** 最终发送请求的方法 */
|
|
106
|
-
method: string;
|
|
107
|
-
/** 最终发送请求的 url(带有params) */
|
|
108
|
-
url: string;
|
|
109
|
-
/** 状态码,如果是网络错误或其他异常,返回负数状态码 */
|
|
110
|
-
status: number;
|
|
111
|
-
/** 状态描述信息 */
|
|
112
|
-
statusText: string;
|
|
113
|
-
/** 响应头,如果网络错误,则返回空对象 */
|
|
114
|
-
headers?: Record<string, string | undefined>;
|
|
115
|
-
/** 响应体,如果网络错误或 204/202,则返回空或错误信息 */
|
|
116
|
-
body: string;
|
|
117
|
-
}
|
|
118
|
-
/** 对外工具接口的返回内容 */
|
|
119
|
-
export interface IResponseResult<T = unknown> {
|
|
120
|
-
/** 标记响应是否成功,包括检测 http statusCode 以及 自定义 Response rule 中的规则 */
|
|
121
|
-
ok: boolean;
|
|
122
|
-
/** 响应的 http 状态码,异常情况返回负数(仅代表异常,具体数值无含义) */
|
|
123
|
-
status: number;
|
|
124
|
-
/** 响应返回的错误码或者自定义响应码 */
|
|
125
|
-
code: string;
|
|
126
|
-
/** 从响应体中分析出的提示信息 */
|
|
127
|
-
message: string;
|
|
128
|
-
/** 响应的 headers 信息 */
|
|
129
|
-
headers: Record<string, string | undefined>;
|
|
130
|
-
/**
|
|
131
|
-
* 成功时返回的数据,如果网络错误/服务器没有响应内容(比如 http status 202/204)/类型守卫检查失败则是 null
|
|
132
|
-
*
|
|
133
|
-
* 如果需要检查返回的内容,可以访问 body 属性
|
|
134
|
-
*/
|
|
135
|
-
data: T;
|
|
136
|
-
}
|
|
137
|
-
export type ResponseWithType<T> = Promise<IResponseResult<T | null>>;
|
|
138
|
-
export type ResponseWithoutType = Promise<IResponseResult>;
|
|
139
|
-
export interface NetRequestCoreFn {
|
|
140
|
-
(url: string, config: RequestGlobalConfig, options?: IBaseRequestOptions): Promise<IRequestBaseResponse>;
|
|
141
|
-
}
|
|
142
|
-
export interface NetRequestAgent {
|
|
143
|
-
(url: string, config: RequestGlobalConfig, options?: IRequestOptions): Promise<IResponseResult>;
|
|
144
|
-
}
|
|
145
|
-
interface LogBase {
|
|
146
|
-
method: string;
|
|
147
|
-
url: string;
|
|
148
|
-
}
|
|
149
|
-
interface RetryCount extends LogBase {
|
|
150
|
-
retry: number;
|
|
151
|
-
maxRetry: number;
|
|
152
|
-
message: string;
|
|
153
|
-
}
|
|
154
|
-
interface LogPrepear extends RetryCount {
|
|
155
|
-
type: "prepear";
|
|
156
|
-
/** 请求的参数 */
|
|
157
|
-
options?: IRequestOptions;
|
|
158
|
-
/** 自定义追加的请求 header 头 */
|
|
159
|
-
headers?: Record<string, string>;
|
|
160
|
-
}
|
|
161
|
-
interface LogReady extends LogBase {
|
|
162
|
-
type: "ready";
|
|
163
|
-
/** 实际发送的请求 header 头 */
|
|
164
|
-
headers: Record<string, string>;
|
|
165
|
-
/** 实际发送的数据 */
|
|
166
|
-
body?: IBaseRequestBody;
|
|
167
|
-
/** 实际发送设定的 timeout */
|
|
168
|
-
timeout?: number;
|
|
169
|
-
}
|
|
170
|
-
interface LogFinished extends RetryCount {
|
|
171
|
-
type: "finished";
|
|
172
|
-
/** 请求消耗的时间,单位 ms */
|
|
173
|
-
cost: number;
|
|
174
|
-
/** 请求响应的内容 */
|
|
175
|
-
response: IRequestBaseResponse;
|
|
176
|
-
/** 请求响应的 header */
|
|
177
|
-
headers?: Record<string, string | undefined>;
|
|
178
|
-
}
|
|
179
|
-
export type IRequestLog = LogPrepear | LogReady | LogFinished;
|
|
180
|
-
export type TypeGuardParam<T> = TypeGuard<T> | TypeGuardFn<T>;
|
|
181
|
-
export {};
|
package/dist/request/index.d.ts
DELETED
package/dist/utils/base.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 暂停一段时间
|
|
3
|
-
* @param {number} ms 暂停的毫秒数
|
|
4
|
-
*/
|
|
5
|
-
export declare function sleep(ms: number): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* 空函数,异步空函数为 asyncNoop
|
|
8
|
-
*/
|
|
9
|
-
export declare function noop(): void;
|
|
10
|
-
type EmptyValue = null | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* 检查是否为空值 null / undefined
|
|
13
|
-
*/
|
|
14
|
-
export declare function isEmpty(data: unknown): data is EmptyValue;
|
|
15
|
-
/**
|
|
16
|
-
* 检查是否为 object(非 null / array)
|
|
17
|
-
*/
|
|
18
|
-
export declare function isObject(data: unknown): data is object;
|
|
19
|
-
/**
|
|
20
|
-
* 检测是否为 String Record
|
|
21
|
-
*/
|
|
22
|
-
export declare function isStringRecord(data: unknown): data is Record<string, unknown>;
|
|
23
|
-
/**
|
|
24
|
-
* 检查一个url地址是否以 http/https 开头,如果第二个参数传递 true,则自适应协议(//....)也被认为是完整 url
|
|
25
|
-
*/
|
|
26
|
-
export declare function isFullURL(url: string, ignoreProtocol?: boolean): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* 检测文本是否有可能转化为 object 或 array,注意,检测通过也未必能被正确格式化为 json
|
|
29
|
-
*/
|
|
30
|
-
export declare function isJsonLike(text: string): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* 基于 baseURL 计算完整的 url 信息,仅可在浏览器环境使用
|
|
33
|
-
* @param url 要转化的 url,如果以 https: 或 http: 开头则直接返回
|
|
34
|
-
* @param baseURL 可选 baseURL
|
|
35
|
-
*/
|
|
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>;
|
|
41
|
-
/**
|
|
42
|
-
* JSON.parse的扩展,格式化错误则返回 null,第二个参数为可选 typeGuard
|
|
43
|
-
*/
|
|
44
|
-
export declare function parseJSON(str: string): unknown;
|
|
45
|
-
export declare function parseJSON<T>(str: string, typeGuard: (data: unknown) => data is T): T | null;
|
|
46
|
-
export {};
|
package/dist/utils/config.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** 通用初始化配置 */
|
|
2
|
-
export interface SDKBaseConfig {
|
|
3
|
-
/** 服务地址,内置 Endpoint 枚举可选 */
|
|
4
|
-
endpoint: `http://${string}` | `https://${string}`;
|
|
5
|
-
/** 游戏 Game ID */
|
|
6
|
-
game: string;
|
|
7
|
-
/** 游戏 Secret Key */
|
|
8
|
-
secret: `sk_${string}`;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* 校验通用配置,如果有错误,则直接 throw Error
|
|
12
|
-
*/
|
|
13
|
-
export declare function verifyConfig(config: SDKBaseConfig): void;
|
|
14
|
-
/**
|
|
15
|
-
* 校验通用配置,如果有错误,则直接 throw Error
|
|
16
|
-
*/
|
|
17
|
-
export declare function verifyConfigWithoutEndpoint(config: Omit<SDKBaseConfig, "endpoint">): void;
|
package/dist/utils/gcm.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
type SecretKey = string | Buffer;
|
|
4
|
-
/**
|
|
5
|
-
* decryptAESGCM 使用 AES-256-GCM 解密 base64 编码的密文。
|
|
6
|
-
* 密文格式为 base64(nonce || ciphertext || authTag),其中 nonce 为 12 字节,authTag 为 16 字节。
|
|
7
|
-
*/
|
|
8
|
-
export declare function decryptAESGCM(sk: SecretKey, encoded: string): string;
|
|
9
|
-
export {};
|
package/dist/utils/http.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { IncomingMessage, ServerResponse } from "http";
|
|
3
|
-
export declare function readBody(req: IncomingMessage, backup?: string): Promise<string>;
|
|
4
|
-
export declare function done(res: ServerResponse, statusCode: number, message?: string): Promise<void>;
|
|
5
|
-
export declare function responseError(res: ServerResponse, statusCode: number, error: string, message: string): Promise<void>;
|
|
6
|
-
export declare function responseJson(res: ServerResponse, data: unknown, statusCode?: number): Promise<void>;
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from "./base";
|
|
2
|
-
export * from "./types";
|
|
3
|
-
export * from "./config";
|
|
4
|
-
export * from "./signer";
|
|
5
|
-
export * from "./http";
|
|
6
|
-
/** 生成一个 SessionID 以用作用户上下线的上报标记 */
|
|
7
|
-
export declare function genSessionID(comboId: string): string;
|
|
8
|
-
/** 生成一个随机id */
|
|
9
|
-
export declare function genNonceString(): string;
|
package/dist/utils/signer.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { IBaseRequestBody } from "../request";
|
|
2
|
-
export declare const AuthorizationField = "Authorization";
|
|
3
|
-
interface SignDataOption {
|
|
4
|
-
game: string;
|
|
5
|
-
secret: string;
|
|
6
|
-
endpoint: string;
|
|
7
|
-
method: string;
|
|
8
|
-
url: string;
|
|
9
|
-
data: IBaseRequestBody;
|
|
10
|
-
timestamp?: string;
|
|
11
|
-
}
|
|
12
|
-
type SignDataOptionForVerify = Omit<SignDataOption, "game" | "timestamp"> & {
|
|
13
|
-
game?: string;
|
|
14
|
-
};
|
|
15
|
-
declare const SigningDefinitions: {
|
|
16
|
-
readonly HS256: {
|
|
17
|
-
readonly prefix: "SEAYOO-HMAC-SHA256";
|
|
18
|
-
readonly sign: ({ game, secret, method, url, data, timestamp }: SignDataOption, onlySignature?: boolean) => string;
|
|
19
|
-
readonly verify: (authString: string, option: SignDataOptionForVerify) => boolean;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* 格式化 AuthorizationHeader
|
|
24
|
-
*/
|
|
25
|
-
export declare function parseAuthorizationHeader(authString: string, version?: keyof typeof SigningDefinitions): Record<string, string | undefined> | null;
|
|
26
|
-
/**
|
|
27
|
-
* 获取请求签名值,默认签名方法是 HS256
|
|
28
|
-
*/
|
|
29
|
-
export declare function calcAuthorizationHeader(option: SignDataOption, onlySignature?: boolean, version?: keyof typeof SigningDefinitions): string;
|
|
30
|
-
/**
|
|
31
|
-
* 检查 http auth 信息是否正确
|
|
32
|
-
*/
|
|
33
|
-
export declare function checkHttpAuthInfo(authString: string, option: SignDataOptionForVerify): boolean;
|
|
34
|
-
export {};
|
package/dist/utils/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type MaybePromise<T> = T extends Promise<infer P> ? P | T : T | Promise<T>;
|
|
2
|
-
export type SomeRequired<T, K extends keyof T> = Omit<T, K> & {
|
|
3
|
-
[F in K]-?: T[F];
|
|
4
|
-
};
|
|
5
|
-
export type TypeGuardFn<T> = (data: unknown) => data is T;
|
|
6
|
-
export type TypeGuard<T> = {
|
|
7
|
-
guard: TypeGuardFn<T>;
|
|
8
|
-
message: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function getTypeGuard<T>(typeGuard: TypeGuardFn<T> | TypeGuard<T>, defaultMessage?: string): TypeGuard<T>;
|
|
11
|
-
/**
|
|
12
|
-
* 获取一个指定类型数据的 list 守卫函数
|
|
13
|
-
*/
|
|
14
|
-
export declare function typedArrayGuard<T>(fn: TypeGuardFn<T>): TypeGuardFn<T[]>;
|
|
15
|
-
/**
|
|
16
|
-
* 获取一个指定类型数据的 map 守卫函数,需要是一个纯对象,否则校验将失败
|
|
17
|
-
*/
|
|
18
|
-
export declare function typedMapGuard<K extends string | number | symbol, T>(fn: TypeGuardFn<T>): TypeGuardFn<Record<K, T>>;
|
package/dist/verify/ads.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
export interface AdPayload {
|
|
3
|
-
/**
|
|
4
|
-
* combo_id 是世游分配的聚合用户 ID
|
|
5
|
-
*
|
|
6
|
-
* 游戏侧应当使用 combo_id 作为用户的唯一标识。
|
|
7
|
-
*/
|
|
8
|
-
combo_id: string;
|
|
9
|
-
/**
|
|
10
|
-
* placement_id 是广告位 ID,游戏侧用它确定发放什么样的广告激励。
|
|
11
|
-
*/
|
|
12
|
-
placement_id: string;
|
|
13
|
-
/**
|
|
14
|
-
* impression_id 是世游服务端创建的,标识单次广告播放的唯一 ID。
|
|
15
|
-
*/
|
|
16
|
-
impression_id: string;
|
|
17
|
-
}
|
|
18
|
-
export type AdJwtPayload = JwtPayload & Omit<AdPayload, "combo_id"> & {
|
|
19
|
-
scope: string;
|
|
20
|
-
};
|
|
21
|
-
export declare function isAdJwtPayload(payload: unknown): payload is AdJwtPayload;
|
package/dist/verify/id.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { JwtPayload } from "jsonwebtoken";
|
|
2
|
-
import type { IdP } from "../const";
|
|
3
|
-
export interface IdentityPayload {
|
|
4
|
-
/**
|
|
5
|
-
* combo_id 是世游分配的聚合用户 ID
|
|
6
|
-
*
|
|
7
|
-
* 游戏侧应当使用 combo_id 作为用户的唯一标识,即游戏帐号。
|
|
8
|
-
*/
|
|
9
|
-
combo_id: string;
|
|
10
|
-
/**
|
|
11
|
-
* IdP (Identity Provider) 是用户身份的提供者
|
|
12
|
-
*
|
|
13
|
-
* 游戏侧可以使用 IdP 做业务辅助判断,例如判定用户是否使用了某个特定的登录方式。
|
|
14
|
-
*/
|
|
15
|
-
idp: IdP;
|
|
16
|
-
/**
|
|
17
|
-
* external_id 是用户在外部 IdP 中的唯一标识
|
|
18
|
-
*
|
|
19
|
-
* 例如:
|
|
20
|
-
* - 如果用户使用世游通行证登录,那么 external_id 就是用户的世游通行证 ID。
|
|
21
|
-
* - 如果用户使用 Google Account 登录,那么 external_id 就是用户在 Google 中的账号标识。
|
|
22
|
-
* - 如果用户使用微信登录,那么 external_id 就是用户在微信中的 OpenId。
|
|
23
|
-
*
|
|
24
|
-
* 注意:
|
|
25
|
-
* 游戏侧不应当使用 external_id 作为用户标识,但可以将 external_id 用于特定的业务逻辑。
|
|
26
|
-
*/
|
|
27
|
-
external_id: string;
|
|
28
|
-
/**
|
|
29
|
-
* external_name 是用户在外部 IdP 中的名称,通常是用户的昵称
|
|
30
|
-
*/
|
|
31
|
-
external_name: string;
|
|
32
|
-
/**
|
|
33
|
-
* weixin_session_key 是用户在微信小游戏登录时,从微信服务端获得的会话密钥 session_key。
|
|
34
|
-
* 该字段在 Identity Token 中以 AES-256-GCM 加密存储,SDK 会自动解密。
|
|
35
|
-
*
|
|
36
|
-
* weixin_session_key 只在 IdP 为 MinigameWeixin 时才会有值。
|
|
37
|
-
*/
|
|
38
|
-
weixin_session_key: string;
|
|
39
|
-
/**
|
|
40
|
-
* DeviceId 是用户在登录时使用的设备的唯一 ID。
|
|
41
|
-
*/
|
|
42
|
-
device_id: string;
|
|
43
|
-
/**
|
|
44
|
-
* distro 是游戏客户端的发行版本标识。
|
|
45
|
-
* 游戏侧可将 distro 用于服务端数据埋点,以及特定的业务逻辑判断。
|
|
46
|
-
*/
|
|
47
|
-
distro: string;
|
|
48
|
-
/**
|
|
49
|
-
* variant 是游戏客户端的分包标识。
|
|
50
|
-
* 游戏侧可将 variant 用于服务端数据埋点,以及特定的业务逻辑判断。
|
|
51
|
-
*
|
|
52
|
-
* 注意:variant 只在客户端是分包时才会有值。当客户端不是分包的情况下,variant 为空字符串。
|
|
53
|
-
*/
|
|
54
|
-
variant: string;
|
|
55
|
-
/**
|
|
56
|
-
* age 是根据用户的实名认证信息得到的年龄。
|
|
57
|
-
*
|
|
58
|
-
* 0 表示未知。
|
|
59
|
-
*
|
|
60
|
-
* 在某些特殊场景下,游戏侧可用 age 来自行处理防沉迷。
|
|
61
|
-
*
|
|
62
|
-
* 注意:age 不保证返回精确的年龄信息,仅保证用于防沉迷处理时的准确度够用。
|
|
63
|
-
*
|
|
64
|
-
* 例如:
|
|
65
|
-
*
|
|
66
|
-
* 当某个用户真实年龄为 35 岁时,age 可能返回 18,
|
|
67
|
-
* 当某个用户真实年龄为 17 岁时,age 可能返回 16。
|
|
68
|
-
*/
|
|
69
|
-
age: number;
|
|
70
|
-
/**
|
|
71
|
-
* reg_time 是用户 ID(Combo ID)注册时间。Unix timestamp in seconds。
|
|
72
|
-
*/
|
|
73
|
-
reg_time: number;
|
|
74
|
-
}
|
|
75
|
-
export type IdentityJwtPayload = JwtPayload & Omit<IdentityPayload, "combo_id"> & {
|
|
76
|
-
scope: string;
|
|
77
|
-
};
|
|
78
|
-
export declare function isIdentityJwtPayload(payload: unknown): payload is IdentityJwtPayload;
|
package/dist/verify/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type SDKBaseConfig } from "../utils";
|
|
2
|
-
import { type IdentityPayload } from "./id";
|
|
3
|
-
import { type AdPayload } from "./ads";
|
|
4
|
-
/**
|
|
5
|
-
* token 验证器
|
|
6
|
-
*/
|
|
7
|
-
export declare class TokenVerifier {
|
|
8
|
-
private privateKey;
|
|
9
|
-
private baseOption;
|
|
10
|
-
constructor(config: SDKBaseConfig);
|
|
11
|
-
/**
|
|
12
|
-
* verifyIdentityToken 对 IdentityToken 进行验证
|
|
13
|
-
*
|
|
14
|
-
* 验证失败会返回 Error 对象
|
|
15
|
-
*/
|
|
16
|
-
verifyIdentityToken(token: string): IdentityPayload | Error;
|
|
17
|
-
/**
|
|
18
|
-
* verifyAdToken 对 AdToken 进行验证
|
|
19
|
-
*
|
|
20
|
-
* 验证失败会返回 Error 对象
|
|
21
|
-
*/
|
|
22
|
-
verifyAdToken(token: string): AdPayload | Error;
|
|
23
|
-
}
|
package/vitest.config.ts
DELETED