コンテンツにスキップ

@alneas/eaos-server API

Import Contract
@alneas/eaos-server/storage Typed public export
@alneas/eaos-server/storage/s3-compatible Typed public export

Creates an unscoped private-upload, signed-URL storage adapter for R2 or S3.

Imports: @alneas/eaos-server/storage, @alneas/eaos-server/storage/s3-compatible.

declare function createS3CompatibleStorage(config: S3CompatibleStorageConfig): Promise<StorageAdapter>;
Name Type Required Description
config S3CompatibleStorageConfig Yes Provider configuration, credentials, and URL ceiling; see {@link S3CompatibleStorageConfig}.

Promise<StorageAdapter>

A frozen app-core adapter whose uploads reject public=true and whose URLs always use signatures within the configured ceiling.

Server-only: transport/signing stay in app-core and the host supplies secrets. Credentials are resolved once at construction. Signed access also works during a public-bucket migration but cannot close existing public URLs. Keep this unscoped adapter host-owned; give plugins createTenantS3CompatibleStorage. Constructing an adapter does not verify remote credentials or create a bucket.

Rejects invalid provider, lifetime, bucket, account/region, endpoint, or empty credentials, and propagates credential callback/import/adapter construction errors. Subsequent operations propagate transport errors.

import { createS3CompatibleStorage, readS3CompatibleStorageConfig } from "@alneas/eaos-server/storage/s3-compatible";
// The host provisions a private bucket and supplies the documented storage environment.
const config = readS3CompatibleStorageConfig();
if (!config) throw new Error("Storage is not configured");
const storage = await createS3CompatibleStorage(config);
// Retain storage in trusted server code; authorize requests before performing operations.

[FUNCTION] createTenantS3CompatibleStorage

Section titled “[FUNCTION] createTenantS3CompatibleStorage”

Creates provider-backed storage isolated to a verified tenant/plugin scope.

Imports: @alneas/eaos-server/storage, @alneas/eaos-server/storage/s3-compatible.

declare function createTenantS3CompatibleStorage(config: S3CompatibleStorageConfig, options: TenantStorageOptions): Promise<StorageAdapter>;
Name Type Required Description
config S3CompatibleStorageConfig Yes Host provider configuration and credentials.
options TenantStorageOptions Yes Trusted scope and live authorization; an omitted scope URL ceiling inherits config.maxUrlLifetimeSeconds, then 300.

Promise<StorageAdapter>

A frozen scoped adapter; see {@link createTenantStorage} for relative key and operation policy.

The provider ceiling also applies, so a larger scope ceiling cannot increase it. The host owns bucket provisioning and verified identity resolution.

Rejects provider construction failures and invalid scope settings; operations propagate authorization, policy, and transport errors.

import { createTenantS3CompatibleStorage, type S3CompatibleStorageConfig } from "@alneas/eaos-server/storage/s3-compatible";
import type { TenantStorageOptions } from "@alneas/eaos-server/storage";
export async function scopedStorage(config: S3CompatibleStorageConfig, trustedOptions: TenantStorageOptions) {
return createTenantS3CompatibleStorage(config, trustedOptions);
}

Wraps a storage adapter with tenant/plugin key isolation and per-operation authorization.

Imports: @alneas/eaos-server/storage.

declare function createTenantStorage(adapter: StorageAdapter, options: TenantStorageOptions): StorageAdapter;
Name Type Required Description
adapter StorageAdapter Yes Host-owned transport/signing adapter; optional copy and move are exposed only when supported.
options TenantStorageOptions Yes Trusted scope, authorization callback, and signed URL ceiling; see {@link TenantStorageOptions}.

StorageAdapter

A frozen adapter using relative keys while storing under tenants/{tenantId}/plugins/{pluginId}/; returned object keys and list cursors are scope-relative.

