@voyantjs/finance-react 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.
Files changed (61) hide show
  1. package/dist/client.d.ts +14 -0
  2. package/dist/client.d.ts.map +1 -0
  3. package/dist/client.js +59 -0
  4. package/dist/hooks/index.d.ts +14 -0
  5. package/dist/hooks/index.d.ts.map +1 -0
  6. package/dist/hooks/index.js +13 -0
  7. package/dist/hooks/use-invoice-credit-note-mutation.d.ts +38 -0
  8. package/dist/hooks/use-invoice-credit-note-mutation.d.ts.map +1 -0
  9. package/dist/hooks/use-invoice-credit-note-mutation.js +35 -0
  10. package/dist/hooks/use-invoice-credit-notes.d.ts +17 -0
  11. package/dist/hooks/use-invoice-credit-notes.d.ts.map +1 -0
  12. package/dist/hooks/use-invoice-credit-notes.js +12 -0
  13. package/dist/hooks/use-invoice-line-item-mutation.d.ts +40 -0
  14. package/dist/hooks/use-invoice-line-item-mutation.d.ts.map +1 -0
  15. package/dist/hooks/use-invoice-line-item-mutation.js +42 -0
  16. package/dist/hooks/use-invoice-line-items.d.ts +17 -0
  17. package/dist/hooks/use-invoice-line-items.d.ts.map +1 -0
  18. package/dist/hooks/use-invoice-line-items.js +12 -0
  19. package/dist/hooks/use-invoice-mutation.d.ts +65 -0
  20. package/dist/hooks/use-invoice-mutation.d.ts.map +1 -0
  21. package/dist/hooks/use-invoice-mutation.js +44 -0
  22. package/dist/hooks/use-invoice-note-mutation.d.ts +11 -0
  23. package/dist/hooks/use-invoice-note-mutation.d.ts.map +1 -0
  24. package/dist/hooks/use-invoice-note-mutation.js +23 -0
  25. package/dist/hooks/use-invoice-notes.d.ts +13 -0
  26. package/dist/hooks/use-invoice-notes.d.ts.map +1 -0
  27. package/dist/hooks/use-invoice-notes.js +12 -0
  28. package/dist/hooks/use-invoice-payment-mutation.d.ts +22 -0
  29. package/dist/hooks/use-invoice-payment-mutation.d.ts.map +1 -0
  30. package/dist/hooks/use-invoice-payment-mutation.js +24 -0
  31. package/dist/hooks/use-invoice-payments.d.ts +18 -0
  32. package/dist/hooks/use-invoice-payments.d.ts.map +1 -0
  33. package/dist/hooks/use-invoice-payments.js +12 -0
  34. package/dist/hooks/use-invoice.d.ts +25 -0
  35. package/dist/hooks/use-invoice.d.ts.map +1 -0
  36. package/dist/hooks/use-invoice.js +12 -0
  37. package/dist/hooks/use-invoices.d.ts +29 -0
  38. package/dist/hooks/use-invoices.d.ts.map +1 -0
  39. package/dist/hooks/use-invoices.js +12 -0
  40. package/dist/hooks/use-supplier-payment-mutation.d.ts +44 -0
  41. package/dist/hooks/use-supplier-payment-mutation.d.ts.map +1 -0
  42. package/dist/hooks/use-supplier-payment-mutation.js +33 -0
  43. package/dist/hooks/use-supplier-payments.d.ts +23 -0
  44. package/dist/hooks/use-supplier-payments.d.ts.map +1 -0
  45. package/dist/hooks/use-supplier-payments.js +12 -0
  46. package/dist/index.d.ts +7 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +6 -0
  49. package/dist/provider.d.ts +2 -0
  50. package/dist/provider.d.ts.map +1 -0
  51. package/dist/provider.js +1 -0
  52. package/dist/query-keys.d.ts +22 -0
  53. package/dist/query-keys.d.ts.map +1 -0
  54. package/dist/query-keys.js +12 -0
  55. package/dist/query-options.d.ts +485 -0
  56. package/dist/query-options.d.ts.map +1 -0
  57. package/dist/query-options.js +92 -0
  58. package/dist/schemas.d.ts +276 -0
  59. package/dist/schemas.d.ts.map +1 -0
  60. package/dist/schemas.js +100 -0
  61. package/package.json +79 -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;AAaD,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,CAgCf"}
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,14 @@
1
+ export * from "./use-invoice.js";
2
+ export * from "./use-invoice-credit-note-mutation.js";
3
+ export * from "./use-invoice-credit-notes.js";
4
+ export * from "./use-invoice-line-item-mutation.js";
5
+ export * from "./use-invoice-line-items.js";
6
+ export * from "./use-invoice-mutation.js";
7
+ export * from "./use-invoice-note-mutation.js";
8
+ export * from "./use-invoice-notes.js";
9
+ export * from "./use-invoice-payment-mutation.js";
10
+ export * from "./use-invoice-payments.js";
11
+ export * from "./use-invoices.js";
12
+ export * from "./use-supplier-payment-mutation.js";
13
+ export * from "./use-supplier-payments.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,uCAAuC,CAAA;AACrD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,qCAAqC,CAAA;AACnD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oCAAoC,CAAA;AAClD,cAAc,4BAA4B,CAAA"}
@@ -0,0 +1,13 @@
1
+ export * from "./use-invoice.js";
2
+ export * from "./use-invoice-credit-note-mutation.js";
3
+ export * from "./use-invoice-credit-notes.js";
4
+ export * from "./use-invoice-line-item-mutation.js";
5
+ export * from "./use-invoice-line-items.js";
6
+ export * from "./use-invoice-mutation.js";
7
+ export * from "./use-invoice-note-mutation.js";
8
+ export * from "./use-invoice-notes.js";
9
+ export * from "./use-invoice-payment-mutation.js";
10
+ export * from "./use-invoice-payments.js";
11
+ export * from "./use-invoices.js";
12
+ export * from "./use-supplier-payment-mutation.js";
13
+ export * from "./use-supplier-payments.js";
@@ -0,0 +1,38 @@
1
+ export interface CreateInvoiceCreditNoteInput {
2
+ creditNoteNumber: string;
3
+ amountCents: number;
4
+ currency: string;
5
+ reason: string;
6
+ notes?: string | null;
7
+ }
8
+ export type UpdateInvoiceCreditNoteInput = Partial<CreateInvoiceCreditNoteInput> & {
9
+ status?: "draft" | "issued" | "applied";
10
+ };
11
+ export declare function useInvoiceCreditNoteMutation(invoiceId: string): {
12
+ create: import("@tanstack/react-query").UseMutationResult<{
13
+ id: string;
14
+ creditNoteNumber: string;
15
+ invoiceId: string;
16
+ status: "draft" | "issued" | "applied";
17
+ amountCents: number;
18
+ currency: string;
19
+ reason: string;
20
+ notes: string | null;
21
+ createdAt: string;
22
+ }, Error, CreateInvoiceCreditNoteInput, unknown>;
23
+ update: import("@tanstack/react-query").UseMutationResult<{
24
+ id: string;
25
+ creditNoteNumber: string;
26
+ invoiceId: string;
27
+ status: "draft" | "issued" | "applied";
28
+ amountCents: number;
29
+ currency: string;
30
+ reason: string;
31
+ notes: string | null;
32
+ createdAt: string;
33
+ }, Error, {
34
+ id: string;
35
+ input: UpdateInvoiceCreditNoteInput;
36
+ }, unknown>;
37
+ };
38
+ //# sourceMappingURL=use-invoice-credit-note-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-credit-note-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-credit-note-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,4BAA4B;IAC3C,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,MAAM,MAAM,4BAA4B,GAAG,OAAO,CAAC,4BAA4B,CAAC,GAAG;IACjF,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;CACxC,CAAA;AAMD,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;YAqBlB,MAAM;eAAS,4BAA4B;;EAgBtF"}
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantFinanceContext } from "../provider.js";
6
+ import { financeQueryKeys } from "../query-keys.js";
7
+ import { creditNoteRecordSchema } from "../schemas.js";
8
+ const invoiceCreditNoteSingleResponse = z.object({
9
+ data: creditNoteRecordSchema,
10
+ });
11
+ export function useInvoiceCreditNoteMutation(invoiceId) {
12
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
13
+ const queryClient = useQueryClient();
14
+ const create = useMutation({
15
+ mutationFn: async (input) => {
16
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/credit-notes`, invoiceCreditNoteSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
17
+ return data;
18
+ },
19
+ onSuccess: () => {
20
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.creditNotes(invoiceId) });
21
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
22
+ },
23
+ });
24
+ const update = useMutation({
25
+ mutationFn: async ({ id, input }) => {
26
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/credit-notes/${id}`, invoiceCreditNoteSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
27
+ return data;
28
+ },
29
+ onSuccess: () => {
30
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.creditNotes(invoiceId) });
31
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
32
+ },
33
+ });
34
+ return { create, update };
35
+ }
@@ -0,0 +1,17 @@
1
+ export interface UseInvoiceCreditNotesOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useInvoiceCreditNotes(invoiceId: string | null | undefined, options?: UseInvoiceCreditNotesOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ creditNoteNumber: string;
8
+ invoiceId: string;
9
+ status: "draft" | "issued" | "applied";
10
+ amountCents: number;
11
+ currency: string;
12
+ reason: string;
13
+ notes: string | null;
14
+ createdAt: string;
15
+ }[];
16
+ }, Error>;
17
+ //# sourceMappingURL=use-invoice-credit-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-credit-notes.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-credit-notes.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,4BAAiC;;;;;;;;;;;;UAS3C"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFinanceContext } from "../provider.js";
4
+ import { getInvoiceCreditNotesQueryOptions } from "../query-options.js";
5
+ export function useInvoiceCreditNotes(invoiceId, options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getInvoiceCreditNotesQueryOptions({ baseUrl, fetcher }, invoiceId),
10
+ enabled: enabled && Boolean(invoiceId),
11
+ });
12
+ }
@@ -0,0 +1,40 @@
1
+ export interface CreateInvoiceLineItemInput {
2
+ description: string;
3
+ quantity: number;
4
+ unitPriceCents: number;
5
+ totalCents: number;
6
+ taxRate?: number | null;
7
+ sortOrder?: number;
8
+ }
9
+ export type UpdateInvoiceLineItemInput = Partial<CreateInvoiceLineItemInput>;
10
+ export declare function useInvoiceLineItemMutation(invoiceId: string): {
11
+ create: import("@tanstack/react-query").UseMutationResult<{
12
+ id: string;
13
+ invoiceId: string;
14
+ description: string;
15
+ quantity: number;
16
+ unitPriceCents: number;
17
+ totalCents: number;
18
+ taxRate: number | null;
19
+ sortOrder: number;
20
+ createdAt: string;
21
+ }, Error, CreateInvoiceLineItemInput, unknown>;
22
+ update: import("@tanstack/react-query").UseMutationResult<{
23
+ id: string;
24
+ invoiceId: string;
25
+ description: string;
26
+ quantity: number;
27
+ unitPriceCents: number;
28
+ totalCents: number;
29
+ taxRate: number | null;
30
+ sortOrder: number;
31
+ createdAt: string;
32
+ }, Error, {
33
+ id: string;
34
+ input: UpdateInvoiceLineItemInput;
35
+ }, unknown>;
36
+ remove: import("@tanstack/react-query").UseMutationResult<{
37
+ success: boolean;
38
+ }, Error, string, unknown>;
39
+ };
40
+ //# sourceMappingURL=use-invoice-line-item-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-line-item-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-line-item-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,0BAA0B;IACzC,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAA;AAM5E,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;YAqBhB,MAAM;eAAS,0BAA0B;;;;;EA8BpF"}
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantFinanceContext } from "../provider.js";
6
+ import { financeQueryKeys } from "../query-keys.js";
7
+ import { lineItemRecordSchema, successEnvelope } from "../schemas.js";
8
+ const invoiceLineItemSingleResponse = z.object({
9
+ data: lineItemRecordSchema,
10
+ });
11
+ export function useInvoiceLineItemMutation(invoiceId) {
12
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
13
+ const queryClient = useQueryClient();
14
+ const create = useMutation({
15
+ mutationFn: async (input) => {
16
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/line-items`, invoiceLineItemSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
17
+ return data;
18
+ },
19
+ onSuccess: () => {
20
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.lineItems(invoiceId) });
21
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
22
+ },
23
+ });
24
+ const update = useMutation({
25
+ mutationFn: async ({ id, input }) => {
26
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/line-items/${id}`, invoiceLineItemSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
27
+ return data;
28
+ },
29
+ onSuccess: () => {
30
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.lineItems(invoiceId) });
31
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
32
+ },
33
+ });
34
+ const remove = useMutation({
35
+ mutationFn: async (lineItemId) => fetchWithValidation(`/v1/finance/invoices/${invoiceId}/line-items/${lineItemId}`, successEnvelope, { baseUrl, fetcher }, { method: "DELETE" }),
36
+ onSuccess: () => {
37
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.lineItems(invoiceId) });
38
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
39
+ },
40
+ });
41
+ return { create, update, remove };
42
+ }
@@ -0,0 +1,17 @@
1
+ export interface UseInvoiceLineItemsOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useInvoiceLineItems(invoiceId: string | null | undefined, options?: UseInvoiceLineItemsOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ invoiceId: string;
8
+ description: string;
9
+ quantity: number;
10
+ unitPriceCents: number;
11
+ totalCents: number;
12
+ taxRate: number | null;
13
+ sortOrder: number;
14
+ createdAt: string;
15
+ }[];
16
+ }, Error>;
17
+ //# sourceMappingURL=use-invoice-line-items.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-line-items.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-line-items.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,0BAA+B;;;;;;;;;;;;UASzC"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFinanceContext } from "../provider.js";
4
+ import { getInvoiceLineItemsQueryOptions } from "../query-options.js";
5
+ export function useInvoiceLineItems(invoiceId, options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getInvoiceLineItemsQueryOptions({ baseUrl, fetcher }, invoiceId),
10
+ enabled: enabled && Boolean(invoiceId),
11
+ });
12
+ }
@@ -0,0 +1,65 @@
1
+ import { type InvoiceRecord } from "../schemas.js";
2
+ export interface CreateInvoiceInput {
3
+ invoiceNumber: string;
4
+ bookingId: string;
5
+ personId?: string | null;
6
+ organizationId?: string | null;
7
+ status?: InvoiceRecord["status"];
8
+ currency: string;
9
+ subtotalCents?: number;
10
+ taxCents?: number;
11
+ totalCents?: number;
12
+ paidCents?: number;
13
+ balanceDueCents?: number;
14
+ issueDate: string;
15
+ dueDate: string;
16
+ notes?: string | null;
17
+ }
18
+ export type UpdateInvoiceInput = Partial<CreateInvoiceInput>;
19
+ export declare function useInvoiceMutation(): {
20
+ create: import("@tanstack/react-query").UseMutationResult<{
21
+ id: string;
22
+ invoiceNumber: string;
23
+ bookingId: string;
24
+ personId: string | null;
25
+ organizationId: string | null;
26
+ status: "draft" | "void" | "sent" | "partially_paid" | "paid" | "overdue";
27
+ currency: string;
28
+ subtotalCents: number;
29
+ taxCents: number;
30
+ totalCents: number;
31
+ paidCents: number;
32
+ balanceDueCents: number;
33
+ issueDate: string;
34
+ dueDate: string;
35
+ notes: string | null;
36
+ createdAt: string;
37
+ updatedAt: string;
38
+ }, Error, CreateInvoiceInput, unknown>;
39
+ update: import("@tanstack/react-query").UseMutationResult<{
40
+ id: string;
41
+ invoiceNumber: string;
42
+ bookingId: string;
43
+ personId: string | null;
44
+ organizationId: string | null;
45
+ status: "draft" | "void" | "sent" | "partially_paid" | "paid" | "overdue";
46
+ currency: string;
47
+ subtotalCents: number;
48
+ taxCents: number;
49
+ totalCents: number;
50
+ paidCents: number;
51
+ balanceDueCents: number;
52
+ issueDate: string;
53
+ dueDate: string;
54
+ notes: string | null;
55
+ createdAt: string;
56
+ updatedAt: string;
57
+ }, Error, {
58
+ id: string;
59
+ input: UpdateInvoiceInput;
60
+ }, unknown>;
61
+ remove: import("@tanstack/react-query").UseMutationResult<{
62
+ success: boolean;
63
+ }, Error, string, unknown>;
64
+ };
65
+ //# sourceMappingURL=use-invoice-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-mutation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,aAAa,EAA0C,MAAM,eAAe,CAAA;AAE1F,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,MAAM,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAE5D,wBAAgB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBU,MAAM;eAAS,kBAAkB;;;;;EAoC5E"}
@@ -0,0 +1,44 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantFinanceContext } from "../provider.js";
5
+ import { financeQueryKeys } from "../query-keys.js";
6
+ import { invoiceSingleResponse, successEnvelope } from "../schemas.js";
7
+ export function useInvoiceMutation() {
8
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation("/v1/finance/invoices", invoiceSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: (data) => {
16
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoices() });
17
+ queryClient.setQueryData(financeQueryKeys.invoice(data.id), { data });
18
+ },
19
+ });
20
+ const update = useMutation({
21
+ mutationFn: async ({ id, input }) => {
22
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${id}`, invoiceSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
23
+ return data;
24
+ },
25
+ onSuccess: (data) => {
26
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoices() });
27
+ queryClient.setQueryData(financeQueryKeys.invoice(data.id), { data });
28
+ },
29
+ });
30
+ const remove = useMutation({
31
+ mutationFn: async (id) => fetchWithValidation(`/v1/finance/invoices/${id}`, successEnvelope, { baseUrl, fetcher }, {
32
+ method: "DELETE",
33
+ }),
34
+ onSuccess: (_data, id) => {
35
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoices() });
36
+ queryClient.removeQueries({ queryKey: financeQueryKeys.invoice(id) });
37
+ queryClient.removeQueries({ queryKey: financeQueryKeys.lineItems(id) });
38
+ queryClient.removeQueries({ queryKey: financeQueryKeys.payments(id) });
39
+ queryClient.removeQueries({ queryKey: financeQueryKeys.creditNotes(id) });
40
+ queryClient.removeQueries({ queryKey: financeQueryKeys.notes(id) });
41
+ },
42
+ });
43
+ return { create, update, remove };
44
+ }
@@ -0,0 +1,11 @@
1
+ export interface CreateInvoiceNoteInput {
2
+ content: string;
3
+ }
4
+ export declare function useInvoiceNoteMutation(invoiceId: string): import("@tanstack/react-query").UseMutationResult<{
5
+ id: string;
6
+ invoiceId: string;
7
+ authorId: string;
8
+ content: string;
9
+ createdAt: string;
10
+ }, Error, CreateInvoiceNoteInput, unknown>;
11
+ //# sourceMappingURL=use-invoice-note-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-note-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-note-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAA;CAChB;AAMD,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM;;;;;;2CAkBvD"}
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantFinanceContext } from "../provider.js";
6
+ import { financeQueryKeys } from "../query-keys.js";
7
+ import { financeNoteRecordSchema } from "../schemas.js";
8
+ const invoiceNoteSingleResponse = z.object({
9
+ data: financeNoteRecordSchema,
10
+ });
11
+ export function useInvoiceNoteMutation(invoiceId) {
12
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
13
+ const queryClient = useQueryClient();
14
+ return useMutation({
15
+ mutationFn: async (input) => {
16
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/notes`, invoiceNoteSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
17
+ return data;
18
+ },
19
+ onSuccess: () => {
20
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.notes(invoiceId) });
21
+ },
22
+ });
23
+ }
@@ -0,0 +1,13 @@
1
+ export interface UseInvoiceNotesOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useInvoiceNotes(invoiceId: string | null | undefined, options?: UseInvoiceNotesOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ invoiceId: string;
8
+ authorId: string;
9
+ content: string;
10
+ createdAt: string;
11
+ }[];
12
+ }, Error>;
13
+ //# sourceMappingURL=use-invoice-notes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-notes.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-notes.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,sBAA2B;;;;;;;;UASrC"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFinanceContext } from "../provider.js";
4
+ import { getInvoiceNotesQueryOptions } from "../query-options.js";
5
+ export function useInvoiceNotes(invoiceId, options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getInvoiceNotesQueryOptions({ baseUrl, fetcher }, invoiceId),
10
+ enabled: enabled && Boolean(invoiceId),
11
+ });
12
+ }
@@ -0,0 +1,22 @@
1
+ export interface CreateInvoicePaymentInput {
2
+ amountCents: number;
3
+ currency: string;
4
+ paymentMethod: "bank_transfer" | "credit_card" | "cash" | "cheque" | "other";
5
+ status: "pending" | "completed" | "failed" | "refunded";
6
+ referenceNumber?: string | null;
7
+ paymentDate: string;
8
+ notes?: string | null;
9
+ }
10
+ export declare function useInvoicePaymentMutation(invoiceId: string): import("@tanstack/react-query").UseMutationResult<{
11
+ id: string;
12
+ invoiceId: string;
13
+ amountCents: number;
14
+ currency: string;
15
+ paymentMethod: string;
16
+ status: "pending" | "completed" | "failed" | "refunded";
17
+ referenceNumber: string | null;
18
+ paymentDate: string;
19
+ notes: string | null;
20
+ createdAt: string;
21
+ }, Error, CreateInvoicePaymentInput, unknown>;
22
+ //# sourceMappingURL=use-invoice-payment-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-payment-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-payment-mutation.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,eAAe,GAAG,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;IAC5E,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAA;IACvD,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;AAMD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;8CAmB1D"}
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { z } from "zod";
4
+ import { fetchWithValidation } from "../client.js";
5
+ import { useVoyantFinanceContext } from "../provider.js";
6
+ import { financeQueryKeys } from "../query-keys.js";
7
+ import { paymentRecordSchema } from "../schemas.js";
8
+ const invoicePaymentSingleResponse = z.object({
9
+ data: paymentRecordSchema,
10
+ });
11
+ export function useInvoicePaymentMutation(invoiceId) {
12
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
13
+ const queryClient = useQueryClient();
14
+ return useMutation({
15
+ mutationFn: async (input) => {
16
+ const { data } = await fetchWithValidation(`/v1/finance/invoices/${invoiceId}/payments`, invoicePaymentSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
17
+ return data;
18
+ },
19
+ onSuccess: () => {
20
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.payments(invoiceId) });
21
+ void queryClient.invalidateQueries({ queryKey: financeQueryKeys.invoice(invoiceId) });
22
+ },
23
+ });
24
+ }
@@ -0,0 +1,18 @@
1
+ export interface UseInvoicePaymentsOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useInvoicePayments(invoiceId: string | null | undefined, options?: UseInvoicePaymentsOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ data: {
6
+ id: string;
7
+ invoiceId: string;
8
+ amountCents: number;
9
+ currency: string;
10
+ paymentMethod: string;
11
+ status: "pending" | "completed" | "failed" | "refunded";
12
+ referenceNumber: string | null;
13
+ paymentDate: string;
14
+ notes: string | null;
15
+ createdAt: string;
16
+ }[];
17
+ }, Error>;
18
+ //# sourceMappingURL=use-invoice-payments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-invoice-payments.d.ts","sourceRoot":"","sources":["../../src/hooks/use-invoice-payments.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,yBAA8B;;;;;;;;;;;;;UASxC"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantFinanceContext } from "../provider.js";
4
+ import { getInvoicePaymentsQueryOptions } from "../query-options.js";
5
+ export function useInvoicePayments(invoiceId, options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantFinanceContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getInvoicePaymentsQueryOptions({ baseUrl, fetcher }, invoiceId),
10
+ enabled: enabled && Boolean(invoiceId),
11
+ });
12
+ }