@fengsoft/auth-fastify 0.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/CHANGELOG.md +7 -0
- package/LICENSE +100 -0
- package/README.md +24 -0
- package/dist/auth-contracts/src/index.d.ts +89 -0
- package/dist/auth-contracts/src/index.d.ts.map +1 -0
- package/dist/auth-contracts/src/index.js +2 -0
- package/dist/auth-contracts/src/index.js.map +1 -0
- package/dist/auth-core/src/index.d.ts +105 -0
- package/dist/auth-core/src/index.d.ts.map +1 -0
- package/dist/auth-core/src/index.js +227 -0
- package/dist/auth-core/src/index.js.map +1 -0
- package/dist/auth-fastify/src/index.d.ts +19 -0
- package/dist/auth-fastify/src/index.d.ts.map +1 -0
- package/dist/auth-fastify/src/index.js +104 -0
- package/dist/auth-fastify/src/index.js.map +1 -0
- package/dist/foundation-config/src/index.d.ts +9 -0
- package/dist/foundation-config/src/index.d.ts.map +1 -0
- package/dist/foundation-config/src/index.js +28 -0
- package/dist/foundation-config/src/index.js.map +1 -0
- package/dist/foundation-contracts/src/index.d.ts +24 -0
- package/dist/foundation-contracts/src/index.d.ts.map +1 -0
- package/dist/foundation-contracts/src/index.js +4 -0
- package/dist/foundation-contracts/src/index.js.map +1 -0
- package/dist/foundation-observability/src/index.d.ts +16 -0
- package/dist/foundation-observability/src/index.d.ts.map +1 -0
- package/dist/foundation-observability/src/index.js +43 -0
- package/dist/foundation-observability/src/index.js.map +1 -0
- package/package.json +33 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
|
34
|
+
available under the License, as indicated by a copyright notice that is included
|
|
35
|
+
in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship.
|
|
41
|
+
|
|
42
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
43
|
+
of the Work and any modifications or additions to that Work or Derivative Works,
|
|
44
|
+
that is intentionally submitted to Licensor for inclusion in the Work by the
|
|
45
|
+
copyright owner or by an individual or Legal Entity authorized to submit on
|
|
46
|
+
behalf of the copyright owner.
|
|
47
|
+
|
|
48
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
49
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
50
|
+
incorporated within the Work.
|
|
51
|
+
|
|
52
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
53
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
54
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
55
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
56
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
57
|
+
Object form.
|
|
58
|
+
|
|
59
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
60
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
61
|
+
no-charge, royalty-free, irrevocable patent license to make, have made, use,
|
|
62
|
+
offer to sell, sell, import, and otherwise transfer the Work.
|
|
63
|
+
|
|
64
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
65
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
66
|
+
Source or Object form, provided that You meet the following conditions:
|
|
67
|
+
|
|
68
|
+
You must give any other recipients of the Work or Derivative Works a copy of
|
|
69
|
+
this License; and
|
|
70
|
+
|
|
71
|
+
You must cause any modified files to carry prominent notices stating that You
|
|
72
|
+
changed the files; and
|
|
73
|
+
|
|
74
|
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
|
75
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
76
|
+
of the Work; and
|
|
77
|
+
|
|
78
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
|
79
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
80
|
+
attribution notices contained within such NOTICE file.
|
|
81
|
+
|
|
82
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
83
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
84
|
+
Licensor shall be under the terms and conditions of this License.
|
|
85
|
+
|
|
86
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
87
|
+
trademarks, service marks, or product names of the Licensor.
|
|
88
|
+
|
|
89
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
90
|
+
writing, Licensor provides the Work on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
91
|
+
CONDITIONS OF ANY KIND, either express or implied.
|
|
92
|
+
|
|
93
|
+
8. Limitation of Liability. In no event and under no legal theory shall any
|
|
94
|
+
Contributor be liable to You for damages arising as a result of this License or
|
|
95
|
+
out of the use or inability to use the Work.
|
|
96
|
+
|
|
97
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
98
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
99
|
+
acceptance of support, warranty, indemnity, or other liability obligations.
|
|
100
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @fengsoft/auth-fastify
|
|
2
|
+
|
|
3
|
+
Fastify adapter surface for Better Auth routes, session loading, and request guards.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @fengsoft/auth-fastify fastify better-auth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use When
|
|
12
|
+
|
|
13
|
+
- you are wiring Better Auth into a Fastify app
|
|
14
|
+
- you want reusable route plugins and session hydration helpers
|
|
15
|
+
|
|
16
|
+
## Related Packages
|
|
17
|
+
|
|
18
|
+
- `@fengsoft/auth-core`
|
|
19
|
+
- `@fengsoft/auth-organizations`
|
|
20
|
+
|
|
21
|
+
## Source
|
|
22
|
+
|
|
23
|
+
- Repo: `fengsoft/auth-core`
|
|
24
|
+
- Docs: see the root repository README and docs app for architecture and adoption guides
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Id, Timestamp } from "@fengsoft/foundation-contracts";
|
|
2
|
+
export declare const AUTH_ROLES: readonly ["owner", "admin", "member", "viewer"];
|
|
3
|
+
export type AuthRole = (typeof AUTH_ROLES)[number];
|
|
4
|
+
export type AuthPermission = string;
|
|
5
|
+
export type AuthUser = {
|
|
6
|
+
id: Id;
|
|
7
|
+
email: string;
|
|
8
|
+
name: string | null;
|
|
9
|
+
emailVerified: boolean;
|
|
10
|
+
createdAt: Timestamp;
|
|
11
|
+
updatedAt: Timestamp;
|
|
12
|
+
};
|
|
13
|
+
export type AuthSession = {
|
|
14
|
+
id: Id;
|
|
15
|
+
user: AuthUser;
|
|
16
|
+
activeOrganizationId: Id | null;
|
|
17
|
+
expiresAt: Timestamp;
|
|
18
|
+
createdAt: Timestamp;
|
|
19
|
+
};
|
|
20
|
+
export type AuthOrganization = {
|
|
21
|
+
id: Id;
|
|
22
|
+
name: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
createdAt: Timestamp;
|
|
25
|
+
updatedAt: Timestamp;
|
|
26
|
+
};
|
|
27
|
+
export type AuthMembership = {
|
|
28
|
+
id: Id;
|
|
29
|
+
organizationId: Id;
|
|
30
|
+
userId: Id;
|
|
31
|
+
role: AuthRole;
|
|
32
|
+
permissions: AuthPermission[];
|
|
33
|
+
createdAt: Timestamp;
|
|
34
|
+
};
|
|
35
|
+
export type AuthInvite = {
|
|
36
|
+
id: Id;
|
|
37
|
+
email: string;
|
|
38
|
+
organizationId: Id;
|
|
39
|
+
role: AuthRole;
|
|
40
|
+
status: "pending" | "accepted" | "revoked";
|
|
41
|
+
expiresAt: Timestamp;
|
|
42
|
+
createdAt: Timestamp;
|
|
43
|
+
};
|
|
44
|
+
export type AuthApiKeyOwnerType = "user" | "organization";
|
|
45
|
+
export type AuthApiKeyPermissions = Record<string, string[]>;
|
|
46
|
+
export type AuthApiKey = {
|
|
47
|
+
id: Id;
|
|
48
|
+
configId: string;
|
|
49
|
+
label: string | null;
|
|
50
|
+
start: string | null;
|
|
51
|
+
prefix: string | null;
|
|
52
|
+
ownerType: AuthApiKeyOwnerType;
|
|
53
|
+
ownerId: Id;
|
|
54
|
+
enabled: boolean;
|
|
55
|
+
permissions: AuthApiKeyPermissions | null;
|
|
56
|
+
metadata: Record<string, unknown> | null;
|
|
57
|
+
rateLimitEnabled: boolean;
|
|
58
|
+
rateLimitTimeWindow: number | null;
|
|
59
|
+
rateLimitMax: number | null;
|
|
60
|
+
requestCount: number;
|
|
61
|
+
remaining: number | null;
|
|
62
|
+
refillAmount: number | null;
|
|
63
|
+
refillInterval: number | null;
|
|
64
|
+
lastRefillAt: Timestamp | null;
|
|
65
|
+
lastUsedAt: Timestamp | null;
|
|
66
|
+
expiresAt: Timestamp | null;
|
|
67
|
+
createdAt: Timestamp;
|
|
68
|
+
updatedAt: Timestamp;
|
|
69
|
+
};
|
|
70
|
+
export type CreatedAuthApiKey = {
|
|
71
|
+
apiKey: AuthApiKey;
|
|
72
|
+
secret: string;
|
|
73
|
+
};
|
|
74
|
+
export type AuthApiKeyVerificationResult = {
|
|
75
|
+
valid: boolean;
|
|
76
|
+
apiKey: AuthApiKey | null;
|
|
77
|
+
errorCode: string | null;
|
|
78
|
+
errorMessage: string | null;
|
|
79
|
+
};
|
|
80
|
+
export type AuthAuditEvent = {
|
|
81
|
+
id: Id;
|
|
82
|
+
action: string;
|
|
83
|
+
actorId: Id | null;
|
|
84
|
+
organizationId: Id | null;
|
|
85
|
+
resourceType: string;
|
|
86
|
+
resourceId: Id | null;
|
|
87
|
+
createdAt: Timestamp;
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../auth-contracts/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEpE,eAAO,MAAM,UAAU,iDAAkD,CAAC;AAE1E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG;IACtB,EAAE,EAAE,EAAE,CAA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G;IAC5B,EAAE,EAAE,EAAE,CAAC;IACP,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC;IACnB,cAAc,EAAE,EAAE,GAAG,IAAI,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,EAAE,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../auth-contracts/src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type ApiKeyConfigurationOptions, type ApiKeyOptions } from "@better-auth/api-key";
|
|
2
|
+
import type { AuthSession, AuthUser } from "@fengsoft/auth-contracts";
|
|
3
|
+
import { type EnvSource, z } from "@fengsoft/foundation-config";
|
|
4
|
+
import type { Auth as BetterAuthInstance, BetterAuthOptions, BetterAuthPlugin } from "better-auth";
|
|
5
|
+
import { APIError } from "better-auth";
|
|
6
|
+
import { organization } from "better-auth/plugins";
|
|
7
|
+
type TimestampLike = Date | string;
|
|
8
|
+
type AuthHeaders = Headers | Array<[string, string]> | Record<string, string>;
|
|
9
|
+
type BetterAuthUserPayload = {
|
|
10
|
+
id: string;
|
|
11
|
+
email: string;
|
|
12
|
+
name?: string | null;
|
|
13
|
+
emailVerified: boolean;
|
|
14
|
+
createdAt: TimestampLike;
|
|
15
|
+
updatedAt: TimestampLike;
|
|
16
|
+
};
|
|
17
|
+
type BetterAuthSessionRecord = {
|
|
18
|
+
id: string;
|
|
19
|
+
expiresAt: TimestampLike;
|
|
20
|
+
createdAt: TimestampLike;
|
|
21
|
+
updatedAt: TimestampLike;
|
|
22
|
+
token: string;
|
|
23
|
+
activeOrganizationId?: string | null;
|
|
24
|
+
};
|
|
25
|
+
export type BetterAuthSessionPayload = {
|
|
26
|
+
session: BetterAuthSessionRecord;
|
|
27
|
+
user: BetterAuthUserPayload;
|
|
28
|
+
};
|
|
29
|
+
export type AuthenticatedSessionResult = {
|
|
30
|
+
cookie: string;
|
|
31
|
+
headers: Headers;
|
|
32
|
+
session: AuthSession;
|
|
33
|
+
};
|
|
34
|
+
export declare const authEnvironmentSchema: z.ZodObject<{
|
|
35
|
+
AUTH_SECRET: z.ZodString;
|
|
36
|
+
AUTH_BASE_URL: z.ZodURL;
|
|
37
|
+
AUTH_TRUSTED_ORIGINS: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
export type AuthEnvironment = z.infer<typeof authEnvironmentSchema>;
|
|
40
|
+
export type AuthRuntimeConfig = {
|
|
41
|
+
baseURL: string;
|
|
42
|
+
secret: string;
|
|
43
|
+
trustedOrigins: string[];
|
|
44
|
+
};
|
|
45
|
+
export type SignUpInput = {
|
|
46
|
+
email: string;
|
|
47
|
+
password: string;
|
|
48
|
+
name?: string | null;
|
|
49
|
+
};
|
|
50
|
+
export type SignInInput = {
|
|
51
|
+
email: string;
|
|
52
|
+
password: string;
|
|
53
|
+
};
|
|
54
|
+
export type PasswordResetInput = {
|
|
55
|
+
email: string;
|
|
56
|
+
redirectTo?: string;
|
|
57
|
+
};
|
|
58
|
+
export type PasswordResetConfirmationInput = {
|
|
59
|
+
token: string;
|
|
60
|
+
newPassword: string;
|
|
61
|
+
};
|
|
62
|
+
export type AuthCoreAdapter = {
|
|
63
|
+
signUp: (input: SignUpInput) => Promise<AuthSession>;
|
|
64
|
+
signIn: (input: SignInInput) => Promise<AuthSession>;
|
|
65
|
+
signOut: (sessionId: string) => Promise<void>;
|
|
66
|
+
getSession: (sessionId: string) => Promise<AuthSession | null>;
|
|
67
|
+
getUser: (userId: string) => Promise<AuthUser | null>;
|
|
68
|
+
revokeSession: (sessionId: string) => Promise<void>;
|
|
69
|
+
verifyEmail: (token: string) => Promise<void>;
|
|
70
|
+
requestPasswordReset: (input: PasswordResetInput) => Promise<void>;
|
|
71
|
+
confirmPasswordReset: (input: PasswordResetConfirmationInput) => Promise<void>;
|
|
72
|
+
};
|
|
73
|
+
export type BetterAuthService = {
|
|
74
|
+
auth: BetterAuthInstance;
|
|
75
|
+
confirmPasswordReset: (input: PasswordResetConfirmationInput) => Promise<void>;
|
|
76
|
+
getSession: (headers: AuthHeaders) => Promise<AuthSession | null>;
|
|
77
|
+
getUserFromHeaders: (headers: AuthHeaders) => Promise<AuthUser | null>;
|
|
78
|
+
requestPasswordReset: (input: PasswordResetInput) => Promise<void>;
|
|
79
|
+
revokeSession: (token: string, headers: AuthHeaders) => Promise<void>;
|
|
80
|
+
signIn: (input: SignInInput, headers?: AuthHeaders) => Promise<AuthenticatedSessionResult>;
|
|
81
|
+
signOut: (headers: AuthHeaders) => Promise<void>;
|
|
82
|
+
signUp: (input: SignUpInput, headers?: AuthHeaders) => Promise<AuthenticatedSessionResult>;
|
|
83
|
+
verifyEmail: (token: string, callbackURL?: string) => Promise<void>;
|
|
84
|
+
};
|
|
85
|
+
export type OrganizationPluginOptions = Exclude<Parameters<typeof organization>[0], undefined>;
|
|
86
|
+
export type ApiKeyPluginFeatureOptions = {
|
|
87
|
+
configurations?: ApiKeyConfigurationOptions | ApiKeyConfigurationOptions[];
|
|
88
|
+
options?: ApiKeyOptions;
|
|
89
|
+
};
|
|
90
|
+
export type CreateBetterAuthOptions = Omit<BetterAuthOptions, "plugins"> & {
|
|
91
|
+
organizations?: boolean | OrganizationPluginOptions;
|
|
92
|
+
apiKeys?: boolean | ApiKeyPluginFeatureOptions;
|
|
93
|
+
plugins?: BetterAuthPlugin[];
|
|
94
|
+
};
|
|
95
|
+
export declare function readAuthRuntimeConfig(env?: EnvSource): AuthRuntimeConfig;
|
|
96
|
+
export declare function normalizeAuthUser(user: BetterAuthUserPayload): AuthUser;
|
|
97
|
+
export declare function normalizeBetterAuthSession(payload: BetterAuthSessionPayload): AuthSession;
|
|
98
|
+
export declare function createBetterAuthOptions(options: CreateBetterAuthOptions): BetterAuthOptions;
|
|
99
|
+
export declare function createBetterAuthServer(options: CreateBetterAuthOptions): BetterAuthInstance;
|
|
100
|
+
export declare function getSessionFromHeaders(auth: BetterAuthInstance, headers: AuthHeaders): Promise<AuthSession | null>;
|
|
101
|
+
export declare function createBetterAuthService(auth: BetterAuthInstance): BetterAuthService;
|
|
102
|
+
export declare function isBetterAuthError(error: unknown): error is APIError;
|
|
103
|
+
export declare function createAuthCore(adapter: AuthCoreAdapter): AuthCoreAdapter;
|
|
104
|
+
export { APIError };
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../auth-core/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAElB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAgB,KAAK,SAAS,EAAE,CAAC,EAAE,MAAM,6BAA6B,CAAC;AAE9E,OAAO,KAAK,EACX,IAAI,IAAI,kBAAkB,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAc,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,KAAK,aAAa,GAAG,IAAI,GAAG,MAAM,CAAC;AACnC,KAAK,WAAW,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9E,KAAK,qBAAqB,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,C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QAAQ,CASvE;AAED,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,wBAAwB,GAC/B,WAAW,CAQb;AAED,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,uBAAuB,GAC9B,iBAAiB,CAqBnB;AAED,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,uBAAuB,GAC9B,kBAAkB,CAWpB;AAED,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,kBAAkB,EACxB,OAAO,EAAE,WAAW,GAClB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAU7B;AAED,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,kBAAkB,GACtB,iBAAiB,CAsFnB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAEnE;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAGxE;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { apiKey, } from "@better-auth/api-key";
|
|
2
|
+
import { createConfig, z } from "@fengsoft/foundation-config";
|
|
3
|
+
import { createLogger } from "@fengsoft/foundation-observability";
|
|
4
|
+
import { APIError, betterAuth } from "better-auth";
|
|
5
|
+
import { organization } from "better-auth/plugins";
|
|
6
|
+
const logger = createLogger("auth-core");
|
|
7
|
+
export const authEnvironmentSchema = z.object({
|
|
8
|
+
AUTH_SECRET: z.string().min(1),
|
|
9
|
+
AUTH_BASE_URL: z.url(),
|
|
10
|
+
AUTH_TRUSTED_ORIGINS: z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
function normalizeTimestamp(value) {
|
|
13
|
+
return value instanceof Date
|
|
14
|
+
? value.toISOString()
|
|
15
|
+
: new Date(value).toISOString();
|
|
16
|
+
}
|
|
17
|
+
function splitOrigins(value) {
|
|
18
|
+
if (!value) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
return value
|
|
22
|
+
.split(",")
|
|
23
|
+
.map((origin) => origin.trim())
|
|
24
|
+
.filter((origin) => origin.length > 0);
|
|
25
|
+
}
|
|
26
|
+
function toHeaders(headers) {
|
|
27
|
+
return new Headers(headers);
|
|
28
|
+
}
|
|
29
|
+
function getSetCookieValues(headers) {
|
|
30
|
+
const withGetSetCookie = headers;
|
|
31
|
+
if (typeof withGetSetCookie.getSetCookie === "function") {
|
|
32
|
+
return withGetSetCookie.getSetCookie();
|
|
33
|
+
}
|
|
34
|
+
const setCookie = headers.get("set-cookie");
|
|
35
|
+
return setCookie ? [setCookie] : [];
|
|
36
|
+
}
|
|
37
|
+
function extractCookiePair(headers) {
|
|
38
|
+
for (const value of getSetCookieValues(headers)) {
|
|
39
|
+
const [cookie] = value.split(";");
|
|
40
|
+
if (cookie && cookie.length > 0) {
|
|
41
|
+
return cookie;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function withCookie(headers, cookie) {
|
|
47
|
+
const resolvedHeaders = toHeaders(headers);
|
|
48
|
+
resolvedHeaders.set("cookie", cookie);
|
|
49
|
+
return resolvedHeaders;
|
|
50
|
+
}
|
|
51
|
+
function resolveOrganizationPlugins(organizations) {
|
|
52
|
+
if (organizations === false) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
if (organizations === true || organizations === undefined) {
|
|
56
|
+
return [organization({ allowUserToCreateOrganization: true })];
|
|
57
|
+
}
|
|
58
|
+
return [organization(organizations)];
|
|
59
|
+
}
|
|
60
|
+
function resolveApiKeyPlugins(apiKeys) {
|
|
61
|
+
if (apiKeys === false || apiKeys === undefined) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
if (apiKeys === true) {
|
|
65
|
+
return [apiKey()];
|
|
66
|
+
}
|
|
67
|
+
return [apiKey(apiKeys.configurations, apiKeys.options)];
|
|
68
|
+
}
|
|
69
|
+
async function sessionFromResponse(auth, response, headers) {
|
|
70
|
+
const cookie = extractCookiePair(response.headers);
|
|
71
|
+
if (!cookie) {
|
|
72
|
+
throw new Error("Better Auth did not return a session cookie.");
|
|
73
|
+
}
|
|
74
|
+
const session = await getSessionFromHeaders(auth, withCookie(headers, cookie));
|
|
75
|
+
if (!session) {
|
|
76
|
+
throw new Error("Better Auth returned a cookie but the session could not be loaded.");
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
cookie,
|
|
80
|
+
headers: withCookie(headers, cookie),
|
|
81
|
+
session,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function readAuthRuntimeConfig(env = process.env) {
|
|
85
|
+
const parsed = createConfig(authEnvironmentSchema, env);
|
|
86
|
+
return {
|
|
87
|
+
baseURL: parsed.AUTH_BASE_URL,
|
|
88
|
+
secret: parsed.AUTH_SECRET,
|
|
89
|
+
trustedOrigins: splitOrigins(parsed.AUTH_TRUSTED_ORIGINS),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function normalizeAuthUser(user) {
|
|
93
|
+
return {
|
|
94
|
+
id: user.id,
|
|
95
|
+
email: user.email,
|
|
96
|
+
name: user.name ?? null,
|
|
97
|
+
emailVerified: user.emailVerified,
|
|
98
|
+
createdAt: normalizeTimestamp(user.createdAt),
|
|
99
|
+
updatedAt: normalizeTimestamp(user.updatedAt),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export function normalizeBetterAuthSession(payload) {
|
|
103
|
+
return {
|
|
104
|
+
id: payload.session.id,
|
|
105
|
+
user: normalizeAuthUser(payload.user),
|
|
106
|
+
activeOrganizationId: payload.session.activeOrganizationId ?? null,
|
|
107
|
+
expiresAt: normalizeTimestamp(payload.session.expiresAt),
|
|
108
|
+
createdAt: normalizeTimestamp(payload.session.createdAt),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function createBetterAuthOptions(options) {
|
|
112
|
+
const { organizations = true, apiKeys = false, plugins = [], emailAndPassword, ...rest } = options;
|
|
113
|
+
return {
|
|
114
|
+
...rest,
|
|
115
|
+
emailAndPassword: {
|
|
116
|
+
...emailAndPassword,
|
|
117
|
+
enabled: emailAndPassword?.enabled ?? true,
|
|
118
|
+
},
|
|
119
|
+
plugins: [
|
|
120
|
+
...resolveOrganizationPlugins(organizations),
|
|
121
|
+
...resolveApiKeyPlugins(apiKeys),
|
|
122
|
+
...plugins,
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
export function createBetterAuthServer(options) {
|
|
127
|
+
logger.info("Creating Better Auth server", {
|
|
128
|
+
baseURL: options.baseURL,
|
|
129
|
+
apiKeys: options.apiKeys === undefined || options.apiKeys === false
|
|
130
|
+
? "disabled"
|
|
131
|
+
: "enabled",
|
|
132
|
+
organizations: options.organizations === false ? "disabled" : "enabled",
|
|
133
|
+
});
|
|
134
|
+
return betterAuth(createBetterAuthOptions(options));
|
|
135
|
+
}
|
|
136
|
+
export async function getSessionFromHeaders(auth, headers) {
|
|
137
|
+
const session = await auth.api.getSession({
|
|
138
|
+
headers: toHeaders(headers),
|
|
139
|
+
});
|
|
140
|
+
if (!session) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return normalizeBetterAuthSession(session);
|
|
144
|
+
}
|
|
145
|
+
export function createBetterAuthService(auth) {
|
|
146
|
+
const signIn = async (input, headers) => {
|
|
147
|
+
const response = await auth.api.signInEmail({
|
|
148
|
+
asResponse: true,
|
|
149
|
+
body: {
|
|
150
|
+
email: input.email,
|
|
151
|
+
password: input.password,
|
|
152
|
+
},
|
|
153
|
+
headers: toHeaders(headers),
|
|
154
|
+
});
|
|
155
|
+
return sessionFromResponse(auth, response, headers);
|
|
156
|
+
};
|
|
157
|
+
const signUp = async (input, headers) => {
|
|
158
|
+
await auth.api.signUpEmail({
|
|
159
|
+
body: {
|
|
160
|
+
email: input.email,
|
|
161
|
+
password: input.password,
|
|
162
|
+
name: input.name ?? input.email,
|
|
163
|
+
},
|
|
164
|
+
headers: toHeaders(headers),
|
|
165
|
+
});
|
|
166
|
+
return signIn({
|
|
167
|
+
email: input.email,
|
|
168
|
+
password: input.password,
|
|
169
|
+
}, headers);
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
auth,
|
|
173
|
+
signUp,
|
|
174
|
+
signIn,
|
|
175
|
+
getSession: (headers) => getSessionFromHeaders(auth, headers),
|
|
176
|
+
getUserFromHeaders: async (headers) => {
|
|
177
|
+
const session = await getSessionFromHeaders(auth, headers);
|
|
178
|
+
return session?.user ?? null;
|
|
179
|
+
},
|
|
180
|
+
signOut: async (headers) => {
|
|
181
|
+
await auth.api.signOut({
|
|
182
|
+
headers: toHeaders(headers),
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
revokeSession: async (token, headers) => {
|
|
186
|
+
await auth.api.revokeSession({
|
|
187
|
+
body: {
|
|
188
|
+
token,
|
|
189
|
+
},
|
|
190
|
+
headers: toHeaders(headers),
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
verifyEmail: async (token, callbackURL) => {
|
|
194
|
+
await auth.api.verifyEmail({
|
|
195
|
+
query: {
|
|
196
|
+
token,
|
|
197
|
+
callbackURL,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
requestPasswordReset: async (input) => {
|
|
202
|
+
await auth.api.requestPasswordReset({
|
|
203
|
+
body: {
|
|
204
|
+
email: input.email,
|
|
205
|
+
redirectTo: input.redirectTo,
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
confirmPasswordReset: async (input) => {
|
|
210
|
+
await auth.api.resetPassword({
|
|
211
|
+
body: {
|
|
212
|
+
newPassword: input.newPassword,
|
|
213
|
+
token: input.token,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
export function isBetterAuthError(error) {
|
|
220
|
+
return error instanceof APIError;
|
|
221
|
+
}
|
|
222
|
+
export function createAuthCore(adapter) {
|
|
223
|
+
logger.info("Auth core adapter registered");
|
|
224
|
+
return adapter;
|
|
225
|
+
}
|
|
226
|
+
export { APIError };
|
|
227
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../auth-core/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,MAAM,GACN,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAkB,CAAC,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAMlE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;AAkCzC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,aAAa,EAAE,CAAC,CAAC,GAAG,EAAE;IACtB,oBAAoB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC;AAqFH,SAAS,kBAAkB,CAAC,KAAoB;IAC/C,OAAO,KAAK,YAAY,IAAI;QAC3B,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE;QACrB,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,KAAK;SACV,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;SAC9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AE,KAAK,EAAE,WAAW,EAAE,EAAE;YACzC,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC1B,KAAK,EAAE;oBACN,KAAK;oBACL,WAAW;iBACX;aACD,CAAC,CAAC;QACJ,CAAC;QACD,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACrC,MAAM,IAAI,CAAC,GAAG,CAAC,oBAAoB,CAAC;gBACnC,IAAI,EAAE;oBACL,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,UAAU,EAAE,KAAK,CAAC,UAAU;iBAC5B;aACD,CAAC,CAAC;QACJ,CAAC;QACD,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACrC,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;gBAC5B,IAAI,EAAE;oBACL,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;iBAClB;aACD,CAAC,CAAC;QACJ,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC/C,OAAO,KAAK,YAAY,QAAQ,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAwB;IACtD,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,OAAO,CAAC;AAChB,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AuthSession } from "@fengsoft/auth-contracts";
|
|
2
|
+
import type { Auth as BetterAuthInstance } from "better-auth";
|
|
3
|
+
import type { FastifyPluginAsync, FastifyRequest, preHandlerHookHandler } from "fastify";
|
|
4
|
+
export type SessionResolver = (request: FastifyRequest) => Promise<AuthSession | null>;
|
|
5
|
+
export type BetterAuthRouteOptions = {
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
};
|
|
9
|
+
declare module "fastify" {
|
|
10
|
+
interface FastifyRequest {
|
|
11
|
+
authSession: AuthSession | null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function createAuthPlugin(resolveSession: SessionResolver): FastifyPluginAsync;
|
|
15
|
+
export declare function createBetterAuthSessionResolver(auth: BetterAuthInstance): SessionResolver;
|
|
16
|
+
export declare function createBetterAuthSessionPlugin(auth: BetterAuthInstance): FastifyPluginAsync;
|
|
17
|
+
export declare function createBetterAuthRoutePlugin(auth: BetterAuthInstance, options?: BetterAuthRouteOptions): FastifyPluginAsync;
|
|
18
|
+
export declare function createRequireSessionHook(): preHandlerHookHandler;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D,OAAO,KAAK,EAAE,IAAI,IAAI,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,KAAK,EACX,kBAAkB,EAElB,cAAc,EACd,qBAAqB,EACrB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,CAC7B,OAAO,EAAE,cAAc,KACnB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEjC,MAAM,MAAM,sBAAsB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AASF,OAAO,QAAQ,SAAS,CAAC;IACxB,UAAU,cAAc;QACvB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;KAChC;CACD;AAgGD,wBAAgB,gBAAgB,CAC/B,cAAc,EAAE,eAAe,GAC7B,kBAAkB,CAQpB;AAED,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,kBAAkB,GACtB,eAAe,CAQjB;AAED,wBAAgB,6BAA6B,CAC5C,IAAI,EAAE,kBAAkB,GACtB,kBAAkB,CAEpB;AAED,wBAAgB,2BAA2B,CAC1C,IAAI,EAAE,kBAAkB,EACxB,OAAO,GAAE,sBAA2B,GAClC,kBAAkB,CAWpB;AAED,wBAAgB,wBAAwB,IAAI,qBAAqB,CAWhE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { normalizeBetterAuthSession } from "@fengsoft/auth-core";
|
|
2
|
+
import { fromNodeHeaders } from "better-auth/node";
|
|
3
|
+
function shouldIncludeBody(method) {
|
|
4
|
+
const normalizedMethod = method.toUpperCase();
|
|
5
|
+
return normalizedMethod !== "GET" && normalizedMethod !== "HEAD";
|
|
6
|
+
}
|
|
7
|
+
function createRequestUrl(request, baseURL) {
|
|
8
|
+
const host = request.headers.host ?? "localhost";
|
|
9
|
+
const origin = baseURL ?? `${request.protocol ?? "http"}://${host}`;
|
|
10
|
+
return new URL(request.raw.url ?? request.url, origin);
|
|
11
|
+
}
|
|
12
|
+
function serializeRequestBody(request, headers) {
|
|
13
|
+
if (!shouldIncludeBody(request.method) || request.body == null) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (typeof request.body === "string" ||
|
|
17
|
+
request.body instanceof ArrayBuffer ||
|
|
18
|
+
request.body instanceof DataView ||
|
|
19
|
+
request.body instanceof Uint8Array) {
|
|
20
|
+
return request.body;
|
|
21
|
+
}
|
|
22
|
+
if (ArrayBuffer.isView(request.body)) {
|
|
23
|
+
return new Uint8Array(request.body.buffer, request.body.byteOffset, request.body.byteLength);
|
|
24
|
+
}
|
|
25
|
+
const contentType = headers.get("content-type") ?? "";
|
|
26
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
27
|
+
const formEntries = Object.entries(request.body);
|
|
28
|
+
return new URLSearchParams(formEntries).toString();
|
|
29
|
+
}
|
|
30
|
+
if (!headers.has("content-type")) {
|
|
31
|
+
headers.set("content-type", "application/json");
|
|
32
|
+
}
|
|
33
|
+
return JSON.stringify(request.body);
|
|
34
|
+
}
|
|
35
|
+
async function replyWithAuthResponse(reply, response) {
|
|
36
|
+
reply.code(response.status);
|
|
37
|
+
for (const [name, value] of response.headers.entries()) {
|
|
38
|
+
reply.header(name, value);
|
|
39
|
+
}
|
|
40
|
+
const bodyText = await response.text();
|
|
41
|
+
if (bodyText.length === 0) {
|
|
42
|
+
void reply.send();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
46
|
+
if (contentType.includes("application/json")) {
|
|
47
|
+
void reply.send(JSON.parse(bodyText));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
void reply.send(bodyText);
|
|
51
|
+
}
|
|
52
|
+
async function forwardToBetterAuth(auth, request, reply, baseURL) {
|
|
53
|
+
const headers = fromNodeHeaders(request.headers);
|
|
54
|
+
const body = serializeRequestBody(request, headers);
|
|
55
|
+
const authRequest = new Request(createRequestUrl(request, baseURL), {
|
|
56
|
+
method: request.method,
|
|
57
|
+
headers,
|
|
58
|
+
body,
|
|
59
|
+
duplex: body ? "half" : undefined,
|
|
60
|
+
});
|
|
61
|
+
const response = await auth.handler(authRequest);
|
|
62
|
+
await replyWithAuthResponse(reply, response);
|
|
63
|
+
}
|
|
64
|
+
export function createAuthPlugin(resolveSession) {
|
|
65
|
+
return async (app) => {
|
|
66
|
+
app.decorateRequest("authSession", null);
|
|
67
|
+
app.addHook("preHandler", async (request) => {
|
|
68
|
+
request.authSession = await resolveSession(request);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function createBetterAuthSessionResolver(auth) {
|
|
73
|
+
return async (request) => {
|
|
74
|
+
const session = await auth.api.getSession({
|
|
75
|
+
headers: fromNodeHeaders(request.headers),
|
|
76
|
+
});
|
|
77
|
+
return session ? normalizeBetterAuthSession(session) : null;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export function createBetterAuthSessionPlugin(auth) {
|
|
81
|
+
return createAuthPlugin(createBetterAuthSessionResolver(auth));
|
|
82
|
+
}
|
|
83
|
+
export function createBetterAuthRoutePlugin(auth, options = {}) {
|
|
84
|
+
const routePath = options.path ?? "/api/auth";
|
|
85
|
+
return async (app) => {
|
|
86
|
+
app.route({
|
|
87
|
+
method: ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
|
|
88
|
+
url: `${routePath}/*`,
|
|
89
|
+
handler: async (request, reply) => forwardToBetterAuth(auth, request, reply, options.baseURL),
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export function createRequireSessionHook() {
|
|
94
|
+
return async (request, reply) => {
|
|
95
|
+
if (request.authSession) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
void reply.code(401).send({
|
|
99
|
+
code: "UNAUTHORIZED",
|
|
100
|
+
message: "Authentication required.",
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA8BnD,SAAS,iBAAiB,CAAC,MAAc;IACxC,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAC9C,OAAO,gBAAgB,KAAK,KAAK,IAAI,gBAAgB,KAAK,MAAM,CAAC;AAClE,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAuB,EAAE,OAAgB;IAClE,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC;IACjD,MAAM,MAAM,GAAG,OAAO,IAAI,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,MAAM,IAAI,EAAE,CAAC;IAEpE,OAAO,IAAI,GAAG,CAAC,OAA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E,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC;YACpE,GAAG,EAAE,GAAG,SAAS,IAAI;YACrB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CACjC,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;SAC3D,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACvC,OAAO,KAAK,EAAE,OAAuB,EAAE,KAAmB,EAAE,EAAE;QAC7D,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACzB,OAAO;QACR,CAAC;QAED,KAAK,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;YACzB,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,0BAA0B;SACnC,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ZodObject, type ZodRawShape, z } from "zod";
|
|
2
|
+
export type EnvSource = Record<string, string | undefined>;
|
|
3
|
+
export declare function readRequiredEnv(name: string, env?: EnvSource): string;
|
|
4
|
+
export declare function readOptionalEnv(name: string, env?: EnvSource): string | undefined;
|
|
5
|
+
export declare function readUrl(name: string, env?: EnvSource): URL;
|
|
6
|
+
export declare function readInt(name: string, fallback: number, env?: EnvSource): number;
|
|
7
|
+
export declare function createConfig<TShape extends ZodRawShape>(schema: ZodObject<TShape>, env?: EnvSource): z.core.$InferObjectOutput<TShape, {}>;
|
|
8
|
+
export { z };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../foundation-config/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE1D,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAE3D,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,SAAuB,GAC1B,MAAM,CAMR;AAED,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,GAAG,GAAE,SAAuB,GAC1B,MAAM,GAAG,SAAS,CAGpB;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,SAAuB,GAAG,GAAG,CAEvE;AAED,wBAAgB,OAAO,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,GAAG,GAAE,SAAuB,GAC1B,MAAM,CAQR;AAED,wBAAgB,YAAY,CAAC,MAAM,SAAS,WAAW,EACtD,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,GAAG,GAAE,SAAuB,yCAG5B;AAED,OAAO,EAAE,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export function readRequiredEnv(name, env = process.env) {
|
|
3
|
+
const value = env[name]?.trim();
|
|
4
|
+
if (!value) {
|
|
5
|
+
throw new Error(`Missing required environment variable: ${name}`);
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function readOptionalEnv(name, env = process.env) {
|
|
10
|
+
const value = env[name]?.trim();
|
|
11
|
+
return value && value.length > 0 ? value : undefined;
|
|
12
|
+
}
|
|
13
|
+
export function readUrl(name, env = process.env) {
|
|
14
|
+
return new URL(readRequiredEnv(name, env));
|
|
15
|
+
}
|
|
16
|
+
export function readInt(name, fallback, env = process.env) {
|
|
17
|
+
const raw = env[name]?.trim();
|
|
18
|
+
if (!raw) {
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
const value = Number.parseInt(raw, 10);
|
|
22
|
+
return Number.isNaN(value) ? fallback : value;
|
|
23
|
+
}
|
|
24
|
+
export function createConfig(schema, env = process.env) {
|
|
25
|
+
return schema.parse(env);
|
|
26
|
+
}
|
|
27
|
+
export { z };
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../foundation-config/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,CAAC,EAAE,MAAM,KAAK,CAAC;AAI1D,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,MAAiB,OAAO,CAAC,GAAG;IAE5B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,MAAiB,OAAO,CAAC,GAAG;IAE5B,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IAChC,OAAO,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,MAAiB,OAAO,CAAC,GAAG;IACjE,OAAO,IAAI,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,OAAO,CACtB,IAAY,EACZ,QAAgB,EAChB,MAAiB,OAAO,CAAC,GAAG;IAE5B,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,YAAY,CAC3B,MAAyB,EACzB,MAAiB,OAAO,CAAC,GAAG;IAE5B,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED,OAAO,EAAE,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Id = string;
|
|
2
|
+
export type Timestamp = string;
|
|
3
|
+
export type MetadataValue = string | number | boolean | null | MetadataValue[] | {
|
|
4
|
+
[key: string]: MetadataValue;
|
|
5
|
+
};
|
|
6
|
+
export type Metadata = Record<string, MetadataValue>;
|
|
7
|
+
export type ErrorEnvelope = {
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
status: number;
|
|
11
|
+
requestId?: string;
|
|
12
|
+
details?: Metadata;
|
|
13
|
+
};
|
|
14
|
+
export type PageRequest = {
|
|
15
|
+
cursor?: string | null;
|
|
16
|
+
limit?: number;
|
|
17
|
+
};
|
|
18
|
+
export type PageResult<TItem> = {
|
|
19
|
+
items: TItem[];
|
|
20
|
+
nextCursor: string | null;
|
|
21
|
+
totalCount?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare function createErrorEnvelope(input: ErrorEnvelope): ErrorEnvelope;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../foundation-contracts/src/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,EAAE,GAAG,MAAM,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAC/B,MAAM,MAAM,aAAa,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,aAAa,EAAE,GACf;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,KAAK,IAAI;IAC/B,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAEvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../foundation-contracts/src/index.ts"],"names":[],"mappings":"AA+BA,MAAM,UAAU,mBAAmB,CAAC,KAAoB;IACvD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
2
|
+
export type LogContext = Record<string, unknown>;
|
|
3
|
+
export type Logger = {
|
|
4
|
+
debug: (message: string, context?: LogContext) => void;
|
|
5
|
+
info: (message: string, context?: LogContext) => void;
|
|
6
|
+
warn: (message: string, context?: LogContext) => void;
|
|
7
|
+
error: (message: string, context?: LogContext) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createLogger(scope: string): Logger;
|
|
10
|
+
export declare function createRequestId(prefix?: string): string;
|
|
11
|
+
export declare function createHealthPayload(service: string): {
|
|
12
|
+
service: string;
|
|
13
|
+
status: "ok";
|
|
14
|
+
timestamp: string;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../foundation-observability/src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAC3D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,MAAM,MAAM,GAAG;IACpB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACvD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACtD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACtD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;CACvD,CAAC;AAgCF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,eAAe,CAAC,MAAM,SAAQ,GAAG,MAAM,CAEtD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM;;;;EAMlD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
function writeLog(level, scope, message, context) {
|
|
3
|
+
const payload = {
|
|
4
|
+
level,
|
|
5
|
+
scope,
|
|
6
|
+
message,
|
|
7
|
+
context: context ?? {},
|
|
8
|
+
timestamp: new Date().toISOString(),
|
|
9
|
+
};
|
|
10
|
+
switch (level) {
|
|
11
|
+
case "debug":
|
|
12
|
+
console.debug(payload);
|
|
13
|
+
return;
|
|
14
|
+
case "info":
|
|
15
|
+
console.info(payload);
|
|
16
|
+
return;
|
|
17
|
+
case "warn":
|
|
18
|
+
console.warn(payload);
|
|
19
|
+
return;
|
|
20
|
+
case "error":
|
|
21
|
+
console.error(payload);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function createLogger(scope) {
|
|
26
|
+
return {
|
|
27
|
+
debug: (message, context) => writeLog("debug", scope, message, context),
|
|
28
|
+
info: (message, context) => writeLog("info", scope, message, context),
|
|
29
|
+
warn: (message, context) => writeLog("warn", scope, message, context),
|
|
30
|
+
error: (message, context) => writeLog("error", scope, message, context),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function createRequestId(prefix = "req") {
|
|
34
|
+
return `${prefix}_${randomUUID()}`;
|
|
35
|
+
}
|
|
36
|
+
export function createHealthPayload(service) {
|
|
37
|
+
return {
|
|
38
|
+
service,
|
|
39
|
+
status: "ok",
|
|
40
|
+
timestamp: new Date().toISOString(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../foundation-observability/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAYzC,SAAS,QAAQ,CAChB,KAAe,EACf,KAAa,EACb,OAAe,EACf,OAAoB;IAEpB,MAAM,OAAO,GAAG;QACf,KAAK;QACL,KAAK;QACL,OAAO;QACP,OAAO,EAAE,OAAO,IAAI,EAAE;QACtB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC;IAEF,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,OAAO;YACX,O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+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md",
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"better-auth": "^1.5.6",
|
|
24
|
+
"fastify": "^5.8.4",
|
|
25
|
+
"@fengsoft/auth-core": "0.1.0",
|
|
26
|
+
"@fengsoft/auth-contracts": "0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.json",
|
|
30
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
31
|
+
"lint": "biome check src package.json tsconfig.json"
|
|
32
|
+
}
|
|
33
|
+
}
|