@meistrari/auth-core 1.15.0 → 1.17.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 CHANGED
@@ -42,401 +42,4 @@ console.log('Organizations:', organizations)
42
42
 
43
43
  ## API Reference
44
44
 
45
- ### AuthClient
46
-
47
- The main entry point for the SDK. Provides access to session and organization services.
48
-
49
- #### Constructor
50
-
51
- ```typescript
52
- new AuthClient(apiUrl: string, headers?: Record<string, string>)
53
- ```
54
-
55
- **Parameters:**
56
- - `apiUrl` - The base URL of the Auth API
57
- - `headers` (optional) - Custom headers to include in all requests
58
-
59
- **Example:**
60
- ```typescript
61
- const authClient = new AuthClient('https://auth.example.com', {
62
- 'X-Custom-Header': 'value'
63
- })
64
- ```
65
-
66
- ### Session Management
67
-
68
- Access via `authClient.session`
69
-
70
- #### signInWithEmailAndPassword
71
-
72
- Authenticates a user with email and password credentials.
73
-
74
- ```typescript
75
- await authClient.session.signInWithEmailAndPassword({
76
- email: 'user@example.com',
77
- password: 'password123'
78
- })
79
- ```
80
-
81
- #### signInWithSocialProvider
82
-
83
- Initiates social authentication flow with Google or Microsoft.
84
-
85
- ```typescript
86
- await authClient.session.signInWithSocialProvider({
87
- provider: 'google', // or 'microsoft'
88
- callbackURL: 'https://app.example.com/callback',
89
- errorCallbackURL: 'https://app.example.com/error', // optional
90
- })
91
- ```
92
-
93
- The error callback URL receives an `error` query parameter with the error status text.
94
-
95
- #### signInWithSaml
96
-
97
- Initiates SAML-based Single Sign-On authentication flow.
98
-
99
- ```typescript
100
- await authClient.session.signInWithSaml({
101
- email: 'user@company.com',
102
- callbackURL: 'https://app.example.com/callback',
103
- errorCallbackURL: 'https://app.example.com/error', // optional
104
- })
105
- ```
106
-
107
- The error callback URL receives an `error` query parameter with the error status text.
108
-
109
- #### signOut
110
-
111
- Signs out the currently authenticated user.
112
-
113
- ```typescript
114
- // Simple sign out
115
- await authClient.session.signOut()
116
-
117
- // Sign out with callback
118
- await authClient.session.signOut(() => {
119
- console.log('User signed out')
120
- window.location.href = '/login'
121
- })
122
- ```
123
-
124
- #### requestPasswordReset
125
-
126
- Initiates a password reset request.
127
-
128
- ```typescript
129
- await authClient.session.requestPasswordReset(
130
- 'user@example.com',
131
- 'https://app.example.com/reset-password'
132
- )
133
- ```
134
-
135
- #### resetPassword
136
-
137
- Completes the password reset process.
138
-
139
- ```typescript
140
- await authClient.session.resetPassword(
141
- 'reset-token-from-email',
142
- 'NewSecurePassword123!'
143
- )
144
- ```
145
-
146
- ### Organization Management
147
-
148
- Access via `authClient.organization`
149
-
150
- #### listOrganizations
151
-
152
- Lists all organizations accessible to the current user.
153
-
154
- ```typescript
155
- const organizations = await authClient.organization.listOrganizations()
156
- ```
157
-
158
- #### getOrganization
159
-
160
- Retrieves a single organization with teams, invites and members.
161
-
162
- ```typescript
163
- const organization = await authClient.organization.getOrganization('org-123')
164
- ```
165
-
166
- #### setActiveOrganization
167
-
168
- Sets the active organization for the current user session.
169
-
170
- ```typescript
171
- await authClient.organization.setActiveOrganization('org-123')
172
- ```
173
-
174
- #### updateOrganization
175
-
176
- Updates an organization's details.
177
-
178
- ```typescript
179
- const updated = await authClient.organization.updateOrganization({
180
- name: 'New Organization Name',
181
- logo: 'https://example.com/logo.png',
182
- settings: {
183
- disableStorage: true,
184
- dataRetentionHours: 24
185
- }
186
- })
187
- ```
188
-
189
- ### Member Management
190
-
191
- #### listMembers
192
-
193
- Lists members of the active organization.
194
-
195
- ```typescript
196
- const members = await authClient.organization.listMembers({
197
- limit: 10,
198
- offset: 0
199
- })
200
- ```
201
-
202
- #### getActiveMember
203
-
204
- Gets the currently active organization member for the authenticated user.
205
-
206
- ```typescript
207
- const activeMember = await authClient.organization.getActiveMember()
208
- console.log(`Role: ${activeMember.role}`)
209
- ```
210
-
211
- #### inviteUserToOrganization
212
-
213
- Invites a user to join the active organization.
214
-
215
- ```typescript
216
- import { Roles } from '@meistrari/auth-core'
217
-
218
- await authClient.organization.inviteUserToOrganization({
219
- userEmail: 'newuser@example.com',
220
- role: Roles.ORG_MEMBER,
221
- teamId: 'team-123' // optional
222
- })
223
- ```
224
-
225
- #### acceptInvitation
226
-
227
- Accepts an organization invitation.
228
-
229
- ```typescript
230
- await authClient.organization.acceptInvitation('invitation-123')
231
- ```
232
-
233
- #### cancelInvitation
234
-
235
- Cancels a pending invitation.
236
-
237
- ```typescript
238
- await authClient.organization.cancelInvitation('invitation-123')
239
- ```
240
-
241
- #### removeUserFromOrganization
242
-
243
- Removes a user from the active organization.
244
-
245
- ```typescript
246
- // Remove by member ID
247
- await authClient.organization.removeUserFromOrganization({
248
- memberId: 'member-123'
249
- })
250
-
251
- // Remove by email
252
- await authClient.organization.removeUserFromOrganization({
253
- userEmail: 'user@example.com'
254
- })
255
- ```
256
-
257
- #### updateMemberRole
258
-
259
- Updates the role of an organization member.
260
-
261
- ```typescript
262
- import { Roles } from '@meistrari/auth-core'
263
-
264
- await authClient.organization.updateMemberRole({
265
- memberId: 'member-123',
266
- role: Roles.ORG_ADMIN
267
- })
268
- ```
269
-
270
- ### Team Management
271
-
272
- #### listTeams
273
-
274
- Lists all teams in the active organization.
275
-
276
- ```typescript
277
- const teams = await authClient.organization.listTeams()
278
- ```
279
-
280
- #### createTeam
281
-
282
- Creates a new team.
283
-
284
- ```typescript
285
- const team = await authClient.organization.createTeam({
286
- name: 'Engineering Team'
287
- })
288
- ```
289
-
290
- #### updateTeam
291
-
292
- Updates a team's details.
293
-
294
- ```typescript
295
- const updated = await authClient.organization.updateTeam('team-123', {
296
- name: 'Updated Team Name'
297
- })
298
- ```
299
-
300
- #### deleteTeam
301
-
302
- Deletes a team.
303
-
304
- ```typescript
305
- await authClient.organization.deleteTeam('team-123')
306
- ```
307
-
308
- #### listTeamMembers
309
-
310
- Lists all members of a specific team.
311
-
312
- ```typescript
313
- const members = await authClient.organization.listTeamMembers('team-123')
314
- ```
315
-
316
- #### addTeamMember
317
-
318
- Adds a user to a team.
319
-
320
- ```typescript
321
- await authClient.organization.addTeamMember('team-123', 'user-456')
322
- ```
323
-
324
- #### removeTeamMember
325
-
326
- Removes a user from a team.
327
-
328
- ```typescript
329
- await authClient.organization.removeTeamMember('team-123', 'user-456')
330
- ```
331
-
332
- ### Token Validation
333
-
334
- Standalone utility functions for JWT token validation.
335
-
336
- #### isTokenExpired
337
-
338
- Checks if a JWT token has expired.
339
-
340
- ```typescript
341
- import { isTokenExpired } from '@meistrari/auth-core'
342
-
343
- const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...'
344
- if (isTokenExpired(token)) {
345
- console.log('Token has expired')
346
- }
347
- ```
348
-
349
- #### validateToken
350
-
351
- Validates a JWT token by checking expiration and verifying signature.
352
-
353
- ```typescript
354
- import { validateToken } from '@meistrari/auth-core'
355
-
356
- const token = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...'
357
- const isValid = await validateToken(token, 'https://auth.example.com')
358
-
359
- if (isValid) {
360
- console.log('Token is valid')
361
- }
362
- ```
363
-
364
- ## Roles and Permissions
365
-
366
- The SDK provides predefined organization roles with specific permissions:
367
-
368
- ```typescript
369
- import { Roles } from '@meistrari/auth-core'
370
-
371
- // Available roles
372
- Roles.ORG_ADMIN // Full access: org updates, team/member management, invitations
373
- Roles.ORG_MEMBER // Basic member access
374
- Roles.ORG_REVIEWER // Read-only reviewer access
375
- ```
376
-
377
- ## Error Handling
378
-
379
- The SDK provides typed error classes for better error handling:
380
-
381
- ### BaseError
382
-
383
- Base class for all SDK errors with a `code` property.
384
-
385
- ```typescript
386
- import { BaseError } from '@meistrari/auth-core'
387
-
388
- try {
389
- // SDK operation
390
- }
391
- catch (error) {
392
- if (error instanceof BaseError) {
393
- console.log(`Error code: ${error.code}`)
394
- console.log(`Error message: ${error.message}`)
395
- }
396
- }
397
- ```
398
-
399
- ### Specific Error Classes
400
-
401
- - **InvalidSocialProvider** - Invalid social provider specified
402
- - **InvalidCallbackURL** - Malformed callback URL
403
- - **EmailRequired** - Email parameter required but not provided
404
- - **APIError** (BetterFetchError) - API request failed
405
-
406
- ```typescript
407
- import {
408
- InvalidSocialProvider,
409
- InvalidCallbackURL,
410
- EmailRequired,
411
- APIError
412
- } from '@meistrari/auth-core'
413
-
414
- try {
415
- await authClient.session.signInWithSocialProvider({
416
- provider: 'invalid' as any,
417
- callbackURL: 'https://app.example.com/callback'
418
- })
419
- }
420
- catch (error) {
421
- if (error instanceof InvalidSocialProvider) {
422
- console.log('Invalid provider specified')
423
- }
424
- }
425
- ```
426
-
427
- ## Type Definitions
428
-
429
- The SDK exports TypeScript types for all data structures:
430
-
431
- ```typescript
432
- import type {
433
- User,
434
- Session,
435
- Organization,
436
- Member,
437
- Invitation,
438
- Team,
439
- TeamMember,
440
- Role
441
- } from '@meistrari/auth-core'
442
- ```
45
+ See it on [Pantry](https://pantry.tela.tools/ingredients/auth-core/api)