@cohostvip/cohost-node 0.1.17 → 0.2.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/README.md +285 -24
- package/dist/index.d.mts +220 -2
- package/dist/index.d.ts +220 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
# @cohostvip/cohost-node
|
|
2
2
|
|
|
3
|
-
> Official Node.js SDK for
|
|
3
|
+
> Official Node.js SDK for the Cohost API
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@cohostvip/cohost-node)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
4
7
|
|
|
5
8
|
---
|
|
6
9
|
|
|
7
10
|
## ✨ Features
|
|
8
11
|
|
|
9
|
-
- TypeScript-first
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
12
|
+
- 🎯 **TypeScript-first** - Full type safety and IntelliSense support
|
|
13
|
+
- 🔐 **Token authentication** - Secure API access with bearer tokens
|
|
14
|
+
- 📦 **Dual module support** - Works with ESM and CommonJS
|
|
15
|
+
- 🚀 **Promise-based** - Modern async/await API
|
|
16
|
+
- 🔄 **Auto-unwrapping** - Automatically extracts data from API responses
|
|
17
|
+
- 🛡️ **Error handling** - Custom error types with status codes
|
|
18
|
+
- 📊 **Pagination** - Built-in support for paginated endpoints
|
|
13
19
|
|
|
14
20
|
---
|
|
15
21
|
|
|
@@ -19,56 +25,311 @@
|
|
|
19
25
|
npm install @cohostvip/cohost-node
|
|
20
26
|
# or
|
|
21
27
|
pnpm add @cohostvip/cohost-node
|
|
28
|
+
# or
|
|
29
|
+
yarn add @cohostvip/cohost-node
|
|
22
30
|
```
|
|
23
31
|
|
|
24
32
|
---
|
|
25
33
|
|
|
26
|
-
##
|
|
34
|
+
## 🚀 Quick Start
|
|
27
35
|
|
|
28
|
-
```
|
|
29
|
-
import {
|
|
36
|
+
```typescript
|
|
37
|
+
import { createCohostClient } from '@cohostvip/cohost-node';
|
|
30
38
|
|
|
31
|
-
const client =
|
|
39
|
+
const client = createCohostClient({
|
|
32
40
|
token: 'your-api-token',
|
|
41
|
+
settings: { debug: false } // optional
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Fetch events
|
|
45
|
+
const events = await client.events.list();
|
|
46
|
+
const event = await client.events.fetch('evt_123');
|
|
47
|
+
|
|
48
|
+
// Create an event
|
|
49
|
+
const newEvent = await client.events.create({
|
|
50
|
+
name: 'Summer Concert',
|
|
51
|
+
startDate: '2025-07-15T19:00:00Z',
|
|
52
|
+
venue: { name: 'City Arena' }
|
|
33
53
|
});
|
|
34
54
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
// Create tickets
|
|
56
|
+
await client.events.createTickets(newEvent.id, [
|
|
57
|
+
{ name: 'General Admission', price: 50, quantity: 100 },
|
|
58
|
+
{ name: 'VIP', price: 150, quantity: 20 }
|
|
59
|
+
]);
|
|
38
60
|
```
|
|
39
61
|
|
|
40
62
|
---
|
|
41
63
|
|
|
42
|
-
##
|
|
64
|
+
## 📚 API Reference
|
|
65
|
+
|
|
66
|
+
### Events API
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
// List all events
|
|
70
|
+
const events = await client.events.list();
|
|
71
|
+
|
|
72
|
+
// Get single event
|
|
73
|
+
const event = await client.events.fetch('evt_123');
|
|
74
|
+
|
|
75
|
+
// Search events (with pagination)
|
|
76
|
+
const results = await client.events.search({
|
|
77
|
+
page: 1,
|
|
78
|
+
size: 20
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Create event
|
|
82
|
+
const newEvent = await client.events.create({
|
|
83
|
+
name: 'My Event',
|
|
84
|
+
startDate: '2025-12-01T18:00:00Z'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Update event
|
|
88
|
+
await client.events.update('evt_123', {
|
|
89
|
+
name: 'Updated Event Name'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Get event tickets
|
|
93
|
+
const tickets = await client.events.tickets('evt_123');
|
|
94
|
+
|
|
95
|
+
// Create tickets
|
|
96
|
+
const result = await client.events.createTickets('evt_123', {
|
|
97
|
+
name: 'General Admission',
|
|
98
|
+
price: 50,
|
|
99
|
+
currency: 'USD',
|
|
100
|
+
quantity: 100
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Update ticket
|
|
104
|
+
await client.events.updateTicket('evt_123', 'tkt_456', {
|
|
105
|
+
price: 55
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Delete ticket
|
|
109
|
+
await client.events.deleteTicket('evt_123', 'tkt_456');
|
|
110
|
+
|
|
111
|
+
// Get attendees (requires authentication)
|
|
112
|
+
const attendees = await client.events.attendees('evt_123', {
|
|
113
|
+
page: 1,
|
|
114
|
+
size: 50
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Orders API
|
|
43
119
|
|
|
44
|
-
|
|
120
|
+
```typescript
|
|
121
|
+
// List orders with filters
|
|
122
|
+
const orders = await client.orders.list({
|
|
123
|
+
status: 'completed',
|
|
124
|
+
startDate: '2025-01-01',
|
|
125
|
+
endDate: '2025-12-31'
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Get order details
|
|
129
|
+
const order = await client.orders.fetch('ord_123', 'user_456');
|
|
130
|
+
|
|
131
|
+
// Get order attendees
|
|
132
|
+
const attendees = await client.orders.attendees('ord_123', 'user_456');
|
|
133
|
+
|
|
134
|
+
// Send order confirmation email
|
|
135
|
+
await client.orders.sendConfirmation('ord_123');
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Cart/Checkout API
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Start cart session
|
|
142
|
+
const session = await client.cart.start({
|
|
143
|
+
contextId: 'evt_123'
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Get cart session
|
|
147
|
+
const cart = await client.cart.get(session.id);
|
|
148
|
+
|
|
149
|
+
// Update session (customer info)
|
|
150
|
+
await client.cart.update(session.id, {
|
|
151
|
+
customer: {
|
|
152
|
+
email: 'customer@example.com',
|
|
153
|
+
name: 'John Doe'
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Add/update cart items
|
|
158
|
+
await client.cart.updateItem(session.id, {
|
|
159
|
+
offeringId: 'tkt_456',
|
|
160
|
+
quantity: 2
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Apply coupon
|
|
164
|
+
await client.cart.applyCoupon(session.id, 'SUMMER20');
|
|
165
|
+
|
|
166
|
+
// Remove coupon
|
|
167
|
+
await client.cart.deleteCoupon(session.id, 'cpn_789');
|
|
168
|
+
|
|
169
|
+
// Pre-validate payment
|
|
170
|
+
const validation = await client.cart.preValidate(session.id);
|
|
171
|
+
|
|
172
|
+
// Process payment
|
|
173
|
+
await client.cart.processPayment(session.id, {
|
|
174
|
+
paymentMethod: 'card',
|
|
175
|
+
// payment details...
|
|
176
|
+
});
|
|
45
177
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- `orders.fetch(id, uid)` – Fetch an order
|
|
178
|
+
// Place order
|
|
179
|
+
const result = await client.cart.placeOrder(session.id);
|
|
49
180
|
|
|
50
|
-
|
|
181
|
+
// Cancel session
|
|
182
|
+
await client.cart.cancel(session.id);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Coupons API
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// List all coupons
|
|
189
|
+
const coupons = await client.coupons.list();
|
|
190
|
+
|
|
191
|
+
// List coupons for specific event
|
|
192
|
+
const eventCoupons = await client.coupons.list({
|
|
193
|
+
eventId: 'evt_123'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Create coupon
|
|
197
|
+
const coupon = await client.coupons.create({
|
|
198
|
+
code: 'SUMMER2025',
|
|
199
|
+
discountType: 'percentage',
|
|
200
|
+
discountValue: 20,
|
|
201
|
+
maxUses: 100,
|
|
202
|
+
expiresAt: '2025-08-31T23:59:59Z'
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Update coupon
|
|
206
|
+
await client.coupons.update('cpn_789', {
|
|
207
|
+
discountValue: 25,
|
|
208
|
+
maxUses: 150
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Delete coupon
|
|
212
|
+
await client.coupons.delete('cpn_789');
|
|
213
|
+
```
|
|
51
214
|
|
|
52
215
|
---
|
|
53
216
|
|
|
54
|
-
##
|
|
217
|
+
## 🔧 Configuration
|
|
218
|
+
|
|
219
|
+
### Client Options
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { createCohostClient } from '@cohostvip/cohost-node';
|
|
223
|
+
|
|
224
|
+
const client = createCohostClient({
|
|
225
|
+
token: 'your-api-token',
|
|
226
|
+
settings: {
|
|
227
|
+
debug: true, // Enable debug logging
|
|
228
|
+
apiUrl: 'https://api.cohost.vip/v1' // Custom API URL (optional)
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
```
|
|
55
232
|
|
|
56
|
-
|
|
57
|
-
|
|
233
|
+
### Runtime Overrides
|
|
234
|
+
|
|
235
|
+
Override token, baseUrl, or headers for specific requests:
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const adminClient = client.requestWithOverrides({
|
|
239
|
+
token: 'admin-token',
|
|
240
|
+
headers: {
|
|
241
|
+
'X-Custom-Header': 'value'
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const event = await adminClient.events.fetch('evt_123');
|
|
246
|
+
```
|
|
58
247
|
|
|
59
248
|
---
|
|
60
249
|
|
|
61
|
-
##
|
|
62
|
-
|
|
250
|
+
## 🛡️ Error Handling
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { CohostError } from '@cohostvip/cohost-node';
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
const event = await client.events.fetch('invalid-id');
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (error instanceof CohostError) {
|
|
259
|
+
console.error('Error code:', error.errorCode);
|
|
260
|
+
console.error('Status code:', error.statusCode);
|
|
261
|
+
console.error('Message:', error.message);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 📊 TypeScript Support
|
|
269
|
+
|
|
270
|
+
Full TypeScript definitions included:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import {
|
|
274
|
+
createCohostClient,
|
|
275
|
+
CohostClient,
|
|
276
|
+
EventProfile,
|
|
277
|
+
Ticket,
|
|
278
|
+
Coupon,
|
|
279
|
+
PaginatedResponse
|
|
280
|
+
} from '@cohostvip/cohost-node';
|
|
281
|
+
|
|
282
|
+
const client: CohostClient = createCohostClient({
|
|
283
|
+
token: 'your-token'
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const events: EventProfile[] = await client.events.list();
|
|
287
|
+
const tickets: Ticket[] = await client.events.tickets('evt_123');
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 🛠 Environment Requirements
|
|
293
|
+
|
|
294
|
+
- **Node.js**: 18 or later
|
|
295
|
+
- **API Token**: Active Cohost API authentication token
|
|
63
296
|
|
|
64
297
|
---
|
|
65
298
|
|
|
66
299
|
## 🚧 Roadmap
|
|
67
|
-
|
|
300
|
+
|
|
301
|
+
See our [ROADMAP.md](./ROADMAP.md) for planned features and improvements.
|
|
302
|
+
|
|
303
|
+
**Coming Soon:**
|
|
304
|
+
- Workflows API integration
|
|
305
|
+
- Webhook validation helpers
|
|
306
|
+
- Enhanced retry logic and rate limiting
|
|
68
307
|
|
|
69
308
|
---
|
|
70
309
|
|
|
310
|
+
## 📖 Documentation
|
|
311
|
+
|
|
312
|
+
- [API Reference](https://docs.cohost.vip)
|
|
313
|
+
- [Changelog](./CHANGELOG.md)
|
|
314
|
+
- [Contributing Guidelines](./CONTRIBUTING.md)
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## 🤝 Contributing
|
|
319
|
+
|
|
320
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
321
|
+
|
|
322
|
+
---
|
|
71
323
|
|
|
72
324
|
## 📄 License
|
|
73
325
|
|
|
74
326
|
ISC © [Cohost](https://cohost.vip)
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🔗 Links
|
|
331
|
+
|
|
332
|
+
- [npm Package](https://www.npmjs.com/package/@cohostvip/cohost-node)
|
|
333
|
+
- [GitHub Repository](https://github.com/cohostvip/cohost-node)
|
|
334
|
+
- [API Documentation](https://docs.cohost.vip)
|
|
335
|
+
- [Cohost Website](https://cohost.vip)
|
package/dist/index.d.mts
CHANGED
|
@@ -1163,7 +1163,7 @@ interface EventProfile extends EventBase {
|
|
|
1163
1163
|
*
|
|
1164
1164
|
* @export
|
|
1165
1165
|
*/
|
|
1166
|
-
interface Coupon extends VersionedDataRecord {
|
|
1166
|
+
interface Coupon$1 extends VersionedDataRecord {
|
|
1167
1167
|
/**
|
|
1168
1168
|
* ID of the company that issued this coupon.
|
|
1169
1169
|
* @example "company_123abc"
|
|
@@ -1410,7 +1410,7 @@ interface ResolvedCartContextOffering {
|
|
|
1410
1410
|
path: string;
|
|
1411
1411
|
offering: Offering;
|
|
1412
1412
|
}
|
|
1413
|
-
type CouponSummary = Pick<Coupon, "id" | "code" | "amountOff" | "percentOff" | "offeringIds">;
|
|
1413
|
+
type CouponSummary = Pick<Coupon$1, "id" | "code" | "amountOff" | "percentOff" | "offeringIds">;
|
|
1414
1414
|
type OrderStatus = "placed" | "completed" | "attending" | "cancelled" | "refunded" | "started" | "pending" | "abandoned";
|
|
1415
1415
|
interface OrderCosts {
|
|
1416
1416
|
subtotal: CurrencyAmount;
|
|
@@ -1806,6 +1806,109 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
1806
1806
|
*/
|
|
1807
1807
|
attendees(id: string, filters?: PaginatedRequest<any>): Promise<PaginatedResponse<Attendee>>;
|
|
1808
1808
|
search(filters?: PaginatedRequest<any>): Promise<PaginatedResponse<EventProfile>>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Create a new event.
|
|
1811
|
+
*
|
|
1812
|
+
* @param event - The event data to create (without id)
|
|
1813
|
+
* @param context - Optional context information for event creation
|
|
1814
|
+
* @returns A Promise resolving to an object with the created event ID
|
|
1815
|
+
* @throws Will throw an error if the request fails or authentication is missing
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```ts
|
|
1819
|
+
* const result = await client.events.create({
|
|
1820
|
+
* name: 'Summer Concert',
|
|
1821
|
+
* startDate: '2025-07-15T19:00:00Z',
|
|
1822
|
+
* venue: { name: 'City Arena' }
|
|
1823
|
+
* });
|
|
1824
|
+
* console.log(result.id); // 'evt_abc123'
|
|
1825
|
+
* ```
|
|
1826
|
+
*/
|
|
1827
|
+
create(event: Omit<Partial<EventProfile>, 'id'>, context?: any): Promise<{
|
|
1828
|
+
id: string;
|
|
1829
|
+
}>;
|
|
1830
|
+
/**
|
|
1831
|
+
* Update an existing event.
|
|
1832
|
+
*
|
|
1833
|
+
* @param id - The unique identifier of the event to update
|
|
1834
|
+
* @param event - Partial event data to update
|
|
1835
|
+
* @param context - Optional context information for event update
|
|
1836
|
+
* @returns A Promise resolving to an object with the updated event ID
|
|
1837
|
+
* @throws Will throw an error if the request fails or event is not found
|
|
1838
|
+
*
|
|
1839
|
+
* @example
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* const result = await client.events.update('evt_abc123', {
|
|
1842
|
+
* name: 'Summer Concert - Updated',
|
|
1843
|
+
* capacity: 5000
|
|
1844
|
+
* });
|
|
1845
|
+
* ```
|
|
1846
|
+
*/
|
|
1847
|
+
update(id: string, event: Partial<EventProfile>, context?: any): Promise<{
|
|
1848
|
+
id: string;
|
|
1849
|
+
}>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Create one or more tickets for an event.
|
|
1852
|
+
*
|
|
1853
|
+
* @param eventId - The unique identifier of the event
|
|
1854
|
+
* @param tickets - Single ticket or array of tickets to create
|
|
1855
|
+
* @param context - Optional context information for ticket creation
|
|
1856
|
+
* @returns A Promise resolving to an object mapping reference IDs to created ticket IDs
|
|
1857
|
+
* @throws Will throw an error if the request fails or validation fails
|
|
1858
|
+
*
|
|
1859
|
+
* @example
|
|
1860
|
+
* ```ts
|
|
1861
|
+
* // Create single ticket
|
|
1862
|
+
* const result = await client.events.createTickets('evt_abc123', {
|
|
1863
|
+
* name: 'General Admission',
|
|
1864
|
+
* price: 50,
|
|
1865
|
+
* currency: 'USD',
|
|
1866
|
+
* quantity: 100
|
|
1867
|
+
* });
|
|
1868
|
+
*
|
|
1869
|
+
* // Create multiple tickets
|
|
1870
|
+
* const result = await client.events.createTickets('evt_abc123', [
|
|
1871
|
+
* { name: 'VIP', price: 150, quantity: 20 },
|
|
1872
|
+
* { name: 'Early Bird', price: 40, quantity: 50 }
|
|
1873
|
+
* ]);
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
createTickets(eventId: string, tickets: Partial<Ticket> | Partial<Ticket>[], context?: any): Promise<{
|
|
1877
|
+
ids: Record<string, string>;
|
|
1878
|
+
}>;
|
|
1879
|
+
/**
|
|
1880
|
+
* Update an existing ticket.
|
|
1881
|
+
*
|
|
1882
|
+
* @param eventId - The unique identifier of the event
|
|
1883
|
+
* @param ticketId - The unique identifier of the ticket to update
|
|
1884
|
+
* @param ticket - Partial ticket data to update
|
|
1885
|
+
* @param context - Optional context information for ticket update
|
|
1886
|
+
* @returns A Promise resolving to the updated ticket
|
|
1887
|
+
* @throws Will throw an error if the request fails or ticket is not found
|
|
1888
|
+
*
|
|
1889
|
+
* @example
|
|
1890
|
+
* ```ts
|
|
1891
|
+
* const result = await client.events.updateTicket('evt_abc123', 'tkt_xyz789', {
|
|
1892
|
+
* price: 55,
|
|
1893
|
+
* quantity: 120
|
|
1894
|
+
* });
|
|
1895
|
+
* ```
|
|
1896
|
+
*/
|
|
1897
|
+
updateTicket(eventId: string, ticketId: string, ticket: Partial<Ticket>, context?: any): Promise<Ticket>;
|
|
1898
|
+
/**
|
|
1899
|
+
* Delete a ticket from an event.
|
|
1900
|
+
*
|
|
1901
|
+
* @param eventId - The unique identifier of the event
|
|
1902
|
+
* @param ticketId - The unique identifier of the ticket to delete
|
|
1903
|
+
* @returns A Promise resolving when the ticket is deleted (no content)
|
|
1904
|
+
* @throws Will throw an error if the request fails or ticket is not found
|
|
1905
|
+
*
|
|
1906
|
+
* @example
|
|
1907
|
+
* ```ts
|
|
1908
|
+
* await client.events.deleteTicket('evt_abc123', 'tkt_xyz789');
|
|
1909
|
+
* ```
|
|
1910
|
+
*/
|
|
1911
|
+
deleteTicket(eventId: string, ticketId: string): Promise<void>;
|
|
1809
1912
|
}
|
|
1810
1913
|
|
|
1811
1914
|
/**
|
|
@@ -1851,6 +1954,22 @@ declare class OrdersAPI extends CohostEndpoint {
|
|
|
1851
1954
|
page?: number;
|
|
1852
1955
|
pageSize?: number;
|
|
1853
1956
|
}): Promise<any>;
|
|
1957
|
+
/**
|
|
1958
|
+
* Send order confirmation email to customer.
|
|
1959
|
+
*
|
|
1960
|
+
* @param id - The unique identifier of the order
|
|
1961
|
+
* @returns A Promise resolving to the confirmation response
|
|
1962
|
+
* @throws Will throw an error if the request fails or order is not found
|
|
1963
|
+
*
|
|
1964
|
+
* @example
|
|
1965
|
+
* ```ts
|
|
1966
|
+
* const result = await client.orders.sendConfirmation('ord_abc123');
|
|
1967
|
+
* console.log(result.response); // Confirmation sent status
|
|
1968
|
+
* ```
|
|
1969
|
+
*/
|
|
1970
|
+
sendConfirmation(id: string): Promise<{
|
|
1971
|
+
response: any;
|
|
1972
|
+
}>;
|
|
1854
1973
|
}
|
|
1855
1974
|
|
|
1856
1975
|
/**
|
|
@@ -1987,6 +2106,104 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
1987
2106
|
deleteCoupon(id: string, couponId: string): Promise<CartSession>;
|
|
1988
2107
|
}
|
|
1989
2108
|
|
|
2109
|
+
/**
|
|
2110
|
+
* Coupon interface for the Cohost API
|
|
2111
|
+
*/
|
|
2112
|
+
interface Coupon {
|
|
2113
|
+
id: string;
|
|
2114
|
+
code: string;
|
|
2115
|
+
discountType: 'percentage' | 'fixed';
|
|
2116
|
+
discountValue: number;
|
|
2117
|
+
maxUses?: number;
|
|
2118
|
+
usedCount?: number;
|
|
2119
|
+
expiresAt?: string;
|
|
2120
|
+
companyId: string;
|
|
2121
|
+
eventId?: string;
|
|
2122
|
+
status?: 'active' | 'inactive' | 'expired';
|
|
2123
|
+
created?: string;
|
|
2124
|
+
updated?: string;
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Provides methods to interact with the Cohost Coupons API.
|
|
2128
|
+
*
|
|
2129
|
+
* Usage:
|
|
2130
|
+
* ```ts
|
|
2131
|
+
* const client = new CohostClient({ token: 'your-token' });
|
|
2132
|
+
* const coupons = await client.coupons.list();
|
|
2133
|
+
* const coupon = await client.coupons.create({ code: 'SUMMER2025', discountType: 'percentage', discountValue: 20 });
|
|
2134
|
+
* ```
|
|
2135
|
+
*/
|
|
2136
|
+
declare class CouponsAPI extends CohostEndpoint {
|
|
2137
|
+
/**
|
|
2138
|
+
* List all coupons for the authenticated company.
|
|
2139
|
+
*
|
|
2140
|
+
* @param filters - Optional filters to apply when retrieving coupons
|
|
2141
|
+
* @returns A Promise resolving to an array of coupon objects
|
|
2142
|
+
* @throws Will throw an error if the request fails
|
|
2143
|
+
*
|
|
2144
|
+
* @example
|
|
2145
|
+
* ```ts
|
|
2146
|
+
* // List all coupons
|
|
2147
|
+
* const allCoupons = await client.coupons.list();
|
|
2148
|
+
*
|
|
2149
|
+
* // List coupons for specific event
|
|
2150
|
+
* const eventCoupons = await client.coupons.list({ eventId: 'evt_abc123' });
|
|
2151
|
+
* ```
|
|
2152
|
+
*/
|
|
2153
|
+
list(filters?: {
|
|
2154
|
+
eventId?: string;
|
|
2155
|
+
}): Promise<Coupon[]>;
|
|
2156
|
+
/**
|
|
2157
|
+
* Create a new coupon.
|
|
2158
|
+
*
|
|
2159
|
+
* @param coupon - The coupon data to create
|
|
2160
|
+
* @returns A Promise resolving to the created coupon object
|
|
2161
|
+
* @throws Will throw an error if the request fails or validation fails
|
|
2162
|
+
*
|
|
2163
|
+
* @example
|
|
2164
|
+
* ```ts
|
|
2165
|
+
* const coupon = await client.coupons.create({
|
|
2166
|
+
* code: 'SUMMER2025',
|
|
2167
|
+
* discountType: 'percentage',
|
|
2168
|
+
* discountValue: 20,
|
|
2169
|
+
* maxUses: 100,
|
|
2170
|
+
* expiresAt: '2025-08-31T23:59:59Z'
|
|
2171
|
+
* });
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
create(coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>): Promise<Coupon>;
|
|
2175
|
+
/**
|
|
2176
|
+
* Update an existing coupon.
|
|
2177
|
+
*
|
|
2178
|
+
* @param id - The unique identifier of the coupon to update
|
|
2179
|
+
* @param coupon - Partial coupon data to update
|
|
2180
|
+
* @returns A Promise resolving to the updated coupon object
|
|
2181
|
+
* @throws Will throw an error if the request fails or coupon is not found
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```ts
|
|
2185
|
+
* const updated = await client.coupons.update('cpn_xyz789', {
|
|
2186
|
+
* discountValue: 25,
|
|
2187
|
+
* maxUses: 150
|
|
2188
|
+
* });
|
|
2189
|
+
* ```
|
|
2190
|
+
*/
|
|
2191
|
+
update(id: string, coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>): Promise<Coupon>;
|
|
2192
|
+
/**
|
|
2193
|
+
* Delete a coupon.
|
|
2194
|
+
*
|
|
2195
|
+
* @param id - The unique identifier of the coupon to delete
|
|
2196
|
+
* @returns A Promise resolving when the coupon is deleted
|
|
2197
|
+
* @throws Will throw an error if the request fails or coupon is not found
|
|
2198
|
+
*
|
|
2199
|
+
* @example
|
|
2200
|
+
* ```ts
|
|
2201
|
+
* await client.coupons.delete('cpn_xyz789');
|
|
2202
|
+
* ```
|
|
2203
|
+
*/
|
|
2204
|
+
delete(id: string): Promise<void>;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
1990
2207
|
/**
|
|
1991
2208
|
* Configuration options for instantiating a CohostClient.
|
|
1992
2209
|
*/
|
|
@@ -2003,6 +2220,7 @@ declare class CohostClient {
|
|
|
2003
2220
|
readonly events: EventsAPI;
|
|
2004
2221
|
readonly orders: OrdersAPI;
|
|
2005
2222
|
readonly cart: SessionsAPI;
|
|
2223
|
+
readonly coupons: CouponsAPI;
|
|
2006
2224
|
private readonly baseOptions;
|
|
2007
2225
|
constructor(options: CohostClientOptions, customRequestFn?: RequestFn);
|
|
2008
2226
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1163,7 +1163,7 @@ interface EventProfile extends EventBase {
|
|
|
1163
1163
|
*
|
|
1164
1164
|
* @export
|
|
1165
1165
|
*/
|
|
1166
|
-
interface Coupon extends VersionedDataRecord {
|
|
1166
|
+
interface Coupon$1 extends VersionedDataRecord {
|
|
1167
1167
|
/**
|
|
1168
1168
|
* ID of the company that issued this coupon.
|
|
1169
1169
|
* @example "company_123abc"
|
|
@@ -1410,7 +1410,7 @@ interface ResolvedCartContextOffering {
|
|
|
1410
1410
|
path: string;
|
|
1411
1411
|
offering: Offering;
|
|
1412
1412
|
}
|
|
1413
|
-
type CouponSummary = Pick<Coupon, "id" | "code" | "amountOff" | "percentOff" | "offeringIds">;
|
|
1413
|
+
type CouponSummary = Pick<Coupon$1, "id" | "code" | "amountOff" | "percentOff" | "offeringIds">;
|
|
1414
1414
|
type OrderStatus = "placed" | "completed" | "attending" | "cancelled" | "refunded" | "started" | "pending" | "abandoned";
|
|
1415
1415
|
interface OrderCosts {
|
|
1416
1416
|
subtotal: CurrencyAmount;
|
|
@@ -1806,6 +1806,109 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
1806
1806
|
*/
|
|
1807
1807
|
attendees(id: string, filters?: PaginatedRequest<any>): Promise<PaginatedResponse<Attendee>>;
|
|
1808
1808
|
search(filters?: PaginatedRequest<any>): Promise<PaginatedResponse<EventProfile>>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Create a new event.
|
|
1811
|
+
*
|
|
1812
|
+
* @param event - The event data to create (without id)
|
|
1813
|
+
* @param context - Optional context information for event creation
|
|
1814
|
+
* @returns A Promise resolving to an object with the created event ID
|
|
1815
|
+
* @throws Will throw an error if the request fails or authentication is missing
|
|
1816
|
+
*
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```ts
|
|
1819
|
+
* const result = await client.events.create({
|
|
1820
|
+
* name: 'Summer Concert',
|
|
1821
|
+
* startDate: '2025-07-15T19:00:00Z',
|
|
1822
|
+
* venue: { name: 'City Arena' }
|
|
1823
|
+
* });
|
|
1824
|
+
* console.log(result.id); // 'evt_abc123'
|
|
1825
|
+
* ```
|
|
1826
|
+
*/
|
|
1827
|
+
create(event: Omit<Partial<EventProfile>, 'id'>, context?: any): Promise<{
|
|
1828
|
+
id: string;
|
|
1829
|
+
}>;
|
|
1830
|
+
/**
|
|
1831
|
+
* Update an existing event.
|
|
1832
|
+
*
|
|
1833
|
+
* @param id - The unique identifier of the event to update
|
|
1834
|
+
* @param event - Partial event data to update
|
|
1835
|
+
* @param context - Optional context information for event update
|
|
1836
|
+
* @returns A Promise resolving to an object with the updated event ID
|
|
1837
|
+
* @throws Will throw an error if the request fails or event is not found
|
|
1838
|
+
*
|
|
1839
|
+
* @example
|
|
1840
|
+
* ```ts
|
|
1841
|
+
* const result = await client.events.update('evt_abc123', {
|
|
1842
|
+
* name: 'Summer Concert - Updated',
|
|
1843
|
+
* capacity: 5000
|
|
1844
|
+
* });
|
|
1845
|
+
* ```
|
|
1846
|
+
*/
|
|
1847
|
+
update(id: string, event: Partial<EventProfile>, context?: any): Promise<{
|
|
1848
|
+
id: string;
|
|
1849
|
+
}>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Create one or more tickets for an event.
|
|
1852
|
+
*
|
|
1853
|
+
* @param eventId - The unique identifier of the event
|
|
1854
|
+
* @param tickets - Single ticket or array of tickets to create
|
|
1855
|
+
* @param context - Optional context information for ticket creation
|
|
1856
|
+
* @returns A Promise resolving to an object mapping reference IDs to created ticket IDs
|
|
1857
|
+
* @throws Will throw an error if the request fails or validation fails
|
|
1858
|
+
*
|
|
1859
|
+
* @example
|
|
1860
|
+
* ```ts
|
|
1861
|
+
* // Create single ticket
|
|
1862
|
+
* const result = await client.events.createTickets('evt_abc123', {
|
|
1863
|
+
* name: 'General Admission',
|
|
1864
|
+
* price: 50,
|
|
1865
|
+
* currency: 'USD',
|
|
1866
|
+
* quantity: 100
|
|
1867
|
+
* });
|
|
1868
|
+
*
|
|
1869
|
+
* // Create multiple tickets
|
|
1870
|
+
* const result = await client.events.createTickets('evt_abc123', [
|
|
1871
|
+
* { name: 'VIP', price: 150, quantity: 20 },
|
|
1872
|
+
* { name: 'Early Bird', price: 40, quantity: 50 }
|
|
1873
|
+
* ]);
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
createTickets(eventId: string, tickets: Partial<Ticket> | Partial<Ticket>[], context?: any): Promise<{
|
|
1877
|
+
ids: Record<string, string>;
|
|
1878
|
+
}>;
|
|
1879
|
+
/**
|
|
1880
|
+
* Update an existing ticket.
|
|
1881
|
+
*
|
|
1882
|
+
* @param eventId - The unique identifier of the event
|
|
1883
|
+
* @param ticketId - The unique identifier of the ticket to update
|
|
1884
|
+
* @param ticket - Partial ticket data to update
|
|
1885
|
+
* @param context - Optional context information for ticket update
|
|
1886
|
+
* @returns A Promise resolving to the updated ticket
|
|
1887
|
+
* @throws Will throw an error if the request fails or ticket is not found
|
|
1888
|
+
*
|
|
1889
|
+
* @example
|
|
1890
|
+
* ```ts
|
|
1891
|
+
* const result = await client.events.updateTicket('evt_abc123', 'tkt_xyz789', {
|
|
1892
|
+
* price: 55,
|
|
1893
|
+
* quantity: 120
|
|
1894
|
+
* });
|
|
1895
|
+
* ```
|
|
1896
|
+
*/
|
|
1897
|
+
updateTicket(eventId: string, ticketId: string, ticket: Partial<Ticket>, context?: any): Promise<Ticket>;
|
|
1898
|
+
/**
|
|
1899
|
+
* Delete a ticket from an event.
|
|
1900
|
+
*
|
|
1901
|
+
* @param eventId - The unique identifier of the event
|
|
1902
|
+
* @param ticketId - The unique identifier of the ticket to delete
|
|
1903
|
+
* @returns A Promise resolving when the ticket is deleted (no content)
|
|
1904
|
+
* @throws Will throw an error if the request fails or ticket is not found
|
|
1905
|
+
*
|
|
1906
|
+
* @example
|
|
1907
|
+
* ```ts
|
|
1908
|
+
* await client.events.deleteTicket('evt_abc123', 'tkt_xyz789');
|
|
1909
|
+
* ```
|
|
1910
|
+
*/
|
|
1911
|
+
deleteTicket(eventId: string, ticketId: string): Promise<void>;
|
|
1809
1912
|
}
|
|
1810
1913
|
|
|
1811
1914
|
/**
|
|
@@ -1851,6 +1954,22 @@ declare class OrdersAPI extends CohostEndpoint {
|
|
|
1851
1954
|
page?: number;
|
|
1852
1955
|
pageSize?: number;
|
|
1853
1956
|
}): Promise<any>;
|
|
1957
|
+
/**
|
|
1958
|
+
* Send order confirmation email to customer.
|
|
1959
|
+
*
|
|
1960
|
+
* @param id - The unique identifier of the order
|
|
1961
|
+
* @returns A Promise resolving to the confirmation response
|
|
1962
|
+
* @throws Will throw an error if the request fails or order is not found
|
|
1963
|
+
*
|
|
1964
|
+
* @example
|
|
1965
|
+
* ```ts
|
|
1966
|
+
* const result = await client.orders.sendConfirmation('ord_abc123');
|
|
1967
|
+
* console.log(result.response); // Confirmation sent status
|
|
1968
|
+
* ```
|
|
1969
|
+
*/
|
|
1970
|
+
sendConfirmation(id: string): Promise<{
|
|
1971
|
+
response: any;
|
|
1972
|
+
}>;
|
|
1854
1973
|
}
|
|
1855
1974
|
|
|
1856
1975
|
/**
|
|
@@ -1987,6 +2106,104 @@ declare class SessionsAPI extends CohostEndpoint {
|
|
|
1987
2106
|
deleteCoupon(id: string, couponId: string): Promise<CartSession>;
|
|
1988
2107
|
}
|
|
1989
2108
|
|
|
2109
|
+
/**
|
|
2110
|
+
* Coupon interface for the Cohost API
|
|
2111
|
+
*/
|
|
2112
|
+
interface Coupon {
|
|
2113
|
+
id: string;
|
|
2114
|
+
code: string;
|
|
2115
|
+
discountType: 'percentage' | 'fixed';
|
|
2116
|
+
discountValue: number;
|
|
2117
|
+
maxUses?: number;
|
|
2118
|
+
usedCount?: number;
|
|
2119
|
+
expiresAt?: string;
|
|
2120
|
+
companyId: string;
|
|
2121
|
+
eventId?: string;
|
|
2122
|
+
status?: 'active' | 'inactive' | 'expired';
|
|
2123
|
+
created?: string;
|
|
2124
|
+
updated?: string;
|
|
2125
|
+
}
|
|
2126
|
+
/**
|
|
2127
|
+
* Provides methods to interact with the Cohost Coupons API.
|
|
2128
|
+
*
|
|
2129
|
+
* Usage:
|
|
2130
|
+
* ```ts
|
|
2131
|
+
* const client = new CohostClient({ token: 'your-token' });
|
|
2132
|
+
* const coupons = await client.coupons.list();
|
|
2133
|
+
* const coupon = await client.coupons.create({ code: 'SUMMER2025', discountType: 'percentage', discountValue: 20 });
|
|
2134
|
+
* ```
|
|
2135
|
+
*/
|
|
2136
|
+
declare class CouponsAPI extends CohostEndpoint {
|
|
2137
|
+
/**
|
|
2138
|
+
* List all coupons for the authenticated company.
|
|
2139
|
+
*
|
|
2140
|
+
* @param filters - Optional filters to apply when retrieving coupons
|
|
2141
|
+
* @returns A Promise resolving to an array of coupon objects
|
|
2142
|
+
* @throws Will throw an error if the request fails
|
|
2143
|
+
*
|
|
2144
|
+
* @example
|
|
2145
|
+
* ```ts
|
|
2146
|
+
* // List all coupons
|
|
2147
|
+
* const allCoupons = await client.coupons.list();
|
|
2148
|
+
*
|
|
2149
|
+
* // List coupons for specific event
|
|
2150
|
+
* const eventCoupons = await client.coupons.list({ eventId: 'evt_abc123' });
|
|
2151
|
+
* ```
|
|
2152
|
+
*/
|
|
2153
|
+
list(filters?: {
|
|
2154
|
+
eventId?: string;
|
|
2155
|
+
}): Promise<Coupon[]>;
|
|
2156
|
+
/**
|
|
2157
|
+
* Create a new coupon.
|
|
2158
|
+
*
|
|
2159
|
+
* @param coupon - The coupon data to create
|
|
2160
|
+
* @returns A Promise resolving to the created coupon object
|
|
2161
|
+
* @throws Will throw an error if the request fails or validation fails
|
|
2162
|
+
*
|
|
2163
|
+
* @example
|
|
2164
|
+
* ```ts
|
|
2165
|
+
* const coupon = await client.coupons.create({
|
|
2166
|
+
* code: 'SUMMER2025',
|
|
2167
|
+
* discountType: 'percentage',
|
|
2168
|
+
* discountValue: 20,
|
|
2169
|
+
* maxUses: 100,
|
|
2170
|
+
* expiresAt: '2025-08-31T23:59:59Z'
|
|
2171
|
+
* });
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
create(coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>): Promise<Coupon>;
|
|
2175
|
+
/**
|
|
2176
|
+
* Update an existing coupon.
|
|
2177
|
+
*
|
|
2178
|
+
* @param id - The unique identifier of the coupon to update
|
|
2179
|
+
* @param coupon - Partial coupon data to update
|
|
2180
|
+
* @returns A Promise resolving to the updated coupon object
|
|
2181
|
+
* @throws Will throw an error if the request fails or coupon is not found
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```ts
|
|
2185
|
+
* const updated = await client.coupons.update('cpn_xyz789', {
|
|
2186
|
+
* discountValue: 25,
|
|
2187
|
+
* maxUses: 150
|
|
2188
|
+
* });
|
|
2189
|
+
* ```
|
|
2190
|
+
*/
|
|
2191
|
+
update(id: string, coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>): Promise<Coupon>;
|
|
2192
|
+
/**
|
|
2193
|
+
* Delete a coupon.
|
|
2194
|
+
*
|
|
2195
|
+
* @param id - The unique identifier of the coupon to delete
|
|
2196
|
+
* @returns A Promise resolving when the coupon is deleted
|
|
2197
|
+
* @throws Will throw an error if the request fails or coupon is not found
|
|
2198
|
+
*
|
|
2199
|
+
* @example
|
|
2200
|
+
* ```ts
|
|
2201
|
+
* await client.coupons.delete('cpn_xyz789');
|
|
2202
|
+
* ```
|
|
2203
|
+
*/
|
|
2204
|
+
delete(id: string): Promise<void>;
|
|
2205
|
+
}
|
|
2206
|
+
|
|
1990
2207
|
/**
|
|
1991
2208
|
* Configuration options for instantiating a CohostClient.
|
|
1992
2209
|
*/
|
|
@@ -2003,6 +2220,7 @@ declare class CohostClient {
|
|
|
2003
2220
|
readonly events: EventsAPI;
|
|
2004
2221
|
readonly orders: OrdersAPI;
|
|
2005
2222
|
readonly cart: SessionsAPI;
|
|
2223
|
+
readonly coupons: CouponsAPI;
|
|
2006
2224
|
private readonly baseOptions;
|
|
2007
2225
|
constructor(options: CohostClientOptions, customRequestFn?: RequestFn);
|
|
2008
2226
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var V=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var G=(r,e)=>{for(var t in e)m(r,t,{get:e[t],enumerable:!0})},L=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of z(e))!B.call(r,s)&&s!==t&&m(r,s,{get:()=>e[s],enumerable:!(n=D(e,s))||n.enumerable});return r};var M=r=>L(m({},"__esModule",{value:!0}),r);var o=(r,e,t)=>V(r,typeof e!="symbol"?e+"":e,t);var j={};G(j,{CohostClient:()=>l,createCohostClient:()=>F});module.exports=M(j);var a=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var p="https://api.cohost.vip/v1";var f=class r extends Error{constructor(t,n){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=n?.errorCode,this.statusCode=n?.statusCode}static fromError(t,n){return new r(t.message,{...n,errorCode:n?.errorCode||t.name})}};var A={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},q={};var I=(r,e)=>{let{pagination:t,...n}=r;return{query:n,pagination:t,...e}},_=r=>{if(!r)return"";let e=new URLSearchParams;for(let[t,n]of Object.entries(r))n!==void 0&&(Array.isArray(n)?n.forEach(s=>e.append(t,String(s))):e.set(t,String(n)));return e.toString()?`?${e.toString()}`:""},R=({token:r,baseUrl:e=p,debug:t=!1})=>async function(n,s={}){let{method:i="GET",data:g,query:T,pagination:E,headers:$={}}=s,w={...T,...E},U=_(w),b=`${q.baseUrl??e}${n}${U}`,O={...A.headers,...q.headers,...$};r&&(O.Authorization=`Bearer ${r}`);let P=g&&i!=="GET"?JSON.stringify(g):void 0;if(t){console.log(`[Cohost SDK] Request: ${i} ${b}`),P&&console.log("[Cohost SDK] Body:",P);let c={};for(let[S,k]of Object.entries(O))if(S.toLowerCase()==="authorization"){let v=k?.split(" ")[1];c[S]="Bearer <token-"+(v?`${v[0]}...${v.slice(-4)}>`:"")}else c[S]=k;console.log("[Cohost SDK] Headers:",c)}let u=await fetch(b,{method:i,headers:O,body:P}),d=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let c=typeof d=="string"?d:JSON.stringify(d);throw console.error(`[Cohost SDK] Error(${u.status}): ${c}`,{url:b}),new f(c||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof d=="object"&&d!==null&&d.status==="ok"&&"data"in d?d.data:d};var y=class extends a{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,I(t))}async search(e){return this.request("/events/search",I(e))}async create(e,t){return this.request("/events",{method:"POST",data:{event:e,context:t}})}async update(e,t,n){return this.request(`/events/${e}`,{method:"PATCH",data:{event:t,context:n}})}async createTickets(e,t,n){let s=Array.isArray(t)?{tickets:t,context:n}:{ticket:t,context:n};return this.request(`/events/${e}/tickets`,{method:"POST",data:s})}async updateTicket(e,t,n,s){return this.request(`/events/${e}/tickets/${t}`,{method:"PATCH",data:{ticket:n,context:s}})}async deleteTicket(e,t){return this.request(`/events/${e}/tickets/${t}`,{method:"DELETE"})}};var C=class extends a{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async attendees(e,t){return this.request(`/orders/${e}/attendees?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}async sendConfirmation(e){return this.request(`/orders/${e}/send-confirmation`,{method:"POST"})}};var h=class extends a{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}async applyCoupon(e,t){return this.request(`/cart/sessions/${e}/coupons`,{method:"POST",data:{code:t}})}async deleteCoupon(e,t){return this.request(`/cart/sessions/${e}/coupons/${t}`,{method:"DELETE"})}};var x=class extends a{async list(e){let t=e?.eventId?`?eventId=${e.eventId}`:"";return this.request(`/coupons${t}`)}async create(e){return this.request("/coupons",{method:"POST",data:e})}async update(e,t){return this.request(`/coupons/${e}`,{method:"PATCH",data:t})}async delete(e){return this.request(`/coupons/${e}`,{method:"DELETE"})}};var l=class r{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"coupons");o(this,"baseOptions");this.baseOptions=e;let{token:n,settings:s={}}=e,i=t??R({token:n,baseUrl:s.apiUrl||p,debug:s.debug});this.events=new y(i,s),this.orders=new C(i,s),this.cart=new h(i,s),this.coupons=new x(i,s)}requestWithOverrides(e){let{token:t,settings:n={}}=this.baseOptions,s=(i,g={})=>R({token:e.token??t,baseUrl:e.baseUrl??n.apiUrl??p,debug:n.debug})(i,{...g,headers:{...e.headers||{},...g.headers||{}}});return new r({token:e.token??t,settings:{...n,apiUrl:e.baseUrl??n.apiUrl}},s)}};function F(r){return new l(r)}0&&(module.exports={CohostClient,createCohostClient});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/apiVersion.ts","../src/error/CohostError.ts","../src/settings.ts","../src/http/request.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/client.ts"],"sourcesContent":["import { CohostClient, CohostClientOptions } from './client';\nexport { type CohostClientSettings } from './settings';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }\n\nexport * from '../types';","import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.vip/v1'","\nexport interface CohostErrorProps {\n /**\n * Optional error code.\n * @default undefined\n */\n errorCode?: string;\n\n /**\n * Optional status code.\n * @default undefined\n */\n statusCode?: number;\n};\n\nexport class CohostError extends Error {\n errorCode: string | undefined;\n statusCode: number | undefined;\n\n /**\n * Custom error class for Cohost SDK errors.\n * @param message - The error message.\n */\n constructor(message: string, props?: CohostErrorProps) {\n // Call the parent constructor with the message\n super(message);\n\n // Set the name of the error to \"CohostError\"\n this.name = \"CohostError\";\n\n // Set the error code if provided\n this.errorCode = props?.errorCode;\n // Set the status code if provided\n this.statusCode = props?.statusCode;\n }\n\n static fromError(err: Error, props?: CohostErrorProps): CohostError {\n // Create a new CohostError instance from an existing error\n return new CohostError(err.message, {\n ...props,\n errorCode: props?.errorCode || err.name,\n });\n }\n\n}\n\n\n\n\n","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { PaginatedRequest } from \"../../types\";\nimport { apiBaseUrl } from \"../apiVersion\";\nimport { CohostError } from \"../error/CohostError\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\nimport { Pagination } from \"../types/pagination\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ntype RequestOptions = {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | string[] | undefined>;\n headers?: Record<string, string>;\n pagination?: Pagination;\n};\n\nexport const paginatedOptions = (req: PaginatedRequest<any>, options?: Partial<RequestOptions>): RequestOptions => {\n const { pagination, ...rest } = req;\n return {\n query: rest,\n pagination,\n ...options,\n };\n};\n\n/**\n * Builds a query string from a flat object, supporting array values via repeated keys.\n */\nconst buildQueryString = (\n input?: Record<string, string | number | boolean | string[] | undefined>\n): string => {\n if (!input) return \"\";\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n value.forEach((v) => params.append(key, String(v)));\n } else {\n params.set(key, String(value));\n }\n }\n return params.toString() ? `?${params.toString()}` : \"\";\n};\n\n/**\n * A function that performs a request to the Cohost API.\n * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: RequestOptions\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, pagination, headers = {} } = options;\n\n const _query = {\n ...query,\n ...pagination,\n };\n\n const queryString = buildQueryString(_query);\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n\n const cleanHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(reqHeaders)) {\n if (key.toLowerCase() === \"authorization\") {\n const tokenValue = value?.split(\" \")[1];\n cleanHeaders[key] = \"Bearer <token-\" + (tokenValue ? `${tokenValue[0]}...${tokenValue.slice(-4)}>` : \"\");\n } else {\n cleanHeaders[key] = value;\n }\n }\n\n console.log(`[Cohost SDK] Headers:`, cleanHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error(${res.status}): ${message}`, { url });\n throw new CohostError(message || res.statusText, {\n errorCode: res.statusText || \"API_ERROR\",\n statusCode: res.status,\n });\n }\n\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n return responseBody as T;\n };\n};\n\nexport { type RequestProps, type RequestFn };\nexport { request };\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { Attendee, EventProfile, PaginatedRequest, PaginatedResponse, Ticket } from '../../types/index';\nimport { paginatedOptions } from '../http/request';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const list = await client.events.list();\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n\n /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request<EventProfile>(`/events/${id}`);\n }\n\n\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request<Ticket[]>(`/events/${id}/tickets`);\n }\n\n /**\n * List attendees in the event.\n *\n * Requires: valid authentication token. This endpoint is not public.\n * \n * @param id - The ID of the event.\n * @returns List of tickets (attendees) for the event.\n */\n async attendees(id: string, filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<Attendee>>(`/events/${id}/attendees`, paginatedOptions(filters));\n }\n\n\n\n async search(filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<EventProfile>>('/events/search', paginatedOptions(filters));\n\n }\n\n\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * const list = await client.orders.list({ status: 'completed' });\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}?uid=${uid}`);\n }\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async attendees(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}/attendees?uid=${uid}`);\n }\n\n /**\n * List orders with optional filters.\n * \n * @param filters - Optional filters to apply when retrieving orders\n * @returns A Promise resolving to an array of order summaries\n * @throws Will throw an error if the request fails\n */\n async list(filters?: {\n status?: string;\n startDate?: string;\n endDate?: string;\n page?: number;\n pageSize?: number;\n }) {\n const query = new URLSearchParams(filters as Record<string, string>).toString();\n return this.request(`/orders${query ? `?${query}` : ''}`);\n }\n}\n","import { CartSession, StartCartSessionInput, UpdatableCartSession } from '../../types';\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: Partial<UpdatableCartSession>) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * \n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n itemId: string;\n quantity: number;\n options?: {\n [key: string]: any;\n };\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n data: props,\n });\n }\n\n /**\n * Pre-validate the cart session for payment and checkout.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for validation\n * @returns {CartSession} The validated cart session\n * \n * @throws Will throw an error if validation fails\n */\n async preValidate(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/pre-validate`, {\n method: 'POST',\n data: data,\n });\n }\n\n\n\n /**\n * Prepare the cart session for payment.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for payment preparation\n * @returns {CartSession} The prepared cart session\n * \n * @throws Will throw an error if preparation fails\n */\n async processPayment(sessionId: string, data: unknown) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/process`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Close the cart session, and place the order.\n * \n * @param sessionId - The ID of the session\n * @param data - Data to place the order\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the order placement fails\n */\n async placeOrder(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/place-order`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId - The ID of the cart session\n * @param itemId - The ID of the item to remove\n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, itemId: string) {\n return this.updateItem(sessionId, {\n itemId,\n quantity: 0,\n });\n }\n\n\n\n\n\n /**\n * Join a table commitment within an active cart session.\n *\n * @param id - The ID of the cart session\n * @param tableCommitmentId - The table commitment ID to join\n * @returns {CartSession} Updated cart session with joined table\n * \n * @throws Will throw an error if the join operation fails\n */\n async joinTableCommitment(id: string, tableCommitmentId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/join-table`, {\n method: 'POST',\n data: {\n tableCommitmentId,\n }\n });\n }\n\n\n /**\n * Apply a coupon code to the cart session.\n *\n * @param id - The ID of the cart session\n * @param code - The coupon code to apply\n * @returns {CartSession} Updated cart session with applied coupon\n * \n * @throws Will throw an error if the coupon application fails\n */\n async applyCoupon(id: string, code: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons`, {\n method: 'POST',\n data: {\n code\n }\n });\n }\n\n /**\n * Find viable table options for a cart session.\n *\n * @param id - The ID of the cart session\n * @param props - Properties to find viable tables\n * @returns {ViableTableOption[]} List of viable table options\n * \n * @throws Will throw an error if the request fails\n */\n async deleteCoupon(id: string, couponId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons/${couponId}`, {\n method: 'DELETE'\n });\n }\n}\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n"],"mappings":"ijBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,uBAAAC,IAAA,eAAAC,EAAAJ,GCOO,IAAMK,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECtBO,IAAME,EAAa,4BCanB,IAAMC,EAAN,MAAMC,UAAoB,KAAM,CAQnC,YAAYC,EAAiBC,EAA0B,CAEnD,MAAMD,CAAO,EATjBE,EAAA,kBACAA,EAAA,mBAWI,KAAK,KAAO,cAGZ,KAAK,UAAYD,GAAO,UAExB,KAAK,WAAaA,GAAO,UAC7B,CAEA,OAAO,UAAUE,EAAYF,EAAuC,CAEhE,OAAO,IAAIF,EAAYI,EAAI,QAAS,CAChC,GAAGF,EACH,UAAWA,GAAO,WAAaE,EAAI,IACvC,CAAC,CACL,CAEJ,EChCO,IAAMC,EAAkB,CAC3B,QAAS,yBACT,QAAS,CACL,eAAgB,kBACpB,CACJ,EAG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AqBO,EAIX,CACf,GAAM,CAAE,MAAAR,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCQ,EAA+B,CAACC,EAAMb,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOK,EAAU,OAASR,EAC1B,QAASQ,EAAU,SAAWP,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAES,EAAM,CACP,GAAGb,EACH,QAAS,CACP,GAAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ETnEO,SAASE,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["index_exports","__export","CohostClient","createCohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","apiBaseUrl","CohostError","_CohostError","message","props","__publicField","err","defaultSettings","runtimeOverrides","paginatedOptions","req","options","pagination","rest","buildQueryString","input","params","key","value","v","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","_query","queryString","url","runtimeOverrides","reqHeaders","defaultSettings","body","cleanHeaders","tokenValue","res","responseBody","message","CohostError","EventsAPI","CohostEndpoint","id","filters","paginatedOptions","OrdersAPI","CohostEndpoint","id","uid","filters","query","SessionsAPI","CohostEndpoint","input","id","sessionId","props","data","itemId","tableCommitmentId","code","couponId","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/apiVersion.ts","../src/error/CohostError.ts","../src/settings.ts","../src/http/request.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/api/coupons.ts","../src/client.ts"],"sourcesContent":["import { CohostClient, CohostClientOptions } from './client';\nexport { type CohostClientSettings } from './settings';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }\nexport { type Coupon } from './api/coupons';\n\nexport * from '../types';","import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.vip/v1'","\nexport interface CohostErrorProps {\n /**\n * Optional error code.\n * @default undefined\n */\n errorCode?: string;\n\n /**\n * Optional status code.\n * @default undefined\n */\n statusCode?: number;\n};\n\nexport class CohostError extends Error {\n errorCode: string | undefined;\n statusCode: number | undefined;\n\n /**\n * Custom error class for Cohost SDK errors.\n * @param message - The error message.\n */\n constructor(message: string, props?: CohostErrorProps) {\n // Call the parent constructor with the message\n super(message);\n\n // Set the name of the error to \"CohostError\"\n this.name = \"CohostError\";\n\n // Set the error code if provided\n this.errorCode = props?.errorCode;\n // Set the status code if provided\n this.statusCode = props?.statusCode;\n }\n\n static fromError(err: Error, props?: CohostErrorProps): CohostError {\n // Create a new CohostError instance from an existing error\n return new CohostError(err.message, {\n ...props,\n errorCode: props?.errorCode || err.name,\n });\n }\n\n}\n\n\n\n\n","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { PaginatedRequest } from \"../../types\";\nimport { apiBaseUrl } from \"../apiVersion\";\nimport { CohostError } from \"../error/CohostError\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\nimport { Pagination } from \"../types/pagination\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ntype RequestOptions = {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | string[] | undefined>;\n headers?: Record<string, string>;\n pagination?: Pagination;\n};\n\nexport const paginatedOptions = (req: PaginatedRequest<any>, options?: Partial<RequestOptions>): RequestOptions => {\n const { pagination, ...rest } = req;\n return {\n query: rest,\n pagination,\n ...options,\n };\n};\n\n/**\n * Builds a query string from a flat object, supporting array values via repeated keys.\n */\nconst buildQueryString = (\n input?: Record<string, string | number | boolean | string[] | undefined>\n): string => {\n if (!input) return \"\";\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n value.forEach((v) => params.append(key, String(v)));\n } else {\n params.set(key, String(value));\n }\n }\n return params.toString() ? `?${params.toString()}` : \"\";\n};\n\n/**\n * A function that performs a request to the Cohost API.\n * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: RequestOptions\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, pagination, headers = {} } = options;\n\n const _query = {\n ...query,\n ...pagination,\n };\n\n const queryString = buildQueryString(_query);\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n\n const cleanHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(reqHeaders)) {\n if (key.toLowerCase() === \"authorization\") {\n const tokenValue = value?.split(\" \")[1];\n cleanHeaders[key] = \"Bearer <token-\" + (tokenValue ? `${tokenValue[0]}...${tokenValue.slice(-4)}>` : \"\");\n } else {\n cleanHeaders[key] = value;\n }\n }\n\n console.log(`[Cohost SDK] Headers:`, cleanHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error(${res.status}): ${message}`, { url });\n throw new CohostError(message || res.statusText, {\n errorCode: res.statusText || \"API_ERROR\",\n statusCode: res.status,\n });\n }\n\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n return responseBody as T;\n };\n};\n\nexport { type RequestProps, type RequestFn };\nexport { request };\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { Attendee, EventProfile, PaginatedRequest, PaginatedResponse, Ticket } from '../../types/index';\nimport { paginatedOptions } from '../http/request';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const list = await client.events.list();\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n\n /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request<EventProfile>(`/events/${id}`);\n }\n\n\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request<Ticket[]>(`/events/${id}/tickets`);\n }\n\n /**\n * List attendees in the event.\n *\n * Requires: valid authentication token. This endpoint is not public.\n * \n * @param id - The ID of the event.\n * @returns List of tickets (attendees) for the event.\n */\n async attendees(id: string, filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<Attendee>>(`/events/${id}/attendees`, paginatedOptions(filters));\n }\n\n\n\n async search(filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<EventProfile>>('/events/search', paginatedOptions(filters));\n }\n\n /**\n * Create a new event.\n *\n * @param event - The event data to create (without id)\n * @param context - Optional context information for event creation\n * @returns A Promise resolving to an object with the created event ID\n * @throws Will throw an error if the request fails or authentication is missing\n *\n * @example\n * ```ts\n * const result = await client.events.create({\n * name: 'Summer Concert',\n * startDate: '2025-07-15T19:00:00Z',\n * venue: { name: 'City Arena' }\n * });\n * console.log(result.id); // 'evt_abc123'\n * ```\n */\n async create(event: Omit<Partial<EventProfile>, 'id'>, context?: any) {\n return this.request<{ id: string }>('/events', {\n method: 'POST',\n data: { event, context }\n });\n }\n\n /**\n * Update an existing event.\n *\n * @param id - The unique identifier of the event to update\n * @param event - Partial event data to update\n * @param context - Optional context information for event update\n * @returns A Promise resolving to an object with the updated event ID\n * @throws Will throw an error if the request fails or event is not found\n *\n * @example\n * ```ts\n * const result = await client.events.update('evt_abc123', {\n * name: 'Summer Concert - Updated',\n * capacity: 5000\n * });\n * ```\n */\n async update(id: string, event: Partial<EventProfile>, context?: any) {\n return this.request<{ id: string }>(`/events/${id}`, {\n method: 'PATCH',\n data: { event, context }\n });\n }\n\n /**\n * Create one or more tickets for an event.\n *\n * @param eventId - The unique identifier of the event\n * @param tickets - Single ticket or array of tickets to create\n * @param context - Optional context information for ticket creation\n * @returns A Promise resolving to an object mapping reference IDs to created ticket IDs\n * @throws Will throw an error if the request fails or validation fails\n *\n * @example\n * ```ts\n * // Create single ticket\n * const result = await client.events.createTickets('evt_abc123', {\n * name: 'General Admission',\n * price: 50,\n * currency: 'USD',\n * quantity: 100\n * });\n *\n * // Create multiple tickets\n * const result = await client.events.createTickets('evt_abc123', [\n * { name: 'VIP', price: 150, quantity: 20 },\n * { name: 'Early Bird', price: 40, quantity: 50 }\n * ]);\n * ```\n */\n async createTickets(eventId: string, tickets: Partial<Ticket> | Partial<Ticket>[], context?: any) {\n const data = Array.isArray(tickets)\n ? { tickets, context }\n : { ticket: tickets, context };\n\n return this.request<{ ids: Record<string, string> }>(`/events/${eventId}/tickets`, {\n method: 'POST',\n data\n });\n }\n\n /**\n * Update an existing ticket.\n *\n * @param eventId - The unique identifier of the event\n * @param ticketId - The unique identifier of the ticket to update\n * @param ticket - Partial ticket data to update\n * @param context - Optional context information for ticket update\n * @returns A Promise resolving to the updated ticket\n * @throws Will throw an error if the request fails or ticket is not found\n *\n * @example\n * ```ts\n * const result = await client.events.updateTicket('evt_abc123', 'tkt_xyz789', {\n * price: 55,\n * quantity: 120\n * });\n * ```\n */\n async updateTicket(eventId: string, ticketId: string, ticket: Partial<Ticket>, context?: any) {\n return this.request<Ticket>(`/events/${eventId}/tickets/${ticketId}`, {\n method: 'PATCH',\n data: { ticket, context }\n });\n }\n\n /**\n * Delete a ticket from an event.\n *\n * @param eventId - The unique identifier of the event\n * @param ticketId - The unique identifier of the ticket to delete\n * @returns A Promise resolving when the ticket is deleted (no content)\n * @throws Will throw an error if the request fails or ticket is not found\n *\n * @example\n * ```ts\n * await client.events.deleteTicket('evt_abc123', 'tkt_xyz789');\n * ```\n */\n async deleteTicket(eventId: string, ticketId: string) {\n return this.request<void>(`/events/${eventId}/tickets/${ticketId}`, {\n method: 'DELETE'\n });\n }\n\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * const list = await client.orders.list({ status: 'completed' });\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}?uid=${uid}`);\n }\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async attendees(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}/attendees?uid=${uid}`);\n }\n\n /**\n * List orders with optional filters.\n * \n * @param filters - Optional filters to apply when retrieving orders\n * @returns A Promise resolving to an array of order summaries\n * @throws Will throw an error if the request fails\n */\n async list(filters?: {\n status?: string;\n startDate?: string;\n endDate?: string;\n page?: number;\n pageSize?: number;\n }) {\n const query = new URLSearchParams(filters as Record<string, string>).toString();\n return this.request(`/orders${query ? `?${query}` : ''}`);\n }\n\n /**\n * Send order confirmation email to customer.\n *\n * @param id - The unique identifier of the order\n * @returns A Promise resolving to the confirmation response\n * @throws Will throw an error if the request fails or order is not found\n *\n * @example\n * ```ts\n * const result = await client.orders.sendConfirmation('ord_abc123');\n * console.log(result.response); // Confirmation sent status\n * ```\n */\n async sendConfirmation(id: string) {\n return this.request<{ response: any }>(`/orders/${id}/send-confirmation`, {\n method: 'POST'\n });\n }\n}\n","import { CartSession, StartCartSessionInput, UpdatableCartSession } from '../../types';\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: Partial<UpdatableCartSession>) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * \n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n itemId: string;\n quantity: number;\n options?: {\n [key: string]: any;\n };\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n data: props,\n });\n }\n\n /**\n * Pre-validate the cart session for payment and checkout.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for validation\n * @returns {CartSession} The validated cart session\n * \n * @throws Will throw an error if validation fails\n */\n async preValidate(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/pre-validate`, {\n method: 'POST',\n data: data,\n });\n }\n\n\n\n /**\n * Prepare the cart session for payment.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for payment preparation\n * @returns {CartSession} The prepared cart session\n * \n * @throws Will throw an error if preparation fails\n */\n async processPayment(sessionId: string, data: unknown) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/process`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Close the cart session, and place the order.\n * \n * @param sessionId - The ID of the session\n * @param data - Data to place the order\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the order placement fails\n */\n async placeOrder(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/place-order`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId - The ID of the cart session\n * @param itemId - The ID of the item to remove\n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, itemId: string) {\n return this.updateItem(sessionId, {\n itemId,\n quantity: 0,\n });\n }\n\n\n\n\n\n /**\n * Join a table commitment within an active cart session.\n *\n * @param id - The ID of the cart session\n * @param tableCommitmentId - The table commitment ID to join\n * @returns {CartSession} Updated cart session with joined table\n * \n * @throws Will throw an error if the join operation fails\n */\n async joinTableCommitment(id: string, tableCommitmentId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/join-table`, {\n method: 'POST',\n data: {\n tableCommitmentId,\n }\n });\n }\n\n\n /**\n * Apply a coupon code to the cart session.\n *\n * @param id - The ID of the cart session\n * @param code - The coupon code to apply\n * @returns {CartSession} Updated cart session with applied coupon\n * \n * @throws Will throw an error if the coupon application fails\n */\n async applyCoupon(id: string, code: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons`, {\n method: 'POST',\n data: {\n code\n }\n });\n }\n\n /**\n * Find viable table options for a cart session.\n *\n * @param id - The ID of the cart session\n * @param props - Properties to find viable tables\n * @returns {ViableTableOption[]} List of viable table options\n * \n * @throws Will throw an error if the request fails\n */\n async deleteCoupon(id: string, couponId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons/${couponId}`, {\n method: 'DELETE'\n });\n }\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Coupon interface for the Cohost API\n */\nexport interface Coupon {\n id: string;\n code: string;\n discountType: 'percentage' | 'fixed';\n discountValue: number;\n maxUses?: number;\n usedCount?: number;\n expiresAt?: string;\n companyId: string;\n eventId?: string;\n status?: 'active' | 'inactive' | 'expired';\n created?: string;\n updated?: string;\n}\n\n/**\n * Provides methods to interact with the Cohost Coupons API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const coupons = await client.coupons.list();\n * const coupon = await client.coupons.create({ code: 'SUMMER2025', discountType: 'percentage', discountValue: 20 });\n * ```\n */\nexport class CouponsAPI extends CohostEndpoint {\n\n /**\n * List all coupons for the authenticated company.\n *\n * @param filters - Optional filters to apply when retrieving coupons\n * @returns A Promise resolving to an array of coupon objects\n * @throws Will throw an error if the request fails\n *\n * @example\n * ```ts\n * // List all coupons\n * const allCoupons = await client.coupons.list();\n *\n * // List coupons for specific event\n * const eventCoupons = await client.coupons.list({ eventId: 'evt_abc123' });\n * ```\n */\n async list(filters?: { eventId?: string }) {\n const query = filters?.eventId ? `?eventId=${filters.eventId}` : '';\n return this.request<Coupon[]>(`/coupons${query}`);\n }\n\n /**\n * Create a new coupon.\n *\n * @param coupon - The coupon data to create\n * @returns A Promise resolving to the created coupon object\n * @throws Will throw an error if the request fails or validation fails\n *\n * @example\n * ```ts\n * const coupon = await client.coupons.create({\n * code: 'SUMMER2025',\n * discountType: 'percentage',\n * discountValue: 20,\n * maxUses: 100,\n * expiresAt: '2025-08-31T23:59:59Z'\n * });\n * ```\n */\n async create(coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>) {\n return this.request<Coupon>('/coupons', {\n method: 'POST',\n data: coupon\n });\n }\n\n /**\n * Update an existing coupon.\n *\n * @param id - The unique identifier of the coupon to update\n * @param coupon - Partial coupon data to update\n * @returns A Promise resolving to the updated coupon object\n * @throws Will throw an error if the request fails or coupon is not found\n *\n * @example\n * ```ts\n * const updated = await client.coupons.update('cpn_xyz789', {\n * discountValue: 25,\n * maxUses: 150\n * });\n * ```\n */\n async update(id: string, coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>) {\n return this.request<Coupon>(`/coupons/${id}`, {\n method: 'PATCH',\n data: coupon\n });\n }\n\n /**\n * Delete a coupon.\n *\n * @param id - The unique identifier of the coupon to delete\n * @returns A Promise resolving when the coupon is deleted\n * @throws Will throw an error if the request fails or coupon is not found\n *\n * @example\n * ```ts\n * await client.coupons.delete('cpn_xyz789');\n * ```\n */\n async delete(id: string) {\n return this.request<void>(`/coupons/${id}`, {\n method: 'DELETE'\n });\n }\n}\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\nimport { CouponsAPI } from './api/coupons';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n public readonly coupons: CouponsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n this.cart = new SessionsAPI(sharedRequest, settings);\n this.coupons = new CouponsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n"],"mappings":"ijBA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AAIY,EAAU,SAAW,CAAC,EAC1B,GAAIZ,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOa,EAAU,OAAST,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQQ,EAAU,SAAWR,EAAS,MACxC,CACF,EACAS,CACF,CACF,CACF,EVtEO,SAASE,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["index_exports","__export","CohostClient","createCohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","apiBaseUrl","CohostError","_CohostError","message","props","__publicField","err","defaultSettings","runtimeOverrides","paginatedOptions","req","options","pagination","rest","buildQueryString","input","params","key","value","v","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","_query","queryString","url","runtimeOverrides","reqHeaders","defaultSettings","body","cleanHeaders","tokenValue","res","responseBody","message","CohostError","EventsAPI","CohostEndpoint","id","filters","paginatedOptions","event","context","eventId","tickets","data","ticketId","ticket","OrdersAPI","CohostEndpoint","id","uid","filters","query","SessionsAPI","CohostEndpoint","input","id","sessionId","props","data","itemId","tableCommitmentId","code","couponId","CouponsAPI","CohostEndpoint","filters","query","coupon","id","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","CouponsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var U=Object.defineProperty;var D=(n,e,t)=>e in n?U(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>D(n,typeof e!="symbol"?e+"":e,t);var a=class{constructor(e,t){o(this,"request");o(this,"settings");this.request=e,this.settings=t}};var p="https://api.cohost.vip/v1";var l=class n extends Error{constructor(t,r){super(t);o(this,"errorCode");o(this,"statusCode");this.name="CohostError",this.errorCode=r?.errorCode,this.statusCode=r?.statusCode}static fromError(t,r){return new n(t.message,{...r,errorCode:r?.errorCode||t.name})}};var k={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},v={};var q=(n,e)=>{let{pagination:t,...r}=n;return{query:r,pagination:t,...e}},z=n=>{if(!n)return"";let e=new URLSearchParams;for(let[t,r]of Object.entries(n))r!==void 0&&(Array.isArray(r)?r.forEach(s=>e.append(t,String(s))):e.set(t,String(r)));return e.toString()?`?${e.toString()}`:""},I=({token:n,baseUrl:e=p,debug:t=!1})=>async function(r,s={}){let{method:i="GET",data:g,query:A,pagination:T,headers:E={}}=s,$={...A,...T},w=z($),x=`${v.baseUrl??e}${r}${w}`,b={...k.headers,...v.headers,...E};n&&(b.Authorization=`Bearer ${n}`);let O=g&&i!=="GET"?JSON.stringify(g):void 0;if(t){console.log(`[Cohost SDK] Request: ${i} ${x}`),O&&console.log("[Cohost SDK] Body:",O);let c={};for(let[P,R]of Object.entries(b))if(P.toLowerCase()==="authorization"){let S=R?.split(" ")[1];c[P]="Bearer <token-"+(S?`${S[0]}...${S.slice(-4)}>`:"")}else c[P]=R;console.log("[Cohost SDK] Headers:",c)}let u=await fetch(x,{method:i,headers:b,body:O}),d=u.headers.get("content-type")?.includes("application/json")?await u.json():await u.text();if(!u.ok){let c=typeof d=="string"?d:JSON.stringify(d);throw console.error(`[Cohost SDK] Error(${u.status}): ${c}`,{url:x}),new l(c||u.statusText,{errorCode:u.statusText||"API_ERROR",statusCode:u.status})}return typeof d=="object"&&d!==null&&d.status==="ok"&&"data"in d?d.data:d};var m=class extends a{async list(){return this.request("/events")}async fetch(e){return this.request(`/events/${e}`)}async tickets(e){return this.request(`/events/${e}/tickets`)}async attendees(e,t){return this.request(`/events/${e}/attendees`,q(t))}async search(e){return this.request("/events/search",q(e))}async create(e,t){return this.request("/events",{method:"POST",data:{event:e,context:t}})}async update(e,t,r){return this.request(`/events/${e}`,{method:"PATCH",data:{event:t,context:r}})}async createTickets(e,t,r){let s=Array.isArray(t)?{tickets:t,context:r}:{ticket:t,context:r};return this.request(`/events/${e}/tickets`,{method:"POST",data:s})}async updateTicket(e,t,r,s){return this.request(`/events/${e}/tickets/${t}`,{method:"PATCH",data:{ticket:r,context:s}})}async deleteTicket(e,t){return this.request(`/events/${e}/tickets/${t}`,{method:"DELETE"})}};var f=class extends a{async fetch(e,t){return this.request(`/orders/${e}?uid=${t}`)}async attendees(e,t){return this.request(`/orders/${e}/attendees?uid=${t}`)}async list(e){let t=new URLSearchParams(e).toString();return this.request(`/orders${t?`?${t}`:""}`)}async sendConfirmation(e){return this.request(`/orders/${e}/send-confirmation`,{method:"POST"})}};var y=class extends a{async start(e){return this.request("/cart/sessions",{method:"POST",data:e})}async get(e){return this.request(`/cart/sessions/${e}`)}async update(e,t){return this.request(`/cart/sessions/${e}`,{method:"PATCH",data:t})}async cancel(e){return this.request(`/cart/sessions/${e}`,{method:"DELETE"})}async updateItem(e,t){return this.request(`/cart/sessions/${e}/item`,{method:"POST",data:t})}async preValidate(e,t){return this.request(`/cart/sessions/${e}/payment/pre-validate`,{method:"POST",data:t})}async processPayment(e,t){return this.request(`/cart/sessions/${e}/payment/process`,{method:"POST",data:t})}async placeOrder(e,t){return this.request(`/cart/sessions/${e}/place-order`,{method:"POST",data:t})}async deleteItem(e,t){return this.updateItem(e,{itemId:t,quantity:0})}async joinTableCommitment(e,t){return this.request(`/cart/sessions/${e}/join-table`,{method:"POST",data:{tableCommitmentId:t}})}async applyCoupon(e,t){return this.request(`/cart/sessions/${e}/coupons`,{method:"POST",data:{code:t}})}async deleteCoupon(e,t){return this.request(`/cart/sessions/${e}/coupons/${t}`,{method:"DELETE"})}};var C=class extends a{async list(e){let t=e?.eventId?`?eventId=${e.eventId}`:"";return this.request(`/coupons${t}`)}async create(e){return this.request("/coupons",{method:"POST",data:e})}async update(e,t){return this.request(`/coupons/${e}`,{method:"PATCH",data:t})}async delete(e){return this.request(`/coupons/${e}`,{method:"DELETE"})}};var h=class n{constructor(e,t){o(this,"events");o(this,"orders");o(this,"cart");o(this,"coupons");o(this,"baseOptions");this.baseOptions=e;let{token:r,settings:s={}}=e,i=t??I({token:r,baseUrl:s.apiUrl||p,debug:s.debug});this.events=new m(i,s),this.orders=new f(i,s),this.cart=new y(i,s),this.coupons=new C(i,s)}requestWithOverrides(e){let{token:t,settings:r={}}=this.baseOptions,s=(i,g={})=>I({token:e.token??t,baseUrl:e.baseUrl??r.apiUrl??p,debug:r.debug})(i,{...g,headers:{...e.headers||{},...g.headers||{}}});return new n({token:e.token??t,settings:{...r,apiUrl:e.baseUrl??r.apiUrl}},s)}};function ye(n){return new h(n)}export{h as CohostClient,ye as createCohostClient};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/endpoint.ts","../src/apiVersion.ts","../src/error/CohostError.ts","../src/settings.ts","../src/http/request.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.vip/v1'","\nexport interface CohostErrorProps {\n /**\n * Optional error code.\n * @default undefined\n */\n errorCode?: string;\n\n /**\n * Optional status code.\n * @default undefined\n */\n statusCode?: number;\n};\n\nexport class CohostError extends Error {\n errorCode: string | undefined;\n statusCode: number | undefined;\n\n /**\n * Custom error class for Cohost SDK errors.\n * @param message - The error message.\n */\n constructor(message: string, props?: CohostErrorProps) {\n // Call the parent constructor with the message\n super(message);\n\n // Set the name of the error to \"CohostError\"\n this.name = \"CohostError\";\n\n // Set the error code if provided\n this.errorCode = props?.errorCode;\n // Set the status code if provided\n this.statusCode = props?.statusCode;\n }\n\n static fromError(err: Error, props?: CohostErrorProps): CohostError {\n // Create a new CohostError instance from an existing error\n return new CohostError(err.message, {\n ...props,\n errorCode: props?.errorCode || err.name,\n });\n }\n\n}\n\n\n\n\n","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { PaginatedRequest } from \"../../types\";\nimport { apiBaseUrl } from \"../apiVersion\";\nimport { CohostError } from \"../error/CohostError\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\nimport { Pagination } from \"../types/pagination\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ntype RequestOptions = {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | string[] | undefined>;\n headers?: Record<string, string>;\n pagination?: Pagination;\n};\n\nexport const paginatedOptions = (req: PaginatedRequest<any>, options?: Partial<RequestOptions>): RequestOptions => {\n const { pagination, ...rest } = req;\n return {\n query: rest,\n pagination,\n ...options,\n };\n};\n\n/**\n * Builds a query string from a flat object, supporting array values via repeated keys.\n */\nconst buildQueryString = (\n input?: Record<string, string | number | boolean | string[] | undefined>\n): string => {\n if (!input) return \"\";\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n value.forEach((v) => params.append(key, String(v)));\n } else {\n params.set(key, String(value));\n }\n }\n return params.toString() ? `?${params.toString()}` : \"\";\n};\n\n/**\n * A function that performs a request to the Cohost API.\n * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: RequestOptions\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, pagination, headers = {} } = options;\n\n const _query = {\n ...query,\n ...pagination,\n };\n\n const queryString = buildQueryString(_query);\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n\n const cleanHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(reqHeaders)) {\n if (key.toLowerCase() === \"authorization\") {\n const tokenValue = value?.split(\" \")[1];\n cleanHeaders[key] = \"Bearer <token-\" + (tokenValue ? `${tokenValue[0]}...${tokenValue.slice(-4)}>` : \"\");\n } else {\n cleanHeaders[key] = value;\n }\n }\n\n console.log(`[Cohost SDK] Headers:`, cleanHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error(${res.status}): ${message}`, { url });\n throw new CohostError(message || res.statusText, {\n errorCode: res.statusText || \"API_ERROR\",\n statusCode: res.status,\n });\n }\n\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n return responseBody as T;\n };\n};\n\nexport { type RequestProps, type RequestFn };\nexport { request };\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { Attendee, EventProfile, PaginatedRequest, PaginatedResponse, Ticket } from '../../types/index';\nimport { paginatedOptions } from '../http/request';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const list = await client.events.list();\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n\n /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request<EventProfile>(`/events/${id}`);\n }\n\n\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request<Ticket[]>(`/events/${id}/tickets`);\n }\n\n /**\n * List attendees in the event.\n *\n * Requires: valid authentication token. This endpoint is not public.\n * \n * @param id - The ID of the event.\n * @returns List of tickets (attendees) for the event.\n */\n async attendees(id: string, filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<Attendee>>(`/events/${id}/attendees`, paginatedOptions(filters));\n }\n\n\n\n async search(filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<EventProfile>>('/events/search', paginatedOptions(filters));\n\n }\n\n\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * const list = await client.orders.list({ status: 'completed' });\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}?uid=${uid}`);\n }\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async attendees(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}/attendees?uid=${uid}`);\n }\n\n /**\n * List orders with optional filters.\n * \n * @param filters - Optional filters to apply when retrieving orders\n * @returns A Promise resolving to an array of order summaries\n * @throws Will throw an error if the request fails\n */\n async list(filters?: {\n status?: string;\n startDate?: string;\n endDate?: string;\n page?: number;\n pageSize?: number;\n }) {\n const query = new URLSearchParams(filters as Record<string, string>).toString();\n return this.request(`/orders${query ? `?${query}` : ''}`);\n }\n}\n","import { CartSession, StartCartSessionInput, UpdatableCartSession } from '../../types';\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: Partial<UpdatableCartSession>) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * \n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n itemId: string;\n quantity: number;\n options?: {\n [key: string]: any;\n };\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n data: props,\n });\n }\n\n /**\n * Pre-validate the cart session for payment and checkout.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for validation\n * @returns {CartSession} The validated cart session\n * \n * @throws Will throw an error if validation fails\n */\n async preValidate(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/pre-validate`, {\n method: 'POST',\n data: data,\n });\n }\n\n\n\n /**\n * Prepare the cart session for payment.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for payment preparation\n * @returns {CartSession} The prepared cart session\n * \n * @throws Will throw an error if preparation fails\n */\n async processPayment(sessionId: string, data: unknown) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/process`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Close the cart session, and place the order.\n * \n * @param sessionId - The ID of the session\n * @param data - Data to place the order\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the order placement fails\n */\n async placeOrder(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/place-order`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId - The ID of the cart session\n * @param itemId - The ID of the item to remove\n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, itemId: string) {\n return this.updateItem(sessionId, {\n itemId,\n quantity: 0,\n });\n }\n\n\n\n\n\n /**\n * Join a table commitment within an active cart session.\n *\n * @param id - The ID of the cart session\n * @param tableCommitmentId - The table commitment ID to join\n * @returns {CartSession} Updated cart session with joined table\n * \n * @throws Will throw an error if the join operation fails\n */\n async joinTableCommitment(id: string, tableCommitmentId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/join-table`, {\n method: 'POST',\n data: {\n tableCommitmentId,\n }\n });\n }\n\n\n /**\n * Apply a coupon code to the cart session.\n *\n * @param id - The ID of the cart session\n * @param code - The coupon code to apply\n * @returns {CartSession} Updated cart session with applied coupon\n * \n * @throws Will throw an error if the coupon application fails\n */\n async applyCoupon(id: string, code: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons`, {\n method: 'POST',\n data: {\n code\n }\n });\n }\n\n /**\n * Find viable table options for a cart session.\n *\n * @param id - The ID of the cart session\n * @param props - Properties to find viable tables\n * @returns {ViableTableOption[]} List of viable table options\n * \n * @throws Will throw an error if the request fails\n */\n async deleteCoupon(id: string, couponId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons/${couponId}`, {\n method: 'DELETE'\n });\n }\n}\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n this.cart = new SessionsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n","import { CohostClient, CohostClientOptions } from './client';\nexport { type CohostClientSettings } from './settings';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }\n\nexport * from '../types';"],"mappings":"oKAOO,IAAMA,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECtBO,IAAME,EAAa,4BCanB,IAAMC,EAAN,MAAMC,UAAoB,KAAM,CAQnC,YAAYC,EAAiBC,EAA0B,CAEnD,MAAMD,CAAO,EATjBE,EAAA,kBACAA,EAAA,mBAWI,KAAK,KAAO,cAGZ,KAAK,UAAYD,GAAO,UAExB,KAAK,WAAaA,GAAO,UAC7B,CAEA,OAAO,UAAUE,EAAYF,EAAuC,CAEhE,OAAO,IAAIF,EAAYI,EAAI,QAAS,CAChC,GAAGF,EACH,UAAWA,GAAO,WAAaE,EAAI,IACvC,CAAC,CACL,CAEJ,EChCO,IAAMC,EAAkB,CAC3B,QAAS,yBACT,QAAS,CACL,eAAgB,kBACpB,CACJ,EAGWC,EAGP,CAAC,ECUE,IAAMC,EAAmB,CAACC,EAA4BC,IAAsD,CACjH,GAAM,CAAE,WAAAC,EAAY,GAAGC,CAAK,EAAIH,EAChC,MAAO,CACL,MAAOG,EACP,WAAAD,EACA,GAAGD,CACL,CACF,EAKMG,EACJC,GACW,CACX,GAAI,CAACA,EAAO,MAAO,GAEnB,IAAMC,EAAS,IAAI,gBACnB,OAAW,CAACC,EAAKC,CAAK,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AAIW,EAAU,SAAW,CAAC,EAC1B,GAAIX,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOY,EAAU,OAASR,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQO,EAAU,SAAWP,EAAS,MACxC,CACF,EACAQ,CACF,CACF,CACF,ECnEO,SAASE,GAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","apiBaseUrl","CohostError","_CohostError","message","props","__publicField","err","defaultSettings","runtimeOverrides","paginatedOptions","req","options","pagination","rest","buildQueryString","input","params","key","value","v","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","_query","queryString","url","runtimeOverrides","reqHeaders","defaultSettings","body","cleanHeaders","tokenValue","res","responseBody","message","CohostError","EventsAPI","CohostEndpoint","id","filters","paginatedOptions","OrdersAPI","CohostEndpoint","id","uid","filters","query","SessionsAPI","CohostEndpoint","input","id","sessionId","props","data","itemId","tableCommitmentId","code","couponId","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoint.ts","../src/apiVersion.ts","../src/error/CohostError.ts","../src/settings.ts","../src/http/request.ts","../src/api/events.ts","../src/api/orders.ts","../src/api/sessions.ts","../src/api/coupons.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["import { RequestFn } from \"./http/request\";\nimport { CohostClientSettings } from \"./settings\";\n\n/**\n * Base class for all API endpoint groups within the Cohost SDK.\n * Provides shared access to the configured request function and settings.\n */\nexport class CohostEndpoint {\n /** Shared request function injected from the client */\n protected request: RequestFn;\n\n /** Client settings passed during instantiation */\n protected settings: CohostClientSettings;\n\n /**\n * Constructs a new endpoint group.\n *\n * @param request - The shared request function for performing API calls\n * @param settings - The client-wide settings passed from the parent client\n */\n constructor(request: RequestFn, settings: CohostClientSettings) {\n this.request = request;\n this.settings = settings;\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.vip/v1'","\nexport interface CohostErrorProps {\n /**\n * Optional error code.\n * @default undefined\n */\n errorCode?: string;\n\n /**\n * Optional status code.\n * @default undefined\n */\n statusCode?: number;\n};\n\nexport class CohostError extends Error {\n errorCode: string | undefined;\n statusCode: number | undefined;\n\n /**\n * Custom error class for Cohost SDK errors.\n * @param message - The error message.\n */\n constructor(message: string, props?: CohostErrorProps) {\n // Call the parent constructor with the message\n super(message);\n\n // Set the name of the error to \"CohostError\"\n this.name = \"CohostError\";\n\n // Set the error code if provided\n this.errorCode = props?.errorCode;\n // Set the status code if provided\n this.statusCode = props?.statusCode;\n }\n\n static fromError(err: Error, props?: CohostErrorProps): CohostError {\n // Create a new CohostError instance from an existing error\n return new CohostError(err.message, {\n ...props,\n errorCode: props?.errorCode || err.name,\n });\n }\n\n}\n\n\n\n\n","/**\n * Optional settings for customizing the behavior of the CohostClient.\n */\nexport interface CohostClientSettings {\n /** Enable verbose debug output for all API requests. */\n debug?: boolean;\n\n /** Override the default API base URL (defaults to apiBaseUrl). */\n apiUrl?: string;\n}\n\n// settings.ts\nexport const defaultSettings = {\n baseUrl: 'https://api.cohost.vip',\n headers: {\n 'Content-Type': 'application/json',\n },\n};\n\n// In dev or testing, you can override this in the browser or Node\nexport let runtimeOverrides: {\n baseUrl?: string;\n headers?: Record<string, string>;\n} = {};\n\nexport function setSdkOverrides(overrides: typeof runtimeOverrides) {\n runtimeOverrides = overrides;\n}\n\n","import { PaginatedRequest } from \"../../types\";\nimport { apiBaseUrl } from \"../apiVersion\";\nimport { CohostError } from \"../error/CohostError\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\nimport { Pagination } from \"../types/pagination\";\n\n/**\n * Options for configuring the request handler.\n */\ninterface RequestProps {\n /** API token for authentication (Bearer token). */\n token: string | null;\n\n /** Base URL of the API (defaults to versioned `apiBaseUrl`). */\n baseUrl?: string;\n\n /** Enable debug logging of requests/responses. */\n debug?: boolean;\n}\n\n/**\n * Supported HTTP methods.\n */\ntype RequestMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\ntype RequestOptions = {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | string[] | undefined>;\n headers?: Record<string, string>;\n pagination?: Pagination;\n};\n\nexport const paginatedOptions = (req: PaginatedRequest<any>, options?: Partial<RequestOptions>): RequestOptions => {\n const { pagination, ...rest } = req;\n return {\n query: rest,\n pagination,\n ...options,\n };\n};\n\n/**\n * Builds a query string from a flat object, supporting array values via repeated keys.\n */\nconst buildQueryString = (\n input?: Record<string, string | number | boolean | string[] | undefined>\n): string => {\n if (!input) return \"\";\n\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined) continue;\n if (Array.isArray(value)) {\n value.forEach((v) => params.append(key, String(v)));\n } else {\n params.set(key, String(value));\n }\n }\n return params.toString() ? `?${params.toString()}` : \"\";\n};\n\n/**\n * A function that performs a request to the Cohost API.\n * The generic <T> allows you to specify the expected response type.\n */\ntype RequestFn = <T = any>(\n path: string,\n options?: RequestOptions\n) => Promise<T>;\n\n/**\n * Creates a request function configured with authentication and client defaults.\n * The returned function supports generic return typing via <T>.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async function <T = any>(\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, pagination, headers = {} } = options;\n\n const _query = {\n ...query,\n ...pagination,\n };\n\n const queryString = buildQueryString(_query);\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n\n const cleanHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(reqHeaders)) {\n if (key.toLowerCase() === \"authorization\") {\n const tokenValue = value?.split(\" \")[1];\n cleanHeaders[key] = \"Bearer <token-\" + (tokenValue ? `${tokenValue[0]}...${tokenValue.slice(-4)}>` : \"\");\n } else {\n cleanHeaders[key] = value;\n }\n }\n\n console.log(`[Cohost SDK] Headers:`, cleanHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n console.error(`[Cohost SDK] Error(${res.status}): ${message}`, { url });\n throw new CohostError(message || res.statusText, {\n errorCode: res.statusText || \"API_ERROR\",\n statusCode: res.status,\n });\n }\n\n if (\n typeof responseBody === \"object\" &&\n responseBody !== null &&\n (responseBody as any).status === \"ok\" &&\n \"data\" in responseBody\n ) {\n return (responseBody as { data: T }).data;\n }\n\n return responseBody as T;\n };\n};\n\nexport { type RequestProps, type RequestFn };\nexport { request };\n","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { Attendee, EventProfile, PaginatedRequest, PaginatedResponse, Ticket } from '../../types/index';\nimport { paginatedOptions } from '../http/request';\n\n/**\n * Provides methods to interact with the Cohost Events API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const list = await client.events.list();\n * const event = await client.events.fetch('event-id');\n * const tickets = await client.events.tickets('event-id');\n * ```\n */\nexport class EventsAPI extends CohostEndpoint {\n\n /**\n * Fetch a list of all events.\n * \n * @returns A Promise resolving to an array of event objects\n * @throws Will throw an error if the request fails\n * \n * @todo Implement pagination and filtering options\n */\n async list() {\n return this.request<EventProfile[]>('/events');\n }\n\n\n /**\n * Fetch a single event by ID.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to the event object\n * @throws Will throw an error if the request fails or the event is not found\n */\n async fetch(id: string) {\n return this.request<EventProfile>(`/events/${id}`);\n }\n\n\n\n /**\n * List all tickets associated with a specific event.\n * \n * @param id - The unique identifier of the event\n * @returns A Promise resolving to an array of ticket objects\n * @throws Will throw an error if the request fails or the event does not exist\n */\n async tickets(id: string) {\n return this.request<Ticket[]>(`/events/${id}/tickets`);\n }\n\n /**\n * List attendees in the event.\n *\n * Requires: valid authentication token. This endpoint is not public.\n * \n * @param id - The ID of the event.\n * @returns List of tickets (attendees) for the event.\n */\n async attendees(id: string, filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<Attendee>>(`/events/${id}/attendees`, paginatedOptions(filters));\n }\n\n\n\n async search(filters?: PaginatedRequest<any>) {\n return this.request<PaginatedResponse<EventProfile>>('/events/search', paginatedOptions(filters));\n }\n\n /**\n * Create a new event.\n *\n * @param event - The event data to create (without id)\n * @param context - Optional context information for event creation\n * @returns A Promise resolving to an object with the created event ID\n * @throws Will throw an error if the request fails or authentication is missing\n *\n * @example\n * ```ts\n * const result = await client.events.create({\n * name: 'Summer Concert',\n * startDate: '2025-07-15T19:00:00Z',\n * venue: { name: 'City Arena' }\n * });\n * console.log(result.id); // 'evt_abc123'\n * ```\n */\n async create(event: Omit<Partial<EventProfile>, 'id'>, context?: any) {\n return this.request<{ id: string }>('/events', {\n method: 'POST',\n data: { event, context }\n });\n }\n\n /**\n * Update an existing event.\n *\n * @param id - The unique identifier of the event to update\n * @param event - Partial event data to update\n * @param context - Optional context information for event update\n * @returns A Promise resolving to an object with the updated event ID\n * @throws Will throw an error if the request fails or event is not found\n *\n * @example\n * ```ts\n * const result = await client.events.update('evt_abc123', {\n * name: 'Summer Concert - Updated',\n * capacity: 5000\n * });\n * ```\n */\n async update(id: string, event: Partial<EventProfile>, context?: any) {\n return this.request<{ id: string }>(`/events/${id}`, {\n method: 'PATCH',\n data: { event, context }\n });\n }\n\n /**\n * Create one or more tickets for an event.\n *\n * @param eventId - The unique identifier of the event\n * @param tickets - Single ticket or array of tickets to create\n * @param context - Optional context information for ticket creation\n * @returns A Promise resolving to an object mapping reference IDs to created ticket IDs\n * @throws Will throw an error if the request fails or validation fails\n *\n * @example\n * ```ts\n * // Create single ticket\n * const result = await client.events.createTickets('evt_abc123', {\n * name: 'General Admission',\n * price: 50,\n * currency: 'USD',\n * quantity: 100\n * });\n *\n * // Create multiple tickets\n * const result = await client.events.createTickets('evt_abc123', [\n * { name: 'VIP', price: 150, quantity: 20 },\n * { name: 'Early Bird', price: 40, quantity: 50 }\n * ]);\n * ```\n */\n async createTickets(eventId: string, tickets: Partial<Ticket> | Partial<Ticket>[], context?: any) {\n const data = Array.isArray(tickets)\n ? { tickets, context }\n : { ticket: tickets, context };\n\n return this.request<{ ids: Record<string, string> }>(`/events/${eventId}/tickets`, {\n method: 'POST',\n data\n });\n }\n\n /**\n * Update an existing ticket.\n *\n * @param eventId - The unique identifier of the event\n * @param ticketId - The unique identifier of the ticket to update\n * @param ticket - Partial ticket data to update\n * @param context - Optional context information for ticket update\n * @returns A Promise resolving to the updated ticket\n * @throws Will throw an error if the request fails or ticket is not found\n *\n * @example\n * ```ts\n * const result = await client.events.updateTicket('evt_abc123', 'tkt_xyz789', {\n * price: 55,\n * quantity: 120\n * });\n * ```\n */\n async updateTicket(eventId: string, ticketId: string, ticket: Partial<Ticket>, context?: any) {\n return this.request<Ticket>(`/events/${eventId}/tickets/${ticketId}`, {\n method: 'PATCH',\n data: { ticket, context }\n });\n }\n\n /**\n * Delete a ticket from an event.\n *\n * @param eventId - The unique identifier of the event\n * @param ticketId - The unique identifier of the ticket to delete\n * @returns A Promise resolving when the ticket is deleted (no content)\n * @throws Will throw an error if the request fails or ticket is not found\n *\n * @example\n * ```ts\n * await client.events.deleteTicket('evt_abc123', 'tkt_xyz789');\n * ```\n */\n async deleteTicket(eventId: string, ticketId: string) {\n return this.request<void>(`/events/${eventId}/tickets/${ticketId}`, {\n method: 'DELETE'\n });\n }\n\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with the Cohost Orders API.\n * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const order = await client.orders.fetch('order-id', 'user-id');\n * const list = await client.orders.list({ status: 'completed' });\n * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async fetch(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}?uid=${uid}`);\n }\n\n /**\n * Fetch a single order by ID.\n * \n * @param id - The unique identifier of the order\n * @param uid - The unique user ID associated with the order (currently unused but reserved for future auth context)\n * @returns A Promise resolving to the order object\n * @throws Will throw an error if the request fails or the order is not found\n */\n async attendees(id: string, uid: string) {\n // uid is reserved for future scoped access/auth features\n return this.request(`/orders/${id}/attendees?uid=${uid}`);\n }\n\n /**\n * List orders with optional filters.\n * \n * @param filters - Optional filters to apply when retrieving orders\n * @returns A Promise resolving to an array of order summaries\n * @throws Will throw an error if the request fails\n */\n async list(filters?: {\n status?: string;\n startDate?: string;\n endDate?: string;\n page?: number;\n pageSize?: number;\n }) {\n const query = new URLSearchParams(filters as Record<string, string>).toString();\n return this.request(`/orders${query ? `?${query}` : ''}`);\n }\n\n /**\n * Send order confirmation email to customer.\n *\n * @param id - The unique identifier of the order\n * @returns A Promise resolving to the confirmation response\n * @throws Will throw an error if the request fails or order is not found\n *\n * @example\n * ```ts\n * const result = await client.orders.sendConfirmation('ord_abc123');\n * console.log(result.response); // Confirmation sent status\n * ```\n */\n async sendConfirmation(id: string) {\n return this.request<{ response: any }>(`/orders/${id}/send-confirmation`, {\n method: 'POST'\n });\n }\n}\n","import { CartSession, StartCartSessionInput, UpdatableCartSession } from '../../types';\nimport { CohostEndpoint } from '../endpoint';\n\n/**\n * Provides methods to interact with cart sessions in the Cohost API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const session = await client.sessions.start({ contextId: 'evt_abc123' });\n * ```\n */\nexport class SessionsAPI extends CohostEndpoint {\n\n /**\n * Start a new cart session.\n *\n * @param input - Data to start the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the request fails\n */\n async start(input: StartCartSessionInput) {\n return this.request<CartSession>('/cart/sessions', {\n method: 'POST',\n data: input,\n });\n }\n\n /**\n * Get a cart session by its ID.\n *\n * @param id - The unique session ID\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the session is not found or request fails\n */\n async get(id: string) {\n return this.request<CartSession>(`/cart/sessions/${id}`);\n }\n\n /**\n * Update a cart session.\n *\n * @param id - The ID of the session to update\n * @param input - Data to update the session\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async update(id: string, input: Partial<UpdatableCartSession>) {\n return this.request<CartSession>(`/cart/sessions/${id}`, {\n method: 'PATCH',\n data: input,\n });\n }\n\n /**\n * Cancel (soft delete) a cart session.\n *\n * @param id - The ID of the session to cancel\n * @returns Nothing if successful\n * \n * @throws Will throw an error if the cancel operation fails\n */\n async cancel(id: string) {\n return this.request<void>(`/cart/sessions/${id}`, {\n method: 'DELETE',\n });\n }\n\n /**\n * Update an item in the cart session.\n *\n * @param sessionId - The ID of the session\n * @param props - Properties to update\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the update fails\n */\n async updateItem(sessionId: string, props: {\n itemId: string;\n quantity: number;\n options?: {\n [key: string]: any;\n };\n }) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/item`, {\n method: 'POST',\n data: props,\n });\n }\n\n /**\n * Pre-validate the cart session for payment and checkout.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for validation\n * @returns {CartSession} The validated cart session\n * \n * @throws Will throw an error if validation fails\n */\n async preValidate(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/pre-validate`, {\n method: 'POST',\n data: data,\n });\n }\n\n\n\n /**\n * Prepare the cart session for payment.\n *\n * @param sessionId - The ID of the cart session\n * @param data - Data required for payment preparation\n * @returns {CartSession} The prepared cart session\n * \n * @throws Will throw an error if preparation fails\n */\n async processPayment(sessionId: string, data: unknown) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/payment/process`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Close the cart session, and place the order.\n * \n * @param sessionId - The ID of the session\n * @param data - Data to place the order\n * @returns {CartSession} The latest cart session\n * \n * @throws Will throw an error if the order placement fails\n */\n async placeOrder(sessionId: string, data: any) {\n return this.request<CartSession>(`/cart/sessions/${sessionId}/place-order`, {\n method: 'POST',\n data: data,\n });\n }\n\n /**\n * Remove an item from the cart session.\n * The same as setting the quantity to 0.\n * \n * @param sessionId - The ID of the cart session\n * @param itemId - The ID of the item to remove\n * @returns {CartSession} The latest cart session\n */\n async deleteItem(sessionId: string, itemId: string) {\n return this.updateItem(sessionId, {\n itemId,\n quantity: 0,\n });\n }\n\n\n\n\n\n /**\n * Join a table commitment within an active cart session.\n *\n * @param id - The ID of the cart session\n * @param tableCommitmentId - The table commitment ID to join\n * @returns {CartSession} Updated cart session with joined table\n * \n * @throws Will throw an error if the join operation fails\n */\n async joinTableCommitment(id: string, tableCommitmentId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/join-table`, {\n method: 'POST',\n data: {\n tableCommitmentId,\n }\n });\n }\n\n\n /**\n * Apply a coupon code to the cart session.\n *\n * @param id - The ID of the cart session\n * @param code - The coupon code to apply\n * @returns {CartSession} Updated cart session with applied coupon\n * \n * @throws Will throw an error if the coupon application fails\n */\n async applyCoupon(id: string, code: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons`, {\n method: 'POST',\n data: {\n code\n }\n });\n }\n\n /**\n * Find viable table options for a cart session.\n *\n * @param id - The ID of the cart session\n * @param props - Properties to find viable tables\n * @returns {ViableTableOption[]} List of viable table options\n * \n * @throws Will throw an error if the request fails\n */\n async deleteCoupon(id: string, couponId: string): Promise<CartSession> {\n return this.request<CartSession>(`/cart/sessions/${id}/coupons/${couponId}`, {\n method: 'DELETE'\n });\n }\n}\n","import { CohostEndpoint } from '../endpoint';\n\n/**\n * Coupon interface for the Cohost API\n */\nexport interface Coupon {\n id: string;\n code: string;\n discountType: 'percentage' | 'fixed';\n discountValue: number;\n maxUses?: number;\n usedCount?: number;\n expiresAt?: string;\n companyId: string;\n eventId?: string;\n status?: 'active' | 'inactive' | 'expired';\n created?: string;\n updated?: string;\n}\n\n/**\n * Provides methods to interact with the Cohost Coupons API.\n *\n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const coupons = await client.coupons.list();\n * const coupon = await client.coupons.create({ code: 'SUMMER2025', discountType: 'percentage', discountValue: 20 });\n * ```\n */\nexport class CouponsAPI extends CohostEndpoint {\n\n /**\n * List all coupons for the authenticated company.\n *\n * @param filters - Optional filters to apply when retrieving coupons\n * @returns A Promise resolving to an array of coupon objects\n * @throws Will throw an error if the request fails\n *\n * @example\n * ```ts\n * // List all coupons\n * const allCoupons = await client.coupons.list();\n *\n * // List coupons for specific event\n * const eventCoupons = await client.coupons.list({ eventId: 'evt_abc123' });\n * ```\n */\n async list(filters?: { eventId?: string }) {\n const query = filters?.eventId ? `?eventId=${filters.eventId}` : '';\n return this.request<Coupon[]>(`/coupons${query}`);\n }\n\n /**\n * Create a new coupon.\n *\n * @param coupon - The coupon data to create\n * @returns A Promise resolving to the created coupon object\n * @throws Will throw an error if the request fails or validation fails\n *\n * @example\n * ```ts\n * const coupon = await client.coupons.create({\n * code: 'SUMMER2025',\n * discountType: 'percentage',\n * discountValue: 20,\n * maxUses: 100,\n * expiresAt: '2025-08-31T23:59:59Z'\n * });\n * ```\n */\n async create(coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>) {\n return this.request<Coupon>('/coupons', {\n method: 'POST',\n data: coupon\n });\n }\n\n /**\n * Update an existing coupon.\n *\n * @param id - The unique identifier of the coupon to update\n * @param coupon - Partial coupon data to update\n * @returns A Promise resolving to the updated coupon object\n * @throws Will throw an error if the request fails or coupon is not found\n *\n * @example\n * ```ts\n * const updated = await client.coupons.update('cpn_xyz789', {\n * discountValue: 25,\n * maxUses: 150\n * });\n * ```\n */\n async update(id: string, coupon: Omit<Partial<Coupon>, 'id' | 'companyId' | 'created' | 'updated'>) {\n return this.request<Coupon>(`/coupons/${id}`, {\n method: 'PATCH',\n data: coupon\n });\n }\n\n /**\n * Delete a coupon.\n *\n * @param id - The unique identifier of the coupon to delete\n * @returns A Promise resolving when the coupon is deleted\n * @throws Will throw an error if the request fails or coupon is not found\n *\n * @example\n * ```ts\n * await client.coupons.delete('cpn_xyz789');\n * ```\n */\n async delete(id: string) {\n return this.request<void>(`/coupons/${id}`, {\n method: 'DELETE'\n });\n }\n}\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\nimport { SessionsAPI } from './api/sessions';\nimport { CouponsAPI } from './api/coupons';\nimport { apiBaseUrl } from './apiVersion';\nimport { request, RequestFn } from './http/request';\nimport { CohostClientSettings } from './settings';\n\n/**\n * Configuration options for instantiating a CohostClient.\n */\nexport interface CohostClientOptions {\n /** API token used for authenticated requests. */\n token: string;\n\n /** Optional client settings such as debug mode or custom API URL. */\n settings?: CohostClientSettings;\n}\n\n/**\n * CohostClient provides grouped access to various API modules such as Events and Orders.\n */\nexport class CohostClient {\n public readonly events: EventsAPI;\n public readonly orders: OrdersAPI;\n public readonly cart: SessionsAPI;\n public readonly coupons: CouponsAPI;\n\n private readonly baseOptions: CohostClientOptions;\n\n constructor(options: CohostClientOptions, customRequestFn?: RequestFn) {\n this.baseOptions = options;\n\n const { token, settings = {} } = options;\n\n const sharedRequest = customRequestFn ?? request({\n token,\n baseUrl: settings.apiUrl || apiBaseUrl,\n debug: settings.debug,\n });\n\n this.events = new EventsAPI(sharedRequest, settings);\n this.orders = new OrdersAPI(sharedRequest, settings);\n this.cart = new SessionsAPI(sharedRequest, settings);\n this.coupons = new CouponsAPI(sharedRequest, settings);\n }\n\n /**\n * Returns a new CohostClient instance with overridden request behavior\n */\n public requestWithOverrides(overrides: {\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n }): CohostClient {\n const { token, settings = {} } = this.baseOptions;\n\n const overriddenRequest: RequestFn = (path, options = {}) =>\n request({\n token: overrides.token ?? token,\n baseUrl: overrides.baseUrl ?? settings.apiUrl ?? apiBaseUrl,\n debug: settings.debug,\n })(path, {\n ...options,\n headers: {\n ...(overrides.headers || {}),\n ...(options.headers || {}),\n },\n });\n\n return new CohostClient(\n {\n token: overrides.token ?? token,\n settings: {\n ...settings,\n apiUrl: overrides.baseUrl ?? settings.apiUrl,\n },\n },\n overriddenRequest\n );\n }\n}\n","import { CohostClient, CohostClientOptions } from './client';\nexport { type CohostClientSettings } from './settings';\n\n/**\n * Factory method for creating a CohostClient instance.\n * \n * Example:\n * ```ts\n * const client = createCohostClient({ token: 'your-token' });\n * ```\n */\nexport function createCohostClient(options: CohostClientOptions): CohostClient {\n return new CohostClient(options);\n}\n\n\nexport { CohostClient }\nexport { type Coupon } from './api/coupons';\n\nexport * from '../types';"],"mappings":"oKAOO,IAAMA,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECtBO,IAAME,EAAa,4BCanB,IAAMC,EAAN,MAAMC,UAAoB,KAAM,CAQnC,YAAYC,EAAiBC,EAA0B,CAEnD,MAAMD,CAAO,EATjBE,EAAA,kBACAA,EAAA,mBAWI,KAAK,KAAO,cAGZ,KAAK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,CACF,EChGO,IAAMC,EAAN,MAAMC,CAAa,CAQxB,YAAYC,EAA8BC,EAA6B,CAPvEC,EAAA,KAAgB,UAChBA,EAAA,KAAgB,UAChBA,EAAA,KAAgB,QAChBA,EAAA,KAAgB,WAEhBA,EAAA,KAAiB,eAGf,KAAK,YAAcF,EAEnB,GAAM,CAAE,MAAAG,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAIJ,EAE3BK,EAAgBJ,GAAmBK,EAAQ,CAC/C,MAAAH,EACA,QAASC,EAAS,QAAUG,EAC5B,MAAOH,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAII,EAAUH,EAAeD,CAAQ,EACnD,KAAK,OAAS,IAAIK,EAAUJ,EAAeD,CAAQ,EACnD,KAAK,KAAO,IAAIM,EAAYL,EAAeD,CAAQ,EACnD,KAAK,QAAU,IAAIO,EAAWN,EAAeD,CAAQ,CACvD,CAKO,qBAAqBQ,EAIX,CACf,GAAM,CAAE,MAAAT,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCS,EAA+B,CAACC,EAAMd,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOM,EAAU,OAAST,EAC1B,QAASS,EAAU,SAAWR,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAEU,EAAM,CACP,GAAGd,EACH,QAAS,CACP,GAAIY,EAAU,SAAW,CAAC,EAC1B,GAAIZ,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOa,EAAU,OAAST,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQQ,EAAU,SAAWR,EAAS,MACxC,CACF,EACAS,CACF,CACF,CACF,ECtEO,SAASE,GAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","apiBaseUrl","CohostError","_CohostError","message","props","__publicField","err","defaultSettings","runtimeOverrides","paginatedOptions","req","options","pagination","rest","buildQueryString","input","params","key","value","v","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","_query","queryString","url","runtimeOverrides","reqHeaders","defaultSettings","body","cleanHeaders","tokenValue","res","responseBody","message","CohostError","EventsAPI","CohostEndpoint","id","filters","paginatedOptions","event","context","eventId","tickets","data","ticketId","ticket","OrdersAPI","CohostEndpoint","id","uid","filters","query","SessionsAPI","CohostEndpoint","input","id","sessionId","props","data","itemId","tableCommitmentId","code","couponId","CouponsAPI","CohostEndpoint","filters","query","coupon","id","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","SessionsAPI","CouponsAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cohostvip/cohost-node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Cohost API wrapper",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
},
|
|
46
46
|
"packageManager": "pnpm@10.8.1",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "
|
|
48
|
+
"@types/node": "24.6.2",
|
|
49
49
|
"@vitest/ui": "^3.2.0",
|
|
50
|
-
"tsup": "
|
|
51
|
-
"typescript": "5.
|
|
52
|
-
"vite": "6.
|
|
50
|
+
"tsup": "8.5.0",
|
|
51
|
+
"typescript": "5.9.3",
|
|
52
|
+
"vite": "^6.3.6",
|
|
53
53
|
"vitest": "^3.2.0"
|
|
54
54
|
}
|
|
55
55
|
}
|