/** * Ductape Resilience Module * * Provides code-first API for building resilient integrations with * healthchecks, quotas (load distribution), and fallbacks (automatic failover). * * @example * ```ts * import { ResilienceService, HealthcheckService, QuotaService, FallbackService } from '@ductape/sdk'; * * // Create a unified resilience service * const resilience = new ResilienceService({ * workspace_id: 'your-workspace-id', * public_key: 'your-public-key', * user_id: 'your-user-id', * token: 'your-token', * env_type: 'prd', * }); * * // Define a healthcheck * const healthcheck = await resilience.healthcheck.define({ * product: 'my-product', * tag: 'stripe-health', * handler: async (ctx) => { * ctx.probe().app('stripe-app').action('health'); * ctx.interval(30000); * ctx.retries(2); * ctx.env('prd'); * }, * }); * * // Define a quota * const quota = await resilience.quota.define({ * product: 'my-product', * tag: 'sms-quota', * input: { * phone: { type: 'string', required: true }, * message: { type: 'string', required: true }, * }, * handler: async (ctx) => { * ctx.provider('twilio') * .weight(70) * .healthcheck('twilio-health') * .app('twilio-app') * .action('send-sms') * .retries(2); * * ctx.provider('nexmo') * .weight(30) * .healthcheck('nexmo-health') * .app('nexmo-app') * .action('send-sms') * .retries(2); * }, * }); * * // Define a fallback * const fallback = await resilience.fallback.define({ * product: 'my-product', * tag: 'payment-fallback', * input: { * amount: { type: 'number', required: true }, * }, * handler: async (ctx) => { * ctx.primary('stripe') * .healthcheck('stripe-health') * .app('stripe-app') * .action('charge') * .retries(2); * * ctx.fallback('paypal') * .healthcheck('paypal-health') * .app('paypal-app') * .action('payment') * .retries(2); * }, * }); * * // Run quota * const result = await resilience.quota.run({ * product: 'my-product', * env: 'prd', * tag: 'sms-quota', * input: { phone: '+1234567890', message: 'Hello!' }, * }); * * // Run fallback * const paymentResult = await resilience.fallback.run({ * product: 'my-product', * env: 'prd', * tag: 'payment-fallback', * input: { amount: 1000 }, * }); * ``` */ export { ResilienceService, ResilienceError, IDefinedResilience, } from './resilience.service'; export { default as ResilienceServiceDefault } from './resilience.service'; export { HealthcheckService, HealthcheckError } from './healthcheck.service'; export { default as HealthcheckServiceDefault } from './healthcheck.service'; export { QuotaService, QuotaError } from './quota.service'; export { default as QuotaServiceDefault } from './quota.service'; export { FallbackService, FallbackError } from './fallback.service'; export { default as FallbackServiceDefault } from './fallback.service'; export * from './types'; export * from './rate-limit.service';