ldelalande+alexhancock/shared-config-client (#1219)

Co-authored-by: Lily Delalande <ldelalande@squareup.com>
This commit is contained in:
Alex Hancock
2025-02-13 13:50:02 -05:00
committed by GitHub
parent 4ed0a3fac3
commit 3ef552d7bf
20 changed files with 3981 additions and 1117 deletions

View File

@@ -0,0 +1,59 @@
import {
readAllConfig,
readConfig,
removeConfig,
upsertConfig,
addExtension,
removeExtension,
} from './generated';
import { client } from './generated/client.gen';
// Initialize client configuration
client.setConfig({
baseUrl: window.appConfig.get('GOOSE_API_HOST') + ':' + window.appConfig.get('GOOSE_PORT'),
headers: {
'Content-Type': 'application/json',
'X-Secret-Key': window.appConfig.get('secretKey'),
},
});
export class Config {
static async upsert(key: string, value: any, isSecret?: boolean) {
return await upsertConfig({
body: {
key,
value,
is_secret: isSecret,
},
});
}
static async read(key: string) {
return await readConfig({
body: { key },
});
}
static async remove(key: string) {
return await removeConfig({
body: { key },
});
}
static async readAll() {
const response = await readAllConfig();
return response.data.config;
}
static async addExtension(name: string, config: any) {
return await addExtension({
body: { name, config },
});
}
static async removeExtension(name: string) {
return await removeExtension({
body: { key: name },
});
}
}

View File

@@ -0,0 +1,16 @@
// This file is auto-generated by @hey-api/openapi-ts
import type { ClientOptions } from './types.gen';
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from '@hey-api/client-fetch';
/**
* The `createClientConfig()` function will be called on client initialization
* and the returned object will become the client's initial configuration.
*
* You may want to initialize your client this way instead of calling
* `setConfig()`. This is useful for example if you're using Next.js
* to ensure your client always has the correct values.
*/
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
export const client = createClient(createConfig<ClientOptions>());

View File

@@ -0,0 +1,3 @@
// This file is auto-generated by @hey-api/openapi-ts
export * from './types.gen';
export * from './sdk.gen';

View File

@@ -0,0 +1,81 @@
// This file is auto-generated by @hey-api/openapi-ts
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
import type { ReadAllConfigData, ReadAllConfigResponse, RemoveExtensionData, RemoveExtensionResponse, AddExtensionData, AddExtensionResponse, ReadConfigData, RemoveConfigData, RemoveConfigResponse, UpsertConfigData, UpsertConfigResponse } from './types.gen';
import { client as _heyApiClient } from './client.gen';
export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
/**
* You can provide a client instance returned by `createClient()` instead of
* individual options. This might be also useful if you want to implement a
* custom client.
*/
client?: Client;
/**
* You can pass arbitrary values through the `meta` object. This can be
* used to access values that aren't defined as part of the SDK function.
*/
meta?: Record<string, unknown>;
};
export const readAllConfig = <ThrowOnError extends boolean = false>(options?: Options<ReadAllConfigData, ThrowOnError>) => {
return (options?.client ?? _heyApiClient).get<ReadAllConfigResponse, unknown, ThrowOnError>({
url: '/config',
...options
});
};
export const removeExtension = <ThrowOnError extends boolean = false>(options: Options<RemoveExtensionData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).delete<RemoveExtensionResponse, unknown, ThrowOnError>({
url: '/config/extension',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};
export const addExtension = <ThrowOnError extends boolean = false>(options: Options<AddExtensionData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).post<AddExtensionResponse, unknown, ThrowOnError>({
url: '/config/extension',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};
export const readConfig = <ThrowOnError extends boolean = false>(options: Options<ReadConfigData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({
url: '/config/read',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};
export const removeConfig = <ThrowOnError extends boolean = false>(options: Options<RemoveConfigData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).post<RemoveConfigResponse, unknown, ThrowOnError>({
url: '/config/remove',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};
export const upsertConfig = <ThrowOnError extends boolean = false>(options: Options<UpsertConfigData, ThrowOnError>) => {
return (options.client ?? _heyApiClient).post<UpsertConfigResponse, unknown, ThrowOnError>({
url: '/config/upsert',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};

View File

@@ -0,0 +1,165 @@
// This file is auto-generated by @hey-api/openapi-ts
export type ConfigKeyQuery = {
key: string;
};
export type ConfigResponse = {
config: {};
};
export type ExtensionQuery = {
config: unknown;
name: string;
};
export type UpsertConfigQuery = {
is_secret?: boolean | null;
key: string;
value: unknown;
};
export type ReadAllConfigData = {
body?: never;
path?: never;
query?: never;
url: '/config';
};
export type ReadAllConfigResponses = {
/**
* All configuration values retrieved successfully
*/
200: ConfigResponse;
};
export type ReadAllConfigResponse = ReadAllConfigResponses[keyof ReadAllConfigResponses];
export type RemoveExtensionData = {
body: ConfigKeyQuery;
path?: never;
query?: never;
url: '/config/extension';
};
export type RemoveExtensionErrors = {
/**
* Extension not found
*/
404: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type RemoveExtensionResponses = {
/**
* Extension removed successfully
*/
200: string;
};
export type RemoveExtensionResponse = RemoveExtensionResponses[keyof RemoveExtensionResponses];
export type AddExtensionData = {
body: ExtensionQuery;
path?: never;
query?: never;
url: '/config/extension';
};
export type AddExtensionErrors = {
/**
* Invalid request
*/
400: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type AddExtensionResponses = {
/**
* Extension added successfully
*/
200: string;
};
export type AddExtensionResponse = AddExtensionResponses[keyof AddExtensionResponses];
export type ReadConfigData = {
body: ConfigKeyQuery;
path?: never;
query?: never;
url: '/config/read';
};
export type ReadConfigErrors = {
/**
* Configuration key not found
*/
404: unknown;
};
export type ReadConfigResponses = {
/**
* Configuration value retrieved successfully
*/
200: unknown;
};
export type RemoveConfigData = {
body: ConfigKeyQuery;
path?: never;
query?: never;
url: '/config/remove';
};
export type RemoveConfigErrors = {
/**
* Configuration key not found
*/
404: unknown;
/**
* Internal server error
*/
500: unknown;
};
export type RemoveConfigResponses = {
/**
* Configuration value removed successfully
*/
200: string;
};
export type RemoveConfigResponse = RemoveConfigResponses[keyof RemoveConfigResponses];
export type UpsertConfigData = {
body: UpsertConfigQuery;
path?: never;
query?: never;
url: '/config/upsert';
};
export type UpsertConfigErrors = {
/**
* Internal server error
*/
500: unknown;
};
export type UpsertConfigResponses = {
/**
* Configuration value upserted successfully
*/
200: string;
};
export type UpsertConfigResponse = UpsertConfigResponses[keyof UpsertConfigResponses];
export type ClientOptions = {
baseUrl: `${string}://${string}` | (string & {});
};