UNPKG

@paykit-sdk/core

Version:

The Payment Toolkit for Typescript

54 lines (50 loc) 1.36 kB
'use strict'; // src/error.ts var PayKitError = class extends Error { code; statusCode; provider; method; context; constructor(message, options) { super(message); this.name = this.constructor.name; this.code = options?.code || "PAYKIT_ERROR"; this.statusCode = options?.statusCode || 500; this.provider = options?.provider; this.method = options?.method; this.context = options?.context; if (options?.cause) { this.cause = options.cause; } Error.captureStackTrace(this, this.constructor); } }; var ConfigurationError = class extends PayKitError { constructor(message, options) { super(message, { code: "CONFIGURATION_ERROR", statusCode: 500, provider: options?.provider, context: { missingKeys: options?.missingKeys } }); this.stack = void 0; } }; // src/paykit-provider.ts var AbstractPayKitProvider = class { providerVersion = process.env.PROVIDER_VERSION; constructor(schema, options, providerName) { const { error } = schema.safeParse(options); if (error) { throw new ConfigurationError( `Invalid ${providerName} configuration`, { provider: providerName, missingKeys: Object.keys(error.flatten().fieldErrors ?? {}) } ); } } }; exports.AbstractPayKitProvider = AbstractPayKitProvider;