@seayoo-io/combo-sdk-node 1.7.0 → 1.9.0

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/package.json CHANGED
@@ -1,16 +1,24 @@
1
1
  {
2
2
  "name": "@seayoo-io/combo-sdk-node",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Combo SDK for Node.js",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
7
7
  "types": "./dist/index.d.ts",
8
8
  "main": "./dist/index.cjs",
9
9
  "module": "./dist/index.js",
10
+ "sideEffects": false,
10
11
  "exports": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ }
14
22
  },
15
23
  "publishConfig": {
16
24
  "access": "public"
@@ -23,7 +31,7 @@
23
31
  },
24
32
  "repository": {
25
33
  "type": "git",
26
- "url": "https://github.com/seayoo-io/combo-sdk-node"
34
+ "url": "git+https://github.com/seayoo-io/combo-sdk-node.git"
27
35
  },
28
36
  "keywords": [
29
37
  "combo",
@@ -33,36 +41,44 @@
33
41
  "author": "seayoo.io",
34
42
  "license": "MIT",
35
43
  "devDependencies": {
44
+ "@arethetypeswrong/cli": "^0.18.5",
36
45
  "@types/express": "^4.17.21",
37
46
  "@types/jsonwebtoken": "^9.0.5",
38
47
  "@types/koa": "^2.13.12",
39
- "@types/node": "12.0.0",
40
- "@typescript-eslint/eslint-plugin": "^6.18.1",
41
- "@typescript-eslint/parser": "^6.18.1",
42
- "eslint": "^8.56.0",
43
- "eslint-config-prettier": "^9.1.0",
44
- "eslint-plugin-prettier": "^5.1.2",
48
+ "@types/node": "22.20.1",
49
+ "acorn": "^8.18.0",
45
50
  "ioredis": "^5.4.1",
46
- "lint-staged": "^15.2.0",
47
- "microbundle": "^0.15.1",
48
- "msw": "^2.0.12",
49
- "rimraf": "^5.0.5",
50
- "simple-git-hooks": "^2.9.0",
51
- "typescript": "5.2.2",
52
- "vite": "^3.2.7",
53
- "vitest": "^0.34.6"
51
+ "lint-staged": "^17.3.0",
52
+ "msw": "^2.15.0",
53
+ "oxfmt": "^0.62.0",
54
+ "oxlint": "^1.77.0",
55
+ "publint": "^0.3.23",
56
+ "rimraf": "^6.1.3",
57
+ "simple-git-hooks": "^2.13.1",
58
+ "tsdown": "0.21.0",
59
+ "typescript": "6.0.3",
60
+ "vite": "^8.2.0",
61
+ "vitest": "^4.1.10"
54
62
  },
55
63
  "dependencies": {
56
64
  "jsonwebtoken": "^9.0.2"
57
65
  },
58
66
  "scripts": {
59
- "build": "rimraf ./dist && node preconvert.cjs && microbundle --sourcemap false --format cjs,es --target node",
67
+ "build": "rimraf ./dist && node preconvert.cjs && tsdown",
60
68
  "preconvert": "node preconvert.cjs",
61
- "dev": "microbundle watch --target node",
69
+ "dev": "tsdown --watch",
62
70
  "clear": "rimraf dist && rimraf node_modules",
63
71
  "type-check": "tsc --noEmit -p tsconfig.typecheck.json",
64
- "lint": "eslint ./src/**/*.ts",
65
- "lint:fix": "eslint ./src/**/*.{ts,js} --fix",
66
- "test": "vitest"
72
+ "lint": "oxlint",
73
+ "lint:fix": "oxlint --fix",
74
+ "format": "oxfmt",
75
+ "format:check": "oxfmt --check",
76
+ "test": "vitest",
77
+ "test:run": "vitest run",
78
+ "test:src": "vitest run --project src",
79
+ "test:dist": "vitest run --project dist --project contract",
80
+ "check:publish": "publint && attw --pack .",
81
+ "verify:node12": "node scripts/verify-node12.mjs",
82
+ "verify:all": "pnpm type-check && pnpm lint && pnpm build && pnpm test:run && pnpm check:publish && pnpm verify:node12"
67
83
  }
68
84
  }