Keys cannot be absolute or contain traversal, empty segments, backslashes, percent escapes, control characters, query strings, or fragments. List permits an empty prefix and slash delimiter only. URLs default to a 300-second ceiling and remain usable until expiry after authorization changes. This wrapper supplies no persistence, locking, revocation, or transaction mechanism beyond the underlying adapter. The host must retain ownership of the unscoped adapter.

Throws synchronously for invalid scope IDs or URL lifetime. Operations reject for invalid relative keys, denied access, public uploads, unsigned or overlong URLs, invalid cursors/delimiters, out-of-scope provider results, or propagated adapter/authorization errors.

import { createTenantStorage, type StorageAdapter, type TenantStorageOptions } from "@alneas/eaos-server/storage";
export function pluginStorage(adapter: StorageAdapter, trustedOptions: TenantStorageOptions) {
// Resolve scope and authorization from verified host identity, never request body IDs.
return createTenantStorage(adapter, trustedOptions);
}

Reads trimmed S3 or R2 configuration from a host environment map.

Imports: @alneas/eaos-server/storage, @alneas/eaos-server/storage/s3-compatible.

declare function readS3CompatibleStorageConfig(env?: Record<string, string | undefined>): S3CompatibleStorageConfig | null;
Name Type Required Description
env Record<string, string | undefined> No Environment values; defaults to process.env. EAOS_STORAGE_PROVIDER selects s3/r2 case-insensitively. R2 uses R2_ACCOUNT_ID, R2_BUCKET, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, and optional R2_ENDPOINT. S3 uses S3_BUCKET, S3_REGION, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, optional S3_ENDPOINT, and S3_FORCE_PATH_STYLE (true or 1). EAOS_STORAGE_MAX_URL_SECONDS is converted with Number.

S3CompatibleStorageConfig \| null

Configuration, or null when the provider is absent/blank. This read does not fully validate values; creation validates provider settings.

Returned configuration contains secrets and belongs exclusively in trusted server code.

If a selected provider lacks required nonblank values, or the provider is unsupported.

import { readS3CompatibleStorageConfig } from "@alneas/eaos-server/storage/s3-compatible";
const config = readS3CompatibleStorageConfig();
console.log(config ? "Storage configured" : "Storage disabled");

Selects R2 or S3 transport settings with host-held credentials and a signed URL ceiling.

Imports: @alneas/eaos-server/storage, @alneas/eaos-server/storage/s3-compatible.

type S3CompatibleStorageConfig = Common & (({
provider: 'r2';
} & Omit<R2StorageConfig, 'accessKeyId' | 'secretAccessKey' | 'publicUrl' | 'defaultExpiresIn'>) | ({
provider: 's3';
} & Omit<S3StorageConfig, 'accessKeyId' | 'secretAccessKey' | 'defaultExpiresIn'>));
Name Type Required Description
— — — No call parameters.

Type declaration; no runtime value.

R2 requires a 32-hex-character accountId; S3 requires region. Both require a valid bucket name. Optional endpoints must be HTTPS URLs without credentials, query, or fragment. Provider-specific fields follow app-core storage configuration; public URLs are not configured by this factory.

createS3CompatibleStorage for a complete setup example.

Select Cloudflare R2 transport; accountId must be 32 hexadecimal characters and bucket/credentials must be configured.

Select S3-compatible transport; a nonempty region and valid bucket/credentials are required, with optional HTTPS endpoint.

See the owning declaration and linked feature guide for usage; no standalone example is documented in source.

Compatibility re-export; its implementation and documentation are owned by the owning package @dataarthub/app-core.

Imports: @alneas/eaos-server/storage.

