@bookinglab/booking-journey-api 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -11
- package/dist/index.d.mts +252 -2
- package/dist/index.d.ts +252 -2
- package/dist/index.js +269 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,28 @@ interface ApiError {
|
|
|
25
25
|
code?: string;
|
|
26
26
|
details?: any;
|
|
27
27
|
}
|
|
28
|
+
interface Booking {
|
|
29
|
+
id: string;
|
|
30
|
+
userId: string;
|
|
31
|
+
serviceId: string;
|
|
32
|
+
date: string;
|
|
33
|
+
status: 'pending' | 'confirmed' | 'cancelled';
|
|
34
|
+
createdAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
}
|
|
37
|
+
interface CreateBookingRequest {
|
|
38
|
+
userId: string;
|
|
39
|
+
serviceId: string;
|
|
40
|
+
date: string;
|
|
41
|
+
notes?: string;
|
|
42
|
+
}
|
|
43
|
+
interface Service {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
duration: number;
|
|
48
|
+
price: number;
|
|
49
|
+
}
|
|
28
50
|
/**
|
|
29
51
|
* JRNI Configuration
|
|
30
52
|
*/
|
|
@@ -286,6 +308,109 @@ interface UpdateMemberDetailsData {
|
|
|
286
308
|
answer_id: number;
|
|
287
309
|
}>;
|
|
288
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Child Company Types
|
|
313
|
+
*/
|
|
314
|
+
interface ChildCompanyAddress {
|
|
315
|
+
id: number;
|
|
316
|
+
address1: string;
|
|
317
|
+
address2: string;
|
|
318
|
+
address3: string;
|
|
319
|
+
address4: string;
|
|
320
|
+
address5: string;
|
|
321
|
+
postcode: string;
|
|
322
|
+
country: string;
|
|
323
|
+
lat: number;
|
|
324
|
+
long: number;
|
|
325
|
+
map_url: string;
|
|
326
|
+
map_marker: string;
|
|
327
|
+
phone: string;
|
|
328
|
+
homephone: string;
|
|
329
|
+
pretty_workphone: string;
|
|
330
|
+
_links: Record<string, any>;
|
|
331
|
+
}
|
|
332
|
+
interface ChildCompanySettings {
|
|
333
|
+
has_services: boolean;
|
|
334
|
+
has_resources: boolean;
|
|
335
|
+
has_groups: boolean;
|
|
336
|
+
payment_tax: number;
|
|
337
|
+
currency: string;
|
|
338
|
+
requires_login: boolean;
|
|
339
|
+
has_wallets: boolean;
|
|
340
|
+
has_question_groups: boolean;
|
|
341
|
+
_links: Record<string, any>;
|
|
342
|
+
}
|
|
343
|
+
interface ChildCompany {
|
|
344
|
+
id: number;
|
|
345
|
+
name: string;
|
|
346
|
+
description: string;
|
|
347
|
+
company_type: string;
|
|
348
|
+
address_id: number;
|
|
349
|
+
website: string;
|
|
350
|
+
multi_status: string[];
|
|
351
|
+
numeric_widget_id: number;
|
|
352
|
+
currency_code: string;
|
|
353
|
+
timezone: string;
|
|
354
|
+
country_code: string;
|
|
355
|
+
live: boolean;
|
|
356
|
+
ref: string;
|
|
357
|
+
created_at: string;
|
|
358
|
+
updated_at: string;
|
|
359
|
+
children_count: number;
|
|
360
|
+
locale: string;
|
|
361
|
+
available_locales: string[];
|
|
362
|
+
membership_id: number;
|
|
363
|
+
address: ChildCompanyAddress;
|
|
364
|
+
_embedded: {
|
|
365
|
+
settings: ChildCompanySettings;
|
|
366
|
+
};
|
|
367
|
+
_links: Record<string, any>;
|
|
368
|
+
}
|
|
369
|
+
interface ChildCompaniesResponse {
|
|
370
|
+
total_entries: number;
|
|
371
|
+
_embedded: {
|
|
372
|
+
companies: ChildCompany[];
|
|
373
|
+
};
|
|
374
|
+
_links: Record<string, any>;
|
|
375
|
+
}
|
|
376
|
+
interface GetChildCompaniesParams {
|
|
377
|
+
person_id?: number;
|
|
378
|
+
Person_Id?: string;
|
|
379
|
+
service_id?: string;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Resource Types
|
|
383
|
+
*/
|
|
384
|
+
interface ResourceLinks {
|
|
385
|
+
self: {
|
|
386
|
+
href: string;
|
|
387
|
+
};
|
|
388
|
+
items: {
|
|
389
|
+
href: string;
|
|
390
|
+
};
|
|
391
|
+
images: {
|
|
392
|
+
href: string;
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
interface Resource {
|
|
396
|
+
id: number;
|
|
397
|
+
name: string;
|
|
398
|
+
type: string;
|
|
399
|
+
group_id: number;
|
|
400
|
+
deleted: boolean;
|
|
401
|
+
disabled: boolean;
|
|
402
|
+
company_id: number;
|
|
403
|
+
order: number;
|
|
404
|
+
max_book: number;
|
|
405
|
+
_links: ResourceLinks;
|
|
406
|
+
}
|
|
407
|
+
interface ResourcesResponse {
|
|
408
|
+
total_entries: number;
|
|
409
|
+
_embedded: {
|
|
410
|
+
resources: Resource[];
|
|
411
|
+
};
|
|
412
|
+
_links: Record<string, any>;
|
|
413
|
+
}
|
|
289
414
|
|
|
290
415
|
/**
|
|
291
416
|
* Core API Client
|
|
@@ -335,6 +460,50 @@ declare class ApiClient {
|
|
|
335
460
|
private normalizeError;
|
|
336
461
|
}
|
|
337
462
|
|
|
463
|
+
/**
|
|
464
|
+
* BookingLab API Client
|
|
465
|
+
* Provides methods for interacting with the BookingLab API
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
declare class BookingLabClient extends ApiClient {
|
|
469
|
+
/**
|
|
470
|
+
* Get all bookings
|
|
471
|
+
*/
|
|
472
|
+
getBookings(userId?: string): Promise<ApiResponse<Booking[]>>;
|
|
473
|
+
/**
|
|
474
|
+
* Get a single booking by ID
|
|
475
|
+
*/
|
|
476
|
+
getBooking(bookingId: string): Promise<ApiResponse<Booking>>;
|
|
477
|
+
/**
|
|
478
|
+
* Create a new booking
|
|
479
|
+
*/
|
|
480
|
+
createBooking(booking: CreateBookingRequest): Promise<ApiResponse<Booking>>;
|
|
481
|
+
/**
|
|
482
|
+
* Update an existing booking
|
|
483
|
+
*/
|
|
484
|
+
updateBooking(bookingId: string, updates: Partial<Booking>): Promise<ApiResponse<Booking>>;
|
|
485
|
+
/**
|
|
486
|
+
* Cancel a booking
|
|
487
|
+
*/
|
|
488
|
+
cancelBooking(bookingId: string): Promise<ApiResponse<Booking>>;
|
|
489
|
+
/**
|
|
490
|
+
* Delete a booking
|
|
491
|
+
*/
|
|
492
|
+
deleteBooking(bookingId: string): Promise<ApiResponse<void>>;
|
|
493
|
+
/**
|
|
494
|
+
* Get all services
|
|
495
|
+
*/
|
|
496
|
+
getServices(): Promise<ApiResponse<Service[]>>;
|
|
497
|
+
/**
|
|
498
|
+
* Get a single service by ID
|
|
499
|
+
*/
|
|
500
|
+
getService(serviceId: string): Promise<ApiResponse<Service>>;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Create a new BookingLab client instance
|
|
504
|
+
*/
|
|
505
|
+
declare function createBookingLabClient(baseUrl: string, authToken?: string): BookingLabClient;
|
|
506
|
+
|
|
338
507
|
/**
|
|
339
508
|
* JRNI API Client
|
|
340
509
|
* Provides methods for interacting with the JRNI API
|
|
@@ -344,10 +513,25 @@ declare class JrniClient extends ApiClient {
|
|
|
344
513
|
private appId;
|
|
345
514
|
private appKey;
|
|
346
515
|
constructor(baseUrl: string, config: JrniConfig);
|
|
516
|
+
/**
|
|
517
|
+
* Get default headers for JRNI API requests
|
|
518
|
+
*/
|
|
519
|
+
private getDefaultHeaders;
|
|
347
520
|
/**
|
|
348
521
|
* Login to JRNI
|
|
349
522
|
*/
|
|
350
523
|
login(credentials: LoginRequest): Promise<ApiResponse<LoginResponse>>;
|
|
524
|
+
/**
|
|
525
|
+
* Get child companies for a parent company
|
|
526
|
+
* @param companyId - The parent company ID
|
|
527
|
+
* @param params - Optional query parameters (person_id, Person_Id)
|
|
528
|
+
*/
|
|
529
|
+
getChildCompanies(companyId: number, params?: GetChildCompaniesParams): Promise<ApiResponse<ChildCompaniesResponse>>;
|
|
530
|
+
/**
|
|
531
|
+
* Get resources for a company
|
|
532
|
+
* @param companyId - The company ID
|
|
533
|
+
*/
|
|
534
|
+
getResources(companyId: number): Promise<ApiResponse<ResourcesResponse>>;
|
|
351
535
|
/**
|
|
352
536
|
* Update JRNI configuration
|
|
353
537
|
*/
|
|
@@ -359,24 +543,41 @@ declare class JrniClient extends ApiClient {
|
|
|
359
543
|
declare function createJrniClient(baseUrl: string, config: JrniConfig): JrniClient;
|
|
360
544
|
|
|
361
545
|
interface ApiClientContextValue {
|
|
546
|
+
bookingLabClient: BookingLabClient | null;
|
|
362
547
|
jrniClient: JrniClient | null;
|
|
363
548
|
}
|
|
364
549
|
interface ApiClientProviderProps {
|
|
365
550
|
children: ReactNode;
|
|
551
|
+
bookingLabBaseUrl?: string;
|
|
366
552
|
jrniBaseUrl?: string;
|
|
367
553
|
jrniConfig?: JrniConfig;
|
|
554
|
+
authToken?: string;
|
|
368
555
|
queryClient?: QueryClient;
|
|
369
556
|
}
|
|
370
557
|
/**
|
|
371
558
|
* Combined provider for multiple API clients
|
|
372
559
|
* Includes QueryClientProvider for React Query hooks
|
|
373
560
|
*/
|
|
374
|
-
declare function ApiClientProvider({ children, jrniBaseUrl, jrniConfig, queryClient, }: ApiClientProviderProps): react_jsx_runtime.JSX.Element;
|
|
561
|
+
declare function ApiClientProvider({ children, bookingLabBaseUrl, jrniBaseUrl, jrniConfig, authToken, queryClient, }: ApiClientProviderProps): react_jsx_runtime.JSX.Element;
|
|
375
562
|
/**
|
|
376
563
|
* Hook to access API client context
|
|
377
564
|
*/
|
|
378
565
|
declare function useApiClientContext(): ApiClientContextValue;
|
|
379
566
|
|
|
567
|
+
interface BookingLabProviderProps {
|
|
568
|
+
children: ReactNode;
|
|
569
|
+
baseUrl: string;
|
|
570
|
+
authToken?: string;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Provider component for BookingLab client
|
|
574
|
+
*/
|
|
575
|
+
declare function BookingLabProvider({ children, baseUrl, authToken, }: BookingLabProviderProps): react_jsx_runtime.JSX.Element;
|
|
576
|
+
/**
|
|
577
|
+
* Hook to access BookingLab client from context
|
|
578
|
+
*/
|
|
579
|
+
declare function useBookingLabContext(): BookingLabClient;
|
|
580
|
+
|
|
380
581
|
interface JrniProviderProps {
|
|
381
582
|
children: ReactNode;
|
|
382
583
|
baseUrl: string;
|
|
@@ -394,6 +595,10 @@ declare function useJrniContext(): JrniClient;
|
|
|
394
595
|
/**
|
|
395
596
|
* Hook to access API clients from context
|
|
396
597
|
*/
|
|
598
|
+
/**
|
|
599
|
+
* Hook to get BookingLab client from either ApiClientProvider or BookingLabProvider
|
|
600
|
+
*/
|
|
601
|
+
declare function useBookingLabClient(): BookingLabClient;
|
|
397
602
|
/**
|
|
398
603
|
* Hook to get JRNI client from either ApiClientProvider or JrniProvider
|
|
399
604
|
*/
|
|
@@ -403,5 +608,50 @@ declare function useJrniClient(): JrniClient;
|
|
|
403
608
|
* Hook for JRNI login
|
|
404
609
|
*/
|
|
405
610
|
declare function useLogin(): _tanstack_react_query.UseMutationResult<LoginResponse, Error, LoginRequest, unknown>;
|
|
611
|
+
/**
|
|
612
|
+
* Hook for fetching child companies
|
|
613
|
+
* @param companyId - The parent company ID
|
|
614
|
+
* @param params - Optional query parameters
|
|
615
|
+
* @param enabled - Whether the query should run
|
|
616
|
+
*/
|
|
617
|
+
declare function useChildCompanies(companyId: number, params?: GetChildCompaniesParams, enabled?: boolean): _tanstack_react_query.UseQueryResult<ChildCompaniesResponse, Error>;
|
|
618
|
+
/**
|
|
619
|
+
* Hook for fetching resources
|
|
620
|
+
* @param companyId - The company ID
|
|
621
|
+
* @param enabled - Whether the query should run
|
|
622
|
+
*/
|
|
623
|
+
declare function useResources(companyId: number, enabled?: boolean): _tanstack_react_query.UseQueryResult<ResourcesResponse, Error>;
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Hook to fetch bookings
|
|
627
|
+
*/
|
|
628
|
+
declare function useBookings(userId?: string): _tanstack_react_query.UseQueryResult<Booking[], Error>;
|
|
629
|
+
/**
|
|
630
|
+
* Hook to fetch a single booking
|
|
631
|
+
*/
|
|
632
|
+
declare function useBooking(bookingId: string): _tanstack_react_query.UseQueryResult<Booking, Error>;
|
|
633
|
+
/**
|
|
634
|
+
* Hook to create a booking
|
|
635
|
+
*/
|
|
636
|
+
declare function useCreateBooking(): _tanstack_react_query.UseMutationResult<Booking, Error, CreateBookingRequest, unknown>;
|
|
637
|
+
/**
|
|
638
|
+
* Hook to update a booking
|
|
639
|
+
*/
|
|
640
|
+
declare function useUpdateBooking(): _tanstack_react_query.UseMutationResult<Booking, Error, {
|
|
641
|
+
id: string;
|
|
642
|
+
updates: Partial<Booking>;
|
|
643
|
+
}, unknown>;
|
|
644
|
+
/**
|
|
645
|
+
* Hook to cancel a booking
|
|
646
|
+
*/
|
|
647
|
+
declare function useCancelBooking(): _tanstack_react_query.UseMutationResult<Booking, Error, string, unknown>;
|
|
648
|
+
/**
|
|
649
|
+
* Hook to fetch services
|
|
650
|
+
*/
|
|
651
|
+
declare function useServices(): _tanstack_react_query.UseQueryResult<Service[], Error>;
|
|
652
|
+
/**
|
|
653
|
+
* Hook to fetch a single service
|
|
654
|
+
*/
|
|
655
|
+
declare function useService(serviceId: string): _tanstack_react_query.UseQueryResult<Service, Error>;
|
|
406
656
|
|
|
407
|
-
export { type AddBasketItemRequest, ApiClient, type ApiClientConfig, ApiClientProvider, type ApiError, type ApiResponse, type AvailabilityTime, type AvailabilityTimesResponse, type JrniBooking, JrniClient, type JrniConfig, JrniProvider, type JrniService, type Location, type LocationsResponse, type LoginRequest, type LoginResponse, type MemberBookingsResponse, type PersonImage, type PersonImagesResponse, type Question, type QuestionOption, type QuestionsResponse, type RequestOptions, type ServicesResponse, type UpdateClientDetailsData, type UpdateMemberDetailsData, type Vehicle, type VehiclesResponse, createJrniClient, useApiClientContext, useJrniClient, useJrniContext, useLogin };
|
|
657
|
+
export { type AddBasketItemRequest, ApiClient, type ApiClientConfig, ApiClientProvider, type ApiError, type ApiResponse, type AvailabilityTime, type AvailabilityTimesResponse, type Booking, BookingLabClient, BookingLabProvider, type ChildCompaniesResponse, type ChildCompany, type ChildCompanyAddress, type ChildCompanySettings, type CreateBookingRequest, type GetChildCompaniesParams, type JrniBooking, JrniClient, type JrniConfig, JrniProvider, type JrniService, type Location, type LocationsResponse, type LoginRequest, type LoginResponse, type MemberBookingsResponse, type PersonImage, type PersonImagesResponse, type Question, type QuestionOption, type QuestionsResponse, type RequestOptions, type Resource, type ResourceLinks, type ResourcesResponse, type Service, type ServicesResponse, type UpdateClientDetailsData, type UpdateMemberDetailsData, type Vehicle, type VehiclesResponse, createBookingLabClient, createJrniClient, useApiClientContext, useBooking, useBookingLabClient, useBookingLabContext, useBookings, useCancelBooking, useChildCompanies, useCreateBooking, useJrniClient, useJrniContext, useLogin, useResources, useService, useServices, useUpdateBooking };
|
package/dist/index.js
CHANGED
|
@@ -144,6 +144,67 @@ var ApiClient = class {
|
|
|
144
144
|
}
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
+
// src/booking-lab.ts
|
|
148
|
+
var BookingLabClient = class extends ApiClient {
|
|
149
|
+
/**
|
|
150
|
+
* Get all bookings
|
|
151
|
+
*/
|
|
152
|
+
async getBookings(userId) {
|
|
153
|
+
return this.get("/bookings", {
|
|
154
|
+
params: userId ? { userId } : void 0
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get a single booking by ID
|
|
159
|
+
*/
|
|
160
|
+
async getBooking(bookingId) {
|
|
161
|
+
return this.get(`/bookings/${bookingId}`);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Create a new booking
|
|
165
|
+
*/
|
|
166
|
+
async createBooking(booking) {
|
|
167
|
+
return this.post("/bookings", booking);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Update an existing booking
|
|
171
|
+
*/
|
|
172
|
+
async updateBooking(bookingId, updates) {
|
|
173
|
+
return this.put(`/bookings/${bookingId}`, updates);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Cancel a booking
|
|
177
|
+
*/
|
|
178
|
+
async cancelBooking(bookingId) {
|
|
179
|
+
return this.put(`/bookings/${bookingId}`, { status: "cancelled" });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Delete a booking
|
|
183
|
+
*/
|
|
184
|
+
async deleteBooking(bookingId) {
|
|
185
|
+
return this.delete(`/bookings/${bookingId}`);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Get all services
|
|
189
|
+
*/
|
|
190
|
+
async getServices() {
|
|
191
|
+
return this.get("/services");
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get a single service by ID
|
|
195
|
+
*/
|
|
196
|
+
async getService(serviceId) {
|
|
197
|
+
return this.get(`/services/${serviceId}`);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function createBookingLabClient(baseUrl, authToken) {
|
|
201
|
+
const client = new BookingLabClient({ baseUrl });
|
|
202
|
+
if (authToken) {
|
|
203
|
+
client.setAuthToken(authToken);
|
|
204
|
+
}
|
|
205
|
+
return client;
|
|
206
|
+
}
|
|
207
|
+
|
|
147
208
|
// src/jrni.ts
|
|
148
209
|
var JrniClient = class extends ApiClient {
|
|
149
210
|
constructor(baseUrl, config) {
|
|
@@ -151,18 +212,58 @@ var JrniClient = class extends ApiClient {
|
|
|
151
212
|
this.appId = config.appId;
|
|
152
213
|
this.appKey = config.appKey;
|
|
153
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Get default headers for JRNI API requests
|
|
217
|
+
*/
|
|
218
|
+
getDefaultHeaders() {
|
|
219
|
+
return {
|
|
220
|
+
"Content-Type": "application/json",
|
|
221
|
+
"App-Id": this.appId
|
|
222
|
+
};
|
|
223
|
+
}
|
|
154
224
|
/**
|
|
155
225
|
* Login to JRNI
|
|
156
226
|
*/
|
|
157
227
|
async login(credentials) {
|
|
158
228
|
return this.post("/login", credentials, {
|
|
159
229
|
headers: {
|
|
160
|
-
|
|
161
|
-
"App-Id": this.appId,
|
|
230
|
+
...this.getDefaultHeaders(),
|
|
162
231
|
"App-Key": this.appKey
|
|
163
232
|
}
|
|
164
233
|
});
|
|
165
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Get child companies for a parent company
|
|
237
|
+
* @param companyId - The parent company ID
|
|
238
|
+
* @param params - Optional query parameters (person_id, Person_Id)
|
|
239
|
+
*/
|
|
240
|
+
async getChildCompanies(companyId, params) {
|
|
241
|
+
return this.get(
|
|
242
|
+
`/api/v5/company/${companyId}/children`,
|
|
243
|
+
{
|
|
244
|
+
headers: {
|
|
245
|
+
...this.getDefaultHeaders(),
|
|
246
|
+
"App-Key": this.appKey
|
|
247
|
+
},
|
|
248
|
+
params
|
|
249
|
+
}
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get resources for a company
|
|
254
|
+
* @param companyId - The company ID
|
|
255
|
+
*/
|
|
256
|
+
async getResources(companyId) {
|
|
257
|
+
return this.get(
|
|
258
|
+
`/api/v5/${companyId}/resources`,
|
|
259
|
+
{
|
|
260
|
+
headers: {
|
|
261
|
+
...this.getDefaultHeaders(),
|
|
262
|
+
"App-Key": this.appKey
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
166
267
|
/**
|
|
167
268
|
* Update JRNI configuration
|
|
168
269
|
*/
|
|
@@ -185,11 +286,21 @@ var defaultQueryClient = new reactQuery.QueryClient({
|
|
|
185
286
|
});
|
|
186
287
|
function ApiClientProvider({
|
|
187
288
|
children,
|
|
289
|
+
bookingLabBaseUrl,
|
|
188
290
|
jrniBaseUrl,
|
|
189
291
|
jrniConfig,
|
|
292
|
+
authToken,
|
|
190
293
|
queryClient
|
|
191
294
|
}) {
|
|
192
295
|
const client = queryClient || defaultQueryClient;
|
|
296
|
+
const bookingLabClient = react.useMemo(() => {
|
|
297
|
+
if (!bookingLabBaseUrl) return null;
|
|
298
|
+
const clientInstance = new BookingLabClient({ baseUrl: bookingLabBaseUrl });
|
|
299
|
+
if (authToken) {
|
|
300
|
+
clientInstance.setAuthToken(authToken);
|
|
301
|
+
}
|
|
302
|
+
return clientInstance;
|
|
303
|
+
}, [bookingLabBaseUrl, authToken]);
|
|
193
304
|
const jrniClient = react.useMemo(() => {
|
|
194
305
|
if (jrniBaseUrl && jrniConfig) {
|
|
195
306
|
return new JrniClient(jrniBaseUrl, jrniConfig);
|
|
@@ -198,9 +309,10 @@ function ApiClientProvider({
|
|
|
198
309
|
}, [jrniBaseUrl, jrniConfig?.appId, jrniConfig?.appKey]);
|
|
199
310
|
const value = react.useMemo(
|
|
200
311
|
() => ({
|
|
312
|
+
bookingLabClient,
|
|
201
313
|
jrniClient
|
|
202
314
|
}),
|
|
203
|
-
[jrniClient]
|
|
315
|
+
[bookingLabClient, jrniClient]
|
|
204
316
|
);
|
|
205
317
|
return /* @__PURE__ */ jsxRuntime.jsx(reactQuery.QueryClientProvider, { client, children: /* @__PURE__ */ jsxRuntime.jsx(ApiClientContext.Provider, { value, children }) });
|
|
206
318
|
}
|
|
@@ -211,6 +323,29 @@ function useApiClientContext() {
|
|
|
211
323
|
}
|
|
212
324
|
return context;
|
|
213
325
|
}
|
|
326
|
+
var BookingLabContext = react.createContext(void 0);
|
|
327
|
+
function BookingLabProvider({
|
|
328
|
+
children,
|
|
329
|
+
baseUrl,
|
|
330
|
+
authToken
|
|
331
|
+
}) {
|
|
332
|
+
const client = react.useMemo(() => {
|
|
333
|
+
const clientInstance = new BookingLabClient({ baseUrl });
|
|
334
|
+
if (authToken) {
|
|
335
|
+
clientInstance.setAuthToken(authToken);
|
|
336
|
+
}
|
|
337
|
+
return clientInstance;
|
|
338
|
+
}, [baseUrl, authToken]);
|
|
339
|
+
const value = react.useMemo(() => ({ client }), [client]);
|
|
340
|
+
return /* @__PURE__ */ jsxRuntime.jsx(BookingLabContext.Provider, { value, children });
|
|
341
|
+
}
|
|
342
|
+
function useBookingLabContext() {
|
|
343
|
+
const context = react.useContext(BookingLabContext);
|
|
344
|
+
if (context === void 0) {
|
|
345
|
+
throw new Error("useBookingLabContext must be used within a BookingLabProvider");
|
|
346
|
+
}
|
|
347
|
+
return context.client;
|
|
348
|
+
}
|
|
214
349
|
var JrniContext = react.createContext(void 0);
|
|
215
350
|
function JrniProvider({ children, baseUrl, config }) {
|
|
216
351
|
const client = react.useMemo(() => {
|
|
@@ -228,6 +363,19 @@ function useJrniContext() {
|
|
|
228
363
|
}
|
|
229
364
|
|
|
230
365
|
// src/hooks/useApiClient.ts
|
|
366
|
+
function useBookingLabClient() {
|
|
367
|
+
try {
|
|
368
|
+
return useBookingLabContext();
|
|
369
|
+
} catch {
|
|
370
|
+
const context = useApiClientContext();
|
|
371
|
+
if (!context.bookingLabClient) {
|
|
372
|
+
throw new Error(
|
|
373
|
+
"BookingLab client not configured. Wrap your app with ApiClientProvider or BookingLabProvider."
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return context.bookingLabClient;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
231
379
|
function useJrniClient() {
|
|
232
380
|
try {
|
|
233
381
|
return useJrniContext();
|
|
@@ -250,15 +398,133 @@ function useLogin() {
|
|
|
250
398
|
}
|
|
251
399
|
});
|
|
252
400
|
}
|
|
401
|
+
function useChildCompanies(companyId, params, enabled = true) {
|
|
402
|
+
const client = useJrniClient();
|
|
403
|
+
return reactQuery.useQuery({
|
|
404
|
+
queryKey: ["childCompanies", companyId, params],
|
|
405
|
+
queryFn: async () => {
|
|
406
|
+
const response = await client.getChildCompanies(companyId, params);
|
|
407
|
+
return response.data;
|
|
408
|
+
},
|
|
409
|
+
enabled: enabled && !!companyId
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
function useResources(companyId, enabled = true) {
|
|
413
|
+
const client = useJrniClient();
|
|
414
|
+
return reactQuery.useQuery({
|
|
415
|
+
queryKey: ["resources", companyId],
|
|
416
|
+
queryFn: async () => {
|
|
417
|
+
const response = await client.getResources(companyId);
|
|
418
|
+
return response.data;
|
|
419
|
+
},
|
|
420
|
+
enabled: enabled && !!companyId
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
function useBookings(userId) {
|
|
424
|
+
const client = useBookingLabClient();
|
|
425
|
+
return reactQuery.useQuery({
|
|
426
|
+
queryKey: ["bookings", userId],
|
|
427
|
+
queryFn: async () => {
|
|
428
|
+
const response = await client.getBookings(userId);
|
|
429
|
+
return response.data;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function useBooking(bookingId) {
|
|
434
|
+
const client = useBookingLabClient();
|
|
435
|
+
return reactQuery.useQuery({
|
|
436
|
+
queryKey: ["booking", bookingId],
|
|
437
|
+
queryFn: async () => {
|
|
438
|
+
const response = await client.getBooking(bookingId);
|
|
439
|
+
return response.data;
|
|
440
|
+
},
|
|
441
|
+
enabled: !!bookingId
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
function useCreateBooking() {
|
|
445
|
+
const client = useBookingLabClient();
|
|
446
|
+
const queryClient = reactQuery.useQueryClient();
|
|
447
|
+
return reactQuery.useMutation({
|
|
448
|
+
mutationFn: async (booking) => {
|
|
449
|
+
const response = await client.createBooking(booking);
|
|
450
|
+
return response.data;
|
|
451
|
+
},
|
|
452
|
+
onSuccess: () => {
|
|
453
|
+
queryClient.invalidateQueries({ queryKey: ["bookings"] });
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function useUpdateBooking() {
|
|
458
|
+
const client = useBookingLabClient();
|
|
459
|
+
const queryClient = reactQuery.useQueryClient();
|
|
460
|
+
return reactQuery.useMutation({
|
|
461
|
+
mutationFn: async ({ id, updates }) => {
|
|
462
|
+
const response = await client.updateBooking(id, updates);
|
|
463
|
+
return response.data;
|
|
464
|
+
},
|
|
465
|
+
onSuccess: (_, variables) => {
|
|
466
|
+
queryClient.invalidateQueries({ queryKey: ["bookings"] });
|
|
467
|
+
queryClient.invalidateQueries({ queryKey: ["booking", variables.id] });
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
function useCancelBooking() {
|
|
472
|
+
const client = useBookingLabClient();
|
|
473
|
+
const queryClient = reactQuery.useQueryClient();
|
|
474
|
+
return reactQuery.useMutation({
|
|
475
|
+
mutationFn: async (bookingId) => {
|
|
476
|
+
const response = await client.cancelBooking(bookingId);
|
|
477
|
+
return response.data;
|
|
478
|
+
},
|
|
479
|
+
onSuccess: () => {
|
|
480
|
+
queryClient.invalidateQueries({ queryKey: ["bookings"] });
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function useServices() {
|
|
485
|
+
const client = useBookingLabClient();
|
|
486
|
+
return reactQuery.useQuery({
|
|
487
|
+
queryKey: ["services"],
|
|
488
|
+
queryFn: async () => {
|
|
489
|
+
const response = await client.getServices();
|
|
490
|
+
return response.data;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function useService(serviceId) {
|
|
495
|
+
const client = useBookingLabClient();
|
|
496
|
+
return reactQuery.useQuery({
|
|
497
|
+
queryKey: ["service", serviceId],
|
|
498
|
+
queryFn: async () => {
|
|
499
|
+
const response = await client.getService(serviceId);
|
|
500
|
+
return response.data;
|
|
501
|
+
},
|
|
502
|
+
enabled: !!serviceId
|
|
503
|
+
});
|
|
504
|
+
}
|
|
253
505
|
|
|
254
506
|
exports.ApiClient = ApiClient;
|
|
255
507
|
exports.ApiClientProvider = ApiClientProvider;
|
|
508
|
+
exports.BookingLabClient = BookingLabClient;
|
|
509
|
+
exports.BookingLabProvider = BookingLabProvider;
|
|
256
510
|
exports.JrniClient = JrniClient;
|
|
257
511
|
exports.JrniProvider = JrniProvider;
|
|
512
|
+
exports.createBookingLabClient = createBookingLabClient;
|
|
258
513
|
exports.createJrniClient = createJrniClient;
|
|
259
514
|
exports.useApiClientContext = useApiClientContext;
|
|
515
|
+
exports.useBooking = useBooking;
|
|
516
|
+
exports.useBookingLabClient = useBookingLabClient;
|
|
517
|
+
exports.useBookingLabContext = useBookingLabContext;
|
|
518
|
+
exports.useBookings = useBookings;
|
|
519
|
+
exports.useCancelBooking = useCancelBooking;
|
|
520
|
+
exports.useChildCompanies = useChildCompanies;
|
|
521
|
+
exports.useCreateBooking = useCreateBooking;
|
|
260
522
|
exports.useJrniClient = useJrniClient;
|
|
261
523
|
exports.useJrniContext = useJrniContext;
|
|
262
524
|
exports.useLogin = useLogin;
|
|
525
|
+
exports.useResources = useResources;
|
|
526
|
+
exports.useService = useService;
|
|
527
|
+
exports.useServices = useServices;
|
|
528
|
+
exports.useUpdateBooking = useUpdateBooking;
|
|
263
529
|
//# sourceMappingURL=index.js.map
|
|
264
530
|
//# sourceMappingURL=index.js.map
|