@meistrari/auth-core 1.4.0 → 1.4.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/README.md +69 -67
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.mjs +13 -14
- package/package.json +29 -29
package/README.md
CHANGED
|
@@ -31,8 +31,8 @@ const authClient = new AuthClient('https://auth.example.com')
|
|
|
31
31
|
|
|
32
32
|
// Sign in with email and password
|
|
33
33
|
await authClient.session.signInWithEmailAndPassword({
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
email: 'user@example.com',
|
|
35
|
+
password: 'SecurePassword123!'
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
// List user's organizations
|
|
@@ -59,7 +59,7 @@ new AuthClient(apiUrl: string, headers?: Record<string, string>)
|
|
|
59
59
|
**Example:**
|
|
60
60
|
```typescript
|
|
61
61
|
const authClient = new AuthClient('https://auth.example.com', {
|
|
62
|
-
|
|
62
|
+
'X-Custom-Header': 'value'
|
|
63
63
|
})
|
|
64
64
|
```
|
|
65
65
|
|
|
@@ -73,8 +73,8 @@ Authenticates a user with email and password credentials.
|
|
|
73
73
|
|
|
74
74
|
```typescript
|
|
75
75
|
await authClient.session.signInWithEmailAndPassword({
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
email: 'user@example.com',
|
|
77
|
+
password: 'password123'
|
|
78
78
|
})
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -84,9 +84,9 @@ Initiates social authentication flow with Google or Microsoft.
|
|
|
84
84
|
|
|
85
85
|
```typescript
|
|
86
86
|
await authClient.session.signInWithSocialProvider({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
provider: 'google', // or 'microsoft'
|
|
88
|
+
callbackURL: 'https://app.example.com/callback',
|
|
89
|
+
errorCallbackURL: 'https://app.example.com/error' // optional
|
|
90
90
|
})
|
|
91
91
|
```
|
|
92
92
|
|
|
@@ -98,9 +98,9 @@ Initiates SAML-based Single Sign-On authentication flow.
|
|
|
98
98
|
|
|
99
99
|
```typescript
|
|
100
100
|
await authClient.session.signInWithSaml({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
email: 'user@company.com',
|
|
102
|
+
callbackURL: 'https://app.example.com/callback',
|
|
103
|
+
errorCallbackURL: 'https://app.example.com/error' // optional
|
|
104
104
|
})
|
|
105
105
|
```
|
|
106
106
|
|
|
@@ -116,8 +116,8 @@ await authClient.session.signOut()
|
|
|
116
116
|
|
|
117
117
|
// Sign out with callback
|
|
118
118
|
await authClient.session.signOut(() => {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
console.log('User signed out')
|
|
120
|
+
window.location.href = '/login'
|
|
121
121
|
})
|
|
122
122
|
```
|
|
123
123
|
|
|
@@ -127,8 +127,8 @@ Initiates a password reset request.
|
|
|
127
127
|
|
|
128
128
|
```typescript
|
|
129
129
|
await authClient.session.requestPasswordReset(
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
'user@example.com',
|
|
131
|
+
'https://app.example.com/reset-password'
|
|
132
132
|
)
|
|
133
133
|
```
|
|
134
134
|
|
|
@@ -138,8 +138,8 @@ Completes the password reset process.
|
|
|
138
138
|
|
|
139
139
|
```typescript
|
|
140
140
|
await authClient.session.resetPassword(
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
'reset-token-from-email',
|
|
142
|
+
'NewSecurePassword123!'
|
|
143
143
|
)
|
|
144
144
|
```
|
|
145
145
|
|
|
@@ -161,9 +161,9 @@ Retrieves a single organization with optional related data.
|
|
|
161
161
|
|
|
162
162
|
```typescript
|
|
163
163
|
const organization = await authClient.organization.getOrganization('org-123', {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
includeMembers: true,
|
|
165
|
+
includeInvitations: true,
|
|
166
|
+
includeTeams: true
|
|
167
167
|
})
|
|
168
168
|
```
|
|
169
169
|
|
|
@@ -181,12 +181,12 @@ Updates an organization's details.
|
|
|
181
181
|
|
|
182
182
|
```typescript
|
|
183
183
|
const updated = await authClient.organization.updateOrganization({
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
name: 'New Organization Name',
|
|
185
|
+
logo: 'https://example.com/logo.png',
|
|
186
|
+
settings: {
|
|
187
|
+
disableStorage: true,
|
|
188
|
+
dataRetentionHours: 24
|
|
189
|
+
}
|
|
190
190
|
})
|
|
191
191
|
```
|
|
192
192
|
|
|
@@ -198,8 +198,8 @@ Lists members of the active organization.
|
|
|
198
198
|
|
|
199
199
|
```typescript
|
|
200
200
|
const members = await authClient.organization.listMembers({
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
limit: 10,
|
|
202
|
+
offset: 0
|
|
203
203
|
})
|
|
204
204
|
```
|
|
205
205
|
|
|
@@ -220,9 +220,9 @@ Invites a user to join the active organization.
|
|
|
220
220
|
import { Roles } from '@meistrari/auth-core'
|
|
221
221
|
|
|
222
222
|
await authClient.organization.inviteUserToOrganization({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
userEmail: 'newuser@example.com',
|
|
224
|
+
role: Roles.ORG_MEMBER,
|
|
225
|
+
teamId: 'team-123' // optional
|
|
226
226
|
})
|
|
227
227
|
```
|
|
228
228
|
|
|
@@ -249,12 +249,12 @@ Removes a user from the active organization.
|
|
|
249
249
|
```typescript
|
|
250
250
|
// Remove by member ID
|
|
251
251
|
await authClient.organization.removeUserFromOrganization({
|
|
252
|
-
|
|
252
|
+
memberId: 'member-123'
|
|
253
253
|
})
|
|
254
254
|
|
|
255
255
|
// Remove by email
|
|
256
256
|
await authClient.organization.removeUserFromOrganization({
|
|
257
|
-
|
|
257
|
+
userEmail: 'user@example.com'
|
|
258
258
|
})
|
|
259
259
|
```
|
|
260
260
|
|
|
@@ -266,8 +266,8 @@ Updates the role of an organization member.
|
|
|
266
266
|
import { Roles } from '@meistrari/auth-core'
|
|
267
267
|
|
|
268
268
|
await authClient.organization.updateMemberRole({
|
|
269
|
-
|
|
270
|
-
|
|
269
|
+
memberId: 'member-123',
|
|
270
|
+
role: Roles.ORG_ADMIN
|
|
271
271
|
})
|
|
272
272
|
```
|
|
273
273
|
|
|
@@ -287,7 +287,7 @@ Creates a new team.
|
|
|
287
287
|
|
|
288
288
|
```typescript
|
|
289
289
|
const team = await authClient.organization.createTeam({
|
|
290
|
-
|
|
290
|
+
name: 'Engineering Team'
|
|
291
291
|
})
|
|
292
292
|
```
|
|
293
293
|
|
|
@@ -297,7 +297,7 @@ Updates a team's details.
|
|
|
297
297
|
|
|
298
298
|
```typescript
|
|
299
299
|
const updated = await authClient.organization.updateTeam('team-123', {
|
|
300
|
-
|
|
300
|
+
name: 'Updated Team Name'
|
|
301
301
|
})
|
|
302
302
|
```
|
|
303
303
|
|
|
@@ -346,7 +346,7 @@ import { isTokenExpired } from '@meistrari/auth-core'
|
|
|
346
346
|
|
|
347
347
|
const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
348
348
|
if (isTokenExpired(token)) {
|
|
349
|
-
|
|
349
|
+
console.log('Token has expired')
|
|
350
350
|
}
|
|
351
351
|
```
|
|
352
352
|
|
|
@@ -361,7 +361,7 @@ const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
|
361
361
|
const isValid = await validateToken(token, 'https://auth.example.com')
|
|
362
362
|
|
|
363
363
|
if (isValid) {
|
|
364
|
-
|
|
364
|
+
console.log('Token is valid')
|
|
365
365
|
}
|
|
366
366
|
```
|
|
367
367
|
|
|
@@ -373,8 +373,8 @@ The SDK provides predefined organization roles with specific permissions:
|
|
|
373
373
|
import { Roles } from '@meistrari/auth-core'
|
|
374
374
|
|
|
375
375
|
// Available roles
|
|
376
|
-
Roles.ORG_ADMIN
|
|
377
|
-
Roles.ORG_MEMBER
|
|
376
|
+
Roles.ORG_ADMIN // Full access: org updates, team/member management, invitations
|
|
377
|
+
Roles.ORG_MEMBER // Basic member access
|
|
378
378
|
Roles.ORG_REVIEWER // Read-only reviewer access
|
|
379
379
|
```
|
|
380
380
|
|
|
@@ -390,12 +390,13 @@ Base class for all SDK errors with a `code` property.
|
|
|
390
390
|
import { BaseError } from '@meistrari/auth-core'
|
|
391
391
|
|
|
392
392
|
try {
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
393
|
+
// SDK operation
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
if (error instanceof BaseError) {
|
|
397
|
+
console.log(`Error code: ${error.code}`)
|
|
398
|
+
console.log(`Error message: ${error.message}`)
|
|
399
|
+
}
|
|
399
400
|
}
|
|
400
401
|
```
|
|
401
402
|
|
|
@@ -408,21 +409,22 @@ try {
|
|
|
408
409
|
|
|
409
410
|
```typescript
|
|
410
411
|
import {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
412
|
+
InvalidSocialProvider,
|
|
413
|
+
InvalidCallbackURL,
|
|
414
|
+
EmailRequired,
|
|
415
|
+
APIError
|
|
415
416
|
} from '@meistrari/auth-core'
|
|
416
417
|
|
|
417
418
|
try {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
await authClient.session.signInWithSocialProvider({
|
|
420
|
+
provider: 'invalid' as any,
|
|
421
|
+
callbackURL: 'https://app.example.com/callback'
|
|
422
|
+
})
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
if (error instanceof InvalidSocialProvider) {
|
|
426
|
+
console.log('Invalid provider specified')
|
|
427
|
+
}
|
|
426
428
|
}
|
|
427
429
|
```
|
|
428
430
|
|
|
@@ -432,13 +434,13 @@ The SDK exports TypeScript types for all data structures:
|
|
|
432
434
|
|
|
433
435
|
```typescript
|
|
434
436
|
import type {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
437
|
+
User,
|
|
438
|
+
Session,
|
|
439
|
+
Organization,
|
|
440
|
+
Member,
|
|
441
|
+
Invitation,
|
|
442
|
+
Team,
|
|
443
|
+
TeamMember,
|
|
444
|
+
Role
|
|
443
445
|
} from '@meistrari/auth-core'
|
|
444
446
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -6221,7 +6221,7 @@ declare class OrganizationService {
|
|
|
6221
6221
|
* @param options - User identifier (either memberId or userEmail must be provided)
|
|
6222
6222
|
* @param options.memberId - The member ID to remove
|
|
6223
6223
|
* @param options.userEmail - The user email to remove
|
|
6224
|
-
|
|
6224
|
+
|
|
6225
6225
|
*/
|
|
6226
6226
|
removeUserFromOrganization({ memberId, userEmail }: RemoveUserFromOrganizationOptions): Promise<void>;
|
|
6227
6227
|
/**
|
|
@@ -6326,8 +6326,6 @@ type SignInWithSamlOptions = {
|
|
|
6326
6326
|
type SignInWithEmailAndPasswordOptions = {
|
|
6327
6327
|
email: string;
|
|
6328
6328
|
password: string;
|
|
6329
|
-
callbackURL: string;
|
|
6330
|
-
errorCallbackURL?: string;
|
|
6331
6329
|
};
|
|
6332
6330
|
|
|
6333
6331
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6221,7 +6221,7 @@ declare class OrganizationService {
|
|
|
6221
6221
|
* @param options - User identifier (either memberId or userEmail must be provided)
|
|
6222
6222
|
* @param options.memberId - The member ID to remove
|
|
6223
6223
|
* @param options.userEmail - The user email to remove
|
|
6224
|
-
|
|
6224
|
+
|
|
6225
6225
|
*/
|
|
6226
6226
|
removeUserFromOrganization({ memberId, userEmail }: RemoveUserFromOrganizationOptions): Promise<void>;
|
|
6227
6227
|
/**
|
|
@@ -6326,8 +6326,6 @@ type SignInWithSamlOptions = {
|
|
|
6326
6326
|
type SignInWithEmailAndPasswordOptions = {
|
|
6327
6327
|
email: string;
|
|
6328
6328
|
password: string;
|
|
6329
|
-
callbackURL: string;
|
|
6330
|
-
errorCallbackURL?: string;
|
|
6331
6329
|
};
|
|
6332
6330
|
|
|
6333
6331
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRemoteJWKSet, jwtVerify
|
|
1
|
+
import { decodeJwt, createRemoteJWKSet, jwtVerify } from 'jose';
|
|
2
2
|
import { ssoClient } from '@better-auth/sso/client';
|
|
3
3
|
import { createAuthClient } from 'better-auth/client';
|
|
4
4
|
import { organizationClient, twoFactorClient, jwtClient, apiKeyClient, adminClient, inferAdditionalFields } from 'better-auth/client/plugins';
|
|
@@ -6,8 +6,6 @@ import { createAccessControl } from 'better-auth/plugins/access';
|
|
|
6
6
|
import { defaultStatements } from 'better-auth/plugins/organization/access';
|
|
7
7
|
export { BetterFetchError as APIError } from '@better-fetch/fetch';
|
|
8
8
|
|
|
9
|
-
const version = "1.4.0";
|
|
10
|
-
|
|
11
9
|
const statements = {
|
|
12
10
|
...defaultStatements,
|
|
13
11
|
access: ["admin", "member", "reviewer"]
|
|
@@ -48,18 +46,19 @@ const organizationAdditionalFields = {
|
|
|
48
46
|
}
|
|
49
47
|
};
|
|
50
48
|
|
|
51
|
-
const
|
|
49
|
+
const version = "1.4.2";
|
|
50
|
+
function customEndpointsPluginClient() {
|
|
52
51
|
return {
|
|
53
52
|
id: "custom-endpoints",
|
|
54
53
|
$InferServerPlugin: {}
|
|
55
54
|
};
|
|
56
|
-
}
|
|
57
|
-
|
|
55
|
+
}
|
|
56
|
+
function handshakePluginClient() {
|
|
58
57
|
return {
|
|
59
58
|
id: "handshake",
|
|
60
59
|
$InferServerPlugin: {}
|
|
61
60
|
};
|
|
62
|
-
}
|
|
61
|
+
}
|
|
63
62
|
function createAPIClient(apiUrl, fetchOptions = {}) {
|
|
64
63
|
const serviceName = typeof process !== "undefined" ? process.env.SERVICE_NAME : "";
|
|
65
64
|
const userAgent = `auth-sdk:core:${version}${serviceName ? `@${serviceName}` : ""}`;
|
|
@@ -255,13 +254,13 @@ class OrganizationService {
|
|
|
255
254
|
});
|
|
256
255
|
}
|
|
257
256
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
257
|
+
* Removes a user from the active organization.
|
|
258
|
+
*
|
|
259
|
+
* @param options - User identifier (either memberId or userEmail must be provided)
|
|
260
|
+
* @param options.memberId - The member ID to remove
|
|
261
|
+
* @param options.userEmail - The user email to remove
|
|
262
|
+
|
|
263
|
+
*/
|
|
265
264
|
async removeUserFromOrganization({ memberId, userEmail }) {
|
|
266
265
|
await this.client.organization.removeMember({
|
|
267
266
|
memberIdOrEmail: memberId ?? userEmail
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"main": "./dist/index.mjs",
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"files": [
|
|
14
|
-
"dist"
|
|
15
|
-
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "unbuild"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@better-auth/sso": "1.4.7",
|
|
21
|
-
"better-auth": "1.4.7",
|
|
22
|
-
"jose": "6.1.0",
|
|
23
|
-
"nanostores": "1.0.1",
|
|
24
|
-
"@better-fetch/fetch": "1.1.21",
|
|
25
|
-
"better-call": "1.1.5"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/node": "latest",
|
|
29
|
-
"typescript": "5.9.2",
|
|
30
|
-
"unbuild": "3.6.1"
|
|
2
|
+
"name": "@meistrari/auth-core",
|
|
3
|
+
"version": "1.4.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.mjs"
|
|
31
9
|
}
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "unbuild"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@better-auth/sso": "1.4.7",
|
|
21
|
+
"better-auth": "1.4.7",
|
|
22
|
+
"jose": "6.1.0",
|
|
23
|
+
"nanostores": "1.0.1",
|
|
24
|
+
"@better-fetch/fetch": "1.1.21",
|
|
25
|
+
"better-call": "1.1.5"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "latest",
|
|
29
|
+
"typescript": "5.9.2",
|
|
30
|
+
"unbuild": "3.6.1"
|
|
31
|
+
}
|
|
32
32
|
}
|