import {z} from 'zod' export type ULID = string; export type GetApiV3OpenmeterCustomersCustomerIdEntitlementAccessArgs = {customerId: ULID}; export type GetApiV3OpenmeterCustomersCustomerIdEntitlementAccessOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const numeric = z.string(); export const billingEntitlementValueResult = z.object({type: z.enum(["metered", "static", "boolean"]), feature_key: z.string().min(1).max(64), has_access: z.boolean(), config: z.string().optional(), value: z.object({balance: z.string(), grant_balances: z.record(z.string(), numeric), overage: z.string(), total_available_grant_amount: z.string(), usage: z.string()}).optional()}); export const listCustomerEntitlementAccessResponseData = z.object({data: z.array(billingEntitlementValueResult)}); 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 customer entitlement access * * GET /v3/openmeter/customers/{customerId}/entitlement-access * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV3OpenmeterCustomersCustomerIdEntitlementAccess = async (args: GetApiV3OpenmeterCustomersCustomerIdEntitlementAccessArgs, options?: GetApiV3OpenmeterCustomersCustomerIdEntitlementAccessOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/openmeter/customers/${encodeURIComponent(String(args.customerId))}/entitlement-access${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(listCustomerEntitlementAccessResponseData, await res.json()) };