faire-auth 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 +661 -0
- package/README.md +34 -0
- package/dist/access-B5bBI4uT.mjs +39 -0
- package/dist/access-Crt-IJ2P.cjs +51 -0
- package/dist/adapter-factory-BXei1QRX.mjs +881 -0
- package/dist/adapter-factory-DT-_2aHJ.cjs +893 -0
- package/dist/adapters/drizzle-adapter/index.cjs +208 -0
- package/dist/adapters/drizzle-adapter/index.d.cts +48 -0
- package/dist/adapters/drizzle-adapter/index.d.mts +48 -0
- package/dist/adapters/drizzle-adapter/index.mjs +207 -0
- package/dist/adapters/index.cjs +23 -0
- package/dist/adapters/index.d.cts +157 -0
- package/dist/adapters/index.d.mts +157 -0
- package/dist/adapters/index.mjs +17 -0
- package/dist/adapters/kysely-adapter/index.cjs +11 -0
- package/dist/adapters/kysely-adapter/index.d.cts +52 -0
- package/dist/adapters/kysely-adapter/index.d.mts +52 -0
- package/dist/adapters/kysely-adapter/index.mjs +9 -0
- package/dist/adapters/memory-adapter/index.cjs +9 -0
- package/dist/adapters/memory-adapter/index.d.cts +15 -0
- package/dist/adapters/memory-adapter/index.d.mts +15 -0
- package/dist/adapters/memory-adapter/index.mjs +9 -0
- package/dist/adapters/mongodb-adapter/index.cjs +9 -0
- package/dist/adapters/mongodb-adapter/index.d.cts +4 -0
- package/dist/adapters/mongodb-adapter/index.d.mts +4 -0
- package/dist/adapters/mongodb-adapter/index.mjs +9 -0
- package/dist/adapters/prisma-adapter/index.cjs +156 -0
- package/dist/adapters/prisma-adapter/index.d.cts +35 -0
- package/dist/adapters/prisma-adapter/index.d.mts +35 -0
- package/dist/adapters/prisma-adapter/index.mjs +155 -0
- package/dist/adapters/test.cjs +797 -0
- package/dist/adapters/test.d.cts +82 -0
- package/dist/adapters/test.d.mts +82 -0
- package/dist/adapters/test.mjs +793 -0
- package/dist/api/index.cjs +20 -0
- package/dist/api/index.d.cts +3 -0
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +20 -0
- package/dist/api/middleware/index.cjs +16 -0
- package/dist/api/middleware/index.d.cts +16 -0
- package/dist/api/middleware/index.d.mts +16 -0
- package/dist/api/middleware/index.mjs +11 -0
- package/dist/api-Bm89BLgN.cjs +1899 -0
- package/dist/api-_B7qO28y.mjs +1892 -0
- package/dist/auth-Bo9PDt5j.cjs +739 -0
- package/dist/auth-Ds4AG4h4.mjs +709 -0
- package/dist/bearer-0SeEmaS4.mjs +54 -0
- package/dist/bearer-CHeREcGT.cjs +60 -0
- package/dist/bun-sqlite-dialect-CfkBo2v5.mjs +155 -0
- package/dist/bun-sqlite-dialect-wuaC2-gh.cjs +156 -0
- package/dist/chunk-Ceigfy4P.mjs +39 -0
- package/dist/chunk-oakRccI5.cjs +60 -0
- package/dist/client/index.cjs +22 -0
- package/dist/client/index.d.cts +8 -0
- package/dist/client/index.d.mts +8 -0
- package/dist/client/index.mjs +19 -0
- package/dist/client/lynx/index.cjs +79 -0
- package/dist/client/lynx/index.d.cts +156 -0
- package/dist/client/lynx/index.d.mts +156 -0
- package/dist/client/lynx/index.mjs +76 -0
- package/dist/client/plugins/index.cjs +11 -0
- package/dist/client/plugins/index.d.cts +17 -0
- package/dist/client/plugins/index.d.mts +17 -0
- package/dist/client/plugins/index.mjs +10 -0
- package/dist/client/react/index.cjs +79 -0
- package/dist/client/react/index.d.cts +156 -0
- package/dist/client/react/index.d.mts +156 -0
- package/dist/client/react/index.mjs +76 -0
- package/dist/client/solid/index.cjs +51 -0
- package/dist/client/solid/index.d.cts +90 -0
- package/dist/client/solid/index.d.mts +90 -0
- package/dist/client/solid/index.mjs +50 -0
- package/dist/client/svelte/index.cjs +28 -0
- package/dist/client/svelte/index.d.cts +110 -0
- package/dist/client/svelte/index.d.mts +110 -0
- package/dist/client/svelte/index.mjs +28 -0
- package/dist/client/vue/index.cjs +68 -0
- package/dist/client/vue/index.d.cts +123 -0
- package/dist/client/vue/index.d.mts +123 -0
- package/dist/client/vue/index.mjs +67 -0
- package/dist/cookies-B5xeA6i8.cjs +456 -0
- package/dist/cookies-Ch1JfQIz.mjs +367 -0
- package/dist/crypto/index.cjs +11 -0
- package/dist/crypto/index.d.cts +22 -0
- package/dist/crypto/index.d.mts +22 -0
- package/dist/crypto/index.mjs +5 -0
- package/dist/crypto-CcTxYH82.cjs +57 -0
- package/dist/crypto-CyQRFtkq.mjs +41 -0
- package/dist/db/index.cjs +40 -0
- package/dist/db/index.d.cts +4 -0
- package/dist/db/index.d.mts +4 -0
- package/dist/db/index.mjs +16 -0
- package/dist/db-BTKyYu-_.cjs +1180 -0
- package/dist/db-xiJtoDgz.mjs +1119 -0
- package/dist/defu-B0Svx_x4.cjs +34 -0
- package/dist/defu-SZkpHhbR.mjs +28 -0
- package/dist/email-verification-C-AsfJsb.cjs +247 -0
- package/dist/email-verification-CWhj2qfb.mjs +228 -0
- package/dist/hono-BEq1NYVX.cjs +526 -0
- package/dist/hono-Cdukwu5K.cjs +13 -0
- package/dist/hono-CoKYWnXA.mjs +7 -0
- package/dist/hono-Covz10jU.mjs +508 -0
- package/dist/hono-DOM31WQz.d.cts +18 -0
- package/dist/hono-DuE14mmj.d.mts +18 -0
- package/dist/index-B-WeOMzg.d.cts +13350 -0
- package/dist/index-B09P9p5_.d.cts +33 -0
- package/dist/index-B5_0QTLg.d.mts +3 -0
- package/dist/index-B7SKyR_a.d.cts +3 -0
- package/dist/index-BVHscLQl.d.cts +992 -0
- package/dist/index-C2-2QDyS.d.cts +35 -0
- package/dist/index-CTwrVluH.d.mts +41 -0
- package/dist/index-CWAqWfoZ.d.cts +27 -0
- package/dist/index-CYSShrFx.d.mts +27 -0
- package/dist/index-Qu-iJGNr.d.mts +992 -0
- package/dist/index-cs4Sh0En.d.cts +41 -0
- package/dist/index-jlessPI0.d.mts +13350 -0
- package/dist/index-ppgcFe12.d.mts +33 -0
- package/dist/index-to0RO38U.d.mts +35 -0
- package/dist/index.cjs +85 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +27 -0
- package/dist/integrations/next-js.cjs +50 -0
- package/dist/integrations/next-js.d.cts +23 -0
- package/dist/integrations/next-js.d.mts +23 -0
- package/dist/integrations/next-js.mjs +49 -0
- package/dist/integrations/node.cjs +139 -0
- package/dist/integrations/node.d.cts +22 -0
- package/dist/integrations/node.d.mts +22 -0
- package/dist/integrations/node.mjs +134 -0
- package/dist/integrations/react-start.cjs +37 -0
- package/dist/integrations/react-start.d.cts +17 -0
- package/dist/integrations/react-start.d.mts +17 -0
- package/dist/integrations/react-start.mjs +37 -0
- package/dist/integrations/solid-start.cjs +14 -0
- package/dist/integrations/solid-start.d.cts +13 -0
- package/dist/integrations/solid-start.d.mts +13 -0
- package/dist/integrations/solid-start.mjs +13 -0
- package/dist/integrations/svelte-kit.cjs +52 -0
- package/dist/integrations/svelte-kit.d.cts +42 -0
- package/dist/integrations/svelte-kit.d.mts +42 -0
- package/dist/integrations/svelte-kit.mjs +49 -0
- package/dist/ip-B5SwXaMB.cjs +54 -0
- package/dist/ip-BjNYspCH.mjs +36 -0
- package/dist/json-B1v2qRTQ.mjs +24 -0
- package/dist/json-CcJ2HjGo.cjs +30 -0
- package/dist/kysely-adapter-Bxi7sPdG.cjs +288 -0
- package/dist/kysely-adapter-DRuoT_X8.mjs +270 -0
- package/dist/logged-CyGfp8_H.mjs +187 -0
- package/dist/logged-DQK3C64b.cjs +193 -0
- package/dist/memory-adapter-BlnDIAAX.cjs +154 -0
- package/dist/memory-adapter-Db3tsJTn.mjs +148 -0
- package/dist/middleware-CE6OhDkq.mjs +29 -0
- package/dist/middleware-CWvRH4EW.cjs +47 -0
- package/dist/mongodb-adapter-C_qGQED5.mjs +291 -0
- package/dist/mongodb-adapter-C_qfK87x.cjs +297 -0
- package/dist/node-sqlite-dialect-BfBzyOAg.mjs +155 -0
- package/dist/node-sqlite-dialect-mJWC8LWQ.cjs +156 -0
- package/dist/oauth2/index.cjs +25 -0
- package/dist/oauth2/index.d.cts +42 -0
- package/dist/oauth2/index.d.mts +42 -0
- package/dist/oauth2/index.mjs +16 -0
- package/dist/oauth2-B8M0lW9l.mjs +159 -0
- package/dist/oauth2-BLeOEi7Y.cjs +177 -0
- package/dist/origin-check-8Gajklvh.mjs +228 -0
- package/dist/origin-check-id9lTnqZ.cjs +246 -0
- package/dist/parser-CdncAl9i.cjs +83 -0
- package/dist/parser-CeAer-RM.mjs +71 -0
- package/dist/passkey-B6N20LSS.cjs +512 -0
- package/dist/passkey-DJsR_GX3.mjs +505 -0
- package/dist/plugins/access/index.cjs +4 -0
- package/dist/plugins/access/index.d.cts +2 -0
- package/dist/plugins/access/index.d.mts +2 -0
- package/dist/plugins/access/index.mjs +3 -0
- package/dist/plugins/bearer/index.cjs +7 -0
- package/dist/plugins/bearer/index.d.cts +4 -0
- package/dist/plugins/bearer/index.d.mts +4 -0
- package/dist/plugins/bearer/index.mjs +7 -0
- package/dist/plugins/index.cjs +49 -0
- package/dist/plugins/index.d.cts +9326 -0
- package/dist/plugins/index.d.mts +9326 -0
- package/dist/plugins/index.mjs +26 -0
- package/dist/plugins/passkey/index.cjs +15 -0
- package/dist/plugins/passkey/index.d.cts +4 -0
- package/dist/plugins/passkey/index.d.mts +4 -0
- package/dist/plugins/passkey/index.mjs +15 -0
- package/dist/plugins-C1lm2Wj3.cjs +5254 -0
- package/dist/plugins-Dai1QkRU.mjs +5199 -0
- package/dist/request-1NL_1lyJ.mjs +58 -0
- package/dist/request-CPNlp-DK.cjs +100 -0
- package/dist/schema-D-qjygfE.cjs +179 -0
- package/dist/schema-DTIwLLmf.mjs +125 -0
- package/dist/session-De9POJTW.cjs +641 -0
- package/dist/session-rH8ougDl.mjs +538 -0
- package/dist/social-providers/index.cjs +10 -0
- package/dist/social-providers/index.d.cts +2 -0
- package/dist/social-providers/index.d.mts +2 -0
- package/dist/social-providers/index.mjs +5 -0
- package/dist/social-providers-DcFNUT0S.cjs +13 -0
- package/dist/social-providers-DoYJhBe3.mjs +9 -0
- package/dist/state--f7fwIGh.cjs +99 -0
- package/dist/state-CqJfCIl9.mjs +86 -0
- package/dist/test-utils/index.cjs +27492 -0
- package/dist/test-utils/index.d.cts +4584 -0
- package/dist/test-utils/index.d.mts +4584 -0
- package/dist/test-utils/index.mjs +27490 -0
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +3 -0
- package/dist/types/index.d.mts +3 -0
- package/dist/types/index.mjs +1 -0
- package/dist/url-BoUuoIwZ.mjs +88 -0
- package/dist/url-D2yvKaM7.cjs +118 -0
- package/dist/utils/cookies.cjs +51 -0
- package/dist/utils/cookies.d.cts +179 -0
- package/dist/utils/cookies.d.mts +179 -0
- package/dist/utils/cookies.mjs +7 -0
- package/dist/utils-44aDDP8f.cjs +2 -0
- package/dist/utils-D4vZd1-9.mjs +4 -0
- package/dist/vanilla-Bu2PmFzE.cjs +30 -0
- package/dist/vanilla-TfHqeiC7.mjs +25 -0
- package/package.json +470 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as ContextVars } from "./hono-DuE14mmj.mjs";
|
|
2
|
+
import * as hono44 from "hono";
|
|
3
|
+
import * as _faire_auth_core_types39 from "@faire-auth/core/types";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/bearer/index.d.ts
|
|
6
|
+
interface BearerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* If true, only signed tokens
|
|
9
|
+
* will be converted to session
|
|
10
|
+
* cookies
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
requireSignature?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Converts bearer token to session cookie
|
|
18
|
+
*/
|
|
19
|
+
declare const bearer: (options?: BearerOptions) => {
|
|
20
|
+
id: "bearer";
|
|
21
|
+
hooks: {
|
|
22
|
+
before: {
|
|
23
|
+
matcher: (ctx: hono44.Context<ContextVars<any>, any, {}>) => boolean;
|
|
24
|
+
handler: (_opts: _faire_auth_core_types39.FaireAuthOptions<any>) => (ctx: hono44.Context<ContextVars<object>, string, {}>) => Promise<void>;
|
|
25
|
+
}[];
|
|
26
|
+
after: {
|
|
27
|
+
matcher: (_ctx: hono44.Context<ContextVars<any>, any, {}>) => true;
|
|
28
|
+
handler: (_opts: _faire_auth_core_types39.FaireAuthOptions<any>) => (ctx: hono44.Context<ContextVars<object>, string, {}>) => Promise<void>;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { bearer as t };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { I as FaireAuthOptions } from "./index-jlessPI0.mjs";
|
|
2
|
+
import { DBAdapter, DBAdapterDebugLogOption } from "@faire-auth/core/db/adapter";
|
|
3
|
+
import { Db, MongoClient } from "mongodb";
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/mongodb-adapter/mongodb-adapter.d.ts
|
|
6
|
+
interface MongoDBAdapterConfig {
|
|
7
|
+
/**
|
|
8
|
+
* MongoDB client instance
|
|
9
|
+
* If not provided, Database transactions won't be enabled.
|
|
10
|
+
*/
|
|
11
|
+
client?: MongoClient;
|
|
12
|
+
/**
|
|
13
|
+
* Enable debug logs for the adapter
|
|
14
|
+
*
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
debugLogs?: DBAdapterDebugLogOption;
|
|
18
|
+
/**
|
|
19
|
+
* Use plural table names
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
usePlural?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to execute multiple operations in a transaction.
|
|
26
|
+
*
|
|
27
|
+
* If the database doesn't support transactions,
|
|
28
|
+
* set this to `false` and operations will be executed sequentially.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
transaction?: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare const mongodbAdapter: (db: Db, config?: MongoDBAdapterConfig) => (options: FaireAuthOptions) => DBAdapter<FaireAuthOptions>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { mongodbAdapter as n, MongoDBAdapterConfig as t };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-oakRccI5.cjs');
|
|
2
|
+
require('./hono-Cdukwu5K.cjs');
|
|
3
|
+
const require_ip = require('./ip-B5SwXaMB.cjs');
|
|
4
|
+
require('./crypto-CcTxYH82.cjs');
|
|
5
|
+
require('./json-CcJ2HjGo.cjs');
|
|
6
|
+
require('./cookies-B5xeA6i8.cjs');
|
|
7
|
+
require('./logged-DQK3C64b.cjs');
|
|
8
|
+
require('./url-D2yvKaM7.cjs');
|
|
9
|
+
require('./middleware-CWvRH4EW.cjs');
|
|
10
|
+
require('./session-De9POJTW.cjs');
|
|
11
|
+
require('./origin-check-id9lTnqZ.cjs');
|
|
12
|
+
require('./email-verification-C-AsfJsb.cjs');
|
|
13
|
+
require('./oauth2-BLeOEi7Y.cjs');
|
|
14
|
+
const require_state = require('./state--f7fwIGh.cjs');
|
|
15
|
+
require('./social-providers-DcFNUT0S.cjs');
|
|
16
|
+
require('./api-Bm89BLgN.cjs');
|
|
17
|
+
const require_request = require('./request-CPNlp-DK.cjs');
|
|
18
|
+
require('./utils-44aDDP8f.cjs');
|
|
19
|
+
require('./schema-D-qjygfE.cjs');
|
|
20
|
+
const require_auth = require('./auth-Bo9PDt5j.cjs');
|
|
21
|
+
require('./kysely-adapter-Bxi7sPdG.cjs');
|
|
22
|
+
require('./adapter-factory-DT-_2aHJ.cjs');
|
|
23
|
+
require('./db-BTKyYu-_.cjs');
|
|
24
|
+
require('./memory-adapter-BlnDIAAX.cjs');
|
|
25
|
+
require('./defu-B0Svx_x4.cjs');
|
|
26
|
+
let __faire_auth_core_error = require("@faire-auth/core/error");
|
|
27
|
+
let __faire_auth_core_env = require("@faire-auth/core/env");
|
|
28
|
+
let __faire_auth_core_crypto = require("@faire-auth/core/crypto");
|
|
29
|
+
|
|
30
|
+
Object.defineProperty(exports, 'APIError', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return __faire_auth_core_error.APIError;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, 'ENV', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return __faire_auth_core_env.ENV;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, 'FaireAuthError', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return __faire_auth_core_error.FaireAuthError;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, 'MissingDependencyError', {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return __faire_auth_core_error.MissingDependencyError;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, 'createLogger', {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return __faire_auth_core_env.createLogger;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
exports.createTelemetry = require_auth.createTelemetry;
|
|
61
|
+
exports.defineOptions = require_auth.defineOptions;
|
|
62
|
+
exports.faireAuth = require_auth.faireAuth;
|
|
63
|
+
Object.defineProperty(exports, 'generateId', {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function () {
|
|
66
|
+
return __faire_auth_core_crypto.generateId;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, 'generateRandomString', {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () {
|
|
72
|
+
return __faire_auth_core_crypto.generateRandomString;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
exports.generateState = require_state.generateState;
|
|
76
|
+
exports.getCurrentAdapter = require_ip.getCurrentAdapter;
|
|
77
|
+
exports.getTelemetryAuthConfig = require_auth.getTelemetryAuthConfig;
|
|
78
|
+
Object.defineProperty(exports, 'logger', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return __faire_auth_core_env.logger;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
exports.mergeHeaders = require_request.mergeHeaders;
|
|
85
|
+
exports.parseState = require_state.parseState;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { $ as Client, A as logger, C as InternalLogger, Ct as InferPluginRateLimit, D as createLogger, E as Logger, F as DTO, H as InferApp, I as FaireAuthOptions, L as FaireAuthRateLimitOptions, M as generateState, N as parseState, O as generateId, P as CustomRules, Q as CamelCase, R as Hooks, S as ENV, St as InferPluginMiddleware, T as LogLevel, U as InferClient, V as InferAPI, Z as AtomListener, _ as MissingDependencyError, _t as FaireAuthPlugin, a as InferPluginTypes, an as AuthContext, at as InferAdditionalAsClient, b as createTelemetry, bt as InferPluginErrorCodes, c as Models, cn as Adapter, ct as InferPluginsFromClient, d as WithJsDoc, dn as DBAdapter, dt as IsSignal, et as ClientOptions, f as defineOptions, fn as DBAdapterInstance, ft as RevalidateOptions, g as FaireAuthError, gn as Where, gt as AuthPluginSchema, h as APIError, hn as TransactionAdapter, i as AdditionalUserFieldsOutput, it as InferActions, j as mergeHeaders, k as generateRandomString, l as RateLimit, ln as AdapterInstance, lt as InferSessionFromClient, mn as DBTransactionAdapter, mt as Store, n as AdditionalSessionFieldsOutput, nn as AuthFactory, nt as FaireAuthClientPlugin, o as InferSession, on as init, ot as InferAdditionalFromClient, p as faireAuth, pn as DBAdapterSchemaCreation, pt as SessionQueryParams, r as AdditionalUserFieldsInput, rn as AuthProperties, rt as Inc, s as InferUser, sn as getCurrentAdapter, st as InferErrorCodes, t as AdditionalSessionFieldsInput, tn as AuthEndpoint, tt as CreateSchemaType, u as Auth, un as AdapterSchemaCreation, ut as InferUserFromClient, v as OpenAPIHono, vt as InferOptionSchema, w as LogHandlerParams, x as TelemetryEvent, xt as InferPluginHooks, y as getTelemetryAuthConfig, yt as InferPluginDTO, z as Middleware } from "./index-B-WeOMzg.cjs";
|
|
2
|
+
import { n as Execute, r as ToExecFull, t as ContextVars } from "./hono-DOM31WQz.cjs";
|
|
3
|
+
export * from "zod";
|
|
4
|
+
export * from "zod/v4/core";
|
|
5
|
+
export { APIError, Adapter, AdapterInstance, AdapterSchemaCreation, AdditionalSessionFieldsInput, AdditionalSessionFieldsOutput, AdditionalUserFieldsInput, AdditionalUserFieldsOutput, AtomListener, Auth, AuthContext, AuthEndpoint, AuthFactory, AuthPluginSchema, AuthProperties, CamelCase, Client, ClientOptions, ContextVars, CreateSchemaType, CustomRules, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, DTO, ENV, Execute, FaireAuthClientPlugin, FaireAuthError, FaireAuthOptions, FaireAuthPlugin, FaireAuthRateLimitOptions, Hooks, Inc, InferAPI, InferActions, InferAdditionalAsClient, InferAdditionalFromClient, InferApp, InferClient, InferErrorCodes, InferOptionSchema, InferPluginDTO, InferPluginErrorCodes, InferPluginHooks, InferPluginMiddleware, InferPluginRateLimit, InferPluginTypes, InferPluginsFromClient, InferSession, InferSessionFromClient, InferUser, InferUserFromClient, InternalLogger, IsSignal, LogHandlerParams, LogLevel, Logger, Middleware, MissingDependencyError, Models, OpenAPIHono, RateLimit, RevalidateOptions, SessionQueryParams, Store, TelemetryEvent, ToExecFull, TransactionAdapter, Where, WithJsDoc, createLogger, createTelemetry, defineOptions, faireAuth, generateId, generateRandomString, generateState, getCurrentAdapter, getTelemetryAuthConfig, init, logger, mergeHeaders, parseState };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { $ as Client, A as logger, C as InternalLogger, Ct as InferPluginRateLimit, D as createLogger, E as Logger, F as DTO, H as InferApp, I as FaireAuthOptions, L as FaireAuthRateLimitOptions, M as generateState, N as parseState, O as generateId, P as CustomRules, Q as CamelCase, R as Hooks, S as ENV, St as InferPluginMiddleware, T as LogLevel, U as InferClient, V as InferAPI, Z as AtomListener, _ as MissingDependencyError, _t as FaireAuthPlugin, a as InferPluginTypes, an as AuthContext, at as InferAdditionalAsClient, b as createTelemetry, bt as InferPluginErrorCodes, c as Models, cn as Adapter, ct as InferPluginsFromClient, d as WithJsDoc, dn as DBAdapter, dt as IsSignal, et as ClientOptions, f as defineOptions, fn as DBAdapterInstance, ft as RevalidateOptions, g as FaireAuthError, gn as Where, gt as AuthPluginSchema, h as APIError, hn as TransactionAdapter, i as AdditionalUserFieldsOutput, it as InferActions, j as mergeHeaders, k as generateRandomString, l as RateLimit, ln as AdapterInstance, lt as InferSessionFromClient, mn as DBTransactionAdapter, mt as Store, n as AdditionalSessionFieldsOutput, nn as AuthFactory, nt as FaireAuthClientPlugin, o as InferSession, on as init, ot as InferAdditionalFromClient, p as faireAuth, pn as DBAdapterSchemaCreation, pt as SessionQueryParams, r as AdditionalUserFieldsInput, rn as AuthProperties, rt as Inc, s as InferUser, sn as getCurrentAdapter, st as InferErrorCodes, t as AdditionalSessionFieldsInput, tn as AuthEndpoint, tt as CreateSchemaType, u as Auth, un as AdapterSchemaCreation, ut as InferUserFromClient, v as OpenAPIHono, vt as InferOptionSchema, w as LogHandlerParams, x as TelemetryEvent, xt as InferPluginHooks, y as getTelemetryAuthConfig, yt as InferPluginDTO, z as Middleware } from "./index-jlessPI0.mjs";
|
|
2
|
+
import { n as Execute, r as ToExecFull, t as ContextVars } from "./hono-DuE14mmj.mjs";
|
|
3
|
+
export * from "zod";
|
|
4
|
+
export * from "zod/v4/core";
|
|
5
|
+
export { APIError, Adapter, AdapterInstance, AdapterSchemaCreation, AdditionalSessionFieldsInput, AdditionalSessionFieldsOutput, AdditionalUserFieldsInput, AdditionalUserFieldsOutput, AtomListener, Auth, AuthContext, AuthEndpoint, AuthFactory, AuthPluginSchema, AuthProperties, CamelCase, Client, ClientOptions, ContextVars, CreateSchemaType, CustomRules, DBAdapter, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, DTO, ENV, Execute, FaireAuthClientPlugin, FaireAuthError, FaireAuthOptions, FaireAuthPlugin, FaireAuthRateLimitOptions, Hooks, Inc, InferAPI, InferActions, InferAdditionalAsClient, InferAdditionalFromClient, InferApp, InferClient, InferErrorCodes, InferOptionSchema, InferPluginDTO, InferPluginErrorCodes, InferPluginHooks, InferPluginMiddleware, InferPluginRateLimit, InferPluginTypes, InferPluginsFromClient, InferSession, InferSessionFromClient, InferUser, InferUserFromClient, InternalLogger, IsSignal, LogHandlerParams, LogLevel, Logger, Middleware, MissingDependencyError, Models, OpenAPIHono, RateLimit, RevalidateOptions, SessionQueryParams, Store, TelemetryEvent, ToExecFull, TransactionAdapter, Where, WithJsDoc, createLogger, createTelemetry, defineOptions, faireAuth, generateId, generateRandomString, generateState, getCurrentAdapter, getTelemetryAuthConfig, init, logger, mergeHeaders, parseState };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./hono-CoKYWnXA.mjs";
|
|
2
|
+
import { n as getCurrentAdapter } from "./ip-BjNYspCH.mjs";
|
|
3
|
+
import "./crypto-CyQRFtkq.mjs";
|
|
4
|
+
import "./json-B1v2qRTQ.mjs";
|
|
5
|
+
import "./cookies-Ch1JfQIz.mjs";
|
|
6
|
+
import "./logged-CyGfp8_H.mjs";
|
|
7
|
+
import "./url-BoUuoIwZ.mjs";
|
|
8
|
+
import "./middleware-CE6OhDkq.mjs";
|
|
9
|
+
import "./session-rH8ougDl.mjs";
|
|
10
|
+
import "./origin-check-8Gajklvh.mjs";
|
|
11
|
+
import "./email-verification-CWhj2qfb.mjs";
|
|
12
|
+
import "./oauth2-B8M0lW9l.mjs";
|
|
13
|
+
import { n as parseState, t as generateState } from "./state-CqJfCIl9.mjs";
|
|
14
|
+
import "./social-providers-DoYJhBe3.mjs";
|
|
15
|
+
import "./api-_B7qO28y.mjs";
|
|
16
|
+
import { n as mergeHeaders } from "./request-1NL_1lyJ.mjs";
|
|
17
|
+
import { a as logger, i as generateRandomString, n as createLogger, r as generateId, t as ENV } from "./utils-D4vZd1-9.mjs";
|
|
18
|
+
import "./schema-DTIwLLmf.mjs";
|
|
19
|
+
import { a as getTelemetryAuthConfig, i as createTelemetry, n as faireAuth, t as defineOptions } from "./auth-Ds4AG4h4.mjs";
|
|
20
|
+
import "./kysely-adapter-DRuoT_X8.mjs";
|
|
21
|
+
import "./adapter-factory-BXei1QRX.mjs";
|
|
22
|
+
import "./db-xiJtoDgz.mjs";
|
|
23
|
+
import "./memory-adapter-Db3tsJTn.mjs";
|
|
24
|
+
import "./defu-SZkpHhbR.mjs";
|
|
25
|
+
import { APIError, FaireAuthError, MissingDependencyError } from "@faire-auth/core/error";
|
|
26
|
+
|
|
27
|
+
export { APIError, ENV, FaireAuthError, MissingDependencyError, createLogger, createTelemetry, defineOptions, faireAuth, generateId, generateRandomString, generateState, getCurrentAdapter, getTelemetryAuthConfig, logger, mergeHeaders, parseState };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require('../crypto-CcTxYH82.cjs');
|
|
2
|
+
require('../json-CcJ2HjGo.cjs');
|
|
3
|
+
const require_cookies = require('../cookies-B5xeA6i8.cjs');
|
|
4
|
+
const require_middleware = require('../middleware-CWvRH4EW.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/integrations/next-js.ts
|
|
7
|
+
function toNextJsHandler(auth) {
|
|
8
|
+
const handler = async (request) => "handler" in auth ? auth.handler(request) : auth(request);
|
|
9
|
+
return {
|
|
10
|
+
GET: handler,
|
|
11
|
+
POST: handler
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const nextCookies = () => ({
|
|
15
|
+
id: "next-cookies",
|
|
16
|
+
hooks: { after: [{
|
|
17
|
+
matcher: (_ctx) => true,
|
|
18
|
+
handler: (_authOptions) => require_middleware.createHook()(async (ctx) => {
|
|
19
|
+
const setCookies = ctx.res.headers.getSetCookie();
|
|
20
|
+
if (!setCookies.length) return;
|
|
21
|
+
const parsed = require_cookies.parseSetCookieHeader(setCookies);
|
|
22
|
+
const { cookies } = await import("next/headers");
|
|
23
|
+
let cookieHelper;
|
|
24
|
+
try {
|
|
25
|
+
cookieHelper = await cookies();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && error.message.startsWith("`cookies` was called outside a request scope.")) return;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
parsed.forEach((value, key) => {
|
|
31
|
+
if (!key) return;
|
|
32
|
+
const opts = {
|
|
33
|
+
sameSite: value.samesite,
|
|
34
|
+
secure: value.secure,
|
|
35
|
+
maxAge: value["max-age"],
|
|
36
|
+
httpOnly: value.httponly,
|
|
37
|
+
domain: value.domain,
|
|
38
|
+
path: value.path
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
cookieHelper.set(key, decodeURIComponent(value.value), opts);
|
|
42
|
+
} catch (e) {}
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
}] }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
exports.nextCookies = nextCookies;
|
|
50
|
+
exports.toNextJsHandler = toNextJsHandler;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../index-B-WeOMzg.cjs";
|
|
2
|
+
import { t as ContextVars } from "../hono-DOM31WQz.cjs";
|
|
3
|
+
import * as _faire_auth_core_types29 from "@faire-auth/core/types";
|
|
4
|
+
import * as hono29 from "hono";
|
|
5
|
+
|
|
6
|
+
//#region src/integrations/next-js.d.ts
|
|
7
|
+
declare function toNextJsHandler(auth: {
|
|
8
|
+
handler: (request: Request) => Promise<Response>;
|
|
9
|
+
} | ((request: Request) => Promise<Response>)): {
|
|
10
|
+
GET: (request: Request) => Promise<Response>;
|
|
11
|
+
POST: (request: Request) => Promise<Response>;
|
|
12
|
+
};
|
|
13
|
+
declare const nextCookies: () => {
|
|
14
|
+
id: "next-cookies";
|
|
15
|
+
hooks: {
|
|
16
|
+
after: {
|
|
17
|
+
matcher: (_ctx: hono29.Context<ContextVars<any>, any, {}>) => true;
|
|
18
|
+
handler: (_authOptions: _faire_auth_core_types29.FaireAuthOptions<any>) => (ctx: hono29.Context<ContextVars<object>, string, {}>) => Promise<void>;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { nextCookies, toNextJsHandler };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "../index-jlessPI0.mjs";
|
|
2
|
+
import { t as ContextVars } from "../hono-DuE14mmj.mjs";
|
|
3
|
+
import * as hono0 from "hono";
|
|
4
|
+
import * as _faire_auth_core_types0 from "@faire-auth/core/types";
|
|
5
|
+
|
|
6
|
+
//#region src/integrations/next-js.d.ts
|
|
7
|
+
declare function toNextJsHandler(auth: {
|
|
8
|
+
handler: (request: Request) => Promise<Response>;
|
|
9
|
+
} | ((request: Request) => Promise<Response>)): {
|
|
10
|
+
GET: (request: Request) => Promise<Response>;
|
|
11
|
+
POST: (request: Request) => Promise<Response>;
|
|
12
|
+
};
|
|
13
|
+
declare const nextCookies: () => {
|
|
14
|
+
id: "next-cookies";
|
|
15
|
+
hooks: {
|
|
16
|
+
after: {
|
|
17
|
+
matcher: (_ctx: hono0.Context<ContextVars<any>, any, {}>) => true;
|
|
18
|
+
handler: (_authOptions: _faire_auth_core_types0.FaireAuthOptions<any>) => (ctx: hono0.Context<ContextVars<object>, string, {}>) => Promise<void>;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { nextCookies, toNextJsHandler };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "../crypto-CyQRFtkq.mjs";
|
|
2
|
+
import "../json-B1v2qRTQ.mjs";
|
|
3
|
+
import { p as parseSetCookieHeader } from "../cookies-Ch1JfQIz.mjs";
|
|
4
|
+
import { n as createHook } from "../middleware-CE6OhDkq.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/integrations/next-js.ts
|
|
7
|
+
function toNextJsHandler(auth) {
|
|
8
|
+
const handler = async (request) => "handler" in auth ? auth.handler(request) : auth(request);
|
|
9
|
+
return {
|
|
10
|
+
GET: handler,
|
|
11
|
+
POST: handler
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const nextCookies = () => ({
|
|
15
|
+
id: "next-cookies",
|
|
16
|
+
hooks: { after: [{
|
|
17
|
+
matcher: (_ctx) => true,
|
|
18
|
+
handler: (_authOptions) => createHook()(async (ctx) => {
|
|
19
|
+
const setCookies = ctx.res.headers.getSetCookie();
|
|
20
|
+
if (!setCookies.length) return;
|
|
21
|
+
const parsed = parseSetCookieHeader(setCookies);
|
|
22
|
+
const { cookies } = await import("next/headers");
|
|
23
|
+
let cookieHelper;
|
|
24
|
+
try {
|
|
25
|
+
cookieHelper = await cookies();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && error.message.startsWith("`cookies` was called outside a request scope.")) return;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
parsed.forEach((value, key) => {
|
|
31
|
+
if (!key) return;
|
|
32
|
+
const opts = {
|
|
33
|
+
sameSite: value.samesite,
|
|
34
|
+
secure: value.secure,
|
|
35
|
+
maxAge: value["max-age"],
|
|
36
|
+
httpOnly: value.httponly,
|
|
37
|
+
domain: value.domain,
|
|
38
|
+
path: value.path
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
cookieHelper.set(key, decodeURIComponent(value.value), opts);
|
|
42
|
+
} catch (e) {}
|
|
43
|
+
});
|
|
44
|
+
})
|
|
45
|
+
}] }
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { nextCookies, toNextJsHandler };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/integrations/node.ts
|
|
3
|
+
function get_raw_body(req, body_size_limit) {
|
|
4
|
+
const h = req.headers;
|
|
5
|
+
if (!h["content-type"]) return null;
|
|
6
|
+
const content_length = Number(h["content-length"]);
|
|
7
|
+
if (req.httpVersionMajor === 1 && isNaN(content_length) && h["transfer-encoding"] == null || content_length === 0) return null;
|
|
8
|
+
let length = content_length;
|
|
9
|
+
if (body_size_limit) {
|
|
10
|
+
if (!length) length = body_size_limit;
|
|
11
|
+
else if (length > body_size_limit) throw Error(`Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`);
|
|
12
|
+
}
|
|
13
|
+
if (req.destroyed) {
|
|
14
|
+
const readable = new ReadableStream();
|
|
15
|
+
readable.cancel();
|
|
16
|
+
return readable;
|
|
17
|
+
}
|
|
18
|
+
let size = 0;
|
|
19
|
+
let cancelled = false;
|
|
20
|
+
return new ReadableStream({
|
|
21
|
+
start(controller) {
|
|
22
|
+
req.on("error", (error) => {
|
|
23
|
+
cancelled = true;
|
|
24
|
+
controller.error(error);
|
|
25
|
+
});
|
|
26
|
+
req.on("end", () => {
|
|
27
|
+
if (cancelled) return;
|
|
28
|
+
controller.close();
|
|
29
|
+
});
|
|
30
|
+
req.on("data", (chunk) => {
|
|
31
|
+
if (cancelled) return;
|
|
32
|
+
size += chunk.length;
|
|
33
|
+
if (size > length) {
|
|
34
|
+
cancelled = true;
|
|
35
|
+
controller.error(/* @__PURE__ */ new Error(`request body size exceeded ${content_length ? "'content-length'" : "BODY_SIZE_LIMIT"} of ${length}`));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
controller.enqueue(chunk);
|
|
39
|
+
if (controller.desiredSize === null || controller.desiredSize <= 0) req.pause();
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
pull() {
|
|
43
|
+
req.resume();
|
|
44
|
+
},
|
|
45
|
+
cancel(reason) {
|
|
46
|
+
cancelled = true;
|
|
47
|
+
req.destroy(reason);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function getRequest({ request, base, bodySizeLimit }) {
|
|
52
|
+
const baseUrl = request?.baseUrl;
|
|
53
|
+
const fullPath = baseUrl ? baseUrl + request.url : request.url;
|
|
54
|
+
const maybeConsumedReq = request;
|
|
55
|
+
let body = void 0;
|
|
56
|
+
const method = request.method;
|
|
57
|
+
if (method !== "GET" && method !== "HEAD") if (maybeConsumedReq.body !== void 0) {
|
|
58
|
+
const bodyContent = typeof maybeConsumedReq.body === "string" ? maybeConsumedReq.body : JSON.stringify(maybeConsumedReq.body);
|
|
59
|
+
body = new ReadableStream({ start(controller) {
|
|
60
|
+
controller.enqueue(new TextEncoder().encode(bodyContent));
|
|
61
|
+
controller.close();
|
|
62
|
+
} });
|
|
63
|
+
} else body = get_raw_body(request, bodySizeLimit);
|
|
64
|
+
return new Request(base + fullPath, {
|
|
65
|
+
duplex: "half",
|
|
66
|
+
method: request.method,
|
|
67
|
+
body,
|
|
68
|
+
headers: request.headers
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async function setResponse(res, response) {
|
|
72
|
+
for (const [key, value] of response.headers) try {
|
|
73
|
+
res.setHeader(key, key === "set-cookie" ? response.headers.getSetCookie() : value);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
76
|
+
res.writeHead(500).end(String(error));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
res.writeHead(response.status);
|
|
80
|
+
if (!response.body) {
|
|
81
|
+
res.end();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (response.body.locked) {
|
|
85
|
+
res.end("Fatal error: Response body is locked. This can happen when the response was already read (for example through 'response.json()' or 'response.text()').");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const reader = response.body.getReader();
|
|
89
|
+
if (res.destroyed) {
|
|
90
|
+
reader.cancel();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const cancel = (error) => {
|
|
94
|
+
res.off("close", cancel);
|
|
95
|
+
res.off("error", cancel);
|
|
96
|
+
reader.cancel(error).catch(() => {});
|
|
97
|
+
if (error) res.destroy(error);
|
|
98
|
+
};
|
|
99
|
+
res.on("close", cancel);
|
|
100
|
+
res.on("error", cancel);
|
|
101
|
+
await next();
|
|
102
|
+
async function next() {
|
|
103
|
+
try {
|
|
104
|
+
for (;;) {
|
|
105
|
+
const { done, value } = await reader.read();
|
|
106
|
+
if (done) break;
|
|
107
|
+
if (!res.write(value)) {
|
|
108
|
+
res.once("drain", next);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
res.end();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function toNode(handler) {
|
|
119
|
+
return async (req, res) => {
|
|
120
|
+
return setResponse(res, await handler(getRequest({
|
|
121
|
+
base: `${req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http")}://${req.headers[":authority"] || req.headers.host}`,
|
|
122
|
+
request: req
|
|
123
|
+
})));
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const toNodeHandler = (auth) => "handler" in auth ? toNode(auth.handler) : toNode(auth);
|
|
127
|
+
function fromNodeHeaders(nodeHeaders) {
|
|
128
|
+
const webHeaders = new Headers();
|
|
129
|
+
for (const [key, value] of Object.entries(nodeHeaders)) if (value !== void 0) if (Array.isArray(value)) value.forEach((v) => webHeaders.append(key, v));
|
|
130
|
+
else webHeaders.set(key, value);
|
|
131
|
+
return webHeaders;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
exports.fromNodeHeaders = fromNodeHeaders;
|
|
136
|
+
exports.getRequest = getRequest;
|
|
137
|
+
exports.setResponse = setResponse;
|
|
138
|
+
exports.toNode = toNode;
|
|
139
|
+
exports.toNodeHandler = toNodeHandler;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { u as Auth } from "../index-B-WeOMzg.cjs";
|
|
2
|
+
import "../hono-DOM31WQz.cjs";
|
|
3
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/node.d.ts
|
|
6
|
+
declare function getRequest({
|
|
7
|
+
request,
|
|
8
|
+
base,
|
|
9
|
+
bodySizeLimit
|
|
10
|
+
}: {
|
|
11
|
+
base: string;
|
|
12
|
+
bodySizeLimit?: number;
|
|
13
|
+
request: IncomingMessage;
|
|
14
|
+
}): Request;
|
|
15
|
+
declare function setResponse(res: ServerResponse, response: Response): Promise<void>;
|
|
16
|
+
declare function toNode(handler: Auth["handler"]): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
17
|
+
declare const toNodeHandler: (auth: {
|
|
18
|
+
handler: Auth["handler"];
|
|
19
|
+
} | Auth["handler"]) => (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
20
|
+
declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { fromNodeHeaders, getRequest, setResponse, toNode, toNodeHandler };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { u as Auth } from "../index-jlessPI0.mjs";
|
|
2
|
+
import "../hono-DuE14mmj.mjs";
|
|
3
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http";
|
|
4
|
+
|
|
5
|
+
//#region src/integrations/node.d.ts
|
|
6
|
+
declare function getRequest({
|
|
7
|
+
request,
|
|
8
|
+
base,
|
|
9
|
+
bodySizeLimit
|
|
10
|
+
}: {
|
|
11
|
+
base: string;
|
|
12
|
+
bodySizeLimit?: number;
|
|
13
|
+
request: IncomingMessage;
|
|
14
|
+
}): Request;
|
|
15
|
+
declare function setResponse(res: ServerResponse, response: Response): Promise<void>;
|
|
16
|
+
declare function toNode(handler: Auth["handler"]): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
17
|
+
declare const toNodeHandler: (auth: {
|
|
18
|
+
handler: Auth["handler"];
|
|
19
|
+
} | Auth["handler"]) => (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
20
|
+
declare function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { fromNodeHeaders, getRequest, setResponse, toNode, toNodeHandler };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
//#region src/integrations/node.ts
|
|
2
|
+
function get_raw_body(req, body_size_limit) {
|
|
3
|
+
const h = req.headers;
|
|
4
|
+
if (!h["content-type"]) return null;
|
|
5
|
+
const content_length = Number(h["content-length"]);
|
|
6
|
+
if (req.httpVersionMajor === 1 && isNaN(content_length) && h["transfer-encoding"] == null || content_length === 0) return null;
|
|
7
|
+
let length = content_length;
|
|
8
|
+
if (body_size_limit) {
|
|
9
|
+
if (!length) length = body_size_limit;
|
|
10
|
+
else if (length > body_size_limit) throw Error(`Received content-length of ${length}, but only accept up to ${body_size_limit} bytes.`);
|
|
11
|
+
}
|
|
12
|
+
if (req.destroyed) {
|
|
13
|
+
const readable = new ReadableStream();
|
|
14
|
+
readable.cancel();
|
|
15
|
+
return readable;
|
|
16
|
+
}
|
|
17
|
+
let size = 0;
|
|
18
|
+
let cancelled = false;
|
|
19
|
+
return new ReadableStream({
|
|
20
|
+
start(controller) {
|
|
21
|
+
req.on("error", (error) => {
|
|
22
|
+
cancelled = true;
|
|
23
|
+
controller.error(error);
|
|
24
|
+
});
|
|
25
|
+
req.on("end", () => {
|
|
26
|
+
if (cancelled) return;
|
|
27
|
+
controller.close();
|
|
28
|
+
});
|
|
29
|
+
req.on("data", (chunk) => {
|
|
30
|
+
if (cancelled) return;
|
|
31
|
+
size += chunk.length;
|
|
32
|
+
if (size > length) {
|
|
33
|
+
cancelled = true;
|
|
34
|
+
controller.error(/* @__PURE__ */ new Error(`request body size exceeded ${content_length ? "'content-length'" : "BODY_SIZE_LIMIT"} of ${length}`));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
controller.enqueue(chunk);
|
|
38
|
+
if (controller.desiredSize === null || controller.desiredSize <= 0) req.pause();
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
pull() {
|
|
42
|
+
req.resume();
|
|
43
|
+
},
|
|
44
|
+
cancel(reason) {
|
|
45
|
+
cancelled = true;
|
|
46
|
+
req.destroy(reason);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function getRequest({ request, base, bodySizeLimit }) {
|
|
51
|
+
const baseUrl = request?.baseUrl;
|
|
52
|
+
const fullPath = baseUrl ? baseUrl + request.url : request.url;
|
|
53
|
+
const maybeConsumedReq = request;
|
|
54
|
+
let body = void 0;
|
|
55
|
+
const method = request.method;
|
|
56
|
+
if (method !== "GET" && method !== "HEAD") if (maybeConsumedReq.body !== void 0) {
|
|
57
|
+
const bodyContent = typeof maybeConsumedReq.body === "string" ? maybeConsumedReq.body : JSON.stringify(maybeConsumedReq.body);
|
|
58
|
+
body = new ReadableStream({ start(controller) {
|
|
59
|
+
controller.enqueue(new TextEncoder().encode(bodyContent));
|
|
60
|
+
controller.close();
|
|
61
|
+
} });
|
|
62
|
+
} else body = get_raw_body(request, bodySizeLimit);
|
|
63
|
+
return new Request(base + fullPath, {
|
|
64
|
+
duplex: "half",
|
|
65
|
+
method: request.method,
|
|
66
|
+
body,
|
|
67
|
+
headers: request.headers
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function setResponse(res, response) {
|
|
71
|
+
for (const [key, value] of response.headers) try {
|
|
72
|
+
res.setHeader(key, key === "set-cookie" ? response.headers.getSetCookie() : value);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
75
|
+
res.writeHead(500).end(String(error));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
res.writeHead(response.status);
|
|
79
|
+
if (!response.body) {
|
|
80
|
+
res.end();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (response.body.locked) {
|
|
84
|
+
res.end("Fatal error: Response body is locked. This can happen when the response was already read (for example through 'response.json()' or 'response.text()').");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const reader = response.body.getReader();
|
|
88
|
+
if (res.destroyed) {
|
|
89
|
+
reader.cancel();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const cancel = (error) => {
|
|
93
|
+
res.off("close", cancel);
|
|
94
|
+
res.off("error", cancel);
|
|
95
|
+
reader.cancel(error).catch(() => {});
|
|
96
|
+
if (error) res.destroy(error);
|
|
97
|
+
};
|
|
98
|
+
res.on("close", cancel);
|
|
99
|
+
res.on("error", cancel);
|
|
100
|
+
await next();
|
|
101
|
+
async function next() {
|
|
102
|
+
try {
|
|
103
|
+
for (;;) {
|
|
104
|
+
const { done, value } = await reader.read();
|
|
105
|
+
if (done) break;
|
|
106
|
+
if (!res.write(value)) {
|
|
107
|
+
res.once("drain", next);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
res.end();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
cancel(error instanceof Error ? error : new Error(String(error)));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function toNode(handler) {
|
|
118
|
+
return async (req, res) => {
|
|
119
|
+
return setResponse(res, await handler(getRequest({
|
|
120
|
+
base: `${req.headers["x-forwarded-proto"] || (req.socket.encrypted ? "https" : "http")}://${req.headers[":authority"] || req.headers.host}`,
|
|
121
|
+
request: req
|
|
122
|
+
})));
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const toNodeHandler = (auth) => "handler" in auth ? toNode(auth.handler) : toNode(auth);
|
|
126
|
+
function fromNodeHeaders(nodeHeaders) {
|
|
127
|
+
const webHeaders = new Headers();
|
|
128
|
+
for (const [key, value] of Object.entries(nodeHeaders)) if (value !== void 0) if (Array.isArray(value)) value.forEach((v) => webHeaders.append(key, v));
|
|
129
|
+
else webHeaders.set(key, value);
|
|
130
|
+
return webHeaders;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { fromNodeHeaders, getRequest, setResponse, toNode, toNodeHandler };
|