@seayoo-io/combo-sdk-node 0.1.11 → 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 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 = {
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.1.12";
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.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(/(?<!:)\/{2,}/g, "/");
117
+ return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
118
118
  }
119
119
  /**
120
120
  * 给 url 添加完整域名和协议,仅可在浏览器环境使用
@@ -1144,6 +1144,10 @@ function isShipOrderPayload(data) {
1144
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;
1145
1145
  }
1146
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
+
1147
1151
  /**
1148
1152
  * 消息处理分发配置
1149
1153
  */
@@ -1151,6 +1155,10 @@ const messageDataGuards = {
1151
1155
  ["ship_order" /* NotificationType.ShipOrder */]: {
1152
1156
  guard: isShipOrderPayload,
1153
1157
  message: "ShipOrder Data Format Error"
1158
+ },
1159
+ ["refund" /* NotificationType.Refund */]: {
1160
+ guard: isRefundPayload,
1161
+ message: "Refund Data Format Error"
1154
1162
  }
1155
1163
  };
1156
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.11";
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(/(?<!:)\/{2,}/g, "/");
112
+ return (fillUrl(baseURL) + "/" + url).replace(/\/{2,}/g, "/").replace(/:\//, "://");
113
113
  }
114
114
  /**
115
115
  * 给 url 添加完整域名和协议,仅可在浏览器环境使用
@@ -1139,6 +1139,10 @@ function isShipOrderPayload(data) {
1139
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;
1140
1140
  }
1141
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
+
1142
1146
  /**
1143
1147
  * 消息处理分发配置
1144
1148
  */
@@ -1146,6 +1150,10 @@ const messageDataGuards = {
1146
1150
  ["ship_order" /* NotificationType.ShipOrder */]: {
1147
1151
  guard: isShipOrderPayload,
1148
1152
  message: "ShipOrder Data Format Error"
1153
+ },
1154
+ ["refund" /* NotificationType.Refund */]: {
1155
+ guard: isRefundPayload,
1156
+ message: "Refund Data Format Error"
1149
1157
  }
1150
1158
  };
1151
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;
@@ -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>;
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.1.12",
4
4
  "description": "Combo SDK for Node.js",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",