import {z} from 'zod' export type FeaturesListWithAvailabilityFlagExample = {CEP?: boolean | undefined, DOCS?: boolean | undefined, DYNAMO?: boolean | undefined, REDIS?: boolean | undefined, GEO_FABRICS?: boolean | undefined, GRAPHS?: boolean | undefined, KV?: boolean | undefined, LOCAL_COLLECTIONS?: boolean | undefined, STREAMS?: boolean | undefined, USERS?: boolean | undefined, EVENT_HUB?: boolean | undefined}; export type CreateApiApiFeaturesTenantTenantArgs = {tenant: unknown, body: FeaturesListWithAvailabilityFlagExample}; export type CreateApiApiFeaturesTenantTenantOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiFeaturesTenantTenantResponse = z.boolean(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Set features for a tenant * * POST /_api/features/tenant/{tenant} * * Also accepts auth: BearerAuth */ export const createApiApiFeaturesTenantTenant = async (args: CreateApiApiFeaturesTenantTenantArgs, options: CreateApiApiFeaturesTenantTenantOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/_api/features/tenant/${encodeURIComponent(String(args.tenant))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiFeaturesTenantTenantResponse, await res.json()) };