@voyantjs/transactions-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.
- package/dist/client.d.ts +14 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +58 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +4 -0
- package/dist/hooks/use-offer-mutation.d.ts +96 -0
- package/dist/hooks/use-offer-mutation.d.ts.map +1 -0
- package/dist/hooks/use-offer-mutation.js +40 -0
- package/dist/hooks/use-offers.d.ts +39 -0
- package/dist/hooks/use-offers.d.ts.map +1 -0
- package/dist/hooks/use-offers.js +12 -0
- package/dist/hooks/use-order-mutation.d.ts +96 -0
- package/dist/hooks/use-order-mutation.d.ts.map +1 -0
- package/dist/hooks/use-order-mutation.js +40 -0
- package/dist/hooks/use-orders.d.ts +39 -0
- package/dist/hooks/use-orders.d.ts.map +1 -0
- package/dist/hooks/use-orders.js +12 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/provider.d.ts +2 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +1 -0
- package/dist/query-keys.d.ts +33 -0
- package/dist/query-keys.d.ts.map +1 -0
- package/dist/query-keys.js +9 -0
- package/dist/query-options.d.ts +524 -0
- package/dist/query-options.d.ts.map +1 -0
- package/dist/query-options.js +47 -0
- package/dist/schemas.d.ts +249 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +64 -0
- package/package.json +79 -0
package/dist/client.d.ts
ADDED
|
@@ -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,CA8Bf"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
const body = await safeJson(response);
|
|
37
|
+
const parsed = schema.safeParse(body);
|
|
38
|
+
if (!parsed.success) {
|
|
39
|
+
throw new VoyantApiError(`Voyant API response failed validation: ${parsed.error.message}`, response.status, body);
|
|
40
|
+
}
|
|
41
|
+
return parsed.data;
|
|
42
|
+
}
|
|
43
|
+
async function safeJson(response) {
|
|
44
|
+
const text = await response.text();
|
|
45
|
+
if (!text)
|
|
46
|
+
return undefined;
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(text);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return text;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function joinUrl(baseUrl, path) {
|
|
55
|
+
const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
56
|
+
const trimmedPath = path.startsWith("/") ? path : `/${path}`;
|
|
57
|
+
return `${trimmedBase}${trimmedPath}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,yBAAyB,CAAA;AACvC,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { insertOfferSchema, updateOfferSchema } from "@voyantjs/transactions";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
export type CreateOfferInput = z.input<typeof insertOfferSchema>;
|
|
4
|
+
export type UpdateOfferInput = z.input<typeof updateOfferSchema>;
|
|
5
|
+
export declare function useOfferMutation(): {
|
|
6
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
7
|
+
offerNumber: string;
|
|
8
|
+
title: string;
|
|
9
|
+
status: "draft" | "published" | "sent" | "accepted" | "expired" | "withdrawn" | "converted";
|
|
10
|
+
currency: string;
|
|
11
|
+
id: string;
|
|
12
|
+
personId: string | null;
|
|
13
|
+
organizationId: string | null;
|
|
14
|
+
opportunityId: string | null;
|
|
15
|
+
quoteId: string | null;
|
|
16
|
+
marketId: string | null;
|
|
17
|
+
sourceChannelId: string | null;
|
|
18
|
+
baseCurrency: string | null;
|
|
19
|
+
fxRateSetId: string | null;
|
|
20
|
+
subtotalAmountCents: number;
|
|
21
|
+
taxAmountCents: number;
|
|
22
|
+
feeAmountCents: number;
|
|
23
|
+
totalAmountCents: number;
|
|
24
|
+
costAmountCents: number;
|
|
25
|
+
validFrom: string | null;
|
|
26
|
+
validUntil: string | null;
|
|
27
|
+
sentAt: string | null;
|
|
28
|
+
acceptedAt: string | null;
|
|
29
|
+
convertedAt: string | null;
|
|
30
|
+
notes: string | null;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
34
|
+
}, Error, {
|
|
35
|
+
offerNumber: string;
|
|
36
|
+
title: string;
|
|
37
|
+
currency: string;
|
|
38
|
+
status?: "draft" | "published" | "sent" | "accepted" | "expired" | "withdrawn" | "converted" | undefined;
|
|
39
|
+
personId?: string | null | undefined;
|
|
40
|
+
organizationId?: string | null | undefined;
|
|
41
|
+
opportunityId?: string | null | undefined;
|
|
42
|
+
quoteId?: string | null | undefined;
|
|
43
|
+
marketId?: string | null | undefined;
|
|
44
|
+
sourceChannelId?: string | null | undefined;
|
|
45
|
+
baseCurrency?: string | null | undefined;
|
|
46
|
+
fxRateSetId?: string | null | undefined;
|
|
47
|
+
subtotalAmountCents?: number | undefined;
|
|
48
|
+
taxAmountCents?: number | undefined;
|
|
49
|
+
feeAmountCents?: number | undefined;
|
|
50
|
+
totalAmountCents?: number | undefined;
|
|
51
|
+
costAmountCents?: number | undefined;
|
|
52
|
+
validFrom?: string | null | undefined;
|
|
53
|
+
validUntil?: string | null | undefined;
|
|
54
|
+
sentAt?: string | null | undefined;
|
|
55
|
+
acceptedAt?: string | null | undefined;
|
|
56
|
+
convertedAt?: string | null | undefined;
|
|
57
|
+
notes?: string | null | undefined;
|
|
58
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
59
|
+
}, unknown>;
|
|
60
|
+
update: import("@tanstack/react-query").UseMutationResult<{
|
|
61
|
+
offerNumber: string;
|
|
62
|
+
title: string;
|
|
63
|
+
status: "draft" | "published" | "sent" | "accepted" | "expired" | "withdrawn" | "converted";
|
|
64
|
+
currency: string;
|
|
65
|
+
id: string;
|
|
66
|
+
personId: string | null;
|
|
67
|
+
organizationId: string | null;
|
|
68
|
+
opportunityId: string | null;
|
|
69
|
+
quoteId: string | null;
|
|
70
|
+
marketId: string | null;
|
|
71
|
+
sourceChannelId: string | null;
|
|
72
|
+
baseCurrency: string | null;
|
|
73
|
+
fxRateSetId: string | null;
|
|
74
|
+
subtotalAmountCents: number;
|
|
75
|
+
taxAmountCents: number;
|
|
76
|
+
feeAmountCents: number;
|
|
77
|
+
totalAmountCents: number;
|
|
78
|
+
costAmountCents: number;
|
|
79
|
+
validFrom: string | null;
|
|
80
|
+
validUntil: string | null;
|
|
81
|
+
sentAt: string | null;
|
|
82
|
+
acceptedAt: string | null;
|
|
83
|
+
convertedAt: string | null;
|
|
84
|
+
notes: string | null;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
88
|
+
}, Error, {
|
|
89
|
+
id: string;
|
|
90
|
+
input: UpdateOfferInput;
|
|
91
|
+
}, unknown>;
|
|
92
|
+
remove: import("@tanstack/react-query").UseMutationResult<{
|
|
93
|
+
success: boolean;
|
|
94
|
+
}, Error, string, unknown>;
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=use-offer-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-offer-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-offer-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAO5B,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAChE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEhE,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBY,MAAM;eAAS,gBAAgB;;;;;EAgC1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { fetchWithValidation } from "../client.js";
|
|
4
|
+
import { useVoyantTransactionsContext } from "../provider.js";
|
|
5
|
+
import { transactionsQueryKeys } from "../query-keys.js";
|
|
6
|
+
import { offerSingleResponse, successEnvelope } from "../schemas.js";
|
|
7
|
+
export function useOfferMutation() {
|
|
8
|
+
const { baseUrl, fetcher } = useVoyantTransactionsContext();
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const create = useMutation({
|
|
11
|
+
mutationFn: async (input) => {
|
|
12
|
+
const { data } = await fetchWithValidation("/v1/transactions/offers", offerSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
13
|
+
return data;
|
|
14
|
+
},
|
|
15
|
+
onSuccess: (data) => {
|
|
16
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.offers() });
|
|
17
|
+
queryClient.setQueryData(transactionsQueryKeys.offer(data.id), data);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const update = useMutation({
|
|
21
|
+
mutationFn: async ({ id, input }) => {
|
|
22
|
+
const { data } = await fetchWithValidation(`/v1/transactions/offers/${id}`, offerSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
|
|
23
|
+
return data;
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data) => {
|
|
26
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.offers() });
|
|
27
|
+
queryClient.setQueryData(transactionsQueryKeys.offer(data.id), data);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const remove = useMutation({
|
|
31
|
+
mutationFn: async (id) => fetchWithValidation(`/v1/transactions/offers/${id}`, successEnvelope, { baseUrl, fetcher }, {
|
|
32
|
+
method: "DELETE",
|
|
33
|
+
}),
|
|
34
|
+
onSuccess: (_data, id) => {
|
|
35
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.offers() });
|
|
36
|
+
queryClient.removeQueries({ queryKey: transactionsQueryKeys.offer(id) });
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return { create, update, remove };
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OffersListFilters } from "../query-keys.js";
|
|
2
|
+
export interface UseOffersOptions extends OffersListFilters {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function useOffers(options?: UseOffersOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
6
|
+
data: {
|
|
7
|
+
offerNumber: string;
|
|
8
|
+
title: string;
|
|
9
|
+
status: "draft" | "published" | "sent" | "accepted" | "expired" | "withdrawn" | "converted";
|
|
10
|
+
currency: string;
|
|
11
|
+
id: string;
|
|
12
|
+
personId: string | null;
|
|
13
|
+
organizationId: string | null;
|
|
14
|
+
opportunityId: string | null;
|
|
15
|
+
quoteId: string | null;
|
|
16
|
+
marketId: string | null;
|
|
17
|
+
sourceChannelId: string | null;
|
|
18
|
+
baseCurrency: string | null;
|
|
19
|
+
fxRateSetId: string | null;
|
|
20
|
+
subtotalAmountCents: number;
|
|
21
|
+
taxAmountCents: number;
|
|
22
|
+
feeAmountCents: number;
|
|
23
|
+
totalAmountCents: number;
|
|
24
|
+
costAmountCents: number;
|
|
25
|
+
validFrom: string | null;
|
|
26
|
+
validUntil: string | null;
|
|
27
|
+
sentAt: string | null;
|
|
28
|
+
acceptedAt: string | null;
|
|
29
|
+
convertedAt: string | null;
|
|
30
|
+
notes: string | null;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
34
|
+
}[];
|
|
35
|
+
total: number;
|
|
36
|
+
limit: number;
|
|
37
|
+
offset: number;
|
|
38
|
+
}, Error>;
|
|
39
|
+
//# sourceMappingURL=use-offers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-offers.d.ts","sourceRoot":"","sources":["../../src/hooks/use-offers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGzD,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAQvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantTransactionsContext } from "../provider.js";
|
|
4
|
+
import { getOffersQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useOffers(options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantTransactionsContext();
|
|
7
|
+
const { enabled = true, ...filters } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getOffersQueryOptions({ baseUrl, fetcher }, filters),
|
|
10
|
+
enabled,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { insertOrderSchema, updateOrderSchema } from "@voyantjs/transactions";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
export type CreateOrderInput = z.input<typeof insertOrderSchema>;
|
|
4
|
+
export type UpdateOrderInput = z.input<typeof updateOrderSchema>;
|
|
5
|
+
export declare function useOrderMutation(): {
|
|
6
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
7
|
+
orderNumber: string;
|
|
8
|
+
title: string;
|
|
9
|
+
status: "draft" | "expired" | "pending" | "confirmed" | "fulfilled" | "cancelled";
|
|
10
|
+
currency: string;
|
|
11
|
+
id: string;
|
|
12
|
+
offerId: string | null;
|
|
13
|
+
personId: string | null;
|
|
14
|
+
organizationId: string | null;
|
|
15
|
+
opportunityId: string | null;
|
|
16
|
+
quoteId: string | null;
|
|
17
|
+
marketId: string | null;
|
|
18
|
+
sourceChannelId: string | null;
|
|
19
|
+
baseCurrency: string | null;
|
|
20
|
+
fxRateSetId: string | null;
|
|
21
|
+
subtotalAmountCents: number;
|
|
22
|
+
taxAmountCents: number;
|
|
23
|
+
feeAmountCents: number;
|
|
24
|
+
totalAmountCents: number;
|
|
25
|
+
costAmountCents: number;
|
|
26
|
+
orderedAt: string | null;
|
|
27
|
+
confirmedAt: string | null;
|
|
28
|
+
cancelledAt: string | null;
|
|
29
|
+
expiresAt: string | null;
|
|
30
|
+
notes: string | null;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
34
|
+
}, Error, {
|
|
35
|
+
orderNumber: string;
|
|
36
|
+
title: string;
|
|
37
|
+
currency: string;
|
|
38
|
+
offerId?: string | null | undefined;
|
|
39
|
+
status?: "draft" | "expired" | "pending" | "confirmed" | "fulfilled" | "cancelled" | undefined;
|
|
40
|
+
personId?: string | null | undefined;
|
|
41
|
+
organizationId?: string | null | undefined;
|
|
42
|
+
opportunityId?: string | null | undefined;
|
|
43
|
+
quoteId?: string | null | undefined;
|
|
44
|
+
marketId?: string | null | undefined;
|
|
45
|
+
sourceChannelId?: string | null | undefined;
|
|
46
|
+
baseCurrency?: string | null | undefined;
|
|
47
|
+
fxRateSetId?: string | null | undefined;
|
|
48
|
+
subtotalAmountCents?: number | undefined;
|
|
49
|
+
taxAmountCents?: number | undefined;
|
|
50
|
+
feeAmountCents?: number | undefined;
|
|
51
|
+
totalAmountCents?: number | undefined;
|
|
52
|
+
costAmountCents?: number | undefined;
|
|
53
|
+
orderedAt?: string | null | undefined;
|
|
54
|
+
confirmedAt?: string | null | undefined;
|
|
55
|
+
cancelledAt?: string | null | undefined;
|
|
56
|
+
expiresAt?: string | null | undefined;
|
|
57
|
+
notes?: string | null | undefined;
|
|
58
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
59
|
+
}, unknown>;
|
|
60
|
+
update: import("@tanstack/react-query").UseMutationResult<{
|
|
61
|
+
orderNumber: string;
|
|
62
|
+
title: string;
|
|
63
|
+
status: "draft" | "expired" | "pending" | "confirmed" | "fulfilled" | "cancelled";
|
|
64
|
+
currency: string;
|
|
65
|
+
id: string;
|
|
66
|
+
offerId: string | null;
|
|
67
|
+
personId: string | null;
|
|
68
|
+
organizationId: string | null;
|
|
69
|
+
opportunityId: string | null;
|
|
70
|
+
quoteId: string | null;
|
|
71
|
+
marketId: string | null;
|
|
72
|
+
sourceChannelId: string | null;
|
|
73
|
+
baseCurrency: string | null;
|
|
74
|
+
fxRateSetId: string | null;
|
|
75
|
+
subtotalAmountCents: number;
|
|
76
|
+
taxAmountCents: number;
|
|
77
|
+
feeAmountCents: number;
|
|
78
|
+
totalAmountCents: number;
|
|
79
|
+
costAmountCents: number;
|
|
80
|
+
orderedAt: string | null;
|
|
81
|
+
confirmedAt: string | null;
|
|
82
|
+
cancelledAt: string | null;
|
|
83
|
+
expiresAt: string | null;
|
|
84
|
+
notes: string | null;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
88
|
+
}, Error, {
|
|
89
|
+
id: string;
|
|
90
|
+
input: UpdateOrderInput;
|
|
91
|
+
}, unknown>;
|
|
92
|
+
remove: import("@tanstack/react-query").UseMutationResult<{
|
|
93
|
+
success: boolean;
|
|
94
|
+
}, Error, string, unknown>;
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=use-order-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-order-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-order-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAO5B,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAChE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAEhE,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBY,MAAM;eAAS,gBAAgB;;;;;EAgC1E"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { fetchWithValidation } from "../client.js";
|
|
4
|
+
import { useVoyantTransactionsContext } from "../provider.js";
|
|
5
|
+
import { transactionsQueryKeys } from "../query-keys.js";
|
|
6
|
+
import { orderSingleResponse, successEnvelope } from "../schemas.js";
|
|
7
|
+
export function useOrderMutation() {
|
|
8
|
+
const { baseUrl, fetcher } = useVoyantTransactionsContext();
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const create = useMutation({
|
|
11
|
+
mutationFn: async (input) => {
|
|
12
|
+
const { data } = await fetchWithValidation("/v1/transactions/orders", orderSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
13
|
+
return data;
|
|
14
|
+
},
|
|
15
|
+
onSuccess: (data) => {
|
|
16
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.orders() });
|
|
17
|
+
queryClient.setQueryData(transactionsQueryKeys.order(data.id), data);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const update = useMutation({
|
|
21
|
+
mutationFn: async ({ id, input }) => {
|
|
22
|
+
const { data } = await fetchWithValidation(`/v1/transactions/orders/${id}`, orderSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
|
|
23
|
+
return data;
|
|
24
|
+
},
|
|
25
|
+
onSuccess: (data) => {
|
|
26
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.orders() });
|
|
27
|
+
queryClient.setQueryData(transactionsQueryKeys.order(data.id), data);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const remove = useMutation({
|
|
31
|
+
mutationFn: async (id) => fetchWithValidation(`/v1/transactions/orders/${id}`, successEnvelope, { baseUrl, fetcher }, {
|
|
32
|
+
method: "DELETE",
|
|
33
|
+
}),
|
|
34
|
+
onSuccess: (_data, id) => {
|
|
35
|
+
void queryClient.invalidateQueries({ queryKey: transactionsQueryKeys.orders() });
|
|
36
|
+
queryClient.removeQueries({ queryKey: transactionsQueryKeys.order(id) });
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return { create, update, remove };
|
|
40
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { OrdersListFilters } from "../query-keys.js";
|
|
2
|
+
export interface UseOrdersOptions extends OrdersListFilters {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function useOrders(options?: UseOrdersOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
6
|
+
data: {
|
|
7
|
+
orderNumber: string;
|
|
8
|
+
title: string;
|
|
9
|
+
status: "draft" | "expired" | "pending" | "confirmed" | "fulfilled" | "cancelled";
|
|
10
|
+
currency: string;
|
|
11
|
+
id: string;
|
|
12
|
+
offerId: string | null;
|
|
13
|
+
personId: string | null;
|
|
14
|
+
organizationId: string | null;
|
|
15
|
+
opportunityId: string | null;
|
|
16
|
+
quoteId: string | null;
|
|
17
|
+
marketId: string | null;
|
|
18
|
+
sourceChannelId: string | null;
|
|
19
|
+
baseCurrency: string | null;
|
|
20
|
+
fxRateSetId: string | null;
|
|
21
|
+
subtotalAmountCents: number;
|
|
22
|
+
taxAmountCents: number;
|
|
23
|
+
feeAmountCents: number;
|
|
24
|
+
totalAmountCents: number;
|
|
25
|
+
costAmountCents: number;
|
|
26
|
+
orderedAt: string | null;
|
|
27
|
+
confirmedAt: string | null;
|
|
28
|
+
cancelledAt: string | null;
|
|
29
|
+
expiresAt: string | null;
|
|
30
|
+
notes: string | null;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
metadata?: Record<string, unknown> | null | undefined;
|
|
34
|
+
}[];
|
|
35
|
+
total: number;
|
|
36
|
+
limit: number;
|
|
37
|
+
offset: number;
|
|
38
|
+
}, Error>;
|
|
39
|
+
//# sourceMappingURL=use-orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-orders.d.ts","sourceRoot":"","sources":["../../src/hooks/use-orders.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGzD,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAQvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantTransactionsContext } from "../provider.js";
|
|
4
|
+
import { getOrdersQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useOrders(options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantTransactionsContext();
|
|
7
|
+
const { enabled = true, ...filters } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getOrdersQueryOptions({ baseUrl, fetcher }, filters),
|
|
10
|
+
enabled,
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { defaultFetcher, fetchWithValidation, VoyantApiError, type VoyantFetcher, } from "./client.js";
|
|
2
|
+
export * from "./hooks/index.js";
|
|
3
|
+
export { useVoyantTransactionsContext, type VoyantTransactionsContextValue, VoyantTransactionsProvider, type VoyantTransactionsProviderProps, } from "./provider.js";
|
|
4
|
+
export { type OffersListFilters, type OrdersListFilters, transactionsQueryKeys, } from "./query-keys.js";
|
|
5
|
+
export { getOfferQueryOptions, getOffersQueryOptions, getOrderQueryOptions, getOrdersQueryOptions, } from "./query-options.js";
|
|
6
|
+
export * from "./schemas.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA;AACpB,cAAc,kBAAkB,CAAA;AAChC,OAAO,EACL,4BAA4B,EAC5B,KAAK,8BAA8B,EACnC,0BAA0B,EAC1B,KAAK,+BAA+B,GACrC,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,oBAAoB,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { defaultFetcher, fetchWithValidation, VoyantApiError, } from "./client.js";
|
|
2
|
+
export * from "./hooks/index.js";
|
|
3
|
+
export { useVoyantTransactionsContext, VoyantTransactionsProvider, } from "./provider.js";
|
|
4
|
+
export { transactionsQueryKeys, } from "./query-keys.js";
|
|
5
|
+
export { getOfferQueryOptions, getOffersQueryOptions, getOrderQueryOptions, getOrdersQueryOptions, } from "./query-options.js";
|
|
6
|
+
export * from "./schemas.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { useVoyantReactContext as useVoyantTransactionsContext, type VoyantReactContextValue as VoyantTransactionsContextValue, VoyantReactProvider as VoyantTransactionsProvider, type VoyantReactProviderProps as VoyantTransactionsProviderProps, } from "@voyantjs/react";
|
|
2
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,IAAI,4BAA4B,EACrD,KAAK,uBAAuB,IAAI,8BAA8B,EAC9D,mBAAmB,IAAI,0BAA0B,EACjD,KAAK,wBAAwB,IAAI,+BAA+B,GACjE,MAAM,iBAAiB,CAAA"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useVoyantReactContext as useVoyantTransactionsContext, VoyantReactProvider as VoyantTransactionsProvider, } from "@voyantjs/react";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface OffersListFilters {
|
|
2
|
+
status?: string | undefined;
|
|
3
|
+
opportunityId?: string | undefined;
|
|
4
|
+
quoteId?: string | undefined;
|
|
5
|
+
personId?: string | undefined;
|
|
6
|
+
organizationId?: string | undefined;
|
|
7
|
+
marketId?: string | undefined;
|
|
8
|
+
search?: string | undefined;
|
|
9
|
+
limit?: number | undefined;
|
|
10
|
+
offset?: number | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface OrdersListFilters {
|
|
13
|
+
status?: string | undefined;
|
|
14
|
+
offerId?: string | undefined;
|
|
15
|
+
opportunityId?: string | undefined;
|
|
16
|
+
quoteId?: string | undefined;
|
|
17
|
+
personId?: string | undefined;
|
|
18
|
+
organizationId?: string | undefined;
|
|
19
|
+
marketId?: string | undefined;
|
|
20
|
+
search?: string | undefined;
|
|
21
|
+
limit?: number | undefined;
|
|
22
|
+
offset?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare const transactionsQueryKeys: {
|
|
25
|
+
all: readonly ["transactions"];
|
|
26
|
+
offers: () => readonly ["transactions", "offers"];
|
|
27
|
+
offersList: (filters: OffersListFilters) => readonly ["transactions", "offers", OffersListFilters];
|
|
28
|
+
offer: (id: string) => readonly ["transactions", "offers", string];
|
|
29
|
+
orders: () => readonly ["transactions", "orders"];
|
|
30
|
+
ordersList: (filters: OrdersListFilters) => readonly ["transactions", "orders", OrdersListFilters];
|
|
31
|
+
order: (id: string) => readonly ["transactions", "orders", string];
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=query-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../src/query-keys.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,eAAO,MAAM,qBAAqB;;;0BAGV,iBAAiB;gBAC3B,MAAM;;0BAEI,iBAAiB;gBAC3B,MAAM;CACnB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const transactionsQueryKeys = {
|
|
2
|
+
all: ["transactions"],
|
|
3
|
+
offers: () => [...transactionsQueryKeys.all, "offers"],
|
|
4
|
+
offersList: (filters) => [...transactionsQueryKeys.offers(), filters],
|
|
5
|
+
offer: (id) => [...transactionsQueryKeys.offers(), id],
|
|
6
|
+
orders: () => [...transactionsQueryKeys.all, "orders"],
|
|
7
|
+
ordersList: (filters) => [...transactionsQueryKeys.orders(), filters],
|
|
8
|
+
order: (id) => [...transactionsQueryKeys.orders(), id],
|
|
9
|
+
};
|