@guren/server 2.10.0 → 2.10.1
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/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
- package/dist/Hash-CzrwKeDp.js +133 -0
- package/dist/HttpException-BkS3euNG.js +161 -0
- package/dist/Job-BVT813DO.js +441 -0
- package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
- package/dist/MessageSigner-Bd25ZJAV.js +93 -0
- package/dist/Random-DbIJ22KQ.js +191 -0
- package/dist/address-D0Iq-XIH.js +20 -0
- package/dist/auth/index.js +2 -122
- package/dist/auth-C7sVmYgc.js +1954 -0
- package/dist/authorization/index.js +2 -38
- package/dist/authorization-Dbcuc5ZK.js +610 -0
- package/dist/broadcasting/index.js +2 -26
- package/dist/broadcasting-Dw-FhyjN.js +1055 -0
- package/dist/cache/index.js +2 -17
- package/dist/cache/types.d.ts +4 -4
- package/dist/cache-BYnZf2FR.js +812 -0
- package/dist/client-Dd7vLcqp.js +27 -0
- package/dist/console/Output.d.ts +18 -18
- package/dist/encryption/index.js +5 -96
- package/dist/encryption-fOWQaKqX.js +250 -0
- package/dist/endpoint-D-20PiHY.js +46 -0
- package/dist/endpoint-D6GIqOpe.js +31 -0
- package/dist/errors-quJOkkCn.js +81 -0
- package/dist/events/index.js +2 -28
- package/dist/events-aIH_bWRx.js +410 -0
- package/dist/health/index.js +2 -24
- package/dist/health-VWdWXRwh.js +345 -0
- package/dist/hot-disposables-WsTX2ySN.js +281 -0
- package/dist/hot-reload/testing.d.ts +1 -1
- package/dist/i18n/index.js +2 -30
- package/dist/i18n-mcWi7LCd.js +617 -0
- package/dist/index.js +7495 -7276
- package/dist/lambda/index.js +114 -71
- package/dist/logging/index.js +2 -24
- package/dist/logging-CPaRMuPP.js +518 -0
- package/dist/loopback-guard-D0Kc7-xc.js +224 -0
- package/dist/mail/index.js +2 -27
- package/dist/mail-DfEfSQEr.js +699 -0
- package/dist/mcp/index.js +2 -10
- package/dist/notifications/index.js +2 -33
- package/dist/notifications-BGqmUNZ8.js +759 -0
- package/dist/queue/index.js +3 -42
- package/dist/queue-CXrRK85G.js +948 -0
- package/dist/redis/index.js +672 -642
- package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
- package/dist/runtime/index.js +472 -616
- package/dist/scheduling/index.js +2 -29
- package/dist/scheduling-CPiEdtQd.js +839 -0
- package/dist/storage/index.js +2 -15
- package/dist/storage-tWHMv2H_.js +841 -0
- package/dist/support/expiry.js +69 -12
- package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
- package/dist/vite/index.js +118 -181
- package/dist/vite/plugin.d.ts +1 -1
- package/dist/vite-dev-server-CpCUqmiC.js +131 -0
- package/package.json +6 -5
- package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
- package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
- package/dist/chunk-2SC566CD.js +0 -376
- package/dist/chunk-2V3YID4H.js +0 -20
- package/dist/chunk-3KV5X2FL.js +0 -31
- package/dist/chunk-63SKW5PS.js +0 -457
- package/dist/chunk-6J6B5KOB.js +0 -425
- package/dist/chunk-A5JJ7XTH.js +0 -24
- package/dist/chunk-AZOYI43J.js +0 -18
- package/dist/chunk-B5E5VBDI.js +0 -115
- package/dist/chunk-DAQKYKLH.js +0 -182
- package/dist/chunk-DRNPVBAA.js +0 -1002
- package/dist/chunk-EI5GYMAT.js +0 -853
- package/dist/chunk-H3B23O6T.js +0 -271
- package/dist/chunk-HPET6XY5.js +0 -853
- package/dist/chunk-HR2KZ3WL.js +0 -616
- package/dist/chunk-IOTWFHZU.js +0 -558
- package/dist/chunk-K6CUBJX6.js +0 -642
- package/dist/chunk-KTNJG7R7.js +0 -911
- package/dist/chunk-LAJQCSSF.js +0 -355
- package/dist/chunk-LHR6OHI7.js +0 -189
- package/dist/chunk-N7PLD7MB.js +0 -729
- package/dist/chunk-Q2P6YLRR.js +0 -24
- package/dist/chunk-QQKTH5KX.js +0 -114
- package/dist/chunk-SFQP6O52.js +0 -126
- package/dist/chunk-SQR7277M.js +0 -911
- package/dist/chunk-T2FFUU6J.js +0 -484
- package/dist/chunk-TVV5YNEC.js +0 -1842
- package/dist/chunk-UY3AZSYL.js +0 -14
- package/dist/chunk-V4DNC2ER.js +0 -114
- package/dist/chunk-VSA3QY5Q.js +0 -274
- package/dist/chunk-YSOJKAAU.js +0 -427
- package/dist/errors-PUNHAFL2.js +0 -34
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
//#region src/container/ServiceProvider.ts
|
|
2
|
+
/**
|
|
3
|
+
* Base service provider class.
|
|
4
|
+
*
|
|
5
|
+
* Service providers are the central place of all application bootstrapping.
|
|
6
|
+
* Your own application, as well as all core services, are bootstrapped via providers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export class AppServiceProvider extends ServiceProvider {
|
|
11
|
+
* register(): void {
|
|
12
|
+
* // Register bindings
|
|
13
|
+
* this.container.singleton('db', (c) => new Database(c.make('config')))
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* boot(): void {
|
|
17
|
+
* // Bootstrap after all providers registered
|
|
18
|
+
* const db = this.container.make<Database>('db')
|
|
19
|
+
* db.connect()
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var ServiceProvider = class {
|
|
25
|
+
container;
|
|
26
|
+
/**
|
|
27
|
+
* Whether this provider should be deferred.
|
|
28
|
+
* Deferred providers are only loaded when one of their provided services is requested.
|
|
29
|
+
*/
|
|
30
|
+
static deferred = false;
|
|
31
|
+
/**
|
|
32
|
+
* The services provided by this provider (for deferred loading).
|
|
33
|
+
*/
|
|
34
|
+
static provides = [];
|
|
35
|
+
constructor(container) {
|
|
36
|
+
this.container = container;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the services provided by the provider.
|
|
40
|
+
*/
|
|
41
|
+
provides() {
|
|
42
|
+
return this.constructor.provides;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if this provider is deferred.
|
|
46
|
+
*/
|
|
47
|
+
isDeferred() {
|
|
48
|
+
return this.constructor.deferred;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Provider manager for registering and booting providers.
|
|
53
|
+
*/
|
|
54
|
+
var ProviderManager = class {
|
|
55
|
+
container;
|
|
56
|
+
providers = [];
|
|
57
|
+
registered = /* @__PURE__ */ new Set();
|
|
58
|
+
booted = /* @__PURE__ */ new Set();
|
|
59
|
+
deferredProviders = /* @__PURE__ */ new Map();
|
|
60
|
+
allBooted = false;
|
|
61
|
+
constructor(container) {
|
|
62
|
+
this.container = container;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Register a provider.
|
|
66
|
+
*/
|
|
67
|
+
register(providerOrClass) {
|
|
68
|
+
if (this.allBooted) {
|
|
69
|
+
const name = providerOrClass instanceof ServiceProvider ? providerOrClass.constructor.name : providerOrClass.name;
|
|
70
|
+
throw new Error(`Cannot register provider "${name}" after bootAll() has been called. Register all providers before booting the application.`);
|
|
71
|
+
}
|
|
72
|
+
const provider = providerOrClass instanceof ServiceProvider ? providerOrClass : new providerOrClass(this.container);
|
|
73
|
+
if (provider.isDeferred() && provider.provides().length === 0) throw new Error(`Deferred provider "${provider.constructor.name}" must declare at least one service in "provides", otherwise it can never be loaded.`);
|
|
74
|
+
if (provider.isDeferred()) for (const service of provider.provides()) this.deferredProviders.set(service, provider);
|
|
75
|
+
else this.providers.push(provider);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register multiple providers.
|
|
80
|
+
*/
|
|
81
|
+
registerMany(providers) {
|
|
82
|
+
for (const provider of providers) this.register(provider);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Register all non-deferred providers.
|
|
87
|
+
*/
|
|
88
|
+
async registerAll() {
|
|
89
|
+
for (const provider of this.providers) if (!this.registered.has(provider)) {
|
|
90
|
+
await provider.register();
|
|
91
|
+
this.registered.add(provider);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Boot all registered providers.
|
|
96
|
+
*/
|
|
97
|
+
async bootAll() {
|
|
98
|
+
for (const provider of this.providers) if (!this.booted.has(provider) && this.registered.has(provider)) {
|
|
99
|
+
await provider.boot?.();
|
|
100
|
+
this.booted.add(provider);
|
|
101
|
+
}
|
|
102
|
+
this.allBooted = true;
|
|
103
|
+
if (this.deferredProviders.size > 0) this.container.deferredProviderLoader = (service) => this.loadDeferredProvider(service);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Load a deferred provider for a service.
|
|
107
|
+
*/
|
|
108
|
+
async loadDeferredProvider(service) {
|
|
109
|
+
const provider = this.deferredProviders.get(service);
|
|
110
|
+
if (!provider) return;
|
|
111
|
+
if (!this.registered.has(provider)) {
|
|
112
|
+
await provider.register();
|
|
113
|
+
this.registered.add(provider);
|
|
114
|
+
this.providers.push(provider);
|
|
115
|
+
}
|
|
116
|
+
if (!this.booted.has(provider)) {
|
|
117
|
+
await provider.boot?.();
|
|
118
|
+
this.booted.add(provider);
|
|
119
|
+
}
|
|
120
|
+
for (const providedService of provider.provides()) this.deferredProviders.delete(providedService);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if a service is provided by a deferred provider.
|
|
124
|
+
*/
|
|
125
|
+
isDeferredService(service) {
|
|
126
|
+
return this.deferredProviders.has(service);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get all registered providers.
|
|
130
|
+
*/
|
|
131
|
+
getProviders() {
|
|
132
|
+
return [...this.providers];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get all deferred services.
|
|
136
|
+
*/
|
|
137
|
+
getDeferredServices() {
|
|
138
|
+
return Array.from(this.deferredProviders.keys());
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/http/middleware/loopback-guard.ts
|
|
143
|
+
const LOOPBACK_HOSTNAMES = /* @__PURE__ */ new Set(["localhost", "[::1]"]);
|
|
144
|
+
const LOOPBACK_IPV4 = /^127\.\d+\.\d+\.\d+$/;
|
|
145
|
+
/**
|
|
146
|
+
* Whether an `Origin` header value belongs to the developer's own machine.
|
|
147
|
+
*
|
|
148
|
+
* Non-browser clients send no `Origin` at all; a value only appears when a
|
|
149
|
+
* web page made the request. Restricting those to loopback blocks both
|
|
150
|
+
* ordinary cross-site requests and DNS rebinding, where an attacker's
|
|
151
|
+
* domain resolves to 127.0.0.1 so the browser skips preflight.
|
|
152
|
+
*
|
|
153
|
+
* This is a *negative* filter only. A loopback `Origin` is never proof that
|
|
154
|
+
* the caller is local: browsers set the header honestly, but any other
|
|
155
|
+
* client sets it with one flag. Never use it to satisfy the peer check.
|
|
156
|
+
*/
|
|
157
|
+
function isLoopbackOrigin(origin) {
|
|
158
|
+
try {
|
|
159
|
+
const { hostname } = new URL(origin);
|
|
160
|
+
return LOOPBACK_HOSTNAMES.has(hostname) || LOOPBACK_IPV4.test(hostname);
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Whether a socket peer address belongs to this machine.
|
|
167
|
+
*
|
|
168
|
+
* Bun reports IPv4-mapped peers as `::ffff:127.0.0.1`, so unwrap that prefix
|
|
169
|
+
* before matching.
|
|
170
|
+
*/
|
|
171
|
+
function isLoopbackAddress(address) {
|
|
172
|
+
const normalized = address.startsWith("::ffff:") ? address.slice(7) : address;
|
|
173
|
+
return normalized === "::1" || LOOPBACK_IPV4.test(normalized);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The peer address of the current request, when the runtime exposes one.
|
|
177
|
+
*
|
|
178
|
+
* `Bun.serve` passes `{ server }` through Hono's env — the same access path
|
|
179
|
+
* the rate limiter uses, and the one `Application.listen()` wires up. Proxy
|
|
180
|
+
* headers are deliberately ignored: they are attacker-controlled, and these
|
|
181
|
+
* endpoints are never meant to sit behind a proxy.
|
|
182
|
+
*
|
|
183
|
+
* `undefined` means "this runtime did not tell us", not "the peer is
|
|
184
|
+
* remote": either the host never passed a `server` through (Node, Vercel's
|
|
185
|
+
* `app.fetch(request)`, in-process test requests), or `requestIP()` itself
|
|
186
|
+
* returned `null`, which Bun does for a socket that is already closed or is
|
|
187
|
+
* not TCP.
|
|
188
|
+
*/
|
|
189
|
+
function clientAddress(ctx) {
|
|
190
|
+
const env = ctx.env;
|
|
191
|
+
if (typeof env?.server?.requestIP !== "function") return;
|
|
192
|
+
return env.server.requestIP(ctx.req.raw)?.address;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Whether the operator accepted serving these endpoints on a runtime that
|
|
196
|
+
* cannot report the socket peer.
|
|
197
|
+
*
|
|
198
|
+
* Read per request, and written in the plain `process.env.X` form for the
|
|
199
|
+
* same bundler reason as the endpoint gates (see `mcp/endpoint.ts`).
|
|
200
|
+
*/
|
|
201
|
+
function allowsUnverifiedPeer() {
|
|
202
|
+
return typeof process !== "undefined" && process.env.GUREN_ALLOW_UNVERIFIED_PEER === "1";
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Restricts an endpoint to the developer's own machine. `resource` names
|
|
206
|
+
* the endpoint in the 403 body (e.g. "the MCP endpoint").
|
|
207
|
+
*
|
|
208
|
+
* Three outcomes, and the two denials say different things on purpose:
|
|
209
|
+
* a peer that is present and not loopback is a remote caller, while a peer
|
|
210
|
+
* the runtime never reported is a deployment the guard cannot vouch for —
|
|
211
|
+
* the developer needs to know which one they are looking at.
|
|
212
|
+
*/
|
|
213
|
+
function createLoopbackGuard(resource) {
|
|
214
|
+
return async (ctx, next) => {
|
|
215
|
+
const origin = ctx.req.header("origin");
|
|
216
|
+
if (origin !== void 0 && !isLoopbackOrigin(origin)) return ctx.json({ message: `Forbidden: cross-origin request to ${resource}` }, 403);
|
|
217
|
+
const address = clientAddress(ctx);
|
|
218
|
+
if (address !== void 0 && !isLoopbackAddress(address)) return ctx.json({ message: `Forbidden: remote request to ${resource}` }, 403);
|
|
219
|
+
if (address === void 0 && !allowsUnverifiedPeer()) return ctx.json({ message: `Forbidden: this runtime does not report the peer address, so ${resource} cannot confirm the request came from this machine. Serve the app with Application.listen() on Bun, or set GUREN_ALLOW_UNVERIFIED_PEER=1 to accept requests from anywhere the process is reachable.` }, 403);
|
|
220
|
+
await next();
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
export { ProviderManager as n, ServiceProvider as r, createLoopbackGuard as t };
|
package/dist/mail/index.js
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Mail,
|
|
4
|
-
MailManager,
|
|
5
|
-
MemoryTransport,
|
|
6
|
-
ResendTransport,
|
|
7
|
-
SmtpTransport,
|
|
8
|
-
createMailManager,
|
|
9
|
-
getMailManager,
|
|
10
|
-
mail,
|
|
11
|
-
setMailManager
|
|
12
|
-
} from "../chunk-K6CUBJX6.js";
|
|
13
|
-
import "../chunk-2V3YID4H.js";
|
|
14
|
-
import "../chunk-KTNJG7R7.js";
|
|
15
|
-
import "../chunk-6J6B5KOB.js";
|
|
16
|
-
export {
|
|
17
|
-
LogTransport,
|
|
18
|
-
Mail,
|
|
19
|
-
MailManager,
|
|
20
|
-
MemoryTransport,
|
|
21
|
-
ResendTransport,
|
|
22
|
-
SmtpTransport,
|
|
23
|
-
createMailManager,
|
|
24
|
-
getMailManager,
|
|
25
|
-
mail,
|
|
26
|
-
setMailManager
|
|
27
|
-
};
|
|
1
|
+
import { a as MailManager, c as MemoryTransport, i as setMailManager, l as ResendTransport, n as getMailManager, o as createMailManager, r as mail, s as LogTransport, t as Mail, u as SmtpTransport } from "../mail-DfEfSQEr.js";
|
|
2
|
+
export { LogTransport, Mail, MailManager, MemoryTransport, ResendTransport, SmtpTransport, createMailManager, getMailManager, mail, setMailManager };
|