@seayoo-io/combo-sdk-node 1.7.0 → 1.8.1
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 +44 -56
- package/dist/index.cjs +1448 -1609
- package/dist/index.d.cts +848 -0
- package/dist/index.d.ts +848 -15
- package/dist/index.js +1418 -1605
- package/package.json +40 -24
- package/dist/api/index.d.ts +0 -61
- package/dist/api/types.d.ts +0 -97
- package/dist/api/ua.d.ts +0 -1
- package/dist/const.d.ts +0 -143
- package/dist/gm/index.d.ts +0 -51
- package/dist/gm/types.d.ts +0 -58
- package/dist/gm/utils.d.ts +0 -31
- package/dist/notify/index.d.ts +0 -49
- package/dist/notify/msgRefund.d.ts +0 -20
- package/dist/notify/msgShipOrder.d.ts +0 -26
- package/dist/notify/types.d.ts +0 -49
- package/dist/request/inc/cache.d.ts +0 -10
- package/dist/request/inc/config.d.ts +0 -12
- package/dist/request/inc/guard.d.ts +0 -3
- package/dist/request/inc/main.d.ts +0 -60
- package/dist/request/inc/option.d.ts +0 -10
- package/dist/request/inc/request.d.ts +0 -7
- package/dist/request/inc/response.d.ts +0 -3
- package/dist/request/inc/retry.d.ts +0 -3
- package/dist/request/inc/rule.d.ts +0 -12
- package/dist/request/inc/type.d.ts +0 -181
- package/dist/request/index.d.ts +0 -4
- package/dist/utils/base.d.ts +0 -46
- package/dist/utils/config.d.ts +0 -17
- package/dist/utils/gcm.d.ts +0 -9
- package/dist/utils/http.d.ts +0 -6
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/signer.d.ts +0 -34
- package/dist/utils/types.d.ts +0 -18
- package/dist/verify/ads.d.ts +0 -21
- package/dist/verify/id.d.ts +0 -78
- package/dist/verify/index.d.ts +0 -23
- package/vitest.config.ts +0 -10
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
v1 新增 gm 模块的 [IdempotencyKey](https://docs.seayoo.com/combo/server/gm/#idempotency),主要改动包括:
|
|
15
15
|
|
|
16
16
|
1. 修改了 commandHandler 的参数,插入 idempotencyKey 参数;当此参数为非空字符串时需要处理幂等性;
|
|
17
|
-
2. 新增预设错误
|
|
17
|
+
2. 新增预设错误 IdempotencyConflict / IdempotencyMismatch
|
|
18
18
|
3. gm 服务版本号升级到 2.0
|
|
19
19
|
|
|
20
20
|
## 安装
|
|
@@ -32,7 +32,7 @@ pnpm add @seayoo-io/combo-sdk-node
|
|
|
32
32
|
请按照工程实际情况选择导入方式,后续示例采用 ES 方式导入。
|
|
33
33
|
|
|
34
34
|
```js
|
|
35
|
-
// ES
|
|
35
|
+
// ES
|
|
36
36
|
import { ApiClient } from "@seayoo-io/combo-sdk-node"
|
|
37
37
|
|
|
38
38
|
// CommonJS
|
|
@@ -47,14 +47,14 @@ const { ApiClient } = require("@seayoo-io/combo-sdk-node")
|
|
|
47
47
|
import { ApiClient, Endpoint } from "@seayoo-io/combo-sdk-node"
|
|
48
48
|
|
|
49
49
|
const client = new ApiClient({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
game: "<GameId>",
|
|
51
|
+
secret: "<SecretKey>",
|
|
52
|
+
endpoint: Endpoint.China,
|
|
53
|
+
// 以下参数可选
|
|
54
|
+
maxRetry: 1, // 失败后自动重试次数,默认 1
|
|
55
|
+
retryInterval: 1000, // 重试间隔,默认是 1000,单位 ms,可以传递函数动态设置间隔
|
|
56
|
+
logger: function (log) {}, // 请求日志函数,log 类型参见源码类型定义
|
|
57
|
+
timeout: 5000, // 超时等待时长,单位 ms,默认 5000
|
|
58
58
|
})
|
|
59
59
|
```
|
|
60
60
|
|
|
@@ -78,7 +78,7 @@ const createOrderResult = await client.createOrder({
|
|
|
78
78
|
*/
|
|
79
79
|
product_id: "<ProductID>",
|
|
80
80
|
/** 平台,支持类型见源码类型定义 Platform */
|
|
81
|
-
platform: Platform.iOS,
|
|
81
|
+
platform: Platform.iOS,
|
|
82
82
|
/**
|
|
83
83
|
* 游戏侧接收发货通知的服务端地址
|
|
84
84
|
* 这个地址对应的服务端应该通过 Notify 模块实现路由处理
|
|
@@ -126,11 +126,10 @@ interface CreateOrderResponse {
|
|
|
126
126
|
|
|
127
127
|
```js
|
|
128
128
|
// 进入游戏
|
|
129
|
-
await client.enterGame("<ComboID>", "<SessionID>")
|
|
129
|
+
await client.enterGame("<ComboID>", "<SessionID>")
|
|
130
130
|
|
|
131
131
|
// 离开游戏
|
|
132
|
-
await client.leaveGame("<ComboID>", "<SessionID>")
|
|
133
|
-
|
|
132
|
+
await client.leaveGame("<ComboID>", "<SessionID>")
|
|
134
133
|
```
|
|
135
134
|
|
|
136
135
|
> 注意,SessionID 不可重复使用,可以使用 SDK 提供的工具函数生成 SessionID
|
|
@@ -140,7 +139,6 @@ import { genSessionID } from "@seayoo-io/combo-sdk-node"
|
|
|
140
139
|
|
|
141
140
|
// genSessionID 接受唯一参数 comboId 作为输入,返回一个 32 位固定长度的不重复字符串
|
|
142
141
|
const userSessionID = genSessionID("<ComboID>")
|
|
143
|
-
|
|
144
142
|
```
|
|
145
143
|
|
|
146
144
|
### 发送/验证短信验证码 OTP
|
|
@@ -277,7 +275,7 @@ interface ShipOrderNotification {
|
|
|
277
275
|
*/
|
|
278
276
|
is_sandbox?: boolean
|
|
279
277
|
}
|
|
280
|
-
|
|
278
|
+
|
|
281
279
|
interface RefundNotification {
|
|
282
280
|
// 结构同 ShipOrderNotification
|
|
283
281
|
}
|
|
@@ -296,10 +294,10 @@ const config = {
|
|
|
296
294
|
// 使用 http 模块的处理函数
|
|
297
295
|
import { getNotificationHandler } from "@seayoo-io/combo-sdk-node"
|
|
298
296
|
const notifyHandler = getNotificationHandler(config, notificationHandler)
|
|
299
|
-
http.createServer(async function(req, res){
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
http.createServer(async function (req, res) {
|
|
298
|
+
if (req.path === "<YourNotifyUrl>" && req.method === "POST") {
|
|
299
|
+
await notifyHandler(req, res)
|
|
300
|
+
}
|
|
303
301
|
})
|
|
304
302
|
|
|
305
303
|
// 或,使用 Express 处理函数
|
|
@@ -327,15 +325,15 @@ app.post("/path/to/your/notify/url", koaHandler)
|
|
|
327
325
|
|
|
328
326
|
```js
|
|
329
327
|
// 插件需要先于 bodyParse 类似的插件执行,以确保可以获取原始请求的内容
|
|
330
|
-
app.use(function(req, res, next){
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
328
|
+
app.use(function (req, res, next) {
|
|
329
|
+
// 在其他插件处理之前,检查是否为通知请求的 url,方法是否为 POST
|
|
330
|
+
if (req.method === "POST" && req.path === "/path/to/your/notify/url") {
|
|
331
|
+
// 如果是,则交由插件处理后续响应
|
|
332
|
+
notifyMiddleware(req, res)
|
|
333
|
+
return
|
|
334
|
+
}
|
|
335
|
+
// 否则其他一切正常
|
|
336
|
+
next()
|
|
339
337
|
})
|
|
340
338
|
```
|
|
341
339
|
|
|
@@ -344,21 +342,13 @@ SDK 提供了两个插件来处理:
|
|
|
344
342
|
```js
|
|
345
343
|
// express 插件
|
|
346
344
|
import { getNotificationMiddlewareForExpress } from "@seayoo-io/combo-sdk-node"
|
|
347
|
-
const notifyMiddleware = getNotificationMiddlewareForExpress(
|
|
348
|
-
|
|
349
|
-
config,
|
|
350
|
-
notificationHandler
|
|
351
|
-
);
|
|
352
|
-
app.use(notifyMiddleware);
|
|
345
|
+
const notifyMiddleware = getNotificationMiddlewareForExpress("/path/to/your/notify/url", config, notificationHandler)
|
|
346
|
+
app.use(notifyMiddleware)
|
|
353
347
|
|
|
354
348
|
// koa 插件
|
|
355
349
|
import { getNotificationMiddlewareForKoa } from "@seayoo-io/combo-sdk-node"
|
|
356
|
-
const notifyMiddleware = getNotificationMiddlewareForKoa(
|
|
357
|
-
|
|
358
|
-
config,
|
|
359
|
-
notificationHandler
|
|
360
|
-
);
|
|
361
|
-
app.use(notifyMiddleware);
|
|
350
|
+
const notifyMiddleware = getNotificationMiddlewareForKoa("/path/to/your/notify/url", config, notificationHandler)
|
|
351
|
+
app.use(notifyMiddleware)
|
|
362
352
|
```
|
|
363
353
|
|
|
364
354
|
## Verify
|
|
@@ -369,9 +359,9 @@ app.use(notifyMiddleware);
|
|
|
369
359
|
import { TokenVerifier, Endpoint } from "@seayoo-io/combo-sdk-node"
|
|
370
360
|
|
|
371
361
|
const verifier = new TokenVerifier({
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
362
|
+
game: "<GameId>",
|
|
363
|
+
secret: "<SecretKey>",
|
|
364
|
+
endpoint: Endpoint.China,
|
|
375
365
|
})
|
|
376
366
|
```
|
|
377
367
|
|
|
@@ -385,7 +375,7 @@ const identityPayload = verifier.verifyIdentityToken(token)
|
|
|
385
375
|
if(identityPayload instanceof Error) {
|
|
386
376
|
console.error(result.message)
|
|
387
377
|
} else {
|
|
388
|
-
// WebGL 平台,包括微信、抖音等小游戏,以及 HTML5 网页游戏
|
|
378
|
+
// WebGL 平台,包括微信、抖音等小游戏,以及 HTML5 网页游戏
|
|
389
379
|
if(identityPayload.idp === IdP.WebGL) {
|
|
390
380
|
// do something
|
|
391
381
|
}
|
|
@@ -580,7 +570,7 @@ interface IdempotencyKeyStoreHelper {
|
|
|
580
570
|
*/
|
|
581
571
|
setXX: (key: string, value: string) => Promise<void>
|
|
582
572
|
}
|
|
583
|
-
|
|
573
|
+
|
|
584
574
|
// SDK 内置实现了两个工具类
|
|
585
575
|
import { MemoryIdempotencyStore, RedisIdempotencyStore } from "@seayoo-io/combo-sdk-node"
|
|
586
576
|
|
|
@@ -609,10 +599,10 @@ import { getGMCommandHandler } from "@seayoo-io/combo-sdk-node"
|
|
|
609
599
|
// storeHelper 类型为 IdempotencyKeyStoreHelper
|
|
610
600
|
// 可不传递,如果不提供则不会启用内置的 idempotencyKey 处理逻辑,下同
|
|
611
601
|
const handler = getGMCommandHandler(config, gmCommandHandler, storeHelper)
|
|
612
|
-
http.createServer(async function(req, res){
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
602
|
+
http.createServer(async function (req, res) {
|
|
603
|
+
if (req.path === "<YourNotifyUrl>" && req.method === "POST") {
|
|
604
|
+
await handler(req, res)
|
|
605
|
+
}
|
|
616
606
|
})
|
|
617
607
|
|
|
618
608
|
// 方式 2. 使用 express / koa 的 handler
|
|
@@ -626,12 +616,10 @@ app.post("/path/to/your/gm/url", koaHandler)
|
|
|
626
616
|
|
|
627
617
|
// 方式 3. 使用 express / koa 的中间件,推荐
|
|
628
618
|
import { getGMMiddlewareForExpress } from "@seayoo-io/combo-sdk-node"
|
|
629
|
-
const gmMiddleware = getGMMiddlewareForExpress("/path/to/your/gm/url", config, gmCommandHandler, storeHelper)
|
|
630
|
-
app.use(gmMiddleware)
|
|
619
|
+
const gmMiddleware = getGMMiddlewareForExpress("/path/to/your/gm/url", config, gmCommandHandler, storeHelper)
|
|
620
|
+
app.use(gmMiddleware)
|
|
631
621
|
|
|
632
622
|
import { getGMMiddlewareForKoa } from "@seayoo-io/combo-sdk-node"
|
|
633
|
-
const gmMiddleware = getGMMiddlewareForKoa("/path/to/your/gm/url", config, gmCommandHandler, storeHelper)
|
|
634
|
-
app.use(gmMiddleware)
|
|
635
|
-
|
|
623
|
+
const gmMiddleware = getGMMiddlewareForKoa("/path/to/your/gm/url", config, gmCommandHandler, storeHelper)
|
|
624
|
+
app.use(gmMiddleware)
|
|
636
625
|
```
|
|
637
|
-
|