@ffstack/turnos 0.0.0-stage → 0.1.0

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,21 @@
1
+ rules_version = '2';
2
+
3
+ // turnos v0.1.0 — generada por `npx turnos init --firebase`.
4
+ // Publicar: firebase deploy --only firestore:rules
5
+ //
6
+ // Integridad de la reserva (capacidad + sin duplicados): las reglas de
7
+ // Firestore no pueden expresar "booked.length < capacity", así que el
8
+ // adaptador del paquete `turnos` la garantiza con una transacción
9
+ // (runTransaction) en el cliente. Estas reglas solo controlan ACCESO.
10
+
11
+ service cloud.firestore {
12
+ match /databases/{database}/documents {
13
+
14
+ // El horario es público para lectura; solo un admin de TU auth escribe.
15
+ // AJUSTA el claim a tu esquema (p. ej. request.auth.token.roles).
16
+ match /turnos/{turno} {
17
+ allow read: if true;
18
+ allow write: if request.auth != null && request.auth.token.admin == true;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,74 @@
1
+ -- turnos v0.1.0 — migración Supabase
2
+ -- Generada por `npx turnos init --supabase`.
3
+ -- Ejecutar: supabase db push (o psql "$DATABASE_URL" < 0001_turnos.sql)
4
+
5
+ create table if not exists public.turnos (
6
+ id text primary key default encode(gen_random_uuid(), 'hex'),
7
+ title text not null,
8
+ staff text not null,
9
+ date date not null,
10
+ hour text not null check (hour ~ '^[0-2][0-9]:[0-5][0-9]$'),
11
+ duration_min integer not null default 30 check (duration_min >= 10),
12
+ priority text not null default 'medium' check (priority in ('low','medium','high')),
13
+ status text not null default 'pending' check (status in ('pending','confirmed','completed','cancelled')),
14
+ capacity integer not null default 1 check (capacity >= 1),
15
+ booked text[] not null default '{}',
16
+ notes text not null default '',
17
+ created_at timestamptz not null default now(),
18
+ updated_at timestamptz not null default now()
19
+ );
20
+
21
+ create index if not exists turnos_date_idx on public.turnos (date, hour);
22
+
23
+ alter table public.turnos enable row level security;
24
+
25
+ -- Lectura del horario: pública. AJUSTA a tu esquema de auth si el horario
26
+ -- debe ser privado.
27
+ create policy turnos_read on public.turnos
28
+ for select using (true);
29
+
30
+ -- Escritura del horario: solo el rol "admin" de TU auth.
31
+ -- AJUSTA la expresión al esquema de roles que uses
32
+ -- (p. ej. auth.jwt() ->> 'role' = 'admin').
33
+ create policy turnos_admin_write on public.turnos for insert
34
+ with check (auth.jwt() ->> 'role' = 'admin');
35
+ create policy turnos_admin_update on public.turnos for update
36
+ using (auth.jwt() ->> 'role' = 'admin')
37
+ with check (auth.jwt() ->> 'role' = 'admin');
38
+ create policy turnos_admin_delete on public.turnos for delete
39
+ using (auth.jwt() ->> 'role' = 'admin');
40
+
41
+ -- Reserva condicional y atómica (nunca supera la capacidad, sin duplicados).
42
+ -- El adaptador del paquete `turnos` la llama así:
43
+ -- supabase.rpc('book_turno', { turno_id, user })
44
+ create or replace function public.book_turno(turno_id text, user text)
45
+ returns boolean
46
+ language plpgsql
47
+ security definer
48
+ set search_path = public
49
+ as $$
50
+ declare
51
+ rec public.turnos%rowtype;
52
+ begin
53
+ select * into rec from public.turnos where id = turno_id for update;
54
+ if not found then
55
+ return false;
56
+ end if;
57
+ if rec.status = 'cancelled' then
58
+ return false;
59
+ end if;
60
+ if array_position(rec.booked, user) is not null then
61
+ return false;
62
+ end if;
63
+ if coalesce(array_length(rec.booked, 1), 0) >= rec.capacity then
64
+ return false;
65
+ end if;
66
+ update public.turnos
67
+ set booked = array_append(booked, user),
68
+ updated_at = now()
69
+ where id = turno_id;
70
+ return true;
71
+ end;
72
+ $$;
73
+
74
+ grant execute on function public.book_turno(text, text) to anon, authenticated;
@@ -0,0 +1,363 @@
1
+ /* turnos v0.1.0 — estilos de los componentes generados.
2
+ Autónomos (sin Tailwind, sin fuentes externas) y acotados a .turnos
3
+ para no chocar con el tema de tu app.
4
+
5
+ TEMA — el componente NO trae paleta ni tipografía propia. Por defecto
6
+ hereda las del proyecto (currentColor / inherit) y se ve nativo en
7
+ cualquier app. Para darle identidad, sobreescribí estos tokens desde tu
8
+ CSS; los valores por defecto viven en `:where(.turnos)` (especificidad 0),
9
+ así que cualquier regla tuya gana sin pelear con import order:
10
+
11
+ .turnos {
12
+ --turnos-font: "Inter", system-ui, sans-serif;
13
+ --turnos-serif: Georgia, serif; // hora y título
14
+ --turnos-bg: #faf7f1; // fondo de la tarjeta
15
+ --turnos-surface: #fff; // filas, talones, paneles
16
+ --turnos-field: #faf7f1; // inputs del admin
17
+ --turnos-ink: #221a12; // texto y bordes fuertes
18
+ --turnos-soft: #6b6257; // texto secundario
19
+ --turnos-line: #e6ded2; // bordes y líneas
20
+ --turnos-accent: #3f5a2f; // foco, avisos OK
21
+ --turnos-danger: #9c3b2e; // errores y eliminar
22
+ --turnos-primary-bg: #221a12; // botón primario
23
+ --turnos-primary-ink: #faf7f1;
24
+ --turnos-primary-bg-hover: #3a2c1f;
25
+ }
26
+
27
+ Los TAMAÑOS de texto y el espaciado no son tokens: son parte del
28
+ componente y no cambian con el tema. Los estados y prioridades también
29
+ son tokens (--turnos-status-*, --turnos-priority-*).
30
+
31
+ Identidad "papel y talón": el usuario recibe talones (stub) con línea de
32
+ corte y muescas; el administrador trabaja sobre un registro rayado. La hora
33
+ es la protagonista tipográfica (cifras tabulares). Un solo gesto de
34
+ movimiento: el grupo entra al cambiar de día. */
35
+
36
+ :where(.turnos) {
37
+ --turnos-font: inherit;
38
+ --turnos-serif: var(--turnos-font);
39
+
40
+ --turnos-bg: transparent;
41
+ --turnos-surface: transparent;
42
+ --turnos-field: color-mix(in srgb, currentColor 4%, transparent);
43
+
44
+ --turnos-ink: currentColor;
45
+ --turnos-soft: color-mix(in srgb, currentColor 62%, transparent);
46
+ --turnos-line: color-mix(in srgb, currentColor 18%, transparent);
47
+
48
+ --turnos-accent: currentColor;
49
+ --turnos-danger: currentColor;
50
+ --turnos-status-pending: var(--turnos-soft);
51
+ --turnos-status-confirmed: var(--turnos-accent);
52
+ --turnos-status-completed: var(--turnos-soft);
53
+ --turnos-status-cancelled: var(--turnos-danger);
54
+ --turnos-priority-low: var(--turnos-soft);
55
+ --turnos-priority-medium: var(--turnos-soft);
56
+ --turnos-priority-high: var(--turnos-danger);
57
+
58
+ /* Tonal por defecto: se lee sobre cualquier fondo, sin paleta. */
59
+ --turnos-primary-bg: color-mix(in srgb, currentColor 12%, transparent);
60
+ --turnos-primary-ink: currentColor;
61
+ --turnos-primary-bg-hover: color-mix(in srgb, currentColor 20%, transparent);
62
+
63
+ --turnos-radius: 8px;
64
+ }
65
+
66
+ .turnos {
67
+ font-family: var(--turnos-font);
68
+ color: var(--turnos-ink);
69
+ background: var(--turnos-bg);
70
+ border: 1px solid var(--turnos-line);
71
+ border-radius: var(--turnos-radius);
72
+ padding: 22px;
73
+ max-width: 720px;
74
+ }
75
+
76
+ .turnos * { box-sizing: border-box; }
77
+ .turnos :focus-visible { outline: 2px solid var(--turnos-accent); outline-offset: 2px; }
78
+
79
+ /* Encabezado: título + navegación del día */
80
+ .turnos-cabecera {
81
+ display: flex;
82
+ align-items: baseline;
83
+ justify-content: space-between;
84
+ gap: 12px;
85
+ flex-wrap: wrap;
86
+ margin-bottom: 14px;
87
+ }
88
+ .turnos-titulo { font-family: var(--turnos-serif); font-size: 1.45rem; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
89
+ .turnos-nav { display: flex; align-items: center; gap: 6px; }
90
+ .turnos-nav .turnos-btn { padding: 5px 10px; font-size: 0.95rem; line-height: 1; }
91
+ .turnos-campo {
92
+ border: 1px solid var(--turnos-line);
93
+ border-radius: var(--turnos-radius);
94
+ background: var(--turnos-surface);
95
+ color: var(--turnos-ink);
96
+ padding: 6px 9px;
97
+ font: inherit;
98
+ font-size: 0.85rem;
99
+ font-variant-numeric: tabular-nums;
100
+ }
101
+
102
+ /* Franja horaria (Mañana / Tarde / Noche, o la fecha del admin):
103
+ etiqueta + línea que recorta la franja + cantidad */
104
+ .turnos-franja-grupo { margin-top: 16px; animation: turnos-entra 160ms ease-out both; }
105
+ .turnos-franja {
106
+ display: flex;
107
+ align-items: center;
108
+ gap: 10px;
109
+ margin: 0 0 8px;
110
+ font-size: 0.75rem;
111
+ font-weight: 600;
112
+ color: var(--turnos-soft);
113
+ }
114
+ .turnos-franja::after { content: ""; flex: 1; height: 1px; background: var(--turnos-line); }
115
+
116
+ .turnos-lista { list-style: none; margin: 0; padding: 0; }
117
+
118
+ /* ---- TALÓN: la fila que el usuario elige.
119
+ La línea de corte está en la columna de acción: borde punteado + dos
120
+ muescas recortadas sobre el borde superior e inferior. Las muescas usan
121
+ --turnos-bg: si tu tarjeta es transparente, dejá ese token con el fondo
122
+ real de la página para que la perforación se vea. */
123
+ .turnos-talon {
124
+ position: relative;
125
+ display: grid;
126
+ grid-template-columns: 62px minmax(0, 1fr) auto auto 104px;
127
+ align-items: center;
128
+ gap: 12px;
129
+ padding: 11px 12px;
130
+ margin-top: 8px;
131
+ border: 1px solid var(--turnos-line);
132
+ border-radius: var(--turnos-radius);
133
+ background:
134
+ radial-gradient(circle at calc(100% - 116px) 0, var(--turnos-bg) 6px, transparent 6.5px),
135
+ radial-gradient(circle at calc(100% - 116px) 100%, var(--turnos-bg) 6px, transparent 6.5px),
136
+ var(--turnos-surface);
137
+ transition: border-color 0.15s ease;
138
+ }
139
+ .turnos-talon:hover { border-color: var(--turnos-ink); }
140
+ .turnos-talon--cancelada { opacity: 0.55; }
141
+ .turnos-talon--cancelada .turnos-talon-titulo { text-decoration: line-through; }
142
+
143
+ /* La hora manda: serif (token), tabular, grande */
144
+ .turnos-talon-hora { display: grid; gap: 3px; }
145
+ .turnos-hora {
146
+ font-family: var(--turnos-serif);
147
+ font-size: 1.35rem;
148
+ font-weight: 500;
149
+ line-height: 0.95;
150
+ font-variant-numeric: tabular-nums;
151
+ }
152
+ .turnos-dur { font-size: 0.7rem; color: var(--turnos-soft); font-variant-numeric: tabular-nums; }
153
+
154
+ .turnos-talon-datos { display: grid; gap: 2px; min-width: 0; }
155
+ .turnos-talon-titulo { font-size: 0.95rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
156
+ .turnos-bajito { font-size: 0.76rem; color: var(--turnos-soft); }
157
+
158
+ /* Sello de estado: tinta sobre papel, borde fino, sin relleno */
159
+ .turnos-sello {
160
+ font-size: 0.7rem;
161
+ font-weight: 600;
162
+ padding: 2px 7px;
163
+ border-radius: 4px;
164
+ border: 1px solid currentColor;
165
+ color: var(--turnos-soft);
166
+ white-space: nowrap;
167
+ }
168
+ .turnos-sello--pending { color: var(--turnos-status-pending); }
169
+ .turnos-sello--confirmed { color: var(--turnos-status-confirmed); }
170
+ .turnos-sello--completed { color: var(--turnos-status-completed); }
171
+ .turnos-sello--cancelled { color: var(--turnos-status-cancelled); }
172
+
173
+ .turnos-cupo {
174
+ font-size: 0.74rem;
175
+ color: var(--turnos-soft);
176
+ white-space: nowrap;
177
+ font-variant-numeric: tabular-nums;
178
+ }
179
+
180
+ .turnos-talon-accion {
181
+ display: flex;
182
+ justify-content: flex-end;
183
+ align-self: stretch;
184
+ align-items: center;
185
+ padding-left: 12px;
186
+ border-left: 1px dashed var(--turnos-line);
187
+ }
188
+
189
+ /* Botones: el primario se pinta con --turnos-primary-* */
190
+ .turnos-btn {
191
+ font: inherit;
192
+ font-size: 0.8rem;
193
+ font-weight: 600;
194
+ padding: 8px 13px;
195
+ border-radius: 6px;
196
+ border: 1px solid var(--turnos-line);
197
+ background: transparent;
198
+ color: var(--turnos-ink);
199
+ cursor: pointer;
200
+ transition: background-color 0.15s, border-color 0.15s;
201
+ }
202
+ .turnos-btn:hover:not(:disabled) { border-color: var(--turnos-ink); }
203
+ .turnos-btn:disabled { opacity: 0.5; cursor: not-allowed; }
204
+ .turnos-btn--primary {
205
+ background: var(--turnos-primary-bg);
206
+ border-color: transparent;
207
+ color: var(--turnos-primary-ink);
208
+ }
209
+ .turnos-btn--primary:hover:not(:disabled) {
210
+ background: var(--turnos-primary-bg-hover);
211
+ border-color: transparent;
212
+ }
213
+ .turnos-btn--soft { color: var(--turnos-soft); }
214
+ .turnos-btn--danger { color: var(--turnos-danger); border-color: color-mix(in srgb, var(--turnos-danger) 45%, transparent); }
215
+ .turnos-btn--danger:hover:not(:disabled) { border-color: var(--turnos-danger); }
216
+
217
+ .turnos-vacio { color: var(--turnos-soft); font-size: 0.88rem; padding: 26px 4px; text-align: center; }
218
+
219
+ .turnos-aviso { font-size: 0.84rem; margin: 14px 0 0; }
220
+ .turnos-aviso--ok { color: var(--turnos-accent); font-weight: 600; }
221
+ .turnos-aviso--err { color: var(--turnos-danger); }
222
+
223
+ /* ---- REGISTRO DEL ADMINISTRADOR: filas rayadas, sin talón. */
224
+
225
+ /* Formulario en rejilla de 12 columnas: los campos anchos ocupan más y el
226
+ botón cierra la última fila alineado a la derecha. El ritmo vertical
227
+ (14px entre filas) es mayor que el horizontal para que cada campo se lea
228
+ como una unidad y no como una sopa de cajas. */
229
+ .turnos-form {
230
+ display: grid;
231
+ grid-template-columns: repeat(12, minmax(0, 1fr));
232
+ gap: 14px 12px;
233
+ align-items: end;
234
+ background: var(--turnos-surface);
235
+ border: 1px solid var(--turnos-line);
236
+ border-radius: var(--turnos-radius);
237
+ padding: 16px;
238
+ margin-bottom: 12px;
239
+ }
240
+ .turnos-form label {
241
+ display: grid;
242
+ gap: 6px;
243
+ min-width: 0;
244
+ font-size: 0.72rem;
245
+ font-weight: 600;
246
+ line-height: 1.3;
247
+ color: var(--turnos-soft);
248
+ }
249
+ .turnos-form input,
250
+ .turnos-form select,
251
+ .turnos-form textarea {
252
+ width: 100%;
253
+ min-width: 0;
254
+ font: inherit;
255
+ font-size: 0.875rem;
256
+ font-weight: 400;
257
+ line-height: 1.4;
258
+ border: 1px solid var(--turnos-line);
259
+ border-radius: 6px;
260
+ background: var(--turnos-field);
261
+ color: var(--turnos-ink);
262
+ padding: 9px 10px;
263
+ }
264
+ .turnos-form input::placeholder { color: var(--turnos-soft); opacity: 0.75; }
265
+
266
+ .turnos-f-titulo { grid-column: span 5; }
267
+ .turnos-f-staff { grid-column: span 4; }
268
+ .turnos-f-prioridad { grid-column: span 3; }
269
+ .turnos-f-fecha,
270
+ .turnos-f-hora,
271
+ .turnos-f-duracion,
272
+ .turnos-f-capacidad { grid-column: span 3; }
273
+ .turnos-f-notas { grid-column: span 8; }
274
+ .turnos-form .turnos-btn { grid-column: span 4; justify-self: end; align-self: end; }
275
+
276
+ .turnos-error-lista {
277
+ margin: 10px 0 0;
278
+ padding: 10px 12px 10px 26px;
279
+ color: var(--turnos-danger);
280
+ font-size: 0.8rem;
281
+ background: color-mix(in srgb, var(--turnos-danger) 8%, transparent);
282
+ border: 1px solid color-mix(in srgb, var(--turnos-danger) 28%, transparent);
283
+ border-radius: 6px;
284
+ }
285
+
286
+ .turnos-fila {
287
+ display: grid;
288
+ grid-template-columns: 88px 54px minmax(0, 1fr) 40px auto auto;
289
+ align-items: center;
290
+ gap: 12px;
291
+ padding: 10px 2px;
292
+ border-bottom: 1px solid var(--turnos-line);
293
+ }
294
+ .turnos-lista .turnos-fila:last-child { border-bottom: 0; }
295
+ .turnos-fecha { font-size: 0.75rem; color: var(--turnos-soft); font-variant-numeric: tabular-nums; }
296
+ .turnos-fila .turnos-hora { font-size: 1.05rem; }
297
+ .turnos-fila .turnos-cuerpo { display: grid; gap: 2px; min-width: 0; }
298
+ .turnos-fila .turnos-cuerpo strong { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
299
+
300
+ .turnos-prio { font-size: 0.7rem; font-weight: 600; white-space: nowrap; }
301
+ .turnos-prio--low { color: var(--turnos-priority-low); }
302
+ .turnos-prio--medium { color: var(--turnos-priority-medium); }
303
+ .turnos-prio--high { color: var(--turnos-priority-high); }
304
+
305
+ .turnos-estado {
306
+ font: inherit;
307
+ font-size: 0.76rem;
308
+ border: 1px solid var(--turnos-line);
309
+ border-radius: 6px;
310
+ background: var(--turnos-surface);
311
+ color: var(--turnos-ink);
312
+ padding: 5px 8px;
313
+ }
314
+
315
+ /* El único momento de movimiento: el grupo entra al cambiar de día. */
316
+ @keyframes turnos-entra {
317
+ from { opacity: 0; transform: translateY(4px); }
318
+ }
319
+ @media (prefers-reduced-motion: reduce) {
320
+ .turnos-franja-grupo { animation: none; }
321
+ }
322
+
323
+ /* En pantallas angostas el talón pierde la perforación y pasa a dos columnas. */
324
+ @media (max-width: 560px) {
325
+ .turnos-talon {
326
+ grid-template-columns: 54px minmax(0, 1fr);
327
+ grid-template-areas:
328
+ "hora datos"
329
+ "sello cupo"
330
+ "accion accion";
331
+ row-gap: 10px;
332
+ background: var(--turnos-surface);
333
+ }
334
+ .turnos-talon-hora { grid-area: hora; }
335
+ .turnos-talon-datos { grid-area: datos; }
336
+ .turnos-sello { grid-area: sello; justify-self: start; }
337
+ .turnos-cupo { grid-area: cupo; justify-self: end; }
338
+ .turnos-talon-accion {
339
+ grid-area: accion;
340
+ border-left: 0;
341
+ border-top: 1px dashed var(--turnos-line);
342
+ padding: 10px 0 0;
343
+ justify-content: stretch;
344
+ }
345
+ .turnos-talon-accion .turnos-btn { width: 100%; }
346
+ .turnos-fila { grid-template-columns: 1fr auto; row-gap: 8px; }
347
+ .turnos-fila .turnos-fecha, .turnos-fila .turnos-hora { grid-column: auto; }
348
+ }
349
+
350
+ /* Formulario en dos columnas: los campos anchos y el botón ocupan la fila. */
351
+ @media (max-width: 620px) {
352
+ .turnos-form { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 14px; }
353
+ .turnos-f-titulo,
354
+ .turnos-f-staff,
355
+ .turnos-f-notas,
356
+ .turnos-f-prioridad,
357
+ .turnos-form .turnos-btn { grid-column: span 2; }
358
+ .turnos-f-fecha,
359
+ .turnos-f-hora,
360
+ .turnos-f-duracion,
361
+ .turnos-f-capacidad { grid-column: span 1; }
362
+ .turnos-form .turnos-btn { justify-self: stretch; }
363
+ }