@cequrebackends/cequre-ts 0.12.0 → 0.12.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.
|
@@ -65,11 +65,11 @@ export declare function createBunWebSocketRoute({ path, heartbeat, onJoinRoom, }
|
|
|
65
65
|
timeout?: number;
|
|
66
66
|
} | false;
|
|
67
67
|
onJoinRoom?: (room: string, ws: CequreServerWebSocket) => MaybePromise<boolean>;
|
|
68
|
-
}): (request: Request, server
|
|
68
|
+
}): (request: Request, server?: any) => Promise<any>;
|
|
69
69
|
export declare function createBunWebSocketHandlers(): Bun.WebSocketHandler<CequreWebSocketData>;
|
|
70
70
|
export declare class CequreWebsocket {
|
|
71
71
|
static get manager(): WebSocketManager;
|
|
72
|
-
static route(options?: Parameters<typeof createBunWebSocketRoute>[0]): (request: Request, server
|
|
72
|
+
static route(options?: Parameters<typeof createBunWebSocketRoute>[0]): (request: Request, server?: any) => Promise<any>;
|
|
73
73
|
static handler(options?: Parameters<typeof createWebSocketHandler>[0]): CequreWebSocketHandler;
|
|
74
74
|
static handlers(): Bun.WebSocketHandler<CequreWebSocketData>;
|
|
75
75
|
static register(ws: CequreServerWebSocket): void;
|
|
@@ -45,6 +45,7 @@ class BunServerProvider {
|
|
|
45
45
|
tls: finalTls,
|
|
46
46
|
...config.maxRequestBodySize ? { maxRequestBodySize: config.maxRequestBodySize } : {},
|
|
47
47
|
...config.routes ? { routes: config.routes } : {},
|
|
48
|
+
websocket: config.websocket,
|
|
48
49
|
fetch: config.fetch
|
|
49
50
|
});
|
|
50
51
|
console.log(`\uD83D\uDE80 Cequre starting on http://${this.server.hostname}:${this.server.port}`);
|
|
@@ -381,7 +382,7 @@ function createBunWebSocketRoute({
|
|
|
381
382
|
}
|
|
382
383
|
});
|
|
383
384
|
if (didUpgrade) {
|
|
384
|
-
return;
|
|
385
|
+
return UPGRADED;
|
|
385
386
|
}
|
|
386
387
|
return new Response(JSON.stringify({ message: "WebSocket upgrade failed" }), { status: 400 });
|
|
387
388
|
};
|
package/dist/index.js
CHANGED
|
@@ -1449,12 +1449,12 @@ async function populateDocuments(schema, collectionSlug, docs, adapter, depth) {
|
|
|
1449
1449
|
// shared/main/runtime.ts
|
|
1450
1450
|
init_openapi();
|
|
1451
1451
|
init_kv();
|
|
1452
|
-
import { RateLimiter } from "@cequrebackends/
|
|
1452
|
+
import { RateLimiter } from "@cequrebackends/plugin-security";
|
|
1453
1453
|
init_logger();
|
|
1454
1454
|
import path from "path";
|
|
1455
1455
|
import { AsyncLocalStorage } from "async_hooks";
|
|
1456
|
-
import { computeAuditHmac, verifyAuditChain } from "@cequrebackends/
|
|
1457
|
-
import { encryptField, decryptField, isEncrypted } from "@cequrebackends/
|
|
1456
|
+
import { computeAuditHmac, verifyAuditChain } from "@cequrebackends/plugin-security";
|
|
1457
|
+
import { encryptField, decryptField, isEncrypted } from "@cequrebackends/plugin-security";
|
|
1458
1458
|
|
|
1459
1459
|
// shared/utils/crypto.ts
|
|
1460
1460
|
async function sha256Hex(input) {
|
|
@@ -2022,7 +2022,7 @@ class CequreRuntime {
|
|
|
2022
2022
|
}
|
|
2023
2023
|
return checkSecureChannel(room, req, user);
|
|
2024
2024
|
};
|
|
2025
|
-
this.router.get(`${prefix}/ws`, async (ctx) => this.realtimeProvider?.websocket?.route?.({ path: `${prefix}/ws`, onJoinRoom })(ctx.request,
|
|
2025
|
+
this.router.get(`${prefix}/ws`, async (ctx) => this.realtimeProvider?.websocket?.route?.({ path: `${prefix}/ws`, onJoinRoom })(ctx.request, ctx.state));
|
|
2026
2026
|
this.router.get(`${prefix}/sse`, async (ctx) => {
|
|
2027
2027
|
const resolveUser = async (request) => {
|
|
2028
2028
|
const reqCtx = await this.getContext(request);
|
|
@@ -2881,6 +2881,7 @@ class CequreRuntime {
|
|
|
2881
2881
|
},
|
|
2882
2882
|
maxBodyBytes: this.schema.core?.api?.maxBodyBytes,
|
|
2883
2883
|
idempotencyKV: this.idempotencyKV,
|
|
2884
|
+
state: (server2) => server2,
|
|
2884
2885
|
headers: {
|
|
2885
2886
|
...this.schema.security?.headers?.enabled ? {
|
|
2886
2887
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -2939,7 +2940,7 @@ class CequreRuntime {
|
|
|
2939
2940
|
tls: finalTls,
|
|
2940
2941
|
...maxRequestBodySize ? { maxRequestBodySize } : {},
|
|
2941
2942
|
routes: nativeRoutes,
|
|
2942
|
-
fetch: async (req) => {
|
|
2943
|
+
fetch: async (req, srv) => {
|
|
2943
2944
|
if (this.shuttingDown) {
|
|
2944
2945
|
return new Response("Service Unavailable", { status: 503, headers: { Connection: "close" } });
|
|
2945
2946
|
}
|
|
@@ -2968,8 +2969,8 @@ class CequreRuntime {
|
|
|
2968
2969
|
await plugin.beforeRequest(ctx);
|
|
2969
2970
|
}
|
|
2970
2971
|
let executionPromise = (async () => {
|
|
2971
|
-
let r2 = await this.router.handle(req,
|
|
2972
|
-
return r2
|
|
2972
|
+
let r2 = await this.router.handle(req, srv, ctx.user, this);
|
|
2973
|
+
return r2;
|
|
2973
2974
|
})();
|
|
2974
2975
|
const timeoutMs = this.schema.core?.api?.requestTimeoutMs;
|
|
2975
2976
|
let timeoutHandle;
|
|
@@ -2984,7 +2985,7 @@ class CequreRuntime {
|
|
|
2984
2985
|
}
|
|
2985
2986
|
let res = await executionPromise;
|
|
2986
2987
|
for (const plugin of this.plugins) {
|
|
2987
|
-
if (plugin.afterRequest)
|
|
2988
|
+
if (plugin.afterRequest && res)
|
|
2988
2989
|
await plugin.afterRequest(ctx, res);
|
|
2989
2990
|
}
|
|
2990
2991
|
return res;
|
|
@@ -13,7 +13,7 @@ export interface DurableStreamStore {
|
|
|
13
13
|
* In-memory implementation of DurableStreamStore.
|
|
14
14
|
* [Development Only] This uses a local array ring buffer.
|
|
15
15
|
* It does not scale across multiple servers and loses data on restart.
|
|
16
|
-
* Use @cequrebackends/
|
|
16
|
+
* Use @cequrebackends/plugin-durable-streams for production.
|
|
17
17
|
*/
|
|
18
18
|
export declare class MemoryStreamStore implements DurableStreamStore {
|
|
19
19
|
private streams;
|
|
@@ -2,7 +2,7 @@ import type { TSchema, Static } from "@sinclair/typebox";
|
|
|
2
2
|
import type { CequreRuntime } from "./runtime";
|
|
3
3
|
import type { CequreRouteContext, CequreParams, CequreQuery } from "../core/request";
|
|
4
4
|
import { type BunRouteResult } from "../../adapters/bun/bun-response";
|
|
5
|
-
import type { CequreMonitoringAPI } from "@cequrebackends/
|
|
5
|
+
import type { CequreMonitoringAPI } from "@cequrebackends/plugin-monitoring";
|
|
6
6
|
export type CequreRouteHandler<TCollections extends Record<string, any> = any, TState = unknown, TParams extends TSchema | undefined = undefined, TQuery extends TSchema | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined> = (context: CequreRouteContext<TCollections, TState, TParams extends TSchema ? Static<TParams> : CequreParams, TQuery extends TSchema ? Static<TQuery> : CequreQuery, TBody extends TSchema ? Static<TBody> : unknown>) => TResponse extends TSchema ? BunRouteResult<Static<TResponse>> | Promise<BunRouteResult<Static<TResponse>>> : BunRouteResult | Promise<BunRouteResult>;
|
|
7
7
|
export interface CequreRouteOptions<TParams extends TSchema | undefined = undefined, TQuery extends TSchema | undefined = undefined, TBody extends TSchema | undefined = undefined, TResponse extends TSchema | undefined = undefined> {
|
|
8
8
|
body?: TBody;
|
|
@@ -4,12 +4,12 @@ import { type DurableStreamStore } from "../core/stream";
|
|
|
4
4
|
import type { AccessRules, AuthUser, CequreRequestContext } from "./access";
|
|
5
5
|
import type { Hooks } from "./hooks";
|
|
6
6
|
import { CequreRouter } from "./router";
|
|
7
|
-
import { type CequreMonitoringAPI } from "@cequrebackends/
|
|
8
|
-
import { RateLimiter } from "@cequrebackends/
|
|
7
|
+
import { type CequreMonitoringAPI } from "@cequrebackends/plugin-monitoring";
|
|
8
|
+
import { RateLimiter } from "@cequrebackends/plugin-security";
|
|
9
9
|
import { type CequreMailer } from "../core/email";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
|
-
import { JWTAuthenticator } from "@cequrebackends/
|
|
12
|
-
import { type CequreAuditEvent } from "@cequrebackends/
|
|
11
|
+
import { JWTAuthenticator } from "@cequrebackends/plugin-security";
|
|
12
|
+
import { type CequreAuditEvent } from "@cequrebackends/plugin-security";
|
|
13
13
|
/**
|
|
14
14
|
* AsyncLocalStorage for propagating the request ID from the router
|
|
15
15
|
* to the runtime's audit calls without threading it through every
|