New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nimbella/storage

Package Overview
Dependencies
Maintainers
4
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nimbella/storage - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

1

lib/index.d.ts
import { StorageProvider } from './providers/interface';
export declare function getStorageProvider(providerId: string): StorageProvider;
export * from './providers/interface';

2

lib/index.js

@@ -1,2 +0,2 @@

var F=Object.create,u=Object.defineProperty,N=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty,R=Object.getOwnPropertyNames,M=Object.getOwnPropertyDescriptor;var S=r=>u(r,"__esModule",{value:!0});var U=(r,e)=>{for(var t in e)u(r,t,{get:e[t],enumerable:!0})},D=(r,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of R(e))!B.call(r,n)&&n!=="default"&&u(r,n,{get:()=>e[n],enumerable:!(t=M(e,n))||t.enumerable});return r},d=r=>D(S(u(r!=null?F(N(r)):{},"default",r&&r.__esModule&&"default"in r?{get:()=>r.default,enumerable:!0}:{value:r,enumerable:!0})),r);S(exports);U(exports,{getStorageProvider:()=>G});var o=d(require("@aws-sdk/client-s3")),h=d(require("@aws-sdk/s3-request-presigner")),g=d(require("fs")),C=d(require("memory-streams")),O=d(require("debug")),c=(0,O.default)("nim:storage-s3"),f=class{constructor(e,t,n,i){c("created file handle for %s",n),this.s3=e,this.bucketName=t,this.name=n,this.web=i}getImplementation(){return this.s3}save(e,t){var s,a;c("save was called for file %s",this.name);let n=this.web?"public-read":void 0,i=new o.PutObjectCommand({Bucket:this.bucketName,Key:this.name,Body:e,ContentType:(s=t==null?void 0:t.metadata)==null?void 0:s.contentType,CacheControl:(a=t==null?void 0:t.metadata)==null?void 0:a.cacheControl,ACL:n});return this.s3.send(i)}setMetadata(e){c("setMetadata was called for file %s",this.name);let t=`${this.bucketName}/${this.name}`,{cacheControl:n,contentType:i}=e,s=this.web?"public-read":void 0,a=new o.CopyObjectCommand({CopySource:t,Bucket:this.bucketName,Key:this.name,CacheControl:n,ContentType:i,MetadataDirective:"REPLACE",ACL:s});return this.s3.send(a)}async getMetadata(){var a;c("getMetadata was called for file %s",this.name);let e=new o.HeadObjectCommand({Bucket:this.bucketName,Key:this.name}),t=await this.s3.send(e),{StorageClass:n,ContentLength:i,ETag:s}=t;return{name:this.name,storageClass:n,size:String(i),etag:s,updated:(a=t.LastModified)==null?void 0:a.toISOString()}}async exists(){return c("exists was called for file %s",this.name),!!await this.getMetadata()}delete(){c("delete was called for file %s",this.name);let e=new o.DeleteObjectCommand({Bucket:this.bucketName,Key:this.name});return this.s3.send(e)}async download(e){c("download was called for file %s",this.name);let t=(e==null?void 0:e.destination)?(0,g.createWriteStream)(e.destination):new C.WritableStream({highWaterMark:1024*1024});c("download: created destination for options %O",e);let n=new o.GetObjectCommand({Bucket:this.bucketName,Key:this.name});c("will send command: %O",n);let i=await this.s3.send(n);c("got back result: %O",i);let s=i.Body;return c("about to pipe"),await K(s,t),c("piping complete"),(e==null?void 0:e.destination)?Buffer.from(""):t.toBuffer()}async getSignedUrl(e){c("getSignedUrl was called for file %s",this.name);let{action:t,expires:n,version:i,contentType:s}=e;if(i!=="v4")throw new Error("Signing version v4 is required for s3");let a,l=this.web?"public-read":void 0;switch(t){case"read":a=new o.GetObjectCommand({Bucket:this.bucketName,Key:this.name});break;case"write":a=new o.PutObjectCommand({Bucket:this.bucketName,Key:this.name,ContentType:s,ACL:l});break;case"delete":a=new o.DeleteObjectCommand({Bucket:this.bucketName,Key:this.name})}if(!a)throw new Error("The action for a signed URL must be one of 'read' | 'write' | 'delete'");if(n){let m=Math.round((new Date(n).getTime()-Date.now())/1e3);return(0,h.getSignedUrl)(this.s3,a,{expiresIn:m})}return(0,h.getSignedUrl)(this.s3,a,{})}};function K(r,e){let t=new Promise(function(n){e.on("close",()=>{n(!0)}),e.on("finish",()=>{n(!0)})});return r.pipe(e),t}var b=class{constructor(e,t,n=""){c("s3client: %O, bucketName=%s, url=%s",e.config,t,n),this.s3=e,this.bucketName=t,this.url=n}getImplementation(){return this.s3}getURL(){return this.url}getBucketName(){return this.bucketName}setWebsite(e){c("setWebsite was called for bucket %s",this.bucketName);let{notFoundPage:t,mainPageSuffix:n}=e,i=new o.PutBucketWebsiteCommand({Bucket:this.bucketName,WebsiteConfiguration:{ErrorDocument:{Key:t},IndexDocument:{Suffix:n}}});return this.s3.send(i)}async deleteFiles(e){c("deleteFiles was called for bucket %s",this.bucketName);let t=new o.ListObjectsCommand({Bucket:this.bucketName,Prefix:e==null?void 0:e.prefix}),n=await this.s3.send(t);if(!n.Contents)return!0;let i=n.Contents.map(a=>({Key:a.Key})),s=new o.DeleteObjectsCommand({Bucket:this.bucketName,Delete:{Objects:i}});return this.s3.send(s)}file(e){return new f(this.s3,this.bucketName,e,!!this.url)}upload(e,t){var l,m;c("upload was called for path %s to bucket %s",e,this.bucketName);let n=(0,g.createReadStream)(e),i=(t==null?void 0:t.destination)||e,s=this.url?"public-read":void 0,a=new o.PutObjectCommand({Bucket:this.bucketName,Key:i,ContentType:(l=t==null?void 0:t.metadata)==null?void 0:l.contentType,CacheControl:(m=t==null?void 0:t.metadata)==null?void 0:m.cacheControl,Body:n,ACL:s});return this.s3.send(a)}async getFiles(e){c("getFiles was called for bucket %s",this.bucketName);let t=new o.ListObjectsCommand({Bucket:this.bucketName,Prefix:e==null?void 0:e.prefix}),n=await this.s3.send(t);return x((n.Contents||[]).map(s=>s.Key)).map(s=>new f(this.s3,this.bucketName,s,!!this.url))}};function x(r=[]){return r.filter(e=>!!e)}function W(r,e,t){let n=r.replace("https://","").split(".")[0];c("calculated deployment %s from apihost %s",n,r);let i=`${e}-${n}-nimbella-io`;return t?i:`data-${i}`}function L(r,e){if(!r)throw new Error("Every credential set on AWS must have either a web URL or an endpoint URL");let t=new URL(r);return`http://${e}.${t.hostname}`}var j={prepareCredentials:r=>(c("preparing credentials: %O",r),r),getClient:(r,e,t,n)=>{c("making S3Client with credentials %O",n);let i=new o.S3Client(n);c("have client: %O",i);let s=W(e,r,t);if(t){let a=n.weburl||L(n.endpoint,s);return new b(i,s,a)}return new b(i,s)},identifier:"@nimbella/storage-s3"},p=j;var v=d(require("@google-cloud/storage")),w=class{constructor(e){this.file=e,this.name=e.name}getImplementation(){return this.file}save(e,t){return this.file.save(e,t)}setMetadata(e){return this.file.setMetadata(e)}async getMetadata(){return(await this.file.getMetadata())[0]}async exists(){return(await this.file.exists())[0]}delete(){return this.file.delete()}async download(e){return(await this.file.download(e))[0]}async getSignedUrl(e){return(await this.file.getSignedUrl(e))[0]}},k=class{constructor(e,t=""){this.bucket=e,this.url=t}getImplementation(){return this.bucket}getURL(){return this.url}setWebsite(e){return this.bucket.setMetadata({website:e})}deleteFiles(e){return this.bucket.deleteFiles(e)}file(e){return new w(this.bucket.file(e))}upload(e,t){return this.bucket.upload(e,t)}async getFiles(e){return(await this.bucket.getFiles(e))[0].map(n=>new w(n))}};function T(r,e,t){let n=P(r,e).split(".").join("-");return t?n:`data-${n}`}function P(r,e){let t=new URL(r);return e+"-"+t.hostname}var $={prepareCredentials:r=>{let{client_email:e,private_key:t,project_id:n}=r;return{credentials:{client_email:e,private_key:t},project_id:n,provider:"@nimbella/storage-gcs"}},getClient:(r,e,t,n)=>{let i=new v.Storage(n),s=T(e,r,t),a=i.bucket(s);if(t){let l=`https://${P(e,r)}`;return new k(a,l)}return new k(a)},identifier:"@nimbella/storage-gcs"},y=$;var E=new Map([[p.identifier,p],[y.identifier,y]]);function G(r){let e=E.get(r);if(!e)throw new Error(`Unable to find storage provider with id: ${r}`);return e}0&&(module.exports={getStorageProvider});
var F=Object.create,u=Object.defineProperty,x=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty,M=Object.getOwnPropertyNames,N=Object.getOwnPropertyDescriptor;var k=n=>u(n,"__esModule",{value:!0});var R=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},U=(n,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of M(e))!B.call(n,i)&&i!=="default"&&u(n,i,{get:()=>e[i],enumerable:!(t=N(e,i))||t.enumerable});return n},d=n=>U(k(u(n!=null?F(x(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);k(exports);R(exports,{getStorageProvider:()=>G});var o=d(require("@aws-sdk/client-s3")),p=d(require("@aws-sdk/s3-request-presigner")),g=d(require("fs")),C=d(require("memory-streams")),O=d(require("debug")),l=(0,O.default)("nim:storage-s3"),f=class{constructor(e,t,i,r){l("created file handle for %s",i),this.s3=e,this.bucketName=t,this.name=i,this.web=r}getImplementation(){return this.s3}save(e,t){var a,s;l("save was called for file %s",this.name);let i=this.web?"public-read":void 0,r=new o.PutObjectCommand({Bucket:this.bucketName,Key:this.name,Body:e,ContentType:(a=t==null?void 0:t.metadata)==null?void 0:a.contentType,CacheControl:(s=t==null?void 0:t.metadata)==null?void 0:s.cacheControl,ACL:i});return this.s3.send(r)}setMetadata(e){l("setMetadata was called for file %s",this.name);let t=`${this.bucketName}/${this.name}`,{cacheControl:i,contentType:r}=e,a=this.web?"public-read":void 0,s=new o.CopyObjectCommand({CopySource:t,Bucket:this.bucketName,Key:this.name,CacheControl:i,ContentType:r,MetadataDirective:"REPLACE",ACL:a});return this.s3.send(s)}async getMetadata(){var s;l("getMetadata was called for file %s",this.name);let e=new o.HeadObjectCommand({Bucket:this.bucketName,Key:this.name}),t=await this.s3.send(e),{StorageClass:i,ContentLength:r,ETag:a}=t;return{name:this.name,storageClass:i,size:String(r),etag:a,updated:(s=t.LastModified)==null?void 0:s.toISOString()}}async exists(){return l("exists was called for file %s",this.name),!!await this.getMetadata()}delete(){l("delete was called for file %s",this.name);let e=new o.DeleteObjectCommand({Bucket:this.bucketName,Key:this.name});return this.s3.send(e)}async download(e){l("download was called for file %s",this.name);let t=(e==null?void 0:e.destination)?(0,g.createWriteStream)(e.destination):new C.WritableStream({highWaterMark:1024*1024});l("download: created destination for options %O",e);let i=new o.GetObjectCommand({Bucket:this.bucketName,Key:this.name});l("will send command: %O",i);let r=await this.s3.send(i);l("got back result: %O",r);let a=r.Body;return l("about to pipe"),await D(a,t),l("piping complete"),(e==null?void 0:e.destination)?Buffer.from(""):t.toBuffer()}async getSignedUrl(e){l("getSignedUrl was called for file %s",this.name);let{action:t,expires:i,version:r,contentType:a}=e;if(r!=="v4")throw new Error("Signing version v4 is required for s3");let s,c=this.web?"public-read":void 0;switch(t){case"read":s=new o.GetObjectCommand({Bucket:this.bucketName,Key:this.name});break;case"write":s=new o.PutObjectCommand({Bucket:this.bucketName,Key:this.name,ContentType:a,ACL:c});break;case"delete":s=new o.DeleteObjectCommand({Bucket:this.bucketName,Key:this.name})}if(!s)throw new Error("The action for a signed URL must be one of 'read' | 'write' | 'delete'");if(i){let m=Math.round((new Date(i).getTime()-Date.now())/1e3);return(0,p.getSignedUrl)(this.s3,s,{expiresIn:m})}return(0,p.getSignedUrl)(this.s3,s,{})}};function D(n,e){let t=new Promise(function(i){e.on("close",()=>{i(!0)}),e.on("finish",()=>{i(!0)})});return n.pipe(e),t}var h=class{constructor(e,t,i=""){l("s3client: %O, bucketName=%s, url=%s",e.config,t,i),this.s3=e,this.bucketName=t,this.url=i}getImplementation(){return this.s3}getURL(){return this.url}getBucketName(){return this.bucketName}setWebsite(e){l("setWebsite was called for bucket %s",this.bucketName);let{notFoundPage:t,mainPageSuffix:i}=e,r=new o.PutBucketWebsiteCommand({Bucket:this.bucketName,WebsiteConfiguration:{ErrorDocument:{Key:t},IndexDocument:{Suffix:i}}});return this.s3.send(r)}async deleteFiles(e){l("deleteFiles was called for bucket %s",this.bucketName);let t=new o.ListObjectsCommand({Bucket:this.bucketName,Prefix:e==null?void 0:e.prefix}),i=await this.s3.send(t);if(!i.Contents)return!0;let r=i.Contents.map(s=>({Key:s.Key})),a=new o.DeleteObjectsCommand({Bucket:this.bucketName,Delete:{Objects:r}});return this.s3.send(a)}file(e){return new f(this.s3,this.bucketName,e,!!this.url)}upload(e,t){var c,m;l("upload was called for path %s to bucket %s",e,this.bucketName);let i=(0,g.createReadStream)(e),r=(t==null?void 0:t.destination)||e,a=this.url?"public-read":void 0,s=new o.PutObjectCommand({Bucket:this.bucketName,Key:r,ContentType:(c=t==null?void 0:t.metadata)==null?void 0:c.contentType,CacheControl:(m=t==null?void 0:t.metadata)==null?void 0:m.cacheControl,Body:i,ACL:a});return this.s3.send(s)}async getFiles(e){l("getFiles was called for bucket %s",this.bucketName);let t=new o.ListObjectsCommand({Bucket:this.bucketName,Prefix:e==null?void 0:e.prefix}),i=await this.s3.send(t);return K((i.Contents||[]).map(a=>a.Key)).map(a=>new f(this.s3,this.bucketName,a,!!this.url))}};function K(n=[]){return n.filter(e=>!!e)}function W(n,e,t){let i=n.replace("https://","").split(".")[0];l("calculated deployment %s from apihost %s",i,n);let r=`${e}-${i}-nimbella-io`;return t?r:`data-${r}`}function L(n,e){if(!n)throw new Error("Every credential set on AWS must have either a web URL or an endpoint URL");let t=new URL(n);return`http://${e}.${t.hostname}`}var T={prepareCredentials:n=>(l("preparing credentials: %O",n),n),getClient:(n,e,t,i)=>{l("making S3Client with credentials %O",i);let r=new o.S3Client(i);l("have client: %O",r);let a=W(e,n,t);if(t){let s=i.weburl||L(i.endpoint,a);return new h(r,a,s)}return new h(r,a)},identifier:"@nimbella/storage-s3"},b=T;var P=d(require("@google-cloud/storage")),w=class{constructor(e){this.file=e,this.name=e.name}getImplementation(){return this.file}save(e,t){return this.file.save(e,t)}setMetadata(e){return this.file.setMetadata(e)}async getMetadata(){return(await this.file.getMetadata())[0]}async exists(){return(await this.file.exists())[0]}delete(){return this.file.delete()}async download(e){return(await this.file.download(e))[0]}async getSignedUrl(e){return(await this.file.getSignedUrl(e))[0]}},y=class{constructor(e,t=""){this.bucket=e,this.url=t}getImplementation(){return this.bucket}getURL(){return this.url}setWebsite(e){return this.bucket.setMetadata({website:e})}deleteFiles(e){return this.bucket.deleteFiles(e)}file(e){return new w(this.bucket.file(e))}upload(e,t){return this.bucket.upload(e,t)}async getFiles(e){return(await this.bucket.getFiles(e))[0].map(i=>new w(i))}};function j(n,e,t){let i=v(n,e).split(".").join("-");return t?i:`data-${i}`}function v(n,e){let t=new URL(n);return e+"-"+t.hostname}var $={prepareCredentials:n=>{let{client_email:e,private_key:t,project_id:i}=n;return{credentials:{client_email:e,private_key:t},project_id:i,provider:"@nimbella/storage-gcs"}},getClient:(n,e,t,i)=>{let r=new P.Storage(i),a=j(e,n,t),s=r.bucket(a);if(t){let c=`https://${v(e,n)}`;return new y(s,c)}return new y(s)},identifier:"@nimbella/storage-gcs"},S=$;var E=new Map([[b.identifier,b],[S.identifier,S]]);function G(n){let e=E.get(n);if(!e)throw new Error(`Unable to find storage provider with id: ${n}`);return e}0&&(module.exports={getStorageProvider});
//# sourceMappingURL=index.js.map
{
"name": "@nimbella/storage",
"version": "0.0.2",
"version": "0.0.3",
"description": "Nimbella Platform Storage providers implementations and interfaces types.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -33,1 +33,3 @@ /*

}
export * from './providers/interface'

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc