@seayoo-io/combo-sdk-node 1.8.1 → 1.10.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/dist/index.cjs CHANGED
@@ -33,7 +33,7 @@ jsonwebtoken = __toESM(jsonwebtoken);
33
33
  /** SDK 名称 */
34
34
  const SDKName = "combo-sdk-node";
35
35
  /** SDK 版本,在编译前会被动态替换 */
36
- const SDKVersion = "1.8.1";
36
+ const SDKVersion = "1.10.0";
37
37
  /**
38
38
  * 世游支持的服务端点列表
39
39
  */
@@ -1082,6 +1082,31 @@ var ApiClient = class {
1082
1082
  return data;
1083
1083
  }
1084
1084
  /**
1085
+ * 获取微信小游戏的接口调用凭证(Access Token),供游戏服务端调用微信服务端 API 使用。
1086
+ *
1087
+ * 接口调用凭证由世游服务端统一维护和刷新,游戏侧无需自行调用微信接口获取。
1088
+ *
1089
+ * 此接口仅适用于微信小游戏。
1090
+ *
1091
+ * 游戏服务端应当缓存接口调用凭证,缓存时间 1 分钟,按照 1 次/分钟 的频率请求该 API 获取并刷新缓存。
1092
+ *
1093
+ * @param option 获取接口调用凭证的参数
1094
+ */
1095
+ async getMiniGameWeixinAccessToken(option) {
1096
+ const { ok, data, code, status, message, headers } = await this.req.post("minigame-weixin-access-token", option, isGetMiniGameWeixinAccessTokenResponse);
1097
+ if (!ok || !data) {
1098
+ console.error({
1099
+ type: "getMiniGameWeixinAccessToken Error",
1100
+ status,
1101
+ code,
1102
+ message,
1103
+ traceId: headers[TraceIdField]
1104
+ });
1105
+ throw new Error(`getMiniGameWeixinAccessToken: ${message || code || status}`);
1106
+ }
1107
+ return data;
1108
+ }
1109
+ /**
1085
1110
  * 申请语音审核。
1086
1111
  *
1087
1112
  * 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
@@ -1107,6 +1132,9 @@ function isSendOtpResponse(data) {
1107
1132
  function isVerifyOtpResponse(data) {
1108
1133
  return isObject(data) && "valid" in data && typeof data.valid === "boolean";
1109
1134
  }
1135
+ function isGetMiniGameWeixinAccessTokenResponse(data) {
1136
+ return isObject(data) && "app_id" in data && "access_token" in data && typeof data.app_id === "string" && typeof data.access_token === "string" && data.access_token !== "";
1137
+ }
1110
1138
  //#endregion
1111
1139
  //#region src/verify/id.ts
1112
1140
  function isIdentityJwtPayload(payload) {
@@ -1233,6 +1261,14 @@ function isRefundPayload(data) {
1233
1261
  return isObject(data) && "order_id" in data && "reference_id" in data && "combo_id" in data && "product_id" in data && "quantity" in data && "currency" in data && "amount" in data && typeof data.order_id === "string" && typeof data.combo_id === "string" && typeof data.quantity === "number" && typeof data.amount === "number" && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
1234
1262
  }
1235
1263
  //#endregion
1264
+ //#region src/notify/msgDataTags.ts
1265
+ function isDataTag(data) {
1266
+ return isObject(data) && "entity_type" in data && "entity_id" in data && "tag_name" in data && "tag_value" in data && typeof data.entity_type === "string" && typeof data.entity_id === "string" && typeof data.tag_name === "string" && typeof data.tag_value === "string" && !!data.entity_type && !!data.entity_id && !!data.tag_name;
1267
+ }
1268
+ function isDataTagsPayload(data) {
1269
+ return isObject(data) && "tags" in data && Array.isArray(data.tags) && data.tags.every(isDataTag);
1270
+ }
1271
+ //#endregion
1236
1272
  //#region src/notify/types.ts
1237
1273
  /**
1238
1274
  * 通知类型枚举
@@ -1251,6 +1287,15 @@ let NotificationType = /* @__PURE__ */ function(NotificationType) {
1251
1287
  * 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
1252
1288
  */
1253
1289
  NotificationType["Refund"] = "refund";
1290
+ /**
1291
+ * 世游服务端会将约定好的数据标签批量推送给游戏侧。
1292
+ *
1293
+ * 预期游戏侧在接收到数据标签通知后,将这些数据标签持久化存储:
1294
+ *
1295
+ * - 如果游戏内成功处理了数据标签通知,则应当返回 void 或 Promise<void>
1296
+ * - 如果游戏内处理数据标签时出现错误,则应当 throw Error。世游服务端会在稍后重试推送数据标签通知。
1297
+ */
1298
+ NotificationType["DataTags"] = "data_tags";
1254
1299
  return NotificationType;
1255
1300
  }({});
