@central-ticket/queue-sdk 0.0.2 → 0.0.4
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/dist/{centralq-C3ukDo0x.d.mts → centralq-CCw_Cqam.d.mts} +97 -2
- package/dist/{centralq-C3ukDo0x.d.ts → centralq-CCw_Cqam.d.ts} +97 -2
- package/dist/chunk-CFWLZCAR.mjs +115 -0
- package/dist/{chunk-P73Q2ZIO.mjs → chunk-OR3GGW4J.mjs} +25 -0
- package/dist/{chunk-BVCZFNM3.mjs → chunk-OVV3CIZZ.mjs} +27 -2
- package/dist/index.d.mts +4 -75
- package/dist/index.d.ts +4 -75
- package/dist/index.js +163 -19
- package/dist/index.mjs +15 -5
- package/dist/{queue-element-DXBW64U2.mjs → queue-element-QDDGTF6K.mjs} +5 -0
- package/dist/react.d.mts +3 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.js +70 -0
- package/dist/react.mjs +24 -2
- package/dist/server.d.mts +82 -2
- package/dist/server.d.ts +82 -2
- package/dist/server.js +108 -19
- package/dist/server.mjs +14 -4
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +64 -0
- package/dist/svelte.mjs +18 -2
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +9 -0
- package/dist/vue.mjs +9 -0
- package/package.json +2 -2
- package/dist/centralq-I9tdL_Xr.d.mts +0 -133
- package/dist/centralq-I9tdL_Xr.d.ts +0 -133
- package/dist/chunk-4MXU7S6A.mjs +0 -235
- package/dist/chunk-A37B25XO.mjs +0 -126
- package/dist/chunk-GWPLLJTU.mjs +0 -31
- package/dist/chunk-JJ33EJ65.mjs +0 -31
- package/dist/chunk-XIQ6LS62.mjs +0 -312
package/dist/index.js
CHANGED
|
@@ -68,6 +68,11 @@ var init_queue_element = __esm({
|
|
|
68
68
|
Por favor, no cierres esta ventana.
|
|
69
69
|
</p>
|
|
70
70
|
` : ""}
|
|
71
|
+
${this.status === "PAUSED" ? import_lit.html`
|
|
72
|
+
<h2>La fila está temporalmente cerrada</h2>
|
|
73
|
+
<p>Volveremos a intentar automáticamente.</p>
|
|
74
|
+
<div class="spinner"></div>
|
|
75
|
+
` : ""}
|
|
71
76
|
${this.status === "EXPIRED" ? import_lit.html`
|
|
72
77
|
<h2 style="color: #f59e0b;">Tu sesión ha expirado</h2>
|
|
73
78
|
<p>El tiempo para completar la compra terminó.</p>
|
|
@@ -149,9 +154,14 @@ __export(index_exports, {
|
|
|
149
154
|
CENTRALQ_DEFAULT_API_URL: () => CENTRALQ_DEFAULT_API_URL,
|
|
150
155
|
CentralQ: () => CentralQ,
|
|
151
156
|
CentralQClient: () => CentralQClient,
|
|
157
|
+
CentralQServerClient: () => CentralQServerClient,
|
|
158
|
+
CentralQServerRequestError: () => CentralQServerRequestError,
|
|
152
159
|
QueueHttpClient: () => QueueHttpClient,
|
|
160
|
+
completeQueueAccessServer: () => completeQueueAccessServer,
|
|
153
161
|
createCentralQClient: () => createCentralQClient,
|
|
154
|
-
|
|
162
|
+
createCentralQServerClient: () => createCentralQServerClient,
|
|
163
|
+
validateQueueTokenServer: () => validateQueueTokenServer,
|
|
164
|
+
verifyQueueAccessServer: () => verifyQueueAccessServer
|
|
155
165
|
});
|
|
156
166
|
module.exports = __toCommonJS(index_exports);
|
|
157
167
|
|
|
@@ -195,6 +205,30 @@ var QueueHttpClient = class {
|
|
|
195
205
|
}
|
|
196
206
|
return res.json();
|
|
197
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Canjea un código de bypass por un token de acceso activo.
|
|
210
|
+
* El worker descuenta un uso únicamente cuando el canje es exitoso.
|
|
211
|
+
*/
|
|
212
|
+
async redeemBypassCode(eventId, code, userId) {
|
|
213
|
+
const res = await fetch(
|
|
214
|
+
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/bypass`,
|
|
215
|
+
{
|
|
216
|
+
method: "POST",
|
|
217
|
+
headers: this.headers,
|
|
218
|
+
body: JSON.stringify({ code, userId })
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
const body = await res.json().catch(() => ({}));
|
|
222
|
+
if (!res.ok) {
|
|
223
|
+
throw new Error(
|
|
224
|
+
body.message ?? `Error ${res.status} al canjear c\xF3digo bypass`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
if (body.status !== "ACTIVE" || !body.token || !body.expiresAt || body.bypass !== true) {
|
|
228
|
+
throw new Error("Respuesta inv\xE1lida al canjear c\xF3digo bypass");
|
|
229
|
+
}
|
|
230
|
+
return body;
|
|
231
|
+
}
|
|
198
232
|
/**
|
|
199
233
|
* Envía un heartbeat para mantener vivo el slot (waiting o active).
|
|
200
234
|
* El SDK lo llama cada 10s automáticamente.
|
|
@@ -264,6 +298,7 @@ var QueueHttpClient = class {
|
|
|
264
298
|
configured: body.configured === true,
|
|
265
299
|
protected: body.protected === true,
|
|
266
300
|
isActive: body.isActive === true,
|
|
301
|
+
isPaused: body.isPaused === true,
|
|
267
302
|
admissionMode: body.admissionMode ?? "PUBLIC",
|
|
268
303
|
challengeRequired: body.challengeRequired === true
|
|
269
304
|
};
|
|
@@ -581,6 +616,24 @@ var CentralQ = class _CentralQ {
|
|
|
581
616
|
this.pollInterval
|
|
582
617
|
);
|
|
583
618
|
}
|
|
619
|
+
} else if (res.status === "PAUSED") {
|
|
620
|
+
this.updateUI("PAUSED");
|
|
621
|
+
this.emit("paused", {
|
|
622
|
+
message: res.message,
|
|
623
|
+
retryAfterSeconds: res.retryAfterSeconds,
|
|
624
|
+
userId: this.userId,
|
|
625
|
+
eventId: this.eventId
|
|
626
|
+
});
|
|
627
|
+
if (!this.pollingTimer) {
|
|
628
|
+
const retryInterval = Math.max(
|
|
629
|
+
this.pollInterval,
|
|
630
|
+
res.retryAfterSeconds * 1e3
|
|
631
|
+
);
|
|
632
|
+
this.pollingTimer = setInterval(
|
|
633
|
+
() => this.checkQueue(),
|
|
634
|
+
retryInterval
|
|
635
|
+
);
|
|
636
|
+
}
|
|
584
637
|
}
|
|
585
638
|
} catch {
|
|
586
639
|
this.updateUI("ERROR");
|
|
@@ -596,6 +649,13 @@ var CentralQClient = class {
|
|
|
596
649
|
constructor(defaults) {
|
|
597
650
|
this.defaults = defaults;
|
|
598
651
|
}
|
|
652
|
+
redeemBypassCode(eventId, code, userId) {
|
|
653
|
+
const client = new QueueHttpClient(
|
|
654
|
+
this.defaults.apiUrl,
|
|
655
|
+
this.defaults.apiKey
|
|
656
|
+
);
|
|
657
|
+
return client.redeemBypassCode(eventId, code, userId);
|
|
658
|
+
}
|
|
599
659
|
issueQueueInitToken(eventId, userId) {
|
|
600
660
|
const client = new QueueHttpClient(
|
|
601
661
|
this.defaults.apiUrl,
|
|
@@ -638,34 +698,118 @@ function createCentralQClient(options) {
|
|
|
638
698
|
}
|
|
639
699
|
|
|
640
700
|
// src/server.ts
|
|
701
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
702
|
+
var CentralQServerRequestError = class extends Error {
|
|
703
|
+
constructor(code, message, options) {
|
|
704
|
+
super(message, options);
|
|
705
|
+
this.name = "CentralQServerRequestError";
|
|
706
|
+
this.code = code;
|
|
707
|
+
}
|
|
708
|
+
};
|
|
641
709
|
function normalizeApiUrl2(apiUrl) {
|
|
642
|
-
|
|
710
|
+
const trimmed = apiUrl.trim().replace(/\/+$/, "");
|
|
711
|
+
return trimmed.endsWith("/api") ? trimmed.slice(0, -4) : trimmed;
|
|
643
712
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
713
|
+
function validateOptions(options) {
|
|
714
|
+
if (!options.secretKey?.trim()) {
|
|
715
|
+
throw new TypeError("CentralQ secretKey es requerida");
|
|
716
|
+
}
|
|
717
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs <= 0) {
|
|
718
|
+
throw new TypeError("CentralQ timeoutMs debe ser mayor a cero");
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
var CentralQServerClient = class {
|
|
722
|
+
constructor(options) {
|
|
723
|
+
validateOptions(options);
|
|
724
|
+
this.apiUrl = normalizeApiUrl2(options.apiUrl ?? CENTRALQ_DEFAULT_API_URL);
|
|
725
|
+
this.secretKey = options.secretKey.trim();
|
|
726
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
727
|
+
this.fetchFn = options.fetch ?? globalThis.fetch;
|
|
728
|
+
}
|
|
729
|
+
validateToken(input) {
|
|
730
|
+
return this.post(
|
|
731
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}`,
|
|
732
|
+
{ token: input.token },
|
|
733
|
+
{ valid: false, reason: "Respuesta inv\xE1lida" }
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
verifyAccess(input) {
|
|
737
|
+
return this.post(
|
|
738
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}/access`,
|
|
739
|
+
{ token: input.token ?? null },
|
|
740
|
+
{
|
|
741
|
+
allowed: false,
|
|
742
|
+
reason: "invalid_response",
|
|
743
|
+
message: "Respuesta inv\xE1lida"
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
completeAccess(input) {
|
|
748
|
+
return this.post(
|
|
749
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}/complete`,
|
|
750
|
+
{
|
|
751
|
+
token: input.token,
|
|
752
|
+
completionId: input.completionId
|
|
653
753
|
},
|
|
654
|
-
|
|
754
|
+
{ completed: false, reason: "invalid_response" }
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
async post(path, body, fallback) {
|
|
758
|
+
const controller = new AbortController();
|
|
759
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
760
|
+
try {
|
|
761
|
+
const response = await this.fetchFn(`${this.apiUrl}${path}`, {
|
|
762
|
+
method: "POST",
|
|
763
|
+
headers: {
|
|
764
|
+
"Content-Type": "application/json",
|
|
765
|
+
"x-api-key": this.secretKey
|
|
766
|
+
},
|
|
767
|
+
body: JSON.stringify(body),
|
|
768
|
+
signal: controller.signal
|
|
769
|
+
});
|
|
770
|
+
const data = await response.json().catch(() => fallback);
|
|
771
|
+
return { status: response.status, data };
|
|
772
|
+
} catch (error) {
|
|
773
|
+
if (controller.signal.aborted) {
|
|
774
|
+
throw new CentralQServerRequestError(
|
|
775
|
+
"timeout",
|
|
776
|
+
`CentralQ no respondi\xF3 en ${this.timeoutMs}ms`,
|
|
777
|
+
{ cause: error }
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
throw new CentralQServerRequestError(
|
|
781
|
+
"network_error",
|
|
782
|
+
"No se pudo conectar con CentralQ",
|
|
783
|
+
{ cause: error }
|
|
784
|
+
);
|
|
785
|
+
} finally {
|
|
786
|
+
clearTimeout(timeout);
|
|
655
787
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
function createCentralQServerClient(options) {
|
|
791
|
+
return new CentralQServerClient(options);
|
|
792
|
+
}
|
|
793
|
+
function validateQueueTokenServer(options) {
|
|
794
|
+
return createCentralQServerClient(options).validateToken(options);
|
|
795
|
+
}
|
|
796
|
+
function verifyQueueAccessServer(options) {
|
|
797
|
+
return createCentralQServerClient(options).verifyAccess(options);
|
|
798
|
+
}
|
|
799
|
+
function completeQueueAccessServer(options) {
|
|
800
|
+
return createCentralQServerClient(options).completeAccess(options);
|
|
662
801
|
}
|
|
663
802
|
// Annotate the CommonJS export names for ESM import in node:
|
|
664
803
|
0 && (module.exports = {
|
|
665
804
|
CENTRALQ_DEFAULT_API_URL,
|
|
666
805
|
CentralQ,
|
|
667
806
|
CentralQClient,
|
|
807
|
+
CentralQServerClient,
|
|
808
|
+
CentralQServerRequestError,
|
|
668
809
|
QueueHttpClient,
|
|
810
|
+
completeQueueAccessServer,
|
|
669
811
|
createCentralQClient,
|
|
670
|
-
|
|
812
|
+
createCentralQServerClient,
|
|
813
|
+
validateQueueTokenServer,
|
|
814
|
+
verifyQueueAccessServer
|
|
671
815
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
CentralQServerClient,
|
|
3
|
+
CentralQServerRequestError,
|
|
4
|
+
completeQueueAccessServer,
|
|
5
|
+
createCentralQServerClient,
|
|
6
|
+
validateQueueTokenServer,
|
|
7
|
+
verifyQueueAccessServer
|
|
8
|
+
} from "./chunk-CFWLZCAR.mjs";
|
|
4
9
|
import {
|
|
5
10
|
CentralQ,
|
|
6
11
|
CentralQClient,
|
|
7
12
|
createCentralQClient
|
|
8
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-OVV3CIZZ.mjs";
|
|
9
14
|
import {
|
|
10
15
|
CENTRALQ_DEFAULT_API_URL,
|
|
11
16
|
QueueHttpClient
|
|
12
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-OR3GGW4J.mjs";
|
|
13
18
|
import "./chunk-XRJFNASX.mjs";
|
|
14
19
|
export {
|
|
15
20
|
CENTRALQ_DEFAULT_API_URL,
|
|
16
21
|
CentralQ,
|
|
17
22
|
CentralQClient,
|
|
23
|
+
CentralQServerClient,
|
|
24
|
+
CentralQServerRequestError,
|
|
18
25
|
QueueHttpClient,
|
|
26
|
+
completeQueueAccessServer,
|
|
19
27
|
createCentralQClient,
|
|
20
|
-
|
|
28
|
+
createCentralQServerClient,
|
|
29
|
+
validateQueueTokenServer,
|
|
30
|
+
verifyQueueAccessServer
|
|
21
31
|
};
|
|
@@ -34,6 +34,11 @@ var CentralQElement = class extends LitElement {
|
|
|
34
34
|
Por favor, no cierres esta ventana.
|
|
35
35
|
</p>
|
|
36
36
|
` : ""}
|
|
37
|
+
${this.status === "PAUSED" ? html`
|
|
38
|
+
<h2>La fila está temporalmente cerrada</h2>
|
|
39
|
+
<p>Volveremos a intentar automáticamente.</p>
|
|
40
|
+
<div class="spinner"></div>
|
|
41
|
+
` : ""}
|
|
37
42
|
${this.status === "EXPIRED" ? html`
|
|
38
43
|
<h2 style="color: #f59e0b;">Tu sesión ha expirado</h2>
|
|
39
44
|
<p>El tiempo para completar la compra terminó.</p>
|
package/dist/react.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as CentralQ, e as CentralQCreateOptions, c as CentralQClient, m as QueueStatus, f as CentralQOptions } from './centralq-CCw_Cqam.mjs';
|
|
2
2
|
|
|
3
3
|
interface UseCentralQReturn {
|
|
4
4
|
/** Token JWT si el usuario fue admitido, null si no */
|
|
@@ -11,6 +11,8 @@ interface UseCentralQReturn {
|
|
|
11
11
|
expired: boolean;
|
|
12
12
|
/** true si hay un error de conexión */
|
|
13
13
|
error: boolean;
|
|
14
|
+
/** true si la cola no acepta nuevos ingresos temporalmente */
|
|
15
|
+
paused: boolean;
|
|
14
16
|
/** Libera el slot (llamar después de comprar) */
|
|
15
17
|
leave: () => void;
|
|
16
18
|
/** Instancia CentralQ subyacente (para uso avanzado) */
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as CentralQ, e as CentralQCreateOptions, c as CentralQClient, m as QueueStatus, f as CentralQOptions } from './centralq-CCw_Cqam.js';
|
|
2
2
|
|
|
3
3
|
interface UseCentralQReturn {
|
|
4
4
|
/** Token JWT si el usuario fue admitido, null si no */
|
|
@@ -11,6 +11,8 @@ interface UseCentralQReturn {
|
|
|
11
11
|
expired: boolean;
|
|
12
12
|
/** true si hay un error de conexión */
|
|
13
13
|
error: boolean;
|
|
14
|
+
/** true si la cola no acepta nuevos ingresos temporalmente */
|
|
15
|
+
paused: boolean;
|
|
14
16
|
/** Libera el slot (llamar después de comprar) */
|
|
15
17
|
leave: () => void;
|
|
16
18
|
/** Instancia CentralQ subyacente (para uso avanzado) */
|
package/dist/react.js
CHANGED
|
@@ -68,6 +68,11 @@ var init_queue_element = __esm({
|
|
|
68
68
|
Por favor, no cierres esta ventana.
|
|
69
69
|
</p>
|
|
70
70
|
` : ""}
|
|
71
|
+
${this.status === "PAUSED" ? import_lit.html`
|
|
72
|
+
<h2>La fila está temporalmente cerrada</h2>
|
|
73
|
+
<p>Volveremos a intentar automáticamente.</p>
|
|
74
|
+
<div class="spinner"></div>
|
|
75
|
+
` : ""}
|
|
71
76
|
${this.status === "EXPIRED" ? import_lit.html`
|
|
72
77
|
<h2 style="color: #f59e0b;">Tu sesión ha expirado</h2>
|
|
73
78
|
<p>El tiempo para completar la compra terminó.</p>
|
|
@@ -192,6 +197,30 @@ var QueueHttpClient = class {
|
|
|
192
197
|
}
|
|
193
198
|
return res.json();
|
|
194
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Canjea un código de bypass por un token de acceso activo.
|
|
202
|
+
* El worker descuenta un uso únicamente cuando el canje es exitoso.
|
|
203
|
+
*/
|
|
204
|
+
async redeemBypassCode(eventId, code, userId) {
|
|
205
|
+
const res = await fetch(
|
|
206
|
+
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/bypass`,
|
|
207
|
+
{
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers: this.headers,
|
|
210
|
+
body: JSON.stringify({ code, userId })
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
const body = await res.json().catch(() => ({}));
|
|
214
|
+
if (!res.ok) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
body.message ?? `Error ${res.status} al canjear c\xF3digo bypass`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
if (body.status !== "ACTIVE" || !body.token || !body.expiresAt || body.bypass !== true) {
|
|
220
|
+
throw new Error("Respuesta inv\xE1lida al canjear c\xF3digo bypass");
|
|
221
|
+
}
|
|
222
|
+
return body;
|
|
223
|
+
}
|
|
195
224
|
/**
|
|
196
225
|
* Envía un heartbeat para mantener vivo el slot (waiting o active).
|
|
197
226
|
* El SDK lo llama cada 10s automáticamente.
|
|
@@ -261,6 +290,7 @@ var QueueHttpClient = class {
|
|
|
261
290
|
configured: body.configured === true,
|
|
262
291
|
protected: body.protected === true,
|
|
263
292
|
isActive: body.isActive === true,
|
|
293
|
+
isPaused: body.isPaused === true,
|
|
264
294
|
admissionMode: body.admissionMode ?? "PUBLIC",
|
|
265
295
|
challengeRequired: body.challengeRequired === true
|
|
266
296
|
};
|
|
@@ -499,6 +529,24 @@ var CentralQ = class _CentralQ {
|
|
|
499
529
|
this.pollInterval
|
|
500
530
|
);
|
|
501
531
|
}
|
|
532
|
+
} else if (res.status === "PAUSED") {
|
|
533
|
+
this.updateUI("PAUSED");
|
|
534
|
+
this.emit("paused", {
|
|
535
|
+
message: res.message,
|
|
536
|
+
retryAfterSeconds: res.retryAfterSeconds,
|
|
537
|
+
userId: this.userId,
|
|
538
|
+
eventId: this.eventId
|
|
539
|
+
});
|
|
540
|
+
if (!this.pollingTimer) {
|
|
541
|
+
const retryInterval = Math.max(
|
|
542
|
+
this.pollInterval,
|
|
543
|
+
res.retryAfterSeconds * 1e3
|
|
544
|
+
);
|
|
545
|
+
this.pollingTimer = setInterval(
|
|
546
|
+
() => this.checkQueue(),
|
|
547
|
+
retryInterval
|
|
548
|
+
);
|
|
549
|
+
}
|
|
502
550
|
}
|
|
503
551
|
} catch {
|
|
504
552
|
this.updateUI("ERROR");
|
|
@@ -518,12 +566,14 @@ function useCentralQ(options) {
|
|
|
518
566
|
const [ahead, setAhead] = (0, import_react.useState)(null);
|
|
519
567
|
const [expired, setExpired] = (0, import_react.useState)(false);
|
|
520
568
|
const [error, setError] = (0, import_react.useState)(false);
|
|
569
|
+
const [paused, setPaused] = (0, import_react.useState)(false);
|
|
521
570
|
const instanceRef = (0, import_react.useRef)(null);
|
|
522
571
|
const leave = (0, import_react.useCallback)(() => {
|
|
523
572
|
instanceRef.current?.leave();
|
|
524
573
|
setToken(null);
|
|
525
574
|
setPosition(null);
|
|
526
575
|
setAhead(null);
|
|
576
|
+
setPaused(false);
|
|
527
577
|
}, []);
|
|
528
578
|
(0, import_react.useEffect)(() => {
|
|
529
579
|
const queue = CentralQ.init(options);
|
|
@@ -533,17 +583,26 @@ function useCentralQ(options) {
|
|
|
533
583
|
setAhead(null);
|
|
534
584
|
setExpired(false);
|
|
535
585
|
setError(false);
|
|
586
|
+
setPaused(false);
|
|
536
587
|
});
|
|
537
588
|
queue.on("position", (detail) => {
|
|
538
589
|
setPosition(detail.position);
|
|
539
590
|
setAhead(detail.ahead);
|
|
591
|
+
setPaused(false);
|
|
592
|
+
});
|
|
593
|
+
queue.on("paused", () => {
|
|
594
|
+
setPosition(null);
|
|
595
|
+
setAhead(null);
|
|
596
|
+
setPaused(true);
|
|
540
597
|
});
|
|
541
598
|
queue.on("expired", () => {
|
|
542
599
|
setToken(null);
|
|
543
600
|
setExpired(true);
|
|
601
|
+
setPaused(false);
|
|
544
602
|
});
|
|
545
603
|
queue.on("error", () => {
|
|
546
604
|
setError(true);
|
|
605
|
+
setPaused(false);
|
|
547
606
|
});
|
|
548
607
|
instanceRef.current = queue;
|
|
549
608
|
return () => {
|
|
@@ -557,6 +616,7 @@ function useCentralQ(options) {
|
|
|
557
616
|
ahead,
|
|
558
617
|
expired,
|
|
559
618
|
error,
|
|
619
|
+
paused,
|
|
560
620
|
leave,
|
|
561
621
|
instance: instanceRef.current
|
|
562
622
|
};
|
|
@@ -636,6 +696,16 @@ function useQueue(options) {
|
|
|
636
696
|
}));
|
|
637
697
|
setStatus("waiting");
|
|
638
698
|
});
|
|
699
|
+
queue.on("paused", (_detail) => {
|
|
700
|
+
setData({
|
|
701
|
+
token: null,
|
|
702
|
+
position: null,
|
|
703
|
+
ahead: null,
|
|
704
|
+
expiresAt: null
|
|
705
|
+
});
|
|
706
|
+
setStatus("paused");
|
|
707
|
+
setError(null);
|
|
708
|
+
});
|
|
639
709
|
queue.on("expired", () => {
|
|
640
710
|
setData({
|
|
641
711
|
token: null,
|
package/dist/react.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CentralQ
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-OVV3CIZZ.mjs";
|
|
4
|
+
import "./chunk-OR3GGW4J.mjs";
|
|
5
5
|
import "./chunk-XRJFNASX.mjs";
|
|
6
6
|
|
|
7
7
|
// src/react.ts
|
|
@@ -12,12 +12,14 @@ function useCentralQ(options) {
|
|
|
12
12
|
const [ahead, setAhead] = useState(null);
|
|
13
13
|
const [expired, setExpired] = useState(false);
|
|
14
14
|
const [error, setError] = useState(false);
|
|
15
|
+
const [paused, setPaused] = useState(false);
|
|
15
16
|
const instanceRef = useRef(null);
|
|
16
17
|
const leave = useCallback(() => {
|
|
17
18
|
instanceRef.current?.leave();
|
|
18
19
|
setToken(null);
|
|
19
20
|
setPosition(null);
|
|
20
21
|
setAhead(null);
|
|
22
|
+
setPaused(false);
|
|
21
23
|
}, []);
|
|
22
24
|
useEffect(() => {
|
|
23
25
|
const queue = CentralQ.init(options);
|
|
@@ -27,17 +29,26 @@ function useCentralQ(options) {
|
|
|
27
29
|
setAhead(null);
|
|
28
30
|
setExpired(false);
|
|
29
31
|
setError(false);
|
|
32
|
+
setPaused(false);
|
|
30
33
|
});
|
|
31
34
|
queue.on("position", (detail) => {
|
|
32
35
|
setPosition(detail.position);
|
|
33
36
|
setAhead(detail.ahead);
|
|
37
|
+
setPaused(false);
|
|
38
|
+
});
|
|
39
|
+
queue.on("paused", () => {
|
|
40
|
+
setPosition(null);
|
|
41
|
+
setAhead(null);
|
|
42
|
+
setPaused(true);
|
|
34
43
|
});
|
|
35
44
|
queue.on("expired", () => {
|
|
36
45
|
setToken(null);
|
|
37
46
|
setExpired(true);
|
|
47
|
+
setPaused(false);
|
|
38
48
|
});
|
|
39
49
|
queue.on("error", () => {
|
|
40
50
|
setError(true);
|
|
51
|
+
setPaused(false);
|
|
41
52
|
});
|
|
42
53
|
instanceRef.current = queue;
|
|
43
54
|
return () => {
|
|
@@ -51,6 +62,7 @@ function useCentralQ(options) {
|
|
|
51
62
|
ahead,
|
|
52
63
|
expired,
|
|
53
64
|
error,
|
|
65
|
+
paused,
|
|
54
66
|
leave,
|
|
55
67
|
instance: instanceRef.current
|
|
56
68
|
};
|
|
@@ -130,6 +142,16 @@ function useQueue(options) {
|
|
|
130
142
|
}));
|
|
131
143
|
setStatus("waiting");
|
|
132
144
|
});
|
|
145
|
+
queue.on("paused", (_detail) => {
|
|
146
|
+
setData({
|
|
147
|
+
token: null,
|
|
148
|
+
position: null,
|
|
149
|
+
ahead: null,
|
|
150
|
+
expiresAt: null
|
|
151
|
+
});
|
|
152
|
+
setStatus("paused");
|
|
153
|
+
setError(null);
|
|
154
|
+
});
|
|
133
155
|
queue.on("expired", () => {
|
|
134
156
|
setData({
|
|
135
157
|
token: null,
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
interface
|
|
1
|
+
interface CentralQServerClientOptions {
|
|
2
2
|
apiUrl?: string;
|
|
3
3
|
secretKey: string;
|
|
4
|
+
timeoutMs?: number;
|
|
5
|
+
fetch?: typeof fetch;
|
|
6
|
+
}
|
|
7
|
+
interface ValidateQueueTokenServerOptions extends CentralQServerClientOptions {
|
|
4
8
|
eventId: string;
|
|
5
9
|
token: string;
|
|
6
10
|
}
|
|
@@ -13,9 +17,85 @@ type QueueTokenValidationResult = {
|
|
|
13
17
|
valid: false;
|
|
14
18
|
reason: string;
|
|
15
19
|
};
|
|
20
|
+
interface VerifyQueueAccessServerOptions extends CentralQServerClientOptions {
|
|
21
|
+
eventId: string;
|
|
22
|
+
token?: string;
|
|
23
|
+
}
|
|
24
|
+
type QueueAccessValidationResult = {
|
|
25
|
+
allowed: true;
|
|
26
|
+
eventId: string;
|
|
27
|
+
protected: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
userId?: string;
|
|
30
|
+
expiresAt?: string;
|
|
31
|
+
} | {
|
|
32
|
+
allowed: false;
|
|
33
|
+
eventId?: string;
|
|
34
|
+
protected?: boolean;
|
|
35
|
+
reason?: string;
|
|
36
|
+
message?: string;
|
|
37
|
+
};
|
|
38
|
+
interface CompleteQueueAccessServerOptions extends CentralQServerClientOptions {
|
|
39
|
+
eventId: string;
|
|
40
|
+
token: string;
|
|
41
|
+
completionId: string;
|
|
42
|
+
}
|
|
43
|
+
type QueueAccessCompletionResult = {
|
|
44
|
+
completed: true;
|
|
45
|
+
alreadyCompleted: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
completed: false;
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
type CentralQServerRequestErrorCode = "network_error" | "timeout";
|
|
51
|
+
declare class CentralQServerRequestError extends Error {
|
|
52
|
+
readonly code: CentralQServerRequestErrorCode;
|
|
53
|
+
constructor(code: CentralQServerRequestErrorCode, message: string, options?: {
|
|
54
|
+
cause?: unknown;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
declare class CentralQServerClient {
|
|
58
|
+
private readonly apiUrl;
|
|
59
|
+
private readonly secretKey;
|
|
60
|
+
private readonly timeoutMs;
|
|
61
|
+
private readonly fetchFn;
|
|
62
|
+
constructor(options: CentralQServerClientOptions);
|
|
63
|
+
validateToken(input: {
|
|
64
|
+
eventId: string;
|
|
65
|
+
token: string;
|
|
66
|
+
}): Promise<{
|
|
67
|
+
status: number;
|
|
68
|
+
data: QueueTokenValidationResult;
|
|
69
|
+
}>;
|
|
70
|
+
verifyAccess(input: {
|
|
71
|
+
eventId: string;
|
|
72
|
+
token?: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
status: number;
|
|
75
|
+
data: QueueAccessValidationResult;
|
|
76
|
+
}>;
|
|
77
|
+
completeAccess(input: {
|
|
78
|
+
eventId: string;
|
|
79
|
+
token: string;
|
|
80
|
+
completionId: string;
|
|
81
|
+
}): Promise<{
|
|
82
|
+
status: number;
|
|
83
|
+
data: QueueAccessCompletionResult;
|
|
84
|
+
}>;
|
|
85
|
+
private post;
|
|
86
|
+
}
|
|
87
|
+
declare function createCentralQServerClient(options: CentralQServerClientOptions): CentralQServerClient;
|
|
16
88
|
declare function validateQueueTokenServer(options: ValidateQueueTokenServerOptions): Promise<{
|
|
17
89
|
status: number;
|
|
18
90
|
data: QueueTokenValidationResult;
|
|
19
91
|
}>;
|
|
92
|
+
declare function verifyQueueAccessServer(options: VerifyQueueAccessServerOptions): Promise<{
|
|
93
|
+
status: number;
|
|
94
|
+
data: QueueAccessValidationResult;
|
|
95
|
+
}>;
|
|
96
|
+
declare function completeQueueAccessServer(options: CompleteQueueAccessServerOptions): Promise<{
|
|
97
|
+
status: number;
|
|
98
|
+
data: QueueAccessCompletionResult;
|
|
99
|
+
}>;
|
|
20
100
|
|
|
21
|
-
export { type QueueTokenValidationResult, type ValidateQueueTokenServerOptions, validateQueueTokenServer };
|
|
101
|
+
export { CentralQServerClient, type CentralQServerClientOptions, CentralQServerRequestError, type CentralQServerRequestErrorCode, type CompleteQueueAccessServerOptions, type QueueAccessCompletionResult, type QueueAccessValidationResult, type QueueTokenValidationResult, type ValidateQueueTokenServerOptions, type VerifyQueueAccessServerOptions, completeQueueAccessServer, createCentralQServerClient, validateQueueTokenServer, verifyQueueAccessServer };
|