import {z} from 'zod' export type SchemeFeeDetailsReportName = 'SchemeFeeDetails'; 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 NetworkFundsTransfersReportName = 'NetworkFundsTransfers'; export type NetworkFundsTransfersReportMimeType = 'text/csv' | 'application/json' | 'application/x-ndjson'; export type NetworkFundsTransfersTrigger = {type: 'interval', cadence: 'daily', hour: Hour}; export type MerchantPayoutReportName = 'MerchantPayout'; export type MerchantPayoutReportMimeType = 'text/csv'; export type MerchantPayoutScheduleTrigger = {type: 'interval', cadence: 'daily', hour: Hour}; export type MerchantPayoutReportType = 'Standardized'; export type MerchantPayoutReportScheduleParameters = {type: MerchantPayoutReportType}; export type ReconciliationDetailsReportName = 'ReconciliationDetails'; 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 ChargesReportName = 'Charges'; export type ChargesReportMimeType = 'text/csv'; export type ChargesScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type DisputeHistoryEventsReportName = 'DisputeHistoryEvents'; 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 FraudNotificationsReportName = 'FraudNotifications'; 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 SettlementDetailsReportName = 'SettlementDetails'; export type SettlementDetailsReportMimeType = 'text/csv' | 'application/x-ndjson'; export type SettlementDetailsScheduleTrigger = {type: 'interval', cadence: 'hourly'} | {type: 'interval', cadence: 'daily', hour: Hour}; export type AMMFReportName = 'AmmfReport'; export type DayOfMonth = number; export type AmmfReportScheduleTrigger = {type: 'interval', cadence: 'monthly', day: DayOfMonth, hour: Hour}; export type AmmfAcquirerIdCode = string; export type AmmfDirectSubmission = boolean; export type AMMFReportScheduleParameters = {acquirerIdCode: AmmfAcquirerIdCode, directSubmission?: AmmfDirectSubmission | undefined}; export type AmmfReportMimeType = 'application/vnd.ms-excel'; export type CreateReportScheduleRequest = {reportName: SchemeFeeDetailsReportName, mimeType: SchemeFeeDetailsReportMimeType, trigger: SchemeFeeDetailsTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: NetworkFundsTransfersReportName, mimeType: NetworkFundsTransfersReportMimeType, trigger: NetworkFundsTransfersTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: MerchantPayoutReportName, mimeType: MerchantPayoutReportMimeType, trigger: MerchantPayoutScheduleTrigger, parameters: MerchantPayoutReportScheduleParameters, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: ReconciliationDetailsReportName, mimeType: ReconciliationDetailsReportMimeType, trigger: ReconciliationDetailsScheduleTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: ChargesReportName, mimeType: ChargesReportMimeType, trigger: ChargesScheduleTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: DisputeHistoryEventsReportName, mimeType: DisputeHistoryEventsReportMimeType, trigger: DisputeHistoryEventsScheduleTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: FraudNotificationsReportName, mimeType: FraudNotificationsReportMimeType, trigger: FraudNotificationsScheduleTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: SettlementDetailsReportName, mimeType: SettlementDetailsReportMimeType, trigger: SettlementDetailsScheduleTrigger, reference?: ComponentsSchemasReference | undefined, distributions?: Distributions | undefined} | {reportName: AMMFReportName, trigger: AmmfReportScheduleTrigger, parameters: AMMFReportScheduleParameters, reference?: ComponentsSchemasReference | undefined, mimeType: AmmfReportMimeType, distributions?: Distributions | undefined}; export type CreateApiReportSchedulesArgs = {body: CreateReportScheduleRequest}; export type CreateApiReportSchedulesOptions = {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 }; /** * Create a Report Schedule * * POST /reportSchedules * * Also accepts auth: BearerToken */ export const createApiReportSchedules = async (args: CreateApiReportSchedulesArgs, options?: CreateApiReportSchedulesOptions) => { 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/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/reportSchedules${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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()) };