1256
1301
  /**
@@ -1264,6 +1309,10 @@ const messageDataGuards = {
1264
1309
  [NotificationType.Refund]: {
1265
1310
  guard: isRefundPayload,
1266
1311
  message: "Refund Data Format Error"
1312
+ },
1313
+ [NotificationType.DataTags]: {
1314
+ guard: isDataTagsPayload,
1315
+ message: "DataTags Data Format Error"
1267
1316
  }
1268
1317
  };
1269
1318
  //#endregion
package/dist/index.d.cts CHANGED
@@ -426,6 +426,16 @@ interface VerifyOtpResponse {
426
426
  */
427
427
  valid: boolean;
428
428
  }
429
+ interface GetMiniGameWeixinAccessTokenOption {
430
+ /** 微信小游戏的 AppID。必须是当前游戏配置的微信小游戏应用。 */
431
+ app_id: string;
432
+ }
433
+ interface GetMiniGameWeixinAccessTokenResponse {
434
+ /** 微信小游戏的 AppID,与请求中的 app_id 一致。 */
435
+ app_id: string;
436
+ /** 微信小游戏的接口调用凭证。 */
437
+ access_token: string;
438
+ }
429
439
  interface VoiceModerationRequestOption {
430
440
  /** 房间实例 ID,唯一标识某个语音房间的一次存续(从开启到关闭)。 */
431
441
  room_instance_id: string;
@@ -433,8 +443,17 @@ interface VoiceModerationRequestOption {
433
443
  server_id: number;
434
444
  /** 提交审核申请的玩家角色 ID。 */
435
445
  requester_role_id: string;
446
+ /** 提交审核申请的玩家的唯一标识,选填。不传表示未提供。 */
447
+ requester_combo_id?: string;
436
448
  /** 被提交语音审核的玩家角色 ID 列表,一次最多提交 32 个。 */
437
449
  target_role_ids: string[];
450
+ /**
451
+ * 提交审核申请的原因列表,选填。
452
+ *
453
+ * 一次最多提交 12 个,单个原因最多 32 个字符,取值参见:审核申请原因维度表。
454
+ * 注意:取值不能包含英文逗号。
455
+ */
456
+ reasons?: string[];
438
457
  }
439
458
  //#endregion
440
459
  //#region src/api/index.d.ts
@@ -489,6 +508,18 @@ declare class ApiClient {
489
508
  * @param option 验证码验证参数
490
509
  */
491
510
  verifyOtp(option: VerifyOtpOption): Promise<VerifyOtpResponse>;
511
+ /**
512
+ * 获取微信小游戏的接口调用凭证(Access Token),供游戏服务端调用微信服务端 API 使用。
513
+ *
514
+ * 接口调用凭证由世游服务端统一维护和刷新,游戏侧无需自行调用微信接口获取。
515
+ *
516
+ * 此接口仅适用于微信小游戏。
517
+ *
518
+ * 游戏服务端应当缓存接口调用凭证,缓存时间 1 分钟,按照 1 次/分钟 的频率请求该 API 获取并刷新缓存。
519
+ *
520
+ * @param option 获取接口调用凭证的参数
521
+ */
522
+ getMiniGameWeixinAccessToken(option: GetMiniGameWeixinAccessTokenOption): Promise<GetMiniGameWeixinAccessTokenResponse>;
492
523
  /**
493
524
  * 申请语音审核。
494
525
  *
@@ -659,6 +690,24 @@ interface RefundNotification {
659
690
  context?: string;
660
691
  }
661
692
  //#endregion
693
+ //#region src/notify/msgDataTags.d.ts
694
+ /** DataTag 表示单条数据标签,即某个数据实体的某个标签 */
695
+ interface DataTag {
696
+ /** 标签所属实体的类型。例如 `role` 代表实体类型为游戏角色 */
697
+ entity_type: string;
698
+ /** 标签所属实体的唯一标识 */
699
+ entity_id: string;
700
+ /** 标签名称 */
701
+ tag_name: string;
702
+ /** 标签值 */
703
+ tag_value: string;
704
+ }
705
+ /** DataTagsNotification 是数据标签通知的数据结构,包含一批数据标签 */
706
+ interface DataTagsNotification {
707
+ /** 一批数据标签,数组长度不定 */
708
+ tags: DataTag[];
709
+ }
710
+ //#endregion
662
711
  //#region src/notify/types.d.ts
663
712
  /**
664
713
  * 通知类型枚举
@@ -676,7 +725,16 @@ declare enum NotificationType {
676
725
  /**
677
726
  * 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
678
727
  */
679
- Refund = "refund"
728
+ Refund = "refund",
729
+ /**
730
+ * 世游服务端会将约定好的数据标签批量推送给游戏侧。
731
+ *
732
+ * 预期游戏侧在接收到数据标签通知后,将这些数据标签持久化存储:
733
+ *
734
+ * - 如果游戏内成功处理了数据标签通知,则应当返回 void 或 Promise<void>
735
+ * - 如果游戏内处理数据标签时出现错误,则应当 throw Error。世游服务端会在稍后重试推送数据标签通知。
736
+ */
737
+ DataTags = "data_tags"
680
738
  }
681
739
  /**
682
740
  * 通知类型对应的 payload
@@ -684,6 +742,7 @@ declare enum NotificationType {
684
742
  interface ENotificationPayload {
685
743
  [NotificationType.ShipOrder]: ShipOrderNotification;
686
744
  [NotificationType.Refund]: RefundNotification;
745
+ [NotificationType.DataTags]: DataTagsNotification;
687
746
  }
688
747
  /**
689
748
  * 自定义通知处理函数
@@ -845,4 +904,4 @@ declare class RedisIdempotencyStore implements IdempotencyKeyStoreHelper {
845
904
  setXX(key: string, value: string): Promise<void>;
846
905
  }
847
906
  //#endregion
848
- export { type AdPayload, ApiClient, type ApiClientConfig, type CreateOrderOption, type CreateOrderResponse, Endpoint, GMError, IdP, type IdentityPayload, MemoryIdempotencyStore, type NotificationHandler, NotificationType, type OrderMetaData, Platform, RedisIdempotencyStore, type SDKBaseConfig, type SendOtpMetaData, type SendOtpOption, type SendOtpResponse, type SupportedOtpChannel, TokenVerifier, type VerifyOtpOption, type VerifyOtpResponse, type VoiceModerationRequestOption, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
907
+ export { type AdPayload, ApiClient, type ApiClientConfig, type CreateOrderOption, type CreateOrderResponse, type DataTag, type DataTagsNotification, type ENotificationPayload, Endpoint, GMError, type GetMiniGameWeixinAccessTokenOption, type GetMiniGameWeixinAccessTokenResponse, IdP, type IdentityPayload, MemoryIdempotencyStore, type NotificationHandler, NotificationType, type OrderMetaData, Platform, RedisIdempotencyStore, type RefundNotification, type SDKBaseConfig, type SendOtpMetaData, type SendOtpOption, type SendOtpResponse, type ShipOrderNotification, type SupportedOtpChannel, TokenVerifier, type VerifyOtpOption, type VerifyOtpResponse, type VoiceModerationRequestOption, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
package/dist/index.d.ts CHANGED
@@ -426,6 +426,16 @@ interface VerifyOtpResponse {
426
426
  */
427
427
  valid: boolean;
428
428
  }
