import {z} from 'zod' export type GetApiV1CompaniesCompanyCodeOrSidApiKeysArgs = {company_code_or_sid: string, include_expired?: boolean | undefined, expires?: ('EXPIRES_ANY' | 'EXPIRES_NO' | 'EXPIRES_YES') | undefined, page_size?: number | undefined, page_token?: string | undefined}; export type GetApiV1CompaniesCompanyCodeOrSidApiKeysOptions = {baseUrl?: string | undefined, apiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const streemApiCompanyApiKey = z.object({api_key_id: z.string().optional(), api_key_secret: z.string().optional(), expires_at: z.string().optional(), company_sid: z.string().optional(), label: z.string().optional()}); export const streemApiListCompanyApiKeysResponse = z.object({api_keys: z.array(streemApiCompanyApiKey).optional(), next_page_token: z.string().optional(), total_size: z.number().int().optional()}); 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 }; /** * List API Keys * * GET /v1/companies/{company_code_or_sid}/api-keys * * Also accepts auth: bearer-auth */ export const getApiV1CompaniesCompanyCodeOrSidApiKeys = async (args: GetApiV1CompaniesCompanyCodeOrSidApiKeysArgs, options?: GetApiV1CompaniesCompanyCodeOrSidApiKeysOptions) => { const {baseUrl = "https://api.prod-us.streem.cloud", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.include_expired != null) query.append("include_expired", String(args.include_expired)) if (args.expires != null) query.append("expires", String(args.expires)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (apiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${apiKey.username}:${apiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.company_code_or_sid))}/api-keys${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(streemApiListCompanyApiKeysResponse, await res.json()) };