@voyantjs/external-refs-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,3 @@
1
+ export * from "./use-external-ref-mutation.js";
2
+ export * from "./use-external-refs.js";
3
+ //# 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,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./use-external-ref-mutation.js";
2
+ export * from "./use-external-refs.js";
@@ -0,0 +1,57 @@
1
+ import type { insertExternalRefSchema, updateExternalRefSchema } from "@voyantjs/external-refs";
2
+ import type { z } from "zod";
3
+ export type CreateExternalRefInput = z.input<typeof insertExternalRefSchema>;
4
+ export type UpdateExternalRefInput = z.input<typeof updateExternalRefSchema>;
5
+ export declare function useExternalRefMutation(): {
6
+ create: import("@tanstack/react-query").UseMutationResult<{
7
+ entityType: string;
8
+ entityId: string;
9
+ sourceSystem: string;
10
+ objectType: string;
11
+ namespace: string;
12
+ externalId: string;
13
+ isPrimary: boolean;
14
+ status: "active" | "inactive" | "archived";
15
+ id: string;
16
+ externalParentId: string | null;
17
+ lastSyncedAt: string | null;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ metadata?: Record<string, unknown> | null | undefined;
21
+ }, Error, {
22
+ entityType: string;
23
+ entityId: string;
24
+ sourceSystem: string;
25
+ objectType: string;
26
+ externalId: string;
27
+ namespace?: string | undefined;
28
+ externalParentId?: string | null | undefined;
29
+ isPrimary?: boolean | undefined;
30
+ status?: "active" | "inactive" | "archived" | undefined;
31
+ lastSyncedAt?: string | null | undefined;
32
+ metadata?: Record<string, unknown> | null | undefined;
33
+ }, unknown>;
34
+ update: import("@tanstack/react-query").UseMutationResult<{
35
+ entityType: string;
36
+ entityId: string;
37
+ sourceSystem: string;
38
+ objectType: string;
39
+ namespace: string;
40
+ externalId: string;
41
+ isPrimary: boolean;
42
+ status: "active" | "inactive" | "archived";
43
+ id: string;
44
+ externalParentId: string | null;
45
+ lastSyncedAt: string | null;
46
+ createdAt: string;
47
+ updatedAt: string;
48
+ metadata?: Record<string, unknown> | null | undefined;
49
+ }, Error, {
50
+ id: string;
51
+ input: UpdateExternalRefInput;
52
+ }, unknown>;
53
+ remove: import("@tanstack/react-query").UseMutationResult<{
54
+ success: boolean;
55
+ }, Error, string, unknown>;
56
+ };
57
+ //# sourceMappingURL=use-external-ref-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-external-ref-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-external-ref-mutation.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AAC/F,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAO5B,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAC5E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAE5E,wBAAgB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqBM,MAAM;eAAS,sBAAsB;;;;;EAgChF"}
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantExternalRefsContext } from "../provider.js";
5
+ import { externalRefsQueryKeys } from "../query-keys.js";
6
+ import { externalRefSingleResponse, successEnvelope } from "../schemas.js";
7
+ export function useExternalRefMutation() {
8
+ const { baseUrl, fetcher } = useVoyantExternalRefsContext();
9
+ const queryClient = useQueryClient();
10
+ const create = useMutation({
11
+ mutationFn: async (input) => {
12
+ const { data } = await fetchWithValidation("/v1/external-refs/refs", externalRefSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
13
+ return data;
14
+ },
15
+ onSuccess: (data) => {
16
+ void queryClient.invalidateQueries({ queryKey: externalRefsQueryKeys.refs() });
17
+ queryClient.setQueryData(externalRefsQueryKeys.ref(data.id), data);
18
+ },
19
+ });
20
+ const update = useMutation({
21
+ mutationFn: async ({ id, input }) => {
22
+ const { data } = await fetchWithValidation(`/v1/external-refs/refs/${id}`, externalRefSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
23
+ return data;
24
+ },
25
+ onSuccess: (data) => {
26
+ void queryClient.invalidateQueries({ queryKey: externalRefsQueryKeys.refs() });
27
+ queryClient.setQueryData(externalRefsQueryKeys.ref(data.id), data);
28
+ },
29
+ });
30
+ const remove = useMutation({
31
+ mutationFn: async (id) => fetchWithValidation(`/v1/external-refs/refs/${id}`, successEnvelope, { baseUrl, fetcher }, {
32
+ method: "DELETE",
33
+ }),
34
+ onSuccess: (_data, id) => {
35
+ void queryClient.invalidateQueries({ queryKey: externalRefsQueryKeys.refs() });
36
+ queryClient.removeQueries({ queryKey: externalRefsQueryKeys.ref(id) });
37
+ },
38
+ });
39
+ return { create, update, remove };
40
+ }
@@ -0,0 +1,26 @@
1
+ import type { ExternalRefsListFilters } from "../query-keys.js";
2
+ export interface UseExternalRefsOptions extends ExternalRefsListFilters {
3
+ enabled?: boolean;
4
+ }
5
+ export declare function useExternalRefs(options?: UseExternalRefsOptions): import("@tanstack/react-query").UseQueryResult<{
6
+ data: {
7
+ entityType: string;
8
+ entityId: string;
9
+ sourceSystem: string;
10
+ objectType: string;
11
+ namespace: string;
12
+ externalId: string;
13
+ isPrimary: boolean;
14
+ status: "active" | "inactive" | "archived";
15
+ id: string;
16
+ externalParentId: string | null;
17
+ lastSyncedAt: string | null;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ metadata?: Record<string, unknown> | null | undefined;
21
+ }[];
22
+ total: number;
23
+ limit: number;
24
+ offset: number;
25
+ }, Error>;
26
+ //# sourceMappingURL=use-external-refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-external-refs.d.ts","sourceRoot":"","sources":["../../src/hooks/use-external-refs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAG/D,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;UAQnE"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { useVoyantExternalRefsContext } from "../provider.js";
4
+ import { getExternalRefsQueryOptions } from "../query-options.js";
5
+ export function useExternalRefs(options = {}) {
6
+ const { baseUrl, fetcher } = useVoyantExternalRefsContext();
7
+ const { enabled = true, ...filters } = options;
8
+ return useQuery({
9
+ ...getExternalRefsQueryOptions({ baseUrl, fetcher }, filters),
10
+ enabled,
11
+ });
12
+ }
@@ -0,0 +1,7 @@
1
+ export { defaultFetcher, fetchWithValidation, VoyantApiError, type VoyantFetcher, } from "./client.js";
2
+ export * from "./hooks/index.js";
3
+ export { useVoyantExternalRefsContext, type VoyantExternalRefsContextValue, VoyantExternalRefsProvider, type VoyantExternalRefsProviderProps, } from "./provider.js";
4
+ export { type ExternalRefsListFilters, externalRefsQueryKeys } from "./query-keys.js";
5
+ export { getExternalRefQueryOptions, getExternalRefsQueryOptions } 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,EAAE,KAAK,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACrF,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAA;AAC5F,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 { useVoyantExternalRefsContext, VoyantExternalRefsProvider, } from "./provider.js";
4
+ export { externalRefsQueryKeys } from "./query-keys.js";
5
+ export { getExternalRefQueryOptions, getExternalRefsQueryOptions } from "./query-options.js";
6
+ export * from "./schemas.js";
@@ -0,0 +1,2 @@
1
+ export { useVoyantReactContext as useVoyantExternalRefsContext, type VoyantReactContextValue as VoyantExternalRefsContextValue, VoyantReactProvider as VoyantExternalRefsProvider, type VoyantReactProviderProps as VoyantExternalRefsProviderProps, } 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"}
@@ -0,0 +1 @@
1
+ export { useVoyantReactContext as useVoyantExternalRefsContext, VoyantReactProvider as VoyantExternalRefsProvider, } from "@voyantjs/react";
@@ -0,0 +1,18 @@
1
+ export interface ExternalRefsListFilters {
2
+ entityType?: string | undefined;
3
+ entityId?: string | undefined;
4
+ sourceSystem?: string | undefined;
5
+ objectType?: string | undefined;
6
+ namespace?: string | undefined;
7
+ status?: string | undefined;
8
+ search?: string | undefined;
9
+ limit?: number | undefined;
10
+ offset?: number | undefined;
11
+ }
12
+ export declare const externalRefsQueryKeys: {
13
+ all: readonly ["external-refs"];
14
+ refs: () => readonly ["external-refs", "refs"];
15
+ refsList: (filters: ExternalRefsListFilters) => readonly ["external-refs", "refs", ExternalRefsListFilters];
16
+ ref: (id: string) => readonly ["external-refs", "refs", string];
17
+ };
18
+ //# 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,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,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;;;wBAGZ,uBAAuB;cAEjC,MAAM;CACjB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export const externalRefsQueryKeys = {
2
+ all: ["external-refs"],
3
+ refs: () => [...externalRefsQueryKeys.all, "refs"],
4
+ refsList: (filters) => [...externalRefsQueryKeys.refs(), filters],
5
+ ref: (id) => [...externalRefsQueryKeys.refs(), id],
6
+ };
@@ -0,0 +1,159 @@
1
+ import { type FetchWithValidationOptions } from "./client.js";
2
+ import type { UseExternalRefsOptions } from "./hooks/use-external-refs.js";
3
+ export declare function getExternalRefsQueryOptions(client: FetchWithValidationOptions, options?: UseExternalRefsOptions): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
4
+ data: {
5
+ entityType: string;
6
+ entityId: string;
7
+ sourceSystem: string;
8
+ objectType: string;
9
+ namespace: string;
10
+ externalId: string;
11
+ isPrimary: boolean;
12
+ status: "active" | "inactive" | "archived";
13
+ id: string;
14
+ externalParentId: string | null;
15
+ lastSyncedAt: string | null;
16
+ createdAt: string;
17
+ updatedAt: string;
18
+ metadata?: Record<string, unknown> | null | undefined;
19
+ }[];
20
+ total: number;
21
+ limit: number;
22
+ offset: number;
23
+ }, Error, {
24
+ data: {
25
+ entityType: string;
26
+ entityId: string;
27
+ sourceSystem: string;
28
+ objectType: string;
29
+ namespace: string;
30
+ externalId: string;
31
+ isPrimary: boolean;
32
+ status: "active" | "inactive" | "archived";
33
+ id: string;
34
+ externalParentId: string | null;
35
+ lastSyncedAt: string | null;
36
+ createdAt: string;
37
+ updatedAt: string;
38
+ metadata?: Record<string, unknown> | null | undefined;
39
+ }[];
40
+ total: number;
41
+ limit: number;
42
+ offset: number;
43
+ }, readonly ["external-refs", "refs", import("./query-keys.js").ExternalRefsListFilters]>, "queryFn"> & {
44
+ queryFn?: import("@tanstack/react-query").QueryFunction<{
45
+ data: {
46
+ entityType: string;
47
+ entityId: string;
48
+ sourceSystem: string;
49
+ objectType: string;
50
+ namespace: string;
51
+ externalId: string;
52
+ isPrimary: boolean;
53
+ status: "active" | "inactive" | "archived";
54
+ id: string;
55
+ externalParentId: string | null;
56
+ lastSyncedAt: string | null;
57
+ createdAt: string;
58
+ updatedAt: string;
59
+ metadata?: Record<string, unknown> | null | undefined;
60
+ }[];
61
+ total: number;
62
+ limit: number;
63
+ offset: number;
64
+ }, readonly ["external-refs", "refs", import("./query-keys.js").ExternalRefsListFilters], never> | undefined;
65
+ } & {
66
+ queryKey: readonly ["external-refs", "refs", import("./query-keys.js").ExternalRefsListFilters] & {
67
+ [dataTagSymbol]: {
68
+ data: {
69
+ entityType: string;
70
+ entityId: string;
71
+ sourceSystem: string;
72
+ objectType: string;
73
+ namespace: string;
74
+ externalId: string;
75
+ isPrimary: boolean;
76
+ status: "active" | "inactive" | "archived";
77
+ id: string;
78
+ externalParentId: string | null;
79
+ lastSyncedAt: string | null;
80
+ createdAt: string;
81
+ updatedAt: string;
82
+ metadata?: Record<string, unknown> | null | undefined;
83
+ }[];
84
+ total: number;
85
+ limit: number;
86
+ offset: number;
87
+ };
88
+ [dataTagErrorSymbol]: Error;
89
+ };
90
+ };
91
+ export declare function getExternalRefQueryOptions(client: FetchWithValidationOptions, id: string): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<{
92
+ entityType: string;
93
+ entityId: string;
94
+ sourceSystem: string;
95
+ objectType: string;
96
+ namespace: string;
97
+ externalId: string;
98
+ isPrimary: boolean;
99
+ status: "active" | "inactive" | "archived";
100
+ id: string;
101
+ externalParentId: string | null;
102
+ lastSyncedAt: string | null;
103
+ createdAt: string;
104
+ updatedAt: string;
105
+ metadata?: Record<string, unknown> | null | undefined;
106
+ }, Error, {
107
+ entityType: string;
108
+ entityId: string;
109
+ sourceSystem: string;
110
+ objectType: string;
111
+ namespace: string;
112
+ externalId: string;
113
+ isPrimary: boolean;
114
+ status: "active" | "inactive" | "archived";
115
+ id: string;
116
+ externalParentId: string | null;
117
+ lastSyncedAt: string | null;
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ metadata?: Record<string, unknown> | null | undefined;
121
+ }, readonly ["external-refs", "refs", string]>, "queryFn"> & {
122
+ queryFn?: import("@tanstack/react-query").QueryFunction<{
123
+ entityType: string;
124
+ entityId: string;
125
+ sourceSystem: string;
126
+ objectType: string;
127
+ namespace: string;
128
+ externalId: string;
129
+ isPrimary: boolean;
130
+ status: "active" | "inactive" | "archived";
131
+ id: string;
132
+ externalParentId: string | null;
133
+ lastSyncedAt: string | null;
134
+ createdAt: string;
135
+ updatedAt: string;
136
+ metadata?: Record<string, unknown> | null | undefined;
137
+ }, readonly ["external-refs", "refs", string], never> | undefined;
138
+ } & {
139
+ queryKey: readonly ["external-refs", "refs", string] & {
140
+ [dataTagSymbol]: {
141
+ entityType: string;
142
+ entityId: string;
143
+ sourceSystem: string;
144
+ objectType: string;
145
+ namespace: string;
146
+ externalId: string;
147
+ isPrimary: boolean;
148
+ status: "active" | "inactive" | "archived";
149
+ id: string;
150
+ externalParentId: string | null;
151
+ lastSyncedAt: string | null;
152
+ createdAt: string;
153
+ updatedAt: string;
154
+ metadata?: Record<string, unknown> | null | undefined;
155
+ };
156
+ [dataTagErrorSymbol]: Error;
157
+ };
158
+ };
159
+ //# 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,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAc1E,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,0BAA0B,EAClC,OAAO,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYrC;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYxF"}
@@ -0,0 +1,31 @@
1
+ "use client";
2
+ import { queryOptions } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "./client.js";
4
+ import { externalRefsQueryKeys } from "./query-keys.js";
5
+ import { externalRefListResponse, externalRefSingleResponse } 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 getExternalRefsQueryOptions(client, options = {}) {
17
+ const { enabled: _enabled = true, ...filters } = options;
18
+ return queryOptions({
19
+ queryKey: externalRefsQueryKeys.refsList(filters),
20
+ queryFn: () => fetchWithValidation(`/v1/external-refs/refs${toQueryString(filters)}`, externalRefListResponse, client),
21
+ });
22
+ }
23
+ export function getExternalRefQueryOptions(client, id) {
24
+ return queryOptions({
25
+ queryKey: externalRefsQueryKeys.ref(id),
26
+ queryFn: async () => {
27
+ const { data } = await fetchWithValidation(`/v1/external-refs/refs/${id}`, externalRefSingleResponse, client);
28
+ return data;
29
+ },
30
+ });
31
+ }
@@ -0,0 +1,82 @@
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 externalRefRecordSchema: z.ZodObject<{
15
+ entityType: z.ZodString;
16
+ entityId: z.ZodString;
17
+ sourceSystem: z.ZodString;
18
+ objectType: z.ZodString;
19
+ namespace: z.ZodDefault<z.ZodString>;
20
+ externalId: z.ZodString;
21
+ isPrimary: z.ZodDefault<z.ZodBoolean>;
22
+ status: z.ZodDefault<z.ZodEnum<{
23
+ active: "active";
24
+ inactive: "inactive";
25
+ archived: "archived";
26
+ }>>;
27
+ id: z.ZodString;
28
+ externalParentId: z.ZodNullable<z.ZodString>;
29
+ lastSyncedAt: z.ZodNullable<z.ZodString>;
30
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
31
+ createdAt: z.ZodString;
32
+ updatedAt: z.ZodString;
33
+ }, z.core.$strip>;
34
+ export type ExternalRefRecord = z.infer<typeof externalRefRecordSchema>;
35
+ export declare const externalRefListResponse: z.ZodObject<{
36
+ data: z.ZodArray<z.ZodObject<{
37
+ entityType: z.ZodString;
38
+ entityId: z.ZodString;
39
+ sourceSystem: z.ZodString;
40
+ objectType: z.ZodString;
41
+ namespace: z.ZodDefault<z.ZodString>;
42
+ externalId: z.ZodString;
43
+ isPrimary: z.ZodDefault<z.ZodBoolean>;
44
+ status: z.ZodDefault<z.ZodEnum<{
45
+ active: "active";
46
+ inactive: "inactive";
47
+ archived: "archived";
48
+ }>>;
49
+ id: z.ZodString;
50
+ externalParentId: z.ZodNullable<z.ZodString>;
51
+ lastSyncedAt: z.ZodNullable<z.ZodString>;
52
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
53
+ createdAt: z.ZodString;
54
+ updatedAt: z.ZodString;
55
+ }, z.core.$strip>>;
56
+ total: z.ZodNumber;
57
+ limit: z.ZodNumber;
58
+ offset: z.ZodNumber;
59
+ }, z.core.$strip>;
60
+ export declare const externalRefSingleResponse: z.ZodObject<{
61
+ data: z.ZodObject<{
62
+ entityType: z.ZodString;
63
+ entityId: z.ZodString;
64
+ sourceSystem: z.ZodString;
65
+ objectType: z.ZodString;
66
+ namespace: z.ZodDefault<z.ZodString>;
67
+ externalId: z.ZodString;
68
+ isPrimary: z.ZodDefault<z.ZodBoolean>;
69
+ status: z.ZodDefault<z.ZodEnum<{
70
+ active: "active";
71
+ inactive: "inactive";
72
+ archived: "archived";
73
+ }>>;
74
+ id: z.ZodString;
75
+ externalParentId: z.ZodNullable<z.ZodString>;
76
+ lastSyncedAt: z.ZodNullable<z.ZodString>;
77
+ metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
78
+ createdAt: z.ZodString;
79
+ updatedAt: z.ZodString;
80
+ }, z.core.$strip>;
81
+ }, z.core.$strip>;
82
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AACA,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,uBAAuB;;;;;;;;;;;;;;;;;;;iBAOlC,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAEvE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;iBAA6C,CAAA;AACjF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;iBAA0C,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { insertExternalRefSchema } from "@voyantjs/external-refs";
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 externalRefRecordSchema = insertExternalRefSchema.extend({
12
+ id: z.string(),
13
+ externalParentId: z.string().nullable(),
14
+ lastSyncedAt: z.string().nullable(),
15
+ metadata: z.record(z.string(), z.unknown()).nullable().optional(),
16
+ createdAt: z.string(),
17
+ updatedAt: z.string(),
18
+ });
19
+ export const externalRefListResponse = paginatedEnvelope(externalRefRecordSchema);
20
+ export const externalRefSingleResponse = singleEnvelope(externalRefRecordSchema);
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@voyantjs/external-refs-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/external-refs-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/external-refs": "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/external-refs": "workspace:*",
38
+ "@voyantjs/react": "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
+ }