@uploadista/flow-security-clamscan 1.0.0-beta.3 → 1.0.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.
@@ -1,27 +1,30 @@
1
-
2
- > @uploadista/flow-security-clamscan@1.0.0-beta.3 build /home/runner/work/uploadista-sdk/uploadista-sdk/packages/flow/security/clamscan
3
- > tsc --noEmit && tsdown
4
-
5
- ℹ tsdown v0.20.3 powered by rolldown v1.0.0-rc.3
1
+ $ tsc --noEmit && tsdown
2
+ ℹ tsdown v0.22.3 powered by rolldown v1.1.3
6
3
  ℹ config file: /home/runner/work/uploadista-sdk/uploadista-sdk/packages/flow/security/clamscan/tsdown.config.ts
7
4
  ℹ entry: src/index.ts
8
5
  ℹ tsconfig: tsconfig.json
9
6
  ℹ Build start
10
- ℹ [CJS] dist/index.cjs 2.96 kB │ gzip: 1.25 kB
11
- ℹ [CJS] 1 files, total: 2.96 kB
12
- [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `tsdown:shebang`. See https://rolldown.rs/options/checks#plugintimings for more details.
7
+ ℹ [CJS] dist/index.cjs 2.97 kB │ gzip: 1.25 kB
8
+ ℹ [CJS] 1 files, total: 2.97 kB
9
+ [PLUGIN_TIMINGS] Your build spent significant time in plugin `tsdown:deps`. See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.
13
10
 
14
11
  ℹ [CJS] dist/index.d.cts.map 0.32 kB │ gzip: 0.22 kB
15
12
  ℹ [CJS] dist/index.d.cts 1.68 kB │ gzip: 0.73 kB
16
- ℹ [CJS] 2 files, total: 1.99 kB
17
- ℹ [ESM] dist/index.mjs 2.27 kB │ gzip: 0.97 kB
18
- ℹ [ESM] dist/index.mjs.map 9.40 kB │ gzip: 2.93 kB
13
+ ℹ [CJS] 2 files, total: 2.00 kB
14
+ ✔ Build complete in 12777ms
15
+ [PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
16
+ - rolldown-plugin-dts:generate (50%)
17
+ - tsdown:deps (49%)
18
+ See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.
19
+
20
+ ℹ [ESM] dist/index.mjs 2.28 kB │ gzip: 0.97 kB
21
+ ℹ [ESM] dist/index.mjs.map 9.49 kB │ gzip: 2.96 kB
19
22
  ℹ [ESM] dist/index.d.mts.map 0.32 kB │ gzip: 0.22 kB
20
23
  ℹ [ESM] dist/index.d.mts 1.68 kB │ gzip: 0.73 kB
21
- ℹ [ESM] 4 files, total: 13.66 kB
22
- [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
23
-
24
- [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
24
+ ℹ [ESM] 4 files, total: 13.77 kB
25
+ [PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
26
+ - rolldown-plugin-dts:generate (65%)
27
+ - tsdown:deps (34%)
28
+ See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.
25
29
 
26
- ✔ Build complete in 13056ms
27
- ✔ Build complete in 13057ms
30
+ ✔ Build complete in 12797ms
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:crypto`),l=require(`node:fs/promises`);l=s(l);let u=require(`node:os`);u=s(u);let d=require(`node:path`);d=s(d);let f=require(`@uploadista/core/errors`),p=require(`@uploadista/core/flow`),m=require(`@uploadista/observability`),h=require(`clamscan`);h=s(h);let g=require(`effect`);var _=class{clamscan=null;constructor(e={}){this.config=e}initScanner(){return g.Effect.gen(function*(){if(this.clamscan)return this.clamscan;let e=yield*g.Effect.tryPromise({try:async()=>await new h.default().init({preference:this.config.preference??`clamdscan`,remove_infected:this.config.remove_infected??!1,debug_mode:this.config.debug_mode??!1,clamdscan:{socket:this.config.clamdscan_socket,host:this.config.clamdscan_host,port:this.config.clamdscan_port??3310,timeout:6e4,local_fallback:!0},clamscan:{path:`/usr/bin/clamscan`,scan_archives:!0,active:!0}}),catch:e=>f.UploadistaError.fromCode(`CLAMAV_NOT_INSTALLED`,{body:`ClamAV initialization failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})});return this.clamscan=e,e}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`init`,{"scan.preference":this.config.preference??`clamdscan`}))}scan(e){return g.Effect.gen(function*(){let t=yield*this.initScanner(),n=u.tmpdir(),r=`uploadista-scan-${(0,c.randomUUID)()}`,i=d.join(n,r);return yield*g.Effect.tryPromise({try:()=>l.writeFile(i,e),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to create temporary file for scanning`,details:{error:e}})}),yield*g.Effect.tryPromise({try:()=>t.isInfected(i),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Virus scan failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})}).pipe(g.Effect.map(e=>({isClean:!e.isInfected,detectedViruses:e.viruses||[]})),g.Effect.ensuring(g.Effect.tryPromise({try:()=>l.unlink(i),catch:()=>void 0}).pipe(g.Effect.ignore)))}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`scan`,{"scan.file_size":e.byteLength}))}getVersion(){return g.Effect.gen(function*(){let e=yield*this.initScanner();return(yield*g.Effect.tryPromise({try:()=>e.getVersion(),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to get ClamAV version`,details:{error:e}})})).version||`Unknown`}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`get-version`,{}))}};function v(e={}){return g.Layer.succeed(p.VirusScanPlugin,new _(e))}exports.virusScanPlugin=v;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("node:crypto"),l=require("node:fs/promises");l=s(l,1);let u=require("node:os");u=s(u,1);let d=require("node:path");d=s(d,1);let f=require("@uploadista/core/errors"),p=require("@uploadista/core/flow"),m=require("@uploadista/observability"),h=require("clamscan");h=s(h,1);let g=require("effect");var _=class{config;clamscan=null;constructor(e={}){this.config=e}initScanner(){return g.Effect.gen(function*(){if(this.clamscan)return this.clamscan;let e=yield*g.Effect.tryPromise({try:async()=>await new h.default().init({preference:this.config.preference??`clamdscan`,remove_infected:this.config.remove_infected??!1,debug_mode:this.config.debug_mode??!1,clamdscan:{socket:this.config.clamdscan_socket,host:this.config.clamdscan_host,port:this.config.clamdscan_port??3310,timeout:6e4,local_fallback:!0},clamscan:{path:`/usr/bin/clamscan`,scan_archives:!0,active:!0}}),catch:e=>f.UploadistaError.fromCode(`CLAMAV_NOT_INSTALLED`,{body:`ClamAV initialization failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})});return this.clamscan=e,e}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`init`,{"scan.preference":this.config.preference??`clamdscan`}))}scan(e){return g.Effect.gen(function*(){let t=yield*this.initScanner(),n=u.tmpdir(),r=`uploadista-scan-${(0,c.randomUUID)()}`,i=d.join(n,r);return yield*g.Effect.tryPromise({try:()=>l.writeFile(i,e),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to create temporary file for scanning`,details:{error:e}})}),yield*g.Effect.tryPromise({try:()=>t.isInfected(i),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Virus scan failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})}).pipe(g.Effect.map(e=>({isClean:!e.isInfected,detectedViruses:e.viruses||[]})),g.Effect.ensuring(g.Effect.tryPromise({try:()=>l.unlink(i),catch:()=>void 0}).pipe(g.Effect.ignore)))}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`scan`,{"scan.file_size":e.byteLength}))}getVersion(){return g.Effect.gen(function*(){let e=yield*this.initScanner();return(yield*g.Effect.tryPromise({try:()=>e.getVersion(),catch:e=>f.UploadistaError.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to get ClamAV version`,details:{error:e}})})).version||`Unknown`}.bind(this)).pipe((0,m.withOperationSpan)(`virus-scan`,`get-version`,{}))}};function v(e={}){return g.Layer.succeed(p.VirusScanPlugin,new _(e))}exports.virusScanPlugin=v;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/clamscan-plugin.ts"],"mappings":";;;;;;AAcA;UAAiB,qBAAA;;;;;;EAMf,UAAA;EAuBA;;;;EAjBA,gBAAA;EAyM6B;;;EApM7B,cAAA;EAsMC;;;;EAhMD,cAAA;EAgMC;;;;EA1LD,eAAA;;;;;EAMA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;iBAkLc,eAAA,CACd,MAAA,GAAQ,qBAAA,GACP,KAAA,CAAM,KAAA,CAAM,eAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/clamscan-plugin.ts"],"mappings":";;;;;;AAcA;UAAiB,qBAAA;;;;;;EAMf,UAAA;EAuBA;;;AAMU;EAvBV,gBAAA;EAyM6B;;;EApM7B,cAAA;EAsMC;;;;EAhMD,cAAA;EAgMC;;;;EA1LD,eAAA;;;;;EAMA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;iBAkLc,eAAA,CACd,MAAA,GAAQ,qBAAA,GACP,KAAA,CAAM,KAAA,CAAM,eAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/clamscan-plugin.ts"],"mappings":";;;;;;AAcA;UAAiB,qBAAA;;;;;;EAMf,UAAA;EAuBA;;;;EAjBA,gBAAA;EAyM6B;;;EApM7B,cAAA;EAsMC;;;;EAhMD,cAAA;EAgMC;;;;EA1LD,eAAA;;;;;EAMA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;iBAkLc,eAAA,CACd,MAAA,GAAQ,qBAAA,GACP,KAAA,CAAM,KAAA,CAAM,eAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/clamscan-plugin.ts"],"mappings":";;;;;;AAcA;UAAiB,qBAAA;;;;;;EAMf,UAAA;EAuBA;;;AAMU;EAvBV,gBAAA;EAyM6B;;;EApM7B,cAAA;EAsMC;;;;EAhMD,cAAA;EAgMC;;;;EA1LD,eAAA;;;;;EAMA,UAAA;AAAA;;;;;;;;;;;;;;;;;;;iBAkLc,eAAA,CACd,MAAA,GAAQ,qBAAA,GACP,KAAA,CAAM,KAAA,CAAM,eAAA"}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{randomUUID as e}from"node:crypto";import*as t from"node:fs/promises";import*as n from"node:os";import*as r from"node:path";import{UploadistaError as i}from"@uploadista/core/errors";import{VirusScanPlugin as a}from"@uploadista/core/flow";import{withOperationSpan as o}from"@uploadista/observability";import s from"clamscan";import{Effect as c,Layer as l}from"effect";var u=class{clamscan=null;constructor(e={}){this.config=e}initScanner(){return c.gen(function*(){if(this.clamscan)return this.clamscan;let e=yield*c.tryPromise({try:async()=>await new s().init({preference:this.config.preference??`clamdscan`,remove_infected:this.config.remove_infected??!1,debug_mode:this.config.debug_mode??!1,clamdscan:{socket:this.config.clamdscan_socket,host:this.config.clamdscan_host,port:this.config.clamdscan_port??3310,timeout:6e4,local_fallback:!0},clamscan:{path:`/usr/bin/clamscan`,scan_archives:!0,active:!0}}),catch:e=>i.fromCode(`CLAMAV_NOT_INSTALLED`,{body:`ClamAV initialization failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})});return this.clamscan=e,e}.bind(this)).pipe(o(`virus-scan`,`init`,{"scan.preference":this.config.preference??`clamdscan`}))}scan(a){return c.gen(function*(){let o=yield*this.initScanner(),s=n.tmpdir(),l=`uploadista-scan-${e()}`,u=r.join(s,l);return yield*c.tryPromise({try:()=>t.writeFile(u,a),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to create temporary file for scanning`,details:{error:e}})}),yield*c.tryPromise({try:()=>o.isInfected(u),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Virus scan failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})}).pipe(c.map(e=>({isClean:!e.isInfected,detectedViruses:e.viruses||[]})),c.ensuring(c.tryPromise({try:()=>t.unlink(u),catch:()=>void 0}).pipe(c.ignore)))}.bind(this)).pipe(o(`virus-scan`,`scan`,{"scan.file_size":a.byteLength}))}getVersion(){return c.gen(function*(){let e=yield*this.initScanner();return(yield*c.tryPromise({try:()=>e.getVersion(),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to get ClamAV version`,details:{error:e}})})).version||`Unknown`}.bind(this)).pipe(o(`virus-scan`,`get-version`,{}))}};function d(e={}){return l.succeed(a,new u(e))}export{d as virusScanPlugin};
1
+ import{randomUUID as e}from"node:crypto";import*as t from"node:fs/promises";import*as n from"node:os";import*as r from"node:path";import{UploadistaError as i}from"@uploadista/core/errors";import{VirusScanPlugin as a}from"@uploadista/core/flow";import{withOperationSpan as o}from"@uploadista/observability";import s from"clamscan";import{Effect as c,Layer as l}from"effect";var u=class{config;clamscan=null;constructor(e={}){this.config=e}initScanner(){return c.gen(function*(){if(this.clamscan)return this.clamscan;let e=yield*c.tryPromise({try:async()=>await new s().init({preference:this.config.preference??`clamdscan`,remove_infected:this.config.remove_infected??!1,debug_mode:this.config.debug_mode??!1,clamdscan:{socket:this.config.clamdscan_socket,host:this.config.clamdscan_host,port:this.config.clamdscan_port??3310,timeout:6e4,local_fallback:!0},clamscan:{path:`/usr/bin/clamscan`,scan_archives:!0,active:!0}}),catch:e=>i.fromCode(`CLAMAV_NOT_INSTALLED`,{body:`ClamAV initialization failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})});return this.clamscan=e,e}.bind(this)).pipe(o(`virus-scan`,`init`,{"scan.preference":this.config.preference??`clamdscan`}))}scan(a){return c.gen(function*(){let o=yield*this.initScanner(),s=n.tmpdir(),l=`uploadista-scan-${e()}`,u=r.join(s,l);return yield*c.tryPromise({try:()=>t.writeFile(u,a),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to create temporary file for scanning`,details:{error:e}})}),yield*c.tryPromise({try:()=>o.isInfected(u),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Virus scan failed: ${e instanceof Error?e.message:String(e)}`,details:{error:e}})}).pipe(c.map(e=>({isClean:!e.isInfected,detectedViruses:e.viruses||[]})),c.ensuring(c.tryPromise({try:()=>t.unlink(u),catch:()=>void 0}).pipe(c.ignore)))}.bind(this)).pipe(o(`virus-scan`,`scan`,{"scan.file_size":a.byteLength}))}getVersion(){return c.gen(function*(){let e=yield*this.initScanner();return(yield*c.tryPromise({try:()=>e.getVersion(),catch:e=>i.fromCode(`VIRUS_SCAN_FAILED`,{body:`Failed to get ClamAV version`,details:{error:e}})})).version||`Unknown`}.bind(this)).pipe(o(`virus-scan`,`get-version`,{}))}};function d(e={}){return l.succeed(a,new u(e))}export{d as virusScanPlugin};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/clamscan-plugin.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { UploadistaError } from \"@uploadista/core/errors\";\nimport type { ScanResult, VirusScanPluginShape } from \"@uploadista/core/flow\";\nimport { VirusScanPlugin } from \"@uploadista/core/flow\";\nimport { withOperationSpan } from \"@uploadista/observability\";\nimport NodeClam from \"clamscan\";\nimport { Effect, Layer } from \"effect\";\n\n/**\n * Configuration options for the ClamAV Virus Scan plugin\n */\nexport interface VirusScanPluginConfig {\n /**\n * Preference for scanning method\n * - \"clamdscan\": Use clamd daemon (faster, recommended)\n * - \"clamscan\": Use command-line binary\n */\n preference?: \"clamdscan\" | \"clamscan\";\n\n /**\n * Path to clamd socket (for daemon mode)\n * Default: /var/run/clamd.scan/clamd.sock\n */\n clamdscan_socket?: string;\n\n /**\n * TCP host for clamd (alternative to socket)\n */\n clamdscan_host?: string;\n\n /**\n * TCP port for clamd\n * Default: 3310\n */\n clamdscan_port?: number;\n\n /**\n * Whether to remove infected files automatically\n * Default: false (not recommended in flow context)\n */\n remove_infected?: boolean;\n\n /**\n * Debug mode for clamscan library\n * Default: false\n */\n debug_mode?: boolean;\n}\n\n/**\n * ClamAV implementation of the VirusScanPlugin\n *\n * This plugin uses the `clamscan` npm package to scan files for viruses\n * using ClamAV antivirus engine. It supports both clamd daemon mode (fast)\n * and binary mode (slower but more portable).\n *\n * @example\n * ```typescript\n * import { ClamScanPluginLayer } from \"@uploadista/flow-security-clamscan\";\n *\n * const program = Effect.gen(function* () {\n * const virusScan = yield* VirusScanPlugin;\n * const result = yield* virusScan.scan(fileBytes);\n * console.log(result.isClean ? \"Clean\" : \"Infected\");\n * }).pipe(Effect.provide(ClamScanPluginLayer));\n * ```\n */\nclass ClamScanPluginImpl implements VirusScanPluginShape {\n private clamscan: NodeClam | null = null;\n\n constructor(private config: VirusScanPluginConfig = {}) {}\n\n /**\n * Initialize the ClamAV scanner\n * This is called lazily on first use\n */\n private initScanner(): Effect.Effect<NodeClam, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n if (this.clamscan) {\n return this.clamscan;\n }\n\n const scanner = yield* Effect.tryPromise({\n try: async () => {\n // Initialize clamscan with configuration\n return await new NodeClam().init({\n preference: this.config.preference ?? \"clamdscan\",\n remove_infected: this.config.remove_infected ?? false,\n debug_mode: this.config.debug_mode ?? false,\n clamdscan: {\n socket: this.config.clamdscan_socket,\n host: this.config.clamdscan_host,\n port: this.config.clamdscan_port ?? 3310,\n timeout: 60000,\n local_fallback: true, // Fall back to binary if daemon unavailable\n },\n clamscan: {\n path: \"/usr/bin/clamscan\", // Standard path\n scan_archives: true,\n active: true,\n },\n });\n },\n catch: (error) =>\n UploadistaError.fromCode(\"CLAMAV_NOT_INSTALLED\", {\n body: `ClamAV initialization failed: ${error instanceof Error ? error.message : String(error)}`,\n details: { error },\n }),\n });\n\n this.clamscan = scanner;\n return scanner;\n }.bind(this),\n ).pipe(\n withOperationSpan(\"virus-scan\", \"init\", {\n \"scan.preference\": this.config.preference ?? \"clamdscan\",\n }),\n );\n }\n\n /**\n * Scans a file for viruses using ClamAV\n *\n * @param input - File contents as Uint8Array\n * @returns Effect with scan results\n */\n scan(input: Uint8Array): Effect.Effect<ScanResult, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n // Initialize scanner (lazy initialization)\n const scanner = yield* this.initScanner();\n\n // Create temporary file path for scanning\n const tmpDir = os.tmpdir();\n const fileName = `uploadista-scan-${randomUUID()}`;\n const tempFilePath = path.join(tmpDir, fileName);\n\n // Write file data to temp file\n yield* Effect.tryPromise({\n try: () => fs.writeFile(tempFilePath, input),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: \"Failed to create temporary file for scanning\",\n details: { error },\n }),\n });\n\n // Scan the file and ensure cleanup\n const result = yield* Effect.tryPromise({\n try: () => scanner.isInfected(tempFilePath),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: `Virus scan failed: ${error instanceof Error ? error.message : String(error)}`,\n details: { error },\n }),\n }).pipe(\n Effect.map((scanResult) => ({\n isClean: !scanResult.isInfected,\n detectedViruses: scanResult.viruses || [],\n })),\n Effect.ensuring(\n // Clean up temporary file (ignore errors)\n Effect.tryPromise({\n try: () => fs.unlink(tempFilePath),\n catch: () => undefined,\n }).pipe(Effect.ignore),\n ),\n );\n\n return result;\n }.bind(this),\n ).pipe(\n withOperationSpan(\"virus-scan\", \"scan\", {\n \"scan.file_size\": input.byteLength,\n }),\n );\n }\n\n /**\n * Gets the ClamAV engine version\n *\n * @returns Effect with version string\n */\n getVersion(): Effect.Effect<string, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n // Initialize scanner (lazy initialization)\n const scanner = yield* this.initScanner();\n\n // Get version from ClamAV\n const versionResult = yield* Effect.tryPromise({\n try: () => scanner.getVersion(),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: \"Failed to get ClamAV version\",\n details: { error },\n }),\n });\n\n return versionResult.version || \"Unknown\";\n }.bind(this),\n ).pipe(withOperationSpan(\"virus-scan\", \"get-version\", {}));\n }\n}\n\n/**\n * Creates a Virus Scan Plugin layer using ClamAV\n *\n * @param config - Optional ClamAV configuration\n * @returns Layer providing VirusScanPlugin\n *\n * @example\n * ```typescript\n * // Use with default configuration\n * const layer = ClamScanPluginLayer();\n *\n * // Use with custom configuration\n * const customLayer = ClamScanPluginLayer({\n * preference: \"clamdscan\",\n * clamdscan_socket: \"/var/run/clamav/clamd.ctl\"\n * });\n * ```\n */\nexport function virusScanPlugin(\n config: VirusScanPluginConfig = {},\n): Layer.Layer<VirusScanPlugin,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CAGa,MAAO,EAAO,WAAW,CACtC,QAAW,EAAQ,WAAW,EAAa,CAC3C,MAAQ,GACN,EAAgB,SAAS,oBAAqB,CAC5C,KAAM,sBAAsB,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,GAClF,QAAS,CAAE,QAAO,CACnB,CAAC,CACL,CAAC,CAAC,KACD,EAAO,IAAK,IAAgB,CAC1B,QAAS,CAAC,EAAW,WACrB,gBAAiB,EAAW,SAAW,EAAE,CAC1C,EAAE,CACH,EAAO,SAEL,EAAO,WAAW,CAChB,QAAW,EAAG,OAAO,EAAa,CAClC,UAAa,IAAA,GACd,CAAC,CAAC,KAAK,EAAO,OAAO,CACvB,CACF,EAGD,KAAK,KAAK,CACb,CAAC,KACA,EAAkB,aAAc,OAAQ,CACtC,iBAAkB,EAAM,WACzB,CAAC,CACH,CAQH,YAAqD,CACnD,OAAO,EAAO,IACZ,WAAqC,CAEnC,IAAM,EAAU,MAAO,KAAK,aAAa,CAYzC,OATsB,MAAO,EAAO,WAAW,CAC7C,QAAW,EAAQ,YAAY,CAC/B,MAAQ,GACN,EAAgB,SAAS,oBAAqB,CAC5C,KAAM,+BACN,QAAS,CAAE,QAAO,CACnB,CAAC,CACL,CAAC,EAEmB,SAAW,WAChC,KAAK,KAAK,CACb,CAAC,KAAK,EAAkB,aAAc,cAAe,EAAE,CAAC,CAAC,GAsB9D,SAAgB,EACd,EAAgC,EAAE,CACU,CAC5C,OAAO,EAAM,QAAQ,EAAiB,IAAI,EAAmB,EAAO,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/clamscan-plugin.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport * as fs from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { UploadistaError } from \"@uploadista/core/errors\";\nimport type { ScanResult, VirusScanPluginShape } from \"@uploadista/core/flow\";\nimport { VirusScanPlugin } from \"@uploadista/core/flow\";\nimport { withOperationSpan } from \"@uploadista/observability\";\nimport NodeClam from \"clamscan\";\nimport { Effect, Layer } from \"effect\";\n\n/**\n * Configuration options for the ClamAV Virus Scan plugin\n */\nexport interface VirusScanPluginConfig {\n /**\n * Preference for scanning method\n * - \"clamdscan\": Use clamd daemon (faster, recommended)\n * - \"clamscan\": Use command-line binary\n */\n preference?: \"clamdscan\" | \"clamscan\";\n\n /**\n * Path to clamd socket (for daemon mode)\n * Default: /var/run/clamd.scan/clamd.sock\n */\n clamdscan_socket?: string;\n\n /**\n * TCP host for clamd (alternative to socket)\n */\n clamdscan_host?: string;\n\n /**\n * TCP port for clamd\n * Default: 3310\n */\n clamdscan_port?: number;\n\n /**\n * Whether to remove infected files automatically\n * Default: false (not recommended in flow context)\n */\n remove_infected?: boolean;\n\n /**\n * Debug mode for clamscan library\n * Default: false\n */\n debug_mode?: boolean;\n}\n\n/**\n * ClamAV implementation of the VirusScanPlugin\n *\n * This plugin uses the `clamscan` npm package to scan files for viruses\n * using ClamAV antivirus engine. It supports both clamd daemon mode (fast)\n * and binary mode (slower but more portable).\n *\n * @example\n * ```typescript\n * import { ClamScanPluginLayer } from \"@uploadista/flow-security-clamscan\";\n *\n * const program = Effect.gen(function* () {\n * const virusScan = yield* VirusScanPlugin;\n * const result = yield* virusScan.scan(fileBytes);\n * console.log(result.isClean ? \"Clean\" : \"Infected\");\n * }).pipe(Effect.provide(ClamScanPluginLayer));\n * ```\n */\nclass ClamScanPluginImpl implements VirusScanPluginShape {\n private clamscan: NodeClam | null = null;\n\n constructor(private config: VirusScanPluginConfig = {}) {}\n\n /**\n * Initialize the ClamAV scanner\n * This is called lazily on first use\n */\n private initScanner(): Effect.Effect<NodeClam, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n if (this.clamscan) {\n return this.clamscan;\n }\n\n const scanner = yield* Effect.tryPromise({\n try: async () => {\n // Initialize clamscan with configuration\n return await new NodeClam().init({\n preference: this.config.preference ?? \"clamdscan\",\n remove_infected: this.config.remove_infected ?? false,\n debug_mode: this.config.debug_mode ?? false,\n clamdscan: {\n socket: this.config.clamdscan_socket,\n host: this.config.clamdscan_host,\n port: this.config.clamdscan_port ?? 3310,\n timeout: 60000,\n local_fallback: true, // Fall back to binary if daemon unavailable\n },\n clamscan: {\n path: \"/usr/bin/clamscan\", // Standard path\n scan_archives: true,\n active: true,\n },\n });\n },\n catch: (error) =>\n UploadistaError.fromCode(\"CLAMAV_NOT_INSTALLED\", {\n body: `ClamAV initialization failed: ${error instanceof Error ? error.message : String(error)}`,\n details: { error },\n }),\n });\n\n this.clamscan = scanner;\n return scanner;\n }.bind(this),\n ).pipe(\n withOperationSpan(\"virus-scan\", \"init\", {\n \"scan.preference\": this.config.preference ?? \"clamdscan\",\n }),\n );\n }\n\n /**\n * Scans a file for viruses using ClamAV\n *\n * @param input - File contents as Uint8Array\n * @returns Effect with scan results\n */\n scan(input: Uint8Array): Effect.Effect<ScanResult, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n // Initialize scanner (lazy initialization)\n const scanner = yield* this.initScanner();\n\n // Create temporary file path for scanning\n const tmpDir = os.tmpdir();\n const fileName = `uploadista-scan-${randomUUID()}`;\n const tempFilePath = path.join(tmpDir, fileName);\n\n // Write file data to temp file\n yield* Effect.tryPromise({\n try: () => fs.writeFile(tempFilePath, input),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: \"Failed to create temporary file for scanning\",\n details: { error },\n }),\n });\n\n // Scan the file and ensure cleanup\n const result = yield* Effect.tryPromise({\n try: () => scanner.isInfected(tempFilePath),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: `Virus scan failed: ${error instanceof Error ? error.message : String(error)}`,\n details: { error },\n }),\n }).pipe(\n Effect.map((scanResult) => ({\n isClean: !scanResult.isInfected,\n detectedViruses: scanResult.viruses || [],\n })),\n Effect.ensuring(\n // Clean up temporary file (ignore errors)\n Effect.tryPromise({\n try: () => fs.unlink(tempFilePath),\n catch: () => undefined,\n }).pipe(Effect.ignore),\n ),\n );\n\n return result;\n }.bind(this),\n ).pipe(\n withOperationSpan(\"virus-scan\", \"scan\", {\n \"scan.file_size\": input.byteLength,\n }),\n );\n }\n\n /**\n * Gets the ClamAV engine version\n *\n * @returns Effect with version string\n */\n getVersion(): Effect.Effect<string, UploadistaError> {\n return Effect.gen(\n function* (this: ClamScanPluginImpl) {\n // Initialize scanner (lazy initialization)\n const scanner = yield* this.initScanner();\n\n // Get version from ClamAV\n const versionResult = yield* Effect.tryPromise({\n try: () => scanner.getVersion(),\n catch: (error) =>\n UploadistaError.fromCode(\"VIRUS_SCAN_FAILED\", {\n body: \"Failed to get ClamAV version\",\n details: { error },\n }),\n });\n\n return versionResult.version || \"Unknown\";\n }.bind(this),\n ).pipe(withOperationSpan(\"virus-scan\", \"get-version\", {}));\n }\n}\n\n/**\n * Creates a Virus Scan Plugin layer using ClamAV\n *\n * @param config - Optional ClamAV configuration\n * @returns Layer providing VirusScanPlugin\n *\n * @example\n * ```typescript\n * // Use with default configuration\n * const layer = ClamScanPluginLayer();\n *\n * // Use with custom configuration\n * const customLayer = ClamScanPluginLayer({\n * preference: \"clamdscan\",\n * clamdscan_socket: \"/var/run/clamav/clamd.ctl\"\n * });\n * ```\n */\nexport function virusScanPlugin(\n config: VirusScanPluginConfig = {},\n): Layer.Layer<VirusScanPlugin, never, never> {\n return Layer.succeed(VirusScanPlugin, new ClamScanPluginImpl(config));\n}\n"],"mappings":"qXAsEA,IAAM,EAAN,KAAyD,CAGnC,OAFpB,SAAoC,KAEpC,YAAY,EAAwC,CAAC,EAAG,CAApC,KAAA,OAAA,CAAqC,CAMzD,aAAgE,CAC9D,OAAO,EAAO,IACZ,WAAqC,CACnC,GAAI,KAAK,SACP,OAAO,KAAK,SAGd,IAAM,EAAU,MAAO,EAAO,WAAW,CACvC,IAAK,SAEI,MAAM,IAAI,EAAS,CAAC,CAAC,KAAK,CAC/B,WAAY,KAAK,OAAO,YAAc,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AW,CAChB,QAAW,EAAG,OAAO,CAAY,EACjC,UAAa,IAAA,EACf,CAAC,CAAC,CAAC,KAAK,EAAO,MAAM,CACvB,CACF,CAGF,EAAE,KAAK,IAAI,CACb,CAAC,CAAC,KACA,EAAkB,aAAc,OAAQ,CACtC,iBAAkB,EAAM,UAC1B,CAAC,CACH,CACF,CAOA,YAAqD,CACnD,OAAO,EAAO,IACZ,WAAqC,CAEnC,IAAM,EAAU,MAAO,KAAK,YAAY,EAYxC,OAAO,MATsB,EAAO,WAAW,CAC7C,QAAW,EAAQ,WAAW,EAC9B,MAAQ,GACN,EAAgB,SAAS,oBAAqB,CAC5C,KAAM,+BACN,QAAS,CAAE,OAAM,CACnB,CAAC,CACL,CAAC,EAAA,CAEoB,SAAW,SAClC,EAAE,KAAK,IAAI,CACb,CAAC,CAAC,KAAK,EAAkB,aAAc,cAAe,CAAC,CAAC,CAAC,CAC3D,CACF,EAoBA,SAAgB,EACd,EAAgC,CAAC,EACW,CAC5C,OAAO,EAAM,QAAQ,EAAiB,IAAI,EAAmB,CAAM,CAAC,CACtE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/flow-security-clamscan",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0",
5
5
  "description": "ClamAV virus scanning plugin for Uploadista Flow",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -15,21 +15,21 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "clamscan": "^2.3.3",
18
- "@uploadista/core": "1.0.0-beta.3",
19
- "@uploadista/observability": "1.0.0-beta.3"
18
+ "@uploadista/core": "1.0.0",
19
+ "@uploadista/observability": "1.0.0"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "effect": "^3.0.0",
23
23
  "zod": "^4.0.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@effect/vitest": "0.27.0",
26
+ "@effect/vitest": "0.29.0",
27
27
  "@types/node": "24.10.9",
28
- "effect": "3.19.19",
29
- "tsdown": "0.20.3",
30
- "vitest": "4.0.18",
31
- "zod": "4.3.6",
32
- "@uploadista/typescript-config": "1.0.0-beta.3"
28
+ "effect": "3.21.4",
29
+ "tsdown": "0.22.3",
30
+ "vitest": "4.1.10",
31
+ "zod": "4.4.3",
32
+ "@uploadista/typescript-config": "1.0.0"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc --noEmit && tsdown",
package/tsconfig.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "extends": "@uploadista/typescript-config/server.json",
3
3
  "compilerOptions": {
4
- "baseUrl": "./",
5
4
  "paths": {
6
5
  "@/*": ["./src/*"]
7
6
  },