@livex/contracts 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 ADDED
@@ -0,0 +1,11 @@
1
+ # @livex/contracts
2
+
3
+ Contratos compartidos (OpenAPI v1 + esquemas de eventos) del MVP.
4
+
5
+ ## Uso
6
+
7
+ ```ts
8
+ import { openapi, BookingConfirmed } from "@livex/contracts";
9
+
10
+ console.log(openapi.info.version); // "1.0.0"
11
+ console.log(BookingConfirmed.title); // "booking.confirmed"
@@ -0,0 +1,83 @@
1
+ // src/validators.ts
2
+ import Ajv from "ajv";
3
+ import addFormats from "ajv-formats";
4
+
5
+ // messages/booking.confirmed.schema.json
6
+ var booking_confirmed_schema_default = {
7
+ $schema: "https://json-schema.org/draft/2020-12/schema",
8
+ $id: "https://contracts.livex.app/messages/booking.confirmed.schema.json",
9
+ title: "booking.confirmed",
10
+ type: "object",
11
+ properties: {
12
+ eventType: { const: "booking.confirmed" },
13
+ eventId: { type: "string", format: "uuid" },
14
+ occurredAt: { type: "string", format: "date-time" },
15
+ booking: {
16
+ type: "object",
17
+ properties: {
18
+ id: { type: "string", format: "uuid" },
19
+ experienceId: { type: "string", format: "uuid" },
20
+ slotId: { type: "string", format: "uuid" },
21
+ quantity: { type: "integer", minimum: 1 },
22
+ totalInCents: { type: "integer", minimum: 0 },
23
+ currency: { type: "string", minLength: 3, maxLength: 3 }
24
+ },
25
+ required: ["id", "experienceId", "slotId", "quantity", "totalInCents", "currency"]
26
+ },
27
+ payment: {
28
+ type: "object",
29
+ properties: {
30
+ provider: { type: "string" },
31
+ providerRef: { type: "string" }
32
+ },
33
+ required: ["provider", "providerRef"]
34
+ },
35
+ request_id: { type: "string" }
36
+ },
37
+ required: ["eventType", "eventId", "occurredAt", "booking", "payment"],
38
+ additionalProperties: false
39
+ };
40
+
41
+ // messages/webhook.payment.received.schema.json
42
+ var webhook_payment_received_schema_default = {
43
+ $schema: "https://json-schema.org/draft/2020-12/schema",
44
+ $id: "https://contracts.livex.app/messages/webhook.payment.received.schema.json",
45
+ title: "webhook.payment.received",
46
+ type: "object",
47
+ properties: {
48
+ eventType: { const: "webhook.payment.received" },
49
+ eventId: { type: "string", format: "uuid" },
50
+ provider: { type: "string", enum: ["wompi", "epayco", "other"] },
51
+ provider_event_id: { type: "string" },
52
+ payload: { type: "object" },
53
+ receivedAt: { type: "string", format: "date-time" }
54
+ },
55
+ required: ["eventType", "eventId", "provider", "provider_event_id", "payload", "receivedAt"],
56
+ additionalProperties: false
57
+ };
58
+
59
+ // src/validators.ts
60
+ var ajv = new Ajv({ allErrors: true, strict: true });
61
+ addFormats(ajv);
62
+ var _validateBookingConfirmed = ajv.compile(booking_confirmed_schema_default);
63
+ var _validateWebhookPaymentReceived = ajv.compile(webhook_payment_received_schema_default);
64
+ function validateBookingConfirmed(payload) {
65
+ const ok = _validateBookingConfirmed(payload);
66
+ return { ok, errors: _validateBookingConfirmed.errors ?? null };
67
+ }
68
+ function validateWebhookPaymentReceived(payload) {
69
+ const ok = _validateWebhookPaymentReceived(payload);
70
+ return { ok, errors: _validateWebhookPaymentReceived.errors ?? null };
71
+ }
72
+ var validators = {
73
+ bookingConfirmed: validateBookingConfirmed,
74
+ webhookPaymentReceived: validateWebhookPaymentReceived
75
+ };
76
+
77
+ export {
78
+ booking_confirmed_schema_default,
79
+ webhook_payment_received_schema_default,
80
+ validateBookingConfirmed,
81
+ validateWebhookPaymentReceived,
82
+ validators
83
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,436 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ BookingConfirmed: () => BookingConfirmed,
34
+ DB: () => types_db_exports,
35
+ WebhookPaymentReceived: () => WebhookPaymentReceived,
36
+ openapi: () => livex_v1_default,
37
+ validateBookingConfirmed: () => validateBookingConfirmed,
38
+ validateWebhookPaymentReceived: () => validateWebhookPaymentReceived,
39
+ validators: () => validators
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // openapi/livex.v1.json
44
+ var livex_v1_default = {
45
+ openapi: "3.1.0",
46
+ info: {
47
+ title: "LIVEX API",
48
+ version: "1.0.0",
49
+ description: "Contratos v1 del MVP: cat\xE1logo, disponibilidad, bookings y webhooks de pago.",
50
+ license: { name: "MIT", url: "https://opensource.org/licenses/MIT" }
51
+ },
52
+ servers: [{ url: "https://api.livex.app/v1" }],
53
+ security: [
54
+ { BearerAuth: [] }
55
+ ],
56
+ paths: {
57
+ "/experiences": {
58
+ get: {
59
+ summary: "Listar experiencias",
60
+ operationId: "listExperiences",
61
+ security: [],
62
+ parameters: [
63
+ { name: "q", in: "query", schema: { type: "string" } },
64
+ { name: "categoryId", in: "query", schema: { type: "string", format: "uuid" } },
65
+ { name: "limit", in: "query", schema: { type: "integer", minimum: 1, maximum: 100, default: 20 } },
66
+ { name: "offset", in: "query", schema: { type: "integer", minimum: 0, default: 0 } }
67
+ ],
68
+ responses: {
69
+ "200": {
70
+ description: "OK",
71
+ content: {
72
+ "application/json": {
73
+ schema: {
74
+ type: "object",
75
+ properties: {
76
+ items: { type: "array", items: { $ref: "#/components/schemas/ExperienceSummary" } },
77
+ total: { type: "integer" }
78
+ },
79
+ required: ["items", "total"]
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "400": { $ref: "#/components/responses/BadRequest" }
85
+ }
86
+ }
87
+ },
88
+ "/experiences/{experienceId}": {
89
+ get: {
90
+ summary: "Detalle de experiencia",
91
+ operationId: "getExperience",
92
+ security: [],
93
+ parameters: [
94
+ { name: "experienceId", in: "path", required: true, schema: { type: "string", format: "uuid" } }
95
+ ],
96
+ responses: {
97
+ "200": {
98
+ description: "OK",
99
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Experience" } } }
100
+ },
101
+ "400": { $ref: "#/components/responses/BadRequest" },
102
+ "404": { $ref: "#/components/responses/NotFound" }
103
+ }
104
+ }
105
+ },
106
+ "/availability": {
107
+ get: {
108
+ summary: "Consultar disponibilidad por experiencia y fecha",
109
+ operationId: "getAvailability",
110
+ security: [],
111
+ parameters: [
112
+ { name: "experienceId", in: "query", required: true, schema: { type: "string", format: "uuid" } },
113
+ { name: "date", in: "query", required: true, schema: { type: "string", format: "date" } }
114
+ ],
115
+ responses: {
116
+ "200": {
117
+ description: "OK",
118
+ content: {
119
+ "application/json": {
120
+ schema: { type: "array", items: { $ref: "#/components/schemas/AvailabilitySlot" } }
121
+ }
122
+ }
123
+ },
124
+ "400": { $ref: "#/components/responses/BadRequest" }
125
+ }
126
+ }
127
+ },
128
+ "/bookings": {
129
+ post: {
130
+ summary: "Crear booking (pending + lock de inventario)",
131
+ operationId: "createBooking",
132
+ parameters: [
133
+ {
134
+ name: "Idempotency-Key",
135
+ in: "header",
136
+ required: true,
137
+ description: "Requerido para evitar duplicados en creaci\xF3n.",
138
+ schema: { type: "string", maxLength: 128 }
139
+ }
140
+ ],
141
+ requestBody: {
142
+ required: true,
143
+ content: { "application/json": { schema: { $ref: "#/components/schemas/CreateBookingInput" } } }
144
+ },
145
+ responses: {
146
+ "201": {
147
+ description: "Creado",
148
+ headers: {
149
+ Location: { schema: { type: "string" }, description: "URL del booking creado." }
150
+ },
151
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Booking" } } }
152
+ },
153
+ "400": { $ref: "#/components/responses/BadRequest" },
154
+ "409": { $ref: "#/components/responses/Conflict" },
155
+ "422": { $ref: "#/components/responses/UnprocessableEntity" }
156
+ }
157
+ }
158
+ },
159
+ "/bookings/{bookingId}": {
160
+ get: {
161
+ summary: "Obtener booking por ID",
162
+ operationId: "getBooking",
163
+ parameters: [
164
+ { name: "bookingId", in: "path", required: true, schema: { type: "string", format: "uuid" } }
165
+ ],
166
+ responses: {
167
+ "200": { description: "OK", content: { "application/json": { schema: { $ref: "#/components/schemas/Booking" } } } },
168
+ "400": { $ref: "#/components/responses/BadRequest" },
169
+ "404": { $ref: "#/components/responses/NotFound" }
170
+ }
171
+ }
172
+ },
173
+ "/webhooks/payments/{provider}": {
174
+ post: {
175
+ summary: "Webhook de pagos (firma validada por API)",
176
+ operationId: "paymentsWebhook",
177
+ security: [],
178
+ parameters: [
179
+ { name: "provider", in: "path", required: true, schema: { type: "string", enum: ["wompi", "epayco", "other"] } }
180
+ ],
181
+ requestBody: {
182
+ required: true,
183
+ content: {
184
+ "application/json": { schema: { $ref: "#/components/schemas/PaymentWebhookPayload" } }
185
+ }
186
+ },
187
+ responses: {
188
+ "202": { description: "Aceptado para procesamiento as\xEDncrono" },
189
+ "400": { $ref: "#/components/responses/BadRequest" },
190
+ "401": { $ref: "#/components/responses/Unauthorized" }
191
+ }
192
+ }
193
+ }
194
+ },
195
+ components: {
196
+ securitySchemes: {
197
+ BearerAuth: {
198
+ type: "http",
199
+ scheme: "bearer",
200
+ bearerFormat: "JWT"
201
+ }
202
+ },
203
+ schemas: {
204
+ UUID: { type: "string", format: "uuid" },
205
+ Money: {
206
+ type: "object",
207
+ properties: {
208
+ amount: { type: "integer", minimum: 0, description: "Centavos" },
209
+ currency: { type: "string", minLength: 3, maxLength: 3, example: "COP" }
210
+ },
211
+ required: ["amount", "currency"],
212
+ additionalProperties: false
213
+ },
214
+ ExperienceSummary: {
215
+ type: "object",
216
+ properties: {
217
+ id: { $ref: "#/components/schemas/UUID" },
218
+ title: { type: "string" },
219
+ coverImageUrl: { type: "string", format: "uri" },
220
+ city: { type: "string" },
221
+ country: { type: "string" },
222
+ ratingAvg: { type: "number", minimum: 0, maximum: 5 },
223
+ ratingCount: { type: "integer", minimum: 0 },
224
+ fromPrice: { $ref: "#/components/schemas/Money" }
225
+ },
226
+ required: ["id", "title", "fromPrice"]
227
+ },
228
+ Experience: {
229
+ allOf: [
230
+ { $ref: "#/components/schemas/ExperienceSummary" },
231
+ {
232
+ type: "object",
233
+ properties: {
234
+ description: { type: "string" },
235
+ includes: { type: "array", items: { type: "string" } },
236
+ notIncludes: { type: "array", items: { type: "string" } },
237
+ images: { type: "array", items: { type: "string", format: "uri" } },
238
+ status: { type: "string", enum: ["draft", "under_review", "active", "rejected"] }
239
+ },
240
+ required: ["status"]
241
+ }
242
+ ]
243
+ },
244
+ AvailabilitySlot: {
245
+ type: "object",
246
+ properties: {
247
+ slotId: { $ref: "#/components/schemas/UUID" },
248
+ start: { type: "string", format: "date-time" },
249
+ end: { type: "string", format: "date-time" },
250
+ capacity: { type: "integer", minimum: 1 },
251
+ remaining: { type: "integer", minimum: 0 },
252
+ price: { $ref: "#/components/schemas/Money" }
253
+ },
254
+ required: ["slotId", "start", "end", "capacity", "remaining", "price"]
255
+ },
256
+ CreateBookingInput: {
257
+ type: "object",
258
+ properties: {
259
+ experienceId: { $ref: "#/components/schemas/UUID" },
260
+ slotId: { $ref: "#/components/schemas/UUID" },
261
+ quantity: { type: "integer", minimum: 1 },
262
+ buyer: {
263
+ type: "object",
264
+ properties: {
265
+ fullName: { type: "string" },
266
+ email: { type: "string", format: "email" },
267
+ phone: { type: "string" }
268
+ },
269
+ required: ["fullName", "email"]
270
+ },
271
+ payment: {
272
+ type: "object",
273
+ properties: {
274
+ method: { type: "string", enum: ["card", "pse", "cash", "other"] },
275
+ provider: { type: "string", enum: ["wompi", "epayco", "other"] }
276
+ },
277
+ required: ["method", "provider"]
278
+ }
279
+ },
280
+ required: ["experienceId", "slotId", "quantity", "buyer", "payment"],
281
+ additionalProperties: false
282
+ },
283
+ Booking: {
284
+ type: "object",
285
+ properties: {
286
+ id: { $ref: "#/components/schemas/UUID" },
287
+ status: { type: "string", enum: ["pending", "confirmed", "completed", "cancelled", "refunded", "expired"] },
288
+ experienceId: { $ref: "#/components/schemas/UUID" },
289
+ slotId: { $ref: "#/components/schemas/UUID" },
290
+ quantity: { type: "integer", minimum: 1 },
291
+ total: { $ref: "#/components/schemas/Money" },
292
+ createdAt: { type: "string", format: "date-time" }
293
+ },
294
+ required: ["id", "status", "experienceId", "slotId", "quantity", "total", "createdAt"]
295
+ },
296
+ PaymentWebhookPayload: {
297
+ type: "object",
298
+ properties: {
299
+ event: { type: "string", example: "transaction.updated" },
300
+ data: {
301
+ type: "object",
302
+ properties: {
303
+ providerRef: { type: "string" },
304
+ status: { type: "string", enum: ["APPROVED", "DECLINED", "VOIDED", "ERROR", "PENDING"] },
305
+ amountInCents: { type: "integer", minimum: 0 },
306
+ currency: { type: "string", minLength: 3, maxLength: 3 },
307
+ bookingId: { type: "string", format: "uuid", description: "Opcional si el flujo incluye referencia directa al booking." }
308
+ },
309
+ required: ["providerRef", "status", "amountInCents", "currency"]
310
+ },
311
+ sentAt: { type: "string", format: "date-time" }
312
+ },
313
+ required: ["event", "data"]
314
+ },
315
+ Error: {
316
+ type: "object",
317
+ properties: {
318
+ error_code: { type: "string" },
319
+ message: { type: "string" },
320
+ details: { type: ["object", "null"] }
321
+ },
322
+ required: ["error_code", "message"]
323
+ }
324
+ },
325
+ responses: {
326
+ BadRequest: {
327
+ description: "Solicitud inv\xE1lida",
328
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } }
329
+ },
330
+ Unauthorized: { description: "No autorizado" },
331
+ NotFound: {
332
+ description: "No encontrado",
333
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } }
334
+ },
335
+ Conflict: {
336
+ description: "Conflicto (idempotencia, duplicado, etc.)",
337
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } }
338
+ },
339
+ UnprocessableEntity: {
340
+ description: "Validaci\xF3n fallida",
341
+ content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } }
342
+ }
343
+ }
344
+ }
345
+ };
346
+
347
+ // messages/booking.confirmed.schema.json
348
+ var booking_confirmed_schema_default = {
349
+ $schema: "https://json-schema.org/draft/2020-12/schema",
350
+ $id: "https://contracts.livex.app/messages/booking.confirmed.schema.json",
351
+ title: "booking.confirmed",
352
+ type: "object",
353
+ properties: {
354
+ eventType: { const: "booking.confirmed" },
355
+ eventId: { type: "string", format: "uuid" },
356
+ occurredAt: { type: "string", format: "date-time" },
357
+ booking: {
358
+ type: "object",
359
+ properties: {
360
+ id: { type: "string", format: "uuid" },
361
+ experienceId: { type: "string", format: "uuid" },
362
+ slotId: { type: "string", format: "uuid" },
363
+ quantity: { type: "integer", minimum: 1 },
364
+ totalInCents: { type: "integer", minimum: 0 },
365
+ currency: { type: "string", minLength: 3, maxLength: 3 }
366
+ },
367
+ required: ["id", "experienceId", "slotId", "quantity", "totalInCents", "currency"]
368
+ },
369
+ payment: {
370
+ type: "object",
371
+ properties: {
372
+ provider: { type: "string" },
373
+ providerRef: { type: "string" }
374
+ },
375
+ required: ["provider", "providerRef"]
376
+ },
377
+ request_id: { type: "string" }
378
+ },
379
+ required: ["eventType", "eventId", "occurredAt", "booking", "payment"],
380
+ additionalProperties: false
381
+ };
382
+
383
+ // messages/webhook.payment.received.schema.json
384
+ var webhook_payment_received_schema_default = {
385
+ $schema: "https://json-schema.org/draft/2020-12/schema",
386
+ $id: "https://contracts.livex.app/messages/webhook.payment.received.schema.json",
387
+ title: "webhook.payment.received",
388
+ type: "object",
389
+ properties: {
390
+ eventType: { const: "webhook.payment.received" },
391
+ eventId: { type: "string", format: "uuid" },
392
+ provider: { type: "string", enum: ["wompi", "epayco", "other"] },
393
+ provider_event_id: { type: "string" },
394
+ payload: { type: "object" },
395
+ receivedAt: { type: "string", format: "date-time" }
396
+ },
397
+ required: ["eventType", "eventId", "provider", "provider_event_id", "payload", "receivedAt"],
398
+ additionalProperties: false
399
+ };
400
+
401
+ // src/types.db.ts
402
+ var types_db_exports = {};
403
+
404
+ // src/validators.ts
405
+ var import_ajv = __toESM(require("ajv"), 1);
406
+ var import_ajv_formats = __toESM(require("ajv-formats"), 1);
407
+ var ajv = new import_ajv.default({ allErrors: true, strict: true });
408
+ (0, import_ajv_formats.default)(ajv);
409
+ var _validateBookingConfirmed = ajv.compile(booking_confirmed_schema_default);
410
+ var _validateWebhookPaymentReceived = ajv.compile(webhook_payment_received_schema_default);
411
+ function validateBookingConfirmed(payload) {
412
+ const ok = _validateBookingConfirmed(payload);
413
+ return { ok, errors: _validateBookingConfirmed.errors ?? null };
414
+ }
415
+ function validateWebhookPaymentReceived(payload) {
416
+ const ok = _validateWebhookPaymentReceived(payload);
417
+ return { ok, errors: _validateWebhookPaymentReceived.errors ?? null };
418
+ }
419
+ var validators = {
420
+ bookingConfirmed: validateBookingConfirmed,
421
+ webhookPaymentReceived: validateWebhookPaymentReceived
422
+ };
423
+
424
+ // src/index.ts
425
+ var BookingConfirmed = booking_confirmed_schema_default;
426
+ var WebhookPaymentReceived = webhook_payment_received_schema_default;
427
+ // Annotate the CommonJS export names for ESM import in node:
428
+ 0 && (module.exports = {
429
+ BookingConfirmed,
430
+ DB,
431
+ WebhookPaymentReceived,
432
+ openapi,
433
+ validateBookingConfirmed,
434
+ validateWebhookPaymentReceived,
435
+ validators
436
+ });