@travories/frontend-sdk 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 +20 -0
- package/README.md +193 -0
- package/dist/index.d.mts +633 -0
- package/dist/index.d.ts +633 -0
- package/dist/index.js +2406 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2373 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles.css +2 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Travories
|
|
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 OF THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# @travories/sdk
|
|
2
|
+
|
|
3
|
+
Official Travories SDK. Fetch packages by slug and drop the full **Package Detail page** into any React app.
|
|
4
|
+
|
|
5
|
+
- Framework-agnostic API client (`TravoriesClient`)
|
|
6
|
+
- React hooks (`usePackageBySlug`, `usePackageBundle`)
|
|
7
|
+
- Self-contained UI component (`<PackageDetailView />`) with bundled styles — **no Tailwind required**
|
|
8
|
+
- Full TypeScript types
|
|
9
|
+
- ESM + CJS builds
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @travories/sdk
|
|
17
|
+
# peer deps (only needed if you use the React component / hooks)
|
|
18
|
+
npm install react react-dom
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 1. Just the data
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { TravoriesClient } from "@travories/sdk";
|
|
27
|
+
|
|
28
|
+
const travories = new TravoriesClient({
|
|
29
|
+
baseUrl: "https://api.travories.com",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const pkg = await travories.packages.getBySlug("everest-base-camp");
|
|
33
|
+
console.log(pkg?.title, pkg?.totalDays);
|
|
34
|
+
|
|
35
|
+
// Or the convenience shortcut:
|
|
36
|
+
const pkg2 = await travories.getPackageBySlug("everest-base-camp");
|
|
37
|
+
|
|
38
|
+
// Or fetch the full bundle (package + host + attractions) in one call:
|
|
39
|
+
const bundle = await travories.getPackageBundle("everest-base-camp");
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Returns `null` on 404 / network error (silent by default), or throws `TravoriesApiError` for unexpected statuses when not in silent mode.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 2. The drop-in component
|
|
47
|
+
|
|
48
|
+
`<PackageDetailView />` renders the whole detail page: gallery, overview, quick facts, itinerary, what's included / excluded / to pack, host card, and a sticky booking sidebar.
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { TravoriesClient, PackageDetailView } from "@travories/sdk";
|
|
52
|
+
import "@travories/sdk/styles.css"; // <- bundled styles
|
|
53
|
+
|
|
54
|
+
const client = new TravoriesClient({ baseUrl: "https://api.travories.com" });
|
|
55
|
+
|
|
56
|
+
export default function PackagePage({ slug }: { slug: string }) {
|
|
57
|
+
return (
|
|
58
|
+
<PackageDetailView
|
|
59
|
+
client={client}
|
|
60
|
+
slug={slug}
|
|
61
|
+
currency="USD"
|
|
62
|
+
onReserve={(pkg) => {
|
|
63
|
+
// navigate to your booking flow
|
|
64
|
+
window.location.href = `/checkout/${pkg.slug}`;
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Props
|
|
72
|
+
|
|
73
|
+
| Prop | Type | Notes |
|
|
74
|
+
| --------------- | ------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
75
|
+
| `client` | `TravoriesClient` | Required when using `slug`. |
|
|
76
|
+
| `slug` | `string` | Package slug to fetch. |
|
|
77
|
+
| `initialBundle` | `PackageBundle \| null` | Pre-fetched data. If set, no client-side fetch runs. Use this for SSR. |
|
|
78
|
+
| `currency` | `string` | Default `"USD"`. Anything `Intl.NumberFormat` accepts. |
|
|
79
|
+
| `onReserve` | `(pkg: TravoriesPackage) => void` | If omitted, the Reserve button shows a disabled "Contact host to book" state. |
|
|
80
|
+
| `className` | `string` | Extra class on the root container. |
|
|
81
|
+
| `renderLoading` | `() => ReactNode` | Override the loading skeleton. |
|
|
82
|
+
| `renderNotFound`| `() => ReactNode` | Override the empty state. |
|
|
83
|
+
|
|
84
|
+
### SSR example (Next.js App Router)
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
// app/packages/[slug]/page.tsx
|
|
88
|
+
import { TravoriesClient, PackageDetailView } from "@travories/sdk";
|
|
89
|
+
import "@travories/sdk/styles.css";
|
|
90
|
+
|
|
91
|
+
const client = new TravoriesClient({ baseUrl: process.env.TRAVORIES_API_URL! });
|
|
92
|
+
|
|
93
|
+
export default async function Page({ params }: { params: { slug: string } }) {
|
|
94
|
+
const bundle = await client.getPackageBundle(params.slug);
|
|
95
|
+
if (!bundle) return <div>Not found</div>;
|
|
96
|
+
|
|
97
|
+
return <PackageDetailView initialBundle={bundle} />;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 3. Hooks (build your own UI)
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
import { TravoriesClient, usePackageBySlug } from "@travories/sdk";
|
|
107
|
+
|
|
108
|
+
const client = new TravoriesClient({ baseUrl: "https://api.travories.com" });
|
|
109
|
+
|
|
110
|
+
function MyPackage({ slug }: { slug: string }) {
|
|
111
|
+
const { data, loading, error, refetch } = usePackageBySlug(client, slug);
|
|
112
|
+
|
|
113
|
+
if (loading) return <p>Loading…</p>;
|
|
114
|
+
if (error) return <p>{error.message}</p>;
|
|
115
|
+
if (!data) return <p>Not found</p>;
|
|
116
|
+
|
|
117
|
+
return <h1>{data.title}</h1>;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`usePackageBundle(client, slug)` works the same way but returns `{ pkg, host, attractions }`.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Client config
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
new TravoriesClient({
|
|
129
|
+
baseUrl: "https://api.travories.com", // required
|
|
130
|
+
apiKey: "tvr_xxx", // optional, sent as x-api-key
|
|
131
|
+
authToken: () => session?.accessToken, // optional, sent as Bearer
|
|
132
|
+
defaultHeaders: { "x-trace-id": "abc" }, // optional
|
|
133
|
+
fetchImpl: customFetch, // optional, e.g. node-fetch in old Node
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`authToken` accepts a string, a function, or an async function — useful when the token is rotated.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## TypeScript
|
|
142
|
+
|
|
143
|
+
All types are exported:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import type {
|
|
147
|
+
TravoriesPackage,
|
|
148
|
+
PackageHost,
|
|
149
|
+
PackageBundle,
|
|
150
|
+
PackageDay,
|
|
151
|
+
PackagePriceTier,
|
|
152
|
+
PackageDiscount,
|
|
153
|
+
TravoriesImage,
|
|
154
|
+
} from "@travories/sdk";
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Styling
|
|
160
|
+
|
|
161
|
+
The component ships with scoped CSS (every class is prefixed `tvr-`). Import it once:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
import "@travories/sdk/styles.css";
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
CSS variables on `.tvr-root` let you re-skin without overriding individual selectors:
|
|
168
|
+
|
|
169
|
+
```css
|
|
170
|
+
.tvr-root {
|
|
171
|
+
--tvr-primary: #1d4ed8;
|
|
172
|
+
--tvr-accent: #ec4899;
|
|
173
|
+
--tvr-radius: 18px;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Local development
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
cd sdk
|
|
183
|
+
npm install
|
|
184
|
+
npm run build # build to dist/
|
|
185
|
+
npm run dev # watch mode
|
|
186
|
+
|
|
187
|
+
# example app
|
|
188
|
+
cd example
|
|
189
|
+
npm install
|
|
190
|
+
npm run dev # http://localhost:5173
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
The example uses `"@travories/sdk": "file:.."` so any rebuild of the SDK is picked up immediately.
|