import {z} from 'zod' export type DeleteApiOrganizationsOrgIdCommitmentsIdArgs = {orgId: string, id: string}; export type DeleteApiOrganizationsOrgIdCommitmentsIdOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const commitmentFee = z.object({date: z.string(), amount: z.number().gt(0), servicePeriodStartDate: z.string(), servicePeriodEndDate: z.string()}); export const childBillingMode = z.enum(["PARENT_SUMMARY", "PARENT_BREAKDOWN", "CHILD"]); export const commitmentLineItemType = z.enum(["STANDING_CHARGE", "USAGE", "MINIMUM_SPEND", "COUNTER_RUNNING_TOTAL_CHARGE", "COUNTER_ADJUSTMENT_DEBIT"]); export const commitmentResponse = z.object({id: z.string(), version: z.number().int().optional(), accountId: z.string().optional(), billingPlanId: z.string().optional(), productIds: z.array(z.string()).optional(), startDate: z.string().optional(), endDate: z.string().optional(), currency: z.string().optional(), amount: z.number().optional(), amountPrePaid: z.number().optional(), amountFirstBill: z.number().optional(), amountSpent: z.number().optional(), overageSurchargePercent: z.number().optional(), separateOverageUsage: z.boolean().optional(), billingInterval: z.number().int().optional(), billingOffset: z.number().int().optional(), commitmentFeeDescription: z.string().optional(), commitmentUsageDescription: z.string().optional(), overageDescription: z.string().optional(), commitmentFeeBillInAdvance: z.boolean().optional(), billEpoch: z.string().optional(), contractId: z.string().optional(), accountingProductId: z.string().optional(), feesAccountingProductId: z.string().optional(), drawdownsAccountingProductId: z.string().optional(), feeDates: z.array(commitmentFee).optional(), childBillingMode: childBillingMode.optional(), lineItemTypes: z.array(commitmentLineItemType).optional(), dtCreated: z.string().optional(), dtLastModified: z.string().optional(), createdBy: z.string().optional(), lastModifiedBy: z.string().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 }; /** * Delete Commitment * * DELETE /organizations/{orgId}/commitments/{id} */ export const deleteApiOrganizationsOrgIdCommitmentsId = async (args: DeleteApiOrganizationsOrgIdCommitmentsIdArgs, options?: DeleteApiOrganizationsOrgIdCommitmentsIdOptions) => { const {baseUrl = "https://api.m3ter.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/${encodeURIComponent(String(args.orgId))}/commitments/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(commitmentResponse, await res.json()) };