@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
package/dist/content.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { redirectMap } from './seo.js';
|
|
2
|
+
/** Adresa unei intrări după tiparul tipului: `/blog/{slug}` + `salut` dă `/blog/salut`. */
|
|
3
|
+
export const entryPath = (pattern, slug) => pattern.replace('{slug}', slug);
|
|
4
|
+
/** Slug-ul din adresă, dacă adresa se potrivește cu tiparul (`/blog/{slug}` și `/blog/salut` dau `salut`); altfel `null`. */
|
|
5
|
+
export function matchPattern(pattern, path) {
|
|
6
|
+
const i = pattern.indexOf('{slug}');
|
|
7
|
+
if (i < 0)
|
|
8
|
+
return null;
|
|
9
|
+
const before = pattern.slice(0, i);
|
|
10
|
+
const after = pattern.slice(i + '{slug}'.length);
|
|
11
|
+
const p = path.length > 1 ? path.replace(/\/+$/, '') : path;
|
|
12
|
+
if (!p.startsWith(before) || !p.endsWith(after) || p.length <= before.length + after.length)
|
|
13
|
+
return null;
|
|
14
|
+
const slug = p.slice(before.length, p.length - after.length);
|
|
15
|
+
return slug.includes('/') ? null : decodeURIComponent(slug);
|
|
16
|
+
}
|
|
17
|
+
/** Tipul și slug-ul pentru o adresă. Tiparele mai lungi (mai precise) au prioritate față de `/{slug}`. */
|
|
18
|
+
export function resolvePath(types, path) {
|
|
19
|
+
const withPages = types.filter((t) => t.url_pattern && !t.singleton).sort((a, b) => b.url_pattern.length - a.url_pattern.length);
|
|
20
|
+
for (const type of withPages) {
|
|
21
|
+
const slug = matchPattern(type.url_pattern, path);
|
|
22
|
+
if (slug)
|
|
23
|
+
return { type, slug };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const enc = encodeURIComponent;
|
|
28
|
+
/** Modulul Site (`/api/site/v1`): setări, meniuri, redirecturi, termeni, intrări, formulare. Citirile trec prin memoria clientului. */
|
|
29
|
+
export function createContentApi(client) {
|
|
30
|
+
const q = (locale, extra) => {
|
|
31
|
+
const sp = new URLSearchParams();
|
|
32
|
+
if (locale)
|
|
33
|
+
sp.set('locale', locale);
|
|
34
|
+
for (const [k, v] of Object.entries(extra ?? {}))
|
|
35
|
+
if (v !== undefined && v !== '')
|
|
36
|
+
sp.set(k, String(v));
|
|
37
|
+
const s = sp.toString();
|
|
38
|
+
return s ? `?${s}` : '';
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
/** Tipurile de conținut ale site-ului, cu tiparul de adresă și câmpurile. */
|
|
42
|
+
async types() {
|
|
43
|
+
return (await client.get('/types'))?.items ?? [];
|
|
44
|
+
},
|
|
45
|
+
/** Toate adresele publice indexabile, cu variantele pe limbi. */
|
|
46
|
+
async sitemap() {
|
|
47
|
+
const r = await client.get('/sitemap');
|
|
48
|
+
return { domain: r?.domain ?? null, items: r?.items ?? [] };
|
|
49
|
+
},
|
|
50
|
+
async settings(locale) {
|
|
51
|
+
return (await client.get(`/settings${q(locale)}`))?.items ?? {};
|
|
52
|
+
},
|
|
53
|
+
/** Meniurile site-ului, după cheie (`header`, `footer`...). */
|
|
54
|
+
async menus(locale) {
|
|
55
|
+
const r = await client.get(`/menus${q(locale)}`);
|
|
56
|
+
return Object.fromEntries((r?.items ?? []).map((m) => [m.key, m.items]));
|
|
57
|
+
},
|
|
58
|
+
async redirects() {
|
|
59
|
+
return redirectMap((await client.get('/redirects'))?.items ?? []);
|
|
60
|
+
},
|
|
61
|
+
async terms(taxonomy, locale) {
|
|
62
|
+
return (await client.get(`/terms${q(locale, { taxonomy })}`))?.items ?? [];
|
|
63
|
+
},
|
|
64
|
+
/** Intrările unui tip (`page`, `post`...). `params`: `per_page`, `page`, filtre pe câmpuri, `sort`. */
|
|
65
|
+
async list(type, locale, params = { per_page: 100 }) {
|
|
66
|
+
const r = await client.get(`/entries/${enc(type)}${q(locale, params)}`);
|
|
67
|
+
return { items: r?.items ?? [], total: r?.total ?? r?.items?.length ?? 0 };
|
|
68
|
+
},
|
|
69
|
+
/** O intrare după slug; `null` dacă nu există sau nu e publicată. */
|
|
70
|
+
async one(type, slug, locale) {
|
|
71
|
+
return (await client.get(`/entries/${enc(type)}/${enc(slug)}${q(locale)}`))?.item ?? null;
|
|
72
|
+
},
|
|
73
|
+
/** Căutare în conținutul public. */
|
|
74
|
+
async search(text, locale) {
|
|
75
|
+
return (await client.call(`/search${q(locale, { q: text })}`))?.items ?? [];
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Trimite un formular de pe site (Site, Cereri). Răspunsul vine așa cum l-a dat ERP-ul, ca ruta site-ului să-l poată da mai departe.
|
|
79
|
+
* `visitorIp` e obligatoriu în practică: limitele se aplică pe vizitator.
|
|
80
|
+
*/
|
|
81
|
+
submitForm(form, body, o = {}) {
|
|
82
|
+
return client.request(`/forms/${enc(form)}`, { method: 'POST', json: body, visitorIp: o.visitorIp });
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export type I18nOptions<L extends string> = {
|
|
3
|
+
/** Prima e limba implicită (fără prefix în adresă), restul au prefix: `['ro', 'en']` dă `/despre` și `/en/despre`. */
|
|
4
|
+
locales: readonly [L, ...L[]];
|
|
5
|
+
/**
|
|
6
|
+
* Segmentele traduse, pe limbă: `{ en: { produse: 'products', cos: 'cart' } }`. Se traduce doar primul segment al adresei
|
|
7
|
+
* (paginile sunt aceleași fișiere, middleware-ul rescrie); slugurile din restul adresei nu se ating.
|
|
8
|
+
*/
|
|
9
|
+
segments?: Partial<Record<L, Record<string, string>>>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Limba cererii, din prefixul adresei. Middleware-ul o pune în context cu `run`, iar `lang()`, `t()` și `lp()` o citesc
|
|
13
|
+
* fără să fie trimisă prin fiecare componentă.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createI18n<L extends string>(o: I18nOptions<L>): {
|
|
16
|
+
locales: readonly [L, ...L[]];
|
|
17
|
+
defaultLocale: L;
|
|
18
|
+
store: AsyncLocalStorage<{
|
|
19
|
+
lang: L;
|
|
20
|
+
}>;
|
|
21
|
+
run: <T>(l: L, fn: () => T) => T;
|
|
22
|
+
lang: () => L;
|
|
23
|
+
t: (...texts: string[]) => string;
|
|
24
|
+
lp: (url: string) => string;
|
|
25
|
+
langOf: (pathname: string) => L;
|
|
26
|
+
stripLang: (pathname: string) => string;
|
|
27
|
+
toDefault: (pathname: string) => string;
|
|
28
|
+
pathIn: (url: string, l: L) => string;
|
|
29
|
+
localizeLinks: (html: string, l?: L) => string;
|
|
30
|
+
};
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const STATIC = /\.(?:css|js|mjs|png|jpe?g|gif|svg|webp|avif|ico|woff2?|xml|json|txt|pdf|map)$/i;
|
|
3
|
+
const TAG = /<(?:a|form|area)(?=[\s>])[^>]*>/gi;
|
|
4
|
+
const ATTR = /(\s(?:href|action)=)(["'])(\/(?!\/)[^"']*?)(["'])/g;
|
|
5
|
+
const split = (url) => {
|
|
6
|
+
const i = url.search(/[?#]/);
|
|
7
|
+
return i < 0 ? [url, ''] : [url.slice(0, i), url.slice(i)];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Limba cererii, din prefixul adresei. Middleware-ul o pune în context cu `run`, iar `lang()`, `t()` și `lp()` o citesc
|
|
11
|
+
* fără să fie trimisă prin fiecare componentă.
|
|
12
|
+
*/
|
|
13
|
+
export function createI18n(o) {
|
|
14
|
+
const [def, ...others] = o.locales;
|
|
15
|
+
const store = new AsyncLocalStorage();
|
|
16
|
+
const fwd = Object.fromEntries(others.map((l) => [l, o.segments?.[l] ?? {}]));
|
|
17
|
+
const back = Object.fromEntries(others.map((l) => [l, Object.fromEntries(Object.entries(fwd[l]).map(([a, b]) => [b, a]))]));
|
|
18
|
+
const prefixRe = new RegExp(`^/(${others.join('|')})(?=/|$)`);
|
|
19
|
+
const mapFirst = (path, m) => {
|
|
20
|
+
const parts = path.split('/');
|
|
21
|
+
if (parts[1] && m[parts[1]])
|
|
22
|
+
parts[1] = m[parts[1]];
|
|
23
|
+
return parts.join('/');
|
|
24
|
+
};
|
|
25
|
+
/** Limba unei adrese, după prefix. */
|
|
26
|
+
const langOf = (pathname) => prefixRe.exec(pathname)?.[1] ?? def;
|
|
27
|
+
/** Adresa fără prefixul de limbă. */
|
|
28
|
+
const stripLang = (pathname) => pathname.replace(prefixRe, '') || '/';
|
|
29
|
+
/** Adresa fără prefix, cu segmentele în limba implicită: fișierul de pagină care o servește (`/en/products` -> `/produse`). */
|
|
30
|
+
const toDefault = (pathname) => {
|
|
31
|
+
const l = langOf(pathname);
|
|
32
|
+
const p = stripLang(pathname);
|
|
33
|
+
return l === def ? p : mapFirst(p, back[l]);
|
|
34
|
+
};
|
|
35
|
+
/** Adresa unei pagini (fără prefix, cu segmente în limba implicită) în limba `l`. */
|
|
36
|
+
const pathIn = (url, l) => {
|
|
37
|
+
if (l === def || !url.startsWith('/') || url.startsWith('//') || url.startsWith('/api/'))
|
|
38
|
+
return url;
|
|
39
|
+
if (prefixRe.test(url))
|
|
40
|
+
return url;
|
|
41
|
+
const [p, rest] = split(url);
|
|
42
|
+
return p === '/' ? `/${l}${rest}` : `/${l}${mapFirst(p, fwd[l])}${rest}`;
|
|
43
|
+
};
|
|
44
|
+
const lang = () => store.getStore()?.lang ?? def;
|
|
45
|
+
const run = (l, fn) => store.run({ lang: l }, fn);
|
|
46
|
+
/** Textul în limba curentă, în ordinea din `locales`: `t('Coșul meu', 'My cart')`. */
|
|
47
|
+
const t = (...texts) => texts[o.locales.indexOf(lang())] ?? texts[0];
|
|
48
|
+
/** Adresa internă în limba curentă (`/cos` -> `/en/cart`). Adresele externe și `/api` rămân neschimbate. */
|
|
49
|
+
const lp = (url) => pathIn(url, lang());
|
|
50
|
+
const skip = new RegExp(`^/(?:(?:${others.join('|')})(?:[/?#]|$)|api/|_astro/|_image|fonts/|favicon|robots\\.txt|sitemap)`);
|
|
51
|
+
/**
|
|
52
|
+
* Pune prefixul limbii pe linkurile și formularele interne dintr-un HTML (și pe cele din conținutul venit din ERP).
|
|
53
|
+
* Un element cu `data-nolang` rămâne neschimbat.
|
|
54
|
+
*/
|
|
55
|
+
function localizeLinks(html, l = lang()) {
|
|
56
|
+
if (l === def)
|
|
57
|
+
return html;
|
|
58
|
+
return html.replace(TAG, (tag) => {
|
|
59
|
+
if (tag.includes('data-nolang'))
|
|
60
|
+
return tag;
|
|
61
|
+
return tag.replace(ATTR, (m, attr, q, url, end) => {
|
|
62
|
+
if (skip.test(url) || STATIC.test(split(url)[0]))
|
|
63
|
+
return m;
|
|
64
|
+
return `${attr}${q}${pathIn(url, l)}${end}`;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return { locales: o.locales, defaultLocale: def, store, run, lang, t, lp, langOf, stripLang, toDefault, pathIn, localizeLinks };
|
|
69
|
+
}
|
package/dist/images.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pozele din ERP au două variante: miniatura (`?size=thumb`, latura mică 480 px) și cea mare (cel mult 1600 px).
|
|
3
|
+
* Site-ul nu le prelucrează: alege doar varianta potrivită lățimii cerute.
|
|
4
|
+
*/
|
|
5
|
+
export declare const THUMB_WIDTH = 480;
|
|
6
|
+
export declare const FULL_WIDTH = 1600;
|
|
7
|
+
/** Până la această lățime ajunge miniatura; cardurile din liste nu cer mai mult, deci nu descarcă varianta mare. */
|
|
8
|
+
export declare const THUMB_UP_TO = 960;
|
|
9
|
+
export declare const isErpImage: (url: string | null | undefined) => boolean;
|
|
10
|
+
/** Poza la lățimea cerută: miniatura sau varianta mare la ERP, parametrul `w` la Unsplash; orice altă adresă rămâne neschimbată. */
|
|
11
|
+
export declare function imageAt(url: string | null | undefined, width: number): string;
|
|
12
|
+
/** Lățimile care există cu adevărat pentru `srcset`: cele două variante la ERP, cele cerute la Unsplash, niciuna altundeva. */
|
|
13
|
+
export declare function imageWidths(url: string, widths?: number[]): number[];
|
package/dist/images.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pozele din ERP au două variante: miniatura (`?size=thumb`, latura mică 480 px) și cea mare (cel mult 1600 px).
|
|
3
|
+
* Site-ul nu le prelucrează: alege doar varianta potrivită lățimii cerute.
|
|
4
|
+
*/
|
|
5
|
+
export const THUMB_WIDTH = 480;
|
|
6
|
+
export const FULL_WIDTH = 1600;
|
|
7
|
+
/** Până la această lățime ajunge miniatura; cardurile din liste nu cer mai mult, deci nu descarcă varianta mare. */
|
|
8
|
+
export const THUMB_UP_TO = 960;
|
|
9
|
+
export const isErpImage = (url) => !!url && (url.includes('/api/img/') || url.includes('/api/shop/media/') || url.includes('/stay/image/'));
|
|
10
|
+
/** Poza la lățimea cerută: miniatura sau varianta mare la ERP, parametrul `w` la Unsplash; orice altă adresă rămâne neschimbată. */
|
|
11
|
+
export function imageAt(url, width) {
|
|
12
|
+
const u = (url ?? '').split('?size')[0];
|
|
13
|
+
if (isErpImage(u))
|
|
14
|
+
return width <= THUMB_UP_TO ? `${u}?size=thumb` : u;
|
|
15
|
+
return u.includes('images.unsplash.com') ? u.replace(/([?&])w=\d+/, `$1w=${width}`) : u;
|
|
16
|
+
}
|
|
17
|
+
/** Lățimile care există cu adevărat pentru `srcset`: cele două variante la ERP, cele cerute la Unsplash, niciuna altundeva. */
|
|
18
|
+
export function imageWidths(url, widths = []) {
|
|
19
|
+
if (!widths.length)
|
|
20
|
+
return [];
|
|
21
|
+
if (url.includes('images.unsplash.com'))
|
|
22
|
+
return widths;
|
|
23
|
+
if (isErpImage(url))
|
|
24
|
+
return Math.max(...widths) > THUMB_UP_TO ? [THUMB_WIDTH, FULL_WIDTH] : [THUMB_WIDTH];
|
|
25
|
+
return [];
|
|
26
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createSiteClient, apiError, fieldErrors, RivilApiError, type SiteClient, type SiteClientOptions, type RequestOptions } from './client.js';
|
|
2
|
+
export { createShopApi, prefixPath, type ShopApi, type ShopApiOptions, type ShopChanged, type ShopData, type ShopList } from './shop.js';
|
|
3
|
+
export { accountGet, accountProxy, accountRequest, AUTH_ROUTES, type AccountProxyOptions, type AccountRoute, type CookieJar, type ProxyContext } from './account.js';
|
|
4
|
+
export { createContentApi, entryPath, matchPattern, resolvePath, type ContentType, type Entry, type Img, type MenuItem, type SitemapItem, type Term } from './content.js';
|
|
5
|
+
export { createI18n, type I18nOptions } from './i18n.js';
|
|
6
|
+
export { imageAt, imageWidths, isErpImage, THUMB_UP_TO, THUMB_WIDTH, FULL_WIDTH } from './images.js';
|
|
7
|
+
export { sitemapXml, sitemapResponse, robotsTxt, redirectMap, redirectKey, matchRedirect, type SitemapEntry, type Redirect } from './seo.js';
|
|
8
|
+
export { consentScriptUrl, CONSENT_ORIGIN } from './consent.js';
|
|
9
|
+
export { visitorIp, VISITOR_HEADER } from './visitor.js';
|
|
10
|
+
export { verifyRivilSignature, signRivilPayload, rivilWebhookHandler, type RivilEvent } from './webhook.js';
|
|
11
|
+
export { createModulesApi, type ModulesApi, type BookingCatalog, type BookingService, type BookingField, type Consent, type Slot, type JobSummary, type Job, type ApplyInfo, type ReviewSurvey, type ReviewWall, type EventSummary, type EventDetail, type EventOrder, type EventQuestion, type TicketType } from './modules.js';
|
|
12
|
+
export { siteProxy, MODULE_ROUTES, ALL_MODULE_ROUTES, type ProxyRoute, type SiteProxyOptions } from './proxy.js';
|
|
13
|
+
export { textToHtml } from './web.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createSiteClient, apiError, fieldErrors, RivilApiError } from './client.js';
|
|
2
|
+
export { createShopApi, prefixPath } from './shop.js';
|
|
3
|
+
export { accountGet, accountProxy, accountRequest, AUTH_ROUTES } from './account.js';
|
|
4
|
+
export { createContentApi, entryPath, matchPattern, resolvePath } from './content.js';
|
|
5
|
+
export { createI18n } from './i18n.js';
|
|
6
|
+
export { imageAt, imageWidths, isErpImage, THUMB_UP_TO, THUMB_WIDTH, FULL_WIDTH } from './images.js';
|
|
7
|
+
export { sitemapXml, sitemapResponse, robotsTxt, redirectMap, redirectKey, matchRedirect } from './seo.js';
|
|
8
|
+
export { consentScriptUrl, CONSENT_ORIGIN } from './consent.js';
|
|
9
|
+
export { visitorIp, VISITOR_HEADER } from './visitor.js';
|
|
10
|
+
export { verifyRivilSignature, signRivilPayload, rivilWebhookHandler } from './webhook.js';
|
|
11
|
+
export { createModulesApi } from './modules.js';
|
|
12
|
+
export { siteProxy, MODULE_ROUTES, ALL_MODULE_ROUTES } from './proxy.js';
|
|
13
|
+
export { textToHtml } from './web.js';
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import type { SiteClient } from './client.js';
|
|
2
|
+
/** Câmpurile pe care le folosesc blocurile; ERP-ul trimite mai multe, toate rămân în obiect. */
|
|
3
|
+
export type BookingService = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
category?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
durationMinutes: number;
|
|
9
|
+
price: number | null;
|
|
10
|
+
specialistIds: string[] | null;
|
|
11
|
+
locationIds: string[];
|
|
12
|
+
};
|
|
13
|
+
export type BookingField = {
|
|
14
|
+
key: string;
|
|
15
|
+
label: string;
|
|
16
|
+
type: string;
|
|
17
|
+
required?: boolean;
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
help?: string;
|
|
21
|
+
options?: string[];
|
|
22
|
+
};
|
|
23
|
+
export type Consent = {
|
|
24
|
+
key: string;
|
|
25
|
+
text: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
enabled?: boolean;
|
|
28
|
+
};
|
|
29
|
+
export type BookingCatalog = {
|
|
30
|
+
services: BookingService[];
|
|
31
|
+
locations: Array<{
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
address?: string;
|
|
35
|
+
}>;
|
|
36
|
+
employees: Array<{
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
locationIds?: string[];
|
|
40
|
+
}>;
|
|
41
|
+
config?: {
|
|
42
|
+
horizonDays?: number;
|
|
43
|
+
holdMinutes?: number;
|
|
44
|
+
showSpecialists?: boolean;
|
|
45
|
+
[k: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
form?: {
|
|
48
|
+
fields?: BookingField[];
|
|
49
|
+
consents?: Consent[];
|
|
50
|
+
};
|
|
51
|
+
flow?: {
|
|
52
|
+
steps?: Array<{
|
|
53
|
+
type: string;
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
currency?: string;
|
|
58
|
+
[k: string]: unknown;
|
|
59
|
+
};
|
|
60
|
+
export type Slot = {
|
|
61
|
+
start: string;
|
|
62
|
+
end: string;
|
|
63
|
+
spots: number;
|
|
64
|
+
locationName?: string;
|
|
65
|
+
employees?: Array<{
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
export type JobSummary = {
|
|
71
|
+
id: string;
|
|
72
|
+
slug: string;
|
|
73
|
+
title: string;
|
|
74
|
+
department: string | null;
|
|
75
|
+
location: string | null;
|
|
76
|
+
employmentType: string;
|
|
77
|
+
workMode: string;
|
|
78
|
+
salary: string | null;
|
|
79
|
+
closesAt: string | null;
|
|
80
|
+
publishedAt: string | null;
|
|
81
|
+
featured: boolean;
|
|
82
|
+
[k: string]: unknown;
|
|
83
|
+
};
|
|
84
|
+
export type Job = JobSummary & {
|
|
85
|
+
description: string | null;
|
|
86
|
+
requirements: string | null;
|
|
87
|
+
benefits: string | null;
|
|
88
|
+
sections: Array<{
|
|
89
|
+
title: string;
|
|
90
|
+
body: string;
|
|
91
|
+
}>;
|
|
92
|
+
seo?: {
|
|
93
|
+
title: string;
|
|
94
|
+
description: string;
|
|
95
|
+
imageUrl: string;
|
|
96
|
+
};
|
|
97
|
+
[k: string]: unknown;
|
|
98
|
+
};
|
|
99
|
+
export type ApplyInfo = {
|
|
100
|
+
fields?: Record<string, {
|
|
101
|
+
on: boolean;
|
|
102
|
+
required: boolean;
|
|
103
|
+
label: string;
|
|
104
|
+
}>;
|
|
105
|
+
cv?: {
|
|
106
|
+
on: boolean;
|
|
107
|
+
required?: boolean;
|
|
108
|
+
maxMb?: number;
|
|
109
|
+
types?: string[];
|
|
110
|
+
};
|
|
111
|
+
questions?: Array<{
|
|
112
|
+
id: string;
|
|
113
|
+
type: string;
|
|
114
|
+
label: string;
|
|
115
|
+
help?: string;
|
|
116
|
+
required?: boolean;
|
|
117
|
+
options?: string[];
|
|
118
|
+
min?: number;
|
|
119
|
+
max?: number;
|
|
120
|
+
showIf?: unknown;
|
|
121
|
+
}>;
|
|
122
|
+
consents?: Consent[];
|
|
123
|
+
texts?: Record<string, string>;
|
|
124
|
+
[k: string]: unknown;
|
|
125
|
+
};
|
|
126
|
+
export type ReviewSurvey = {
|
|
127
|
+
surveys?: Array<{
|
|
128
|
+
questions: Array<Record<string, unknown>>;
|
|
129
|
+
match: {
|
|
130
|
+
channels: unknown[];
|
|
131
|
+
services: unknown[];
|
|
132
|
+
locations: unknown[];
|
|
133
|
+
};
|
|
134
|
+
}>;
|
|
135
|
+
fields?: Record<string, {
|
|
136
|
+
on: boolean;
|
|
137
|
+
required: boolean;
|
|
138
|
+
}>;
|
|
139
|
+
consents?: Consent[];
|
|
140
|
+
texts?: Record<string, string>;
|
|
141
|
+
options?: {
|
|
142
|
+
services?: Array<{
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
[k: string]: unknown;
|
|
148
|
+
};
|
|
149
|
+
export type ReviewWall = {
|
|
150
|
+
count: number;
|
|
151
|
+
average: number | null;
|
|
152
|
+
distribution: number[];
|
|
153
|
+
reviews: Array<{
|
|
154
|
+
id: string;
|
|
155
|
+
score: number;
|
|
156
|
+
comment: string;
|
|
157
|
+
author: string;
|
|
158
|
+
date: string;
|
|
159
|
+
iso: string;
|
|
160
|
+
service: string | null;
|
|
161
|
+
specialist: string | null;
|
|
162
|
+
reply: {
|
|
163
|
+
text: string;
|
|
164
|
+
date: string;
|
|
165
|
+
} | null;
|
|
166
|
+
}>;
|
|
167
|
+
hasMore: boolean;
|
|
168
|
+
services: Array<{
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
}>;
|
|
172
|
+
employees: Array<{
|
|
173
|
+
id: string;
|
|
174
|
+
name: string;
|
|
175
|
+
}>;
|
|
176
|
+
};
|
|
177
|
+
export type EventSummary = {
|
|
178
|
+
code: string;
|
|
179
|
+
title: string;
|
|
180
|
+
summary: string;
|
|
181
|
+
imageUrl: string | null;
|
|
182
|
+
venueName: string;
|
|
183
|
+
venueAddress: string;
|
|
184
|
+
startsAt: string;
|
|
185
|
+
endsAt: string;
|
|
186
|
+
timezone: string;
|
|
187
|
+
currency: string;
|
|
188
|
+
state: 'open' | 'cancelled';
|
|
189
|
+
fromPrice: number | null;
|
|
190
|
+
};
|
|
191
|
+
export type TicketType = {
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
description: string;
|
|
195
|
+
price: number;
|
|
196
|
+
state: 'open' | 'soldout' | 'soon' | 'closed' | 'paid';
|
|
197
|
+
left: number | null;
|
|
198
|
+
minPerOrder: number;
|
|
199
|
+
maxPerOrder: number;
|
|
200
|
+
};
|
|
201
|
+
export type EventQuestion = {
|
|
202
|
+
id: string;
|
|
203
|
+
label: string;
|
|
204
|
+
type: 'text' | 'textarea' | 'select' | 'checkbox';
|
|
205
|
+
required: boolean;
|
|
206
|
+
options: string[];
|
|
207
|
+
};
|
|
208
|
+
export type EventDetail = Omit<EventSummary, 'state' | 'fromPrice'> & {
|
|
209
|
+
description: string;
|
|
210
|
+
photos: string[];
|
|
211
|
+
cancellationPolicy: string;
|
|
212
|
+
state: 'open' | 'ended' | 'cancelled';
|
|
213
|
+
waitlistEnabled: boolean;
|
|
214
|
+
questions: EventQuestion[];
|
|
215
|
+
types: TicketType[];
|
|
216
|
+
};
|
|
217
|
+
export type EventOrder = {
|
|
218
|
+
event: {
|
|
219
|
+
title: string;
|
|
220
|
+
startsAt: string;
|
|
221
|
+
endsAt: string;
|
|
222
|
+
timezone: string;
|
|
223
|
+
venueName: string;
|
|
224
|
+
venueAddress: string;
|
|
225
|
+
onlineUrl: string | null;
|
|
226
|
+
state: string;
|
|
227
|
+
publicCode: string;
|
|
228
|
+
};
|
|
229
|
+
buyerName: string;
|
|
230
|
+
email: string;
|
|
231
|
+
status: string;
|
|
232
|
+
tickets: Array<{
|
|
233
|
+
number: number;
|
|
234
|
+
typeName: string;
|
|
235
|
+
attendeeName: string;
|
|
236
|
+
status: string;
|
|
237
|
+
}>;
|
|
238
|
+
total: number;
|
|
239
|
+
discount: number;
|
|
240
|
+
currency: string;
|
|
241
|
+
paymentUrl: string | null;
|
|
242
|
+
reservedUntil: string | null;
|
|
243
|
+
lateWithoutSeats: boolean;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Citirile modulelor pentru paginile randate pe server: catalogul de programări, joburile, chestionarul și peretele de recenzii, evenimentele.
|
|
247
|
+
* Ce se schimbă de la minut la minut (locuri la eveniment, starea unei comenzi) nu trece prin memorie.
|
|
248
|
+
*/
|
|
249
|
+
export declare function createModulesApi(client: SiteClient): {
|
|
250
|
+
booking: {
|
|
251
|
+
/** Serviciile, specialiștii, locațiile și formularul; `null` când programările online nu sunt pornite. */
|
|
252
|
+
catalog: (lang?: string) => Promise<BookingCatalog | null>;
|
|
253
|
+
};
|
|
254
|
+
careers: {
|
|
255
|
+
list: (lang?: string) => Promise<JobSummary[]>;
|
|
256
|
+
/** Jobul și formularul lui; `null` dacă s-a închis sau nu există. */
|
|
257
|
+
job: (slug: string, lang?: string) => Promise<{
|
|
258
|
+
posting: Job;
|
|
259
|
+
info: ApplyInfo;
|
|
260
|
+
} | null>;
|
|
261
|
+
/** Formularul de aplicare spontană; `null` dacă firma nu îl are pornit. */
|
|
262
|
+
spontaneous: (lang?: string) => Promise<{
|
|
263
|
+
info: ApplyInfo;
|
|
264
|
+
} | null>;
|
|
265
|
+
};
|
|
266
|
+
reviews: {
|
|
267
|
+
/** Chestionarul deschis (fără invitație). */
|
|
268
|
+
survey: (lang?: string) => Promise<ReviewSurvey | null>;
|
|
269
|
+
/** Recenziile publicate de firmă; `null` când peretele nu e pornit. */
|
|
270
|
+
wall: (o?: {
|
|
271
|
+
lang?: string;
|
|
272
|
+
page?: number;
|
|
273
|
+
service?: string;
|
|
274
|
+
employee?: string;
|
|
275
|
+
}) => Promise<ReviewWall | null>;
|
|
276
|
+
};
|
|
277
|
+
events: {
|
|
278
|
+
list: (lang?: string) => Promise<EventSummary[]>;
|
|
279
|
+
/** Cu locurile de acum, deci fără memorie. */
|
|
280
|
+
get: (code: string, o?: {
|
|
281
|
+
lang?: string;
|
|
282
|
+
access?: string;
|
|
283
|
+
invite?: string;
|
|
284
|
+
}) => Promise<EventDetail | null>;
|
|
285
|
+
order: (token: string, lang?: string) => Promise<EventOrder | null>;
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
export type ModulesApi = ReturnType<typeof createModulesApi>;
|
package/dist/modules.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const enc = encodeURIComponent;
|
|
2
|
+
const qs = (o) => {
|
|
3
|
+
const sp = new URLSearchParams();
|
|
4
|
+
for (const [k, v] of Object.entries(o))
|
|
5
|
+
if (v !== undefined && v !== null && v !== '')
|
|
6
|
+
sp.set(k, String(v));
|
|
7
|
+
const s = sp.toString();
|
|
8
|
+
return s ? `?${s}` : '';
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Citirile modulelor pentru paginile randate pe server: catalogul de programări, joburile, chestionarul și peretele de recenzii, evenimentele.
|
|
12
|
+
* Ce se schimbă de la minut la minut (locuri la eveniment, starea unei comenzi) nu trece prin memorie.
|
|
13
|
+
*/
|
|
14
|
+
export function createModulesApi(client) {
|
|
15
|
+
/** Fără memorie; `null` la 404. */
|
|
16
|
+
const fresh = async (path) => {
|
|
17
|
+
const res = await client.request(path);
|
|
18
|
+
if (res.status === 404)
|
|
19
|
+
return null;
|
|
20
|
+
if (!res.ok)
|
|
21
|
+
throw new Error(`${path}: HTTP ${res.status}`);
|
|
22
|
+
return (await res.json());
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
booking: {
|
|
26
|
+
/** Serviciile, specialiștii, locațiile și formularul; `null` când programările online nu sunt pornite. */
|
|
27
|
+
catalog: (lang) => client.get(`/booking${qs({ lang })}`),
|
|
28
|
+
},
|
|
29
|
+
careers: {
|
|
30
|
+
list: async (lang) => (await client.get(`/careers${qs({ lang })}`))?.postings ?? [],
|
|
31
|
+
/** Jobul și formularul lui; `null` dacă s-a închis sau nu există. */
|
|
32
|
+
job: (slug, lang) => client.get(`/careers${qs({ job: slug, lang })}`),
|
|
33
|
+
/** Formularul de aplicare spontană; `null` dacă firma nu îl are pornit. */
|
|
34
|
+
spontaneous: (lang) => client.get(`/careers${qs({ spontaneous: 1, lang })}`),
|
|
35
|
+
},
|
|
36
|
+
reviews: {
|
|
37
|
+
/** Chestionarul deschis (fără invitație). */
|
|
38
|
+
survey: (lang) => client.get(`/reviews${qs({ open: 1, lang })}`),
|
|
39
|
+
/** Recenziile publicate de firmă; `null` când peretele nu e pornit. */
|
|
40
|
+
wall: (o = {}) => client.get(`/reviews/wall${qs(o)}`),
|
|
41
|
+
},
|
|
42
|
+
events: {
|
|
43
|
+
list: async (lang) => (await client.get(`/events${qs({ lang })}`))?.events ?? [],
|
|
44
|
+
/** Cu locurile de acum, deci fără memorie. */
|
|
45
|
+
get: async (code, o = {}) => (await fresh(`/events/${enc(code)}${qs(o)}`))?.event ?? null,
|
|
46
|
+
order: async (token, lang) => (await fresh(`/events/orders/${enc(token)}${qs({ lang })}`))?.order ?? null,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
package/dist/proxy.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SiteClient } from './client.js';
|
|
2
|
+
export type ProxyRoute = {
|
|
3
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
4
|
+
/** Calea după `/api/rivil/`, aceeași ca în `/api/site/v1/`, de exemplu `/^booking\/hold$/`. */
|
|
5
|
+
path: RegExp;
|
|
6
|
+
/** Corpul: JSON (implicit la scrieri), fișiere (`multipart`) sau nimic. */
|
|
7
|
+
body?: 'json' | 'multipart' | 'none';
|
|
8
|
+
/** Răspunsul e un fișier (bilete PDF): trece ca atare. */
|
|
9
|
+
file?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Ce poate cere browserul prin site, pe module. Doar citiri publice și acțiunile unui vizitator (rezervă, aplică, comandă);
|
|
13
|
+
* nimic din administrare. Lista se poate restrânge la modulele site-ului: `routes: [...MODULE_ROUTES.booking, ...MODULE_ROUTES.forms]`.
|
|
14
|
+
*/
|
|
15
|
+
export declare const MODULE_ROUTES: {
|
|
16
|
+
forms: ProxyRoute[];
|
|
17
|
+
newsletter: ProxyRoute[];
|
|
18
|
+
addresses: ProxyRoute[];
|
|
19
|
+
booking: ProxyRoute[];
|
|
20
|
+
stay: ProxyRoute[];
|
|
21
|
+
careers: ProxyRoute[];
|
|
22
|
+
reviews: ProxyRoute[];
|
|
23
|
+
events: ProxyRoute[];
|
|
24
|
+
};
|
|
25
|
+
export declare const ALL_MODULE_ROUTES: ProxyRoute[];
|
|
26
|
+
export type SiteProxyOptions = {
|
|
27
|
+
client: SiteClient;
|
|
28
|
+
/** Implicit toate modulele din `MODULE_ROUTES`. */
|
|
29
|
+
routes?: ProxyRoute[];
|
|
30
|
+
/**
|
|
31
|
+
* Adresele de pe care pot veni scrierile, pe lângă adresa cererii. Pune aici adresa publică a site-ului: în spatele unui proxy,
|
|
32
|
+
* Astro vede cererea pe `localhost`, iar fără ea browserul ar primi 403.
|
|
33
|
+
*/
|
|
34
|
+
origins?: string[];
|
|
35
|
+
/** Limita pentru fișiere (implicit 25 MB). */
|
|
36
|
+
maxUploadBytes?: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Proxy-ul modulelor: browserul vorbește doar cu site-ul (fără CORS, fără cheie în pagină), site-ul cheamă `/api/site/v1` cu cheia de site.
|
|
40
|
+
* Trec doar rutele din listă, cu adresa vizitatorului. Răspunsul nu se ține în memorie: locurile și orele libere trebuie să fie cele de acum.
|
|
41
|
+
* În Astro (`src/pages/api/rivil/[...path].ts`): `const proxy = siteProxy({ client }); export const ALL = (c) => proxy({ request: c.request, path: c.params.path, clientAddress: c.clientAddress })`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function siteProxy(o: SiteProxyOptions): (c: {
|
|
44
|
+
request: Request;
|
|
45
|
+
path: string | undefined;
|
|
46
|
+
clientAddress?: string;
|
|
47
|
+
}) => Promise<Response>;
|