@juanito_boop/w-sdk 0.1.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 +126 -0
- package/dist/client.d.ts +218 -0
- package/dist/client.js +33 -0
- package/dist/http/auth.d.ts +38 -0
- package/dist/http/auth.js +42 -0
- package/dist/index.d.mts +1428 -0
- package/dist/index.d.ts +1428 -0
- package/dist/index.js +716 -0
- package/dist/index.mjs +663 -0
- package/dist/test.quokka.d.ts +1 -0
- package/dist/test.quokka.js +32 -0
- package/dist/types/_helpers.d.ts +5 -0
- package/dist/types/_helpers.js +5 -0
- package/dist/types.d.ts +300 -0
- package/dist/types.js +120 -0
- package/dist/ws/realtime.d.ts +90 -0
- package/dist/ws/realtime.js +103 -0
- package/package.json +40 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ClientOptionsDef: {
|
|
3
|
+
schema: z.ZodObject<{
|
|
4
|
+
baseUrl: z.ZodURL;
|
|
5
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>;
|
|
7
|
+
type: {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
apiKey?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type ClientOptions = typeof ClientOptionsDef.type;
|
|
13
|
+
export type HttpClient = {
|
|
14
|
+
post<T>(path: string, body: unknown): Promise<T>;
|
|
15
|
+
};
|
|
16
|
+
export type Result<T, E = ApiError> = {
|
|
17
|
+
success: true;
|
|
18
|
+
data: T;
|
|
19
|
+
} | {
|
|
20
|
+
success: false;
|
|
21
|
+
error: E;
|
|
22
|
+
};
|
|
23
|
+
export declare const ApiErrorDef: {
|
|
24
|
+
schema: z.ZodObject<{
|
|
25
|
+
message: z.ZodString;
|
|
26
|
+
code: z.ZodOptional<z.ZodString>;
|
|
27
|
+
statusCode: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
details: z.ZodOptional<z.ZodUnknown>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
type: {
|
|
31
|
+
message: string;
|
|
32
|
+
code?: string | undefined;
|
|
33
|
+
statusCode?: number | undefined;
|
|
34
|
+
details?: unknown;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type ApiError = typeof ApiErrorDef.type;
|
|
38
|
+
export declare const LoginDataDef: {
|
|
39
|
+
schema: z.ZodObject<{
|
|
40
|
+
email: z.ZodEmail;
|
|
41
|
+
password: z.ZodString;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
type: {
|
|
44
|
+
email: string;
|
|
45
|
+
password: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export type LoginData = typeof LoginDataDef.type;
|
|
49
|
+
export declare const RegisterDataDef: {
|
|
50
|
+
schema: z.ZodObject<{
|
|
51
|
+
email: z.ZodEmail;
|
|
52
|
+
password: z.ZodString;
|
|
53
|
+
fullName: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
type: {
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
fullName?: string | undefined;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export type RegisterData = typeof RegisterDataDef.type;
|
|
62
|
+
export declare const MagicLinkRequestDataDef: {
|
|
63
|
+
schema: z.ZodObject<{
|
|
64
|
+
email: z.ZodEmail;
|
|
65
|
+
redirectUrl: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
type: {
|
|
68
|
+
email: string;
|
|
69
|
+
redirectUrl?: string | undefined;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export type MagicLinkRequestData = typeof MagicLinkRequestDataDef.type;
|
|
73
|
+
export declare const AuthResponseDef: {
|
|
74
|
+
schema: z.ZodObject<{
|
|
75
|
+
token: z.ZodString;
|
|
76
|
+
user: z.ZodObject<{
|
|
77
|
+
id: z.ZodUUID;
|
|
78
|
+
email: z.ZodEmail;
|
|
79
|
+
fullName: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
apiKey: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
id: z.ZodUUID;
|
|
83
|
+
key: z.ZodString;
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
expiresAt: z.ZodString;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
type: {
|
|
89
|
+
token: string;
|
|
90
|
+
user: {
|
|
91
|
+
id: string;
|
|
92
|
+
email: string;
|
|
93
|
+
fullName?: string | undefined;
|
|
94
|
+
};
|
|
95
|
+
apiKey?: {
|
|
96
|
+
id: string;
|
|
97
|
+
key: string;
|
|
98
|
+
name: string;
|
|
99
|
+
expiresAt: string;
|
|
100
|
+
} | undefined;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export type AuthResponse = typeof AuthResponseDef.type;
|
|
104
|
+
export declare const RealtimeOptionsDef: {
|
|
105
|
+
schema: z.ZodObject<{
|
|
106
|
+
baseUrl: z.ZodString;
|
|
107
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
type: {
|
|
110
|
+
baseUrl: string;
|
|
111
|
+
apiKey?: string | undefined;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export type RealtimeOptions = typeof RealtimeOptionsDef.type;
|
|
115
|
+
export declare const WineDataDef: {
|
|
116
|
+
schema: z.ZodObject<{
|
|
117
|
+
id: z.ZodOptional<z.ZodUUID>;
|
|
118
|
+
}, z.core.$strict>;
|
|
119
|
+
type: {
|
|
120
|
+
id?: string | undefined;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
export type WineData = typeof WineDataDef.type;
|
|
124
|
+
export declare const WineDetailsDef: {
|
|
125
|
+
schema: z.ZodObject<{
|
|
126
|
+
id_detalle: z.ZodOptional<z.ZodUUID>;
|
|
127
|
+
id_vino: z.ZodOptional<z.ZodUUID>;
|
|
128
|
+
notas_cata: z.ZodString;
|
|
129
|
+
tipo_crianza: z.ZodString;
|
|
130
|
+
bodega: z.ZodString;
|
|
131
|
+
}, z.core.$strip>;
|
|
132
|
+
type: {
|
|
133
|
+
notas_cata: string;
|
|
134
|
+
tipo_crianza: string;
|
|
135
|
+
bodega: string;
|
|
136
|
+
id_detalle?: string | undefined;
|
|
137
|
+
id_vino?: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export type WineDetails = typeof WineDetailsDef.type;
|
|
141
|
+
export declare const WineDef: {
|
|
142
|
+
schema: z.ZodObject<{
|
|
143
|
+
id_vino: z.ZodUUID;
|
|
144
|
+
nombre: z.ZodString;
|
|
145
|
+
precio: z.ZodNumber;
|
|
146
|
+
url_imagen: z.ZodString;
|
|
147
|
+
descripcion: z.ZodString;
|
|
148
|
+
nivel_alcohol: z.ZodNumber;
|
|
149
|
+
variedades: z.ZodArray<z.ZodString>;
|
|
150
|
+
pais_importacion: z.ZodString;
|
|
151
|
+
color_vino: z.ZodString;
|
|
152
|
+
stock: z.ZodNumber;
|
|
153
|
+
capacidad: z.ZodNumber;
|
|
154
|
+
is_deleted: z.ZodDefault<z.ZodBoolean>;
|
|
155
|
+
wine_details: z.ZodObject<{
|
|
156
|
+
id_detalle: z.ZodOptional<z.ZodUUID>;
|
|
157
|
+
id_vino: z.ZodOptional<z.ZodUUID>;
|
|
158
|
+
notas_cata: z.ZodString;
|
|
159
|
+
tipo_crianza: z.ZodString;
|
|
160
|
+
bodega: z.ZodString;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
type: {
|
|
164
|
+
id_vino: string;
|
|
165
|
+
nombre: string;
|
|
166
|
+
precio: number;
|
|
167
|
+
url_imagen: string;
|
|
168
|
+
descripcion: string;
|
|
169
|
+
nivel_alcohol: number;
|
|
170
|
+
variedades: string[];
|
|
171
|
+
pais_importacion: string;
|
|
172
|
+
color_vino: string;
|
|
173
|
+
stock: number;
|
|
174
|
+
capacidad: number;
|
|
175
|
+
is_deleted: boolean;
|
|
176
|
+
wine_details: {
|
|
177
|
+
notas_cata: string;
|
|
178
|
+
tipo_crianza: string;
|
|
179
|
+
bodega: string;
|
|
180
|
+
id_detalle?: string | undefined;
|
|
181
|
+
id_vino?: string | undefined;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
export type Wine = typeof WineDef.type;
|
|
186
|
+
export declare const EditWineDef: {
|
|
187
|
+
schema: z.ZodObject<{
|
|
188
|
+
nombre: z.ZodOptional<z.ZodString>;
|
|
189
|
+
precio: z.ZodOptional<z.ZodNumber>;
|
|
190
|
+
url_imagen: z.ZodOptional<z.ZodString>;
|
|
191
|
+
descripcion: z.ZodOptional<z.ZodString>;
|
|
192
|
+
nivel_alcohol: z.ZodOptional<z.ZodNumber>;
|
|
193
|
+
variedades: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
194
|
+
pais_importacion: z.ZodOptional<z.ZodString>;
|
|
195
|
+
color_vino: z.ZodOptional<z.ZodString>;
|
|
196
|
+
stock: z.ZodOptional<z.ZodNumber>;
|
|
197
|
+
capacidad: z.ZodOptional<z.ZodNumber>;
|
|
198
|
+
is_deleted: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
199
|
+
id_vino: z.ZodUUID;
|
|
200
|
+
wine_details: z.ZodOptional<z.ZodObject<{
|
|
201
|
+
id_detalle: z.ZodOptional<z.ZodOptional<z.ZodUUID>>;
|
|
202
|
+
id_vino: z.ZodOptional<z.ZodOptional<z.ZodUUID>>;
|
|
203
|
+
notas_cata: z.ZodOptional<z.ZodString>;
|
|
204
|
+
tipo_crianza: z.ZodOptional<z.ZodString>;
|
|
205
|
+
bodega: z.ZodOptional<z.ZodString>;
|
|
206
|
+
}, z.core.$strip>>;
|
|
207
|
+
}, z.core.$strict>;
|
|
208
|
+
type: {
|
|
209
|
+
id_vino: string;
|
|
210
|
+
nombre?: string | undefined;
|
|
211
|
+
precio?: number | undefined;
|
|
212
|
+
url_imagen?: string | undefined;
|
|
213
|
+
descripcion?: string | undefined;
|
|
214
|
+
nivel_alcohol?: number | undefined;
|
|
215
|
+
variedades?: string[] | undefined;
|
|
216
|
+
pais_importacion?: string | undefined;
|
|
217
|
+
color_vino?: string | undefined;
|
|
218
|
+
stock?: number | undefined;
|
|
219
|
+
capacidad?: number | undefined;
|
|
220
|
+
is_deleted?: boolean | undefined;
|
|
221
|
+
wine_details?: {
|
|
222
|
+
id_detalle?: string | undefined;
|
|
223
|
+
id_vino?: string | undefined;
|
|
224
|
+
notas_cata?: string | undefined;
|
|
225
|
+
tipo_crianza?: string | undefined;
|
|
226
|
+
bodega?: string | undefined;
|
|
227
|
+
} | undefined;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
export type EditWine = typeof EditWineDef.type;
|
|
231
|
+
export declare const CreateWineDef: {
|
|
232
|
+
schema: z.ZodObject<{
|
|
233
|
+
nombre: z.ZodString;
|
|
234
|
+
precio: z.ZodNumber;
|
|
235
|
+
url_imagen: z.ZodOptional<z.ZodString>;
|
|
236
|
+
descripcion: z.ZodOptional<z.ZodString>;
|
|
237
|
+
nivel_alcohol: z.ZodDefault<z.ZodNumber>;
|
|
238
|
+
variedades: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
239
|
+
pais_importacion: z.ZodOptional<z.ZodString>;
|
|
240
|
+
color_vino: z.ZodOptional<z.ZodString>;
|
|
241
|
+
stock: z.ZodDefault<z.ZodNumber>;
|
|
242
|
+
capacidad: z.ZodDefault<z.ZodNumber>;
|
|
243
|
+
is_deleted: z.ZodDefault<z.ZodBoolean>;
|
|
244
|
+
notas_cata: z.ZodOptional<z.ZodString>;
|
|
245
|
+
tipo_crianza: z.ZodOptional<z.ZodString>;
|
|
246
|
+
bodega: z.ZodOptional<z.ZodString>;
|
|
247
|
+
}, z.core.$strip>;
|
|
248
|
+
type: {
|
|
249
|
+
nombre: string;
|
|
250
|
+
precio: number;
|
|
251
|
+
nivel_alcohol: number;
|
|
252
|
+
stock: number;
|
|
253
|
+
capacidad: number;
|
|
254
|
+
is_deleted: boolean;
|
|
255
|
+
url_imagen?: string | undefined;
|
|
256
|
+
descripcion?: string | undefined;
|
|
257
|
+
variedades?: string[] | undefined;
|
|
258
|
+
pais_importacion?: string | undefined;
|
|
259
|
+
color_vino?: string | undefined;
|
|
260
|
+
notas_cata?: string | undefined;
|
|
261
|
+
tipo_crianza?: string | undefined;
|
|
262
|
+
bodega?: string | undefined;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
export type CreateWine = typeof CreateWineDef.type;
|
|
266
|
+
export declare const BulkInsertWinesDef: {
|
|
267
|
+
schema: z.ZodArray<z.ZodObject<{
|
|
268
|
+
nombre: z.ZodString;
|
|
269
|
+
precio: z.ZodNumber;
|
|
270
|
+
url_imagen: z.ZodOptional<z.ZodString>;
|
|
271
|
+
descripcion: z.ZodOptional<z.ZodString>;
|
|
272
|
+
nivel_alcohol: z.ZodDefault<z.ZodNumber>;
|
|
273
|
+
variedades: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
274
|
+
pais_importacion: z.ZodOptional<z.ZodString>;
|
|
275
|
+
color_vino: z.ZodOptional<z.ZodString>;
|
|
276
|
+
stock: z.ZodDefault<z.ZodNumber>;
|
|
277
|
+
capacidad: z.ZodDefault<z.ZodNumber>;
|
|
278
|
+
is_deleted: z.ZodDefault<z.ZodBoolean>;
|
|
279
|
+
notas_cata: z.ZodOptional<z.ZodString>;
|
|
280
|
+
tipo_crianza: z.ZodOptional<z.ZodString>;
|
|
281
|
+
bodega: z.ZodOptional<z.ZodString>;
|
|
282
|
+
}, z.core.$strip>>;
|
|
283
|
+
type: {
|
|
284
|
+
nombre: string;
|
|
285
|
+
precio: number;
|
|
286
|
+
nivel_alcohol: number;
|
|
287
|
+
stock: number;
|
|
288
|
+
capacidad: number;
|
|
289
|
+
is_deleted: boolean;
|
|
290
|
+
url_imagen?: string | undefined;
|
|
291
|
+
descripcion?: string | undefined;
|
|
292
|
+
variedades?: string[] | undefined;
|
|
293
|
+
pais_importacion?: string | undefined;
|
|
294
|
+
color_vino?: string | undefined;
|
|
295
|
+
notas_cata?: string | undefined;
|
|
296
|
+
tipo_crianza?: string | undefined;
|
|
297
|
+
bodega?: string | undefined;
|
|
298
|
+
}[];
|
|
299
|
+
};
|
|
300
|
+
export type BulkInsertWines = typeof BulkInsertWinesDef.type;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineSchema } from './types/_helpers';
|
|
3
|
+
/* ============================================================================
|
|
4
|
+
* Core / Client
|
|
5
|
+
* ========================================================================== */
|
|
6
|
+
export const ClientOptionsDef = defineSchema(z.object({
|
|
7
|
+
baseUrl: z.url('baseUrl debe ser una URL válida'),
|
|
8
|
+
apiKey: z.string().optional(),
|
|
9
|
+
}));
|
|
10
|
+
export const ApiErrorDef = defineSchema(z.object({
|
|
11
|
+
message: z.string(),
|
|
12
|
+
code: z.string().optional(),
|
|
13
|
+
statusCode: z.number().optional(),
|
|
14
|
+
details: z.unknown().optional(),
|
|
15
|
+
}));
|
|
16
|
+
/* ============================================================================
|
|
17
|
+
* Auth
|
|
18
|
+
* ========================================================================== */
|
|
19
|
+
export const LoginDataDef = defineSchema(z.object({
|
|
20
|
+
email: z.email('Email inválido'),
|
|
21
|
+
password: z.string().min(1, 'Password es requerido'),
|
|
22
|
+
}));
|
|
23
|
+
export const RegisterDataDef = defineSchema(z.object({
|
|
24
|
+
email: z.email('Email inválido'),
|
|
25
|
+
password: z.string().min(6, 'Password debe tener al menos 6 caracteres'),
|
|
26
|
+
fullName: z.string().optional(),
|
|
27
|
+
}));
|
|
28
|
+
export const MagicLinkRequestDataDef = defineSchema(z.object({
|
|
29
|
+
email: z.email('Email inválido'),
|
|
30
|
+
redirectUrl: z.string().url().optional(),
|
|
31
|
+
}));
|
|
32
|
+
export const AuthResponseDef = defineSchema(z.object({
|
|
33
|
+
token: z.string(),
|
|
34
|
+
user: z.object({
|
|
35
|
+
id: z.uuid(),
|
|
36
|
+
email: z.email(),
|
|
37
|
+
fullName: z.string().optional(),
|
|
38
|
+
}),
|
|
39
|
+
apiKey: z.object({
|
|
40
|
+
id: z.uuid(),
|
|
41
|
+
key: z.string(),
|
|
42
|
+
name: z.string(),
|
|
43
|
+
expiresAt: z.string().datetime(),
|
|
44
|
+
}).optional(),
|
|
45
|
+
}));
|
|
46
|
+
/* ============================================================================
|
|
47
|
+
* Realtime
|
|
48
|
+
* ========================================================================== */
|
|
49
|
+
export const RealtimeOptionsDef = defineSchema(z.object({
|
|
50
|
+
baseUrl: z.string().url(),
|
|
51
|
+
apiKey: z.string().optional(),
|
|
52
|
+
}));
|
|
53
|
+
/* ============================================================================
|
|
54
|
+
* Wine – Base
|
|
55
|
+
* ========================================================================== */
|
|
56
|
+
export const WineDataDef = defineSchema(z.object({
|
|
57
|
+
id: z.uuid().optional(),
|
|
58
|
+
}).strict());
|
|
59
|
+
/* ============================================================================
|
|
60
|
+
* Wine – Details
|
|
61
|
+
* ========================================================================== */
|
|
62
|
+
export const WineDetailsDef = defineSchema(z.object({
|
|
63
|
+
id_detalle: z.uuid().optional(),
|
|
64
|
+
id_vino: z.uuid().optional(),
|
|
65
|
+
notas_cata: z.string(),
|
|
66
|
+
tipo_crianza: z.string(),
|
|
67
|
+
bodega: z.string(),
|
|
68
|
+
}));
|
|
69
|
+
/* ============================================================================
|
|
70
|
+
* Wine – Read
|
|
71
|
+
* ========================================================================== */
|
|
72
|
+
export const WineDef = defineSchema(z.object({
|
|
73
|
+
id_vino: z.uuid(),
|
|
74
|
+
nombre: z.string(),
|
|
75
|
+
precio: z.number().int(),
|
|
76
|
+
url_imagen: z.string(),
|
|
77
|
+
descripcion: z.string(),
|
|
78
|
+
nivel_alcohol: z.number(),
|
|
79
|
+
variedades: z.array(z.string()),
|
|
80
|
+
pais_importacion: z.string(),
|
|
81
|
+
color_vino: z.string(),
|
|
82
|
+
stock: z.number().int(),
|
|
83
|
+
capacidad: z.number().int(),
|
|
84
|
+
is_deleted: z.boolean().default(false),
|
|
85
|
+
wine_details: WineDetailsDef.schema,
|
|
86
|
+
}));
|
|
87
|
+
/* ============================================================================
|
|
88
|
+
* Wine – Update
|
|
89
|
+
* ========================================================================== */
|
|
90
|
+
export const EditWineDef = defineSchema(WineDef.schema
|
|
91
|
+
.omit({ wine_details: true })
|
|
92
|
+
.partial()
|
|
93
|
+
.extend({
|
|
94
|
+
id_vino: z.uuid(),
|
|
95
|
+
wine_details: WineDetailsDef.schema.partial().optional(),
|
|
96
|
+
})
|
|
97
|
+
.strict());
|
|
98
|
+
/* ============================================================================
|
|
99
|
+
* Wine – Create
|
|
100
|
+
* ========================================================================== */
|
|
101
|
+
export const CreateWineDef = defineSchema(z.object({
|
|
102
|
+
nombre: z.string().min(1, 'El campo "nombre" es obligatorio'),
|
|
103
|
+
precio: z.number().int().positive('El precio debe ser positivo'),
|
|
104
|
+
url_imagen: z.string().optional(),
|
|
105
|
+
descripcion: z.string().optional(),
|
|
106
|
+
nivel_alcohol: z.number().default(0),
|
|
107
|
+
variedades: z.array(z.string()).optional(),
|
|
108
|
+
pais_importacion: z.string().optional(),
|
|
109
|
+
color_vino: z.string().optional(),
|
|
110
|
+
stock: z.number().int().default(0),
|
|
111
|
+
capacidad: z.number().int().default(750),
|
|
112
|
+
is_deleted: z.boolean().default(false),
|
|
113
|
+
notas_cata: z.string().optional(),
|
|
114
|
+
tipo_crianza: z.string().optional(),
|
|
115
|
+
bodega: z.string().optional(),
|
|
116
|
+
}));
|
|
117
|
+
/* ============================================================================
|
|
118
|
+
* Wine – Bulk
|
|
119
|
+
* ========================================================================== */
|
|
120
|
+
export const BulkInsertWinesDef = defineSchema(z.array(CreateWineDef.schema));
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Result, CreateWine, EditWine, RealtimeOptions } from '../types';
|
|
2
|
+
export declare function createRealtime(opts: RealtimeOptions): {
|
|
3
|
+
connect: () => Promise<void>;
|
|
4
|
+
disconnect: () => void;
|
|
5
|
+
setApiKey: (key?: string) => void;
|
|
6
|
+
getWines: () => Promise<Result<{
|
|
7
|
+
id_vino: string;
|
|
8
|
+
nombre: string;
|
|
9
|
+
precio: number;
|
|
10
|
+
url_imagen: string;
|
|
11
|
+
descripcion: string;
|
|
12
|
+
nivel_alcohol: number;
|
|
13
|
+
variedades: string[];
|
|
14
|
+
pais_importacion: string;
|
|
15
|
+
color_vino: string;
|
|
16
|
+
stock: number;
|
|
17
|
+
capacidad: number;
|
|
18
|
+
is_deleted: boolean;
|
|
19
|
+
wine_details: {
|
|
20
|
+
notas_cata: string;
|
|
21
|
+
tipo_crianza: string;
|
|
22
|
+
bodega: string;
|
|
23
|
+
id_detalle?: string | undefined;
|
|
24
|
+
id_vino?: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
}[]>>;
|
|
27
|
+
insertWine: (data: CreateWine) => Promise<Result<{
|
|
28
|
+
id_vino: string;
|
|
29
|
+
nombre: string;
|
|
30
|
+
precio: number;
|
|
31
|
+
url_imagen: string;
|
|
32
|
+
descripcion: string;
|
|
33
|
+
nivel_alcohol: number;
|
|
34
|
+
variedades: string[];
|
|
35
|
+
pais_importacion: string;
|
|
36
|
+
color_vino: string;
|
|
37
|
+
stock: number;
|
|
38
|
+
capacidad: number;
|
|
39
|
+
is_deleted: boolean;
|
|
40
|
+
wine_details: {
|
|
41
|
+
notas_cata: string;
|
|
42
|
+
tipo_crianza: string;
|
|
43
|
+
bodega: string;
|
|
44
|
+
id_detalle?: string | undefined;
|
|
45
|
+
id_vino?: string | undefined;
|
|
46
|
+
};
|
|
47
|
+
}>>;
|
|
48
|
+
insertBulkWines: (data: CreateWine[]) => Promise<Result<{
|
|
49
|
+
id_vino: string;
|
|
50
|
+
nombre: string;
|
|
51
|
+
precio: number;
|
|
52
|
+
url_imagen: string;
|
|
53
|
+
descripcion: string;
|
|
54
|
+
nivel_alcohol: number;
|
|
55
|
+
variedades: string[];
|
|
56
|
+
pais_importacion: string;
|
|
57
|
+
color_vino: string;
|
|
58
|
+
stock: number;
|
|
59
|
+
capacidad: number;
|
|
60
|
+
is_deleted: boolean;
|
|
61
|
+
wine_details: {
|
|
62
|
+
notas_cata: string;
|
|
63
|
+
tipo_crianza: string;
|
|
64
|
+
bodega: string;
|
|
65
|
+
id_detalle?: string | undefined;
|
|
66
|
+
id_vino?: string | undefined;
|
|
67
|
+
};
|
|
68
|
+
}[]>>;
|
|
69
|
+
editWine: (data: EditWine) => Promise<Result<{
|
|
70
|
+
id_vino: string;
|
|
71
|
+
nombre: string;
|
|
72
|
+
precio: number;
|
|
73
|
+
url_imagen: string;
|
|
74
|
+
descripcion: string;
|
|
75
|
+
nivel_alcohol: number;
|
|
76
|
+
variedades: string[];
|
|
77
|
+
pais_importacion: string;
|
|
78
|
+
color_vino: string;
|
|
79
|
+
stock: number;
|
|
80
|
+
capacidad: number;
|
|
81
|
+
is_deleted: boolean;
|
|
82
|
+
wine_details: {
|
|
83
|
+
notas_cata: string;
|
|
84
|
+
tipo_crianza: string;
|
|
85
|
+
bodega: string;
|
|
86
|
+
id_detalle?: string | undefined;
|
|
87
|
+
id_vino?: string | undefined;
|
|
88
|
+
};
|
|
89
|
+
}>>;
|
|
90
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { io } from 'socket.io-client';
|
|
2
|
+
export function createRealtime(opts) {
|
|
3
|
+
let socket = null;
|
|
4
|
+
let apiKey = opts.apiKey;
|
|
5
|
+
function connect() {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
if (socket?.connected) {
|
|
8
|
+
resolve();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const auth = apiKey ? { apiKey } : undefined;
|
|
12
|
+
const extraHeaders = apiKey ? { 'x-api-key': apiKey } : undefined;
|
|
13
|
+
socket = io(opts.baseUrl, {
|
|
14
|
+
path: '/ws',
|
|
15
|
+
transports: ['websocket', 'polling'],
|
|
16
|
+
auth,
|
|
17
|
+
extraHeaders,
|
|
18
|
+
});
|
|
19
|
+
const handleConnect = () => {
|
|
20
|
+
socket?.off('connect', handleConnect);
|
|
21
|
+
socket?.off('connect_error', handleError);
|
|
22
|
+
resolve();
|
|
23
|
+
};
|
|
24
|
+
const handleError = (error) => {
|
|
25
|
+
socket?.off('connect', handleConnect);
|
|
26
|
+
socket?.off('connect_error', handleError);
|
|
27
|
+
reject(error);
|
|
28
|
+
};
|
|
29
|
+
socket.on('connect', handleConnect);
|
|
30
|
+
socket.on('connect_error', handleError);
|
|
31
|
+
// Timeout de seguridad
|
|
32
|
+
const timeoutId = setTimeout(() => {
|
|
33
|
+
socket?.off('connect', handleConnect);
|
|
34
|
+
socket?.off('connect_error', handleError);
|
|
35
|
+
reject(new Error('Connection timeout'));
|
|
36
|
+
}, 5000);
|
|
37
|
+
// Limpiar timeout cuando se resuelva
|
|
38
|
+
Promise.resolve().then(() => {
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function disconnect() {
|
|
44
|
+
socket?.disconnect();
|
|
45
|
+
socket = null;
|
|
46
|
+
}
|
|
47
|
+
function setApiKey(key) {
|
|
48
|
+
apiKey = key;
|
|
49
|
+
if (socket) {
|
|
50
|
+
disconnect();
|
|
51
|
+
connect();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function emitAck(event, payload) {
|
|
55
|
+
if (!socket) {
|
|
56
|
+
return Promise.resolve({
|
|
57
|
+
success: false,
|
|
58
|
+
error: {
|
|
59
|
+
message: 'Socket no conectado',
|
|
60
|
+
code: 'SOCKET_NOT_CONNECTED',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
socket
|
|
66
|
+
.timeout(10000)
|
|
67
|
+
.emit(event, payload, (err, res) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
resolve({
|
|
70
|
+
success: false,
|
|
71
|
+
error: {
|
|
72
|
+
message: err.message ?? 'Socket error',
|
|
73
|
+
code: err.code ?? 'SOCKET_ERROR',
|
|
74
|
+
details: err,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (res?.error) {
|
|
80
|
+
resolve({
|
|
81
|
+
success: false,
|
|
82
|
+
error: {
|
|
83
|
+
message: res.error.message,
|
|
84
|
+
code: res.error.code,
|
|
85
|
+
details: res.error,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
resolve({ success: true, data: res });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
connect,
|
|
96
|
+
disconnect,
|
|
97
|
+
setApiKey,
|
|
98
|
+
getWines: () => emitAck('get_wines', undefined),
|
|
99
|
+
insertWine: (data) => emitAck('insert_wine', data),
|
|
100
|
+
insertBulkWines: (data) => emitAck('insert_bulk_wines', data),
|
|
101
|
+
editWine: (data) => emitAck('edit_wine', data),
|
|
102
|
+
};
|
|
103
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@juanito_boop/w-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK oficial para la API de juanito_boop",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
17
|
+
"dev": "tsup src/index.ts --watch --format esm,cjs --dts",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"test": "jest --runInBand --detectOpenHandles",
|
|
20
|
+
"release": "npm publish --access public"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"sdk",
|
|
24
|
+
"api",
|
|
25
|
+
"nestjs",
|
|
26
|
+
"rest"
|
|
27
|
+
],
|
|
28
|
+
"author": "juanito_boop",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"socket.io-client": "^4.7.5",
|
|
32
|
+
"zod": "^4.3.6"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/jest": "^30.0.0",
|
|
36
|
+
"ts-jest": "^29.4.6",
|
|
37
|
+
"tsup": "^8.0.1",
|
|
38
|
+
"typescript": "^5.3.3"
|
|
39
|
+
}
|
|
40
|
+
}
|