@ticketlayer/backstage 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js ADDED
@@ -0,0 +1,2736 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BackstageClient = exports.SDK_CLIENT_HEADER = exports.API_DATED_VERSION = exports.BackstageAPIError = void 0;
4
+ const version_1 = require("./version");
5
+ class BackstageAPIError extends Error {
6
+ constructor(message, code, statusCode) {
7
+ super(message);
8
+ this.name = 'BackstageAPIError';
9
+ this.code = code;
10
+ this.statusCode = statusCode;
11
+ }
12
+ isPermissionDenied() {
13
+ return this.code === 'PERMISSION_DENIED';
14
+ }
15
+ isAuthenticationError() {
16
+ return this.code === 'AUTHENTICATION_REQUIRED' || this.code === 'INVALID_TOKEN' || this.code === 'SESSION_EXPIRED';
17
+ }
18
+ isSessionExpired() {
19
+ return this.code === 'SESSION_EXPIRED';
20
+ }
21
+ isNotFound() {
22
+ return this.code === 'NOT_FOUND';
23
+ }
24
+ isValidationError() {
25
+ return this.code === 'VALIDATION_ERROR';
26
+ }
27
+ }
28
+ exports.BackstageAPIError = BackstageAPIError;
29
+ exports.API_DATED_VERSION = '2026-06-13';
30
+ function describeRuntime() {
31
+ const g = globalThis;
32
+ if (g.navigator?.product === 'ReactNative')
33
+ return 'react-native';
34
+ if (typeof g.window !== 'undefined' && typeof g.document !== 'undefined')
35
+ return 'browser';
36
+ if (g.process?.versions?.node)
37
+ return `node/${g.process.versions.node}`;
38
+ if (g.EdgeRuntime)
39
+ return 'edge';
40
+ return 'unknown';
41
+ }
42
+ exports.SDK_CLIENT_HEADER = `${version_1.SDK_NAME.replace(/^@/, '').replace('/', '-')}/${version_1.SDK_VERSION} (${describeRuntime()})`;
43
+ class BackstageClient {
44
+ constructor(config) {
45
+ this.meta = {
46
+ versions: async () => {
47
+ const response = await this.request(`/meta/versions`, {
48
+ method: 'GET'
49
+ });
50
+ return response;
51
+ }
52
+ };
53
+ this.authentication = {
54
+ login: async (request) => {
55
+ const response = await this.request(`/auth/login`, {
56
+ method: 'POST',
57
+ body: JSON.stringify(request)
58
+ });
59
+ this.setAccessToken(response.accessToken);
60
+ this.setRefreshToken(response.refreshToken);
61
+ return response;
62
+ },
63
+ refresh: async (request) => {
64
+ const response = await this.request(`/auth/refresh`, {
65
+ method: 'POST',
66
+ body: JSON.stringify(request)
67
+ });
68
+ this.setAccessToken(response.accessToken);
69
+ this.setRefreshToken(response.refreshToken);
70
+ if (this.onTokenRefresh) {
71
+ await this.onTokenRefresh(response.accessToken, response.refreshToken);
72
+ }
73
+ return response;
74
+ },
75
+ redeem: async (request) => {
76
+ const response = await this.request(`/auth/redeem`, {
77
+ method: 'POST',
78
+ body: JSON.stringify(request)
79
+ });
80
+ this.setAccessToken(response.accessToken);
81
+ this.setRefreshToken(response.refreshToken);
82
+ return response;
83
+ },
84
+ federate: async (request) => {
85
+ const response = await this.request(`/auth/federate`, {
86
+ method: 'POST',
87
+ body: JSON.stringify(request)
88
+ });
89
+ this.setAccessToken(response.accessToken);
90
+ this.setRefreshToken(response.refreshToken);
91
+ return response;
92
+ }
93
+ };
94
+ this.me = {
95
+ current: async () => {
96
+ const response = await this.request(`/me`, {
97
+ method: 'GET'
98
+ });
99
+ return response.user;
100
+ },
101
+ organisations: async () => {
102
+ const response = await this.request(`/me/organisations`, {
103
+ method: 'GET'
104
+ });
105
+ return response.organisations;
106
+ },
107
+ roles: async () => {
108
+ const response = await this.request(`/me/roles`, {
109
+ method: 'GET'
110
+ });
111
+ return response;
112
+ },
113
+ permissions: async (options) => {
114
+ const params = new URLSearchParams();
115
+ if (options?.resource !== undefined)
116
+ params.append('resource', String(options.resource));
117
+ if (options?.action !== undefined)
118
+ params.append('action', String(options.action));
119
+ const queryString = params.toString();
120
+ const requestPath = queryString ? `/me/permissions?${queryString}` : `/me/permissions`;
121
+ const response = await this.request(requestPath, {
122
+ method: 'GET'
123
+ });
124
+ return response;
125
+ }
126
+ };
127
+ this.organisations = {
128
+ get: async (id) => {
129
+ const response = await this.request(`/organisations/${id}`, {
130
+ method: 'GET'
131
+ });
132
+ return response.organisation;
133
+ },
134
+ update: async (id, request) => {
135
+ const response = await this.request(`/organisations/${id}`, {
136
+ method: 'PATCH',
137
+ body: JSON.stringify(request)
138
+ });
139
+ return response.organisation;
140
+ }
141
+ };
142
+ this.accounts = {
143
+ list: async (options) => {
144
+ const params = new URLSearchParams();
145
+ if (options?.search !== undefined)
146
+ params.append('search', String(options.search));
147
+ if (options?.status !== undefined)
148
+ params.append('status', String(options.status));
149
+ const queryString = params.toString();
150
+ const requestPath = queryString ? `/accounts?${queryString}` : `/accounts`;
151
+ const response = await this.request(requestPath, {
152
+ method: 'GET'
153
+ });
154
+ return response.accounts;
155
+ },
156
+ create: async (request) => {
157
+ const response = await this.request(`/accounts`, {
158
+ method: 'POST',
159
+ body: JSON.stringify(request)
160
+ });
161
+ return response.account;
162
+ },
163
+ get: async (id) => {
164
+ const response = await this.request(`/accounts/${id}`, {
165
+ method: 'GET'
166
+ });
167
+ return response.account;
168
+ },
169
+ update: async (id, request) => {
170
+ const response = await this.request(`/accounts/${id}`, {
171
+ method: 'PATCH',
172
+ body: JSON.stringify(request)
173
+ });
174
+ return response.account;
175
+ },
176
+ delete: async (id) => {
177
+ const response = await this.request(`/accounts/${id}`, {
178
+ method: 'DELETE'
179
+ });
180
+ return response;
181
+ }
182
+ };
183
+ this.identityProviders = {
184
+ list: async (options) => {
185
+ const params = new URLSearchParams();
186
+ if (options?.organisationId !== undefined)
187
+ params.append('organisationId', String(options.organisationId));
188
+ const queryString = params.toString();
189
+ const requestPath = queryString ? `/identity-providers?${queryString}` : `/identity-providers`;
190
+ const response = await this.request(requestPath, {
191
+ method: 'GET'
192
+ });
193
+ return response.providers;
194
+ },
195
+ get: async (id) => {
196
+ const response = await this.request(`/identity-providers/${id}`, {
197
+ method: 'GET'
198
+ });
199
+ return response.provider;
200
+ },
201
+ update: async (id, request) => {
202
+ const response = await this.request(`/identity-providers/${id}`, {
203
+ method: 'PATCH',
204
+ body: JSON.stringify(request)
205
+ });
206
+ return response.provider;
207
+ }
208
+ };
209
+ this.userInvitations = {
210
+ create: async (request) => {
211
+ const response = await this.request(`/users/invitations`, {
212
+ method: 'POST',
213
+ body: JSON.stringify(request)
214
+ });
215
+ return response.invitation;
216
+ },
217
+ list: async (options) => {
218
+ const params = new URLSearchParams();
219
+ if (options?.organisationId !== undefined)
220
+ params.append('organisationId', String(options.organisationId));
221
+ if (options?.status !== undefined)
222
+ params.append('status', String(options.status));
223
+ const queryString = params.toString();
224
+ const requestPath = queryString ? `/users/invitations?${queryString}` : `/users/invitations`;
225
+ const response = await this.request(requestPath, {
226
+ method: 'GET'
227
+ });
228
+ return response.invitations;
229
+ },
230
+ get: async (id) => {
231
+ const response = await this.request(`/users/invitations/${id}`, {
232
+ method: 'GET'
233
+ });
234
+ return response.invitation;
235
+ },
236
+ cancel: async (id) => {
237
+ const response = await this.request(`/users/invitations/${id}`, {
238
+ method: 'DELETE'
239
+ });
240
+ return response;
241
+ },
242
+ resend: async (id) => {
243
+ const response = await this.request(`/users/invitations/${id}/resend`, {
244
+ method: 'POST'
245
+ });
246
+ return response.invitation;
247
+ }
248
+ };
249
+ this.roles = {
250
+ list: async () => {
251
+ const response = await this.request(`/roles`, {
252
+ method: 'GET'
253
+ });
254
+ return response.roles;
255
+ },
256
+ create: async (request) => {
257
+ const response = await this.request(`/roles`, {
258
+ method: 'POST',
259
+ body: JSON.stringify(request)
260
+ });
261
+ return response;
262
+ },
263
+ get: async (id) => {
264
+ const response = await this.request(`/roles/${id}`, {
265
+ method: 'GET'
266
+ });
267
+ return response;
268
+ },
269
+ update: async (id, request) => {
270
+ const response = await this.request(`/roles/${id}`, {
271
+ method: 'PATCH',
272
+ body: JSON.stringify(request)
273
+ });
274
+ return response;
275
+ },
276
+ delete: async (id) => {
277
+ const response = await this.request(`/roles/${id}`, {
278
+ method: 'DELETE'
279
+ });
280
+ return response;
281
+ }
282
+ };
283
+ this.userAccountRoles = {
284
+ list: async () => {
285
+ const response = await this.request(`/user-accounts`, {
286
+ method: 'GET'
287
+ });
288
+ return response.assignments;
289
+ },
290
+ assign: async (request) => {
291
+ const response = await this.request(`/user-accounts`, {
292
+ method: 'POST',
293
+ body: JSON.stringify(request)
294
+ });
295
+ return response.assignment;
296
+ },
297
+ update: async (request) => {
298
+ const response = await this.request(`/user-accounts`, {
299
+ method: 'PUT',
300
+ body: JSON.stringify(request)
301
+ });
302
+ return response.assignments;
303
+ },
304
+ remove: async (id) => {
305
+ const response = await this.request(`/user-accounts/${id}`, {
306
+ method: 'DELETE'
307
+ });
308
+ return response.success;
309
+ },
310
+ listByUser: async (userId) => {
311
+ const response = await this.request(`/user-accounts/user/${userId}`, {
312
+ method: 'GET'
313
+ });
314
+ return response.assignments;
315
+ },
316
+ listByAccount: async (accountId) => {
317
+ const response = await this.request(`/user-accounts/account/${accountId}`, {
318
+ method: 'GET'
319
+ });
320
+ return response.assignments;
321
+ }
322
+ };
323
+ this.partners = {
324
+ createAccount: async (request) => {
325
+ const response = await this.request(`/partners/accounts`, {
326
+ method: 'POST',
327
+ body: JSON.stringify(request)
328
+ });
329
+ return response;
330
+ }
331
+ };
332
+ this.apiKeys = {
333
+ create: async (request) => {
334
+ const response = await this.request(`/api-keys`, {
335
+ method: 'POST',
336
+ body: JSON.stringify(request)
337
+ });
338
+ return response;
339
+ },
340
+ list: async () => {
341
+ const response = await this.request(`/api-keys`, {
342
+ method: 'GET'
343
+ });
344
+ return response.apiKeys;
345
+ },
346
+ revoke: async (id) => {
347
+ const response = await this.request(`/api-keys/${id}`, {
348
+ method: 'DELETE'
349
+ });
350
+ return response.apiKey;
351
+ }
352
+ };
353
+ this.embedSessions = {
354
+ create: async (request) => {
355
+ const response = await this.request(`/embed/sessions`, {
356
+ method: 'POST',
357
+ body: JSON.stringify(request)
358
+ });
359
+ return response;
360
+ },
361
+ current: async () => {
362
+ const response = await this.request(`/embed/sessions/current`, {
363
+ method: 'GET'
364
+ });
365
+ return response;
366
+ }
367
+ };
368
+ this.events = Object.assign((eventId) => ({
369
+ occurrences: {
370
+ list: async (options) => {
371
+ const params = new URLSearchParams();
372
+ if (options?.status !== undefined)
373
+ params.append('status', String(options.status));
374
+ if (options?.venueId !== undefined)
375
+ params.append('venueId', String(options.venueId));
376
+ if (options?.startDateFrom !== undefined)
377
+ params.append('startDateFrom', String(options.startDateFrom));
378
+ if (options?.startDateTo !== undefined)
379
+ params.append('startDateTo', String(options.startDateTo));
380
+ if (options?.page !== undefined)
381
+ params.append('page', String(options.page));
382
+ if (options?.limit !== undefined)
383
+ params.append('limit', String(options.limit));
384
+ const queryString = params.toString();
385
+ const requestPath = queryString ? `/events/${eventId}/occurrences?${queryString}` : `/events/${eventId}/occurrences`;
386
+ const response = await this.request(requestPath, {
387
+ method: 'GET'
388
+ });
389
+ return response;
390
+ },
391
+ create: async (request) => {
392
+ const response = await this.request(`/events/${eventId}/occurrences`, {
393
+ method: 'POST',
394
+ body: JSON.stringify(request)
395
+ });
396
+ return response.eventOccurrence;
397
+ },
398
+ get: async (occurrenceId) => {
399
+ const response = await this.request(`/events/${eventId}/occurrences/${occurrenceId}`, {
400
+ method: 'GET'
401
+ });
402
+ return response.eventOccurrence;
403
+ },
404
+ update: async (occurrenceId, request) => {
405
+ const response = await this.request(`/events/${eventId}/occurrences/${occurrenceId}`, {
406
+ method: 'PATCH',
407
+ body: JSON.stringify(request)
408
+ });
409
+ return response.eventOccurrence;
410
+ },
411
+ delete: async (occurrenceId) => {
412
+ const response = await this.request(`/events/${eventId}/occurrences/${occurrenceId}`, {
413
+ method: 'DELETE'
414
+ });
415
+ return response;
416
+ }
417
+ },
418
+ priceschemes: {
419
+ list: async () => {
420
+ const response = await this.request(`/events/${eventId}/price-schemes`, {
421
+ method: 'GET'
422
+ });
423
+ return response.priceSchemes;
424
+ },
425
+ create: async (request) => {
426
+ const response = await this.request(`/events/${eventId}/price-schemes`, {
427
+ method: 'POST',
428
+ body: JSON.stringify(request)
429
+ });
430
+ return response.priceScheme;
431
+ },
432
+ get: async (priceSchemeId) => {
433
+ const response = await this.request(`/events/${eventId}/price-schemes/${priceSchemeId}`, {
434
+ method: 'GET'
435
+ });
436
+ return response.priceScheme;
437
+ },
438
+ update: async (priceSchemeId, request) => {
439
+ const response = await this.request(`/events/${eventId}/price-schemes/${priceSchemeId}`, {
440
+ method: 'PATCH',
441
+ body: JSON.stringify(request)
442
+ });
443
+ return response.priceScheme;
444
+ },
445
+ delete: async (priceSchemeId) => {
446
+ const response = await this.request(`/events/${eventId}/price-schemes/${priceSchemeId}`, {
447
+ method: 'DELETE'
448
+ });
449
+ return response;
450
+ }
451
+ }
452
+ }), {
453
+ list: async (options) => {
454
+ const params = new URLSearchParams();
455
+ if (options?.search !== undefined)
456
+ params.append('search', String(options.search));
457
+ if (options?.status !== undefined)
458
+ params.append('status', String(options.status));
459
+ if (options?.venueId !== undefined)
460
+ params.append('venueId', String(options.venueId));
461
+ if (options?.accountId !== undefined)
462
+ params.append('accountId', String(options.accountId));
463
+ if (options?.expand !== undefined)
464
+ params.append('expand', String(options.expand));
465
+ if (options?.page !== undefined)
466
+ params.append('page', String(options.page));
467
+ if (options?.limit !== undefined)
468
+ params.append('limit', String(options.limit));
469
+ const queryString = params.toString();
470
+ const requestPath = queryString ? `/events?${queryString}` : `/events`;
471
+ const response = await this.request(requestPath, {
472
+ method: 'GET'
473
+ });
474
+ return response;
475
+ },
476
+ create: async (request) => {
477
+ const response = await this.request(`/events`, {
478
+ method: 'POST',
479
+ body: JSON.stringify(request)
480
+ });
481
+ return response.event;
482
+ },
483
+ get: async (id, options) => {
484
+ const params = new URLSearchParams();
485
+ if (options?.expand !== undefined)
486
+ params.append('expand', String(options.expand));
487
+ const queryString = params.toString();
488
+ const requestPath = queryString ? `/events/${id}?${queryString}` : `/events/${id}`;
489
+ const response = await this.request(requestPath, {
490
+ method: 'GET'
491
+ });
492
+ return response.event;
493
+ },
494
+ update: async (id, request) => {
495
+ const response = await this.request(`/events/${id}`, {
496
+ method: 'PATCH',
497
+ body: JSON.stringify(request)
498
+ });
499
+ return response.event;
500
+ },
501
+ delete: async (id) => {
502
+ const response = await this.request(`/events/${id}`, {
503
+ method: 'DELETE'
504
+ });
505
+ return response;
506
+ }
507
+ });
508
+ this.venues = Object.assign((id) => ({
509
+ venuelayouts: {
510
+ list: async (options) => {
511
+ const params = new URLSearchParams();
512
+ if (options?.search !== undefined)
513
+ params.append('search', String(options.search));
514
+ if (options?.status !== undefined)
515
+ params.append('status', String(options.status));
516
+ if (options?.accountId !== undefined)
517
+ params.append('accountId', String(options.accountId));
518
+ if (options?.page !== undefined)
519
+ params.append('page', String(options.page));
520
+ if (options?.limit !== undefined)
521
+ params.append('limit', String(options.limit));
522
+ const queryString = params.toString();
523
+ const requestPath = queryString ? `/venues/${id}/layouts?${queryString}` : `/venues/${id}/layouts`;
524
+ const response = await this.request(requestPath, {
525
+ method: 'GET'
526
+ });
527
+ return response;
528
+ },
529
+ create: async (request) => {
530
+ const response = await this.request(`/venues/${id}/layouts`, {
531
+ method: 'POST',
532
+ body: JSON.stringify(request)
533
+ });
534
+ return response.venueLayout;
535
+ },
536
+ get: async (layoutId) => {
537
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}`, {
538
+ method: 'GET'
539
+ });
540
+ return response.venueLayout;
541
+ },
542
+ update: async (layoutId, request) => {
543
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}`, {
544
+ method: 'PATCH',
545
+ body: JSON.stringify(request)
546
+ });
547
+ return response.venueLayout;
548
+ },
549
+ delete: async (layoutId) => {
550
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}`, {
551
+ method: 'DELETE'
552
+ });
553
+ return response;
554
+ }
555
+ },
556
+ venuelayoutareas: {
557
+ addArea: async (layoutId, request) => {
558
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas`, {
559
+ method: 'POST',
560
+ body: JSON.stringify(request)
561
+ });
562
+ return response;
563
+ },
564
+ updateArea: async (layoutId, areaId, request) => {
565
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}`, {
566
+ method: 'PATCH',
567
+ body: JSON.stringify(request)
568
+ });
569
+ return response;
570
+ },
571
+ deleteArea: async (layoutId, areaId) => {
572
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}`, {
573
+ method: 'DELETE'
574
+ });
575
+ return response;
576
+ }
577
+ },
578
+ venuelayoutcategories: {
579
+ addCategory: async (layoutId, request) => {
580
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/categories`, {
581
+ method: 'POST',
582
+ body: JSON.stringify(request)
583
+ });
584
+ return response;
585
+ },
586
+ updateCategory: async (layoutId, categoryId, request) => {
587
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/categories/${categoryId}`, {
588
+ method: 'PATCH',
589
+ body: JSON.stringify(request)
590
+ });
591
+ return response;
592
+ },
593
+ deleteCategory: async (layoutId, categoryId) => {
594
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/categories/${categoryId}`, {
595
+ method: 'DELETE'
596
+ });
597
+ return response;
598
+ }
599
+ },
600
+ venuelayoutseats: {
601
+ addSeat: async (layoutId, areaId, request) => {
602
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats`, {
603
+ method: 'POST',
604
+ body: JSON.stringify(request)
605
+ });
606
+ return response;
607
+ },
608
+ bulkAddSeats: async (layoutId, areaId, request) => {
609
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats/bulk`, {
610
+ method: 'POST',
611
+ body: JSON.stringify(request)
612
+ });
613
+ return response;
614
+ },
615
+ generateSeats: async (layoutId, areaId, request) => {
616
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats/generate`, {
617
+ method: 'POST',
618
+ body: JSON.stringify(request)
619
+ });
620
+ return response;
621
+ },
622
+ syncSeats: async (layoutId, areaId, request) => {
623
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats/sync`, {
624
+ method: 'PUT',
625
+ body: JSON.stringify(request)
626
+ });
627
+ return response;
628
+ },
629
+ updateSeat: async (layoutId, areaId, seatId, request) => {
630
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats/${seatId}`, {
631
+ method: 'PATCH',
632
+ body: JSON.stringify(request)
633
+ });
634
+ return response;
635
+ },
636
+ deleteSeat: async (layoutId, areaId, seatId) => {
637
+ const response = await this.request(`/venues/${id}/layouts/${layoutId}/areas/${areaId}/seats/${seatId}`, {
638
+ method: 'DELETE'
639
+ });
640
+ return response;
641
+ }
642
+ }
643
+ }), {
644
+ list: async (options) => {
645
+ const params = new URLSearchParams();
646
+ if (options?.search !== undefined)
647
+ params.append('search', String(options.search));
648
+ if (options?.status !== undefined)
649
+ params.append('status', String(options.status));
650
+ if (options?.accountId !== undefined)
651
+ params.append('accountId', String(options.accountId));
652
+ if (options?.page !== undefined)
653
+ params.append('page', String(options.page));
654
+ if (options?.limit !== undefined)
655
+ params.append('limit', String(options.limit));
656
+ const queryString = params.toString();
657
+ const requestPath = queryString ? `/venues?${queryString}` : `/venues`;
658
+ const response = await this.request(requestPath, {
659
+ method: 'GET'
660
+ });
661
+ return response;
662
+ },
663
+ create: async (request) => {
664
+ const response = await this.request(`/venues`, {
665
+ method: 'POST',
666
+ body: JSON.stringify(request)
667
+ });
668
+ return response.venue;
669
+ },
670
+ get: async (id) => {
671
+ const response = await this.request(`/venues/${id}`, {
672
+ method: 'GET'
673
+ });
674
+ return response.venue;
675
+ },
676
+ update: async (id, request) => {
677
+ const response = await this.request(`/venues/${id}`, {
678
+ method: 'PATCH',
679
+ body: JSON.stringify(request)
680
+ });
681
+ return response.venue;
682
+ },
683
+ delete: async (id) => {
684
+ const response = await this.request(`/venues/${id}`, {
685
+ method: 'DELETE'
686
+ });
687
+ return response;
688
+ }
689
+ });
690
+ this.billing = {
691
+ listPackages: async () => {
692
+ const response = await this.request(`/billing/packages`, {
693
+ method: 'GET'
694
+ });
695
+ return response.packages;
696
+ },
697
+ canSell: async (organisationId) => {
698
+ const response = await this.request(`/organisations/${organisationId}/billing/can-sell`, {
699
+ method: 'GET'
700
+ });
701
+ return response;
702
+ },
703
+ getBalance: async () => {
704
+ const response = await this.request(`/billing/balance`, {
705
+ method: 'GET'
706
+ });
707
+ return response.balance;
708
+ },
709
+ listTransactions: async (options) => {
710
+ const params = new URLSearchParams();
711
+ if (options?.page !== undefined)
712
+ params.append('page', String(options.page));
713
+ if (options?.limit !== undefined)
714
+ params.append('limit', String(options.limit));
715
+ if (options?.type !== undefined)
716
+ params.append('type', String(options.type));
717
+ const queryString = params.toString();
718
+ const requestPath = queryString ? `/billing/transactions?${queryString}` : `/billing/transactions`;
719
+ const response = await this.request(requestPath, {
720
+ method: 'GET'
721
+ });
722
+ return response.transactions;
723
+ },
724
+ createPurchase: async (request) => {
725
+ const response = await this.request(`/billing/purchases`, {
726
+ method: 'POST',
727
+ body: JSON.stringify(request)
728
+ });
729
+ return response;
730
+ },
731
+ listInvoices: async (options) => {
732
+ const params = new URLSearchParams();
733
+ if (options?.page !== undefined)
734
+ params.append('page', String(options.page));
735
+ if (options?.limit !== undefined)
736
+ params.append('limit', String(options.limit));
737
+ if (options?.status !== undefined)
738
+ params.append('status', String(options.status));
739
+ const queryString = params.toString();
740
+ const requestPath = queryString ? `/billing/invoices?${queryString}` : `/billing/invoices`;
741
+ const response = await this.request(requestPath, {
742
+ method: 'GET'
743
+ });
744
+ return response.invoices;
745
+ },
746
+ getInvoice: async (invoiceId) => {
747
+ const response = await this.request(`/billing/invoices/${invoiceId}`, {
748
+ method: 'GET'
749
+ });
750
+ return response.invoice;
751
+ },
752
+ listPayments: async (options) => {
753
+ const params = new URLSearchParams();
754
+ if (options?.page !== undefined)
755
+ params.append('page', String(options.page));
756
+ if (options?.limit !== undefined)
757
+ params.append('limit', String(options.limit));
758
+ if (options?.status !== undefined)
759
+ params.append('status', String(options.status));
760
+ const queryString = params.toString();
761
+ const requestPath = queryString ? `/billing/payments?${queryString}` : `/billing/payments`;
762
+ const response = await this.request(requestPath, {
763
+ method: 'GET'
764
+ });
765
+ return response.payments;
766
+ },
767
+ createSubscription: async (request) => {
768
+ const response = await this.request(`/billing/subscriptions`, {
769
+ method: 'POST',
770
+ body: JSON.stringify(request)
771
+ });
772
+ return response.subscription;
773
+ },
774
+ listSubscriptions: async () => {
775
+ const response = await this.request(`/billing/subscriptions`, {
776
+ method: 'GET'
777
+ });
778
+ return response.subscriptions;
779
+ },
780
+ cancelSubscription: async (subscriptionId) => {
781
+ const response = await this.request(`/billing/subscriptions/${subscriptionId}`, {
782
+ method: 'DELETE'
783
+ });
784
+ return response.subscription;
785
+ },
786
+ getAutoTopup: async () => {
787
+ const response = await this.request(`/billing/auto-topup`, {
788
+ method: 'GET'
789
+ });
790
+ return response.autoTopup;
791
+ },
792
+ updateAutoTopup: async (request) => {
793
+ const response = await this.request(`/billing/auto-topup`, {
794
+ method: 'PUT',
795
+ body: JSON.stringify(request)
796
+ });
797
+ return response.autoTopup;
798
+ },
799
+ listPaymentMethods: async () => {
800
+ const response = await this.request(`/billing/payment-methods`, {
801
+ method: 'GET'
802
+ });
803
+ return response.paymentMethods;
804
+ },
805
+ savePaymentMethod: async (request) => {
806
+ const response = await this.request(`/billing/payment-methods`, {
807
+ method: 'POST',
808
+ body: JSON.stringify(request)
809
+ });
810
+ return response.paymentMethod;
811
+ },
812
+ createSetupIntent: async () => {
813
+ const response = await this.request(`/billing/setup-intent`, {
814
+ method: 'POST'
815
+ });
816
+ return response.clientSecret;
817
+ },
818
+ deletePaymentMethod: async (paymentMethodId) => {
819
+ const response = await this.request(`/billing/payment-methods/${paymentMethodId}`, {
820
+ method: 'DELETE'
821
+ });
822
+ return response.success;
823
+ },
824
+ setDefaultPaymentMethod: async (paymentMethodId) => {
825
+ const response = await this.request(`/billing/payment-methods/${paymentMethodId}/default`, {
826
+ method: 'PUT'
827
+ });
828
+ return response.paymentMethod;
829
+ },
830
+ listAiPackages: async () => {
831
+ const response = await this.request(`/billing/ai/packages`, {
832
+ method: 'GET'
833
+ });
834
+ return response.packages;
835
+ },
836
+ getAiBalance: async () => {
837
+ const response = await this.request(`/billing/ai/balance`, {
838
+ method: 'GET'
839
+ });
840
+ return response.aiBalance;
841
+ },
842
+ listAiTransactions: async (options) => {
843
+ const params = new URLSearchParams();
844
+ if (options?.page !== undefined)
845
+ params.append('page', String(options.page));
846
+ if (options?.limit !== undefined)
847
+ params.append('limit', String(options.limit));
848
+ const queryString = params.toString();
849
+ const requestPath = queryString ? `/billing/ai/transactions?${queryString}` : `/billing/ai/transactions`;
850
+ const response = await this.request(requestPath, {
851
+ method: 'GET'
852
+ });
853
+ return response.transactions;
854
+ },
855
+ createAiTopup: async (request) => {
856
+ const response = await this.request(`/billing/ai-topup`, {
857
+ method: 'POST',
858
+ body: JSON.stringify(request)
859
+ });
860
+ return response;
861
+ }
862
+ };
863
+ this.inventory = {
864
+ create: async (request) => {
865
+ const response = await this.request(`/inventory`, {
866
+ method: 'POST',
867
+ body: JSON.stringify(request)
868
+ });
869
+ return response.inventory;
870
+ },
871
+ list: async (options) => {
872
+ const params = new URLSearchParams();
873
+ if (options?.sourceType !== undefined)
874
+ params.append('sourceType', String(options.sourceType));
875
+ if (options?.eventOccurrenceId !== undefined)
876
+ params.append('eventOccurrenceId', String(options.eventOccurrenceId));
877
+ if (options?.eventId !== undefined)
878
+ params.append('eventId', String(options.eventId));
879
+ if (options?.productId !== undefined)
880
+ params.append('productId', String(options.productId));
881
+ if (options?.isAllocated !== undefined)
882
+ params.append('isAllocated', String(options.isAllocated));
883
+ const queryString = params.toString();
884
+ const requestPath = queryString ? `/inventory?${queryString}` : `/inventory`;
885
+ const response = await this.request(requestPath, {
886
+ method: 'GET'
887
+ });
888
+ return response.inventory;
889
+ },
890
+ get: async (id, options) => {
891
+ const params = new URLSearchParams();
892
+ if (options?.accountId !== undefined)
893
+ params.append('accountId', String(options.accountId));
894
+ const queryString = params.toString();
895
+ const requestPath = queryString ? `/inventory/${id}?${queryString}` : `/inventory/${id}`;
896
+ const response = await this.request(requestPath, {
897
+ method: 'GET'
898
+ });
899
+ return response.inventory;
900
+ },
901
+ delete: async (id, options) => {
902
+ const params = new URLSearchParams();
903
+ if (options?.accountId !== undefined)
904
+ params.append('accountId', String(options.accountId));
905
+ const queryString = params.toString();
906
+ const requestPath = queryString ? `/inventory/${id}?${queryString}` : `/inventory/${id}`;
907
+ const response = await this.request(requestPath, {
908
+ method: 'DELETE'
909
+ });
910
+ return response.message;
911
+ },
912
+ updateCapacity: async (id, request) => {
913
+ const response = await this.request(`/inventory/${id}/capacity`, {
914
+ method: 'PATCH',
915
+ body: JSON.stringify(request)
916
+ });
917
+ return response.inventory;
918
+ },
919
+ getAuditLog: async (id, options) => {
920
+ const params = new URLSearchParams();
921
+ if (options?.accountId !== undefined)
922
+ params.append('accountId', String(options.accountId));
923
+ const queryString = params.toString();
924
+ const requestPath = queryString ? `/inventory/${id}/audit-log?${queryString}` : `/inventory/${id}/audit-log`;
925
+ const response = await this.request(requestPath, {
926
+ method: 'GET'
927
+ });
928
+ return response.auditLog;
929
+ }
930
+ };
931
+ this.inventorySeats = {
932
+ importSeats: async (id, request) => {
933
+ const response = await this.request(`/inventory/${id}/seats`, {
934
+ method: 'POST',
935
+ body: JSON.stringify(request)
936
+ });
937
+ return response;
938
+ },
939
+ listSeats: async (id, options) => {
940
+ const params = new URLSearchParams();
941
+ if (options?.status !== undefined)
942
+ params.append('status', String(options.status));
943
+ if (options?.priceCategory !== undefined)
944
+ params.append('priceCategory', String(options.priceCategory));
945
+ if (options?.isAccessible !== undefined)
946
+ params.append('isAccessible', String(options.isAccessible));
947
+ if (options?.rowName !== undefined)
948
+ params.append('rowName', String(options.rowName));
949
+ const queryString = params.toString();
950
+ const requestPath = queryString ? `/inventory/${id}/seats?${queryString}` : `/inventory/${id}/seats`;
951
+ const response = await this.request(requestPath, {
952
+ method: 'GET'
953
+ });
954
+ return response.seats;
955
+ }
956
+ };
957
+ this.inventoryReservations = {
958
+ reserve: async (request) => {
959
+ const response = await this.request(`/inventory/reserve`, {
960
+ method: 'POST',
961
+ body: JSON.stringify(request)
962
+ });
963
+ return response.reservation;
964
+ },
965
+ checkAvailability: async (request) => {
966
+ const response = await this.request(`/inventory/check-availability`, {
967
+ method: 'POST',
968
+ body: JSON.stringify(request)
969
+ });
970
+ return response;
971
+ },
972
+ listReservations: async (options) => {
973
+ const params = new URLSearchParams();
974
+ if (options?.inventoryId !== undefined)
975
+ params.append('inventoryId', String(options.inventoryId));
976
+ if (options?.accountId !== undefined)
977
+ params.append('accountId', String(options.accountId));
978
+ if (options?.type !== undefined)
979
+ params.append('type', String(options.type));
980
+ if (options?.referenceType !== undefined)
981
+ params.append('referenceType', String(options.referenceType));
982
+ if (options?.referenceId !== undefined)
983
+ params.append('referenceId', String(options.referenceId));
984
+ const queryString = params.toString();
985
+ const requestPath = queryString ? `/inventory/reservations?${queryString}` : `/inventory/reservations`;
986
+ const response = await this.request(requestPath, {
987
+ method: 'GET'
988
+ });
989
+ return response.reservations;
990
+ },
991
+ getReservation: async (id, options) => {
992
+ const params = new URLSearchParams();
993
+ if (options?.accountId !== undefined)
994
+ params.append('accountId', String(options.accountId));
995
+ const queryString = params.toString();
996
+ const requestPath = queryString ? `/inventory/reservations/${id}?${queryString}` : `/inventory/reservations/${id}`;
997
+ const response = await this.request(requestPath, {
998
+ method: 'GET'
999
+ });
1000
+ return response.reservation;
1001
+ },
1002
+ confirmReservation: async (id, request) => {
1003
+ const response = await this.request(`/inventory/reservations/${id}/confirm`, {
1004
+ method: 'POST',
1005
+ body: JSON.stringify(request)
1006
+ });
1007
+ return response.reservation;
1008
+ },
1009
+ releaseReservation: async (id, request) => {
1010
+ const response = await this.request(`/inventory/reservations/${id}/release`, {
1011
+ method: 'POST',
1012
+ body: JSON.stringify(request)
1013
+ });
1014
+ return response.message;
1015
+ },
1016
+ extendReservation: async (id, request) => {
1017
+ const response = await this.request(`/inventory/reservations/${id}/extend`, {
1018
+ method: 'PATCH',
1019
+ body: JSON.stringify(request)
1020
+ });
1021
+ return response.reservation;
1022
+ }
1023
+ };
1024
+ this.inventoryHolds = {
1025
+ createHold: async (request) => {
1026
+ const response = await this.request(`/inventory/holds`, {
1027
+ method: 'POST',
1028
+ body: JSON.stringify(request)
1029
+ });
1030
+ return response.reservation;
1031
+ },
1032
+ releaseHold: async (id, request) => {
1033
+ const response = await this.request(`/inventory/holds/${id}/release`, {
1034
+ method: 'POST',
1035
+ body: JSON.stringify(request)
1036
+ });
1037
+ return response.message;
1038
+ }
1039
+ };
1040
+ this.customers = {
1041
+ create: async (request) => {
1042
+ const response = await this.request(`/customers`, {
1043
+ method: 'POST',
1044
+ body: JSON.stringify(request)
1045
+ });
1046
+ return response.customer;
1047
+ },
1048
+ list: async (options) => {
1049
+ const params = new URLSearchParams();
1050
+ if (options?.search !== undefined)
1051
+ params.append('search', String(options.search));
1052
+ if (options?.email !== undefined)
1053
+ params.append('email', String(options.email));
1054
+ if (options?.accountId !== undefined)
1055
+ params.append('accountId', String(options.accountId));
1056
+ if (options?.isBlocked !== undefined)
1057
+ params.append('isBlocked', String(options.isBlocked));
1058
+ if (options?.updatedSince !== undefined)
1059
+ params.append('updatedSince', String(options.updatedSince));
1060
+ if (options?.cursor !== undefined)
1061
+ params.append('cursor', String(options.cursor));
1062
+ if (options?.page !== undefined)
1063
+ params.append('page', String(options.page));
1064
+ if (options?.limit !== undefined)
1065
+ params.append('limit', String(options.limit));
1066
+ const queryString = params.toString();
1067
+ const requestPath = queryString ? `/customers?${queryString}` : `/customers`;
1068
+ const response = await this.request(requestPath, {
1069
+ method: 'GET'
1070
+ });
1071
+ return response;
1072
+ },
1073
+ get: async (customerId) => {
1074
+ const response = await this.request(`/customers/${customerId}`, {
1075
+ method: 'GET'
1076
+ });
1077
+ return response.customer;
1078
+ },
1079
+ update: async (customerId, request) => {
1080
+ const response = await this.request(`/customers/${customerId}`, {
1081
+ method: 'PATCH',
1082
+ body: JSON.stringify(request)
1083
+ });
1084
+ return response.customer;
1085
+ },
1086
+ block: async (customerId, request) => {
1087
+ const response = await this.request(`/customers/${customerId}/block`, {
1088
+ method: 'POST',
1089
+ body: JSON.stringify(request)
1090
+ });
1091
+ return response.customer;
1092
+ },
1093
+ unblock: async (customerId) => {
1094
+ const response = await this.request(`/customers/${customerId}/unblock`, {
1095
+ method: 'POST'
1096
+ });
1097
+ return response.customer;
1098
+ }
1099
+ };
1100
+ this.orders = {
1101
+ create: async (request) => {
1102
+ const response = await this.request(`/orders`, {
1103
+ method: 'POST',
1104
+ body: JSON.stringify(request)
1105
+ });
1106
+ return response.order;
1107
+ },
1108
+ list: async (options) => {
1109
+ const params = new URLSearchParams();
1110
+ if (options?.status !== undefined)
1111
+ params.append('status', String(options.status));
1112
+ if (options?.customerId !== undefined)
1113
+ params.append('customerId', String(options.customerId));
1114
+ if (options?.channel !== undefined)
1115
+ params.append('channel', String(options.channel));
1116
+ if (options?.fromDate !== undefined)
1117
+ params.append('fromDate', String(options.fromDate));
1118
+ if (options?.toDate !== undefined)
1119
+ params.append('toDate', String(options.toDate));
1120
+ if (options?.updatedSince !== undefined)
1121
+ params.append('updatedSince', String(options.updatedSince));
1122
+ if (options?.cursor !== undefined)
1123
+ params.append('cursor', String(options.cursor));
1124
+ if (options?.search !== undefined)
1125
+ params.append('search', String(options.search));
1126
+ if (options?.page !== undefined)
1127
+ params.append('page', String(options.page));
1128
+ if (options?.limit !== undefined)
1129
+ params.append('limit', String(options.limit));
1130
+ const queryString = params.toString();
1131
+ const requestPath = queryString ? `/orders?${queryString}` : `/orders`;
1132
+ const response = await this.request(requestPath, {
1133
+ method: 'GET'
1134
+ });
1135
+ return response;
1136
+ },
1137
+ get: async (orderId) => {
1138
+ const response = await this.request(`/orders/${orderId}`, {
1139
+ method: 'GET'
1140
+ });
1141
+ return response.order;
1142
+ },
1143
+ update: async (orderId, request) => {
1144
+ const response = await this.request(`/orders/${orderId}`, {
1145
+ method: 'PATCH',
1146
+ body: JSON.stringify(request)
1147
+ });
1148
+ return response.order;
1149
+ },
1150
+ getByNumber: async (orderNumber) => {
1151
+ const response = await this.request(`/orders/number/${orderNumber}`, {
1152
+ method: 'GET'
1153
+ });
1154
+ return response.order;
1155
+ },
1156
+ cancel: async (orderId, request) => {
1157
+ const response = await this.request(`/orders/${orderId}/cancel`, {
1158
+ method: 'POST',
1159
+ body: JSON.stringify(request)
1160
+ });
1161
+ return response.order;
1162
+ },
1163
+ transitionStatus: async (orderId, request) => {
1164
+ const response = await this.request(`/orders/${orderId}/status`, {
1165
+ method: 'POST',
1166
+ body: JSON.stringify(request)
1167
+ });
1168
+ return response.order;
1169
+ },
1170
+ validate: async (orderId, request) => {
1171
+ const response = await this.request(`/orders/${orderId}/validate`, {
1172
+ method: 'POST',
1173
+ body: JSON.stringify(request)
1174
+ });
1175
+ return response;
1176
+ },
1177
+ addItem: async (orderId, request) => {
1178
+ const response = await this.request(`/orders/${orderId}/items`, {
1179
+ method: 'POST',
1180
+ body: JSON.stringify(request)
1181
+ });
1182
+ return response;
1183
+ },
1184
+ updateItem: async (orderId, itemId, request) => {
1185
+ const response = await this.request(`/orders/${orderId}/items/${itemId}`, {
1186
+ method: 'PATCH',
1187
+ body: JSON.stringify(request)
1188
+ });
1189
+ return response;
1190
+ },
1191
+ removeItem: async (orderId, itemId) => {
1192
+ const response = await this.request(`/orders/${orderId}/items/${itemId}`, {
1193
+ method: 'DELETE'
1194
+ });
1195
+ return response.order;
1196
+ },
1197
+ initiatePayment: async (orderId, request) => {
1198
+ const response = await this.request(`/orders/${orderId}/payment`, {
1199
+ method: 'POST',
1200
+ body: JSON.stringify(request)
1201
+ });
1202
+ return response;
1203
+ },
1204
+ getPaymentStatus: async (orderId) => {
1205
+ const response = await this.request(`/orders/${orderId}/payment/status`, {
1206
+ method: 'GET'
1207
+ });
1208
+ return response;
1209
+ },
1210
+ getPassPdf: async (orderId, passId) => {
1211
+ const response = await this.request(`/orders/${orderId}/passes/${passId}/ticket.pdf`, {
1212
+ method: 'GET'
1213
+ });
1214
+ return response;
1215
+ },
1216
+ resendConfirmation: async (orderId) => {
1217
+ const response = await this.request(`/orders/${orderId}/resend-confirmation`, {
1218
+ method: 'POST'
1219
+ });
1220
+ return response;
1221
+ },
1222
+ getPasses: async (orderId) => {
1223
+ const response = await this.request(`/orders/${orderId}/passes`, {
1224
+ method: 'GET'
1225
+ });
1226
+ return response;
1227
+ },
1228
+ printPass: async (orderId, passId, request) => {
1229
+ const response = await this.request(`/orders/${orderId}/passes/${passId}/print`, {
1230
+ method: 'POST',
1231
+ body: JSON.stringify(request)
1232
+ });
1233
+ return response;
1234
+ }
1235
+ };
1236
+ this.payments = {
1237
+ create: async (request) => {
1238
+ const response = await this.request(`/payments`, {
1239
+ method: 'POST',
1240
+ body: JSON.stringify(request)
1241
+ });
1242
+ return response.payment;
1243
+ },
1244
+ list: async (options) => {
1245
+ const params = new URLSearchParams();
1246
+ if (options?.orderId !== undefined)
1247
+ params.append('orderId', String(options.orderId));
1248
+ if (options?.status !== undefined)
1249
+ params.append('status', String(options.status));
1250
+ if (options?.paymentType !== undefined)
1251
+ params.append('paymentType', String(options.paymentType));
1252
+ if (options?.paymentProviderId !== undefined)
1253
+ params.append('paymentProviderId', String(options.paymentProviderId));
1254
+ if (options?.fromDate !== undefined)
1255
+ params.append('fromDate', String(options.fromDate));
1256
+ if (options?.toDate !== undefined)
1257
+ params.append('toDate', String(options.toDate));
1258
+ if (options?.page !== undefined)
1259
+ params.append('page', String(options.page));
1260
+ if (options?.limit !== undefined)
1261
+ params.append('limit', String(options.limit));
1262
+ const queryString = params.toString();
1263
+ const requestPath = queryString ? `/payments?${queryString}` : `/payments`;
1264
+ const response = await this.request(requestPath, {
1265
+ method: 'GET'
1266
+ });
1267
+ return response.payments;
1268
+ },
1269
+ get: async (paymentId) => {
1270
+ const response = await this.request(`/payments/${paymentId}`, {
1271
+ method: 'GET'
1272
+ });
1273
+ return response.payment;
1274
+ },
1275
+ cancel: async (paymentId, request) => {
1276
+ const response = await this.request(`/payments/${paymentId}/cancel`, {
1277
+ method: 'POST',
1278
+ body: JSON.stringify(request)
1279
+ });
1280
+ return response.payment;
1281
+ },
1282
+ createRefund: async (paymentId, request) => {
1283
+ const response = await this.request(`/payments/${paymentId}/refunds`, {
1284
+ method: 'POST',
1285
+ body: JSON.stringify(request)
1286
+ });
1287
+ return response.refund;
1288
+ },
1289
+ listRefunds: async (paymentId) => {
1290
+ const response = await this.request(`/payments/${paymentId}/refunds`, {
1291
+ method: 'GET'
1292
+ });
1293
+ return response.refunds;
1294
+ }
1295
+ };
1296
+ this.paymentProviders = {
1297
+ create: async (request) => {
1298
+ const response = await this.request(`/payment-providers`, {
1299
+ method: 'POST',
1300
+ body: JSON.stringify(request)
1301
+ });
1302
+ return response.provider;
1303
+ },
1304
+ list: async (options) => {
1305
+ const params = new URLSearchParams();
1306
+ if (options?.accountId !== undefined)
1307
+ params.append('accountId', String(options.accountId));
1308
+ if (options?.type !== undefined)
1309
+ params.append('type', String(options.type));
1310
+ if (options?.status !== undefined)
1311
+ params.append('status', String(options.status));
1312
+ if (options?.paymentType !== undefined)
1313
+ params.append('paymentType', String(options.paymentType));
1314
+ if (options?.isDefault !== undefined)
1315
+ params.append('isDefault', String(options.isDefault));
1316
+ if (options?.integrationType !== undefined)
1317
+ params.append('integrationType', String(options.integrationType));
1318
+ if (options?.page !== undefined)
1319
+ params.append('page', String(options.page));
1320
+ if (options?.limit !== undefined)
1321
+ params.append('limit', String(options.limit));
1322
+ const queryString = params.toString();
1323
+ const requestPath = queryString ? `/payment-providers?${queryString}` : `/payment-providers`;
1324
+ const response = await this.request(requestPath, {
1325
+ method: 'GET'
1326
+ });
1327
+ return response;
1328
+ },
1329
+ getDefault: async () => {
1330
+ const response = await this.request(`/payment-providers/default`, {
1331
+ method: 'GET'
1332
+ });
1333
+ return response.provider;
1334
+ },
1335
+ get: async (providerId) => {
1336
+ const response = await this.request(`/payment-providers/${providerId}`, {
1337
+ method: 'GET'
1338
+ });
1339
+ return response.provider;
1340
+ },
1341
+ update: async (providerId, request) => {
1342
+ const response = await this.request(`/payment-providers/${providerId}`, {
1343
+ method: 'PATCH',
1344
+ body: JSON.stringify(request)
1345
+ });
1346
+ return response.provider;
1347
+ },
1348
+ delete: async (providerId) => {
1349
+ const response = await this.request(`/payment-providers/${providerId}`, {
1350
+ method: 'DELETE'
1351
+ });
1352
+ return response;
1353
+ },
1354
+ enableTicketlayerPay: async (request) => {
1355
+ const response = await this.request(`/payment-providers/ticketlayer-pay/enable`, {
1356
+ method: 'POST',
1357
+ body: JSON.stringify(request)
1358
+ });
1359
+ return response;
1360
+ },
1361
+ getTicketlayerPay: async (options) => {
1362
+ const params = new URLSearchParams();
1363
+ if (options?.refresh !== undefined)
1364
+ params.append('refresh', String(options.refresh));
1365
+ const queryString = params.toString();
1366
+ const requestPath = queryString ? `/payment-providers/ticketlayer-pay?${queryString}` : `/payment-providers/ticketlayer-pay`;
1367
+ const response = await this.request(requestPath, {
1368
+ method: 'GET'
1369
+ });
1370
+ return response;
1371
+ },
1372
+ createTicketlayerPayOnboardingSession: async () => {
1373
+ const response = await this.request(`/payment-providers/ticketlayer-pay/onboarding-session`, {
1374
+ method: 'POST'
1375
+ });
1376
+ return response;
1377
+ },
1378
+ createTicketlayerPayOnboardingLink: async (request) => {
1379
+ const response = await this.request(`/payment-providers/ticketlayer-pay/onboarding-link`, {
1380
+ method: 'POST',
1381
+ body: JSON.stringify(request)
1382
+ });
1383
+ return response.link;
1384
+ },
1385
+ linkStripeConnect: async (request) => {
1386
+ const response = await this.request(`/payment-providers/stripe-connect`, {
1387
+ method: 'POST',
1388
+ body: JSON.stringify(request)
1389
+ });
1390
+ return response;
1391
+ },
1392
+ getStripeConnect: async () => {
1393
+ const response = await this.request(`/payment-providers/stripe-connect`, {
1394
+ method: 'GET'
1395
+ });
1396
+ return response;
1397
+ },
1398
+ listAccounts: async (providerId) => {
1399
+ const response = await this.request(`/payment-providers/${providerId}/accounts`, {
1400
+ method: 'GET'
1401
+ });
1402
+ return response;
1403
+ },
1404
+ getAccount: async (providerId, accountId, options) => {
1405
+ const params = new URLSearchParams();
1406
+ if (options?.refresh !== undefined)
1407
+ params.append('refresh', String(options.refresh));
1408
+ const queryString = params.toString();
1409
+ const requestPath = queryString ? `/payment-providers/${providerId}/accounts/${accountId}?${queryString}` : `/payment-providers/${providerId}/accounts/${accountId}`;
1410
+ const response = await this.request(requestPath, {
1411
+ method: 'GET'
1412
+ });
1413
+ return response;
1414
+ },
1415
+ setAccountMode: async (providerId, accountId, request) => {
1416
+ const response = await this.request(`/payment-providers/${providerId}/accounts/${accountId}`, {
1417
+ method: 'PUT',
1418
+ body: JSON.stringify(request)
1419
+ });
1420
+ return response;
1421
+ },
1422
+ createAccountOnboardingSession: async (providerId, accountId) => {
1423
+ const response = await this.request(`/payment-providers/${providerId}/accounts/${accountId}/onboarding-session`, {
1424
+ method: 'POST'
1425
+ });
1426
+ return response;
1427
+ },
1428
+ createAccountOnboardingLink: async (providerId, accountId, request) => {
1429
+ const response = await this.request(`/payment-providers/${providerId}/accounts/${accountId}/onboarding-link`, {
1430
+ method: 'POST',
1431
+ body: JSON.stringify(request)
1432
+ });
1433
+ return response.link;
1434
+ }
1435
+ };
1436
+ this.salesChannels = Object.assign((channelId) => ({
1437
+ keys: {
1438
+ issue: async (request) => {
1439
+ const response = await this.request(`/sales-channels/${channelId}/keys`, {
1440
+ method: 'POST',
1441
+ body: JSON.stringify(request)
1442
+ });
1443
+ return response;
1444
+ },
1445
+ list: async () => {
1446
+ const response = await this.request(`/sales-channels/${channelId}/keys`, {
1447
+ method: 'GET'
1448
+ });
1449
+ return response.keys;
1450
+ },
1451
+ revoke: async (keyId, request) => {
1452
+ const response = await this.request(`/sales-channels/${channelId}/keys/${keyId}/revoke`, {
1453
+ method: 'POST',
1454
+ body: JSON.stringify(request)
1455
+ });
1456
+ return response.key;
1457
+ }
1458
+ },
1459
+ listings: {
1460
+ create: async (request) => {
1461
+ const response = await this.request(`/sales-channels/${channelId}/listings`, {
1462
+ method: 'POST',
1463
+ body: JSON.stringify(request)
1464
+ });
1465
+ return response.listing;
1466
+ },
1467
+ list: async () => {
1468
+ const response = await this.request(`/sales-channels/${channelId}/listings`, {
1469
+ method: 'GET'
1470
+ });
1471
+ return response.listings;
1472
+ },
1473
+ delete: async (listingId) => {
1474
+ const response = await this.request(`/sales-channels/${channelId}/listings/${listingId}`, {
1475
+ method: 'DELETE'
1476
+ });
1477
+ return response.deleted;
1478
+ }
1479
+ },
1480
+ carts: {
1481
+ create: async (request) => {
1482
+ const response = await this.request(`/sales-channels/${channelId}/carts`, {
1483
+ method: 'POST',
1484
+ body: JSON.stringify(request)
1485
+ });
1486
+ return response;
1487
+ },
1488
+ get: async (cartId) => {
1489
+ const response = await this.request(`/sales-channels/${channelId}/carts/${cartId}`, {
1490
+ method: 'GET'
1491
+ });
1492
+ return response;
1493
+ },
1494
+ addItem: async (cartId, request) => {
1495
+ const response = await this.request(`/sales-channels/${channelId}/carts/${cartId}/items`, {
1496
+ method: 'POST',
1497
+ body: JSON.stringify(request)
1498
+ });
1499
+ return response;
1500
+ },
1501
+ removeItem: async (cartId, itemId) => {
1502
+ const response = await this.request(`/sales-channels/${channelId}/carts/${cartId}/items/${itemId}`, {
1503
+ method: 'DELETE'
1504
+ });
1505
+ return response;
1506
+ },
1507
+ checkout: async (cartId, request) => {
1508
+ const response = await this.request(`/sales-channels/${channelId}/carts/${cartId}/checkout`, {
1509
+ method: 'POST',
1510
+ body: JSON.stringify(request)
1511
+ });
1512
+ return response;
1513
+ }
1514
+ }
1515
+ }), {
1516
+ create: async (request) => {
1517
+ const response = await this.request(`/sales-channels`, {
1518
+ method: 'POST',
1519
+ body: JSON.stringify(request)
1520
+ });
1521
+ return response.channel;
1522
+ },
1523
+ list: async () => {
1524
+ const response = await this.request(`/sales-channels`, {
1525
+ method: 'GET'
1526
+ });
1527
+ return response.channels;
1528
+ },
1529
+ get: async (channelId) => {
1530
+ const response = await this.request(`/sales-channels/${channelId}`, {
1531
+ method: 'GET'
1532
+ });
1533
+ return response.channel;
1534
+ },
1535
+ update: async (channelId, request) => {
1536
+ const response = await this.request(`/sales-channels/${channelId}`, {
1537
+ method: 'PATCH',
1538
+ body: JSON.stringify(request)
1539
+ });
1540
+ return response.channel;
1541
+ },
1542
+ delete: async (channelId) => {
1543
+ const response = await this.request(`/sales-channels/${channelId}`, {
1544
+ method: 'DELETE'
1545
+ });
1546
+ return response.deleted;
1547
+ }
1548
+ });
1549
+ this.presaleCodes = {
1550
+ create: async (request) => {
1551
+ const response = await this.request(`/presale-codes`, {
1552
+ method: 'POST',
1553
+ body: JSON.stringify(request)
1554
+ });
1555
+ return response.presaleCode;
1556
+ },
1557
+ list: async () => {
1558
+ const response = await this.request(`/presale-codes`, {
1559
+ method: 'GET'
1560
+ });
1561
+ return response.presaleCodes;
1562
+ },
1563
+ deactivate: async (codeId) => {
1564
+ const response = await this.request(`/presale-codes/${codeId}/deactivate`, {
1565
+ method: 'POST'
1566
+ });
1567
+ return response.presaleCode;
1568
+ }
1569
+ };
1570
+ this.feeProfiles = {
1571
+ create: async (request) => {
1572
+ const response = await this.request(`/fee-profiles`, {
1573
+ method: 'POST',
1574
+ body: JSON.stringify(request)
1575
+ });
1576
+ return response.feeProfile;
1577
+ },
1578
+ list: async () => {
1579
+ const response = await this.request(`/fee-profiles`, {
1580
+ method: 'GET'
1581
+ });
1582
+ return response.feeProfiles;
1583
+ },
1584
+ get: async (profileId) => {
1585
+ const response = await this.request(`/fee-profiles/${profileId}`, {
1586
+ method: 'GET'
1587
+ });
1588
+ return response.feeProfile;
1589
+ },
1590
+ update: async (profileId, request) => {
1591
+ const response = await this.request(`/fee-profiles/${profileId}`, {
1592
+ method: 'PATCH',
1593
+ body: JSON.stringify(request)
1594
+ });
1595
+ return response.feeProfile;
1596
+ },
1597
+ delete: async (profileId) => {
1598
+ const response = await this.request(`/fee-profiles/${profileId}`, {
1599
+ method: 'DELETE'
1600
+ });
1601
+ return response.deleted;
1602
+ }
1603
+ };
1604
+ this.salesListings = {
1605
+ list: async () => {
1606
+ const response = await this.request(`/sales/listings`, {
1607
+ method: 'GET'
1608
+ });
1609
+ return response;
1610
+ }
1611
+ };
1612
+ this.salesCustomerAuth = {
1613
+ magicLink: async (request) => {
1614
+ const response = await this.request(`/sales/customer-auth/magic-link`, {
1615
+ method: 'POST',
1616
+ body: JSON.stringify(request)
1617
+ });
1618
+ return response.sent;
1619
+ }
1620
+ };
1621
+ this.salesCustomerTokens = {
1622
+ create: async (request) => {
1623
+ const response = await this.request(`/sales/customer-tokens`, {
1624
+ method: 'POST',
1625
+ body: JSON.stringify(request)
1626
+ });
1627
+ return response;
1628
+ },
1629
+ refresh: async () => {
1630
+ const response = await this.request(`/sales/customer-tokens/refresh`, {
1631
+ method: 'POST'
1632
+ });
1633
+ return response;
1634
+ }
1635
+ };
1636
+ this.salesCarts = {
1637
+ create: async (request) => {
1638
+ const response = await this.request(`/sales/carts`, {
1639
+ method: 'POST',
1640
+ body: JSON.stringify(request)
1641
+ });
1642
+ return response.cart;
1643
+ },
1644
+ get: async (cartId) => {
1645
+ const response = await this.request(`/sales/carts/${cartId}`, {
1646
+ method: 'GET'
1647
+ });
1648
+ return response.cart;
1649
+ },
1650
+ addItem: async (cartId, request) => {
1651
+ const response = await this.request(`/sales/carts/${cartId}/items`, {
1652
+ method: 'POST',
1653
+ body: JSON.stringify(request)
1654
+ });
1655
+ return response.cart;
1656
+ },
1657
+ removeItem: async (cartId, itemId) => {
1658
+ const response = await this.request(`/sales/carts/${cartId}/items/${itemId}`, {
1659
+ method: 'DELETE'
1660
+ });
1661
+ return response.cart;
1662
+ },
1663
+ checkout: async (cartId, request) => {
1664
+ const response = await this.request(`/sales/carts/${cartId}/checkout`, {
1665
+ method: 'POST',
1666
+ body: JSON.stringify(request)
1667
+ });
1668
+ return response;
1669
+ }
1670
+ };
1671
+ this.salesMyOrders = {
1672
+ list: async () => {
1673
+ const response = await this.request(`/sales/my-orders`, {
1674
+ method: 'GET'
1675
+ });
1676
+ return response.orders;
1677
+ }
1678
+ };
1679
+ this.salesOrders = {
1680
+ get: async (orderId) => {
1681
+ const response = await this.request(`/sales/orders/${orderId}`, {
1682
+ method: 'GET'
1683
+ });
1684
+ return response.order;
1685
+ },
1686
+ ticketPdf: async (orderId, passId) => {
1687
+ const response = await this.request(`/sales/orders/${orderId}/passes/${passId}/ticket.pdf`, {
1688
+ method: 'GET'
1689
+ });
1690
+ return response;
1691
+ }
1692
+ };
1693
+ this.salesOrderPayments = {
1694
+ create: async (orderId, request) => {
1695
+ const response = await this.request(`/sales/orders/${orderId}/payments`, {
1696
+ method: 'POST',
1697
+ body: JSON.stringify(request)
1698
+ });
1699
+ return response.payment;
1700
+ }
1701
+ };
1702
+ this.salesRefundRequests = {
1703
+ create: async (orderId, request) => {
1704
+ const response = await this.request(`/sales/orders/${orderId}/refund-requests`, {
1705
+ method: 'POST',
1706
+ body: JSON.stringify(request)
1707
+ });
1708
+ return response.request;
1709
+ }
1710
+ };
1711
+ this.salesCustomers = {
1712
+ create: async (request) => {
1713
+ const response = await this.request(`/sales/customers`, {
1714
+ method: 'POST',
1715
+ body: JSON.stringify(request)
1716
+ });
1717
+ return response.customer;
1718
+ },
1719
+ get: async (customerId) => {
1720
+ const response = await this.request(`/sales/customers/${customerId}`, {
1721
+ method: 'GET'
1722
+ });
1723
+ return response.customer;
1724
+ },
1725
+ update: async (customerId, request) => {
1726
+ const response = await this.request(`/sales/customers/${customerId}`, {
1727
+ method: 'PATCH',
1728
+ body: JSON.stringify(request)
1729
+ });
1730
+ return response.customer;
1731
+ }
1732
+ };
1733
+ this.salesPresaleCodes = {
1734
+ redeem: async (request) => {
1735
+ const response = await this.request(`/sales/presale-codes/redeem`, {
1736
+ method: 'POST',
1737
+ body: JSON.stringify(request)
1738
+ });
1739
+ return response;
1740
+ }
1741
+ };
1742
+ this.sales = {
1743
+ resolveChannel: async (options) => {
1744
+ const params = new URLSearchParams();
1745
+ if (options?.domain !== undefined)
1746
+ params.append('domain', String(options.domain));
1747
+ const queryString = params.toString();
1748
+ const requestPath = queryString ? `/sales/channel?${queryString}` : `/sales/channel`;
1749
+ const response = await this.request(requestPath, {
1750
+ method: 'GET'
1751
+ });
1752
+ return response;
1753
+ },
1754
+ get: async (eventId) => {
1755
+ const response = await this.request(`/sales/events/${eventId}`, {
1756
+ method: 'GET'
1757
+ });
1758
+ return response.event;
1759
+ },
1760
+ getTheme: async () => {
1761
+ const response = await this.request(`/sales/theme`, {
1762
+ method: 'GET'
1763
+ });
1764
+ return response.theme;
1765
+ }
1766
+ };
1767
+ this.themes = {
1768
+ list: async () => {
1769
+ const response = await this.request(`/themes`, {
1770
+ method: 'GET'
1771
+ });
1772
+ return response.themes;
1773
+ },
1774
+ create: async (request) => {
1775
+ const response = await this.request(`/themes`, {
1776
+ method: 'POST',
1777
+ body: JSON.stringify(request)
1778
+ });
1779
+ return response.theme;
1780
+ },
1781
+ get: async (id) => {
1782
+ const response = await this.request(`/themes/${id}`, {
1783
+ method: 'GET'
1784
+ });
1785
+ return response.theme;
1786
+ },
1787
+ update: async (id, request) => {
1788
+ const response = await this.request(`/themes/${id}`, {
1789
+ method: 'PATCH',
1790
+ body: JSON.stringify(request)
1791
+ });
1792
+ return response.theme;
1793
+ },
1794
+ delete: async (id) => {
1795
+ const response = await this.request(`/themes/${id}`, {
1796
+ method: 'DELETE'
1797
+ });
1798
+ return response.deleted;
1799
+ },
1800
+ resolved: async (id) => {
1801
+ const response = await this.request(`/themes/${id}/resolved`, {
1802
+ method: 'GET'
1803
+ });
1804
+ return response.theme;
1805
+ }
1806
+ };
1807
+ this.passes = Object.assign((passeId) => ({
1808
+ entitlements: {
1809
+ redeem: async (barcode, request) => {
1810
+ const response = await this.request(`/passes/${barcode}/redeem`, {
1811
+ method: 'POST',
1812
+ body: JSON.stringify(request)
1813
+ });
1814
+ return response;
1815
+ }
1816
+ }
1817
+ }), {});
1818
+ this.ticketTemplates = {
1819
+ list: async (options) => {
1820
+ const params = new URLSearchParams();
1821
+ if (options?.status !== undefined)
1822
+ params.append('status', String(options.status));
1823
+ if (options?.eventId !== undefined)
1824
+ params.append('eventId', String(options.eventId));
1825
+ const queryString = params.toString();
1826
+ const requestPath = queryString ? `/ticket-templates?${queryString}` : `/ticket-templates`;
1827
+ const response = await this.request(requestPath, {
1828
+ method: 'GET'
1829
+ });
1830
+ return response.templates;
1831
+ },
1832
+ create: async (request) => {
1833
+ const response = await this.request(`/ticket-templates`, {
1834
+ method: 'POST',
1835
+ body: JSON.stringify(request)
1836
+ });
1837
+ return response.template;
1838
+ },
1839
+ get: async (id) => {
1840
+ const response = await this.request(`/ticket-templates/${id}`, {
1841
+ method: 'GET'
1842
+ });
1843
+ return response.template;
1844
+ },
1845
+ update: async (id, request) => {
1846
+ const response = await this.request(`/ticket-templates/${id}`, {
1847
+ method: 'PATCH',
1848
+ body: JSON.stringify(request)
1849
+ });
1850
+ return response.template;
1851
+ },
1852
+ delete: async (id) => {
1853
+ const response = await this.request(`/ticket-templates/${id}`, {
1854
+ method: 'DELETE'
1855
+ });
1856
+ return response.deleted;
1857
+ }
1858
+ };
1859
+ this.scanConfigs = {
1860
+ create: async (request) => {
1861
+ const response = await this.request(`/scan-configs`, {
1862
+ method: 'POST',
1863
+ body: JSON.stringify(request)
1864
+ });
1865
+ return response;
1866
+ },
1867
+ list: async () => {
1868
+ const response = await this.request(`/scan-configs`, {
1869
+ method: 'GET'
1870
+ });
1871
+ return response;
1872
+ },
1873
+ get: async (configId) => {
1874
+ const response = await this.request(`/scan-configs/${configId}`, {
1875
+ method: 'GET'
1876
+ });
1877
+ return response;
1878
+ },
1879
+ update: async (configId, request) => {
1880
+ const response = await this.request(`/scan-configs/${configId}`, {
1881
+ method: 'PATCH',
1882
+ body: JSON.stringify(request)
1883
+ });
1884
+ return response;
1885
+ },
1886
+ delete: async (configId) => {
1887
+ const response = await this.request(`/scan-configs/${configId}`, {
1888
+ method: 'DELETE'
1889
+ });
1890
+ return response;
1891
+ },
1892
+ setDevices: async (configId, request) => {
1893
+ const response = await this.request(`/scan-configs/${configId}/devices`, {
1894
+ method: 'PUT',
1895
+ body: JSON.stringify(request)
1896
+ });
1897
+ return response;
1898
+ }
1899
+ };
1900
+ this.scan = {
1901
+ config: async () => {
1902
+ const response = await this.request(`/scan/config`, {
1903
+ method: 'GET'
1904
+ });
1905
+ return response;
1906
+ },
1907
+ manifest: async (options) => {
1908
+ const params = new URLSearchParams();
1909
+ if (options?.since !== undefined)
1910
+ params.append('since', String(options.since));
1911
+ const queryString = params.toString();
1912
+ const requestPath = queryString ? `/scan/manifest?${queryString}` : `/scan/manifest`;
1913
+ const response = await this.request(requestPath, {
1914
+ method: 'GET'
1915
+ });
1916
+ return response;
1917
+ },
1918
+ operations: async (request) => {
1919
+ const response = await this.request(`/scan/operations`, {
1920
+ method: 'POST',
1921
+ body: JSON.stringify(request)
1922
+ });
1923
+ return response;
1924
+ }
1925
+ };
1926
+ this.scans = {
1927
+ list: async (options) => {
1928
+ const params = new URLSearchParams();
1929
+ if (options?.occurrenceId !== undefined)
1930
+ params.append('occurrenceId', String(options.occurrenceId));
1931
+ if (options?.eventId !== undefined)
1932
+ params.append('eventId', String(options.eventId));
1933
+ if (options?.deviceId !== undefined)
1934
+ params.append('deviceId', String(options.deviceId));
1935
+ if (options?.status !== undefined)
1936
+ params.append('status', String(options.status));
1937
+ if (options?.from !== undefined)
1938
+ params.append('from', String(options.from));
1939
+ if (options?.to !== undefined)
1940
+ params.append('to', String(options.to));
1941
+ if (options?.limit !== undefined)
1942
+ params.append('limit', String(options.limit));
1943
+ const queryString = params.toString();
1944
+ const requestPath = queryString ? `/scans?${queryString}` : `/scans`;
1945
+ const response = await this.request(requestPath, {
1946
+ method: 'GET'
1947
+ });
1948
+ return response;
1949
+ },
1950
+ reverse: async (redemptionId, request) => {
1951
+ const response = await this.request(`/redemptions/${redemptionId}/reverse`, {
1952
+ method: 'POST',
1953
+ body: JSON.stringify(request)
1954
+ });
1955
+ return response;
1956
+ }
1957
+ };
1958
+ this.assets = Object.assign((assetId) => ({
1959
+ assets: {
1960
+ list: async (options) => {
1961
+ const params = new URLSearchParams();
1962
+ if (options?.q !== undefined)
1963
+ params.append('q', String(options.q));
1964
+ if (options?.purpose !== undefined)
1965
+ params.append('purpose', String(options.purpose));
1966
+ if (options?.ownerType !== undefined)
1967
+ params.append('ownerType', String(options.ownerType));
1968
+ if (options?.ownerId !== undefined)
1969
+ params.append('ownerId', String(options.ownerId));
1970
+ if (options?.accountId !== undefined)
1971
+ params.append('accountId', String(options.accountId));
1972
+ const queryString = params.toString();
1973
+ const requestPath = queryString ? `/assets?${queryString}` : `/assets`;
1974
+ const response = await this.request(requestPath, {
1975
+ method: 'GET'
1976
+ });
1977
+ return response.assets;
1978
+ },
1979
+ upload: async (request) => {
1980
+ const response = await this.request(`/assets`, {
1981
+ method: 'POST',
1982
+ body: JSON.stringify(request)
1983
+ });
1984
+ return response.asset;
1985
+ },
1986
+ get: async (id) => {
1987
+ const response = await this.request(`/assets/${id}`, {
1988
+ method: 'GET'
1989
+ });
1990
+ return response.asset;
1991
+ },
1992
+ delete: async (id) => {
1993
+ const response = await this.request(`/assets/${id}`, {
1994
+ method: 'DELETE'
1995
+ });
1996
+ return response.deleted;
1997
+ }
1998
+ }
1999
+ }), {});
2000
+ this.devicePairing = {
2001
+ start: async (request) => {
2002
+ const response = await this.request(`/devices/pairing`, {
2003
+ method: 'POST',
2004
+ body: JSON.stringify(request)
2005
+ });
2006
+ return response;
2007
+ },
2008
+ getStatus: async (pairingId) => {
2009
+ const response = await this.request(`/devices/pairing/${pairingId}`, {
2010
+ method: 'GET'
2011
+ });
2012
+ return response;
2013
+ },
2014
+ claim: async (request) => {
2015
+ const response = await this.request(`/devices/pairing/claim`, {
2016
+ method: 'POST',
2017
+ body: JSON.stringify(request)
2018
+ });
2019
+ return response;
2020
+ },
2021
+ confirm: async (pairingId, request) => {
2022
+ const response = await this.request(`/devices/pairing/${pairingId}/confirm`, {
2023
+ method: 'POST',
2024
+ body: JSON.stringify(request)
2025
+ });
2026
+ return response;
2027
+ },
2028
+ reject: async (pairingId, request) => {
2029
+ const response = await this.request(`/devices/pairing/${pairingId}/reject`, {
2030
+ method: 'POST',
2031
+ body: JSON.stringify(request)
2032
+ });
2033
+ return response;
2034
+ }
2035
+ };
2036
+ this.deviceAuth = {
2037
+ issueToken: async (request) => {
2038
+ const response = await this.request(`/devices/token`, {
2039
+ method: 'POST',
2040
+ body: JSON.stringify(request)
2041
+ });
2042
+ return response;
2043
+ },
2044
+ jwks: async () => {
2045
+ const response = await this.request(`/devices/jwks`, {
2046
+ method: 'GET'
2047
+ });
2048
+ return response;
2049
+ }
2050
+ };
2051
+ this.deviceSelf = {
2052
+ getMe: async () => {
2053
+ const response = await this.request(`/devices/me`, {
2054
+ method: 'GET'
2055
+ });
2056
+ return response;
2057
+ },
2058
+ heartbeat: async (request) => {
2059
+ const response = await this.request(`/devices/me/heartbeat`, {
2060
+ method: 'POST',
2061
+ body: JSON.stringify(request)
2062
+ });
2063
+ return response;
2064
+ },
2065
+ declarePeripherals: async (request) => {
2066
+ const response = await this.request(`/devices/me/peripherals`, {
2067
+ method: 'PUT',
2068
+ body: JSON.stringify(request)
2069
+ });
2070
+ return response;
2071
+ },
2072
+ fetchCommands: async (options) => {
2073
+ const params = new URLSearchParams();
2074
+ if (options?.wait !== undefined)
2075
+ params.append('wait', String(options.wait));
2076
+ const queryString = params.toString();
2077
+ const requestPath = queryString ? `/devices/me/commands?${queryString}` : `/devices/me/commands`;
2078
+ const response = await this.request(requestPath, {
2079
+ method: 'GET'
2080
+ });
2081
+ return response;
2082
+ },
2083
+ reportProgress: async (commandId, request) => {
2084
+ const response = await this.request(`/devices/me/commands/${commandId}/progress`, {
2085
+ method: 'POST',
2086
+ body: JSON.stringify(request)
2087
+ });
2088
+ return response;
2089
+ },
2090
+ reportResult: async (commandId, request) => {
2091
+ const response = await this.request(`/devices/me/commands/${commandId}/result`, {
2092
+ method: 'POST',
2093
+ body: JSON.stringify(request)
2094
+ });
2095
+ return response;
2096
+ },
2097
+ ingestEvents: async (request) => {
2098
+ const response = await this.request(`/devices/me/events`, {
2099
+ method: 'POST',
2100
+ body: JSON.stringify(request)
2101
+ });
2102
+ return response;
2103
+ },
2104
+ getCertificate: async () => {
2105
+ const response = await this.request(`/devices/me/certificate`, {
2106
+ method: 'GET'
2107
+ });
2108
+ return response;
2109
+ }
2110
+ };
2111
+ this.devices = {
2112
+ printers: async () => {
2113
+ const response = await this.request(`/devices/printers`, {
2114
+ method: 'GET'
2115
+ });
2116
+ return response;
2117
+ },
2118
+ mediaCatalog: async () => {
2119
+ const response = await this.request(`/devices/media-catalog`, {
2120
+ method: 'GET'
2121
+ });
2122
+ return response;
2123
+ },
2124
+ list: async (options) => {
2125
+ const params = new URLSearchParams();
2126
+ if (options?.accountId !== undefined)
2127
+ params.append('accountId', String(options.accountId));
2128
+ if (options?.type !== undefined)
2129
+ params.append('type', String(options.type));
2130
+ if (options?.status !== undefined)
2131
+ params.append('status', String(options.status));
2132
+ if (options?.connectivity !== undefined)
2133
+ params.append('connectivity', String(options.connectivity));
2134
+ if (options?.locationId !== undefined)
2135
+ params.append('locationId', String(options.locationId));
2136
+ const queryString = params.toString();
2137
+ const requestPath = queryString ? `/devices?${queryString}` : `/devices`;
2138
+ const response = await this.request(requestPath, {
2139
+ method: 'GET'
2140
+ });
2141
+ return response;
2142
+ },
2143
+ get: async (deviceId) => {
2144
+ const response = await this.request(`/devices/${deviceId}`, {
2145
+ method: 'GET'
2146
+ });
2147
+ return response;
2148
+ },
2149
+ update: async (deviceId, request) => {
2150
+ const response = await this.request(`/devices/${deviceId}`, {
2151
+ method: 'PATCH',
2152
+ body: JSON.stringify(request)
2153
+ });
2154
+ return response;
2155
+ },
2156
+ delete: async (deviceId) => {
2157
+ const response = await this.request(`/devices/${deviceId}`, {
2158
+ method: 'DELETE'
2159
+ });
2160
+ return response;
2161
+ },
2162
+ revoke: async (deviceId) => {
2163
+ const response = await this.request(`/devices/${deviceId}/revoke`, {
2164
+ method: 'POST'
2165
+ });
2166
+ return response;
2167
+ },
2168
+ assignRoles: async (deviceId, request) => {
2169
+ const response = await this.request(`/devices/${deviceId}/roles`, {
2170
+ method: 'PUT',
2171
+ body: JSON.stringify(request)
2172
+ });
2173
+ return response;
2174
+ },
2175
+ rotateCredential: async (deviceId, request) => {
2176
+ const response = await this.request(`/devices/${deviceId}/credentials/rotate`, {
2177
+ method: 'POST',
2178
+ body: JSON.stringify(request)
2179
+ });
2180
+ return response;
2181
+ },
2182
+ dispatchCommand: async (deviceId, request) => {
2183
+ const response = await this.request(`/devices/${deviceId}/commands`, {
2184
+ method: 'POST',
2185
+ body: JSON.stringify(request)
2186
+ });
2187
+ return response;
2188
+ },
2189
+ listCommands: async (deviceId) => {
2190
+ const response = await this.request(`/devices/${deviceId}/commands`, {
2191
+ method: 'GET'
2192
+ });
2193
+ return response;
2194
+ },
2195
+ getCommand: async (commandId) => {
2196
+ const response = await this.request(`/devices/commands/${commandId}`, {
2197
+ method: 'GET'
2198
+ });
2199
+ return response;
2200
+ },
2201
+ listEvents: async (deviceId) => {
2202
+ const response = await this.request(`/devices/${deviceId}/events`, {
2203
+ method: 'GET'
2204
+ });
2205
+ return response;
2206
+ },
2207
+ mintLocalToken: async (deviceId, request) => {
2208
+ const response = await this.request(`/devices/${deviceId}/local-tokens`, {
2209
+ method: 'POST',
2210
+ body: JSON.stringify(request)
2211
+ });
2212
+ return response;
2213
+ }
2214
+ };
2215
+ this.locations = {
2216
+ create: async (request) => {
2217
+ const response = await this.request(`/locations`, {
2218
+ method: 'POST',
2219
+ body: JSON.stringify(request)
2220
+ });
2221
+ return response;
2222
+ },
2223
+ list: async () => {
2224
+ const response = await this.request(`/locations`, {
2225
+ method: 'GET'
2226
+ });
2227
+ return response;
2228
+ },
2229
+ get: async (locationId) => {
2230
+ const response = await this.request(`/locations/${locationId}`, {
2231
+ method: 'GET'
2232
+ });
2233
+ return response;
2234
+ },
2235
+ update: async (locationId, request) => {
2236
+ const response = await this.request(`/locations/${locationId}`, {
2237
+ method: 'PATCH',
2238
+ body: JSON.stringify(request)
2239
+ });
2240
+ return response;
2241
+ },
2242
+ delete: async (locationId) => {
2243
+ const response = await this.request(`/locations/${locationId}`, {
2244
+ method: 'DELETE'
2245
+ });
2246
+ return response;
2247
+ }
2248
+ };
2249
+ this.reports = {
2250
+ summary: async (options) => {
2251
+ const params = new URLSearchParams();
2252
+ if (options?.eventId !== undefined)
2253
+ params.append('eventId', String(options.eventId));
2254
+ if (options?.from !== undefined)
2255
+ params.append('from', String(options.from));
2256
+ if (options?.to !== undefined)
2257
+ params.append('to', String(options.to));
2258
+ const queryString = params.toString();
2259
+ const requestPath = queryString ? `/reports/summary?${queryString}` : `/reports/summary`;
2260
+ const response = await this.request(requestPath, {
2261
+ method: 'GET'
2262
+ });
2263
+ return response;
2264
+ },
2265
+ timeseries: async (options) => {
2266
+ const params = new URLSearchParams();
2267
+ if (options?.eventId !== undefined)
2268
+ params.append('eventId', String(options.eventId));
2269
+ if (options?.from !== undefined)
2270
+ params.append('from', String(options.from));
2271
+ if (options?.to !== undefined)
2272
+ params.append('to', String(options.to));
2273
+ if (options?.granularity !== undefined)
2274
+ params.append('granularity', String(options.granularity));
2275
+ const queryString = params.toString();
2276
+ const requestPath = queryString ? `/reports/timeseries?${queryString}` : `/reports/timeseries`;
2277
+ const response = await this.request(requestPath, {
2278
+ method: 'GET'
2279
+ });
2280
+ return response;
2281
+ },
2282
+ inventory: async (options) => {
2283
+ const params = new URLSearchParams();
2284
+ if (options?.eventId !== undefined)
2285
+ params.append('eventId', String(options.eventId));
2286
+ const queryString = params.toString();
2287
+ const requestPath = queryString ? `/reports/inventory?${queryString}` : `/reports/inventory`;
2288
+ const response = await this.request(requestPath, {
2289
+ method: 'GET'
2290
+ });
2291
+ return response;
2292
+ },
2293
+ meta: async () => {
2294
+ const response = await this.request(`/reports/meta`, {
2295
+ method: 'GET'
2296
+ });
2297
+ return response;
2298
+ },
2299
+ query: async (request) => {
2300
+ const response = await this.request(`/reports/query`, {
2301
+ method: 'POST',
2302
+ body: JSON.stringify(request)
2303
+ });
2304
+ return response;
2305
+ },
2306
+ savedList: async (options) => {
2307
+ const params = new URLSearchParams();
2308
+ if (options?.accountId !== undefined)
2309
+ params.append('accountId', String(options.accountId));
2310
+ const queryString = params.toString();
2311
+ const requestPath = queryString ? `/reports/saved?${queryString}` : `/reports/saved`;
2312
+ const response = await this.request(requestPath, {
2313
+ method: 'GET'
2314
+ });
2315
+ return response;
2316
+ },
2317
+ savedCreate: async (request) => {
2318
+ const response = await this.request(`/reports/saved`, {
2319
+ method: 'POST',
2320
+ body: JSON.stringify(request)
2321
+ });
2322
+ return response;
2323
+ },
2324
+ savedGet: async (id) => {
2325
+ const response = await this.request(`/reports/saved/${id}`, {
2326
+ method: 'GET'
2327
+ });
2328
+ return response;
2329
+ },
2330
+ savedUpdate: async (id, request) => {
2331
+ const response = await this.request(`/reports/saved/${id}`, {
2332
+ method: 'PATCH',
2333
+ body: JSON.stringify(request)
2334
+ });
2335
+ return response;
2336
+ },
2337
+ savedDelete: async (id) => {
2338
+ const response = await this.request(`/reports/saved/${id}`, {
2339
+ method: 'DELETE'
2340
+ });
2341
+ return response;
2342
+ },
2343
+ savedRun: async (id, request) => {
2344
+ const response = await this.request(`/reports/saved/${id}/run`, {
2345
+ method: 'POST',
2346
+ body: JSON.stringify(request)
2347
+ });
2348
+ return response;
2349
+ },
2350
+ dashboardList: async (options) => {
2351
+ const params = new URLSearchParams();
2352
+ if (options?.accountId !== undefined)
2353
+ params.append('accountId', String(options.accountId));
2354
+ const queryString = params.toString();
2355
+ const requestPath = queryString ? `/reports/dashboards?${queryString}` : `/reports/dashboards`;
2356
+ const response = await this.request(requestPath, {
2357
+ method: 'GET'
2358
+ });
2359
+ return response;
2360
+ },
2361
+ dashboardCreate: async (request) => {
2362
+ const response = await this.request(`/reports/dashboards`, {
2363
+ method: 'POST',
2364
+ body: JSON.stringify(request)
2365
+ });
2366
+ return response;
2367
+ },
2368
+ dashboardGet: async (id) => {
2369
+ const response = await this.request(`/reports/dashboards/${id}`, {
2370
+ method: 'GET'
2371
+ });
2372
+ return response;
2373
+ },
2374
+ dashboardUpdate: async (id, request) => {
2375
+ const response = await this.request(`/reports/dashboards/${id}`, {
2376
+ method: 'PATCH',
2377
+ body: JSON.stringify(request)
2378
+ });
2379
+ return response;
2380
+ },
2381
+ dashboardDelete: async (id) => {
2382
+ const response = await this.request(`/reports/dashboards/${id}`, {
2383
+ method: 'DELETE'
2384
+ });
2385
+ return response;
2386
+ },
2387
+ templateList: async () => {
2388
+ const response = await this.request(`/reports/templates`, {
2389
+ method: 'GET'
2390
+ });
2391
+ return response;
2392
+ },
2393
+ templateInstall: async (key) => {
2394
+ const response = await this.request(`/reports/templates/${key}/install`, {
2395
+ method: 'POST'
2396
+ });
2397
+ return response;
2398
+ }
2399
+ };
2400
+ this.webhookEndpoints = {
2401
+ create: async (request) => {
2402
+ const response = await this.request(`/webhook-endpoints`, {
2403
+ method: 'POST',
2404
+ body: JSON.stringify(request)
2405
+ });
2406
+ return response;
2407
+ },
2408
+ list: async (options) => {
2409
+ const params = new URLSearchParams();
2410
+ if (options?.accountId !== undefined)
2411
+ params.append('accountId', String(options.accountId));
2412
+ const queryString = params.toString();
2413
+ const requestPath = queryString ? `/webhook-endpoints?${queryString}` : `/webhook-endpoints`;
2414
+ const response = await this.request(requestPath, {
2415
+ method: 'GET'
2416
+ });
2417
+ return response;
2418
+ },
2419
+ get: async (endpointId) => {
2420
+ const response = await this.request(`/webhook-endpoints/${endpointId}`, {
2421
+ method: 'GET'
2422
+ });
2423
+ return response;
2424
+ },
2425
+ update: async (endpointId, request) => {
2426
+ const response = await this.request(`/webhook-endpoints/${endpointId}`, {
2427
+ method: 'PATCH',
2428
+ body: JSON.stringify(request)
2429
+ });
2430
+ return response;
2431
+ },
2432
+ delete: async (endpointId) => {
2433
+ const response = await this.request(`/webhook-endpoints/${endpointId}`, {
2434
+ method: 'DELETE'
2435
+ });
2436
+ return response;
2437
+ },
2438
+ test: async (endpointId) => {
2439
+ const response = await this.request(`/webhook-endpoints/${endpointId}/test`, {
2440
+ method: 'POST'
2441
+ });
2442
+ return response;
2443
+ }
2444
+ };
2445
+ this.webhookEventTypes = {
2446
+ list: async () => {
2447
+ const response = await this.request(`/webhook-event-types`, {
2448
+ method: 'GET'
2449
+ });
2450
+ return response;
2451
+ }
2452
+ };
2453
+ this.webhookDeliveries = {
2454
+ listInbound: async () => {
2455
+ const response = await this.request(`/webhook-inbound`, {
2456
+ method: 'GET'
2457
+ });
2458
+ return response;
2459
+ },
2460
+ list: async (options) => {
2461
+ const params = new URLSearchParams();
2462
+ if (options?.endpointId !== undefined)
2463
+ params.append('endpointId', String(options.endpointId));
2464
+ if (options?.limit !== undefined)
2465
+ params.append('limit', String(options.limit));
2466
+ const queryString = params.toString();
2467
+ const requestPath = queryString ? `/webhook-deliveries?${queryString}` : `/webhook-deliveries`;
2468
+ const response = await this.request(requestPath, {
2469
+ method: 'GET'
2470
+ });
2471
+ return response;
2472
+ },
2473
+ get: async (deliveryId) => {
2474
+ const response = await this.request(`/webhook-deliveries/${deliveryId}`, {
2475
+ method: 'GET'
2476
+ });
2477
+ return response;
2478
+ }
2479
+ };
2480
+ this.integrations = {
2481
+ list: async () => {
2482
+ const response = await this.request(`/integrations`, {
2483
+ method: 'GET'
2484
+ });
2485
+ return response;
2486
+ },
2487
+ listConnectedApps: async () => {
2488
+ const response = await this.request(`/integrations/connected-apps`, {
2489
+ method: 'GET'
2490
+ });
2491
+ return response;
2492
+ },
2493
+ get: async (id) => {
2494
+ const response = await this.request(`/integrations/${id}`, {
2495
+ method: 'GET'
2496
+ });
2497
+ return response;
2498
+ },
2499
+ revokeConnection: async (id) => {
2500
+ const response = await this.request(`/integrations/${id}/connection`, {
2501
+ method: 'DELETE'
2502
+ });
2503
+ return response;
2504
+ }
2505
+ };
2506
+ this.baseUrl = config.baseUrl.replace(/\/$/, '');
2507
+ this.authMode = config.authMode || 'bearer';
2508
+ this.accessToken = config.accessToken;
2509
+ this.refreshToken = config.refreshToken;
2510
+ this.onTokenRefresh = config.onTokenRefresh;
2511
+ this.onAuthFailure = config.onAuthFailure;
2512
+ this.organisationSlug = config.organisationSlug;
2513
+ this.headers = config.headers || {};
2514
+ this.refreshEndpoint = config.refreshEndpoint ||
2515
+ (this.authMode === 'cookie' ? '/api/oauth/refresh' : '/v1/auth/refresh');
2516
+ if (config.debug === true) {
2517
+ this.debugConfig = { logRequests: true, logResponses: true, logErrors: true };
2518
+ }
2519
+ else if (config.debug && typeof config.debug === 'object') {
2520
+ this.debugConfig = config.debug;
2521
+ }
2522
+ else {
2523
+ this.debugConfig = null;
2524
+ }
2525
+ this.logger = this.debugConfig?.logger || {
2526
+ log: (...args) => console.log('[BackstageSDK]', ...args),
2527
+ error: (...args) => console.error('[BackstageSDK]', ...args),
2528
+ };
2529
+ }
2530
+ debugLog(type, ...args) {
2531
+ if (!this.debugConfig)
2532
+ return;
2533
+ if (type === 'request' && this.debugConfig.logRequests) {
2534
+ this.logger.log('→', ...args);
2535
+ }
2536
+ else if (type === 'response' && this.debugConfig.logResponses) {
2537
+ this.logger.log('←', ...args);
2538
+ }
2539
+ else if (type === 'error' && this.debugConfig.logErrors) {
2540
+ this.logger.error('✗', ...args);
2541
+ }
2542
+ }
2543
+ setAccessToken(token) {
2544
+ this.accessToken = token;
2545
+ }
2546
+ clearAccessToken() {
2547
+ this.accessToken = undefined;
2548
+ }
2549
+ getAccessToken() {
2550
+ return typeof this.accessToken === 'function' ? this.accessToken() : this.accessToken;
2551
+ }
2552
+ setRefreshToken(token) {
2553
+ this.refreshToken = token;
2554
+ }
2555
+ getRefreshToken() {
2556
+ return this.refreshToken;
2557
+ }
2558
+ getCookie(name) {
2559
+ if (typeof document === 'undefined') {
2560
+ return undefined;
2561
+ }
2562
+ const value = `; ${document.cookie}`;
2563
+ const parts = value.split(`; ${name}=`);
2564
+ if (parts.length === 2) {
2565
+ return parts.pop()?.split(';').shift();
2566
+ }
2567
+ return undefined;
2568
+ }
2569
+ resolveOrgSlug() {
2570
+ if (this.organisationSlug !== undefined) {
2571
+ return typeof this.organisationSlug === 'function'
2572
+ ? this.organisationSlug()
2573
+ : this.organisationSlug;
2574
+ }
2575
+ return this.getOrgFromSubdomain();
2576
+ }
2577
+ getOrgFromSubdomain() {
2578
+ if (typeof window === 'undefined') {
2579
+ return undefined;
2580
+ }
2581
+ const host = window.location.hostname;
2582
+ const parts = host.split('.');
2583
+ if (parts.length >= 3) {
2584
+ const orgSlug = parts[0];
2585
+ if (orgSlug && orgSlug !== 'www' && orgSlug.length > 0) {
2586
+ return orgSlug;
2587
+ }
2588
+ }
2589
+ return undefined;
2590
+ }
2591
+ async attemptTokenRefresh() {
2592
+ if (this.onAuthFailure) {
2593
+ return await this.onAuthFailure();
2594
+ }
2595
+ if (this.authMode === 'cookie') {
2596
+ try {
2597
+ const refreshResponse = await fetch(this.refreshEndpoint, {
2598
+ method: 'POST',
2599
+ credentials: 'include',
2600
+ });
2601
+ return refreshResponse.ok;
2602
+ }
2603
+ catch {
2604
+ return false;
2605
+ }
2606
+ }
2607
+ else if (this.refreshToken) {
2608
+ try {
2609
+ const refreshUrl = this.refreshEndpoint.startsWith('http')
2610
+ ? this.refreshEndpoint
2611
+ : `${this.baseUrl}${this.refreshEndpoint}`;
2612
+ const refreshResponse = await fetch(refreshUrl, {
2613
+ method: 'POST',
2614
+ headers: {
2615
+ 'Content-Type': 'application/json',
2616
+ },
2617
+ body: JSON.stringify({ refreshToken: this.refreshToken }),
2618
+ });
2619
+ if (!refreshResponse.ok) {
2620
+ return false;
2621
+ }
2622
+ const refreshJson = await refreshResponse.json();
2623
+ const refreshData = refreshJson.status === 'success' && refreshJson.data !== undefined
2624
+ ? refreshJson.data
2625
+ : refreshJson;
2626
+ this.accessToken = refreshData.accessToken;
2627
+ this.refreshToken = refreshData.refreshToken;
2628
+ if (this.onTokenRefresh) {
2629
+ await this.onTokenRefresh(refreshData.accessToken, refreshData.refreshToken);
2630
+ }
2631
+ return true;
2632
+ }
2633
+ catch {
2634
+ return false;
2635
+ }
2636
+ }
2637
+ return false;
2638
+ }
2639
+ async request(path, options = {}) {
2640
+ const versionedPath = path.startsWith('/v1') ? path : `/v1${path}`;
2641
+ const url = `${this.baseUrl}${versionedPath}`;
2642
+ const headers = {
2643
+ 'Content-Type': 'application/json',
2644
+ 'TL-Version': exports.API_DATED_VERSION,
2645
+ 'TL-Client': exports.SDK_CLIENT_HEADER,
2646
+ ...this.headers,
2647
+ ...(options.headers || {}),
2648
+ };
2649
+ if (this.authMode === 'bearer') {
2650
+ const bearerToken = this.getAccessToken();
2651
+ if (bearerToken) {
2652
+ headers['Authorization'] = `Bearer ${bearerToken}`;
2653
+ }
2654
+ if (this.organisationSlug !== undefined) {
2655
+ const orgSlug = this.resolveOrgSlug();
2656
+ if (orgSlug) {
2657
+ headers['X-Ticketlayer-Org'] = orgSlug;
2658
+ }
2659
+ }
2660
+ }
2661
+ if (this.authMode === 'cookie') {
2662
+ const cookieToken = this.getCookie('access_token');
2663
+ if (cookieToken) {
2664
+ headers['Authorization'] = `Bearer ${cookieToken}`;
2665
+ }
2666
+ const orgSlug = this.resolveOrgSlug();
2667
+ if (orgSlug) {
2668
+ headers['X-Ticketlayer-Org'] = orgSlug;
2669
+ }
2670
+ }
2671
+ const fetchOptions = {
2672
+ ...options,
2673
+ headers,
2674
+ };
2675
+ if (this.authMode === 'cookie') {
2676
+ fetchOptions.credentials = 'include';
2677
+ }
2678
+ const requestBody = options.body ? JSON.parse(options.body) : undefined;
2679
+ this.debugLog('request', options.method || 'GET', versionedPath, requestBody ? { body: requestBody } : '');
2680
+ let response = await fetch(url, fetchOptions);
2681
+ const shouldRefresh = response.status === 401 &&
2682
+ !path.includes('/auth/refresh') &&
2683
+ !path.includes('/oauth/refresh');
2684
+ if (shouldRefresh) {
2685
+ const refreshSuccessful = await this.attemptTokenRefresh();
2686
+ if (refreshSuccessful) {
2687
+ if (this.authMode === 'bearer') {
2688
+ const newBearerToken = this.getAccessToken();
2689
+ if (newBearerToken) {
2690
+ headers['Authorization'] = `Bearer ${newBearerToken}`;
2691
+ }
2692
+ }
2693
+ if (this.authMode === 'cookie') {
2694
+ const newCookieToken = this.getCookie('access_token');
2695
+ if (newCookieToken) {
2696
+ headers['Authorization'] = `Bearer ${newCookieToken}`;
2697
+ }
2698
+ }
2699
+ response = await fetch(url, {
2700
+ ...options,
2701
+ headers,
2702
+ credentials: this.authMode === 'cookie' ? 'include' : undefined,
2703
+ });
2704
+ }
2705
+ else {
2706
+ throw new BackstageAPIError('Session expired. Please log in again.', 'SESSION_EXPIRED', 401);
2707
+ }
2708
+ }
2709
+ if (!response.ok) {
2710
+ const errorBody = await response.json().catch(() => ({
2711
+ error: { message: response.statusText, code: 'HTTP_ERROR' },
2712
+ }));
2713
+ const errorInfo = errorBody.error || errorBody;
2714
+ const message = typeof errorInfo === 'object' && errorInfo !== null
2715
+ ? (errorInfo.message || 'Request failed')
2716
+ : String(errorInfo || 'Request failed');
2717
+ const code = typeof errorInfo === 'object' && errorInfo !== null
2718
+ ? (errorInfo.code || 'UNKNOWN_ERROR')
2719
+ : 'UNKNOWN_ERROR';
2720
+ const error = new BackstageAPIError(message, code, response.status);
2721
+ this.debugLog('error', options.method || 'GET', versionedPath, { status: response.status, code, message });
2722
+ throw error;
2723
+ }
2724
+ const json = await response.json();
2725
+ let result;
2726
+ if (json.status === 'success' && json.data !== undefined) {
2727
+ result = json.data;
2728
+ }
2729
+ else {
2730
+ result = json;
2731
+ }
2732
+ this.debugLog('response', options.method || 'GET', versionedPath, { status: response.status, data: result });
2733
+ return result;
2734
+ }
2735
+ }
2736
+ exports.BackstageClient = BackstageClient;