@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.
- package/dist/centralq-I9tdL_Xr.d.mts +133 -0
- package/dist/centralq-I9tdL_Xr.d.ts +133 -0
- package/dist/chunk-42RGFZKP.mjs +99 -0
- package/dist/chunk-A4HITWM4.mjs +235 -0
- package/dist/chunk-JR7BCYB5.mjs +31 -0
- package/dist/chunk-XRJFNASX.mjs +14 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +509 -0
- package/dist/index.mjs +21 -0
- package/dist/queue-element-DXBW64U2.mjs +111 -0
- package/dist/react.d.mts +65 -0
- package/dist/react.d.ts +65 -0
- package/dist/react.js +624 -0
- package/dist/react.mjs +185 -0
- package/dist/server.d.mts +21 -0
- package/dist/server.d.ts +21 -0
- package/dist/server.js +56 -0
- package/dist/server.mjs +8 -0
- package/dist/svelte.d.mts +79 -0
- package/dist/svelte.d.ts +79 -0
- package/dist/svelte.js +628 -0
- package/dist/svelte.mjs +189 -0
- package/dist/vue.d.mts +31 -0
- package/dist/vue.d.ts +31 -0
- package/dist/vue.js +152 -0
- package/dist/vue.mjs +136 -0
- package/package.json +90 -0
package/dist/svelte.mjs
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CentralQ
|
|
3
|
+
} from "./chunk-A4HITWM4.mjs";
|
|
4
|
+
import "./chunk-42RGFZKP.mjs";
|
|
5
|
+
import "./chunk-XRJFNASX.mjs";
|
|
6
|
+
|
|
7
|
+
// src/svelte.ts
|
|
8
|
+
import { writable, readonly, get, derived } from "svelte/store";
|
|
9
|
+
import { onMount } from "svelte";
|
|
10
|
+
function createCentralQ(options) {
|
|
11
|
+
const _token = writable(null);
|
|
12
|
+
const _position = writable(null);
|
|
13
|
+
const _ahead = writable(null);
|
|
14
|
+
const _expired = writable(false);
|
|
15
|
+
const _error = writable(false);
|
|
16
|
+
let queue = null;
|
|
17
|
+
onMount(() => {
|
|
18
|
+
queue = CentralQ.init(options);
|
|
19
|
+
queue.on("passed", (detail) => {
|
|
20
|
+
_token.set(detail.token);
|
|
21
|
+
_position.set(null);
|
|
22
|
+
_ahead.set(null);
|
|
23
|
+
_expired.set(false);
|
|
24
|
+
_error.set(false);
|
|
25
|
+
});
|
|
26
|
+
queue.on("position", (detail) => {
|
|
27
|
+
_position.set(detail.position);
|
|
28
|
+
_ahead.set(detail.ahead);
|
|
29
|
+
});
|
|
30
|
+
queue.on("expired", () => {
|
|
31
|
+
_token.set(null);
|
|
32
|
+
_expired.set(true);
|
|
33
|
+
});
|
|
34
|
+
queue.on("error", () => {
|
|
35
|
+
_error.set(true);
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
queue?.destroy();
|
|
39
|
+
queue = null;
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
token: readonly(_token),
|
|
44
|
+
position: readonly(_position),
|
|
45
|
+
ahead: readonly(_ahead),
|
|
46
|
+
expired: readonly(_expired),
|
|
47
|
+
error: readonly(_error),
|
|
48
|
+
leave: () => {
|
|
49
|
+
queue?.leave();
|
|
50
|
+
_token.set(null);
|
|
51
|
+
_position.set(null);
|
|
52
|
+
_ahead.set(null);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function useQueue(optionsInput) {
|
|
57
|
+
const status = writable("idle");
|
|
58
|
+
const data = writable({
|
|
59
|
+
token: null,
|
|
60
|
+
position: null,
|
|
61
|
+
ahead: null,
|
|
62
|
+
expiresAt: null
|
|
63
|
+
});
|
|
64
|
+
const error = writable(null);
|
|
65
|
+
const isPending = writable(true);
|
|
66
|
+
const instance = writable(null);
|
|
67
|
+
const token = derived(data, ($data) => $data.token);
|
|
68
|
+
const position = derived(data, ($data) => $data.position);
|
|
69
|
+
const ahead = derived(data, ($data) => $data.ahead);
|
|
70
|
+
const expiresAt = derived(data, ($data) => $data.expiresAt);
|
|
71
|
+
const reset = () => {
|
|
72
|
+
status.set("idle");
|
|
73
|
+
error.set(null);
|
|
74
|
+
data.set({ token: null, position: null, ahead: null, expiresAt: null });
|
|
75
|
+
isPending.set(true);
|
|
76
|
+
};
|
|
77
|
+
const leave = () => {
|
|
78
|
+
get(instance)?.leave();
|
|
79
|
+
status.set("idle");
|
|
80
|
+
data.set({ token: null, position: null, ahead: null, expiresAt: null });
|
|
81
|
+
isPending.set(true);
|
|
82
|
+
};
|
|
83
|
+
onMount(() => {
|
|
84
|
+
let queue = null;
|
|
85
|
+
let cancelled = false;
|
|
86
|
+
const options = typeof optionsInput === "function" ? optionsInput() : optionsInput;
|
|
87
|
+
if (options.enabled === false) {
|
|
88
|
+
reset();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
status.set("joining");
|
|
92
|
+
error.set(null);
|
|
93
|
+
isPending.set(true);
|
|
94
|
+
const init = async () => {
|
|
95
|
+
try {
|
|
96
|
+
let userId = options.userId;
|
|
97
|
+
let queueInitToken = options.queueInitToken;
|
|
98
|
+
if (!userId || !queueInitToken) {
|
|
99
|
+
if (options.autoInitToken === false) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Falta queueInitToken/userId y initEndpoint est\xE1 deshabilitado"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
const init2 = await options.client.issueQueueInitToken(
|
|
105
|
+
options.eventId,
|
|
106
|
+
userId
|
|
107
|
+
);
|
|
108
|
+
userId = init2.userId;
|
|
109
|
+
queueInitToken = init2.queueInitToken;
|
|
110
|
+
}
|
|
111
|
+
if (cancelled) return;
|
|
112
|
+
queue = options.client.createQueue({
|
|
113
|
+
eventId: options.eventId,
|
|
114
|
+
userId,
|
|
115
|
+
queueInitToken,
|
|
116
|
+
pollInterval: options.pollInterval,
|
|
117
|
+
container: options.container
|
|
118
|
+
});
|
|
119
|
+
queue.on("passed", (detail) => {
|
|
120
|
+
data.set({
|
|
121
|
+
token: detail.token,
|
|
122
|
+
position: null,
|
|
123
|
+
ahead: null,
|
|
124
|
+
expiresAt: detail.expiresAt
|
|
125
|
+
});
|
|
126
|
+
status.set("passed");
|
|
127
|
+
error.set(null);
|
|
128
|
+
isPending.set(false);
|
|
129
|
+
});
|
|
130
|
+
queue.on("position", (detail) => {
|
|
131
|
+
data.update((prev) => ({
|
|
132
|
+
...prev,
|
|
133
|
+
token: null,
|
|
134
|
+
position: detail.position,
|
|
135
|
+
ahead: detail.ahead
|
|
136
|
+
}));
|
|
137
|
+
status.set("waiting");
|
|
138
|
+
isPending.set(false);
|
|
139
|
+
});
|
|
140
|
+
queue.on("expired", () => {
|
|
141
|
+
data.set({
|
|
142
|
+
token: null,
|
|
143
|
+
position: null,
|
|
144
|
+
ahead: null,
|
|
145
|
+
expiresAt: null
|
|
146
|
+
});
|
|
147
|
+
status.set("expired");
|
|
148
|
+
isPending.set(false);
|
|
149
|
+
});
|
|
150
|
+
queue.on("error", () => {
|
|
151
|
+
status.set("error");
|
|
152
|
+
error.set(new Error("Queue connection error"));
|
|
153
|
+
isPending.set(false);
|
|
154
|
+
});
|
|
155
|
+
instance.set(queue);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
if (cancelled) return;
|
|
158
|
+
status.set("error");
|
|
159
|
+
error.set(
|
|
160
|
+
err instanceof Error ? err : new Error("Queue connection error")
|
|
161
|
+
);
|
|
162
|
+
isPending.set(false);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
init();
|
|
166
|
+
return () => {
|
|
167
|
+
cancelled = true;
|
|
168
|
+
queue?.destroy();
|
|
169
|
+
instance.set(null);
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
status: readonly(status),
|
|
174
|
+
token,
|
|
175
|
+
position,
|
|
176
|
+
ahead,
|
|
177
|
+
expiresAt,
|
|
178
|
+
data: readonly(data),
|
|
179
|
+
isPending: readonly(isPending),
|
|
180
|
+
error: readonly(error),
|
|
181
|
+
leave,
|
|
182
|
+
reset,
|
|
183
|
+
instance: readonly(instance)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export {
|
|
187
|
+
createCentralQ,
|
|
188
|
+
useQueue
|
|
189
|
+
};
|
package/dist/vue.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-I9tdL_Xr.mjs';
|
|
3
|
+
|
|
4
|
+
interface QueueData {
|
|
5
|
+
token: string | null;
|
|
6
|
+
position: number | null;
|
|
7
|
+
ahead: number | null;
|
|
8
|
+
expiresAt: number | null;
|
|
9
|
+
}
|
|
10
|
+
interface UseQueueOptions extends Omit<CentralQCreateOptions, "apiUrl" | "apiKey"> {
|
|
11
|
+
client: CentralQClient;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
autoInitToken?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type UseQueueOptionsInput = UseQueueOptions | (() => UseQueueOptions);
|
|
16
|
+
interface UseQueueReturn {
|
|
17
|
+
status: Readonly<Ref<QueueStatus>>;
|
|
18
|
+
token: Readonly<Ref<string | null>>;
|
|
19
|
+
position: Readonly<Ref<number | null>>;
|
|
20
|
+
ahead: Readonly<Ref<number | null>>;
|
|
21
|
+
expiresAt: Readonly<Ref<number | null>>;
|
|
22
|
+
data: Readonly<Ref<QueueData>>;
|
|
23
|
+
isPending: Readonly<Ref<boolean>>;
|
|
24
|
+
error: Readonly<Ref<Error | null>>;
|
|
25
|
+
instance: Readonly<Ref<CentralQ | null>>;
|
|
26
|
+
leave: () => void;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare function useQueue(optionsInput: UseQueueOptionsInput): UseQueueReturn;
|
|
30
|
+
|
|
31
|
+
export { type QueueData, type UseQueueOptions, type UseQueueOptionsInput, type UseQueueReturn, useQueue };
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { c as CentralQCreateOptions, a as CentralQClient, Q as QueueStatus, C as CentralQ } from './centralq-I9tdL_Xr.js';
|
|
3
|
+
|
|
4
|
+
interface QueueData {
|
|
5
|
+
token: string | null;
|
|
6
|
+
position: number | null;
|
|
7
|
+
ahead: number | null;
|
|
8
|
+
expiresAt: number | null;
|
|
9
|
+
}
|
|
10
|
+
interface UseQueueOptions extends Omit<CentralQCreateOptions, "apiUrl" | "apiKey"> {
|
|
11
|
+
client: CentralQClient;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
autoInitToken?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type UseQueueOptionsInput = UseQueueOptions | (() => UseQueueOptions);
|
|
16
|
+
interface UseQueueReturn {
|
|
17
|
+
status: Readonly<Ref<QueueStatus>>;
|
|
18
|
+
token: Readonly<Ref<string | null>>;
|
|
19
|
+
position: Readonly<Ref<number | null>>;
|
|
20
|
+
ahead: Readonly<Ref<number | null>>;
|
|
21
|
+
expiresAt: Readonly<Ref<number | null>>;
|
|
22
|
+
data: Readonly<Ref<QueueData>>;
|
|
23
|
+
isPending: Readonly<Ref<boolean>>;
|
|
24
|
+
error: Readonly<Ref<Error | null>>;
|
|
25
|
+
instance: Readonly<Ref<CentralQ | null>>;
|
|
26
|
+
leave: () => void;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare function useQueue(optionsInput: UseQueueOptionsInput): UseQueueReturn;
|
|
30
|
+
|
|
31
|
+
export { type QueueData, type UseQueueOptions, type UseQueueOptionsInput, type UseQueueReturn, useQueue };
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vue.ts
|
|
21
|
+
var vue_exports = {};
|
|
22
|
+
__export(vue_exports, {
|
|
23
|
+
useQueue: () => useQueue
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vue_exports);
|
|
26
|
+
var import_vue = require("vue");
|
|
27
|
+
function useQueue(optionsInput) {
|
|
28
|
+
const status = (0, import_vue.ref)("idle");
|
|
29
|
+
const token = (0, import_vue.ref)(null);
|
|
30
|
+
const position = (0, import_vue.ref)(null);
|
|
31
|
+
const ahead = (0, import_vue.ref)(null);
|
|
32
|
+
const expiresAt = (0, import_vue.ref)(null);
|
|
33
|
+
const data = (0, import_vue.computed)(() => ({
|
|
34
|
+
token: token.value,
|
|
35
|
+
position: position.value,
|
|
36
|
+
ahead: ahead.value,
|
|
37
|
+
expiresAt: expiresAt.value
|
|
38
|
+
}));
|
|
39
|
+
const isPending = (0, import_vue.ref)(true);
|
|
40
|
+
const error = (0, import_vue.ref)(null);
|
|
41
|
+
const instance = (0, import_vue.shallowRef)(null);
|
|
42
|
+
let cancelled = false;
|
|
43
|
+
const readOptions = () => typeof optionsInput === "function" ? optionsInput() : optionsInput;
|
|
44
|
+
const reset = () => {
|
|
45
|
+
status.value = "idle";
|
|
46
|
+
token.value = null;
|
|
47
|
+
position.value = null;
|
|
48
|
+
ahead.value = null;
|
|
49
|
+
expiresAt.value = null;
|
|
50
|
+
isPending.value = true;
|
|
51
|
+
error.value = null;
|
|
52
|
+
};
|
|
53
|
+
const leave = () => {
|
|
54
|
+
instance.value?.leave();
|
|
55
|
+
reset();
|
|
56
|
+
};
|
|
57
|
+
const bindQueueListeners = (queue) => {
|
|
58
|
+
queue.on("passed", (detail) => {
|
|
59
|
+
token.value = detail.token;
|
|
60
|
+
position.value = null;
|
|
61
|
+
ahead.value = null;
|
|
62
|
+
expiresAt.value = detail.expiresAt;
|
|
63
|
+
status.value = "passed";
|
|
64
|
+
isPending.value = false;
|
|
65
|
+
error.value = null;
|
|
66
|
+
});
|
|
67
|
+
queue.on("position", (detail) => {
|
|
68
|
+
token.value = null;
|
|
69
|
+
position.value = detail.position;
|
|
70
|
+
ahead.value = detail.ahead;
|
|
71
|
+
status.value = "waiting";
|
|
72
|
+
isPending.value = false;
|
|
73
|
+
});
|
|
74
|
+
queue.on("expired", () => {
|
|
75
|
+
token.value = null;
|
|
76
|
+
position.value = null;
|
|
77
|
+
ahead.value = null;
|
|
78
|
+
expiresAt.value = null;
|
|
79
|
+
status.value = "expired";
|
|
80
|
+
isPending.value = false;
|
|
81
|
+
});
|
|
82
|
+
queue.on("error", () => {
|
|
83
|
+
status.value = "error";
|
|
84
|
+
isPending.value = false;
|
|
85
|
+
error.value = new Error("Queue connection error");
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
(0, import_vue.onMounted)(async () => {
|
|
89
|
+
const options = readOptions();
|
|
90
|
+
if (options.enabled === false) {
|
|
91
|
+
reset();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
status.value = "joining";
|
|
95
|
+
isPending.value = true;
|
|
96
|
+
error.value = null;
|
|
97
|
+
try {
|
|
98
|
+
let resolvedUserId = options.userId;
|
|
99
|
+
let queueInitToken = options.queueInitToken;
|
|
100
|
+
if (!resolvedUserId || !queueInitToken) {
|
|
101
|
+
if (options.autoInitToken === false) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"Falta queueInitToken/userId y autoInitToken est\xE1 deshabilitado"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const init = await options.client.issueQueueInitToken(
|
|
107
|
+
options.eventId,
|
|
108
|
+
resolvedUserId
|
|
109
|
+
);
|
|
110
|
+
resolvedUserId = init.userId;
|
|
111
|
+
queueInitToken = init.queueInitToken;
|
|
112
|
+
}
|
|
113
|
+
if (cancelled) return;
|
|
114
|
+
const queue = options.client.createQueue({
|
|
115
|
+
eventId: options.eventId,
|
|
116
|
+
userId: resolvedUserId,
|
|
117
|
+
queueInitToken,
|
|
118
|
+
pollInterval: options.pollInterval,
|
|
119
|
+
container: options.container
|
|
120
|
+
});
|
|
121
|
+
bindQueueListeners(queue);
|
|
122
|
+
instance.value = queue;
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if (cancelled) return;
|
|
125
|
+
status.value = "error";
|
|
126
|
+
isPending.value = false;
|
|
127
|
+
error.value = err instanceof Error ? err : new Error("Queue connection error");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
(0, import_vue.onUnmounted)(() => {
|
|
131
|
+
cancelled = true;
|
|
132
|
+
instance.value?.destroy();
|
|
133
|
+
instance.value = null;
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
status: (0, import_vue.readonly)(status),
|
|
137
|
+
token: (0, import_vue.readonly)(token),
|
|
138
|
+
position: (0, import_vue.readonly)(position),
|
|
139
|
+
ahead: (0, import_vue.readonly)(ahead),
|
|
140
|
+
expiresAt: (0, import_vue.readonly)(expiresAt),
|
|
141
|
+
data: (0, import_vue.readonly)(data),
|
|
142
|
+
isPending: (0, import_vue.readonly)(isPending),
|
|
143
|
+
error: (0, import_vue.readonly)(error),
|
|
144
|
+
instance,
|
|
145
|
+
leave,
|
|
146
|
+
reset
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
150
|
+
0 && (module.exports = {
|
|
151
|
+
useQueue
|
|
152
|
+
});
|
package/dist/vue.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import "./chunk-XRJFNASX.mjs";
|
|
2
|
+
|
|
3
|
+
// src/vue.ts
|
|
4
|
+
import {
|
|
5
|
+
ref,
|
|
6
|
+
readonly,
|
|
7
|
+
computed,
|
|
8
|
+
shallowRef,
|
|
9
|
+
onMounted,
|
|
10
|
+
onUnmounted
|
|
11
|
+
} from "vue";
|
|
12
|
+
function useQueue(optionsInput) {
|
|
13
|
+
const status = ref("idle");
|
|
14
|
+
const token = ref(null);
|
|
15
|
+
const position = ref(null);
|
|
16
|
+
const ahead = ref(null);
|
|
17
|
+
const expiresAt = ref(null);
|
|
18
|
+
const data = computed(() => ({
|
|
19
|
+
token: token.value,
|
|
20
|
+
position: position.value,
|
|
21
|
+
ahead: ahead.value,
|
|
22
|
+
expiresAt: expiresAt.value
|
|
23
|
+
}));
|
|
24
|
+
const isPending = ref(true);
|
|
25
|
+
const error = ref(null);
|
|
26
|
+
const instance = shallowRef(null);
|
|
27
|
+
let cancelled = false;
|
|
28
|
+
const readOptions = () => typeof optionsInput === "function" ? optionsInput() : optionsInput;
|
|
29
|
+
const reset = () => {
|
|
30
|
+
status.value = "idle";
|
|
31
|
+
token.value = null;
|
|
32
|
+
position.value = null;
|
|
33
|
+
ahead.value = null;
|
|
34
|
+
expiresAt.value = null;
|
|
35
|
+
isPending.value = true;
|
|
36
|
+
error.value = null;
|
|
37
|
+
};
|
|
38
|
+
const leave = () => {
|
|
39
|
+
instance.value?.leave();
|
|
40
|
+
reset();
|
|
41
|
+
};
|
|
42
|
+
const bindQueueListeners = (queue) => {
|
|
43
|
+
queue.on("passed", (detail) => {
|
|
44
|
+
token.value = detail.token;
|
|
45
|
+
position.value = null;
|
|
46
|
+
ahead.value = null;
|
|
47
|
+
expiresAt.value = detail.expiresAt;
|
|
48
|
+
status.value = "passed";
|
|
49
|
+
isPending.value = false;
|
|
50
|
+
error.value = null;
|
|
51
|
+
});
|
|
52
|
+
queue.on("position", (detail) => {
|
|
53
|
+
token.value = null;
|
|
54
|
+
position.value = detail.position;
|
|
55
|
+
ahead.value = detail.ahead;
|
|
56
|
+
status.value = "waiting";
|
|
57
|
+
isPending.value = false;
|
|
58
|
+
});
|
|
59
|
+
queue.on("expired", () => {
|
|
60
|
+
token.value = null;
|
|
61
|
+
position.value = null;
|
|
62
|
+
ahead.value = null;
|
|
63
|
+
expiresAt.value = null;
|
|
64
|
+
status.value = "expired";
|
|
65
|
+
isPending.value = false;
|
|
66
|
+
});
|
|
67
|
+
queue.on("error", () => {
|
|
68
|
+
status.value = "error";
|
|
69
|
+
isPending.value = false;
|
|
70
|
+
error.value = new Error("Queue connection error");
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
onMounted(async () => {
|
|
74
|
+
const options = readOptions();
|
|
75
|
+
if (options.enabled === false) {
|
|
76
|
+
reset();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
status.value = "joining";
|
|
80
|
+
isPending.value = true;
|
|
81
|
+
error.value = null;
|
|
82
|
+
try {
|
|
83
|
+
let resolvedUserId = options.userId;
|
|
84
|
+
let queueInitToken = options.queueInitToken;
|
|
85
|
+
if (!resolvedUserId || !queueInitToken) {
|
|
86
|
+
if (options.autoInitToken === false) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"Falta queueInitToken/userId y autoInitToken est\xE1 deshabilitado"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const init = await options.client.issueQueueInitToken(
|
|
92
|
+
options.eventId,
|
|
93
|
+
resolvedUserId
|
|
94
|
+
);
|
|
95
|
+
resolvedUserId = init.userId;
|
|
96
|
+
queueInitToken = init.queueInitToken;
|
|
97
|
+
}
|
|
98
|
+
if (cancelled) return;
|
|
99
|
+
const queue = options.client.createQueue({
|
|
100
|
+
eventId: options.eventId,
|
|
101
|
+
userId: resolvedUserId,
|
|
102
|
+
queueInitToken,
|
|
103
|
+
pollInterval: options.pollInterval,
|
|
104
|
+
container: options.container
|
|
105
|
+
});
|
|
106
|
+
bindQueueListeners(queue);
|
|
107
|
+
instance.value = queue;
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if (cancelled) return;
|
|
110
|
+
status.value = "error";
|
|
111
|
+
isPending.value = false;
|
|
112
|
+
error.value = err instanceof Error ? err : new Error("Queue connection error");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
onUnmounted(() => {
|
|
116
|
+
cancelled = true;
|
|
117
|
+
instance.value?.destroy();
|
|
118
|
+
instance.value = null;
|
|
119
|
+
});
|
|
120
|
+
return {
|
|
121
|
+
status: readonly(status),
|
|
122
|
+
token: readonly(token),
|
|
123
|
+
position: readonly(position),
|
|
124
|
+
ahead: readonly(ahead),
|
|
125
|
+
expiresAt: readonly(expiresAt),
|
|
126
|
+
data: readonly(data),
|
|
127
|
+
isPending: readonly(isPending),
|
|
128
|
+
error: readonly(error),
|
|
129
|
+
instance,
|
|
130
|
+
leave,
|
|
131
|
+
reset
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
useQueue
|
|
136
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@central-ticket/queue-sdk",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"virtual-queue",
|
|
6
|
+
"waiting-room",
|
|
7
|
+
"ticketing",
|
|
8
|
+
"event-ticketing",
|
|
9
|
+
"queue-management",
|
|
10
|
+
"queue-token",
|
|
11
|
+
"sdk",
|
|
12
|
+
"centralq",
|
|
13
|
+
"react",
|
|
14
|
+
"vue",
|
|
15
|
+
"svelte",
|
|
16
|
+
"web-component",
|
|
17
|
+
"typescript"
|
|
18
|
+
],
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./react": {
|
|
29
|
+
"types": "./dist/react.d.ts",
|
|
30
|
+
"import": "./dist/react.mjs",
|
|
31
|
+
"require": "./dist/react.js"
|
|
32
|
+
},
|
|
33
|
+
"./svelte": {
|
|
34
|
+
"types": "./dist/svelte.d.ts",
|
|
35
|
+
"import": "./dist/svelte.mjs",
|
|
36
|
+
"require": "./dist/svelte.js"
|
|
37
|
+
},
|
|
38
|
+
"./vue": {
|
|
39
|
+
"types": "./dist/vue.d.ts",
|
|
40
|
+
"import": "./dist/vue.mjs",
|
|
41
|
+
"require": "./dist/vue.js"
|
|
42
|
+
},
|
|
43
|
+
"./server": {
|
|
44
|
+
"types": "./dist/server.d.ts",
|
|
45
|
+
"import": "./dist/server.mjs",
|
|
46
|
+
"require": "./dist/server.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup src/index.ts src/react.ts src/svelte.ts src/vue.ts src/server.ts --format cjs,esm --dts",
|
|
57
|
+
"dev": "tsup src/index.ts src/react.ts src/svelte.ts src/vue.ts src/server.ts --format cjs,esm --dts --watch",
|
|
58
|
+
"check-types": "tsc --noEmit",
|
|
59
|
+
"test": "vitest run",
|
|
60
|
+
"test:watch": "vitest"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"react": ">=18",
|
|
64
|
+
"svelte": ">=4",
|
|
65
|
+
"vue": ">=3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"react": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"svelte": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"vue": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"devDependencies": {
|
|
79
|
+
"@types/react": ">=18",
|
|
80
|
+
"react": ">=18",
|
|
81
|
+
"svelte": "^5.51.0",
|
|
82
|
+
"vue": "^3.5.18",
|
|
83
|
+
"tsup": "^8.0.0",
|
|
84
|
+
"typescript": "^5.0.0",
|
|
85
|
+
"vitest": "^2.1.8"
|
|
86
|
+
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"lit": "^3.3.2"
|
|
89
|
+
}
|
|
90
|
+
}
|