@tuya-sat/micro-dev-proxy 3.0.27-beta.9 → 3.0.28

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/dist/appProxy.js CHANGED
@@ -39,7 +39,7 @@ exports.GSdf = void 0;
39
39
  const globalAxios_1 = __importDefault(require("./globalAxios"));
40
40
  const js_sha256_1 = require("js-sha256");
41
41
  const csrf_1 = __importStar(require("./csrf"));
42
- const initLogin_1 = __importStar(require("./initLogin"));
42
+ const initLogin_1 = __importDefault(require("./initLogin"));
43
43
  const token_1 = __importDefault(require("./token"));
44
44
  const util_1 = require("./util");
45
45
  const url_1 = require("url");
@@ -51,7 +51,7 @@ const mf = fs.existsSync(mfPath) && JSON.parse(fs.readFileSync(mfPath, 'utf8'));
51
51
  let SDF;
52
52
  function parse_SDF(html) {
53
53
  var _a;
54
- const REGEX = /(?<=window._SDF=).*?}(?=;)/;
54
+ const REGEX = /(?<=window._SDF=).*?}(?=(;|<\/script>))/;
55
55
  return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
56
56
  }
57
57
  function GSdf() {
@@ -112,7 +112,6 @@ class AppProxy {
112
112
  }).then(({ body }) => {
113
113
  body.text().then((data) => {
114
114
  SDF = JSON.parse(parse_SDF(data));
115
- console.log(SDF);
116
115
  });
117
116
  });
118
117
  })
@@ -132,7 +131,7 @@ class AppProxy {
132
131
  if (csrf_1.COOKIE_CSRF === key) {
133
132
  return false;
134
133
  }
135
- if (initLogin_1.LOGIN_COOKIE_KEY === key && !this.isMainApp) {
134
+ if (('connect.sid' === key || 'sid' === key) && !this.isMainApp) {
136
135
  return false;
137
136
  }
138
137
  return true;
@@ -150,7 +149,6 @@ class AppProxy {
150
149
  Object.entries(combineHeaders).forEach(([headerKey, value]) => proxyReq.setHeader(headerKey, value));
151
150
  const prevCookie = proxyReq.getHeader('cookie') || '';
152
151
  proxyReq.setHeader('cookie', this.getCookie(prevCookie));
153
- this.log('----req-header----', proxyReq.getHeaders());
154
152
  }
155
153
  combinedHeader(prevHeadar) {
156
154
  let proccessedHeader = Object.assign({}, prevHeadar);
package/dist/csrf.js CHANGED
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.HEADERS_CSRF = exports.COOKIE_CSRF = void 0;
7
7
  const globalAxios_1 = __importDefault(require("./globalAxios"));
8
- const util_1 = require("./util");
9
8
  exports.COOKIE_CSRF = '_csrf';
10
9
  exports.HEADERS_CSRF = 'csrf-token';
11
10
  function parseHtml(html) {
@@ -15,7 +14,9 @@ function parseHtml(html) {
15
14
  }
16
15
  function getCsrf(url) {
17
16
  return globalAxios_1.default.get(url).then((res) => {
18
- let csrfCookie = (0, util_1.parseSetCookie)(res.headers['set-cookie'], exports.COOKIE_CSRF);
17
+ const csrfCookie = res.headers['set-cookie']
18
+ .map((cookieInfo) => cookieInfo.split(';')[0])
19
+ .find((cookie) => cookie.split('=')[0] === exports.COOKIE_CSRF) || '';
19
20
  let csrfToken = parseHtml(res.data);
20
21
  return [csrfCookie, csrfToken];
21
22
  });
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ function awaiting() {
31
31
  exports.awaiting = awaiting;
32
32
  function createProxy(_a) {
33
33
  var { additionHeaders = {} } = _a, restPrevConfig = __rest(_a, ["additionHeaders"]);
34
- const config = Object.assign({ additionHeaders: Object.assign({ terminalId: os_1.default.hostname() }, additionHeaders), isMainApp: restPrevConfig.isMainApp, loginApi: '/api/login', needProxyApi: ['/api', '/open-api', '/custom-api'], logSign: false, csrf: true }, restPrevConfig);
34
+ const config = Object.assign({ additionHeaders: Object.assign({ terminalId: os_1.default.hostname() + Date.now() }, additionHeaders), isMainApp: restPrevConfig.isMainApp, loginApi: '/api/login', needProxyApi: ['/api', '/open-api', '/custom-api'], logSign: false, csrf: true }, restPrevConfig);
35
35
  const { needProxyApi } = config, appProxyConfig = __rest(config, ["needProxyApi"]);
36
36
  const appProxy = new appProxy_1.default(appProxyConfig);
37
37
  return function middleware(app) {
package/dist/util.js CHANGED
@@ -20,8 +20,8 @@ function logFactory(isLog) {
20
20
  exports.logFactory = logFactory;
21
21
  function parseSetCookie(setCookie, key) {
22
22
  const targetCookie = setCookie
23
- .map((cookieInfo) => cookieInfo.split(";")[0])
24
- .find((cookie) => cookie.split("=")[0] === key);
25
- return targetCookie || "";
23
+ .map((cookieInfo) => cookieInfo.split(';')[0])
24
+ .find((cookie) => cookie.split('=')[0] === 'connect.sid' || cookie.split('=')[0] === 'sid');
25
+ return targetCookie || '';
26
26
  }
27
27
  exports.parseSetCookie = parseSetCookie;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-proxy",
3
- "version": "3.0.27-beta.9",
3
+ "version": "3.0.28",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {