@softdin/shared 0.1.3 → 0.2.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/src/types/auth.ts CHANGED
@@ -1,146 +1,147 @@
1
- export interface Tenant {
2
- id: string
3
- name: string
4
- slug: string
5
- database: string
6
- status: string
7
- has_logo?: boolean
8
- role?: string
9
- }
10
-
11
- export interface User {
12
- id: number
13
- name: string
14
- email: string
15
- is_admin?: boolean
16
- is_superuser?: boolean
17
- is_platform_admin?: boolean
18
- has_avatar?: boolean
19
- requires_data_processing_consent?: boolean
20
- data_processing_consent_accepted_at?: string | null
21
- data_processing_consent_version?: string | null
22
- }
23
-
24
- export interface PublicTenant {
25
- id: string
26
- name: string
27
- slug: string
28
- has_logo?: boolean
29
- }
30
-
31
- export interface RegisterPayload {
32
- name: string
33
- email: string
34
- tenant_mode: 'new' | 'existing'
35
- tenant_slug: string
36
- tenant_name?: string
37
- tenant_domain?: string
38
- migrate?: boolean
39
- seed?: boolean
40
- }
41
-
42
- export interface PublicTenantsResponse {
43
- tenants: PublicTenant[]
44
- }
45
-
46
- export interface RegisterResponse {
47
- message: string
48
- user: User
49
- mail_sent?: boolean
50
- debug_activation_url?: string
51
- debug_mail_error?: string
52
- }
53
-
54
- export interface ForgotPasswordResponse {
55
- message: string
56
- debug_reset_url?: string
57
- debug_mail_error?: string
58
- debug_mail_hint?: string
59
- }
60
-
61
- export interface ResetPasswordPayload {
62
- email: string
63
- token: string
64
- password: string
65
- password_confirmation: string
66
- }
67
-
68
- export interface MessageResponse {
69
- message: string
70
- }
71
-
72
- export interface CentralAdminLoginCredentials {
73
- email: string
74
- password: string
75
- data_processing_consent_accepted?: boolean
76
- }
77
-
78
- export interface LoginCredentials {
79
- email: string
80
- password: string
81
- tenant: string
82
- data_processing_consent_accepted?: boolean
83
- }
84
-
85
- export interface UpdateProfilePayload {
86
- name: string
87
- password?: string
88
- password_confirmation?: string
89
- current_password?: string
90
- }
91
-
92
- export interface ProfileUpdateResponse {
93
- user: User
94
- message: string
95
- }
96
-
97
- export interface ProfilePhotoResponse {
98
- user: User
99
- message: string
100
- avatar_size?: number
101
- }
102
-
103
- export interface CentralLoginResponse {
104
- user: User
105
- tenants: Tenant[]
106
- tenant_selection_required?: boolean
107
- central_access_available?: boolean
108
- }
109
-
110
- export interface AuthResponse {
111
- token: string
112
- user: User
113
- tenants: Tenant[]
114
- active_tenant: Tenant | null
115
- session_mode?: 'tenant' | 'central' | null
116
- }
117
-
118
- export interface MeResponse {
119
- user: User
120
- tenants: Tenant[]
121
- active_tenant: Tenant | null
122
- token_tenant?: Tenant | null
123
- session_mode?: 'tenant' | 'central' | null
124
- }
125
-
126
- export interface TenantLogoResponse {
127
- tenant: Tenant
128
- message: string
129
- logo_size?: number
130
- }
131
-
132
- export interface DataProcessingConsentPolicy {
133
- version: string
134
- title: string
135
- summary: string
136
- paragraphs: string[]
137
- accepted?: boolean
138
- accepted_at?: string | null
139
- accepted_version?: string | null
140
- }
141
-
142
- export interface DataProcessingConsentResponse {
143
- message: string
144
- accepted: boolean
145
- user?: User
146
- }
1
+ export interface Tenant {
2
+ id: string
3
+ name: string
4
+ slug: string
5
+ database: string
6
+ status: string
7
+ has_logo?: boolean
8
+ /** Id de EnumRolTenant (1 owner, 2 admin, 3 member, 4 viewer). */
9
+ role?: number
10
+ }
11
+
12
+ export interface User {
13
+ id: number
14
+ name: string
15
+ email: string
16
+ is_admin?: boolean
17
+ is_superuser?: boolean
18
+ is_platform_admin?: boolean
19
+ has_avatar?: boolean
20
+ requires_data_processing_consent?: boolean
21
+ data_processing_consent_accepted_at?: string | null
22
+ data_processing_consent_version?: string | null
23
+ }
24
+
25
+ export interface PublicTenant {
26
+ id: string
27
+ name: string
28
+ slug: string
29
+ has_logo?: boolean
30
+ }
31
+
32
+ export interface RegisterPayload {
33
+ name: string
34
+ email: string
35
+ tenant_mode: 'new' | 'existing'
36
+ tenant_slug: string
37
+ tenant_name?: string
38
+ tenant_domain?: string
39
+ migrate?: boolean
40
+ seed?: boolean
41
+ }
42
+
43
+ export interface PublicTenantsResponse {
44
+ tenants: PublicTenant[]
45
+ }
46
+
47
+ export interface RegisterResponse {
48
+ message: string
49
+ user: User
50
+ mail_sent?: boolean
51
+ debug_activation_url?: string
52
+ debug_mail_error?: string
53
+ }
54
+
55
+ export interface ForgotPasswordResponse {
56
+ message: string
57
+ debug_reset_url?: string
58
+ debug_mail_error?: string
59
+ debug_mail_hint?: string
60
+ }
61
+
62
+ export interface ResetPasswordPayload {
63
+ email: string
64
+ token: string
65
+ password: string
66
+ password_confirmation: string
67
+ }
68
+
69
+ export interface MessageResponse {
70
+ message: string
71
+ }
72
+
73
+ export interface CentralAdminLoginCredentials {
74
+ email: string
75
+ password: string
76
+ data_processing_consent_accepted?: boolean
77
+ }
78
+
79
+ export interface LoginCredentials {
80
+ email: string
81
+ password: string
82
+ tenant: string
83
+ data_processing_consent_accepted?: boolean
84
+ }
85
+
86
+ export interface UpdateProfilePayload {
87
+ name: string
88
+ password?: string
89
+ password_confirmation?: string
90
+ current_password?: string
91
+ }
92
+
93
+ export interface ProfileUpdateResponse {
94
+ user: User
95
+ message: string
96
+ }
97
+
98
+ export interface ProfilePhotoResponse {
99
+ user: User
100
+ message: string
101
+ avatar_size?: number
102
+ }
103
+
104
+ export interface CentralLoginResponse {
105
+ user: User
106
+ tenants: Tenant[]
107
+ tenant_selection_required?: boolean
108
+ central_access_available?: boolean
109
+ }
110
+
111
+ export interface AuthResponse {
112
+ token: string
113
+ user: User
114
+ tenants: Tenant[]
115
+ active_tenant: Tenant | null
116
+ session_mode?: 'tenant' | 'central' | null
117
+ }
118
+
119
+ export interface MeResponse {
120
+ user: User
121
+ tenants: Tenant[]
122
+ active_tenant: Tenant | null
123
+ token_tenant?: Tenant | null
124
+ session_mode?: 'tenant' | 'central' | null
125
+ }
126
+
127
+ export interface TenantLogoResponse {
128
+ tenant: Tenant
129
+ message: string
130
+ logo_size?: number
131
+ }
132
+
133
+ export interface DataProcessingConsentPolicy {
134
+ version: string
135
+ title: string
136
+ summary: string
137
+ paragraphs: string[]
138
+ accepted?: boolean
139
+ accepted_at?: string | null
140
+ accepted_version?: string | null
141
+ }
142
+
143
+ export interface DataProcessingConsentResponse {
144
+ message: string
145
+ accepted: boolean
146
+ user?: User
147
+ }
@@ -1,55 +1,55 @@
1
- import axios from 'axios'
2
- import { getConnectivityMessage } from './connectivity'
3
-
4
- export * from './connectivity'
5
-
6
- export function extractAxiosErrorMessage(error: unknown, fallback: string): string {
7
- const connectivityMessage = getConnectivityMessage(error)
8
- if (connectivityMessage) {
9
- return connectivityMessage
10
- }
11
-
12
- if (!axios.isAxiosError(error) || !error.response) {
13
- return fallback
14
- }
15
-
16
- const status = error.response.status
17
- const data = error.response.data
18
-
19
- if (typeof data === 'object' && data !== null) {
20
- const payload = data as { message?: string; errors?: Record<string, string[]> }
21
- const firstFieldError = payload.errors
22
- ? Object.values(payload.errors).flat()[0]
23
- : undefined
24
-
25
- if (firstFieldError) {
26
- return firstFieldError
27
- }
28
-
29
- if (typeof payload.message === 'string' && payload.message.trim() !== '') {
30
- return payload.message
31
- }
32
- }
33
-
34
- if (status === 500) {
35
- return 'Error interno del servidor. Revise storage/logs/laravel.log en softdin-api.'
36
- }
37
-
38
- if (status === 503) {
39
- return 'El servicio no está disponible en este momento.'
40
- }
41
-
42
- if (status === 419) {
43
- return 'La sesión expiró. Recargue la página e intente de nuevo.'
44
- }
45
-
46
- if (typeof data === 'string' && data.trim() !== '') {
47
- if (data.includes('<!DOCTYPE html>') || data.includes('<html')) {
48
- return `${fallback} (HTTP ${status}: el servidor respondió HTML, no JSON).`
49
- }
50
-
51
- return fallback
52
- }
53
-
54
- return `${fallback} (HTTP ${status}).`
55
- }
1
+ import axios from 'axios'
2
+ import { getConnectivityMessage } from './connectivity'
3
+
4
+ export * from './connectivity'
5
+
6
+ export function extractAxiosErrorMessage(error: unknown, fallback: string): string {
7
+ const connectivityMessage = getConnectivityMessage(error)
8
+ if (connectivityMessage) {
9
+ return connectivityMessage
10
+ }
11
+
12
+ if (!axios.isAxiosError(error) || !error.response) {
13
+ return fallback
14
+ }
15
+
16
+ const status = error.response.status
17
+ const data = error.response.data
18
+
19
+ if (typeof data === 'object' && data !== null) {
20
+ const payload = data as { message?: string; errors?: Record<string, string[]> }
21
+ const firstFieldError = payload.errors
22
+ ? Object.values(payload.errors).flat()[0]
23
+ : undefined
24
+
25
+ if (firstFieldError) {
26
+ return firstFieldError
27
+ }
28
+
29
+ if (typeof payload.message === 'string' && payload.message.trim() !== '') {
30
+ return payload.message
31
+ }
32
+ }
33
+
34
+ if (status === 500) {
35
+ return 'Error interno del servidor. Revise storage/logs/laravel.log en softdin-api.'
36
+ }
37
+
38
+ if (status === 503) {
39
+ return 'El servicio no está disponible en este momento.'
40
+ }
41
+
42
+ if (status === 419) {
43
+ return 'La sesión expiró. Recargue la página e intente de nuevo.'
44
+ }
45
+
46
+ if (typeof data === 'string' && data.trim() !== '') {
47
+ if (data.includes('<!DOCTYPE html>') || data.includes('<html')) {
48
+ return `${fallback} (HTTP ${status}: el servidor respondió HTML, no JSON).`
49
+ }
50
+
51
+ return fallback
52
+ }
53
+
54
+ return `${fallback} (HTTP ${status}).`
55
+ }
@@ -1,33 +1,33 @@
1
- import axios from 'axios'
2
-
3
- let backendReachable = false
4
-
5
- export function markBackendReachable(): void {
6
- backendReachable = true
7
- }
8
-
9
- export function hasReachedBackend(): boolean {
10
- return backendReachable
11
- }
12
-
13
- function isBrowserOffline(): boolean {
14
- return typeof navigator !== 'undefined' && navigator.onLine === false
15
- }
16
-
17
- export function isConnectivityError(error: unknown): boolean {
18
- if (axios.isAxiosError(error)) {
19
- return !error.response
20
- }
21
-
22
- return isBrowserOffline()
23
- }
24
-
25
- export function getConnectivityMessage(error: unknown): string | null {
26
- if (!isConnectivityError(error)) {
27
- return null
28
- }
29
-
30
- return hasReachedBackend()
31
- ? 'Se perdió la conexión con el servidor. Verifique su red e intente nuevamente.'
32
- : 'No hay conexión con el servidor. Verifique su red e intente nuevamente.'
33
- }
1
+ import axios from 'axios'
2
+
3
+ let backendReachable = false
4
+
5
+ export function markBackendReachable(): void {
6
+ backendReachable = true
7
+ }
8
+
9
+ export function hasReachedBackend(): boolean {
10
+ return backendReachable
11
+ }
12
+
13
+ function isBrowserOffline(): boolean {
14
+ return typeof navigator !== 'undefined' && navigator.onLine === false
15
+ }
16
+
17
+ export function isConnectivityError(error: unknown): boolean {
18
+ if (axios.isAxiosError(error)) {
19
+ return !error.response
20
+ }
21
+
22
+ return isBrowserOffline()
23
+ }
24
+
25
+ export function getConnectivityMessage(error: unknown): string | null {
26
+ if (!isConnectivityError(error)) {
27
+ return null
28
+ }
29
+
30
+ return hasReachedBackend()
31
+ ? 'Se perdió la conexión con el servidor. Verifique su red e intente nuevamente.'
32
+ : 'No hay conexión con el servidor. Verifique su red e intente nuevamente.'
33
+ }