export interface StorageAdapter {
upload(key: string, data: Buffer | Blob | ReadableStream | string, options?: StorageUploadOptions): Promise<StorageObject>;
download(key: string): Promise<Buffer | null>;
getUrl(key: string, options?: StorageURLOptions): Promise<string>;
delete(key: string): Promise<boolean>;
exists(key: string): Promise<boolean>;
head(key: string): Promise<StorageObject | null>;
list(options?: StorageListOptions): Promise<StorageListResult>;
copy?(sourceKey: string, destinationKey: string): Promise<StorageObject>;
move?(sourceKey: string, destinationKey: string): Promise<StorageObject>;
}
Name Type Required Description
upload Promise<StorageObject> Yes See the upstream owning declaration.
download Promise<Buffer | null> Yes See the upstream owning declaration.
getUrl Promise<string> Yes See the upstream owning declaration.
delete Promise<boolean> Yes See the upstream owning declaration.
exists Promise<boolean> Yes See the upstream owning declaration.
head Promise<StorageObject | null> Yes See the upstream owning declaration.
list Promise<StorageListResult> Yes See the upstream owning declaration.
copy Promise<StorageObject> No See the upstream owning declaration.
move Promise<StorageObject> No See the upstream owning declaration.

Type declaration; no runtime value.

See the owning declaration and linked feature guide for usage; no standalone example is documented in source.

Server-held signing credentials; never expose these through browser configuration.

Imports: @alneas/eaos-server/storage, @alneas/eaos-server/storage/s3-compatible.

interface StorageCredentials {
accessKeyId: string;
secretAccessKey: string;
}
Name Type Required Description
accessKeyId string Yes Nonempty access key identifier for the selected provider.
secretAccessKey string Yes Nonempty secret used for request signing.

Type declaration; no runtime value.

createS3CompatibleStorage for host setup.

Nonempty access key identifier for the selected provider.

Nonempty secret used for request signing.

See the owning declaration and linked feature guide for usage; no standalone example is documented in source.

Operation names passed to the host authorization callback before scoped storage access.

Imports: @alneas/eaos-server/storage.

type StorageOperation = 'upload' | 'download' | 'delete' | 'exists' | 'head' | 'list' | 'getUrl' | 'copy' | 'move';
Name Type Required Description
— — — No call parameters.

Type declaration; no runtime value.

createTenantStorage for a complete usage example.

See the owning declaration and linked feature guide for usage; no standalone example is documented in source.

Trusted tenant/plugin scope and per-operation authorization for createTenantStorage.

Imports: @alneas/eaos-server/storage.

interface TenantStorageOptions {
tenantId: string;
pluginId: string;
authorize: (request: {
tenantId: string;
pluginId: string;
operation: StorageOperation;
keys: readonly string[];
}) => boolean | Promise<boolean>;
maxUrlLifetimeSeconds?: number;
}
Name Type Required Description
tenantId string Yes Trusted tenant ID: 1–128 ASCII letters, digits, underscores, or hyphens, starting alphanumeric. It must come from verified server identity/configuration, never request body keys.
pluginId string Yes Trusted plugin ID: 1–128 ASCII letters, digits, underscores, or hyphens, starting with a letter or digit.
authorize (request: { tenantId: string; pluginId: string; operation: StorageOperation; keys: readonly string[]; }) => boolean | Promise<boolean> Yes Invoked before each operation with trusted scope, operation, and frozen relative keys (list receives its prefix); only exactly true allows access. Errors propagate.
maxUrlLifetimeSeconds number No Signed URLs remain usable until expiry; default ceiling 300 seconds.

Type declaration; no runtime value.

Trusted tenant ID: 1–128 ASCII letters, digits, underscores, or hyphens, starting alphanumeric. It must come from verified server identity/configuration, never request body keys.

Trusted plugin ID: 1–128 ASCII letters, digits, underscores, or hyphens, starting with a letter or digit.

Invoked before each operation with trusted scope, operation, and frozen relative keys (list receives its prefix); only exactly true allows access. Errors propagate.

Trusted tenant scope captured at adapter construction, independent of caller object keys.

Trusted plugin scope captured at adapter construction.

Storage operation about to be delegated to the provider.

Frozen relative-key array; copy/move supplies source then destination, and list supplies its requested prefix.

Signed URLs remain usable until expiry; default ceiling 300 seconds.

See the owning declaration and linked feature guide for usage; no standalone example is documented in source.