@tuya-sat/micro-dev-proxy 3.0.10 → 3.0.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/dist/appProxy.d.ts +2 -0
- package/dist/appProxy.js +29 -7
- package/dist/csrf.js +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +3 -2
package/dist/appProxy.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface AppProxyConfig {
|
|
|
13
13
|
logSign?: boolean;
|
|
14
14
|
isThirdLogin?: boolean;
|
|
15
15
|
}
|
|
16
|
+
export declare function GSdf(): any;
|
|
16
17
|
export default class AppProxy {
|
|
17
18
|
target: string;
|
|
18
19
|
username: string;
|
|
@@ -34,6 +35,7 @@ export default class AppProxy {
|
|
|
34
35
|
init(): Promise<void>;
|
|
35
36
|
getCsrf(): Promise<void>;
|
|
36
37
|
getLoginCookie(): Promise<void>;
|
|
38
|
+
getCookie(prevCookie: any): string;
|
|
37
39
|
processReq(proxyReq: Parameters<Options['onProxyReq']>[0], req: any, res: any): void;
|
|
38
40
|
combinedHeader(prevHeadar: any): any;
|
|
39
41
|
processRes(responseBuffer: any, proxyRes: any, req: any, res: any): Promise<any>;
|
package/dist/appProxy.js
CHANGED
|
@@ -35,6 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.GSdf = void 0;
|
|
38
39
|
const globalAxios_1 = __importDefault(require("./globalAxios"));
|
|
39
40
|
const js_sha256_1 = require("js-sha256");
|
|
40
41
|
const csrf_1 = __importStar(require("./csrf"));
|
|
@@ -44,8 +45,19 @@ const util_1 = require("./util");
|
|
|
44
45
|
const url_1 = require("url");
|
|
45
46
|
const fs = __importStar(require("fs"));
|
|
46
47
|
const path = __importStar(require("path"));
|
|
48
|
+
const undici_1 = require("undici");
|
|
47
49
|
const mfPath = path.join(process.cwd(), 'manifest.json');
|
|
48
50
|
const mf = fs.existsSync(mfPath) && JSON.parse(fs.readFileSync(mfPath, 'utf8'));
|
|
51
|
+
let SDF;
|
|
52
|
+
function parse_SDF(html) {
|
|
53
|
+
var _a;
|
|
54
|
+
const REGEX = /(?<=window._SDF=).*?}(?=;)/;
|
|
55
|
+
return ((_a = REGEX.exec(html)) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
56
|
+
}
|
|
57
|
+
function GSdf() {
|
|
58
|
+
return SDF;
|
|
59
|
+
}
|
|
60
|
+
exports.GSdf = GSdf;
|
|
49
61
|
class AppProxy {
|
|
50
62
|
constructor({ target, username, password, additionHeaders, isMainApp, isThirdLogin, loginApi, csrf = true, logSign, }) {
|
|
51
63
|
this.loginCookie = new token_1.default();
|
|
@@ -95,6 +107,14 @@ class AppProxy {
|
|
|
95
107
|
})
|
|
96
108
|
.then((cookie) => {
|
|
97
109
|
this.loginCookie.setValue(cookie);
|
|
110
|
+
(0, undici_1.request)(new url_1.URL('/', this.target).href, {
|
|
111
|
+
headers: this.combinedHeader({ cookie }),
|
|
112
|
+
}).then(({ body }) => {
|
|
113
|
+
body.text().then((data) => {
|
|
114
|
+
SDF = JSON.parse(parse_SDF(data));
|
|
115
|
+
console.log(SDF);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
98
118
|
})
|
|
99
119
|
.catch((err) => {
|
|
100
120
|
this.log('----inital login error----' + err);
|
|
@@ -102,12 +122,8 @@ class AppProxy {
|
|
|
102
122
|
});
|
|
103
123
|
});
|
|
104
124
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const combineHeaders = this.combinedHeader(this.additionHeaders);
|
|
108
|
-
Object.entries(combineHeaders).forEach(([headerKey, value]) => proxyReq.setHeader(headerKey, value));
|
|
109
|
-
const prevCookie = proxyReq.getHeader('cookie') || '';
|
|
110
|
-
const cookie = [
|
|
125
|
+
getCookie(prevCookie) {
|
|
126
|
+
return [
|
|
111
127
|
...prevCookie
|
|
112
128
|
.split(';')
|
|
113
129
|
.map((item) => [item.split('=')[0].trim(), item])
|
|
@@ -127,7 +143,13 @@ class AppProxy {
|
|
|
127
143
|
]
|
|
128
144
|
.filter(Boolean)
|
|
129
145
|
.join(';');
|
|
130
|
-
|
|
146
|
+
}
|
|
147
|
+
processReq(proxyReq, req, res) {
|
|
148
|
+
//整合需要添加的header头
|
|
149
|
+
const combineHeaders = this.combinedHeader(this.additionHeaders);
|
|
150
|
+
Object.entries(combineHeaders).forEach(([headerKey, value]) => proxyReq.setHeader(headerKey, value));
|
|
151
|
+
const prevCookie = proxyReq.getHeader('cookie') || '';
|
|
152
|
+
proxyReq.setHeader('cookie', this.getCookie(prevCookie));
|
|
131
153
|
this.log('----req-header----', proxyReq.getHeaders());
|
|
132
154
|
}
|
|
133
155
|
combinedHeader(prevHeadar) {
|
package/dist/csrf.js
CHANGED
|
@@ -6,16 +6,16 @@ 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
8
|
const util_1 = require("./util");
|
|
9
|
-
exports.COOKIE_CSRF =
|
|
10
|
-
exports.HEADERS_CSRF =
|
|
9
|
+
exports.COOKIE_CSRF = '_csrf';
|
|
10
|
+
exports.HEADERS_CSRF = 'csrf-token';
|
|
11
11
|
function parseHtml(html) {
|
|
12
12
|
var _a;
|
|
13
13
|
const CSRF_REGEX = /.*window.csrf=('|")?([^'"]+)/;
|
|
14
|
-
return ((_a = html.match(CSRF_REGEX)) === null || _a === void 0 ? void 0 : _a[2]) ||
|
|
14
|
+
return ((_a = html.match(CSRF_REGEX)) === null || _a === void 0 ? void 0 : _a[2]) || '';
|
|
15
15
|
}
|
|
16
16
|
function getCsrf(url) {
|
|
17
17
|
return globalAxios_1.default.get(url).then((res) => {
|
|
18
|
-
let csrfCookie = (0, util_1.parseSetCookie)(res.headers[
|
|
18
|
+
let csrfCookie = (0, util_1.parseSetCookie)(res.headers['set-cookie'], exports.COOKIE_CSRF);
|
|
19
19
|
let csrfToken = parseHtml(res.data);
|
|
20
20
|
return [csrfCookie, csrfToken];
|
|
21
21
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,10 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.awaiting = void 0;
|
|
17
|
+
exports.awaiting = exports.GSdf = void 0;
|
|
18
18
|
const os_1 = __importDefault(require("os"));
|
|
19
19
|
const http_proxy_middleware_1 = require("http-proxy-middleware");
|
|
20
20
|
const appProxy_1 = __importDefault(require("./appProxy"));
|
|
21
|
+
var appProxy_2 = require("./appProxy");
|
|
22
|
+
Object.defineProperty(exports, "GSdf", { enumerable: true, get: function () { return appProxy_2.GSdf; } });
|
|
21
23
|
function awaiting() {
|
|
22
24
|
let $resolve, $reject;
|
|
23
25
|
const waiting = new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-dev-proxy",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.12",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"chalk": "5.0.1",
|
|
15
15
|
"fs-extra": "10.0.1",
|
|
16
16
|
"http-proxy-middleware": "2.0.4",
|
|
17
|
-
"js-sha256": "0.9.0"
|
|
17
|
+
"js-sha256": "0.9.0",
|
|
18
|
+
"undici": "^5.20.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/fs-extra": "9.0.13",
|