@seayoo-io/combo-sdk-node 0.1.3 → 0.1.6

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
@@ -40,12 +40,12 @@ import { ApiClient, Endpoint } from "@seayoo-io/combo-sdk-node"
40
40
  const client = new ApiClient({
41
41
  game: "<GameId>",
42
42
  secret: "<SecretKey>",
43
- endpoint: Endpoint.China
43
+ endpoint: Endpoint.China,
44
44
  // 以下参数可选
45
- maxRetry: 1, // 失败后自动重试次数,默认 1
46
- retryInterval: 100 // 重试间隔,默认是 100,单位 ms,可以传递函数动态设置间隔
47
- logger: function(log) {} // 请求日志函数,log 类型参见源码类型定义
48
- timeout: 5000, // 超时等待时长,单位 ms,默认 5000
45
+ maxRetry: 1, // 失败后自动重试次数,默认 1
46
+ retryInterval: 1000, // 重试间隔,默认是 1000,单位 ms,可以传递函数动态设置间隔
47
+ logger: function(log) {}, // 请求日志函数,log 类型参见源码类型定义
48
+ timeout: 5000, // 超时等待时长,单位 ms,默认 5000
49
49
  })
50
50
  ```
51
51
 
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.3";
4
+ export declare const SDKVersion = "0.1.6";
5
5
  /**
6
6
  * 世游支持的服务端点列表
7
7
  */
package/dist/index.cjs CHANGED
@@ -4,31 +4,15 @@ var https = require('node:https');
4
4
  var crypto = require('crypto');
5
5
  var jsonwebtoken = require('jsonwebtoken');
6
6
 
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return n;
23
- }
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
24
8
 
25
- var http__namespace = /*#__PURE__*/_interopNamespace(http);
26
- var https__namespace = /*#__PURE__*/_interopNamespace(https);
9
+ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
10
+ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
27
11
 
28
12
  /** SDK 名称 */
29
13
  const SDKName = "combo-sdk-node";
30
14
  /** SDK 版本,在编译前会被动态替换 */
31
- const SDKVersion = "0.1.3";
15
+ const SDKVersion = "0.1.6";
32
16
  /**
33
17
  * 世游支持的服务端点列表
34
18
  */
@@ -172,7 +156,7 @@ function verifyConfig(config) {
172
156
  throw Error("Config Missing");
173
157
  }
174
158
  if (!isFullURL(config.endpoint)) {
175
- throw Error(`Config.endpoint Error, Should be url, Preset Values: ${"https://api.seayoo.com" /* Endpoint.China */}, ${"https://api.seayoo.io" /* Endpoint.Global */}}`);
159
+ throw Error(`Config.endpoint Error, Should be url, Preset Values: ${exports.Endpoint.China}, ${exports.Endpoint.Global}}`);
176
160
  }
177
161
  if (!config.game) {
178
162
  throw Error(`Config.game Error, Missing Required GameId`);
@@ -663,7 +647,7 @@ const coreNodeRequest = async function (url, config, options) {
663
647
  body: ""
664
648
  };
665
649
  }
666
- const client = /^https:\/\//i.test(opt.url) ? https__namespace : http__namespace;
650
+ const client = /^https:\/\//i.test(opt.url) ? https__default["default"] : http__default["default"];
667
651
  const iURL = new URL(opt.url);
668
652
  const params = opt.params;
669
653
  if (params instanceof Object) {
@@ -908,6 +892,7 @@ function NetRequest(config) {
908
892
  }
909
893
 
910
894
  const ApiPrefix = "/v1/server";
895
+ const TraceIdField = "x-trace-id";
911
896
  /**
912
897
  * Combo SDK For Server REST Api
913
898
  */
@@ -955,7 +940,7 @@ class ApiClient {
955
940
  });
956
941
  },
957
942
  logHandler: config.logger,
958
- timeout: config.timeout
943
+ timeout: config.timeout || 5000
959
944
  });
960
945
  }
961
946
  /**
@@ -965,8 +950,15 @@ class ApiClient {
965
950
  if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
966
951
  throw new Error("createOrder: 必要参数缺失");
967
952
  }
953
+ // 检查通知回调地址
954
+ if (!isFullURL(option.notify_url)) {
955
+ throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
956
+ }
968
957
  // 检查购买数量
969
- option.quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
958
+ const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
959
+ if (quantity !== option.quantity) {
960
+ throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
961
+ }
970
962
  const {
971
963
  ok,
972
964
  data,
@@ -981,7 +973,7 @@ class ApiClient {
981
973
  status,
982
974
  code,
983
975
  message,
984
- traceId: headers["x-trace-id"]
976
+ traceId: headers[TraceIdField]
985
977
  });
986
978
  throw new Error(`createOrder: ${message || code || status}`);
987
979
  }
@@ -1015,7 +1007,7 @@ class ApiClient {
1015
1007
  status,
1016
1008
  code,
1017
1009
  message,
1018
- traceId: headers["x-trace-id"]
1010
+ traceId: headers[TraceIdField]
1019
1011
  });
1020
1012
  }
1021
1013
  return ok;
@@ -1048,7 +1040,7 @@ class ApiClient {
1048
1040
  status,
1049
1041
  code,
1050
1042
  message,
1051
- traceId: headers["x-trace-id"]
1043
+ traceId: headers[TraceIdField]
1052
1044
  });
1053
1045
  }
1054
1046
  return ok;
@@ -1107,7 +1099,7 @@ class TokenVerifier {
1107
1099
  idp: payload.idp,
1108
1100
  external_id: payload.external_id,
1109
1101
  external_name: payload.external_name,
1110
- weixin_unionid: payload.weixin_unionid
1102
+ weixin_unionid: payload.weixin_unionid || ""
1111
1103
  };
1112
1104
  } catch (error) {
1113
1105
  return new Error(`IdentityToken 验证失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -1280,13 +1272,14 @@ function getNotificationMiddlewareForKoa(paths, config, handler) {
1280
1272
  await func(ctx.req, ctx.res);
1281
1273
  return;
1282
1274
  }
1283
- next();
1275
+ await next();
1284
1276
  };
1285
1277
  }
1286
1278
 
1287
1279
  exports.ApiClient = ApiClient;
1288
1280
  exports.TokenVerifier = TokenVerifier;
1289
1281
  exports.calcAuthorizationHeader = calcAuthorizationHeader;
1282
+ exports.checkHttpAuthInfo = checkHttpAuthInfo;
1290
1283
  exports.getNotificationHandler = getNotificationHandler;
1291
1284
  exports.getNotificationHandlerForExpress = getNotificationHandlerForExpress;
1292
1285
  exports.getNotificationHandlerForKoa = getNotificationHandlerForKoa;
package/dist/index.d.ts CHANGED
@@ -8,5 +8,5 @@ export { getNotificationHandler, getNotificationHandlerForExpress, getNotificati
8
8
  export { NotificationType } from "./notify/types";
9
9
  export type { NotificationHandler } from "./notify/types";
10
10
  export type { SDKBaseConfig } from "./utils";
11
- export { parseAuthorizationHeader, calcAuthorizationHeader } from "./utils";
12
11
  export { Endpoint, Platform, IdP } from "./const";
12
+ export { parseAuthorizationHeader, calcAuthorizationHeader, checkHttpAuthInfo } from "./utils";
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { platform, arch } from 'node:os';
2
- import * as http from 'node:http';
3
- import * as https from 'node:https';
2
+ import http from 'node:http';
3
+ import https from 'node:https';
4
4
  import { createHash, createHmac } from 'crypto';
5
5
  import { verify } from 'jsonwebtoken';
6
6
 
7
7
  /** SDK 名称 */
8
8
  const SDKName = "combo-sdk-node";
9
9
  /** SDK 版本,在编译前会被动态替换 */
10
- const SDKVersion = "0.1.3";
10
+ const SDKVersion = "0.1.6";
11
11
  /**
12
12
  * 世游支持的服务端点列表
13
13
  */
@@ -151,7 +151,7 @@ function verifyConfig(config) {
151
151
  throw Error("Config Missing");
152
152
  }
153
153
  if (!isFullURL(config.endpoint)) {
154
- throw Error(`Config.endpoint Error, Should be url, Preset Values: ${"https://api.seayoo.com" /* Endpoint.China */}, ${"https://api.seayoo.io" /* Endpoint.Global */}}`);
154
+ throw Error(`Config.endpoint Error, Should be url, Preset Values: ${Endpoint.China}, ${Endpoint.Global}}`);
155
155
  }
156
156
  if (!config.game) {
157
157
  throw Error(`Config.game Error, Missing Required GameId`);
@@ -887,6 +887,7 @@ function NetRequest(config) {
887
887
  }
888
888
 
889
889
  const ApiPrefix = "/v1/server";
890
+ const TraceIdField = "x-trace-id";
890
891
  /**
891
892
  * Combo SDK For Server REST Api
892
893
  */
@@ -934,7 +935,7 @@ class ApiClient {
934
935
  });
935
936
  },
936
937
  logHandler: config.logger,
