-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathindex.ts
More file actions
143 lines (132 loc) · 2.88 KB
/
Copy pathindex.ts
File metadata and controls
143 lines (132 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @emdash-cms/auth - Passkey-first authentication for EmDash
*
* Email is now handled by the plugin email pipeline (see PLUGIN-EMAIL.md).
* Auth functions accept an optional `email` send function instead of a
* hardcoded adapter. The route layer bridges `emdash.email.send()` from
* the pipeline into the auth functions.
*
* @example
* ```ts
* import { auth } from '@emdash-cms/auth'
*
* export default defineConfig({
* integrations: [
* emdash({
* auth: auth({
* secret: import.meta.env.EMDASH_AUTH_SECRET,
* passkeys: { rpName: 'My Site' },
* }),
* }),
* ],
* })
* ```
*/
// Types
export * from "./types.js";
// Config
import { authConfigSchema as _authConfigSchema } from "./config.js";
export {
authConfigSchema,
resolveConfig,
type AuthConfig,
type ResolvedAuthConfig,
} from "./config.js";
// RBAC
export {
Permissions,
hasPermission,
requirePermission,
canActOnOwn,
requirePermissionOnResource,
PermissionError,
scopesForRole,
clampScopes,
type Permission,
} from "./rbac.js";
// Tokens
export {
generateToken,
hashToken,
generateTokenWithHash,
generateSessionId,
generateAuthSecret,
secureCompare,
encrypt,
decrypt,
// Prefixed API tokens (ec_pat_, ec_oat_, ec_ort_)
TOKEN_PREFIXES,
generatePrefixedToken,
hashPrefixedToken,
// Scopes
VALID_SCOPES,
validateScopes,
isValidScope,
hasScope,
type ApiTokenScope,
// PKCE
computeS256Challenge,
} from "./tokens.js";
// Passkey
export * from "./passkey/index.js";
// Magic Link
export {
sendMagicLink,
verifyMagicLink,
MagicLinkError,
buildMagicLinkEmail,
type MagicLinkConfig,
type MagicLinkEmailStrings,
} from "./magic-link/index.js";
// Invite
export {
createInvite,
createInviteToken,
validateInvite,
completeInvite,
buildInviteEmail,
InviteError,
escapeHtml,
type InviteConfig,
type InviteTokenResult,
type InviteEmailStrings,
type EmailSendFn,
} from "./invite.js";
// Signup
export {
canSignup,
requestSignup,
validateSignupToken,
completeSignup,
SignupError,
type SignupConfig,
} from "./signup.js";
// OAuth
export {
createAuthorizationUrl,
handleOAuthCallback,
findOrCreateOAuthUser,
acceptInviteViaOAuth,
OAuthError,
github,
google,
type CanSelfSignup,
type StateStore,
type OAuthConsumerConfig,
} from "./oauth/consumer.js";
export type { OAuthProvider, OAuthConfig, OAuthProfile, OAuthState } from "./oauth/types.js";
// Email types (implementations moved to plugin email pipeline)
export type { EmailAdapter, EmailMessage } from "./types.js";
/**
* Create an auth configuration
*
* This is a helper function that validates the config at runtime.
*/
export function auth(config: import("./config.js").AuthConfig): import("./config.js").AuthConfig {
// Validate config
const result = _authConfigSchema.safeParse(config);
if (!result.success) {
throw new Error(`Invalid auth config: ${result.error.message}`);
}
return result.data;
}