@fleetbridge/ui 0.0.0-stage → 1.0.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/package.json CHANGED
@@ -1,6 +1,96 @@
1
1
  {
2
2
  "name": "@fleetbridge/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "FleetBridge customer UI (search, results, booking, manage booking) for WordPress and custom sites.",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "type": "module",
10
+ "sideEffects": [
11
+ "*.css"
12
+ ],
13
+ "main": "./index.js",
14
+ "module": "./index.js",
15
+ "types": "./index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./index.d.ts",
19
+ "import": "./index.js"
20
+ },
21
+ "./server": {
22
+ "types": "./server.d.ts",
23
+ "import": "./server.js"
24
+ },
25
+ "./theme": {
26
+ "types": "./theme.d.ts",
27
+ "import": "./theme.js"
28
+ },
29
+ "./styles.css": "./styles.css",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "dependencies": {
33
+ "@base-ui/react": "^1.6.0",
34
+ "@gsap/react": "2.1.1",
35
+ "@heroui/react": "^3.0.3",
36
+ "@heroui/styles": "^3.0.3",
37
+ "@hookform/resolvers": "^3.9.0",
38
+ "@radix-ui/react-accordion": "^1.2.1",
39
+ "@radix-ui/react-alert-dialog": "^1.1.2",
40
+ "@radix-ui/react-avatar": "^1.1.1",
41
+ "@radix-ui/react-checkbox": "^1.1.2",
42
+ "@radix-ui/react-collapsible": "^1.1.1",
43
+ "@radix-ui/react-dropdown-menu": "^2.1.2",
44
+ "@radix-ui/react-hover-card": "^1.1.2",
45
+ "@radix-ui/react-label": "^2.1.0",
46
+ "@radix-ui/react-menubar": "^1.1.2",
47
+ "@radix-ui/react-navigation-menu": "^1.2.1",
48
+ "@radix-ui/react-popover": "^1.1.2",
49
+ "@radix-ui/react-progress": "^1.1.0",
50
+ "@radix-ui/react-radio-group": "^1.2.1",
51
+ "@radix-ui/react-scroll-area": "^1.1.0",
52
+ "@radix-ui/react-select": "^2.1.2",
53
+ "@radix-ui/react-separator": "^1.1.0",
54
+ "@radix-ui/react-slider": "^1.2.1",
55
+ "@radix-ui/react-slot": "^1.2.4",
56
+ "@radix-ui/react-switch": "^1.1.1",
57
+ "@radix-ui/react-tabs": "^1.1.1",
58
+ "@radix-ui/react-toast": "^1.2.2",
59
+ "@radix-ui/react-toggle": "^1.1.0",
60
+ "@radix-ui/react-toggle-group": "^1.1.0",
61
+ "@radix-ui/react-tooltip": "^1.1.3",
62
+ "@tanstack/query-async-storage-persister": "^5.102.8",
63
+ "@tanstack/react-query": "^5.102.8",
64
+ "@tanstack/react-query-persist-client": "^5.102.8",
65
+ "class-variance-authority": "^0.7.1",
66
+ "clsx": "^2.1.1",
67
+ "cmdk": "^1.1.1",
68
+ "date-fns": "^4.1.0",
69
+ "embla-carousel-react": "^8.6.0",
70
+ "framer-motion": "^12.41.0",
71
+ "gsap": "^3.15.0",
72
+ "input-otp": "^1.4.2",
73
+ "lucide-react": "^1.21.0",
74
+ "next-themes": "^0.4.6",
75
+ "radix-ui": "^1.4.3",
76
+ "react-day-picker": "^10.0.1",
77
+ "react-hook-form": "^7.54.0",
78
+ "react-resizable-panels": "^4.10.0",
79
+ "recharts": "3.8.0",
80
+ "sonner": "^2.0.7",
81
+ "tailwind-merge": "^3.5.0",
82
+ "vaul": "^1.1.2",
83
+ "zod": "^3.23.8",
84
+ "zustand": "^5.0.14"
85
+ },
86
+ "peerDependencies": {
87
+ "react": "^19",
88
+ "react-dom": "^19",
89
+ "@fleetbridge/sdk": "^1.2.0"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@fleetbridge/sdk": {
93
+ "optional": true
94
+ }
95
+ }
96
+ }
package/server.d.ts ADDED
@@ -0,0 +1,199 @@
1
+ import { AppConnector, FleetBridge, StorageAdapter } from '@fleetbridge/sdk';
2
+
3
+ /**
4
+ * One supplier connection the site may search and book. The browser only
5
+ * ever sees `identifier` (for example "europcar") and `name`. `credentials`
6
+ * stay on the server.
7
+ *
8
+ * The site's own fleet is the entry whose identifier is "own-fleet"; it needs
9
+ * no credentials. (You can also switch it on with `ownFleet: true`.)
10
+ */
11
+ interface SupplierAccount {
12
+ /** The account's supplier connection id (AccountSupplier.id) — what the core calls supplierId. */
13
+ supplierId: string;
14
+ /** The adapter name, for example "europcar", "bluu" or "own-fleet". */
15
+ identifier: string;
16
+ /** The name customers see. */
17
+ name: string;
18
+ logo?: string;
19
+ /** The supplier login details (server-only). Empty for the own fleet. */
20
+ credentials: Record<string, unknown>;
21
+ /** False switches the connection off without removing it. Default true. */
22
+ enabled?: boolean;
23
+ }
24
+ /**
25
+ * Small key/value store with expiry. Used for the per-visitor request limits
26
+ * (WordPress keeps those in transients). The default keeps them in memory,
27
+ * which is right for one long-running server; give a shared store (Redis,
28
+ * KV, …) when the app runs on many servers or serverless.
29
+ */
30
+ interface StateStore {
31
+ get(key: string): Promise<string | null>;
32
+ set(key: string, value: string, ttlSeconds: number): Promise<void>;
33
+ delete(key: string): Promise<void>;
34
+ }
35
+ /** Anything that can run an action through the site's tenant database. AppConnector satisfies it. */
36
+ type Forwarding = Pick<AppConnector, 'forward'>;
37
+ interface PublicHandlerHooks {
38
+ /** Runs before every action. Return a Response to stop (rate limits, blocked visitors…). */
39
+ beforeAction?(ctx: {
40
+ action: string;
41
+ fields: Record<string, string>;
42
+ ip: string | null;
43
+ request: Request;
44
+ }): Promise<Response | void>;
45
+ onSearch?(e: {
46
+ trip: unknown;
47
+ resultCount: number;
48
+ sources: unknown[];
49
+ }): Promise<void>;
50
+ onBookingCreated?(e: {
51
+ booking: unknown;
52
+ customer: unknown;
53
+ trip: unknown;
54
+ source: unknown;
55
+ extras: unknown[];
56
+ price: unknown;
57
+ }): Promise<void>;
58
+ onBookingCancelled?(e: {
59
+ booking: unknown;
60
+ }): Promise<void>;
61
+ onBookingAmended?(e: {
62
+ booking: unknown;
63
+ price?: unknown;
64
+ }): Promise<void>;
65
+ onLookup?(e: {
66
+ bookingNumber: string;
67
+ found: boolean;
68
+ ip: string | null;
69
+ }): Promise<void>;
70
+ onPaymentStarted?(e: {
71
+ bookingId: string;
72
+ methodId: string;
73
+ redirectUrl?: string;
74
+ }): Promise<void>;
75
+ onPaymentVerified?(e: {
76
+ bookingId?: string;
77
+ status: string;
78
+ payment: unknown;
79
+ }): Promise<void>;
80
+ onError?(e: {
81
+ action: string;
82
+ error: unknown;
83
+ }): Promise<void>;
84
+ }
85
+ interface PublicHandlerOptions {
86
+ /** From createAppConnector (tenant DB: Postgres, MySQL or SQLite). */
87
+ connector: Forwarding & Partial<Pick<AppConnector, 'client' | 'executor'>>;
88
+ /** Optional ApiKeyAuth client, for account-level calls. Not needed by the public actions today. */
89
+ client?: FleetBridge;
90
+ /** The site's connected suppliers with their login details (server-only). */
91
+ suppliers: () => Promise<SupplierAccount[]>;
92
+ /** Absolute site address, for example "https://www.example.com". Used for payment return and email links. */
93
+ siteUrl: string;
94
+ /** Where the customer lands after paying online when the page they booked on is not usable. Default "/booking/payment-return". */
95
+ paymentReturnPath?: string;
96
+ /** The page that opens "Manage my booking" from email links (#manage=…). Default "/manage-booking". */
97
+ manageBookingPath?: string;
98
+ hooks?: PublicHandlerHooks;
99
+ /**
100
+ * The tenant database, for the reads the plugin does itself (branch list,
101
+ * add-ons, payment methods, booking rows, customers, quotes). Defaults to
102
+ * the storage inside `connector`.
103
+ */
104
+ storage?: StorageAdapter;
105
+ /** The branch time zone used to read the form's dates. Default "Africa/Johannesburg". */
106
+ timeZone?: string;
107
+ /** Signs payment links. Default: FLEETBRIDGE_SITE_SECRET. */
108
+ secret?: string;
109
+ /** The FleetBridge account id (Customers.accountId). Default: FLEETBRIDGE_ACCOUNT_ID. */
110
+ accountId?: string;
111
+ /** The own fleet's name when the core gives none. Default: FLEETBRIDGE_ACCOUNT_NAME, else "Our fleet". */
112
+ ownFleetName?: string;
113
+ /** Search the site's own fleet even when `suppliers()` has no "own-fleet" entry. */
114
+ ownFleet?: boolean;
115
+ /** Per-visitor hourly limits (WordPress's PublicRequest::guard). false switches them off. */
116
+ rateLimit?: false | {
117
+ store?: StateStore;
118
+ };
119
+ /** Finds the visitor's address. Default: x-forwarded-for, x-real-ip, cf-connecting-ip. */
120
+ getIp?(request: Request): string | null;
121
+ /** Where values are read from (process.env by default). */
122
+ env?: Record<string, string | undefined>;
123
+ /** Logs problems (WordPress's error_log). Default console.error. */
124
+ log?(message: string): void;
125
+ }
126
+ interface AdminHandlerOptions {
127
+ /** Runs actions through the site's tenant database (preferred, same as WordPress). */
128
+ connector?: Forwarding;
129
+ /** ApiKeyAuth client; used when no connector is given. */
130
+ client: FleetBridge;
131
+ /** Decides who may run admin actions. */
132
+ authorize(request: Request): Promise<{
133
+ ok: true;
134
+ actor: string;
135
+ } | {
136
+ ok: false;
137
+ status?: number;
138
+ message?: string;
139
+ }>;
140
+ /** Allowed action names. An entry ending with "." allows every action starting with it. Default: DEFAULT_ADMIN_ALLOW. */
141
+ allow?: string[];
142
+ hooks?: {
143
+ onAction?(e: {
144
+ action: string;
145
+ actor: string;
146
+ ok: boolean;
147
+ }): Promise<void>;
148
+ };
149
+ log?(message: string): void;
150
+ }
151
+
152
+ /** Core error codes whose message is written for customers. Any other error only says "try again". */
153
+ declare const CUSTOMER_ERRORS: string[];
154
+ /** One message for "no such booking number" and "wrong PIN", so nobody can tell which part was wrong. */
155
+ declare const LOOKUP_ERROR = "We could not find a booking with that booking number and PIN. Please check both and try again.";
156
+ /** Row keys the customer never sees: the site's own ids and the PIN. */
157
+ declare const STAFF_ONLY: string[];
158
+ /** Every public action this handler answers, by its WordPress name without "fleetbridge_". */
159
+ declare const PUBLIC_ACTIONS: readonly ["public_branches", "search_sources", "search_availability", "booking_request", "lookup_booking", "cancel_my_booking", "amend_my_booking", "get_estimation", "get_extras", "get_one_way_fee", "supplier_terms", "payment_methods", "start_payment", "verify_payment", "request_quote", "lookup_quote", "confirm_quote"];
160
+ type PublicAction = (typeof PUBLIC_ACTIONS)[number];
161
+ declare function createPublicHandler(opts: PublicHandlerOptions): (request: Request) => Promise<Response>;
162
+
163
+ /** The WordPress admin allowlist. An entry ending in "." allows every action starting with it. */
164
+ declare const DEFAULT_ADMIN_ALLOW: string[];
165
+ /**
166
+ * DEFAULT_ADMIN_ALLOW plus what a staff dashboard outside WordPress needs
167
+ * (WordPress serves these through its own admin controllers): listing and
168
+ * cancelling bookings, and the suppliers' branch and extras lists.
169
+ */
170
+ declare const STAFF_ADMIN_ALLOW: string[];
171
+ /** Whether `action` is allowed by `allow` (a well-formed dotted name, exact or by prefix). */
172
+ declare function adminMayRun(action: unknown, allow?: string[]): action is string;
173
+ declare function createAdminHandler(opts: AdminHandlerOptions): (request: Request) => Promise<Response>;
174
+
175
+ /**
176
+ * Reads the site's supplier connections from FLEETBRIDGE_SUPPLIERS, a JSON
177
+ * array of SupplierAccount, for example:
178
+ *
179
+ * FLEETBRIDGE_SUPPLIERS='[
180
+ * {"supplierId":"as_123","identifier":"europcar","name":"Europcar","credentials":{"endpoint":"…","username":"…","password":"…"}},
181
+ * {"supplierId":"as_456","identifier":"own-fleet","name":"Carhire fleet","credentials":{}}
182
+ * ]'
183
+ *
184
+ * Entries without supplierId or identifier are skipped. Bad JSON gives an
185
+ * empty list (and a log line), so a typo never takes the site down.
186
+ */
187
+ declare function readSuppliersFromEnv(env?: Record<string, string | undefined>): SupplierAccount[];
188
+
189
+ declare class MemoryStateStore implements StateStore {
190
+ private readonly items;
191
+ get(key: string): Promise<string | null>;
192
+ set(key: string, value: string, ttlSeconds: number): Promise<void>;
193
+ delete(key: string): Promise<void>;
194
+ }
195
+
196
+ /** The name the core and the widget use for the site's own cars. */
197
+ declare const OWN_FLEET = "own-fleet";
198
+
199
+ export { type AdminHandlerOptions, CUSTOMER_ERRORS, DEFAULT_ADMIN_ALLOW, type Forwarding, LOOKUP_ERROR, MemoryStateStore, OWN_FLEET, PUBLIC_ACTIONS, type PublicAction, type PublicHandlerHooks, type PublicHandlerOptions, STAFF_ADMIN_ALLOW, STAFF_ONLY, type StateStore, type SupplierAccount, adminMayRun, createAdminHandler, createPublicHandler, readSuppliersFromEnv };