@voyantjs/suppliers-react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +35 -0
  2. package/dist/client.d.ts +14 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +59 -0
  5. package/dist/constants.d.ts +69 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +34 -0
  8. package/dist/hooks/index.d.ts +10 -0
  9. package/dist/hooks/index.d.ts.map +1 -0
  10. package/dist/hooks/index.js +10 -0
  11. package/dist/hooks/use-supplier-mutation.d.ts +67 -0
  12. package/dist/hooks/use-supplier-mutation.d.ts.map +1 -0
  13. package/dist/hooks/use-supplier-mutation.js +41 -0
  14. package/dist/hooks/use-supplier-note-mutation.d.ts +13 -0
  15. package/dist/hooks/use-supplier-note-mutation.d.ts.map +1 -0
  16. package/dist/hooks/use-supplier-note-mutation.js +20 -0
  17. package/dist/hooks/use-supplier-notes.d.ts +13 -0
  18. package/dist/hooks/use-supplier-notes.d.ts.map +1 -0
  19. package/dist/hooks/use-supplier-notes.js +12 -0
  20. package/dist/hooks/use-supplier-rate-mutation.d.ts +56 -0
  21. package/dist/hooks/use-supplier-rate-mutation.d.ts.map +1 -0
  22. package/dist/hooks/use-supplier-rate-mutation.js +41 -0
  23. package/dist/hooks/use-supplier-service-mutation.d.ts +45 -0
  24. package/dist/hooks/use-supplier-service-mutation.d.ts.map +1 -0
  25. package/dist/hooks/use-supplier-service-mutation.js +44 -0
  26. package/dist/hooks/use-supplier-service-rates.d.ts +20 -0
  27. package/dist/hooks/use-supplier-service-rates.d.ts.map +1 -0
  28. package/dist/hooks/use-supplier-service-rates.js +12 -0
  29. package/dist/hooks/use-supplier-services.d.ts +19 -0
  30. package/dist/hooks/use-supplier-services.d.ts.map +1 -0
  31. package/dist/hooks/use-supplier-services.js +12 -0
  32. package/dist/hooks/use-supplier.d.ts +26 -0
  33. package/dist/hooks/use-supplier.d.ts.map +1 -0
  34. package/dist/hooks/use-supplier.js +9 -0
  35. package/dist/hooks/use-suppliers.d.ts +30 -0
  36. package/dist/hooks/use-suppliers.d.ts.map +1 -0
  37. package/dist/hooks/use-suppliers.js +9 -0
  38. package/dist/index.d.ts +9 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +8 -0
  41. package/dist/provider.d.ts +2 -0
  42. package/dist/provider.d.ts.map +1 -0
  43. package/dist/provider.js +1 -0
  44. package/dist/query-keys.d.ts +20 -0
  45. package/dist/query-keys.d.ts.map +1 -0
  46. package/dist/query-keys.js +12 -0
  47. package/dist/query-options.d.ts +371 -0
  48. package/dist/query-options.d.ts.map +1 -0
  49. package/dist/query-options.js +49 -0
  50. package/dist/schemas.d.ts +300 -0
  51. package/dist/schemas.d.ts.map +1 -0
  52. package/dist/schemas.js +95 -0
  53. package/dist/utils.d.ts +4 -0
  54. package/dist/utils.d.ts.map +1 -0
  55. package/dist/utils.js +10 -0
  56. package/package.json +79 -0
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @voyantjs/booking-requirements-react
2
+
3
+ React runtime package for Voyant booking requirements. Provides the shared provider, typed fetch client, query keys, constants, and TanStack Query hooks that power booking-requirements-focused frontend experiences.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @voyantjs/booking-requirements-react @voyantjs/booking-requirements @tanstack/react-query react react-dom zod
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import {
15
+ VoyantBookingRequirementsProvider,
16
+ useProducts,
17
+ } from "@voyantjs/booking-requirements-react"
18
+
19
+ function App() {
20
+ return (
21
+ <VoyantBookingRequirementsProvider baseUrl="/api">
22
+ <ProductsList />
23
+ </VoyantBookingRequirementsProvider>
24
+ )
25
+ }
26
+
27
+ function ProductsList() {
28
+ const { data } = useProducts({ limit: 50 })
29
+ return <>{data?.data.map((product) => <div key={product.id}>{product.name}</div>)}</>
30
+ }
31
+ ```
32
+
33
+ ## License
34
+
35
+ FSL-1.1-Apache-2.0
@@ -0,0 +1,14 @@
1
+ import type { z } from "zod";
2
+ export type VoyantFetcher = (url: string, init?: RequestInit) => Promise<Response>;
3
+ export declare const defaultFetcher: VoyantFetcher;
4
+ export declare class VoyantApiError extends Error {
5
+ readonly status: number;
6
+ readonly body: unknown;
7
+ constructor(message: string, status: number, body: unknown);
8
+ }
9
+ export interface FetchWithValidationOptions {
10
+ baseUrl: string;
11
+ fetcher: VoyantFetcher;
12
+ }
13
+ export declare function fetchWithValidation<TOut>(path: string, schema: z.ZodType<TOut>, options: FetchWithValidationOptions, init?: RequestInit): Promise<TOut>;
14
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;AAElF,eAAO,MAAM,cAAc,EAAE,aACoB,CAAA;AAEjD,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAM3D;AAcD,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;CACvB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAC5C,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EACvB,OAAO,EAAE,0BAA0B,EACnC,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAiCf"}
package/dist/client.js ADDED
@@ -0,0 +1,59 @@
1
+ export const defaultFetcher = (url, init) => fetch(url, { credentials: "include", ...init });
2
+ export class VoyantApiError extends Error {
3
+ status;
4
+ body;
5
+ constructor(message, status, body) {
6
+ super(message);
7
+ this.name = "VoyantApiError";
8
+ this.status = status;
9
+ this.body = body;
10
+ }
11
+ }
12
+ function extractErrorMessage(status, statusText, body) {
13
+ if (typeof body === "object" && body !== null && "error" in body) {
14
+ const err = body.error;
15
+ if (typeof err === "string")
16
+ return err;
17
+ if (typeof err === "object" && err !== null && "message" in err) {
18
+ return String(err.message);
19
+ }
20
+ }
21
+ return `Voyant API error: ${status} ${statusText}`;
22
+ }
23
+ export async function fetchWithValidation(path, schema, options, init) {
24
+ const url = joinUrl(options.baseUrl, path);
25
+ const headers = new Headers(init?.headers);
26
+ if (init?.body !== undefined && !headers.has("Content-Type")) {
27
+ headers.set("Content-Type", "application/json");
28
+ }
29
+ const response = await options.fetcher(url, { ...init, headers });
30
+ if (!response.ok) {
31
+ const body = await safeJson(response);
32
+ throw new VoyantApiError(extractErrorMessage(response.status, response.statusText, body), response.status, body);
33
+ }
34
+ if (response.status === 204) {
35
+ return schema.parse(undefined);
36
+ }
37
+ const body = await safeJson(response);
38
+ const parsed = schema.safeParse(body);
39
+ if (!parsed.success) {
40
+ throw new VoyantApiError(`Voyant API response failed validation: ${parsed.error.message}`, response.status, body);
41
+ }
42
+ return parsed.data;
43
+ }
44
+ async function safeJson(response) {
45
+ const text = await response.text();
46
+ if (!text)
47
+ return undefined;
48
+ try {
49
+ return JSON.parse(text);
50
+ }
51
+ catch {
52
+ return text;
53
+ }
54
+ }
55
+ function joinUrl(baseUrl, path) {
56
+ const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
57
+ const trimmedPath = path.startsWith("/") ? path : `/${path}`;
58
+ return `${trimmedBase}${trimmedPath}`;
59
+ }
@@ -0,0 +1,69 @@
1
+ export declare const SUPPLIER_TYPES: readonly [{
2
+ readonly value: "hotel";
3
+ readonly label: "Hotel";
4
+ }, {
5
+ readonly value: "transfer";
6
+ readonly label: "Transfer";
7
+ }, {
8
+ readonly value: "guide";
9
+ readonly label: "Guide";
10
+ }, {
11
+ readonly value: "experience";
12
+ readonly label: "Experience";
13
+ }, {
14
+ readonly value: "airline";
15
+ readonly label: "Airline";
16
+ }, {
17
+ readonly value: "restaurant";
18
+ readonly label: "Restaurant";
19
+ }, {
20
+ readonly value: "other";
21
+ readonly label: "Other";
22
+ }];
23
+ export declare const SUPPLIER_STATUSES: readonly [{
24
+ readonly value: "active";
25
+ readonly label: "Active";
26
+ }, {
27
+ readonly value: "inactive";
28
+ readonly label: "Inactive";
29
+ }, {
30
+ readonly value: "pending";
31
+ readonly label: "Pending";
32
+ }];
33
+ export declare const SERVICE_TYPES: readonly [{
34
+ readonly value: "accommodation";
35
+ readonly label: "Accommodation";
36
+ }, {
37
+ readonly value: "transfer";
38
+ readonly label: "Transfer";
39
+ }, {
40
+ readonly value: "experience";
41
+ readonly label: "Experience";
42
+ }, {
43
+ readonly value: "guide";
44
+ readonly label: "Guide";
45
+ }, {
46
+ readonly value: "meal";
47
+ readonly label: "Meal";
48
+ }, {
49
+ readonly value: "other";
50
+ readonly label: "Other";
51
+ }];
52
+ export declare const RATE_UNITS: readonly [{
53
+ readonly value: "per_person";
54
+ readonly label: "Per Person";
55
+ }, {
56
+ readonly value: "per_group";
57
+ readonly label: "Per Group";
58
+ }, {
59
+ readonly value: "per_night";
60
+ readonly label: "Per Night";
61
+ }, {
62
+ readonly value: "per_vehicle";
63
+ readonly label: "Per Vehicle";
64
+ }, {
65
+ readonly value: "flat";
66
+ readonly label: "Flat";
67
+ }];
68
+ export declare const statusVariant: Record<string, "default" | "secondary" | "outline" | "destructive">;
69
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;EAQjB,CAAA;AAEV,eAAO,MAAM,iBAAiB;;;;;;;;;EAIpB,CAAA;AAEV,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;EAOhB,CAAA;AAEV,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;EAMb,CAAA;AAEV,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,aAAa,CAI7F,CAAA"}
@@ -0,0 +1,34 @@
1
+ export const SUPPLIER_TYPES = [
2
+ { value: "hotel", label: "Hotel" },
3
+ { value: "transfer", label: "Transfer" },
4
+ { value: "guide", label: "Guide" },
5
+ { value: "experience", label: "Experience" },
6
+ { value: "airline", label: "Airline" },
7
+ { value: "restaurant", label: "Restaurant" },
8
+ { value: "other", label: "Other" },
9
+ ];
10
+ export const SUPPLIER_STATUSES = [
11
+ { value: "active", label: "Active" },
12
+ { value: "inactive", label: "Inactive" },
13
+ { value: "pending", label: "Pending" },
14
+ ];
15
+ export const SERVICE_TYPES = [
16
+ { value: "accommodation", label: "Accommodation" },
17
+ { value: "transfer", label: "Transfer" },
18
+ { value: "experience", label: "Experience" },
19
+ { value: "guide", label: "Guide" },
20
+ { value: "meal", label: "Meal" },
21
+ { value: "other", label: "Other" },
22
+ ];
23
+ export const RATE_UNITS = [
24
+ { value: "per_person", label: "Per Person" },
25
+ { value: "per_group", label: "Per Group" },
26
+ { value: "per_night", label: "Per Night" },
27
+ { value: "per_vehicle", label: "Per Vehicle" },
28
+ { value: "flat", label: "Flat" },
29
+ ];
30
+ export const statusVariant = {
31
+ active: "default",
32
+ inactive: "secondary",
33
+ pending: "outline",
34
+ };
@@ -0,0 +1,10 @@
1
+ export * from "./use-supplier.js";
2
+ export * from "./use-supplier-mutation.js";
3
+ export * from "./use-supplier-note-mutation.js";
4
+ export * from "./use-supplier-notes.js";
5
+ export * from "./use-supplier-rate-mutation.js";
6
+ export * from "./use-supplier-service-mutation.js";
7
+ export * from "./use-supplier-service-rates.js";
8
+ export * from "./use-supplier-services.js";
9
+ export * from "./use-suppliers.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAEA,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yBAAyB,CAAA;AACvC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,oCAAoC,CAAA;AAClD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ export * from "./use-supplier.js";
3
+ export * from "./use-supplier-mutation.js";
4
+ export * from "./use-supplier-note-mutation.js";
5
+ export * from "./use-supplier-notes.js";
6
+ export * from "./use-supplier-rate-mutation.js";
7
+ export * from "./use-supplier-service-mutation.js";
8
+ export * from "./use-supplier-service-rates.js";
9
+ export * from "./use-supplier-services.js";
10
+ export * from "./use-suppliers.js";
@@ -0,0 +1,67 @@
1
+ export interface CreateSupplierInput {
2
+ name: string;
3
+ type: "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant" | "other";
4
+ status?: "active" | "inactive" | "pending";
5
+ description?: string | null;
6
+ email?: string | null;
7
+ phone?: string | null;
8
+ website?: string | null;
9
+ address?: string | null;
10
+ city?: string | null;
11
+ country?: string | null;
12
+ defaultCurrency?: string | null;
13
+ contactName?: string | null;
14
+ contactEmail?: string | null;
15
+ contactPhone?: string | null;
16
+ tags?: string[];
17
+ }
18
+ export type UpdateSupplierInput = Partial<CreateSupplierInput>;
19
+ export declare function useSupplierMutation(): {
20
+ create: import("@tanstack/react-query").UseMutationResult<{
21
+ id: string;
22
+ name: string;
23
+ type: "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant" | "other";
24
+ status: "active" | "inactive" | "pending";
25
+ description: string | null;
26
+ email: string | null;
27
+ phone: string | null;
28
+ website: string | null;
29
+ address: string | null;
30
+ city: string | null;
31
+ country: string | null;
32
+ defaultCurrency: string | null;
33
+ contactName: string | null;
34
+ contactEmail: string | null;
35
+ contactPhone: string | null;
36
+ tags: string[];
37
+ createdAt: string;
38
+ updatedAt: string;
39
+ }, Error, CreateSupplierInput, unknown>;
40
+ update: import("@tanstack/react-query").UseMutationResult<{
41
+ id: string;
42
+ name: string;
43
+ type: "hotel" | "transfer" | "guide" | "experience" | "airline" | "restaurant" | "other";
44
+ status: "active" | "inactive" | "pending";
45
+ description: string | null;
46
+ email: string | null;
47
+ phone: string | null;
48
+ website: string | null;
49
+ address: string | null;
50
+ city: string | null;
51
+ country: string | null;
52
+ defaultCurrency: string | null;
53
+ contactName: string | null;
54
+ contactEmail: string | null;
55
+ contactPhone: string | null;
56
+ tags: string[];
57
+ createdAt: string;
58
+ updatedAt: string;
59
+ }, Error, {
60
+ id: string;
61
+ input: UpdateSupplierInput;
62
+ }, unknown>;
63
+ remove: import("@tanstack/react-query").UseMutationResult<{
64
+ success: boolean;
65
+ }, Error, string, unknown>;
66
+ };
67
+ //# sourceMappingURL=use-supplier-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-supplier-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-supplier-mutation.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,GAAG,YAAY,GAAG,OAAO,CAAA;IACxF,MAAM,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAA;IAC1C,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;AAE9D,wBAAgB,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBS,MAAM;eAAS,mBAAmB;;;;;EAiC7E"}
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantSuppliersContext } from "../provider.js";
5
+ import { suppliersQueryKeys } from "../query-keys.js";
6
+ import { deleteSuccessResponse, supplierDetailResponse } from "../schemas.js";
7
+ export function useSupplierMutation() {
8
+ const { baseUrl, fetcher } = useVoyantSuppliersContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation("/v1/suppliers", supplierDetailResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: (data) => {
16
+ void queryClient.invalidateQueries({ queryKey: suppliersQueryKeys.suppliers() });
17
+ queryClient.setQueryData(suppliersQueryKeys.supplierDetail(data.id), { data });
18
+ },
19
+ });
20
+ const update = useMutation({
21
+ mutationFn: async ({ id, input }) => {
22
+ const { data } = await fetchWithValidation(`/v1/suppliers/${id}`, supplierDetailResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
23
+ return data;
24
+ },
25
+ onSuccess: (data) => {
26
+ void queryClient.invalidateQueries({ queryKey: suppliersQueryKeys.suppliers() });
27
+ queryClient.setQueryData(suppliersQueryKeys.supplierDetail(data.id), { data });
28
+ },
29
+ });
30
+ const remove = useMutation({
31
+ mutationFn: async (id) => fetchWithValidation(`/v1/suppliers/${id}`, deleteSuccessResponse, { baseUrl, fetcher }, { method: "DELETE" }),
32
+ onSuccess: (_result, id) => {
33
+ void queryClient.invalidateQueries({ queryKey: suppliersQueryKeys.suppliers() });
34
+ queryClient.removeQueries({ queryKey: suppliersQueryKeys.supplierDetail(id) });
35
+ queryClient.removeQueries({ queryKey: suppliersQueryKeys.supplierServices(id) });
36
+ queryClient.removeQueries({ queryKey: suppliersQueryKeys.supplierNotes(id) });
37
+ void queryClient.invalidateQueries({ queryKey: suppliersQueryKeys.rates() });
38
+ },
39
+ });
40
+ return { create, update, remove };
41
+ }
@@ -0,0 +1,13 @@
1
+ export interface CreateSupplierNoteInput {
2
+ content: string;
3
+ }
4
+ export declare function useSupplierNoteMutation(supplierId: string): {
5
+ create: import("@tanstack/react-query").UseMutationResult<{
6
+ id: string;
7
+ supplierId: string;
8
+ authorId: string;
9
+ content: string;
10
+ createdAt: string;
11
+ }, Error, CreateSupplierNoteInput, unknown>;
12
+ };
13
+ //# sourceMappingURL=use-supplier-note-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-supplier-note-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-supplier-note-mutation.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM;;;;;;;;EAoBzD"}
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantSuppliersContext } from "../provider.js";
5
+ import { suppliersQueryKeys } from "../query-keys.js";
6
+ import { supplierNoteResponse } from "../schemas.js";
7
+ export function useSupplierNoteMutation(supplierId) {
8
+ const { baseUrl, fetcher } = useVoyantSuppliersContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation(`/v1/suppliers/${supplierId}/notes`, supplierNoteResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: () => {
16
+ void queryClient.invalidateQueries({ queryKey: suppliersQueryKeys.supplierNotes(supplierId) });
17
+ },
18
+ });
19
+ return { create };
20
+ }
@@ -0,0 +1,13 @@
1
+ export interface UseSupplierNotesOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useSupplierNotes(supplierId: string, options?: UseSupplierNotesOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ supplierId: string;
8
+ authorId: string;
9
+ content: string;
10
+ createdAt: string;
11
+ }[];
12
+ }, Error>;
13
+ //# sourceMappingURL=use-supplier-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-supplier-notes.d.ts","sourceRoot":"","sources":["../../src/hooks/use-supplier-notes.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B;;;;;;;;UAOzF"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantSuppliersContext } from "../provider.js";
4
+ import { getSupplierNotesQueryOptions } from "../query-options.js";
5
+ export function useSupplierNotes(supplierId, options = {}) {
6
+ const client = useVoyantSuppliersContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getSupplierNotesQueryOptions(client, supplierId),
10
+ enabled: enabled && !!supplierId,
11
+ });
12
+ }
@@ -0,0 +1,56 @@
1
+ export interface CreateSupplierRateInput {
2
+ name: string;
3
+ currency: string;
4
+ amountCents: number;
5
+ unit: "per_person" | "per_group" | "per_night" | "per_vehicle" | "flat";
6
+ validFrom?: string | null;
7
+ validTo?: string | null;
8
+ minPax?: number | null;
9
+ maxPax?: number | null;
10
+ notes?: string | null;
11
+ }
12
+ export type UpdateSupplierRateInput = Partial<CreateSupplierRateInput>;
13
+ export declare function useSupplierRateMutation(supplierId: string): {
14
+ create: import("@tanstack/react-query").UseMutationResult<{
15
+ id: string;
16
+ serviceId: string;
17
+ name: string;
18
+ currency: string;
19
+ amountCents: number;
20
+ unit: "per_person" | "per_group" | "per_night" | "per_vehicle" | "flat";
21
+ validFrom: string | null;
22
+ validTo: string | null;
23
+ minPax: number | null;
24
+ maxPax: number | null;
25
+ notes: string | null;
26
+ createdAt: string;
27
+ }, Error, {
28
+ serviceId: string;
29
+ input: CreateSupplierRateInput;
30
+ }, unknown>;
31
+ update: import("@tanstack/react-query").UseMutationResult<{
32
+ id: string;
33
+ serviceId: string;
34
+ name: string;
35
+ currency: string;
36
+ amountCents: number;
37
+ unit: "per_person" | "per_group" | "per_night" | "per_vehicle" | "flat";
38
+ validFrom: string | null;
39
+ validTo: string | null;
40
+ minPax: number | null;
41
+ maxPax: number | null;
42
+ notes: string | null;
43
+ createdAt: string;
44
+ }, Error, {
45
+ serviceId: string;
46
+ rateId: string;
47
+ input: UpdateSupplierRateInput;
48
+ }, unknown>;
49
+ remove: import("@tanstack/react-query").UseMutationResult<{
50
+ success: boolean;
51
+ }, Error, {
52
+ serviceId: string;
53
+ rateId: string;
54
+ }, unknown>;
55
+ };
56
+ //# sourceMappingURL=use-supplier-rate-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-supplier-rate-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-supplier-rate-mutation.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,CAAA;IACvE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AAEtE,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;mBASzC,MAAM;eACV,uBAAuB;;;;;;;;;;;;;;;;mBAuBnB,MAAM;gBACT,MAAM;eACP,uBAAuB;;;;;mBAkBuB,MAAM;gBAAU,MAAM;;EAehF"}
@@ -0,0 +1,41 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantSuppliersContext } from "../provider.js";
5
+ import { suppliersQueryKeys } from "../query-keys.js";
6
+ import { deleteSuccessResponse, supplierRateResponse } from "../schemas.js";
7
+ export function useSupplierRateMutation(supplierId) {
8
+ const { baseUrl, fetcher } = useVoyantSuppliersContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async ({ serviceId, input, }) => {
12
+ const { data } = await fetchWithValidation(`/v1/suppliers/${supplierId}/services/${serviceId}/rates`, supplierRateResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: (_data, { serviceId }) => {
16
+ void queryClient.invalidateQueries({
17
+ queryKey: suppliersQueryKeys.supplierServiceRates(supplierId, serviceId),
18
+ });
19
+ },
20
+ });
21
+ const update = useMutation({
22
+ mutationFn: async ({ serviceId, rateId, input, }) => {
23
+ const { data } = await fetchWithValidation(`/v1/suppliers/${supplierId}/services/${serviceId}/rates/${rateId}`, supplierRateResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
24
+ return data;
25
+ },
26
+ onSuccess: (_data, { serviceId }) => {
27
+ void queryClient.invalidateQueries({
28
+ queryKey: suppliersQueryKeys.supplierServiceRates(supplierId, serviceId),
29
+ });
30
+ },
31
+ });
32
+ const remove = useMutation({
33
+ mutationFn: async ({ serviceId, rateId }) => fetchWithValidation(`/v1/suppliers/${supplierId}/services/${serviceId}/rates/${rateId}`, deleteSuccessResponse, { baseUrl, fetcher }, { method: "DELETE" }),
34
+ onSuccess: (_data, { serviceId }) => {
35
+ void queryClient.invalidateQueries({
36
+ queryKey: suppliersQueryKeys.supplierServiceRates(supplierId, serviceId),
37
+ });
38
+ },
39
+ });
40
+ return { create, update, remove };
41
+ }
@@ -0,0 +1,45 @@
1
+ export interface CreateSupplierServiceInput {
2
+ serviceType: "accommodation" | "transfer" | "experience" | "guide" | "meal" | "other";
3
+ name: string;
4
+ description?: string | null;
5
+ duration?: string | null;
6
+ capacity?: number | null;
7
+ active?: boolean;
8
+ tags?: string[];
9
+ }
10
+ export type UpdateSupplierServiceInput = Partial<CreateSupplierServiceInput>;
11
+ export declare function useSupplierServiceMutation(supplierId: string): {
12
+ create: import("@tanstack/react-query").UseMutationResult<{
13
+ id: string;
14
+ supplierId: string;
15
+ serviceType: "transfer" | "guide" | "experience" | "other" | "accommodation" | "meal";
16
+ name: string;
17
+ description: string | null;
18
+ duration: string | null;
19
+ capacity: number | null;
20
+ active: boolean;
21
+ tags: string[];
22
+ createdAt: string;
23
+ updatedAt: string;
24
+ }, Error, CreateSupplierServiceInput, unknown>;
25
+ update: import("@tanstack/react-query").UseMutationResult<{
26
+ id: string;
27
+ supplierId: string;
28
+ serviceType: "transfer" | "guide" | "experience" | "other" | "accommodation" | "meal";
29
+ name: string;
30
+ description: string | null;
31
+ duration: string | null;
32
+ capacity: number | null;
33
+ active: boolean;
34
+ tags: string[];
35
+ createdAt: string;
36
+ updatedAt: string;
37
+ }, Error, {
38
+ serviceId: string;
39
+ input: UpdateSupplierServiceInput;
40
+ }, unknown>;
41
+ remove: import("@tanstack/react-query").UseMutationResult<{
42
+ success: boolean;
43
+ }, Error, string, unknown>;
44
+ };
45
+ //# sourceMappingURL=use-supplier-service-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-supplier-service-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-supplier-service-mutation.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,eAAe,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;IACrF,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAE5E,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA0B5C,MAAM;eACV,0BAA0B;;;;;EAoCtC"}
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantSuppliersContext } from "../provider.js";
5
+ import { suppliersQueryKeys } from "../query-keys.js";
6
+ import { deleteSuccessResponse, supplierServiceResponse } from "../schemas.js";
7
+ export function useSupplierServiceMutation(supplierId) {
8
+ const { baseUrl, fetcher } = useVoyantSuppliersContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation(`/v1/suppliers/${supplierId}/services`, supplierServiceResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: () => {
16
+ void queryClient.invalidateQueries({
17
+ queryKey: suppliersQueryKeys.supplierServices(supplierId),
18
+ });
19
+ },
20
+ });
21
+ const update = useMutation({
22
+ mutationFn: async ({ serviceId, input, }) => {
23
+ const { data } = await fetchWithValidation(`/v1/suppliers/${supplierId}/services/${serviceId}`, supplierServiceResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
24
+ return data;
25
+ },
26
+ onSuccess: () => {
27
+ void queryClient.invalidateQueries({
28
+ queryKey: suppliersQueryKeys.supplierServices(supplierId),
29
+ });
30
+ },
31
+ });
32
+ const remove = useMutation({
33
+ mutationFn: async (serviceId) => fetchWithValidation(`/v1/suppliers/${supplierId}/services/${serviceId}`, deleteSuccessResponse, { baseUrl, fetcher }, { method: "DELETE" }),
34
+ onSuccess: (_result, serviceId) => {
35
+ void queryClient.invalidateQueries({
36
+ queryKey: suppliersQueryKeys.supplierServices(supplierId),
37
+ });
38
+ queryClient.removeQueries({
39
+ queryKey: suppliersQueryKeys.supplierServiceRates(supplierId, serviceId),
40
+ });
41
+ },
42
+ });
43
+ return { create, update, remove };
44
+ }
@@ -0,0 +1,20 @@
1
+ export interface UseSupplierServiceRatesOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useSupplierServiceRates(supplierId: string, serviceId: string, options?: UseSupplierServiceRatesOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ serviceId: string;
8
+ name: string;
9
+ currency: string;
10
+ amountCents: number;
11
+ unit: "per_person" | "per_group" | "per_night" | "per_vehicle" | "flat";
12
+ validFrom: string | null;
13
+ validTo: string | null;
14
+ minPax: number | null;
15
+ maxPax: number | null;
16
+ notes: string | null;
17
+ createdAt: string;
18
+ }[];
19
+ }, Error>;
20
+ //# sourceMappingURL=use-supplier-service-rates.d.ts.map