@coreframe/object-storage 0.0.0 → 0.1.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/credentials.d.ts +35 -0
- package/dist/credentials.js +1 -0
- package/dist/environment.js +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +1 -0
- package/package.json +33 -10
- package/readme.md +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/credentials.d.ts
|
|
2
|
+
declare const assetCredentialEnvironment: {
|
|
3
|
+
readonly applicationKey: "COREFRAME_ASSETS_B2_APPLICATION_KEY";
|
|
4
|
+
readonly applicationKeyId: "COREFRAME_ASSETS_B2_APPLICATION_KEY_ID";
|
|
5
|
+
};
|
|
6
|
+
type AssetCredentials = {
|
|
7
|
+
applicationKey: string;
|
|
8
|
+
applicationKeyId: string;
|
|
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
|
+
declare function resolveAssetCredentials({
|
|
16
|
+
env,
|
|
17
|
+
profile,
|
|
18
|
+
store
|
|
19
|
+
}: {
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
profile: string;
|
|
22
|
+
store?: AssetCredentialStore;
|
|
23
|
+
}): Promise<AssetCredentials>;
|
|
24
|
+
declare function configureAssetCredentials({
|
|
25
|
+
applicationKey,
|
|
26
|
+
applicationKeyId,
|
|
27
|
+
profile,
|
|
28
|
+
store
|
|
29
|
+
}: AssetCredentials & {
|
|
30
|
+
profile: string;
|
|
31
|
+
store?: AssetCredentialStore;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
declare function assertAssetCredentialProfile(profile: string): string;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { AssetCredentialStore, AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials, systemAssetCredentialStore };
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +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};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AssetCredentialStore, AssetCredentials, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, resolveAssetCredentials, systemAssetCredentialStore } from "./credentials.js";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type PrivateObjectStore = {
|
|
5
|
+
has(bucket: string, key: string): Promise<boolean>;
|
|
6
|
+
download(bucket: string, key: string, target: string): Promise<void>;
|
|
7
|
+
upload(bucket: string, key: string, source: string, contentType: string): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
type PrivateObjectStoreConfig = {
|
|
10
|
+
credentialProfile: string;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
region: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates the shared private S3-compatible store used by managed-asset sources and build-only state
|
|
16
|
+
* such as i18n snapshots. The credential names remain compatible with existing Coreframe projects.
|
|
17
|
+
*/
|
|
18
|
+
declare function createB2PrivateObjectStore({
|
|
19
|
+
config,
|
|
20
|
+
credentialStore,
|
|
21
|
+
env
|
|
22
|
+
}: {
|
|
23
|
+
config: PrivateObjectStoreConfig;
|
|
24
|
+
credentialStore?: AssetCredentialStore;
|
|
25
|
+
env?: NodeJS.ProcessEnv;
|
|
26
|
+
}): PrivateObjectStore;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { type AssetCredentialStore, type AssetCredentials, PrivateObjectStore, PrivateObjectStoreConfig, assertAssetCredentialProfile, assetCredentialEnvironment, configureAssetCredentials, createB2PrivateObjectStore, resolveAssetCredentials, systemAssetCredentialStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +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};
|
package/package.json
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreframe/object-storage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/airlock-labs/coreframe.git",
|
|
7
|
+
"directory": "node/object-storage"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@aws-sdk/client-s3": "^3.1090.0",
|
|
21
|
+
"cross-keychain": "1.1.0"
|
|
8
22
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^26.1.0",
|
|
25
|
+
"tsdown": "0.22.3",
|
|
26
|
+
"typescript": "6.0.3",
|
|
27
|
+
"vitest": "^4.1.9"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsdown",
|
|
31
|
+
"test": "vitest run --reporter=minimal",
|
|
32
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
33
|
+
"format": "oxlint --fix && oxfmt",
|
|
34
|
+
"lint": "oxlint"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/readme.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Coming soon...
|