@coreframe/object-storage 0.1.3 → 0.1.5-next.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.
package/dist/index.d.ts CHANGED
@@ -6,6 +6,13 @@ type PrivateObjectStore = {
6
6
  download(bucket: string, key: string, target: string): Promise<void>;
7
7
  upload(bucket: string, key: string, source: string, contentType: string): Promise<void>;
8
8
  };
9
+ type ListedObject = {
10
+ key: string;
11
+ size: number;
12
+ };
13
+ type ListablePrivateObjectStore = PrivateObjectStore & {
14
+ list(bucket: string): Promise<ListedObject[]>;
15
+ };
9
16
  type PrivateObjectStoreConfig = {
10
17
  credentialProfile: string;
11
18
  endpoint: string;
@@ -21,6 +28,6 @@ declare function createB2PrivateObjectStore({
21
28
  }: {
22
29
  config: PrivateObjectStoreConfig;
23
30
  env?: NodeJS.ProcessEnv;
24
- }): PrivateObjectStore;
31
+ }): ListablePrivateObjectStore;
25
32
  //#endregion
26
- export { type AssetCredentials, PrivateObjectStore, PrivateObjectStoreConfig, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, createB2PrivateObjectStore, resolveAssetCredentials };
33
+ export { type AssetCredentials, ListablePrivateObjectStore, ListedObject, PrivateObjectStore, PrivateObjectStoreConfig, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, createB2PrivateObjectStore, resolveAssetCredentials };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{fs as e,process as t}from"./environment.js";import{assertAssetCredentialProfile as n,assetCredentialEnvironment as r,configureAssetCredentials as i,resolveAssetCredentials as a}from"./credentials.js";import{pipeline as o}from"node:stream/promises";import{GetObjectCommand as s,HeadObjectCommand as c,PutObjectCommand as l,S3Client as u}from"@aws-sdk/client-s3";function d({config:n,env:r=t.env}){let i;async function d(){if(i)return i;let e=await a({env:r,profile:n.credentialProfile});return i=new u({endpoint:n.endpoint,forcePathStyle:!0,region:n.region,credentials:{accessKeyId:e.applicationKeyId,secretAccessKey:e.applicationKey}}),i}return{async has(e,t){try{return await(await d()).send(new c({Bucket:e,Key:t})),!0}catch(e){if(e.$metadata?.httpStatusCode===404)return!1;throw e}},async download(t,n,r){let i=await(await d()).send(new s({Bucket:t,Key:n}));if(!i.Body)throw Error(`Backblaze B2 returned an empty body for ${t}/${n}.`);await o(i.Body,e.createWriteStream(r,{flags:`wx`}))},async upload(t,n,r,i){let{size:a}=await e.stat(r);await(await d()).send(new l({Bucket:t,Key:n,Body:e.createReadStream(r),ContentLength:a,ContentType:i}))}}}export{n as assertAssetCredentialProfile,r as assetCredentialEnvironment,i as configureAssetCredentials,d as createB2PrivateObjectStore,a as resolveAssetCredentials};
1
+ import{fs as e,process as t}from"./environment.js";import{assertAssetCredentialProfile as n,assetCredentialEnvironment as r,configureAssetCredentials as i,resolveAssetCredentials as a}from"./credentials.js";import{pipeline as o}from"node:stream/promises";import{GetObjectCommand as s,HeadObjectCommand as c,ListObjectsV2Command as l,PutObjectCommand as u,S3Client as d}from"@aws-sdk/client-s3";function f({config:n,env:r=t.env}){let i;async function f(){if(i)return i;let e=await a({env:r,profile:n.credentialProfile});return i=new d({endpoint:n.endpoint,forcePathStyle:!0,region:n.region,credentials:{accessKeyId:e.applicationKeyId,secretAccessKey:e.applicationKey}}),i}return{async list(e){let t=[],n;do{let r=await(await f()).send(new l({Bucket:e,ContinuationToken:n}));for(let e of r.Contents??[])e.Key!==void 0&&t.push({key:e.Key,size:e.Size??0});if(r.IsTruncated&&!r.NextContinuationToken)throw Error(`Backblaze B2 truncated the object listing for ${e} without a token.`);n=r.IsTruncated?r.NextContinuationToken:void 0}while(n);return t},async has(e,t){try{return await(await f()).send(new c({Bucket:e,Key:t})),!0}catch(e){if(e.$metadata?.httpStatusCode===404)return!1;throw e}},async download(t,n,r){let i=await(await f()).send(new s({Bucket:t,Key:n}));if(!i.Body)throw Error(`Backblaze B2 returned an empty body for ${t}/${n}.`);await o(i.Body,e.createWriteStream(r,{flags:`wx`}))},async upload(t,n,r,i){let{size:a}=await e.stat(r);await(await f()).send(new u({Bucket:t,Key:n,Body:e.createReadStream(r),ContentLength:a,ContentType:i}))}}}export{n as assertAssetCredentialProfile,r as assetCredentialEnvironment,i as configureAssetCredentials,f as createB2PrivateObjectStore,a as resolveAssetCredentials};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@coreframe/object-storage",
3
- "version": "0.1.3",
3
+ "version": "0.1.5-next.0",
4
4
  "description": "Object-storage credentials and S3 utilities for Coreframe apps",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/airlock-labs/coreframe.git",
7
+ "url": "git+https://github.com/coreframe-js/coreframe.git",
8
8
  "directory": "node/object-storage"
9
9
  },
10
10
  "files": [