@cohostvip/cohost-node 0.1.17 → 0.2.4

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 CHANGED
@@ -1,15 +1,21 @@
1
1
  # @cohostvip/cohost-node
2
2
 
3
- > Official Node.js SDK for interacting with the Cohost API
3
+ > Official Node.js SDK for the Cohost API
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@cohostvip/cohost-node.svg)](https://www.npmjs.com/package/@cohostvip/cohost-node)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue.svg)](https://www.typescriptlang.org/)
4
7
 
5
8
  ---
6
9
 
7
10
  ## ✨ Features
8
11
 
9
- - TypeScript-first API client
10
- - Supports Node.js `>=18`
11
- - Automatically unwraps `{ status: 'ok', data: ... }` responses
12
- - Supports ESM and CommonJS
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
- ## 🧱 Usage
34
+ ## 🚀 Quick Start
27
35
 
28
- ```ts
29
- import { CohostClient } from '@cohostvip/cohost-node';
36
+ ```typescript
37
+ import { createCohostClient } from '@cohostvip/cohost-node';
30
38
 
31
- const client = new CohostClient({
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
- const event = await client.events.fetch('event-id');
36
- const tickets = await client.events.tickets('event-id');
37
- const order = await client.orders.fetch('order-id', 'user-id');
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
- ## 🧩 API Coverage
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
- This SDK currently supports:
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
- - `events.fetch(id)` – Fetch a single event
47
- - `events.tickets(id)` – Fetch tickets for an event
48
- - `orders.fetch(id, uid)` – Fetch an order
178
+ // Place order
179
+ const result = await client.cart.placeOrder(session.id);
49
180
 
50
- More endpoints coming soon.
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
- ## 🛠 Environment Requirements
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
- - Node.js 18 or later
57
- - An active Cohost API token
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
- ## 🗒️ Changelog
62
- See the latest changes [here](./CHANGELOG.md).
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
- Planned features and improvements are tracked [here](./ROADMAP.md).
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,12 +2106,110 @@ 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
  */
1993
2210
  interface CohostClientOptions {
1994
- /** API token used for authenticated requests. */
1995
- token: string;
2211
+ /** API token used for authenticated requests. Defaults to COHOST_API_TOKEN or NEXT_PUBLIC_COHOST_API_TOKEN env var. */
2212
+ token?: string;
1996
2213
  /** Optional client settings such as debug mode or custom API URL. */
1997
2214
  settings?: CohostClientSettings;
1998
2215
  }
@@ -2003,8 +2220,9 @@ 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
- constructor(options: CohostClientOptions, customRequestFn?: RequestFn);
2225
+ constructor(options?: CohostClientOptions, customRequestFn?: RequestFn);
2008
2226
  /**
2009
2227
  * Returns a new CohostClient instance with overridden request behavior
2010
2228
  */