import {z} from 'zod' export type GetApiV2UserCustomerBillingPeriodsArgs = {'If-None-Match'?: string | undefined}; export type GetApiV2UserCustomerBillingPeriodsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const beezUPCommonDocUrl = z.string(); export const beezUPCommonHref = z.string(); export const beezUPCommonOperationId = z.string(); export const beezUPCommonHttpMethod = z.enum(["GET", "POST", "PATCH", "DELETE", "PUT", "HEAD"]); export const beezUPCommonParameterIn = z.enum(["path", "header", "query", "body"]); export const beezUPCommonParameterType = z.enum(["string", "integer", "number", "boolean", "object", "array", "date", "date-time"]); export const beezUPCommonLOVLink3 = z.object({href: z.string(), method: beezUPCommonHttpMethod.optional()}); export const beezUPCommonLinkParameterProperty3 = z.object({label: z.string().optional(), value: z.object({}).optional(), required: z.boolean().optional(), type: beezUPCommonParameterType, lovLink: beezUPCommonLOVLink3.optional(), lovRequired: z.boolean().optional(), description: z.string().optional(), schema: z.string().optional()}); export const beezUPCommonLinkParameter3 = z.object({label: z.string().optional(), value: z.object({}).optional(), required: z.boolean().optional(), in: beezUPCommonParameterIn, type: beezUPCommonParameterType.optional(), lovLink: beezUPCommonLOVLink3.optional(), lovRequired: z.boolean().optional(), description: z.string().optional(), schema: z.string().optional(), properties: z.record(z.string(), beezUPCommonLinkParameterProperty3).optional()}); export const beezUPCommonSuccessSummary = z.object({successCode: z.string().optional(), successMessage: z.string().optional(), successArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional()}); export const beezUPCommonExceptionDetail = z.object({helpLink: z.string().optional(), message: z.string().optional(), stackTrace: z.string().optional(), type: z.string().optional()}); export const beezUPCommonErrorSummary = z.object({utcDate: z.string().optional(), errorGuid: z.string().optional(), errorCode: z.string().optional(), errorMessage: z.string().optional(), technicalErrorMessage: z.string().optional(), exceptionDetail: beezUPCommonExceptionDetail.optional(), errorArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional(), source: z.string().optional()}); export const beezUPCommonWarningSummary = z.object({technicalErrorMessage: z.string().optional(), warningMessage: z.string().optional(), warningCode: z.string().optional(), warningArguments: z.record(z.string(), z.string()).optional()}); export const beezUPCommonInfoSummary = z.object({informationCode: z.string().optional(), informationMessage: z.string().optional(), informationArguments: z.record(z.string(), z.string()).optional(), propertyName: z.string().optional(), propertyValue: z.string().optional(), objectName: z.string().optional()}); export const beezUPCommonInfoSummaries = z.object({successes: z.array(beezUPCommonSuccessSummary).optional(), errors: z.array(beezUPCommonErrorSummary).optional(), warnings: z.array(beezUPCommonWarningSummary).optional(), informations: z.array(beezUPCommonInfoSummary).optional()}); export const linksGetBillingPeriodsLink = z.object({label: z.string().optional(), docUrl: beezUPCommonDocUrl.optional(), description: z.string().optional(), href: beezUPCommonHref, operationId: beezUPCommonOperationId.optional(), method: beezUPCommonHttpMethod.optional(), parameters: z.record(z.string(), beezUPCommonLinkParameter3).optional(), urlTemplated: z.boolean().optional(), allRequiredParamsProvided: z.boolean().optional(), allOptionalParamsProvided: z.boolean().optional(), info: beezUPCommonInfoSummaries.optional()}); export const billingPeriodListLinks = z.object({self: linksGetBillingPeriodsLink.optional()}); export const billingPeriod = z.object({billingPeriodInMonth: z.number().int(), discountPercentage: z.number()}); export const billingPeriodList = z.object({links: billingPeriodListLinks, billingPeriods: z.array(billingPeriod)}); 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 }; /** * Get billing periods conditions * * GET /v2/user/customer/billingPeriods */ export const getApiV2UserCustomerBillingPeriods = async (args: GetApiV2UserCustomerBillingPeriodsArgs, options?: GetApiV2UserCustomerBillingPeriodsOptions) => { const {baseUrl = "https://api.beezup.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['If-None-Match'] != null) headers.set("If-None-Match", String(args['If-None-Match'])) const url = `${baseUrl.replace(/\/+$/, '')}/v2/user/customer/billingPeriods${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(billingPeriodList, await res.json()) };