@tuya-sat/micro-script 3.1.7 → 3.2.0

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.
@@ -1,2 +1,7 @@
1
1
  import { Express } from 'express';
2
- export default function mockSaasInfo(app: Express, microPort: number): void;
2
+ import AppProxy from "@tuya-sat/micro-dev-proxy/dist/appProxy";
3
+ interface IApp extends Express {
4
+ __appProxy__?: AppProxy;
5
+ }
6
+ export default function mockSaasInfo(app: IApp, microPort: number): void;
7
+ export {};
@@ -46,6 +46,7 @@ const axios_1 = __importDefault(require("axios"));
46
46
  function mockSaasInfo(app, microPort) {
47
47
  let { multiApps, microApps, debuggerConfig: { isMainApp, target }, } = require(paths_1.default.microConfig);
48
48
  const idsMap = new Map();
49
+ const expressApp = app;
49
50
  multiApps = (0, utils_1.processMultiApps)(multiApps);
50
51
  if (isMainApp && fs_extra_1.default.existsSync(path.join(process.cwd(), 'apps'))) {
51
52
  const dirs = ((microApps === null || microApps === void 0 ? void 0 : microApps.length) > 0 && microApps) ||
@@ -93,7 +94,7 @@ function mockSaasInfo(app, microPort) {
93
94
  multiApps === null || multiApps === void 0 ? void 0 : multiApps.forEach((app) => {
94
95
  idsMap.set(app.name, { entry_id: (0, uuid_1.v4)(), oem_micro_app_id: (0, uid_1.uid)(16) });
95
96
  });
96
- app.get('/api/saas-info', (req, res) => {
97
+ app.get('/api/saas-info', (req, res) => __awaiter(this, void 0, void 0, function* () {
97
98
  const lang = parseCookie(req.headers['cookie'], 'main-i18next');
98
99
  if ((0, utils_1.isMonorepo)() || (multiApps && multiApps.length > 0)) {
99
100
  const result = {
@@ -132,7 +133,21 @@ function mockSaasInfo(app, microPort) {
132
133
  const entry_id = (0, uuid_1.v4)();
133
134
  const oem_micro_app_id = manifest.universalId;
134
135
  const baseUrl = `/apps/${oem_micro_app_id}`;
135
- const app = consturctApp(manifest, oem_micro_app_id, baseUrl, lang, microPort);
136
+ const saasApps = yield refactorConstructApp({
137
+ url: target,
138
+ headers: {
139
+ cookie: expressApp.__appProxy__.getCookie(''),
140
+ csrf: expressApp.__appProxy__.csrfValue.value,
141
+ }
142
+ }, [
143
+ {
144
+ manifest,
145
+ oem_micro_app_id,
146
+ baseUrl,
147
+ lang,
148
+ port: microPort
149
+ }
150
+ ]);
136
151
  const entryInfo = consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, '');
137
152
  const permission = consturctPermissions();
138
153
  res.send({
@@ -140,7 +155,7 @@ function mockSaasInfo(app, microPort) {
140
155
  errorMsg: null,
141
156
  msg: null,
142
157
  result: {
143
- apps: [app],
158
+ apps: saasApps,
144
159
  entry_info: { entries: [entryInfo], entry_mode: 'normal' },
145
160
  permissions: { [oem_micro_app_id]: permission },
146
161
  saas_id_info_list: [
@@ -150,7 +165,7 @@ function mockSaasInfo(app, microPort) {
150
165
  success: true,
151
166
  });
152
167
  }
153
- });
168
+ }));
154
169
  }
155
170
  }
156
171
  exports.default = mockSaasInfo;
@@ -188,24 +203,40 @@ function consturctEntry(manifest, oem_micro_app_id, entry_id, baseUrl, lang, dir
188
203
  }
189
204
  return fakeMenu;
190
205
  }
191
- function refactorConstructApp(saasUrl, localApps) {
206
+ function refactorConstructApp(config, localApps) {
192
207
  var _a;
193
208
  return __awaiter(this, void 0, void 0, function* () {
194
209
  const saasAppsMap = {};
195
210
  try {
196
- const res = yield axios_1.default.get(new URL('/api/saas-info', saasUrl).href);
211
+ const res = yield axios_1.default.get(new URL('/api/saas-info', config.url).href, {
212
+ headers: config.headers,
213
+ });
197
214
  (_a = res.data.result.apps) === null || _a === void 0 ? void 0 : _a.forEach((app) => {
198
215
  saasAppsMap[app.universal_id] = app;
199
216
  });
200
217
  }
201
218
  catch (e) {
202
- console.error('获取 SaaS 信息失败,尝试使用假数据模拟 APP 信息');
219
+ console.error('\n获取 SaaS 信息失败,尝试使用假数据模拟 APP 信息\n');
203
220
  }
204
221
  const packageInfo = (0, micro_utils_1.getPackage)();
205
222
  return localApps.map((app) => {
206
223
  const uuid = app.manifest.universalId;
207
224
  const code = app.code || `${packageInfo.name}`;
208
- return Object.assign(Object.assign({}, saasAppsMap[app.oem_micro_app_id]), { active_rule: app.baseUrl, micro_app_code: code, micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`, micro_app_version: '0.0.0-x', oem_micro_app_id: app.oem_micro_app_id, resource: `http://localhost:${app.port}/${code || 'index'}.html`, universal_id: uuid, isAuth: true, schema: null });
225
+ const appInfo = saasAppsMap[app.oem_micro_app_id];
226
+ return {
227
+ ext_info: appInfo === null || appInfo === void 0 ? void 0 : appInfo.ext_info,
228
+ micro_app_config: appInfo.micro_app_config,
229
+ lang_package_biz_id: appInfo.lang_package_biz_id,
230
+ active_rule: app.baseUrl,
231
+ micro_app_code: code,
232
+ micro_app_name: code ? `${code}-dev` : `${packageInfo.name}-dev`,
233
+ micro_app_version: '0.0.0-x',
234
+ oem_micro_app_id: app.oem_micro_app_id,
235
+ resource: `http://localhost:${app.port}/${code || 'index'}.html`,
236
+ universal_id: uuid,
237
+ isAuth: true,
238
+ schema: null,
239
+ };
209
240
  });
210
241
  });
211
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-script",
3
- "version": "3.1.7",
3
+ "version": "3.2.0",
4
4
  "bin": "./dist/bin/cli.js",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -23,9 +23,9 @@
23
23
  "@babel/preset-typescript": "7.16.7",
24
24
  "@babel/traverse": "^7.20.13",
25
25
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
26
- "@tuya-sat/micro-dev-loader": "3.1.7",
27
- "@tuya-sat/micro-dev-proxy": "3.1.7",
28
- "@tuya-sat/micro-utils": "3.1.7",
26
+ "@tuya-sat/micro-dev-loader": "3.2.0",
27
+ "@tuya-sat/micro-dev-proxy": "3.2.0",
28
+ "@tuya-sat/micro-utils": "3.2.0",
29
29
  "@types/kill-port": "^2.0.0",
30
30
  "babel-loader": "8.2.4",
31
31
  "babel-plugin-import": "1.13.3",