node-easywechat 3.1.2 → 3.1.4

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/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.1.3 (2023-02-01)
5
+
6
+ - Fix: 修复默认的文件缓存配置项不生效问题 (#35)
7
+
4
8
  ## v3.1.2 (2022-12-06)
5
9
 
6
10
  - Feat: 新作微信支付模块的文件上传方法
@@ -45,7 +45,11 @@ class CacheMixin {
45
45
  */
46
46
  getCache() {
47
47
  if (!this.cache) {
48
- this.cache = new FileCache_1.default();
48
+ let options = null;
49
+ if (typeof this['getConfig'] === 'function') {
50
+ options = this['getConfig']()['get']('file_cache');
51
+ }
52
+ this.cache = new FileCache_1.default(options);
49
53
  }
50
54
  return this.cache;
51
55
  }
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
15
- const FileCache_1 = __importDefault(require("../Core/Cache/FileCache"));
16
15
  class AccessToken {
17
16
  constructor(appId, secret, key = null, cache = null, httpClient = null) {
18
17
  this.appId = appId;
@@ -20,9 +19,6 @@ class AccessToken {
20
19
  this.key = key;
21
20
  this.cache = cache;
22
21
  this.httpClient = httpClient;
23
- if (!this.cache) {
24
- this.cache = new FileCache_1.default();
25
- }
26
22
  if (!this.httpClient) {
27
23
  this.httpClient = HttpClient_1.default.create({
28
24
  baseURL: 'https://api.weixin.qq.com/',
@@ -50,7 +46,10 @@ class AccessToken {
50
46
  }
51
47
  getToken() {
52
48
  return __awaiter(this, void 0, void 0, function* () {
53
- let token = yield this.cache.get(this.getKey());
49
+ let token = '';
50
+ if (this.cache) {
51
+ token = yield this.cache.get(this.getKey());
52
+ }
54
53
  if (!!token && typeof token === 'string') {
55
54
  return token;
56
55
  }
@@ -76,7 +75,9 @@ class AccessToken {
76
75
  if (!response['access_token']) {
77
76
  throw new Error('Failed to get access_token: ' + JSON.stringify(response));
78
77
  }
79
- yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
78
+ if (this.cache) {
79
+ yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
80
+ }
80
81
  return response['access_token'];
81
82
  });
82
83
  }
@@ -31,7 +31,10 @@ class JsApiTicket extends AccessToken_1.default {
31
31
  getTicket() {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  let key = this.getKey();
34
- let ticket = yield this.cache.get(key);
34
+ let ticket = '';
35
+ if (this.cache) {
36
+ ticket = yield this.cache.get(key);
37
+ }
35
38
  if (!!ticket && typeof ticket === 'string') {
36
39
  return ticket;
37
40
  }
@@ -43,7 +46,9 @@ class JsApiTicket extends AccessToken_1.default {
43
46
  if (!response['ticket']) {
44
47
  throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
45
48
  }
46
- yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
49
+ if (this.cache) {
50
+ yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
51
+ }
47
52
  return response['ticket'];
48
53
  });
49
54
  }
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
15
- const FileCache_1 = __importDefault(require("../Core/Cache/FileCache"));
16
15
  class ComponentAccessToken {
17
16
  constructor(appId, secret, verifyTicket, key = null, cache = null, httpClient = null) {
18
17
  this.appId = appId;
@@ -21,9 +20,6 @@ class ComponentAccessToken {
21
20
  this.key = key;
22
21
  this.cache = cache;
23
22
  this.httpClient = httpClient;
24
- if (!this.cache) {
25
- this.cache = new FileCache_1.default();
26
- }
27
23
  if (!this.httpClient) {
28
24
  this.httpClient = HttpClient_1.default.create({
29
25
  baseURL: 'https://api.weixin.qq.com/',
@@ -51,7 +47,10 @@ class ComponentAccessToken {
51
47
  }
52
48
  getToken() {
53
49
  return __awaiter(this, void 0, void 0, function* () {
54
- let token = yield this.cache.get(this.getKey());
50
+ let token = '';
51
+ if (this.cache) {
52
+ token = yield this.cache.get(this.getKey());
53
+ }
55
54
  if (!!token && typeof token === 'string') {
56
55
  return token;
57
56
  }
@@ -77,7 +76,9 @@ class ComponentAccessToken {
77
76
  if (!response['component_access_token']) {
78
77
  throw new Error('Failed to get component_access_token: ' + JSON.stringify(response));
79
78
  }
80
- yield this.cache.set(this.getKey(), response['component_access_token'], parseInt(response['expires_in']) - 100);
79
+ if (this.cache) {
80
+ yield this.cache.set(this.getKey(), response['component_access_token'], parseInt(response['expires_in']) - 100);
81
+ }
81
82
  return response['component_access_token'];
82
83
  });
83
84
  }
@@ -8,16 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- const FileCache_1 = __importDefault(require("../Core/Cache/FileCache"));
15
11
  class VerifyTicket {
16
12
  constructor(appId, key = null, cache = null) {
17
13
  this.appId = appId;
18
14
  this.key = key;
19
15
  this.cache = cache;
20
- this.cache = cache !== null && cache !== void 0 ? cache : new FileCache_1.default();
21
16
  }
22
17
  getKey() {
23
18
  if (!this.key) {
@@ -31,13 +26,18 @@ class VerifyTicket {
31
26
  }
32
27
  setTicket(ticket) {
33
28
  return __awaiter(this, void 0, void 0, function* () {
34
- yield this.cache.set(this.getKey(), ticket, 6000);
29
+ if (this.cache) {
30
+ yield this.cache.set(this.getKey(), ticket, 6000);
31
+ }
35
32
  return this;
36
33
  });
37
34
  }
38
35
  getTicket() {
39
36
  return __awaiter(this, void 0, void 0, function* () {
40
- let ticket = yield this.cache.get(this.getKey());
37
+ let ticket = '';
38
+ if (this.cache) {
39
+ ticket = yield this.cache.get(this.getKey());
40
+ }
41
41
  if (!ticket || typeof ticket != 'string') {
42
42
  throw new Error('No component_verify_ticket found.');
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {