@rivil-solutions/site-kit 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +109 -2
- package/bin/rivil.mjs +118 -0
- package/blocks/booking/block.json +7 -0
- package/blocks/booking/files/src/components/rivil/BookingForm.tsx +187 -0
- package/blocks/booking/files/src/pages/programare.astro +18 -0
- package/blocks/careers/block.json +7 -0
- package/blocks/careers/files/src/components/rivil/ApplyForm.tsx +62 -0
- package/blocks/careers/files/src/pages/cariere/[job].astro +49 -0
- package/blocks/careers/files/src/pages/cariere/index.astro +32 -0
- package/blocks/events/block.json +7 -0
- package/blocks/events/files/src/components/rivil/EventCheckout.tsx +93 -0
- package/blocks/events/files/src/pages/evenimente/[code].astro +35 -0
- package/blocks/events/files/src/pages/evenimente/comanda.astro +36 -0
- package/blocks/events/files/src/pages/evenimente/index.astro +30 -0
- package/blocks/newsletter/block.json +4 -0
- package/blocks/newsletter/files/src/components/rivil/Newsletter.astro +35 -0
- package/blocks/reviews/block.json +7 -0
- package/blocks/reviews/files/src/components/rivil/ReviewForm.tsx +73 -0
- package/blocks/reviews/files/src/pages/recenzii.astro +39 -0
- package/blocks/stay/block.json +7 -0
- package/blocks/stay/files/src/components/rivil/StayBooking.tsx +121 -0
- package/blocks/stay/files/src/pages/rezervare.astro +11 -0
- package/blocks/ui/block.json +1 -0
- package/blocks/ui/files/src/components/rivil/ui.tsx +99 -0
- package/blocks/ui/files/src/styles/rivil-blocks.css +47 -0
- package/dist/account.d.ts +84 -0
- package/dist/account.js +104 -0
- package/dist/astro-image.d.ts +29 -0
- package/dist/astro-image.js +12 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.js +153 -0
- package/dist/consent.d.ts +6 -0
- package/dist/consent.js +10 -0
- package/dist/content.d.ts +93 -0
- package/dist/content.js +85 -0
- package/dist/i18n.d.ts +30 -0
- package/dist/i18n.js +69 -0
- package/dist/images.d.ts +13 -0
- package/dist/images.js +26 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/modules.d.ts +288 -0
- package/dist/modules.js +49 -0
- package/dist/proxy.d.ts +47 -0
- package/dist/proxy.js +82 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +6 -0
- package/dist/react/texts.d.ts +17 -0
- package/dist/react/texts.js +28 -0
- package/dist/react/useApplication.d.ts +67 -0
- package/dist/react/useApplication.js +94 -0
- package/dist/react/useBooking.d.ts +81 -0
- package/dist/react/useBooking.js +151 -0
- package/dist/react/useEventCheckout.d.ts +48 -0
- package/dist/react/useEventCheckout.js +104 -0
- package/dist/react/useReview.d.ts +58 -0
- package/dist/react/useReview.js +69 -0
- package/dist/react/useStay.d.ts +82 -0
- package/dist/react/useStay.js +105 -0
- package/dist/seo.d.ts +27 -0
- package/dist/seo.js +36 -0
- package/dist/shop.d.ts +111 -0
- package/dist/shop.js +167 -0
- package/dist/visitor.d.ts +7 -0
- package/dist/visitor.js +17 -0
- package/dist/web.d.ts +83 -0
- package/dist/web.js +131 -0
- package/dist/webhook.d.ts +20 -0
- package/dist/webhook.js +39 -0
- package/package.json +68 -4
- package/themes/aer.css +12 -0
- package/themes/cabana.css +12 -0
- package/themes/curte.css +12 -0
- package/themes/lumen.css +12 -0
- package/themes/miez.css +12 -0
- package/themes/solvar.css +12 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { errorMessage, isEmail, rivilFetch } from '../web.js';
|
|
3
|
+
import { formText } from './texts.js';
|
|
4
|
+
/** Starea de vânzare a unui tip de bilet, cu „epuizat” când nu mai sunt locuri. */
|
|
5
|
+
export const ticketState = (t) => (t.left === 0 && (t.state === 'paid' || t.state === 'open') ? 'soldout' : t.state);
|
|
6
|
+
export const ticketOnSale = (t) => ['open', 'paid'].includes(ticketState(t));
|
|
7
|
+
/**
|
|
8
|
+
* Înscrierea la un eveniment: bilete, cupon, cumpărător, întrebări. La biletele plătite, ERP-ul dă adresa de plată și omul pleacă acolo;
|
|
9
|
+
* la cele gratuite comanda e gata și se merge la `successPath` cu `order_token`.
|
|
10
|
+
*/
|
|
11
|
+
export function useEventCheckout(o) {
|
|
12
|
+
const f = o.fetcher ?? rivilFetch;
|
|
13
|
+
const e = o.event;
|
|
14
|
+
const [qty, setQty] = useState({});
|
|
15
|
+
const [coupon, setCouponState] = useState('');
|
|
16
|
+
const [quote, setQuote] = useState(null);
|
|
17
|
+
const [couponError, setCouponError] = useState('');
|
|
18
|
+
const [buyer, setBuyerState] = useState({ name: '', email: '', phone: '' });
|
|
19
|
+
const [answers, setAnswers] = useState({});
|
|
20
|
+
const [busy, setBusy] = useState(false);
|
|
21
|
+
const [error, setError] = useState('');
|
|
22
|
+
const [waitlisted, setWaitlisted] = useState(false);
|
|
23
|
+
const lines = e.types.filter((t) => qty[t.id]).map((t) => ({ typeId: t.id, quantity: qty[t.id] }));
|
|
24
|
+
const subtotal = e.types.reduce((n, t) => n + t.price * (qty[t.id] ?? 0), 0);
|
|
25
|
+
const absolute = (path) => new URL(path, window.location.origin).toString();
|
|
26
|
+
return {
|
|
27
|
+
types: e.types,
|
|
28
|
+
questions: e.questions,
|
|
29
|
+
qty,
|
|
30
|
+
change(t, n) {
|
|
31
|
+
const max = Math.min(t.maxPerOrder, t.left ?? t.maxPerOrder);
|
|
32
|
+
setQty((q) => ({ ...q, [t.id]: Math.max(0, Math.min(max, n)) }));
|
|
33
|
+
setQuote(null);
|
|
34
|
+
setError('');
|
|
35
|
+
},
|
|
36
|
+
subtotal,
|
|
37
|
+
total: quote?.total ?? subtotal,
|
|
38
|
+
discount: quote?.discount ?? 0,
|
|
39
|
+
coupon,
|
|
40
|
+
setCoupon(v) {
|
|
41
|
+
setCouponState(v.toUpperCase());
|
|
42
|
+
setQuote(null);
|
|
43
|
+
setCouponError('');
|
|
44
|
+
},
|
|
45
|
+
couponError,
|
|
46
|
+
async applyCoupon() {
|
|
47
|
+
setCouponError('');
|
|
48
|
+
setBusy(true);
|
|
49
|
+
try {
|
|
50
|
+
setQuote(await f(`events/${encodeURIComponent(e.code)}/quote`, { json: { lines, coupon, lang: o.lang, accessCode: o.access, invite: o.invite } }));
|
|
51
|
+
}
|
|
52
|
+
catch (x) {
|
|
53
|
+
setCouponError(errorMessage(x));
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
setBusy(false);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
buyer,
|
|
60
|
+
setBuyer: (patch) => setBuyerState((b) => ({ ...b, ...patch })),
|
|
61
|
+
answers,
|
|
62
|
+
setAnswer: (id, v) => setAnswers((a) => ({ ...a, [id]: v })),
|
|
63
|
+
busy,
|
|
64
|
+
error,
|
|
65
|
+
async submit() {
|
|
66
|
+
setError('');
|
|
67
|
+
if (!lines.length)
|
|
68
|
+
return setError(formText(o.lang, 'tickets'));
|
|
69
|
+
if (!buyer.name.trim() || !isEmail(buyer.email))
|
|
70
|
+
return setError(formText(o.lang, 'nameEmail'));
|
|
71
|
+
if (e.questions.some((q) => q.required && !answers[q.id]))
|
|
72
|
+
return setError(formText(o.lang, 'answers'));
|
|
73
|
+
setBusy(true);
|
|
74
|
+
try {
|
|
75
|
+
const out = await f(`events/${encodeURIComponent(e.code)}/orders`, {
|
|
76
|
+
json: { ...buyer, lines, answers, coupon: coupon || undefined, accessCode: o.access, invite: o.invite, lang: o.lang, success_url: absolute(o.successPath), cancel_url: window.location.href },
|
|
77
|
+
});
|
|
78
|
+
window.location.href = out.payment_url ?? `${absolute(o.successPath)}?order_token=${encodeURIComponent(out.order_token)}`;
|
|
79
|
+
}
|
|
80
|
+
catch (x) {
|
|
81
|
+
setError(errorMessage(x));
|
|
82
|
+
setBusy(false);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
waitlistEnabled: e.waitlistEnabled,
|
|
86
|
+
waitlisted,
|
|
87
|
+
async joinWaitlist(typeId) {
|
|
88
|
+
setError('');
|
|
89
|
+
if (!buyer.name.trim() || !isEmail(buyer.email))
|
|
90
|
+
return setError(formText(o.lang, 'nameEmail'));
|
|
91
|
+
setBusy(true);
|
|
92
|
+
try {
|
|
93
|
+
await f(`events/${encodeURIComponent(e.code)}/waitlist`, { json: { ...buyer, typeId, lang: o.lang } });
|
|
94
|
+
setWaitlisted(true);
|
|
95
|
+
}
|
|
96
|
+
catch (x) {
|
|
97
|
+
setError(errorMessage(x));
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
setBusy(false);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ReviewSurvey } from '../modules.js';
|
|
2
|
+
import { type RivilFetch } from '../web.js';
|
|
3
|
+
export type ReviewQuestion = {
|
|
4
|
+
id: string;
|
|
5
|
+
type: string;
|
|
6
|
+
label: string;
|
|
7
|
+
help?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
options?: string[];
|
|
10
|
+
low?: string;
|
|
11
|
+
high?: string;
|
|
12
|
+
scaleMax?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Chestionarul general: cel fără reguli de canal, serviciu sau locație, altfel primul. */
|
|
15
|
+
export declare function pickSurvey(data: ReviewSurvey): {
|
|
16
|
+
questions: Array<Record<string, unknown>>;
|
|
17
|
+
match: {
|
|
18
|
+
channels: unknown[];
|
|
19
|
+
services: unknown[];
|
|
20
|
+
locations: unknown[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Recenzia deschisă (fără invitație): întrebările, câmpurile și consimțămintele vin din ERP. */
|
|
24
|
+
export declare function useReview(o: {
|
|
25
|
+
survey: ReviewSurvey;
|
|
26
|
+
lang: string;
|
|
27
|
+
fetcher?: RivilFetch;
|
|
28
|
+
}): {
|
|
29
|
+
questions: ReviewQuestion[];
|
|
30
|
+
fields: Record<string, {
|
|
31
|
+
on: boolean;
|
|
32
|
+
required: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
consents: import("../modules.js").Consent[];
|
|
35
|
+
services: {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
}[];
|
|
39
|
+
/** Textele chestionarului din ERP (titlu, butoane), cu cheile lor. */
|
|
40
|
+
texts: Record<string, string>;
|
|
41
|
+
answers: Record<string, unknown>;
|
|
42
|
+
setAnswer: (id: string, v: unknown) => void;
|
|
43
|
+
accepted: Record<string, boolean>;
|
|
44
|
+
setAccepted: (k: string, v: boolean) => void;
|
|
45
|
+
name: string;
|
|
46
|
+
setName: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
47
|
+
email: string;
|
|
48
|
+
setEmail: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
49
|
+
service: string;
|
|
50
|
+
setService: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
51
|
+
trap: string;
|
|
52
|
+
setTrap: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
53
|
+
busy: boolean;
|
|
54
|
+
error: string;
|
|
55
|
+
done: string | null;
|
|
56
|
+
submit(): Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
export type ReviewState = ReturnType<typeof useReview>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { errorMessage, isEmpty, rivilFetch } from '../web.js';
|
|
3
|
+
import { formText } from './texts.js';
|
|
4
|
+
/** Chestionarul general: cel fără reguli de canal, serviciu sau locație, altfel primul. */
|
|
5
|
+
export function pickSurvey(data) {
|
|
6
|
+
const all = data.surveys ?? [];
|
|
7
|
+
return all.find((s) => !s.match.channels.length && !s.match.services.length && !s.match.locations.length) ?? all[0] ?? null;
|
|
8
|
+
}
|
|
9
|
+
/** Recenzia deschisă (fără invitație): întrebările, câmpurile și consimțămintele vin din ERP. */
|
|
10
|
+
export function useReview(o) {
|
|
11
|
+
const f = o.fetcher ?? rivilFetch;
|
|
12
|
+
const questions = (pickSurvey(o.survey)?.questions ?? []).filter((q) => !q.showIf);
|
|
13
|
+
const fields = o.survey.fields ?? {};
|
|
14
|
+
const consents = (o.survey.consents ?? []).filter((c) => c.enabled !== false);
|
|
15
|
+
const [answers, setAnswers] = useState({});
|
|
16
|
+
const [accepted, setAcceptedState] = useState({});
|
|
17
|
+
const [name, setName] = useState('');
|
|
18
|
+
const [email, setEmail] = useState('');
|
|
19
|
+
const [service, setService] = useState('');
|
|
20
|
+
const [trap, setTrap] = useState('');
|
|
21
|
+
const [busy, setBusy] = useState(false);
|
|
22
|
+
const [error, setError] = useState('');
|
|
23
|
+
const [done, setDone] = useState(null);
|
|
24
|
+
return {
|
|
25
|
+
questions,
|
|
26
|
+
fields,
|
|
27
|
+
consents,
|
|
28
|
+
services: o.survey.options?.services ?? [],
|
|
29
|
+
/** Textele chestionarului din ERP (titlu, butoane), cu cheile lor. */
|
|
30
|
+
texts: o.survey.texts ?? {},
|
|
31
|
+
answers,
|
|
32
|
+
setAnswer: (id, v) => setAnswers((a) => ({ ...a, [id]: v })),
|
|
33
|
+
accepted,
|
|
34
|
+
setAccepted: (k, v) => setAcceptedState((s) => ({ ...s, [k]: v })),
|
|
35
|
+
name,
|
|
36
|
+
setName,
|
|
37
|
+
email,
|
|
38
|
+
setEmail,
|
|
39
|
+
service,
|
|
40
|
+
setService,
|
|
41
|
+
trap,
|
|
42
|
+
setTrap,
|
|
43
|
+
busy,
|
|
44
|
+
error,
|
|
45
|
+
done,
|
|
46
|
+
async submit() {
|
|
47
|
+
setError('');
|
|
48
|
+
if (questions.some((q) => q.required && isEmpty(answers[q.id])))
|
|
49
|
+
return setError(formText(o.lang, 'answers'));
|
|
50
|
+
if (consents.some((c) => c.required && !accepted[c.key]))
|
|
51
|
+
return setError(formText(o.lang, 'consents'));
|
|
52
|
+
if ((fields.name?.required && !name.trim()) || (fields.email?.required && !email.trim()))
|
|
53
|
+
return setError(formText(o.lang, 'required'));
|
|
54
|
+
setBusy(true);
|
|
55
|
+
try {
|
|
56
|
+
const out = await f('reviews', {
|
|
57
|
+
json: { open: true, channel: 'link', lang: o.lang, name: name.trim() || undefined, email: email.trim() || undefined, serviceId: service || undefined, answers, consents: accepted, website: trap },
|
|
58
|
+
});
|
|
59
|
+
setDone(out?.thanks ?? '');
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
setError(errorMessage(e));
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
setBusy(false);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type RivilFetch } from '../web.js';
|
|
2
|
+
export type StayRoom = {
|
|
3
|
+
typeId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
freeUnits: number;
|
|
6
|
+
total: number | null;
|
|
7
|
+
average: number | null;
|
|
8
|
+
reason: string | null;
|
|
9
|
+
options: Array<{
|
|
10
|
+
method: string;
|
|
11
|
+
label: string;
|
|
12
|
+
dueNow: number;
|
|
13
|
+
instructions?: string;
|
|
14
|
+
}>;
|
|
15
|
+
type: {
|
|
16
|
+
shortDescription?: string;
|
|
17
|
+
maxAdults?: number;
|
|
18
|
+
areaM2?: number;
|
|
19
|
+
beds?: string;
|
|
20
|
+
photoUrls?: string[];
|
|
21
|
+
descriptionHtml?: string;
|
|
22
|
+
[k: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type StayBooked = {
|
|
26
|
+
number: string;
|
|
27
|
+
typeName: string;
|
|
28
|
+
checkIn: string;
|
|
29
|
+
checkOut: string;
|
|
30
|
+
total: number;
|
|
31
|
+
transfer?: {
|
|
32
|
+
amount: number;
|
|
33
|
+
instructions: string;
|
|
34
|
+
} | null;
|
|
35
|
+
};
|
|
36
|
+
/** Rezervarea de cazare fără aspect: nopți și oaspeți, camere libere cu preț, datele oaspetelui, confirmare sau plată. */
|
|
37
|
+
export declare function useStay(o: {
|
|
38
|
+
lang: string;
|
|
39
|
+
nightsAhead?: number;
|
|
40
|
+
fetcher?: RivilFetch;
|
|
41
|
+
}): {
|
|
42
|
+
checkIn: string;
|
|
43
|
+
checkOut: string;
|
|
44
|
+
setDates(inDate: string, outDate: string): void;
|
|
45
|
+
nights: number;
|
|
46
|
+
adults: number;
|
|
47
|
+
setAdults: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
48
|
+
children: number;
|
|
49
|
+
setChildren: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
50
|
+
rooms: StayRoom[] | null;
|
|
51
|
+
searching: boolean;
|
|
52
|
+
search(): Promise<void>;
|
|
53
|
+
picked: StayRoom | null;
|
|
54
|
+
pick(r: StayRoom | null): void;
|
|
55
|
+
/** Metodele de plată pe care le poate alege oaspetele pentru camera aleasă. */
|
|
56
|
+
methods: {
|
|
57
|
+
method: string;
|
|
58
|
+
label: string;
|
|
59
|
+
dueNow: number;
|
|
60
|
+
instructions?: string;
|
|
61
|
+
}[];
|
|
62
|
+
method: string;
|
|
63
|
+
setMethod: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
64
|
+
guest: {
|
|
65
|
+
name: string;
|
|
66
|
+
email: string;
|
|
67
|
+
phone: string;
|
|
68
|
+
notes: string;
|
|
69
|
+
};
|
|
70
|
+
setGuest: (patch: Partial<{
|
|
71
|
+
name: string;
|
|
72
|
+
email: string;
|
|
73
|
+
phone: string;
|
|
74
|
+
notes: string;
|
|
75
|
+
}>) => void;
|
|
76
|
+
busy: boolean;
|
|
77
|
+
error: string;
|
|
78
|
+
booked: StayBooked | null;
|
|
79
|
+
reserve(): Promise<void>;
|
|
80
|
+
reset(): void;
|
|
81
|
+
};
|
|
82
|
+
export type StayState = ReturnType<typeof useStay>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { addDays, errorMessage, isEmail, isoDay, rivilFetch } from '../web.js';
|
|
3
|
+
import { formText } from './texts.js';
|
|
4
|
+
/** Metodele care cer plată online se aleg doar când există `checkoutUrl`; formularul simplu le lasă la ERP. */
|
|
5
|
+
const ONLINE = new Set(['card', 'deposit']);
|
|
6
|
+
/** Rezervarea de cazare fără aspect: nopți și oaspeți, camere libere cu preț, datele oaspetelui, confirmare sau plată. */
|
|
7
|
+
export function useStay(o) {
|
|
8
|
+
const f = o.fetcher ?? rivilFetch;
|
|
9
|
+
const start = addDays(new Date(), o.nightsAhead ?? 14);
|
|
10
|
+
const [checkIn, setCheckIn] = useState(isoDay(start));
|
|
11
|
+
const [checkOut, setCheckOut] = useState(isoDay(addDays(start, 2)));
|
|
12
|
+
const [adults, setAdults] = useState(2);
|
|
13
|
+
const [children, setChildren] = useState(0);
|
|
14
|
+
const [rooms, setRooms] = useState(null);
|
|
15
|
+
const [searching, setSearching] = useState(false);
|
|
16
|
+
const [picked, setPicked] = useState(null);
|
|
17
|
+
const [guest, setGuestState] = useState({ name: '', email: '', phone: '', notes: '' });
|
|
18
|
+
const [method, setMethod] = useState('');
|
|
19
|
+
const [busy, setBusy] = useState(false);
|
|
20
|
+
const [error, setError] = useState('');
|
|
21
|
+
const [booked, setBooked] = useState(null);
|
|
22
|
+
const nights = Math.max(0, Math.round((new Date(checkOut).getTime() - new Date(checkIn).getTime()) / 86_400_000));
|
|
23
|
+
return {
|
|
24
|
+
checkIn,
|
|
25
|
+
checkOut,
|
|
26
|
+
setDates(inDate, outDate) {
|
|
27
|
+
setCheckIn(inDate);
|
|
28
|
+
setCheckOut(outDate);
|
|
29
|
+
setRooms(null);
|
|
30
|
+
setPicked(null);
|
|
31
|
+
},
|
|
32
|
+
nights,
|
|
33
|
+
adults,
|
|
34
|
+
setAdults,
|
|
35
|
+
children,
|
|
36
|
+
setChildren,
|
|
37
|
+
rooms,
|
|
38
|
+
searching,
|
|
39
|
+
async search() {
|
|
40
|
+
setError('');
|
|
41
|
+
setPicked(null);
|
|
42
|
+
if (!checkIn || !checkOut || nights < 1)
|
|
43
|
+
return setError(formText(o.lang, 'dates'));
|
|
44
|
+
setSearching(true);
|
|
45
|
+
try {
|
|
46
|
+
const out = await f('stay/search', { query: { checkIn, checkOut, adults, children, lang: o.lang } });
|
|
47
|
+
setRooms(out.types ?? []);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
setRooms(null);
|
|
51
|
+
setError(errorMessage(e));
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
setSearching(false);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
picked,
|
|
58
|
+
pick(r) {
|
|
59
|
+
setPicked(r);
|
|
60
|
+
setMethod(r?.options.find((x) => !ONLINE.has(x.method))?.method ?? r?.options[0]?.method ?? '');
|
|
61
|
+
setError('');
|
|
62
|
+
},
|
|
63
|
+
/** Metodele de plată pe care le poate alege oaspetele pentru camera aleasă. */
|
|
64
|
+
methods: (picked?.options ?? []).filter((x) => !ONLINE.has(x.method)),
|
|
65
|
+
method,
|
|
66
|
+
setMethod,
|
|
67
|
+
guest,
|
|
68
|
+
setGuest: (patch) => setGuestState((g) => ({ ...g, ...patch })),
|
|
69
|
+
busy,
|
|
70
|
+
error,
|
|
71
|
+
booked,
|
|
72
|
+
async reserve() {
|
|
73
|
+
setError('');
|
|
74
|
+
if (!picked)
|
|
75
|
+
return;
|
|
76
|
+
if (!guest.name.trim())
|
|
77
|
+
return setError(formText(o.lang, 'required'));
|
|
78
|
+
if (!isEmail(guest.email))
|
|
79
|
+
return setError(formText(o.lang, 'email'));
|
|
80
|
+
if (!/^[0-9+().\s-]{6,30}$/.test(guest.phone.trim()))
|
|
81
|
+
return setError(formText(o.lang, 'phone'));
|
|
82
|
+
setBusy(true);
|
|
83
|
+
try {
|
|
84
|
+
const out = await f('stay/reserve', {
|
|
85
|
+
json: { rooms: [{ typeId: picked.typeId, adults, children }], checkIn, checkOut, name: guest.name.trim(), email: guest.email.trim(), phone: guest.phone.trim(), notes: guest.notes.trim(), paymentMethod: method || 'on_site', lang: o.lang },
|
|
86
|
+
});
|
|
87
|
+
if (out.checkoutUrl)
|
|
88
|
+
window.location.href = out.checkoutUrl;
|
|
89
|
+
else
|
|
90
|
+
setBooked(out);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
setError(errorMessage(e));
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
setBusy(false);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
reset() {
|
|
100
|
+
setBooked(null);
|
|
101
|
+
setPicked(null);
|
|
102
|
+
setRooms(null);
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
package/dist/seo.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type SitemapEntry = {
|
|
2
|
+
/** Adresa completă a paginii. */
|
|
3
|
+
loc: string;
|
|
4
|
+
lastmod?: string | Date | null;
|
|
5
|
+
/** Perechile în alte limbi: `{ ro: 'https://site.ro/despre', en: 'https://site.ro/en/about' }`. */
|
|
6
|
+
alternates?: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
/** Sitemap XML; fiecare adresă își anunță perechile din alte limbi (`hreflang`). */
|
|
9
|
+
export declare function sitemapXml(entries: SitemapEntry[]): string;
|
|
10
|
+
export declare function sitemapResponse(entries: SitemapEntry[], maxAgeSec?: number): Response;
|
|
11
|
+
/** `robots.txt`: cu `index: false` (site de test sau preview) nu se indexează nimic. */
|
|
12
|
+
export declare function robotsTxt(o: {
|
|
13
|
+
site: string;
|
|
14
|
+
index: boolean;
|
|
15
|
+
disallow?: string[];
|
|
16
|
+
}): string;
|
|
17
|
+
export type Redirect = {
|
|
18
|
+
from: string;
|
|
19
|
+
to: string;
|
|
20
|
+
status: number;
|
|
21
|
+
};
|
|
22
|
+
/** Cheia unei adrese în lista de redirecturi: fără `/` la final. */
|
|
23
|
+
export declare const redirectKey: (pathname: string) => string;
|
|
24
|
+
/** Redirecturile din ERP (Site, Redirecturi), după adresa veche. */
|
|
25
|
+
export declare const redirectMap: (items: Redirect[]) => Map<string, Redirect>;
|
|
26
|
+
/** Redirectul care se aplică unei cereri: doar pentru pagini (GET/HEAD), nu pentru `/api`, `/_astro` sau fișiere. */
|
|
27
|
+
export declare function matchRedirect(map: Map<string, Redirect>, method: string, pathname: string): Redirect | null;
|
package/dist/seo.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
2
|
+
const day = (v) => (v instanceof Date ? v.toISOString() : String(v)).slice(0, 10);
|
|
3
|
+
/** Sitemap XML; fiecare adresă își anunță perechile din alte limbi (`hreflang`). */
|
|
4
|
+
export function sitemapXml(entries) {
|
|
5
|
+
const rows = entries.map((e) => {
|
|
6
|
+
const mod = e.lastmod ? `<lastmod>${day(e.lastmod)}</lastmod>` : '';
|
|
7
|
+
const alt = Object.entries(e.alternates ?? {})
|
|
8
|
+
.map(([l, href]) => `<xhtml:link rel="alternate" hreflang="${esc(l)}" href="${esc(href)}"/>`)
|
|
9
|
+
.join('');
|
|
10
|
+
return `<url><loc>${esc(e.loc)}</loc>${mod}${alt}</url>`;
|
|
11
|
+
});
|
|
12
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${rows.join('')}</urlset>`;
|
|
13
|
+
}
|
|
14
|
+
export function sitemapResponse(entries, maxAgeSec = 600) {
|
|
15
|
+
return new Response(sitemapXml(entries), { headers: { 'Content-Type': 'application/xml; charset=utf-8', 'Cache-Control': `public, max-age=${maxAgeSec}` } });
|
|
16
|
+
}
|
|
17
|
+
/** `robots.txt`: cu `index: false` (site de test sau preview) nu se indexează nimic. */
|
|
18
|
+
export function robotsTxt(o) {
|
|
19
|
+
const site = o.site.replace(/\/+$/, '');
|
|
20
|
+
if (!o.index)
|
|
21
|
+
return 'User-agent: *\nDisallow: /\n';
|
|
22
|
+
const extra = (o.disallow ?? ['/api/']).map((p) => `Disallow: ${p}`).join('\n');
|
|
23
|
+
return `User-agent: *\nAllow: /\n${extra}\n\nSitemap: ${site}/sitemap.xml\n`;
|
|
24
|
+
}
|
|
25
|
+
/** Cheia unei adrese în lista de redirecturi: fără `/` la final. */
|
|
26
|
+
export const redirectKey = (pathname) => pathname.replace(/\/+$/, '') || '/';
|
|
27
|
+
/** Redirecturile din ERP (Site, Redirecturi), după adresa veche. */
|
|
28
|
+
export const redirectMap = (items) => new Map(items.map((r) => [redirectKey(r.from), r]));
|
|
29
|
+
/** Redirectul care se aplică unei cereri: doar pentru pagini (GET/HEAD), nu pentru `/api`, `/_astro` sau fișiere. */
|
|
30
|
+
export function matchRedirect(map, method, pathname) {
|
|
31
|
+
if (method !== 'GET' && method !== 'HEAD')
|
|
32
|
+
return null;
|
|
33
|
+
if (pathname.startsWith('/api/') || pathname.startsWith('/_') || /\.[a-z0-9]+$/i.test(pathname))
|
|
34
|
+
return null;
|
|
35
|
+
return map.get(redirectKey(pathname)) ?? null;
|
|
36
|
+
}
|
package/dist/shop.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { SiteClient } from './client.js';
|
|
2
|
+
/** Un obiect din API-ul magazinului; forma exactă e în documentația API-ului de site. */
|
|
3
|
+
export type ShopData = Record<string, any>;
|
|
4
|
+
export type ShopList = {
|
|
5
|
+
items: ShopData[];
|
|
6
|
+
next_cursor?: string | null;
|
|
7
|
+
};
|
|
8
|
+
export type ShopApiOptions = {
|
|
9
|
+
/** Limba cererii curente: ERP-ul întoarce textele traduse și prețurile în moneda limbii. */
|
|
10
|
+
lang?: () => string | null | undefined;
|
|
11
|
+
/** Limba fără parametru în adresă (implicit `ro`). */
|
|
12
|
+
defaultLang?: string;
|
|
13
|
+
};
|
|
14
|
+
/** Ce trimite ERP-ul în webhook-ul `shop.changed`. */
|
|
15
|
+
export type ShopChanged = {
|
|
16
|
+
all?: boolean;
|
|
17
|
+
product_ids?: string[];
|
|
18
|
+
prefixes?: string[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Magazinul online (`/api/site/v1/shop`), cu cheia canalului. Citirile de catalog trec prin memoria clientului (separat pe limbă),
|
|
22
|
+
* coșul și cotele de livrare au o memorie scurtă proprie, iar tot ce ține de un cont cere sesiunea clientului (`session`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function createShopApi(client: SiteClient, o?: ShopApiOptions): {
|
|
25
|
+
channel: () => Promise<ShopData | null>;
|
|
26
|
+
paymentMethods: () => Promise<ShopData | null>;
|
|
27
|
+
menus: () => Promise<ShopData | null>;
|
|
28
|
+
pages: () => Promise<ShopData | null>;
|
|
29
|
+
page: (slug: string) => Promise<ShopData | null>;
|
|
30
|
+
redirects: () => Promise<{
|
|
31
|
+
items: Array<{
|
|
32
|
+
from: string;
|
|
33
|
+
to: string;
|
|
34
|
+
status: number;
|
|
35
|
+
}>;
|
|
36
|
+
} | null>;
|
|
37
|
+
/** O pagină de produse (`collection`, `limit`, `cursor`, filtre). */
|
|
38
|
+
products: (params?: Record<string, string | number | undefined>) => Promise<ShopList | null>;
|
|
39
|
+
/** Toate produsele unei liste, urmând `next_cursor` (de obicei o singură cerere), ca filtrele și paginarea să lucreze pe tot catalogul. */
|
|
40
|
+
allProducts(params?: Record<string, string | number | undefined>): Promise<ShopList>;
|
|
41
|
+
product: (slug: string) => Promise<ShopData | null>;
|
|
42
|
+
productReviews: (slug: string) => Promise<ShopData | null>;
|
|
43
|
+
recentReviews: (params?: {
|
|
44
|
+
limit?: number;
|
|
45
|
+
min_rating?: number;
|
|
46
|
+
}) => Promise<ShopData | null>;
|
|
47
|
+
collections: () => Promise<ShopList | null>;
|
|
48
|
+
collection: (slug: string) => Promise<ShopData | null>;
|
|
49
|
+
/** Căutarea nu trece prin memorie: interogările sunt prea variate. */
|
|
50
|
+
search: (q: string) => Promise<ShopData>;
|
|
51
|
+
counties: () => Promise<ShopData | null>;
|
|
52
|
+
cities: (county: string, q: string) => Promise<ShopData>;
|
|
53
|
+
streets: (a: {
|
|
54
|
+
county: string;
|
|
55
|
+
city: string;
|
|
56
|
+
q: string;
|
|
57
|
+
number?: string;
|
|
58
|
+
}) => Promise<ShopData>;
|
|
59
|
+
/** Verificarea adresei de livrare: un ajutor pentru client, nu un blocaj. */
|
|
60
|
+
addressCheck: (a: {
|
|
61
|
+
county: string;
|
|
62
|
+
city: string;
|
|
63
|
+
street: string;
|
|
64
|
+
number: string;
|
|
65
|
+
postal_code: string;
|
|
66
|
+
}) => Promise<ShopData>;
|
|
67
|
+
createCart: (body?: unknown) => Promise<ShopData>;
|
|
68
|
+
cart(token: string): Promise<ShopData>;
|
|
69
|
+
addLine: (token: string, productId: string, qty?: number) => Promise<ShopData>;
|
|
70
|
+
setLineQty: (token: string, lineId: string, qty: number) => Promise<ShopData>;
|
|
71
|
+
removeLine: (token: string, lineId: string) => Promise<ShopData>;
|
|
72
|
+
applyDiscount: (token: string, code: string) => Promise<ShopData>;
|
|
73
|
+
clearDiscount: (token: string) => Promise<ShopData>;
|
|
74
|
+
shippingQuote(token: string, a: {
|
|
75
|
+
county: string;
|
|
76
|
+
city?: string;
|
|
77
|
+
postalCode?: string;
|
|
78
|
+
}): Promise<ShopData>;
|
|
79
|
+
/** `idempotencyKey`: același pentru reîncercările aceleiași comenzi (de exemplu un id generat când se deschide checkout-ul). */
|
|
80
|
+
checkout(token: string, body: unknown, idempotencyKey: string, session?: string | null): Promise<ShopData>;
|
|
81
|
+
trackOrder: (params: Record<string, string>) => Promise<ShopData>;
|
|
82
|
+
register: (body: unknown) => Promise<ShopData>;
|
|
83
|
+
login: (body: unknown) => Promise<ShopData>;
|
|
84
|
+
me: (session: string) => Promise<ShopData>;
|
|
85
|
+
updateMe: (session: string, body: unknown) => Promise<ShopData>;
|
|
86
|
+
loyalty: (session: string) => Promise<ShopData>;
|
|
87
|
+
orders: (session: string, limit?: number) => Promise<ShopData>;
|
|
88
|
+
order: (session: string, number: string) => Promise<ShopData>;
|
|
89
|
+
addresses: (session: string) => Promise<ShopData>;
|
|
90
|
+
addAddress: (session: string, body: unknown) => Promise<ShopData>;
|
|
91
|
+
deleteAddress: (session: string, id: string) => Promise<ShopData>;
|
|
92
|
+
wishlist: (session: string) => Promise<ShopData>;
|
|
93
|
+
wishAdd: (session: string, productId: string) => Promise<ShopData>;
|
|
94
|
+
wishRemove: (session: string, productId: string) => Promise<ShopData>;
|
|
95
|
+
orderReviews: (session: string, number: string) => Promise<ShopData>;
|
|
96
|
+
pendingReviews: (session: string) => Promise<ShopData>;
|
|
97
|
+
submitReview(slug: string, body: unknown): Promise<ShopData>;
|
|
98
|
+
giftOffer: () => Promise<ShopData>;
|
|
99
|
+
buyGiftCard: (body: unknown) => Promise<ShopData>;
|
|
100
|
+
giftStatus: (token: string) => Promise<ShopData>;
|
|
101
|
+
requestQuote: (body: unknown) => Promise<ShopData>;
|
|
102
|
+
requestReturn: (body: unknown) => Promise<ShopData>;
|
|
103
|
+
/**
|
|
104
|
+
* Webhook-ul `shop.changed`: reîmprospătează în fundal doar ce s-a schimbat. Cu `product_ids`, intrările care conțin acele produse
|
|
105
|
+
* (fișa, listele, colecțiile); cu `prefixes`, părțile din vitrină numite de ERP (`page:`, `menus`, `redirects`...); fără ele, tot magazinul.
|
|
106
|
+
*/
|
|
107
|
+
purgeChanged(e?: ShopChanged): void;
|
|
108
|
+
};
|
|
109
|
+
/** Prefixul unei chei de vitrină din `shop.changed` -> începutul căii din API: `page:` -> `/shop/pages/`, `menus` -> `/shop/menus`. */
|
|
110
|
+
export declare const prefixPath: (prefix: string) => string;
|
|
111
|
+
export type ShopApi = ReturnType<typeof createShopApi>;
|