@byteplus-iga-pages/cli 0.0.0-stage → 1.1.13
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/LICENSE +21 -0
- package/README.md +290 -2
- package/bin/bp-iga.js +4 -0
- package/dist/functions-runtime.js +12354 -0
- package/dist/functions-runtime.js.LICENSE.txt +1 -0
- package/dist/index.js +721 -0
- package/dist/index.js.LICENSE.txt +161 -0
- package/dist/request-handler.js +458 -0
- package/package.json +26 -4
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Array of passes.
|
|
3
|
+
*
|
|
4
|
+
* A `pass` is just a function that is executed on `req, res, options`
|
|
5
|
+
* so that you can easily add new checks while still keeping the base
|
|
6
|
+
* flexible.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/*!
|
|
10
|
+
* Array of passes.
|
|
11
|
+
*
|
|
12
|
+
* A `pass` is just a function that is executed on `req, socket, options`
|
|
13
|
+
* so that you can easily add new checks while still keeping the base
|
|
14
|
+
* flexible.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*!
|
|
18
|
+
* Caron dimonio, con occhi di bragia
|
|
19
|
+
* loro accennando, tutte le raccoglie;
|
|
20
|
+
* batte col remo qualunque s’adagia
|
|
21
|
+
*
|
|
22
|
+
* Charon the demon, with the eyes of glede,
|
|
23
|
+
* Beckoning to them, collects them all together,
|
|
24
|
+
* Beats with his oar whoever lags behind
|
|
25
|
+
*
|
|
26
|
+
* Dante - The Divine Comedy (Canto III)
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/*!
|
|
30
|
+
* bytes
|
|
31
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
32
|
+
* Copyright(c) 2015 Jed Watson
|
|
33
|
+
* MIT Licensed
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/*!
|
|
37
|
+
* content-disposition
|
|
38
|
+
* Copyright(c) 2014 Douglas Christopher Wilson
|
|
39
|
+
* MIT Licensed
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/*!
|
|
43
|
+
* fill-range <https://github.com/jonschlinkert/fill-range>
|
|
44
|
+
*
|
|
45
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
46
|
+
* Licensed under the MIT License.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/*!
|
|
50
|
+
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
|
51
|
+
*
|
|
52
|
+
* Copyright (c) 2014-2016, Jon Schlinkert.
|
|
53
|
+
* Licensed under the MIT License.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/*!
|
|
57
|
+
* is-glob <https://github.com/jonschlinkert/is-glob>
|
|
58
|
+
*
|
|
59
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
60
|
+
* Released under the MIT License.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/*!
|
|
64
|
+
* is-number <https://github.com/jonschlinkert/is-number>
|
|
65
|
+
*
|
|
66
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
67
|
+
* Released under the MIT License.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/*!
|
|
71
|
+
* mime-db
|
|
72
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
73
|
+
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
74
|
+
* MIT Licensed
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
/*!
|
|
78
|
+
* mime-db
|
|
79
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
80
|
+
* MIT Licensed
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/*!
|
|
84
|
+
* mime-types
|
|
85
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
86
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
87
|
+
* MIT Licensed
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/*!
|
|
91
|
+
* normalize-path <https://github.com/jonschlinkert/normalize-path>
|
|
92
|
+
*
|
|
93
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
|
94
|
+
* Released under the MIT License.
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/*!
|
|
98
|
+
* range-parser
|
|
99
|
+
* Copyright(c) 2012-2014 TJ Holowaychuk
|
|
100
|
+
* Copyright(c) 2015-2016 Douglas Christopher Wilson
|
|
101
|
+
* MIT Licensed
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/*!
|
|
105
|
+
* to-regex-range <https://github.com/micromatch/to-regex-range>
|
|
106
|
+
*
|
|
107
|
+
* Copyright (c) 2015-present, Jon Schlinkert.
|
|
108
|
+
* Released under the MIT License.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com */
|
|
112
|
+
|
|
113
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Archiver Core
|
|
117
|
+
*
|
|
118
|
+
* @ignore
|
|
119
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
120
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Archiver Vending
|
|
125
|
+
*
|
|
126
|
+
* @ignore
|
|
127
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
128
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* JSON Format Plugin
|
|
133
|
+
*
|
|
134
|
+
* @module plugins/json
|
|
135
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
136
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
137
|
+
*/
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* TAR Format Plugin
|
|
141
|
+
*
|
|
142
|
+
* @module plugins/tar
|
|
143
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
144
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* ZIP Format Plugin
|
|
149
|
+
*
|
|
150
|
+
* @module plugins/zip
|
|
151
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
152
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* ZipStream
|
|
157
|
+
*
|
|
158
|
+
* @ignore
|
|
159
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-zip-stream/blob/master/LICENSE}
|
|
160
|
+
* @copyright (c) 2014 Chris Talkington, contributors.
|
|
161
|
+
*/
|
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
// Copyright (c) 2026 BytePlus Pte. Ltd.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
"use strict";
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
stream (module) {
|
|
7
|
+
module.exports = require("stream");
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
31
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: definition[key]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
|
+
})();
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r = (exports1)=>{
|
|
42
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
43
|
+
value: 'Module'
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
(()=>{
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
RequestHandler: ()=>RequestHandler,
|
|
55
|
+
calculateRoutePrefix: ()=>calculateRoutePrefix
|
|
56
|
+
});
|
|
57
|
+
var stream__rspack_import_0 = __webpack_require__("stream");
|
|
58
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
59
|
+
try {
|
|
60
|
+
var info = gen[key](arg);
|
|
61
|
+
var value = info.value;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (info.done) resolve(value);
|
|
67
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
68
|
+
}
|
|
69
|
+
function _async_to_generator(fn) {
|
|
70
|
+
return function() {
|
|
71
|
+
var self = this, args = arguments;
|
|
72
|
+
return new Promise(function(resolve, reject) {
|
|
73
|
+
var gen = fn.apply(self, args);
|
|
74
|
+
function _next(value) {
|
|
75
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
76
|
+
}
|
|
77
|
+
function _throw(err) {
|
|
78
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
79
|
+
}
|
|
80
|
+
_next(void 0);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function _define_property(obj, key, value) {
|
|
85
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
86
|
+
value: value,
|
|
87
|
+
enumerable: true,
|
|
88
|
+
configurable: true,
|
|
89
|
+
writable: true
|
|
90
|
+
});
|
|
91
|
+
else obj[key] = value;
|
|
92
|
+
return obj;
|
|
93
|
+
}
|
|
94
|
+
function _object_spread(target) {
|
|
95
|
+
for(var i = 1; i < arguments.length; i++){
|
|
96
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
97
|
+
var ownKeys = Object.keys(source);
|
|
98
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
99
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
100
|
+
}));
|
|
101
|
+
ownKeys.forEach(function(key) {
|
|
102
|
+
_define_property(target, key, source[key]);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return target;
|
|
106
|
+
}
|
|
107
|
+
class RequestHandler {
|
|
108
|
+
execute(handler, context) {
|
|
109
|
+
return _async_to_generator(function*() {
|
|
110
|
+
const { req, res, params, routePrefix, method } = context;
|
|
111
|
+
const HTTP_METHODS = [
|
|
112
|
+
"GET",
|
|
113
|
+
"POST",
|
|
114
|
+
"PUT",
|
|
115
|
+
"PATCH",
|
|
116
|
+
"DELETE",
|
|
117
|
+
"HEAD",
|
|
118
|
+
"OPTIONS"
|
|
119
|
+
];
|
|
120
|
+
const hasNamedMethodExports = HTTP_METHODS.some((m)=>handler[m] && "function" == typeof handler[m]);
|
|
121
|
+
if (handler[method] && "function" == typeof handler[method]) {
|
|
122
|
+
yield this.handleWeb((request)=>handler[method](request), context);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (hasNamedMethodExports) {
|
|
126
|
+
res.statusCode = 405;
|
|
127
|
+
res.setHeader("Allow", HTTP_METHODS.filter((m)=>handler[m] && "function" == typeof handler[m]).join(", "));
|
|
128
|
+
res.end();
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (handler.fetch && "function" == typeof handler.fetch) {
|
|
132
|
+
yield this.handleWeb((request)=>handler.fetch(request), context);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
if (this.isFrameworkInstance(handler)) {
|
|
136
|
+
yield this.handleFramework(handler, req, res, params, routePrefix);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
if ("function" == typeof handler) {
|
|
140
|
+
yield this.handleLegacy(handler, req, res, params);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}).call(this);
|
|
145
|
+
}
|
|
146
|
+
isFrameworkInstance(handler) {
|
|
147
|
+
if ("function" == typeof handler && (handler.handle || handler._router)) return true;
|
|
148
|
+
if (null !== handler && "object" == typeof handler && "function" == typeof handler.callback && Array.isArray(handler.middleware)) return true;
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
handleFramework(app, req, res, params, routePrefix) {
|
|
152
|
+
return _async_to_generator(function*() {
|
|
153
|
+
req.params = _object_spread({}, req.params, params);
|
|
154
|
+
const originalUrl = req.url || "/";
|
|
155
|
+
if (routePrefix && "/" !== routePrefix) {
|
|
156
|
+
const pathname = originalUrl.split("?")[0];
|
|
157
|
+
const queryString = originalUrl.includes("?") ? originalUrl.substring(originalUrl.indexOf("?")) : "";
|
|
158
|
+
const escapedPrefix = this.escapeRegExp(routePrefix);
|
|
159
|
+
let newPath = pathname.replace(new RegExp(`^${escapedPrefix}`), "") || "/";
|
|
160
|
+
if (!newPath.startsWith("/")) newPath = "/" + newPath;
|
|
161
|
+
req.url = newPath + queryString;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
yield new Promise((resolve, reject)=>{
|
|
165
|
+
const originalEnd = res.end.bind(res);
|
|
166
|
+
res.end = function(...args) {
|
|
167
|
+
originalEnd(...args);
|
|
168
|
+
resolve();
|
|
169
|
+
return res;
|
|
170
|
+
};
|
|
171
|
+
res.on("error", reject);
|
|
172
|
+
try {
|
|
173
|
+
if ("function" == typeof app) app(req, res, (err)=>{
|
|
174
|
+
if (err) reject(err);
|
|
175
|
+
});
|
|
176
|
+
else {
|
|
177
|
+
app.on("error", (err)=>{
|
|
178
|
+
if (err) reject(err);
|
|
179
|
+
});
|
|
180
|
+
app.callback()(req, res);
|
|
181
|
+
}
|
|
182
|
+
} catch (error) {
|
|
183
|
+
reject(error);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
} finally{
|
|
187
|
+
req.url = originalUrl;
|
|
188
|
+
}
|
|
189
|
+
}).call(this);
|
|
190
|
+
}
|
|
191
|
+
handleLegacy(handler, req, res, params) {
|
|
192
|
+
return _async_to_generator(function*() {
|
|
193
|
+
const igaReq = req;
|
|
194
|
+
const igaRes = res;
|
|
195
|
+
const raw = yield this.readRequestBody(req);
|
|
196
|
+
this.restoreBody(req, raw);
|
|
197
|
+
igaReq.query = this.parseQuery(req.url || "");
|
|
198
|
+
igaReq.params = params;
|
|
199
|
+
igaReq.cookies = this.parseCookies(req);
|
|
200
|
+
igaReq.body = this.parseBodyBuffer(raw, req.headers["content-type"], req.method);
|
|
201
|
+
this.enhanceResponse(igaRes);
|
|
202
|
+
yield handler(igaReq, igaRes);
|
|
203
|
+
}).call(this);
|
|
204
|
+
}
|
|
205
|
+
restoreBody(req, body) {
|
|
206
|
+
const pt = new stream__rspack_import_0.PassThrough();
|
|
207
|
+
const on = pt.on.bind(pt);
|
|
208
|
+
const originalOn = req.on.bind(req);
|
|
209
|
+
req.read = pt.read.bind(pt);
|
|
210
|
+
req.on = req.addListener = (name, cb)=>"data" === name || "end" === name ? on(name, cb) : originalOn(name, cb);
|
|
211
|
+
pt.write(body);
|
|
212
|
+
pt.end();
|
|
213
|
+
}
|
|
214
|
+
createWebRequest(_0, _1) {
|
|
215
|
+
return _async_to_generator(function*(req, params = {}, signal) {
|
|
216
|
+
const protocol = "http";
|
|
217
|
+
const host = req.headers.host || "localhost";
|
|
218
|
+
const url = `${protocol}://${host}${req.url}`;
|
|
219
|
+
const requestInit = {
|
|
220
|
+
method: req.method || "GET",
|
|
221
|
+
headers: req.headers,
|
|
222
|
+
signal
|
|
223
|
+
};
|
|
224
|
+
const method = (req.method || "GET").toUpperCase();
|
|
225
|
+
if ([
|
|
226
|
+
"POST",
|
|
227
|
+
"PUT",
|
|
228
|
+
"PATCH"
|
|
229
|
+
].includes(method)) {
|
|
230
|
+
const raw = yield this.readRequestBody(req, signal);
|
|
231
|
+
if (raw.length) requestInit.body = raw;
|
|
232
|
+
}
|
|
233
|
+
const request = new Request(url, requestInit);
|
|
234
|
+
request.params = params;
|
|
235
|
+
return request;
|
|
236
|
+
}).apply(this, arguments);
|
|
237
|
+
}
|
|
238
|
+
sendWebResponse(webResponse, res, signal) {
|
|
239
|
+
return _async_to_generator(function*() {
|
|
240
|
+
var _webResponse_body;
|
|
241
|
+
if (signal.aborted) {
|
|
242
|
+
var _webResponse_body1;
|
|
243
|
+
null == (_webResponse_body1 = webResponse.body) || _webResponse_body1.cancel(signal.reason).catch(()=>void 0);
|
|
244
|
+
signal.throwIfAborted();
|
|
245
|
+
}
|
|
246
|
+
res.statusCode = webResponse.status;
|
|
247
|
+
webResponse.headers.forEach((value, key)=>{
|
|
248
|
+
res.setHeader(key, value);
|
|
249
|
+
});
|
|
250
|
+
const reader = null == (_webResponse_body = webResponse.body) ? void 0 : _webResponse_body.getReader();
|
|
251
|
+
const cancel = ()=>{
|
|
252
|
+
null == reader || reader.cancel(signal.reason).catch(()=>void 0);
|
|
253
|
+
};
|
|
254
|
+
signal.addEventListener("abort", cancel, {
|
|
255
|
+
once: true
|
|
256
|
+
});
|
|
257
|
+
try {
|
|
258
|
+
if (signal.aborted) cancel();
|
|
259
|
+
signal.throwIfAborted();
|
|
260
|
+
if (reader) while(true){
|
|
261
|
+
const { done, value } = yield reader.read();
|
|
262
|
+
signal.throwIfAborted();
|
|
263
|
+
if (done) break;
|
|
264
|
+
yield this.writeWebResponse(res, signal, value);
|
|
265
|
+
}
|
|
266
|
+
yield this.writeWebResponse(res, signal);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
null == reader || reader.cancel(error).catch(()=>void 0);
|
|
269
|
+
throw error;
|
|
270
|
+
} finally{
|
|
271
|
+
signal.removeEventListener("abort", cancel);
|
|
272
|
+
null == reader || reader.releaseLock();
|
|
273
|
+
}
|
|
274
|
+
}).call(this);
|
|
275
|
+
}
|
|
276
|
+
writeWebResponse(res, signal, chunk) {
|
|
277
|
+
return new Promise((resolve, reject)=>{
|
|
278
|
+
const finish = (error)=>{
|
|
279
|
+
res.removeListener("error", onError);
|
|
280
|
+
signal.removeEventListener("abort", onAbort);
|
|
281
|
+
if (error) reject(error);
|
|
282
|
+
else resolve();
|
|
283
|
+
};
|
|
284
|
+
const onError = (error)=>finish(error);
|
|
285
|
+
const onAbort = ()=>finish(signal.reason);
|
|
286
|
+
res.once("error", onError);
|
|
287
|
+
signal.addEventListener("abort", onAbort, {
|
|
288
|
+
once: true
|
|
289
|
+
});
|
|
290
|
+
if (signal.aborted) return onAbort();
|
|
291
|
+
try {
|
|
292
|
+
if (void 0 === chunk) res.end(()=>finish());
|
|
293
|
+
else res.write(chunk, finish);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
finish(error);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
handleWeb(_0, _1) {
|
|
300
|
+
return _async_to_generator(function*(handler, { req, res, params }) {
|
|
301
|
+
const controller = new AbortController();
|
|
302
|
+
const { signal } = controller;
|
|
303
|
+
const onAborted = ()=>controller.abort(new DOMException("Client disconnected", "AbortError"));
|
|
304
|
+
const onError = (error)=>controller.abort(error);
|
|
305
|
+
const onClose = ()=>{
|
|
306
|
+
if (!res.writableFinished) onAborted();
|
|
307
|
+
};
|
|
308
|
+
req.once("aborted", onAborted);
|
|
309
|
+
req.once("error", onError);
|
|
310
|
+
res.once("close", onClose);
|
|
311
|
+
if (req.aborted || res.destroyed) onAborted();
|
|
312
|
+
try {
|
|
313
|
+
signal.throwIfAborted();
|
|
314
|
+
const request = yield this.createWebRequest(req, params, signal);
|
|
315
|
+
signal.throwIfAborted();
|
|
316
|
+
const response = yield handler(request);
|
|
317
|
+
yield this.sendWebResponse(response, res, signal);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
if (signal.aborted && error === signal.reason) return;
|
|
320
|
+
if (res.headersSent && !res.destroyed) {
|
|
321
|
+
res.removeListener("close", onClose);
|
|
322
|
+
res.destroy();
|
|
323
|
+
}
|
|
324
|
+
throw error;
|
|
325
|
+
} finally{
|
|
326
|
+
req.removeListener("aborted", onAborted);
|
|
327
|
+
req.removeListener("error", onError);
|
|
328
|
+
res.removeListener("close", onClose);
|
|
329
|
+
}
|
|
330
|
+
}).apply(this, arguments);
|
|
331
|
+
}
|
|
332
|
+
readRequestBody(req, signal) {
|
|
333
|
+
return new Promise((resolve, reject)=>{
|
|
334
|
+
const chunks = [];
|
|
335
|
+
const cleanup = ()=>{
|
|
336
|
+
req.removeListener("data", onData);
|
|
337
|
+
req.removeListener("end", onEnd);
|
|
338
|
+
req.removeListener("error", onError);
|
|
339
|
+
null == signal || signal.removeEventListener("abort", onAbort);
|
|
340
|
+
};
|
|
341
|
+
const onData = (chunk)=>chunks.push(chunk);
|
|
342
|
+
const onEnd = ()=>{
|
|
343
|
+
cleanup();
|
|
344
|
+
resolve(Buffer.concat(chunks));
|
|
345
|
+
};
|
|
346
|
+
const onError = (error)=>{
|
|
347
|
+
cleanup();
|
|
348
|
+
reject(error);
|
|
349
|
+
};
|
|
350
|
+
const onAbort = ()=>onError(null == signal ? void 0 : signal.reason);
|
|
351
|
+
req.on("data", onData);
|
|
352
|
+
req.once("end", onEnd);
|
|
353
|
+
req.once("error", onError);
|
|
354
|
+
null == signal || signal.addEventListener("abort", onAbort, {
|
|
355
|
+
once: true
|
|
356
|
+
});
|
|
357
|
+
if (null == signal ? void 0 : signal.aborted) onAbort();
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
parseBodyBuffer(raw, contentTypeHeader, method) {
|
|
361
|
+
const verb = (method || "GET").toUpperCase();
|
|
362
|
+
if (![
|
|
363
|
+
"POST",
|
|
364
|
+
"PUT",
|
|
365
|
+
"PATCH"
|
|
366
|
+
].includes(verb)) return;
|
|
367
|
+
if (!raw.length) return;
|
|
368
|
+
const contentType = (contentTypeHeader || "").split(";")[0].trim();
|
|
369
|
+
if ("application/json" === contentType) try {
|
|
370
|
+
return JSON.parse(raw.toString("utf-8"));
|
|
371
|
+
} catch (unused) {
|
|
372
|
+
throw Object.assign(new Error("Invalid JSON body"), {
|
|
373
|
+
statusCode: 400
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
if ("application/x-www-form-urlencoded" === contentType) return Object.fromEntries(new URLSearchParams(raw.toString("utf-8")));
|
|
377
|
+
if ("application/octet-stream" === contentType) return raw;
|
|
378
|
+
return raw.toString("utf-8");
|
|
379
|
+
}
|
|
380
|
+
parseCookies(req) {
|
|
381
|
+
const header = req.headers.cookie;
|
|
382
|
+
if (!header) return {};
|
|
383
|
+
const raw = Array.isArray(header) ? header.join("; ") : header;
|
|
384
|
+
const result = {};
|
|
385
|
+
for (const pair of raw.split(";")){
|
|
386
|
+
const idx = pair.indexOf("=");
|
|
387
|
+
if (idx < 0) continue;
|
|
388
|
+
const key = pair.slice(0, idx).trim();
|
|
389
|
+
const value = pair.slice(idx + 1).trim();
|
|
390
|
+
if (key) result[key] = decodeURIComponent(value);
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
parseQuery(url) {
|
|
395
|
+
const search = url.includes("?") ? url.slice(url.indexOf("?")) : "";
|
|
396
|
+
const sp = new URLSearchParams(search);
|
|
397
|
+
const result = {};
|
|
398
|
+
for (const key of sp.keys()){
|
|
399
|
+
const values = sp.getAll(key);
|
|
400
|
+
result[key] = 1 === values.length ? values[0] : values;
|
|
401
|
+
}
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
escapeRegExp(str) {
|
|
405
|
+
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
|
406
|
+
}
|
|
407
|
+
enhanceResponse(res) {
|
|
408
|
+
res.json = function(data) {
|
|
409
|
+
this.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
410
|
+
this.end(JSON.stringify(data));
|
|
411
|
+
return this;
|
|
412
|
+
};
|
|
413
|
+
res.status = function(code) {
|
|
414
|
+
this.statusCode = code;
|
|
415
|
+
return this;
|
|
416
|
+
};
|
|
417
|
+
res.send = function(data) {
|
|
418
|
+
if ("object" == typeof data && null !== data && !Buffer.isBuffer(data)) return this.json(data);
|
|
419
|
+
if ("string" == typeof data) {
|
|
420
|
+
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
421
|
+
this.end(data);
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
if (Buffer.isBuffer(data)) {
|
|
425
|
+
if (!this.getHeader("Content-Type")) this.setHeader("Content-Type", "application/octet-stream");
|
|
426
|
+
this.end(data);
|
|
427
|
+
return this;
|
|
428
|
+
}
|
|
429
|
+
this.end(String(data));
|
|
430
|
+
return this;
|
|
431
|
+
};
|
|
432
|
+
res.redirect = function(statusOrUrl, url) {
|
|
433
|
+
if ("string" == typeof statusOrUrl) {
|
|
434
|
+
url = statusOrUrl;
|
|
435
|
+
statusOrUrl = 307;
|
|
436
|
+
}
|
|
437
|
+
if ("number" != typeof statusOrUrl || "string" != typeof url) throw new Error("Invalid redirect arguments. Use res.redirect('/url') or res.redirect(301, '/url').");
|
|
438
|
+
this.writeHead(statusOrUrl, {
|
|
439
|
+
Location: url
|
|
440
|
+
}).end();
|
|
441
|
+
return this;
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function calculateRoutePrefix(route) {
|
|
446
|
+
const prefix = route.replace(/\/\[\[.*?\]\]$/, "");
|
|
447
|
+
return prefix || "/";
|
|
448
|
+
}
|
|
449
|
+
})();
|
|
450
|
+
exports.RequestHandler = __webpack_exports__.RequestHandler;
|
|
451
|
+
exports.calculateRoutePrefix = __webpack_exports__.calculateRoutePrefix;
|
|
452
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
453
|
+
"RequestHandler",
|
|
454
|
+
"calculateRoutePrefix"
|
|
455
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
456
|
+
Object.defineProperty(exports, '__esModule', {
|
|
457
|
+
value: true
|
|
458
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byteplus-iga-pages/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.13",
|
|
4
|
+
"description": "A CLI tool for BytePlus IGA Pages",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"bp-iga": "./bin/bp-iga.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"iga-pages",
|
|
15
|
+
"cli",
|
|
16
|
+
"deployment",
|
|
17
|
+
"full-stack",
|
|
18
|
+
"ai-agent"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"esbuild": "^0.19.11"
|
|
27
|
+
}
|
|
28
|
+
}
|