@seayoo-io/combo-sdk-node 1.5.2 → 1.7.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/README.md CHANGED
@@ -143,6 +143,97 @@ const userSessionID = genSessionID("<ComboID>")
143
143
 
144
144
  ```
145
145
 
146
+ ### 发送/验证短信验证码 OTP
147
+
148
+ 用于向用户发送短信验证码 (OTP),以及校验用户输入的验证码,可用于账号绑定、敏感操作二次确认等场景。
149
+
150
+ > 验证码的目标行为 `action` 由世游发行平台创建并管理。同一次验证流程中,`sendOtp` 与 `verifyOtp` 传入的 `action` 和 `channel` 必须保持一致。
151
+
152
+ ```js
153
+ // 1. 发送验证码
154
+ const sendResult = await client.sendOtp({
155
+ /** 要发送验证码的用户的唯一标识 */
156
+ combo_id: "<ComboID>",
157
+ /** [可选] 发送验证码的通道,目前仅支持 "sms",不填写时默认为 "sms" */
158
+ channel: "sms",
159
+ /** 发送验证码的目标行为,由世游发行平台创建并管理 */
160
+ action: "<Action>",
161
+ /**
162
+ * [可选] 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供
163
+ * 字段定义同 OrderMetaData
164
+ */
165
+ meta: { ... },
166
+ })
167
+
168
+ interface SendOtpResponse {
169
+ /** 掩码后的手机号,仅当 channel=sms 时有值。 */
170
+ mobile: string
171
+ /** 验证码有效期,单位秒。 */
172
+ otp_ttl: number
173
+ /** 重新发送验证码的冷却时间,单位秒。 */
174
+ otp_cooldown: number
175
+ }
176
+
177
+ // 2. 验证验证码
178
+ const verifyResult = await client.verifyOtp({
179
+ /** 要验证验证码的用户的唯一标识 */
180
+ combo_id: "<ComboID>",
181
+ /** [可选] 发送验证码的通道,需与发送时一致,不填写时默认为 "sms" */
182
+ channel: "sms",
183
+ /** 发送验证码的目标行为,需与发送时一致 */
184
+ action: "<Action>",
185
+ /** 用户输入的验证码 */
186
+ otp: "<OTP>",
187
+ })
188
+
189
+ if (verifyResult.valid) {
190
+ // 验证通过。验证码立即失效,不可重复使用
191
+ } else {
192
+ // 验证失败:验证码错误或已过期,建议提示用户重新输入
193
+ }
194
+
195
+ interface VerifyOtpResponse {
196
+ /**
197
+ * 是否验证通过。
198
+ * - true 表示验证通过。验证通过后验证码立即失效,不可重复使用。
199
+ * - false 表示验证失败,验证码不匹配或已过期,建议用户重新检查后重试。
200
+ */
201
+ valid: boolean
202
+ }
203
+ ```
204
+
205
+ > ⚠️ 错误处理
206
+ >
207
+ > - `sendOtp` 在请求失败时(如触发发送冷却、参数错误、服务端错误)会**抛出异常**,请使用 try/catch 捕获处理。
208
+ > - `verifyOtp` 仅在请求本身失败时抛出异常。**验证码不正确属于正常业务结果**,此时会返回 `{ valid: false }` 而不会抛出异常,游戏侧需要根据 `valid` 字段判断验证是否通过。
209
+
210
+ ### 申请语音审核 VoiceModerationRequest
211
+
212
+ 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
213
+
214
+ ```js
215
+ const ok = await client.voiceModerationRequest({
216
+ /** 房间实例 ID,唯一标识某个语音房间的一次存续(从开启到关闭) */
217
+ room_instance_id: "<RoomInstanceID>",
218
+ /** 游戏服务器 ID */
219
+ server_id: 1001,
220
+ /** 提交审核申请的玩家角色 ID */
221
+ requester_role_id: "<PlayerRoleID>",
222
+ /** 被提交语音审核的玩家角色 ID 列表,一次最多提交 32 个 */
223
+ target_role_ids: ["<TargetRoleID1>", "<TargetRoleID2>"],
224
+ })
225
+
226
+ // ok 为 true 表示提交成功,false 表示提交失败(已自动打印错误日志)
227
+ if (ok) {
228
+ // 提交成功
229
+ }
230
+ ```
231
+
232
+ > ⚠️ 注意事项
233
+ >
234
+ > - `voiceModerationRequest` 不会在失败时抛出异常,而是返回 `false`。游戏侧可根据返回值决定后续处理。
235
+ > - `target_role_ids` 一次最多提交 32 个玩家角色 ID。
236
+
146
237
  ## Notify
147
238
 
148
239
  ### Step 1 准备参数
@@ -1,6 +1,6 @@
1
1
  import { type IRequestGlobalConfig } from "../request";
2
2
  import { type SDKBaseConfig } from "../utils";
3
- import type { CreateOrderOption, CreateOrderResponse } from "./types";
3
+ import type { CreateOrderOption, CreateOrderResponse, SendOtpOption, SendOtpResponse, VerifyOtpOption, VerifyOtpResponse, VoiceModerationRequestOption } from "./types";
4
4
  /** Api Client Config */
5
5
  export interface ApiClientConfig extends SDKBaseConfig {
6
6
  /** 自动重试次数,默认重试 1 次 */
@@ -40,4 +40,22 @@ export declare class ApiClient {
40
40
  * @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
41
41
  */
42
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>;
43
61
  }
@@ -46,3 +46,52 @@ export interface CreateOrderResponse {
46
46
  /** 订单失效时间。Unix timestamp in seconds。 */
47
47
  expires_at: number;
48
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/const.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** SDK 名称 */
2
2
  export declare const SDKName = "combo-sdk-node";
3
3
  /** SDK 版本,在编译前会被动态替换 */
4
- export declare const SDKVersion = "1.5.2";
4
+ export declare const SDKVersion = "1.7.0";
5
5
  /**
6
6
  * 世游支持的服务端点列表
7
7
  */
package/dist/index.cjs CHANGED
@@ -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 = "1.5.2";
15
+ const SDKVersion = "1.7.0";
16
16
  /**
17
17
  * 世游支持的服务端点列表
18
18
  */
@@ -1163,10 +1163,95 @@ class ApiClient {
1163
1163
  }
1164
1164
  return ok;
1165
1165
  }
1166
+ /**
1167
+ * 发送验证码
1168
+ *
1169
+ * @param option 发送验证码参数
1170
+ */
1171
+ async sendOtp(option) {
1172
+ const {
1173
+ ok,
1174
+ data,
1175
+ code,
1176
+ status,
1177
+ message,
1178
+ headers
1179
+ } = await this.req.post("send-otp", option, isSendOtpResponse);
1180
+ if (!ok || !data) {
1181
+ console.error({
1182
+ type: "sendOtp Error",
1183
+ status,
1184
+ code,
1185
+ message,
1186
+ traceId: headers[TraceIdField]
1187
+ });
1188
+ throw new Error(`sendOtp: ${message || code || status}`);
1189
+ }
1190
+ return data;
1191
+ }
1192
+ /**
1193
+ * 验证验证码
1194
+ *
1195
+ * @param option 验证码验证参数
1196
+ */
1197
+ async verifyOtp(option) {
1198
+ const {
1199
+ ok,
1200
+ data,
1201
+ code,
1202
+ status,
1203
+ message,
1204
+ headers
1205
+ } = await this.req.post("verify-otp", option, isVerifyOtpResponse);
1206
+ if (!ok || !data) {
1207
+ console.error({
1208
+ type: "verifyOtp Error",
1209
+ status,
1210
+ code,
1211
+ message,
1212
+ traceId: headers[TraceIdField]
1213
+ });
1214
+ throw new Error(`verifyOtp: ${message || code || status}`);
1215
+ }
1216
+ return data;
1217
+ }
1218
+ /**
1219
+ * 申请语音审核。
1220
+ *
1221
+ * 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
1222
+ */
1223
+ async voiceModerationRequest(option) {
1224
+ const {
1225
+ ok,
1226
+ status,
1227
+ code,
1228
+ message,
1229
+ headers
1230
+ } = await this.req.post("voice-moderation-request", option);
1231
+ if (!ok) {
1232
+ console.error({
1233
+ type: "voiceModerationRequest Error",
1234
+ status,
1235
+ code,
1236
+ message,
1237
+ traceId: headers[TraceIdField]
1238
+ });
1239
+ }
1240
+ return ok;
1241
+ }
1166
1242
  }
1167
1243
  function isCreateOrderResponse(data) {
1168
1244
  return isObject(data) && ["order_id", "order_token"].every(field => field in data) && "expires_at" in data && typeof data.expires_at === "number";
1169
1245
  }
1246
+ // 目前 OTP 仅支持 sms 通道,mobile 恒为掩码后的手机号字符串,故此处统一按 string 校验。
1247
+ // 后续新增 channel 时,需要在此根据 channel 补充 mobile 的关联校验
1248
+ // (例如非 sms 通道下 mobile 可能为空),届时可考虑将 channel 传入本守卫。
1249
+ function isSendOtpResponse(data) {
1250
+ return isObject(data) && "mobile" in data && "otp_ttl" in data && "otp_cooldown" in data && typeof data.mobile === "string" && typeof data.otp_ttl === "number" && typeof data.otp_cooldown === "number";
1251
+ }
1252
+ function isVerifyOtpResponse(data) {
1253
+ return isObject(data) && "valid" in data && typeof data.valid === "boolean";
1254
+ }
1170
1255
 
1171
1256
  function isIdentityJwtPayload(payload) {
1172
1257
  return isObject(payload) && "sub" in payload && "iss" in payload && "scope" in payload && "idp" in payload && "device_id" in payload && "external_id" in payload && "external_name" in payload && "reg_time" in payload;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { ApiClient } from "./api";
2
2
  export type { ApiClientConfig } from "./api";
3
3
  export type { CreateOrderOption, OrderMetaData, CreateOrderResponse } from "./api/types";
4
+ export type { SendOtpOption, SendOtpMetaData, SendOtpResponse, SupportedOtpChannel, VerifyOtpOption, VerifyOtpResponse, VoiceModerationRequestOption, } from "./api/types";
4
5
  export { TokenVerifier } from "./verify";
5
6
  export type { IdentityPayload } from "./verify/id";
6
7
  export type { AdPayload } from "./verify/ads";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { verify } from 'jsonwebtoken';
7
7
  /** SDK 名称 */
8
8
  const SDKName = "combo-sdk-node";
9
9
  /** SDK 版本,在编译前会被动态替换 */
10
- const SDKVersion = "1.5.2";
10
+ const SDKVersion = "1.7.0";
11
11
  /**
12
12
  * 世游支持的服务端点列表
13
13
  */
@@ -1158,10 +1158,95 @@ class ApiClient {
1158
1158
  }
1159
1159
  return ok;
1160
1160
  }
1161
+ /**
1162
+ * 发送验证码
1163
+ *
1164
+ * @param option 发送验证码参数
1165
+ */
1166
+ async sendOtp(option) {
1167
+ const {
1168
+ ok,
1169
+ data,
1170
+ code,
1171
+ status,
1172
+ message,
1173
+ headers
1174
+ } = await this.req.post("send-otp", option, isSendOtpResponse);
1175
+ if (!ok || !data) {
1176
+ console.error({
1177
+ type: "sendOtp Error",
1178
+ status,
1179
+ code,
1180
+ message,
1181
+ traceId: headers[TraceIdField]
1182
+ });
1183
+ throw new Error(`sendOtp: ${message || code || status}`);
1184
+ }
1185
+ return data;
1186
+ }
1187
+ /**
1188
+ * 验证验证码
1189
+ *
1190
+ * @param option 验证码验证参数
1191
+ */
1192
+ async verifyOtp(option) {
1193
+ const {
1194
+ ok,
1195
+ data,
1196
+ code,
1197
+ status,
1198
+ message,
1199
+ headers
1200
+ } = await this.req.post("verify-otp", option, isVerifyOtpResponse);
1201
+ if (!ok || !data) {
1202
+ console.error({
1203
+ type: "verifyOtp Error",
1204
+ status,
1205
+ code,
1206
+ message,
1207
+ traceId: headers[TraceIdField]
1208
+ });
1209
+ throw new Error(`verifyOtp: ${message || code || status}`);
1210
+ }
1211
+ return data;
1212
+ }
1213
+ /**
1214
+ * 申请语音审核。
1215
+ *
1216
+ * 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
1217
+ */
1218
+ async voiceModerationRequest(option) {
1219
+ const {
1220
+ ok,
1221
+ status,
1222
+ code,
1223
+ message,
1224
+ headers
1225
+ } = await this.req.post("voice-moderation-request", option);
1226
+ if (!ok) {
1227
+ console.error({
1228
+ type: "voiceModerationRequest Error",
1229
+ status,
1230
+ code,
1231
+ message,
1232
+ traceId: headers[TraceIdField]
1233
+ });
1234
+ }
1235
+ return ok;
1236
+ }
1161
1237
  }
1162
1238
  function isCreateOrderResponse(data) {
1163
1239
  return isObject(data) && ["order_id", "order_token"].every(field => field in data) && "expires_at" in data && typeof data.expires_at === "number";
1164
1240
  }
1241
+ // 目前 OTP 仅支持 sms 通道,mobile 恒为掩码后的手机号字符串,故此处统一按 string 校验。
1242
+ // 后续新增 channel 时,需要在此根据 channel 补充 mobile 的关联校验
1243
+ // (例如非 sms 通道下 mobile 可能为空),届时可考虑将 channel 传入本守卫。
1244
+ function isSendOtpResponse(data) {
1245
+ return isObject(data) && "mobile" in data && "otp_ttl" in data && "otp_cooldown" in data && typeof data.mobile === "string" && typeof data.otp_ttl === "number" && typeof data.otp_cooldown === "number";
1246
+ }
1247
+ function isVerifyOtpResponse(data) {
1248
+ return isObject(data) && "valid" in data && typeof data.valid === "boolean";
1249
+ }
1165
1250
 
1166
1251
  function isIdentityJwtPayload(payload) {
1167
1252
  return isObject(payload) && "sub" in payload && "iss" in payload && "scope" in payload && "idp" in payload && "device_id" in payload && "external_id" in payload && "external_name" in payload && "reg_time" in payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-io/combo-sdk-node",
3
- "version": "1.5.2",
3
+ "version": "1.7.0",
4
4
  "description": "Combo SDK for Node.js",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -21,7 +21,10 @@
21
21
  "simple-git-hooks": {
22
22
  "pre-commit": "pnpm lint && pnpm type-check"
23
23
  },
24
- "repository": "https://github.com/seayoo-io/combo-sdk-node",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/seayoo-io/combo-sdk-node"
27
+ },
25
28
  "keywords": [
26
29
  "combo",
27
30
  "seayoo",
@@ -57,10 +60,9 @@
57
60
  "preconvert": "node preconvert.cjs",
58
61
  "dev": "microbundle watch --target node",
59
62
  "clear": "rimraf dist && rimraf node_modules",
60
- "type-check": "tsc --noEmit",
63
+ "type-check": "tsc --noEmit -p tsconfig.typecheck.json",
61
64
  "lint": "eslint ./src/**/*.ts",
62
65
  "lint:fix": "eslint ./src/**/*.{ts,js} --fix",
63
- "test": "vitest",
64
- "prepublish": "pnpm type-check && pnpm lint:fix && vitest run && pnpm build"
66
+ "test": "vitest"
65
67
  }
66
68
  }
@@ -0,0 +1,4 @@
1
+ allowBuilds:
2
+ esbuild: true
3
+ msw: true
4
+ simple-git-hooks: true