429
+ interface GetMiniGameWeixinAccessTokenOption {
430
+ /** 微信小游戏的 AppID。必须是当前游戏配置的微信小游戏应用。 */
431
+ app_id: string;
432
+ }
433
+ interface GetMiniGameWeixinAccessTokenResponse {
434
+ /** 微信小游戏的 AppID,与请求中的 app_id 一致。 */
435
+ app_id: string;
436
+ /** 微信小游戏的接口调用凭证。 */
437
+ access_token: string;
438
+ }
429
439
  interface VoiceModerationRequestOption {
430
440
  /** 房间实例 ID,唯一标识某个语音房间的一次存续(从开启到关闭)。 */
431
441
  room_instance_id: string;
@@ -433,8 +443,17 @@ interface VoiceModerationRequestOption {
433
443
  server_id: number;
434
444
  /** 提交审核申请的玩家角色 ID。 */
435
445
  requester_role_id: string;
446
+ /** 提交审核申请的玩家的唯一标识,选填。不传表示未提供。 */
447
+ requester_combo_id?: string;
436
448
  /** 被提交语音审核的玩家角色 ID 列表,一次最多提交 32 个。 */
437
449
  target_role_ids: string[];
450
+ /**
451
+ * 提交审核申请的原因列表,选填。
452
+ *
453
+ * 一次最多提交 12 个,单个原因最多 32 个字符,取值参见:审核申请原因维度表。
454
+ * 注意:取值不能包含英文逗号。
455
+ */
456
+ reasons?: string[];
438
457
  }
439
458
  //#endregion
440
459
  //#region src/api/index.d.ts
@@ -489,6 +508,18 @@ declare class ApiClient {
489
508
  * @param option 验证码验证参数
490
509
  */
491
510
  verifyOtp(option: VerifyOtpOption): Promise<VerifyOtpResponse>;
511
+ /**
512
+ * 获取微信小游戏的接口调用凭证(Access Token),供游戏服务端调用微信服务端 API 使用。
513
+ *
514
+ * 接口调用凭证由世游服务端统一维护和刷新,游戏侧无需自行调用微信接口获取。
515
+ *
516
+ * 此接口仅适用于微信小游戏。
517
+ *
518
+ * 游戏服务端应当缓存接口调用凭证,缓存时间 1 分钟,按照 1 次/分钟 的频率请求该 API 获取并刷新缓存。
519
+ *
520
+ * @param option 获取接口调用凭证的参数
521
+ */
522
+ getMiniGameWeixinAccessToken(option: GetMiniGameWeixinAccessTokenOption): Promise<GetMiniGameWeixinAccessTokenResponse>;
492
523
  /**
493
524
  * 申请语音审核。
494
525
  *
@@ -659,6 +690,24 @@ interface RefundNotification {
659
690
  context?: string;
660
691
  }
661
692
  //#endregion
693
+ //#region src/notify/msgDataTags.d.ts
694
+ /** DataTag 表示单条数据标签,即某个数据实体的某个标签 */
695
+ interface DataTag {
696
+ /** 标签所属实体的类型。例如 `role` 代表实体类型为游戏角色 */
697
+ entity_type: string;
698
+ /** 标签所属实体的唯一标识 */
699
+ entity_id: string;
700
+ /** 标签名称 */
701
+ tag_name: string;
702
+ /** 标签值 */
703
+ tag_value: string;
704
+ }
705
+ /** DataTagsNotification 是数据标签通知的数据结构,包含一批数据标签 */
706
+ interface DataTagsNotification {
707
+ /** 一批数据标签,数组长度不定 */
708
+ tags: DataTag[];
709
+ }
710
+ //#endregion
662
711
  //#region src/notify/types.d.ts
663
712
  /**
664
713
  * 通知类型枚举
@@ -676,7 +725,16 @@ declare enum NotificationType {
676
725
  /**
677
726
  * 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
678
727
  */
679
- Refund = "refund"
728
+ Refund = "refund",
729
+ /**
730
+ * 世游服务端会将约定好的数据标签批量推送给游戏侧。
731
+ *
732
+ * 预期游戏侧在接收到数据标签通知后,将这些数据标签持久化存储:
733
+ *
734
+ * - 如果游戏内成功处理了数据标签通知,则应当返回 void 或 Promise<void>
735
+ * - 如果游戏内处理数据标签时出现错误,则应当 throw Error。世游服务端会在稍后重试推送数据标签通知。
736
+ */
737
+ DataTags = "data_tags"
680
738
  }
681
739
  /**
682
740
  * 通知类型对应的 payload
@@ -684,6 +742,7 @@ declare enum NotificationType {
684
742
  interface ENotificationPayload {
685
743
  [NotificationType.ShipOrder]: ShipOrderNotification;
686
744
  [NotificationType.Refund]: RefundNotification;
745
+ [NotificationType.DataTags]: DataTagsNotification;
687
746
  }
688
747
  /**
689
748
  * 自定义通知处理函数
@@ -845,4 +904,4 @@ declare class RedisIdempotencyStore implements IdempotencyKeyStoreHelper {
845
904
  setXX(key: string, value: string): Promise<void>;
846
905
  }
847
906
  //#endregion
848
- export { type AdPayload, ApiClient, type ApiClientConfig, type CreateOrderOption, type CreateOrderResponse, Endpoint, GMError, IdP, type IdentityPayload, MemoryIdempotencyStore, type NotificationHandler, NotificationType, type OrderMetaData, Platform, RedisIdempotencyStore, type SDKBaseConfig, type SendOtpMetaData, type SendOtpOption, type SendOtpResponse, type SupportedOtpChannel, TokenVerifier, type VerifyOtpOption, type VerifyOtpResponse, type VoiceModerationRequestOption, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
907
+ export { type AdPayload, ApiClient, type ApiClientConfig, type CreateOrderOption, type CreateOrderResponse, type DataTag, type DataTagsNotification, type ENotificationPayload, Endpoint, GMError, type GetMiniGameWeixinAccessTokenOption, type GetMiniGameWeixinAccessTokenResponse, IdP, type IdentityPayload, MemoryIdempotencyStore, type NotificationHandler, NotificationType, type OrderMetaData, Platform, RedisIdempotencyStore, type RefundNotification, type SDKBaseConfig, type SendOtpMetaData, type SendOtpOption, type SendOtpResponse, type ShipOrderNotification, type SupportedOtpChannel, TokenVerifier, type VerifyOtpOption, type VerifyOtpResponse, type VoiceModerationRequestOption, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import jwt from "jsonwebtoken";
7
7
  /** SDK 名称 */
8
8
  const SDKName = "combo-sdk-node";
9
9
  /** SDK 版本,在编译前会被动态替换 */
10
- const SDKVersion = "1.8.1";
10
+ const SDKVersion = "1.10.0";
11
11
  /**
12
12
  * 世游支持的服务端点列表
13
13
  */
@@ -1056,6 +1056,31 @@ var ApiClient = class {
1056
1056
  return data;
1057
1057
  }
1058
1058
  /**
1059
+ * 获取微信小游戏的接口调用凭证(Access Token),供游戏服务端调用微信服务端 API 使用。
1060
+ *
1061
+ * 接口调用凭证由世游服务端统一维护和刷新,游戏侧无需自行调用微信接口获取。
1062
+ *
1063
+ * 此接口仅适用于微信小游戏。
1064
+ *
1065
+ * 游戏服务端应当缓存接口调用凭证,缓存时间 1 分钟,按照 1 次/分钟 的频率请求该 API 获取并刷新缓存。
1066
+ *
1067
+ * @param option 获取接口调用凭证的参数
1068
+ */
1069
+ async getMiniGameWeixinAccessToken(option) {
1070
+ const { ok, data, code, status, message, headers } = await this.req.post("minigame-weixin-access-token", option, isGetMiniGameWeixinAccessTokenResponse);
1071
+ if (!ok || !data) {
1072
+ console.error({
1073
+ type: "getMiniGameWeixinAccessToken Error",
1074
+ status,
1075
+ code,
1076
+ message,
1077
+ traceId: headers[TraceIdField]
1078
+ });
1079
+ throw new Error(`getMiniGameWeixinAccessToken: ${message || code || status}`);
1080
+ }
1081
+ return data;
1082
+ }
1083
+ /**
1059
1084
  * 申请语音审核。
1060
1085
  *
1061
1086
  * 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
@@ -1081,6 +1106,9 @@ function isSendOtpResponse(data) {
1081
1106
  function isVerifyOtpResponse(data) {
1082
1107
  return isObject(data) && "valid" in data && typeof data.valid === "boolean";
1083
1108
  }
1109
+ function isGetMiniGameWeixinAccessTokenResponse(data) {
1110
+ return isObject(data) && "app_id" in data && "access_token" in data && typeof data.app_id === "string" && typeof data.access_token === "string" && data.access_token !== "";
1111
+ }
1084
1112
  //#endregion
1085
1113
  //#region src/verify/id.ts
1086
1114
  function isIdentityJwtPayload(payload) {
@@ -1207,6 +1235,14 @@ function isRefundPayload(data) {
1207
1235
  return isObject(data) && "order_id" in data && "reference_id" in data && "combo_id" in data && "product_id" in data && "quantity" in data && "currency" in data && "amount" in data && typeof data.order_id === "string" && typeof data.combo_id === "string" && typeof data.quantity === "number" && typeof data.amount === "number" && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
1208
1236
  }
1209
1237
  //#endregion
1238
+ //#region src/notify/msgDataTags.ts
1239
+ function isDataTag(data) {
1240
+ return isObject(data) && "entity_type" in data && "entity_id" in data && "tag_name" in data && "tag_value" in data && typeof data.entity_type === "string" && typeof data.entity_id === "string" && typeof data.tag_name === "string" && typeof data.tag_value === "string" && !!data.entity_type && !!data.entity_id && !!data.tag_name;
1241
+ }
1242
+ function isDataTagsPayload(data) {
1243
+ return isObject(data) && "tags" in data && Array.isArray(data.tags) && data.tags.every(isDataTag);
1244
+ }
1245
+ //#endregion
1210
1246
  //#region src/notify/types.ts
1211
1247
  /**
1212
1248
  * 通知类型枚举
@@ -1225,6 +1261,15 @@ let NotificationType = /* @__PURE__ */ function(NotificationType) {
1225
1261
  * 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
1226
1262
  */
1227
1263
  NotificationType["Refund"] = "refund";
1264
+ /**
1265
+ * 世游服务端会将约定好的数据标签批量推送给游戏侧。
1266
+ *
1267
+ * 预期游戏侧在接收到数据标签通知后,将这些数据标签持久化存储:
1268
+ *
1269
+ * - 如果游戏内成功处理了数据标签通知,则应当返回 void 或 Promise<void>
1270
+ * - 如果游戏内处理数据标签时出现错误,则应当 throw Error。世游服务端会在稍后重试推送数据标签通知。
1271
+ */
1272
+ NotificationType["DataTags"] = "data_tags";
1228
1273
  return NotificationType;
1229
1274
  }({});
1230
1275
  /**
@@ -1238,6 +1283,10 @@ const messageDataGuards = {
1238
1283
  [NotificationType.Refund]: {
1239
1284
  guard: isRefundPayload,
1240
1285
  message: "Refund Data Format Error"
1286
+ },
1287
+ [NotificationType.DataTags]: {
1288
+ guard: isDataTagsPayload,
1289
+ message: "DataTags Data Format Error"
1241
1290
  }
1242
1291
  };
1243
1292
  //#endregion
@@ -0,0 +1,224 @@
1
+ > [Combo SDK for Node.js](../README.md) / ApiClient
2
+
3
+ # ApiClient
4
+
5
+ ## 初始化
6
+
7
+ ```js
8
+ import { ApiClient, Endpoint } from "@seayoo-io/combo-sdk-node"
9
+
10
+ const client = new ApiClient({
11
+ game: "<GameId>",
12
+ secret: "<SecretKey>",
13
+ endpoint: Endpoint.China,
14
+ // 以下参数可选
15
+ maxRetry: 1, // 失败后自动重试次数,默认 1
16
+ retryInterval: 1000, // 重试间隔,默认是 1000,单位 ms,可以传递函数动态设置间隔
17
+ logger: function (log) {}, // 请求日志函数,log 类型参见源码类型定义
18
+ timeout: 5000, // 超时等待时长,单位 ms,默认 5000
19
+ })
20
+ ```
21
+
22
+ ## 创建订单 CreateOrder
23
+
24
+ ```js
25
+ // 导入枚举变量
26
+ import { Platform } from "@seayoo-io/combo-sdk-node"
27
+
28
+ // 创建订单
29
+ const createOrderResult = await client.createOrder({
30
+ /** 用于标识创建订单请求的唯一 ID */
31
+ reference_id: "<游戏订单ID>",
32
+ /** 发起购买的用户的唯一标识 */
33
+ combo_id: "<ComboID>",
34
+ /**
35
+ * 要购买的商品 ID
36
+ * 这里指的是在世游发行平台管理的商品 ID,其中重要的两个约定是:
37
+ * - 商品价格是正整数
38
+ * - 商品价格单位为 分 或 美分,即商品币种所支持的最小流通单位
39
+ */
40
+ product_id: "<ProductID>",
41
+ /** 平台,支持类型见源码类型定义 Platform */
42
+ platform: Platform.iOS,
43
+ /**
44
+ * 游戏侧接收发货通知的服务端地址
45
+ * 这个地址对应的服务端应该通过 Notify 模块实现路由处理
46
+ */
47
+ notify_url: "https://<YourSite>/<YourPath>"
48
+ /** 要购买的商品的数量,最小为 1,必须为正整数 */
49
+ quantity: 1,
50
+ /** [可选]订单上下文,在发货通知中透传回游戏 */
51
+ context: "",
52
+ /**
53
+ * 订单的元数据,详细定义参看 OrderMetaData
54
+ *
55
+ * 大部分元数据用于数据分析与查询,游戏侧应当尽量提供
56
+ * 某些元数据在特定的支付场景下是必须的,例如微信小游戏的 iOS 支付场景
57
+ */
58
+ meta: { ... }
59
+ })
60
+
61
+ interface OrderMetaData {
62
+ /** 游戏大区 ID */
63
+ zone_id?: string
64
+ /** 游戏服务器 ID */
65
+ server_id?: string
66
+ /** 游戏角色 ID */
67
+ role_id?: string
68
+ /** 游戏角色名 */
69
+ role_name?: string
70
+ /** 游戏角色的等级 */
71
+ role_level?: number
72
+ }
73
+
74
+ interface CreateOrderResponse {
75
+ /** 世游服务端创建的,标识订单的唯一 ID。 */
76
+ order_id: string
77
+ /** 世游服务端创建的订单 token,用于后续支付流程。 */
78
+ order_token: string
79
+ /** 订单失效时间。Unix timestamp in seconds。 */
80
+ expires_at: number
81
+ }
82
+ ```
83
+
84
+ ## 进入/离开游戏
85
+
86
+ 下述两个接口对应的功能是**中宣部防沉迷系统**的上报功能,这里的 SessionID 是一次游戏会话的标识,也就是每次玩家进入游戏+离开游戏,算一个 Game Session。单次游戏会话的上下线动作必须使用同一个 SessionID 上报。
87
+
88
+ ```js
89
+ // 进入游戏
90
+ await client.enterGame("<ComboID>", "<SessionID>")
91
+
92
+ // 离开游戏
93
+ await client.leaveGame("<ComboID>", "<SessionID>")
94
+ ```
95
+
96
+ > 注意,SessionID 不可重复使用,可以使用 SDK 提供的工具函数生成 SessionID
97
+
98
+ ```js
99
+ import { genSessionID } from "@seayoo-io/combo-sdk-node"
100
+
101
+ // genSessionID 接受唯一参数 comboId 作为输入,返回一个 32 位固定长度的不重复字符串
102
+ const userSessionID = genSessionID("<ComboID>")
103
+ ```
104
+
105
+ ## 发送/验证短信验证码 OTP
106
+
107
+ 用于向用户发送短信验证码 (OTP),以及校验用户输入的验证码,可用于账号绑定、敏感操作二次确认等场景。
108
+
109
+ > 验证码的目标行为 `action` 由世游发行平台创建并管理。同一次验证流程中,`sendOtp` 与 `verifyOtp` 传入的 `action` 和 `channel` 必须保持一致。
110
+
111
+ ```js
112
+ // 1. 发送验证码
113
+ const sendResult = await client.sendOtp({
114
+ /** 要发送验证码的用户的唯一标识 */
115
+ combo_id: "<ComboID>",
116
+ /** [可选] 发送验证码的通道,目前仅支持 "sms",不填写时默认为 "sms" */
117
+ channel: "sms",
118
+ /** 发送验证码的目标行为,由世游发行平台创建并管理 */
119
+ action: "<Action>",
120
+ /**
121
+ * [可选] 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供
122
+ * 字段定义同 OrderMetaData
123
+ */
124
+ meta: { ... },
125
+ })
126
+
127
+ interface SendOtpResponse {
128
+ /** 掩码后的手机号,仅当 channel=sms 时有值。 */
129
+ mobile: string
130
+ /** 验证码有效期,单位秒。 */
131
+ otp_ttl: number
132
+ /** 重新发送验证码的冷却时间,单位秒。 */
133
+ otp_cooldown: number
134
+ }
135
+
136
+ // 2. 验证验证码
137
+ const verifyResult = await client.verifyOtp({
138
+ /** 要验证验证码的用户的唯一标识 */
139
+ combo_id: "<ComboID>",
140
+ /** [可选] 发送验证码的通道,需与发送时一致,不填写时默认为 "sms" */
141
+ channel: "sms",
142
+ /** 发送验证码的目标行为,需与发送时一致 */
143
+ action: "<Action>",
144
+ /** 用户输入的验证码 */
145
+ otp: "<OTP>",
146
+ })
147
+
148
+ if (verifyResult.valid) {
149
+ // 验证通过。验证码立即失效,不可重复使用
150
+ } else {
151
+ // 验证失败:验证码错误或已过期,建议提示用户重新输入
152
+ }
153
+
154
+ interface VerifyOtpResponse {
155
+ /**
156
+ * 是否验证通过。
157
+ * - true 表示验证通过。验证通过后验证码立即失效,不可重复使用。
158
+ * - false 表示验证失败,验证码不匹配或已过期,建议用户重新检查后重试。
159
+ */
160
+ valid: boolean
161
+ }
162
+ ```
163
+
164
+ > ⚠️ 错误处理
165
+ >
166
+ > - `sendOtp` 在请求失败时(如触发发送冷却、参数错误、服务端错误)会**抛出异常**,请使用 try/catch 捕获处理。
167
+ > - `verifyOtp` 仅在请求本身失败时抛出异常。**验证码不正确属于正常业务结果**,此时会返回 `{ valid: false }` 而不会抛出异常,游戏侧需要根据 `valid` 字段判断验证是否通过。
168
+
169
+ ## 获取微信小游戏接口调用凭证 GetMiniGameWeixinAccessToken
170
+
171
+ 获取微信小游戏的接口调用凭证(Access Token),供游戏服务端调用微信服务端 API 使用。接口调用凭证由世游服务端统一维护和刷新,游戏侧无需自行调用微信接口获取。
172
+
173
+ > 此接口仅适用于微信小游戏。
174
+
175
+ ```js
176
+ const result = await client.getMiniGameWeixinAccessToken({
177
+ /** 微信小游戏的 AppID,必须是当前游戏配置的微信小游戏应用 */
178
+ app_id: "<WeixinAppID>",
179
+ })
180
+
181
+ interface GetMiniGameWeixinAccessTokenResponse {
182
+ /** 微信小游戏的 AppID,与请求中的 app_id 一致。 */
183
+ app_id: string
184
+ /** 微信小游戏的接口调用凭证。 */
185
+ access_token: string
186
+ }
187
+ ```
188
+
189
+ > ⚠️ 注意事项
190
+ >
191
+ > - 游戏服务端应当**缓存**接口调用凭证,缓存时间 1 分钟,按照 1 次/分钟 的频率请求该 API 获取并刷新缓存。
192
+ > - `getMiniGameWeixinAccessToken` 在请求失败时会**抛出异常**,请使用 try/catch 捕获处理。
193
+
194
+ ## 申请语音审核 VoiceModerationRequest
195
+
196
+ 玩家认为语音房间内某些玩家存在语音违规行为时,可提交语音审核申请。调用前提是:游戏已经在世游开启语音审核服务。
197
+
198
+ ```js
199
+ const ok = await client.voiceModerationRequest({
200
+ /** 房间实例 ID,唯一标识某个语音房间的一次存续(从开启到关闭) */
201
+ room_instance_id: "<RoomInstanceID>",
202
+ /** 游戏服务器 ID */
203
+ server_id: 1001,
204
+ /** 提交审核申请的玩家角色 ID */
205
+ requester_role_id: "<PlayerRoleID>",
206
+ /** 提交审核申请的玩家的唯一标识,选填 */
207
+ requester_combo_id: "<PlayerComboID>",
208
+ /** 被提交语音审核的玩家角色 ID 列表,一次最多提交 32 个 */
209
+ target_role_ids: ["<TargetRoleID1>", "<TargetRoleID2>"],
210
+ /** 提交审核申请的原因列表,选填,数据来自于 GM 维度表 */
211
+ reasons: ["abuse", "noise"],
212
+ })
213
+
214
+ // ok 为 true 表示提交成功,false 表示提交失败(已自动打印错误日志)
215
+ if (ok) {
216
+ // 提交成功
217
+ }
218
+ ```
219
+
220
+ > ⚠️ 注意事项
221
+ >
222
+ > - `voiceModerationRequest` 不会在失败时抛出异常,而是返回 `false`。游戏侧可根据返回值决定后续处理。
223
+ > - `target_role_ids` 一次最多提交 32 个玩家角色 ID。
224
+ > - `reasons` 选填,一次最多提交 12 个,单个原因最多 32 个字符且不能包含英文逗号,取值参见:审核申请原因维度表。