Move from openapi-generator-cli to custom Axios approach, and add listFolders endpoint

This commit is contained in:
carlosmonastyrski
2025-05-02 19:12:08 -03:00
parent 1b8aa6d20e
commit 68613f6b13
25 changed files with 1757 additions and 2605 deletions

View File

@@ -1,35 +1,52 @@
import { RawAxiosRequestConfig } from "axios";
import { DefaultApi as InfisicalApi } from "../infisicalapi_client";
import type { ApiV1FoldersPostRequest, ApiV1FoldersPost200Response } from "../infisicalapi_client";
import { FoldersApi } from "../api/endpoints/folders";
import { newInfisicalError } from "./errors";
export type CreateFolderOptions = {
projectId: string;
} & Omit<ApiV1FoldersPostRequest, "workspaceId" | "directory">;
export type CreateFolderResult = ApiV1FoldersPost200Response;
name: string;
path: string;
projectId: string;
environment: string;
description?: string;
};
export type ListFoldersOptions = {
environment: string;
projectId: string;
path?: string;
recursive?: boolean;
lastSecretModified?: string;
};
export default class FoldersClient {
#apiInstance: InfisicalApi;
#requestOptions: RawAxiosRequestConfig | undefined;
constructor(apiInstance: InfisicalApi, requestOptions: RawAxiosRequestConfig | undefined) {
this.#apiInstance = apiInstance;
this.#requestOptions = requestOptions;
}
constructor(private apiClient: FoldersApi) {}
create = async (options: CreateFolderOptions): Promise<CreateFolderResult["folder"]> => {
try {
const res = await this.#apiInstance.apiV1FoldersPost(
{
apiV1FoldersPostRequest: {
...options,
workspaceId: options.projectId
}
},
this.#requestOptions
);
return res.data.folder;
} catch (err) {
throw newInfisicalError(err);
}
};
create = async (options: CreateFolderOptions) => {
try {
const res = await this.apiClient.create({
name: options.name,
path: options.path,
workspaceId: options.projectId,
environment: options.environment,
description: options.description,
});
return res.folder;
} catch (err) {
throw newInfisicalError(err);
}
};
listFolders = async (options: ListFoldersOptions) => {
try {
const res = await this.apiClient.listFolders({
environment: options.environment,
workspaceId: options.projectId,
path: options.path,
recursive: options.recursive,
lastSecretModified: options.lastSecretModified,
});
return res.folders;
} catch (err) {
throw newInfisicalError(err);
}
};
}