@dxos/blob 0.11.1 → 0.14.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/README.md +13 -4
- package/dist/lib/chunk-ni-uri.mjs +103 -0
- package/dist/lib/chunk-ni-uri.mjs.map +1 -0
- package/dist/lib/hosted.mjs +55 -0
- package/dist/lib/hosted.mjs.map +1 -0
- package/dist/lib/index.mjs +2 -0
- package/dist/lib/s3.mjs +515 -0
- package/dist/lib/s3.mjs.map +1 -0
- package/dist/types/src/backend.d.ts +31 -0
- package/dist/types/src/backend.d.ts.map +1 -1
- package/dist/types/src/hosted/blob-backend.d.ts +21 -0
- package/dist/types/src/hosted/blob-backend.d.ts.map +1 -0
- package/dist/types/src/hosted/blob-backend.test.d.ts +2 -0
- package/dist/types/src/hosted/blob-backend.test.d.ts.map +1 -0
- package/dist/types/src/hosted/index.d.ts +2 -0
- package/dist/types/src/hosted/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/ni-uri.d.ts +51 -0
- package/dist/types/src/ni-uri.d.ts.map +1 -0
- package/dist/types/src/ni-uri.test.d.ts +2 -0
- package/dist/types/src/ni-uri.test.d.ts.map +1 -0
- package/dist/types/src/s3/blob-backend.d.ts +38 -0
- package/dist/types/src/s3/blob-backend.d.ts.map +1 -0
- package/dist/types/src/s3/constants.d.ts +17 -0
- package/dist/types/src/s3/constants.d.ts.map +1 -0
- package/dist/types/src/s3/index.d.ts +6 -0
- package/dist/types/src/s3/index.d.ts.map +1 -0
- package/dist/types/src/s3/s3-client.d.ts +93 -0
- package/dist/types/src/s3/s3-client.d.ts.map +1 -0
- package/dist/types/src/s3/s3-client.test.d.ts +2 -0
- package/dist/types/src/s3/s3-client.test.d.ts.map +1 -0
- package/dist/types/src/s3/s3-uri.d.ts +44 -0
- package/dist/types/src/s3/s3-uri.d.ts.map +1 -0
- package/dist/types/src/s3/s3-uri.test.d.ts +2 -0
- package/dist/types/src/s3/s3-uri.test.d.ts.map +1 -0
- package/dist/types/src/s3/sigv4.d.ts +55 -0
- package/dist/types/src/s3/sigv4.d.ts.map +1 -0
- package/dist/types/src/s3/sigv4.test.d.ts +2 -0
- package/dist/types/src/s3/sigv4.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -2
- package/src/backend.ts +23 -0
- package/src/hosted/blob-backend.test.ts +113 -0
- package/src/hosted/blob-backend.ts +67 -0
- package/src/hosted/index.ts +5 -0
- package/src/index.ts +2 -1
- package/src/ni-uri.test.ts +31 -0
- package/src/ni-uri.ts +136 -0
- package/src/s3/blob-backend.ts +75 -0
- package/src/s3/constants.ts +24 -0
- package/src/s3/index.ts +13 -0
- package/src/s3/s3-client.test.ts +145 -0
- package/src/s3/s3-client.ts +331 -0
- package/src/s3/s3-uri.test.ts +81 -0
- package/src/s3/s3-uri.ts +93 -0
- package/src/s3/sigv4.test.ts +99 -0
- package/src/s3/sigv4.ts +203 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type BlobBackend, type BlobTransport } from '../backend.ts';
|
|
2
|
+
export interface CreateEdgeBlobBackendOptions {
|
|
3
|
+
transport: BlobTransport;
|
|
4
|
+
}
|
|
5
|
+
/** Largest blob the edge blob service accepts, in bytes. */
|
|
6
|
+
export declare const MAX_EDGE_BLOB_SIZE: number;
|
|
7
|
+
/**
|
|
8
|
+
* Blob backend that stores bytes in the edge blob service, addressed by RFC 6920 `ni:` URIs over a
|
|
9
|
+
* SHA-256 digest of the complete blob. The edge blob service itself is a flat key-value store keyed
|
|
10
|
+
* by hex digest — online-only in v1; reads and writes reject if the edge is unreachable and there is
|
|
11
|
+
* no local cache.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://www.rfc-editor.org/rfc/rfc6920 RFC 6920}
|
|
14
|
+
*
|
|
15
|
+
* TODO(wittjosiah): Add a local cache (e.g. via `@dxos/random-access-storage`, keyed by content
|
|
16
|
+
* hash) so reads/writes don't always round-trip to the edge. Blocked on `BlobBackend` gaining a
|
|
17
|
+
* `remove` and GC/refcounting for content-addressed blobs — without that, a local cache has no way
|
|
18
|
+
* to know when a cached entry is safe to evict once its owning Blob object is deleted.
|
|
19
|
+
*/
|
|
20
|
+
export declare const createEdgeBlobBackend: ({ transport }: CreateEdgeBlobBackendOptions) => BlobBackend;
|
|
21
|
+
//# sourceMappingURL=blob-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-backend.d.ts","sourceRoot":"","sources":["../../../../src/hosted/blob-backend.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGrE,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,aAAa,CAAC;CAC1B;AAUD,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,QAAmB,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,kBAAmB,4BAA4B,KAAG,WA6BnF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-backend.test.d.ts","sourceRoot":"","sources":["../../../../src/hosted/blob-backend.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hosted/index.ts"],"names":[],"mappings":"AAIA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IANA hash-algorithm name for SHA-256 in RFC 6920 Named Information URIs.
|
|
3
|
+
*
|
|
4
|
+
* @see https://www.rfc-editor.org/rfc/rfc6920
|
|
5
|
+
*/
|
|
6
|
+
export declare const ALG = "sha-256";
|
|
7
|
+
/**
|
|
8
|
+
* URI scheme for Named Information URIs (`ni:`).
|
|
9
|
+
*
|
|
10
|
+
* @see https://www.rfc-editor.org/rfc/rfc6920#section-4
|
|
11
|
+
*/
|
|
12
|
+
export declare const SCHEME = "ni";
|
|
13
|
+
/** RFC 4648 §5 base64url encoding without padding. */
|
|
14
|
+
export declare const toBase64url: (bytes: Uint8Array) => string;
|
|
15
|
+
/** RFC 4648 §5 base64url decoding; ignores characters outside the alphabet. */
|
|
16
|
+
export declare const fromBase64url: (value: string) => Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Computes the raw SHA-256 digest of `bytes`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const digestBytes: (bytes: Uint8Array) => Promise<Uint8Array>;
|
|
21
|
+
/**
|
|
22
|
+
* Builds an RFC 6920 Named Information URI from a raw SHA-256 digest.
|
|
23
|
+
*
|
|
24
|
+
* @see https://www.rfc-editor.org/rfc/rfc6920#section-3
|
|
25
|
+
*/
|
|
26
|
+
export declare const fromDigest: (digest: Uint8Array) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Builds an RFC 6920 Named Information URI from a lowercase hex-encoded SHA-256 digest.
|
|
29
|
+
*/
|
|
30
|
+
export declare const fromDigestHex: (hex: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Computes the RFC 6920 Named Information URI for `bytes` (`ni:///sha-256;<base64url-digest>`).
|
|
33
|
+
*
|
|
34
|
+
* @see https://www.rfc-editor.org/rfc/rfc6920
|
|
35
|
+
*/
|
|
36
|
+
export declare const encode: (bytes: Uint8Array) => Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Extracts the raw SHA-256 digest from a `ni:` URI.
|
|
39
|
+
*
|
|
40
|
+
* @throws If `uri` is not a well-formed `ni:///sha-256;…` URI.
|
|
41
|
+
*/
|
|
42
|
+
export declare const decode: (uri: string) => Uint8Array;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the lowercase hex SHA-256 digest encoded in a `ni:` URI.
|
|
45
|
+
*/
|
|
46
|
+
export declare const digestHex: (uri: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Computes the lowercase hex SHA-256 digest of `bytes`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const digestHexFromBytes: (bytes: Uint8Array) => Promise<string>;
|
|
51
|
+
//# sourceMappingURL=ni-uri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ni-uri.d.ts","sourceRoot":"","sources":["../../../src/ni-uri.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,GAAG,YAAY,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,MAAM,OAAO,CAAC;AAI3B,sDAAsD;AACtD,eAAO,MAAM,WAAW,UAAW,UAAU,KAAG,MAkB/C,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,UA2B7C,CAAC;AAeF;;GAEG;AACH,eAAO,MAAM,WAAW,UAAiB,UAAU,KAAG,OAAO,CAAC,UAAU,CAMvE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,WAAY,UAAU,KAAG,MAA+C,CAAC;AAEhG;;GAEG;AACH,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,MAAwC,CAAC;AAErF;;;;GAIG;AACH,eAAO,MAAM,MAAM,UAAiB,UAAU,KAAG,OAAO,CAAC,MAAM,CAAyC,CAAC;AAEzG;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAS,MAAM,KAAG,UAMpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,MAAoC,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAAiB,UAAU,KAAG,OAAO,CAAC,MAAM,CAA4C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ni-uri.test.d.ts","sourceRoot":"","sources":["../../../src/ni-uri.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type SpaceId } from '@dxos/keys';
|
|
2
|
+
import { type BlobBackend } from '../backend.ts';
|
|
3
|
+
import { type S3Credentials } from './s3-client.ts';
|
|
4
|
+
/**
|
|
5
|
+
* How the host answers the two questions this backend cannot answer itself.
|
|
6
|
+
*
|
|
7
|
+
* Both are supplied rather than derived because they need a space's database, and the hosts that
|
|
8
|
+
* should be able to reach a bucket disagree about how to get one: the browser has a `Client`, while
|
|
9
|
+
* EDGE's `operation-service` has only `Database.Service`. Keeping both out of this package is what
|
|
10
|
+
* makes the backend registrable anywhere.
|
|
11
|
+
*/
|
|
12
|
+
export type S3Host = {
|
|
13
|
+
/** The key pair for a bucket endpoint, or `undefined` to attempt an unsigned (public) read. */
|
|
14
|
+
resolveCredentials: (request: {
|
|
15
|
+
spaceId: SpaceId;
|
|
16
|
+
host: string;
|
|
17
|
+
}) => Promise<S3Credentials | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* The bucket a space writes to. Reads take their endpoint from the URI, so this exists only for
|
|
20
|
+
* `put` — `BlobPutRequest` carries no endpoint of its own.
|
|
21
|
+
*/
|
|
22
|
+
resolveWriteEndpoint: (spaceId: SpaceId) => Promise<{
|
|
23
|
+
host: string;
|
|
24
|
+
credentials: S3Credentials;
|
|
25
|
+
} | undefined>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Blob backend storing bytes in an S3-compatible bucket, addressed by `s3://<host>/<key>` URIs.
|
|
29
|
+
*
|
|
30
|
+
* Reads are attempted unsigned when the space holds no credential for the endpoint, so a public
|
|
31
|
+
* bucket renders for a viewer who was never given the writer's keys. Writes always require one.
|
|
32
|
+
*
|
|
33
|
+
* The bucket must allow the app's origin in its CORS policy for `PUT` and for any programmatic
|
|
34
|
+
* read; rendering does not need it, since a presigned URL in an `<img>` is not CORS-gated. In a
|
|
35
|
+
* headless host CORS does not apply at all.
|
|
36
|
+
*/
|
|
37
|
+
export declare const createS3BlobBackend: ({ resolveCredentials, resolveWriteEndpoint }: S3Host) => BlobBackend;
|
|
38
|
+
//# sourceMappingURL=blob-backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blob-backend.d.ts","sourceRoot":"","sources":["../../../../src/s3/blob-backend.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,KAAK,aAAa,EAAkD,MAAM,gBAAgB,CAAC;AAGpG;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,+FAA+F;IAC/F,kBAAkB,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACxG;;;OAGG;IACH,oBAAoB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,aAAa,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;CAC/G,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,iDAAkD,MAAM,KAAG,WAkC1F,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name this backend registers under on the ECHO Hypergraph, and the value `Blob.fromBytes`'s
|
|
3
|
+
* `storage` option takes when it is selected.
|
|
4
|
+
*/
|
|
5
|
+
export declare const S3_BACKEND = "s3";
|
|
6
|
+
/** URI scheme this backend resolves at read time. */
|
|
7
|
+
export declare const S3_SCHEME = "s3";
|
|
8
|
+
/**
|
|
9
|
+
* Signing region for endpoints that do not encode one. R2 ignores the region but SigV4 still
|
|
10
|
+
* requires a value in the credential scope, and `auto` is what Cloudflare documents.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_REGION = "auto";
|
|
13
|
+
/** Lifetime of a presigned GET URL. Long enough to render a large asset, short enough to not be a handout. */
|
|
14
|
+
export declare const PRESIGN_EXPIRY_SECONDS: number;
|
|
15
|
+
/** Abort a bucket request after this many ms so a hung call cannot wedge an upload or a render. */
|
|
16
|
+
export declare const S3_TIMEOUT_MS = 60000;
|
|
17
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/s3/constants.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,eAAO,MAAM,UAAU,OAAO,CAAC;AAE/B,qDAAqD;AACrD,eAAO,MAAM,SAAS,OAAO,CAAC;AAE9B;;;GAGG;AACH,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,8GAA8G;AAC9G,eAAO,MAAM,sBAAsB,QAAU,CAAC;AAE9C,mGAAmG;AACnG,eAAO,MAAM,aAAa,QAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/s3/index.ts"],"names":[],"mappings":"AAQA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type S3Uri } from './s3-uri.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The key pair for one bucket. `undefined` wherever a caller has no credential for the endpoint —
|
|
4
|
+
* every read path then falls through to an unsigned request, which succeeds on a public bucket and
|
|
5
|
+
* 403s on a private one. That is the intended behavior: rendering a shared object must not require
|
|
6
|
+
* the viewer to hold the writer's keys.
|
|
7
|
+
*/
|
|
8
|
+
export type S3Credentials = {
|
|
9
|
+
accessKeyId: string;
|
|
10
|
+
secretAccessKey: string;
|
|
11
|
+
};
|
|
12
|
+
/** Rejects rather than resolving `undefined`: a transport failure is not a missing object. */
|
|
13
|
+
export declare class S3RequestError extends Error {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly statusText: string;
|
|
16
|
+
readonly body: string;
|
|
17
|
+
constructor(status: number, statusText: string, body: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A request the browser refused to send, or whose response it refused to expose. Almost always a
|
|
21
|
+
* missing bucket CORS policy: `fetch` reports that as an opaque `TypeError` and confines the real
|
|
22
|
+
* reason to the devtools console, so a blocked preflight would otherwise reach the user as
|
|
23
|
+
* "Failed to fetch".
|
|
24
|
+
*
|
|
25
|
+
* The message names the origin and the methods only. The required headers are in the README and in
|
|
26
|
+
* `details` — a status line has to be readable at a glance, and nobody writes a CORS policy from
|
|
27
|
+
* memory of a sentence anyway.
|
|
28
|
+
*/
|
|
29
|
+
export declare class S3NetworkError extends Error {
|
|
30
|
+
readonly host: string;
|
|
31
|
+
readonly cause: unknown;
|
|
32
|
+
/** The full policy requirement, for logs and docs rather than the status line. */
|
|
33
|
+
readonly details: string;
|
|
34
|
+
constructor(host: string, cause: unknown);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The request exceeded its deadline. Distinct from {@link S3NetworkError} because the remedies have
|
|
38
|
+
* nothing in common — a timeout says the endpoint is slow or unreachable, not that a bucket policy
|
|
39
|
+
* is wrong, and conflating them sends the user to edit configuration that is already correct.
|
|
40
|
+
*/
|
|
41
|
+
export declare class S3TimeoutError extends Error {
|
|
42
|
+
readonly host: string;
|
|
43
|
+
readonly timeoutMs: number;
|
|
44
|
+
constructor(host: string, timeoutMs: number);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks that the credential can address the bucket, and explains it when it cannot.
|
|
48
|
+
*
|
|
49
|
+
* Distinct from `headObject`, which deliberately reports 403 and 404 alike as "not there" — correct
|
|
50
|
+
* when reading a blob, useless for a connection test, where telling a rejected key from an absent
|
|
51
|
+
* object is the entire point. Probes a key that should not exist: 404 proves the signature was
|
|
52
|
+
* accepted, and every other outcome names what to fix.
|
|
53
|
+
*/
|
|
54
|
+
export declare const probeAccess: ({ uri, credentials }: {
|
|
55
|
+
uri: S3Uri;
|
|
56
|
+
credentials: S3Credentials;
|
|
57
|
+
}) => Promise<void>;
|
|
58
|
+
export type PutOptions = {
|
|
59
|
+
uri: S3Uri;
|
|
60
|
+
data: Uint8Array;
|
|
61
|
+
contentType?: string;
|
|
62
|
+
/** Hex SHA-256 of `data`, already computed by the blob manager. */
|
|
63
|
+
contentHash: string;
|
|
64
|
+
credentials: S3Credentials;
|
|
65
|
+
now?: () => Date;
|
|
66
|
+
};
|
|
67
|
+
export declare const putObject: ({ uri, data, contentType, contentHash, credentials, now, }: PutOptions) => Promise<void>;
|
|
68
|
+
export type ReadOptions = {
|
|
69
|
+
uri: S3Uri;
|
|
70
|
+
/** Omitted for an unsigned read against a public bucket. */
|
|
71
|
+
credentials?: S3Credentials;
|
|
72
|
+
now?: () => Date;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Reads an object's bytes.
|
|
76
|
+
*
|
|
77
|
+
* Resolves `undefined` when the object is absent, or is not readable with the credentials in hand —
|
|
78
|
+
* see {@link isMiss} for which statuses count. Rejects on a transport failure or an unexpected
|
|
79
|
+
* status, since neither is evidence the object is missing.
|
|
80
|
+
*/
|
|
81
|
+
export declare const getObject: (options: ReadOptions) => Promise<Uint8Array | undefined>;
|
|
82
|
+
/**
|
|
83
|
+
* Whether an object exists and is readable with the credentials in hand. Same miss semantics as
|
|
84
|
+
* {@link getObject}, and the same rejection on anything that is not evidence of absence.
|
|
85
|
+
*/
|
|
86
|
+
export declare const headObject: (options: ReadOptions) => Promise<boolean>;
|
|
87
|
+
/**
|
|
88
|
+
* A URL an `<img>`/`<video>` can load directly. Presigned when a credential is available; the plain
|
|
89
|
+
* public URL otherwise, which is correct for a public bucket and simply fails to load for a private
|
|
90
|
+
* one — the same outcome as returning nothing, without suppressing the browser's own diagnostics.
|
|
91
|
+
*/
|
|
92
|
+
export declare const getObjectUrl: ({ uri, credentials, now }: ReadOptions) => Promise<string>;
|
|
93
|
+
//# sourceMappingURL=s3-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-client.d.ts","sourceRoot":"","sources":["../../../../src/s3/s3-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,KAAK,EAA8B,MAAM,aAAa,CAAC;AAGrE;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAOF,8FAA8F;AAC9F,qBAAa,cAAe,SAAQ,KAAK;IAErC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM;IAHvB,YACW,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EAItB;CACF;AAMD;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAKrC,QAAQ,CAAC,IAAI,EAAE,MAAM;aACH,KAAK,EAAE,OAAO;IALlC,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,YACW,IAAI,EAAE,MAAM,EACH,KAAK,EAAE,OAAO,EAOjC;CACF;AAED;;;;GAIG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAErC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAF5B,YACW,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EAI3B;CACF;AAKD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,yBAAgC;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,aAAa,CAAA;CAAE,KAAG,OAAO,CAAC,IAAI,CAgDhH,CAAC;AAoDF,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,KAAK,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,aAAa,CAAC;IAC3B,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,SAAS,+DAOnB,UAAU,KAAG,OAAO,CAAC,IAAI,CAsB3B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,KAAK,CAAC;IACX,4DAA4D;IAC5D,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB,CAAC;AA+BF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,YAAmB,WAAW,KAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAcpF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,YAAmB,WAAW,KAAG,OAAO,CAAC,OAAO,CAetE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,8BAAwD,WAAW,KAAG,OAAO,CAAC,MAAM,CAY5G,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-client.test.d.ts","sourceRoot":"","sources":["../../../../src/s3/s3-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stored blob's address: `s3://<host>/<key>`, where `host` is the virtual-hosted-style bucket
|
|
3
|
+
* endpoint (`media.<account>.r2.cloudflarestorage.com`, `media.s3.eu-west-1.amazonaws.com`).
|
|
4
|
+
*
|
|
5
|
+
* The host carries the bucket, so it is also the `AccessToken.source` the credential is filed
|
|
6
|
+
* under — one connection per bucket, resolved without a side table mapping URIs to configuration.
|
|
7
|
+
*/
|
|
8
|
+
export type S3Uri = {
|
|
9
|
+
host: string;
|
|
10
|
+
key: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const formatUri: ({ host, key }: S3Uri) => string;
|
|
13
|
+
/** Returns `undefined` for anything that is not one of this backend's URIs. */
|
|
14
|
+
export declare const parseUri: (uri: string) => S3Uri | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The HTTPS URL the object is served from. Public buckets resolve this without a signature.
|
|
17
|
+
*
|
|
18
|
+
* Rejects `.` and `..` segments rather than trying to carry them. WHATWG URL parsing resolves them
|
|
19
|
+
* away, and percent-encoding does not help — it decodes `%2E` and normalizes anyway — so such a key
|
|
20
|
+
* would silently be requested at a different path than the one it was stored under. Nothing this
|
|
21
|
+
* package writes produces one (`objectKey` is a space id and a hex digest), so a key that reaches
|
|
22
|
+
* here with a dot segment is a corrupted or hand-authored URI, and failing is better than reading
|
|
23
|
+
* the wrong object.
|
|
24
|
+
*/
|
|
25
|
+
export declare const toHttpsUrl: ({ host, key }: S3Uri) => URL;
|
|
26
|
+
/**
|
|
27
|
+
* SigV4 signing region for an endpoint. AWS encodes it in the hostname; R2 and most self-hosted
|
|
28
|
+
* S3 implementations do not, and take {@link DEFAULT_REGION}.
|
|
29
|
+
*
|
|
30
|
+
* The legacy global endpoint (`bucket.s3.amazonaws.com`, no region segment) is the exception: it
|
|
31
|
+
* routes to us-east-1 and must be signed for that region, since signing it `auto` yields
|
|
32
|
+
* `SignatureDoesNotMatch` rather than anything that names the real problem.
|
|
33
|
+
*/
|
|
34
|
+
export declare const regionFromHost: (host: string) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Object key for a blob. Content-addressed by the digest the blob manager already computed, under a
|
|
37
|
+
* space-scoped prefix so one bucket can serve many spaces and a listing stays navigable. The
|
|
38
|
+
* original filename is deliberately not in the path — it is not unique, and ECHO holds it.
|
|
39
|
+
*/
|
|
40
|
+
export declare const objectKey: ({ spaceId, contentHash }: {
|
|
41
|
+
spaceId: string;
|
|
42
|
+
contentHash: string;
|
|
43
|
+
}) => string;
|
|
44
|
+
//# sourceMappingURL=s3-uri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-uri.d.ts","sourceRoot":"","sources":["../../../../src/s3/s3-uri.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,SAAS,kBAAmB,KAAK,KAAG,MAAyC,CAAC;AAE3F,+EAA+E;AAC/E,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,KAAK,GAAG,SAQ9C,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,kBAAmB,KAAK,KAAG,GAwBjD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,KAAG,MAO7C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,6BAA8B;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,KAAG,MAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-uri.test.d.ts","sourceRoot":"","sources":["../../../../src/s3/s3-uri.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Payload hash S3 accepts in place of a real digest when the body is not signed (presigned URLs). */
|
|
2
|
+
export declare const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
|
3
|
+
/** SHA-256 of the empty string; the payload hash for every request with no body. */
|
|
4
|
+
export declare const EMPTY_PAYLOAD_HASH = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
5
|
+
/**
|
|
6
|
+
* Narrows a view to one backed by a plain `ArrayBuffer`. `Uint8Array` is generic over
|
|
7
|
+
* `ArrayBufferLike`, which includes `SharedArrayBuffer`; WebCrypto and `fetch` accept only the
|
|
8
|
+
* former. The common case aliases the existing buffer, so this costs nothing but a wrapper.
|
|
9
|
+
*/
|
|
10
|
+
export declare const toArrayBufferView: (data: Uint8Array) => Uint8Array<ArrayBuffer>;
|
|
11
|
+
export declare const sha256Hex: (data: Uint8Array | string) => Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* RFC 3986 percent-encoding. `encodeURIComponent` leaves `!'()*` unescaped, which AWS treats as a
|
|
14
|
+
* signature mismatch rather than an equivalent encoding.
|
|
15
|
+
*/
|
|
16
|
+
export declare const uriEncode: (value: string) => string;
|
|
17
|
+
/** Encodes an object key for the canonical URI: every segment escaped, the separating slashes kept. */
|
|
18
|
+
export declare const encodeObjectKey: (key: string) => string;
|
|
19
|
+
/** `20260826T143000Z` and `20260826` — the two timestamp forms SigV4 uses. */
|
|
20
|
+
export declare const formatTimestamps: (date: Date) => {
|
|
21
|
+
amzDate: string;
|
|
22
|
+
dateStamp: string;
|
|
23
|
+
};
|
|
24
|
+
export type SigningCredentials = {
|
|
25
|
+
accessKeyId: string;
|
|
26
|
+
secretAccessKey: string;
|
|
27
|
+
region: string;
|
|
28
|
+
};
|
|
29
|
+
export type SignRequestOptions = {
|
|
30
|
+
method: string;
|
|
31
|
+
url: URL;
|
|
32
|
+
headers?: Record<string, string>;
|
|
33
|
+
/** Hex SHA-256 of the body, or {@link UNSIGNED_PAYLOAD}. Defaults to the empty-body digest. */
|
|
34
|
+
payloadHash?: string;
|
|
35
|
+
credentials: SigningCredentials;
|
|
36
|
+
date: Date;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Signs a request with an `Authorization` header. Returns the headers to send — the caller's
|
|
40
|
+
* `headers` plus `host`, `x-amz-date`, `x-amz-content-sha256` and `Authorization`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const signRequest: ({ method, url, headers, payloadHash, credentials, date, }: SignRequestOptions) => Promise<Record<string, string>>;
|
|
43
|
+
export type PresignOptions = {
|
|
44
|
+
method?: string;
|
|
45
|
+
url: URL;
|
|
46
|
+
expiresIn: number;
|
|
47
|
+
credentials: SigningCredentials;
|
|
48
|
+
date: Date;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Produces a URL carrying its own authorization in the query string, so it can be handed to an
|
|
52
|
+
* `<img>` or `<video>` element that cannot send an `Authorization` header.
|
|
53
|
+
*/
|
|
54
|
+
export declare const presignUrl: ({ method, url, expiresIn, credentials, date, }: PresignOptions) => Promise<string>;
|
|
55
|
+
//# sourceMappingURL=sigv4.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sigv4.d.ts","sourceRoot":"","sources":["../../../../src/s3/sigv4.ts"],"names":[],"mappings":"AAgBA,sGAAsG;AACtG,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,qEAAqE,CAAC;AASrG;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,SAAU,UAAU,KAAG,UAAU,CAAC,WAAW,CAGjD,CAAC;AAE3B,eAAO,MAAM,SAAS,SAAgB,UAAU,GAAG,MAAM,KAAG,OAAO,CAAC,MAAM,CAGzE,CAAC;AAOF;;;GAGG;AACH,eAAO,MAAM,SAAS,UAAW,MAAM,KAAG,MACoE,CAAC;AAE/G,uGAAuG;AACvG,eAAO,MAAM,eAAe,QAAS,MAAM,KAAG,MAAiD,CAAC;AAEhG,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,SAAU,IAAI,KAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAGjF,CAAC;AAuBF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAwBF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,kBAAkB,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,8DAOrB,kBAAkB,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwBrD,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,kBAAkB,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,mDAMpB,cAAc,KAAG,OAAO,CAAC,MAAM,CAuBjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sigv4.test.d.ts","sourceRoot":"","sources":["../../../../src/s3/sigv4.test.ts"],"names":[],"mappings":""}
|