sa2kit 3.2.1 → 3.2.3

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.
@@ -6,7 +6,7 @@ import 'drizzle-orm/pg-core';
6
6
  /**
7
7
  * sa2kit auth 服务端配置类型(Better Auth 3.0)
8
8
  */
9
- type Sa2kitSmsProvider = {
9
+ type Sa2kitSmsProvider$1 = {
10
10
  sendOTP: (phoneNumber: string, code: string) => void | Promise<void>;
11
11
  };
12
12
  type Sa2kitEmailProvider = {
@@ -18,7 +18,7 @@ type Sa2kitAuthConfig = {
18
18
  secret: string;
19
19
  trustedOrigins?: string[];
20
20
  basePath?: string;
21
- sms?: Sa2kitSmsProvider;
21
+ sms?: Sa2kitSmsProvider$1;
22
22
  email?: Sa2kitEmailProvider;
23
23
  phoneNumberValidator?: (phoneNumber: string) => boolean;
24
24
  logOtpInDev?: boolean;
@@ -40,6 +40,59 @@ type Sa2kitAuth = Sa2kitAuthInstance;
40
40
 
41
41
  declare function createSa2kitAuth(config: Sa2kitAuthConfig): Sa2kitAuthInstance;
42
42
 
43
+ type AuthEnvPlacement = 'env_file' | 'github_secret' | 'runtime_env' | 'database';
44
+ type AuthEnvVarDefinition = {
45
+ key: string;
46
+ featureId: string;
47
+ required: boolean;
48
+ placement: AuthEnvPlacement[];
49
+ description: string;
50
+ example?: string;
51
+ secret?: boolean;
52
+ };
53
+ type AuthFeatureDefinition = {
54
+ id: string;
55
+ name: string;
56
+ description: string;
57
+ envKeys: string[];
58
+ };
59
+ declare const AUTH_FEATURES: AuthFeatureDefinition[];
60
+ declare const AUTH_ENV_CATALOG: AuthEnvVarDefinition[];
61
+ declare const AUTH_ENV_ALIASES: Record<string, string[]>;
62
+
63
+ type ResolveAuthEnvInput = Partial<Sa2kitAuthConfig> & Pick<Sa2kitAuthConfig, 'db'>;
64
+ type ResolvedAuthEnv = {
65
+ config: Sa2kitAuthConfig;
66
+ envSnapshot: Record<string, string | undefined>;
67
+ };
68
+ declare function resolveAuthEnv(input: ResolveAuthEnvInput): ResolvedAuthEnv;
69
+
70
+ type AuthEnvIssueLevel = 'error' | 'warning' | 'info';
71
+ type AuthEnvIssue = {
72
+ level: AuthEnvIssueLevel;
73
+ featureId: string;
74
+ featureName: string;
75
+ message: string;
76
+ missingKeys?: string[];
77
+ hints?: string[];
78
+ };
79
+ type AuthEnvReport = {
80
+ ok: boolean;
81
+ issues: AuthEnvIssue[];
82
+ enabledFeatures: string[];
83
+ disabledFeatures: string[];
84
+ };
85
+ declare function checkAuthEnv(envSnapshot: Record<string, string | undefined>): AuthEnvReport;
86
+ declare function logAuthEnvReport(report: AuthEnvReport, options?: {
87
+ force?: boolean;
88
+ }): void;
89
+ declare function formatAuthEnvSetupMarkdown(report?: AuthEnvReport): string;
90
+ declare function checkAuthEnvFromProcessEnv(extraSnapshot?: Record<string, string | undefined>): AuthEnvReport;
91
+
92
+ declare function createSa2kitAuthFromEnv(input: ResolveAuthEnvInput, options?: {
93
+ logEnvReport?: boolean;
94
+ }): Sa2kitAuthInstance;
95
+
43
96
  declare function mountNextAuthHandler(auth: Sa2kitAuthInstance): {
44
97
  GET: (request: Request) => Promise<Response>;
45
98
  POST: (request: Request) => Promise<Response>;
@@ -86,4 +139,34 @@ declare function createSessionValidator(auth: Sa2kitAuthInstance): {
86
139
  declare const defaultPhoneValidator: (phoneNumber: string) => boolean;
87
140
  declare const defaultTempEmailFromPhone: (phoneNumber: string) => string;
88
141
 
89
- export { type Sa2kitAuth, type Sa2kitAuthConfig, type Sa2kitAuthInstance, type Sa2kitEmailProvider, type Sa2kitSmsProvider, type SessionUser, createAuthRouteHandlers, createSa2kitAuth, createSessionValidator, defaultPhoneValidator, defaultTempEmailFromPhone, getSessionUser, getSessionUserNumeric, mountAuthHandler, mountNextAuthHandler };
142
+ type Sa2kitSmsProvider = {
143
+ sendOTP: (phoneNumber: string, code: string) => void | Promise<void>;
144
+ };
145
+ type Sa2kitSmsProviderId = 'console' | 'aliyun-pnvs' | 'none';
146
+ type AliyunPnvsSmsConfig = {
147
+ accessKeyId: string;
148
+ accessKeySecret: string;
149
+ signName: string;
150
+ templateCode: string;
151
+ countryCode?: string;
152
+ codeValidMinutes?: number;
153
+ endpoint?: string;
154
+ };
155
+
156
+ declare function createConsoleSmsProvider(): Sa2kitSmsProvider;
157
+
158
+ declare function createAliyunPnvsSmsProvider(config: AliyunPnvsSmsConfig): Sa2kitSmsProvider;
159
+
160
+ declare function resolveSmsProviderId(explicit?: Sa2kitSmsProviderId): Sa2kitSmsProviderId | undefined;
161
+ declare function createSmsProviderFromEnv(options?: {
162
+ providerId?: Sa2kitSmsProviderId;
163
+ }): Sa2kitSmsProvider | undefined;
164
+
165
+ declare function stashPhoneSignupPassword(phoneNumber: string, password: string): void;
166
+ declare function consumePhoneSignupPassword(phoneNumber: string): string | undefined;
167
+ declare function handlePhoneSignupIntentRequest(request: Request): Promise<Response>;
168
+
169
+ /** 为手机号注册用户写入 credential 密码,供「手机+密码」登录 */
170
+ declare function upsertCredentialPassword(db: unknown, userId: string, plainPassword: string): Promise<void>;
171
+
172
+ export { AUTH_ENV_ALIASES, AUTH_ENV_CATALOG, AUTH_FEATURES, type AliyunPnvsSmsConfig, type AuthEnvIssue, type AuthEnvReport, type AuthEnvVarDefinition, type AuthFeatureDefinition, type Sa2kitAuth, type Sa2kitAuthConfig, type Sa2kitAuthInstance, type Sa2kitEmailProvider, type Sa2kitSmsProvider$1 as Sa2kitSmsProvider, type Sa2kitSmsProviderId, type SessionUser, checkAuthEnv, checkAuthEnvFromProcessEnv, consumePhoneSignupPassword, createAliyunPnvsSmsProvider, createAuthRouteHandlers, createConsoleSmsProvider, createSa2kitAuth, createSa2kitAuthFromEnv, createSessionValidator, createSmsProviderFromEnv, defaultPhoneValidator, defaultTempEmailFromPhone, formatAuthEnvSetupMarkdown, getSessionUser, getSessionUserNumeric, handlePhoneSignupIntentRequest, logAuthEnvReport, mountAuthHandler, mountNextAuthHandler, resolveAuthEnv, resolveSmsProviderId, stashPhoneSignupPassword, upsertCredentialPassword };