@central-ticket/queue-sdk 0.0.1 → 0.0.3
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 +134 -0
- package/dist/centralq-C3ukDo0x.d.ts +134 -0
- package/dist/{chunk-A4HITWM4.mjs → chunk-4MXU7S6A.mjs} +1 -1
- package/dist/{chunk-42RGFZKP.mjs → chunk-A37B25XO.mjs} +27 -0
- package/dist/chunk-BVCZFNM3.mjs +329 -0
- package/dist/chunk-CURBGL7P.mjs +63 -0
- package/dist/chunk-FAJWYFUK.mjs +115 -0
- package/dist/{chunk-JR7BCYB5.mjs → chunk-GWPLLJTU.mjs} +2 -2
- package/dist/chunk-JJ33EJ65.mjs +31 -0
- package/dist/chunk-P73Q2ZIO.mjs +167 -0
- package/dist/chunk-XIQ6LS62.mjs +312 -0
- package/dist/index.d.mts +32 -4
- package/dist/index.d.ts +32 -4
- package/dist/index.js +273 -22
- package/dist/index.mjs +15 -5
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +70 -2
- package/dist/react.mjs +2 -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 +70 -2
- package/dist/svelte.mjs +2 -2
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/package.json +2 -2
package/dist/server.d.ts
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 };
|
package/dist/server.js
CHANGED
|
@@ -20,7 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/server.ts
|
|
21
21
|
var server_exports = {};
|
|
22
22
|
__export(server_exports, {
|
|
23
|
-
|
|
23
|
+
CentralQServerClient: () => CentralQServerClient,
|
|
24
|
+
CentralQServerRequestError: () => CentralQServerRequestError,
|
|
25
|
+
completeQueueAccessServer: () => completeQueueAccessServer,
|
|
26
|
+
createCentralQServerClient: () => createCentralQServerClient,
|
|
27
|
+
validateQueueTokenServer: () => validateQueueTokenServer,
|
|
28
|
+
verifyQueueAccessServer: () => verifyQueueAccessServer
|
|
24
29
|
});
|
|
25
30
|
module.exports = __toCommonJS(server_exports);
|
|
26
31
|
|
|
@@ -28,29 +33,113 @@ module.exports = __toCommonJS(server_exports);
|
|
|
28
33
|
var CENTRALQ_DEFAULT_API_URL = "http://localhost:3001";
|
|
29
34
|
|
|
30
35
|
// src/server.ts
|
|
36
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
37
|
+
var CentralQServerRequestError = class extends Error {
|
|
38
|
+
constructor(code, message, options) {
|
|
39
|
+
super(message, options);
|
|
40
|
+
this.name = "CentralQServerRequestError";
|
|
41
|
+
this.code = code;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
31
44
|
function normalizeApiUrl(apiUrl) {
|
|
32
|
-
|
|
45
|
+
const trimmed = apiUrl.trim().replace(/\/+$/, "");
|
|
46
|
+
return trimmed.endsWith("/api") ? trimmed.slice(0, -4) : trimmed;
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
function validateOptions(options) {
|
|
49
|
+
if (!options.secretKey?.trim()) {
|
|
50
|
+
throw new TypeError("CentralQ secretKey es requerida");
|
|
51
|
+
}
|
|
52
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs <= 0) {
|
|
53
|
+
throw new TypeError("CentralQ timeoutMs debe ser mayor a cero");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
var CentralQServerClient = class {
|
|
57
|
+
constructor(options) {
|
|
58
|
+
validateOptions(options);
|
|
59
|
+
this.apiUrl = normalizeApiUrl(options.apiUrl ?? CENTRALQ_DEFAULT_API_URL);
|
|
60
|
+
this.secretKey = options.secretKey.trim();
|
|
61
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
62
|
+
this.fetchFn = options.fetch ?? globalThis.fetch;
|
|
63
|
+
}
|
|
64
|
+
validateToken(input) {
|
|
65
|
+
return this.post(
|
|
66
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}`,
|
|
67
|
+
{ token: input.token },
|
|
68
|
+
{ valid: false, reason: "Respuesta inv\xE1lida" }
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
verifyAccess(input) {
|
|
72
|
+
return this.post(
|
|
73
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}/access`,
|
|
74
|
+
{ token: input.token ?? null },
|
|
75
|
+
{
|
|
76
|
+
allowed: false,
|
|
77
|
+
reason: "invalid_response",
|
|
78
|
+
message: "Respuesta inv\xE1lida"
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
completeAccess(input) {
|
|
83
|
+
return this.post(
|
|
84
|
+
`/api/queue/verify/${encodeURIComponent(input.eventId)}/complete`,
|
|
85
|
+
{
|
|
86
|
+
token: input.token,
|
|
87
|
+
completionId: input.completionId
|
|
43
88
|
},
|
|
44
|
-
|
|
89
|
+
{ completed: false, reason: "invalid_response" }
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
async post(path, body, fallback) {
|
|
93
|
+
const controller = new AbortController();
|
|
94
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
95
|
+
try {
|
|
96
|
+
const response = await this.fetchFn(`${this.apiUrl}${path}`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: {
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
"x-api-key": this.secretKey
|
|
101
|
+
},
|
|
102
|
+
body: JSON.stringify(body),
|
|
103
|
+
signal: controller.signal
|
|
104
|
+
});
|
|
105
|
+
const data = await response.json().catch(() => fallback);
|
|
106
|
+
return { status: response.status, data };
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (controller.signal.aborted) {
|
|
109
|
+
throw new CentralQServerRequestError(
|
|
110
|
+
"timeout",
|
|
111
|
+
`CentralQ no respondi\xF3 en ${this.timeoutMs}ms`,
|
|
112
|
+
{ cause: error }
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
throw new CentralQServerRequestError(
|
|
116
|
+
"network_error",
|
|
117
|
+
"No se pudo conectar con CentralQ",
|
|
118
|
+
{ cause: error }
|
|
119
|
+
);
|
|
120
|
+
} finally {
|
|
121
|
+
clearTimeout(timeout);
|
|
45
122
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function createCentralQServerClient(options) {
|
|
126
|
+
return new CentralQServerClient(options);
|
|
127
|
+
}
|
|
128
|
+
function validateQueueTokenServer(options) {
|
|
129
|
+
return createCentralQServerClient(options).validateToken(options);
|
|
130
|
+
}
|
|
131
|
+
function verifyQueueAccessServer(options) {
|
|
132
|
+
return createCentralQServerClient(options).verifyAccess(options);
|
|
133
|
+
}
|
|
134
|
+
function completeQueueAccessServer(options) {
|
|
135
|
+
return createCentralQServerClient(options).completeAccess(options);
|
|
52
136
|
}
|
|
53
137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
138
|
0 && (module.exports = {
|
|
55
|
-
|
|
139
|
+
CentralQServerClient,
|
|
140
|
+
CentralQServerRequestError,
|
|
141
|
+
completeQueueAccessServer,
|
|
142
|
+
createCentralQServerClient,
|
|
143
|
+
validateQueueTokenServer,
|
|
144
|
+
verifyQueueAccessServer
|
|
56
145
|
});
|
package/dist/server.mjs
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
CentralQServerClient,
|
|
3
|
+
CentralQServerRequestError,
|
|
4
|
+
completeQueueAccessServer,
|
|
5
|
+
createCentralQServerClient,
|
|
6
|
+
validateQueueTokenServer,
|
|
7
|
+
verifyQueueAccessServer
|
|
8
|
+
} from "./chunk-FAJWYFUK.mjs";
|
|
9
|
+
import "./chunk-P73Q2ZIO.mjs";
|
|
5
10
|
import "./chunk-XRJFNASX.mjs";
|
|
6
11
|
export {
|
|
7
|
-
|
|
12
|
+
CentralQServerClient,
|
|
13
|
+
CentralQServerRequestError,
|
|
14
|
+
completeQueueAccessServer,
|
|
15
|
+
createCentralQServerClient,
|
|
16
|
+
validateQueueTokenServer,
|
|
17
|
+
verifyQueueAccessServer
|
|
8
18
|
};
|
package/dist/svelte.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'svelte/store';
|
|
2
|
-
import { Q as QueueStatus, C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, d as CentralQOptions } from './centralq-
|
|
2
|
+
import { Q as QueueStatus, C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, d as CentralQOptions } from './centralq-C3ukDo0x.mjs';
|
|
3
3
|
|
|
4
4
|
interface CentralQStores {
|
|
5
5
|
/** Store con el token JWT si el usuario fue admitido */
|
package/dist/svelte.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'svelte/store';
|
|
2
|
-
import { Q as QueueStatus, C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, d as CentralQOptions } from './centralq-
|
|
2
|
+
import { Q as QueueStatus, C as CentralQ, c as CentralQCreateOptions, a as CentralQClient, d as CentralQOptions } from './centralq-C3ukDo0x.js';
|
|
3
3
|
|
|
4
4
|
interface CentralQStores {
|
|
5
5
|
/** Store con el token JWT si el usuario fue admitido */
|
package/dist/svelte.js
CHANGED
|
@@ -221,13 +221,13 @@ var QueueHttpClient = class {
|
|
|
221
221
|
}
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
|
-
async issueQueueInitToken(eventId, userId) {
|
|
224
|
+
async issueQueueInitToken(eventId, userId, admissionProof) {
|
|
225
225
|
const res = await fetch(
|
|
226
226
|
`${this.apiUrl}/api/queue/init/${encodeURIComponent(eventId)}`,
|
|
227
227
|
{
|
|
228
228
|
method: "POST",
|
|
229
229
|
headers: this.headers,
|
|
230
|
-
body: JSON.stringify({ userId })
|
|
230
|
+
body: JSON.stringify({ userId, admissionProof })
|
|
231
231
|
}
|
|
232
232
|
);
|
|
233
233
|
const body = await res.json().catch(() => ({}));
|
|
@@ -246,6 +246,74 @@ var QueueHttpClient = class {
|
|
|
246
246
|
expiresAt: body.expiresAt
|
|
247
247
|
};
|
|
248
248
|
}
|
|
249
|
+
async getProtection(eventId) {
|
|
250
|
+
const res = await fetch(
|
|
251
|
+
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/protection`,
|
|
252
|
+
{ headers: this.headers }
|
|
253
|
+
);
|
|
254
|
+
const body = await res.json().catch(() => ({}));
|
|
255
|
+
if (!res.ok) {
|
|
256
|
+
throw new Error(
|
|
257
|
+
body.message ?? `Error ${res.status} al consultar protecci\xF3n`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
eventId: body.eventId ?? eventId,
|
|
262
|
+
configured: body.configured === true,
|
|
263
|
+
protected: body.protected === true,
|
|
264
|
+
isActive: body.isActive === true,
|
|
265
|
+
admissionMode: body.admissionMode ?? "PUBLIC",
|
|
266
|
+
challengeRequired: body.challengeRequired === true
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
async getAdmissionChallenge(eventId) {
|
|
270
|
+
const res = await fetch(
|
|
271
|
+
`${this.apiUrl}/api/queue/${encodeURIComponent(eventId)}/admission`,
|
|
272
|
+
{ headers: this.headers }
|
|
273
|
+
);
|
|
274
|
+
const body = await res.json().catch(() => ({}));
|
|
275
|
+
if (!res.ok) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
body.message ?? `Error ${res.status} al preparar la admisi\xF3n`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (body.required !== true) return { required: false };
|
|
281
|
+
if (!("publicKey" in body) || !body.publicKey) {
|
|
282
|
+
throw new Error("Respuesta inv\xE1lida al preparar la admisi\xF3n");
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
required: true,
|
|
286
|
+
publicKey: body.publicKey,
|
|
287
|
+
appearance: "interaction-only"
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
async verifyToken(eventId, token) {
|
|
291
|
+
const res = await fetch(
|
|
292
|
+
`${this.apiUrl}/api/queue/verify/${encodeURIComponent(eventId)}`,
|
|
293
|
+
{
|
|
294
|
+
method: "POST",
|
|
295
|
+
headers: this.headers,
|
|
296
|
+
body: JSON.stringify({ token })
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
const body = await res.json().catch(() => ({
|
|
300
|
+
valid: false,
|
|
301
|
+
reason: "Respuesta inv\xE1lida"
|
|
302
|
+
}));
|
|
303
|
+
if (body.valid === true && body.userId && body.eventId && body.expiresAt) {
|
|
304
|
+
return body;
|
|
305
|
+
}
|
|
306
|
+
if (body.valid === false) {
|
|
307
|
+
return { valid: false, reason: body.reason ?? "Token inv\xE1lido" };
|
|
308
|
+
}
|
|
309
|
+
if (!res.ok) {
|
|
310
|
+
return {
|
|
311
|
+
valid: false,
|
|
312
|
+
reason: body.message ?? `Error ${res.status} al validar token de cola`
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
return { valid: false, reason: "Respuesta inv\xE1lida" };
|
|
316
|
+
}
|
|
249
317
|
};
|
|
250
318
|
|
|
251
319
|
// src/centralq.ts
|
package/dist/svelte.mjs
CHANGED
package/dist/vue.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-
|
|
2
|
+
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-C3ukDo0x.mjs';
|
|
3
3
|
|
|
4
4
|
interface QueueData {
|
|
5
5
|
token: string | null;
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
|
-
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-
|
|
2
|
+
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-C3ukDo0x.js';
|
|
3
3
|
|
|
4
4
|
interface QueueData {
|
|
5
5
|
token: string | null;
|