@objectstack/plugin-hono-server 4.0.4 → 4.1.0
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/README.md +22 -0
- package/dist/index.d.mts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +299 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -8
- package/.turbo/turbo-build.log +0 -22
- package/CHANGELOG.md +0 -688
- package/objectstack.config.ts +0 -240
- package/src/adapter.ts +0 -228
- package/src/hono-plugin.test.ts +0 -236
- package/src/hono-plugin.ts +0 -456
- package/src/index.ts +0 -5
- package/src/pattern-matcher.test.ts +0 -180
- package/tsconfig.json +0 -24
- package/vitest.config.ts +0 -22
package/README.md
CHANGED
|
@@ -100,6 +100,28 @@ kernel.use(new HonoServerPlugin({
|
|
|
100
100
|
}));
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
### Bearer token auth (`set-auth-token`)
|
|
104
|
+
|
|
105
|
+
The CORS middleware always includes `set-auth-token` in `Access-Control-Expose-Headers`
|
|
106
|
+
so that `@objectstack/plugin-auth`'s `bearer()` plugin can deliver rotated session
|
|
107
|
+
tokens to cross-origin and mobile clients. `Authorization` is included in
|
|
108
|
+
`Access-Control-Allow-Headers` by default so `Authorization: Bearer <token>`
|
|
109
|
+
requests succeed preflight.
|
|
110
|
+
|
|
111
|
+
You can contribute additional exposed / allowed headers — `exposeHeaders`
|
|
112
|
+
entries you supply are **merged** with the `set-auth-token` default:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
kernel.use(new HonoServerPlugin({
|
|
116
|
+
cors: {
|
|
117
|
+
origins: ['https://app.example.com'],
|
|
118
|
+
credentials: true,
|
|
119
|
+
exposeHeaders: ['X-Request-Id'], // in addition to set-auth-token
|
|
120
|
+
allowHeaders: ['Content-Type', 'Authorization', 'X-Tenant-Id'],
|
|
121
|
+
},
|
|
122
|
+
}));
|
|
123
|
+
```
|
|
124
|
+
|
|
103
125
|
## Architecture
|
|
104
126
|
|
|
105
127
|
This plugin wraps `@objectstack/hono` to provide a turnkey HTTP server solution for the Runtime. It binds the standard `HttpDispatcher` to a Hono application and starts listening on the configured port.
|
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,22 @@ interface HonoCorsOptions {
|
|
|
8
8
|
enabled?: boolean;
|
|
9
9
|
origins?: string | string[];
|
|
10
10
|
methods?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Request headers allowed on preflight (`Access-Control-Allow-Headers`).
|
|
13
|
+
*
|
|
14
|
+
* Defaults to `['Content-Type', 'Authorization', 'X-Requested-With']`,
|
|
15
|
+
* which is sufficient for cookie and bearer-token auth.
|
|
16
|
+
*/
|
|
17
|
+
allowHeaders?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Response headers exposed to JS (`Access-Control-Expose-Headers`).
|
|
20
|
+
*
|
|
21
|
+
* Defaults to `['set-auth-token']` so that better-auth's `bearer()` plugin
|
|
22
|
+
* can hand rotated session tokens to cross-origin clients. User-supplied
|
|
23
|
+
* values are merged with this default — `set-auth-token` is always
|
|
24
|
+
* exposed unless CORS is disabled entirely.
|
|
25
|
+
*/
|
|
26
|
+
exposeHeaders?: string[];
|
|
11
27
|
credentials?: boolean;
|
|
12
28
|
maxAge?: number;
|
|
13
29
|
}
|
|
@@ -81,6 +97,16 @@ interface HonoPluginOptions {
|
|
|
81
97
|
*/
|
|
82
98
|
cors?: HonoCorsOptions | false;
|
|
83
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Hono Server Plugin
|
|
102
|
+
*
|
|
103
|
+
* Provides HTTP server capabilities using Hono framework.
|
|
104
|
+
* Registers the IHttpServer service so other plugins can register routes.
|
|
105
|
+
*
|
|
106
|
+
* Route registration is handled by plugins:
|
|
107
|
+
* - `@objectstack/rest` → CRUD, metadata, discovery, UI, batch
|
|
108
|
+
* - `createDispatcherPlugin()` → auth, graphql, analytics, packages, etc.
|
|
109
|
+
*/
|
|
84
110
|
declare class HonoServerPlugin implements Plugin {
|
|
85
111
|
name: string;
|
|
86
112
|
type: string;
|
|
@@ -110,4 +136,65 @@ declare class HonoServerPlugin implements Plugin {
|
|
|
110
136
|
destroy(): Promise<void>;
|
|
111
137
|
}
|
|
112
138
|
|
|
113
|
-
|
|
139
|
+
/**
|
|
140
|
+
* CORS origin pattern matching utilities.
|
|
141
|
+
*
|
|
142
|
+
* Supports the same wildcard syntax as better-auth's `trustedOrigins`:
|
|
143
|
+
* - `*` → matches any origin
|
|
144
|
+
* - `https://*.example.com` → matches any subdomain
|
|
145
|
+
* - `http://localhost:*` → matches any port
|
|
146
|
+
* - Comma-separated list of the above
|
|
147
|
+
*
|
|
148
|
+
* These helpers are shared between the Hono plugin's CORS middleware and
|
|
149
|
+
* consumers that need to apply CORS headers outside the Hono request
|
|
150
|
+
* pipeline (e.g., the Vercel serverless entrypoint's preflight
|
|
151
|
+
* short-circuit in `apps/objectos`). Keeping a single implementation
|
|
152
|
+
* ensures both paths stay consistent — divergence caused bug where
|
|
153
|
+
* wildcard `CORS_ORIGIN` values worked locally but produced browser
|
|
154
|
+
* CORS errors on Vercel.
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* Returns true when the origin points to localhost (any port, http or https).
|
|
158
|
+
*
|
|
159
|
+
* Matches:
|
|
160
|
+
* - `http://localhost`
|
|
161
|
+
* - `http://localhost:3000`
|
|
162
|
+
* - `https://localhost:8443`
|
|
163
|
+
* - `http://127.0.0.1:5173`
|
|
164
|
+
* - `http://[::1]:3000`
|
|
165
|
+
*/
|
|
166
|
+
declare function isLocalhostOrigin(origin: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Check if an origin matches a pattern with wildcards.
|
|
169
|
+
*
|
|
170
|
+
* Localhost origins (`http(s)://localhost:<any-port>`, `127.0.0.1`, `[::1]`)
|
|
171
|
+
* are **always allowed** regardless of the pattern — this removes the need to
|
|
172
|
+
* enumerate every development port in `CORS_ORIGIN`.
|
|
173
|
+
*
|
|
174
|
+
* @param origin The origin to check (e.g., `https://app.example.com`)
|
|
175
|
+
* @param pattern The pattern to match against (supports `*` wildcard)
|
|
176
|
+
* @returns true if origin matches the pattern
|
|
177
|
+
*/
|
|
178
|
+
declare function matchOriginPattern(origin: string, pattern: string): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Normalize a single string / comma-separated string / array into a
|
|
181
|
+
* trimmed array of non-empty patterns.
|
|
182
|
+
*/
|
|
183
|
+
declare function normalizeOriginPatterns(patterns: string | string[]): string[];
|
|
184
|
+
/**
|
|
185
|
+
* Create a CORS origin matcher function that supports wildcard patterns.
|
|
186
|
+
*
|
|
187
|
+
* The returned function follows Hono's `cors({ origin })` contract:
|
|
188
|
+
* given the request's `Origin` header, it returns the origin to echo
|
|
189
|
+
* back in `Access-Control-Allow-Origin`, or `null` if the origin is not
|
|
190
|
+
* allowed.
|
|
191
|
+
*
|
|
192
|
+
* @param patterns Single pattern, array of patterns, or comma-separated patterns
|
|
193
|
+
*/
|
|
194
|
+
declare function createOriginMatcher(patterns: string | string[]): (origin: string) => string | null;
|
|
195
|
+
/**
|
|
196
|
+
* True if any pattern in the given list contains a `*` wildcard.
|
|
197
|
+
*/
|
|
198
|
+
declare function hasWildcardPattern(patterns: string | string[]): boolean;
|
|
199
|
+
|
|
200
|
+
export { type HonoCorsOptions, HonoHttpServer, type HonoPluginOptions, HonoServerPlugin, type StaticMount, createOriginMatcher, hasWildcardPattern, isLocalhostOrigin, matchOriginPattern, normalizeOriginPatterns };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,22 @@ interface HonoCorsOptions {
|
|
|
8
8
|
enabled?: boolean;
|
|
9
9
|
origins?: string | string[];
|
|
10
10
|
methods?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* Request headers allowed on preflight (`Access-Control-Allow-Headers`).
|
|
13
|
+
*
|
|
14
|
+
* Defaults to `['Content-Type', 'Authorization', 'X-Requested-With']`,
|
|
15
|
+
* which is sufficient for cookie and bearer-token auth.
|
|
16
|
+
*/
|
|
17
|
+
allowHeaders?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Response headers exposed to JS (`Access-Control-Expose-Headers`).
|
|
20
|
+
*
|
|
21
|
+
* Defaults to `['set-auth-token']` so that better-auth's `bearer()` plugin
|
|
22
|
+
* can hand rotated session tokens to cross-origin clients. User-supplied
|
|
23
|
+
* values are merged with this default — `set-auth-token` is always
|
|
24
|
+
* exposed unless CORS is disabled entirely.
|
|
25
|
+
*/
|
|
26
|
+
exposeHeaders?: string[];
|
|
11
27
|
credentials?: boolean;
|
|
12
28
|
maxAge?: number;
|
|
13
29
|
}
|
|
@@ -81,6 +97,16 @@ interface HonoPluginOptions {
|
|
|
81
97
|
*/
|
|
82
98
|
cors?: HonoCorsOptions | false;
|
|
83
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Hono Server Plugin
|
|
102
|
+
*
|
|
103
|
+
* Provides HTTP server capabilities using Hono framework.
|
|
104
|
+
* Registers the IHttpServer service so other plugins can register routes.
|
|
105
|
+
*
|
|
106
|
+
* Route registration is handled by plugins:
|
|
107
|
+
* - `@objectstack/rest` → CRUD, metadata, discovery, UI, batch
|
|
108
|
+
* - `createDispatcherPlugin()` → auth, graphql, analytics, packages, etc.
|
|
109
|
+
*/
|
|
84
110
|
declare class HonoServerPlugin implements Plugin {
|
|
85
111
|
name: string;
|
|
86
112
|
type: string;
|
|
@@ -110,4 +136,65 @@ declare class HonoServerPlugin implements Plugin {
|
|
|
110
136
|
destroy(): Promise<void>;
|
|
111
137
|
}
|
|
112
138
|
|
|
113
|
-
|
|
139
|
+
/**
|
|
140
|
+
* CORS origin pattern matching utilities.
|
|
141
|
+
*
|
|
142
|
+
* Supports the same wildcard syntax as better-auth's `trustedOrigins`:
|
|
143
|
+
* - `*` → matches any origin
|
|
144
|
+
* - `https://*.example.com` → matches any subdomain
|
|
145
|
+
* - `http://localhost:*` → matches any port
|
|
146
|
+
* - Comma-separated list of the above
|
|
147
|
+
*
|
|
148
|
+
* These helpers are shared between the Hono plugin's CORS middleware and
|
|
149
|
+
* consumers that need to apply CORS headers outside the Hono request
|
|
150
|
+
* pipeline (e.g., the Vercel serverless entrypoint's preflight
|
|
151
|
+
* short-circuit in `apps/objectos`). Keeping a single implementation
|
|
152
|
+
* ensures both paths stay consistent — divergence caused bug where
|
|
153
|
+
* wildcard `CORS_ORIGIN` values worked locally but produced browser
|
|
154
|
+
* CORS errors on Vercel.
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* Returns true when the origin points to localhost (any port, http or https).
|
|
158
|
+
*
|
|
159
|
+
* Matches:
|
|
160
|
+
* - `http://localhost`
|
|
161
|
+
* - `http://localhost:3000`
|
|
162
|
+
* - `https://localhost:8443`
|
|
163
|
+
* - `http://127.0.0.1:5173`
|
|
164
|
+
* - `http://[::1]:3000`
|
|
165
|
+
*/
|
|
166
|
+
declare function isLocalhostOrigin(origin: string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Check if an origin matches a pattern with wildcards.
|
|
169
|
+
*
|
|
170
|
+
* Localhost origins (`http(s)://localhost:<any-port>`, `127.0.0.1`, `[::1]`)
|
|
171
|
+
* are **always allowed** regardless of the pattern — this removes the need to
|
|
172
|
+
* enumerate every development port in `CORS_ORIGIN`.
|
|
173
|
+
*
|
|
174
|
+
* @param origin The origin to check (e.g., `https://app.example.com`)
|
|
175
|
+
* @param pattern The pattern to match against (supports `*` wildcard)
|
|
176
|
+
* @returns true if origin matches the pattern
|
|
177
|
+
*/
|
|
178
|
+
declare function matchOriginPattern(origin: string, pattern: string): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Normalize a single string / comma-separated string / array into a
|
|
181
|
+
* trimmed array of non-empty patterns.
|
|
182
|
+
*/
|
|
183
|
+
declare function normalizeOriginPatterns(patterns: string | string[]): string[];
|
|
184
|
+
/**
|
|
185
|
+
* Create a CORS origin matcher function that supports wildcard patterns.
|
|
186
|
+
*
|
|
187
|
+
* The returned function follows Hono's `cors({ origin })` contract:
|
|
188
|
+
* given the request's `Origin` header, it returns the origin to echo
|
|
189
|
+
* back in `Access-Control-Allow-Origin`, or `null` if the origin is not
|
|
190
|
+
* allowed.
|
|
191
|
+
*
|
|
192
|
+
* @param patterns Single pattern, array of patterns, or comma-separated patterns
|
|
193
|
+
*/
|
|
194
|
+
declare function createOriginMatcher(patterns: string | string[]): (origin: string) => string | null;
|
|
195
|
+
/**
|
|
196
|
+
* True if any pattern in the given list contains a `*` wildcard.
|
|
197
|
+
*/
|
|
198
|
+
declare function hasWildcardPattern(patterns: string | string[]): boolean;
|
|
199
|
+
|
|
200
|
+
export { type HonoCorsOptions, HonoHttpServer, type HonoPluginOptions, HonoServerPlugin, type StaticMount, createOriginMatcher, hasWildcardPattern, isLocalhostOrigin, matchOriginPattern, normalizeOriginPatterns };
|