mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 08:14:06 +00:00
feature: secret sync base + aws parameter store & github
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { SecretSync, TSecretSyncOption } from "@app/hooks/api/secretSyncs";
|
||||
import {
|
||||
TListSecretSyncOptions,
|
||||
TListSecretSyncs,
|
||||
TSecretSync,
|
||||
TSecretSyncResponse
|
||||
} from "@app/hooks/api/secretSyncs/types";
|
||||
|
||||
export const secretSyncKeys = {
|
||||
all: ["secret-sync"] as const,
|
||||
options: () => [...secretSyncKeys.all, "options"] as const,
|
||||
list: () => [...secretSyncKeys.all, "list"] as const,
|
||||
byId: (destination: SecretSync, syncId: string) =>
|
||||
[...secretSyncKeys.all, destination, "by-id", syncId] as const
|
||||
};
|
||||
|
||||
export const useSecretSyncOptions = (
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TSecretSyncOption[],
|
||||
unknown,
|
||||
TSecretSyncOption[],
|
||||
ReturnType<typeof secretSyncKeys.options>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: secretSyncKeys.options(),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TListSecretSyncOptions>("/api/v1/secret-syncs/options");
|
||||
|
||||
return data.secretSyncOptions;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useSecretSyncOption = (destination: SecretSync) => {
|
||||
const { data: syncOptions, isPending } = useSecretSyncOptions();
|
||||
const syncOption = syncOptions?.find((option) => option.destination === destination);
|
||||
|
||||
return { syncOption, isPending };
|
||||
};
|
||||
|
||||
export const useListSecretSyncs = (
|
||||
projectId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<TSecretSync[], unknown, TSecretSync[], ReturnType<typeof secretSyncKeys.list>>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: secretSyncKeys.list(),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TListSecretSyncs>("/api/v1/secret-syncs", {
|
||||
params: { projectId }
|
||||
});
|
||||
|
||||
return data.secretSyncs;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetSecretSync = (
|
||||
destination: SecretSync,
|
||||
syncId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<TSecretSync, unknown, TSecretSync, ReturnType<typeof secretSyncKeys.byId>>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: secretSyncKeys.byId(destination, syncId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TSecretSyncResponse>(
|
||||
`/api/v1/secret-syncs/${destination}/${syncId}`
|
||||
);
|
||||
|
||||
return data.secretSync;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user