@kyro-cms/core 0.12.71 → 0.13.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 +6 -0
- package/dist/{WebhookService-DQyM9fVo.d.ts → WebhookService-BLi5Rz2m.d.ts} +1 -1
- package/dist/{WebhookService-bo1NrgBW.d.cts → WebhookService-BcuD8tnn.d.cts} +1 -1
- package/dist/WebhookService-D5PSI5t6.d.cts +143 -0
- package/dist/WebhookService-DPCCn_12.d.ts +143 -0
- package/dist/WebhookService-Dncnbgm9.d.cts +143 -0
- package/dist/WebhookService-UY5p89Bj.d.ts +143 -0
- package/dist/WebhookService-YZXBCRXA.d.ts +143 -0
- package/dist/WebhookService-zrDmAx7L.d.cts +143 -0
- package/dist/api-handler-graphql.cjs +1 -1
- package/dist/api-handler-graphql.js +1 -1
- package/dist/api-handler-trpc.cjs +1 -1
- package/dist/api-handler-trpc.js +1 -1
- package/dist/api-handler.cjs +1 -1
- package/dist/api-handler.js +1 -1
- package/dist/{base-urWvrsX8.d.cts → base-B--L0lCn.d.cts} +1 -1
- package/dist/base-BVoDPNjJ.d.cts +218 -0
- package/dist/base-CAb9EYQs.d.ts +218 -0
- package/dist/base-CyG7aF1e.d.cts +218 -0
- package/dist/{base-BcfNgOqZ.d.ts → base-DOImeJ-F.d.ts} +1 -1
- package/dist/base-DbnwE42-.d.cts +218 -0
- package/dist/base-NyiSsD-n.d.ts +218 -0
- package/dist/base-xflndGDO.d.ts +218 -0
- package/dist/bootstrap-QQ6D3OYG.js +1 -0
- package/dist/bootstrap-QVKSKXJF.cjs +1 -0
- package/dist/bootstrap-RILR44UM.cjs +1 -0
- package/dist/bootstrap-ZRRUPRUR.js +1 -0
- package/dist/chunk-262YP5XA.cjs +1 -0
- package/dist/chunk-2FSOHXOU.cjs +56 -0
- package/dist/chunk-2OS5Y4LE.cjs +1 -0
- package/dist/chunk-2PXXQKN3.cjs +3 -0
- package/dist/{chunk-K6ZW5M6S.cjs → chunk-355R4LS5.cjs} +3 -3
- package/dist/chunk-35IVNLMA.js +122 -0
- package/dist/{chunk-FSWDDVLA.js → chunk-3GXLOYM3.js} +1 -1
- package/dist/chunk-3KZXF4US.js +2 -0
- package/dist/{chunk-H7PC2ENZ.cjs → chunk-3LAWUINR.cjs} +1 -1
- package/dist/chunk-3O3AVMWM.cjs +1 -0
- package/dist/chunk-3U6MKWET.cjs +120 -0
- package/dist/chunk-4BMWWGJN.js +384 -0
- package/dist/chunk-5A7E7N4B.cjs +431 -0
- package/dist/chunk-6DD4J7LI.js +2 -0
- package/dist/chunk-6GGPY7U2.js +4 -0
- package/dist/chunk-6MNLRAKM.cjs +121 -0
- package/dist/chunk-6NBZDW53.js +133 -0
- package/dist/{chunk-2HATK4C5.js → chunk-73Y63IPP.js} +4 -4
- package/dist/chunk-7K6ZUNJM.js +4 -0
- package/dist/chunk-7NKNSRCB.cjs +448 -0
- package/dist/chunk-A3IOQOV6.js +2 -0
- package/dist/chunk-A3XVL6ED.cjs +3 -0
- package/dist/{chunk-LKQHIOPW.cjs → chunk-APDQ6ZTG.cjs} +1 -1
- package/dist/chunk-ATI2UZ7U.js +2 -0
- package/dist/chunk-B4AC23SG.js +122 -0
- package/dist/chunk-BD6XHMMM.cjs +2 -0
- package/dist/chunk-CH4TZZI5.js +449 -0
- package/dist/{chunk-26KFM3P6.js → chunk-CNHUCCQJ.js} +1 -1
- package/dist/chunk-CRP6PSCE.js +2 -0
- package/dist/chunk-DI6TCZSE.js +122 -0
- package/dist/chunk-DORUYZQV.cjs +1 -0
- package/dist/chunk-EFKEVWAD.js +4 -0
- package/dist/chunk-EI7FRSNY.js +57 -0
- package/dist/chunk-EON4XLKQ.cjs +1 -0
- package/dist/chunk-EUQAOYEO.cjs +121 -0
- package/dist/chunk-EVAUBT7H.js +57 -0
- package/dist/chunk-EYHD7HZE.cjs +1 -0
- package/dist/chunk-EYYIPA5N.js +432 -0
- package/dist/chunk-F2O4QO5N.cjs +383 -0
- package/dist/chunk-FBWLSWZ4.js +122 -0
- package/dist/chunk-FGN6IMPY.cjs +3 -0
- package/dist/chunk-FK2BG4HU.js +3 -0
- package/dist/chunk-GWIZT2P5.js +57 -0
- package/dist/chunk-H3FJ54KB.cjs +121 -0
- package/dist/chunk-HY3EAWB2.js +4 -0
- package/dist/chunk-I6UJVO2P.js +57 -0
- package/dist/chunk-IQSF6XRV.js +57 -0
- package/dist/chunk-IXGDTAES.js +4 -0
- package/dist/chunk-JA44K75G.js +2 -0
- package/dist/chunk-K5XGP57D.cjs +19 -0
- package/dist/chunk-KEITOXIP.js +2 -0
- package/dist/chunk-LPFRMQFQ.js +121 -0
- package/dist/chunk-LYU44UNN.cjs +56 -0
- package/dist/chunk-MDLJTZLV.cjs +1 -0
- package/dist/chunk-MJAODEFC.cjs +121 -0
- package/dist/chunk-MYHNTJLR.cjs +56 -0
- package/dist/chunk-N2YHO2WI.cjs +3 -0
- package/dist/chunk-N4FXLQE3.cjs +132 -0
- package/dist/chunk-NPBXLPOP.js +3 -0
- package/dist/chunk-ON5XJEPO.cjs +3 -0
- package/dist/chunk-OT2Z4XBD.cjs +1 -0
- package/dist/chunk-PFTBTWSC.cjs +1 -0
- package/dist/chunk-PTPVFLET.js +20 -0
- package/dist/chunk-PZDLPRJF.js +4 -0
- package/dist/chunk-Q5TFO66G.cjs +1 -0
- package/dist/chunk-QUTYCUST.js +4 -0
- package/dist/chunk-REKKBAQX.cjs +56 -0
- package/dist/chunk-REQ622YC.js +3 -0
- package/dist/chunk-RTNQP6BV.js +2 -0
- package/dist/chunk-RUJW47ZJ.js +2 -0
- package/dist/chunk-RXYCFZJC.cjs +121 -0
- package/dist/chunk-RYHOWZLK.js +2 -0
- package/dist/chunk-S2MZNEBQ.cjs +1 -0
- package/dist/chunk-S73YERS2.js +57 -0
- package/dist/chunk-SBNMXQNO.cjs +2 -0
- package/dist/chunk-T3DJ3UTP.cjs +121 -0
- package/dist/chunk-TJZO7ZSX.cjs +3 -0
- package/dist/chunk-TKUNRCRH.js +4 -0
- package/dist/chunk-TQLCOMKC.js +4 -0
- package/dist/chunk-TRXYDWGE.cjs +1 -0
- package/dist/chunk-TS55CUNJ.js +57 -0
- package/dist/chunk-UFBJ3WOZ.js +2 -0
- package/dist/chunk-UQRVQUVR.js +2 -0
- package/dist/chunk-UW5W35NP.js +122 -0
- package/dist/chunk-VI7WCO2J.cjs +3 -0
- package/dist/chunk-W2GPP6RB.js +122 -0
- package/dist/chunk-WHOA7YJU.cjs +1 -0
- package/dist/chunk-WNRUPL26.js +2 -0
- package/dist/chunk-WXT2XW7T.js +13 -0
- package/dist/chunk-XFYSADHV.cjs +2 -0
- package/dist/chunk-XIAJQLGS.js +2 -0
- package/dist/chunk-XK6UB77Q.js +4 -0
- package/dist/chunk-Y2VHO66Q.cjs +3 -0
- package/dist/chunk-Y5O2OD7J.cjs +3 -0
- package/dist/chunk-YARB43JG.cjs +56 -0
- package/dist/chunk-YLCEMVYY.cjs +56 -0
- package/dist/chunk-YSOM57GK.cjs +3 -0
- package/dist/chunk-Z3UVDGYS.cjs +56 -0
- package/dist/chunk-ZTLGK6R4.cjs +12 -0
- package/dist/chunk-ZUBJ6RLQ.cjs +1 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/client.cjs +8 -8
- package/dist/client.d.cts +1248 -0
- package/dist/client.d.ts +1248 -0
- package/dist/client.js +8 -8
- package/dist/drizzle/index.cjs +1 -1
- package/dist/drizzle/index.d.cts +3 -3
- package/dist/drizzle/index.d.ts +3 -3
- package/dist/drizzle/index.js +1 -1
- package/dist/fields/index.cjs +1 -1
- package/dist/fields/index.d.cts +2 -2
- package/dist/fields/index.d.ts +2 -2
- package/dist/fields/index.js +1 -1
- package/dist/graphql/index.d.cts +3 -3
- package/dist/graphql/index.d.ts +3 -3
- package/dist/{index-d1m_oup7.d.cts → index-B9BFNOHd.d.cts} +1 -1
- package/dist/index-BMcYFpTv.d.cts +105 -0
- package/dist/index-BttsFZDa.d.ts +105 -0
- package/dist/index-CxA9uOv0.d.ts +105 -0
- package/dist/{index-4cH-BjtP.d.ts → index-D6AXbuPI.d.ts} +1 -1
- package/dist/index-DF0KDBaM.d.cts +105 -0
- package/dist/index-DG4Xu7gA.d.cts +105 -0
- package/dist/index-eHex8Iwj.d.ts +105 -0
- package/dist/index.cjs +32 -32
- package/dist/index.d.cts +73 -11
- package/dist/index.d.ts +73 -11
- package/dist/index.js +32 -32
- package/dist/lib-A2D63VXD.cjs +1 -0
- package/dist/lib-JQD2JAOO.js +2 -0
- package/dist/local-KR3AIGVA.cjs +1 -0
- package/dist/local-T7GISZBL.js +1 -0
- package/dist/mongo-auth-adapter-GR2CFFEA.js +1 -0
- package/dist/mongo-auth-adapter-UOO2LZUJ.cjs +1 -0
- package/dist/mongodb/index.cjs +1 -1
- package/dist/mongodb/index.d.cts +4 -3
- package/dist/mongodb/index.d.ts +4 -3
- package/dist/mongodb/index.js +1 -1
- package/dist/nodemailer-transport-3VWVUBM5.cjs +1 -0
- package/dist/nodemailer-transport-7RHATUKL.js +1 -0
- package/dist/nodemailer-transport-CHO2WKIY.js +1 -0
- package/dist/nodemailer-transport-ED2IXNGW.cjs +1 -0
- package/dist/rest/index.cjs +1 -1
- package/dist/rest/index.d.cts +4 -4
- package/dist/rest/index.d.ts +4 -4
- package/dist/rest/index.js +1 -1
- package/dist/templates/index.cjs +1 -1
- package/dist/templates/index.d.cts +2 -2
- package/dist/templates/index.d.ts +2 -2
- package/dist/templates/index.js +1 -1
- package/dist/trpc/index.cjs +1 -1
- package/dist/trpc/index.d.cts +3 -3
- package/dist/trpc/index.d.ts +3 -3
- package/dist/trpc/index.js +1 -1
- package/dist/types-B5Qz1svz.d.cts +822 -0
- package/dist/types-Bii0bhUV.d.cts +329 -0
- package/dist/types-Bii0bhUV.d.ts +329 -0
- package/dist/{types-BADIMVGF.d.ts → types-Bt2_ycUO.d.ts} +36 -1
- package/dist/types-C4wXHImf.d.ts +822 -0
- package/dist/types-DCWgPFmi.d.cts +822 -0
- package/dist/types-DROqAsr0.d.cts +330 -0
- package/dist/types-DROqAsr0.d.ts +330 -0
- package/dist/{types-YAVR0H9Z.d.cts → types-DsF64Wrc.d.cts} +36 -1
- package/dist/types-ZrjEVWfi.d.ts +811 -0
- package/dist/types-dEy5JxvN.d.ts +822 -0
- package/dist/types-tVJc9YbX.d.cts +811 -0
- package/dist/ws/index.cjs +1 -1
- package/dist/ws/index.d.cts +121 -1
- package/dist/ws/index.d.ts +121 -1
- package/dist/ws/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-5M3FKE2V.js +0 -2
- package/dist/chunk-WCFHS7EZ.cjs +0 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, U as UpdateArgs, D as DeleteArgs, e as FindOneArgs, f as FindVersionsArgs, V as VersionRecord, g as CreateVersionArgs } from './types-ZrjEVWfi.js';
|
|
2
|
+
import { F as Field, u as RelationshipField, U as UploadField } from './types-Bii0bhUV.js';
|
|
3
|
+
|
|
4
|
+
type AuditAction = "login" | "logout" | "login_failed" | "register" | "verify_email" | "password_change" | "password_reset" | "password_reset_request" | "role_change" | "permission_change" | "document_create" | "document_update" | "document_delete" | "settings_change" | "user_lockout" | "user_unlock" | "user_create" | "user_update" | "user_delete" | "api_request" | "api_key_create" | "api_key_update" | "api_key_rotate" | "api_key_delete" | "tenant_create" | "tenant_delete";
|
|
5
|
+
interface AuditLog {
|
|
6
|
+
id: string;
|
|
7
|
+
timestamp: Date;
|
|
8
|
+
action: AuditAction;
|
|
9
|
+
userId?: string;
|
|
10
|
+
userEmail?: string;
|
|
11
|
+
role?: string;
|
|
12
|
+
resource: string;
|
|
13
|
+
resourceId?: string;
|
|
14
|
+
changes?: {
|
|
15
|
+
field: string;
|
|
16
|
+
old: any;
|
|
17
|
+
new: any;
|
|
18
|
+
}[];
|
|
19
|
+
ipAddress?: string;
|
|
20
|
+
userAgent?: string;
|
|
21
|
+
success: boolean;
|
|
22
|
+
error?: string;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
interface AuditLogFilter {
|
|
26
|
+
userId?: string;
|
|
27
|
+
action?: AuditAction | AuditAction[];
|
|
28
|
+
resource?: string;
|
|
29
|
+
resourceId?: string;
|
|
30
|
+
success?: boolean;
|
|
31
|
+
startDate?: Date;
|
|
32
|
+
endDate?: Date;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface AuthUser {
|
|
38
|
+
id: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
email: string;
|
|
41
|
+
passwordHash?: string;
|
|
42
|
+
role: UserRole;
|
|
43
|
+
avatar?: string;
|
|
44
|
+
tenantId?: string;
|
|
45
|
+
emailVerified?: boolean;
|
|
46
|
+
locked?: boolean;
|
|
47
|
+
lastLogin?: string;
|
|
48
|
+
failedLoginAttempts?: number;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
}
|
|
52
|
+
type UserRole = "super_admin" | "admin" | "editor" | "author" | "customer" | "guest";
|
|
53
|
+
interface Session {
|
|
54
|
+
id: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
token: string;
|
|
57
|
+
refreshToken?: string;
|
|
58
|
+
expiresAt: string;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
ipAddress?: string;
|
|
61
|
+
userAgent?: string;
|
|
62
|
+
}
|
|
63
|
+
interface JWTPayload {
|
|
64
|
+
sub: string;
|
|
65
|
+
email: string;
|
|
66
|
+
role: UserRole;
|
|
67
|
+
tenantId?: string;
|
|
68
|
+
iat?: number;
|
|
69
|
+
exp?: number;
|
|
70
|
+
sid?: string;
|
|
71
|
+
}
|
|
72
|
+
interface AuthTokenConfig {
|
|
73
|
+
secret: string;
|
|
74
|
+
expiresIn?: string | number;
|
|
75
|
+
refreshExpiresIn?: string | number;
|
|
76
|
+
issuer?: string;
|
|
77
|
+
audience?: string[];
|
|
78
|
+
saltRounds?: number;
|
|
79
|
+
}
|
|
80
|
+
interface LoginCredentials {
|
|
81
|
+
email: string;
|
|
82
|
+
password: string;
|
|
83
|
+
}
|
|
84
|
+
interface RegisterData {
|
|
85
|
+
email: string;
|
|
86
|
+
password: string;
|
|
87
|
+
role?: UserRole;
|
|
88
|
+
tenantId?: string;
|
|
89
|
+
}
|
|
90
|
+
interface AuthResult {
|
|
91
|
+
success: boolean;
|
|
92
|
+
user?: AuthUser;
|
|
93
|
+
session?: Session;
|
|
94
|
+
token?: string;
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
interface AuthAdapter {
|
|
98
|
+
createUser(data: {
|
|
99
|
+
email: string;
|
|
100
|
+
password: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
role?: UserRole;
|
|
103
|
+
avatar?: string;
|
|
104
|
+
tenantId?: string;
|
|
105
|
+
}): Promise<AuthUser>;
|
|
106
|
+
findUserByEmail(email: string): Promise<AuthUser | null>;
|
|
107
|
+
findUserById(id: string): Promise<AuthUser | null>;
|
|
108
|
+
updateUser(id: string, data: Partial<AuthUser> & {
|
|
109
|
+
password?: string;
|
|
110
|
+
}): Promise<AuthUser | null>;
|
|
111
|
+
deleteUser(id: string): Promise<boolean>;
|
|
112
|
+
verifyPassword(email: string, password: string): Promise<AuthUser | null>;
|
|
113
|
+
hashPassword(password: string): Promise<string>;
|
|
114
|
+
createSession(userId: string, data?: {
|
|
115
|
+
ipAddress?: string;
|
|
116
|
+
userAgent?: string;
|
|
117
|
+
}): Promise<Session>;
|
|
118
|
+
findSessionByToken(token: string): Promise<Session | null>;
|
|
119
|
+
findSessionByRefreshToken(refreshToken: string): Promise<Session | null>;
|
|
120
|
+
deleteSession(sessionId: string): Promise<boolean>;
|
|
121
|
+
deleteUserSessions(userId: string): Promise<number>;
|
|
122
|
+
createEmailVerificationToken(userId: string): Promise<{
|
|
123
|
+
token: string;
|
|
124
|
+
expiresAt: Date;
|
|
125
|
+
}>;
|
|
126
|
+
verifyEmailToken(token: string): Promise<{
|
|
127
|
+
success: boolean;
|
|
128
|
+
userId?: string;
|
|
129
|
+
error?: string;
|
|
130
|
+
}>;
|
|
131
|
+
createPasswordResetToken(email: string): Promise<{
|
|
132
|
+
token: string;
|
|
133
|
+
expiresAt: Date;
|
|
134
|
+
error?: string;
|
|
135
|
+
}>;
|
|
136
|
+
resetPasswordWithToken(token: string, newPassword: string): Promise<{
|
|
137
|
+
success: boolean;
|
|
138
|
+
error?: string;
|
|
139
|
+
}>;
|
|
140
|
+
hasAnyUsers?(): Promise<boolean>;
|
|
141
|
+
connect?(): Promise<void>;
|
|
142
|
+
disconnect?(): Promise<void>;
|
|
143
|
+
addPasswordToHistory?(userId: string, passwordHash: string): Promise<void>;
|
|
144
|
+
getPasswordHistory?(userId: string, count?: number): Promise<string[]>;
|
|
145
|
+
isPasswordInHistory?(password: string, userId: string, historyCount?: number): Promise<boolean>;
|
|
146
|
+
findAuditLogs(filter: AuditLogFilter): Promise<{
|
|
147
|
+
logs: AuditLog[];
|
|
148
|
+
total: number;
|
|
149
|
+
}>;
|
|
150
|
+
createAuditLog(data: Omit<AuditLog, "id" | "timestamp">): Promise<AuditLog>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare abstract class AbstractBaseAdapter implements BaseAdapter {
|
|
154
|
+
protected collections: Map<string, CollectionConfig>;
|
|
155
|
+
protected globals: Map<string, GlobalConfig>;
|
|
156
|
+
protected connected: boolean;
|
|
157
|
+
protected tenantContext?: TenantContext;
|
|
158
|
+
abstract connect(): Promise<void>;
|
|
159
|
+
abstract disconnect(): Promise<void>;
|
|
160
|
+
setTenantContext(context: TenantContext | undefined): void;
|
|
161
|
+
getTenantContext(): TenantContext | undefined;
|
|
162
|
+
init(collections: CollectionConfig[], globals?: GlobalConfig[]): Promise<void>;
|
|
163
|
+
abstract find<T>(args: FindArgs): Promise<FindResult<T>>;
|
|
164
|
+
abstract findByID<T>(args: FindByIDArgs): Promise<T | null>;
|
|
165
|
+
abstract create<T>(args: CreateArgs): Promise<T>;
|
|
166
|
+
abstract update<T>(args: UpdateArgs): Promise<T>;
|
|
167
|
+
abstract delete<T>(args: DeleteArgs): Promise<T>;
|
|
168
|
+
abstract count(args: {
|
|
169
|
+
collection: string;
|
|
170
|
+
where?: Record<string, any>;
|
|
171
|
+
tenantId?: string;
|
|
172
|
+
}): Promise<number>;
|
|
173
|
+
abstract findOne(args: FindOneArgs): Promise<any>;
|
|
174
|
+
abstract findVersions(args: FindVersionsArgs): Promise<FindResult<VersionRecord>>;
|
|
175
|
+
abstract findVersionByID(args: {
|
|
176
|
+
collection: string;
|
|
177
|
+
versionId: string;
|
|
178
|
+
tenantId?: string;
|
|
179
|
+
}): Promise<VersionRecord | null>;
|
|
180
|
+
abstract createVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
|
|
181
|
+
abstract updateLatestVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
|
|
182
|
+
abstract deleteVersions(args: {
|
|
183
|
+
collection: string;
|
|
184
|
+
documentId: string;
|
|
185
|
+
keepLatest?: number;
|
|
186
|
+
tenantId?: string;
|
|
187
|
+
}): Promise<void>;
|
|
188
|
+
migrate?(): Promise<void>;
|
|
189
|
+
rollback?(): Promise<void>;
|
|
190
|
+
transaction?<T>(fn: (tx: any) => Promise<T>): Promise<T>;
|
|
191
|
+
protected getCollection(slug: string): CollectionConfig;
|
|
192
|
+
protected applyTenantFilter(where?: Record<string, any>, tenantId?: string): Record<string, any>;
|
|
193
|
+
protected getTableName(slug: string): string;
|
|
194
|
+
protected prepareData(data: Record<string, any>, collection: CollectionConfig): Record<string, any>;
|
|
195
|
+
protected processRelationships(data: Record<string, any>, fields: Field[], depth: number): Record<string, any>;
|
|
196
|
+
protected parseSort(sort?: string): {
|
|
197
|
+
field: string;
|
|
198
|
+
direction: 'asc' | 'desc';
|
|
199
|
+
};
|
|
200
|
+
protected calculatePagination(page: number, limit: number, totalDocs: number): {
|
|
201
|
+
totalDocs: number;
|
|
202
|
+
limit: number;
|
|
203
|
+
totalPages: number;
|
|
204
|
+
page: number;
|
|
205
|
+
pagingCounter: number;
|
|
206
|
+
hasPrevPage: boolean;
|
|
207
|
+
hasNextPage: boolean;
|
|
208
|
+
prevPage: number | null;
|
|
209
|
+
nextPage: number | null;
|
|
210
|
+
};
|
|
211
|
+
protected selectFields(data: Record<string, any>, select?: string[]): Record<string, any>;
|
|
212
|
+
protected isRelationshipField(field: Field): field is RelationshipField;
|
|
213
|
+
protected isUploadField(field: Field): field is UploadField;
|
|
214
|
+
protected getRelationshipFields(fields: Field[]): RelationshipField[];
|
|
215
|
+
protected getUploadFields(fields: Field[]): UploadField[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { type AuditLog as A, type JWTPayload as J, type LoginCredentials as L, type RegisterData as R, type Session as S, type UserRole as U, type AuditLogFilter as a, AbstractBaseAdapter as b, type AuthAdapter as c, type AuthUser as d, type AuthTokenConfig as e, type AuthResult as f, type AuditAction as g };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { B as BaseAdapter, C as CollectionConfig, G as GlobalConfig, T as TenantContext, F as FindArgs, b as FindResult, c as FindByIDArgs, d as CreateArgs, U as UpdateArgs, D as DeleteArgs, e as FindOneArgs, f as FindVersionsArgs, V as VersionRecord, g as CreateVersionArgs } from './types-dEy5JxvN.js';
|
|
2
|
+
import { F as Field, u as RelationshipField, U as UploadField } from './types-Bii0bhUV.js';
|
|
3
|
+
|
|
4
|
+
type AuditAction = "login" | "logout" | "login_failed" | "register" | "verify_email" | "password_change" | "password_reset" | "password_reset_request" | "role_change" | "permission_change" | "document_create" | "document_update" | "document_delete" | "settings_change" | "user_lockout" | "user_unlock" | "user_create" | "user_update" | "user_delete" | "api_request" | "api_key_create" | "api_key_update" | "api_key_rotate" | "api_key_delete" | "tenant_create" | "tenant_delete";
|
|
5
|
+
interface AuditLog {
|
|
6
|
+
id: string;
|
|
7
|
+
timestamp: Date;
|
|
8
|
+
action: AuditAction;
|
|
9
|
+
userId?: string;
|
|
10
|
+
userEmail?: string;
|
|
11
|
+
role?: string;
|
|
12
|
+
resource: string;
|
|
13
|
+
resourceId?: string;
|
|
14
|
+
changes?: {
|
|
15
|
+
field: string;
|
|
16
|
+
old: any;
|
|
17
|
+
new: any;
|
|
18
|
+
}[];
|
|
19
|
+
ipAddress?: string;
|
|
20
|
+
userAgent?: string;
|
|
21
|
+
success: boolean;
|
|
22
|
+
error?: string;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
interface AuditLogFilter {
|
|
26
|
+
userId?: string;
|
|
27
|
+
action?: AuditAction | AuditAction[];
|
|
28
|
+
resource?: string;
|
|
29
|
+
resourceId?: string;
|
|
30
|
+
success?: boolean;
|
|
31
|
+
startDate?: Date;
|
|
32
|
+
endDate?: Date;
|
|
33
|
+
limit?: number;
|
|
34
|
+
offset?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface AuthUser {
|
|
38
|
+
id: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
email: string;
|
|
41
|
+
passwordHash?: string;
|
|
42
|
+
role: UserRole;
|
|
43
|
+
avatar?: string;
|
|
44
|
+
tenantId?: string;
|
|
45
|
+
emailVerified?: boolean;
|
|
46
|
+
locked?: boolean;
|
|
47
|
+
lastLogin?: string;
|
|
48
|
+
failedLoginAttempts?: number;
|
|
49
|
+
createdAt: string;
|
|
50
|
+
updatedAt: string;
|
|
51
|
+
}
|
|
52
|
+
type UserRole = "super_admin" | "admin" | "editor" | "author" | "customer" | "guest";
|
|
53
|
+
interface Session {
|
|
54
|
+
id: string;
|
|
55
|
+
userId: string;
|
|
56
|
+
token: string;
|
|
57
|
+
refreshToken?: string;
|
|
58
|
+
expiresAt: string;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
ipAddress?: string;
|
|
61
|
+
userAgent?: string;
|
|
62
|
+
}
|
|
63
|
+
interface JWTPayload {
|
|
64
|
+
sub: string;
|
|
65
|
+
email: string;
|
|
66
|
+
role: UserRole;
|
|
67
|
+
tenantId?: string;
|
|
68
|
+
iat?: number;
|
|
69
|
+
exp?: number;
|
|
70
|
+
sid?: string;
|
|
71
|
+
}
|
|
72
|
+
interface AuthTokenConfig {
|
|
73
|
+
secret: string;
|
|
74
|
+
expiresIn?: string | number;
|
|
75
|
+
refreshExpiresIn?: string | number;
|
|
76
|
+
issuer?: string;
|
|
77
|
+
audience?: string[];
|
|
78
|
+
saltRounds?: number;
|
|
79
|
+
}
|
|
80
|
+
interface LoginCredentials {
|
|
81
|
+
email: string;
|
|
82
|
+
password: string;
|
|
83
|
+
}
|
|
84
|
+
interface RegisterData {
|
|
85
|
+
email: string;
|
|
86
|
+
password: string;
|
|
87
|
+
role?: UserRole;
|
|
88
|
+
tenantId?: string;
|
|
89
|
+
}
|
|
90
|
+
interface AuthResult {
|
|
91
|
+
success: boolean;
|
|
92
|
+
user?: AuthUser;
|
|
93
|
+
session?: Session;
|
|
94
|
+
token?: string;
|
|
95
|
+
error?: string;
|
|
96
|
+
}
|
|
97
|
+
interface AuthAdapter {
|
|
98
|
+
createUser(data: {
|
|
99
|
+
email: string;
|
|
100
|
+
password: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
role?: UserRole;
|
|
103
|
+
avatar?: string;
|
|
104
|
+
tenantId?: string;
|
|
105
|
+
}): Promise<AuthUser>;
|
|
106
|
+
findUserByEmail(email: string): Promise<AuthUser | null>;
|
|
107
|
+
findUserById(id: string): Promise<AuthUser | null>;
|
|
108
|
+
updateUser(id: string, data: Partial<AuthUser> & {
|
|
109
|
+
password?: string;
|
|
110
|
+
}): Promise<AuthUser | null>;
|
|
111
|
+
deleteUser(id: string): Promise<boolean>;
|
|
112
|
+
verifyPassword(email: string, password: string): Promise<AuthUser | null>;
|
|
113
|
+
hashPassword(password: string): Promise<string>;
|
|
114
|
+
createSession(userId: string, data?: {
|
|
115
|
+
ipAddress?: string;
|
|
116
|
+
userAgent?: string;
|
|
117
|
+
}): Promise<Session>;
|
|
118
|
+
findSessionByToken(token: string): Promise<Session | null>;
|
|
119
|
+
findSessionByRefreshToken(refreshToken: string): Promise<Session | null>;
|
|
120
|
+
deleteSession(sessionId: string): Promise<boolean>;
|
|
121
|
+
deleteUserSessions(userId: string): Promise<number>;
|
|
122
|
+
createEmailVerificationToken(userId: string): Promise<{
|
|
123
|
+
token: string;
|
|
124
|
+
expiresAt: Date;
|
|
125
|
+
}>;
|
|
126
|
+
verifyEmailToken(token: string): Promise<{
|
|
127
|
+
success: boolean;
|
|
128
|
+
userId?: string;
|
|
129
|
+
error?: string;
|
|
130
|
+
}>;
|
|
131
|
+
createPasswordResetToken(email: string): Promise<{
|
|
132
|
+
token: string;
|
|
133
|
+
expiresAt: Date;
|
|
134
|
+
error?: string;
|
|
135
|
+
}>;
|
|
136
|
+
resetPasswordWithToken(token: string, newPassword: string): Promise<{
|
|
137
|
+
success: boolean;
|
|
138
|
+
error?: string;
|
|
139
|
+
}>;
|
|
140
|
+
hasAnyUsers?(): Promise<boolean>;
|
|
141
|
+
connect?(): Promise<void>;
|
|
142
|
+
disconnect?(): Promise<void>;
|
|
143
|
+
addPasswordToHistory?(userId: string, passwordHash: string): Promise<void>;
|
|
144
|
+
getPasswordHistory?(userId: string, count?: number): Promise<string[]>;
|
|
145
|
+
isPasswordInHistory?(password: string, userId: string, historyCount?: number): Promise<boolean>;
|
|
146
|
+
findAuditLogs(filter: AuditLogFilter): Promise<{
|
|
147
|
+
logs: AuditLog[];
|
|
148
|
+
total: number;
|
|
149
|
+
}>;
|
|
150
|
+
createAuditLog(data: Omit<AuditLog, "id" | "timestamp">): Promise<AuditLog>;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
declare abstract class AbstractBaseAdapter implements BaseAdapter {
|
|
154
|
+
protected collections: Map<string, CollectionConfig>;
|
|
155
|
+
protected globals: Map<string, GlobalConfig>;
|
|
156
|
+
protected connected: boolean;
|
|
157
|
+
protected tenantContext?: TenantContext;
|
|
158
|
+
abstract connect(): Promise<void>;
|
|
159
|
+
abstract disconnect(): Promise<void>;
|
|
160
|
+
setTenantContext(context: TenantContext | undefined): void;
|
|
161
|
+
getTenantContext(): TenantContext | undefined;
|
|
162
|
+
init(collections: CollectionConfig[], globals?: GlobalConfig[]): Promise<void>;
|
|
163
|
+
abstract find<T>(args: FindArgs): Promise<FindResult<T>>;
|
|
164
|
+
abstract findByID<T>(args: FindByIDArgs): Promise<T | null>;
|
|
165
|
+
abstract create<T>(args: CreateArgs): Promise<T>;
|
|
166
|
+
abstract update<T>(args: UpdateArgs): Promise<T>;
|
|
167
|
+
abstract delete<T>(args: DeleteArgs): Promise<T>;
|
|
168
|
+
abstract count(args: {
|
|
169
|
+
collection: string;
|
|
170
|
+
where?: Record<string, any>;
|
|
171
|
+
tenantId?: string;
|
|
172
|
+
}): Promise<number>;
|
|
173
|
+
abstract findOne(args: FindOneArgs): Promise<any>;
|
|
174
|
+
abstract findVersions(args: FindVersionsArgs): Promise<FindResult<VersionRecord>>;
|
|
175
|
+
abstract findVersionByID(args: {
|
|
176
|
+
collection: string;
|
|
177
|
+
versionId: string;
|
|
178
|
+
tenantId?: string;
|
|
179
|
+
}): Promise<VersionRecord | null>;
|
|
180
|
+
abstract createVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
|
|
181
|
+
abstract updateLatestVersion<T = Record<string, any>>(args: CreateVersionArgs<T>): Promise<VersionRecord<T>>;
|
|
182
|
+
abstract deleteVersions(args: {
|
|
183
|
+
collection: string;
|
|
184
|
+
documentId: string;
|
|
185
|
+
keepLatest?: number;
|
|
186
|
+
tenantId?: string;
|
|
187
|
+
}): Promise<void>;
|
|
188
|
+
migrate?(): Promise<void>;
|
|
189
|
+
rollback?(): Promise<void>;
|
|
190
|
+
transaction?<T>(fn: (tx: any) => Promise<T>): Promise<T>;
|
|
191
|
+
protected getCollection(slug: string): CollectionConfig;
|
|
192
|
+
protected applyTenantFilter(where?: Record<string, any>, tenantId?: string): Record<string, any>;
|
|
193
|
+
protected getTableName(slug: string): string;
|
|
194
|
+
protected prepareData(data: Record<string, any>, collection: CollectionConfig): Record<string, any>;
|
|
195
|
+
protected processRelationships(data: Record<string, any>, fields: Field[], depth: number): Record<string, any>;
|
|
196
|
+
protected parseSort(sort?: string): {
|
|
197
|
+
field: string;
|
|
198
|
+
direction: 'asc' | 'desc';
|
|
199
|
+
};
|
|
200
|
+
protected calculatePagination(page: number, limit: number, totalDocs: number): {
|
|
201
|
+
totalDocs: number;
|
|
202
|
+
limit: number;
|
|
203
|
+
totalPages: number;
|
|
204
|
+
page: number;
|
|
205
|
+
pagingCounter: number;
|
|
206
|
+
hasPrevPage: boolean;
|
|
207
|
+
hasNextPage: boolean;
|
|
208
|
+
prevPage: number | null;
|
|
209
|
+
nextPage: number | null;
|
|
210
|
+
};
|
|
211
|
+
protected selectFields(data: Record<string, any>, select?: string[]): Record<string, any>;
|
|
212
|
+
protected isRelationshipField(field: Field): field is RelationshipField;
|
|
213
|
+
protected isUploadField(field: Field): field is UploadField;
|
|
214
|
+
protected getRelationshipFields(fields: Field[]): RelationshipField[];
|
|
215
|
+
protected getUploadFields(fields: Field[]): UploadField[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export { type AuditLog as A, type JWTPayload as J, type LoginCredentials as L, type RegisterData as R, type Session as S, type UserRole as U, type AuditLogFilter as a, AbstractBaseAdapter as b, type AuthAdapter as c, type AuthUser as d, type AuthTokenConfig as e, type AuthResult as f, type AuditAction as g };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{e as autoBootstrap,a as bootstrapAdmin,f as bootstrapWithRetry,c as buildBootstrapConfig,b as checkBootstrapRequired,d as getBootstrapFromEnv}from'./chunk-ATI2UZ7U.js';import'./chunk-3KZXF4US.js';import'./chunk-CH4TZZI5.js';import'./chunk-OLRCZ6E3.js';import'./chunk-N6MNQIQU.js';import'./chunk-3NSZZCOJ.js';import'./chunk-7NH7H3WA.js';import'./chunk-Y2YAKDEQ.js';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkWHOA7YJU_cjs=require('./chunk-WHOA7YJU.cjs');require('./chunk-Q5TFO66G.cjs'),require('./chunk-5A7E7N4B.cjs'),require('./chunk-HPYH7GTS.cjs'),require('./chunk-OPTVCCQQ.cjs'),require('./chunk-VRZC4TTF.cjs'),require('./chunk-HTYVI2HK.cjs'),require('./chunk-BUNLC3II.cjs');Object.defineProperty(exports,"autoBootstrap",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.e}});Object.defineProperty(exports,"bootstrapAdmin",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.a}});Object.defineProperty(exports,"bootstrapWithRetry",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.f}});Object.defineProperty(exports,"buildBootstrapConfig",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.c}});Object.defineProperty(exports,"checkBootstrapRequired",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.b}});Object.defineProperty(exports,"getBootstrapFromEnv",{enumerable:true,get:function(){return chunkWHOA7YJU_cjs.d}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk3O3AVMWM_cjs=require('./chunk-3O3AVMWM.cjs');require('./chunk-Q5TFO66G.cjs'),require('./chunk-7NKNSRCB.cjs'),require('./chunk-HPYH7GTS.cjs'),require('./chunk-OPTVCCQQ.cjs'),require('./chunk-VRZC4TTF.cjs'),require('./chunk-HTYVI2HK.cjs'),require('./chunk-BUNLC3II.cjs');Object.defineProperty(exports,"autoBootstrap",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.e}});Object.defineProperty(exports,"bootstrapAdmin",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.a}});Object.defineProperty(exports,"bootstrapWithRetry",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.f}});Object.defineProperty(exports,"buildBootstrapConfig",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.c}});Object.defineProperty(exports,"checkBootstrapRequired",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.b}});Object.defineProperty(exports,"getBootstrapFromEnv",{enumerable:true,get:function(){return chunk3O3AVMWM_cjs.d}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{e as autoBootstrap,a as bootstrapAdmin,f as bootstrapWithRetry,c as buildBootstrapConfig,b as checkBootstrapRequired,d as getBootstrapFromEnv}from'./chunk-UFBJ3WOZ.js';import'./chunk-3KZXF4US.js';import'./chunk-EYYIPA5N.js';import'./chunk-OLRCZ6E3.js';import'./chunk-N6MNQIQU.js';import'./chunk-3NSZZCOJ.js';import'./chunk-7NH7H3WA.js';import'./chunk-Y2YAKDEQ.js';if (typeof window === "undefined") { const { createRequire } = await import(/* @vite-ignore */ 'module'); createRequire(import.meta.url); }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkSBNMXQNO_cjs=require('./chunk-SBNMXQNO.cjs'),chunkZHA446FA_cjs=require('./chunk-ZHA446FA.cjs'),chunkZUBJ6RLQ_cjs=require('./chunk-ZUBJ6RLQ.cjs'),chunkBUNLC3II_cjs=require('./chunk-BUNLC3II.cjs');chunkBUNLC3II_cjs.h();chunkBUNLC3II_cjs.h();async function V(e){let a=chunkSBNMXQNO_cjs.n(e.db),t={db:e.db,registry:e.registry,req:e.req,user:e.user,tenantId:e.tenantId,webhookService:a,settings:e.settings},n=chunkZHA446FA_cjs.c(e.req);if(n){let r=await chunkZHA446FA_cjs.b(n,e.db,async o=>{try{return await e.db.findByID({collection:"users",id:o})||null}catch{return null}});r.valid&&(t.user=r.user||e.user,t.tenantId=r.tenantId||e.tenantId,t.apiKey=chunkZHA446FA_cjs.d(r));}return t}chunkBUNLC3II_cjs.h();var G={_media:{create:chunkSBNMXQNO_cjs.c.MEDIA_UPLOAD,update:chunkSBNMXQNO_cjs.c.MEDIA_UPLOAD,delete:chunkSBNMXQNO_cjs.c.MEDIA_DELETE}};function R(e,a){let t=G[e];return t?t[a]:`collection.${a}`}async function q(e,a,t){if(e.webhookService)try{await e.webhookService.trigger(a,{collection:t.collection,operation:t.operation,data:t.data,previousData:t.previousData,user:e.user?{id:e.user.id,email:e.user.email,role:e.user.role}:void 0,tenantId:e.tenantId});}catch(n){console.error(`[Webhook] Failed to trigger ${a}:`,n);}}function I(e,a){if(!(!e||typeof e!="object"))for(let t of a){if(t.type==="tabs"&&Array.isArray(t.tabs)){let r=t.name?e[t.name]:e;if(r&&typeof r=="object")for(let o of t.tabs)Array.isArray(o.fields)&&I(r,o.fields);continue}if(!t.name||!(t.name in e))continue;if(e[t.name]===""&&(t.type==="text"||t.type==="textarea"||t.type==="code"||t.type==="markdown"||t.type==="email"||t.type==="password"||t.type==="color"||(e[t.name]=null)),(t.type==="group"||t.type==="collapsible")&&t.name&&Array.isArray(t.fields)&&e[t.name]&&typeof e[t.name]=="object")I(e[t.name],t.fields);else if(t.type==="array"&&t.name&&Array.isArray(t.fields)&&Array.isArray(e[t.name]))for(let r of e[t.name])r&&typeof r=="object"&&I(r,t.fields);else if(t.type==="blocks"&&t.name&&Array.isArray(t.blocks)&&Array.isArray(e[t.name]))for(let r of e[t.name]){if(!r||typeof r!="object")continue;let o=r.type||r.blockType;if(!o)continue;let s=t.blocks.find(i=>i.slug===o);if(!s||!Array.isArray(s.fields))continue;let u=r.data&&typeof r.data=="object"?r.data:r;I(u,s.fields);}}}async function b(e,a,t){let n=await chunkSBNMXQNO_cjs.a(e,a,{user:t.user,req:t.req,tenantId:t.tenantId,apiKey:t.apiKey});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function P(e){return async a=>{let{collection:t,where:n,sort:r,limit:o,page:s,depth:u,select:i,draft:d}=a,l=e.registry.getCollection(t);if(await b(l,"read",e),l.hooks?.beforeRead)for(let p of l.hooks.beforeRead)await p({collection:t,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",where:n});let c=d??!!e.user,h=await e.db.find({collection:t,where:n||{},sort:r,limit:o||10,page:s||1,depth:u||0,tenantId:e.tenantId,select:i,draft:c});if(l.hooks?.afterRead)for(let p of h.docs)for(let k of l.hooks.afterRead)await k({collection:t,doc:p,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read"});return await chunkSBNMXQNO_cjs.o(h.docs,l.fields,e.db,e.registry,1,u||0),chunkZUBJ6RLQ_cjs.a(h)}}function v(e){return async a=>{let{collection:t,id:n,depth:r,select:o,draft:s}=a,u=e.registry.getCollection(t);await b(u,"read",e);let i=s??!!e.user,d=await e.db.findByID({collection:t,id:n,depth:r||0,tenantId:e.tenantId,select:o,draft:i});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(u.hooks?.afterRead)for(let l of u.hooks.afterRead)await l({collection:t,doc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"read",id:n});return await chunkSBNMXQNO_cjs.o([d],u.fields,e.db,e.registry,1,r||0),chunkZUBJ6RLQ_cjs.a(d)}}function K(e){return async a=>{let{collection:t,data:n,depth:r,select:o}=a,s=e.registry.getCollection(t);await b(s,"create",e);let i=e.registry.getCreateZodSchema(t).parse(n);if(s.tenantScoped&&e.tenantId&&(i.tenantId=e.tenantId),s.hooks?.beforeValidate)for(let l of s.hooks.beforeValidate){let c=await l({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(i,c);}if(s.hooks?.beforeChange)for(let l of s.hooks.beforeChange){let c=await l({collection:t,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});c&&typeof c=="object"&&!Array.isArray(c)&&Object.assign(i,c);}let d=await e.db.create({collection:t,data:i,depth:r||0,tenantId:e.tenantId,select:o});if(s.hooks?.afterChange)for(let l of s.hooks.afterChange)await l({collection:t,doc:d,data:i,req:e.req,user:e.user,tenantId:e.tenantId,operation:"create"});return await q(e,R(t,"create"),{collection:t,data:d,operation:"create"}),{doc:d}}}function E(e){return async a=>{let{collection:t,id:n,data:r,depth:o,select:s,baseUpdatedAt:u}=a,i=e.registry.getCollection(t);await b(i,"update",e);let d=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!d)throw new Error(`Document not found: ${t}/${n}`);if(u&&d.updatedAt&&u!==d.updatedAt)throw new Error(`Revision conflict: document has changed since ${u}. Current updatedAt: ${d.updatedAt}`);I(r,i.fields);let c=e.registry.getUpdateZodSchema(t).parse(r);if(i.tenantScoped&&e.tenantId&&(c.tenantId=e.tenantId),i.hooks?.beforeValidate)for(let m of i.hooks.beforeValidate){let f=await m({collection:t,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});f&&typeof f=="object"&&!Array.isArray(f)&&Object.assign(c,f);}if(i.hooks?.beforeChange)for(let m of i.hooks.beforeChange){let f=await m({collection:t,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});f&&typeof f=="object"&&!Array.isArray(f)&&Object.assign(c,f);}let h=e.req&&typeof e.req.headers?.get=="function"&&e.req.headers.get("x-draft")==="true"||a.draft===true,p=i.versions?.drafts===true,k=e.req?.query?.autosave==="true"||e.req?.url?.includes("autosave=true")||a.autosave===true,g;if(p&&h?(await e.db.createVersion({collection:t,documentId:n,data:c,status:"draft",autosave:k,createdBy:e.user?.id,tenantId:e.tenantId}),g=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true})):p?(g=await e.db.update({collection:t,id:n,data:{...c,status:"published"},depth:o||0,tenantId:e.tenantId,select:s}),await e.db.createVersion({collection:t,documentId:n,data:c,status:"published",createdBy:e.user?.id,tenantId:e.tenantId})):g=await e.db.update({collection:t,id:n,data:c,depth:o||0,tenantId:e.tenantId,select:s}),i.hooks?.afterChange)for(let m of i.hooks.afterChange)await m({collection:t,doc:g,data:c,originalDoc:d,req:e.req,user:e.user,tenantId:e.tenantId,operation:"update",id:n});return await q(e,R(t,"update"),{collection:t,data:g,previousData:d,operation:"update"}),{doc:g}}}function j(e){return async a=>{let{collection:t,id:n}=a,r=e.registry.getCollection(t);await b(r,"delete",e);let o=await e.db.findByID({collection:t,id:n,tenantId:e.tenantId,draft:true});if(!o)throw new Error(`Document not found: ${t}/${n}`);if(r.hooks?.beforeDelete)for(let u of r.hooks.beforeDelete)await u({collection:t,doc:o,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});let s=await e.db.delete({collection:t,id:n,tenantId:e.tenantId});if(r.hooks?.afterDelete)for(let u of r.hooks.afterDelete)await u({collection:t,doc:s,req:e.req,user:e.user,tenantId:e.tenantId,operation:"delete",id:n});return await q(e,R(t,"delete"),{collection:t,data:s,previousData:o,operation:"delete"}),{doc:s,message:"Deleted successfully"}}}function S(e){return async a=>{let{collection:t,where:n}=a,r=e.registry.getCollection(t);return await b(r,"read",e),{totalDocs:await e.db.count({collection:t,where:n||{},tenantId:e.tenantId})}}}chunkBUNLC3II_cjs.h();async function W(e,a,t){let n=await chunkSBNMXQNO_cjs.b(e,a,{user:t.user,req:t.req,tenantId:t.tenantId});if(!n.allowed)throw new Error(n.error||"Access denied");t.tenantId&&t.db.setTenantContext({tenantId:t.tenantId,userId:t.user?.id??"",role:t.user?.role,isSuperAdmin:t.user?.role==="super_admin"});}function O(e){let a={},t=e.registry.getCollections();for(let r of t){let o=r.slug;a[o]={find:P(e),findByID:v(e),create:K(e),update:E(e),delete:j(e),count:S(e)};}let n=e.registry.getGlobals();for(let r of n){let o=r.slug;a[`_globals_${o}`]={get:async s=>(await W(r,"read",e),await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId,depth:s?.depth,draft:s?.draft,select:s?.select})),update:async s=>{await W(r,"update",e);let i=e.registry.getZodSchema(o).parse(s.data),d=await e.db.findOne({collection:`_globals_${o}`,where:{},tenantId:e.tenantId,draft:true}),l;return d?l=await e.db.update({collection:`_globals_${o}`,id:d.id,data:i,tenantId:e.tenantId}):l=await e.db.create({collection:`_globals_${o}`,data:{...i,id:o},tenantId:e.tenantId}),l}};}return a}function L(e){if(e.settings?.access?.apiAccess?.trpcEnabled===false)throw new Error("tRPC API is disabled");return O(e)}exports.a=V;exports.b=P;exports.c=v;exports.d=K;exports.e=E;exports.f=j;exports.g=S;exports.h=O;exports.i=L;
|