@nehorai/payments-drizzle 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +1310 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +1289 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-health.drizzle-repository-DfRo4qJ8.d.cts +185 -0
- package/dist/provider-health.drizzle-repository-DfRo4qJ8.d.ts +185 -0
- package/dist/repositories/index.cjs +1190 -0
- package/dist/repositories/index.cjs.map +1 -0
- package/dist/repositories/index.d.cts +16 -0
- package/dist/repositories/index.d.ts +16 -0
- package/dist/repositories/index.js +1177 -0
- package/dist/repositories/index.js.map +1 -0
- package/dist/schema/index.cjs +276 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.cts +1729 -0
- package/dist/schema/index.d.ts +1729 -0
- package/dist/schema/index.js +269 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/storage/index.cjs +124 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +52 -0
- package/dist/storage/index.d.ts +52 -0
- package/dist/storage/index.js +96 -0
- package/dist/storage/index.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schema/payment-transactions.ts","../src/schema/payment-methods.ts","../src/schema/webhook-events.ts","../src/schema/payment-audit-log.ts","../src/schema/provider-health.ts","../src/repositories/base-drizzle.repository.ts","../src/repositories/transaction.drizzle-repository.ts","../src/repositories/payment-method.drizzle-repository.ts","../src/repositories/webhook-event.drizzle-repository.ts","../src/repositories/audit-log.drizzle-repository.ts","../src/repositories/provider-health.drizzle-repository.ts","../src/storage/drizzle-circuit-breaker-storage.ts","../src/factory.ts"],"sourcesContent":["/**\n * @nehorai/payments-drizzle\n *\n * Drizzle ORM adapter for @nehorai/payments.\n * Provides PostgreSQL schema definitions, repository implementations,\n * and database-backed circuit breaker storage.\n *\n * Subpath exports:\n * - @nehorai/payments-drizzle/schema - Drizzle pgTable definitions\n * - @nehorai/payments-drizzle/repositories - Repository implementations + factory\n * - @nehorai/payments-drizzle/storage - DrizzleCircuitBreakerStorage\n */\n\n// Schema\nexport {\n paymentTransactions,\n paymentMethods,\n paymentWebhookEvents,\n paymentAuditLog,\n providerHealth,\n type PaymentTransactionStatus,\n type PaymentTransactionType,\n type PaymentTaxInvoiceStatus,\n type PaymentMethodType,\n type CardBrandType,\n type WebhookEventStatus,\n type AuditLogAction,\n type AuditLogTrigger,\n type CircuitBreakerState,\n} from './schema/index.js'\n\n// Repositories\nexport {\n type DrizzleDB,\n toCamelCase,\n toSnakeCase,\n applyPagination,\n parseNumeric,\n normalizeArrayFilter,\n DrizzleTransactionRepository,\n DrizzlePaymentMethodRepository,\n DrizzleWebhookEventRepository,\n DrizzleAuditLogRepository,\n DrizzleProviderHealthRepository,\n} from './repositories/index.js'\n\n// Storage\nexport {\n DrizzleCircuitBreakerStorage,\n createDrizzleCircuitBreakerStorage,\n} from './storage/index.js'\n\n// Factory\nexport {\n createDrizzleRepositories,\n createDrizzlePaymentServices,\n type DrizzlePaymentServicesOptions,\n} from './factory.js'\n","/**\r\n * PaymentOS - Payment Transactions Schema\r\n *\r\n * Core table for tracking all payment operations.\r\n * Implements Two-Phase Commit (J5) pattern with authorize/capture flow.\r\n *\r\n * Note: User FK is optional and configured via schema-config.ts\r\n */\r\n\r\nimport { pgTable, uuid, text, numeric, timestamp, jsonb, index, unique } from 'drizzle-orm/pg-core'\r\n\r\n// ============================================================================\r\n// Type Definitions\r\n// ============================================================================\r\n\r\n/**\r\n * Payment transaction states (strict state machine)\r\n * @see src/lib/payments/types/state-machine.ts for transition rules\r\n */\r\nexport type PaymentTransactionStatus =\r\n | 'created'\r\n | 'pending_authorization'\r\n | 'authorized'\r\n | 'capturing'\r\n | 'captured'\r\n | 'voided'\r\n | 'failed'\r\n | 'expired'\r\n | 'partially_refunded'\r\n | 'fully_refunded'\r\n\r\n/**\r\n * Payment transaction types\r\n */\r\nexport type PaymentTransactionType =\r\n | 'one_time_purchase'\r\n | 'subscription_initial'\r\n | 'subscription_renewal'\r\n | 'refund'\r\n\r\n/**\r\n * Tax invoice status (Israeli compliance)\r\n */\r\nexport type PaymentTaxInvoiceStatus = 'pending' | 'generated' | 'sent' | 'failed'\r\n\r\n// ============================================================================\r\n// Schema Definition\r\n// ============================================================================\r\n\r\n/**\r\n * Payment transactions table\r\n *\r\n * FK to user table is NOT defined here - it's application-specific.\r\n * The user_id column stores the UUID, but the FK constraint should be\r\n * added via migration if needed for your specific user table.\r\n *\r\n * To add FK constraint, create a migration:\r\n * ```sql\r\n * ALTER TABLE payment_transactions\r\n * ADD CONSTRAINT payment_transactions_user_id_fkey\r\n * FOREIGN KEY (user_id) REFERENCES your_users_table(id) ON DELETE CASCADE;\r\n * ```\r\n */\r\nexport const paymentTransactions = pgTable(\r\n 'payment_transactions',\r\n {\r\n id: uuid('id').defaultRandom().primaryKey(),\r\n\r\n // Idempotency - prevents duplicate charges\r\n internal_payment_id: text('internal_payment_id').notNull(),\r\n idempotency_key: text('idempotency_key'),\r\n\r\n // User association (FK configured at application level)\r\n user_id: uuid('user_id').notNull(),\r\n\r\n // Transaction classification\r\n transaction_type: text('transaction_type').$type<PaymentTransactionType>().notNull(),\r\n status: text('status').$type<PaymentTransactionStatus>().notNull().default('created'),\r\n\r\n // Amounts in smallest currency unit (cents/agorot)\r\n amount_minor: numeric('amount_minor').notNull(),\r\n currency: text('currency').notNull().default('USD'),\r\n\r\n // Original amount if currency converted\r\n original_amount_minor: numeric('original_amount_minor'),\r\n original_currency: text('original_currency'),\r\n currency_conversion_rate: numeric('currency_conversion_rate'),\r\n\r\n // Provider information\r\n provider: text('provider').notNull(), // stripe, hyp, cardcom\r\n provider_transaction_id: text('provider_transaction_id'),\r\n provider_authorization_code: text('provider_authorization_code'),\r\n provider_metadata: jsonb('provider_metadata').$type<Record<string, unknown>>(),\r\n\r\n // Two-phase commit tracking (J5)\r\n authorized_at: timestamp('authorized_at', { withTimezone: true }),\r\n captured_at: timestamp('captured_at', { withTimezone: true }),\r\n voided_at: timestamp('voided_at', { withTimezone: true }),\r\n capture_deadline: timestamp('capture_deadline', { withTimezone: true }),\r\n\r\n // Refund tracking\r\n refunded_amount_minor: numeric('refunded_amount_minor').default('0'),\r\n last_refund_at: timestamp('last_refund_at', { withTimezone: true }),\r\n\r\n // Tax invoice (Israeli requirement)\r\n tax_invoice_status: text('tax_invoice_status')\r\n .$type<PaymentTaxInvoiceStatus>()\r\n .default('pending'),\r\n tax_invoice_number: text('tax_invoice_number'),\r\n tax_invoice_url: text('tax_invoice_url'),\r\n\r\n // Error tracking\r\n failure_code: text('failure_code'),\r\n failure_message: text('failure_message'),\r\n failure_details: jsonb('failure_details'),\r\n\r\n // Application metadata\r\n description: text('description'),\r\n metadata: jsonb('metadata').$type<{\r\n credit_package_id?: string\r\n subscription_plan_id?: string\r\n credits_amount?: number\r\n [key: string]: unknown\r\n }>(),\r\n\r\n // Timestamps\r\n created_at: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),\r\n updated_at: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),\r\n },\r\n (table) => ({\r\n // Performance indexes\r\n userIdx: index('payment_transactions_user_idx').on(table.user_id),\r\n statusIdx: index('payment_transactions_status_idx').on(table.status),\r\n providerIdx: index('payment_transactions_provider_idx').on(table.provider),\r\n providerTxIdx: index('payment_transactions_provider_tx_idx').on(table.provider_transaction_id),\r\n createdAtIdx: index('payment_transactions_created_at_idx').on(table.created_at),\r\n // Unique constraints for idempotency\r\n internalIdUnique: unique('payment_transactions_internal_id_unique').on(\r\n table.internal_payment_id\r\n ),\r\n idempotencyUnique: unique('payment_transactions_idempotency_unique').on(table.idempotency_key),\r\n })\r\n)\r\n","/**\r\n * PaymentOS - Payment Methods Schema\r\n *\r\n * Stores tokenized payment methods (PCI-compliant - no full card numbers).\r\n * Used for saved cards and recurring billing.\r\n *\r\n * Note: User FK is optional and configured via schema-config.ts\r\n */\r\n\r\nimport { pgTable, uuid, text, boolean, timestamp, jsonb, index } from 'drizzle-orm/pg-core'\r\n\r\n// ============================================================================\r\n// Type Definitions\r\n// ============================================================================\r\n\r\n/**\r\n * Payment method types\r\n */\r\nexport type PaymentMethodType = 'card' | 'bank_account' | 'paypal'\r\n\r\n/**\r\n * Card brands\r\n */\r\nexport type CardBrandType =\r\n | 'visa'\r\n | 'mastercard'\r\n | 'amex'\r\n | 'discover'\r\n | 'isracard'\r\n | 'diners'\r\n | 'unknown'\r\n\r\n// ============================================================================\r\n// Schema Definition\r\n// ============================================================================\r\n\r\n/**\r\n * Payment methods table\r\n *\r\n * FK to user table is NOT defined here - it's application-specific.\r\n * The user_id column stores the UUID, but the FK constraint should be\r\n * added via migration if needed for your specific user table.\r\n *\r\n * To add FK constraint, create a migration:\r\n * ```sql\r\n * ALTER TABLE payment_methods\r\n * ADD CONSTRAINT payment_methods_user_id_fkey\r\n * FOREIGN KEY (user_id) REFERENCES your_users_table(id) ON DELETE CASCADE;\r\n * ```\r\n */\r\nexport const paymentMethods = pgTable(\r\n 'payment_methods',\r\n {\r\n id: uuid('id').defaultRandom().primaryKey(),\r\n\r\n // User association (FK configured at application level)\r\n user_id: uuid('user_id').notNull(),\r\n\r\n // Method type\r\n type: text('type').$type<PaymentMethodType>().notNull(),\r\n\r\n // Provider information\r\n provider: text('provider').notNull(), // stripe, hyp, cardcom\r\n provider_payment_method_id: text('provider_payment_method_id').notNull(),\r\n\r\n // Card details (tokenized, never full numbers)\r\n card_brand: text('card_brand').$type<CardBrandType>(),\r\n card_last4: text('card_last4'),\r\n card_exp_month: text('card_exp_month'),\r\n card_exp_year: text('card_exp_year'),\r\n card_bin: text('card_bin'), // First 6-8 digits for routing\r\n\r\n // State\r\n is_default: boolean('is_default').default(false),\r\n is_active: boolean('is_active').default(true),\r\n\r\n // Provider-specific data\r\n provider_metadata: jsonb('provider_metadata').$type<Record<string, unknown>>(),\r\n\r\n // Timestamps\r\n created_at: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),\r\n updated_at: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),\r\n last_used_at: timestamp('last_used_at', { withTimezone: true }),\r\n },\r\n (table) => ({\r\n // Performance indexes\r\n userIdx: index('payment_methods_user_idx').on(table.user_id),\r\n userDefaultIdx: index('payment_methods_user_default_idx').on(table.user_id, table.is_default),\r\n providerIdx: index('payment_methods_provider_idx').on(table.provider),\r\n providerMethodIdx: index('payment_methods_provider_method_idx').on(\r\n table.provider_payment_method_id\r\n ),\r\n cardBinIdx: index('payment_methods_card_bin_idx').on(table.card_bin),\r\n })\r\n)\r\n","import {\r\n pgTable,\r\n uuid,\r\n text,\r\n timestamp,\r\n jsonb,\r\n index,\r\n unique,\r\n} from 'drizzle-orm/pg-core'\r\n\r\n/**\r\n * Webhook processing status\r\n */\r\nexport type WebhookEventStatus =\r\n | 'pending'\r\n | 'processing'\r\n | 'processed'\r\n | 'failed'\r\n | 'ignored'\r\n\r\n/**\r\n * Payment webhook events table\r\n * Stores all incoming webhooks for idempotent processing.\r\n * Ensures each provider event is processed exactly once.\r\n */\r\nexport const paymentWebhookEvents = pgTable(\r\n 'payment_webhook_events',\r\n {\r\n id: uuid('id').defaultRandom().primaryKey(),\r\n\r\n // Event identification\r\n provider: text('provider').notNull(), // stripe, hyp, cardcom\r\n provider_event_id: text('provider_event_id').notNull(),\r\n event_type: text('event_type').notNull(),\r\n\r\n // Processing state\r\n status: text('status')\r\n .$type<WebhookEventStatus>()\r\n .notNull()\r\n .default('pending'),\r\n attempts: text('attempts').default('0'),\r\n last_attempt_at: timestamp('last_attempt_at', { withTimezone: true }),\r\n\r\n // Linked transaction (if applicable)\r\n transaction_id: uuid('transaction_id'),\r\n\r\n // Event payload (store for debugging and retry)\r\n payload: jsonb('payload').$type<Record<string, unknown>>().notNull(),\r\n signature: text('signature'),\r\n\r\n // Error tracking\r\n error_message: text('error_message'),\r\n error_details: jsonb('error_details'),\r\n\r\n // Timestamps\r\n received_at: timestamp('received_at', { withTimezone: true })\r\n .notNull()\r\n .defaultNow(),\r\n processed_at: timestamp('processed_at', { withTimezone: true }),\r\n created_at: timestamp('created_at', { withTimezone: true })\r\n .notNull()\r\n .defaultNow(),\r\n },\r\n (table) => ({\r\n // Unique constraint for idempotency\r\n providerEventUnique: unique('webhook_events_provider_event_unique').on(\r\n table.provider,\r\n table.provider_event_id\r\n ),\r\n // Performance indexes\r\n statusIdx: index('webhook_events_status_idx').on(table.status),\r\n transactionIdx: index('webhook_events_transaction_idx').on(\r\n table.transaction_id\r\n ),\r\n receivedAtIdx: index('webhook_events_received_at_idx').on(table.received_at),\r\n providerIdx: index('webhook_events_provider_idx').on(table.provider),\r\n eventTypeIdx: index('webhook_events_event_type_idx').on(table.event_type),\r\n })\r\n)\r\n","/**\n * @nehorai/payments-drizzle - Payment Audit Log Schema\n *\n * Immutable audit trail for all payment state changes.\n * Used for debugging, compliance, and dispute resolution.\n */\n\nimport {\n pgTable,\n uuid,\n text,\n timestamp,\n jsonb,\n index,\n} from 'drizzle-orm/pg-core'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\n/**\n * Audit log action types\n */\nexport type AuditLogAction =\n | 'created'\n | 'status_changed'\n | 'authorized'\n | 'captured'\n | 'voided'\n | 'refund_initiated'\n | 'refund_completed'\n | 'webhook_received'\n | 'webhook_processed'\n | 'error_occurred'\n | 'retry_attempted'\n | 'manual_intervention'\n\n/**\n * Who/what triggered the action\n */\nexport type AuditLogTrigger =\n | 'user'\n | 'webhook'\n | 'system'\n | 'admin'\n | 'cron'\n | 'api'\n\n// ============================================================================\n// Schema Definition\n// ============================================================================\n\n/**\n * Payment audit log table\n * Immutable audit trail for all payment state changes.\n * Used for debugging, compliance, and dispute resolution.\n */\nexport const paymentAuditLog = pgTable(\n 'payment_audit_log',\n {\n id: uuid('id').defaultRandom().primaryKey(),\n\n // What transaction was affected\n transaction_id: uuid('transaction_id').notNull(),\n\n // What action occurred\n action: text('action').$type<AuditLogAction>().notNull(),\n\n // State before and after\n previous_state: jsonb('previous_state'),\n new_state: jsonb('new_state').notNull(),\n\n // Who/what triggered this change\n triggered_by: text('triggered_by').$type<AuditLogTrigger>().notNull(),\n triggered_by_id: uuid('triggered_by_id'), // User ID if applicable\n\n // Request context\n ip_address: text('ip_address'),\n user_agent: text('user_agent'),\n\n // Correlation for distributed tracing\n correlation_id: text('correlation_id'),\n\n // Additional context\n metadata: jsonb('metadata').$type<Record<string, unknown>>(),\n\n // Immutable timestamp (never updated)\n created_at: timestamp('created_at', { withTimezone: true })\n .notNull()\n .defaultNow(),\n },\n (table) => ({\n // Performance indexes\n transactionIdx: index('payment_audit_log_transaction_idx').on(\n table.transaction_id\n ),\n actionIdx: index('payment_audit_log_action_idx').on(table.action),\n correlationIdx: index('payment_audit_log_correlation_idx').on(\n table.correlation_id\n ),\n createdAtIdx: index('payment_audit_log_created_at_idx').on(table.created_at),\n triggeredByIdx: index('payment_audit_log_triggered_by_idx').on(\n table.triggered_by\n ),\n })\n)\n","/**\n * @nehorai/payments-drizzle - Provider Health Schema\n *\n * Tracks payment provider health for circuit breaker pattern.\n * Used for intelligent failover when providers experience issues.\n */\n\nimport {\n pgTable,\n uuid,\n text,\n numeric,\n timestamp,\n jsonb,\n index,\n unique,\n} from 'drizzle-orm/pg-core'\n\n// ============================================================================\n// Type Definitions\n// ============================================================================\n\n/**\n * Circuit breaker states\n */\nexport type CircuitBreakerState = 'closed' | 'open' | 'half_open'\n\n// ============================================================================\n// Schema Definition\n// ============================================================================\n\n/**\n * Provider health table\n * Tracks payment provider health for circuit breaker pattern.\n * Used for intelligent failover when providers experience issues.\n */\nexport const providerHealth = pgTable(\n 'payment_provider_health',\n {\n id: uuid('id').defaultRandom().primaryKey(),\n\n // Provider identification\n provider: text('provider').notNull(), // stripe, hyp, cardcom\n\n // Circuit breaker state\n circuit_state: text('circuit_state')\n .$type<CircuitBreakerState>()\n .notNull()\n .default('closed'),\n\n // Failure tracking\n failure_count: text('failure_count').default('0'),\n success_count: text('success_count').default('0'),\n last_failure_at: timestamp('last_failure_at', { withTimezone: true }),\n last_success_at: timestamp('last_success_at', { withTimezone: true }),\n\n // Circuit breaker timing\n circuit_opened_at: timestamp('circuit_opened_at', { withTimezone: true }),\n next_retry_at: timestamp('next_retry_at', { withTimezone: true }),\n\n // Performance metrics\n avg_latency_ms: numeric('avg_latency_ms'),\n error_rate: numeric('error_rate'), // 0-1\n request_count_window: text('request_count_window').default('0'),\n\n // Health check results\n last_health_check_at: timestamp('last_health_check_at', { withTimezone: true }),\n health_check_result: jsonb('health_check_result').$type<{\n healthy: boolean\n latency_ms?: number\n error?: string\n }>(),\n\n // Timestamps\n created_at: timestamp('created_at', { withTimezone: true })\n .notNull()\n .defaultNow(),\n updated_at: timestamp('updated_at', { withTimezone: true })\n .notNull()\n .defaultNow(),\n },\n (table) => ({\n // One record per provider\n providerUnique: unique('provider_health_provider_unique').on(table.provider),\n // Performance indexes\n circuitStateIdx: index('provider_health_circuit_state_idx').on(\n table.circuit_state\n ),\n nextRetryIdx: index('provider_health_next_retry_idx').on(table.next_retry_at),\n })\n)\n","/**\n * @nehorai/payments-drizzle - Base Drizzle Repository\n *\n * Common utilities and types for Drizzle repository implementations.\n */\n\n// ============================================================================\n// Database Instance Type\n// ============================================================================\n\n/**\n * Drizzle database instance type\n * Uses a minimal interface to support any Drizzle database instance.\n * Generic enough to work with any Drizzle PostgreSQL database.\n */\nexport type DrizzleDB = {\n /* eslint-disable @typescript-eslint/no-explicit-any */\n select: (...args: any[]) => any\n insert: (table: any) => any\n update: (table: any) => any\n delete: (table: any) => any\n /* eslint-enable @typescript-eslint/no-explicit-any */\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Convert database row to camelCase entity\n */\nexport function toCamelCase<T extends Record<string, unknown>>(row: Record<string, unknown>): T {\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(row)) {\n const camelKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())\n result[camelKey] = value\n }\n return result as T\n}\n\n/**\n * Convert camelCase entity to snake_case for database\n */\nexport function toSnakeCase<T extends Record<string, unknown>>(obj: Record<string, unknown>): T {\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(obj)) {\n if (value === undefined) continue\n const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`)\n result[snakeKey] = value\n }\n return result as T\n}\n\n/**\n * Apply pagination to query results\n */\nexport function applyPagination<T>(\n items: T[],\n total: number,\n limit: number,\n offset: number\n): {\n data: T[]\n total: number\n limit: number\n offset: number\n hasMore: boolean\n} {\n return {\n data: items,\n total,\n limit,\n offset,\n hasMore: offset + items.length < total,\n }\n}\n\n/**\n * Parse numeric string to number (Drizzle returns numeric as string)\n */\nexport function parseNumeric(value: string | number | null | undefined): number {\n if (value === null || value === undefined) return 0\n if (typeof value === 'number') return value\n return parseFloat(value) || 0\n}\n\n/**\n * Convert array filter to SQL-friendly format\n */\nexport function normalizeArrayFilter<T>(value: T | T[] | undefined): T[] | undefined {\n if (value === undefined) return undefined\n return Array.isArray(value) ? value : [value]\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Transaction Repository\n *\n * Implements ITransactionRepository using Drizzle ORM.\n */\n\nimport { eq, and, gte, lte, inArray, sql, count } from 'drizzle-orm'\nimport type { DrizzleDB } from './base-drizzle.repository.js'\nimport { parseNumeric, applyPagination, normalizeArrayFilter } from './base-drizzle.repository.js'\nimport { paymentTransactions } from '../schema/index.js'\nimport type {\n ITransactionRepository,\n Transaction,\n CreateTransactionInput,\n UpdateTransactionInput,\n TransactionFilter,\n TransactionStatus,\n ProviderName,\n PaginationParams,\n PaginatedResult,\n} from '@nehorai/payments/repository'\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Map database row to Transaction entity\n */\nfunction mapToTransaction(row: typeof paymentTransactions.$inferSelect): Transaction {\n return {\n id: row.id,\n internalPaymentId: row.internal_payment_id,\n idempotencyKey: row.idempotency_key,\n userId: row.user_id,\n transactionType: row.transaction_type,\n status: row.status,\n amountMinor: parseNumeric(row.amount_minor),\n currency: row.currency,\n originalAmountMinor: row.original_amount_minor ? parseNumeric(row.original_amount_minor) : null,\n originalCurrency: row.original_currency,\n currencyConversionRate: row.currency_conversion_rate\n ? parseNumeric(row.currency_conversion_rate)\n : null,\n provider: row.provider as ProviderName,\n providerTransactionId: row.provider_transaction_id,\n providerAuthorizationCode: row.provider_authorization_code,\n providerMetadata: row.provider_metadata,\n authorizedAt: row.authorized_at,\n capturedAt: row.captured_at,\n voidedAt: row.voided_at,\n captureDeadline: row.capture_deadline,\n refundedAmountMinor: parseNumeric(row.refunded_amount_minor),\n lastRefundAt: row.last_refund_at,\n taxInvoiceStatus: row.tax_invoice_status ?? 'pending',\n taxInvoiceNumber: row.tax_invoice_number,\n taxInvoiceUrl: row.tax_invoice_url,\n failureCode: row.failure_code,\n failureMessage: row.failure_message,\n failureDetails: row.failure_details as Record<string, unknown> | null,\n description: row.description,\n metadata: row.metadata,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n }\n}\n\n// ============================================================================\n// Repository Implementation\n// ============================================================================\n\n/**\n * Drizzle implementation of ITransactionRepository\n */\nexport class DrizzleTransactionRepository implements ITransactionRepository {\n constructor(private db: DrizzleDB) {}\n\n async findById(id: string): Promise<Transaction | null> {\n const result = await this.db\n .select()\n .from(paymentTransactions)\n .where(eq(paymentTransactions.id, id))\n .limit(1)\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async create(data: CreateTransactionInput): Promise<Transaction> {\n const result = await this.db\n .insert(paymentTransactions)\n .values({\n internal_payment_id: data.internalPaymentId,\n idempotency_key: data.idempotencyKey,\n user_id: data.userId,\n transaction_type: data.transactionType,\n status: data.status ?? 'created',\n amount_minor: String(data.amountMinor),\n currency: data.currency,\n provider: data.provider,\n description: data.description,\n metadata: data.metadata,\n })\n .returning()\n\n return mapToTransaction(result[0])\n }\n\n async update(id: string, data: UpdateTransactionInput): Promise<Transaction | null> {\n const updateData: Partial<typeof paymentTransactions.$inferInsert> = {\n updated_at: new Date(),\n }\n\n if (data.status !== undefined) updateData.status = data.status\n if (data.providerTransactionId !== undefined)\n updateData.provider_transaction_id = data.providerTransactionId\n if (data.providerAuthorizationCode !== undefined)\n updateData.provider_authorization_code = data.providerAuthorizationCode\n if (data.providerMetadata !== undefined) updateData.provider_metadata = data.providerMetadata\n if (data.authorizedAt !== undefined) updateData.authorized_at = data.authorizedAt\n if (data.capturedAt !== undefined) updateData.captured_at = data.capturedAt\n if (data.voidedAt !== undefined) updateData.voided_at = data.voidedAt\n if (data.captureDeadline !== undefined) updateData.capture_deadline = data.captureDeadline\n if (data.refundedAmountMinor !== undefined)\n updateData.refunded_amount_minor = String(data.refundedAmountMinor)\n if (data.lastRefundAt !== undefined) updateData.last_refund_at = data.lastRefundAt\n if (data.taxInvoiceStatus !== undefined) updateData.tax_invoice_status = data.taxInvoiceStatus\n if (data.taxInvoiceNumber !== undefined) updateData.tax_invoice_number = data.taxInvoiceNumber\n if (data.taxInvoiceUrl !== undefined) updateData.tax_invoice_url = data.taxInvoiceUrl\n if (data.failureCode !== undefined) updateData.failure_code = data.failureCode\n if (data.failureMessage !== undefined) updateData.failure_message = data.failureMessage\n if (data.failureDetails !== undefined) updateData.failure_details = data.failureDetails\n\n const result = await this.db\n .update(paymentTransactions)\n .set(updateData)\n .where(eq(paymentTransactions.id, id))\n .returning()\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async delete(id: string): Promise<boolean> {\n const result = await this.db\n .delete(paymentTransactions)\n .where(eq(paymentTransactions.id, id))\n .returning({ id: paymentTransactions.id })\n\n return result.length > 0\n }\n\n async findByInternalPaymentId(internalPaymentId: string): Promise<Transaction | null> {\n const result = await this.db\n .select()\n .from(paymentTransactions)\n .where(eq(paymentTransactions.internal_payment_id, internalPaymentId))\n .limit(1)\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async findByIdempotencyKey(idempotencyKey: string): Promise<Transaction | null> {\n const result = await this.db\n .select()\n .from(paymentTransactions)\n .where(eq(paymentTransactions.idempotency_key, idempotencyKey))\n .limit(1)\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async findByProviderTransactionId(\n provider: ProviderName,\n providerTransactionId: string\n ): Promise<Transaction | null> {\n const result = await this.db\n .select()\n .from(paymentTransactions)\n .where(\n and(\n eq(paymentTransactions.provider, provider),\n eq(paymentTransactions.provider_transaction_id, providerTransactionId)\n )\n )\n .limit(1)\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async findMany(\n filter: TransactionFilter,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<Transaction>> {\n const { limit = 20, offset = 0 } = pagination\n const conditions = this.buildFilterConditions(filter)\n\n const [rows, [countResult]] = await Promise.all([\n this.db\n .select()\n .from(paymentTransactions)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .orderBy(sql`${paymentTransactions.created_at} DESC`)\n .limit(limit)\n .offset(offset),\n this.db\n .select({ total: count() })\n .from(paymentTransactions)\n .where(conditions.length > 0 ? and(...conditions) : undefined),\n ])\n\n const transactions = rows.map(mapToTransaction)\n return applyPagination(transactions, countResult?.total ?? 0, limit, offset)\n }\n\n async findByUserId(\n userId: string,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<Transaction>> {\n return this.findMany({ userId }, pagination)\n }\n\n async updateStatus(\n id: string,\n status: TransactionStatus,\n additionalData: Partial<UpdateTransactionInput> = {}\n ): Promise<Transaction | null> {\n return this.update(id, { ...additionalData, status })\n }\n\n async incrementRefundedAmount(id: string, amountMinor: number): Promise<Transaction | null> {\n const result = await this.db\n .update(paymentTransactions)\n .set({\n refunded_amount_minor: sql`COALESCE(${paymentTransactions.refunded_amount_minor}, '0')::numeric + ${amountMinor}`,\n last_refund_at: new Date(),\n updated_at: new Date(),\n })\n .where(eq(paymentTransactions.id, id))\n .returning()\n\n return result[0] ? mapToTransaction(result[0]) : null\n }\n\n async findExpiredAuthorizations(beforeDate: Date): Promise<Transaction[]> {\n const result = await this.db\n .select()\n .from(paymentTransactions)\n .where(\n and(\n eq(paymentTransactions.status, 'authorized'),\n lte(paymentTransactions.capture_deadline, beforeDate)\n )\n )\n\n return result.map(mapToTransaction)\n }\n\n async countByStatus(filter: TransactionFilter = {}): Promise<Record<TransactionStatus, number>> {\n const conditions = this.buildFilterConditions(filter)\n\n const result = await this.db\n .select({\n status: paymentTransactions.status,\n count: count(),\n })\n .from(paymentTransactions)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .groupBy(paymentTransactions.status)\n\n const counts: Record<TransactionStatus, number> = {\n created: 0,\n pending_authorization: 0,\n authorized: 0,\n capturing: 0,\n captured: 0,\n voided: 0,\n failed: 0,\n expired: 0,\n partially_refunded: 0,\n fully_refunded: 0,\n }\n\n for (const row of result) {\n counts[row.status as TransactionStatus] = row.count\n }\n\n return counts\n }\n\n // ============================================================================\n // Private Helpers\n // ============================================================================\n\n private buildFilterConditions(filter: TransactionFilter) {\n const conditions = []\n\n if (filter.userId) {\n conditions.push(eq(paymentTransactions.user_id, filter.userId))\n }\n\n const statuses = normalizeArrayFilter(filter.status)\n if (statuses && statuses.length > 0) {\n if (statuses.length === 1) {\n conditions.push(eq(paymentTransactions.status, statuses[0]))\n } else {\n conditions.push(inArray(paymentTransactions.status, statuses))\n }\n }\n\n const providers = normalizeArrayFilter(filter.provider)\n if (providers && providers.length > 0) {\n if (providers.length === 1) {\n conditions.push(eq(paymentTransactions.provider, providers[0]))\n } else {\n conditions.push(inArray(paymentTransactions.provider, providers))\n }\n }\n\n const transactionTypes = normalizeArrayFilter(filter.transactionType)\n if (transactionTypes && transactionTypes.length > 0) {\n if (transactionTypes.length === 1) {\n conditions.push(eq(paymentTransactions.transaction_type, transactionTypes[0]))\n } else {\n conditions.push(inArray(paymentTransactions.transaction_type, transactionTypes))\n }\n }\n\n if (filter.dateRange?.from) {\n conditions.push(gte(paymentTransactions.created_at, filter.dateRange.from))\n }\n if (filter.dateRange?.to) {\n conditions.push(lte(paymentTransactions.created_at, filter.dateRange.to))\n }\n\n return conditions\n }\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Payment Method Repository\n *\n * Implements IPaymentMethodRepository using Drizzle ORM.\n */\n\nimport { eq, and, inArray, sql, count } from 'drizzle-orm'\nimport type { DrizzleDB } from './base-drizzle.repository.js'\nimport { applyPagination, normalizeArrayFilter } from './base-drizzle.repository.js'\nimport { paymentMethods } from '../schema/index.js'\nimport type {\n IPaymentMethodRepository,\n PaymentMethod,\n CreatePaymentMethodInput,\n UpdatePaymentMethodInput,\n PaymentMethodFilter,\n ProviderName,\n CardBrand,\n PaginationParams,\n PaginatedResult,\n} from '@nehorai/payments/repository'\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Map database row to PaymentMethod entity\n */\nfunction mapToPaymentMethod(row: typeof paymentMethods.$inferSelect): PaymentMethod {\n return {\n id: row.id,\n userId: row.user_id,\n type: row.type,\n provider: row.provider as ProviderName,\n providerPaymentMethodId: row.provider_payment_method_id,\n cardBrand: row.card_brand as CardBrand | null,\n cardLast4: row.card_last4,\n cardExpMonth: row.card_exp_month,\n cardExpYear: row.card_exp_year,\n cardBin: row.card_bin,\n isDefault: row.is_default ?? false,\n isActive: row.is_active ?? true,\n providerMetadata: row.provider_metadata,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n lastUsedAt: row.last_used_at,\n }\n}\n\n// ============================================================================\n// Repository Implementation\n// ============================================================================\n\n/**\n * Drizzle implementation of IPaymentMethodRepository\n */\nexport class DrizzlePaymentMethodRepository implements IPaymentMethodRepository {\n constructor(private db: DrizzleDB) {}\n\n async findById(id: string): Promise<PaymentMethod | null> {\n const result = await this.db\n .select()\n .from(paymentMethods)\n .where(eq(paymentMethods.id, id))\n .limit(1)\n\n return result[0] ? mapToPaymentMethod(result[0]) : null\n }\n\n async create(data: CreatePaymentMethodInput): Promise<PaymentMethod> {\n const result = await this.db\n .insert(paymentMethods)\n .values({\n user_id: data.userId,\n type: data.type,\n provider: data.provider,\n provider_payment_method_id: data.providerPaymentMethodId,\n card_brand: data.cardBrand,\n card_last4: data.cardLast4,\n card_exp_month: data.cardExpMonth,\n card_exp_year: data.cardExpYear,\n card_bin: data.cardBin,\n is_default: data.isDefault ?? false,\n provider_metadata: data.providerMetadata,\n })\n .returning()\n\n return mapToPaymentMethod(result[0])\n }\n\n async update(id: string, data: UpdatePaymentMethodInput): Promise<PaymentMethod | null> {\n const updateData: Partial<typeof paymentMethods.$inferInsert> = {\n updated_at: new Date(),\n }\n\n if (data.isDefault !== undefined) updateData.is_default = data.isDefault\n if (data.isActive !== undefined) updateData.is_active = data.isActive\n if (data.cardExpMonth !== undefined) updateData.card_exp_month = data.cardExpMonth\n if (data.cardExpYear !== undefined) updateData.card_exp_year = data.cardExpYear\n if (data.lastUsedAt !== undefined) updateData.last_used_at = data.lastUsedAt\n if (data.providerMetadata !== undefined) updateData.provider_metadata = data.providerMetadata\n\n const result = await this.db\n .update(paymentMethods)\n .set(updateData)\n .where(eq(paymentMethods.id, id))\n .returning()\n\n return result[0] ? mapToPaymentMethod(result[0]) : null\n }\n\n async delete(id: string): Promise<boolean> {\n const result = await this.db\n .delete(paymentMethods)\n .where(eq(paymentMethods.id, id))\n .returning({ id: paymentMethods.id })\n\n return result.length > 0\n }\n\n async findByProviderPaymentMethodId(\n provider: ProviderName,\n providerPaymentMethodId: string\n ): Promise<PaymentMethod | null> {\n const result = await this.db\n .select()\n .from(paymentMethods)\n .where(\n and(\n eq(paymentMethods.provider, provider),\n eq(paymentMethods.provider_payment_method_id, providerPaymentMethodId)\n )\n )\n .limit(1)\n\n return result[0] ? mapToPaymentMethod(result[0]) : null\n }\n\n async findByUserId(\n userId: string,\n filter: Partial<PaymentMethodFilter> = {}\n ): Promise<PaymentMethod[]> {\n const conditions = [eq(paymentMethods.user_id, userId)]\n\n if (filter.isActive !== undefined) {\n conditions.push(eq(paymentMethods.is_active, filter.isActive))\n }\n if (filter.isDefault !== undefined) {\n conditions.push(eq(paymentMethods.is_default, filter.isDefault))\n }\n\n const providers = normalizeArrayFilter(filter.provider)\n if (providers && providers.length > 0) {\n conditions.push(inArray(paymentMethods.provider, providers))\n }\n\n const result = await this.db\n .select()\n .from(paymentMethods)\n .where(and(...conditions))\n .orderBy(sql`${paymentMethods.created_at} DESC`)\n\n return result.map(mapToPaymentMethod)\n }\n\n async findDefaultForUser(userId: string): Promise<PaymentMethod | null> {\n const result = await this.db\n .select()\n .from(paymentMethods)\n .where(\n and(\n eq(paymentMethods.user_id, userId),\n eq(paymentMethods.is_default, true),\n eq(paymentMethods.is_active, true)\n )\n )\n .limit(1)\n\n return result[0] ? mapToPaymentMethod(result[0]) : null\n }\n\n async findMany(\n filter: PaymentMethodFilter,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<PaymentMethod>> {\n const { limit = 20, offset = 0 } = pagination\n const conditions = this.buildFilterConditions(filter)\n\n const [rows, [countResult]] = await Promise.all([\n this.db\n .select()\n .from(paymentMethods)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .orderBy(sql`${paymentMethods.created_at} DESC`)\n .limit(limit)\n .offset(offset),\n this.db\n .select({ total: count() })\n .from(paymentMethods)\n .where(conditions.length > 0 ? and(...conditions) : undefined),\n ])\n\n const methods = rows.map(mapToPaymentMethod)\n return applyPagination(methods, countResult?.total ?? 0, limit, offset)\n }\n\n async setAsDefault(id: string, userId: string): Promise<PaymentMethod | null> {\n // First, unset all other defaults for user\n await this.db\n .update(paymentMethods)\n .set({ is_default: false, updated_at: new Date() })\n .where(and(eq(paymentMethods.user_id, userId), eq(paymentMethods.is_default, true)))\n\n // Then set this one as default\n return this.update(id, { isDefault: true })\n }\n\n async deactivate(id: string): Promise<boolean> {\n const result = await this.update(id, { isActive: false })\n return result !== null\n }\n\n async markAsUsed(id: string): Promise<PaymentMethod | null> {\n return this.update(id, { lastUsedAt: new Date() })\n }\n\n async findByCardBin(userId: string, cardBin: string): Promise<PaymentMethod[]> {\n const result = await this.db\n .select()\n .from(paymentMethods)\n .where(\n and(\n eq(paymentMethods.user_id, userId),\n eq(paymentMethods.card_bin, cardBin),\n eq(paymentMethods.is_active, true)\n )\n )\n\n return result.map(mapToPaymentMethod)\n }\n\n async countActiveForUser(userId: string): Promise<number> {\n const result = await this.db\n .select({ count: count() })\n .from(paymentMethods)\n .where(and(eq(paymentMethods.user_id, userId), eq(paymentMethods.is_active, true)))\n\n return result[0]?.count ?? 0\n }\n\n // ============================================================================\n // Private Helpers\n // ============================================================================\n\n private buildFilterConditions(filter: PaymentMethodFilter) {\n const conditions = []\n\n if (filter.userId) {\n conditions.push(eq(paymentMethods.user_id, filter.userId))\n }\n if (filter.isDefault !== undefined) {\n conditions.push(eq(paymentMethods.is_default, filter.isDefault))\n }\n if (filter.isActive !== undefined) {\n conditions.push(eq(paymentMethods.is_active, filter.isActive))\n }\n if (filter.cardBin) {\n conditions.push(eq(paymentMethods.card_bin, filter.cardBin))\n }\n\n const providers = normalizeArrayFilter(filter.provider)\n if (providers && providers.length > 0) {\n conditions.push(inArray(paymentMethods.provider, providers))\n }\n\n const types = normalizeArrayFilter(filter.type)\n if (types && types.length > 0) {\n conditions.push(inArray(paymentMethods.type, types))\n }\n\n return conditions\n }\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Webhook Event Repository\n *\n * Implements IWebhookEventRepository using Drizzle ORM.\n */\n\nimport { eq, and, gte, lte, inArray, sql, count, lt } from 'drizzle-orm'\nimport type { DrizzleDB } from './base-drizzle.repository.js'\nimport { applyPagination, normalizeArrayFilter } from './base-drizzle.repository.js'\nimport { paymentWebhookEvents } from '../schema/index.js'\nimport type {\n IWebhookEventRepository,\n WebhookEvent,\n CreateWebhookEventInput,\n UpdateWebhookEventInput,\n WebhookEventFilter,\n WebhookEventStatus,\n ProviderName,\n PaginationParams,\n PaginatedResult,\n} from '@nehorai/payments/repository'\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Map database row to WebhookEvent entity\n */\nfunction mapToWebhookEvent(row: typeof paymentWebhookEvents.$inferSelect): WebhookEvent {\n return {\n id: row.id,\n provider: row.provider as ProviderName,\n providerEventId: row.provider_event_id,\n eventType: row.event_type,\n status: row.status,\n attempts: parseInt(row.attempts ?? '0', 10),\n lastAttemptAt: row.last_attempt_at,\n transactionId: row.transaction_id,\n payload: row.payload,\n signature: row.signature,\n errorMessage: row.error_message,\n errorDetails: row.error_details as Record<string, unknown> | null,\n receivedAt: row.received_at,\n processedAt: row.processed_at,\n createdAt: row.created_at,\n }\n}\n\n// ============================================================================\n// Repository Implementation\n// ============================================================================\n\n/**\n * Drizzle implementation of IWebhookEventRepository\n */\nexport class DrizzleWebhookEventRepository implements IWebhookEventRepository {\n constructor(private db: DrizzleDB) {}\n\n async findById(id: string): Promise<WebhookEvent | null> {\n const result = await this.db\n .select()\n .from(paymentWebhookEvents)\n .where(eq(paymentWebhookEvents.id, id))\n .limit(1)\n\n return result[0] ? mapToWebhookEvent(result[0]) : null\n }\n\n async create(data: CreateWebhookEventInput): Promise<WebhookEvent> {\n const result = await this.db\n .insert(paymentWebhookEvents)\n .values({\n provider: data.provider,\n provider_event_id: data.providerEventId,\n event_type: data.eventType,\n payload: data.payload,\n signature: data.signature,\n status: 'pending',\n })\n .returning()\n\n return mapToWebhookEvent(result[0])\n }\n\n async update(id: string, data: UpdateWebhookEventInput): Promise<WebhookEvent | null> {\n const updateData: Partial<typeof paymentWebhookEvents.$inferInsert> = {}\n\n if (data.status !== undefined) updateData.status = data.status\n if (data.attempts !== undefined) updateData.attempts = String(data.attempts)\n if (data.lastAttemptAt !== undefined) updateData.last_attempt_at = data.lastAttemptAt\n if (data.transactionId !== undefined) updateData.transaction_id = data.transactionId\n if (data.processedAt !== undefined) updateData.processed_at = data.processedAt\n if (data.errorMessage !== undefined) updateData.error_message = data.errorMessage\n if (data.errorDetails !== undefined) updateData.error_details = data.errorDetails\n\n const result = await this.db\n .update(paymentWebhookEvents)\n .set(updateData)\n .where(eq(paymentWebhookEvents.id, id))\n .returning()\n\n return result[0] ? mapToWebhookEvent(result[0]) : null\n }\n\n async delete(id: string): Promise<boolean> {\n const result = await this.db\n .delete(paymentWebhookEvents)\n .where(eq(paymentWebhookEvents.id, id))\n .returning({ id: paymentWebhookEvents.id })\n\n return result.length > 0\n }\n\n async findByProviderEventId(\n provider: ProviderName,\n providerEventId: string\n ): Promise<WebhookEvent | null> {\n const result = await this.db\n .select()\n .from(paymentWebhookEvents)\n .where(\n and(\n eq(paymentWebhookEvents.provider, provider),\n eq(paymentWebhookEvents.provider_event_id, providerEventId)\n )\n )\n .limit(1)\n\n return result[0] ? mapToWebhookEvent(result[0]) : null\n }\n\n async findByTransactionId(transactionId: string): Promise<WebhookEvent[]> {\n const result = await this.db\n .select()\n .from(paymentWebhookEvents)\n .where(eq(paymentWebhookEvents.transaction_id, transactionId))\n .orderBy(sql`${paymentWebhookEvents.received_at} DESC`)\n\n return result.map(mapToWebhookEvent)\n }\n\n async findMany(\n filter: WebhookEventFilter,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<WebhookEvent>> {\n const { limit = 20, offset = 0 } = pagination\n const conditions = this.buildFilterConditions(filter)\n\n const [rows, [countResult]] = await Promise.all([\n this.db\n .select()\n .from(paymentWebhookEvents)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .orderBy(sql`${paymentWebhookEvents.received_at} DESC`)\n .limit(limit)\n .offset(offset),\n this.db\n .select({ total: count() })\n .from(paymentWebhookEvents)\n .where(conditions.length > 0 ? and(...conditions) : undefined),\n ])\n\n const events = rows.map(mapToWebhookEvent)\n return applyPagination(events, countResult?.total ?? 0, limit, offset)\n }\n\n async findFailedForRetry(maxAttempts: number, olderThan?: Date): Promise<WebhookEvent[]> {\n const conditions = [\n eq(paymentWebhookEvents.status, 'failed'),\n lt(sql`CAST(${paymentWebhookEvents.attempts} AS INTEGER)`, maxAttempts),\n ]\n\n if (olderThan) {\n conditions.push(lt(paymentWebhookEvents.last_attempt_at, olderThan))\n }\n\n const result = await this.db\n .select()\n .from(paymentWebhookEvents)\n .where(and(...conditions))\n .orderBy(sql`${paymentWebhookEvents.last_attempt_at} ASC`)\n .limit(100)\n\n return result.map(mapToWebhookEvent)\n }\n\n async findPending(limit: number = 100): Promise<WebhookEvent[]> {\n const result = await this.db\n .select()\n .from(paymentWebhookEvents)\n .where(eq(paymentWebhookEvents.status, 'pending'))\n .orderBy(sql`${paymentWebhookEvents.received_at} ASC`)\n .limit(limit)\n\n return result.map(mapToWebhookEvent)\n }\n\n async markAsProcessing(id: string): Promise<boolean> {\n // Optimistic locking - only update if still pending\n const result = await this.db\n .update(paymentWebhookEvents)\n .set({\n status: 'processing',\n last_attempt_at: new Date(),\n attempts: sql`CAST(${paymentWebhookEvents.attempts} AS INTEGER) + 1`,\n })\n .where(and(eq(paymentWebhookEvents.id, id), eq(paymentWebhookEvents.status, 'pending')))\n .returning({ id: paymentWebhookEvents.id })\n\n return result.length > 0\n }\n\n async markAsProcessed(id: string, transactionId?: string): Promise<WebhookEvent | null> {\n return this.update(id, {\n status: 'processed',\n processedAt: new Date(),\n transactionId,\n })\n }\n\n async markAsFailed(\n id: string,\n errorMessage: string,\n errorDetails?: Record<string, unknown>\n ): Promise<WebhookEvent | null> {\n return this.update(id, {\n status: 'failed',\n errorMessage,\n errorDetails,\n })\n }\n\n async incrementAttempts(id: string): Promise<WebhookEvent | null> {\n const result = await this.db\n .update(paymentWebhookEvents)\n .set({\n attempts: sql`CAST(${paymentWebhookEvents.attempts} AS INTEGER) + 1`,\n last_attempt_at: new Date(),\n })\n .where(eq(paymentWebhookEvents.id, id))\n .returning()\n\n return result[0] ? mapToWebhookEvent(result[0]) : null\n }\n\n async isAlreadyProcessed(provider: ProviderName, providerEventId: string): Promise<boolean> {\n const result = await this.db\n .select({ status: paymentWebhookEvents.status })\n .from(paymentWebhookEvents)\n .where(\n and(\n eq(paymentWebhookEvents.provider, provider),\n eq(paymentWebhookEvents.provider_event_id, providerEventId),\n eq(paymentWebhookEvents.status, 'processed')\n )\n )\n .limit(1)\n\n return result.length > 0\n }\n\n async countByStatus(\n filter: WebhookEventFilter = {}\n ): Promise<Record<WebhookEventStatus, number>> {\n const conditions = this.buildFilterConditions(filter)\n\n const result = await this.db\n .select({\n status: paymentWebhookEvents.status,\n count: count(),\n })\n .from(paymentWebhookEvents)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .groupBy(paymentWebhookEvents.status)\n\n const counts: Record<WebhookEventStatus, number> = {\n pending: 0,\n processing: 0,\n processed: 0,\n failed: 0,\n ignored: 0,\n }\n\n for (const row of result) {\n counts[row.status as WebhookEventStatus] = row.count\n }\n\n return counts\n }\n\n // ============================================================================\n // Private Helpers\n // ============================================================================\n\n private buildFilterConditions(filter: WebhookEventFilter) {\n const conditions = []\n\n const providers = normalizeArrayFilter(filter.provider)\n if (providers && providers.length > 0) {\n conditions.push(inArray(paymentWebhookEvents.provider, providers))\n }\n\n const eventTypes = normalizeArrayFilter(filter.eventType)\n if (eventTypes && eventTypes.length > 0) {\n conditions.push(inArray(paymentWebhookEvents.event_type, eventTypes))\n }\n\n const statuses = normalizeArrayFilter(filter.status)\n if (statuses && statuses.length > 0) {\n conditions.push(inArray(paymentWebhookEvents.status, statuses))\n }\n\n if (filter.transactionId) {\n conditions.push(eq(paymentWebhookEvents.transaction_id, filter.transactionId))\n }\n\n if (filter.dateRange?.from) {\n conditions.push(gte(paymentWebhookEvents.received_at, filter.dateRange.from))\n }\n if (filter.dateRange?.to) {\n conditions.push(lte(paymentWebhookEvents.received_at, filter.dateRange.to))\n }\n\n return conditions\n }\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Audit Log Repository\n *\n * Implements IAuditLogRepository using Drizzle ORM.\n * Audit logs are immutable - only create and read operations.\n */\n\nimport { eq, and, inArray, sql, count, gte, lte } from 'drizzle-orm'\nimport type { DrizzleDB } from './base-drizzle.repository.js'\nimport { applyPagination, normalizeArrayFilter } from './base-drizzle.repository.js'\nimport { paymentAuditLog } from '../schema/index.js'\nimport type {\n IAuditLogRepository,\n AuditLogEntry,\n CreateAuditLogInput,\n AuditLogFilter,\n AuditLogAction,\n AuditLogTrigger,\n PaginationParams,\n PaginatedResult,\n} from '@nehorai/payments/repository'\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Map database row to AuditLogEntry entity\n */\nfunction mapToAuditLogEntry(row: typeof paymentAuditLog.$inferSelect): AuditLogEntry {\n return {\n id: row.id,\n transactionId: row.transaction_id,\n action: row.action as AuditLogAction,\n previousState: row.previous_state as Record<string, unknown> | null,\n newState: row.new_state as Record<string, unknown>,\n triggeredBy: row.triggered_by as AuditLogTrigger,\n triggeredById: row.triggered_by_id,\n ipAddress: row.ip_address,\n userAgent: row.user_agent,\n correlationId: row.correlation_id,\n metadata: row.metadata as Record<string, unknown> | null,\n createdAt: row.created_at,\n }\n}\n\n// ============================================================================\n// Repository Implementation\n// ============================================================================\n\n/**\n * Drizzle implementation of IAuditLogRepository\n */\nexport class DrizzleAuditLogRepository implements IAuditLogRepository {\n constructor(private db: DrizzleDB) {}\n\n async findById(id: string): Promise<AuditLogEntry | null> {\n const result = await this.db\n .select()\n .from(paymentAuditLog)\n .where(eq(paymentAuditLog.id, id))\n .limit(1)\n\n return result[0] ? mapToAuditLogEntry(result[0]) : null\n }\n\n async create(data: CreateAuditLogInput): Promise<AuditLogEntry> {\n const result = await this.db\n .insert(paymentAuditLog)\n .values({\n transaction_id: data.transactionId,\n action: data.action,\n previous_state: data.previousState,\n new_state: data.newState,\n triggered_by: data.triggeredBy,\n triggered_by_id: data.triggeredById,\n ip_address: data.ipAddress,\n user_agent: data.userAgent,\n correlation_id: data.correlationId,\n metadata: data.metadata,\n })\n .returning()\n\n return mapToAuditLogEntry(result[0])\n }\n\n async createMany(entries: CreateAuditLogInput[]): Promise<AuditLogEntry[]> {\n if (entries.length === 0) return []\n\n const values = entries.map((data) => ({\n transaction_id: data.transactionId,\n action: data.action,\n previous_state: data.previousState,\n new_state: data.newState,\n triggered_by: data.triggeredBy,\n triggered_by_id: data.triggeredById,\n ip_address: data.ipAddress,\n user_agent: data.userAgent,\n correlation_id: data.correlationId,\n metadata: data.metadata,\n }))\n\n const result = await this.db.insert(paymentAuditLog).values(values).returning()\n\n return result.map(mapToAuditLogEntry)\n }\n\n async findByTransactionId(\n transactionId: string,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<AuditLogEntry>> {\n const { limit = 100, offset = 0 } = pagination\n\n const [rows, [countResult]] = await Promise.all([\n this.db\n .select()\n .from(paymentAuditLog)\n .where(eq(paymentAuditLog.transaction_id, transactionId))\n .orderBy(sql`${paymentAuditLog.created_at} ASC`)\n .limit(limit)\n .offset(offset),\n this.db\n .select({ total: count() })\n .from(paymentAuditLog)\n .where(eq(paymentAuditLog.transaction_id, transactionId)),\n ])\n\n const entries = rows.map(mapToAuditLogEntry)\n return applyPagination(entries, countResult?.total ?? 0, limit, offset)\n }\n\n async findMany(\n filter: AuditLogFilter,\n pagination: PaginationParams = {}\n ): Promise<PaginatedResult<AuditLogEntry>> {\n const { limit = 50, offset = 0 } = pagination\n const conditions = this.buildFilterConditions(filter)\n\n const [rows, [countResult]] = await Promise.all([\n this.db\n .select()\n .from(paymentAuditLog)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .orderBy(sql`${paymentAuditLog.created_at} DESC`)\n .limit(limit)\n .offset(offset),\n this.db\n .select({ total: count() })\n .from(paymentAuditLog)\n .where(conditions.length > 0 ? and(...conditions) : undefined),\n ])\n\n const entries = rows.map(mapToAuditLogEntry)\n return applyPagination(entries, countResult?.total ?? 0, limit, offset)\n }\n\n async findByCorrelationId(correlationId: string): Promise<AuditLogEntry[]> {\n const result = await this.db\n .select()\n .from(paymentAuditLog)\n .where(eq(paymentAuditLog.correlation_id, correlationId))\n .orderBy(sql`${paymentAuditLog.created_at} ASC`)\n\n return result.map(mapToAuditLogEntry)\n }\n\n async getTransactionHistory(transactionId: string): Promise<AuditLogEntry[]> {\n const result = await this.db\n .select()\n .from(paymentAuditLog)\n .where(eq(paymentAuditLog.transaction_id, transactionId))\n .orderBy(sql`${paymentAuditLog.created_at} ASC`)\n\n return result.map(mapToAuditLogEntry)\n }\n\n async countByAction(filter: AuditLogFilter = {}): Promise<Record<AuditLogAction, number>> {\n const conditions = this.buildFilterConditions(filter)\n\n const result = await this.db\n .select({\n action: paymentAuditLog.action,\n count: count(),\n })\n .from(paymentAuditLog)\n .where(conditions.length > 0 ? and(...conditions) : undefined)\n .groupBy(paymentAuditLog.action)\n\n const counts: Record<AuditLogAction, number> = {\n created: 0,\n status_changed: 0,\n authorized: 0,\n captured: 0,\n voided: 0,\n refund_initiated: 0,\n refund_completed: 0,\n webhook_received: 0,\n webhook_processed: 0,\n error_occurred: 0,\n retry_attempted: 0,\n manual_intervention: 0,\n }\n\n for (const row of result) {\n counts[row.action as AuditLogAction] = row.count\n }\n\n return counts\n }\n\n // ============================================================================\n // Private Helpers\n // ============================================================================\n\n private buildFilterConditions(filter: AuditLogFilter) {\n const conditions = []\n\n if (filter.transactionId) {\n conditions.push(eq(paymentAuditLog.transaction_id, filter.transactionId))\n }\n\n if (filter.correlationId) {\n conditions.push(eq(paymentAuditLog.correlation_id, filter.correlationId))\n }\n\n if (filter.triggeredById) {\n conditions.push(eq(paymentAuditLog.triggered_by_id, filter.triggeredById))\n }\n\n const actions = normalizeArrayFilter(filter.action)\n if (actions && actions.length > 0) {\n conditions.push(inArray(paymentAuditLog.action, actions))\n }\n\n const triggers = normalizeArrayFilter(filter.triggeredBy)\n if (triggers && triggers.length > 0) {\n conditions.push(inArray(paymentAuditLog.triggered_by, triggers))\n }\n\n if (filter.dateRange?.from) {\n conditions.push(gte(paymentAuditLog.created_at, filter.dateRange.from))\n }\n if (filter.dateRange?.to) {\n conditions.push(lte(paymentAuditLog.created_at, filter.dateRange.to))\n }\n\n return conditions\n }\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Provider Health Repository\n *\n * Implements IProviderHealthRepository using Drizzle ORM.\n * Manages circuit breaker state and provider metrics.\n */\n\nimport { eq, or, sql } from 'drizzle-orm'\nimport type { DrizzleDB } from './base-drizzle.repository.js'\nimport { parseNumeric } from './base-drizzle.repository.js'\nimport { providerHealth } from '../schema/index.js'\nimport type {\n IProviderHealthRepository,\n ProviderHealth,\n UpdateProviderHealthInput,\n HealthCheckResult,\n CircuitBreakerState,\n ProviderName,\n} from '@nehorai/payments/repository'\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Map database row to ProviderHealth entity\n */\nfunction mapToProviderHealth(row: typeof providerHealth.$inferSelect): ProviderHealth {\n return {\n id: row.id,\n provider: row.provider as ProviderName,\n circuitState: row.circuit_state as CircuitBreakerState,\n failureCount: parseInt(row.failure_count ?? '0', 10),\n successCount: parseInt(row.success_count ?? '0', 10),\n lastFailureAt: row.last_failure_at,\n lastSuccessAt: row.last_success_at,\n circuitOpenedAt: row.circuit_opened_at,\n nextRetryAt: row.next_retry_at,\n avgLatencyMs: row.avg_latency_ms ? parseNumeric(row.avg_latency_ms) : null,\n errorRate: row.error_rate ? parseNumeric(row.error_rate) : null,\n requestCountWindow: parseInt(row.request_count_window ?? '0', 10),\n lastHealthCheckAt: row.last_health_check_at,\n healthCheckResult: row.health_check_result as HealthCheckResult | null,\n createdAt: row.created_at,\n updatedAt: row.updated_at,\n }\n}\n\n// ============================================================================\n// Repository Implementation\n// ============================================================================\n\n/**\n * Drizzle implementation of IProviderHealthRepository\n */\nexport class DrizzleProviderHealthRepository implements IProviderHealthRepository {\n constructor(private db: DrizzleDB) {}\n\n async findByProvider(provider: ProviderName): Promise<ProviderHealth | null> {\n const result = await this.db\n .select()\n .from(providerHealth)\n .where(eq(providerHealth.provider, provider))\n .limit(1)\n\n return result[0] ? mapToProviderHealth(result[0]) : null\n }\n\n async getOrCreate(provider: ProviderName): Promise<ProviderHealth> {\n const existing = await this.findByProvider(provider)\n if (existing) return existing\n\n const result = await this.db\n .insert(providerHealth)\n .values({\n provider,\n circuit_state: 'closed',\n })\n .returning()\n\n return mapToProviderHealth(result[0])\n }\n\n async update(\n provider: ProviderName,\n data: UpdateProviderHealthInput\n ): Promise<ProviderHealth | null> {\n const updateData: Partial<typeof providerHealth.$inferInsert> = {\n updated_at: new Date(),\n }\n\n if (data.circuitState !== undefined) updateData.circuit_state = data.circuitState\n if (data.failureCount !== undefined) updateData.failure_count = String(data.failureCount)\n if (data.successCount !== undefined) updateData.success_count = String(data.successCount)\n if (data.lastFailureAt !== undefined) updateData.last_failure_at = data.lastFailureAt\n if (data.lastSuccessAt !== undefined) updateData.last_success_at = data.lastSuccessAt\n if (data.circuitOpenedAt !== undefined) updateData.circuit_opened_at = data.circuitOpenedAt\n if (data.nextRetryAt !== undefined) updateData.next_retry_at = data.nextRetryAt\n if (data.avgLatencyMs !== undefined) updateData.avg_latency_ms = String(data.avgLatencyMs)\n if (data.errorRate !== undefined) updateData.error_rate = String(data.errorRate)\n if (data.requestCountWindow !== undefined)\n updateData.request_count_window = String(data.requestCountWindow)\n if (data.lastHealthCheckAt !== undefined)\n updateData.last_health_check_at = data.lastHealthCheckAt\n if (data.healthCheckResult !== undefined)\n updateData.health_check_result = data.healthCheckResult\n\n const result = await this.db\n .update(providerHealth)\n .set(updateData)\n .where(eq(providerHealth.provider, provider))\n .returning()\n\n return result[0] ? mapToProviderHealth(result[0]) : null\n }\n\n async findAll(): Promise<ProviderHealth[]> {\n const result = await this.db\n .select()\n .from(providerHealth)\n .orderBy(sql`${providerHealth.provider} ASC`)\n\n return result.map(mapToProviderHealth)\n }\n\n async recordSuccess(provider: ProviderName, latencyMs: number): Promise<void> {\n await this.getOrCreate(provider)\n\n await this.db\n .update(providerHealth)\n .set({\n success_count: sql`CAST(${providerHealth.success_count} AS INTEGER) + 1`,\n request_count_window: sql`CAST(${providerHealth.request_count_window} AS INTEGER) + 1`,\n last_success_at: new Date(),\n avg_latency_ms: sql`CASE\n WHEN ${providerHealth.avg_latency_ms} IS NULL THEN ${latencyMs}\n ELSE (CAST(${providerHealth.avg_latency_ms} AS DECIMAL) * 0.9 + ${latencyMs} * 0.1)\n END`,\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async recordFailure(provider: ProviderName, error?: string): Promise<void> {\n await this.getOrCreate(provider)\n\n const updateData: Partial<typeof providerHealth.$inferInsert> = {\n last_failure_at: new Date(),\n updated_at: new Date(),\n }\n\n // Store error in health check result if provided\n if (error) {\n updateData.health_check_result = { healthy: false, error }\n }\n\n await this.db\n .update(providerHealth)\n .set({\n ...updateData,\n failure_count: sql`CAST(${providerHealth.failure_count} AS INTEGER) + 1`,\n request_count_window: sql`CAST(${providerHealth.request_count_window} AS INTEGER) + 1`,\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async openCircuit(provider: ProviderName, retryAfterMs: number): Promise<void> {\n const now = new Date()\n const nextRetry = new Date(now.getTime() + retryAfterMs)\n\n await this.getOrCreate(provider)\n\n await this.db\n .update(providerHealth)\n .set({\n circuit_state: 'open',\n circuit_opened_at: now,\n next_retry_at: nextRetry,\n updated_at: now,\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async closeCircuit(provider: ProviderName): Promise<void> {\n await this.db\n .update(providerHealth)\n .set({\n circuit_state: 'closed',\n circuit_opened_at: null,\n next_retry_at: null,\n failure_count: '0',\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async halfOpenCircuit(provider: ProviderName): Promise<void> {\n await this.db\n .update(providerHealth)\n .set({\n circuit_state: 'half_open',\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async updateHealthCheck(provider: ProviderName, result: HealthCheckResult): Promise<void> {\n await this.getOrCreate(provider)\n\n await this.db\n .update(providerHealth)\n .set({\n last_health_check_at: new Date(),\n health_check_result: result,\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async findOpenCircuits(): Promise<ProviderHealth[]> {\n const result = await this.db\n .select()\n .from(providerHealth)\n .where(eq(providerHealth.circuit_state, 'open'))\n\n return result.map(mapToProviderHealth)\n }\n\n async findReadyForRetry(): Promise<ProviderHealth[]> {\n const now = new Date()\n\n const result = await this.db\n .select()\n .from(providerHealth)\n .where(\n or(\n eq(providerHealth.circuit_state, 'half_open'),\n sql`${providerHealth.circuit_state} = 'open' AND ${providerHealth.next_retry_at} <= ${now}`\n )\n )\n\n return result.map(mapToProviderHealth)\n }\n\n async resetStats(provider: ProviderName): Promise<void> {\n await this.db\n .update(providerHealth)\n .set({\n failure_count: '0',\n success_count: '0',\n request_count_window: '0',\n avg_latency_ms: null,\n error_rate: null,\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n }\n\n async updateErrorRate(provider: ProviderName): Promise<number> {\n const health = await this.findByProvider(provider)\n if (!health || health.requestCountWindow === 0) return 0\n\n const errorRate = health.failureCount / health.requestCountWindow\n\n await this.db\n .update(providerHealth)\n .set({\n error_rate: String(errorRate),\n updated_at: new Date(),\n })\n .where(eq(providerHealth.provider, provider))\n\n return errorRate\n }\n}\n","/**\n * @nehorai/payments-drizzle - Drizzle Circuit Breaker Storage\n *\n * Database-backed storage implementation using the existing provider_health table.\n * Suitable for serverless deployments and multi-instance environments.\n *\n * Benefits:\n * - State persists across deployments\n * - Shared state across multiple instances (serverless-friendly)\n * - Uses existing provider_health table (no migration needed)\n *\n * Usage:\n * ```typescript\n * const repos = createDrizzleRepositories(db);\n * const storage = new DrizzleCircuitBreakerStorage(repos.providerHealth);\n * const circuitBreaker = new CircuitBreaker({ storage });\n * ```\n */\n\nimport type { PaymentProvider } from '@nehorai/payments/types'\nimport type { IProviderHealthRepository } from '@nehorai/payments/repository'\nimport type {\n ICircuitBreakerStorage,\n CircuitBreakerStateRecord,\n StoredCircuitState,\n} from '@nehorai/payments/services'\n\n// ============================================================================\n// Drizzle Storage Implementation\n// ============================================================================\n\n/**\n * Drizzle-based implementation of ICircuitBreakerStorage\n *\n * Uses the existing provider_health table via IProviderHealthRepository.\n * Perfect for serverless environments (Vercel, AWS Lambda) where\n * in-memory state doesn't persist between invocations.\n */\nexport class DrizzleCircuitBreakerStorage implements ICircuitBreakerStorage {\n private repo: IProviderHealthRepository\n\n constructor(providerHealthRepository: IProviderHealthRepository) {\n this.repo = providerHealthRepository\n }\n\n async getState(provider: PaymentProvider): Promise<CircuitBreakerStateRecord | null> {\n try {\n const health = await this.repo.findByProvider(provider)\n if (!health) return null\n\n return this.mapToStateRecord(provider, health)\n } catch (error) {\n console.error(`[DrizzleCircuitBreakerStorage] Failed to get state for ${provider}:`, error)\n return null\n }\n }\n\n async setState(provider: PaymentProvider, state: CircuitBreakerStateRecord): Promise<void> {\n try {\n // Ensure record exists\n await this.repo.getOrCreate(provider)\n\n // Update with new state\n await this.repo.update(provider, {\n circuitState: state.state,\n failureCount: state.failureCount,\n successCount: state.successCount,\n lastFailureAt: state.lastFailure ?? undefined,\n circuitOpenedAt: state.openedAt ?? undefined,\n nextRetryAt: state.nextRetryAt ?? undefined,\n })\n } catch (error) {\n console.error(`[DrizzleCircuitBreakerStorage] Failed to set state for ${provider}:`, error)\n throw error\n }\n }\n\n async getAllStates(): Promise<Map<PaymentProvider, CircuitBreakerStateRecord>> {\n try {\n const allHealth = await this.repo.findAll()\n const states = new Map<PaymentProvider, CircuitBreakerStateRecord>()\n\n for (const health of allHealth) {\n const provider = health.provider as PaymentProvider\n states.set(provider, this.mapToStateRecord(provider, health))\n }\n\n return states\n } catch (error) {\n console.error('[DrizzleCircuitBreakerStorage] Failed to get all states:', error)\n return new Map()\n }\n }\n\n async deleteState(provider: PaymentProvider): Promise<void> {\n try {\n await this.repo.resetStats(provider)\n await this.repo.closeCircuit(provider)\n } catch (error) {\n console.error(`[DrizzleCircuitBreakerStorage] Failed to delete state for ${provider}:`, error)\n throw error\n }\n }\n\n async getOpenCircuits(): Promise<PaymentProvider[]> {\n try {\n const openHealth = await this.repo.findOpenCircuits()\n return openHealth.map((h) => h.provider as PaymentProvider)\n } catch (error) {\n console.error('[DrizzleCircuitBreakerStorage] Failed to get open circuits:', error)\n return []\n }\n }\n\n async isHealthy(): Promise<boolean> {\n try {\n // Try a simple read operation to verify database connectivity\n await this.repo.findAll()\n return true\n } catch (error) {\n console.error('[DrizzleCircuitBreakerStorage] Health check failed:', error)\n return false\n }\n }\n\n // ==========================================================================\n // Helper Methods\n // ==========================================================================\n\n private mapToStateRecord(\n provider: PaymentProvider,\n health: {\n circuitState: string\n failureCount: number\n successCount: number\n lastFailureAt: Date | null\n circuitOpenedAt: Date | null\n nextRetryAt: Date | null\n }\n ): CircuitBreakerStateRecord {\n return {\n provider,\n state: health.circuitState as StoredCircuitState,\n failureCount: health.failureCount,\n successCount: health.successCount,\n lastFailure: health.lastFailureAt,\n openedAt: health.circuitOpenedAt,\n nextRetryAt: health.nextRetryAt,\n }\n }\n}\n\n// ============================================================================\n// Factory Helper\n// ============================================================================\n\n/**\n * Create a Drizzle-based circuit breaker storage\n *\n * Convenience function for creating storage with a provider health repository.\n *\n * @param providerHealthRepo - The Drizzle provider health repository\n * @returns DrizzleCircuitBreakerStorage instance\n */\nexport function createDrizzleCircuitBreakerStorage(\n providerHealthRepo: IProviderHealthRepository\n): DrizzleCircuitBreakerStorage {\n return new DrizzleCircuitBreakerStorage(providerHealthRepo)\n}\n","/**\r\n * @nehorai/payments-drizzle - Factory\r\n *\r\n * Convenience factory functions for creating Drizzle-backed payment repositories\r\n * and full payment services.\r\n */\r\n\r\nimport type { DrizzleDB } from './repositories/base-drizzle.repository.js'\r\nimport type { IPaymentRepositories } from '@nehorai/payments/repository'\r\nimport type { RoutingRules, CircuitBreakerConfig } from '@nehorai/payments/services'\r\nimport type { PaymentConfig } from '@nehorai/payments/config'\r\nimport type { PaymentServices, PaymentServicesConfig } from '@nehorai/payments/factory'\r\nimport { createPaymentServices } from '@nehorai/payments/factory'\r\nimport { DrizzleTransactionRepository } from './repositories/transaction.drizzle-repository.js'\r\nimport { DrizzlePaymentMethodRepository } from './repositories/payment-method.drizzle-repository.js'\r\nimport { DrizzleWebhookEventRepository } from './repositories/webhook-event.drizzle-repository.js'\r\nimport { DrizzleAuditLogRepository } from './repositories/audit-log.drizzle-repository.js'\r\nimport { DrizzleProviderHealthRepository } from './repositories/provider-health.drizzle-repository.js'\r\nimport { DrizzleCircuitBreakerStorage } from './storage/drizzle-circuit-breaker-storage.js'\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\nexport interface DrizzlePaymentServicesOptions {\r\n config?: PaymentConfig\r\n routingRules?: RoutingRules\r\n circuitBreaker?: Partial<CircuitBreakerConfig>\r\n /** Provider instances - required to create full payment services */\r\n providers: PaymentServicesConfig['providers']\r\n /** Webhook handler instances (optional) */\r\n webhookHandlers?: PaymentServicesConfig['webhookHandlers']\r\n}\r\n\r\n// ============================================================================\r\n// Factory Functions\r\n// ============================================================================\r\n\r\n/**\r\n * Create all Drizzle-backed repository implementations\r\n *\r\n * @param db - A Drizzle database instance\r\n * @returns IPaymentRepositories with all repositories implemented\r\n */\r\nexport function createDrizzleRepositories(db: DrizzleDB): IPaymentRepositories {\r\n return {\r\n transactions: new DrizzleTransactionRepository(db),\r\n paymentMethods: new DrizzlePaymentMethodRepository(db),\r\n webhookEvents: new DrizzleWebhookEventRepository(db),\r\n auditLog: new DrizzleAuditLogRepository(db),\r\n providerHealth: new DrizzleProviderHealthRepository(db),\r\n }\r\n}\r\n\r\n/**\r\n * Create full payment services with Drizzle-backed storage\r\n *\r\n * Sets up repositories, circuit breaker storage, and the complete\r\n * payment orchestration layer in one call.\r\n *\r\n * @param db - A Drizzle database instance\r\n * @param options - Configuration including providers and optional overrides\r\n * @returns Fully configured PaymentServices\r\n */\r\nexport function createDrizzlePaymentServices(\r\n db: DrizzleDB,\r\n options: DrizzlePaymentServicesOptions\r\n): PaymentServices {\r\n const repositories = createDrizzleRepositories(db)\r\n const circuitBreakerStorage = new DrizzleCircuitBreakerStorage(repositories.providerHealth)\r\n\r\n return createPaymentServices({\r\n config: options.config,\r\n providers: options.providers,\r\n webhookHandlers: options.webhookHandlers,\r\n repositories,\r\n circuitBreakerStorage,\r\n circuitBreaker: options.circuitBreaker,\r\n routingRules: options.routingRules,\r\n })\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSA,qBAA8E;AAsDvE,IAAM,0BAAsB;AAAA,EACjC;AAAA,EACA;AAAA,IACE,QAAI,qBAAK,IAAI,EAAE,cAAc,EAAE,WAAW;AAAA;AAAA,IAG1C,yBAAqB,qBAAK,qBAAqB,EAAE,QAAQ;AAAA,IACzD,qBAAiB,qBAAK,iBAAiB;AAAA;AAAA,IAGvC,aAAS,qBAAK,SAAS,EAAE,QAAQ;AAAA;AAAA,IAGjC,sBAAkB,qBAAK,kBAAkB,EAAE,MAA8B,EAAE,QAAQ;AAAA,IACnF,YAAQ,qBAAK,QAAQ,EAAE,MAAgC,EAAE,QAAQ,EAAE,QAAQ,SAAS;AAAA;AAAA,IAGpF,kBAAc,wBAAQ,cAAc,EAAE,QAAQ;AAAA,IAC9C,cAAU,qBAAK,UAAU,EAAE,QAAQ,EAAE,QAAQ,KAAK;AAAA;AAAA,IAGlD,2BAAuB,wBAAQ,uBAAuB;AAAA,IACtD,uBAAmB,qBAAK,mBAAmB;AAAA,IAC3C,8BAA0B,wBAAQ,0BAA0B;AAAA;AAAA,IAG5D,cAAU,qBAAK,UAAU,EAAE,QAAQ;AAAA;AAAA,IACnC,6BAAyB,qBAAK,yBAAyB;AAAA,IACvD,iCAA6B,qBAAK,6BAA6B;AAAA,IAC/D,uBAAmB,sBAAM,mBAAmB,EAAE,MAA+B;AAAA;AAAA,IAG7E,mBAAe,0BAAU,iBAAiB,EAAE,cAAc,KAAK,CAAC;AAA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cAAc,IAAI,6BAA6B,EAAE;AAAA,IACjD,gBAAgB,IAAI,+BAA+B,EAAE;AAAA,IACrD,eAAe,IAAI,8BAA8B,EAAE;AAAA,IACnD,UAAU,IAAI,0BAA0B,EAAE;AAAA,IAC1C,gBAAgB,IAAI,gCAAgC,EAAE;AAAA,EACxD;AACF;AAYO,SAAS,6BACd,IACA,SACiB;AACjB,QAAM,eAAe,0BAA0B,EAAE;AACjD,QAAM,wBAAwB,IAAI,6BAA6B,aAAa,cAAc;AAE1F,aAAO,sCAAsB;AAAA,IAC3B,QAAQ,QAAQ;AAAA,IAChB,WAAW,QAAQ;AAAA,IACnB,iBAAiB,QAAQ;AAAA,IACzB;AAAA,IACA;AAAA,IACA,gBAAgB,QAAQ;AAAA,IACxB,cAAc,QAAQ;AAAA,EACxB,CAAC;AACH;","names":["import_pg_core","import_pg_core","import_pg_core","import_pg_core","import_drizzle_orm","import_drizzle_orm","import_drizzle_orm","import_drizzle_orm"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export { AuditLogAction, AuditLogTrigger, CardBrandType, CircuitBreakerState, PaymentMethodType, PaymentTaxInvoiceStatus, PaymentTransactionStatus, PaymentTransactionType, WebhookEventStatus, paymentAuditLog, paymentMethods, paymentTransactions, paymentWebhookEvents, providerHealth } from './schema/index.cjs';
|
|
2
|
+
import { D as DrizzleDB } from './provider-health.drizzle-repository-DfRo4qJ8.cjs';
|
|
3
|
+
export { a as DrizzleAuditLogRepository, b as DrizzlePaymentMethodRepository, c as DrizzleProviderHealthRepository, d as DrizzleTransactionRepository, e as DrizzleWebhookEventRepository, f as applyPagination, n as normalizeArrayFilter, p as parseNumeric, t as toCamelCase, g as toSnakeCase } from './provider-health.drizzle-repository-DfRo4qJ8.cjs';
|
|
4
|
+
export { DrizzleCircuitBreakerStorage, createDrizzleCircuitBreakerStorage } from './storage/index.cjs';
|
|
5
|
+
import { IPaymentRepositories } from '@nehorai/payments/repository';
|
|
6
|
+
import { RoutingRules, CircuitBreakerConfig } from '@nehorai/payments/services';
|
|
7
|
+
import { PaymentConfig } from '@nehorai/payments/config';
|
|
8
|
+
import { PaymentServicesConfig, PaymentServices } from '@nehorai/payments/factory';
|
|
9
|
+
import 'drizzle-orm/pg-core';
|
|
10
|
+
import '@nehorai/payments/types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @nehorai/payments-drizzle - Factory
|
|
14
|
+
*
|
|
15
|
+
* Convenience factory functions for creating Drizzle-backed payment repositories
|
|
16
|
+
* and full payment services.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
interface DrizzlePaymentServicesOptions {
|
|
20
|
+
config?: PaymentConfig;
|
|
21
|
+
routingRules?: RoutingRules;
|
|
22
|
+
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
23
|
+
/** Provider instances - required to create full payment services */
|
|
24
|
+
providers: PaymentServicesConfig['providers'];
|
|
25
|
+
/** Webhook handler instances (optional) */
|
|
26
|
+
webhookHandlers?: PaymentServicesConfig['webhookHandlers'];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create all Drizzle-backed repository implementations
|
|
30
|
+
*
|
|
31
|
+
* @param db - A Drizzle database instance
|
|
32
|
+
* @returns IPaymentRepositories with all repositories implemented
|
|
33
|
+
*/
|
|
34
|
+
declare function createDrizzleRepositories(db: DrizzleDB): IPaymentRepositories;
|
|
35
|
+
/**
|
|
36
|
+
* Create full payment services with Drizzle-backed storage
|
|
37
|
+
*
|
|
38
|
+
* Sets up repositories, circuit breaker storage, and the complete
|
|
39
|
+
* payment orchestration layer in one call.
|
|
40
|
+
*
|
|
41
|
+
* @param db - A Drizzle database instance
|
|
42
|
+
* @param options - Configuration including providers and optional overrides
|
|
43
|
+
* @returns Fully configured PaymentServices
|
|
44
|
+
*/
|
|
45
|
+
declare function createDrizzlePaymentServices(db: DrizzleDB, options: DrizzlePaymentServicesOptions): PaymentServices;
|
|
46
|
+
|
|
47
|
+
export { DrizzleDB, type DrizzlePaymentServicesOptions, createDrizzlePaymentServices, createDrizzleRepositories };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export { AuditLogAction, AuditLogTrigger, CardBrandType, CircuitBreakerState, PaymentMethodType, PaymentTaxInvoiceStatus, PaymentTransactionStatus, PaymentTransactionType, WebhookEventStatus, paymentAuditLog, paymentMethods, paymentTransactions, paymentWebhookEvents, providerHealth } from './schema/index.js';
|
|
2
|
+
import { D as DrizzleDB } from './provider-health.drizzle-repository-DfRo4qJ8.js';
|
|
3
|
+
export { a as DrizzleAuditLogRepository, b as DrizzlePaymentMethodRepository, c as DrizzleProviderHealthRepository, d as DrizzleTransactionRepository, e as DrizzleWebhookEventRepository, f as applyPagination, n as normalizeArrayFilter, p as parseNumeric, t as toCamelCase, g as toSnakeCase } from './provider-health.drizzle-repository-DfRo4qJ8.js';
|
|
4
|
+
export { DrizzleCircuitBreakerStorage, createDrizzleCircuitBreakerStorage } from './storage/index.js';
|
|
5
|
+
import { IPaymentRepositories } from '@nehorai/payments/repository';
|
|
6
|
+
import { RoutingRules, CircuitBreakerConfig } from '@nehorai/payments/services';
|
|
7
|
+
import { PaymentConfig } from '@nehorai/payments/config';
|
|
8
|
+
import { PaymentServicesConfig, PaymentServices } from '@nehorai/payments/factory';
|
|
9
|
+
import 'drizzle-orm/pg-core';
|
|
10
|
+
import '@nehorai/payments/types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @nehorai/payments-drizzle - Factory
|
|
14
|
+
*
|
|
15
|
+
* Convenience factory functions for creating Drizzle-backed payment repositories
|
|
16
|
+
* and full payment services.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
interface DrizzlePaymentServicesOptions {
|
|
20
|
+
config?: PaymentConfig;
|
|
21
|
+
routingRules?: RoutingRules;
|
|
22
|
+
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
23
|
+
/** Provider instances - required to create full payment services */
|
|
24
|
+
providers: PaymentServicesConfig['providers'];
|
|
25
|
+
/** Webhook handler instances (optional) */
|
|
26
|
+
webhookHandlers?: PaymentServicesConfig['webhookHandlers'];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create all Drizzle-backed repository implementations
|
|
30
|
+
*
|
|
31
|
+
* @param db - A Drizzle database instance
|
|
32
|
+
* @returns IPaymentRepositories with all repositories implemented
|
|
33
|
+
*/
|
|
34
|
+
declare function createDrizzleRepositories(db: DrizzleDB): IPaymentRepositories;
|
|
35
|
+
/**
|
|
36
|
+
* Create full payment services with Drizzle-backed storage
|
|
37
|
+
*
|
|
38
|
+
* Sets up repositories, circuit breaker storage, and the complete
|
|
39
|
+
* payment orchestration layer in one call.
|
|
40
|
+
*
|
|
41
|
+
* @param db - A Drizzle database instance
|
|
42
|
+
* @param options - Configuration including providers and optional overrides
|
|
43
|
+
* @returns Fully configured PaymentServices
|
|
44
|
+
*/
|
|
45
|
+
declare function createDrizzlePaymentServices(db: DrizzleDB, options: DrizzlePaymentServicesOptions): PaymentServices;
|
|
46
|
+
|
|
47
|
+
export { DrizzleDB, type DrizzlePaymentServicesOptions, createDrizzlePaymentServices, createDrizzleRepositories };
|