937
- timeout: config.timeout
938
+ timeout: config.timeout || 5000
938
939
  });
939
940
  }
940
941
  /**
@@ -944,8 +945,15 @@ class ApiClient {
944
945
  if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
945
946
  throw new Error("createOrder: 必要参数缺失");
946
947
  }
948
+ // 检查通知回调地址
949
+ if (!isFullURL(option.notify_url)) {
950
+ throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
951
+ }
947
952
  // 检查购买数量
948
- option.quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
953
+ const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
954
+ if (quantity !== option.quantity) {
955
+ throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
956
+ }
949
957
  const {
950
958
  ok,
951
959
  data,
@@ -960,7 +968,7 @@ class ApiClient {
960
968
  status,
961
969
  code,
962
970
  message,
963
- traceId: headers["x-trace-id"]
971
+ traceId: headers[TraceIdField]
964
972
  });
965
973
  throw new Error(`createOrder: ${message || code || status}`);
966
974
  }
@@ -994,7 +1002,7 @@ class ApiClient {
994
1002
  status,
995
1003
  code,
996
1004
  message,
997
- traceId: headers["x-trace-id"]
1005
+ traceId: headers[TraceIdField]
998
1006
  });
999
1007
  }
1000
1008
  return ok;
@@ -1027,7 +1035,7 @@ class ApiClient {
1027
1035
  status,
1028
1036
  code,
1029
1037
  message,
1030
- traceId: headers["x-trace-id"]
1038
+ traceId: headers[TraceIdField]
1031
1039
  });
1032
1040
  }
1033
1041
  return ok;
@@ -1086,7 +1094,7 @@ class TokenVerifier {
1086
1094
  idp: payload.idp,
1087
1095
  external_id: payload.external_id,
1088
1096
  external_name: payload.external_name,
1089
- weixin_unionid: payload.weixin_unionid
1097
+ weixin_unionid: payload.weixin_unionid || ""
1090
1098
  };
1091
1099
  } catch (error) {
1092
1100
  return new Error(`IdentityToken 验证失败: ${error instanceof Error ? error.message : String(error)}`);
@@ -1259,8 +1267,8 @@ function getNotificationMiddlewareForKoa(paths, config, handler) {
1259
1267
  await func(ctx.req, ctx.res);
1260
1268
  return;
1261
1269
  }
1262
- next();
1270
+ await next();
1263
1271
  };
1264
1272
  }
1265
1273
 
1266
- export { ApiClient, Endpoint, IdP, Platform, TokenVerifier, calcAuthorizationHeader, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
1274
+ export { ApiClient, Endpoint, IdP, Platform, TokenVerifier, calcAuthorizationHeader, checkHttpAuthInfo, getNotificationHandler, getNotificationHandlerForExpress, getNotificationHandlerForKoa, getNotificationMiddlewareForExpress, getNotificationMiddlewareForKoa, parseAuthorizationHeader };
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { type SDKBaseConfig } from "../utils";
3
2
  import { type NotificationHandler } from "./types";
4
3
  import type { ParameterizedContext, Next } from "koa";
@@ -35,7 +35,7 @@ export interface IdentityPayload {
35
35
  *
36
36
  * 注意:weixin_unionid 只在 IdP 为 weixin 时才会有值。
37
37
  */
38
- weixin_unionid?: string;
38
+ weixin_unionid: string;
39
39
  }
40
40
  export type IdentityJwtPayload = JwtPayload & Omit<IdentityPayload, "combo_id"> & {
41
41
  scope: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-io/combo-sdk-node",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "Combo SDK for Node.js",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -52,11 +52,11 @@
52
52
  "eslint-plugin-prettier": "^5.1.2",
53
53
  "lint-staged": "^15.2.0",
54
54
  "microbundle": "^0.15.1",
55
+ "msw": "^2.0.11",
55
56
  "rimraf": "^5.0.5",
56
57
  "simple-git-hooks": "^2.9.0",
57
- "typescript": "^5.3.3",
58
- "vite": "^5.0.10",
59
- "vitest": "^1.1.1"
58
+ "typescript": "^5.2.2",
59
+ "vitest": "^1.1.2"
60
60
  },
61
61
  "dependencies": {
62
62
  "jsonwebtoken": "^9.0.2"
package/vitest.config.ts CHANGED
@@ -2,6 +2,7 @@ import { defineConfig } from "vitest/config"
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
+ environment: "node",
5
6
  onConsoleLog(log: string, type: "stdout" | "stderr"): false | void {
6
7
  if (type === "stderr") return false
7
8
  },