@seshn/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,650 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/errors.ts
12
+ var errors_exports = {};
13
+ __export(errors_exports, {
14
+ CancellationDeadlineError: () => CancellationDeadlineError,
15
+ ConflictError: () => ConflictError,
16
+ ForbiddenError: () => ForbiddenError,
17
+ HeadlessBookingError: () => HeadlessBookingError,
18
+ InsufficientCapacityError: () => InsufficientCapacityError,
19
+ InsufficientCreditsError: () => InsufficientCreditsError,
20
+ InvalidStateError: () => InvalidStateError,
21
+ NotFoundError: () => NotFoundError,
22
+ PaymentProviderError: () => PaymentProviderError,
23
+ RateLimitError: () => RateLimitError,
24
+ SeshnError: () => SeshnError,
25
+ UnauthorizedError: () => UnauthorizedError,
26
+ ValidationError: () => ValidationError,
27
+ createError: () => createError
28
+ });
29
+ function createError(status, body) {
30
+ switch (status) {
31
+ case 400:
32
+ return new ValidationError(body);
33
+ case 401:
34
+ return new UnauthorizedError(body);
35
+ case 403:
36
+ return new ForbiddenError(body);
37
+ case 404:
38
+ return new NotFoundError(body);
39
+ case 409:
40
+ if (body.code === "INSUFFICIENT_CAPACITY") return new InsufficientCapacityError(body);
41
+ if (body.code === "INSUFFICIENT_CREDITS") return new InsufficientCreditsError(body);
42
+ return new ConflictError(body);
43
+ case 422:
44
+ if (body.code === "INVALID_STATE" && body.error?.toLowerCase().includes("cancellation deadline")) {
45
+ return new CancellationDeadlineError(body);
46
+ }
47
+ return new InvalidStateError(body);
48
+ case 429:
49
+ return new RateLimitError(body);
50
+ case 502:
51
+ return new PaymentProviderError(body);
52
+ default:
53
+ return new SeshnError(status, body);
54
+ }
55
+ }
56
+ var SeshnError, NotFoundError, ValidationError, UnauthorizedError, ConflictError, InsufficientCapacityError, InsufficientCreditsError, InvalidStateError, CancellationDeadlineError, ForbiddenError, RateLimitError, PaymentProviderError, HeadlessBookingError;
57
+ var init_errors = __esm({
58
+ "src/errors.ts"() {
59
+ "use strict";
60
+ SeshnError = class extends Error {
61
+ status;
62
+ code;
63
+ details;
64
+ constructor(status, body) {
65
+ super(body.error);
66
+ this.name = "SeshnError";
67
+ this.status = status;
68
+ this.code = body.code;
69
+ this.details = body.details;
70
+ }
71
+ };
72
+ NotFoundError = class extends SeshnError {
73
+ constructor(body) {
74
+ super(404, body);
75
+ this.name = "NotFoundError";
76
+ }
77
+ };
78
+ ValidationError = class extends SeshnError {
79
+ constructor(body) {
80
+ super(400, body);
81
+ this.name = "ValidationError";
82
+ }
83
+ };
84
+ UnauthorizedError = class extends SeshnError {
85
+ constructor(body) {
86
+ super(401, body);
87
+ this.name = "UnauthorizedError";
88
+ }
89
+ };
90
+ ConflictError = class extends SeshnError {
91
+ constructor(body) {
92
+ super(409, body);
93
+ this.name = "ConflictError";
94
+ }
95
+ };
96
+ InsufficientCapacityError = class extends ConflictError {
97
+ constructor(body) {
98
+ super(body);
99
+ this.name = "InsufficientCapacityError";
100
+ }
101
+ };
102
+ InsufficientCreditsError = class extends ConflictError {
103
+ constructor(body) {
104
+ super(body);
105
+ this.name = "InsufficientCreditsError";
106
+ }
107
+ };
108
+ InvalidStateError = class extends SeshnError {
109
+ constructor(body) {
110
+ super(422, body);
111
+ this.name = "InvalidStateError";
112
+ }
113
+ };
114
+ CancellationDeadlineError = class extends InvalidStateError {
115
+ constructor(body) {
116
+ super(body);
117
+ this.name = "CancellationDeadlineError";
118
+ }
119
+ };
120
+ ForbiddenError = class extends SeshnError {
121
+ constructor(body) {
122
+ super(403, body);
123
+ this.name = "ForbiddenError";
124
+ }
125
+ };
126
+ RateLimitError = class extends SeshnError {
127
+ constructor(body) {
128
+ super(429, body);
129
+ this.name = "RateLimitError";
130
+ }
131
+ };
132
+ PaymentProviderError = class extends SeshnError {
133
+ constructor(body) {
134
+ super(502, body);
135
+ this.name = "PaymentProviderError";
136
+ }
137
+ };
138
+ HeadlessBookingError = SeshnError;
139
+ }
140
+ });
141
+
142
+ // src/client.ts
143
+ init_errors();
144
+ var HttpClient = class {
145
+ apiKey;
146
+ baseUrl;
147
+ constructor(options) {
148
+ this.apiKey = options.apiKey;
149
+ this.baseUrl = (options.baseUrl ?? "http://localhost:3000").replace(/\/$/, "");
150
+ }
151
+ async request(method, path, body) {
152
+ const headers = {
153
+ "Authorization": `Bearer ${this.apiKey}`,
154
+ "Content-Type": "application/json"
155
+ };
156
+ const response = await fetch(`${this.baseUrl}${path}`, {
157
+ method,
158
+ headers,
159
+ body: body !== void 0 ? JSON.stringify(body) : void 0
160
+ });
161
+ if (!response.ok) {
162
+ let errorBody;
163
+ try {
164
+ errorBody = await response.json();
165
+ } catch {
166
+ errorBody = { error: response.statusText, code: "UNKNOWN_ERROR" };
167
+ }
168
+ throw createError(response.status, errorBody);
169
+ }
170
+ return response.json();
171
+ }
172
+ get(path) {
173
+ return this.request("GET", path);
174
+ }
175
+ post(path, body) {
176
+ return this.request("POST", path, body);
177
+ }
178
+ put(path, body) {
179
+ return this.request("PUT", path, body);
180
+ }
181
+ delete(path) {
182
+ return this.request("DELETE", path);
183
+ }
184
+ };
185
+
186
+ // src/resources/api-keys.ts
187
+ var ApiKeys = class {
188
+ constructor(client) {
189
+ this.client = client;
190
+ }
191
+ async create(data) {
192
+ return this.client.post("/v1/api-keys", data);
193
+ }
194
+ async list(params) {
195
+ const search = new URLSearchParams();
196
+ if (params?.cursor) search.set("cursor", params.cursor);
197
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
198
+ const query = search.toString();
199
+ const path = query ? `/v1/api-keys?${query}` : "/v1/api-keys";
200
+ return this.client.get(path);
201
+ }
202
+ async revoke(id) {
203
+ return this.client.delete(`/v1/api-keys/${id}`);
204
+ }
205
+ };
206
+
207
+ // src/resources/audit-log.ts
208
+ var AuditLog = class {
209
+ constructor(client) {
210
+ this.client = client;
211
+ }
212
+ async list(params) {
213
+ const search = new URLSearchParams();
214
+ if (params?.action) search.set("action", params.action);
215
+ if (params?.resourceType) search.set("resourceType", params.resourceType);
216
+ if (params?.userId) search.set("userId", params.userId);
217
+ if (params?.cursor) search.set("cursor", params.cursor);
218
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
219
+ const query = search.toString();
220
+ const path = query ? `/v1/audit-log?${query}` : "/v1/audit-log";
221
+ return this.client.get(path);
222
+ }
223
+ };
224
+
225
+ // src/resources/availability.ts
226
+ var Availability = class {
227
+ constructor(client) {
228
+ this.client = client;
229
+ }
230
+ async query(params) {
231
+ const search = new URLSearchParams({
232
+ serviceId: params.serviceId,
233
+ from: params.from,
234
+ to: params.to
235
+ });
236
+ if (params.minSeats !== void 0) {
237
+ search.set("minSeats", String(params.minSeats));
238
+ }
239
+ if (params.cursor) search.set("cursor", params.cursor);
240
+ if (params.limit !== void 0) search.set("limit", String(params.limit));
241
+ return this.client.get(
242
+ `/v1/availability?${search.toString()}`
243
+ );
244
+ }
245
+ async generate(data) {
246
+ return this.client.post("/v1/availability/generate", data);
247
+ }
248
+ };
249
+
250
+ // src/resources/bookings.ts
251
+ var Bookings = class {
252
+ constructor(client) {
253
+ this.client = client;
254
+ }
255
+ async create(data) {
256
+ return this.client.post("/v1/bookings", data);
257
+ }
258
+ async list(params) {
259
+ const search = new URLSearchParams();
260
+ if (params?.contactId) search.set("contactId", params.contactId);
261
+ if (params?.slotId) search.set("slotId", params.slotId);
262
+ if (params?.status) search.set("status", params.status);
263
+ if (params?.cursor) search.set("cursor", params.cursor);
264
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
265
+ const query = search.toString();
266
+ const path = query ? `/v1/bookings?${query}` : "/v1/bookings";
267
+ return this.client.get(path);
268
+ }
269
+ async get(id) {
270
+ return this.client.get(`/v1/bookings/${id}`);
271
+ }
272
+ async confirm(id, data) {
273
+ return this.client.post(`/v1/bookings/${id}/confirm`, data ?? {});
274
+ }
275
+ async cancel(id, data) {
276
+ return this.client.put(`/v1/bookings/${id}/cancel`, data ?? {});
277
+ }
278
+ async reschedule(id, data) {
279
+ return this.client.put(`/v1/bookings/${id}/reschedule`, data);
280
+ }
281
+ async checkIn(id) {
282
+ return this.client.post(`/v1/bookings/${id}/checkin`);
283
+ }
284
+ };
285
+
286
+ // src/resources/booking-series.ts
287
+ var BookingSeries = class {
288
+ constructor(client) {
289
+ this.client = client;
290
+ }
291
+ async create(data) {
292
+ return this.client.post("/v1/booking-series", data);
293
+ }
294
+ async list(params) {
295
+ const search = new URLSearchParams();
296
+ if (params?.contactId) search.set("contactId", params.contactId);
297
+ if (params?.serviceId) search.set("serviceId", params.serviceId);
298
+ if (params?.status) search.set("status", params.status);
299
+ if (params?.cursor) search.set("cursor", params.cursor);
300
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
301
+ const query = search.toString();
302
+ const path = query ? `/v1/booking-series?${query}` : "/v1/booking-series";
303
+ return this.client.get(path);
304
+ }
305
+ async get(id) {
306
+ return this.client.get(`/v1/booking-series/${id}`);
307
+ }
308
+ async cancel(id, scope = "future") {
309
+ return this.client.delete(
310
+ `/v1/booking-series/${id}?scope=${scope}`
311
+ );
312
+ }
313
+ async cancelOccurrence(seriesId, index) {
314
+ return this.client.delete(
315
+ `/v1/booking-series/${seriesId}/occurrences/${index}`
316
+ );
317
+ }
318
+ };
319
+
320
+ // src/resources/contacts.ts
321
+ var Contacts = class {
322
+ constructor(client) {
323
+ this.client = client;
324
+ }
325
+ async create(data) {
326
+ return this.client.post("/v1/contacts", data);
327
+ }
328
+ async list(params) {
329
+ const search = new URLSearchParams();
330
+ if (params?.cursor) search.set("cursor", params.cursor);
331
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
332
+ const query = search.toString();
333
+ const path = query ? `/v1/contacts?${query}` : "/v1/contacts";
334
+ return this.client.get(path);
335
+ }
336
+ async get(id) {
337
+ return this.client.get(`/v1/contacts/${id}`);
338
+ }
339
+ async update(id, data) {
340
+ return this.client.put(`/v1/contacts/${id}`, data);
341
+ }
342
+ };
343
+
344
+ // src/resources/entitlements.ts
345
+ var Entitlements = class {
346
+ constructor(client) {
347
+ this.client = client;
348
+ }
349
+ async createType(data) {
350
+ return this.client.post("/v1/entitlements/types", data);
351
+ }
352
+ async listTypes(params) {
353
+ const search = new URLSearchParams();
354
+ if (params?.cursor) search.set("cursor", params.cursor);
355
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
356
+ const query = search.toString();
357
+ const path = query ? `/v1/entitlements/types?${query}` : "/v1/entitlements/types";
358
+ return this.client.get(path);
359
+ }
360
+ async issue(data) {
361
+ return this.client.post("/v1/entitlements", data);
362
+ }
363
+ async list(params) {
364
+ const search = new URLSearchParams({ contactId: params.contactId });
365
+ if (params.serviceId) search.set("serviceId", params.serviceId);
366
+ if (params.cursor) search.set("cursor", params.cursor);
367
+ if (params.limit !== void 0) search.set("limit", String(params.limit));
368
+ return this.client.get(
369
+ `/v1/entitlements?${search.toString()}`
370
+ );
371
+ }
372
+ async get(id) {
373
+ return this.client.get(`/v1/entitlements/${id}`);
374
+ }
375
+ };
376
+
377
+ // src/resources/locations.ts
378
+ var Locations = class {
379
+ constructor(client) {
380
+ this.client = client;
381
+ }
382
+ async create(data) {
383
+ return this.client.post("/v1/locations", data);
384
+ }
385
+ async list(params) {
386
+ const search = new URLSearchParams();
387
+ if (params?.cursor) search.set("cursor", params.cursor);
388
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
389
+ const query = search.toString();
390
+ const path = query ? `/v1/locations?${query}` : "/v1/locations";
391
+ return this.client.get(path);
392
+ }
393
+ };
394
+
395
+ // src/resources/organizations.ts
396
+ var Organizations = class {
397
+ constructor(client, baseUrl) {
398
+ this.client = client;
399
+ this.baseUrl = baseUrl.replace(/\/$/, "");
400
+ }
401
+ baseUrl;
402
+ async create(data) {
403
+ const response = await fetch(`${this.baseUrl}/organizations`, {
404
+ method: "POST",
405
+ headers: { "Content-Type": "application/json" },
406
+ body: JSON.stringify(data)
407
+ });
408
+ if (!response.ok) {
409
+ const { createError: createError2 } = await Promise.resolve().then(() => (init_errors(), errors_exports));
410
+ const body = await response.json();
411
+ throw createError2(response.status, body);
412
+ }
413
+ return response.json();
414
+ }
415
+ };
416
+
417
+ // src/resources/payments.ts
418
+ var Payments = class {
419
+ constructor(client) {
420
+ this.client = client;
421
+ }
422
+ async list(params) {
423
+ const search = new URLSearchParams();
424
+ if (params?.cursor) search.set("cursor", params.cursor);
425
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
426
+ const query = search.toString();
427
+ const path = query ? `/v1/payments?${query}` : "/v1/payments";
428
+ return this.client.get(path);
429
+ }
430
+ async get(id) {
431
+ return this.client.get(`/v1/payments/${id}`);
432
+ }
433
+ async refund(id, amount) {
434
+ return this.client.post(
435
+ `/v1/payments/${id}/refund`,
436
+ amount ? { amount } : {}
437
+ );
438
+ }
439
+ };
440
+
441
+ // src/resources/resources.ts
442
+ var Resources = class {
443
+ constructor(client) {
444
+ this.client = client;
445
+ }
446
+ async create(data) {
447
+ return this.client.post("/v1/resources", data);
448
+ }
449
+ };
450
+
451
+ // src/resources/services.ts
452
+ var Services = class {
453
+ constructor(client) {
454
+ this.client = client;
455
+ }
456
+ async create(data) {
457
+ return this.client.post("/v1/services", data);
458
+ }
459
+ async list(params) {
460
+ const search = new URLSearchParams();
461
+ if (params?.cursor) search.set("cursor", params.cursor);
462
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
463
+ const query = search.toString();
464
+ const path = query ? `/v1/services?${query}` : "/v1/services";
465
+ return this.client.get(path);
466
+ }
467
+ async get(id) {
468
+ return this.client.get(`/v1/services/${id}`);
469
+ }
470
+ async update(id, data) {
471
+ return this.client.put(`/v1/services/${id}`, data);
472
+ }
473
+ async delete(id) {
474
+ return this.client.delete(`/v1/services/${id}`);
475
+ }
476
+ async linkResource(serviceId, data) {
477
+ return this.client.post(`/v1/services/${serviceId}/resources`, data);
478
+ }
479
+ async addPricing(serviceId, data) {
480
+ return this.client.post(`/v1/services/${serviceId}/pricing`, data);
481
+ }
482
+ async createSchedule(serviceId, data) {
483
+ return this.client.post(`/v1/services/${serviceId}/schedules`, data);
484
+ }
485
+ async addOverride(serviceId, scheduleId, data) {
486
+ return this.client.post(
487
+ `/v1/services/${serviceId}/schedules/${scheduleId}/overrides`,
488
+ data
489
+ );
490
+ }
491
+ };
492
+
493
+ // src/resources/users.ts
494
+ var Users = class {
495
+ constructor(client) {
496
+ this.client = client;
497
+ }
498
+ async create(data) {
499
+ return this.client.post("/v1/users", data);
500
+ }
501
+ async list(params) {
502
+ const search = new URLSearchParams();
503
+ if (params?.cursor) search.set("cursor", params.cursor);
504
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
505
+ const query = search.toString();
506
+ const path = query ? `/v1/users?${query}` : "/v1/users";
507
+ return this.client.get(path);
508
+ }
509
+ async get(id) {
510
+ return this.client.get(`/v1/users/${id}`);
511
+ }
512
+ async update(id, data) {
513
+ return this.client.put(`/v1/users/${id}`, data);
514
+ }
515
+ async delete(id) {
516
+ return this.client.delete(`/v1/users/${id}`);
517
+ }
518
+ };
519
+
520
+ // src/resources/waitlist.ts
521
+ var Waitlist = class {
522
+ constructor(client) {
523
+ this.client = client;
524
+ }
525
+ async join(data) {
526
+ return this.client.post("/v1/waitlist", data);
527
+ }
528
+ async list(params) {
529
+ const search = new URLSearchParams();
530
+ if (params?.slotId) search.set("slotId", params.slotId);
531
+ if (params?.contactId) search.set("contactId", params.contactId);
532
+ if (params?.status) search.set("status", params.status);
533
+ if (params?.cursor) search.set("cursor", params.cursor);
534
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
535
+ const query = search.toString();
536
+ const path = query ? `/v1/waitlist?${query}` : "/v1/waitlist";
537
+ return this.client.get(path);
538
+ }
539
+ async cancel(id) {
540
+ return this.client.delete(`/v1/waitlist/${id}`);
541
+ }
542
+ };
543
+
544
+ // src/resources/webhooks.ts
545
+ var Webhooks = class {
546
+ constructor(client) {
547
+ this.client = client;
548
+ }
549
+ async create(data) {
550
+ return this.client.post("/v1/webhooks", data);
551
+ }
552
+ async list(params) {
553
+ const search = new URLSearchParams();
554
+ if (params?.cursor) search.set("cursor", params.cursor);
555
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
556
+ const query = search.toString();
557
+ const path = query ? `/v1/webhooks?${query}` : "/v1/webhooks";
558
+ return this.client.get(path);
559
+ }
560
+ async delete(id) {
561
+ return this.client.delete(`/v1/webhooks/${id}`);
562
+ }
563
+ async listDeliveries(webhookId, params) {
564
+ const search = new URLSearchParams();
565
+ if (params?.cursor) search.set("cursor", params.cursor);
566
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
567
+ const query = search.toString();
568
+ const path = query ? `/v1/webhooks/${webhookId}/deliveries?${query}` : `/v1/webhooks/${webhookId}/deliveries`;
569
+ return this.client.get(path);
570
+ }
571
+ };
572
+
573
+ // src/index.ts
574
+ init_errors();
575
+ var Seshn = class {
576
+ apiKeys;
577
+ auditLog;
578
+ availability;
579
+ bookings;
580
+ bookingSeries;
581
+ contacts;
582
+ entitlements;
583
+ locations;
584
+ organizations;
585
+ payments;
586
+ resources;
587
+ services;
588
+ users;
589
+ waitlist;
590
+ webhooks;
591
+ constructor(apiKey, options) {
592
+ const opts = {
593
+ apiKey,
594
+ baseUrl: options?.baseUrl
595
+ };
596
+ const client = new HttpClient(opts);
597
+ const baseUrl = opts.baseUrl ?? "http://localhost:3000";
598
+ this.apiKeys = new ApiKeys(client);
599
+ this.auditLog = new AuditLog(client);
600
+ this.availability = new Availability(client);
601
+ this.bookings = new Bookings(client);
602
+ this.bookingSeries = new BookingSeries(client);
603
+ this.contacts = new Contacts(client);
604
+ this.entitlements = new Entitlements(client);
605
+ this.locations = new Locations(client);
606
+ this.organizations = new Organizations(client, baseUrl);
607
+ this.payments = new Payments(client);
608
+ this.resources = new Resources(client);
609
+ this.services = new Services(client);
610
+ this.users = new Users(client);
611
+ this.waitlist = new Waitlist(client);
612
+ this.webhooks = new Webhooks(client);
613
+ }
614
+ };
615
+ var HeadlessBooking = Seshn;
616
+ export {
617
+ ApiKeys,
618
+ AuditLog,
619
+ Availability,
620
+ BookingSeries,
621
+ Bookings,
622
+ CancellationDeadlineError,
623
+ ConflictError,
624
+ Contacts,
625
+ Entitlements,
626
+ ForbiddenError,
627
+ HeadlessBooking,
628
+ HeadlessBookingError,
629
+ HttpClient,
630
+ InsufficientCapacityError,
631
+ InsufficientCreditsError,
632
+ InvalidStateError,
633
+ Locations,
634
+ NotFoundError,
635
+ Organizations,
636
+ PaymentProviderError,
637
+ Payments,
638
+ RateLimitError,
639
+ Resources,
640
+ Services,
641
+ Seshn,
642
+ SeshnError,
643
+ UnauthorizedError,
644
+ Users,
645
+ ValidationError,
646
+ Waitlist,
647
+ Webhooks,
648
+ createError
649
+ };
650
+ //# sourceMappingURL=index.js.map