@tuya-sat/micro-dev-proxy 3.2.22 → 3.2.23

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.
@@ -35,6 +35,8 @@ export default class AppProxy {
35
35
  spinnies: Spinnies;
36
36
  constructor({ target, username, password, additionHeaders, isMainApp, isThirdLogin, loginApi, csrf, logSign, }: AppProxyConfig);
37
37
  init(): Promise<void>;
38
+ needManualLogin(): boolean;
39
+ isLoginApi(url: string): boolean;
38
40
  getCsrf(): Promise<void>;
39
41
  getLoginCookie(): Promise<void>;
40
42
  getCookie(prevCookie?: string): string;
package/dist/appProxy.js CHANGED
@@ -99,6 +99,16 @@ class AppProxy {
99
99
  }
100
100
  });
101
101
  }
102
+ needManualLogin() {
103
+ return !this.username || !this.password;
104
+ }
105
+ isLoginApi(url) {
106
+ return [
107
+ this.loginApi,
108
+ '/api/login',
109
+ '/api/login/qrcode'
110
+ ].includes(url.replace(/^\/+/, ''));
111
+ }
102
112
  //获取csrf
103
113
  getCsrf() {
104
114
  return __awaiter(this, void 0, void 0, function* () {
@@ -122,6 +132,12 @@ class AppProxy {
122
132
  if (!this.spinnies.pick('login')) {
123
133
  this.spinnies.add('login', { text: SPIN_LABEL_NAME.login });
124
134
  }
135
+ if (this.needManualLogin()) {
136
+ this.spinnies.fail('login', {
137
+ text: '账密未配置,需要手动登录'
138
+ });
139
+ return;
140
+ }
125
141
  const { href: loginUrl } = new url_1.URL(this.loginApi, this.target);
126
142
  yield (0, initLogin_1.default)(loginUrl, { username: this.username, password: this.password }, {
127
143
  headers: this.combinedHeader({ cookie: this.csrfCookie.value }),
@@ -180,12 +196,12 @@ class AppProxy {
180
196
  return proccessedHeader;
181
197
  }
182
198
  processRes(responseBuffer, proxyRes, req, res) {
183
- var _a, _b;
199
+ var _a, _b, _c;
184
200
  return __awaiter(this, void 0, void 0, function* () {
185
201
  let response;
186
202
  try {
187
203
  response = JSON.parse(responseBuffer.toString('utf8'));
188
- if (req.url === this.loginApi) {
204
+ if (this.isLoginApi(req.url)) {
189
205
  const token = (0, util_1.parseSetCookie)(proxyRes.headers['set-cookie']);
190
206
  if (token) {
191
207
  this.loginCookie.setValue(token);
@@ -197,13 +213,14 @@ class AppProxy {
197
213
  return responseBuffer;
198
214
  }
199
215
  const isApiBelongMainApp = [this.loginApi, '/open-api/v1.0/current/user'];
200
- if (!this.isMainApp && !isApiBelongMainApp.includes(req.url)) {
216
+ const isMicroAppPage = (_b = req.referer) === null || _b === void 0 ? void 0 : _b.includes('/apps');
217
+ if (!this.isMainApp && isMicroAppPage && !isApiBelongMainApp.includes(req.url)) {
201
218
  const apiPathMatchReg = /\/(:[^/]+|\$?{[^/]+})/g;
202
219
  const apis = mf.apis || [];
203
220
  const microAppId = req.headers['micro-app-id'];
204
221
  if (microAppId && !microAppId.includes('main-app')) {
205
222
  const method = (req === null || req === void 0 ? void 0 : req.method) || 'GET';
206
- const urlPath = ((_b = req === null || req === void 0 ? void 0 : req.path) === null || _b === void 0 ? void 0 : _b.replace(/^\s*\/(custom-api|open-api)/, '')) || '';
223
+ const urlPath = ((_c = req === null || req === void 0 ? void 0 : req.path) === null || _c === void 0 ? void 0 : _c.replace(/^\s*\/(custom-api|open-api)/, '')) || '';
207
224
  let isExists = false;
208
225
  apis.forEach((api) => {
209
226
  const isLegal = new RegExp(`^${api.path.replace(apiPathMatchReg, '/[^/]+')}/?$`).test(urlPath);
@@ -215,6 +232,7 @@ class AppProxy {
215
232
  return JSON.stringify({
216
233
  msg: `${method}:${urlPath} 未在manifest.json中注册`,
217
234
  code: '888888',
235
+ success: false,
218
236
  });
219
237
  }
220
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-proxy",
3
- "version": "3.2.22",
3
+ "version": "3.2.23",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {