import { t as CacheAdapter } from "../cache.adapter-z0MMDFoK.js"; import { t as DatabaseAdapter } from "../database.adapter-oL35G_XI.js"; import { s as FeatureRegistry } from "../types-3EaBC58c.js"; import { n as ChargePaymentInput, r as ChargePaymentResult, s as PaymentGatewayAdapter } from "../payment.adapter-BOT9T6jQ.js"; //#region src/testing/memory-database.d.ts /** * Create a fully in-memory {@link DatabaseAdapter}. * * Implements the complete adapter contract — plans (including admin filtering, * `hasActiveSubscribers` and `hasPendingDowngrades`), subscriptions (including * `findExpiring`), invoices (including `findByGatewayInvoiceId` for idempotent * webhook handling), usage tracking (increment/decrement/set/reset with * never-below-zero decrement semantics), and transactions via a shallow * snapshot that is restored when the transaction function throws. * * Useful for unit tests, demos, and as a reference implementation when * building a custom adapter. * * @example * ```typescript * import { memoryDatabaseAdapter } from '@abshahin/subscriptions/testing'; * * const subs = createSubscriptions({ * database: memoryDatabaseAdapter(), * features, * }); * ``` */ declare function memoryDatabaseAdapter(): DatabaseAdapter; //#endregion //#region src/testing/memory-cache.d.ts /** * Create a fully in-memory {@link CacheAdapter}. * * Supports TTL expiry, `deletePattern` with glob patterns (`*` matches any * run of characters, e.g. `'sub:tenant:*'`), atomic `incrBy`/`decrBy`, and * `exists`. Useful for unit tests and as a reference implementation when * building a custom cache adapter (e.g. backed by Redis or Workers KV). * * @example * ```typescript * import { memoryCacheAdapter } from '@abshahin/subscriptions/testing'; * * const subs = createSubscriptions({ * database, * features, * cache: memoryCacheAdapter(), * }); * ``` */ declare function memoryCacheAdapter(): CacheAdapter; //#endregion //#region src/testing/fake-payment-gateway.d.ts /** * Scriptable charge outcome for the fake gateway: * - `'paid'` / `'pending'` / `'failed'` — built-in canned results * - a partial {@link ChargePaymentResult} merged over a paid default * - a function computing the result from the charge input */ type FakeChargeOutcome = 'paid' | 'pending' | 'failed' | Partial | ((input: ChargePaymentInput) => Partial); /** * Options for {@link fakePaymentGateway} */ interface FakePaymentGatewayOptions { /** * Provider name reported by the adapter * @default 'fake' */ provider?: string; /** * Queue of charge outcomes consumed one per {@link chargePayment} call. * When the queue is empty, charges succeed (`'paid'`). */ chargeOutcomes?: FakeChargeOutcome[]; /** * Optional webhook secret. When set, `constructWebhookEvent` verifies the * signature as `sha256=` (plain hex accepted * too) and throws on mismatch. When omitted, the signature is ignored. */ webhookSecret?: string; } /** * A recorded call made to the fake gateway */ interface FakePaymentGatewayCall { method: string; args: unknown[]; } /** * The fake gateway adapter plus test introspection helpers */ interface FakePaymentGateway extends PaymentGatewayAdapter { /** Every call made to the adapter, in order */ readonly calls: FakePaymentGatewayCall[]; /** Append an outcome to the charge outcome queue */ queueChargeOutcome(outcome: FakeChargeOutcome): void; /** Clear the recorded call log */ clearCalls(): void; /** Clear the call log, the outcome queue, and all stored entities */ reset(): void; } /** * Create a fake {@link PaymentGatewayAdapter} for tests. * * All operations are served from memory: customers and gateway subscriptions * are stored locally, charges consume a scriptable outcome queue, and every * call is recorded in `calls` for assertions. `constructWebhookEvent` accepts * a JSON payload of the shape `{ "type": string, "data": object }` and * optionally verifies an HMAC-SHA256 signature when `webhookSecret` is set. * * @example * ```typescript * import { fakePaymentGateway } from '@abshahin/subscriptions/testing'; * * const gateway = fakePaymentGateway({ chargeOutcomes: ['failed', 'paid'] }); * // first charge fails, second succeeds * expect(gateway.calls[0].method).toBe('chargePayment'); * ``` */ declare function fakePaymentGateway(options?: FakePaymentGatewayOptions): FakePaymentGateway; //#endregion //#region src/testing/conformance.d.ts /** * Register the DatabaseAdapter conformance suite. * * @param name - Display name for the describe block (e.g. the adapter name) * @param factory - Returns a fresh, empty adapter instance per test * * @example * ```typescript * // tests/conformance.prisma.test.ts * import { databaseAdapterConformance } from '@abshahin/subscriptions/testing'; * * await databaseAdapterConformance('prismaAdapter', () => prismaAdapter(db)); * ``` */ declare function databaseAdapterConformance(name: string, factory: () => DatabaseAdapter | Promise>): Promise; /** * Register the CacheAdapter conformance suite. * * Optional capabilities (`deletePattern`, `incrBy`/`decrBy`, `exists`) are * verified only when the adapter implements them. * * @param name - Display name for the describe block (e.g. the adapter name) * @param factory - Returns a fresh, empty cache instance per test */ declare function cacheAdapterConformance(name: string, factory: () => CacheAdapter | Promise): Promise; //#endregion export { type FakeChargeOutcome, type FakePaymentGateway, type FakePaymentGatewayCall, type FakePaymentGatewayOptions, cacheAdapterConformance, databaseAdapterConformance, fakePaymentGateway, memoryCacheAdapter, memoryDatabaseAdapter }; //# sourceMappingURL=index.d.ts.map