@fonderie/adapter-hono 1.0.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/LICENSE +21 -0
- package/README.md +45 -0
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fonderie, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @fonderie/adapter-hono
|
|
2
|
+
|
|
3
|
+
Run Fonderie bricks inside your existing Hono app. `bridge()` builds the
|
|
4
|
+
Fonderie context for every request, `adapt()` converts any Fonderie
|
|
5
|
+
middleware into a native Hono one, and `mount()` attaches whole modules.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @fonderie/adapter-hono
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { bridge, adapt, requireAuth } from '@fonderie/adapter-hono';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Register `bridge(fonderie)` as global middleware first, then use the
|
|
20
|
+
re-exported guards (`requireAuth`, `requireWorkspace`, `requirePermission`,
|
|
21
|
+
`requireFeature`) directly on routes.
|
|
22
|
+
|
|
23
|
+
`ContextVariableMap` is augmented so `c.get('_fonderie')` is fully typed;
|
|
24
|
+
`FonderieVariables` is exported for typing your `Hono` instance.
|
|
25
|
+
|
|
26
|
+
## Why this exists
|
|
27
|
+
|
|
28
|
+
You've shipped this plumbing before — auth, teams, billing, messaging —
|
|
29
|
+
and the next project will ask for it again. Fonderie packages it once:
|
|
30
|
+
plain TypeScript modules for
|
|
31
|
+
[`@fonderie/core`](https://github.com/fonderie-js/sdk/tree/main/packages/core),
|
|
32
|
+
PostgreSQL-backed, self-hosted, MIT. No external control plane, no
|
|
33
|
+
per-seat anything. Register the modules you need; skip the ones you don't.
|
|
34
|
+
|
|
35
|
+
**This package owns** the border crossing. It translates Hono contexts and
|
|
36
|
+
middleware conventions into Fonderie's, so the bricks run inside an app you
|
|
37
|
+
already have instead of demanding a rewrite.
|
|
38
|
+
|
|
39
|
+
Browse the whole set at
|
|
40
|
+
[fonderie-js/sdk](https://github.com/fonderie-js/sdk) · follow
|
|
41
|
+
[@fonderiejs](https://x.com/fonderiejs)
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © Fonderie, Inc.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
OPERATIONS: () => import_permissions2.OPERATIONS,
|
|
24
|
+
adapt: () => adapt,
|
|
25
|
+
bridge: () => bridge,
|
|
26
|
+
mount: () => mount,
|
|
27
|
+
requireAuth: () => requireAuth,
|
|
28
|
+
requireFeature: () => requireFeature,
|
|
29
|
+
requirePermission: () => requirePermission,
|
|
30
|
+
withWorkspace: () => withWorkspace
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(index_exports);
|
|
33
|
+
var import_middlewares = require("@fonderie/core/middlewares");
|
|
34
|
+
var import_workspaces = require("@fonderie/workspaces");
|
|
35
|
+
var import_permissions = require("@fonderie/permissions");
|
|
36
|
+
var import_billing = require("@fonderie/billing");
|
|
37
|
+
var import_permissions2 = require("@fonderie/permissions");
|
|
38
|
+
function bridge(fonderie) {
|
|
39
|
+
return async (c, next) => {
|
|
40
|
+
const ctx = await fonderie.buildContext(c.req.raw.clone());
|
|
41
|
+
c.set("_fonderie", ctx);
|
|
42
|
+
await next();
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function adapt(middleware) {
|
|
46
|
+
return async (c, next) => {
|
|
47
|
+
const ctx = c.get("_fonderie");
|
|
48
|
+
if (!ctx) throw new Error("[fonderie] bridge() must be registered before adapt()");
|
|
49
|
+
let continued = false;
|
|
50
|
+
const result = await middleware(ctx, async () => {
|
|
51
|
+
continued = true;
|
|
52
|
+
return new Response();
|
|
53
|
+
});
|
|
54
|
+
if (continued) {
|
|
55
|
+
await next();
|
|
56
|
+
} else {
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
var requireAuth = adapt(import_middlewares.requireAuth);
|
|
62
|
+
function withWorkspace(store) {
|
|
63
|
+
return adapt((0, import_workspaces.withWorkspace)(store));
|
|
64
|
+
}
|
|
65
|
+
function requirePermission(operation, permissionKey) {
|
|
66
|
+
return adapt((0, import_permissions.requirePermission)(operation, permissionKey));
|
|
67
|
+
}
|
|
68
|
+
function requireFeature(key) {
|
|
69
|
+
return adapt((0, import_billing.requireFeature)(key));
|
|
70
|
+
}
|
|
71
|
+
function mount(hono, fonderie) {
|
|
72
|
+
hono.notFound((c) => fonderie.handle(c.req.raw));
|
|
73
|
+
return hono;
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
OPERATIONS,
|
|
78
|
+
adapt,
|
|
79
|
+
bridge,
|
|
80
|
+
mount,
|
|
81
|
+
requireAuth,
|
|
82
|
+
requireFeature,
|
|
83
|
+
requirePermission,
|
|
84
|
+
withWorkspace
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Context, MiddlewareHandler } from 'hono';\nimport type { Hono } from 'hono';\n\nimport type { FonderieApp, IFonderieContext, Middleware } from '@fonderie/core';\nimport { requireAuth as _requireAuth } from '@fonderie/core/middlewares';\nimport { withWorkspace as _withWorkspace } from '@fonderie/workspaces';\nimport { requirePermission as _requirePermission } from '@fonderie/permissions';\nimport { requireFeature as _requireFeature } from '@fonderie/billing';\n\nexport { OPERATIONS } from '@fonderie/permissions';\n\n// Augment Hono's ContextVariableMap so c.get('_fonderie') is typed.\ndeclare module 'hono' {\n\tinterface ContextVariableMap {\n\t\t_fonderie: IFonderieContext;\n\t}\n}\n\n// Re-export for consumers who want to type their Hono app:\n// const hono = new Hono<{ Variables: FonderieVariables }>()\nexport type FonderieVariables = {\n\t_fonderie: IFonderieContext;\n};\n\n// ── bridge ────────────────────────────────────────────────────────\n//\n// Global middleware. Runs fonderie's session + billing global stack so that\n// ctx.user and ctx.meta['billing'] are available in every route handler.\n// Must be registered before any fonderie-aware route middleware.\n//\n// hono.use('*', bridge(fonderie))\n\nexport function bridge(fonderie: FonderieApp): MiddlewareHandler {\n\treturn async (c, next) => {\n\t\tconst ctx = await fonderie.buildContext(c.req.raw.clone());\n\t\tc.set('_fonderie', ctx);\n\t\tawait next();\n\t};\n}\n\n// ── adapt ─────────────────────────────────────────────────────────\n//\n// Low-level escape hatch — wraps any fonderie Middleware into a Hono\n// MiddlewareHandler. Use this for custom fonderie middleware; prefer the\n// named exports below for the built-in fonderie guards.\n\nexport function adapt(middleware: Middleware): MiddlewareHandler {\n\treturn async (c: Context, next) => {\n\t\tconst ctx = c.get('_fonderie');\n\t\tif (!ctx) throw new Error('[fonderie] bridge() must be registered before adapt()');\n\n\t\tlet continued = false;\n\t\tconst result = await middleware(ctx, async () => {\n\t\t\tcontinued = true;\n\t\t\treturn new Response();\n\t\t});\n\n\t\tif (continued) {\n\t\t\tawait next();\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t};\n}\n\n// ── Pre-adapted middleware ────────────────────────────────────────\n//\n// Drop-in replacements for the fonderie middleware functions — no adapt()\n// needed. Import directly from this package instead of from the source\n// packages, and use them as native Hono middleware.\n//\n// hono.get('/jobs', requireAuth, withWorkspace(store), ...)\n\nexport const requireAuth: MiddlewareHandler = adapt(_requireAuth);\n\nexport function withWorkspace(store: Parameters<typeof _withWorkspace>[0]): MiddlewareHandler {\n\treturn adapt(_withWorkspace(store));\n}\n\nexport function requirePermission(\n\toperation: Parameters<typeof _requirePermission>[0],\n\tpermissionKey: Parameters<typeof _requirePermission>[1],\n): MiddlewareHandler {\n\treturn adapt(_requirePermission(operation, permissionKey));\n}\n\nexport function requireFeature(key: string): MiddlewareHandler {\n\treturn adapt(_requireFeature(key));\n}\n\n// ── mount ─────────────────────────────────────────────────────────\n//\n// Wires up fonderie to a Hono app. Returns the same app so you can add\n// routes after mount() — fonderie infra is the notFound handler, so\n// user routes always take priority:\n//\n// const api = mount(hono, fonderie)\n// api.get('/v1/todos', requireAuth, handler)\n// export default hono\n\n// mount() wires fonderie's infrastructure routes as the notFound fallback so\n// user routes always take priority. Call bridge() yourself before your routes\n// to ensure _fonderie is populated for them.\nexport function mount(hono: Hono, fonderie: FonderieApp): Hono {\n\thono.notFound((c) => fonderie.handle(c.req.raw));\n\treturn hono;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA4C;AAC5C,wBAAgD;AAChD,yBAAwD;AACxD,qBAAkD;AAElD,IAAAA,sBAA2B;AAuBpB,SAAS,OAAO,UAA0C;AAChE,SAAO,OAAO,GAAG,SAAS;AACzB,UAAM,MAAM,MAAM,SAAS,aAAa,EAAE,IAAI,IAAI,MAAM,CAAC;AACzD,MAAE,IAAI,aAAa,GAAG;AACtB,UAAM,KAAK;AAAA,EACZ;AACD;AAQO,SAAS,MAAM,YAA2C;AAChE,SAAO,OAAO,GAAY,SAAS;AAClC,UAAM,MAAM,EAAE,IAAI,WAAW;AAC7B,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,uDAAuD;AAEjF,QAAI,YAAY;AAChB,UAAM,SAAS,MAAM,WAAW,KAAK,YAAY;AAChD,kBAAY;AACZ,aAAO,IAAI,SAAS;AAAA,IACrB,CAAC;AAED,QAAI,WAAW;AACd,YAAM,KAAK;AAAA,IACZ,OAAO;AACN,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAUO,IAAM,cAAiC,MAAM,mBAAAC,WAAY;AAEzD,SAAS,cAAc,OAAgE;AAC7F,SAAO,UAAM,kBAAAC,eAAe,KAAK,CAAC;AACnC;AAEO,SAAS,kBACf,WACA,eACoB;AACpB,SAAO,UAAM,mBAAAC,mBAAmB,WAAW,aAAa,CAAC;AAC1D;AAEO,SAAS,eAAe,KAAgC;AAC9D,SAAO,UAAM,eAAAC,gBAAgB,GAAG,CAAC;AAClC;AAeO,SAAS,MAAM,MAAY,UAA6B;AAC9D,OAAK,SAAS,CAAC,MAAM,SAAS,OAAO,EAAE,IAAI,GAAG,CAAC;AAC/C,SAAO;AACR;","names":["import_permissions","_requireAuth","_withWorkspace","_requirePermission","_requireFeature"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MiddlewareHandler, Hono } from 'hono';
|
|
2
|
+
import { IFonderieContext, Middleware, FonderieApp } from '@fonderie/core';
|
|
3
|
+
import { withWorkspace as withWorkspace$1 } from '@fonderie/workspaces';
|
|
4
|
+
import { requirePermission as requirePermission$1 } from '@fonderie/permissions';
|
|
5
|
+
export { OPERATIONS } from '@fonderie/permissions';
|
|
6
|
+
|
|
7
|
+
declare module 'hono' {
|
|
8
|
+
interface ContextVariableMap {
|
|
9
|
+
_fonderie: IFonderieContext;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type FonderieVariables = {
|
|
13
|
+
_fonderie: IFonderieContext;
|
|
14
|
+
};
|
|
15
|
+
declare function bridge(fonderie: FonderieApp): MiddlewareHandler;
|
|
16
|
+
declare function adapt(middleware: Middleware): MiddlewareHandler;
|
|
17
|
+
declare const requireAuth: MiddlewareHandler;
|
|
18
|
+
declare function withWorkspace(store: Parameters<typeof withWorkspace$1>[0]): MiddlewareHandler;
|
|
19
|
+
declare function requirePermission(operation: Parameters<typeof requirePermission$1>[0], permissionKey: Parameters<typeof requirePermission$1>[1]): MiddlewareHandler;
|
|
20
|
+
declare function requireFeature(key: string): MiddlewareHandler;
|
|
21
|
+
declare function mount(hono: Hono, fonderie: FonderieApp): Hono;
|
|
22
|
+
|
|
23
|
+
export { type FonderieVariables, adapt, bridge, mount, requireAuth, requireFeature, requirePermission, withWorkspace };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MiddlewareHandler, Hono } from 'hono';
|
|
2
|
+
import { IFonderieContext, Middleware, FonderieApp } from '@fonderie/core';
|
|
3
|
+
import { withWorkspace as withWorkspace$1 } from '@fonderie/workspaces';
|
|
4
|
+
import { requirePermission as requirePermission$1 } from '@fonderie/permissions';
|
|
5
|
+
export { OPERATIONS } from '@fonderie/permissions';
|
|
6
|
+
|
|
7
|
+
declare module 'hono' {
|
|
8
|
+
interface ContextVariableMap {
|
|
9
|
+
_fonderie: IFonderieContext;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type FonderieVariables = {
|
|
13
|
+
_fonderie: IFonderieContext;
|
|
14
|
+
};
|
|
15
|
+
declare function bridge(fonderie: FonderieApp): MiddlewareHandler;
|
|
16
|
+
declare function adapt(middleware: Middleware): MiddlewareHandler;
|
|
17
|
+
declare const requireAuth: MiddlewareHandler;
|
|
18
|
+
declare function withWorkspace(store: Parameters<typeof withWorkspace$1>[0]): MiddlewareHandler;
|
|
19
|
+
declare function requirePermission(operation: Parameters<typeof requirePermission$1>[0], permissionKey: Parameters<typeof requirePermission$1>[1]): MiddlewareHandler;
|
|
20
|
+
declare function requireFeature(key: string): MiddlewareHandler;
|
|
21
|
+
declare function mount(hono: Hono, fonderie: FonderieApp): Hono;
|
|
22
|
+
|
|
23
|
+
export { type FonderieVariables, adapt, bridge, mount, requireAuth, requireFeature, requirePermission, withWorkspace };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { requireAuth as _requireAuth } from "@fonderie/core/middlewares";
|
|
3
|
+
import { withWorkspace as _withWorkspace } from "@fonderie/workspaces";
|
|
4
|
+
import { requirePermission as _requirePermission } from "@fonderie/permissions";
|
|
5
|
+
import { requireFeature as _requireFeature } from "@fonderie/billing";
|
|
6
|
+
import { OPERATIONS } from "@fonderie/permissions";
|
|
7
|
+
function bridge(fonderie) {
|
|
8
|
+
return async (c, next) => {
|
|
9
|
+
const ctx = await fonderie.buildContext(c.req.raw.clone());
|
|
10
|
+
c.set("_fonderie", ctx);
|
|
11
|
+
await next();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function adapt(middleware) {
|
|
15
|
+
return async (c, next) => {
|
|
16
|
+
const ctx = c.get("_fonderie");
|
|
17
|
+
if (!ctx) throw new Error("[fonderie] bridge() must be registered before adapt()");
|
|
18
|
+
let continued = false;
|
|
19
|
+
const result = await middleware(ctx, async () => {
|
|
20
|
+
continued = true;
|
|
21
|
+
return new Response();
|
|
22
|
+
});
|
|
23
|
+
if (continued) {
|
|
24
|
+
await next();
|
|
25
|
+
} else {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var requireAuth = adapt(_requireAuth);
|
|
31
|
+
function withWorkspace(store) {
|
|
32
|
+
return adapt(_withWorkspace(store));
|
|
33
|
+
}
|
|
34
|
+
function requirePermission(operation, permissionKey) {
|
|
35
|
+
return adapt(_requirePermission(operation, permissionKey));
|
|
36
|
+
}
|
|
37
|
+
function requireFeature(key) {
|
|
38
|
+
return adapt(_requireFeature(key));
|
|
39
|
+
}
|
|
40
|
+
function mount(hono, fonderie) {
|
|
41
|
+
hono.notFound((c) => fonderie.handle(c.req.raw));
|
|
42
|
+
return hono;
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
OPERATIONS,
|
|
46
|
+
adapt,
|
|
47
|
+
bridge,
|
|
48
|
+
mount,
|
|
49
|
+
requireAuth,
|
|
50
|
+
requireFeature,
|
|
51
|
+
requirePermission,
|
|
52
|
+
withWorkspace
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Context, MiddlewareHandler } from 'hono';\nimport type { Hono } from 'hono';\n\nimport type { FonderieApp, IFonderieContext, Middleware } from '@fonderie/core';\nimport { requireAuth as _requireAuth } from '@fonderie/core/middlewares';\nimport { withWorkspace as _withWorkspace } from '@fonderie/workspaces';\nimport { requirePermission as _requirePermission } from '@fonderie/permissions';\nimport { requireFeature as _requireFeature } from '@fonderie/billing';\n\nexport { OPERATIONS } from '@fonderie/permissions';\n\n// Augment Hono's ContextVariableMap so c.get('_fonderie') is typed.\ndeclare module 'hono' {\n\tinterface ContextVariableMap {\n\t\t_fonderie: IFonderieContext;\n\t}\n}\n\n// Re-export for consumers who want to type their Hono app:\n// const hono = new Hono<{ Variables: FonderieVariables }>()\nexport type FonderieVariables = {\n\t_fonderie: IFonderieContext;\n};\n\n// ── bridge ────────────────────────────────────────────────────────\n//\n// Global middleware. Runs fonderie's session + billing global stack so that\n// ctx.user and ctx.meta['billing'] are available in every route handler.\n// Must be registered before any fonderie-aware route middleware.\n//\n// hono.use('*', bridge(fonderie))\n\nexport function bridge(fonderie: FonderieApp): MiddlewareHandler {\n\treturn async (c, next) => {\n\t\tconst ctx = await fonderie.buildContext(c.req.raw.clone());\n\t\tc.set('_fonderie', ctx);\n\t\tawait next();\n\t};\n}\n\n// ── adapt ─────────────────────────────────────────────────────────\n//\n// Low-level escape hatch — wraps any fonderie Middleware into a Hono\n// MiddlewareHandler. Use this for custom fonderie middleware; prefer the\n// named exports below for the built-in fonderie guards.\n\nexport function adapt(middleware: Middleware): MiddlewareHandler {\n\treturn async (c: Context, next) => {\n\t\tconst ctx = c.get('_fonderie');\n\t\tif (!ctx) throw new Error('[fonderie] bridge() must be registered before adapt()');\n\n\t\tlet continued = false;\n\t\tconst result = await middleware(ctx, async () => {\n\t\t\tcontinued = true;\n\t\t\treturn new Response();\n\t\t});\n\n\t\tif (continued) {\n\t\t\tawait next();\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t};\n}\n\n// ── Pre-adapted middleware ────────────────────────────────────────\n//\n// Drop-in replacements for the fonderie middleware functions — no adapt()\n// needed. Import directly from this package instead of from the source\n// packages, and use them as native Hono middleware.\n//\n// hono.get('/jobs', requireAuth, withWorkspace(store), ...)\n\nexport const requireAuth: MiddlewareHandler = adapt(_requireAuth);\n\nexport function withWorkspace(store: Parameters<typeof _withWorkspace>[0]): MiddlewareHandler {\n\treturn adapt(_withWorkspace(store));\n}\n\nexport function requirePermission(\n\toperation: Parameters<typeof _requirePermission>[0],\n\tpermissionKey: Parameters<typeof _requirePermission>[1],\n): MiddlewareHandler {\n\treturn adapt(_requirePermission(operation, permissionKey));\n}\n\nexport function requireFeature(key: string): MiddlewareHandler {\n\treturn adapt(_requireFeature(key));\n}\n\n// ── mount ─────────────────────────────────────────────────────────\n//\n// Wires up fonderie to a Hono app. Returns the same app so you can add\n// routes after mount() — fonderie infra is the notFound handler, so\n// user routes always take priority:\n//\n// const api = mount(hono, fonderie)\n// api.get('/v1/todos', requireAuth, handler)\n// export default hono\n\n// mount() wires fonderie's infrastructure routes as the notFound fallback so\n// user routes always take priority. Call bridge() yourself before your routes\n// to ensure _fonderie is populated for them.\nexport function mount(hono: Hono, fonderie: FonderieApp): Hono {\n\thono.notFound((c) => fonderie.handle(c.req.raw));\n\treturn hono;\n}\n"],"mappings":";AAIA,SAAS,eAAe,oBAAoB;AAC5C,SAAS,iBAAiB,sBAAsB;AAChD,SAAS,qBAAqB,0BAA0B;AACxD,SAAS,kBAAkB,uBAAuB;AAElD,SAAS,kBAAkB;AAuBpB,SAAS,OAAO,UAA0C;AAChE,SAAO,OAAO,GAAG,SAAS;AACzB,UAAM,MAAM,MAAM,SAAS,aAAa,EAAE,IAAI,IAAI,MAAM,CAAC;AACzD,MAAE,IAAI,aAAa,GAAG;AACtB,UAAM,KAAK;AAAA,EACZ;AACD;AAQO,SAAS,MAAM,YAA2C;AAChE,SAAO,OAAO,GAAY,SAAS;AAClC,UAAM,MAAM,EAAE,IAAI,WAAW;AAC7B,QAAI,CAAC,IAAK,OAAM,IAAI,MAAM,uDAAuD;AAEjF,QAAI,YAAY;AAChB,UAAM,SAAS,MAAM,WAAW,KAAK,YAAY;AAChD,kBAAY;AACZ,aAAO,IAAI,SAAS;AAAA,IACrB,CAAC;AAED,QAAI,WAAW;AACd,YAAM,KAAK;AAAA,IACZ,OAAO;AACN,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAUO,IAAM,cAAiC,MAAM,YAAY;AAEzD,SAAS,cAAc,OAAgE;AAC7F,SAAO,MAAM,eAAe,KAAK,CAAC;AACnC;AAEO,SAAS,kBACf,WACA,eACoB;AACpB,SAAO,MAAM,mBAAmB,WAAW,aAAa,CAAC;AAC1D;AAEO,SAAS,eAAe,KAAgC;AAC9D,SAAO,MAAM,gBAAgB,GAAG,CAAC;AAClC;AAeO,SAAS,MAAM,MAAY,UAA6B;AAC9D,OAAK,SAAS,CAAC,MAAM,SAAS,OAAO,EAAE,IAAI,GAAG,CAAC;AAC/C,SAAO;AACR;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fonderie/adapter-hono",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Hono adapter for fonderie-js — bridge(), adapt(), mount() to use fonderie middleware in native Hono routes.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"fonderie-js",
|
|
7
|
+
"hono",
|
|
8
|
+
"adapter",
|
|
9
|
+
"middleware",
|
|
10
|
+
"saas",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=20"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"test": "tsx --test src/__tests__/*.test.ts",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"lint": "biome lint src",
|
|
34
|
+
"format": "biome format --write src",
|
|
35
|
+
"check": "biome check --write src"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@fonderie/core": "^0.1.0",
|
|
39
|
+
"@fonderie/workspaces": "^1.0.0",
|
|
40
|
+
"@fonderie/permissions": "^1.0.0",
|
|
41
|
+
"@fonderie/billing": "^1.0.0",
|
|
42
|
+
"hono": "^4.0.0"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@fonderie/workspaces": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"@fonderie/permissions": {
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"@fonderie/billing": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@fonderie/core": "../core",
|
|
57
|
+
"@fonderie/workspaces": "../workspaces",
|
|
58
|
+
"@fonderie/permissions": "../permissions",
|
|
59
|
+
"@fonderie/billing": "../billing",
|
|
60
|
+
"hono": "^4.7.11",
|
|
61
|
+
"@types/node": "^25.6.0",
|
|
62
|
+
"tsx": "^4.21.0",
|
|
63
|
+
"tsup": "^8.5.1",
|
|
64
|
+
"typescript": "^6.0.3"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"files": [
|
|
70
|
+
"dist",
|
|
71
|
+
"LICENSE",
|
|
72
|
+
"README.md"
|
|
73
|
+
],
|
|
74
|
+
"repository": {
|
|
75
|
+
"type": "git",
|
|
76
|
+
"url": "git+https://github.com/fonderie-js/sdk.git",
|
|
77
|
+
"directory": "packages/adapter-hono"
|
|
78
|
+
},
|
|
79
|
+
"homepage": "https://github.com/fonderie-js/sdk/tree/main/packages/adapter-hono#readme",
|
|
80
|
+
"bugs": {
|
|
81
|
+
"url": "https://github.com/fonderie-js/sdk/issues"
|
|
82
|
+
}
|
|
83
|
+
}
|