@seayoo-io/combo-sdk-node 0.1.11 → 0.2.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 CHANGED
@@ -151,6 +151,9 @@ function notificationHandler(type, payload) {
151
151
  case NotificationType.ShipOrder:
152
152
  // Do your work with payload:定义见 ShipOrderNotification
153
153
  break;
154
+ case NotificationType.Refund:
155
+ // Do your work with payload:定义见 RefundNotification
156
+ break;
154
157
  }
155
158
  }
156
159
 
@@ -173,6 +176,10 @@ interface ShipOrderNotification {
173
176
  /** 游戏侧创建订单时提供的订单上下文,透传回游戏 */
174
177
  context?: string
175
178
  }
179
+
180
+ interface RefundNotification {
181
+ // 结构同 ShipOrderNotification
182
+ }
176
183
 
177
184
  // 1.2 创建配置,类型定义参见源码 SDKBaseConfig
178
185
  const config = {
@@ -273,21 +280,59 @@ const verifier = new TokenVerifier({
273
280
  import { IdP } from "@seayoo-io/combo-sdk-node"
274
281
  // verifyIdentityToken 对 IdentityToken 进行验证
275
282
  // 返回 IdentityPayload 数据,如果解析出错则返回 Error 对象
276
- const result = verifier.verifyIdentityToken(token)
277
- if(result instanceof Error) {
283
+ const identityPayload = verifier.verifyIdentityToken(token)
284
+ if(identityPayload instanceof Error) {
278
285
  console.error(result.message)
279
286
  } else {
280
- // got Id info: { combo_id, idp, external_id, external_name, weixin_unionid }
281
287
  // 微信登录判断
282
- if(result.idp === IdP.Weixin) {
288
+ if(identityPayload.idp === IdP.Weixin) {
283
289
  // 微信登录会提供 weixin_unionid
284
290
  // do something
285
291
  }
286
292
  // 游客登录判断
287
- if(result.idp === IdP.Device) {
293
+ if(identityPayload.idp === IdP.Device) {
288
294
  // do something
289
295
  }
290
- // 更多 IdP 枚举可以查看源码定义
296
+ // 更多 IdP 枚举可以查看源码定义 src/const.ts
297
+ }
298
+
299
+ // IdentityPayload 数据定义
300
+ interface IdentityPayload {
301
+ /** combo_id 是世游分配的聚合用户 ID 游戏侧应当使用 combo_id 作为用户的唯一标识。*/
302
+ combo_id: string
303
+ /** IdP (Identity Provider) 是用户身份的提供者 */
304
+ idp: IdP
305
+ /**
306
+ * external_id 是用户在外部 IdP 中的唯一标识
307
+ *
308
+ * 例如:
309
+ * - 如果用户使用世游通行证登录,那么 external_id 就是用户的世游通行证 ID。
310
+ * - 如果用户使用 Google Account 登录,那么 external_id 就是用户在 Google 中的账号标识。
311
+ * - 如果用户使用微信登录,那么 external_id 就是用户在微信中的 OpenId。
312
+ *
313
+ * 注意:
314
+ * 游戏侧不应当使用 external_id 作为用户标识,但可以将 external_id 用于特定的业务逻辑。
315
+ */
316
+ external_id: string
317
+ /** external_name 是用户在外部 IdP 中的名称,通常是用户的昵称 */
318
+ external_name: string
319
+ /**
320
+ * weixin_unionid 是用户在微信中的 UnionId
321
+ * 游戏侧可以使用 weixin_unionid 实现多端互通
322
+ * 注意:weixin_unionid 只在 IdP 为 weixin 时才会有值。
323
+ */
324
+ weixin_unionid: string
325
+ /**
326
+ * distro 是游戏客户端的发行版本标识。
327
+ * 游戏侧可将 distro 用于服务端数据埋点,以及特定的业务逻辑判断。
328
+ */
329
+ distro: string
330
+ /**
331
+ * variant 是游戏客户端的分包标识。
332
+ * 游戏侧可将 variant 用于服务端数据埋点,以及特定的业务逻辑判断。
333
+ * 注意:Variant 只在客户端是分包时才会有值。当客户端不是分包的情况下,variant 为空字符串。
334
+ */
335
+ variant: string
291
336
  }
292
337
  ```
293
338
 
@@ -302,4 +347,14 @@ if(result instanceof Error) {
302
347
  } else {
303
348
  // got ad info: { combo_id, placement_id, impression_id }
304
349
  }
350
+
351
+ // AdPayload 定义
352
+ interface AdPayload {
353
+ /** combo_id 是世游分配的聚合用户 ID,游戏侧应当使用 combo_id 作为用户的唯一标识。*/
354
+ combo_id: string
355
+ /** placement_id 是广告位 ID,游戏侧用它确定发放什么样的广告激励。*/
356
+ placement_id: string
357
+ /** impression_id 是世游服务端创建的,标识单次广告播放的唯一 ID。*/
358
+ impression_id: string
359
+ }
305
360
  ```
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 = "0.1.11";
4
+ export declare const SDKVersion = "0.2.1";
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 = "0.1.11";
15
+ const SDKVersion = "0.2.1";
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(/(?<!:)\/{2,}/g, "/");
117
+ return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
118
118
  }
119
119
  /**
120
120
  * 给 url 添加完整域名和协议,仅可在浏览器环境使用
@@ -1106,7 +1106,9 @@ class TokenVerifier {
1106
1106
  idp: payload.idp,
1107
1107
  external_id: payload.external_id,
1108
1108
  external_name: payload.external_name,
1109
- weixin_unionid: payload.weixin_unionid || ""
1109
+ weixin_unionid: payload.weixin_unionid || "",
1110
+ distro: payload.distro || "",
1111
+ variant: payload.variant || ""
1110
1112
  };
1111
1113
  } catch (error) {
1112
1114
  return new Error(`IdentityToken 验证失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -1144,6 +1146,10 @@ function isShipOrderPayload(data) {
1144
1146
  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;
1145
1147
  }
1146
1148
 
1149
+ function isRefundPayload(data) {
1150
+ 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;
1151
+ }
1152
+
1147
1153
  /**
1148
1154
  * 消息处理分发配置
1149
1155
  */
@@ -1151,6 +1157,10 @@ const messageDataGuards = {
1151
1157
  ["ship_order" /* NotificationType.ShipOrder */]: {
1152
1158
  guard: isShipOrderPayload,
1153
1159
  message: "ShipOrder Data Format Error"
1160
+ },
1161
+ ["refund" /* NotificationType.Refund */]: {
1162
+ guard: isRefundPayload,
1163
+ message: "Refund Data Format Error"
1154
1164
  }
1155
1165
  };
1156
1166
 
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.11";
10
+ const SDKVersion = "0.2.1";
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(/(?<!:)\/{2,}/g, "/");
112
+ return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
113
113
  }
114
114
  /**
115
115
  * 给 url 添加完整域名和协议,仅可在浏览器环境使用
@@ -1101,7 +1101,9 @@ class TokenVerifier {
1101
1101
  idp: payload.idp,
1102
1102
  external_id: payload.external_id,
1103
1103
  external_name: payload.external_name,
1104
- weixin_unionid: payload.weixin_unionid || ""
1104
+ weixin_unionid: payload.weixin_unionid || "",
1105
+ distro: payload.distro || "",
1106
+ variant: payload.variant || ""
1105
1107
  };
1106
1108
  } catch (error) {
1107
1109
  return new Error(`IdentityToken 验证失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -1139,6 +1141,10 @@ function isShipOrderPayload(data) {
1139
1141
  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;
1140
1142
  }
1141
1143
 
1144
+ function isRefundPayload(data) {
1145
+ 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;
1146
+ }
1147
+
1142
1148
  /**
1143
1149
  * 消息处理分发配置
1144
1150
  */
@@ -1146,6 +1152,10 @@ const messageDataGuards = {
1146
1152
  ["ship_order" /* NotificationType.ShipOrder */]: {
1147
1153
  guard: isShipOrderPayload,
1148
1154
  message: "ShipOrder Data Format Error"
1155
+ },
1156
+ ["refund" /* NotificationType.Refund */]: {
1157
+ guard: isRefundPayload,
1158
+ message: "Refund Data Format Error"
1149
1159
  }
1150
1160
  };
1151
1161
 
@@ -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;
@@ -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>;
@@ -36,6 +36,18 @@ export interface IdentityPayload {
36
36
  * 注意:weixin_unionid 只在 IdP 为 weixin 时才会有值。
37
37
  */
38
38
  weixin_unionid: string;
39
+ /**
40
+ * distro 是游戏客户端的发行版本标识。
41
+ * 游戏侧可将 distro 用于服务端数据埋点,以及特定的业务逻辑判断。
42
+ */
43
+ distro: string;
44
+ /**
45
+ * variant 是游戏客户端的分包标识。
46
+ * 游戏侧可将 variant 用于服务端数据埋点,以及特定的业务逻辑判断。
47
+ *
48
+ * 注意:Variant 只在客户端是分包时才会有值。当客户端不是分包的情况下,variant 为空字符串。
49
+ */
50
+ variant: string;
39
51
  }
40
52
  export type IdentityJwtPayload = JwtPayload & Omit<IdentityPayload, "combo_id"> & {
41
53
  scope: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-io/combo-sdk-node",
3
- "version": "0.1.11",
3
+ "version": "0.2.1",
4
4
  "description": "Combo SDK for Node.js",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",