@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.
@@ -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 { AssetCredentialStore, AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials, systemAssetCredentialStore };
26
+ export { AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials };
@@ -1 +1 @@
1
- import{process as e}from"./environment.js";import{getKeyring as t,getPassword as n,initBackend as r,setPassword as i}from"cross-keychain";const a=`dev.coreframe.assets`,o=new Set([`macos`,`native-macos`,`native-windows`,`secret-service`,`windows`]),s={applicationKey:`COREFRAME_ASSETS_B2_APPLICATION_KEY`,applicationKeyId:`COREFRAME_ASSETS_B2_APPLICATION_KEY_ID`};function c(){let e=!1;async function s(){if(e)return;await r(e=>o.has(e.id));let n=await t();if(!o.has(n.id))throw Error(`No supported operating system credential store is available. Coreframe requires macOS Keychain, Windows Credential Manager, or Linux Secret Service.`);e=!0}return{async get(e){await s();let t=await n(a,e);if(t)try{return p(JSON.parse(t))}catch{throw Error(`The Coreframe asset credential profile "${e}" is invalid. Run: coreframe assets configure ${e}`)}},async set(e,t){await s(),await i(a,e,JSON.stringify(p(t)))}}}async function l({env:t=e.env,profile:n,store:r=c()}){let i=t[s.applicationKeyId],a=t[s.applicationKey];if(i||a){if(!i||!a)throw Error(`${s.applicationKeyId} and ${s.applicationKey} must be provided together.`);return{applicationKey:a,applicationKeyId:i}}let o;try{o=await r.get(n)}catch(e){throw Error(`Coreframe could not access the operating system credential store for asset profile "${n}": ${e.message}`)}if(!o)throw Error(`Coreframe asset credential profile "${n}" is not configured. Run: coreframe assets configure ${n}`);return o}async function u({applicationKey:e,applicationKeyId:t,profile:n,store:r=c()}){f(n);try{await r.set(n,p({applicationKey:e,applicationKeyId:t}))}catch(e){throw Error(`Coreframe could not store asset profile "${n}" in the operating system credential store: ${e.message}`)}}function d(e){return f(e),e}function f(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 p(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{d as assertAssetCredentialProfile,s as assetCredentialEnvironment,u as configureAssetCredentials,l as resolveAssetCredentials,c as systemAssetCredentialStore};
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};
@@ -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 i={createReadStream:e,createWriteStream:t,stat:n},a={env:r.env,pid:r.pid};export{i as fs,a as process};
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 { AssetCredentialStore, AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials, systemAssetCredentialStore } from "./credentials.js";
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 AssetCredentialStore, type AssetCredentials, PrivateObjectStore, PrivateObjectStoreConfig, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, createB2PrivateObjectStore, resolveAssetCredentials, systemAssetCredentialStore };
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,systemAssetCredentialStore as o}from"./credentials.js";import{pipeline as s}from"node:stream/promises";import{GetObjectCommand as c,HeadObjectCommand as l,PutObjectCommand as u,S3Client as d}from"@aws-sdk/client-s3";function f({config:n,credentialStore:r,env:i=t.env}){let o;async function f(){if(o)return o;let e=await a({env:i,profile:n.credentialProfile,store:r});return o=new d({endpoint:n.endpoint,forcePathStyle:!0,region:n.region,credentials:{accessKeyId:e.applicationKeyId,secretAccessKey:e.applicationKey}}),o}return{async has(e,t){try{return await(await f()).send(new l({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 c({Bucket:t,Key:n}));if(!i.Body)throw Error(`Backblaze B2 returned an empty body for ${t}/${n}.`);await s(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,o as systemAssetCredentialStore};
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.0",
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
- "cross-keychain": "1.1.0"
22
+ "@napi-rs/keyring": "1.3.0"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@types/node": "^26.1.0",