@cohostvip/cohost-node 0.0.1 → 0.0.3
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/dist/index.d.mts +479 -22
- package/dist/index.d.ts +479 -22
- 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 +2 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supported HTTP methods.
|
|
3
3
|
*/
|
|
4
|
-
type RequestMethod =
|
|
4
|
+
type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
5
5
|
/**
|
|
6
6
|
* A function that performs a request to the Cohost API.
|
|
7
|
+
* The generic <T> allows you to specify the expected response type.
|
|
7
8
|
*/
|
|
8
|
-
type RequestFn = (
|
|
9
|
-
/** Path of the request relative to baseUrl */
|
|
10
|
-
path: string, options?: {
|
|
11
|
-
/** HTTP method (defaults to 'GET') */
|
|
9
|
+
type RequestFn = <T = any>(path: string, options?: {
|
|
12
10
|
method?: RequestMethod;
|
|
13
|
-
/** Request body data (auto-serialized as JSON) */
|
|
14
11
|
data?: any;
|
|
15
|
-
/** Query parameters to be appended to the URL */
|
|
16
12
|
query?: Record<string, string | number | boolean | undefined>;
|
|
17
|
-
/** Additional headers to merge into the request */
|
|
18
13
|
headers?: Record<string, string>;
|
|
19
|
-
}) => Promise<
|
|
14
|
+
}) => Promise<T>;
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* Optional settings for customizing the behavior of the CohostClient.
|
|
@@ -46,6 +41,458 @@ declare class CohostEndpoint {
|
|
|
46
41
|
constructor(request: RequestFn, settings: CohostClientSettings);
|
|
47
42
|
}
|
|
48
43
|
|
|
44
|
+
type Address = {
|
|
45
|
+
address_1: string;
|
|
46
|
+
address_2?: string;
|
|
47
|
+
city: string;
|
|
48
|
+
country: string;
|
|
49
|
+
formattedAddress?: string;
|
|
50
|
+
localized_address_display?: string;
|
|
51
|
+
localized_area_display?: string;
|
|
52
|
+
localized_multi_line_address_display?: Array<string>;
|
|
53
|
+
postal_code: string;
|
|
54
|
+
premise?: string;
|
|
55
|
+
region: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type BuzzBuilder = {
|
|
59
|
+
countLabel: string;
|
|
60
|
+
profiles: Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
photoURL: string;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
declare enum CostBucket {
|
|
68
|
+
DELIVERY = "delivery",
|
|
69
|
+
FEE = "fee",
|
|
70
|
+
ITEM = "item",
|
|
71
|
+
TAX = "tax"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type CostComponentCap = {
|
|
75
|
+
op: string;
|
|
76
|
+
type: CostComponentCap.type;
|
|
77
|
+
/**
|
|
78
|
+
* The value of the cap. If type is percentage, it is a percentage of the base value.
|
|
79
|
+
* If type is absolute, it is an absolute value.
|
|
80
|
+
*
|
|
81
|
+
* Absolute value is represented in the same denomination as the cost.
|
|
82
|
+
* i.e. if the cost is in cents, the absolute value should be in cents.
|
|
83
|
+
*
|
|
84
|
+
* percentage value is represented as a decimal.
|
|
85
|
+
* For example, 10% is represented as 0.1.
|
|
86
|
+
*/
|
|
87
|
+
value: number;
|
|
88
|
+
};
|
|
89
|
+
declare namespace CostComponentCap {
|
|
90
|
+
enum type {
|
|
91
|
+
ABSOLUTE = "absolute",
|
|
92
|
+
PERCENTAGE = "percentage"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A set of comparison operators used for evaluating conditional expressions.
|
|
98
|
+
*
|
|
99
|
+
* Supported operators:
|
|
100
|
+
* - '==' (equal to)
|
|
101
|
+
* - '!=' (not equal to)
|
|
102
|
+
* - '<' (less than)
|
|
103
|
+
* - '<=' (less than or equal to)
|
|
104
|
+
* - '>' (greater than)
|
|
105
|
+
* - '>=' (greater than or equal to)
|
|
106
|
+
*/
|
|
107
|
+
declare enum EqualOperator {
|
|
108
|
+
_ = "!="
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type CostComponentRuleCondition = {
|
|
112
|
+
/**
|
|
113
|
+
* evaluator, will define a function or endpoint to evaluate the condition.
|
|
114
|
+
*/
|
|
115
|
+
eval?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The field to evaluate the condition against.
|
|
118
|
+
* For example, "item.price" or "order.total".
|
|
119
|
+
* The field should be a valid path to the field in the cost component base.
|
|
120
|
+
*/
|
|
121
|
+
field: string;
|
|
122
|
+
operator: EqualOperator;
|
|
123
|
+
/**
|
|
124
|
+
* Can be a value such as number, currencyAmount, an ISO date string, etc...
|
|
125
|
+
*/
|
|
126
|
+
value: any;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type CostComponentRule = {
|
|
130
|
+
/**
|
|
131
|
+
* The rule will be applied to the cost component if the conditions are met.
|
|
132
|
+
*/
|
|
133
|
+
conditions: Array<CostComponentRuleCondition>;
|
|
134
|
+
/**
|
|
135
|
+
* Friendly name of the rule.
|
|
136
|
+
*/
|
|
137
|
+
name: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
type CostComponent = {
|
|
141
|
+
base: string;
|
|
142
|
+
bucket: CostBucket;
|
|
143
|
+
cap?: CostComponentCap;
|
|
144
|
+
currency: string;
|
|
145
|
+
details?: any;
|
|
146
|
+
id?: string;
|
|
147
|
+
name: string;
|
|
148
|
+
payer: CostComponent.payer;
|
|
149
|
+
recipient: string;
|
|
150
|
+
rules: Array<CostComponentRule>;
|
|
151
|
+
version: string;
|
|
152
|
+
};
|
|
153
|
+
declare namespace CostComponent {
|
|
154
|
+
enum payer {
|
|
155
|
+
ATTENDEE = "attendee",
|
|
156
|
+
ORGANIZER = "organizer"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Status of the event lifecycle.
|
|
162
|
+
*
|
|
163
|
+
* - `archived`: The event is archived and no longer visible in listings.
|
|
164
|
+
* - `draft`: The event is still being edited and not yet published.
|
|
165
|
+
* - `live`: The event is published and accepting actions (e.g., ticket sales).
|
|
166
|
+
* - `started`: The event has begun.
|
|
167
|
+
* - `ended`: The event has ended.
|
|
168
|
+
* - `completed`: The event has concluded successfully and is finalized.
|
|
169
|
+
* - `canceled`: The event was canceled and is no longer active.
|
|
170
|
+
*/
|
|
171
|
+
declare enum EventStatus {
|
|
172
|
+
ARCHIVED = "archived",
|
|
173
|
+
CANCELED = "canceled",
|
|
174
|
+
COMPLETED = "completed",
|
|
175
|
+
DRAFT = "draft",
|
|
176
|
+
ENDED = "ended",
|
|
177
|
+
LIVE = "live",
|
|
178
|
+
STARTED = "started"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type GeometryPoint = {
|
|
182
|
+
lat: number;
|
|
183
|
+
lng: number;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type LocationGeometry = {
|
|
187
|
+
geoHash?: string;
|
|
188
|
+
lat: number;
|
|
189
|
+
lng: number;
|
|
190
|
+
locality?: string;
|
|
191
|
+
region?: string;
|
|
192
|
+
vicinity?: string;
|
|
193
|
+
viewport?: {
|
|
194
|
+
northeast: GeometryPoint;
|
|
195
|
+
southwest: GeometryPoint;
|
|
196
|
+
};
|
|
197
|
+
zoom?: number;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type Location = {
|
|
201
|
+
address: Address;
|
|
202
|
+
geometry: LocationGeometry;
|
|
203
|
+
name: string;
|
|
204
|
+
placeId: string;
|
|
205
|
+
timezone?: string;
|
|
206
|
+
venueId: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A photo object with resolution options and optional metadata.
|
|
211
|
+
*/
|
|
212
|
+
type Photo = {
|
|
213
|
+
/**
|
|
214
|
+
* High-resolution (2x) image URL.
|
|
215
|
+
*/
|
|
216
|
+
'2x'?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Optional caption for the image.
|
|
219
|
+
*/
|
|
220
|
+
caption?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Height of the image in pixels.
|
|
223
|
+
*/
|
|
224
|
+
height?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Internal photo ID, if stored in a media system.
|
|
227
|
+
*/
|
|
228
|
+
id?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Primary image URL.
|
|
231
|
+
* This is the default image URL to be used when no other resolution is specified.
|
|
232
|
+
*/
|
|
233
|
+
url: string;
|
|
234
|
+
/**
|
|
235
|
+
* Width of the image in pixels.
|
|
236
|
+
*/
|
|
237
|
+
width?: number;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type VenueBase = {
|
|
241
|
+
address: Address;
|
|
242
|
+
formattedAddress: string;
|
|
243
|
+
id: string;
|
|
244
|
+
logo: Photo;
|
|
245
|
+
name: string;
|
|
246
|
+
placeId?: string;
|
|
247
|
+
public: boolean;
|
|
248
|
+
slug: string;
|
|
249
|
+
tz: string;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
type EventFeature = {
|
|
253
|
+
data: any;
|
|
254
|
+
description: string;
|
|
255
|
+
enabled: boolean;
|
|
256
|
+
iconName?: string;
|
|
257
|
+
id: string;
|
|
258
|
+
key: string;
|
|
259
|
+
logoUri?: string;
|
|
260
|
+
meta?: any;
|
|
261
|
+
order: number;
|
|
262
|
+
title: string;
|
|
263
|
+
type: string;
|
|
264
|
+
version?: string;
|
|
265
|
+
widgetUri: string;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A rich content object that supports multiple representations of text.
|
|
270
|
+
*/
|
|
271
|
+
type MultipartText = {
|
|
272
|
+
/**
|
|
273
|
+
* Optional rich editor blocks (if structured editing is supported).
|
|
274
|
+
*/
|
|
275
|
+
blocks?: Array<any>;
|
|
276
|
+
/**
|
|
277
|
+
* HTML version of the content.
|
|
278
|
+
*/
|
|
279
|
+
html?: string;
|
|
280
|
+
/**
|
|
281
|
+
* Markdown version of the content.
|
|
282
|
+
*/
|
|
283
|
+
md?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Plain text version of the content.
|
|
286
|
+
*/
|
|
287
|
+
text?: string;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* EventProfile respresent a public view of an event
|
|
292
|
+
*/
|
|
293
|
+
type EventProfile = {
|
|
294
|
+
buzzBuilder?: BuzzBuilder;
|
|
295
|
+
channels: Array<string>;
|
|
296
|
+
companyId: string;
|
|
297
|
+
/**
|
|
298
|
+
* Curerncy used for the event.
|
|
299
|
+
*/
|
|
300
|
+
currency: string;
|
|
301
|
+
description: MultipartText;
|
|
302
|
+
/**
|
|
303
|
+
* The end date and time of the event in ISO 8601 format.
|
|
304
|
+
*/
|
|
305
|
+
end: string;
|
|
306
|
+
flyer?: Photo;
|
|
307
|
+
id: string;
|
|
308
|
+
isSeries?: boolean;
|
|
309
|
+
location?: Location;
|
|
310
|
+
meta?: any;
|
|
311
|
+
name: string;
|
|
312
|
+
organizer: any;
|
|
313
|
+
priceRange?: {
|
|
314
|
+
max?: string;
|
|
315
|
+
min?: string;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Is the event public?
|
|
319
|
+
*/
|
|
320
|
+
public: boolean;
|
|
321
|
+
searchTags: Array<string>;
|
|
322
|
+
sections: Array<string>;
|
|
323
|
+
slug: string;
|
|
324
|
+
/**
|
|
325
|
+
* The start date and time of the event in ISO 8601 format.
|
|
326
|
+
*/
|
|
327
|
+
start: string;
|
|
328
|
+
status: EventStatus;
|
|
329
|
+
summary: string;
|
|
330
|
+
tags: Array<string>;
|
|
331
|
+
ticketPrices: Array<string>;
|
|
332
|
+
/**
|
|
333
|
+
* The timezone in which the event is taking place.
|
|
334
|
+
*/
|
|
335
|
+
tz: string;
|
|
336
|
+
url?: string;
|
|
337
|
+
venue?: VenueBase;
|
|
338
|
+
widgets: Array<EventFeature>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Represents the costs associated with an offering.
|
|
343
|
+
*/
|
|
344
|
+
type OfferingCosts = {
|
|
345
|
+
/**
|
|
346
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
347
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
348
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
349
|
+
*
|
|
350
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
351
|
+
*/
|
|
352
|
+
cost: string;
|
|
353
|
+
/**
|
|
354
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
355
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
356
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
357
|
+
*
|
|
358
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
359
|
+
*/
|
|
360
|
+
delivery: string;
|
|
361
|
+
/**
|
|
362
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
363
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
364
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
365
|
+
*
|
|
366
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
367
|
+
*/
|
|
368
|
+
fee: string;
|
|
369
|
+
/**
|
|
370
|
+
* cost + fee - discount , not including tax
|
|
371
|
+
*/
|
|
372
|
+
gross: string;
|
|
373
|
+
/**
|
|
374
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
375
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
376
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
377
|
+
*
|
|
378
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
379
|
+
*/
|
|
380
|
+
tax: string;
|
|
381
|
+
/**
|
|
382
|
+
* total cost including tax
|
|
383
|
+
*/
|
|
384
|
+
total: string;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
declare enum OfferingStatus {
|
|
388
|
+
DELETED = "deleted",
|
|
389
|
+
DRAFT = "draft",
|
|
390
|
+
HIDDEN = "hidden",
|
|
391
|
+
LIVE = "live",
|
|
392
|
+
SOLD_OUT = "sold-out",
|
|
393
|
+
UNAVAILABLE = "unavailable"
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
declare enum OfferingType {
|
|
397
|
+
ADMISSION = "admission",
|
|
398
|
+
DONATION = "donation",
|
|
399
|
+
DRINK = "drink",
|
|
400
|
+
MEMBERSHIP = "membership",
|
|
401
|
+
MERCH = "merch",
|
|
402
|
+
OTHER = "other",
|
|
403
|
+
PACKAGE = "package",
|
|
404
|
+
SERVICE = "service",
|
|
405
|
+
SKIP = "skip",
|
|
406
|
+
TC_TICKET = "tc-ticket",
|
|
407
|
+
TICKET = "ticket",
|
|
408
|
+
VOUCHER = "voucher"
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
type PackageInclude = {
|
|
412
|
+
description: string;
|
|
413
|
+
id: string;
|
|
414
|
+
quantity: number;
|
|
415
|
+
ref?: any;
|
|
416
|
+
type: OfferingType;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
declare enum PriceCategory {
|
|
420
|
+
DONATION = "donation",
|
|
421
|
+
FREE = "free",
|
|
422
|
+
OTHER = "other",
|
|
423
|
+
PAID = "paid"
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* A repeating or structured date schedule for an event or item.
|
|
428
|
+
*/
|
|
429
|
+
type Schedule = {
|
|
430
|
+
/**
|
|
431
|
+
* Days of the week (0 = Sunday, 6 = Saturday).
|
|
432
|
+
*/
|
|
433
|
+
daysOfWeek?: Array<number>;
|
|
434
|
+
/**
|
|
435
|
+
* ISO-formatted UTC end datetime.
|
|
436
|
+
*/
|
|
437
|
+
end: string;
|
|
438
|
+
/**
|
|
439
|
+
* Specific dates to exclude in "YYYY-MM-DD" format.
|
|
440
|
+
*/
|
|
441
|
+
excludeDates?: Array<string>;
|
|
442
|
+
/**
|
|
443
|
+
* Specific dates to include in "YYYY-MM-DD" format.
|
|
444
|
+
*/
|
|
445
|
+
includeDates?: Array<string>;
|
|
446
|
+
/**
|
|
447
|
+
* ISO-formatted UTC start datetime.
|
|
448
|
+
*/
|
|
449
|
+
start: string;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
type Ticket = {
|
|
453
|
+
capacity: number;
|
|
454
|
+
category: string;
|
|
455
|
+
changed?: string;
|
|
456
|
+
/**
|
|
457
|
+
* Describe fees and other costs associated with purchasing tickets
|
|
458
|
+
* to this offering
|
|
459
|
+
*/
|
|
460
|
+
costComponents?: Array<CostComponent>;
|
|
461
|
+
costs: OfferingCosts;
|
|
462
|
+
created: string;
|
|
463
|
+
description?: string;
|
|
464
|
+
display_name?: string;
|
|
465
|
+
id: string;
|
|
466
|
+
included?: Array<PackageInclude>;
|
|
467
|
+
instructions?: string;
|
|
468
|
+
maximumQuantity: number;
|
|
469
|
+
minimumQuantity: number;
|
|
470
|
+
/**
|
|
471
|
+
* Offering name, can be ticket name, vaucher name, etc...
|
|
472
|
+
*/
|
|
473
|
+
name: string;
|
|
474
|
+
order_confirmation_message?: string;
|
|
475
|
+
package?: boolean;
|
|
476
|
+
parentId?: string;
|
|
477
|
+
priceCategory: PriceCategory;
|
|
478
|
+
quantitySold: number;
|
|
479
|
+
refId?: string;
|
|
480
|
+
salesEnd: string;
|
|
481
|
+
salesStart: string;
|
|
482
|
+
schedule?: Schedule;
|
|
483
|
+
sorting: number;
|
|
484
|
+
source: string;
|
|
485
|
+
status: OfferingStatus;
|
|
486
|
+
ticketParentId?: string;
|
|
487
|
+
type: Ticket.type;
|
|
488
|
+
};
|
|
489
|
+
declare namespace Ticket {
|
|
490
|
+
enum type {
|
|
491
|
+
ADMISSION = "admission",
|
|
492
|
+
PACKAGE = "package"
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
49
496
|
/**
|
|
50
497
|
* Provides methods to interact with the Cohost Events API.
|
|
51
498
|
*
|
|
@@ -64,7 +511,7 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
64
511
|
* @returns A Promise resolving to the event object
|
|
65
512
|
* @throws Will throw an error if the request fails or the event is not found
|
|
66
513
|
*/
|
|
67
|
-
fetch(id: string): Promise<
|
|
514
|
+
fetch(id: string): Promise<EventProfile>;
|
|
68
515
|
/**
|
|
69
516
|
* List all tickets associated with a specific event.
|
|
70
517
|
*
|
|
@@ -72,7 +519,7 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
72
519
|
* @returns A Promise resolving to an array of ticket objects
|
|
73
520
|
* @throws Will throw an error if the request fails or the event does not exist
|
|
74
521
|
*/
|
|
75
|
-
tickets(id: string): Promise<
|
|
522
|
+
tickets(id: string): Promise<Ticket[]>;
|
|
76
523
|
}
|
|
77
524
|
|
|
78
525
|
/**
|
|
@@ -107,20 +554,30 @@ interface CohostClientOptions {
|
|
|
107
554
|
}
|
|
108
555
|
/**
|
|
109
556
|
* CohostClient provides grouped access to various API modules such as Events and Orders.
|
|
110
|
-
*
|
|
111
|
-
* Usage:
|
|
112
|
-
* ```ts
|
|
113
|
-
* const client = new CohostClient({ token: 'your-token' });
|
|
114
|
-
* const event = await client.events.fetch('event-id');
|
|
115
|
-
* const order = await client.orders.fetch('order-id', 'user-id');
|
|
116
|
-
* ```
|
|
117
557
|
*/
|
|
118
558
|
declare class CohostClient {
|
|
119
|
-
/** Access to Event-related endpoints */
|
|
120
559
|
readonly events: EventsAPI;
|
|
121
|
-
/** Access to Order-related endpoints */
|
|
122
560
|
readonly orders: OrdersAPI;
|
|
123
|
-
|
|
561
|
+
private readonly baseOptions;
|
|
562
|
+
constructor(options: CohostClientOptions, customRequestFn?: RequestFn);
|
|
563
|
+
/**
|
|
564
|
+
* Returns a new CohostClient instance with overridden request behavior
|
|
565
|
+
*/
|
|
566
|
+
requestWithOverrides(overrides: {
|
|
567
|
+
token?: string;
|
|
568
|
+
baseUrl?: string;
|
|
569
|
+
headers?: Record<string, string>;
|
|
570
|
+
}): CohostClient;
|
|
124
571
|
}
|
|
125
572
|
|
|
126
|
-
|
|
573
|
+
/**
|
|
574
|
+
* Factory method for creating a CohostClient instance.
|
|
575
|
+
*
|
|
576
|
+
* Example:
|
|
577
|
+
* ```ts
|
|
578
|
+
* const client = createCohostClient({ token: 'your-token' });
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
declare function createCohostClient(options: CohostClientOptions): CohostClient;
|
|
582
|
+
|
|
583
|
+
export { CohostClient, createCohostClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Supported HTTP methods.
|
|
3
3
|
*/
|
|
4
|
-
type RequestMethod =
|
|
4
|
+
type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
5
5
|
/**
|
|
6
6
|
* A function that performs a request to the Cohost API.
|
|
7
|
+
* The generic <T> allows you to specify the expected response type.
|
|
7
8
|
*/
|
|
8
|
-
type RequestFn = (
|
|
9
|
-
/** Path of the request relative to baseUrl */
|
|
10
|
-
path: string, options?: {
|
|
11
|
-
/** HTTP method (defaults to 'GET') */
|
|
9
|
+
type RequestFn = <T = any>(path: string, options?: {
|
|
12
10
|
method?: RequestMethod;
|
|
13
|
-
/** Request body data (auto-serialized as JSON) */
|
|
14
11
|
data?: any;
|
|
15
|
-
/** Query parameters to be appended to the URL */
|
|
16
12
|
query?: Record<string, string | number | boolean | undefined>;
|
|
17
|
-
/** Additional headers to merge into the request */
|
|
18
13
|
headers?: Record<string, string>;
|
|
19
|
-
}) => Promise<
|
|
14
|
+
}) => Promise<T>;
|
|
20
15
|
|
|
21
16
|
/**
|
|
22
17
|
* Optional settings for customizing the behavior of the CohostClient.
|
|
@@ -46,6 +41,458 @@ declare class CohostEndpoint {
|
|
|
46
41
|
constructor(request: RequestFn, settings: CohostClientSettings);
|
|
47
42
|
}
|
|
48
43
|
|
|
44
|
+
type Address = {
|
|
45
|
+
address_1: string;
|
|
46
|
+
address_2?: string;
|
|
47
|
+
city: string;
|
|
48
|
+
country: string;
|
|
49
|
+
formattedAddress?: string;
|
|
50
|
+
localized_address_display?: string;
|
|
51
|
+
localized_area_display?: string;
|
|
52
|
+
localized_multi_line_address_display?: Array<string>;
|
|
53
|
+
postal_code: string;
|
|
54
|
+
premise?: string;
|
|
55
|
+
region: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type BuzzBuilder = {
|
|
59
|
+
countLabel: string;
|
|
60
|
+
profiles: Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
name: string;
|
|
63
|
+
photoURL: string;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
declare enum CostBucket {
|
|
68
|
+
DELIVERY = "delivery",
|
|
69
|
+
FEE = "fee",
|
|
70
|
+
ITEM = "item",
|
|
71
|
+
TAX = "tax"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
type CostComponentCap = {
|
|
75
|
+
op: string;
|
|
76
|
+
type: CostComponentCap.type;
|
|
77
|
+
/**
|
|
78
|
+
* The value of the cap. If type is percentage, it is a percentage of the base value.
|
|
79
|
+
* If type is absolute, it is an absolute value.
|
|
80
|
+
*
|
|
81
|
+
* Absolute value is represented in the same denomination as the cost.
|
|
82
|
+
* i.e. if the cost is in cents, the absolute value should be in cents.
|
|
83
|
+
*
|
|
84
|
+
* percentage value is represented as a decimal.
|
|
85
|
+
* For example, 10% is represented as 0.1.
|
|
86
|
+
*/
|
|
87
|
+
value: number;
|
|
88
|
+
};
|
|
89
|
+
declare namespace CostComponentCap {
|
|
90
|
+
enum type {
|
|
91
|
+
ABSOLUTE = "absolute",
|
|
92
|
+
PERCENTAGE = "percentage"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A set of comparison operators used for evaluating conditional expressions.
|
|
98
|
+
*
|
|
99
|
+
* Supported operators:
|
|
100
|
+
* - '==' (equal to)
|
|
101
|
+
* - '!=' (not equal to)
|
|
102
|
+
* - '<' (less than)
|
|
103
|
+
* - '<=' (less than or equal to)
|
|
104
|
+
* - '>' (greater than)
|
|
105
|
+
* - '>=' (greater than or equal to)
|
|
106
|
+
*/
|
|
107
|
+
declare enum EqualOperator {
|
|
108
|
+
_ = "!="
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type CostComponentRuleCondition = {
|
|
112
|
+
/**
|
|
113
|
+
* evaluator, will define a function or endpoint to evaluate the condition.
|
|
114
|
+
*/
|
|
115
|
+
eval?: string;
|
|
116
|
+
/**
|
|
117
|
+
* The field to evaluate the condition against.
|
|
118
|
+
* For example, "item.price" or "order.total".
|
|
119
|
+
* The field should be a valid path to the field in the cost component base.
|
|
120
|
+
*/
|
|
121
|
+
field: string;
|
|
122
|
+
operator: EqualOperator;
|
|
123
|
+
/**
|
|
124
|
+
* Can be a value such as number, currencyAmount, an ISO date string, etc...
|
|
125
|
+
*/
|
|
126
|
+
value: any;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type CostComponentRule = {
|
|
130
|
+
/**
|
|
131
|
+
* The rule will be applied to the cost component if the conditions are met.
|
|
132
|
+
*/
|
|
133
|
+
conditions: Array<CostComponentRuleCondition>;
|
|
134
|
+
/**
|
|
135
|
+
* Friendly name of the rule.
|
|
136
|
+
*/
|
|
137
|
+
name: string;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
type CostComponent = {
|
|
141
|
+
base: string;
|
|
142
|
+
bucket: CostBucket;
|
|
143
|
+
cap?: CostComponentCap;
|
|
144
|
+
currency: string;
|
|
145
|
+
details?: any;
|
|
146
|
+
id?: string;
|
|
147
|
+
name: string;
|
|
148
|
+
payer: CostComponent.payer;
|
|
149
|
+
recipient: string;
|
|
150
|
+
rules: Array<CostComponentRule>;
|
|
151
|
+
version: string;
|
|
152
|
+
};
|
|
153
|
+
declare namespace CostComponent {
|
|
154
|
+
enum payer {
|
|
155
|
+
ATTENDEE = "attendee",
|
|
156
|
+
ORGANIZER = "organizer"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Status of the event lifecycle.
|
|
162
|
+
*
|
|
163
|
+
* - `archived`: The event is archived and no longer visible in listings.
|
|
164
|
+
* - `draft`: The event is still being edited and not yet published.
|
|
165
|
+
* - `live`: The event is published and accepting actions (e.g., ticket sales).
|
|
166
|
+
* - `started`: The event has begun.
|
|
167
|
+
* - `ended`: The event has ended.
|
|
168
|
+
* - `completed`: The event has concluded successfully and is finalized.
|
|
169
|
+
* - `canceled`: The event was canceled and is no longer active.
|
|
170
|
+
*/
|
|
171
|
+
declare enum EventStatus {
|
|
172
|
+
ARCHIVED = "archived",
|
|
173
|
+
CANCELED = "canceled",
|
|
174
|
+
COMPLETED = "completed",
|
|
175
|
+
DRAFT = "draft",
|
|
176
|
+
ENDED = "ended",
|
|
177
|
+
LIVE = "live",
|
|
178
|
+
STARTED = "started"
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type GeometryPoint = {
|
|
182
|
+
lat: number;
|
|
183
|
+
lng: number;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
type LocationGeometry = {
|
|
187
|
+
geoHash?: string;
|
|
188
|
+
lat: number;
|
|
189
|
+
lng: number;
|
|
190
|
+
locality?: string;
|
|
191
|
+
region?: string;
|
|
192
|
+
vicinity?: string;
|
|
193
|
+
viewport?: {
|
|
194
|
+
northeast: GeometryPoint;
|
|
195
|
+
southwest: GeometryPoint;
|
|
196
|
+
};
|
|
197
|
+
zoom?: number;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
type Location = {
|
|
201
|
+
address: Address;
|
|
202
|
+
geometry: LocationGeometry;
|
|
203
|
+
name: string;
|
|
204
|
+
placeId: string;
|
|
205
|
+
timezone?: string;
|
|
206
|
+
venueId: string;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A photo object with resolution options and optional metadata.
|
|
211
|
+
*/
|
|
212
|
+
type Photo = {
|
|
213
|
+
/**
|
|
214
|
+
* High-resolution (2x) image URL.
|
|
215
|
+
*/
|
|
216
|
+
'2x'?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Optional caption for the image.
|
|
219
|
+
*/
|
|
220
|
+
caption?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Height of the image in pixels.
|
|
223
|
+
*/
|
|
224
|
+
height?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Internal photo ID, if stored in a media system.
|
|
227
|
+
*/
|
|
228
|
+
id?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Primary image URL.
|
|
231
|
+
* This is the default image URL to be used when no other resolution is specified.
|
|
232
|
+
*/
|
|
233
|
+
url: string;
|
|
234
|
+
/**
|
|
235
|
+
* Width of the image in pixels.
|
|
236
|
+
*/
|
|
237
|
+
width?: number;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
type VenueBase = {
|
|
241
|
+
address: Address;
|
|
242
|
+
formattedAddress: string;
|
|
243
|
+
id: string;
|
|
244
|
+
logo: Photo;
|
|
245
|
+
name: string;
|
|
246
|
+
placeId?: string;
|
|
247
|
+
public: boolean;
|
|
248
|
+
slug: string;
|
|
249
|
+
tz: string;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
type EventFeature = {
|
|
253
|
+
data: any;
|
|
254
|
+
description: string;
|
|
255
|
+
enabled: boolean;
|
|
256
|
+
iconName?: string;
|
|
257
|
+
id: string;
|
|
258
|
+
key: string;
|
|
259
|
+
logoUri?: string;
|
|
260
|
+
meta?: any;
|
|
261
|
+
order: number;
|
|
262
|
+
title: string;
|
|
263
|
+
type: string;
|
|
264
|
+
version?: string;
|
|
265
|
+
widgetUri: string;
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A rich content object that supports multiple representations of text.
|
|
270
|
+
*/
|
|
271
|
+
type MultipartText = {
|
|
272
|
+
/**
|
|
273
|
+
* Optional rich editor blocks (if structured editing is supported).
|
|
274
|
+
*/
|
|
275
|
+
blocks?: Array<any>;
|
|
276
|
+
/**
|
|
277
|
+
* HTML version of the content.
|
|
278
|
+
*/
|
|
279
|
+
html?: string;
|
|
280
|
+
/**
|
|
281
|
+
* Markdown version of the content.
|
|
282
|
+
*/
|
|
283
|
+
md?: string;
|
|
284
|
+
/**
|
|
285
|
+
* Plain text version of the content.
|
|
286
|
+
*/
|
|
287
|
+
text?: string;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* EventProfile respresent a public view of an event
|
|
292
|
+
*/
|
|
293
|
+
type EventProfile = {
|
|
294
|
+
buzzBuilder?: BuzzBuilder;
|
|
295
|
+
channels: Array<string>;
|
|
296
|
+
companyId: string;
|
|
297
|
+
/**
|
|
298
|
+
* Curerncy used for the event.
|
|
299
|
+
*/
|
|
300
|
+
currency: string;
|
|
301
|
+
description: MultipartText;
|
|
302
|
+
/**
|
|
303
|
+
* The end date and time of the event in ISO 8601 format.
|
|
304
|
+
*/
|
|
305
|
+
end: string;
|
|
306
|
+
flyer?: Photo;
|
|
307
|
+
id: string;
|
|
308
|
+
isSeries?: boolean;
|
|
309
|
+
location?: Location;
|
|
310
|
+
meta?: any;
|
|
311
|
+
name: string;
|
|
312
|
+
organizer: any;
|
|
313
|
+
priceRange?: {
|
|
314
|
+
max?: string;
|
|
315
|
+
min?: string;
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Is the event public?
|
|
319
|
+
*/
|
|
320
|
+
public: boolean;
|
|
321
|
+
searchTags: Array<string>;
|
|
322
|
+
sections: Array<string>;
|
|
323
|
+
slug: string;
|
|
324
|
+
/**
|
|
325
|
+
* The start date and time of the event in ISO 8601 format.
|
|
326
|
+
*/
|
|
327
|
+
start: string;
|
|
328
|
+
status: EventStatus;
|
|
329
|
+
summary: string;
|
|
330
|
+
tags: Array<string>;
|
|
331
|
+
ticketPrices: Array<string>;
|
|
332
|
+
/**
|
|
333
|
+
* The timezone in which the event is taking place.
|
|
334
|
+
*/
|
|
335
|
+
tz: string;
|
|
336
|
+
url?: string;
|
|
337
|
+
venue?: VenueBase;
|
|
338
|
+
widgets: Array<EventFeature>;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Represents the costs associated with an offering.
|
|
343
|
+
*/
|
|
344
|
+
type OfferingCosts = {
|
|
345
|
+
/**
|
|
346
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
347
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
348
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
349
|
+
*
|
|
350
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
351
|
+
*/
|
|
352
|
+
cost: string;
|
|
353
|
+
/**
|
|
354
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
355
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
356
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
357
|
+
*
|
|
358
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
359
|
+
*/
|
|
360
|
+
delivery: string;
|
|
361
|
+
/**
|
|
362
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
363
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
364
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
365
|
+
*
|
|
366
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
367
|
+
*/
|
|
368
|
+
fee: string;
|
|
369
|
+
/**
|
|
370
|
+
* cost + fee - discount , not including tax
|
|
371
|
+
*/
|
|
372
|
+
gross: string;
|
|
373
|
+
/**
|
|
374
|
+
* A string representing a currency amount in the format `"USD,1000"` where:
|
|
375
|
+
* - `"USD"` is the 3-letter ISO currency code.
|
|
376
|
+
* - The number after the comma represents the value in **minor units** (e.g., cents for USD).
|
|
377
|
+
*
|
|
378
|
+
* For example, `"USD,1000"` equals $10.00 (i.e., 1000 cents).
|
|
379
|
+
*/
|
|
380
|
+
tax: string;
|
|
381
|
+
/**
|
|
382
|
+
* total cost including tax
|
|
383
|
+
*/
|
|
384
|
+
total: string;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
declare enum OfferingStatus {
|
|
388
|
+
DELETED = "deleted",
|
|
389
|
+
DRAFT = "draft",
|
|
390
|
+
HIDDEN = "hidden",
|
|
391
|
+
LIVE = "live",
|
|
392
|
+
SOLD_OUT = "sold-out",
|
|
393
|
+
UNAVAILABLE = "unavailable"
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
declare enum OfferingType {
|
|
397
|
+
ADMISSION = "admission",
|
|
398
|
+
DONATION = "donation",
|
|
399
|
+
DRINK = "drink",
|
|
400
|
+
MEMBERSHIP = "membership",
|
|
401
|
+
MERCH = "merch",
|
|
402
|
+
OTHER = "other",
|
|
403
|
+
PACKAGE = "package",
|
|
404
|
+
SERVICE = "service",
|
|
405
|
+
SKIP = "skip",
|
|
406
|
+
TC_TICKET = "tc-ticket",
|
|
407
|
+
TICKET = "ticket",
|
|
408
|
+
VOUCHER = "voucher"
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
type PackageInclude = {
|
|
412
|
+
description: string;
|
|
413
|
+
id: string;
|
|
414
|
+
quantity: number;
|
|
415
|
+
ref?: any;
|
|
416
|
+
type: OfferingType;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
declare enum PriceCategory {
|
|
420
|
+
DONATION = "donation",
|
|
421
|
+
FREE = "free",
|
|
422
|
+
OTHER = "other",
|
|
423
|
+
PAID = "paid"
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* A repeating or structured date schedule for an event or item.
|
|
428
|
+
*/
|
|
429
|
+
type Schedule = {
|
|
430
|
+
/**
|
|
431
|
+
* Days of the week (0 = Sunday, 6 = Saturday).
|
|
432
|
+
*/
|
|
433
|
+
daysOfWeek?: Array<number>;
|
|
434
|
+
/**
|
|
435
|
+
* ISO-formatted UTC end datetime.
|
|
436
|
+
*/
|
|
437
|
+
end: string;
|
|
438
|
+
/**
|
|
439
|
+
* Specific dates to exclude in "YYYY-MM-DD" format.
|
|
440
|
+
*/
|
|
441
|
+
excludeDates?: Array<string>;
|
|
442
|
+
/**
|
|
443
|
+
* Specific dates to include in "YYYY-MM-DD" format.
|
|
444
|
+
*/
|
|
445
|
+
includeDates?: Array<string>;
|
|
446
|
+
/**
|
|
447
|
+
* ISO-formatted UTC start datetime.
|
|
448
|
+
*/
|
|
449
|
+
start: string;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
type Ticket = {
|
|
453
|
+
capacity: number;
|
|
454
|
+
category: string;
|
|
455
|
+
changed?: string;
|
|
456
|
+
/**
|
|
457
|
+
* Describe fees and other costs associated with purchasing tickets
|
|
458
|
+
* to this offering
|
|
459
|
+
*/
|
|
460
|
+
costComponents?: Array<CostComponent>;
|
|
461
|
+
costs: OfferingCosts;
|
|
462
|
+
created: string;
|
|
463
|
+
description?: string;
|
|
464
|
+
display_name?: string;
|
|
465
|
+
id: string;
|
|
466
|
+
included?: Array<PackageInclude>;
|
|
467
|
+
instructions?: string;
|
|
468
|
+
maximumQuantity: number;
|
|
469
|
+
minimumQuantity: number;
|
|
470
|
+
/**
|
|
471
|
+
* Offering name, can be ticket name, vaucher name, etc...
|
|
472
|
+
*/
|
|
473
|
+
name: string;
|
|
474
|
+
order_confirmation_message?: string;
|
|
475
|
+
package?: boolean;
|
|
476
|
+
parentId?: string;
|
|
477
|
+
priceCategory: PriceCategory;
|
|
478
|
+
quantitySold: number;
|
|
479
|
+
refId?: string;
|
|
480
|
+
salesEnd: string;
|
|
481
|
+
salesStart: string;
|
|
482
|
+
schedule?: Schedule;
|
|
483
|
+
sorting: number;
|
|
484
|
+
source: string;
|
|
485
|
+
status: OfferingStatus;
|
|
486
|
+
ticketParentId?: string;
|
|
487
|
+
type: Ticket.type;
|
|
488
|
+
};
|
|
489
|
+
declare namespace Ticket {
|
|
490
|
+
enum type {
|
|
491
|
+
ADMISSION = "admission",
|
|
492
|
+
PACKAGE = "package"
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
49
496
|
/**
|
|
50
497
|
* Provides methods to interact with the Cohost Events API.
|
|
51
498
|
*
|
|
@@ -64,7 +511,7 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
64
511
|
* @returns A Promise resolving to the event object
|
|
65
512
|
* @throws Will throw an error if the request fails or the event is not found
|
|
66
513
|
*/
|
|
67
|
-
fetch(id: string): Promise<
|
|
514
|
+
fetch(id: string): Promise<EventProfile>;
|
|
68
515
|
/**
|
|
69
516
|
* List all tickets associated with a specific event.
|
|
70
517
|
*
|
|
@@ -72,7 +519,7 @@ declare class EventsAPI extends CohostEndpoint {
|
|
|
72
519
|
* @returns A Promise resolving to an array of ticket objects
|
|
73
520
|
* @throws Will throw an error if the request fails or the event does not exist
|
|
74
521
|
*/
|
|
75
|
-
tickets(id: string): Promise<
|
|
522
|
+
tickets(id: string): Promise<Ticket[]>;
|
|
76
523
|
}
|
|
77
524
|
|
|
78
525
|
/**
|
|
@@ -107,20 +554,30 @@ interface CohostClientOptions {
|
|
|
107
554
|
}
|
|
108
555
|
/**
|
|
109
556
|
* CohostClient provides grouped access to various API modules such as Events and Orders.
|
|
110
|
-
*
|
|
111
|
-
* Usage:
|
|
112
|
-
* ```ts
|
|
113
|
-
* const client = new CohostClient({ token: 'your-token' });
|
|
114
|
-
* const event = await client.events.fetch('event-id');
|
|
115
|
-
* const order = await client.orders.fetch('order-id', 'user-id');
|
|
116
|
-
* ```
|
|
117
557
|
*/
|
|
118
558
|
declare class CohostClient {
|
|
119
|
-
/** Access to Event-related endpoints */
|
|
120
559
|
readonly events: EventsAPI;
|
|
121
|
-
/** Access to Order-related endpoints */
|
|
122
560
|
readonly orders: OrdersAPI;
|
|
123
|
-
|
|
561
|
+
private readonly baseOptions;
|
|
562
|
+
constructor(options: CohostClientOptions, customRequestFn?: RequestFn);
|
|
563
|
+
/**
|
|
564
|
+
* Returns a new CohostClient instance with overridden request behavior
|
|
565
|
+
*/
|
|
566
|
+
requestWithOverrides(overrides: {
|
|
567
|
+
token?: string;
|
|
568
|
+
baseUrl?: string;
|
|
569
|
+
headers?: Record<string, string>;
|
|
570
|
+
}): CohostClient;
|
|
124
571
|
}
|
|
125
572
|
|
|
126
|
-
|
|
573
|
+
/**
|
|
574
|
+
* Factory method for creating a CohostClient instance.
|
|
575
|
+
*
|
|
576
|
+
* Example:
|
|
577
|
+
* ```ts
|
|
578
|
+
* const client = createCohostClient({ token: 'your-token' });
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
declare function createCohostClient(options: CohostClientOptions): CohostClient;
|
|
582
|
+
|
|
583
|
+
export { CohostClient, createCohostClient };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var E=(e,t,s)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var w=(e,t)=>{for(var s in t)h(e,s,{get:t[s],enumerable:!0})},F=(e,t,s,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of $(t))!v.call(e,r)&&r!==s&&h(e,r,{get:()=>t[r],enumerable:!(n=P(t,r))||n.enumerable});return e};var B=e=>F(h({},"__esModule",{value:!0}),e);var a=(e,t,s)=>E(e,typeof t!="symbol"?t+"":t,s);var j={};w(j,{CohostClient:()=>l,createCohostClient:()=>D});module.exports=B(j);var p=class{constructor(t,s){a(this,"request");a(this,"settings");this.request=t,this.settings=s}};var f=class extends p{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var m=class extends p{async fetch(t,s){return this.request(`/orders/${t}`)}};var c="https://api.cohost.com/v1";var x={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},b={};var y=({token:e,baseUrl:t=c,debug:s=!1})=>async function(n,r={}){let{method:i="GET",data:u,query:R,headers:O={}}=r,T=R?"?"+new URLSearchParams(Object.entries(R).reduce((g,[k,S])=>(S!==void 0&&(g[k]=String(S)),g),{})).toString():"",U=`${b.baseUrl??t}${n}${T}`,C={...x.headers,...b.headers,...O};e&&(C.Authorization=`Bearer ${e}`);let q=u&&i!=="GET"?JSON.stringify(u):void 0;s&&(console.log(`[Cohost SDK] Request: ${i} ${U}`),q&&console.log("[Cohost SDK] Body:",q),console.log("[Cohost SDK] Headers:",C));let d=await fetch(U,{method:i,headers:C,body:q}),o=d.headers.get("content-type")?.includes("application/json")?await d.json():await d.text();if(!d.ok){let g=typeof o=="string"?o:JSON.stringify(o);throw new Error(`[Cohost SDK] ${d.status} ${d.statusText}: ${g}`)}return typeof o=="object"&&o!==null&&o.status==="ok"&&"data"in o?o.data:o};var l=class e{constructor(t,s){a(this,"events");a(this,"orders");a(this,"baseOptions");this.baseOptions=t;let{token:n,settings:r={}}=t,i=s??y({token:n,baseUrl:r.apiUrl||c,debug:r.debug});this.events=new f(i,r),this.orders=new m(i,r)}requestWithOverrides(t){let{token:s,settings:n={}}=this.baseOptions,r=(i,u={})=>y({token:t.token??s,baseUrl:t.baseUrl??n.apiUrl??c,debug:n.debug})(i,{...u,headers:{...t.headers||{},...u.headers||{}}});return new e({token:t.token??s,settings:{...n,apiUrl:t.baseUrl??n.apiUrl}},r)}};function D(e){return new l(e)}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/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["export {\n CohostClient } from './client';","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","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\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 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 * 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(`/events/${id}`);\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(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { 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 * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\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}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\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\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\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\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 throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\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 * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = 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 }\n}\n"],"mappings":"ijBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GCOO,IAAMI,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAU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AkB,EAC7C,MAAMA,EAAI,KAAK,EAAI,MAAMA,EAAI,KAAK,EAEhE,GAAI,CAACA,EAAI,GAAI,CACT,IAAME,EAAU,OAAOD,GAAiB,SAAWA,EAAe,KAAK,UAAUA,CAAY,EAC7F,MAAM,IAAI,MAAM,gBAAgBD,EAAI,MAAM,IAAIA,EAAI,UAAU,KAAKE,CAAO,EAAE,CAC9E,CAEA,OAAI,OAAOD,GAAiB,UAAYA,IAAiB,MAAQA,EAAa,SAAW,MAAQ,SAAUA,EAChGA,EAAa,KAGjBA,CACX,EClEG,IAAME,EAAN,KAAmB,CAOxB,YAAY,CAAE,MAAAC,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAwB,CAL3DC,EAAA,KAAS,UAGTA,EAAA,KAAS,UAGP,IAAMC,EAA2BC,EAAQ,CACvC,MAAAJ,EACA,QAASC,EAAS,QAAUI,EAC5B,MAAOJ,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF","names":["index_exports","__export","CohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/settings.ts","../src/http/request.ts","../src/client.ts"],"sourcesContent":["import { CohostClient, CohostClientOptions } from './client';\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 }","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","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { EventProfile, Ticket } from '../../types/index';\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 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 * 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 * 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","// src/api/OrdersAPI.ts\n\nimport { 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 * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\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}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\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 { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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\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?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\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: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\n new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : \"\";\n\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n // If wrapped response structure with { status: 'ok', data }, return `data`\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 // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\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\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 }\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,ECTO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAsB,WAAWA,C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U,CACR,GAAGC,EACH,OAAQM,EAAU,SAAWN,EAAS,MACxC,CACF,EACAO,CACF,CACF,CACF,EPjEO,SAASE,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["index_exports","__export","CohostClient","createCohostClient","__toCommonJS","CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","overrides","overriddenRequest","path","createCohostClient","options","CohostClient"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k=Object.defineProperty;var P=(e,t,s)=>t in e?k(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var a=(e,t,s)=>P(e,typeof t!="symbol"?t+"":t,s);var p=class{constructor(t,s){a(this,"request");a(this,"settings");this.request=t,this.settings=s}};var g=class extends p{async fetch(t){return this.request(`/events/${t}`)}async tickets(t){return this.request(`/events/${t}/tickets`)}};var h=class extends p{async fetch(t,s){return this.request(`/orders/${t}`)}};var c="https://api.cohost.com/v1";var S={baseUrl:"https://api.cohost.vip",headers:{"Content-Type":"application/json"}},q={};var b=({token:e,baseUrl:t=c,debug:s=!1})=>async function(n,o={}){let{method:i="GET",data:u,query:y,headers:x={}}=o,O=y?"?"+new URLSearchParams(Object.entries(y).reduce((l,[T,U])=>(U!==void 0&&(l[T]=String(U)),l),{})).toString():"",R=`${q.baseUrl??t}${n}${O}`,m={...S.headers,...q.headers,...x};e&&(m.Authorization=`Bearer ${e}`);let C=u&&i!=="GET"?JSON.stringify(u):void 0;s&&(console.log(`[Cohost SDK] Request: ${i} ${R}`),C&&console.log("[Cohost SDK] Body:",C),console.log("[Cohost SDK] Headers:",m));let d=await fetch(R,{method:i,headers:m,body:C}),r=d.headers.get("content-type")?.includes("application/json")?await d.json():await d.text();if(!d.ok){let l=typeof r=="string"?r:JSON.stringify(r);throw new Error(`[Cohost SDK] ${d.status} ${d.statusText}: ${l}`)}return typeof r=="object"&&r!==null&&r.status==="ok"&&"data"in r?r.data:r};var f=class e{constructor(t,s){a(this,"events");a(this,"orders");a(this,"baseOptions");this.baseOptions=t;let{token:n,settings:o={}}=t,i=s??b({token:n,baseUrl:o.apiUrl||c,debug:o.debug});this.events=new g(i,o),this.orders=new h(i,o)}requestWithOverrides(t){let{token:s,settings:n={}}=this.baseOptions,o=(i,u={})=>b({token:t.token??s,baseUrl:t.baseUrl??n.apiUrl??c,debug:n.debug})(i,{...u,headers:{...t.headers||{},...u.headers||{}}});return new e({token:t.token??s,settings:{...n,apiUrl:t.baseUrl??n.apiUrl}},o)}};function Z(e){return new f(e)}export{f as CohostClient,Z as createCohostClient};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/http/request.ts","../src/client.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","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\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 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 * 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(`/events/${id}`);\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(`/events/${id}/tickets`);\n }\n}\n","// src/api/OrdersAPI.ts\n\nimport { 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 * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\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}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","import { apiBaseUrl } from \"../apiVersion\";\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\n/**\n * A function that performs a request to the Cohost API.\n */\ntype RequestFn = (\n /** Path of the request relative to baseUrl */\n path: string,\n options?: {\n /** HTTP method (defaults to 'GET') */\n method?: RequestMethod;\n\n /** Request body data (auto-serialized as JSON) */\n data?: any;\n\n /** Query parameters to be appended to the URL */\n query?: Record<string, string | number | boolean | undefined>;\n\n /** Additional headers to merge into the request */\n headers?: Record<string, string>;\n }\n) => Promise<any>;\n\n/**\n * Creates a request function configured with authentication and defaults.\n */\nconst request = ({ token, baseUrl = apiBaseUrl, debug = false }: RequestProps): RequestFn => {\n return async (path, { method = 'GET', data, query, headers = {} } = {}) => {\n const queryString = query\n ? '?' + new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : '';\n\n const url = `${baseUrl}${path}${queryString}`;\n\n const reqHeaders: Record<string, string> = {\n 'Content-Type': 'application/json',\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\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 throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n if (typeof responseBody === 'object' && responseBody !== null && responseBody.status === 'ok' && 'data' in responseBody) {\n return responseBody.data;\n }\n\n return responseBody;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\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 * \n * Usage:\n * ```ts\n * const client = new CohostClient({ token: 'your-token' });\n * const event = await client.events.fetch('event-id');\n * const order = await client.orders.fetch('order-id', 'user-id');\n * ```\n */\nexport class CohostClient {\n /** Access to Event-related endpoints */\n readonly events: EventsAPI;\n\n /** Access to Order-related endpoints */\n readonly orders: OrdersAPI;\n\n constructor({ token, settings = {} }: CohostClientOptions) {\n const sharedRequest: RequestFn = 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 }\n}\n"],"mappings":"oKAOO,IAAMA,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECVO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAQ,WAAWA,CAAE,EAAE,CACrC,CASA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAQ,WAAWA,CAAE,UAAU,CAC7C,CACF,ECvBO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECxBO,IAAME,EAAa,4BC2C1B,IAAMC,EAAU,CAAC,CAAE,MAAAC,EAAO,QAAAC,EAAUC,EAAY,MAAAC,EAAQ,EAAM,IACnD,MAAOC,EAAM,CAAE,OAAAC,EAAS,MAAO,KAAAC,EAAM,MAAAC,EAAO,QAAAC,EAAU,CAAC,CAAE,EAAI,CAAC,IAAM,CACvE,IAAMC,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AK,OAAS,IAAIK,EAAUH,EAAeF,CAAQ,EACnD,KAAK,OAAS,IAAIM,EAAUJ,EAAeF,CAAQ,CACrD,CACF","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","request","token","baseUrl","apiBaseUrl","debug","path","method","data","query","headers","queryString","acc","key","value","url","reqHeaders","body","res","responseBody","message","CohostClient","token","settings","__publicField","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI"]}
|
|
1
|
+
{"version":3,"sources":["../src/endpoint.ts","../src/api/events.ts","../src/api/orders.ts","../src/apiVersion.ts","../src/settings.ts","../src/http/request.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","// src/api/EventsAPI.ts\n\nimport { CohostEndpoint } from '../endpoint';\nimport { EventProfile, Ticket } from '../../types/index';\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 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 * 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 * 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","// src/api/OrdersAPI.ts\n\nimport { 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 * ```\n */\nexport class OrdersAPI extends CohostEndpoint {\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}`);\n }\n}\n","export const apiVersion = '0.1.0';\nexport const apiVersionDate = '2025-04-15';\nexport const apiBaseUrl = 'https://api.cohost.com/v1'","/**\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 { apiBaseUrl } from \"../apiVersion\";\nimport { defaultSettings, runtimeOverrides } from \"../settings\";\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\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?: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n }\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: {\n method?: RequestMethod;\n data?: any;\n query?: Record<string, string | number | boolean | undefined>;\n headers?: Record<string, string>;\n } = {}\n ): Promise<T> {\n const { method = \"GET\", data, query, headers = {} } = options;\n\n // Construct query string from `query` object\n const queryString = query\n ? \"?\" +\n new URLSearchParams(\n Object.entries(query).reduce((acc, [key, value]) => {\n if (value !== undefined) acc[key] = String(value);\n return acc;\n }, {} as Record<string, string>)\n ).toString()\n : \"\";\n\n const finalBaseUrl = runtimeOverrides.baseUrl ?? baseUrl;\n const url = `${finalBaseUrl}${path}${queryString}`;\n\n // Merge default, runtime, and per-request headers\n const reqHeaders: Record<string, string> = {\n ...defaultSettings.headers,\n ...runtimeOverrides.headers,\n ...headers,\n };\n\n // Add Authorization header if token is present\n if (token) {\n reqHeaders[\"Authorization\"] = `Bearer ${token}`;\n }\n\n // Only send body if method allows it\n const body = data && method !== \"GET\" ? JSON.stringify(data) : undefined;\n\n // Optional debug logging\n if (debug) {\n console.log(`[Cohost SDK] Request: ${method} ${url}`);\n if (body) console.log(`[Cohost SDK] Body:`, body);\n console.log(`[Cohost SDK] Headers:`, reqHeaders);\n }\n\n const res = await fetch(url, {\n method,\n headers: reqHeaders,\n body,\n });\n\n // Parse the response based on content type\n const isJson = res.headers.get(\"content-type\")?.includes(\"application/json\");\n const responseBody = isJson ? await res.json() : await res.text();\n\n // Handle error responses\n if (!res.ok) {\n const message = typeof responseBody === \"string\" ? responseBody : JSON.stringify(responseBody);\n throw new Error(`[Cohost SDK] ${res.status} ${res.statusText}: ${message}`);\n }\n\n // If wrapped response structure with { status: 'ok', data }, return `data`\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 // Fallback for raw/unwrapped responses\n return responseBody as T;\n };\n};\n\nexport { request, RequestProps, RequestFn };\n","import { EventsAPI } from './api/events';\nimport { OrdersAPI } from './api/orders';\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\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 }\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';\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 }"],"mappings":"oKAOO,IAAMA,EAAN,KAAqB,CAa1B,YAAYC,EAAoBC,EAAgC,CAXhEC,EAAA,KAAU,WAGVA,EAAA,KAAU,YASR,KAAK,QAAUF,EACf,KAAK,SAAWC,CAClB,CACF,ECTO,IAAME,EAAN,cAAwBC,CAAe,CAQ5C,MAAM,MAAMC,EAAY,CACtB,OAAO,KAAK,QAAsB,WAAWA,CAAE,EAAE,CACnD,CASA,MAAM,QAAQA,EAAY,CACxB,OAAO,KAAK,QAAkB,WAAWA,CAAE,UAAU,CACvD,CACF,ECxBO,IAAMC,EAAN,cAAwBC,CAAe,CAS5C,MAAM,MAAMC,EAAYC,EAAa,CAEnC,OAAO,KAAK,QAAQ,WAAWD,CAAE,EAAE,CACrC,CACF,ECxBO,IAAME,EAAa,4BCUnB,IAAMC,EAAkB,CAC3B,QAAS,yBACT,QAAS,CACL,eAAgB,kBACpB,CACJ,EAGWC,EAGP,CAAC,ECiBL,IAAMC,EAAU,CAAC,CAAE,MAAAC,EAAO,QAAAC,EAAUC,EAAY,MAAAC,EAAQ,EAAM,IACrD,eACLC,EACAC,EAKI,CAAC,EACO,CACZ,GAAM,CAAE,OAAAC,EAAS,MAAO,KAAAC,EAAM,MAAAC,EAAO,QAAAC,EAAU,CAAC,CAAE,EAAIJ,EAGhDK,EAAcF,EAChB,IACA,IAAI,gBACF,OAAO,QAAQA,CAAK,EAAE,OAAO,CAACG,EAAK,CAACC,EAAKC,CAAK,KACxCA,IAAU,SAAWF,EAAIC,CAAG,EAAI,OA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,EAAS,KAClB,CAAC,EAED,KAAK,OAAS,IAAII,EAAUH,EAAeD,CAAQ,EACnD,KAAK,OAAS,IAAIK,EAAUJ,EAAeD,CAAQ,CACrD,CAKO,qBAAqBM,EAIX,CACf,GAAM,CAAE,MAAAP,EAAO,SAAAC,EAAW,CAAC,CAAE,EAAI,KAAK,YAEhCO,EAA+B,CAACC,EAAMZ,EAAU,CAAC,IACrDM,EAAQ,CACN,MAAOI,EAAU,OAASP,EAC1B,QAASO,EAAU,SAAWN,EAAS,QAAUG,EACjD,MAAOH,EAAS,KAClB,CAAC,EAAEQ,EAAM,CACP,GAAGZ,EACH,QAAS,CACP,GAAIU,EAAU,SAAW,CAAC,EAC1B,GAAIV,EAAQ,SAAW,CAAC,CAC1B,CACF,CAAC,EAEH,OAAO,IAAID,EACT,CACE,MAAOW,EAAU,OAASP,EAC1B,SAAU,CACR,GAAGC,EACH,OAAQM,EAAU,SAAWN,EAAS,MACxC,CACF,EACAO,CACF,CACF,CACF,ECjEO,SAASE,EAAmBC,EAA4C,CAC3E,OAAO,IAAIC,EAAaD,CAAO,CACnC","names":["CohostEndpoint","request","settings","__publicField","EventsAPI","CohostEndpoint","id","OrdersAPI","CohostEndpoint","id","uid","apiBaseUrl","defaultSettings","runtimeOverrides","request","token","baseUrl","apiBaseUrl","debug","path","options","method","data","query","headers","queryString","acc","key","value","url","runtimeOverrides","reqHeaders","defaultSettings","body","res","responseBody","message","CohostClient","_CohostClient","options","customRequestFn","__publicField","token","settings","sharedRequest","request","apiBaseUrl","EventsAPI","OrdersAPI","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.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Cohost API wrapper",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"require": "./dist/index.cjs",
|
|
11
|
-
"import": "./dist/index.mjs"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
11
|
+
"import": "./dist/index.mjs"
|
|
13
12
|
}
|
|
14
13
|
},
|
|
15
14
|
"files": [
|