@seayoo-io/combo-sdk-node 1.10.0 → 1.12.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 +22 -0
- package/dist/index.cjs +22 -3
- package/dist/index.d.cts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.js +22 -4
- package/docs/api-client.md +7 -1
- package/docs/notify.md +9 -0
- package/docs/utils.md +74 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -39,6 +39,27 @@ import { ApiClient } from "@seayoo-io/combo-sdk-node"
|
|
|
39
39
|
const { ApiClient } = require("@seayoo-io/combo-sdk-node")
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## 工具函数
|
|
43
|
+
|
|
44
|
+
除上述模块外,SDK 还导出一组通用工具函数,详细说明见 [Utils](./docs/utils.md)。
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { mayBeComboId } from "@seayoo-io/combo-sdk-node"
|
|
48
|
+
|
|
49
|
+
// 校验一个值是否为 Combo ID 格式
|
|
50
|
+
if (mayBeComboId(combo_id)) {
|
|
51
|
+
// ...
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
| 函数 | 说明 |
|
|
56
|
+
| -------------------------- | ---------------------------------- |
|
|
57
|
+
| `genSessionID` | 生成用于标记用户上下线的 SessionID |
|
|
58
|
+
| `mayBeComboId` | 检查值是否符合 Combo ID 格式 |
|
|
59
|
+
| `parseAuthorizationHeader` | 解析 Authorization 请求头 |
|
|
60
|
+
| `calcAuthorizationHeader` | 计算 HTTP 请求的 Authorization 头 |
|
|
61
|
+
| `checkHttpAuthInfo` | 校验 HTTP 请求的签名信息 |
|
|
62
|
+
|
|
42
63
|
## 文档
|
|
43
64
|
|
|
44
65
|
各模块的详细用法见 `docs` 目录:
|
|
@@ -61,3 +82,4 @@ const { ApiClient } = require("@seayoo-io/combo-sdk-node")
|
|
|
61
82
|
- [Step 1 准备](./docs/gm.md#step-1-准备)
|
|
62
83
|
- [Step 2 创建 Store Helper 以启用 idempotencyKey 处理逻辑](./docs/gm.md#step-2-创建-store-helper-以启用-idempotencykey-处理逻辑)
|
|
63
84
|
- [Step 3 绑定处理函数](./docs/gm.md#step-3-绑定处理函数)
|
|
85
|
+
- [Utils](./docs/utils.md) — 通用工具函数
|
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.
|
|
36
|
+
const SDKVersion = "1.12.0";
|
|
37
37
|
/**
|
|
38
38
|
* 世游支持的服务端点列表
|
|
39
39
|
*/
|
|
@@ -413,7 +413,7 @@ async function readBody(req, backup) {
|
|
|
413
413
|
backup || console.error({
|
|
414
414
|
type: "RequestUnReadable",
|
|
415
415
|
url: req.url,
|
|
416
|
-
|
|
416
|
+
method: req.method,
|
|
417
417
|
message: "Cannot read body, stream not readable"
|
|
418
418
|
});
|
|
419
419
|
return backup || "";
|
|
@@ -464,6 +464,24 @@ function genNonceString() {
|
|
|
464
464
|
const r = Math.random() + Math.random();
|
|
465
465
|
return (0, crypto.createHash)("md5").update(`${ts}${r}`).digest("hex").toLowerCase();
|
|
466
466
|
}
|
|
467
|
+
/**
|
|
468
|
+
* 检查一个值是否为 Combo ID 的格式。
|
|
469
|
+
*
|
|
470
|
+
* 仅做格式检查,不检查该 ID 是否真实存在。
|
|
471
|
+
*/
|
|
472
|
+
function mayBeComboId(id) {
|
|
473
|
+
if (typeof id !== "string") return false;
|
|
474
|
+
const m = id.match(/^9?[15](\d{2})(\d{2})(\d{2})(\d{5})(\d{4})$/);
|
|
475
|
+
if (!m) return false;
|
|
476
|
+
const year = 2e3 + Number(m[1]);
|
|
477
|
+
const month = Number(m[2]);
|
|
478
|
+
const date = Number(m[3]);
|
|
479
|
+
const seconds = Number(m[4]);
|
|
480
|
+
const sn = Number(m[5]);
|
|
481
|
+
if (year <= 2020 || seconds >= 24 * 3600 || sn === 0) return false;
|
|
482
|
+
const d = new Date(Date.UTC(year, month - 1, date));
|
|
483
|
+
return d.getUTCFullYear() === year && d.getUTCMonth() === month - 1 && d.getUTCDate() === date;
|
|
484
|
+
}
|
|
467
485
|
//#endregion
|
|
468
486
|
//#region src/request/inc/rule.ts
|
|
469
487
|
const defaultDataField = "data";
|
|
@@ -1253,7 +1271,7 @@ var TokenVerifier = class {
|
|
|
1253
1271
|
//#endregion
|
|
1254
1272
|
//#region src/notify/msgShipOrder.ts
|
|
1255
1273
|
function isShipOrderPayload(data) {
|
|
1256
|
-
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" && ("is_sandbox" in data ? typeof data.is_sandbox === "boolean" : true) && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
|
|
1274
|
+
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" && ("is_sandbox" in data ? typeof data.is_sandbox === "boolean" : true) && ("paid_currency" in data ? typeof data.paid_currency === "string" : true) && ("paid_amount" in data ? typeof data.paid_amount === "number" && Number.isSafeInteger(data.paid_amount) : true) && ("app_store_offer_identifier" in data ? typeof data.app_store_offer_identifier === "string" : true) && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
|
|
1257
1275
|
}
|
|
1258
1276
|
//#endregion
|
|
1259
1277
|
//#region src/notify/msgRefund.ts
|
|
@@ -1710,4 +1728,5 @@ exports.getNotificationHandlerForExpress = getNotificationHandlerForExpress;
|
|
|
1710
1728
|
exports.getNotificationHandlerForKoa = getNotificationHandlerForKoa;
|
|
1711
1729
|
exports.getNotificationMiddlewareForExpress = getNotificationMiddlewareForExpress;
|
|
1712
1730
|
exports.getNotificationMiddlewareForKoa = getNotificationMiddlewareForKoa;
|
|
1731
|
+
exports.mayBeComboId = mayBeComboId;
|
|
1713
1732
|
exports.parseAuthorizationHeader = parseAuthorizationHeader;
|
package/dist/index.d.cts
CHANGED
|
@@ -60,6 +60,12 @@ declare function checkHttpAuthInfo(authString: string, option: SignDataOptionFor
|
|
|
60
60
|
//#region src/utils/index.d.ts
|
|
61
61
|
/** 生成一个 SessionID 以用作用户上下线的上报标记 */
|
|
62
62
|
declare function genSessionID(comboId: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* 检查一个值是否为 Combo ID 的格式。
|
|
65
|
+
*
|
|
66
|
+
* 仅做格式检查,不检查该 ID 是否真实存在。
|
|
67
|
+
*/
|
|
68
|
+
declare function mayBeComboId(id: unknown): id is string;
|
|
63
69
|
//#endregion
|
|
64
70
|
//#region src/request/inc/type.d.ts
|
|
65
71
|
type IBaseRequestBody = URLSearchParams | string;
|
|
@@ -378,6 +384,12 @@ interface OrderMetaData {
|
|
|
378
384
|
role_name?: string;
|
|
379
385
|
/** 游戏角色的等级 */
|
|
380
386
|
role_level?: number;
|
|
387
|
+
/**
|
|
388
|
+
* 是否为 App Store Offer Code 兑换订单。
|
|
389
|
+
*
|
|
390
|
+
* 为 true 时,本单只能通过 App Store Offer Code 兑换;为 false 或未赋值时,只能通过内购购买。
|
|
391
|
+
*/
|
|
392
|
+
redeem_app_store_offer_code?: boolean;
|
|
381
393
|
}
|
|
382
394
|
interface CreateOrderResponse {
|
|
383
395
|
/** 世游服务端创建的,标识订单的唯一 ID。 */
|
|
@@ -398,7 +410,12 @@ interface SendOtpOption {
|
|
|
398
410
|
/** 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供。*/
|
|
399
411
|
meta?: SendOtpMetaData;
|
|
400
412
|
}
|
|
401
|
-
|
|
413
|
+
/**
|
|
414
|
+
* 发送验证码时附带的元数据。
|
|
415
|
+
*
|
|
416
|
+
* 字段定义同 OrderMetaData,但不包含仅对创建订单有意义的 redeem_app_store_offer_code。
|
|
417
|
+
*/
|
|
418
|
+
type SendOtpMetaData = Omit<OrderMetaData, "redeem_app_store_offer_code">;
|
|
402
419
|
interface SendOtpResponse {
|
|
403
420
|
/** 掩码后的手机号,仅当 channel=sms 时有值。*/
|
|
404
421
|
mobile: string;
|
|
@@ -667,6 +684,16 @@ interface ShipOrderNotification {
|
|
|
667
684
|
* 预期此字段仅用于记录日志和数据埋点。无论是否是沙盒订单,游戏侧都应当发货。
|
|
668
685
|
*/
|
|
669
686
|
is_sandbox?: boolean;
|
|
687
|
+
/** 实付币种代码。例如 USD、CNY。可能与订单币种 currency 不同 */
|
|
688
|
+
paid_currency?: string;
|
|
689
|
+
/**
|
|
690
|
+
* 玩家实付金额,单位为分。可能与订单 amount 不同,例如免费兑换的 App Store Offer Code 订单为 0。
|
|
691
|
+
*
|
|
692
|
+
* 预期此字段仅用于对账和数据埋点。无论 paid_amount 是否为 0,游戏侧都应当按订单发货。
|
|
693
|
+
*/
|
|
694
|
+
paid_amount?: number;
|
|
695
|
+
/** 交易实际使用的 App Store Offer 标识(offerIdentifier),只在 App Store Offer Code 兑换订单中出现 */
|
|
696
|
+
app_store_offer_identifier?: string;
|
|
670
697
|
}
|
|
671
698
|
//#endregion
|
|
672
699
|
//#region src/notify/msgRefund.d.ts
|
|
@@ -904,4 +931,4 @@ declare class RedisIdempotencyStore implements IdempotencyKeyStoreHelper {
|
|
|
904
931
|
setXX(key: string, value: string): Promise<void>;
|
|
905
932
|
}
|
|
906
933
|
//#endregion
|
|
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 };
|
|
934
|
+
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, mayBeComboId, parseAuthorizationHeader };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,12 @@ declare function checkHttpAuthInfo(authString: string, option: SignDataOptionFor
|
|
|
60
60
|
//#region src/utils/index.d.ts
|
|
61
61
|
/** 生成一个 SessionID 以用作用户上下线的上报标记 */
|
|
62
62
|
declare function genSessionID(comboId: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* 检查一个值是否为 Combo ID 的格式。
|
|
65
|
+
*
|
|
66
|
+
* 仅做格式检查,不检查该 ID 是否真实存在。
|
|
67
|
+
*/
|
|
68
|
+
declare function mayBeComboId(id: unknown): id is string;
|
|
63
69
|
//#endregion
|
|
64
70
|
//#region src/request/inc/type.d.ts
|
|
65
71
|
type IBaseRequestBody = URLSearchParams | string;
|
|
@@ -378,6 +384,12 @@ interface OrderMetaData {
|
|
|
378
384
|
role_name?: string;
|
|
379
385
|
/** 游戏角色的等级 */
|
|
380
386
|
role_level?: number;
|
|
387
|
+
/**
|
|
388
|
+
* 是否为 App Store Offer Code 兑换订单。
|
|
389
|
+
*
|
|
390
|
+
* 为 true 时,本单只能通过 App Store Offer Code 兑换;为 false 或未赋值时,只能通过内购购买。
|
|
391
|
+
*/
|
|
392
|
+
redeem_app_store_offer_code?: boolean;
|
|
381
393
|
}
|
|
382
394
|
interface CreateOrderResponse {
|
|
383
395
|
/** 世游服务端创建的,标识订单的唯一 ID。 */
|
|
@@ -398,7 +410,12 @@ interface SendOtpOption {
|
|
|
398
410
|
/** 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供。*/
|
|
399
411
|
meta?: SendOtpMetaData;
|
|
400
412
|
}
|
|
401
|
-
|
|
413
|
+
/**
|
|
414
|
+
* 发送验证码时附带的元数据。
|
|
415
|
+
*
|
|
416
|
+
* 字段定义同 OrderMetaData,但不包含仅对创建订单有意义的 redeem_app_store_offer_code。
|
|
417
|
+
*/
|
|
418
|
+
type SendOtpMetaData = Omit<OrderMetaData, "redeem_app_store_offer_code">;
|
|
402
419
|
interface SendOtpResponse {
|
|
403
420
|
/** 掩码后的手机号,仅当 channel=sms 时有值。*/
|
|
404
421
|
mobile: string;
|
|
@@ -667,6 +684,16 @@ interface ShipOrderNotification {
|
|
|
667
684
|
* 预期此字段仅用于记录日志和数据埋点。无论是否是沙盒订单,游戏侧都应当发货。
|
|
668
685
|
*/
|
|
669
686
|
is_sandbox?: boolean;
|
|
687
|
+
/** 实付币种代码。例如 USD、CNY。可能与订单币种 currency 不同 */
|
|
688
|
+
paid_currency?: string;
|
|
689
|
+
/**
|
|
690
|
+
* 玩家实付金额,单位为分。可能与订单 amount 不同,例如免费兑换的 App Store Offer Code 订单为 0。
|
|
691
|
+
*
|
|
692
|
+
* 预期此字段仅用于对账和数据埋点。无论 paid_amount 是否为 0,游戏侧都应当按订单发货。
|
|
693
|
+
*/
|
|
694
|
+
paid_amount?: number;
|
|
695
|
+
/** 交易实际使用的 App Store Offer 标识(offerIdentifier),只在 App Store Offer Code 兑换订单中出现 */
|
|
696
|
+
app_store_offer_identifier?: string;
|
|
670
697
|
}
|
|
671
698
|
//#endregion
|
|
672
699
|
//#region src/notify/msgRefund.d.ts
|
|
@@ -904,4 +931,4 @@ declare class RedisIdempotencyStore implements IdempotencyKeyStoreHelper {
|
|
|
904
931
|
setXX(key: string, value: string): Promise<void>;
|
|
905
932
|
}
|
|
906
933
|
//#endregion
|
|
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 };
|
|
934
|
+
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, mayBeComboId, 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.
|
|
10
|
+
const SDKVersion = "1.12.0";
|
|
11
11
|
/**
|
|
12
12
|
* 世游支持的服务端点列表
|
|
13
13
|
*/
|
|
@@ -387,7 +387,7 @@ async function readBody(req, backup) {
|
|
|
387
387
|
backup || console.error({
|
|
388
388
|
type: "RequestUnReadable",
|
|
389
389
|
url: req.url,
|
|
390
|
-
|
|
390
|
+
method: req.method,
|
|
391
391
|
message: "Cannot read body, stream not readable"
|
|
392
392
|
});
|
|
393
393
|
return backup || "";
|
|
@@ -438,6 +438,24 @@ function genNonceString() {
|
|
|
438
438
|
const r = Math.random() + Math.random();
|
|
439
439
|
return createHash("md5").update(`${ts}${r}`).digest("hex").toLowerCase();
|
|
440
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* 检查一个值是否为 Combo ID 的格式。
|
|
443
|
+
*
|
|
444
|
+
* 仅做格式检查,不检查该 ID 是否真实存在。
|
|
445
|
+
*/
|
|
446
|
+
function mayBeComboId(id) {
|
|
447
|
+
if (typeof id !== "string") return false;
|
|
448
|
+
const m = id.match(/^9?[15](\d{2})(\d{2})(\d{2})(\d{5})(\d{4})$/);
|
|
449
|
+
if (!m) return false;
|
|
450
|
+
const year = 2e3 + Number(m[1]);
|
|
451
|
+
const month = Number(m[2]);
|
|
452
|
+
const date = Number(m[3]);
|
|
453
|
+
const seconds = Number(m[4]);
|
|
454
|
+
const sn = Number(m[5]);
|
|
455
|
+
if (year <= 2020 || seconds >= 24 * 3600 || sn === 0) return false;
|
|
456
|
+
const d = new Date(Date.UTC(year, month - 1, date));
|
|
457
|
+
return d.getUTCFullYear() === year && d.getUTCMonth() === month - 1 && d.getUTCDate() === date;
|
|
458
|
+
}
|
|
441
459
|
//#endregion
|
|
442
460
|
//#region src/request/inc/rule.ts
|
|
443
461
|
const defaultDataField = "data";
|
|
@@ -1227,7 +1245,7 @@ var TokenVerifier = class {
|
|
|
1227
1245
|
//#endregion
|
|
1228
1246
|
//#region src/notify/msgShipOrder.ts
|
|
1229
1247
|
function isShipOrderPayload(data) {
|
|
1230
|
-
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" && ("is_sandbox" in data ? typeof data.is_sandbox === "boolean" : true) && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
|
|
1248
|
+
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" && ("is_sandbox" in data ? typeof data.is_sandbox === "boolean" : true) && ("paid_currency" in data ? typeof data.paid_currency === "string" : true) && ("paid_amount" in data ? typeof data.paid_amount === "number" && Number.isSafeInteger(data.paid_amount) : true) && ("app_store_offer_identifier" in data ? typeof data.app_store_offer_identifier === "string" : true) && Number.isSafeInteger(data.quantity) && Number.isSafeInteger(data.amount) && !!data.order_id && !!data.combo_id;
|
|
1231
1249
|
}
|
|
1232
1250
|
//#endregion
|
|
1233
1251
|
//#region src/notify/msgRefund.ts
|
|
@@ -1662,4 +1680,4 @@ function getGMMiddlewareForKoa(paths, config, handler, storeHelper) {
|
|
|
1662
1680
|
};
|
|
1663
1681
|
}
|
|
1664
1682
|
//#endregion
|
|
1665
|
-
export { ApiClient, Endpoint, GMError, IdP, MemoryIdempotencyStore, NotificationType, Platform, RedisIdempotencyStore, TokenVerifier, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
|
|
1683
|
+
export { ApiClient, Endpoint, GMError, IdP, MemoryIdempotencyStore, NotificationType, Platform, RedisIdempotencyStore, TokenVerifier, calcAuthorizationHeader, checkHttpAuthInfo, genSessionID, getGMCommandHandler, getGMHandlerForExpress, getGMHandlerForKoa, getGMMiddlewareForExpress, getGMMiddlewareForKoa, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, mayBeComboId, parseAuthorizationHeader };
|
package/docs/api-client.md
CHANGED
|
@@ -69,6 +69,12 @@ interface OrderMetaData {
|
|
|
69
69
|
role_name?: string
|
|
70
70
|
/** 游戏角色的等级 */
|
|
71
71
|
role_level?: number
|
|
72
|
+
/**
|
|
73
|
+
* 是否为 App Store Offer Code 兑换订单。
|
|
74
|
+
*
|
|
75
|
+
* 为 true 时,本单只能通过 App Store Offer Code 兑换;为 false 或未赋值时,只能通过内购购买。
|
|
76
|
+
*/
|
|
77
|
+
redeem_app_store_offer_code?: boolean
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
interface CreateOrderResponse {
|
|
@@ -119,7 +125,7 @@ const sendResult = await client.sendOtp({
|
|
|
119
125
|
action: "<Action>",
|
|
120
126
|
/**
|
|
121
127
|
* [可选] 发送方元数据,主要用于数据分析,游戏服务端应当尽量提供
|
|
122
|
-
* 字段定义同 OrderMetaData
|
|
128
|
+
* 字段定义同 OrderMetaData,但不包含仅对创建订单有意义的 redeem_app_store_offer_code
|
|
123
129
|
*/
|
|
124
130
|
meta: { ... },
|
|
125
131
|
})
|
package/docs/notify.md
CHANGED
|
@@ -55,6 +55,15 @@ interface ShipOrderNotification {
|
|
|
55
55
|
* 预期此字段仅用于记录日志和数据埋点。无论是否是沙盒订单,游戏侧都应当发货。
|
|
56
56
|
*/
|
|
57
57
|
is_sandbox?: boolean
|
|
58
|
+
/** 实付币种代码。例如 USD、CNY。可能与订单币种 currency 不同 */
|
|
59
|
+
paid_currency?: string
|
|
60
|
+
/**
|
|
61
|
+
* 玩家实付金额,单位为分。可能与订单 amount 不同,例如免费兑换的 App Store Offer Code 订单为 0。
|
|
62
|
+
* 预期此字段仅用于对账和数据埋点。无论 paid_amount 是否为 0,游戏侧都应当按订单发货。
|
|
63
|
+
*/
|
|
64
|
+
paid_amount?: number
|
|
65
|
+
/** 交易实际使用的 App Store Offer 标识(offerIdentifier),只在 App Store Offer Code 兑换订单中出现 */
|
|
66
|
+
app_store_offer_identifier?: string
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
interface RefundNotification {
|
package/docs/utils.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
> [Combo SDK for Node.js](../README.md) / Utils
|
|
2
|
+
|
|
3
|
+
# Utils
|
|
4
|
+
|
|
5
|
+
## genSessionID
|
|
6
|
+
|
|
7
|
+
生成用于标记用户上下线的 SessionID。
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { genSessionID } from "@seayoo-io/combo-sdk-node"
|
|
11
|
+
|
|
12
|
+
const sessionID = genSessionID(combo_id)
|
|
13
|
+
// 32 位小写十六进制字符串
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## mayBeComboId
|
|
17
|
+
|
|
18
|
+
检查一个值是否为 Combo ID 的格式,仅做格式检查,不检查该 ID 是否真实存在。
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { mayBeComboId } from "@seayoo-io/combo-sdk-node"
|
|
22
|
+
|
|
23
|
+
mayBeComboId("1260418509000005") // true
|
|
24
|
+
mayBeComboId("95231223346130001") // true
|
|
25
|
+
mayBeComboId("1260418509000000") // false
|
|
26
|
+
mayBeComboId(1260418509000005) // false,只接受字符串
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## parseAuthorizationHeader
|
|
30
|
+
|
|
31
|
+
解析 Authorization 请求头,返回 `{ Game, Timestamp, Signature }`,格式不正确时返回 `null`。
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { parseAuthorizationHeader } from "@seayoo-io/combo-sdk-node"
|
|
35
|
+
|
|
36
|
+
const info = parseAuthorizationHeader(authString)
|
|
37
|
+
if (!info) {
|
|
38
|
+
// 请求头格式不正确
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## calcAuthorizationHeader
|
|
43
|
+
|
|
44
|
+
计算 HTTP 请求的 Authorization 请求头。
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { calcAuthorizationHeader } from "@seayoo-io/combo-sdk-node"
|
|
48
|
+
|
|
49
|
+
const authString = calcAuthorizationHeader({
|
|
50
|
+
game: "<GameId>",
|
|
51
|
+
secret: "<SecretKey>",
|
|
52
|
+
endpoint: "https://api.seayoo.com",
|
|
53
|
+
method: "POST",
|
|
54
|
+
url: "/path/to/api",
|
|
55
|
+
data: { combo_id: "<ComboID>" },
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## checkHttpAuthInfo
|
|
60
|
+
|
|
61
|
+
校验 HTTP 请求的签名信息是否正确,签名不合法或时间戳超出允许范围时返回 `false`。
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { checkHttpAuthInfo } from "@seayoo-io/combo-sdk-node"
|
|
65
|
+
|
|
66
|
+
const ok = checkHttpAuthInfo(authString, {
|
|
67
|
+
// 省略 game 时不校验签发方
|
|
68
|
+
secret: "<SecretKey>",
|
|
69
|
+
endpoint: "https://api.seayoo.com",
|
|
70
|
+
method: "POST",
|
|
71
|
+
url: "/path/to/api",
|
|
72
|
+
data: { combo_id: "<ComboID>" },
|
|
73
|
+
})
|
|
74
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-io/combo-sdk-node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Combo SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
"ioredis": "^5.4.1",
|
|
51
51
|
"lint-staged": "^17.3.0",
|
|
52
52
|
"msw": "^2.15.0",
|
|
53
|
-
"oxfmt": "^0.
|
|
53
|
+
"oxfmt": "^0.80.0",
|
|
54
54
|
"oxlint": "^1.77.0",
|
|
55
55
|
"publint": "^0.3.23",
|
|
56
|
-
"rimraf": "^6.1.
|
|
56
|
+
"rimraf": "^6.1.4",
|
|
57
57
|
"simple-git-hooks": "^2.13.1",
|
|
58
58
|
"tsdown": "0.21.0",
|
|
59
59
|
"typescript": "6.0.3",
|
|
60
|
-
"vite": "^8.
|
|
61
|
-
"vitest": "^4.1.
|
|
60
|
+
"vite": "^8.3.8",
|
|
61
|
+
"vitest": "^4.1.12"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"jsonwebtoken": "^9.0.2"
|