pushduck
Version:
The fastest way to add file uploads to any web application. Enterprise security, edge-ready. Works with 16+ frameworks and 5+ storage providers. No heavy AWS SDK required.
16 lines (14 loc) • 6.86 kB
JavaScript
import{S3ArraySchema as e,S3FileSchema as t,S3ImageSchema as n,S3ObjectSchema as r,S3Route as i,S3Schema as a,StorageInstance as o,createProvider as s,createS3RouterWithConfig as c,createStorage as l,createUploadConfig as u,endOperation as d,getProviderEndpoint as f,metrics as p,recordOperation as m,startOperation as h,trackOperation as g,validateProviderConfig as _}from"./upload-config-CCENumjA.mjs";import{PushduckError as v,_defineProperty as y,createConfigError as b,createFileError as x,createNetworkError as S,createS3Client as C,createS3Error as w,isConfigError as T,isFileError as E,isPushduckError as D,isS3Error as O,logger as k,resetS3Client as A,wrapAsync as j}from"./client-BQgbehVh.mjs";var M=class{constructor(){y(this,`checks`,[])}async runHealthChecks(e){this.checks=[];let t=Date.now();k.info(`Starting health checks`),await this.checkConfiguration(e),await this.checkEnvironment(),e&&await this.checkConnectivity(e),await this.checkPerformance();let n=this.calculateSummary(),r=this.determineOverallStatus(n),i=Date.now()-t;return k.info(`Health checks completed in ${i}ms`,{status:r,summary:n}),{status:r,checks:[...this.checks],summary:n,timestamp:new Date}}async checkConfiguration(e){let t=performance.now();try{if(!e){this.addCheck(`Configuration`,`warn`,`No configuration provided for validation`);return}let t=[`provider`,`accessKeyId`,`secretAccessKey`,`bucket`],n=t.filter(t=>!e[t]);if(n.length>0){this.addCheck(`Configuration`,`fail`,`Missing required fields: ${n.join(`, `)}`,{missingFields:n});return}let r=this.validateProviderConfig(e);if(!r.valid){this.addCheck(`Configuration`,`fail`,`Provider configuration invalid: ${r.errors.join(`, `)}`,{errors:r.errors});return}this.addCheck(`Configuration`,`pass`,`Configuration is valid`)}catch(e){this.addCheck(`Configuration`,`fail`,e instanceof Error?e.message:`Configuration check failed`)}finally{this.updateCheckDuration(`Configuration`,performance.now()-t)}}async checkEnvironment(){let e=performance.now();try{let e=process.version,t=parseInt(e.slice(1).split(`.`)[0]);t<16?this.addCheck(`Node.js Version`,`fail`,`Node.js ${e} is not supported. Minimum version: 16.0.0`):t<18?this.addCheck(`Node.js Version`,`warn`,`Node.js ${e} is supported but consider upgrading to v18+ for better performance`):this.addCheck(`Node.js Version`,`pass`,`Node.js ${e} is supported`);let n=process.memoryUsage(),r=Math.round(n.heapUsed/1024/1024),i=Math.round(n.heapTotal/1024/1024);r>512?this.addCheck(`Memory Usage`,`warn`,`High memory usage: ${r}MB used of ${i}MB total`,{memoryUsage:n}):this.addCheck(`Memory Usage`,`pass`,`Memory usage is normal: ${r}MB used of ${i}MB total`),typeof performance>`u`?this.addCheck(`Performance API`,`warn`,`Performance API not available - metrics collection may be limited`):this.addCheck(`Performance API`,`pass`,`Performance API is available`)}catch(e){this.addCheck(`Environment`,`fail`,e instanceof Error?e.message:`Environment check failed`)}finally{this.updateCheckDuration(`Environment`,performance.now()-e)}}async checkConnectivity(e){let t=performance.now();try{let{validateS3Connection:t}=await import(`./client-Dx47Nbr9.mjs`),n=await t(e);n.success?this.addCheck(`S3 Connectivity`,`pass`,`Successfully connected to S3`):this.addCheck(`S3 Connectivity`,`fail`,`Failed to connect to S3: ${n.error}`,{error:n.error})}catch(e){this.addCheck(`S3 Connectivity`,`fail`,e instanceof Error?e.message:`Connectivity check failed`)}finally{this.updateCheckDuration(`S3 Connectivity`,performance.now()-t)}}async checkPerformance(){let e=performance.now();try{if(!p.isMetricsEnabled()){this.addCheck(`Performance Metrics`,`warn`,`Metrics collection is disabled`);return}let e=p.getAggregatedMetrics();if(e.totalOperations===0){this.addCheck(`Performance Metrics`,`pass`,`No operations recorded yet`);return}e.successRate<90?this.addCheck(`Success Rate`,`warn`,`Success rate is ${e.successRate.toFixed(1)}% (below 90%)`,{metrics:e}):this.addCheck(`Success Rate`,`pass`,`Success rate is ${e.successRate.toFixed(1)}%`),e.averageDuration>5e3?this.addCheck(`Performance`,`warn`,`Average operation duration is ${e.averageDuration.toFixed(1)}ms (above 5s)`,{metrics:e}):this.addCheck(`Performance`,`pass`,`Average operation duration is ${e.averageDuration.toFixed(1)}ms`)}catch(e){this.addCheck(`Performance Metrics`,`fail`,e instanceof Error?e.message:`Performance check failed`)}finally{this.updateCheckDuration(`Performance Metrics`,performance.now()-e)}}validateProviderConfig(e){let t=[];switch(e.provider.provider){case`aws`:e.provider.region||t.push(`AWS region is required`);break;case`cloudflare-r2`:e.provider.endpoint||t.push(`Cloudflare R2 endpoint is required`);break;case`digitalocean-spaces`:e.provider.endpoint||t.push(`DigitalOcean Spaces endpoint is required`);break;case`minio`:e.provider.endpoint||t.push(`MinIO endpoint is required`);break;case`s3-compatible`:e.provider.endpoint||t.push(`S3-compatible endpoint is required`);break;default:t.push(`Unsupported provider: ${e.provider.provider}`)}return{valid:t.length===0,errors:t}}addCheck(e,t,n,r){this.checks.push({name:e,status:t,message:n,details:r})}updateCheckDuration(e,t){let n=this.checks.find(t=>t.name===e);n&&(n.duration=t)}calculateSummary(){let e=this.checks.length,t=this.checks.filter(e=>e.status===`pass`).length,n=this.checks.filter(e=>e.status===`warn`).length,r=this.checks.filter(e=>e.status===`fail`).length;return{total:e,passed:t,warnings:n,failures:r}}determineOverallStatus(e){return e.failures>0?`error`:e.warnings>0?`warning`:`healthy`}getHealthReport(e){let t={healthy:`✅`,warning:`⚠️`,error:`❌`},n={pass:`✅`,warn:`⚠️`,fail:`❌`};return`
${t[e.status]} Pushduck Health Check Report
==========================================
Status: ${e.status.toUpperCase()}
Timestamp: ${e.timestamp.toISOString()}
Summary:
- Total Checks: ${e.summary.total}
- Passed: ${e.summary.passed}
- Warnings: ${e.summary.warnings}
- Failures: ${e.summary.failures}
Detailed Results:
${e.checks.map(e=>{let t=e.duration?` (${e.duration.toFixed(1)}ms)`:``;return`${n[e.status]} ${e.name}: ${e.message}${t}`}).join(`
`)}
`.trim()}};const N=new M,P=e=>N.runHealthChecks(e),F=e=>N.getHealthReport(e);export{v as PushduckError,e as S3ArraySchema,t as S3FileSchema,n as S3ImageSchema,r as S3ObjectSchema,i as S3Route,a as S3Schema,o as StorageInstance,b as createConfigError,x as createFileError,S as createNetworkError,s as createProvider,C as createS3Client,w as createS3Error,c as createS3RouterWithConfig,l as createStorage,u as createUploadConfig,d as endOperation,F as getHealthReport,f as getProviderEndpoint,N as healthChecker,T as isConfigError,E as isFileError,D as isPushduckError,O as isS3Error,k as logger,p as metrics,m as recordOperation,A as resetS3Client,P as runHealthCheck,h as startOperation,g as trackOperation,_ as validateProviderConfig,j as wrapAsync};