@requiply/embed 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.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +57 -0
- package/dist/catalog.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/placeholders.d.ts +97 -0
- package/dist/placeholders.d.ts.map +1 -0
- package/dist/placeholders.js +54 -0
- package/dist/placeholders.js.map +1 -0
- package/dist/runtime.d.ts +105 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +164 -0
- package/dist/runtime.js.map +1 -0
- package/dist/script.d.ts +22 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +63 -0
- package/dist/script.js.map +1 -0
- package/dist/types.d.ts +188 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrian Zafiiovskiy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @requiply/embed
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The framework-agnostic core of the [Requiply](https://requiply.com) booking widgets, shared by [`@requiply/react`](https://www.npmjs.com/package/@requiply/react) and [`@requiply/nuxt`](https://www.npmjs.com/package/@requiply/nuxt). Use one of those in an app; use this package to build an integration for another framework.
|
|
4
|
+
|
|
5
|
+
- `embedScriptUrl()`, `embedScriptAttributes()`: the widget runtime's script tag and its `data-*` options.
|
|
6
|
+
- `themeCss()`: theme tokens as `--rq-*` variables.
|
|
7
|
+
- `PLACEHOLDERS`, `placeholderAttributes()`: the element and attributes of each widget.
|
|
8
|
+
- `subscribeEmbed()`, `getEmbedSnapshot()`, `getServerEmbedSnapshot()`: the widgets' cart and readiness as an external store (React's `useSyncExternalStore` takes them as they are).
|
|
9
|
+
- `addToCart()`, `productLiveState()`, `whenEmbedReady()`, `embedRuntime()`: cart actions and live product values.
|
|
10
|
+
- `fetchProducts()`, `createCatalogLoader()`: products from the public catalog, server-side or batched in the browser, no API key needed.
|
|
11
|
+
|
|
12
|
+
MIT licensed.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { RequiplyConfig, RequiplyProduct } from './types.js';
|
|
2
|
+
type Fetch = typeof globalThis.fetch;
|
|
3
|
+
/**
|
|
4
|
+
* Reads products from the booking portal's public catalog (no API key needed), by slug or
|
|
5
|
+
* id, in one request per 100. Works on the server, e.g. in a React Server Component or a
|
|
6
|
+
* loader, to server-render products for search engines.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fetchProducts(config: RequiplyConfig, items: string[], fetcher?: Fetch): Promise<RequiplyProduct[]>;
|
|
9
|
+
/** The product a slug or id names among catalog results. */
|
|
10
|
+
export declare function findProduct(products: RequiplyProduct[], item: string): RequiplyProduct | null;
|
|
11
|
+
/**
|
|
12
|
+
* A product reader that batches every `load()` made in the same tick into one catalog
|
|
13
|
+
* request, so a grid of headless product cards costs one request.
|
|
14
|
+
*/
|
|
15
|
+
export declare function createCatalogLoader(config: RequiplyConfig, fetcher?: Fetch): {
|
|
16
|
+
load(item: string): Promise<RequiplyProduct | null>;
|
|
17
|
+
};
|
|
18
|
+
export type CatalogLoader = ReturnType<typeof createCatalogLoader>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjE,KAAK,KAAK,GAAG,OAAO,UAAU,CAAC,KAAK,CAAA;AAEpC;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,KAAwB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAgB1I;AAED,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAE7F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,GAAE,KAAwB;eAG9E,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;EActD;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { resolveConfig } from './script.js';
|
|
2
|
+
import { isProductId } from './runtime.js';
|
|
3
|
+
/** Slugs and ids per catalog request; the API takes up to 200. */
|
|
4
|
+
const CHUNK = 100;
|
|
5
|
+
/**
|
|
6
|
+
* Reads products from the booking portal's public catalog (no API key needed), by slug or
|
|
7
|
+
* id, in one request per 100. Works on the server, e.g. in a React Server Component or a
|
|
8
|
+
* loader, to server-render products for search engines.
|
|
9
|
+
*/
|
|
10
|
+
export async function fetchProducts(config, items, fetcher = globalThis.fetch) {
|
|
11
|
+
const { apiUrl, org } = resolveConfig(config);
|
|
12
|
+
const unique = [...new Set(items.filter(Boolean))];
|
|
13
|
+
const url = `${apiUrl}/api/portal/v1/orgs/${encodeURIComponent(org)}/catalog`;
|
|
14
|
+
const pages = await Promise.all(Array.from({ length: Math.ceil(unique.length / CHUNK) }, async (_, index) => {
|
|
15
|
+
const chunk = unique.slice(index * CHUNK, (index + 1) * CHUNK);
|
|
16
|
+
const query = new URLSearchParams({ includeSale: '1' });
|
|
17
|
+
const slugs = chunk.filter(item => !isProductId(item));
|
|
18
|
+
const ids = chunk.filter(isProductId);
|
|
19
|
+
if (slugs.length)
|
|
20
|
+
query.set('slugs', slugs.join(','));
|
|
21
|
+
if (ids.length)
|
|
22
|
+
query.set('ids', ids.join(','));
|
|
23
|
+
const response = await fetcher(`${url}?${query}`, { headers: { Accept: 'application/json' } });
|
|
24
|
+
if (!response.ok)
|
|
25
|
+
throw new Error(`[requiply] Catalog request failed with status ${response.status}`);
|
|
26
|
+
return (await response.json()).items;
|
|
27
|
+
}));
|
|
28
|
+
return pages.flat();
|
|
29
|
+
}
|
|
30
|
+
/** The product a slug or id names among catalog results. */
|
|
31
|
+
export function findProduct(products, item) {
|
|
32
|
+
return products.find(product => (isProductId(item) ? product.id : product.slug) === item) ?? null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A product reader that batches every `load()` made in the same tick into one catalog
|
|
36
|
+
* request, so a grid of headless product cards costs one request.
|
|
37
|
+
*/
|
|
38
|
+
export function createCatalogLoader(config, fetcher = globalThis.fetch) {
|
|
39
|
+
let pending = null;
|
|
40
|
+
return {
|
|
41
|
+
load(item) {
|
|
42
|
+
if (!item)
|
|
43
|
+
return Promise.resolve(null);
|
|
44
|
+
if (!pending) {
|
|
45
|
+
const batch = { items: new Set(), result: Promise.resolve([]) };
|
|
46
|
+
batch.result = Promise.resolve().then(() => {
|
|
47
|
+
pending = null;
|
|
48
|
+
return fetchProducts(config, [...batch.items], fetcher);
|
|
49
|
+
});
|
|
50
|
+
pending = batch;
|
|
51
|
+
}
|
|
52
|
+
pending.items.add(item);
|
|
53
|
+
return pending.result.then(products => findProduct(products, item));
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C,kEAAkE;AAClE,MAAM,KAAK,GAAG,GAAG,CAAA;AAIjB;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAsB,EAAE,KAAe,EAAE,UAAiB,UAAU,CAAC,KAAK;IAC5G,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7C,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;IAClD,MAA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,CAAC,CAAC,CAAA;QACrE,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The booking widget placeholders: an element with the widget's class and `data-*` options
|
|
3
|
+
* that the widget runtime fills in a shadow root. Framework packages render these.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PLACEHOLDERS: {
|
|
6
|
+
readonly bookButton: {
|
|
7
|
+
readonly className: "requiply-button";
|
|
8
|
+
readonly tag: "div";
|
|
9
|
+
};
|
|
10
|
+
readonly productCard: {
|
|
11
|
+
readonly className: "requiply-card";
|
|
12
|
+
readonly tag: "div";
|
|
13
|
+
};
|
|
14
|
+
readonly productList: {
|
|
15
|
+
readonly className: "requiply-list";
|
|
16
|
+
readonly tag: "div";
|
|
17
|
+
};
|
|
18
|
+
readonly priceTiers: {
|
|
19
|
+
readonly className: "requiply-tiers";
|
|
20
|
+
readonly tag: "div";
|
|
21
|
+
};
|
|
22
|
+
readonly bundle: {
|
|
23
|
+
readonly className: "requiply-bundle";
|
|
24
|
+
readonly tag: "div";
|
|
25
|
+
};
|
|
26
|
+
readonly datePicker: {
|
|
27
|
+
readonly className: "requiply-datepicker";
|
|
28
|
+
readonly tag: "div";
|
|
29
|
+
};
|
|
30
|
+
readonly cartButton: {
|
|
31
|
+
readonly className: "requiply-cart-button";
|
|
32
|
+
readonly tag: "span";
|
|
33
|
+
};
|
|
34
|
+
readonly portalButton: {
|
|
35
|
+
readonly className: "requiply-portal-button";
|
|
36
|
+
readonly tag: "span";
|
|
37
|
+
};
|
|
38
|
+
readonly accountLinks: {
|
|
39
|
+
readonly className: "requiply-account-links";
|
|
40
|
+
readonly tag: "span";
|
|
41
|
+
};
|
|
42
|
+
readonly callButton: {
|
|
43
|
+
readonly className: "requiply-call-button";
|
|
44
|
+
readonly tag: "span";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type PlaceholderKind = keyof typeof PLACEHOLDERS;
|
|
48
|
+
type Attrs = Record<string, string | number | boolean | null | undefined>;
|
|
49
|
+
/** `{ showSearch: 'true' }` → `{ 'data-show-search': 'true' }`, leaving out empty values. */
|
|
50
|
+
export declare function dataAttributes(attrs: Attrs): Record<string, string>;
|
|
51
|
+
/** Boolean-ish call option → the placeholder's `data-call` value. */
|
|
52
|
+
export declare function callAttr(call: boolean | 'off' | 'icon' | 'label' | undefined): string | undefined;
|
|
53
|
+
/** Props of each placeholder, as the framework components take them. */
|
|
54
|
+
export interface PlaceholderProps {
|
|
55
|
+
bookButton: {
|
|
56
|
+
item: string;
|
|
57
|
+
call?: boolean | 'off' | 'icon' | 'label';
|
|
58
|
+
};
|
|
59
|
+
productCard: {
|
|
60
|
+
item: string;
|
|
61
|
+
};
|
|
62
|
+
productList: {
|
|
63
|
+
category?: string;
|
|
64
|
+
limit?: number;
|
|
65
|
+
search?: string;
|
|
66
|
+
showSearch?: boolean;
|
|
67
|
+
kind?: 'rental' | 'sale' | 'all';
|
|
68
|
+
};
|
|
69
|
+
priceTiers: {
|
|
70
|
+
item: string;
|
|
71
|
+
};
|
|
72
|
+
bundle: {
|
|
73
|
+
bundle: string;
|
|
74
|
+
};
|
|
75
|
+
datePicker: Record<string, never>;
|
|
76
|
+
cartButton: {
|
|
77
|
+
label?: string;
|
|
78
|
+
};
|
|
79
|
+
portalButton: {
|
|
80
|
+
label?: string;
|
|
81
|
+
ghost?: boolean;
|
|
82
|
+
};
|
|
83
|
+
accountLinks: {
|
|
84
|
+
loginLabel?: string;
|
|
85
|
+
registerLabel?: string;
|
|
86
|
+
hideRegister?: boolean;
|
|
87
|
+
showName?: boolean;
|
|
88
|
+
};
|
|
89
|
+
callButton: {
|
|
90
|
+
label?: string;
|
|
91
|
+
iconOnly?: boolean;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** The `data-*` attributes of a placeholder for its props. */
|
|
95
|
+
export declare function placeholderAttributes<K extends PlaceholderKind>(kind: K, props: PlaceholderProps[K]): Record<string, string>;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=placeholders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholders.d.ts","sourceRoot":"","sources":["../src/placeholders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWf,CAAA;AAEV,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,YAAY,CAAA;AAEvD,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;AAEzE,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOnE;AAED,qEAAqE;AACrE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKjG;AAED,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE;QAAE,IAAI,EAAE,MAA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@@
|
|
|
1
|
+
/**
|
|
2
|
+
* The booking widget placeholders: an element with the widget's class and `data-*` options
|
|
3
|
+
* that the widget runtime fills in a shadow root. Framework packages render these.
|
|
4
|
+
*/
|
|
5
|
+
export const PLACEHOLDERS = {
|
|
6
|
+
bookButton: { className: 'requiply-button', tag: 'div' },
|
|
7
|
+
productCard: { className: 'requiply-card', tag: 'div' },
|
|
8
|
+
productList: { className: 'requiply-list', tag: 'div' },
|
|
9
|
+
priceTiers: { className: 'requiply-tiers', tag: 'div' },
|
|
10
|
+
bundle: { className: 'requiply-bundle', tag: 'div' },
|
|
11
|
+
datePicker: { className: 'requiply-datepicker', tag: 'div' },
|
|
12
|
+
cartButton: { className: 'requiply-cart-button', tag: 'span' },
|
|
13
|
+
portalButton: { className: 'requiply-portal-button', tag: 'span' },
|
|
14
|
+
accountLinks: { className: 'requiply-account-links', tag: 'span' },
|
|
15
|
+
callButton: { className: 'requiply-call-button', tag: 'span' },
|
|
16
|
+
};
|
|
17
|
+
/** `{ showSearch: 'true' }` → `{ 'data-show-search': 'true' }`, leaving out empty values. */
|
|
18
|
+
export function dataAttributes(attrs) {
|
|
19
|
+
const out = {};
|
|
20
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
21
|
+
if (value === undefined || value === null || value === '')
|
|
22
|
+
continue;
|
|
23
|
+
out[`data-${key.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)}`] = String(value);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
/** Boolean-ish call option → the placeholder's `data-call` value. */
|
|
28
|
+
export function callAttr(call) {
|
|
29
|
+
if (call === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (call === false)
|
|
32
|
+
return 'off';
|
|
33
|
+
if (call === true)
|
|
34
|
+
return 'icon';
|
|
35
|
+
return call;
|
|
36
|
+
}
|
|
37
|
+
/** The `data-*` attributes of a placeholder for its props. */
|
|
38
|
+
export function placeholderAttributes(kind, props) {
|
|
39
|
+
const p = props;
|
|
40
|
+
const flag = (value) => (value ? 'true' : undefined);
|
|
41
|
+
switch (kind) {
|
|
42
|
+
case 'bookButton': return dataAttributes({ item: p.item, call: callAttr(p.call) });
|
|
43
|
+
case 'productCard':
|
|
44
|
+
case 'priceTiers': return dataAttributes({ item: p.item });
|
|
45
|
+
case 'productList': return dataAttributes({ category: p.category, limit: p.limit, search: p.search, showSearch: flag(p.showSearch), kind: p.kind });
|
|
46
|
+
case 'bundle': return dataAttributes({ bundle: p.bundle });
|
|
47
|
+
case 'cartButton': return dataAttributes({ label: p.label });
|
|
48
|
+
case 'portalButton': return dataAttributes({ label: p.label, style: p.ghost ? 'ghost' : undefined });
|
|
49
|
+
case 'accountLinks': return dataAttributes({ loginLabel: p.loginLabel, registerLabel: p.registerLabel, hideRegister: flag(p.hideRegister), showName: flag(p.showName) });
|
|
50
|
+
case 'callButton': return dataAttributes({ label: p.label, style: p.iconOnly ? 'icon' : undefined });
|
|
51
|
+
default: return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=placeholders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholders.js","sourceRoot":"","sources":["../src/placeholders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,KAAK,EAAE;IACxD,WAAW,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE;IACvD,WAAW,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,EAAE,KAAK,EAAE;IACvD,UAAU,EAAE,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE;IACvD,MAAM,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,KAAK,EAAE;IACpD,UAAU,EAAE,EAAE,SAAS,EAAE,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IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;QAC5L,KAAK,YAAY,CAAC,CAAC,OAAO,cAAc,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAe,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAA;QAC9G,OAAO,CAAC,CAAC,OAAO,EAAE,CAAA;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { RequiplyCart, RequiplyProduct } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The parts of the widget runtime (`window.RequiplyEmbed.runtime`, served by the booking
|
|
4
|
+
* portal) the framework packages rely on. Kept narrow and checked before use, since the
|
|
5
|
+
* runtime is loaded from the portal and may be newer than these packages.
|
|
6
|
+
*/
|
|
7
|
+
export interface EmbedRuntime {
|
|
8
|
+
cart: {
|
|
9
|
+
items: Array<{
|
|
10
|
+
groupId: string;
|
|
11
|
+
quantity: number;
|
|
12
|
+
}>;
|
|
13
|
+
bundles: Array<{
|
|
14
|
+
bundleId: string;
|
|
15
|
+
quantity: number;
|
|
16
|
+
choices?: string[];
|
|
17
|
+
}>;
|
|
18
|
+
saleLines: Array<{
|
|
19
|
+
groupId: string;
|
|
20
|
+
quantity: number;
|
|
21
|
+
}>;
|
|
22
|
+
startDate: string | null;
|
|
23
|
+
endDate: string | null;
|
|
24
|
+
};
|
|
25
|
+
readonly count: number;
|
|
26
|
+
readonly selectedServiceIds: string[];
|
|
27
|
+
readonly hasDates: boolean;
|
|
28
|
+
readonly ui: {
|
|
29
|
+
openCart: (() => void) | null;
|
|
30
|
+
openDatePicker: (() => void) | null;
|
|
31
|
+
openCall: (() => void) | null;
|
|
32
|
+
};
|
|
33
|
+
subscribe(listener: () => void): () => void;
|
|
34
|
+
item(slug: string): RequiplyProduct | null;
|
|
35
|
+
itemById(id: string): RequiplyProduct | null;
|
|
36
|
+
maxQuantity(groupId: string): number | null;
|
|
37
|
+
price(amount: number): string;
|
|
38
|
+
loadBySlugs(slugs: string[]): Promise<void>;
|
|
39
|
+
readCatalog(params: {
|
|
40
|
+
ids?: string[];
|
|
41
|
+
includeSale?: boolean;
|
|
42
|
+
}): Promise<unknown[]>;
|
|
43
|
+
requestAdd(groupId: string, quantity?: number): void;
|
|
44
|
+
setQuantity(groupId: string, quantity: number): void;
|
|
45
|
+
remove(groupId: string): void;
|
|
46
|
+
clear(): void;
|
|
47
|
+
setDates(startDate: string | null, endDate: string | null): void;
|
|
48
|
+
openPortal(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** Whether a product reference is an id rather than a slug. */
|
|
51
|
+
export declare function isProductId(item: string): boolean;
|
|
52
|
+
/** The widget runtime once it has booted, else null (always null on the server). */
|
|
53
|
+
export declare function embedRuntime(): EmbedRuntime | null;
|
|
54
|
+
/** Asks the widget runtime to mount placeholders added since its last look. */
|
|
55
|
+
export declare function rescanEmbed(): void;
|
|
56
|
+
/** Resolves with the widget runtime once it has booted. Never resolves on the server. */
|
|
57
|
+
export declare function whenEmbedReady(): Promise<EmbedRuntime>;
|
|
58
|
+
/** An empty cart, the state before the widgets boot and on the server. */
|
|
59
|
+
export declare function emptyCart(): RequiplyCart;
|
|
60
|
+
/** A plain copy of the runtime's cart, safe to keep in framework state. */
|
|
61
|
+
export declare function cartSnapshot(runtime: EmbedRuntime): RequiplyCart;
|
|
62
|
+
/** What the widgets' state looks like to a framework: whether they loaded, the cart, and a change counter. */
|
|
63
|
+
export interface EmbedSnapshot {
|
|
64
|
+
ready: boolean;
|
|
65
|
+
cart: RequiplyCart;
|
|
66
|
+
/** Grows on every runtime change (cart, dates, products loaded); read it to recompute runtime-derived values. */
|
|
67
|
+
version: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Subscribes to the widgets' state, the shape React's `useSyncExternalStore` expects. The
|
|
71
|
+
* first subscriber starts watching the runtime; until it boots the snapshot is the server one.
|
|
72
|
+
*/
|
|
73
|
+
export declare function subscribeEmbed(listener: () => void): () => void;
|
|
74
|
+
/** The current widget state; the same object until something changes. */
|
|
75
|
+
export declare function getEmbedSnapshot(): EmbedSnapshot;
|
|
76
|
+
/** The state the server renders and hydration starts from: not ready, empty cart. */
|
|
77
|
+
export declare function getServerEmbedSnapshot(): EmbedSnapshot;
|
|
78
|
+
/**
|
|
79
|
+
* Loads products into the runtime by slug, batching every call made in the same tick into
|
|
80
|
+
* one catalog request, as the runtime does for the placeholders of a page.
|
|
81
|
+
*/
|
|
82
|
+
export declare function loadSlugs(runtime: EmbedRuntime, slugs: string[]): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Adds a product by slug or id like "Add to booking": asks for dates first when the
|
|
85
|
+
* organization starts bookings from dates, then opens the cart.
|
|
86
|
+
* @returns False when the widgets have not loaded or the product is unknown or hidden.
|
|
87
|
+
*/
|
|
88
|
+
export declare function addToCart(item: string, quantity?: number): Promise<boolean>;
|
|
89
|
+
/** The live values of a product once the widgets loaded, for headless product UIs. */
|
|
90
|
+
export interface ProductLiveState {
|
|
91
|
+
/** The widgets' copy of the product, with availability for the chosen dates; null until loaded. */
|
|
92
|
+
live: RequiplyProduct | null;
|
|
93
|
+
/** Base price formatted in the organization's currency and the widget language. */
|
|
94
|
+
price: string | null;
|
|
95
|
+
/** Units that can still be booked; null when unknown or unlimited. */
|
|
96
|
+
available: number | null;
|
|
97
|
+
hasDates: boolean;
|
|
98
|
+
/** True when the dates are chosen (or it is for sale) and none is free. */
|
|
99
|
+
soldOut: boolean;
|
|
100
|
+
/** Units of the product in the cart. */
|
|
101
|
+
inCart: number;
|
|
102
|
+
}
|
|
103
|
+
/** Computes a product's live state from the runtime and a cart snapshot. */
|
|
104
|
+
export declare function productLiveState(item: string, fallback: RequiplyProduct | null, state: EmbedSnapshot): ProductLiveState;
|
|
105
|
+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product reference is an id rather than a slug. */
|
|
3
|
+
export function isProductId(item) {
|
|
4
|
+
return UUID.test(item);
|
|
5
|
+
}
|
|
6
|
+
function embedGlobal() {
|
|
7
|
+
if (typeof window === 'undefined')
|
|
8
|
+
return undefined;
|
|
9
|
+
return window.RequiplyEmbed;
|
|
10
|
+
}
|
|
11
|
+
/** The widget runtime once it has booted, else null (always null on the server). */
|
|
12
|
+
export function embedRuntime() {
|
|
13
|
+
return embedGlobal()?.runtime ?? null;
|
|
14
|
+
}
|
|
15
|
+
/** Asks the widget runtime to mount placeholders added since its last look. */
|
|
16
|
+
export function rescanEmbed() {
|
|
17
|
+
embedGlobal()?.scan?.();
|
|
18
|
+
}
|
|
19
|
+
/** Resolves with the widget runtime once it has booted. Never resolves on the server. */
|
|
20
|
+
export function whenEmbedReady() {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
const runtime = embedRuntime();
|
|
23
|
+
if (runtime)
|
|
24
|
+
return resolve(runtime);
|
|
25
|
+
if (typeof document === 'undefined')
|
|
26
|
+
return;
|
|
27
|
+
document.addEventListener('requiply:ready', () => {
|
|
28
|
+
const booted = embedRuntime();
|
|
29
|
+
if (booted)
|
|
30
|
+
resolve(booted);
|
|
31
|
+
}, { once: true });
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** An empty cart, the state before the widgets boot and on the server. */
|
|
35
|
+
export function emptyCart() {
|
|
36
|
+
return { items: [], bundles: [], saleLines: [], serviceIds: [], startDate: null, endDate: null, count: 0 };
|
|
37
|
+
}
|
|
38
|
+
/** A plain copy of the runtime's cart, safe to keep in framework state. */
|
|
39
|
+
export function cartSnapshot(runtime) {
|
|
40
|
+
const { cart } = runtime;
|
|
41
|
+
return {
|
|
42
|
+
items: cart.items.map(line => ({ groupId: line.groupId, quantity: line.quantity })),
|
|
43
|
+
bundles: cart.bundles.map(line => ({
|
|
44
|
+
bundleId: line.bundleId,
|
|
45
|
+
quantity: line.quantity,
|
|
46
|
+
...(line.choices ? { choices: [...line.choices] } : {}),
|
|
47
|
+
})),
|
|
48
|
+
saleLines: cart.saleLines.map(line => ({ saleItemId: line.groupId, quantity: line.quantity })),
|
|
49
|
+
serviceIds: [...(runtime.selectedServiceIds ?? [])],
|
|
50
|
+
startDate: cart.startDate,
|
|
51
|
+
endDate: cart.endDate,
|
|
52
|
+
count: runtime.count,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const SERVER_SNAPSHOT = Object.freeze({ ready: false, cart: Object.freeze(emptyCart()), version: 0 });
|
|
56
|
+
let snapshot = SERVER_SNAPSHOT;
|
|
57
|
+
const listeners = new Set();
|
|
58
|
+
let watching = false;
|
|
59
|
+
function publish(runtime) {
|
|
60
|
+
snapshot = { ready: true, cart: cartSnapshot(runtime), version: snapshot.version + 1 };
|
|
61
|
+
for (const listener of listeners)
|
|
62
|
+
listener();
|
|
63
|
+
}
|
|
64
|
+
function watchRuntime() {
|
|
65
|
+
if (watching || typeof window === 'undefined')
|
|
66
|
+
return;
|
|
67
|
+
watching = true;
|
|
68
|
+
const attach = (runtime) => {
|
|
69
|
+
runtime.subscribe(() => publish(runtime));
|
|
70
|
+
publish(runtime);
|
|
71
|
+
};
|
|
72
|
+
const booted = embedRuntime();
|
|
73
|
+
if (booted)
|
|
74
|
+
return attach(booted);
|
|
75
|
+
document.addEventListener('requiply:ready', () => {
|
|
76
|
+
const runtime = embedRuntime();
|
|
77
|
+
if (runtime)
|
|
78
|
+
attach(runtime);
|
|
79
|
+
}, { once: true });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Subscribes to the widgets' state, the shape React's `useSyncExternalStore` expects. The
|
|
83
|
+
* first subscriber starts watching the runtime; until it boots the snapshot is the server one.
|
|
84
|
+
*/
|
|
85
|
+
export function subscribeEmbed(listener) {
|
|
86
|
+
listeners.add(listener);
|
|
87
|
+
watchRuntime();
|
|
88
|
+
return () => {
|
|
89
|
+
listeners.delete(listener);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The current widget state; the same object until something changes. */
|
|
93
|
+
export function getEmbedSnapshot() {
|
|
94
|
+
return snapshot;
|
|
95
|
+
}
|
|
96
|
+
/** The state the server renders and hydration starts from: not ready, empty cart. */
|
|
97
|
+
export function getServerEmbedSnapshot() {
|
|
98
|
+
return SERVER_SNAPSHOT;
|
|
99
|
+
}
|
|
100
|
+
const pendingSlugs = new Set();
|
|
101
|
+
let flushing = null;
|
|
102
|
+
/**
|
|
103
|
+
* Loads products into the runtime by slug, batching every call made in the same tick into
|
|
104
|
+
* one catalog request, as the runtime does for the placeholders of a page.
|
|
105
|
+
*/
|
|
106
|
+
export function loadSlugs(runtime, slugs) {
|
|
107
|
+
for (const slug of slugs)
|
|
108
|
+
if (slug)
|
|
109
|
+
pendingSlugs.add(slug);
|
|
110
|
+
flushing ??= Promise.resolve().then(async () => {
|
|
111
|
+
const batch = [...pendingSlugs];
|
|
112
|
+
pendingSlugs.clear();
|
|
113
|
+
flushing = null;
|
|
114
|
+
if (batch.length)
|
|
115
|
+
await runtime.loadBySlugs(batch);
|
|
116
|
+
});
|
|
117
|
+
return flushing;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adds a product by slug or id like "Add to booking": asks for dates first when the
|
|
121
|
+
* organization starts bookings from dates, then opens the cart.
|
|
122
|
+
* @returns False when the widgets have not loaded or the product is unknown or hidden.
|
|
123
|
+
*/
|
|
124
|
+
export async function addToCart(item, quantity = 1) {
|
|
125
|
+
const runtime = embedRuntime();
|
|
126
|
+
if (!runtime || !item)
|
|
127
|
+
return false;
|
|
128
|
+
let product = runtime.itemById(item) ?? runtime.item(item);
|
|
129
|
+
if (!product && !isProductId(item)) {
|
|
130
|
+
await runtime.loadBySlugs([item]);
|
|
131
|
+
product = runtime.item(item);
|
|
132
|
+
}
|
|
133
|
+
if (!product && isProductId(item)) {
|
|
134
|
+
await runtime.readCatalog({ ids: [item], includeSale: true });
|
|
135
|
+
product = runtime.itemById(item);
|
|
136
|
+
}
|
|
137
|
+
if (!product)
|
|
138
|
+
return false;
|
|
139
|
+
runtime.requestAdd(product.id, quantity);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/** Computes a product's live state from the runtime and a cart snapshot. */
|
|
143
|
+
export function productLiveState(item, fallback, state) {
|
|
144
|
+
const runtime = state.ready ? embedRuntime() : null;
|
|
145
|
+
const live = runtime && item ? (isProductId(item) ? runtime.itemById(item) : runtime.item(item)) : null;
|
|
146
|
+
const product = live ?? fallback;
|
|
147
|
+
const hasDates = Boolean(state.cart.startDate && state.cart.endDate);
|
|
148
|
+
const available = live && runtime ? runtime.maxQuantity(live.id) : null;
|
|
149
|
+
const id = product?.id;
|
|
150
|
+
const inCart = id
|
|
151
|
+
? state.cart.items.find(line => line.groupId === id)?.quantity
|
|
152
|
+
?? state.cart.saleLines.find(line => line.saleItemId === id)?.quantity
|
|
153
|
+
?? 0
|
|
154
|
+
: 0;
|
|
155
|
+
return {
|
|
156
|
+
live,
|
|
157
|
+
price: runtime && product ? runtime.price(product.price) : null,
|
|
158
|
+
available,
|
|
159
|
+
hasDates,
|
|
160
|
+
soldOut: (product?.kind === 'sale' || hasDates) && available === 0,
|
|
161
|
+
inCart,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AA2CA,MAAM,IAAI,GAAG,iEAAiE,CAAA;AAE9E,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,WAAW;IAClB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,SAAS,CAAA;IACnD,OAAQ,MAAqD,CAAC,aAAa,CAAA;AAC7E,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,YAA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OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/D,SAAS;QACT,QAAQ;QACR,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,SAAS,KAAK,CAAC;QAClE,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/dist/script.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RequiplyConfig, RequiplyEmbedOptions, RequiplyTheme } from './types.js';
|
|
2
|
+
export declare const DEFAULT_API_URL = "https://api.requiply.com";
|
|
3
|
+
export declare const DEFAULT_PORTAL_URL = "https://portal.requiply.com";
|
|
4
|
+
/** The config with its addresses filled in and trailing slashes removed. */
|
|
5
|
+
export declare function resolveConfig(config: RequiplyConfig): Required<RequiplyConfig>;
|
|
6
|
+
/** The script URL of the widget runtime. */
|
|
7
|
+
export declare function embedScriptUrl(config: RequiplyConfig, embed?: RequiplyEmbedOptions): string;
|
|
8
|
+
/**
|
|
9
|
+
* The `data-*` attributes the widget runtime reads from its script tag. Only options that
|
|
10
|
+
* were set are written, so the organization's own settings apply to the rest. Framework
|
|
11
|
+
* packages get a calendar on the cart ("your booking" is a period) and a plus on "Add to
|
|
12
|
+
* booking"; the runtime's own default is a cart on both.
|
|
13
|
+
*/
|
|
14
|
+
export declare function embedScriptAttributes(config: RequiplyConfig, embed?: RequiplyEmbedOptions): Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* The theme as a `:root` rule of `--rq-*` variables, or null without tokens. Values are
|
|
17
|
+
* written as given; characters that could end the rule are dropped.
|
|
18
|
+
*/
|
|
19
|
+
export declare function themeCss(theme: RequiplyTheme | undefined): string | null;
|
|
20
|
+
/** Whether a key is a secret one (`rq_sk_`), which must never reach a browser. */
|
|
21
|
+
export declare function isSecretKeyLike(key: string | undefined | null): boolean;
|
|
22
|
+
//# sourceMappingURL=script.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../src/script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAErF,eAAO,MAAM,eAAe,6BAA6B,CAAA;AACzD,eAAO,MAAM,kBAAkB,gCAAgC,CAAA;AAE/D,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,CAM9E;AAED,4CAA4C;AAC5C,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,GAAE,oBAAyB,GAAG,MAAM,CAE/F;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,GAAE,oBAAyB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BtH;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAKxE;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,OAAO,CAEvE"}
|
package/dist/script.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const DEFAULT_API_URL = 'https://api.requiply.com';
|
|
2
|
+
export const DEFAULT_PORTAL_URL = 'https://portal.requiply.com';
|
|
3
|
+
/** The config with its addresses filled in and trailing slashes removed. */
|
|
4
|
+
export function resolveConfig(config) {
|
|
5
|
+
return {
|
|
6
|
+
org: config.org,
|
|
7
|
+
apiUrl: (config.apiUrl || DEFAULT_API_URL).replace(/\/+$/, ''),
|
|
8
|
+
portalUrl: (config.portalUrl || DEFAULT_PORTAL_URL).replace(/\/+$/, ''),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** The script URL of the widget runtime. */
|
|
12
|
+
export function embedScriptUrl(config, embed = {}) {
|
|
13
|
+
return embed.scriptUrl || `${resolveConfig(config).portalUrl}/embed/v1/requiply-embed.js`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The `data-*` attributes the widget runtime reads from its script tag. Only options that
|
|
17
|
+
* were set are written, so the organization's own settings apply to the rest. Framework
|
|
18
|
+
* packages get a calendar on the cart ("your booking" is a period) and a plus on "Add to
|
|
19
|
+
* booking"; the runtime's own default is a cart on both.
|
|
20
|
+
*/
|
|
21
|
+
export function embedScriptAttributes(config, embed = {}) {
|
|
22
|
+
const { org, apiUrl, portalUrl } = resolveConfig(config);
|
|
23
|
+
const attrs = {
|
|
24
|
+
'data-org': org,
|
|
25
|
+
'data-portal': portalUrl,
|
|
26
|
+
'data-api': apiUrl,
|
|
27
|
+
'data-locale': embed.locale,
|
|
28
|
+
'data-color': embed.color,
|
|
29
|
+
'data-corners': embed.corners,
|
|
30
|
+
'data-return-url': embed.returnUrl,
|
|
31
|
+
'data-site-url': embed.siteUrl,
|
|
32
|
+
'data-cart': embed.floatingCart === undefined ? undefined : String(embed.floatingCart),
|
|
33
|
+
'data-cart-position': embed.cartPosition,
|
|
34
|
+
'data-currency-display': embed.currencyDisplay,
|
|
35
|
+
'data-start-from': embed.startFrom,
|
|
36
|
+
'data-phones': embed.phones?.length ? JSON.stringify(embed.phones) : undefined,
|
|
37
|
+
'data-call': embed.callButton,
|
|
38
|
+
'data-call-float': embed.callFloating,
|
|
39
|
+
'data-call-note': embed.callNote,
|
|
40
|
+
'data-call-hours': embed.callHours === undefined ? undefined : String(embed.callHours),
|
|
41
|
+
'data-cart-icon': embed.cartIcon ?? 'calendar',
|
|
42
|
+
'data-button-icon': embed.buttonIcon ?? 'plus',
|
|
43
|
+
'data-icon-style': embed.iconStyle,
|
|
44
|
+
'data-messages': embed.messages && Object.keys(embed.messages).length ? JSON.stringify(embed.messages) : undefined,
|
|
45
|
+
'data-css': embed.css?.trim() || undefined,
|
|
46
|
+
};
|
|
47
|
+
return Object.fromEntries(Object.entries(attrs).filter((entry) => typeof entry[1] === 'string' && entry[1] !== ''));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The theme as a `:root` rule of `--rq-*` variables, or null without tokens. Values are
|
|
51
|
+
* written as given; characters that could end the rule are dropped.
|
|
52
|
+
*/
|
|
53
|
+
export function themeCss(theme) {
|
|
54
|
+
const declarations = Object.entries(theme ?? {})
|
|
55
|
+
.filter((entry) => typeof entry[1] === 'string' && entry[1].trim() !== '')
|
|
56
|
+
.map(([token, value]) => `--rq-${token.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`).replace(/[^a-z0-9-]/g, '')}: ${value.replace(/[;{}<>]/g, '').trim()};`);
|
|
57
|
+
return declarations.length ? `:root { ${declarations.join(' ')} }` : null;
|
|
58
|
+
}
|
|
59
|
+
/** Whether a key is a secret one (`rq_sk_`), which must never reach a browser. */
|
|
60
|
+
export function isSecretKeyLike(key) {
|
|
61
|
+
return typeof key === 'string' && key.startsWith('rq_sk_');
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"script.js","sourceRoot":"","sources":["../src/script.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAG,6BAA6B,CAAA;AAE/D,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAAC,MAAsB;IAClD,OAAO;QACL,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;QAC9D,SAAS,EAAE,CAAC,MAAM,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;KACxE,CA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,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IACxK,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AAC3E,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,GAA8B;IAC5D,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;AAC5D,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** A phone number the call buttons offer, with an optional caption such as a department. */
|
|
2
|
+
export interface RequiplyPhone {
|
|
3
|
+
number: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
}
|
|
6
|
+
/** The icon on the cart and booking buttons. `plus` only suits booking buttons. */
|
|
7
|
+
export type RequiplyButtonIcon = 'cart' | 'calendar' | 'truck' | 'plus' | 'none';
|
|
8
|
+
/**
|
|
9
|
+
* Design tokens of the booking widgets, written to `:root` as `--rq-*` CSS variables
|
|
10
|
+
* (`surface` becomes `--rq-surface`). Any CSS value works; leave a token out to keep the
|
|
11
|
+
* default. Setting them in your own CSS works just as well.
|
|
12
|
+
*/
|
|
13
|
+
export interface RequiplyTheme {
|
|
14
|
+
/** Buttons, links, the selected state. A hex color also derives `onPrimary`, `link` and the shade ramp. */
|
|
15
|
+
primary?: string;
|
|
16
|
+
/** Text on `primary`. */
|
|
17
|
+
onPrimary?: string;
|
|
18
|
+
/** Links and outlined buttons. */
|
|
19
|
+
link?: string;
|
|
20
|
+
/** Font family; defaults to the page's body font. */
|
|
21
|
+
font?: string;
|
|
22
|
+
/** Base font size, e.g. `15px`. */
|
|
23
|
+
fontSize?: string;
|
|
24
|
+
/** Text color. */
|
|
25
|
+
text?: string;
|
|
26
|
+
/** Card, drawer, dialog and field backgrounds. */
|
|
27
|
+
surface?: string;
|
|
28
|
+
/** Image placeholders and quiet panels. */
|
|
29
|
+
mutedBg?: string;
|
|
30
|
+
/** Card and divider borders. */
|
|
31
|
+
border?: string;
|
|
32
|
+
/** Field and quantity stepper borders. */
|
|
33
|
+
inputBorder?: string;
|
|
34
|
+
/** Height of buttons, fields and steppers, e.g. `48px`. */
|
|
35
|
+
controlHeight?: string;
|
|
36
|
+
radiusCard?: string;
|
|
37
|
+
radiusControl?: string;
|
|
38
|
+
radiusPill?: string;
|
|
39
|
+
radiusImage?: string;
|
|
40
|
+
/** "Available", savings. */
|
|
41
|
+
success?: string;
|
|
42
|
+
successBg?: string;
|
|
43
|
+
/** "Not available", errors. */
|
|
44
|
+
danger?: string;
|
|
45
|
+
/** Chosen days and times in the date picker. */
|
|
46
|
+
range?: string;
|
|
47
|
+
rangeSoft?: string;
|
|
48
|
+
onRange?: string;
|
|
49
|
+
/** Backdrop behind the cart and dialogs. */
|
|
50
|
+
overlay?: string;
|
|
51
|
+
/** Any other `--rq-*` variable, by its name without the prefix. */
|
|
52
|
+
[token: string]: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Texts of the widgets to replace, by key: `{ add: 'Rent' }` for every language, or per
|
|
56
|
+
* language code: `{ uk: { add: 'Орендувати' } }`. Keys are the widget string keys, e.g.
|
|
57
|
+
* `add`, `inCart`, `chooseDates`, `checkAvailability`, `availableCount` (`{n} available`).
|
|
58
|
+
*/
|
|
59
|
+
export type RequiplyMessages = Record<string, string | Record<string, string>>;
|
|
60
|
+
/**
|
|
61
|
+
* How the Requiply booking widgets look and behave. Every option is optional: the widgets
|
|
62
|
+
* take the organization's color, corner style, language and currency from Requiply.
|
|
63
|
+
*/
|
|
64
|
+
export interface RequiplyEmbedOptions {
|
|
65
|
+
/** Language of the widgets, e.g. `en` or `uk`. Defaults to the page's `<html lang>`, then the organization's language. */
|
|
66
|
+
locale?: string;
|
|
67
|
+
/** Brand color as a hex value; defaults to the booking page color set in Requiply. */
|
|
68
|
+
color?: string;
|
|
69
|
+
/** Corner style of buttons and cards; defaults to the booking page setting. */
|
|
70
|
+
corners?: 'sharp' | 'soft' | 'rounded';
|
|
71
|
+
/** Shows the floating cart button in a page corner. Off automatically on pages with a `<RequiplyCartButton>`. Default `true`. */
|
|
72
|
+
floatingCart?: boolean;
|
|
73
|
+
/** Page corner of the floating cart. Default `right`. */
|
|
74
|
+
cartPosition?: 'right' | 'left';
|
|
75
|
+
/** Prices with a currency symbol (`₴ 500`) or code (`UAH 500`). Default `symbol`. */
|
|
76
|
+
currencyDisplay?: 'symbol' | 'code';
|
|
77
|
+
/** Whether visitors pick products or dates first; defaults to the organization's booking setting. */
|
|
78
|
+
startFrom?: 'items' | 'dates';
|
|
79
|
+
/** Where the portal's confirmation page sends visitors back to. Defaults to the page they booked from. */
|
|
80
|
+
returnUrl?: string;
|
|
81
|
+
/** The website home the portal header logo leads back to. Defaults to the site origin. */
|
|
82
|
+
siteUrl?: string;
|
|
83
|
+
/** Numbers for the call buttons; the organization's phone when empty. */
|
|
84
|
+
phones?: Array<string | RequiplyPhone>;
|
|
85
|
+
/** Call button next to "Add to booking": hidden, an icon, or icon and "Call". Default `off`. */
|
|
86
|
+
callButton?: 'off' | 'icon' | 'label';
|
|
87
|
+
/** Floating call button: nowhere, on phones and tablets, or on every screen. Default `off`. */
|
|
88
|
+
callFloating?: 'off' | 'mobile' | 'all';
|
|
89
|
+
/** Text in the call window, such as a note that calls are recorded. */
|
|
90
|
+
callNote?: string;
|
|
91
|
+
/** Whether the call window lists working hours. Default `true`. */
|
|
92
|
+
callHours?: boolean;
|
|
93
|
+
/** Icon of the floating cart and `<RequiplyCartButton>`. Default `calendar`. */
|
|
94
|
+
cartIcon?: RequiplyButtonIcon;
|
|
95
|
+
/** Icon of "Add to booking" on buttons and cards. Default `plus`. */
|
|
96
|
+
buttonIcon?: RequiplyButtonIcon;
|
|
97
|
+
/** Line or solid icons. Default `outline`. */
|
|
98
|
+
iconStyle?: 'outline' | 'filled';
|
|
99
|
+
/** Design tokens, see {@link RequiplyTheme}. */
|
|
100
|
+
theme?: RequiplyTheme;
|
|
101
|
+
/** Replacement texts, see {@link RequiplyMessages}. */
|
|
102
|
+
messages?: RequiplyMessages;
|
|
103
|
+
/**
|
|
104
|
+
* CSS added inside every widget after its own styles, the cart and dialogs included.
|
|
105
|
+
* Elements carry `rq-` classes (`.rq-btn`, `.rq-card__name`, `.rq-drawer`); for styling
|
|
106
|
+
* from your own stylesheet use their parts instead: `.requiply-button::part(btn)`.
|
|
107
|
+
*/
|
|
108
|
+
css?: string;
|
|
109
|
+
/** Loads the widget runtime from another address, e.g. a self-hosted copy. Defaults to `<portalUrl>/embed/v1/requiply-embed.js`. */
|
|
110
|
+
scriptUrl?: string;
|
|
111
|
+
}
|
|
112
|
+
/** Where a site's widgets and catalog reads go: the organization and the Requiply addresses. */
|
|
113
|
+
export interface RequiplyConfig {
|
|
114
|
+
/** The organization code: the end of the booking page address (`portal.requiply.com/<org>`). */
|
|
115
|
+
org: string;
|
|
116
|
+
/** Requiply API address. Default `https://api.requiply.com`. */
|
|
117
|
+
apiUrl?: string;
|
|
118
|
+
/** Booking portal address, where the widget runtime loads from. Default `https://portal.requiply.com`. */
|
|
119
|
+
portalUrl?: string;
|
|
120
|
+
}
|
|
121
|
+
/** A product as the booking portal's catalog describes it. */
|
|
122
|
+
export interface RequiplyProduct {
|
|
123
|
+
id: string;
|
|
124
|
+
name: string;
|
|
125
|
+
sku: string;
|
|
126
|
+
/** The name the product goes by on websites. */
|
|
127
|
+
slug: string | null;
|
|
128
|
+
/** `rental` for equipment booked for a period, `sale` for products the customer buys. */
|
|
129
|
+
kind: 'rental' | 'sale';
|
|
130
|
+
/** Base price per `priceType` unit (flat for products for sale). */
|
|
131
|
+
price: number;
|
|
132
|
+
priceType: 'day' | 'hour' | 'month' | 'quote';
|
|
133
|
+
depositAmount: number | null;
|
|
134
|
+
description: string | null;
|
|
135
|
+
categoryId: string | null;
|
|
136
|
+
categoryName: string | null;
|
|
137
|
+
imageUrl: string | null;
|
|
138
|
+
images: string[];
|
|
139
|
+
/** Units the business can supply. */
|
|
140
|
+
totalQuantity: number;
|
|
141
|
+
/** Units free for the chosen dates; null before dates are chosen. */
|
|
142
|
+
availableQuantity: number | null;
|
|
143
|
+
/** A partner product with no cap: any quantity can be booked; do not show the counts. */
|
|
144
|
+
unlimited?: boolean;
|
|
145
|
+
/** Discounts by rental length: from `fromUnit` units on, `amount` percent of the base price (90 is 10% off). */
|
|
146
|
+
pricingTiers: Array<{
|
|
147
|
+
fromUnit: number;
|
|
148
|
+
toUnit: number | null;
|
|
149
|
+
amount: number;
|
|
150
|
+
}>;
|
|
151
|
+
/** Filterable product properties. */
|
|
152
|
+
properties: Array<{
|
|
153
|
+
key: string;
|
|
154
|
+
name: string;
|
|
155
|
+
type: string;
|
|
156
|
+
value: string | number | boolean | string[];
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
159
|
+
/** A rental product in the cart. */
|
|
160
|
+
export interface RequiplyCartLine {
|
|
161
|
+
/** The product (item group) id. */
|
|
162
|
+
groupId: string;
|
|
163
|
+
quantity: number;
|
|
164
|
+
}
|
|
165
|
+
/** A kit in the cart with the parts chosen for its choice groups. */
|
|
166
|
+
export interface RequiplyCartBundle {
|
|
167
|
+
bundleId: string;
|
|
168
|
+
quantity: number;
|
|
169
|
+
choices?: string[];
|
|
170
|
+
}
|
|
171
|
+
/** The visitor's cart as the booking widgets hold it. */
|
|
172
|
+
export interface RequiplyCart {
|
|
173
|
+
items: RequiplyCartLine[];
|
|
174
|
+
bundles: RequiplyCartBundle[];
|
|
175
|
+
/** Products for sale, which need no dates. */
|
|
176
|
+
saleLines: Array<{
|
|
177
|
+
saleItemId: string;
|
|
178
|
+
quantity: number;
|
|
179
|
+
}>;
|
|
180
|
+
/** Add-on services the visitor selected. */
|
|
181
|
+
serviceIds: string[];
|
|
182
|
+
/** Rental start, ISO date-time in the organization's time zone, or null before dates are chosen. */
|
|
183
|
+
startDate: string | null;
|
|
184
|
+
endDate: string | null;
|
|
185
|
+
/** Number of units in the cart. */
|
|
186
|
+
count: number;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,mFAAmF;AACnF,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;AAEhF;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,2GAA2G;IAC3G,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAA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AAG,IAAI,CAAA;IACxB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAA;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requiply/embed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Framework-agnostic core of the Requiply booking widgets: script options, theme tokens, placeholders, the cart store and catalog reads, shared by @requiply/react and @requiply/nuxt",
|
|
5
|
+
"author": "Andrian Zafiiovskiy <andrian.zafiiovskiy@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://requiply.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Requiply/RequiplyNPM.git",
|
|
11
|
+
"directory": "packages/embed"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Requiply/RequiplyNPM/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.json",
|
|
33
|
+
"prepack": "npm run build",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"requiply",
|
|
38
|
+
"rental",
|
|
39
|
+
"rental booking",
|
|
40
|
+
"booking widget",
|
|
41
|
+
"equipment rental"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"jsdom": "^31.0.1",
|
|
48
|
+
"typescript": "^5.9.3",
|
|
49
|
+
"vitest": "^5.1.2"
|
|
50
|
+
}
|
|
51
|
+
}
|