@orkestrel/middleware 0.0.20 → 0.0.21
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/src/core/index.cjs +27 -27
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.js +28 -28
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +6 -6
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.js +6 -6
- package/dist/src/server/index.js.map +1 -1
- package/package.json +16 -16
package/dist/src/core/index.cjs
CHANGED
|
@@ -199,11 +199,11 @@ function matchesTrustedEntry(address, entry) {
|
|
|
199
199
|
const networkParts = network.split(".");
|
|
200
200
|
const addressParts = address.split(".");
|
|
201
201
|
if (networkParts.length !== 4 || addressParts.length !== 4) return false;
|
|
202
|
-
if (!
|
|
202
|
+
if (!(0, _orkestrel_contract.isInteger)(bits) || bits < 8 || bits > 32) return false;
|
|
203
203
|
const networkOctets = networkParts.map(Number);
|
|
204
204
|
const addressOctets = addressParts.map(Number);
|
|
205
|
-
if (networkOctets.some((value) => !
|
|
206
|
-
if (addressOctets.some((value) => !
|
|
205
|
+
if (networkOctets.some((value) => !(0, _orkestrel_contract.isInteger)(value) || value < 0 || value > 255)) return false;
|
|
206
|
+
if (addressOctets.some((value) => !(0, _orkestrel_contract.isInteger)(value) || value < 0 || value > 255)) return false;
|
|
207
207
|
const networkInt = (networkOctets[0] ?? 0) << 24 | (networkOctets[1] ?? 0) << 16 | (networkOctets[2] ?? 0) << 8 | (networkOctets[3] ?? 0);
|
|
208
208
|
const addressInt = (addressOctets[0] ?? 0) << 24 | (addressOctets[1] ?? 0) << 16 | (addressOctets[2] ?? 0) << 8 | (addressOctets[3] ?? 0);
|
|
209
209
|
const mask = bits === 32 ? -1 : ~((1 << 32 - bits) - 1);
|
|
@@ -438,7 +438,7 @@ async function compressResponse(request, context, response, options) {
|
|
|
438
438
|
const declaredLength = response.headers.get("content-length");
|
|
439
439
|
if (declaredLength !== null) {
|
|
440
440
|
const declared = Number(declaredLength);
|
|
441
|
-
if (
|
|
441
|
+
if ((0, _orkestrel_contract.isFiniteNumber)(declared) && declared < options.threshold) return response;
|
|
442
442
|
}
|
|
443
443
|
const buffer = await response.arrayBuffer();
|
|
444
444
|
if (buffer.byteLength < options.threshold) return rebuildResponse(buffer, response);
|
|
@@ -608,14 +608,14 @@ function snapshotSession(session) {
|
|
|
608
608
|
* ```
|
|
609
609
|
*/
|
|
610
610
|
function isSession(value) {
|
|
611
|
-
if (
|
|
611
|
+
if (!(0, _orkestrel_contract.isObject)(value)) return false;
|
|
612
612
|
const id = Reflect.get(value, "id");
|
|
613
613
|
const state = Reflect.get(value, "state");
|
|
614
|
-
if (!(0, _orkestrel_contract.isString)(id) || !(state
|
|
614
|
+
if (!(0, _orkestrel_contract.isString)(id) || !(0, _orkestrel_contract.isInstance)(state, Map)) return false;
|
|
615
615
|
const set = Reflect.get(value, "set");
|
|
616
616
|
const remove = Reflect.get(value, "delete");
|
|
617
617
|
const clear = Reflect.get(value, "clear");
|
|
618
|
-
return
|
|
618
|
+
return (0, _orkestrel_contract.isFunction)(set) && (0, _orkestrel_contract.isFunction)(remove) && (0, _orkestrel_contract.isFunction)(clear);
|
|
619
619
|
}
|
|
620
620
|
/**
|
|
621
621
|
* Determines whether a value implements {@link SessionControlInterface} — a
|
|
@@ -631,7 +631,7 @@ function isSession(value) {
|
|
|
631
631
|
*/
|
|
632
632
|
function isSessionControl(value) {
|
|
633
633
|
if (!(0, _orkestrel_contract.isRecord)(value)) return false;
|
|
634
|
-
return
|
|
634
|
+
return (0, _orkestrel_contract.isFunction)(value.regenerate) && (0, _orkestrel_contract.isFunction)(value.destroy);
|
|
635
635
|
}
|
|
636
636
|
/**
|
|
637
637
|
* Determines whether a value is one staged {@link MultipartFile} record — a
|
|
@@ -655,7 +655,7 @@ function isSessionControl(value) {
|
|
|
655
655
|
*/
|
|
656
656
|
function isMultipartFile(value) {
|
|
657
657
|
if (!(0, _orkestrel_contract.isRecord)(value)) return false;
|
|
658
|
-
return (0, _orkestrel_contract.isString)(value.field) && (0, _orkestrel_contract.isString)(value.name) &&
|
|
658
|
+
return (0, _orkestrel_contract.isString)(value.field) && (0, _orkestrel_contract.isString)(value.name) && (0, _orkestrel_contract.isNumber)(value.size) && (0, _orkestrel_contract.isString)(value.mime) && (0, _orkestrel_contract.isBoolean)(value.validated) && (0, _orkestrel_contract.isString)(value.status) && (0, _orkestrel_contract.isString)(value.path);
|
|
659
659
|
}
|
|
660
660
|
/**
|
|
661
661
|
* Determines whether a value implements {@link MultipartBody} — a total
|
|
@@ -674,7 +674,7 @@ function isMultipartBody(value) {
|
|
|
674
674
|
if (!(0, _orkestrel_contract.isRecord)(value)) return false;
|
|
675
675
|
if (!(0, _orkestrel_contract.isRecord)(value.files) || !(0, _orkestrel_contract.isRecord)(value.fields)) return false;
|
|
676
676
|
for (const entries of Object.values(value.files)) {
|
|
677
|
-
if (!
|
|
677
|
+
if (!(0, _orkestrel_contract.isArray)(entries)) return false;
|
|
678
678
|
for (const entry of entries) if (!isMultipartFile(entry)) return false;
|
|
679
679
|
}
|
|
680
680
|
for (const fieldValue of Object.values(value.fields)) if (!(0, _orkestrel_contract.isString)(fieldValue)) return false;
|
|
@@ -791,7 +791,7 @@ var MemorySessionStore = class {
|
|
|
791
791
|
#evict;
|
|
792
792
|
constructor(options) {
|
|
793
793
|
validateSessionLimits(options);
|
|
794
|
-
if (options?.capacity !== void 0 && (!(0, _orkestrel_contract.
|
|
794
|
+
if (options?.capacity !== void 0 && (!(0, _orkestrel_contract.isInteger)(options.capacity) || options.capacity <= 0)) throw new TypeError("MemorySessionStore requires options.capacity to be a positive integer when provided");
|
|
795
795
|
if (options?.evict !== void 0 && !(0, _orkestrel_contract.isFunction)(options.evict)) throw new TypeError("MemorySessionStore requires options.evict to be a function when provided");
|
|
796
796
|
this.#entries = /* @__PURE__ */ new Map();
|
|
797
797
|
this.#ttl = options?.ttl;
|
|
@@ -977,7 +977,7 @@ function createBoundary(options) {
|
|
|
977
977
|
report(error);
|
|
978
978
|
} catch {}
|
|
979
979
|
if ((0, _orkestrel_server.isHTTPError)(error)) return new Response(error.message, { status: error.status });
|
|
980
|
-
const message = expose ? error
|
|
980
|
+
const message = expose ? (0, _orkestrel_contract.isError)(error) ? error.message : String(error) : "internal server error";
|
|
981
981
|
return new Response(message, { status: 500 });
|
|
982
982
|
}
|
|
983
983
|
};
|
|
@@ -1036,7 +1036,7 @@ function createTelemetry(options) {
|
|
|
1036
1036
|
function createCompression(options) {
|
|
1037
1037
|
if (options?.threshold !== void 0 && (!(0, _orkestrel_contract.isFiniteNumber)(options.threshold) || options.threshold < 0)) throw new TypeError("CompressionOptions.threshold must be a finite number when provided");
|
|
1038
1038
|
if (options?.filter !== void 0 && !(0, _orkestrel_contract.isFunction)(options.filter)) throw new TypeError("CompressionOptions.filter must be a function when provided");
|
|
1039
|
-
if (options?.encodings !== void 0 && !
|
|
1039
|
+
if (options?.encodings !== void 0 && !(0, _orkestrel_contract.isArray)(options.encodings)) throw new TypeError("CompressionOptions.encodings must be an array when provided");
|
|
1040
1040
|
const threshold = options?.threshold ?? 1024;
|
|
1041
1041
|
const encodings = detectEncodings(options?.encodings ?? DEFAULT_COMPRESSION_ENCODINGS);
|
|
1042
1042
|
const filter = options?.filter;
|
|
@@ -1127,13 +1127,13 @@ function createSecurity(options) {
|
|
|
1127
1127
|
* ```
|
|
1128
1128
|
*/
|
|
1129
1129
|
function createCors(options) {
|
|
1130
|
-
if (options?.origin !== void 0 && !(0, _orkestrel_contract.isString)(options.origin) && !
|
|
1131
|
-
if (options?.methods !== void 0 && !
|
|
1132
|
-
if (options?.headers !== void 0 && !
|
|
1130
|
+
if (options?.origin !== void 0 && !(0, _orkestrel_contract.isString)(options.origin) && !(0, _orkestrel_contract.isArray)(options.origin)) throw new TypeError("CorsOptions.origin must be a string or string array when provided");
|
|
1131
|
+
if (options?.methods !== void 0 && !(0, _orkestrel_contract.isArray)(options.methods)) throw new TypeError("CorsOptions.methods must be an array when provided");
|
|
1132
|
+
if (options?.headers !== void 0 && !(0, _orkestrel_contract.isArray)(options.headers)) throw new TypeError("CorsOptions.headers must be an array when provided");
|
|
1133
1133
|
const origin = options?.origin ?? "*";
|
|
1134
1134
|
const methods = options?.methods ?? DEFAULT_CORS_METHODS;
|
|
1135
1135
|
const headers = options?.headers ?? DEFAULT_CORS_HEADERS;
|
|
1136
|
-
const reflecting =
|
|
1136
|
+
const reflecting = (0, _orkestrel_contract.isArray)(origin);
|
|
1137
1137
|
return async (request, context, next) => {
|
|
1138
1138
|
const requestOrigin = request.headers.get("origin") ?? void 0;
|
|
1139
1139
|
const allowOrigin = (0, _orkestrel_server.resolveOrigin)(origin, requestOrigin);
|
|
@@ -1219,10 +1219,10 @@ function createForwarded(options) {
|
|
|
1219
1219
|
if (!(0, _orkestrel_contract.isRecord)(options) || hasProxies === hasTrusted) throw new TypeError("ForwardedOptions requires exactly one of proxies or trusted");
|
|
1220
1220
|
if (hasProxies) {
|
|
1221
1221
|
const proxies = options.proxies;
|
|
1222
|
-
if (!(0, _orkestrel_contract.
|
|
1222
|
+
if (!(0, _orkestrel_contract.isInteger)(proxies) || proxies < 1) throw new TypeError("ForwardedOptions.proxies must be a positive integer");
|
|
1223
1223
|
} else {
|
|
1224
1224
|
const trusted = options.trusted;
|
|
1225
|
-
if (!
|
|
1225
|
+
if (!(0, _orkestrel_contract.isArray)(trusted)) throw new TypeError("ForwardedOptions.trusted must be an array when provided");
|
|
1226
1226
|
}
|
|
1227
1227
|
const trust = hasProxies ? { proxies: options.proxies } : { trusted: options.trusted };
|
|
1228
1228
|
return async (request, context, next) => {
|
|
@@ -1285,7 +1285,7 @@ function createETag(options) {
|
|
|
1285
1285
|
* ```
|
|
1286
1286
|
*/
|
|
1287
1287
|
function createBearer(options) {
|
|
1288
|
-
if (!(0, _orkestrel_contract.isString)(options.secret) && (!
|
|
1288
|
+
if (!(0, _orkestrel_contract.isString)(options.secret) && (!(0, _orkestrel_contract.isArray)(options.secret) || !options.secret.every(_orkestrel_contract.isString))) throw new TypeError("BearerOptions.secret must be a string or string array");
|
|
1289
1289
|
if (options.header !== void 0 && !(0, _orkestrel_contract.isString)(options.header)) throw new TypeError("BearerOptions.header must be a string when provided");
|
|
1290
1290
|
if (options.scheme !== void 0 && !(0, _orkestrel_contract.isString)(options.scheme)) throw new TypeError("BearerOptions.scheme must be a string when provided");
|
|
1291
1291
|
const secret = options.secret;
|
|
@@ -1321,9 +1321,9 @@ function createBearer(options) {
|
|
|
1321
1321
|
* ```
|
|
1322
1322
|
*/
|
|
1323
1323
|
function createLimiter(options) {
|
|
1324
|
-
if (!(0, _orkestrel_contract.
|
|
1324
|
+
if (!(0, _orkestrel_contract.isInteger)(options.max) || options.max <= 0) throw new TypeError("LimiterOptions.max must be a positive integer");
|
|
1325
1325
|
if (!(0, _orkestrel_contract.isFiniteNumber)(options.window) || options.window <= 0) throw new TypeError("LimiterOptions.window must be a positive finite number");
|
|
1326
|
-
if (options.capacity !== void 0 && (!(0, _orkestrel_contract.
|
|
1326
|
+
if (options.capacity !== void 0 && (!(0, _orkestrel_contract.isInteger)(options.capacity) || options.capacity <= 0)) throw new TypeError("LimiterOptions.capacity must be a positive integer when provided");
|
|
1327
1327
|
if (options.key !== void 0 && !(0, _orkestrel_contract.isFunction)(options.key)) throw new TypeError("LimiterOptions.key must be a function when provided");
|
|
1328
1328
|
if (options.message !== void 0 && !(0, _orkestrel_contract.isString)(options.message)) throw new TypeError("LimiterOptions.message must be a string when provided");
|
|
1329
1329
|
if (options.clock !== void 0 && !(0, _orkestrel_contract.isFunction)(options.clock)) throw new TypeError("LimiterOptions.clock must be a function when provided");
|
|
@@ -1513,11 +1513,11 @@ function createSession(options) {
|
|
|
1513
1513
|
* ```
|
|
1514
1514
|
*/
|
|
1515
1515
|
function createCSRF(options) {
|
|
1516
|
-
if (!(0, _orkestrel_contract.isString)(options.secret) && (!
|
|
1516
|
+
if (!(0, _orkestrel_contract.isString)(options.secret) && (!(0, _orkestrel_contract.isArray)(options.secret) || !options.secret.every(_orkestrel_contract.isString))) throw new TypeError("CSRFOptions.secret must be a string or string array");
|
|
1517
1517
|
if (options.cookie !== void 0 && !(0, _orkestrel_contract.isString)(options.cookie)) throw new TypeError("CSRFOptions.cookie must be a string when provided");
|
|
1518
1518
|
if (options.header !== void 0 && !(0, _orkestrel_contract.isString)(options.header)) throw new TypeError("CSRFOptions.header must be a string when provided");
|
|
1519
1519
|
if (options.field !== void 0 && !(0, _orkestrel_contract.isString)(options.field)) throw new TypeError("CSRFOptions.field must be a string when provided");
|
|
1520
|
-
if (options.safe !== void 0 && !
|
|
1520
|
+
if (options.safe !== void 0 && !(0, _orkestrel_contract.isArray)(options.safe)) throw new TypeError("CSRFOptions.safe must be an array when provided");
|
|
1521
1521
|
const secret = options.secret;
|
|
1522
1522
|
const cookieName = options.cookie ?? "csrf";
|
|
1523
1523
|
const header = options.header ?? "x-csrf-token";
|
|
@@ -1570,7 +1570,7 @@ function createCSRF(options) {
|
|
|
1570
1570
|
* ```
|
|
1571
1571
|
*/
|
|
1572
1572
|
function only(paths, handler) {
|
|
1573
|
-
const matches = new Set(
|
|
1573
|
+
const matches = new Set((0, _orkestrel_contract.isString)(paths) ? [paths] : paths);
|
|
1574
1574
|
return async (request, context, next) => {
|
|
1575
1575
|
if (matches.has(context.url.pathname)) return handler(request, context, next);
|
|
1576
1576
|
return next();
|
|
@@ -1591,7 +1591,7 @@ function only(paths, handler) {
|
|
|
1591
1591
|
* ```
|
|
1592
1592
|
*/
|
|
1593
1593
|
function except(paths, handler) {
|
|
1594
|
-
const matches = new Set(
|
|
1594
|
+
const matches = new Set((0, _orkestrel_contract.isString)(paths) ? [paths] : paths);
|
|
1595
1595
|
return async (request, context, next) => {
|
|
1596
1596
|
if (matches.has(context.url.pathname)) return next();
|
|
1597
1597
|
return handler(request, context, next);
|
|
@@ -1613,7 +1613,7 @@ function except(paths, handler) {
|
|
|
1613
1613
|
* ```
|
|
1614
1614
|
*/
|
|
1615
1615
|
function createCookieTransport(options) {
|
|
1616
|
-
if (!(0, _orkestrel_contract.isString)(options.secret) && (!
|
|
1616
|
+
if (!(0, _orkestrel_contract.isString)(options.secret) && (!(0, _orkestrel_contract.isArray)(options.secret) || !options.secret.every(_orkestrel_contract.isString))) throw new TypeError("CookieTransportOptions.secret must be a string or string array");
|
|
1617
1617
|
if (options.name !== void 0 && !(0, _orkestrel_contract.isString)(options.name)) throw new TypeError("CookieTransportOptions.name must be a string when provided");
|
|
1618
1618
|
const name = options.name ?? "session";
|
|
1619
1619
|
const secret = options.secret;
|