@voyantjs/sellability-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.
@@ -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,4 @@
1
+ export * from "./use-sellability-policies.js";
2
+ export * from "./use-sellability-policy.js";
3
+ export * from "./use-sellability-policy-mutation.js";
4
+ //# 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,+BAA+B,CAAA;AAC7C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sCAAsC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from "./use-sellability-policies.js";
2
+ export * from "./use-sellability-policy.js";
3
+ export * from "./use-sellability-policy-mutation.js";
@@ -0,0 +1,28 @@
1
+ import type { SellabilityPoliciesListFilters } from "../query-keys.js";
2
+ export interface UseSellabilityPoliciesOptions extends SellabilityPoliciesListFilters {
3
+ enabled?: boolean;
4
+ }
5
+ export declare function useSellabilityPolicies(options?: UseSellabilityPoliciesOptions): import("@tanstack/react-query").UseQueryResult<{
6
+ data: {
7
+ name: string;
8
+ priority: number;
9
+ active: boolean;
10
+ id: string;
11
+ scope: "global" | "product" | "option" | "market" | "channel";
12
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
13
+ productId: string | null;
14
+ optionId: string | null;
15
+ marketId: string | null;
16
+ channelId: string | null;
17
+ conditions: Record<string, unknown>;
18
+ effects: Record<string, unknown>;
19
+ createdAt: string;
20
+ updatedAt: string;
21
+ notes?: string | null | undefined;
22
+ metadata?: Record<string, unknown> | null | undefined;
23
+ }[];
24
+ total: number;
25
+ limit: number;
26
+ offset: number;
27
+ }, Error>;
28
+ //# sourceMappingURL=use-sellability-policies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sellability-policies.d.ts","sourceRoot":"","sources":["../../src/hooks/use-sellability-policies.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAA;AAGtE,MAAM,WAAW,6BAA8B,SAAQ,8BAA8B;IACnF,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,6BAAkC;;;;;;;;;;;;;;;;;;;;;;UAQjF"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantSellabilityContext } from "../provider.js";
4
+ import { getSellabilityPoliciesQueryOptions } from "../query-options.js";
5
+ export function useSellabilityPolicies(options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantSellabilityContext();
7
+ const { enabled = true, ...filters } = options;
8
+ return useQuery({
9
+ ...getSellabilityPoliciesQueryOptions({ baseUrl, fetcher }, filters),
10
+ enabled,
11
+ });
12
+ }
@@ -0,0 +1,63 @@
1
+ import type { insertSellabilityPolicySchema, updateSellabilityPolicySchema } from "@voyantjs/sellability/validation";
2
+ import type { z } from "zod";
3
+ export type CreateSellabilityPolicyInput = z.input<typeof insertSellabilityPolicySchema>;
4
+ export type UpdateSellabilityPolicyInput = z.input<typeof updateSellabilityPolicySchema>;
5
+ export declare function useSellabilityPolicyMutation(): {
6
+ create: import("@tanstack/react-query").UseMutationResult<{
7
+ name: string;
8
+ priority: number;
9
+ active: boolean;
10
+ id: string;
11
+ scope: "global" | "product" | "option" | "market" | "channel";
12
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
13
+ productId: string | null;
14
+ optionId: string | null;
15
+ marketId: string | null;
16
+ channelId: string | null;
17
+ conditions: Record<string, unknown>;
18
+ effects: Record<string, unknown>;
19
+ createdAt: string;
20
+ updatedAt: string;
21
+ notes?: string | null | undefined;
22
+ metadata?: Record<string, unknown> | null | undefined;
23
+ }, Error, {
24
+ name: string;
25
+ scope?: "global" | "product" | "option" | "market" | "channel" | undefined;
26
+ policyType?: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency" | undefined;
27
+ productId?: string | null | undefined;
28
+ optionId?: string | null | undefined;
29
+ marketId?: string | null | undefined;
30
+ channelId?: string | null | undefined;
31
+ priority?: number | undefined;
32
+ active?: boolean | undefined;
33
+ conditions?: Record<string, unknown> | undefined;
34
+ effects?: Record<string, unknown> | undefined;
35
+ notes?: string | null | undefined;
36
+ metadata?: Record<string, unknown> | null | undefined;
37
+ }, unknown>;
38
+ update: import("@tanstack/react-query").UseMutationResult<{
39
+ name: string;
40
+ priority: number;
41
+ active: boolean;
42
+ id: string;
43
+ scope: "global" | "product" | "option" | "market" | "channel";
44
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
45
+ productId: string | null;
46
+ optionId: string | null;
47
+ marketId: string | null;
48
+ channelId: string | null;
49
+ conditions: Record<string, unknown>;
50
+ effects: Record<string, unknown>;
51
+ createdAt: string;
52
+ updatedAt: string;
53
+ notes?: string | null | undefined;
54
+ metadata?: Record<string, unknown> | null | undefined;
55
+ }, Error, {
56
+ id: string;
57
+ input: UpdateSellabilityPolicyInput;
58
+ }, unknown>;
59
+ remove: import("@tanstack/react-query").UseMutationResult<{
60
+ success: boolean;
61
+ }, Error, string, unknown>;
62
+ };
63
+ //# sourceMappingURL=use-sellability-policy-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sellability-policy-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-sellability-policy-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,6BAA6B,EAC7B,6BAA6B,EAC9B,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAO5B,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AACxF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAExF,wBAAgB,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBA,MAAM;eAAS,4BAA4B;;;;;EAgCtF"}
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantSellabilityContext } from "../provider.js";
5
+ import { sellabilityQueryKeys } from "../query-keys.js";
6
+ import { sellabilityPolicySingleResponse, successEnvelope } from "../schemas.js";
7
+ export function useSellabilityPolicyMutation() {
8
+ const { baseUrl, fetcher } = useVoyantSellabilityContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation("/v1/sellability/policies", sellabilityPolicySingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: (data) => {
16
+ void queryClient.invalidateQueries({ queryKey: sellabilityQueryKeys.policies() });
17
+ queryClient.setQueryData(sellabilityQueryKeys.policy(data.id), data);
18
+ },
19
+ });
20
+ const update = useMutation({
21
+ mutationFn: async ({ id, input }) => {
22
+ const { data } = await fetchWithValidation(`/v1/sellability/policies/${id}`, sellabilityPolicySingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
23
+ return data;
24
+ },
25
+ onSuccess: (data) => {
26
+ void queryClient.invalidateQueries({ queryKey: sellabilityQueryKeys.policies() });
27
+ queryClient.setQueryData(sellabilityQueryKeys.policy(data.id), data);
28
+ },
29
+ });
30
+ const remove = useMutation({
31
+ mutationFn: async (id) => fetchWithValidation(`/v1/sellability/policies/${id}`, successEnvelope, { baseUrl, fetcher }, {
32
+ method: "DELETE",
33
+ }),
34
+ onSuccess: (_data, id) => {
35
+ void queryClient.invalidateQueries({ queryKey: sellabilityQueryKeys.policies() });
36
+ queryClient.removeQueries({ queryKey: sellabilityQueryKeys.policy(id) });
37
+ },
38
+ });
39
+ return { create, update, remove };
40
+ }
@@ -0,0 +1,22 @@
1
+ export interface UseSellabilityPolicyOptions {
2
+ enabled?: boolean;
3
+ }
4
+ export declare function useSellabilityPolicy(id: string | null | undefined, options?: UseSellabilityPolicyOptions): import("@tanstack/react-query").UseQueryResult<{
5
+ name: string;
6
+ priority: number;
7
+ active: boolean;
8
+ id: string;
9
+ scope: "global" | "product" | "option" | "market" | "channel";
10
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
11
+ productId: string | null;
12
+ optionId: string | null;
13
+ marketId: string | null;
14
+ channelId: string | null;
15
+ conditions: Record<string, unknown>;
16
+ effects: Record<string, unknown>;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ notes?: string | null | undefined;
20
+ metadata?: Record<string, unknown> | null | undefined;
21
+ }, Error>;
22
+ //# sourceMappingURL=use-sellability-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-sellability-policy.d.ts","sourceRoot":"","sources":["../../src/hooks/use-sellability-policy.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,oBAAoB,CAClC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7B,OAAO,GAAE,2BAAgC;;;;;;;;;;;;;;;;;UAS1C"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantSellabilityContext } from "../provider.js";
4
+ import { getSellabilityPolicyQueryOptions } from "../query-options.js";
5
+ export function useSellabilityPolicy(id, options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantSellabilityContext();
7
+ const { enabled = true } = options;
8
+ return useQuery({
9
+ ...getSellabilityPolicyQueryOptions({ baseUrl, fetcher }, id ?? "__missing__"),
10
+ enabled: enabled && Boolean(id),
11
+ });
12
+ }
@@ -0,0 +1,7 @@
1
+ export { defaultFetcher, fetchWithValidation, VoyantApiError, type VoyantFetcher, } from "./client.js";
2
+ export * from "./hooks/index.js";
3
+ export { useVoyantSellabilityContext, type VoyantSellabilityContextValue, VoyantSellabilityProvider, type VoyantSellabilityProviderProps, } from "./provider.js";
4
+ export { type SellabilityPoliciesListFilters, sellabilityQueryKeys, } from "./query-keys.js";
5
+ export { getSellabilityPoliciesQueryOptions, getSellabilityPolicyQueryOptions, } 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,2BAA2B,EAC3B,KAAK,6BAA6B,EAClC,yBAAyB,EACzB,KAAK,8BAA8B,GACpC,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,KAAK,8BAA8B,EACnC,oBAAoB,GACrB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,kCAAkC,EAClC,gCAAgC,GACjC,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 { useVoyantSellabilityContext, VoyantSellabilityProvider, } from "./provider.js";
4
+ export { sellabilityQueryKeys, } from "./query-keys.js";
5
+ export { getSellabilityPoliciesQueryOptions, getSellabilityPolicyQueryOptions, } from "./query-options.js";
6
+ export * from "./schemas.js";
@@ -0,0 +1,2 @@
1
+ export { useVoyantReactContext as useVoyantSellabilityContext, type VoyantReactContextValue as VoyantSellabilityContextValue, VoyantReactProvider as VoyantSellabilityProvider, type VoyantReactProviderProps as VoyantSellabilityProviderProps, } 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,2BAA2B,EACpD,KAAK,uBAAuB,IAAI,6BAA6B,EAC7D,mBAAmB,IAAI,yBAAyB,EAChD,KAAK,wBAAwB,IAAI,8BAA8B,GAChE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1 @@
1
+ export { useVoyantReactContext as useVoyantSellabilityContext, VoyantReactProvider as VoyantSellabilityProvider, } from "@voyantjs/react";
@@ -0,0 +1,20 @@
1
+ import type { sellabilityPolicyScopeSchema, sellabilityPolicyTypeSchema } from "@voyantjs/sellability/validation";
2
+ import type { z } from "zod";
3
+ export interface SellabilityPoliciesListFilters {
4
+ scope?: z.infer<typeof sellabilityPolicyScopeSchema> | undefined;
5
+ policyType?: z.infer<typeof sellabilityPolicyTypeSchema> | undefined;
6
+ productId?: string | undefined;
7
+ optionId?: string | undefined;
8
+ marketId?: string | undefined;
9
+ channelId?: string | undefined;
10
+ active?: boolean | undefined;
11
+ limit?: number | undefined;
12
+ offset?: number | undefined;
13
+ }
14
+ export declare const sellabilityQueryKeys: {
15
+ readonly all: readonly ["voyant", "sellability"];
16
+ readonly policies: () => readonly ["voyant", "sellability", "policies"];
17
+ readonly policiesList: (filters: SellabilityPoliciesListFilters) => readonly ["voyant", "sellability", "policies", "list", SellabilityPoliciesListFilters];
18
+ readonly policy: (id: string) => readonly ["voyant", "sellability", "policies", "detail", string];
19
+ };
20
+ //# 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,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,kCAAkC,CAAA;AACzC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,WAAW,8BAA8B;IAC7C,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,GAAG,SAAS,CAAA;IAChE,UAAU,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,GAAG,SAAS,CAAA;IACpE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5B;AAED,eAAO,MAAM,oBAAoB;;;qCAIP,8BAA8B;0BAEzC,MAAM;CACX,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const sellabilityQueryKeys = {
2
+ all: ["voyant", "sellability"],
3
+ policies: () => [...sellabilityQueryKeys.all, "policies"],
4
+ policiesList: (filters) => [...sellabilityQueryKeys.policies(), "list", filters],
5
+ policy: (id) => [...sellabilityQueryKeys.policies(), "detail", id],
6
+ };
@@ -0,0 +1,175 @@
1
+ import { type FetchWithValidationOptions } from "./client.js";
2
+ import type { UseSellabilityPoliciesOptions } from "./hooks/use-sellability-policies.js";
3
+ export declare function getSellabilityPoliciesQueryOptions(client: FetchWithValidationOptions, options?: UseSellabilityPoliciesOptions): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
4
+ data: {
5
+ name: string;
6
+ priority: number;
7
+ active: boolean;
8
+ id: string;
9
+ scope: "global" | "product" | "option" | "market" | "channel";
10
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
11
+ productId: string | null;
12
+ optionId: string | null;
13
+ marketId: string | null;
14
+ channelId: string | null;
15
+ conditions: Record<string, unknown>;
16
+ effects: Record<string, unknown>;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ notes?: string | null | undefined;
20
+ metadata?: Record<string, unknown> | null | undefined;
21
+ }[];
22
+ total: number;
23
+ limit: number;
24
+ offset: number;
25
+ }, Error, {
26
+ data: {
27
+ name: string;
28
+ priority: number;
29
+ active: boolean;
30
+ id: string;
31
+ scope: "global" | "product" | "option" | "market" | "channel";
32
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
33
+ productId: string | null;
34
+ optionId: string | null;
35
+ marketId: string | null;
36
+ channelId: string | null;
37
+ conditions: Record<string, unknown>;
38
+ effects: Record<string, unknown>;
39
+ createdAt: string;
40
+ updatedAt: string;
41
+ notes?: string | null | undefined;
42
+ metadata?: Record<string, unknown> | null | undefined;
43
+ }[];
44
+ total: number;
45
+ limit: number;
46
+ offset: number;
47
+ }, readonly ["voyant", "sellability", "policies", "list", import("./query-keys.js").SellabilityPoliciesListFilters]>, "queryFn"> & {
48
+ queryFn?: import("@tanstack/react-query").QueryFunction<{
49
+ data: {
50
+ name: string;
51
+ priority: number;
52
+ active: boolean;
53
+ id: string;
54
+ scope: "global" | "product" | "option" | "market" | "channel";
55
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
56
+ productId: string | null;
57
+ optionId: string | null;
58
+ marketId: string | null;
59
+ channelId: string | null;
60
+ conditions: Record<string, unknown>;
61
+ effects: Record<string, unknown>;
62
+ createdAt: string;
63
+ updatedAt: string;
64
+ notes?: string | null | undefined;
65
+ metadata?: Record<string, unknown> | null | undefined;
66
+ }[];
67
+ total: number;
68
+ limit: number;
69
+ offset: number;
70
+ }, readonly ["voyant", "sellability", "policies", "list", import("./query-keys.js").SellabilityPoliciesListFilters], never> | undefined;
71
+ } & {
72
+ queryKey: readonly ["voyant", "sellability", "policies", "list", import("./query-keys.js").SellabilityPoliciesListFilters] & {
73
+ [dataTagSymbol]: {
74
+ data: {
75
+ name: string;
76
+ priority: number;
77
+ active: boolean;
78
+ id: string;
79
+ scope: "global" | "product" | "option" | "market" | "channel";
80
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
81
+ productId: string | null;
82
+ optionId: string | null;
83
+ marketId: string | null;
84
+ channelId: string | null;
85
+ conditions: Record<string, unknown>;
86
+ effects: Record<string, unknown>;
87
+ createdAt: string;
88
+ updatedAt: string;
89
+ notes?: string | null | undefined;
90
+ metadata?: Record<string, unknown> | null | undefined;
91
+ }[];
92
+ total: number;
93
+ limit: number;
94
+ offset: number;
95
+ };
96
+ [dataTagErrorSymbol]: Error;
97
+ };
98
+ };
99
+ export declare function getSellabilityPolicyQueryOptions(client: FetchWithValidationOptions, id: string): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
100
+ name: string;
101
+ priority: number;
102
+ active: boolean;
103
+ id: string;
104
+ scope: "global" | "product" | "option" | "market" | "channel";
105
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
106
+ productId: string | null;
107
+ optionId: string | null;
108
+ marketId: string | null;
109
+ channelId: string | null;
110
+ conditions: Record<string, unknown>;
111
+ effects: Record<string, unknown>;
112
+ createdAt: string;
113
+ updatedAt: string;
114
+ notes?: string | null | undefined;
115
+ metadata?: Record<string, unknown> | null | undefined;
116
+ }, Error, {
117
+ name: string;
118
+ priority: number;
119
+ active: boolean;
120
+ id: string;
121
+ scope: "global" | "product" | "option" | "market" | "channel";
122
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
123
+ productId: string | null;
124
+ optionId: string | null;
125
+ marketId: string | null;
126
+ channelId: string | null;
127
+ conditions: Record<string, unknown>;
128
+ effects: Record<string, unknown>;
129
+ createdAt: string;
130
+ updatedAt: string;
131
+ notes?: string | null | undefined;
132
+ metadata?: Record<string, unknown> | null | undefined;
133
+ }, readonly ["voyant", "sellability", "policies", "detail", string]>, "queryFn"> & {
134
+ queryFn?: import("@tanstack/react-query").QueryFunction<{
135
+ name: string;
136
+ priority: number;
137
+ active: boolean;
138
+ id: string;
139
+ scope: "global" | "product" | "option" | "market" | "channel";
140
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
141
+ productId: string | null;
142
+ optionId: string | null;
143
+ marketId: string | null;
144
+ channelId: string | null;
145
+ conditions: Record<string, unknown>;
146
+ effects: Record<string, unknown>;
147
+ createdAt: string;
148
+ updatedAt: string;
149
+ notes?: string | null | undefined;
150
+ metadata?: Record<string, unknown> | null | undefined;
151
+ }, readonly ["voyant", "sellability", "policies", "detail", string], never> | undefined;
152
+ } & {
153
+ queryKey: readonly ["voyant", "sellability", "policies", "detail", string] & {
154
+ [dataTagSymbol]: {
155
+ name: string;
156
+ priority: number;
157
+ active: boolean;
158
+ id: string;
159
+ scope: "global" | "product" | "option" | "market" | "channel";
160
+ policyType: "custom" | "capability" | "occupancy" | "pickup" | "question" | "allotment" | "availability_window" | "currency";
161
+ productId: string | null;
162
+ optionId: string | null;
163
+ marketId: string | null;
164
+ channelId: string | null;
165
+ conditions: Record<string, unknown>;
166
+ effects: Record<string, unknown>;
167
+ createdAt: string;
168
+ updatedAt: string;
169
+ notes?: string | null | undefined;
170
+ metadata?: Record<string, unknown> | null | undefined;
171
+ };
172
+ [dataTagErrorSymbol]: Error;
173
+ };
174
+ };
175
+ //# sourceMappingURL=query-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-options.d.ts","sourceRoot":"","sources":["../src/query-options.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,0BAA0B,EAAuB,MAAM,aAAa,CAAA;AAClF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,qCAAqC,CAAA;AAcxF,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,0BAA0B,EAClC,OAAO,GAAE,6BAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa5C;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,0BAA0B,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY9F"}
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { queryOptions } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "./client.js";
4
+ import { sellabilityQueryKeys } from "./query-keys.js";
5
+ import { sellabilityPolicyListResponse, sellabilityPolicySingleResponse } from "./schemas.js";
6
+ function toQueryString(filters) {
7
+ const params = new URLSearchParams();
8
+ for (const [key, value] of Object.entries(filters)) {
9
+ if (value === undefined || value === null || value === "")
10
+ continue;
11
+ params.set(key, String(value));
12
+ }
13
+ const qs = params.toString();
14
+ return qs ? `?${qs}` : "";
15
+ }
16
+ export function getSellabilityPoliciesQueryOptions(client, options = {}) {
17
+ const { enabled: _enabled = true, ...filters } = options;
18
+ return queryOptions({
19
+ queryKey: sellabilityQueryKeys.policiesList(filters),
20
+ queryFn: () => fetchWithValidation(`/v1/sellability/policies${toQueryString(filters)}`, sellabilityPolicyListResponse, client),
21
+ });
22
+ }
23
+ export function getSellabilityPolicyQueryOptions(client, id) {
24
+ return queryOptions({
25
+ queryKey: sellabilityQueryKeys.policy(id),
26
+ queryFn: async () => {
27
+ const { data } = await fetchWithValidation(`/v1/sellability/policies/${id}`, sellabilityPolicySingleResponse, client);
28
+ return data;
29
+ },
30
+ });
31
+ }
@@ -0,0 +1,121 @@
1
+ import { z } from "zod";
2
+ export declare const paginatedEnvelope: <T extends z.ZodTypeAny>(item: T) => z.ZodObject<{
3
+ data: z.ZodArray<T>;
4
+ total: z.ZodNumber;
5
+ limit: z.ZodNumber;
6
+ offset: z.ZodNumber;
7
+ }, z.core.$strip>;
8
+ export declare const singleEnvelope: <T extends z.ZodTypeAny>(item: T) => z.ZodObject<{
9
+ data: T;
10
+ }, z.core.$strip>;
11
+ export declare const successEnvelope: z.ZodObject<{
12
+ success: z.ZodBoolean;
13
+ }, z.core.$strip>;
14
+ export declare const sellabilityPolicyRecordSchema: z.ZodObject<{
15
+ name: z.ZodString;
16
+ priority: z.ZodDefault<z.ZodNumber>;
17
+ active: z.ZodDefault<z.ZodBoolean>;
18
+ notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
19
+ id: z.ZodString;
20
+ scope: z.ZodEnum<{
21
+ global: "global";
22
+ product: "product";
23
+ option: "option";
24
+ market: "market";
25
+ channel: "channel";
26
+ }>;
27
+ policyType: z.ZodEnum<{
28
+ custom: "custom";
29
+ capability: "capability";
30
+ occupancy: "occupancy";
31
+ pickup: "pickup";
32
+ question: "question";
33
+ allotment: "allotment";
34
+ availability_window: "availability_window";
35
+ currency: "currency";
36
+ }>;
37
+ productId: z.ZodNullable<z.ZodString>;
38
+ optionId: z.ZodNullable<z.ZodString>;
39
+ marketId: z.ZodNullable<z.ZodString>;
40
+ channelId: z.ZodNullable<z.ZodString>;
41
+ conditions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
42
+ effects: z.ZodRecord<z.ZodString, z.ZodUnknown>;
43
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
44
+ createdAt: z.ZodString;
45
+ updatedAt: z.ZodString;
46
+ }, z.core.$strip>;
47
+ export type SellabilityPolicyRecord = z.infer<typeof sellabilityPolicyRecordSchema>;
48
+ export declare const sellabilityPolicyListResponse: z.ZodObject<{
49
+ data: z.ZodArray<z.ZodObject<{
50
+ name: z.ZodString;
51
+ priority: z.ZodDefault<z.ZodNumber>;
52
+ active: z.ZodDefault<z.ZodBoolean>;
53
+ notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
54
+ id: z.ZodString;
55
+ scope: z.ZodEnum<{
56
+ global: "global";
57
+ product: "product";
58
+ option: "option";
59
+ market: "market";
60
+ channel: "channel";
61
+ }>;
62
+ policyType: z.ZodEnum<{
63
+ custom: "custom";
64
+ capability: "capability";
65
+ occupancy: "occupancy";
66
+ pickup: "pickup";
67
+ question: "question";
68
+ allotment: "allotment";
69
+ availability_window: "availability_window";
70
+ currency: "currency";
71
+ }>;
72
+ productId: z.ZodNullable<z.ZodString>;
73
+ optionId: z.ZodNullable<z.ZodString>;
74
+ marketId: z.ZodNullable<z.ZodString>;
75
+ channelId: z.ZodNullable<z.ZodString>;
76
+ conditions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
77
+ effects: z.ZodRecord<z.ZodString, z.ZodUnknown>;
78
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
79
+ createdAt: z.ZodString;
80
+ updatedAt: z.ZodString;
81
+ }, z.core.$strip>>;
82
+ total: z.ZodNumber;
83
+ limit: z.ZodNumber;
84
+ offset: z.ZodNumber;
85
+ }, z.core.$strip>;
86
+ export declare const sellabilityPolicySingleResponse: z.ZodObject<{
87
+ data: z.ZodObject<{
88
+ name: z.ZodString;
89
+ priority: z.ZodDefault<z.ZodNumber>;
90
+ active: z.ZodDefault<z.ZodBoolean>;
91
+ notes: z.ZodOptional<z.ZodNullable<z.ZodString>>;
92
+ id: z.ZodString;
93
+ scope: z.ZodEnum<{
94
+ global: "global";
95
+ product: "product";
96
+ option: "option";
97
+ market: "market";
98
+ channel: "channel";
99
+ }>;
100
+ policyType: z.ZodEnum<{
101
+ custom: "custom";
102
+ capability: "capability";
103
+ occupancy: "occupancy";
104
+ pickup: "pickup";
105
+ question: "question";
106
+ allotment: "allotment";
107
+ availability_window: "availability_window";
108
+ currency: "currency";
109
+ }>;
110
+ productId: z.ZodNullable<z.ZodString>;
111
+ optionId: z.ZodNullable<z.ZodString>;
112
+ marketId: z.ZodNullable<z.ZodString>;
113
+ channelId: z.ZodNullable<z.ZodString>;
114
+ conditions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
115
+ effects: z.ZodRecord<z.ZodString, z.ZodUnknown>;
116
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
117
+ createdAt: z.ZodString;
118
+ updatedAt: z.ZodString;
119
+ }, z.core.$strip>;
120
+ }, z.core.$strip>;
121
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC;;;;;iBAM7D,CAAA;AAEJ,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC;;iBAA6B,CAAA;AAC3F,eAAO,MAAM,eAAe;;iBAAqC,CAAA;AAEjE,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAaxC,CAAA;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAEnF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAmD,CAAA;AAC7F,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgD,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { insertSellabilityPolicySchema, sellabilityPolicyScopeSchema, sellabilityPolicyTypeSchema, } from "@voyantjs/sellability/validation";
2
+ import { z } from "zod";
3
+ export const paginatedEnvelope = (item) => z.object({
4
+ data: z.array(item),
5
+ total: z.number().int(),
6
+ limit: z.number().int(),
7
+ offset: z.number().int(),
8
+ });
9
+ export const singleEnvelope = (item) => z.object({ data: item });
10
+ export const successEnvelope = z.object({ success: z.boolean() });
11
+ export const sellabilityPolicyRecordSchema = insertSellabilityPolicySchema.extend({
12
+ id: z.string(),
13
+ scope: sellabilityPolicyScopeSchema,
14
+ policyType: sellabilityPolicyTypeSchema,
15
+ productId: z.string().nullable(),
16
+ optionId: z.string().nullable(),
17
+ marketId: z.string().nullable(),
18
+ channelId: z.string().nullable(),
19
+ conditions: z.record(z.string(), z.unknown()),
20
+ effects: z.record(z.string(), z.unknown()),
21
+ metadata: z.record(z.string(), z.unknown()).nullable().optional(),
22
+ createdAt: z.string(),
23
+ updatedAt: z.string(),
24
+ });
25
+ export const sellabilityPolicyListResponse = paginatedEnvelope(sellabilityPolicyRecordSchema);
26
+ export const sellabilityPolicySingleResponse = singleEnvelope(sellabilityPolicyRecordSchema);
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@voyantjs/sellability-react",
3
+ "version": "0.2.0",
4
+ "license": "FSL-1.1-Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/voyantjs/voyant.git",
8
+ "directory": "packages/sellability-react"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": "./src/index.ts",
13
+ "./provider": "./src/provider.tsx",
14
+ "./hooks": "./src/hooks/index.ts",
15
+ "./client": "./src/client.ts",
16
+ "./query-keys": "./src/query-keys.ts"
17
+ },
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json",
20
+ "clean": "rm -rf dist",
21
+ "prepack": "pnpm run build",
22
+ "typecheck": "tsc --noEmit",
23
+ "lint": "biome check src/",
24
+ "test": "vitest run --passWithNoTests"
25
+ },
26
+ "peerDependencies": {
27
+ "@voyantjs/sellability": "workspace:*",
28
+ "@tanstack/react-query": "^5.0.0",
29
+ "react": "^19.0.0",
30
+ "react-dom": "^19.0.0",
31
+ "zod": "^4.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@tanstack/react-query": "^5.96.2",
35
+ "@types/react": "^19.2.14",
36
+ "@types/react-dom": "^19.2.3",
37
+ "@voyantjs/react": "workspace:*",
38
+ "@voyantjs/sellability": "workspace:*",
39
+ "@voyantjs/voyant-typescript-config": "workspace:*",
40
+ "react": "^19.2.4",
41
+ "react-dom": "^19.2.4",
42
+ "typescript": "^6.0.2",
43
+ "vitest": "^4.1.2",
44
+ "zod": "^4.3.6"
45
+ },
46
+ "dependencies": {
47
+ "@voyantjs/react": "workspace:*"
48
+ },
49
+ "files": [
50
+ "dist"
51
+ ],
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "exports": {
55
+ ".": {
56
+ "types": "./dist/index.d.ts",
57
+ "import": "./dist/index.js"
58
+ },
59
+ "./provider": {
60
+ "types": "./dist/provider.d.ts",
61
+ "import": "./dist/provider.js"
62
+ },
63
+ "./hooks": {
64
+ "types": "./dist/hooks/index.d.ts",
65
+ "import": "./dist/hooks/index.js"
66
+ },
67
+ "./client": {
68
+ "types": "./dist/client.d.ts",
69
+ "import": "./dist/client.js"
70
+ },
71
+ "./query-keys": {
72
+ "types": "./dist/query-keys.d.ts",
73
+ "import": "./dist/query-keys.js"
74
+ }
75
+ },
76
+ "main": "./dist/index.js",
77
+ "types": "./dist/index.d.ts"
78
+ }
79
+ }