@coreframe/object-storage 0.1.0 → 0.1.2
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/credentials.d.ts +3 -12
- package/dist/credentials.js +1 -1
- package/dist/environment.js +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/credentials.d.ts
CHANGED
|
@@ -7,29 +7,20 @@ type AssetCredentials = {
|
|
|
7
7
|
applicationKey: string;
|
|
8
8
|
applicationKeyId: string;
|
|
9
9
|
};
|
|
10
|
-
type AssetCredentialStore = {
|
|
11
|
-
get(profile: string): Promise<AssetCredentials | undefined>;
|
|
12
|
-
set(profile: string, credentials: AssetCredentials): Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
declare function systemAssetCredentialStore(): AssetCredentialStore;
|
|
15
10
|
declare function resolveAssetCredentials({
|
|
16
11
|
env,
|
|
17
|
-
profile
|
|
18
|
-
store
|
|
12
|
+
profile
|
|
19
13
|
}: {
|
|
20
14
|
env?: NodeJS.ProcessEnv;
|
|
21
15
|
profile: string;
|
|
22
|
-
store?: AssetCredentialStore;
|
|
23
16
|
}): Promise<AssetCredentials>;
|
|
24
17
|
declare function configureAssetCredentials({
|
|
25
18
|
applicationKey,
|
|
26
19
|
applicationKeyId,
|
|
27
|
-
profile
|
|
28
|
-
store
|
|
20
|
+
profile
|
|
29
21
|
}: AssetCredentials & {
|
|
30
22
|
profile: string;
|
|
31
|
-
store?: AssetCredentialStore;
|
|
32
23
|
}): Promise<void>;
|
|
33
24
|
declare function assertAssetCredentialProfile(profile: string): string;
|
|
34
25
|
//#endregion
|
|
35
|
-
export {
|
|
26
|
+
export { AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials };
|
package/dist/credentials.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{process as
|
|
1
|
+
import{keyring as e,process as t}from"./environment.js";const n=`dev.coreframe.assets`,r={applicationKey:`COREFRAME_ASSETS_B2_APPLICATION_KEY`,applicationKeyId:`COREFRAME_ASSETS_B2_APPLICATION_KEY_ID`};async function i({env:i=t.env,profile:a}){let o=i[r.applicationKeyId],s=i[r.applicationKey];if(o||s){if(!o||!s)throw Error(`${r.applicationKeyId} and ${r.applicationKey} must be provided together.`);return{applicationKey:s,applicationKeyId:o}}let l;try{let t=await e.get(n,a);if(t)try{l=c(JSON.parse(t))}catch{throw Error(`The Coreframe asset credential profile "${a}" is invalid. Run: coreframe assets configure ${a}`)}}catch(e){throw Error(`Coreframe could not access the operating system credential store for asset profile "${a}": ${e.message}`)}if(!l)throw Error(`Coreframe asset credential profile "${a}" is not configured. Run: coreframe assets configure ${a}`);return l}async function a({applicationKey:t,applicationKeyId:r,profile:i}){s(i);try{await e.set(n,i,JSON.stringify(c({applicationKey:t,applicationKeyId:r})))}catch(e){throw Error(`Coreframe could not store asset profile "${i}" in the operating system credential store: ${e.message}`)}}function o(e){return s(e),e}function s(e){if(!/^[a-z0-9][a-z0-9._-]*$/.test(e))throw Error(`Credential profiles must start with a lowercase letter or number and contain only lowercase letters, numbers, dots, underscores, or hyphens.`)}function c(e){if(!e||typeof e!=`object`||typeof e.applicationKeyId!=`string`||!e.applicationKeyId.trim()||typeof e.applicationKey!=`string`||!e.applicationKey.trim())throw Error(`Asset credentials require a non-empty application key ID and application key.`);return{applicationKeyId:e.applicationKeyId.trim(),applicationKey:e.applicationKey}}export{o as assertAssetCredentialProfile,r as assetCredentialEnvironment,a as configureAssetCredentials,i as resolveAssetCredentials};
|
package/dist/environment.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createReadStream as e,createWriteStream as t}from"node:fs";import{stat as n}from"node:fs/promises";import r from"node:process";const
|
|
1
|
+
import{createReadStream as e,createWriteStream as t}from"node:fs";import{stat as n}from"node:fs/promises";import r from"node:process";import{AsyncEntry as i}from"@napi-rs/keyring";const a={createReadStream:e,createWriteStream:t,stat:n},o={env:r.env,pid:r.pid},s={async get(e,t){return await new i(e,t).getPassword()??void 0},async set(e,t,n){await new i(e,t).setPassword(n)}};export{a as fs,s as keyring,o as process};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials } from "./credentials.js";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
type PrivateObjectStore = {
|
|
@@ -17,12 +17,10 @@ type PrivateObjectStoreConfig = {
|
|
|
17
17
|
*/
|
|
18
18
|
declare function createB2PrivateObjectStore({
|
|
19
19
|
config,
|
|
20
|
-
credentialStore,
|
|
21
20
|
env
|
|
22
21
|
}: {
|
|
23
22
|
config: PrivateObjectStoreConfig;
|
|
24
|
-
credentialStore?: AssetCredentialStore;
|
|
25
23
|
env?: NodeJS.ProcessEnv;
|
|
26
24
|
}): PrivateObjectStore;
|
|
27
25
|
//#endregion
|
|
28
|
-
export { type
|
|
26
|
+
export { type AssetCredentials, 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
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/object-storage",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Object-storage credentials and S3 utilities for Coreframe apps",
|
|
4
5
|
"repository": {
|
|
5
6
|
"type": "git",
|
|
6
7
|
"url": "git+https://github.com/airlock-labs/coreframe.git",
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"@aws-sdk/client-s3": "^3.1090.0",
|
|
21
|
-
"
|
|
22
|
+
"@napi-rs/keyring": "1.3.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/node": "^26.1.0",
|