@downcity/services 0.1.6
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 +47 -0
- package/bin/accounts/db.d.ts +19 -0
- package/bin/accounts/db.d.ts.map +1 -0
- package/bin/accounts/db.js +68 -0
- package/bin/accounts/db.js.map +1 -0
- package/bin/accounts/index.d.ts +348 -0
- package/bin/accounts/index.d.ts.map +1 -0
- package/bin/accounts/index.js +681 -0
- package/bin/accounts/index.js.map +1 -0
- package/bin/accounts/oauth.d.ts +129 -0
- package/bin/accounts/oauth.d.ts.map +1 -0
- package/bin/accounts/oauth.js +220 -0
- package/bin/accounts/oauth.js.map +1 -0
- package/bin/accounts/schema.d.ts +319 -0
- package/bin/accounts/schema.d.ts.map +1 -0
- package/bin/accounts/schema.js +72 -0
- package/bin/accounts/schema.js.map +1 -0
- package/bin/balance/index.d.ts +7 -0
- package/bin/balance/index.d.ts.map +1 -0
- package/bin/balance/index.js +6 -0
- package/bin/balance/index.js.map +1 -0
- package/bin/balance/raw.d.ts +20 -0
- package/bin/balance/raw.d.ts.map +1 -0
- package/bin/balance/raw.js +75 -0
- package/bin/balance/raw.js.map +1 -0
- package/bin/balance/routes.d.ts +14 -0
- package/bin/balance/routes.d.ts.map +1 -0
- package/bin/balance/routes.js +166 -0
- package/bin/balance/routes.js.map +1 -0
- package/bin/balance/schema.d.ts +764 -0
- package/bin/balance/schema.d.ts.map +1 -0
- package/bin/balance/schema.js +185 -0
- package/bin/balance/schema.js.map +1 -0
- package/bin/balance/service.d.ts +880 -0
- package/bin/balance/service.d.ts.map +1 -0
- package/bin/balance/service.js +557 -0
- package/bin/balance/service.js.map +1 -0
- package/bin/balance/types.d.ts +326 -0
- package/bin/balance/types.d.ts.map +1 -0
- package/bin/balance/types.js +10 -0
- package/bin/balance/types.js.map +1 -0
- package/bin/balance/utils.d.ts +91 -0
- package/bin/balance/utils.d.ts.map +1 -0
- package/bin/balance/utils.js +231 -0
- package/bin/balance/utils.js.map +1 -0
- package/bin/index.d.ts +22 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +16 -0
- package/bin/index.js.map +1 -0
- package/bin/payment/index.d.ts +19 -0
- package/bin/payment/index.d.ts.map +1 -0
- package/bin/payment/index.js +63 -0
- package/bin/payment/index.js.map +1 -0
- package/bin/payment/types.d.ts +107 -0
- package/bin/payment/types.d.ts.map +1 -0
- package/bin/payment/types.js +10 -0
- package/bin/payment/types.js.map +1 -0
- package/bin/payment-stripe/index.d.ts +17 -0
- package/bin/payment-stripe/index.d.ts.map +1 -0
- package/bin/payment-stripe/index.js +619 -0
- package/bin/payment-stripe/index.js.map +1 -0
- package/bin/payment-stripe/schema.d.ts +378 -0
- package/bin/payment-stripe/schema.d.ts.map +1 -0
- package/bin/payment-stripe/schema.js +47 -0
- package/bin/payment-stripe/schema.js.map +1 -0
- package/bin/payment-stripe/stripe.d.ts +38 -0
- package/bin/payment-stripe/stripe.d.ts.map +1 -0
- package/bin/payment-stripe/stripe.js +129 -0
- package/bin/payment-stripe/stripe.js.map +1 -0
- package/bin/payment-stripe/types.d.ts +331 -0
- package/bin/payment-stripe/types.d.ts.map +1 -0
- package/bin/payment-stripe/types.js +10 -0
- package/bin/payment-stripe/types.js.map +1 -0
- package/bin/usage/index.d.ts +177 -0
- package/bin/usage/index.d.ts.map +1 -0
- package/bin/usage/index.js +120 -0
- package/bin/usage/index.js.map +1 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @downcity/services
|
|
2
|
+
|
|
3
|
+
Downcity 官方服务聚合包。
|
|
4
|
+
|
|
5
|
+
这个包统一提供账号、余额、usage 与 Stripe 支付四类官方服务,避免业务侧分别安装多个 `service-*` 包。
|
|
6
|
+
|
|
7
|
+
## 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @downcity/services
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 使用
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
accountsService,
|
|
18
|
+
balanceService,
|
|
19
|
+
paymentService,
|
|
20
|
+
stripePaymentMethod,
|
|
21
|
+
stripePaymentService,
|
|
22
|
+
usageService,
|
|
23
|
+
type StripePaymentServiceBalanceBridge,
|
|
24
|
+
} from "@downcity/services";
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
产品侧通常先这样读取支付方式:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
const methods = await guest.service("payment").get("methods");
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
再根据返回结果调用具体支付方式,例如:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const checkout = await user.service("payment.stripe").action("checkout/create").invoke({
|
|
37
|
+
topup_id: "topup_demo",
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 包含的服务
|
|
42
|
+
|
|
43
|
+
- `accountsService()`:注册、登录、邮箱验证、GitHub/Google OAuth 与 `user_token` 签发
|
|
44
|
+
- `balanceService()`:全局余额账户、流水、充值单与兑换码
|
|
45
|
+
- `paymentService()`:统一暴露当前 InfraRuntime 可用的支付方式列表
|
|
46
|
+
- `usageService()`:记录真实用户侧 service 调用事件
|
|
47
|
+
- `stripePaymentService()`:把 Stripe 一次性支付同步成 balance topup 到账
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts 服务数据库辅助模块。
|
|
3
|
+
*
|
|
4
|
+
* 兼容 D1 与 better-sqlite3 两种 statement 形态,
|
|
5
|
+
* 给服务内部统一提供 first / all / run 能力。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 读取单行结果。
|
|
9
|
+
*/
|
|
10
|
+
export declare function readPreparedFirst(statement: any, params: unknown[]): Promise<Record<string, unknown> | null>;
|
|
11
|
+
/**
|
|
12
|
+
* 读取多行结果。
|
|
13
|
+
*/
|
|
14
|
+
export declare function readPreparedAll(statement: any, params: unknown[]): Promise<Record<string, unknown>[]>;
|
|
15
|
+
/**
|
|
16
|
+
* 执行写操作。
|
|
17
|
+
*/
|
|
18
|
+
export declare function runPrepared(statement: any, params: unknown[]): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/accounts/db.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,GAAG,EACd,MAAM,EAAE,OAAO,EAAE,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAmBzC;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,SAAS,EAAE,GAAG,EACd,MAAM,EAAE,OAAO,EAAE,GAChB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAiBpC;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAelF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accounts 服务数据库辅助模块。
|
|
3
|
+
*
|
|
4
|
+
* 兼容 D1 与 better-sqlite3 两种 statement 形态,
|
|
5
|
+
* 给服务内部统一提供 first / all / run 能力。
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* 读取单行结果。
|
|
9
|
+
*/
|
|
10
|
+
export async function readPreparedFirst(statement, params) {
|
|
11
|
+
if (typeof statement.bind === "function") {
|
|
12
|
+
const bound = statement.bind(...params);
|
|
13
|
+
if (typeof bound.first === "function") {
|
|
14
|
+
return await bound.first();
|
|
15
|
+
}
|
|
16
|
+
if (typeof bound.get === "function") {
|
|
17
|
+
return await bound.get();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (typeof statement.first === "function") {
|
|
21
|
+
return await statement.first(...params);
|
|
22
|
+
}
|
|
23
|
+
if (typeof statement.get === "function") {
|
|
24
|
+
return await statement.get(...params);
|
|
25
|
+
}
|
|
26
|
+
throw new Error("Unsupported database statement for first()");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 读取多行结果。
|
|
30
|
+
*/
|
|
31
|
+
export async function readPreparedAll(statement, params) {
|
|
32
|
+
if (typeof statement.bind === "function") {
|
|
33
|
+
const bound = statement.bind(...params);
|
|
34
|
+
if (typeof bound.all === "function") {
|
|
35
|
+
const result = await bound.all();
|
|
36
|
+
if (Array.isArray(result))
|
|
37
|
+
return result;
|
|
38
|
+
if (Array.isArray(result?.results))
|
|
39
|
+
return result.results;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (typeof statement.all === "function") {
|
|
43
|
+
const result = await statement.all(...params);
|
|
44
|
+
if (Array.isArray(result))
|
|
45
|
+
return result;
|
|
46
|
+
if (Array.isArray(result?.results))
|
|
47
|
+
return result.results;
|
|
48
|
+
}
|
|
49
|
+
throw new Error("Unsupported database statement for all()");
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 执行写操作。
|
|
53
|
+
*/
|
|
54
|
+
export async function runPrepared(statement, params) {
|
|
55
|
+
if (typeof statement.bind === "function") {
|
|
56
|
+
const bound = statement.bind(...params);
|
|
57
|
+
if (typeof bound.run === "function") {
|
|
58
|
+
await bound.run();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (typeof statement.run === "function") {
|
|
63
|
+
await statement.run(...params);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
throw new Error("Unsupported database statement for run()");
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/accounts/db.ts"],"names":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AAI,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;gBAAE,OAAO,MAAM,CAAC,OAAoC,CAAC;QACzF,CAAC;IACH,CAAC;IAED,IAAI,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO,MAAmC,CAAC;QACtE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;YAAE,OAAO,MAAM,CAAC,OAAoC,CAAC;IACzF,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAC9D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,SAAc,EAAE,MAAiB;IACjE,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;QACxC,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;YACpC,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;IACH,CAAC;IAED,IAAI,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QACxC,MAAM,SAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC/B,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Downcity 官方 Accounts 服务。
|
|
3
|
+
*
|
|
4
|
+
* 设计边界:
|
|
5
|
+
* - better-auth 作为认证事实源,统一落到 `auth_users/auth_accounts/auth_sessions/auth_verifications`
|
|
6
|
+
* - 服务自己只维护 `auth_profiles`
|
|
7
|
+
* - OAuth 为兼容当前 CLI 轮询交互,保留自定义 callback 外壳
|
|
8
|
+
*/
|
|
9
|
+
import { InstallableService } from "@downcity/infra";
|
|
10
|
+
import type { ServiceInstallContext } from "@downcity/infra";
|
|
11
|
+
/**
|
|
12
|
+
* Accounts 服务配置。
|
|
13
|
+
*/
|
|
14
|
+
export interface AccountsServiceOptions {
|
|
15
|
+
/**
|
|
16
|
+
* 登录、验证邮箱或 OAuth 完成后签发的 InfraRuntime user_token 有效期。
|
|
17
|
+
*/
|
|
18
|
+
token_ttl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* 自定义验证邮件发送函数。
|
|
21
|
+
*/
|
|
22
|
+
sendEmail?: (params: {
|
|
23
|
+
to: string;
|
|
24
|
+
subject: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare class AccountsService extends InstallableService {
|
|
29
|
+
private readonly options;
|
|
30
|
+
readonly id = "accounts";
|
|
31
|
+
readonly name = "Accounts";
|
|
32
|
+
readonly version = "0.4.0";
|
|
33
|
+
readonly schema: {
|
|
34
|
+
profile: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
35
|
+
name: "auth_profiles";
|
|
36
|
+
schema: undefined;
|
|
37
|
+
columns: {
|
|
38
|
+
user_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
39
|
+
name: "user_id";
|
|
40
|
+
tableName: "auth_profiles";
|
|
41
|
+
dataType: "string";
|
|
42
|
+
columnType: "SQLiteText";
|
|
43
|
+
data: string;
|
|
44
|
+
driverParam: string;
|
|
45
|
+
notNull: true;
|
|
46
|
+
hasDefault: false;
|
|
47
|
+
isPrimaryKey: true;
|
|
48
|
+
isAutoincrement: false;
|
|
49
|
+
hasRuntimeDefault: false;
|
|
50
|
+
enumValues: [string, ...string[]];
|
|
51
|
+
baseColumn: never;
|
|
52
|
+
identity: undefined;
|
|
53
|
+
generated: undefined;
|
|
54
|
+
}, {}, {
|
|
55
|
+
length: number | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
email: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
58
|
+
name: "email";
|
|
59
|
+
tableName: "auth_profiles";
|
|
60
|
+
dataType: "string";
|
|
61
|
+
columnType: "SQLiteText";
|
|
62
|
+
data: string;
|
|
63
|
+
driverParam: string;
|
|
64
|
+
notNull: true;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
isPrimaryKey: false;
|
|
67
|
+
isAutoincrement: false;
|
|
68
|
+
hasRuntimeDefault: false;
|
|
69
|
+
enumValues: [string, ...string[]];
|
|
70
|
+
baseColumn: never;
|
|
71
|
+
identity: undefined;
|
|
72
|
+
generated: undefined;
|
|
73
|
+
}, {}, {
|
|
74
|
+
length: number | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
display_name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
77
|
+
name: "display_name";
|
|
78
|
+
tableName: "auth_profiles";
|
|
79
|
+
dataType: "string";
|
|
80
|
+
columnType: "SQLiteText";
|
|
81
|
+
data: string;
|
|
82
|
+
driverParam: string;
|
|
83
|
+
notNull: true;
|
|
84
|
+
hasDefault: false;
|
|
85
|
+
isPrimaryKey: false;
|
|
86
|
+
isAutoincrement: false;
|
|
87
|
+
hasRuntimeDefault: false;
|
|
88
|
+
enumValues: [string, ...string[]];
|
|
89
|
+
baseColumn: never;
|
|
90
|
+
identity: undefined;
|
|
91
|
+
generated: undefined;
|
|
92
|
+
}, {}, {
|
|
93
|
+
length: number | undefined;
|
|
94
|
+
}>;
|
|
95
|
+
avatar_url: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
96
|
+
name: "avatar_url";
|
|
97
|
+
tableName: "auth_profiles";
|
|
98
|
+
dataType: "string";
|
|
99
|
+
columnType: "SQLiteText";
|
|
100
|
+
data: string;
|
|
101
|
+
driverParam: string;
|
|
102
|
+
notNull: true;
|
|
103
|
+
hasDefault: false;
|
|
104
|
+
isPrimaryKey: false;
|
|
105
|
+
isAutoincrement: false;
|
|
106
|
+
hasRuntimeDefault: false;
|
|
107
|
+
enumValues: [string, ...string[]];
|
|
108
|
+
baseColumn: never;
|
|
109
|
+
identity: undefined;
|
|
110
|
+
generated: undefined;
|
|
111
|
+
}, {}, {
|
|
112
|
+
length: number | undefined;
|
|
113
|
+
}>;
|
|
114
|
+
bio: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
115
|
+
name: "bio";
|
|
116
|
+
tableName: "auth_profiles";
|
|
117
|
+
dataType: "string";
|
|
118
|
+
columnType: "SQLiteText";
|
|
119
|
+
data: string;
|
|
120
|
+
driverParam: string;
|
|
121
|
+
notNull: true;
|
|
122
|
+
hasDefault: false;
|
|
123
|
+
isPrimaryKey: false;
|
|
124
|
+
isAutoincrement: false;
|
|
125
|
+
hasRuntimeDefault: false;
|
|
126
|
+
enumValues: [string, ...string[]];
|
|
127
|
+
baseColumn: never;
|
|
128
|
+
identity: undefined;
|
|
129
|
+
generated: undefined;
|
|
130
|
+
}, {}, {
|
|
131
|
+
length: number | undefined;
|
|
132
|
+
}>;
|
|
133
|
+
created_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
134
|
+
name: "created_at";
|
|
135
|
+
tableName: "auth_profiles";
|
|
136
|
+
dataType: "string";
|
|
137
|
+
columnType: "SQLiteText";
|
|
138
|
+
data: string;
|
|
139
|
+
driverParam: string;
|
|
140
|
+
notNull: true;
|
|
141
|
+
hasDefault: false;
|
|
142
|
+
isPrimaryKey: false;
|
|
143
|
+
isAutoincrement: false;
|
|
144
|
+
hasRuntimeDefault: false;
|
|
145
|
+
enumValues: [string, ...string[]];
|
|
146
|
+
baseColumn: never;
|
|
147
|
+
identity: undefined;
|
|
148
|
+
generated: undefined;
|
|
149
|
+
}, {}, {
|
|
150
|
+
length: number | undefined;
|
|
151
|
+
}>;
|
|
152
|
+
updated_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
153
|
+
name: "updated_at";
|
|
154
|
+
tableName: "auth_profiles";
|
|
155
|
+
dataType: "string";
|
|
156
|
+
columnType: "SQLiteText";
|
|
157
|
+
data: string;
|
|
158
|
+
driverParam: string;
|
|
159
|
+
notNull: true;
|
|
160
|
+
hasDefault: false;
|
|
161
|
+
isPrimaryKey: false;
|
|
162
|
+
isAutoincrement: false;
|
|
163
|
+
hasRuntimeDefault: false;
|
|
164
|
+
enumValues: [string, ...string[]];
|
|
165
|
+
baseColumn: never;
|
|
166
|
+
identity: undefined;
|
|
167
|
+
generated: undefined;
|
|
168
|
+
}, {}, {
|
|
169
|
+
length: number | undefined;
|
|
170
|
+
}>;
|
|
171
|
+
};
|
|
172
|
+
dialect: "sqlite";
|
|
173
|
+
}>;
|
|
174
|
+
oauth_states: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
175
|
+
name: "service_accounts_oauth_states";
|
|
176
|
+
schema: undefined;
|
|
177
|
+
columns: {
|
|
178
|
+
state: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
179
|
+
name: "state";
|
|
180
|
+
tableName: "service_accounts_oauth_states";
|
|
181
|
+
dataType: "string";
|
|
182
|
+
columnType: "SQLiteText";
|
|
183
|
+
data: string;
|
|
184
|
+
driverParam: string;
|
|
185
|
+
notNull: true;
|
|
186
|
+
hasDefault: false;
|
|
187
|
+
isPrimaryKey: true;
|
|
188
|
+
isAutoincrement: false;
|
|
189
|
+
hasRuntimeDefault: false;
|
|
190
|
+
enumValues: [string, ...string[]];
|
|
191
|
+
baseColumn: never;
|
|
192
|
+
identity: undefined;
|
|
193
|
+
generated: undefined;
|
|
194
|
+
}, {}, {
|
|
195
|
+
length: number | undefined;
|
|
196
|
+
}>;
|
|
197
|
+
product_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
198
|
+
name: "product_id";
|
|
199
|
+
tableName: "service_accounts_oauth_states";
|
|
200
|
+
dataType: "string";
|
|
201
|
+
columnType: "SQLiteText";
|
|
202
|
+
data: string;
|
|
203
|
+
driverParam: string;
|
|
204
|
+
notNull: true;
|
|
205
|
+
hasDefault: false;
|
|
206
|
+
isPrimaryKey: false;
|
|
207
|
+
isAutoincrement: false;
|
|
208
|
+
hasRuntimeDefault: false;
|
|
209
|
+
enumValues: [string, ...string[]];
|
|
210
|
+
baseColumn: never;
|
|
211
|
+
identity: undefined;
|
|
212
|
+
generated: undefined;
|
|
213
|
+
}, {}, {
|
|
214
|
+
length: number | undefined;
|
|
215
|
+
}>;
|
|
216
|
+
provider: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
217
|
+
name: "provider";
|
|
218
|
+
tableName: "service_accounts_oauth_states";
|
|
219
|
+
dataType: "string";
|
|
220
|
+
columnType: "SQLiteText";
|
|
221
|
+
data: string;
|
|
222
|
+
driverParam: string;
|
|
223
|
+
notNull: true;
|
|
224
|
+
hasDefault: false;
|
|
225
|
+
isPrimaryKey: false;
|
|
226
|
+
isAutoincrement: false;
|
|
227
|
+
hasRuntimeDefault: false;
|
|
228
|
+
enumValues: [string, ...string[]];
|
|
229
|
+
baseColumn: never;
|
|
230
|
+
identity: undefined;
|
|
231
|
+
generated: undefined;
|
|
232
|
+
}, {}, {
|
|
233
|
+
length: number | undefined;
|
|
234
|
+
}>;
|
|
235
|
+
user_token: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
236
|
+
name: "user_token";
|
|
237
|
+
tableName: "service_accounts_oauth_states";
|
|
238
|
+
dataType: "string";
|
|
239
|
+
columnType: "SQLiteText";
|
|
240
|
+
data: string;
|
|
241
|
+
driverParam: string;
|
|
242
|
+
notNull: true;
|
|
243
|
+
hasDefault: false;
|
|
244
|
+
isPrimaryKey: false;
|
|
245
|
+
isAutoincrement: false;
|
|
246
|
+
hasRuntimeDefault: false;
|
|
247
|
+
enumValues: [string, ...string[]];
|
|
248
|
+
baseColumn: never;
|
|
249
|
+
identity: undefined;
|
|
250
|
+
generated: undefined;
|
|
251
|
+
}, {}, {
|
|
252
|
+
length: number | undefined;
|
|
253
|
+
}>;
|
|
254
|
+
created_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
255
|
+
name: "created_at";
|
|
256
|
+
tableName: "service_accounts_oauth_states";
|
|
257
|
+
dataType: "number";
|
|
258
|
+
columnType: "SQLiteInteger";
|
|
259
|
+
data: number;
|
|
260
|
+
driverParam: number;
|
|
261
|
+
notNull: true;
|
|
262
|
+
hasDefault: false;
|
|
263
|
+
isPrimaryKey: false;
|
|
264
|
+
isAutoincrement: false;
|
|
265
|
+
hasRuntimeDefault: false;
|
|
266
|
+
enumValues: undefined;
|
|
267
|
+
baseColumn: never;
|
|
268
|
+
identity: undefined;
|
|
269
|
+
generated: undefined;
|
|
270
|
+
}, {}, {}>;
|
|
271
|
+
};
|
|
272
|
+
dialect: "sqlite";
|
|
273
|
+
}>;
|
|
274
|
+
};
|
|
275
|
+
private auth;
|
|
276
|
+
constructor(options: AccountsServiceOptions);
|
|
277
|
+
_onInit(): Promise<void>;
|
|
278
|
+
install(ctx: ServiceInstallContext): void;
|
|
279
|
+
/**
|
|
280
|
+
* 获取 better-auth 的 HTTP handler。
|
|
281
|
+
*/
|
|
282
|
+
getAuthHandler(): (request: Request) => Promise<Response>;
|
|
283
|
+
/**
|
|
284
|
+
* OAuth 回调处理。
|
|
285
|
+
*/
|
|
286
|
+
handleOAuthCallback(request: Request): Promise<Response>;
|
|
287
|
+
/**
|
|
288
|
+
* 列出可用登录方式。
|
|
289
|
+
*/
|
|
290
|
+
private listProviders;
|
|
291
|
+
/**
|
|
292
|
+
* 获取 provider 配置。
|
|
293
|
+
*/
|
|
294
|
+
private getOAuthProviderConfig;
|
|
295
|
+
/**
|
|
296
|
+
* 当前请求环境下的 OAuth callback URL。
|
|
297
|
+
*/
|
|
298
|
+
private getOAuthCallbackURL;
|
|
299
|
+
/**
|
|
300
|
+
* 确保 OAuth 用户落库到 better-auth 认证表,并同步 `auth_profiles`。
|
|
301
|
+
*/
|
|
302
|
+
private ensureOAuthAuthUser;
|
|
303
|
+
/**
|
|
304
|
+
* 创建 OAuth state。
|
|
305
|
+
*/
|
|
306
|
+
private createOAuthState;
|
|
307
|
+
/**
|
|
308
|
+
* 读取 OAuth state。
|
|
309
|
+
*/
|
|
310
|
+
private readOAuthState;
|
|
311
|
+
/**
|
|
312
|
+
* 回填 OAuth state 的 InfraRuntime token。
|
|
313
|
+
*/
|
|
314
|
+
private resolveOAuthState;
|
|
315
|
+
/**
|
|
316
|
+
* 按 ID 读取认证用户。
|
|
317
|
+
*/
|
|
318
|
+
private findAuthUserById;
|
|
319
|
+
/**
|
|
320
|
+
* 按邮箱读取认证用户。
|
|
321
|
+
*/
|
|
322
|
+
private findAuthUserByEmail;
|
|
323
|
+
/**
|
|
324
|
+
* 读取一条 user profile。
|
|
325
|
+
*/
|
|
326
|
+
private readProfile;
|
|
327
|
+
/**
|
|
328
|
+
* upsert user profile。
|
|
329
|
+
*/
|
|
330
|
+
private upsertProfile;
|
|
331
|
+
/**
|
|
332
|
+
* 管理侧用户列表。
|
|
333
|
+
*/
|
|
334
|
+
private listUsers;
|
|
335
|
+
/**
|
|
336
|
+
* 管理侧 session 列表。
|
|
337
|
+
*/
|
|
338
|
+
private listSessions;
|
|
339
|
+
/**
|
|
340
|
+
* 创建原始 statement。
|
|
341
|
+
*/
|
|
342
|
+
private rawPrepare;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* 创建 Accounts 服务实例。
|
|
346
|
+
*/
|
|
347
|
+
export declare function accountsService(options?: AccountsServiceOptions): InstallableService;
|
|
348
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,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