@baasix/types 1.0.10 → 1.0.11
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/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/package.json +1 -1
- package/src/auth.ts +289 -285
package/dist/index.d.mts
CHANGED
|
@@ -125,6 +125,8 @@ interface JWTPayload {
|
|
|
125
125
|
role: string;
|
|
126
126
|
sessionToken: string;
|
|
127
127
|
tenant_Id?: string | number | null;
|
|
128
|
+
/** Pinned baasix_UserRole row id (assignment switching). Absent on legacy tokens. */
|
|
129
|
+
userRole_Id?: string | null;
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* Accountability object interface - used for permission checking
|
|
@@ -141,6 +143,8 @@ interface Accountability {
|
|
|
141
143
|
name?: string;
|
|
142
144
|
isTenantSpecific?: boolean;
|
|
143
145
|
} | string | number;
|
|
146
|
+
/** Full active baasix_UserRole row (assignment) — custom columns included. */
|
|
147
|
+
userRole?: Record<string, any>;
|
|
144
148
|
permissions?: any[];
|
|
145
149
|
tenant?: string | number;
|
|
146
150
|
ipaddress?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,8 @@ interface JWTPayload {
|
|
|
125
125
|
role: string;
|
|
126
126
|
sessionToken: string;
|
|
127
127
|
tenant_Id?: string | number | null;
|
|
128
|
+
/** Pinned baasix_UserRole row id (assignment switching). Absent on legacy tokens. */
|
|
129
|
+
userRole_Id?: string | null;
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* Accountability object interface - used for permission checking
|
|
@@ -141,6 +143,8 @@ interface Accountability {
|
|
|
141
143
|
name?: string;
|
|
142
144
|
isTenantSpecific?: boolean;
|
|
143
145
|
} | string | number;
|
|
146
|
+
/** Full active baasix_UserRole row (assignment) — custom columns included. */
|
|
147
|
+
userRole?: Record<string, any>;
|
|
144
148
|
permissions?: any[];
|
|
145
149
|
tenant?: string | number;
|
|
146
150
|
ipaddress?: string;
|
package/package.json
CHANGED
package/src/auth.ts
CHANGED
|
@@ -1,285 +1,289 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication & Authorization Types
|
|
3
|
-
* Shared across core, sdk, cli, and app packages
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// User Types
|
|
8
|
-
// ============================================================================
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base user interface
|
|
12
|
-
*/
|
|
13
|
-
export interface User {
|
|
14
|
-
id: string;
|
|
15
|
-
email: string;
|
|
16
|
-
firstName?: string;
|
|
17
|
-
lastName?: string;
|
|
18
|
-
avatar?: string;
|
|
19
|
-
role?: Role;
|
|
20
|
-
role_Id?: string;
|
|
21
|
-
tenant_Id?: string;
|
|
22
|
-
status?: string;
|
|
23
|
-
createdAt?: string;
|
|
24
|
-
updatedAt?: string;
|
|
25
|
-
[key: string]: unknown;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* User with password (internal use only)
|
|
30
|
-
*/
|
|
31
|
-
export interface UserWithPassword extends User {
|
|
32
|
-
password?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* User with expanded roles and permissions
|
|
37
|
-
*/
|
|
38
|
-
export interface UserWithRolesAndPermissions {
|
|
39
|
-
id: string | number;
|
|
40
|
-
email?: string;
|
|
41
|
-
roles: string[];
|
|
42
|
-
permissions: string[];
|
|
43
|
-
tenantId?: string | number;
|
|
44
|
-
[key: string]: unknown;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// ============================================================================
|
|
48
|
-
// Role & Permission Types
|
|
49
|
-
// ============================================================================
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Role interface
|
|
53
|
-
*/
|
|
54
|
-
export interface Role {
|
|
55
|
-
id: string;
|
|
56
|
-
name: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
isTenantSpecific?: boolean;
|
|
59
|
-
[key: string]: unknown;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Permission action types
|
|
64
|
-
*/
|
|
65
|
-
export type PermissionAction = "create" | "read" | "update" | "delete";
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Permission interface
|
|
69
|
-
*/
|
|
70
|
-
export interface Permission {
|
|
71
|
-
id: string;
|
|
72
|
-
role_Id: string;
|
|
73
|
-
collection: string;
|
|
74
|
-
action: PermissionAction;
|
|
75
|
-
fields?: string[] | null;
|
|
76
|
-
conditions?: Record<string, unknown>;
|
|
77
|
-
defaultValues?: Record<string, unknown>;
|
|
78
|
-
relConditions?: Record<string, unknown>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Permission data structure (internal to PermissionService)
|
|
83
|
-
*/
|
|
84
|
-
export interface PermissionData {
|
|
85
|
-
fields: string[] | null;
|
|
86
|
-
conditions: Record<string, unknown>;
|
|
87
|
-
relConditions: Record<string, unknown>;
|
|
88
|
-
defaultValues: Record<string, unknown>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Data for creating a new permission
|
|
93
|
-
*/
|
|
94
|
-
export interface CreatePermissionData {
|
|
95
|
-
role_Id: string;
|
|
96
|
-
collection: string;
|
|
97
|
-
action: PermissionAction;
|
|
98
|
-
fields?: string[];
|
|
99
|
-
conditions?: Record<string, unknown>;
|
|
100
|
-
defaultValues?: Record<string, unknown>;
|
|
101
|
-
relConditions?: Record<string, unknown>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// ============================================================================
|
|
105
|
-
// Tenant Types
|
|
106
|
-
// ============================================================================
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Tenant interface
|
|
110
|
-
*/
|
|
111
|
-
export interface Tenant {
|
|
112
|
-
id: string;
|
|
113
|
-
name: string;
|
|
114
|
-
[key: string]: unknown;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// ============================================================================
|
|
118
|
-
// Session & Token Types
|
|
119
|
-
// ============================================================================
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Session interface
|
|
123
|
-
*/
|
|
124
|
-
export interface Session {
|
|
125
|
-
id: string;
|
|
126
|
-
token: string;
|
|
127
|
-
user_Id: string;
|
|
128
|
-
expiresAt: Date | string;
|
|
129
|
-
ipAddress?: string;
|
|
130
|
-
userAgent?: string;
|
|
131
|
-
createdAt?: string;
|
|
132
|
-
updatedAt?: string;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Auth tokens
|
|
137
|
-
*/
|
|
138
|
-
export interface AuthTokens {
|
|
139
|
-
accessToken: string;
|
|
140
|
-
refreshToken?: string;
|
|
141
|
-
expiresAt?: number;
|
|
142
|
-
expiresIn?: number;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* JWT payload interface
|
|
147
|
-
*/
|
|
148
|
-
export interface JWTPayload {
|
|
149
|
-
id: string;
|
|
150
|
-
email: string;
|
|
151
|
-
role: string;
|
|
152
|
-
sessionToken: string;
|
|
153
|
-
tenant_Id?: string | number | null;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// ============================================================================
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
| "
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Authentication & Authorization Types
|
|
3
|
+
* Shared across core, sdk, cli, and app packages
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// User Types
|
|
8
|
+
// ============================================================================
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base user interface
|
|
12
|
+
*/
|
|
13
|
+
export interface User {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
firstName?: string;
|
|
17
|
+
lastName?: string;
|
|
18
|
+
avatar?: string;
|
|
19
|
+
role?: Role;
|
|
20
|
+
role_Id?: string;
|
|
21
|
+
tenant_Id?: string;
|
|
22
|
+
status?: string;
|
|
23
|
+
createdAt?: string;
|
|
24
|
+
updatedAt?: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* User with password (internal use only)
|
|
30
|
+
*/
|
|
31
|
+
export interface UserWithPassword extends User {
|
|
32
|
+
password?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* User with expanded roles and permissions
|
|
37
|
+
*/
|
|
38
|
+
export interface UserWithRolesAndPermissions {
|
|
39
|
+
id: string | number;
|
|
40
|
+
email?: string;
|
|
41
|
+
roles: string[];
|
|
42
|
+
permissions: string[];
|
|
43
|
+
tenantId?: string | number;
|
|
44
|
+
[key: string]: unknown;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ============================================================================
|
|
48
|
+
// Role & Permission Types
|
|
49
|
+
// ============================================================================
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Role interface
|
|
53
|
+
*/
|
|
54
|
+
export interface Role {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
isTenantSpecific?: boolean;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Permission action types
|
|
64
|
+
*/
|
|
65
|
+
export type PermissionAction = "create" | "read" | "update" | "delete";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Permission interface
|
|
69
|
+
*/
|
|
70
|
+
export interface Permission {
|
|
71
|
+
id: string;
|
|
72
|
+
role_Id: string;
|
|
73
|
+
collection: string;
|
|
74
|
+
action: PermissionAction;
|
|
75
|
+
fields?: string[] | null;
|
|
76
|
+
conditions?: Record<string, unknown>;
|
|
77
|
+
defaultValues?: Record<string, unknown>;
|
|
78
|
+
relConditions?: Record<string, unknown>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Permission data structure (internal to PermissionService)
|
|
83
|
+
*/
|
|
84
|
+
export interface PermissionData {
|
|
85
|
+
fields: string[] | null;
|
|
86
|
+
conditions: Record<string, unknown>;
|
|
87
|
+
relConditions: Record<string, unknown>;
|
|
88
|
+
defaultValues: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Data for creating a new permission
|
|
93
|
+
*/
|
|
94
|
+
export interface CreatePermissionData {
|
|
95
|
+
role_Id: string;
|
|
96
|
+
collection: string;
|
|
97
|
+
action: PermissionAction;
|
|
98
|
+
fields?: string[];
|
|
99
|
+
conditions?: Record<string, unknown>;
|
|
100
|
+
defaultValues?: Record<string, unknown>;
|
|
101
|
+
relConditions?: Record<string, unknown>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ============================================================================
|
|
105
|
+
// Tenant Types
|
|
106
|
+
// ============================================================================
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Tenant interface
|
|
110
|
+
*/
|
|
111
|
+
export interface Tenant {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
[key: string]: unknown;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ============================================================================
|
|
118
|
+
// Session & Token Types
|
|
119
|
+
// ============================================================================
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Session interface
|
|
123
|
+
*/
|
|
124
|
+
export interface Session {
|
|
125
|
+
id: string;
|
|
126
|
+
token: string;
|
|
127
|
+
user_Id: string;
|
|
128
|
+
expiresAt: Date | string;
|
|
129
|
+
ipAddress?: string;
|
|
130
|
+
userAgent?: string;
|
|
131
|
+
createdAt?: string;
|
|
132
|
+
updatedAt?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Auth tokens
|
|
137
|
+
*/
|
|
138
|
+
export interface AuthTokens {
|
|
139
|
+
accessToken: string;
|
|
140
|
+
refreshToken?: string;
|
|
141
|
+
expiresAt?: number;
|
|
142
|
+
expiresIn?: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* JWT payload interface
|
|
147
|
+
*/
|
|
148
|
+
export interface JWTPayload {
|
|
149
|
+
id: string;
|
|
150
|
+
email: string;
|
|
151
|
+
role: string;
|
|
152
|
+
sessionToken: string;
|
|
153
|
+
tenant_Id?: string | number | null;
|
|
154
|
+
/** Pinned baasix_UserRole row id (assignment switching). Absent on legacy tokens. */
|
|
155
|
+
userRole_Id?: string | null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ============================================================================
|
|
159
|
+
// Accountability Types
|
|
160
|
+
// ============================================================================
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Accountability object interface - used for permission checking
|
|
164
|
+
*/
|
|
165
|
+
export interface Accountability {
|
|
166
|
+
user?: { id: string | number; email?: string; isAdmin?: boolean; [key: string]: any };
|
|
167
|
+
role?: { id: string | number; name?: string; isTenantSpecific?: boolean } | string | number;
|
|
168
|
+
/** Full active baasix_UserRole row (assignment) — custom columns included. */
|
|
169
|
+
userRole?: Record<string, any>;
|
|
170
|
+
permissions?: any[];
|
|
171
|
+
tenant?: string | number;
|
|
172
|
+
ipaddress?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ============================================================================
|
|
176
|
+
// Auth Request/Response Types
|
|
177
|
+
// ============================================================================
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Login credentials
|
|
181
|
+
*/
|
|
182
|
+
export interface LoginCredentials {
|
|
183
|
+
email: string;
|
|
184
|
+
password: string;
|
|
185
|
+
tenantId?: string;
|
|
186
|
+
/** Authentication mode: 'jwt' for token-based or 'cookie' for cookie-based auth */
|
|
187
|
+
authMode?: "jwt" | "cookie";
|
|
188
|
+
/** Authentication type for session management (e.g., 'web', 'mobile', 'default') */
|
|
189
|
+
authType?: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Registration data
|
|
194
|
+
*/
|
|
195
|
+
export interface RegisterData {
|
|
196
|
+
email: string;
|
|
197
|
+
password: string;
|
|
198
|
+
firstName?: string;
|
|
199
|
+
lastName?: string;
|
|
200
|
+
[key: string]: unknown;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Auth response
|
|
205
|
+
*/
|
|
206
|
+
export interface AuthResponse {
|
|
207
|
+
token: string;
|
|
208
|
+
refreshToken?: string;
|
|
209
|
+
user: User;
|
|
210
|
+
role?: Role;
|
|
211
|
+
expiresIn?: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Auth state events
|
|
216
|
+
*/
|
|
217
|
+
export type AuthStateEvent =
|
|
218
|
+
| "SIGNED_IN"
|
|
219
|
+
| "SIGNED_OUT"
|
|
220
|
+
| "TOKEN_REFRESHED"
|
|
221
|
+
| "USER_UPDATED"
|
|
222
|
+
| "TENANT_SWITCHED";
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Auth state
|
|
226
|
+
*/
|
|
227
|
+
export interface AuthState {
|
|
228
|
+
user: User | null;
|
|
229
|
+
isAuthenticated: boolean;
|
|
230
|
+
isLoading: boolean;
|
|
231
|
+
error: Error | null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Magic link options
|
|
236
|
+
*/
|
|
237
|
+
export interface MagicLinkOptions {
|
|
238
|
+
email: string;
|
|
239
|
+
redirectUrl?: string;
|
|
240
|
+
mode?: "link" | "code";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Password reset options
|
|
245
|
+
*/
|
|
246
|
+
export interface PasswordResetOptions {
|
|
247
|
+
email: string;
|
|
248
|
+
redirectUrl?: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ============================================================================
|
|
252
|
+
// Auth Mode Types
|
|
253
|
+
// ============================================================================
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Authentication mode for the SDK/app
|
|
257
|
+
* - 'jwt': Use JWT tokens stored in the configured storage adapter (default)
|
|
258
|
+
* - 'cookie': Use HTTP-only cookies (server handles token storage)
|
|
259
|
+
*/
|
|
260
|
+
export type AuthMode = "jwt" | "cookie";
|
|
261
|
+
|
|
262
|
+
// ============================================================================
|
|
263
|
+
// OAuth Types
|
|
264
|
+
// ============================================================================
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* OAuth2 tokens
|
|
268
|
+
*/
|
|
269
|
+
export interface OAuth2Tokens {
|
|
270
|
+
accessToken: string;
|
|
271
|
+
refreshToken?: string;
|
|
272
|
+
idToken?: string;
|
|
273
|
+
expiresAt?: Date;
|
|
274
|
+
tokenType?: string;
|
|
275
|
+
scope?: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* OAuth2 user info
|
|
280
|
+
*/
|
|
281
|
+
export interface OAuth2UserInfo {
|
|
282
|
+
id: string;
|
|
283
|
+
email: string;
|
|
284
|
+
name?: string;
|
|
285
|
+
firstName?: string;
|
|
286
|
+
lastName?: string;
|
|
287
|
+
picture?: string;
|
|
288
|
+
[key: string]: unknown;
|
|
289
|
+
}
|