@@ -1,61 +0,0 @@
1
- import { type IRequestGlobalConfig } from "../request";
2
- import { type SDKBaseConfig } from "../utils";
3
- import type { CreateOrderOption, CreateOrderResponse, SendOtpOption, SendOtpResponse, VerifyOtpOption, VerifyOtpResponse, VoiceModerationRequestOption } from "./types";
4
- /** Api Client Config */
5
- export interface ApiClientConfig extends SDKBaseConfig {
6
- /** 自动重试次数,默认重试 1 次 */
7
- maxRetry?: IRequestGlobalConfig["maxRetry"];
8
- /** 重试间隔,可以使用函数设定不同的间隔 */
9
- retryInterval?: IRequestGlobalConfig["retryInterval"];
10
- /** 可选请求日志函数,用于输出请求调试信息 */
11
- logger?: IRequestGlobalConfig["logHandler"];
12
- /** 请求超时设定,单位 ms */
13
- timeout?: number;
14
- }
15
- /**
16
- * Combo SDK For Server REST Api
17
- */
18
- export declare class ApiClient {
19
- private req;
20
- constructor(config: ApiClientConfig);
21
- /**
22
- * 创建订单
23
- */
24
- createOrder(option: CreateOrderOption): Promise<CreateOrderResponse>;
25
- /**
26
- * 通知世游服务端玩家进入游戏世界(上线)
27
- *
28
- * 此接口仅用于中宣部防沉迷系统的上下线数据上报
29
- *
30
- * @param comboId 聚合用户标识
31
- * @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
32
- */
33
- enterGame(comboId: string, sessionId: string): Promise<boolean>;
34
- /**
35
- * 通知世游服务端玩家离开游戏世界(下线)
36
- *
37
- * 此接口仅用于中宣部防沉迷系统的上下线数据上报
38
- *
39
- * @param comboId 聚合用户标识
40
- * @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
41
- */
42
- leaveGame(comboId: string, sessionId: string): Promise<boolean>;
43
- /**
44
- * 发送验证码
45
- *
46
- * @param option 发送验证码参数
47
- */
48
- sendOtp(option: SendOtpOption): Promise<SendOtpResponse>;
49
- /**
50
- * 验证验证码
51
- *
52
- * @param option 验证码验证参数
53
- */
54
- verifyOtp(option: VerifyOtpOption): Promise<VerifyOtpResponse>;
55
- /**
56
- * 申请语音审核。
57
- *
58
- * 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
59
- */
60
- voiceModerationRequest(option: VoiceModerationRequestOption): Promise<boolean>;
61
- }
@@ -1,97 +0,0 @@
1
- import type { Platform } from "../const";
2
- export interface CreateOrderOption {
3
- /** 用于标识创建订单请求的唯一 ID */
4
- reference_id: string;
5
- /** 发起购买的用户的唯一标识 */
6
- combo_id: string;
7
- /** 要购买的商品 ID */
8
- product_id: string;
9
- /** 平台 */
10
- platform: Platform;
11
- /**
12
- * 游戏侧接收发货通知的服务端地址
13
- *
14
- * 这个地址对应的服务端应该通过 Notify 模块实现基础的验证接口
15
- */
16
- notify_url: string;
17
- /** 要购买的商品的数量 */
18
- quantity: number;
19
- /** 订单上下文,在发货通知中透传回游戏 */
20
- context?: string;
21
- /**
22
- * 订单的元数据
23
- *
24
- * 大部分元数据用于数据分析与查询,游戏侧应当尽量提供
25
- * 某些元数据在特定的支付场景下是必须的,例如微信小游戏的 iOS 支付场景
26
- */
27
- meta?: OrderMetaData;
28
- }
29
- export interface OrderMetaData {
30
- /** 游戏大区 ID */
31
- zone_id?: string;
32
- /** 游戏服务器 ID */
33
- server_id?: string;
34
- /** 游戏角色 ID */
35
- role_id?: string;
36
- /** 游戏角色名 */
37
- role_name?: string;
38
- /** 游戏角色的等级 */
39
- role_level?: number;
40
- }
41
- export interface CreateOrderResponse {
42
- /** 世游服务端创建的,标识订单的唯一 ID。 */
43
- order_id: string;
44
- /** 世游服务端创建的订单 token,用于后续支付流程。 */
45
- order_token: string;
46
- /** 订单失效时间。Unix timestamp in seconds。 */
47
- expires_at: number;
48
- }
49
- export type SupportedOtpChannel = "sms";
50
- export interface SendOtpOption {
51
- /** 要发送验证码的用户的唯一标识。 */
52
- combo_id: string;
53
- /** 发送验证码的通道,目前仅支持 sms。不填写时默认为 sms。*/
54
- channel?: SupportedOtpChannel;
55
- /** 发送验证码的目标行为,由世游发行平台创建并管理。*/
56
- action: string;
57
- /** 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供。*/
58
- meta?: SendOtpMetaData;
59
- }
60
- export type SendOtpMetaData = OrderMetaData;
61
- export interface SendOtpResponse {
62
- /** 掩码后的手机号,仅当 channel=sms 时有值。*/
63
- mobile: string;
64
- /** 验证码有效期,单位秒。*/
65
- otp_ttl: number;
66
- /** 重新发送验证码的冷却时间,单位秒。*/
67
- otp_cooldown: number;
68
- }
69
- export interface VerifyOtpOption {
70
- /** 要验证验证码的用户的唯一标识。 */
71
- combo_id: string;
72
- /** 发送验证码的通道,需与发送时一致。不填写时默认为 sms。*/
73
- channel?: SupportedOtpChannel;
74
- /** 发送验证码的目标行为,需与发送时一致。*/
75
- action: string;
76
- /** 用户输入的验证码。*/
77
- otp: string;
78
- }
79
- export interface VerifyOtpResponse {
80
- /**
81
- * 是否验证通过。
82
- *
83
- * - true 表示验证通过。验证通过后验证码立即失效,不可重复使用。
84
- * - false 表示验证失败,用户输入的验证码与系统生成的验证码不匹配,可能是由于输入错误或验证码已过期,建议用户重新检查输入的验证码。
85
- */
86
- valid: boolean;
87
- }
88
- export interface VoiceModerationRequestOption {
89
- /** 房间实例 ID,唯一标识某个语音房间的一次存续(从开启到关闭)。 */
90
- room_instance_id: string;
91
- /** 游戏服务器 ID。 */
92
- server_id: number;
93
- /** 提交审核申请的玩家角色 ID。 */
94
- requester_role_id: string;
95
- /** 被提交语音审核的玩家角色 ID 列表,一次最多提交 32 个。 */
96
- target_role_ids: string[];
97
- }
package/dist/api/ua.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function getUserAgent(game: string): string;
package/dist/const.d.ts DELETED
@@ -1,143 +0,0 @@
1
- /** SDK 名称 */
2
- export declare const SDKName = "combo-sdk-node";
3
- /** SDK 版本,在编译前会被动态替换 */
4
- export declare const SDKVersion = "1.7.0";
5
- /**
6
- * 世游支持的服务端点列表
7
- */
8
- export declare enum Endpoint {
9
- /** 中国大陆 API 端点,用于国内发行 */
10
- China = "https://api.seayoo.com",
11
- /** 全球的 API 端点,用于海外发行 */
12
- Global = "https://api.seayoo.io"
13
- }
14
- /** 支持的系统平台 */
15
- export declare enum Platform {
16
- /** 安卓平台,包括华为鸿蒙系统、小米澎湃 OS 等基于 Android 的操作系统 */
17
- Android = "android",
18
- /** 苹果的 iOS 和 iPadOS */
19
- iOS = "ios",
20
- /** Windows (PC) 桌面平台 */
21
- Windows = "windows",
22
- /** macOS 桌面平台 */
23
- macOS = "macos",
24
- /** WebGL 平台,包括微信、抖音等小游戏,以及 HTML5 网页游戏 */
25
- WebGL = "webgl",
26
- /** 华为的 HarmonyOS NEXT 鸿蒙应用开发平台 */
27
- HarmonyOS = "harmonyos"
28
- }
29
- /** 支持的登录提供方 */
30
- export declare enum IdP {
31
- /** 游客登录 */
32
- Guest = "guest",
33
- /** 世游通行证 */
34
- Seayoo = "seayoo",
35
- /** Sign-in with Apple */
36
- Apple = "apple",
37
- /** Google Account */
38
- Google = "google",
39
- /** Facebook Login */
40
- Facebook = "facebook",
41
- /** 小米账号 */
42
- Xiaomi = "xiaomi",
43
- /** 微信登录 */
44
- Weixin = "weixin",
45
- /** OPPO 账号 */
46
- Oppo = "oppo",
47
- /** VIVO 账号 */
48
- Vivo = "vivo",
49
- /** 华为账号 */
50
- Huawei = "huawei",
51
- /** 荣耀账号 */
52
- Honor = "honor",
53
- /** UC(九游)登录 */
54
- UC = "uc",
55
- /** TapTap 登录 */
56
- TapTap = "taptap",
57
- /** 哔哩哔哩(B站)账号 */
58
- Bilibili = "bilibili",
59
- /** 应用宝 YSDK 登录 */
60
- Yingyongbao = "yingyongbao",
61
- /** 4399 账号登录 */
62
- F4399 = "4399",
63
- /** 抖音账号 */
64
- Douyin = "douyin",
65
- /** 雷电模拟器账号 */
66
- Leidian = "leidian",
67
- /** 猫窝游戏 */
68
- Maowo = "maowo",
69
- /** 联想 */
70
- Lenovo = "lenovo",
71
- /** 魅族 */
72
- Meizu = "meizu",
73
- /** 酷派 */
74
- Coolpad = "coolpad",
75
- /** 努比亚 */
76
- Nubia = "nubia",
77
- /** 绝峰游戏 */
78
- Juefeng = "juefeng",
79
- /** 魅拓游戏 */
80
- Meituo = "meituo",
81
- /** 微信小游戏 */
82
- MinigameWeixin = "minigame_weixin",
83
- /** 抖音小游戏 */
84
- MinigameDouyin = "minigame_douyin",
85
- /** MuMu 模拟器 */
86
- Mumu = "mumu",
87
- /** 虎牙游戏 */
88
- Huya = "huya",
89
- /** 好游快爆 */
90
- Hykb = "hykb",
91
- /** 233 乐园 */
92
- L233 = "233"
93
- }
94
- /** GM 错误类型枚举 */
95
- export declare enum GMError {
96
- /** 请求中的 HTTP method 不正确,没有按照预期使用 POST。*/
97
- InvalidHttpMethod = "invalid_http_method",
98
- /** 请求中的 Content-Type 不是 application/json。*/
99
- InvalidContentType = "invalid_content_type",
100
- /** 对 HTTP 请求的签名验证不通过。这意味着 HTTP 请求不可信。 */
101
- InvalidSignature = "invalid_signature",
102
- /** 请求的结构不正确。例如,缺少必要的字段,或字段类型不正确。 */
103
- InvalidRequest = "invalid_request",
104
- /** 游戏侧不认识请求中的 GM 命令。 */
105
- InvalidCommand = "invalid_command",
106
- /** GM 命令发送频率过高,被游戏侧限流,命令未被处理。 */
107
- ThrottlingError = "throttling_error",
108
- /** 幂等处理重试请求时,idempotency_key 所对应的原始请求尚未处理完毕。*/
109
- IdempotencyConflict = "idempotency_conflict",
110
- /** 幂等处理重试请求时,请求内容和 idempotency_key 所对应的原始请求内容不一致。*/
111
- IdempotencyMismatch = "idempotency_mismatch",
112
- /** GM 命令的参数不正确。例如,参数缺少必要的字段,或参数的字段类型不正确。 */
113
- InvalidArgs = "invalid_args",
114
- /** 游戏当前处于停服维护状态,无法处理收到的 GM 命令。*/
115
- MaintenanceError = "maintenance_error",
116
- /** 网络通信错误。 */
117
- NetworkError = "network_error",
118
- /** 数据库操作异常导致 GM 命令执行失败。 */
119
- DatabaseError = "database_error",
120
- /** GM 命令处理超时。 */
121
- TimeoutError = "timeout_error",
122
- /** 处理 GM 命令时内部出错。可作为兜底的通用错误类型。*/
123
- InternalError = "internal_error"
124
- }
125
- export declare const enum HttpStatus {
126
- OK = 200,
127
- Accepted = 202,
128
- NoContent = 204,
129
- BadRequest = 400,
130
- Unauthorized = 401,
131
- Forbidden = 403,
132
- NotFound = 404,
133
- MethodNotAllowed = 405,
134
- NotAcceptable = 406,
135
- RequestTimeout = 408,
136
- Conflict = 409,
137
- UnsupportedMediaType = 415,
138
- UnprocessableEntity = 422,
139
- TooManyRequests = 429,
140
- InternalServerError = 500,
141
- BadGateway = 502,
142
- ServiceUnavailable = 503
143
- }
@@ -1,51 +0,0 @@
1
- import { type SDKBaseConfig } from "../utils";
2
- import type { IncomingMessage, ServerResponse } from "http";
3
- import { type GMCommandHandler, type IdempotencyKeyStoreHelper } from "./types";
4
- import type { ParameterizedContext, Next } from "koa";
5
- import type { Request as ExpressRequest, Response as ExpressResponse, NextFunction as ExpressNextFunction } from "express";
6
- type SDKMinConfig = Omit<SDKBaseConfig, "endpoint">;
7
- /**
8
- * 获取一个处理函数用于响应 Seayoo Server 推送过来的 GM 执行通知,storeHelper 提供存储支持以实现幂等key(idempotencyKey)的自动化处理
9
- *
10
- * 另有 express 和 koa2 版本的处理函数可以使用。
11
- *
12
- * 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody 字符串以核验签名
13
- */
14
- export declare function getGMCommandHandler(config: SDKMinConfig, handler: GMCommandHandler, storeHelper?: IdempotencyKeyStoreHelper): (req: IncomingMessage, res: ServerResponse, rawBodyString?: string) => Promise<void>;
15
- /**
16
- * 获取基于 express 的处理函数用于响应 Seayoo Server 推送过来的 GM 执行通知
17
- *
18
- * 如需自定义处理,可以使用 getGMCommandHandler 方法,
19
- *
20
- * 如果 express 使用全局的 bodyParse 或类似插件,将需要做额外的处理以获取原始请求的内容 rawBody 以用以计算签名
21
- *
22
- * 处理方法可以参考
23
- *
24
- * https://cloud.tencent.com/developer/ask/sof/110062928
25
- */
26
- export declare function getGMHandlerForExpress(config: SDKMinConfig, handler: GMCommandHandler, storeHelper?: IdempotencyKeyStoreHelper): (req: ExpressRequest & {
27
- rawBody?: string;
28
- }, res: ExpressResponse) => Promise<void>;
29
- /**
30
- * 获取基于 express 的中间件用于响应 Seayoo Server 推送过来的 GM 执行通知
31
- *
32
- * 需要先于 body-parse 等类似插件加载
33
- */
34
- export declare function getGMMiddlewareForExpress(paths: string | string[], config: SDKMinConfig, handler: GMCommandHandler, storeHelper?: IdempotencyKeyStoreHelper): (req: ExpressRequest, res: ServerResponse, next: ExpressNextFunction) => Promise<void>;
35
- /**
36
- * 获取基于 koa2 的处理函数用于响应 Seayoo Server 推送过来的 GM 执行通知
37
- *
38
- * 如需自定义处理,可以使用 getGMCommandHandler 方法
39
- *
40
- * 如果 koa 使用全局的 koa-body 或类似插件,将需要做额外的处理以获取原始请求的内容 rawBody 以用以计算签名
41
- */
42
- export declare function getGMHandlerForKoa(config: SDKMinConfig, handler: GMCommandHandler, storeHelper?: IdempotencyKeyStoreHelper): (ctx: Pick<ParameterizedContext, "req" | "res"> & {
43
- rawBody?: string;
44
- }) => Promise<void>;
45
- /**
46
- * 获取基于 koa2 的中间件用于响应 Seayoo Server 推送过来的 GM 执行通知
47
- *
48
- * 需要先于 koa-body 等类似插件加载
49
- */
50
- export declare function getGMMiddlewareForKoa(paths: string | string[], config: SDKMinConfig, handler: GMCommandHandler, storeHelper?: IdempotencyKeyStoreHelper): (ctx: Pick<ParameterizedContext, "method" | "path" | "req" | "res">, next: Next) => Promise<void>;
51
- export {};
@@ -1,58 +0,0 @@
1
- import { GMError } from "../const";
2
- import { MaybePromise } from "../utils";
3
- export interface GMRequestBody {
4
- /** version 是世游 GM 服务的版本号,目前固定 2.0 */
5
- version: string;
6
- /** 本次 GM 请求的唯一 ID。游戏侧可用此值来对请求进行去重 */
7
- request_id: string;
8
- /** 本次 GM 请求的 Idempotency Key。如果有非空值则应当执行幂等处理逻辑。 */
9
- idempotency_key?: string;
10
- /** 本次 GM 请求的来源,大小写敏感,比如 combo/console。 */
11
- origin?: string;
12
- /** GM 命令标识。取值和 GM 协议文件中的 rpc 名称对应,大小写敏感 */
13
- command: string;
14
- /** args 是和 cmd 对应的命令参数,具体值取决于协议中对应 rpc 的 Request 定义 */
15
- args: Record<string, unknown>;
16
- }
17
- export declare function isGMRequestBody(data: unknown): data is GMRequestBody;
18
- export interface GMErrorResponse {
19
- /** 错误类型。对应内置定义好的 GmError 枚举值 */
20
- error: GMError;
21
- /** 错误描述信息。预期是给人看的,便于联调和问题排查。*/
22
- message: string;
23
- }
24
- export declare function isGMErrorResponse(data: unknown): data is GMErrorResponse;
25
- /**
26
- * 自定义 GM 执行函数,需要返回执行结果,其结构由协议中对应 rpc 的 Response 定义。
27
- *
28
- * 如果遇到错误可以返回错误结构 ({ error, message }) 或 Error 对象
29
- */
30
- export type GMCommandHandler = {
31
- (command: string, args: Record<string, unknown>, requestId: string, idempotencyKey: string, version: string, origin: string): MaybePromise<Record<string, unknown> | GMErrorResponse | Error>;
32
- };
33
- /**
34
- * 在处理幂等性时,需要使用储存支持,比如 Reis
35
- */
36
- export interface IdempotencyKeyStoreHelper {
37
- /**
38
- * setNX 用于原子性地存储幂等记录并返回旧值。
39
- * value 仅在 key 不存在时才会被存储 (Only set the key if it does not already exist)。
40
- * 返回值是 key 存在时的旧值。如果 key 不存在则返回空字符串。
41
- */
42
- setNX: (key: string, value: string) => Promise<string>;
43
- /**
44
- * setXX 用于原子性地更新已存在的幂等记录。
45
- * value 仅在 key 存在时才会被存储 (Only set the key if it already exists)。
46
- */
47
- setXX: (key: string, value: string) => Promise<void>;
48
- }
49
- /** 幂等key 记录 */
50
- export interface IdempotencyRecord {
51
- nonce: string;
52
- key: string;
53
- id: string;
54
- cmd: string;
55
- args: string;
56
- resp?: Record<string, unknown> | GMErrorResponse | Error;
57
- }
58
- export declare function isIdempotencyRecord(data: unknown): data is IdempotencyRecord;
@@ -1,31 +0,0 @@
1
- import { IdempotencyKeyStoreHelper } from "./types";
2
- import type { Redis } from "ioredis";
3
- export declare function verifyStoreHelper(storeHelper: unknown): void;
4
- export declare function toString(data: object): string;
5
- /** 提供基于内存的 store helper,仅供本地调试使用,不支持 ttl 超时功能 */
6
- export declare class MemoryIdempotencyStore implements IdempotencyKeyStoreHelper {
7
- mc: Record<string, string>;
8
- constructor();
9
- setNX(key: string, value: string): Promise<string>;
10
- setXX(key: string, value: string): Promise<void>;
11
- }
12
- /**
13
- * 基于 ioredis 的 store helper,
14
- *
15
- * 需要 Redis >= 7.0,见 https://redis.io/docs/latest/commands/set/
16
- */
17
- export declare class RedisIdempotencyStore implements IdempotencyKeyStoreHelper {
18
- client: Redis;
19
- ttl: number;
20
- prefix: string;
21
- constructor(options: {
22
- /** 超时设定,单位秒,推荐不低于24小时 */
23
- ttl?: number;
24
- /** ioredis 客户端 */
25
- client: Redis;
26
- /** key 前缀 */
27
- prefix?: string;
28
- });
29
- setNX(key: string, value: string): Promise<string>;
30
- setXX(key: string, value: string): Promise<void>;
31
- }
@@ -1,49 +0,0 @@
1
- import { type SDKBaseConfig } from "../utils";
2
- import { type NotificationHandler } from "./types";
3
- import type { ParameterizedContext, Next } from "koa";
4
- import type { IncomingMessage, ServerResponse } from "http";
5
- import type { Request as ExpressRequest, Response as ExpressResponse, NextFunction as ExpressNextFunction } from "express";
6
- /**
7
- * 获取一个处理函数用于接收 Seayoo Server 推送过来的消息通知
8
- *
9
- * 另有 express 和 koa2 版本的处理函数可以使用。
10
- *
11
- * 由于签名需要原始请求的内容,如果 request 在函数执行之前已经被读取,则需要手工传入请求的 rawBody 字符串以核验签名
12
- */
13
- export declare function getNotificationHandler(config: SDKBaseConfig, handler: NotificationHandler): (req: IncomingMessage, res: ServerResponse, rawBodyString?: string) => Promise<void>;
14
- /**
15
- * 获取基于 express 的处理函数用于接收 Seayoo Server 推送过来的消息通知
16
- *
17
- * 如需自定义处理,可以使用 getNotificationHandler 方法,
18
- *
19
- * 如果 express 使用全局的 bodyParse 或类似插件,将需要做额外的处理以获取原始请求的内容 rawBody 以用以计算签名
20
- *
21
- * 处理方法可以参考
22
- *
23
- * https://cloud.tencent.com/developer/ask/sof/110062928
24
- */
25
- export declare function getNotificationHandlerForExpress(config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest & {
26
- rawBody?: string;
27
- }, res: ExpressResponse) => Promise<void>;
28
- /**
29
- * 获取基于 express 的中间件用于接收 Seayoo Server 推送过来的消息通知
30
- *
31
- * 需要先于 body-parse 等类似插件加载
32
- */
33
- export declare function getNotificationMiddlewareForExpress(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (req: ExpressRequest, res: ServerResponse, next: ExpressNextFunction) => Promise<void>;
34
- /**
35
- * 获取基于 koa2 的处理函数用于接收 Seayoo Server 推送过来的消息通知
36
- *
37
- * 如需自定义处理,可以使用 getNotificationHandler 方法
38
- *
39
- * 如果 koa 使用全局的 koa-body 或类似插件,将需要做额外的处理以获取原始请求的内容 rawBody 以用以计算签名
40
- */
41
- export declare function getNotificationHandlerForKoa(config: SDKBaseConfig, handler: NotificationHandler): (ctx: Pick<ParameterizedContext, "req" | "res"> & {
42
- rawBody?: string;
43
- }) => Promise<void>;
44
- /**
45
- * 获取基于 koa2 的中间件用于接收 Seayoo Server 推送过来的消息通知
46
- *
47
- * 需要先于 koa-body 等类似插件加载
48
- */
49
- export declare function getNotificationMiddlewareForKoa(paths: string | string[], config: SDKBaseConfig, handler: NotificationHandler): (ctx: Pick<ParameterizedContext, "method" | "path" | "req" | "res">, next: Next) => Promise<void>;
@@ -1,20 +0,0 @@
1
- /** ShipOrderNotification 是订单发货通知的数据结构,包含了订单的详细信息 */
2
- export interface RefundNotification {
3
- /** 世游服务端创建的,标识订单的唯一 ID */
4
- order_id: string;
5
- /** 游戏侧用于标识创建订单请求的唯一 ID */
6
- reference_id: string;
7
- /** 发起购买的用户的唯一标识 */
8
- combo_id: string;
9
- /** 购买的商品 ID */
10
- product_id: string;
11
- /** 购买的商品的数量 */
12
- quantity: number;
13
- /** 订单币种代码。例如 USD CNY */
14
- currency: string;
15
- /** 订单金额,单位为分,如果币种为美元,则单位为美分。 */
16
- amount: number;
17
- /** 游戏侧创建订单时提供的订单上下文,透传回游戏 */
18
- context?: string;
19
- }
20
- export declare function isRefundPayload(data: unknown): data is RefundNotification;
@@ -1,26 +0,0 @@
1
- /** ShipOrderNotification 是订单发货通知的数据结构,包含了订单的详细信息 */
2
- export interface ShipOrderNotification {
3
- /** 世游服务端创建的,标识订单的唯一 ID */
4
- order_id: string;
5
- /** 游戏侧用于标识创建订单请求的唯一 ID */
6
- reference_id: string;
7
- /** 发起购买的用户的唯一标识 */
8
- combo_id: string;
9
- /** 购买的商品 ID */
10
- product_id: string;
11
- /** 购买的商品的数量 */
12
- quantity: number;
13
- /** 订单币种代码。例如 USD CNY */
14
- currency: string;
15
- /** 订单金额,单位为分,如果币种为美元,则单位为美分。 */
16
- amount: number;
17
- /** 游戏侧创建订单时提供的订单上下文,透传回游戏 */
18
- context?: string;
19
- /**
20
- * 是否是沙盒订单。沙盒订单意味着此订单并未产生真实的付款。
21
- *
22
- * 预期此字段仅用于记录日志和数据埋点。无论是否是沙盒订单,游戏侧都应当发货。
23
- */
24
- is_sandbox?: boolean;
25
- }
26
- export declare function isShipOrderPayload(data: unknown): data is ShipOrderNotification;