@authaz/next 0.0.1 → 1.0.1

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.
@@ -1,163 +0,0 @@
1
- # Authaz SDK Refactoring
2
-
3
- ## 📁 New Structure
4
-
5
- The refactoring organized the SDK by **functional flows**, separating responsibilities and improving maintainability:
6
-
7
- ```
8
- src/
9
- ├── flows/ # Specific functionality flows
10
- │ ├── auth/ # Authentication and MFA
11
- │ │ ├── api.ts # Methods: login, loginVerifyMfa
12
- │ │ └── types.ts # LoginResponse, MfaVerifyResponse
13
- │ ├── password-reset/ # Password recovery
14
- │ │ ├── api.ts # Methods: requestPasswordReset, verifyPasswordResetCode, etc.
15
- │ │ └── types.ts # PasswordResetRequestResponse, etc.
16
- │ ├── signup/ # User registration
17
- │ │ ├── api.ts # Methods: requestSignup, confirmSignup, etc.
18
- │ │ └── types.ts # SignupRequestResponse, etc.
19
- │ └── user/ # User data
20
- │ ├── api.ts # Methods: getMe
21
- │ └── types.ts # UserResponse, UserProfile
22
- ├── shared/ # Shared logic and types
23
- │ ├── base-api.ts # Base class with common authentication
24
- │ └── types.ts # Base types (tokens, session, etc.)
25
- ├── utils/ # Utilities
26
- │ ├── auth.ts # Validation functions and helpers
27
- │ └── session.ts # Session management
28
- ├── api.ts # Main aggregator class
29
- ├── types.ts # Re-exports of all types
30
- ├── http-types.ts # Raw HTTP types (maintained)
31
- └── index.ts # Main exports
32
- ```
33
-
34
- ## 🔄 Compatibility
35
-
36
- The refactoring **maintains full compatibility** with existing code:
37
-
38
- ```typescript
39
- // Will continue to work exactly the same
40
- import { ApiService } from 'authaz-sdk-js'
41
-
42
- const client = new ApiService(clientId, clientSecret, authPoolId, organizationId)
43
-
44
- // All methods work the same
45
- const loginResult = await client.login(email, password)
46
- const userResult = await client.getMe(token)
47
- ```
48
-
49
- ## 🎯 Refactoring Benefits
50
-
51
- ### 1. **Separation of Concerns**
52
- - Each flow has its own class and types
53
- - More organized and easier to maintain code
54
- - Less chance of conflicts between functionalities
55
-
56
- ### 2. **Code Reusability**
57
- - `BaseApiService` class eliminates duplication
58
- - Centralized authentication logic
59
- - Shared configuration across all services
60
-
61
- ### 3. **Better Developer Experience**
62
- - More specific types per flow
63
- - More precise IntelliSense
64
- - Easier debugging and maintenance
65
-
66
- ### 4. **Flexibility**
67
- - Ability to use individual services
68
- - Easier unit testing
69
- - Allows future extensions
70
-
71
- ## 🚀 Advanced Usage (Optional)
72
-
73
- For specific cases, you can use individual services:
74
-
75
- ```typescript
76
- import {
77
- AuthApiService,
78
- PasswordResetApiService,
79
- SignupApiService,
80
- UserApiService
81
- } from 'authaz-sdk-js'
82
-
83
- // Use only the authentication service
84
- const authService = new AuthApiService(baseUrl, clientId, clientSecret, authPoolId, organizationId)
85
- const loginResult = await authService.login(email, password)
86
-
87
- // Or only password recovery
88
- const passwordService = new PasswordResetApiService(baseUrl, clientId, clientSecret, authPoolId, organizationId)
89
- const resetResult = await passwordService.requestPasswordReset(email)
90
- ```
91
-
92
- ## 📝 Usage Examples
93
-
94
- ### Complete Authentication
95
- ```typescript
96
- import { ApiService } from 'authaz-sdk-js'
97
-
98
- const client = new ApiService(/* configs */)
99
-
100
- // Normal login
101
- const loginResult = await client.login('user@example.com', 'password')
102
-
103
- if (loginResult.status === 'mfa_required') {
104
- // Verify MFA
105
- const mfaResult = await client.loginVerifyMfa(
106
- 'user@example.com',
107
- '123456',
108
- loginResult.challengeToken.value
109
- )
110
-
111
- if (mfaResult.status === 'success') {
112
- // User authenticated
113
- console.log('Access token:', mfaResult.accessToken.value)
114
- }
115
- }
116
- ```
117
-
118
- ### Password Recovery
119
- ```typescript
120
- // Request reset
121
- const requestResult = await client.requestPasswordReset('user@example.com')
122
-
123
- // Verify email code
124
- const verifyResult = await client.verifyPasswordResetCode('user@example.com', '123456')
125
-
126
- if (verifyResult.status === 'challenge') {
127
- // Needs MFA
128
- const mfaResult = await client.forgotPasswordVerifyMfa(
129
- 'user@example.com',
130
- '654321',
131
- verifyResult.challengeToken.value
132
- )
133
- }
134
-
135
- // Confirm new password
136
- const confirmResult = await client.confirmPasswordReset(
137
- token,
138
- 'user@example.com',
139
- 'newPassword123'
140
- )
141
- ```
142
-
143
- ## 🔧 Migration (If Needed)
144
-
145
- If you were importing specific internal files, update:
146
-
147
- ```typescript
148
- // ❌ Before (if you were doing this)
149
- import { validateToken } from 'authaz-sdk-js/src/auth'
150
- import { getSession } from 'authaz-sdk-js/src/session'
151
-
152
- // ✅ Now
153
- import { validateToken } from 'authaz-sdk-js'
154
- import { getSession } from 'authaz-sdk-js'
155
- ```
156
-
157
- ## 📊 Impact
158
-
159
- - **Code removed**: ~400 duplicated lines
160
- - **Organized files**: 6 → 14 well-structured files
161
- - **Maintainability**: ↗️ Much better
162
- - **Performance**: Same (no impact)
163
- - **Compatibility**: ✅ 100% maintained
@@ -1,141 +0,0 @@
1
- # Status Codes - Authaz SDK
2
-
3
- This document describes all specific statuses for each operation flow in the Authaz SDK.
4
-
5
- ## 🔐 Authentication (Auth)
6
-
7
- ### LoginResponse
8
- - `success` - Login successful
9
- - `error` - Generic login error
10
- - `mfa_required` - MFA is required to complete login
11
- - `too_many_attempts` - Too many login attempts
12
-
13
- ### MfaVerifyResponse
14
- - `success` - MFA verified successfully
15
- - `error` - Generic MFA verification error
16
- - `invalid_code` - Invalid MFA code
17
- - `expired` - MFA token expired
18
-
19
- ## 📝 Signup
20
-
21
- ### SignupRequestResponse
22
- - `success` - Signup request sent successfully
23
- - `error` - Generic request error
24
- - `user_already_exists` - User already exists in the system
25
- - `invalid_email` - Invalid email
26
- - `password_not_strong_enough` - Password doesn't meet criteria
27
-
28
- ### SignupConfirmResponse
29
- - `success` - Signup confirmed successfully
30
- - `requires_mfa` - MFA is required to complete signup
31
- - `error` - Generic confirmation error
32
- - `invalid_code` - Invalid confirmation code
33
- - `expired` - Confirmation code expired
34
- - `user_exists` - User already exists
35
-
36
- ### SignupConfigureMfaResponse
37
- - `success` - MFA configured successfully
38
- - `error` - Generic configuration error
39
- - `unauthorized` - Invalid access token
40
- - `mfa_already_configured` - MFA already configured
41
-
42
- ### SignupVerifyMfaResponse
43
- - `success` - MFA verified successfully during signup
44
- - `error` - Generic verification error
45
- - `invalid_code` - Invalid MFA code
46
- - `expired` - MFA token expired
47
- - `unauthorized` - Invalid access token
48
- - `user_exists` - User already exists
49
-
50
- ## 🔑 Password Reset
51
-
52
- ### PasswordResetRequestResponse
53
- - `success` - Reset request sent successfully
54
- - `error` - Generic request error
55
- - `user_not_found` - User not found
56
- - `too_many_requests` - Too many reset requests
57
- - `email_not_verified` - Email not verified
58
-
59
- ### PasswordResetVerifyEmailTokenResponse
60
- - `success` - Code verified successfully
61
- - `error` - Generic verification error
62
- - `invalid_code` - Invalid code
63
- - `challenge` - MFA challenge required
64
- - `expired` - Code expired
65
- - `code_already_used` - Code already used
66
-
67
- ### PasswordResetVerifyMfaResponse
68
- - `success` - MFA verified successfully during reset
69
- - `error` - Generic MFA verification error
70
- - `invalid_code` - Invalid MFA code
71
- - `expired` - MFA token expired
72
- - `challenge_token_expired` - Challenge token expired
73
- - `too_many_attempts` - Too many verification attempts
74
-
75
- ### PasswordResetConfirmResponse
76
- - `success` - Password reset successfully
77
- - `password_not_strong_enough` - New password doesn't meet criteria
78
- - `error` - Generic confirmation error
79
- - `token_expired` - Reset token expired
80
- - `token_invalid` - Reset token invalid
81
- - `password_recently_used` - Password was recently used
82
-
83
- ## 👤 User
84
-
85
- ### UserResponse
86
- - `success` - User data retrieved successfully
87
- - `error` - Generic data retrieval error
88
- - `unauthorized` - Invalid access token
89
- - `token_expired` - Access token expired
90
- - `user_not_found` - User not found
91
-
92
- ## 🔒 Password Policy
93
-
94
- ### PasswordPolicyResponse
95
- - `success` - Policy retrieved successfully
96
- - `error` - Generic policy retrieval error
97
- - `policy_not_found` - Policy not found
98
- - `unauthorized` - Unauthorized access
99
-
100
- ## 🔄 Refresh Token
101
-
102
- ### RefreshTokenResponse
103
- - `success` - Token refreshed successfully
104
- - `error` - Generic refresh error
105
- - `invalid_refresh_token` - Invalid refresh token
106
- - `refresh_token_expired` - Refresh token expired
107
- - `unauthorized` - Unauthorized access
108
-
109
- ## 💡 Using Status Codes
110
-
111
- Each status allows specific handling in the frontend:
112
-
113
- ```typescript
114
- const loginResult = await authazClient.login(email, password)
115
-
116
- switch (loginResult.status) {
117
- case 'success':
118
- // Redirect to dashboard
119
- break
120
- case 'mfa_required':
121
- // Show MFA screen
122
- showMfaScreen(loginResult.challengeToken)
123
- break
124
- case 'too_many_attempts':
125
- // Show temporary block message
126
- showBlockedMessage()
127
- break
128
- case 'error':
129
- // Show generic error
130
- showError(loginResult.message)
131
- break
132
- }
133
- ```
134
-
135
- ## 🔍 Advantages of Specific Status Codes
136
-
137
- 1. **Precise Handling**: Each scenario can be handled specifically
138
- 2. **Improved UX**: More precise messages and actions for users
139
- 3. **Easier Debugging**: Quick identification of specific issues
140
- 4. **Flexibility**: Adding new statuses without breaking compatibility
141
- 5. **Strong Typing**: TypeScript ensures all cases are handled
package/jest.config.js DELETED
@@ -1,25 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'node',
4
- roots: ['<rootDir>/src'],
5
- testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
6
- transform: {
7
- '^.+\\.ts$': 'ts-jest',
8
- },
9
- moduleFileExtensions: ['ts', 'js', 'json', 'node'],
10
- collectCoverageFrom: [
11
- 'src/**/*.ts',
12
- '!src/**/*.d.ts',
13
- '!src/**/__tests__/**',
14
- ],
15
- coverageDirectory: 'coverage',
16
- coverageReporters: ['text', 'lcov'],
17
- coverageThreshold: {
18
- global: {
19
- branches: 80,
20
- functions: 80,
21
- lines: 80,
22
- statements: 80,
23
- },
24
- },
25
- }
package/src/index.tsx DELETED
@@ -1,34 +0,0 @@
1
- import { authaz, UserProfile, validateToken } from "@authaz/sdk";
2
- import { cookies } from "next/headers";
3
-
4
- type SdkConfig = { debug?: boolean; cookies?: { accessToken?: string } };
5
-
6
- type AuthazArgs = Parameters<typeof authaz>[0];
7
-
8
- export const authazNext = (config: AuthazArgs, args?: SdkConfig) => {
9
- const sdk = authaz(config);
10
- const isDebug = args?.debug || false;
11
-
12
- const getUserSession = (args?: SdkConfig) => {
13
- const accessTokenCookie = args?.cookies?.accessToken || "accessToken";
14
- return async (): Promise<UserProfile | null> => {
15
- try {
16
- const cookieStore = await cookies();
17
- const accessToken = cookieStore.get(accessTokenCookie)?.value;
18
- if (!accessToken || !validateToken(accessToken)) {
19
- return null;
20
- }
21
- const response = await sdk.getMe(accessToken);
22
- if (response.status !== "success") {
23
- return null;
24
- }
25
- return response.user;
26
- } catch (error) {
27
- if (isDebug) console.error("[authaz-sdk] Error on get user session", error);
28
- return null;
29
- }
30
- };
31
- };
32
-
33
- return { getUserSession: getUserSession(args), sdk };
34
- };
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.root.json",
3
- "include": ["src/**/*"],
4
- "exclude": ["node_modules", "dist", "**/*.test.ts"],
5
- "compilerOptions": {
6
- "outDir": "./dist",
7
- "baseUrl": ".",
8
- "paths": {
9
- "*": ["src/*"]
10
- }
11
- }
12
- }
package/tsdown.config.ts DELETED
@@ -1,21 +0,0 @@
1
- import { defineConfig } from "tsdown";
2
-
3
- export default defineConfig({
4
- entry: ["./src/index.tsx"],
5
- clean: true,
6
- format: ["esm"],
7
- dts: true,
8
- outDir: "dist",
9
- treeshake: true,
10
- tsconfig: "tsconfig.json",
11
- external: [
12
- "next",
13
- "react",
14
- "nookies",
15
- "react-dom",
16
- "@remix-run/react",
17
- "react-router-dom",
18
- "react-router",
19
- "@tanstack/react-router",
20
- ],
21
- });