import {z} from 'zod' export type ReportScheduleKey = string; export type SchemeFeeDetailsReportMimeType = 'application/json' | 'application/x-ndjson' | 'text/csv'; export type Hour = number; export type SchemeFeeDetailsTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type ComponentsSchemasReference = string; export type DistributionKey = string; export type Distributions = Array; export type NetworkFundsTransfersReportMimeType = 'text/csv' | 'application/json' | 'application/x-ndjson'; export type NetworkFundsTransfersTrigger = {type: 'interval', cadence: 'daily', hour: Hour}; export type MerchantPayoutReportMimeType = 'text/csv'; export type MerchantPayoutScheduleTrigger = {type: 'interval', cadence: 'daily', hour: Hour}; export type ReconciliationDetailsReportMimeType = 'text/csv' | 'application/json' | 'application/x-ndjson'; export type ReconciliationDetailsScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type ChargesReportMimeType = 'text/csv'; export type ChargesScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type DisputeHistoryEventsReportMimeType = 'text/csv' | 'application/json' | 'application/x-ndjson'; export type DisputeHistoryEventsScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type FraudNotificationsReportMimeType = 'text/csv' | 'application/json' | 'application/x-ndjson'; export type FraudNotificationsScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type SettlementDetailsReportMimeType = 'text/csv' | 'application/x-ndjson'; export type SettlementDetailsScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type DayOfMonth = number; export type AmmfReportScheduleTrigger = {type: 'interval', cadence: 'monthly', day: DayOfMonth, hour: Hour}; export type AmmfReportMimeType = 'application/vnd.ms-excel'; export type UpdateReportScheduleRequest = {mimeType?: SchemeFeeDetailsReportMimeType | undefined, trigger?: SchemeFeeDetailsTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: NetworkFundsTransfersReportMimeType | undefined, trigger?: NetworkFundsTransfersTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: MerchantPayoutReportMimeType | undefined, trigger?: MerchantPayoutScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: ReconciliationDetailsReportMimeType | undefined, trigger?: ReconciliationDetailsScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: ChargesReportMimeType | undefined, trigger?: ChargesScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: DisputeHistoryEventsReportMimeType | undefined, trigger?: DisputeHistoryEventsScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: FraudNotificationsReportMimeType | undefined, trigger?: FraudNotificationsScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {mimeType?: SettlementDetailsReportMimeType | undefined, trigger?: SettlementDetailsScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {trigger?: AmmfReportScheduleTrigger | undefined, reference?: ComponentsSchemasReference | undefined, mimeType?: AmmfReportMimeType | undefined, distributions?: Distributions | undefined}; export type PatchApiReportSchedulesReportScheduleKeyArgs = {reportScheduleKey: ReportScheduleKey, body: UpdateReportScheduleRequest}; export type PatchApiReportSchedulesReportScheduleKeyOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const schemeFeeDetailsReportName = z.literal("SchemeFeeDetails"); export const reportScheduleKey = z.string().min(10).max(120); export const componentsSchemasStatus = z.enum(["active", "archived"]); export const agentKey = z.string(); export const openapiComponentsSchemasCreated2 = z.string(); export const openapiComponentsSchemasLastModified2 = z.string(); export const openapiComponentsSchemasVersion = z.number().int(); export const componentsSchemasReference = z.string().max(120); export const distributionKey = z.string().min(10).max(120); export const distributions = z.array(distributionKey); export const schemeFeeDetailsReportMimeType = z.enum(["application/json", "application/x-ndjson", "text/csv"]); export const hour = z.number().int().gte(0).lte(23); export const schemeFeeDetailsTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const networkFundsTransfersReportName = z.literal("NetworkFundsTransfers"); export const networkFundsTransfersReportMimeType = z.enum(["text/csv", "application/json", "application/x-ndjson"]); export const networkFundsTransfersTrigger = z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour}); export const merchantPayoutReportName = z.literal("MerchantPayout"); export const merchantPayoutReportMimeType = z.literal("text/csv"); export const merchantPayoutScheduleTrigger = z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour}); export const merchantPayoutReportType = z.literal("Standardized"); export const merchantPayoutReportScheduleParameters = z.object({type: merchantPayoutReportType}); export const reconciliationDetailsReportName = z.literal("ReconciliationDetails"); export const reconciliationDetailsReportMimeType = z.enum(["text/csv", "application/json", "application/x-ndjson"]); export const reconciliationDetailsScheduleTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const chargesReportName = z.literal("Charges"); export const chargesReportMimeType = z.literal("text/csv"); export const chargesScheduleTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const disputeHistoryEventsReportName = z.literal("DisputeHistoryEvents"); export const disputeHistoryEventsReportMimeType = z.enum(["text/csv", "application/json", "application/x-ndjson"]); export const disputeHistoryEventsScheduleTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const fraudNotificationsReportName = z.literal("FraudNotifications"); export const fraudNotificationsReportMimeType = z.enum(["text/csv", "application/json", "application/x-ndjson"]); export const fraudNotificationsScheduleTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const settlementDetailsReportName = z.literal("SettlementDetails"); export const settlementDetailsReportMimeType = z.enum(["text/csv", "application/x-ndjson"]); export const settlementDetailsScheduleTrigger = z.union([z.object({type: z.literal("interval"), cadence: z.literal("hourly")}), z.object({type: z.literal("interval"), cadence: z.literal("daily"), hour: hour})]); export const aMMFReportName = z.literal("AmmfReport"); export const ammfReportMimeType = z.literal("application/vnd.ms-excel"); export const ammfAcquirerIdCode = z.string(); export const ammfDirectSubmission = z.boolean(); export const aMMFReportScheduleParameters = z.object({acquirerIdCode: ammfAcquirerIdCode, directSubmission: ammfDirectSubmission.optional()}); export const dayOfMonth = z.number().int().gte(1).lte(28); export const ammfReportScheduleTrigger = z.object({type: z.literal("interval"), cadence: z.literal("monthly"), day: dayOfMonth, hour: hour}); export const reportScheduleResponse = z.union([z.object({reportName: schemeFeeDetailsReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: schemeFeeDetailsReportMimeType, trigger: schemeFeeDetailsTrigger}), z.object({reportName: networkFundsTransfersReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: networkFundsTransfersReportMimeType, trigger: networkFundsTransfersTrigger}), z.object({reportName: merchantPayoutReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: merchantPayoutReportMimeType, trigger: merchantPayoutScheduleTrigger, parameters: merchantPayoutReportScheduleParameters}), z.object({reportName: reconciliationDetailsReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: reconciliationDetailsReportMimeType, trigger: reconciliationDetailsScheduleTrigger}), z.object({reportName: chargesReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: chargesReportMimeType, trigger: chargesScheduleTrigger}), z.object({reportName: disputeHistoryEventsReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: disputeHistoryEventsReportMimeType, trigger: disputeHistoryEventsScheduleTrigger}), z.object({reportName: fraudNotificationsReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: fraudNotificationsReportMimeType, trigger: fraudNotificationsScheduleTrigger}), z.object({reportName: settlementDetailsReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: settlementDetailsReportMimeType, trigger: settlementDetailsScheduleTrigger}), z.object({reportName: aMMFReportName, key: reportScheduleKey, status: componentsSchemasStatus, agentKey: agentKey, created: openapiComponentsSchemasCreated2, lastModified: openapiComponentsSchemasLastModified2.optional(), version: openapiComponentsSchemasVersion, reference: componentsSchemasReference.optional(), distributions: distributions.optional(), mimeType: ammfReportMimeType, parameters: aMMFReportScheduleParameters, trigger: ammfReportScheduleTrigger})]); 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 }; /** * Update a Report Schedule * * PATCH /reportSchedules/{reportScheduleKey} * * Also accepts auth: BearerToken */ export const patchApiReportSchedulesReportScheduleKey = async (args: PatchApiReportSchedulesReportScheduleKeyArgs, options?: PatchApiReportSchedulesReportScheduleKeyOptions) => { const {baseUrl = "https://eu-west-1.api.silverflow.com/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/merge-patch+json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/reportSchedules/${encodeURIComponent(String(args.reportScheduleKey))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(reportScheduleResponse, await res.json()) };