@central-ticket/queue-sdk 0.0.3 → 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-FAJWYFUK.mjs → chunk-CFWLZCAR.mjs} +1 -1
- 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 +3 -74
- package/dist/index.d.ts +3 -74
- package/dist/index.js +55 -0
- package/dist/index.mjs +3 -3
- 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.mjs +2 -2
- 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-CURBGL7P.mjs +0 -63
- package/dist/chunk-GWPLLJTU.mjs +0 -31
- package/dist/chunk-JJ33EJ65.mjs +0 -31
- package/dist/chunk-XIQ6LS62.mjs +0 -312
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
interface CentralQOptions {
|
|
2
|
-
/** URL del queue worker. */
|
|
3
|
-
apiUrl?: string;
|
|
4
|
-
/** Publishable API key (ctq_pub_xxx) */
|
|
5
|
-
apiKey: string;
|
|
6
|
-
/** ID del evento/recurso a proteger */
|
|
7
|
-
eventId: string;
|
|
8
|
-
/** ID de usuario externo. Si no se provee, se autogenera y persiste en sessionStorage */
|
|
9
|
-
userId?: string;
|
|
10
|
-
/** Init token corto emitido por backend (recomendado para producción) */
|
|
11
|
-
queueInitToken?: string;
|
|
12
|
-
/** Intervalo de polling en ms (default: 10000) */
|
|
13
|
-
pollInterval?: number;
|
|
14
|
-
/** Contenedor donde montar el overlay. Default: document.body */
|
|
15
|
-
container?: HTMLElement;
|
|
16
|
-
}
|
|
17
|
-
interface CentralQClientOptions {
|
|
18
|
-
/** URL del queue worker */
|
|
19
|
-
apiUrl?: string;
|
|
20
|
-
/** Publishable API key (ctq_pub_xxx) */
|
|
21
|
-
apiKey: string;
|
|
22
|
-
/** ID de usuario externo por defecto para todas las colas creadas por el client */
|
|
23
|
-
userId?: string;
|
|
24
|
-
/** Init token corto por defecto para colas creadas por el client */
|
|
25
|
-
queueInitToken?: string;
|
|
26
|
-
/** Intervalo de polling por defecto en ms */
|
|
27
|
-
pollInterval?: number;
|
|
28
|
-
/** Contenedor por defecto donde montar el overlay */
|
|
29
|
-
container?: HTMLElement;
|
|
30
|
-
}
|
|
31
|
-
interface CentralQCreateOptions {
|
|
32
|
-
/** ID del evento/recurso a proteger */
|
|
33
|
-
eventId: string;
|
|
34
|
-
/** Override opcional del userId por cola */
|
|
35
|
-
userId?: string;
|
|
36
|
-
/** Override opcional del queue init token por cola */
|
|
37
|
-
queueInitToken?: string;
|
|
38
|
-
/** Override opcional del poll interval por cola */
|
|
39
|
-
pollInterval?: number;
|
|
40
|
-
/** Override opcional del contenedor por cola */
|
|
41
|
-
container?: HTMLElement;
|
|
42
|
-
/** Override opcional del apiUrl por cola */
|
|
43
|
-
apiUrl?: string;
|
|
44
|
-
/** Override opcional del apiKey por cola */
|
|
45
|
-
apiKey?: string;
|
|
46
|
-
}
|
|
47
|
-
interface PassedDetail {
|
|
48
|
-
token: string;
|
|
49
|
-
expiresAt: number;
|
|
50
|
-
userId: string;
|
|
51
|
-
eventId: string;
|
|
52
|
-
}
|
|
53
|
-
interface PositionDetail {
|
|
54
|
-
position: number;
|
|
55
|
-
ahead: number;
|
|
56
|
-
userId: string;
|
|
57
|
-
eventId: string;
|
|
58
|
-
}
|
|
59
|
-
interface ExpiredDetail {
|
|
60
|
-
userId: string;
|
|
61
|
-
eventId: string;
|
|
62
|
-
}
|
|
63
|
-
interface ErrorDetail {
|
|
64
|
-
userId: string;
|
|
65
|
-
eventId: string;
|
|
66
|
-
}
|
|
67
|
-
type EventMap = {
|
|
68
|
-
passed: PassedDetail;
|
|
69
|
-
expired: ExpiredDetail;
|
|
70
|
-
position: PositionDetail;
|
|
71
|
-
error: ErrorDetail;
|
|
72
|
-
};
|
|
73
|
-
type EventName = keyof EventMap;
|
|
74
|
-
type Listener<T> = (detail: T) => void;
|
|
75
|
-
type QueueStatus = "idle" | "joining" | "waiting" | "passed" | "expired" | "error";
|
|
76
|
-
declare class CentralQ {
|
|
77
|
-
private client;
|
|
78
|
-
private element;
|
|
79
|
-
private userId;
|
|
80
|
-
private eventId;
|
|
81
|
-
private pollInterval;
|
|
82
|
-
private container;
|
|
83
|
-
private pollingTimer?;
|
|
84
|
-
private heartbeatTimer?;
|
|
85
|
-
private expiryTimer?;
|
|
86
|
-
private destroyed;
|
|
87
|
-
private listeners;
|
|
88
|
-
private constructor();
|
|
89
|
-
/**
|
|
90
|
-
* Inicializa CentralQ y comienza el flujo de cola automáticamente.
|
|
91
|
-
* Monta el overlay de UI y empieza a hacer polling.
|
|
92
|
-
*/
|
|
93
|
-
static init(options: CentralQOptions): CentralQ;
|
|
94
|
-
/** Suscribirse a un evento del ciclo de vida de la cola */
|
|
95
|
-
on<K extends EventName>(event: K, listener: Listener<EventMap[K]>): this;
|
|
96
|
-
/** Desuscribirse de un evento */
|
|
97
|
-
off<K extends EventName>(event: K, listener: Listener<EventMap[K]>): this;
|
|
98
|
-
private emit;
|
|
99
|
-
/**
|
|
100
|
-
* Libera el slot del usuario inmediatamente.
|
|
101
|
-
* Llamar cuando el usuario completa la compra.
|
|
102
|
-
*/
|
|
103
|
-
leave(): void;
|
|
104
|
-
/**
|
|
105
|
-
* Destruye la instancia: para todos los timers, desmonta el overlay,
|
|
106
|
-
* y libera el slot en el servidor.
|
|
107
|
-
*/
|
|
108
|
-
destroy(): void;
|
|
109
|
-
/** Retorna el userId resuelto (externo o autogenerado) */
|
|
110
|
-
getUserId(): string;
|
|
111
|
-
private resolveUserId;
|
|
112
|
-
private mount;
|
|
113
|
-
private unmount;
|
|
114
|
-
private updateUI;
|
|
115
|
-
private stopTimers;
|
|
116
|
-
private startHeartbeat;
|
|
117
|
-
private scheduleExpiry;
|
|
118
|
-
private handleExpired;
|
|
119
|
-
private checkQueue;
|
|
120
|
-
}
|
|
121
|
-
declare class CentralQClient {
|
|
122
|
-
private defaults;
|
|
123
|
-
constructor(defaults: CentralQClientOptions);
|
|
124
|
-
issueQueueInitToken(eventId: string, userId?: string): Promise<{
|
|
125
|
-
userId: string;
|
|
126
|
-
queueInitToken: string;
|
|
127
|
-
expiresAt: number;
|
|
128
|
-
}>;
|
|
129
|
-
createQueue(options: CentralQCreateOptions): CentralQ;
|
|
130
|
-
}
|
|
131
|
-
declare function createCentralQClient(options: CentralQClientOptions): CentralQClient;
|
|
132
|
-
|
|
133
|
-
export { CentralQ as C, type ErrorDetail as E, type PassedDetail as P, type QueueStatus as Q, CentralQClient as a, type CentralQClientOptions as b, type CentralQCreateOptions as c, type CentralQOptions as d, type ExpiredDetail as e, type PositionDetail as f, createCentralQClient as g };
|
package/dist/chunk-4MXU7S6A.mjs
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CENTRALQ_DEFAULT_API_URL,
|
|
3
|
-
QueueHttpClient
|
|
4
|
-
} from "./chunk-A37B25XO.mjs";
|
|
5
|
-
|
|
6
|
-
// src/centralq.ts
|
|
7
|
-
var CentralQ = class _CentralQ {
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.element = null;
|
|
10
|
-
this.destroyed = false;
|
|
11
|
-
// biome-ignore lint: allow explicit any for generic event map
|
|
12
|
-
this.listeners = /* @__PURE__ */ new Map();
|
|
13
|
-
this.client = new QueueHttpClient(
|
|
14
|
-
options.apiUrl,
|
|
15
|
-
options.apiKey,
|
|
16
|
-
options.queueInitToken
|
|
17
|
-
);
|
|
18
|
-
this.eventId = options.eventId;
|
|
19
|
-
this.pollInterval = options.pollInterval ?? 1e4;
|
|
20
|
-
this.container = options.container ?? document.body;
|
|
21
|
-
this.userId = this.resolveUserId(options.userId);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Inicializa CentralQ y comienza el flujo de cola automáticamente.
|
|
25
|
-
* Monta el overlay de UI y empieza a hacer polling.
|
|
26
|
-
*/
|
|
27
|
-
static init(options) {
|
|
28
|
-
const instance = new _CentralQ(options);
|
|
29
|
-
instance.mount();
|
|
30
|
-
instance.checkQueue();
|
|
31
|
-
return instance;
|
|
32
|
-
}
|
|
33
|
-
// Event API
|
|
34
|
-
/** Suscribirse a un evento del ciclo de vida de la cola */
|
|
35
|
-
on(event, listener) {
|
|
36
|
-
if (!this.listeners.has(event)) {
|
|
37
|
-
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
38
|
-
}
|
|
39
|
-
this.listeners.get(event).add(listener);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
/** Desuscribirse de un evento */
|
|
43
|
-
off(event, listener) {
|
|
44
|
-
this.listeners.get(event)?.delete(listener);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
emit(event, detail) {
|
|
48
|
-
this.listeners.get(event)?.forEach((fn) => fn(detail));
|
|
49
|
-
}
|
|
50
|
-
// Métodos públicos
|
|
51
|
-
/**
|
|
52
|
-
* Libera el slot del usuario inmediatamente.
|
|
53
|
-
* Llamar cuando el usuario completa la compra.
|
|
54
|
-
*/
|
|
55
|
-
leave() {
|
|
56
|
-
this.stopTimers();
|
|
57
|
-
this.updateUI("ACTIVE");
|
|
58
|
-
this.client.leaveQueue(this.eventId, this.userId).catch(() => {
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Destruye la instancia: para todos los timers, desmonta el overlay,
|
|
63
|
-
* y libera el slot en el servidor.
|
|
64
|
-
*/
|
|
65
|
-
destroy() {
|
|
66
|
-
this.destroyed = true;
|
|
67
|
-
this.stopTimers();
|
|
68
|
-
this.client.leaveQueue(this.eventId, this.userId).catch(() => {
|
|
69
|
-
});
|
|
70
|
-
this.unmount();
|
|
71
|
-
this.listeners.clear();
|
|
72
|
-
}
|
|
73
|
-
/** Retorna el userId resuelto (externo o autogenerado) */
|
|
74
|
-
getUserId() {
|
|
75
|
-
return this.userId;
|
|
76
|
-
}
|
|
77
|
-
// userId: genera y persiste automáticamente
|
|
78
|
-
resolveUserId(externalId) {
|
|
79
|
-
if (externalId) return externalId;
|
|
80
|
-
const key = `ctq_anon_${this.eventId}`;
|
|
81
|
-
try {
|
|
82
|
-
const stored = sessionStorage.getItem(key);
|
|
83
|
-
if (stored) return stored;
|
|
84
|
-
} catch {
|
|
85
|
-
}
|
|
86
|
-
const generated = `anon_${crypto.randomUUID()}`;
|
|
87
|
-
try {
|
|
88
|
-
sessionStorage.setItem(key, generated);
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
return generated;
|
|
92
|
-
}
|
|
93
|
-
// UI: montar/desmontar el Web Component
|
|
94
|
-
mount() {
|
|
95
|
-
import("./queue-element-DXBW64U2.mjs");
|
|
96
|
-
this.element = document.createElement("central-q");
|
|
97
|
-
this.element.onRetry = () => {
|
|
98
|
-
this.updateUI("LOADING");
|
|
99
|
-
this.checkQueue();
|
|
100
|
-
};
|
|
101
|
-
this.container.appendChild(this.element);
|
|
102
|
-
}
|
|
103
|
-
unmount() {
|
|
104
|
-
if (this.element) {
|
|
105
|
-
this.element.remove();
|
|
106
|
-
this.element = null;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
updateUI(status, data) {
|
|
110
|
-
if (!this.element) return;
|
|
111
|
-
this.element.status = status;
|
|
112
|
-
if (data?.position !== void 0) this.element.position = data.position;
|
|
113
|
-
if (data?.ahead !== void 0) this.element.ahead = data.ahead;
|
|
114
|
-
}
|
|
115
|
-
// Timers
|
|
116
|
-
stopTimers() {
|
|
117
|
-
if (this.pollingTimer) {
|
|
118
|
-
clearInterval(this.pollingTimer);
|
|
119
|
-
this.pollingTimer = void 0;
|
|
120
|
-
}
|
|
121
|
-
if (this.heartbeatTimer) {
|
|
122
|
-
clearInterval(this.heartbeatTimer);
|
|
123
|
-
this.heartbeatTimer = void 0;
|
|
124
|
-
}
|
|
125
|
-
if (this.expiryTimer) {
|
|
126
|
-
clearTimeout(this.expiryTimer);
|
|
127
|
-
this.expiryTimer = void 0;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
startHeartbeat() {
|
|
131
|
-
if (this.heartbeatTimer) return;
|
|
132
|
-
this.heartbeatTimer = setInterval(() => {
|
|
133
|
-
this.client.sendHeartbeat(this.eventId, this.userId).catch(() => {
|
|
134
|
-
});
|
|
135
|
-
}, this.pollInterval);
|
|
136
|
-
}
|
|
137
|
-
scheduleExpiry(expiresAt) {
|
|
138
|
-
if (this.expiryTimer) clearTimeout(this.expiryTimer);
|
|
139
|
-
const msLeft = expiresAt * 1e3 - Date.now();
|
|
140
|
-
if (msLeft <= 0) {
|
|
141
|
-
this.handleExpired();
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
this.expiryTimer = setTimeout(() => this.handleExpired(), msLeft);
|
|
145
|
-
}
|
|
146
|
-
handleExpired() {
|
|
147
|
-
this.stopTimers();
|
|
148
|
-
this.updateUI("EXPIRED");
|
|
149
|
-
this.emit("expired", {
|
|
150
|
-
userId: this.userId,
|
|
151
|
-
eventId: this.eventId
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
// Core: polling + join
|
|
155
|
-
async checkQueue() {
|
|
156
|
-
if (this.destroyed) return;
|
|
157
|
-
try {
|
|
158
|
-
const res = await this.client.joinQueue(this.eventId, this.userId);
|
|
159
|
-
if (res.status === "ACTIVE") {
|
|
160
|
-
if (this.pollingTimer) {
|
|
161
|
-
clearInterval(this.pollingTimer);
|
|
162
|
-
this.pollingTimer = void 0;
|
|
163
|
-
}
|
|
164
|
-
this.startHeartbeat();
|
|
165
|
-
this.scheduleExpiry(res.expiresAt);
|
|
166
|
-
this.updateUI("ACTIVE");
|
|
167
|
-
this.emit("passed", {
|
|
168
|
-
token: res.token,
|
|
169
|
-
expiresAt: res.expiresAt,
|
|
170
|
-
userId: this.userId,
|
|
171
|
-
eventId: this.eventId
|
|
172
|
-
});
|
|
173
|
-
} else if (res.status === "WAITING") {
|
|
174
|
-
this.updateUI("WAITING", {
|
|
175
|
-
position: res.position,
|
|
176
|
-
ahead: res.ahead
|
|
177
|
-
});
|
|
178
|
-
this.emit("position", {
|
|
179
|
-
position: res.position,
|
|
180
|
-
ahead: res.ahead,
|
|
181
|
-
userId: this.userId,
|
|
182
|
-
eventId: this.eventId
|
|
183
|
-
});
|
|
184
|
-
if (!this.pollingTimer) {
|
|
185
|
-
this.pollingTimer = setInterval(
|
|
186
|
-
() => this.checkQueue(),
|
|
187
|
-
this.pollInterval
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
} catch {
|
|
192
|
-
this.updateUI("ERROR");
|
|
193
|
-
this.stopTimers();
|
|
194
|
-
this.emit("error", {
|
|
195
|
-
userId: this.userId,
|
|
196
|
-
eventId: this.eventId
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
var CentralQClient = class {
|
|
202
|
-
constructor(defaults) {
|
|
203
|
-
this.defaults = defaults;
|
|
204
|
-
}
|
|
205
|
-
issueQueueInitToken(eventId, userId) {
|
|
206
|
-
const client = new QueueHttpClient(
|
|
207
|
-
this.defaults.apiUrl,
|
|
208
|
-
this.defaults.apiKey
|
|
209
|
-
);
|
|
210
|
-
return client.issueQueueInitToken(eventId, userId);
|
|
211
|
-
}
|
|
212
|
-
createQueue(options) {
|
|
213
|
-
return CentralQ.init({
|
|
214
|
-
apiUrl: options.apiUrl ?? this.defaults.apiUrl,
|
|
215
|
-
apiKey: options.apiKey ?? this.defaults.apiKey,
|
|
216
|
-
eventId: options.eventId,
|
|
217
|
-
userId: options.userId ?? this.defaults.userId,
|
|
218
|
-
queueInitToken: options.queueInitToken ?? this.defaults.queueInitToken,
|
|
219
|
-
pollInterval: options.pollInterval ?? this.defaults.pollInterval,
|
|
220
|
-
container: options.container ?? this.defaults.container
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
function createCentralQClient(options) {
|
|
225
|
-
return new CentralQClient({
|
|
226
|
-
...options,
|
|
227
|
-
apiUrl: options.apiUrl ?? CENTRALQ_DEFAULT_API_URL
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export {
|
|
232
|
-
CentralQ,
|
|
233
|
-
CentralQClient,
|
|
234
|
-
createCentralQClient
|
|
235
|
-
};
|
package/dist/chunk-A37B25XO.mjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// src/queue-client.ts
|
|
2
|
-
var CENTRALQ_DEFAULT_API_URL = "http://localhost:3001";
|
|
3
|
-
function normalizeApiUrl(apiUrl) {
|
|
4
|
-
const trimmed = apiUrl.replace(/\/+$/, "");
|
|
5
|
-
return trimmed.endsWith("/api") ? trimmed.slice(0, -4) : trimmed;
|
|
6
|
-
}
|
|
7
|
-
var QueueHttpClient = class {
|
|
8
|
-
constructor(apiUrl = CENTRALQ_DEFAULT_API_URL, apiKey, queueInitToken) {
|
|
9
|
-
this.apiUrl = apiUrl;
|
|
10
|
-
this.apiKey = apiKey;
|
|
11
|
-
this.queueInitToken = queueInitToken;
|
|
12
|
-
this.apiUrl = normalizeApiUrl(this.apiUrl);
|
|
13
|
-
}
|
|
14
|
-
get headers() {
|
|
15
|
-
const h = { "Content-Type": "application/json" };
|
|
16
|
-
if (this.apiKey) h["x-api-key"] = this.apiKey;
|
|
17
|
-
if (this.queueInitToken) h["x-queue-init-token"] = this.queueInitToken;
|
|
18
|
-
return h;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Intenta unir a un usuario a la cola de un evento.
|
|
22
|
-
* Llama a POST /api/queue/:eventId/join en el worker.
|
|
23
|
-
*/
|
|
24
|
-
async joinQueue(eventId, userId) {
|
|
25
|
-
const res = await fetch(
|
|
26
|
-
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/join`,
|
|
27
|
-
{
|
|
28
|
-
method: "POST",
|
|
29
|
-
headers: this.headers,
|
|
30
|
-
body: JSON.stringify({ userId })
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
const body = await res.json().catch(() => ({}));
|
|
35
|
-
throw new Error(
|
|
36
|
-
body.message ?? `Error ${res.status} al conectar con el sistema de colas`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
return res.json();
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Envía un heartbeat para mantener vivo el slot (waiting o active).
|
|
43
|
-
* El SDK lo llama cada 10s automáticamente.
|
|
44
|
-
*/
|
|
45
|
-
async sendHeartbeat(eventId, userId) {
|
|
46
|
-
await fetch(
|
|
47
|
-
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/heartbeat`,
|
|
48
|
-
{
|
|
49
|
-
method: "POST",
|
|
50
|
-
headers: this.headers,
|
|
51
|
-
body: JSON.stringify({ userId })
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Libera el slot del usuario inmediatamente.
|
|
57
|
-
* Llamar al completar la compra o al salir voluntariamente.
|
|
58
|
-
*/
|
|
59
|
-
async leaveQueue(eventId, userId) {
|
|
60
|
-
await fetch(
|
|
61
|
-
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/leave`,
|
|
62
|
-
{
|
|
63
|
-
method: "POST",
|
|
64
|
-
headers: this.headers,
|
|
65
|
-
body: JSON.stringify({ userId })
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
async issueQueueInitToken(eventId, userId) {
|
|
70
|
-
const res = await fetch(
|
|
71
|
-
`${this.apiUrl}/api/queue/init/${encodeURIComponent(eventId)}`,
|
|
72
|
-
{
|
|
73
|
-
method: "POST",
|
|
74
|
-
headers: this.headers,
|
|
75
|
-
body: JSON.stringify({ userId })
|
|
76
|
-
}
|
|
77
|
-
);
|
|
78
|
-
const body = await res.json().catch(() => ({}));
|
|
79
|
-
if (!res.ok) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
body.message ?? `Error ${res.status} al inicializar sesi\xF3n de cola`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
const token = body.queueInitToken ?? body.initToken;
|
|
85
|
-
if (!body.userId || !token || !body.expiresAt) {
|
|
86
|
-
throw new Error("Respuesta inv\xE1lida al inicializar sesi\xF3n de cola");
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
userId: body.userId,
|
|
90
|
-
queueInitToken: token,
|
|
91
|
-
expiresAt: body.expiresAt
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
async verifyToken(eventId, token) {
|
|
95
|
-
const res = await fetch(
|
|
96
|
-
`${this.apiUrl}/api/queue/verify/${encodeURIComponent(eventId)}`,
|
|
97
|
-
{
|
|
98
|
-
method: "POST",
|
|
99
|
-
headers: this.headers,
|
|
100
|
-
body: JSON.stringify({ token })
|
|
101
|
-
}
|
|
102
|
-
);
|
|
103
|
-
const body = await res.json().catch(() => ({
|
|
104
|
-
valid: false,
|
|
105
|
-
reason: "Respuesta inv\xE1lida"
|
|
106
|
-
}));
|
|
107
|
-
if (body.valid === true && body.userId && body.eventId && body.expiresAt) {
|
|
108
|
-
return body;
|
|
109
|
-
}
|
|
110
|
-
if (body.valid === false) {
|
|
111
|
-
return { valid: false, reason: body.reason ?? "Token inv\xE1lido" };
|
|
112
|
-
}
|
|
113
|
-
if (!res.ok) {
|
|
114
|
-
return {
|
|
115
|
-
valid: false,
|
|
116
|
-
reason: body.message ?? `Error ${res.status} al validar token de cola`
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return { valid: false, reason: "Respuesta inv\xE1lida" };
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export {
|
|
124
|
-
CENTRALQ_DEFAULT_API_URL,
|
|
125
|
-
QueueHttpClient
|
|
126
|
-
};
|
package/dist/chunk-CURBGL7P.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CENTRALQ_DEFAULT_API_URL
|
|
3
|
-
} from "./chunk-P73Q2ZIO.mjs";
|
|
4
|
-
|
|
5
|
-
// src/server.ts
|
|
6
|
-
function normalizeApiUrl(apiUrl) {
|
|
7
|
-
return apiUrl.replace(/\/+$/, "");
|
|
8
|
-
}
|
|
9
|
-
async function postQueueServer(apiUrl, path, secretKey, body, fallback) {
|
|
10
|
-
const response = await fetch(`${normalizeApiUrl(apiUrl)}${path}`, {
|
|
11
|
-
method: "POST",
|
|
12
|
-
headers: {
|
|
13
|
-
"Content-Type": "application/json",
|
|
14
|
-
"x-api-key": secretKey
|
|
15
|
-
},
|
|
16
|
-
body: JSON.stringify(body)
|
|
17
|
-
});
|
|
18
|
-
const data = await response.json().catch(() => fallback);
|
|
19
|
-
return { status: response.status, data };
|
|
20
|
-
}
|
|
21
|
-
async function validateQueueTokenServer(options) {
|
|
22
|
-
const apiUrl = options.apiUrl ?? CENTRALQ_DEFAULT_API_URL;
|
|
23
|
-
return postQueueServer(
|
|
24
|
-
apiUrl,
|
|
25
|
-
`/api/queue/verify/${encodeURIComponent(options.eventId)}`,
|
|
26
|
-
options.secretKey,
|
|
27
|
-
{ token: options.token },
|
|
28
|
-
{ valid: false, reason: "Respuesta inv\xE1lida" }
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
async function verifyQueueAccessServer(options) {
|
|
32
|
-
const apiUrl = options.apiUrl ?? CENTRALQ_DEFAULT_API_URL;
|
|
33
|
-
return postQueueServer(
|
|
34
|
-
apiUrl,
|
|
35
|
-
`/api/queue/verify/${encodeURIComponent(options.eventId)}/access`,
|
|
36
|
-
options.secretKey,
|
|
37
|
-
{ token: options.token ?? null },
|
|
38
|
-
{
|
|
39
|
-
allowed: false,
|
|
40
|
-
reason: "invalid_response",
|
|
41
|
-
message: "Respuesta inv\xE1lida"
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
async function completeQueueAccessServer(options) {
|
|
46
|
-
const apiUrl = options.apiUrl ?? CENTRALQ_DEFAULT_API_URL;
|
|
47
|
-
return postQueueServer(
|
|
48
|
-
apiUrl,
|
|
49
|
-
`/api/queue/verify/${encodeURIComponent(options.eventId)}/complete`,
|
|
50
|
-
options.secretKey,
|
|
51
|
-
{
|
|
52
|
-
token: options.token,
|
|
53
|
-
completionId: options.completionId
|
|
54
|
-
},
|
|
55
|
-
{ completed: false, reason: "invalid_response" }
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export {
|
|
60
|
-
validateQueueTokenServer,
|
|
61
|
-
verifyQueueAccessServer,
|
|
62
|
-
completeQueueAccessServer
|
|
63
|
-
};
|
package/dist/chunk-GWPLLJTU.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CENTRALQ_DEFAULT_API_URL
|
|
3
|
-
} from "./chunk-A37B25XO.mjs";
|
|
4
|
-
|
|
5
|
-
// src/server.ts
|
|
6
|
-
function normalizeApiUrl(apiUrl) {
|
|
7
|
-
return apiUrl.replace(/\/+$/, "");
|
|
8
|
-
}
|
|
9
|
-
async function validateQueueTokenServer(options) {
|
|
10
|
-
const apiUrl = options.apiUrl ?? CENTRALQ_DEFAULT_API_URL;
|
|
11
|
-
const response = await fetch(
|
|
12
|
-
`${normalizeApiUrl(apiUrl)}/api/queue/verify/${encodeURIComponent(options.eventId)}`,
|
|
13
|
-
{
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
"x-api-key": options.secretKey
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({ token: options.token })
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
const data = await response.json().catch(() => ({
|
|
23
|
-
valid: false,
|
|
24
|
-
reason: "Respuesta inv\xE1lida"
|
|
25
|
-
}));
|
|
26
|
-
return { status: response.status, data };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
validateQueueTokenServer
|
|
31
|
-
};
|
package/dist/chunk-JJ33EJ65.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CENTRALQ_DEFAULT_API_URL
|
|
3
|
-
} from "./chunk-P73Q2ZIO.mjs";
|
|
4
|
-
|
|
5
|
-
// src/server.ts
|
|
6
|
-
function normalizeApiUrl(apiUrl) {
|
|
7
|
-
return apiUrl.replace(/\/+$/, "");
|
|
8
|
-
}
|
|
9
|
-
async function validateQueueTokenServer(options) {
|
|
10
|
-
const apiUrl = options.apiUrl ?? CENTRALQ_DEFAULT_API_URL;
|
|
11
|
-
const response = await fetch(
|
|
12
|
-
`${normalizeApiUrl(apiUrl)}/api/queue/verify/${encodeURIComponent(options.eventId)}`,
|
|
13
|
-
{
|
|
14
|
-
method: "POST",
|
|
15
|
-
headers: {
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
"x-api-key": options.secretKey
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({ token: options.token })
|
|
20
|
-
}
|
|
21
|
-
);
|
|
22
|
-
const data = await response.json().catch(() => ({
|
|
23
|
-
valid: false,
|
|
24
|
-
reason: "Respuesta inv\xE1lida"
|
|
25
|
-
}));
|
|
26
|
-
return { status: response.status, data };
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
validateQueueTokenServer
|
|
31
|
-
};
|