@seayoo-io/combo-sdk-node 0.1.10 → 0.1.12
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 +39 -4
- package/dist/const.d.ts +1 -1
- package/dist/index.cjs +10 -20
- package/dist/index.js +10 -20
- package/dist/notify/msgRefund.d.ts +20 -0
- package/dist/notify/types.d.ts +11 -1
- package/dist/request/inc/retry.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,13 +52,21 @@ const client = new ApiClient({
|
|
|
52
52
|
### 创建订单 CreateOrder
|
|
53
53
|
|
|
54
54
|
```js
|
|
55
|
+
// 导入枚举变量
|
|
56
|
+
import { Platform } from "@seayoo-io/combo-sdk-node"
|
|
57
|
+
|
|
55
58
|
// 创建订单
|
|
56
59
|
const createOrderResult = await client.createOrder({
|
|
57
60
|
/** 用于标识创建订单请求的唯一 ID */
|
|
58
61
|
reference_id: "<游戏订单ID>",
|
|
59
62
|
/** 发起购买的用户的唯一标识 */
|
|
60
63
|
combo_id: "<ComboID>",
|
|
61
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* 要购买的商品 ID
|
|
66
|
+
* 这里指的是在世游发行平台管理的商品 ID,其中重要的两个约定是:
|
|
67
|
+
* - 商品价格是正整数
|
|
68
|
+
* - 商品价格单位为 分 或 美分,即商品币种所支持的最小流通单位
|
|
69
|
+
*/
|
|
62
70
|
product_id: "<ProductID>",
|
|
63
71
|
/** 平台,支持类型见源码类型定义 Platform */
|
|
64
72
|
platform: Platform.iOS,
|
|
@@ -67,7 +75,7 @@ const createOrderResult = await client.createOrder({
|
|
|
67
75
|
* 这个地址对应的服务端应该通过 Notify 模块实现路由处理
|
|
68
76
|
*/
|
|
69
77
|
notify_url: "https://<YourSite>/<YourPath>"
|
|
70
|
-
/** 要购买的商品的数量,最小为 1 */
|
|
78
|
+
/** 要购买的商品的数量,最小为 1,必须为正整数 */
|
|
71
79
|
quantity: 1,
|
|
72
80
|
/** [可选]订单上下文,在发货通知中透传回游戏 */
|
|
73
81
|
context: "",
|
|
@@ -126,7 +134,7 @@ await client.leaveGame("<ComboID>", "<SessionID>");
|
|
|
126
134
|
import { genSessionID } from "@seayoo-io/combo-sdk-node"
|
|
127
135
|
|
|
128
136
|
// genSessionID 接受唯一参数 comboId 作为输入,返回一个 32 位固定长度的不重复字符串
|
|
129
|
-
const userSessionID = genSessionID("
|
|
137
|
+
const userSessionID = genSessionID("<ComboID>")
|
|
130
138
|
|
|
131
139
|
```
|
|
132
140
|
|
|
@@ -141,11 +149,38 @@ import { NotificationType, Endpoint } from "@seayoo-io/combo-sdk-node"
|
|
|
141
149
|
function notificationHandler(type, payload) {
|
|
142
150
|
switch(type) {
|
|
143
151
|
case NotificationType.ShipOrder:
|
|
144
|
-
// Do your work with payload
|
|
152
|
+
// Do your work with payload:定义见 ShipOrderNotification
|
|
153
|
+
break;
|
|
154
|
+
case NotificationType.Refund:
|
|
155
|
+
// Do your work with payload:定义见 RefundNotification
|
|
145
156
|
break;
|
|
146
157
|
}
|
|
147
158
|
}
|
|
148
159
|
|
|
160
|
+
/** ShipOrderNotification 是订单发货通知的数据结构,包含了订单的详细信息 */
|
|
161
|
+
interface ShipOrderNotification {
|
|
162
|
+
/** 世游服务端创建的,标识订单的唯一 ID */
|
|
163
|
+
order_id: string
|
|
164
|
+
/** 游戏侧用于标识创建订单请求的唯一 ID */
|
|
165
|
+
reference_id: string
|
|
166
|
+
/** 发起购买的用户的唯一标识 */
|
|
167
|
+
combo_id: string
|
|
168
|
+
/** 购买的商品 ID,指的是在世游发行平台管理的商品 ID */
|
|
169
|
+
product_id: string
|
|
170
|
+
/** 购买的商品的数量 */
|
|
171
|
+
quantity: number
|
|
172
|
+
/** 订单币种代码。例如 USD CNY */
|
|
173
|
+
currency: string
|
|
174
|
+
/** 订单金额,单位为分,如果币种为美元,则单位为美分。 */
|
|
175
|
+
amount: number
|
|
176
|
+
/** 游戏侧创建订单时提供的订单上下文,透传回游戏 */
|
|
177
|
+
context?: string
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface RefundNotification {
|
|
181
|
+
// 结构同 ShipOrderNotification
|
|
182
|
+
}
|
|
183
|
+
|
|
149
184
|
// 1.2 创建配置,类型定义参见源码 SDKBaseConfig
|
|
150
185
|
const config = {
|
|
151
186
|
game: "<GameId>",
|
package/dist/const.d.ts
CHANGED
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 = "0.1.
|
|
15
|
+
const SDKVersion = "0.1.12";
|
|
16
16
|
/**
|
|
17
17
|
* 世游支持的服务端点列表
|
|
18
18
|
*/
|
|
@@ -114,7 +114,7 @@ function getFullURL(url, baseURL = "") {
|
|
|
114
114
|
if (!baseURL || isFullURL(url, true)) {
|
|
115
115
|
return fillUrl(url);
|
|
116
116
|
}
|
|
117
|
-
return (fillUrl(baseURL) + "/" + url).replace(
|
|
117
|
+
return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
120
|
* 给 url 添加完整域名和协议,仅可在浏览器环境使用
|
|
@@ -972,18 +972,6 @@ class ApiClient {
|
|
|
972
972
|
* 创建订单
|
|
973
973
|
*/
|
|
974
974
|
async createOrder(option) {
|
|
975
|
-
if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
|
|
976
|
-
throw new Error("createOrder: 必要参数缺失");
|
|
977
|
-
}
|
|
978
|
-
// 检查通知回调地址
|
|
979
|
-
if (!isFullURL(option.notify_url)) {
|
|
980
|
-
throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
|
|
981
|
-
}
|
|
982
|
-
// 检查购买数量
|
|
983
|
-
const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
|
|
984
|
-
if (quantity !== option.quantity) {
|
|
985
|
-
throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
|
|
986
|
-
}
|
|
987
975
|
const {
|
|
988
976
|
ok,
|
|
989
977
|
data,
|
|
@@ -1013,9 +1001,6 @@ class ApiClient {
|
|
|
1013
1001
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1014
1002
|
*/
|
|
1015
1003
|
async enterGame(comboId, sessionId) {
|
|
1016
|
-
if (!comboId || !sessionId) {
|
|
1017
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1018
|
-
}
|
|
1019
1004
|
const {
|
|
1020
1005
|
ok,
|
|
1021
1006
|
status,
|
|
@@ -1046,9 +1031,6 @@ class ApiClient {
|
|
|
1046
1031
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1047
1032
|
*/
|
|
1048
1033
|
async leaveGame(comboId, sessionId) {
|
|
1049
|
-
if (!comboId || !sessionId) {
|
|
1050
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1051
|
-
}
|
|
1052
1034
|
const {
|
|
1053
1035
|
ok,
|
|
1054
1036
|
status,
|
|
@@ -1162,6 +1144,10 @@ function isShipOrderPayload(data) {
|
|
|
1162
1144
|
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;
|
|
1163
1145
|
}
|
|
1164
1146
|
|
|
1147
|
+
function isRefundPayload(data) {
|
|
1148
|
+
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;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1165
1151
|
/**
|
|
1166
1152
|
* 消息处理分发配置
|
|
1167
1153
|
*/
|
|
@@ -1169,6 +1155,10 @@ const messageDataGuards = {
|
|
|
1169
1155
|
["ship_order" /* NotificationType.ShipOrder */]: {
|
|
1170
1156
|
guard: isShipOrderPayload,
|
|
1171
1157
|
message: "ShipOrder Data Format Error"
|
|
1158
|
+
},
|
|
1159
|
+
["refund" /* NotificationType.Refund */]: {
|
|
1160
|
+
guard: isRefundPayload,
|
|
1161
|
+
message: "Refund Data Format Error"
|
|
1172
1162
|
}
|
|
1173
1163
|
};
|
|
1174
1164
|
|
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 = "0.1.
|
|
10
|
+
const SDKVersion = "0.1.12";
|
|
11
11
|
/**
|
|
12
12
|
* 世游支持的服务端点列表
|
|
13
13
|
*/
|
|
@@ -109,7 +109,7 @@ function getFullURL(url, baseURL = "") {
|
|
|
109
109
|
if (!baseURL || isFullURL(url, true)) {
|
|
110
110
|
return fillUrl(url);
|
|
111
111
|
}
|
|
112
|
-
return (fillUrl(baseURL) + "/" + url).replace(
|
|
112
|
+
return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* 给 url 添加完整域名和协议,仅可在浏览器环境使用
|
|
@@ -967,18 +967,6 @@ class ApiClient {
|
|
|
967
967
|
* 创建订单
|
|
968
968
|
*/
|
|
969
969
|
async createOrder(option) {
|
|
970
|
-
if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
|
|
971
|
-
throw new Error("createOrder: 必要参数缺失");
|
|
972
|
-
}
|
|
973
|
-
// 检查通知回调地址
|
|
974
|
-
if (!isFullURL(option.notify_url)) {
|
|
975
|
-
throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
|
|
976
|
-
}
|
|
977
|
-
// 检查购买数量
|
|
978
|
-
const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
|
|
979
|
-
if (quantity !== option.quantity) {
|
|
980
|
-
throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
|
|
981
|
-
}
|
|
982
970
|
const {
|
|
983
971
|
ok,
|
|
984
972
|
data,
|
|
@@ -1008,9 +996,6 @@ class ApiClient {
|
|
|
1008
996
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1009
997
|
*/
|
|
1010
998
|
async enterGame(comboId, sessionId) {
|
|
1011
|
-
if (!comboId || !sessionId) {
|
|
1012
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1013
|
-
}
|
|
1014
999
|
const {
|
|
1015
1000
|
ok,
|
|
1016
1001
|
status,
|
|
@@ -1041,9 +1026,6 @@ class ApiClient {
|
|
|
1041
1026
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1042
1027
|
*/
|
|
1043
1028
|
async leaveGame(comboId, sessionId) {
|
|
1044
|
-
if (!comboId || !sessionId) {
|
|
1045
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1046
|
-
}
|
|
1047
1029
|
const {
|
|
1048
1030
|
ok,
|
|
1049
1031
|
status,
|
|
@@ -1157,6 +1139,10 @@ function isShipOrderPayload(data) {
|
|
|
1157
1139
|
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;
|
|
1158
1140
|
}
|
|
1159
1141
|
|
|
1142
|
+
function isRefundPayload(data) {
|
|
1143
|
+
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;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1160
1146
|
/**
|
|
1161
1147
|
* 消息处理分发配置
|
|
1162
1148
|
*/
|
|
@@ -1164,6 +1150,10 @@ const messageDataGuards = {
|
|
|
1164
1150
|
["ship_order" /* NotificationType.ShipOrder */]: {
|
|
1165
1151
|
guard: isShipOrderPayload,
|
|
1166
1152
|
message: "ShipOrder Data Format Error"
|
|
1153
|
+
},
|
|
1154
|
+
["refund" /* NotificationType.Refund */]: {
|
|
1155
|
+
guard: isRefundPayload,
|
|
1156
|
+
message: "Refund Data Format Error"
|
|
1167
1157
|
}
|
|
1168
1158
|
};
|
|
1169
1159
|
|
|
@@ -0,0 +1,20 @@
|
|
|
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;
|
package/dist/notify/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isShipOrderPayload, type ShipOrderNotification } from "./msgShipOrder";
|
|
2
|
+
import { isRefundPayload, type RefundNotification } from "./msgRefund";
|
|
2
3
|
import type { MaybePromise } from "../utils";
|
|
3
4
|
/**
|
|
4
5
|
* 通知类型枚举
|
|
@@ -12,13 +13,18 @@ export declare const enum NotificationType {
|
|
|
12
13
|
* - 如果游戏内发货成功,则应当返回 void 或 Promise<void>
|
|
13
14
|
* - 如果游戏内发货出现错误,则应当 throw Error。世游服务端会在稍后重试推送发货通知。
|
|
14
15
|
*/
|
|
15
|
-
ShipOrder = "ship_order"
|
|
16
|
+
ShipOrder = "ship_order",
|
|
17
|
+
/**
|
|
18
|
+
* 世游服务端会在订单状态发生退款时,向游戏侧推送退款通知。
|
|
19
|
+
*/
|
|
20
|
+
Refund = "refund"
|
|
16
21
|
}
|
|
17
22
|
/**
|
|
18
23
|
* 通知类型对应的 payload
|
|
19
24
|
*/
|
|
20
25
|
export interface ENotificationPayload {
|
|
21
26
|
[NotificationType.ShipOrder]: ShipOrderNotification;
|
|
27
|
+
[NotificationType.Refund]: RefundNotification;
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* 自定义处理函数
|
|
@@ -36,4 +42,8 @@ export declare const messageDataGuards: {
|
|
|
36
42
|
readonly guard: typeof isShipOrderPayload;
|
|
37
43
|
readonly message: "ShipOrder Data Format Error";
|
|
38
44
|
};
|
|
45
|
+
readonly refund: {
|
|
46
|
+
readonly guard: typeof isRefundPayload;
|
|
47
|
+
readonly message: "Refund Data Format Error";
|
|
48
|
+
};
|
|
39
49
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { NetRequestCoreFn, IRequestOptions, IRequestBaseResponse } from "./type";
|
|
1
|
+
import type { NetRequestCoreFn, IRequestOptions, IRequestBaseResponse } from "./type";
|
|
2
2
|
import type { RequestGlobalConfig } from "./config";
|
|
3
3
|
export declare function retryRequest(agent: NetRequestCoreFn, url: string, config: RequestGlobalConfig, options?: IRequestOptions, _try?: number): Promise<IRequestBaseResponse>;
|