@plyaz/types 1.25.0 → 1.25.2
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/dist/auth/enums.d.ts +51 -15
- package/dist/auth/index.cjs +22 -6
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.js +21 -7
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/types.d.ts +619 -2
- package/dist/index.cjs +22 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/payments/gateways/provider/fee/types.d.ts +56 -0
- package/dist/payments/gateways/provider/types.d.ts +87 -1
- package/dist/payments/provider/adapter/types.d.ts +3 -2
- package/dist/payments/provider/payment-provider/types.d.ts +3 -2
- package/dist/payments/transaction/types.d.ts +4 -0
- package/dist/storage/interfaces.d.ts +37 -0
- package/package.json +1 -1
package/dist/auth/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { WithExpiration, WithAuthTokens } from '../common/types';
|
|
2
|
+
import type { USER_ROLE_STATUS } from './enums';
|
|
2
3
|
/**
|
|
3
4
|
* AuthToken Interface.
|
|
4
5
|
* @description Represents an authentication token set returned after a successful login or refresh.
|
|
6
|
+
* @interface AuthToken
|
|
5
7
|
*/
|
|
6
8
|
export interface AuthToken extends WithExpiration, WithAuthTokens {
|
|
7
9
|
/**
|
|
@@ -10,22 +12,33 @@ export interface AuthToken extends WithExpiration, WithAuthTokens {
|
|
|
10
12
|
readonly tokenType: 'Bearer';
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
15
|
+
* AuthCredentials.
|
|
16
|
+
* @description Represents the credentials used for traditional email/password authentication.
|
|
14
17
|
* This is used for providers that handle this type of login directly.
|
|
15
18
|
*/
|
|
16
19
|
export type AuthCredentials = {
|
|
20
|
+
/** The user's email address. */
|
|
17
21
|
email: string;
|
|
22
|
+
/** The user's password (optional, used in traditional login flows). */
|
|
18
23
|
password?: string;
|
|
24
|
+
/**
|
|
25
|
+
* One-Time Password (OTP) or magic link token.
|
|
26
|
+
* This could be extended with other credential types as needed.
|
|
27
|
+
*/
|
|
19
28
|
otp?: string;
|
|
20
29
|
};
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
31
|
+
* UserContext.
|
|
32
|
+
* @description A standardized representation of a user's context.
|
|
23
33
|
* This ensures that regardless of the underlying authentication provider (Clerk, Supabase, etc.),
|
|
24
34
|
* your application's internal code can interact with a consistent user object.
|
|
25
35
|
*/
|
|
26
36
|
export type UserContext = {
|
|
37
|
+
/** A unique identifier for the user (e.g., a UUID from Supabase). */
|
|
27
38
|
id: string;
|
|
39
|
+
/** The user's primary email address. */
|
|
28
40
|
email: string;
|
|
41
|
+
/** Timestamp when the user was created. */
|
|
29
42
|
createdAt: Date;
|
|
30
43
|
};
|
|
31
44
|
/**
|
|
@@ -35,6 +48,8 @@ export type UserContext = {
|
|
|
35
48
|
*
|
|
36
49
|
* Any provider implementing this interface must handle user lookup, creation,
|
|
37
50
|
* and issuance of the necessary internal tokens (like the Supabase RLS JWT).
|
|
51
|
+
*
|
|
52
|
+
* @interface AuthServiceProvider
|
|
38
53
|
*/
|
|
39
54
|
export interface AuthServiceProvider {
|
|
40
55
|
/**
|
|
@@ -44,6 +59,7 @@ export interface AuthServiceProvider {
|
|
|
44
59
|
* an external provider to ensure the user exists in the local database,
|
|
45
60
|
* update their metadata, and issue an internal authorization token (e.g., RLS JWT).
|
|
46
61
|
*
|
|
62
|
+
* @param clerkJwt The JWT received from the external provider (e.g., Clerk).
|
|
47
63
|
* @param externalId The unique identifier from the external authentication provider (e.g., Clerk's 'sub').
|
|
48
64
|
* @param email The user's primary email address from the external provider.
|
|
49
65
|
* @returns A Promise resolving to an object containing the internal UserContext and the provider-specific RLS JWT.
|
|
@@ -62,3 +78,604 @@ export interface AuthServiceProvider {
|
|
|
62
78
|
*/
|
|
63
79
|
getUserById(userId: string): Promise<UserContext | null>;
|
|
64
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* B2C User Info (public schema).
|
|
83
|
+
* @description Represents platform users: fans, athletes, clubs, scouts, agents.
|
|
84
|
+
* * @interface UserInfo
|
|
85
|
+
* @property {string} id - Unique user identifier (UUID).
|
|
86
|
+
* @property {string} email - User email address (unique).
|
|
87
|
+
* @property {string} [clerkUserId] - Clerk provider user ID.
|
|
88
|
+
* @property {string} authProvider - Authentication provider used.
|
|
89
|
+
* @property {string} [firstName] - User first name.
|
|
90
|
+
* @property {string} [lastName] - User last name.
|
|
91
|
+
* @property {string} displayName - Display name (required).
|
|
92
|
+
* @property {string} [avatarUrl] - Avatar image URL.
|
|
93
|
+
* @property {string} [phoneNumber] - Phone number.
|
|
94
|
+
* @property {boolean} isActive - Account active status.
|
|
95
|
+
* @property {boolean} isVerified - Email verification status.
|
|
96
|
+
* @property {Date} createdAt - Account creation timestamp.
|
|
97
|
+
* @property {Date} updatedAt - Last update timestamp.
|
|
98
|
+
* @property {Date} [lastLoginAt] - Last login timestamp.
|
|
99
|
+
*/
|
|
100
|
+
export interface UserInfo {
|
|
101
|
+
id: string;
|
|
102
|
+
email: string;
|
|
103
|
+
clerkUserId?: string;
|
|
104
|
+
authProvider: string;
|
|
105
|
+
firstName?: string;
|
|
106
|
+
lastName?: string;
|
|
107
|
+
displayName: string;
|
|
108
|
+
avatarUrl?: string;
|
|
109
|
+
phoneNumber?: string;
|
|
110
|
+
isActive: boolean;
|
|
111
|
+
isVerified: boolean;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
lastLoginAt?: Date;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* B2B User (backoffice schema).
|
|
118
|
+
* @description Represents internal staff: admins, moderators, support, finance, compliance.
|
|
119
|
+
* * @interface BackofficeUser
|
|
120
|
+
* @property {string} id - Unique user identifier (UUID).
|
|
121
|
+
* @property {string} email - User email address (unique).
|
|
122
|
+
* @property {string} passwordHash - Hashed password.
|
|
123
|
+
* @property {string} [clerkUserId] - Clerk provider user ID.
|
|
124
|
+
* @property {string} authProvider - Authentication provider used.
|
|
125
|
+
* @property {string} [firstName] - User first name.
|
|
126
|
+
* @property {string} [lastName] - User last name.
|
|
127
|
+
* @property {string} displayName - Display name (required).
|
|
128
|
+
* @property {string} [avatarUrl] - Avatar image URL.
|
|
129
|
+
* @property {string} [phoneNumber] - Phone number.
|
|
130
|
+
* @property {boolean} isActive - Account active status.
|
|
131
|
+
* @property {boolean} isVerified - Email verification status.
|
|
132
|
+
* @property {boolean} isSuspended - Account suspension status.
|
|
133
|
+
* @property {string} [suspensionReason] - Reason for suspension.
|
|
134
|
+
* @property {Date} [suspendedAt] - Suspension timestamp.
|
|
135
|
+
* @property {Date} createdAt - Account creation timestamp.
|
|
136
|
+
* @property {Date} updatedAt - Last update timestamp.
|
|
137
|
+
* @property {Date} [lastLoginAt] - Last login timestamp.
|
|
138
|
+
*/
|
|
139
|
+
export interface BackofficeUser {
|
|
140
|
+
id: string;
|
|
141
|
+
email: string;
|
|
142
|
+
passwordHash: string;
|
|
143
|
+
clerkUserId?: string;
|
|
144
|
+
authProvider: string;
|
|
145
|
+
firstName?: string;
|
|
146
|
+
lastName?: string;
|
|
147
|
+
displayName: string;
|
|
148
|
+
avatarUrl?: string;
|
|
149
|
+
phoneNumber?: string;
|
|
150
|
+
isActive: boolean;
|
|
151
|
+
isVerified: boolean;
|
|
152
|
+
isSuspended: boolean;
|
|
153
|
+
suspensionReason?: string;
|
|
154
|
+
suspendedAt?: Date;
|
|
155
|
+
createdAt: Date;
|
|
156
|
+
updatedAt: Date;
|
|
157
|
+
lastLoginAt?: Date;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* B2C Session (public schema).
|
|
161
|
+
* @description Tracks authenticated user sessions with device and activity info.
|
|
162
|
+
* * @interface Session
|
|
163
|
+
* @property {string} id - Unique session identifier.
|
|
164
|
+
* @property {string} userId - ID of the user owning the session.
|
|
165
|
+
* @property {string} provider - Authentication provider used.
|
|
166
|
+
* @property {string} [providerSessionId] - External provider's session ID (if applicable).
|
|
167
|
+
* @property {Date} expiresAt - Session expiration timestamp.
|
|
168
|
+
* @property {Date} createdAt - Session creation timestamp.
|
|
169
|
+
* @property {Date} lastActivityAt - Last activity timestamp for the session.
|
|
170
|
+
* @property {string} [ipAddress] - IP address used when the session was created/last used.
|
|
171
|
+
* @property {string} [userAgent] - User agent string of the client.
|
|
172
|
+
* @property {Record<string, unknown>} [metadata] - Arbitrary metadata related to the session.
|
|
173
|
+
*/
|
|
174
|
+
export interface Session {
|
|
175
|
+
id: string;
|
|
176
|
+
userId: string;
|
|
177
|
+
provider: string;
|
|
178
|
+
providerSessionId?: string;
|
|
179
|
+
expiresAt: Date;
|
|
180
|
+
createdAt: Date;
|
|
181
|
+
lastActivityAt: Date;
|
|
182
|
+
ipAddress?: string;
|
|
183
|
+
userAgent?: string;
|
|
184
|
+
metadata?: Record<string, unknown>;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* B2B Session (backoffice schema).
|
|
188
|
+
* @description Tracks authenticated backoffice user sessions.
|
|
189
|
+
* * @interface BackofficeSession
|
|
190
|
+
* @property {string} id - Unique session identifier.
|
|
191
|
+
* @property {string} backofficeUserId - ID of the backoffice user owning the session.
|
|
192
|
+
* @property {string} provider - Authentication provider used.
|
|
193
|
+
* @property {string} [providerSessionId] - External provider's session ID (if applicable).
|
|
194
|
+
* @property {Date} expiresAt - Session expiration timestamp.
|
|
195
|
+
* @property {Date} createdAt - Session creation timestamp.
|
|
196
|
+
* @property {Date} lastActivityAt - Last activity timestamp for the session.
|
|
197
|
+
* @property {string} [ipAddress] - IP address used when the session was created/last used.
|
|
198
|
+
* @property {string} [userAgent] - User agent string of the client.
|
|
199
|
+
* @property {Record<string, unknown>} [metadata] - Arbitrary metadata related to the session.
|
|
200
|
+
*/
|
|
201
|
+
export interface BackofficeSession {
|
|
202
|
+
id: string;
|
|
203
|
+
backofficeUserId: string;
|
|
204
|
+
provider: string;
|
|
205
|
+
providerSessionId?: string;
|
|
206
|
+
expiresAt: Date;
|
|
207
|
+
createdAt: Date;
|
|
208
|
+
lastActivityAt: Date;
|
|
209
|
+
ipAddress?: string;
|
|
210
|
+
userAgent?: string;
|
|
211
|
+
metadata?: Record<string, unknown>;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Connected Account (provider linking).
|
|
215
|
+
* @description Links external OAuth/Web3 provider accounts to users.
|
|
216
|
+
* Supports OAuth providers (Clerk, Google, etc.) and Web3 wallets.
|
|
217
|
+
* * @interface ConnectedAccount
|
|
218
|
+
* @property {string} id - Unique connected account identifier.
|
|
219
|
+
* @property {string} userId - ID of the internal user account.
|
|
220
|
+
* @property {string} providerType - Category of the provider (e.g., 'oauth', 'web3').
|
|
221
|
+
* @property {string} provider - Specific provider name (e.g., 'google', 'metamask').
|
|
222
|
+
* @property {string} providerAccountId - Unique ID from the external provider.
|
|
223
|
+
* @property {string} [walletAddress] - Wallet address for Web3 accounts.
|
|
224
|
+
* @property {string} [accessTokenEncrypted] - Encrypted access token for the provider.
|
|
225
|
+
* @property {boolean} isPrimary - Flag indicating if this is the user's primary login account.
|
|
226
|
+
* @property {Date} linkedAt - Timestamp when the account was linked.
|
|
227
|
+
*/
|
|
228
|
+
export interface ConnectedAccount {
|
|
229
|
+
id: string;
|
|
230
|
+
userId: string;
|
|
231
|
+
providerType: string;
|
|
232
|
+
provider: string;
|
|
233
|
+
providerAccountId: string;
|
|
234
|
+
providerEmail?: string;
|
|
235
|
+
providerUsername?: string;
|
|
236
|
+
providerDisplayName?: string;
|
|
237
|
+
providerAvatarUrl?: string;
|
|
238
|
+
providerProfileUrl?: string;
|
|
239
|
+
providerMetadata?: Record<string, unknown>;
|
|
240
|
+
walletAddress?: string;
|
|
241
|
+
chainId?: string;
|
|
242
|
+
accessTokenEncrypted?: string;
|
|
243
|
+
refreshTokenEncrypted?: string;
|
|
244
|
+
tokenExpiresAt?: Date;
|
|
245
|
+
tokenScope?: string;
|
|
246
|
+
isPrimary: boolean;
|
|
247
|
+
isVerified: boolean;
|
|
248
|
+
isActive: boolean;
|
|
249
|
+
linkedAt: Date;
|
|
250
|
+
linkedIpAddress?: string;
|
|
251
|
+
linkedUserAgent?: string;
|
|
252
|
+
lastUsedAt?: Date;
|
|
253
|
+
lastUsedIpAddress?: string;
|
|
254
|
+
createdAt: Date;
|
|
255
|
+
updatedAt: Date;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Authentication tokens returned after successful login.
|
|
259
|
+
* * @interface AuthTokens
|
|
260
|
+
* @property {string} accessToken - The main access token (JWT or similar).
|
|
261
|
+
* @property {string} [refreshToken] - Token used to refresh the access token.
|
|
262
|
+
* @property {number} expiresIn - Access token expiration time in seconds.
|
|
263
|
+
* @property {string} tokenType - Type of the token, usually 'Bearer'.
|
|
264
|
+
*/
|
|
265
|
+
export interface AuthTokens {
|
|
266
|
+
accessToken: string;
|
|
267
|
+
refreshToken?: string;
|
|
268
|
+
expiresIn: number;
|
|
269
|
+
tokenType: string;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* B2C Role (public schema).
|
|
273
|
+
* @description Defines user roles: FAN, ATHLETE, SCOUT, AGENT, CLUB, DEVELOPER, ADMIN.
|
|
274
|
+
* * @interface Role
|
|
275
|
+
* @property {string} id - Unique role identifier.
|
|
276
|
+
* @property {string} code - Machine-readable role code (e.g., 'ATHLETE').
|
|
277
|
+
* @property {string} name - Human-readable role name.
|
|
278
|
+
* @property {number} hierarchy - Numeric value for role hierarchy/priority.
|
|
279
|
+
* @property {boolean} isSystem - True if the role is system-defined and cannot be deleted.
|
|
280
|
+
*/
|
|
281
|
+
export interface Role {
|
|
282
|
+
id: string;
|
|
283
|
+
code: string;
|
|
284
|
+
name: string;
|
|
285
|
+
description?: string;
|
|
286
|
+
hierarchy: number;
|
|
287
|
+
canCreateCampaigns?: boolean;
|
|
288
|
+
canContribute?: boolean;
|
|
289
|
+
requiresKyc?: boolean;
|
|
290
|
+
isActive: boolean;
|
|
291
|
+
isSystem: boolean;
|
|
292
|
+
metadata?: Record<string, unknown>;
|
|
293
|
+
createdAt: Date;
|
|
294
|
+
updatedAt: Date;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* B2B Role (backoffice schema).
|
|
298
|
+
* @description Defines staff roles: SUPER_ADMIN, ADMIN, MODERATOR, FINANCE, COMPLIANCE, SUPPORT.
|
|
299
|
+
* * @interface BackofficeRole
|
|
300
|
+
* @property {string} id - Unique role identifier.
|
|
301
|
+
* @property {string} code - Machine-readable role code (e.g., 'SUPER_ADMIN').
|
|
302
|
+
* @property {string} name - Human-readable role name.
|
|
303
|
+
* @property {number} hierarchy - Numeric value for role hierarchy/priority.
|
|
304
|
+
* @property {boolean} canManageUsers - Permission to manage user accounts.
|
|
305
|
+
* @property {boolean} canViewAllData - Permission to view all data regardless of ownership.
|
|
306
|
+
*/
|
|
307
|
+
export interface BackofficeRole {
|
|
308
|
+
id: string;
|
|
309
|
+
code: string;
|
|
310
|
+
name: string;
|
|
311
|
+
description?: string;
|
|
312
|
+
hierarchy: number;
|
|
313
|
+
canApproveCampaigns: boolean;
|
|
314
|
+
canApproveKyc: boolean;
|
|
315
|
+
canApprovePayouts: boolean;
|
|
316
|
+
canManageUsers: boolean;
|
|
317
|
+
canManageRoles: boolean;
|
|
318
|
+
canViewAllData: boolean;
|
|
319
|
+
isActive: boolean;
|
|
320
|
+
isSystem: boolean;
|
|
321
|
+
metadata?: Record<string, unknown>;
|
|
322
|
+
createdAt: Date;
|
|
323
|
+
updatedAt: Date;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Permission (backoffice only).
|
|
327
|
+
* @description Fine-grained permissions for backoffice users.
|
|
328
|
+
* * @interface Permission
|
|
329
|
+
* @property {string} id - Unique permission identifier.
|
|
330
|
+
* @property {string} code - Machine-readable permission code (e.g., 'USER_READ').
|
|
331
|
+
* @property {string} resource - The resource the permission applies to (e.g., 'USER', 'CAMPAIGN').
|
|
332
|
+
* @property {string} action - The action the permission allows (e.g., 'READ', 'DELETE').
|
|
333
|
+
*/
|
|
334
|
+
export interface Permission {
|
|
335
|
+
id: string;
|
|
336
|
+
code: string;
|
|
337
|
+
name: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
resource: string;
|
|
340
|
+
action: string;
|
|
341
|
+
isActive: boolean;
|
|
342
|
+
isSystem: boolean;
|
|
343
|
+
metadata?: Record<string, unknown>;
|
|
344
|
+
createdAt: Date;
|
|
345
|
+
updatedAt: Date;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Role-Permission mapping (backoffice only).
|
|
349
|
+
* @description Links permissions to roles.
|
|
350
|
+
* * @interface RolePermission
|
|
351
|
+
* @property {string} id - Unique mapping identifier.
|
|
352
|
+
* @property {string} roleId - ID of the role.
|
|
353
|
+
* @property {string} permissionId - ID of the permission granted.
|
|
354
|
+
* @property {Date} grantedAt - Timestamp when the permission was assigned to the role.
|
|
355
|
+
*/
|
|
356
|
+
export interface RolePermission {
|
|
357
|
+
id: string;
|
|
358
|
+
roleId: string;
|
|
359
|
+
role: string;
|
|
360
|
+
permissionId: string;
|
|
361
|
+
grantedAt: Date;
|
|
362
|
+
grantedBy?: string;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* User-Permission mapping (backoffice only).
|
|
366
|
+
* @description Grants/revokes specific permissions to users, overriding role permissions.
|
|
367
|
+
* * @interface UserPermission
|
|
368
|
+
* @property {string} id - Unique mapping identifier.
|
|
369
|
+
* @property {string} backofficeUserId - ID of the backoffice user.
|
|
370
|
+
* @property {string} permissionId - ID of the permission.
|
|
371
|
+
* @property {boolean} isGranted - True to grant, false to explicitly revoke.
|
|
372
|
+
*/
|
|
373
|
+
export interface UserPermission {
|
|
374
|
+
id: string;
|
|
375
|
+
backofficeUserId: string;
|
|
376
|
+
permissionId: string;
|
|
377
|
+
isGranted: boolean;
|
|
378
|
+
expiresAt?: Date;
|
|
379
|
+
grantedAt: Date;
|
|
380
|
+
grantedBy?: string;
|
|
381
|
+
reason?: string;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* B2C User-Role assignment.
|
|
385
|
+
* @description Links users to roles with status tracking.
|
|
386
|
+
* * @interface UserRole
|
|
387
|
+
* @property {string} userId - ID of the B2C user.
|
|
388
|
+
* @property {string} roleId - ID of the role assigned.
|
|
389
|
+
* @property {boolean} isPrimary - True if this is the user's main, active role.
|
|
390
|
+
* @property {USER_ROLE_STATUS} status - Current status of the role assignment (e.g., ACTIVE, PENDING).
|
|
391
|
+
*/
|
|
392
|
+
export interface UserRole {
|
|
393
|
+
id: string;
|
|
394
|
+
userId: string;
|
|
395
|
+
roleId: string;
|
|
396
|
+
role: string;
|
|
397
|
+
isPrimary: boolean;
|
|
398
|
+
status: USER_ROLE_STATUS;
|
|
399
|
+
assignedBy?: string;
|
|
400
|
+
assignedReason?: string;
|
|
401
|
+
expiresAt?: Date;
|
|
402
|
+
createdAt: Date;
|
|
403
|
+
updatedAt: Date;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* B2B User-Role assignment.
|
|
407
|
+
* @description Links backoffice users to roles.
|
|
408
|
+
* * @interface BackofficeUserRole
|
|
409
|
+
* @property {string} backofficeUserId - ID of the backoffice user.
|
|
410
|
+
* @property {string} roleId - ID of the role assigned.
|
|
411
|
+
* @property {boolean} isPrimary - True if this is the user's main, active role.
|
|
412
|
+
* @property {USER_ROLE_STATUS} status - Current status of the role assignment.
|
|
413
|
+
*/
|
|
414
|
+
export interface BackofficeUserRole {
|
|
415
|
+
id: string;
|
|
416
|
+
backofficeUserId: string;
|
|
417
|
+
roleId: string;
|
|
418
|
+
role: string;
|
|
419
|
+
isPrimary: boolean;
|
|
420
|
+
status: USER_ROLE_STATUS;
|
|
421
|
+
assignedBy?: string;
|
|
422
|
+
assignedReason?: string;
|
|
423
|
+
expiresAt?: Date;
|
|
424
|
+
createdAt: Date;
|
|
425
|
+
updatedAt: Date;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Authentication provider adapter interface.
|
|
429
|
+
* @description Defines contract for provider-agnostic authentication interactions.
|
|
430
|
+
* * @interface AuthProviderAdapter
|
|
431
|
+
* @property {string} name - The name of the authentication provider (e.g., 'clerk', 'auth0').
|
|
432
|
+
*/
|
|
433
|
+
export interface AuthProviderAdapter {
|
|
434
|
+
name: string;
|
|
435
|
+
/**
|
|
436
|
+
* Verifies an external authentication token (e.g., a JWT).
|
|
437
|
+
* @param token The token to verify.
|
|
438
|
+
* @returns A Promise resolving to the verified token result.
|
|
439
|
+
*/
|
|
440
|
+
verifyToken(token: string): Promise<VerifiedToken>;
|
|
441
|
+
/**
|
|
442
|
+
* Retrieves user profile information from the external provider using a token.
|
|
443
|
+
* @param token The access token.
|
|
444
|
+
* @returns A Promise resolving to the provider's user information.
|
|
445
|
+
*/
|
|
446
|
+
getUserInfo(token: string): Promise<ProviderUserInfo>;
|
|
447
|
+
/**
|
|
448
|
+
* Refreshes an expired access token using a refresh token (optional method).
|
|
449
|
+
* @param refreshToken The token used for refreshing.
|
|
450
|
+
* @returns A Promise resolving to a new set of authentication tokens.
|
|
451
|
+
*/
|
|
452
|
+
refreshToken?(refreshToken: string): Promise<AuthTokens>;
|
|
453
|
+
/**
|
|
454
|
+
* Invalidates a token on the provider's side (e.g., logout, optional method).
|
|
455
|
+
* @param token The token to revoke.
|
|
456
|
+
* @returns A Promise that resolves when the token is successfully revoked.
|
|
457
|
+
*/
|
|
458
|
+
revokeToken?(token: string): Promise<void>;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Verified token result.
|
|
462
|
+
* @description Data returned after successful token verification.
|
|
463
|
+
* * @interface VerifiedToken
|
|
464
|
+
* @property {string} userId - The user's ID from the external provider.
|
|
465
|
+
* @property {string} provider - The name of the provider.
|
|
466
|
+
* @property {string} providerAccountId - The provider's unique account ID.
|
|
467
|
+
*/
|
|
468
|
+
export interface VerifiedToken {
|
|
469
|
+
userId: string;
|
|
470
|
+
provider: string;
|
|
471
|
+
providerAccountId: string;
|
|
472
|
+
email?: string;
|
|
473
|
+
expiresAt?: Date;
|
|
474
|
+
metadata?: Record<string, unknown>;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Provider user information.
|
|
478
|
+
* @description User profile data fetched from an external provider.
|
|
479
|
+
* * @interface ProviderUserInfo
|
|
480
|
+
* @property {string} providerAccountId - Unique ID from the external provider.
|
|
481
|
+
* @property {string} [email] - The user's email address from the provider.
|
|
482
|
+
*/
|
|
483
|
+
export interface ProviderUserInfo {
|
|
484
|
+
providerAccountId: string;
|
|
485
|
+
email?: string;
|
|
486
|
+
displayName?: string;
|
|
487
|
+
firstName?: string;
|
|
488
|
+
lastName?: string;
|
|
489
|
+
avatarUrl?: string;
|
|
490
|
+
phoneNumber?: string;
|
|
491
|
+
metadata?: Record<string, unknown>;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* User repository interface.
|
|
495
|
+
* @description Defines data access methods for B2C user management.
|
|
496
|
+
* * @interface UserRepositoryInterface
|
|
497
|
+
*/
|
|
498
|
+
export interface UserRepositoryInterface {
|
|
499
|
+
/** Find a user by their internal ID. */
|
|
500
|
+
findById(id: string): Promise<UserInfo | null>;
|
|
501
|
+
/** Find a user by their primary email address. */
|
|
502
|
+
findByEmail(email: string): Promise<UserInfo | null>;
|
|
503
|
+
/** Find a user linked to a specific external provider account. */
|
|
504
|
+
findByProviderAccount(provider: string, providerAccountId: string): Promise<UserInfo | null>;
|
|
505
|
+
/** Create a new user record. */
|
|
506
|
+
create(data: CreateUserData): Promise<UserInfo>;
|
|
507
|
+
/** Update an existing user record. */
|
|
508
|
+
update(id: string, data: UpdateUserData): Promise<UserInfo>;
|
|
509
|
+
/** Delete a user record. */
|
|
510
|
+
delete(id: string): Promise<void>;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Session repository interface.
|
|
514
|
+
* @description Defines data access methods for B2C session management.
|
|
515
|
+
* * @interface SessionRepositoryInterface
|
|
516
|
+
*/
|
|
517
|
+
export interface SessionRepositoryInterface {
|
|
518
|
+
/** Create a new session record. */
|
|
519
|
+
create(data: CreateSessionData): Promise<Session>;
|
|
520
|
+
/** Find a session by its ID. */
|
|
521
|
+
findById(id: string): Promise<Session | null>;
|
|
522
|
+
/** Find all active sessions for a given user ID. */
|
|
523
|
+
findByUserId(userId: string): Promise<Session[]>;
|
|
524
|
+
/** Validate if a session ID is current and not expired. */
|
|
525
|
+
validate(sessionId: string): Promise<Session | null>;
|
|
526
|
+
/** Invalidate (log out) a specific session. */
|
|
527
|
+
invalidate(sessionId: string): Promise<void>;
|
|
528
|
+
/** Invalidate (log out) all sessions for a user. */
|
|
529
|
+
invalidateAllForUser(userId: string): Promise<void>;
|
|
530
|
+
/** Update the last activity timestamp for a session. */
|
|
531
|
+
updateActivity(sessionId: string): Promise<void>;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Connected account repository interface.
|
|
535
|
+
* @description Defines data access methods for provider account linking.
|
|
536
|
+
* * @interface ConnectedAccountRepositoryInterface
|
|
537
|
+
*/
|
|
538
|
+
export interface ConnectedAccountRepositoryInterface {
|
|
539
|
+
/** Create a new connected account link. */
|
|
540
|
+
create(data: CreateConnectedAccountData): Promise<ConnectedAccount>;
|
|
541
|
+
/** Find a connected account by its internal ID. */
|
|
542
|
+
findById(id: string): Promise<ConnectedAccount | null>;
|
|
543
|
+
/** Find all connected accounts linked to a user. */
|
|
544
|
+
findByUserId(userId: string): Promise<ConnectedAccount[]>;
|
|
545
|
+
/** Find a connected account by provider and account ID. */
|
|
546
|
+
findByProvider(provider: string, providerAccountId: string): Promise<ConnectedAccount | null>;
|
|
547
|
+
/** Update an existing connected account record. */
|
|
548
|
+
update(id: string, data: UpdateConnectedAccountData): Promise<ConnectedAccount>;
|
|
549
|
+
/** Delete a connected account link. */
|
|
550
|
+
delete(id: string): Promise<void>;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* DTO for creating B2C users.
|
|
554
|
+
* @interface CreateUserData
|
|
555
|
+
*/
|
|
556
|
+
export interface CreateUserData {
|
|
557
|
+
email: string;
|
|
558
|
+
clerkUserId?: string;
|
|
559
|
+
authProvider?: string;
|
|
560
|
+
firstName?: string;
|
|
561
|
+
lastName?: string;
|
|
562
|
+
displayName: string;
|
|
563
|
+
avatarUrl?: string;
|
|
564
|
+
phoneNumber?: string;
|
|
565
|
+
isVerified?: boolean;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* DTO for creating B2B users.
|
|
569
|
+
* @interface CreateBackofficeUserData
|
|
570
|
+
*/
|
|
571
|
+
export interface CreateBackofficeUserData {
|
|
572
|
+
email: string;
|
|
573
|
+
passwordHash: string;
|
|
574
|
+
clerkUserId?: string;
|
|
575
|
+
authProvider?: string;
|
|
576
|
+
firstName?: string;
|
|
577
|
+
lastName?: string;
|
|
578
|
+
displayName: string;
|
|
579
|
+
avatarUrl?: string;
|
|
580
|
+
phoneNumber?: string;
|
|
581
|
+
isVerified?: boolean;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* DTO for updating B2C users.
|
|
585
|
+
* @interface UpdateUserData
|
|
586
|
+
*/
|
|
587
|
+
export interface UpdateUserData {
|
|
588
|
+
email?: string;
|
|
589
|
+
clerkUserId?: string;
|
|
590
|
+
authProvider?: string;
|
|
591
|
+
firstName?: string;
|
|
592
|
+
lastName?: string;
|
|
593
|
+
displayName?: string;
|
|
594
|
+
avatarUrl?: string;
|
|
595
|
+
phoneNumber?: string;
|
|
596
|
+
isActive?: boolean;
|
|
597
|
+
isVerified?: boolean;
|
|
598
|
+
lastLoginAt?: Date;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* DTO for updating B2B users.
|
|
602
|
+
* @interface UpdateBackofficeUserData
|
|
603
|
+
*/
|
|
604
|
+
export interface UpdateBackofficeUserData {
|
|
605
|
+
email?: string;
|
|
606
|
+
passwordHash?: string;
|
|
607
|
+
clerkUserId?: string;
|
|
608
|
+
authProvider?: string;
|
|
609
|
+
firstName?: string;
|
|
610
|
+
lastName?: string;
|
|
611
|
+
displayName?: string;
|
|
612
|
+
avatarUrl?: string;
|
|
613
|
+
phoneNumber?: string;
|
|
614
|
+
isActive?: boolean;
|
|
615
|
+
isVerified?: boolean;
|
|
616
|
+
isSuspended?: boolean;
|
|
617
|
+
suspensionReason?: string;
|
|
618
|
+
suspendedAt?: Date;
|
|
619
|
+
lastLoginAt?: Date;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* DTO for creating sessions.
|
|
623
|
+
* @interface CreateSessionData
|
|
624
|
+
*/
|
|
625
|
+
export interface CreateSessionData {
|
|
626
|
+
userId: string;
|
|
627
|
+
provider: string;
|
|
628
|
+
providerSessionId?: string;
|
|
629
|
+
expiresAt: Date;
|
|
630
|
+
ipAddress?: string;
|
|
631
|
+
userAgent?: string;
|
|
632
|
+
metadata?: Record<string, unknown>;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* DTO for creating connected accounts.
|
|
636
|
+
* @interface CreateConnectedAccountData
|
|
637
|
+
*/
|
|
638
|
+
export interface CreateConnectedAccountData {
|
|
639
|
+
userId: string;
|
|
640
|
+
providerType: string;
|
|
641
|
+
provider: string;
|
|
642
|
+
providerAccountId: string;
|
|
643
|
+
providerEmail?: string;
|
|
644
|
+
providerUsername?: string;
|
|
645
|
+
providerDisplayName?: string;
|
|
646
|
+
providerAvatarUrl?: string;
|
|
647
|
+
providerProfileUrl?: string;
|
|
648
|
+
providerMetadata?: Record<string, unknown>;
|
|
649
|
+
walletAddress?: string;
|
|
650
|
+
chainId?: string;
|
|
651
|
+
accessTokenEncrypted?: string;
|
|
652
|
+
refreshTokenEncrypted?: string;
|
|
653
|
+
tokenExpiresAt?: Date;
|
|
654
|
+
tokenScope?: string;
|
|
655
|
+
isPrimary?: boolean;
|
|
656
|
+
isVerified?: boolean;
|
|
657
|
+
isActive?: boolean;
|
|
658
|
+
linkedIpAddress?: string;
|
|
659
|
+
linkedUserAgent?: string;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* DTO for updating connected accounts.
|
|
663
|
+
* @interface UpdateConnectedAccountData
|
|
664
|
+
*/
|
|
665
|
+
export interface UpdateConnectedAccountData {
|
|
666
|
+
providerEmail?: string;
|
|
667
|
+
providerUsername?: string;
|
|
668
|
+
providerDisplayName?: string;
|
|
669
|
+
providerAvatarUrl?: string;
|
|
670
|
+
providerProfileUrl?: string;
|
|
671
|
+
providerMetadata?: Record<string, unknown>;
|
|
672
|
+
accessTokenEncrypted?: string;
|
|
673
|
+
refreshTokenEncrypted?: string;
|
|
674
|
+
tokenExpiresAt?: Date;
|
|
675
|
+
tokenScope?: string;
|
|
676
|
+
isPrimary?: boolean;
|
|
677
|
+
isVerified?: boolean;
|
|
678
|
+
isActive?: boolean;
|
|
679
|
+
lastUsedAt?: Date;
|
|
680
|
+
lastUsedIpAddress?: string;
|
|
681
|
+
}
|