@swift-food-services/catering-widget 0.1.0-beta.6 → 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 +40 -24
- package/dist/index.cjs +7104 -409
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.mjs +7106 -411
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +2 -2
- package/package.json +13 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arnav Vaish
|
|
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
|
@@ -10,7 +10,6 @@ npm install @swift-food-services/catering-widget
|
|
|
10
10
|
|
|
11
11
|
```tsx
|
|
12
12
|
import { CateringWidget } from "@swift-food-services/catering-widget";
|
|
13
|
-
import "@swift-food-services/catering-widget/dist/styles.css";
|
|
14
13
|
|
|
15
14
|
export default function CateringPage() {
|
|
16
15
|
return (
|
|
@@ -33,16 +32,16 @@ Defaults: Swift-hosted backend, `localStorage` persistence, neutral theme.
|
|
|
33
32
|
|
|
34
33
|
- React 18+ and React-DOM 18+ as peer dependencies
|
|
35
34
|
- A publishable key from Swift (see [Getting a publishable key](#getting-a-publishable-key))
|
|
36
|
-
- At least one origin registered with Swift where the widget will load
|
|
37
35
|
|
|
38
36
|
## Props
|
|
39
37
|
|
|
40
38
|
| Prop | Type | Required | Description |
|
|
41
39
|
|---|---|---|---|
|
|
42
|
-
| `publishableKey` | `string` | yes | Your `pk_live_...`
|
|
40
|
+
| `publishableKey` | `string` | yes | Your `pk_live_...` key from Swift. |
|
|
43
41
|
| `googleMapsApiKey` | `string` | yes | Google Maps JavaScript API key with the Places library enabled. Used by the address-autocomplete field. |
|
|
44
42
|
| `theme` | `Theme` | no | Primary color, border radius, and font overrides. |
|
|
45
|
-
| `initialData` | `InitialData` | no | Pre-populate event, address, and contact fields.
|
|
43
|
+
| `initialData` | `InitialData` | no | Pre-populate event window, address, and contact fields. Re-applied when its fingerprint changes between mounts; preserved on reload. See [Pre-filling known event details](#pre-filling-known-event-details). |
|
|
44
|
+
| `allowedCateringTimes` | `AllowedCateringTimes` | no | Partner-level catering availability window (`{ start: "HH:MM", end: "HH:MM" }`). Restricts the session delivery-time picker to slots within this range. |
|
|
46
45
|
| `stickyTopOffset` | `number` | no | Pixels to offset the widget's internal sticky date/session nav from the top of the viewport. Set this to the height of any sticky/fixed navbar in your host layout so the widget's nav doesn't slide underneath it. Defaults to `0`. |
|
|
47
46
|
| `onReady` | `() => void` | no | Fires when the widget has initialized. |
|
|
48
47
|
| `onOrderComplete` | `(result: OrderCompleteResult) => void` | no | Fires after a successful order submission. See [`onOrderComplete` behaviour](#onordercompleteresult) for the timing. |
|
|
@@ -56,7 +55,6 @@ Defaults: Swift-hosted backend, `localStorage` persistence, neutral theme.
|
|
|
56
55
|
```tsx
|
|
57
56
|
"use client";
|
|
58
57
|
import { CateringWidget } from "@swift-food-services/catering-widget";
|
|
59
|
-
import "@swift-food-services/catering-widget/dist/styles.css";
|
|
60
58
|
import { useRouter } from "next/navigation";
|
|
61
59
|
|
|
62
60
|
export default function Page() {
|
|
@@ -93,8 +91,10 @@ export default function Page() {
|
|
|
93
91
|
publishableKey="pk_live_..."
|
|
94
92
|
initialData={{
|
|
95
93
|
eventName: "Alice's Birthday",
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
eventStartDate: "2026-07-12",
|
|
95
|
+
eventStartTime: "18:00",
|
|
96
|
+
eventEndDate: "2026-07-12",
|
|
97
|
+
eventEndTime: "22:00",
|
|
98
98
|
guestCount: 40,
|
|
99
99
|
deliveryAddress: {
|
|
100
100
|
line1: "1 Example Lane",
|
|
@@ -109,9 +109,32 @@ export default function Page() {
|
|
|
109
109
|
/>
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
Every field in `initialData` is optional. Fields remain editable after pre-fill.
|
|
112
|
+
Every field in `initialData` is optional. Fields remain editable after pre-fill.
|
|
113
113
|
|
|
114
|
-
**
|
|
114
|
+
**How `initialData` interacts with persisted in-progress orders:** the widget fingerprints the supplied `initialData` (event window, guest count, address, and contact fields) and stores the fingerprint alongside the order. On every mount it compares the incoming fingerprint to the stored one:
|
|
115
|
+
|
|
116
|
+
- **Match** (e.g. page reload) → the in-progress order is preserved; `initialData` is _not_ re-applied.
|
|
117
|
+
- **Differ** (e.g. customer navigated back to your booking page, edited details, then returned) → the stored order is cleared and `initialData` is applied fresh.
|
|
118
|
+
- **No fingerprint stored yet** (first visit) → `initialData` is applied and the fingerprint is recorded.
|
|
119
|
+
|
|
120
|
+
For this to behave predictably, make sure the values you pass for the same booking are stable across renders — avoid recomputing dynamic values like `new Date()` inline in render.
|
|
121
|
+
|
|
122
|
+
The event window is a start–end pair (`eventStartDate` + `eventStartTime` to `eventEndDate` + `eventEndTime`). When set, the session editor restricts session dates to that range and filters the delivery-time picker so it stays within the window on the boundary days.
|
|
123
|
+
|
|
124
|
+
**Address requires `lat` and `lng`.** Delivery pricing depends on coordinates, so if you pass a `deliveryAddress` without both `lat` and `lng`, the widget ignores the entire address (no fields are pre-filled) and the guest is asked to pick one via the address-autocomplete field instead. The other `initialData` fields (event window, guest count, contact) still apply.
|
|
125
|
+
|
|
126
|
+
### Restricting catering hours (`allowedCateringTimes`)
|
|
127
|
+
|
|
128
|
+
Pass a partner-level catering availability window to restrict the session delivery-time picker to a subset of the day. Times are 24-hour `"HH:MM"` strings.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
<CateringWidget
|
|
132
|
+
publishableKey="pk_live_..."
|
|
133
|
+
allowedCateringTimes={{ start: "09:00", end: "19:00" }}
|
|
134
|
+
/>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Each slot is a 30-minute window. A slot is shown only if it fits entirely within `[start, end]` — its start must be ≥ `start` and its end must be ≤ `end`. With `end: "19:00"`, for example, the latest visible slot is 6:30 PM – 7:00 PM. If `initialData` also defines an event window, the two filters compose: the partner window is the outer bound, and the event start/end further narrow the picker on boundary days.
|
|
115
138
|
|
|
116
139
|
### Offsetting below a host navbar
|
|
117
140
|
|
|
@@ -134,6 +157,7 @@ import {
|
|
|
134
157
|
type CateringWidgetProps,
|
|
135
158
|
type Theme,
|
|
136
159
|
type InitialData,
|
|
160
|
+
type AllowedCateringTimes,
|
|
137
161
|
type OrderCompleteResult,
|
|
138
162
|
type OrderSummary,
|
|
139
163
|
type MealSession,
|
|
@@ -187,14 +211,13 @@ Fires on errors the widget can't recover from. `error.code` is one of:
|
|
|
187
211
|
- Multi-session meal building
|
|
188
212
|
- Contact details and delivery address
|
|
189
213
|
- Promo codes and pricing preview
|
|
190
|
-
- Google Maps address autocomplete
|
|
214
|
+
- Google Maps address autocomplete (requires the `googleMapsApiKey` you provide)
|
|
191
215
|
- Order submission to Swift's API
|
|
192
216
|
- State persistence in `localStorage` (namespaced)
|
|
193
217
|
|
|
194
218
|
## What you're responsible for
|
|
195
219
|
|
|
196
220
|
- Getting a publishable key from Swift.
|
|
197
|
-
- Registering your site's origin(s) with Swift.
|
|
198
221
|
- Providing a Google Maps JavaScript API key (with the Places library enabled) via the `googleMapsApiKey` prop. Restrict the key to your own domain(s) in the Google Cloud Console.
|
|
199
222
|
- Rendering `<CateringWidget>` wherever you want the flow to live.
|
|
200
223
|
- Navigating after `onOrderComplete`.
|
|
@@ -209,26 +232,19 @@ Fires on errors the widget can't recover from. `error.code` is one of:
|
|
|
209
232
|
|
|
210
233
|
## Getting a publishable key
|
|
211
234
|
|
|
212
|
-
Contact Swift at [
|
|
235
|
+
Contact Swift at [swiftfooduk@gmail.com](mailto:swiftfooduk@gmail.com) with:
|
|
213
236
|
|
|
214
237
|
1. Your company name.
|
|
215
|
-
2.
|
|
216
|
-
3. A technical contact for integration support.
|
|
238
|
+
2. A technical contact for integration support.
|
|
217
239
|
|
|
218
|
-
Swift provisions a partner record and returns a publishable key (format: `pk_live_...`
|
|
240
|
+
Swift provisions a partner record and returns a publishable key (format: `pk_live_...`) out of band.
|
|
219
241
|
|
|
220
|
-
The key is public
|
|
242
|
+
The key is public — it ships in the browser bundle.
|
|
221
243
|
|
|
222
244
|
## Troubleshooting
|
|
223
245
|
|
|
224
|
-
**Widget doesn't render / screen is blank**
|
|
225
|
-
Check that you've imported the stylesheet: `import "@swift-food-services/catering-widget/dist/styles.css";`.
|
|
226
|
-
|
|
227
246
|
**Errors mentioning `invalid_publishable_key` or `session_failed`**
|
|
228
|
-
Either the key is wrong
|
|
229
|
-
|
|
230
|
-
**Widget works on `localhost` but not in production**
|
|
231
|
-
Your production origin isn't registered. Ask Swift to add it.
|
|
247
|
+
Either the key is wrong or the key is inactive. Contact Swift if you need a new one.
|
|
232
248
|
|
|
233
249
|
**TypeScript errors importing types**
|
|
234
250
|
Ensure your `tsconfig.json` has `"moduleResolution": "bundler"` or `"node16"`/`"nodenext"`.
|
|
@@ -243,7 +259,7 @@ Modern evergreen browsers (Chrome, Firefox, Safari, Edge) on desktop and mobile.
|
|
|
243
259
|
|
|
244
260
|
## Support
|
|
245
261
|
|
|
246
|
-
- Integration questions: [
|
|
262
|
+
- Integration questions: [swiftfooduk@gmail.com](mailto:swiftfooduk@gmail.com)
|
|
247
263
|
- Bug reports: include your publishable key prefix (first 8 chars), the browser, and a reproducible example.
|
|
248
264
|
|
|
249
265
|
## License
|