@oglofus/auth 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -6
- package/dist/core/auth.d.ts +5 -4
- package/dist/core/auth.js +219 -38
- package/dist/core/utils.d.ts +1 -0
- package/dist/core/utils.js +2 -1
- package/dist/plugins/email-otp.js +28 -4
- package/dist/plugins/magic-link.js +15 -18
- package/dist/plugins/oauth2.d.ts +8 -1
- package/dist/plugins/oauth2.js +65 -36
- package/dist/plugins/organizations.js +38 -6
- package/dist/plugins/passkey.js +20 -26
- package/dist/plugins/password.js +1 -1
- package/dist/plugins/two-factor.js +1 -4
- package/dist/types/adapters.d.ts +26 -22
- package/dist/types/model.d.ts +16 -13
- package/dist/types/plugins.d.ts +24 -5
- package/package.json +2 -2
package/dist/types/plugins.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { CoreAdapters, OrganizationsPluginHandlers } from "./adapters.js";
|
|
2
|
-
import type { AccountDiscoveryMode, AuthRequestContext, CompleteProfileInput, DiscoverAccountInput, DiscoverAccountDecision, MembershipBase, OrganizationBase, OrganizationEntitlementSnapshot, SecondFactorMethod, TwoFactorVerifyInput, UserBase } from "./model.js";
|
|
2
|
+
import type { AccountDiscoveryMode, AuthRequestContext, CompleteProfileInput, DiscoverAccountInput, DiscoverAccountDecision, MembershipBase, OrganizationBase, OrganizationEntitlementSnapshot, ProfileCompletionState, SecondFactorMethod, TwoFactorVerifyInput, UserBase } from "./model.js";
|
|
3
3
|
import type { AuthResult, OperationResult } from "./results.js";
|
|
4
4
|
export interface AuthPluginContext<U extends UserBase> {
|
|
5
5
|
adapters: CoreAdapters<U>;
|
|
6
6
|
now(): Date;
|
|
7
|
+
security?: AuthSecurityConfig;
|
|
7
8
|
request?: AuthRequestContext;
|
|
8
9
|
}
|
|
9
10
|
export interface BasePlugin<Method extends string, U extends UserBase, ExposedApi extends object = {}> {
|
|
@@ -12,6 +13,10 @@ export interface BasePlugin<Method extends string, U extends UserBase, ExposedAp
|
|
|
12
13
|
version: string;
|
|
13
14
|
createApi?: (ctx: Omit<AuthPluginContext<U>, "request">) => ExposedApi;
|
|
14
15
|
}
|
|
16
|
+
export interface CompletePendingProfileInput<U extends UserBase> {
|
|
17
|
+
record: ProfileCompletionState<U>;
|
|
18
|
+
user: U;
|
|
19
|
+
}
|
|
15
20
|
export interface AuthMethodPlugin<Method extends string, RegisterInput extends {
|
|
16
21
|
method: Method;
|
|
17
22
|
}, AuthenticateInput extends {
|
|
@@ -35,6 +40,7 @@ export interface AuthMethodPlugin<Method extends string, RegisterInput extends {
|
|
|
35
40
|
authenticate: (ctx: AuthPluginContext<U>, input: AuthenticateInput) => Promise<OperationResult<{
|
|
36
41
|
user: U;
|
|
37
42
|
}>>;
|
|
43
|
+
completePendingProfile?: (ctx: AuthPluginContext<U>, input: CompletePendingProfileInput<U>) => Promise<OperationResult<void>>;
|
|
38
44
|
}
|
|
39
45
|
export interface DomainPlugin<Method extends string, U extends UserBase, ExposedApi extends object = {}> extends BasePlugin<Method, U, ExposedApi> {
|
|
40
46
|
kind: "domain";
|
|
@@ -113,6 +119,13 @@ export interface OrganizationsPluginApi<O extends OrganizationBase, Role extends
|
|
|
113
119
|
organizationId: string;
|
|
114
120
|
membership: M;
|
|
115
121
|
}>>;
|
|
122
|
+
setActiveOrganization(input: {
|
|
123
|
+
sessionId: string;
|
|
124
|
+
organizationId?: string;
|
|
125
|
+
}, request?: AuthRequestContext): Promise<OperationResult<{
|
|
126
|
+
sessionId: string;
|
|
127
|
+
activeOrganizationId: string | null;
|
|
128
|
+
}>>;
|
|
116
129
|
setMemberRole(input: {
|
|
117
130
|
organizationId: string;
|
|
118
131
|
membershipId: string;
|
|
@@ -176,6 +189,15 @@ export interface OrganizationsPluginConfig<O extends OrganizationBase, Role exte
|
|
|
176
189
|
organizationRequiredFields?: readonly Extract<RequiredOrgFields, string>[];
|
|
177
190
|
handlers: OrganizationsPluginHandlers<O, Role, M, Permission, Feature, LimitKey>;
|
|
178
191
|
}
|
|
192
|
+
export type AuthSecurityRateLimitScope = "discover" | "register" | "authenticate" | "emailOtpRequest" | "magicLinkRequest" | "otpVerify";
|
|
193
|
+
export interface AuthSecurityRateLimitPolicy {
|
|
194
|
+
limit: number;
|
|
195
|
+
windowSeconds: number;
|
|
196
|
+
}
|
|
197
|
+
export interface AuthSecurityConfig {
|
|
198
|
+
rateLimits?: Partial<Record<AuthSecurityRateLimitScope, AuthSecurityRateLimitPolicy>>;
|
|
199
|
+
oauth2IdempotencyTtlSeconds?: number;
|
|
200
|
+
}
|
|
179
201
|
export type AnyMethodPlugin<U extends UserBase> = AuthMethodPlugin<string, any, any, U, any>;
|
|
180
202
|
export type AnyDomainPlugin<U extends UserBase> = DomainPlugin<string, U, any>;
|
|
181
203
|
export type AnyPlugin<U extends UserBase> = AnyMethodPlugin<U> | AnyDomainPlugin<U>;
|
|
@@ -208,6 +230,7 @@ export interface AuthConfig<U extends UserBase, P extends readonly AnyPlugin<U>[
|
|
|
208
230
|
session?: {
|
|
209
231
|
ttlSeconds?: number;
|
|
210
232
|
};
|
|
233
|
+
security?: AuthSecurityConfig;
|
|
211
234
|
validateConfigOnStart?: boolean;
|
|
212
235
|
}
|
|
213
236
|
export interface AuthPublicApi<U extends UserBase, P extends readonly AnyPlugin<U>[]> {
|
|
@@ -217,10 +240,6 @@ export interface AuthPublicApi<U extends UserBase, P extends readonly AnyPlugin<
|
|
|
217
240
|
method<M extends PluginMethodsWithApi<P>>(method: M): PluginApiMap<P>[M];
|
|
218
241
|
verifySecondFactor(input: TwoFactorVerifyInput, request?: AuthRequestContext): Promise<AuthResult<U>>;
|
|
219
242
|
completeProfile(input: CompleteProfileInput<U>, request?: AuthRequestContext): Promise<AuthResult<U>>;
|
|
220
|
-
setActiveOrganization(sessionId: string, organizationId: string, request?: AuthRequestContext): Promise<OperationResult<{
|
|
221
|
-
sessionId: string;
|
|
222
|
-
activeOrganizationId: string;
|
|
223
|
-
}>>;
|
|
224
243
|
validateSession(sessionId: string, request?: AuthRequestContext): Promise<{
|
|
225
244
|
ok: true;
|
|
226
245
|
userId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oglofus/auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Type-safe, plugin-first authentication core",
|
|
5
5
|
"homepage": "https://github.com/oglofus/auth#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"LICENSE"
|
|
27
27
|
],
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^25.3.
|
|
29
|
+
"@types/node": "^25.3.5",
|
|
30
30
|
"tsx": "^4.21.0",
|
|
31
31
|
"typescript": "^5.9.3"
|
|
32
32
|
},
|