@central-ticket/queue-sdk 0.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.
@@ -0,0 +1,111 @@
1
+ import {
2
+ __decorateClass
3
+ } from "./chunk-XRJFNASX.mjs";
4
+
5
+ // src/queue-element.ts
6
+ import { LitElement, html, css } from "lit";
7
+ import { customElement, state } from "lit/decorators.js";
8
+ var CentralQElement = class extends LitElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.status = "LOADING";
12
+ this.position = 0;
13
+ this.ahead = 0;
14
+ }
15
+ render() {
16
+ if (this.status === "ACTIVE") return html``;
17
+ return html`
18
+ <div class="overlay">
19
+ <div class="modal">
20
+ ${this.status === "LOADING" ? html`
21
+ <div class="spinner"></div>
22
+ <h2>Conectando a la fila...</h2>
23
+ ` : ""}
24
+ ${this.status === "WAITING" ? html`
25
+ <div class="spinner"></div>
26
+ <h2>Estás en la fila virtual</h2>
27
+ <p>Tu posición: <strong>#${this.position}</strong></p>
28
+ ${this.ahead > 0 ? html`<p>
29
+ Hay <strong>${this.ahead}</strong>
30
+ ${this.ahead === 1 ? "persona" : "personas"} delante de
31
+ ti.
32
+ </p>` : html`<p>¡Eres el siguiente!</p>`}
33
+ <p style="font-size: 0.85rem; color: #aaa;">
34
+ Por favor, no cierres esta ventana.
35
+ </p>
36
+ ` : ""}
37
+ ${this.status === "EXPIRED" ? html`
38
+ <h2 style="color: #f59e0b;">Tu sesión ha expirado</h2>
39
+ <p>El tiempo para completar la compra terminó.</p>
40
+ <button
41
+ style="margin-top: 1rem; padding: 0.75rem 2rem; font-size: 1rem;
42
+ cursor: pointer; border-radius: 8px; border: none;
43
+ background: #3b82f6; color: white;"
44
+ @click=${() => this.onRetry?.()}
45
+ >
46
+ Volver a la fila
47
+ </button>
48
+ ` : ""}
49
+ ${this.status === "ERROR" ? html`
50
+ <h2 style="color: #ef4444;">Ocurrió un error de conexión</h2>
51
+ <p>Por favor, recarga la página.</p>
52
+ ` : ""}
53
+ </div>
54
+ </div>
55
+ `;
56
+ }
57
+ };
58
+ CentralQElement.styles = css`
59
+ :host {
60
+ display: contents;
61
+ }
62
+ .overlay {
63
+ position: fixed;
64
+ inset: 0;
65
+ background: rgba(0, 0, 0, 0.8);
66
+ backdrop-filter: blur(5px);
67
+ display: flex;
68
+ align-items: center;
69
+ justify-content: center;
70
+ z-index: 9999;
71
+ font-family: system-ui, sans-serif;
72
+ }
73
+ .modal {
74
+ background: #1e1e1e;
75
+ color: white;
76
+ padding: 2rem;
77
+ border-radius: 12px;
78
+ text-align: center;
79
+ max-width: 400px;
80
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
81
+ }
82
+ .spinner {
83
+ margin: 1rem auto;
84
+ width: 40px;
85
+ height: 40px;
86
+ border: 4px solid #333;
87
+ border-top-color: #3b82f6;
88
+ border-radius: 50%;
89
+ animation: spin 1s linear infinite;
90
+ }
91
+ @keyframes spin {
92
+ to {
93
+ transform: rotate(360deg);
94
+ }
95
+ }
96
+ `;
97
+ __decorateClass([
98
+ state()
99
+ ], CentralQElement.prototype, "status", 2);
100
+ __decorateClass([
101
+ state()
102
+ ], CentralQElement.prototype, "position", 2);
103
+ __decorateClass([
104
+ state()
105
+ ], CentralQElement.prototype, "ahead", 2);
106
+ CentralQElement = __decorateClass([
107
+ customElement("central-q")
108
+ ], CentralQElement);
109
+ export {
110
+ CentralQElement
111
+ };
@@ -0,0 +1,65 @@
1
+ import { C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, d as CentralQOptions } from './centralq-I9tdL_Xr.mjs';
2
+
3
+ interface UseCentralQReturn {
4
+ /** Token JWT si el usuario fue admitido, null si no */
5
+ token: string | null;
6
+ /** Posición en la cola (1-based), null si no está esperando */
7
+ position: number | null;
8
+ /** Personas delante en la cola */
9
+ ahead: number | null;
10
+ /** true si la sesión expiró */
11
+ expired: boolean;
12
+ /** true si hay un error de conexión */
13
+ error: boolean;
14
+ /** Libera el slot (llamar después de comprar) */
15
+ leave: () => void;
16
+ /** Instancia CentralQ subyacente (para uso avanzado) */
17
+ instance: CentralQ | null;
18
+ }
19
+ interface QueueData {
20
+ token: string | null;
21
+ position: number | null;
22
+ ahead: number | null;
23
+ expiresAt: number | null;
24
+ }
25
+ interface UseQueueOptions extends Omit<CentralQCreateOptions, "apiUrl" | "apiKey"> {
26
+ /** Cliente global creado con createCentralQClient */
27
+ client: CentralQClient;
28
+ /** Habilita o pausa la suscripción de la cola */
29
+ enabled?: boolean;
30
+ /** Deshabilita bootstrap automático de init token */
31
+ autoInitToken?: boolean;
32
+ }
33
+ interface UseQueueReturn {
34
+ status: QueueStatus;
35
+ data: QueueData;
36
+ isPending: boolean;
37
+ error: Error | null;
38
+ leave: () => void;
39
+ reset: () => void;
40
+ instance: CentralQ | null;
41
+ }
42
+ /**
43
+ * React hook que encapsula toda la lógica de CentralQ.
44
+ *
45
+ * ```tsx
46
+ * import { useCentralQ } from '@central-ticket/queue-sdk/react';
47
+ *
48
+ * function CheckoutPage() {
49
+ * const { token, position, expired, leave } = useCentralQ({
50
+ * apiUrl: 'http://localhost:3001',
51
+ * apiKey: 'ctq_pub_xxx',
52
+ * eventId: 'coldplay-2026',
53
+ * });
54
+ *
55
+ * if (token) return <BuyButton onBuy={() => { buy(); leave(); }} />;
56
+ * if (expired) return <p>Sesión expirada</p>;
57
+ * if (position) return <p>Posición #{position}</p>;
58
+ * return <p>Conectando...</p>;
59
+ * }
60
+ * ```
61
+ */
62
+ declare function useCentralQ(options: CentralQOptions): UseCentralQReturn;
63
+ declare function useQueue(options: UseQueueOptions): UseQueueReturn;
64
+
65
+ export { type QueueData, type UseCentralQReturn, type UseQueueOptions, type UseQueueReturn, useCentralQ, useQueue };
@@ -0,0 +1,65 @@
1
+ import { C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, d as CentralQOptions } from './centralq-I9tdL_Xr.js';
2
+
3
+ interface UseCentralQReturn {
4
+ /** Token JWT si el usuario fue admitido, null si no */
5
+ token: string | null;
6
+ /** Posición en la cola (1-based), null si no está esperando */
7
+ position: number | null;
8
+ /** Personas delante en la cola */
9
+ ahead: number | null;
10
+ /** true si la sesión expiró */
11
+ expired: boolean;
12
+ /** true si hay un error de conexión */
13
+ error: boolean;
14
+ /** Libera el slot (llamar después de comprar) */
15
+ leave: () => void;
16
+ /** Instancia CentralQ subyacente (para uso avanzado) */
17
+ instance: CentralQ | null;
18
+ }
19
+ interface QueueData {
20
+ token: string | null;
21
+ position: number | null;
22
+ ahead: number | null;
23
+ expiresAt: number | null;
24
+ }
25
+ interface UseQueueOptions extends Omit<CentralQCreateOptions, "apiUrl" | "apiKey"> {
26
+ /** Cliente global creado con createCentralQClient */
27
+ client: CentralQClient;
28
+ /** Habilita o pausa la suscripción de la cola */
29
+ enabled?: boolean;
30
+ /** Deshabilita bootstrap automático de init token */
31
+ autoInitToken?: boolean;
32
+ }
33
+ interface UseQueueReturn {
34
+ status: QueueStatus;
35
+ data: QueueData;
36
+ isPending: boolean;
37
+ error: Error | null;
38
+ leave: () => void;
39
+ reset: () => void;
40
+ instance: CentralQ | null;
41
+ }
42
+ /**
43
+ * React hook que encapsula toda la lógica de CentralQ.
44
+ *
45
+ * ```tsx
46
+ * import { useCentralQ } from '@central-ticket/queue-sdk/react';
47
+ *
48
+ * function CheckoutPage() {
49
+ * const { token, position, expired, leave } = useCentralQ({
50
+ * apiUrl: 'http://localhost:3001',
51
+ * apiKey: 'ctq_pub_xxx',
52
+ * eventId: 'coldplay-2026',
53
+ * });
54
+ *
55
+ * if (token) return <BuyButton onBuy={() => { buy(); leave(); }} />;
56
+ * if (expired) return <p>Sesión expirada</p>;
57
+ * if (position) return <p>Posición #{position}</p>;
58
+ * return <p>Conectando...</p>;
59
+ * }
60
+ * ```
61
+ */
62
+ declare function useCentralQ(options: CentralQOptions): UseCentralQReturn;
63
+ declare function useQueue(options: UseQueueOptions): UseQueueReturn;
64
+
65
+ export { type QueueData, type UseCentralQReturn, type UseQueueOptions, type UseQueueReturn, useCentralQ, useQueue };