@utilia-os/sdk-js 1.0.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 ADDED
@@ -0,0 +1,187 @@
1
+ # @utilia-os/sdk-js
2
+
3
+ SDK JavaScript/TypeScript para integrar aplicaciones externas con UTILIA OS.
4
+
5
+ ## Instalacion
6
+
7
+ ```bash
8
+ npm install @utilia-os/sdk-js
9
+ ```
10
+
11
+ ## Configuracion
12
+
13
+ ```typescript
14
+ import { UtiliaSDK } from '@utilia-os/sdk-js';
15
+
16
+ const sdk = new UtiliaSDK({
17
+ baseURL: 'https://os.utilia.ai/api',
18
+ apiKey: 'tu-api-key',
19
+ timeout: 30000, // opcional, default: 30000ms
20
+ debug: false, // opcional, habilita logs de debug
21
+ });
22
+ ```
23
+
24
+ ## Uso
25
+
26
+ ### Identificar Usuario
27
+
28
+ Antes de crear tickets, identifica al usuario en tu sistema:
29
+
30
+ ```typescript
31
+ const user = await sdk.users.identify({
32
+ externalId: 'user-123', // ID unico en tu sistema (requerido)
33
+ email: 'user@example.com', // opcional
34
+ name: 'Juan Perez', // opcional
35
+ avatarUrl: 'https://...', // opcional
36
+ metadata: { // opcional, datos adicionales
37
+ plan: 'premium',
38
+ company: 'Acme Inc',
39
+ },
40
+ });
41
+ ```
42
+
43
+ ### Crear Ticket
44
+
45
+ ```typescript
46
+ const ticket = await sdk.tickets.create({
47
+ user: {
48
+ externalId: 'user-123',
49
+ email: 'user@example.com',
50
+ name: 'Juan Perez',
51
+ },
52
+ title: 'Problema con la facturacion',
53
+ description: 'No puedo ver mis facturas del mes pasado...',
54
+ category: 'PROBLEMA', // CONSULTA | PROBLEMA | SUGERENCIA | OTRO
55
+ priority: 'MEDIA', // BAJA | MEDIA | ALTA | CRITICA
56
+ context: { // opcional
57
+ url: window.location.href,
58
+ appVersion: '1.2.3',
59
+ browserInfo: navigator.userAgent,
60
+ },
61
+ });
62
+
63
+ console.log(ticket.ticketKey); // APP-0001
64
+ console.log(ticket.id); // uuid del ticket
65
+ ```
66
+
67
+ ### Listar Tickets
68
+
69
+ ```typescript
70
+ const result = await sdk.tickets.list('user-123', {
71
+ status: 'OPEN', // OPEN | IN_REVIEW | RESOLVED | CLOSED
72
+ page: 1,
73
+ limit: 20,
74
+ });
75
+
76
+ console.log(result.data); // Array de tickets
77
+ console.log(result.pagination.total); // Total de tickets
78
+ ```
79
+
80
+ ### Obtener Detalle de Ticket
81
+
82
+ ```typescript
83
+ const ticket = await sdk.tickets.get('ticket-uuid', 'user-123');
84
+
85
+ console.log(ticket.title);
86
+ console.log(ticket.messages); // Array de mensajes
87
+ ```
88
+
89
+ ### Agregar Mensaje
90
+
91
+ ```typescript
92
+ const message = await sdk.tickets.addMessage('ticket-uuid', 'user-123', {
93
+ content: 'Gracias por la respuesta, el problema ya fue resuelto.',
94
+ });
95
+ ```
96
+
97
+ ### Cerrar/Reabrir Ticket
98
+
99
+ ```typescript
100
+ // Cerrar
101
+ await sdk.tickets.close('ticket-uuid', 'user-123');
102
+
103
+ // Reabrir
104
+ await sdk.tickets.reopen('ticket-uuid', 'user-123');
105
+ ```
106
+
107
+ ### Obtener Mensajes No Leidos
108
+
109
+ ```typescript
110
+ const { count } = await sdk.tickets.getUnreadCount('user-123');
111
+ if (count > 0) {
112
+ console.log(`Tienes ${count} mensajes sin leer`);
113
+ }
114
+ ```
115
+
116
+ ## Manejo de Errores
117
+
118
+ ```typescript
119
+ import { UtiliaSDK, UtiliaSDKError, ErrorCode } from '@utilia-os/sdk-js';
120
+
121
+ try {
122
+ await sdk.tickets.create({ ... });
123
+ } catch (error) {
124
+ if (error instanceof UtiliaSDKError) {
125
+ switch (error.code) {
126
+ case ErrorCode.UNAUTHORIZED:
127
+ console.error('API Key invalida');
128
+ break;
129
+ case ErrorCode.RATE_LIMITED:
130
+ console.error('Demasiadas peticiones, espera antes de reintentar');
131
+ break;
132
+ case ErrorCode.VALIDATION_ERROR:
133
+ console.error('Datos invalidos:', error.message);
134
+ break;
135
+ case ErrorCode.NOT_FOUND:
136
+ console.error('Recurso no encontrado');
137
+ break;
138
+ default:
139
+ console.error('Error:', error.message);
140
+ }
141
+
142
+ // Verificar si se puede reintentar
143
+ if (error.isRetryable()) {
144
+ // Implementar logica de reintento
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ ## Tipos
151
+
152
+ El SDK exporta todos los tipos TypeScript necesarios:
153
+
154
+ ```typescript
155
+ import type {
156
+ // Configuracion
157
+ UtiliaSDKConfig,
158
+
159
+ // Tickets
160
+ CreateTicketInput,
161
+ TicketFilters,
162
+ AddMessageInput,
163
+ CreatedTicket,
164
+ TicketListItem,
165
+ TicketDetail,
166
+ TicketMessage,
167
+
168
+ // Usuarios
169
+ IdentifyUserInput,
170
+ ExternalUser,
171
+
172
+ // Comunes
173
+ TicketStatus,
174
+ TicketCategory,
175
+ TicketPriority,
176
+ PaginatedResponse,
177
+ } from '@utilia-os/sdk-js';
178
+ ```
179
+
180
+ ## Requisitos
181
+
182
+ - Node.js >= 18.0.0
183
+ - TypeScript >= 4.7 (opcional, para tipos)
184
+
185
+ ## Licencia
186
+
187
+ MIT