@uploadfilm/sdk 0.0.0-stage → 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/LICENSE +4 -0
- package/README.md +509 -2
- package/dist/ai/embed.d.ts +58 -0
- package/dist/ai/fake.d.ts +41 -0
- package/dist/ai/http.d.ts +17 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/languages.d.ts +2 -0
- package/dist/ai/ollama.d.ts +23 -0
- package/dist/ai/openaiCompatible.d.ts +54 -0
- package/dist/ai/passages.d.ts +28 -0
- package/dist/ai/transcribe.d.ts +84 -0
- package/dist/ai/types.d.ts +141 -0
- package/dist/ai/usage.d.ts +66 -0
- package/dist/ai/whisperJson.d.ts +15 -0
- package/dist/ai/workersAi.d.ts +56 -0
- package/dist/ai.js +1 -0
- package/dist/ai.mjs +1 -0
- package/dist/cards/files.d.ts +91 -0
- package/dist/cards/index.d.ts +15 -0
- package/dist/cards/layouts.d.ts +121 -0
- package/dist/cards/probe.d.ts +69 -0
- package/dist/cards/proxies.d.ts +70 -0
- package/dist/cards/select.d.ts +68 -0
- package/dist/cards/volumes.d.ts +170 -0
- package/dist/cards/xml.d.ts +80 -0
- package/dist/cards.js +1 -0
- package/dist/cards.mjs +1 -0
- package/dist/copy/checksums.d.ts +66 -0
- package/dist/copy/engine.d.ts +24 -0
- package/dist/copy/errors.d.ts +109 -0
- package/dist/copy/index.d.ts +15 -0
- package/dist/copy/steps.d.ts +28 -0
- package/dist/copy/sweep.d.ts +24 -0
- package/dist/copy/types.d.ts +336 -0
- package/dist/embed/player.js +2 -0
- package/dist/host/adapters.d.ts +107 -0
- package/dist/host/detect.d.ts +68 -0
- package/dist/host/encoders.d.ts +34 -0
- package/dist/host/environment.d.ts +53 -0
- package/dist/host/index.d.ts +20 -0
- package/dist/host/linux.d.ts +94 -0
- package/dist/host/mac.d.ts +47 -0
- package/dist/host/network.d.ts +54 -0
- package/dist/host/node.d.ts +13 -0
- package/dist/host/policy.d.ts +101 -0
- package/dist/host/tuner.d.ts +48 -0
- package/dist/host/types.d.ts +118 -0
- package/dist/host-node.js +1 -0
- package/dist/host-node.mjs +1 -0
- package/dist/host.js +1 -0
- package/dist/host.mjs +1 -0
- package/dist/images/index.d.ts +11 -0
- package/dist/images/settings.d.ts +43 -0
- package/dist/images/types.d.ts +83 -0
- package/dist/images/url.d.ts +65 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/player/adapters/hlsjs.d.ts +28 -0
- package/dist/player/bandwidthMemory.d.ts +28 -0
- package/dist/player/captions/index.d.ts +55 -0
- package/dist/player/embed/code.d.ts +195 -0
- package/dist/player/embed/constants.d.ts +4 -0
- package/dist/player/embed/controller.d.ts +62 -0
- package/dist/player/embed/element.d.ts +32 -0
- package/dist/player/embed/frame.d.ts +65 -0
- package/dist/player/embed/global.d.ts +14 -0
- package/dist/player/embed/index.d.ts +15 -0
- package/dist/player/embed/loader.d.ts +1 -0
- package/dist/player/embed/oembed.d.ts +74 -0
- package/dist/player/embed/protocol.d.ts +64 -0
- package/dist/player/engine.d.ts +215 -0
- package/dist/player/index.d.ts +18 -0
- package/dist/player/start.d.ts +62 -0
- package/dist/player/store.d.ts +10 -0
- package/dist/player/storyboard/index.d.ts +161 -0
- package/dist/player/stream.d.ts +206 -0
- package/dist/player/tracks.d.ts +41 -0
- package/dist/player.js +1 -0
- package/dist/player.mjs +1 -0
- package/dist/proxies/args.d.ts +19 -0
- package/dist/proxies/budget.d.ts +57 -0
- package/dist/proxies/camera.d.ts +104 -0
- package/dist/proxies/formats.d.ts +36 -0
- package/dist/proxies/index.d.ts +18 -0
- package/dist/proxies/jobs.d.ts +98 -0
- package/dist/proxies/node.d.ts +32 -0
- package/dist/proxies/plan.d.ts +89 -0
- package/dist/proxies/probe.d.ts +39 -0
- package/dist/proxies/render.d.ts +104 -0
- package/dist/proxies/safety.d.ts +45 -0
- package/dist/proxies/types.d.ts +83 -0
- package/dist/proxies/upload.d.ts +14 -0
- package/dist/react/BigPlay.d.ts +26 -0
- package/dist/react/Player.d.ts +58 -0
- package/dist/react/embed/index.d.ts +45 -0
- package/dist/react/examples/CustomControls.d.ts +8 -0
- package/dist/react/images/Image.d.ts +16 -0
- package/dist/react/images/index.d.ts +4 -0
- package/dist/react/images/useImage.d.ts +47 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/storyboard/index.d.ts +58 -0
- package/dist/react/theme.d.ts +37 -0
- package/dist/react/useAdapterErrors.d.ts +8 -0
- package/dist/react/usePlaybackStart.d.ts +18 -0
- package/dist/react/usePlayer.d.ts +28 -0
- package/dist/react/useReducedMotion.d.ts +2 -0
- package/dist/react/useTimedTrack.d.ts +22 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/server/auth/apiKeys.d.ts +30 -0
- package/dist/server/auth/cache.d.ts +21 -0
- package/dist/server/auth/deviceTokens.d.ts +38 -0
- package/dist/server/auth/envelope.d.ts +15 -0
- package/dist/server/auth/grants.d.ts +76 -0
- package/dist/server/auth/index.d.ts +19 -0
- package/dist/server/auth/jwt.d.ts +65 -0
- package/dist/server/auth/keyring.d.ts +31 -0
- package/dist/server/auth/kv.d.ts +12 -0
- package/dist/server/auth/repository.d.ts +45 -0
- package/dist/server/auth/revocations.d.ts +21 -0
- package/dist/server/auth/scope.d.ts +4 -0
- package/dist/server/auth/serviceAuth.d.ts +24 -0
- package/dist/server/auth/signedUrls.d.ts +28 -0
- package/dist/server/embed/index.d.ts +36 -0
- package/dist/server/embed/lifecycle.d.ts +53 -0
- package/dist/server/embed/playerScript.d.ts +4 -0
- package/dist/server/images/index.d.ts +15 -0
- package/dist/server/images/job.d.ts +80 -0
- package/dist/server/images/layout.d.ts +24 -0
- package/dist/server/images/params.d.ts +90 -0
- package/dist/server/images/route.d.ts +101 -0
- package/dist/server/images/sign.d.ts +55 -0
- package/dist/server/index.d.ts +42 -0
- package/dist/server/media/client.d.ts +66 -0
- package/dist/server/media/frameCheck.d.ts +62 -0
- package/dist/server/media/index.d.ts +10 -0
- package/dist/server/media/protocol.d.ts +318 -0
- package/dist/server/media/storyboard.d.ts +144 -0
- package/dist/server/media/transcript.d.ts +143 -0
- package/dist/server/pipeline/index.d.ts +12 -0
- package/dist/server/pipeline/match.d.ts +10 -0
- package/dist/server/pipeline/pipeline.d.ts +182 -0
- package/dist/server/pipeline/queues.d.ts +108 -0
- package/dist/server/pipeline/sources.d.ts +54 -0
- package/dist/server/r2/client.d.ts +150 -0
- package/dist/server/r2/crc32.d.ts +24 -0
- package/dist/server/r2/encoding.d.ts +35 -0
- package/dist/server/r2/errors.d.ts +9 -0
- package/dist/server/r2/integrity.d.ts +25 -0
- package/dist/server/r2/parts.d.ts +46 -0
- package/dist/server/r2/sign.d.ts +47 -0
- package/dist/server/redis/index.d.ts +39 -0
- package/dist/server/state/memory.d.ts +18 -0
- package/dist/server/state/r2.d.ts +73 -0
- package/dist/server/state/types.d.ts +57 -0
- package/dist/server/storage/chunked.d.ts +21 -0
- package/dist/server/storage/index.d.ts +12 -0
- package/dist/server/storage/r2.d.ts +96 -0
- package/dist/server/storage/s3.d.ts +93 -0
- package/dist/server/testing/fake-r2.d.ts +390 -0
- package/dist/server/testing/index.d.ts +10 -0
- package/dist/server/testing/kv-contract.d.ts +14 -0
- package/dist/server/transfer/handler.d.ts +167 -0
- package/dist/server/transfer/keys.d.ts +45 -0
- package/dist/server/transfer/protocol.d.ts +141 -0
- package/dist/server/zip/client.d.ts +32 -0
- package/dist/server/zip/generations.d.ts +83 -0
- package/dist/server/zip/index.d.ts +12 -0
- package/dist/server/zip/planner.d.ts +94 -0
- package/dist/server/zip/sign.d.ts +22 -0
- package/dist/server-media.js +1 -0
- package/dist/server-media.mjs +1 -0
- package/dist/server-redis.js +1 -0
- package/dist/server-redis.mjs +1 -0
- package/dist/server-testing.js +1 -0
- package/dist/server-testing.mjs +1 -0
- package/dist/server.js +1 -0
- package/dist/server.mjs +1 -0
- package/dist/storage/browserFile.d.ts +19 -0
- package/dist/storage/index.d.ts +12 -0
- package/dist/storage/local.d.ts +9 -0
- package/dist/storage/presigned.d.ts +22 -0
- package/dist/sync/ffmpeg.d.ts +44 -0
- package/dist/sync/index.d.ts +17 -0
- package/dist/sync/match.d.ts +28 -0
- package/dist/sync/probe.d.ts +30 -0
- package/dist/sync/timecode.d.ts +50 -0
- package/dist/sync/transcript.d.ts +35 -0
- package/dist/sync/types.d.ts +172 -0
- package/dist/sync/waveform.d.ts +89 -0
- package/dist/sync.js +1 -0
- package/dist/sync.mjs +1 -0
- package/dist/transfer/claims.d.ts +41 -0
- package/dist/transfer/client.d.ts +256 -0
- package/dist/transfer/download.d.ts +192 -0
- package/dist/transfer/engine.d.ts +382 -0
- package/dist/transfer/errors.d.ts +50 -0
- package/dist/transfer/index.d.ts +39 -0
- package/dist/transfer/integrity.d.ts +93 -0
- package/dist/transfer/limits.d.ts +34 -0
- package/dist/transfer/node.d.ts +63 -0
- package/dist/transfer/pool.d.ts +83 -0
- package/dist/transfer/protocol.d.ts +167 -0
- package/dist/transfer/signer.d.ts +29 -0
- package/dist/transfer/storage.d.ts +110 -0
- package/dist/transfer/timing.d.ts +132 -0
- package/dist/transfer/transports/electronNet.d.ts +62 -0
- package/dist/transfer/transports/fetch.d.ts +15 -0
- package/dist/transfer/transports/retryAfter.d.ts +12 -0
- package/dist/transfer/transports/undici.d.ts +72 -0
- package/dist/transfer/tuner.d.ts +56 -0
- package/dist/zip/index.d.ts +13 -0
- package/dist/zip/layout.d.ts +129 -0
- package/dist/zip/names.d.ts +34 -0
- package/dist/zip/plan.d.ts +115 -0
- package/dist/zip/sw.d.ts +7 -0
- package/package.json +265 -4
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `r2(binding | config | client)`: Cloudflare R2 as either end of a copy.
|
|
3
|
+
*
|
|
4
|
+
* - a Worker binding (`env.BUCKET`, R2Bucket): head / ranged get with `onlyIf.etagMatches` / multipart through the
|
|
5
|
+
* binding. No credentials at all.
|
|
6
|
+
* - an account config (`R2Config`) or an `R2Client` (`createR2Client`): the S3 API signed with aws4fetch.
|
|
7
|
+
*
|
|
8
|
+
* As a source: ranges pinned to the version (If-Match / onlyIf), a replaced object is SourceChanged. A single-PUT
|
|
9
|
+
* object's ETag is its MD5 (the checksum a copy is verified against); a multipart object's is md5(part MD5s)-N,
|
|
10
|
+
* checkable when the product says how it cut its uploads (`sourcePartSize`: UploadFilm passes its upload engine's
|
|
11
|
+
* partSizeFor), so a copy cut the same way proves every byte without a separately stored checksum.
|
|
12
|
+
*
|
|
13
|
+
* As a destination: parts are buffered once each for their Content-MD5 (R2 refuses changed bytes with BadDigest)
|
|
14
|
+
* and cut like the upload engine's parts by default, so the stored ETag is the one the Mac engine would make.
|
|
15
|
+
*/
|
|
16
|
+
import { type R2Client, type R2Config } from "../r2/client";
|
|
17
|
+
import type { CopyDestination, CopySource } from "../../copy/types";
|
|
18
|
+
/** The slice of a Workers R2Bucket binding used here (R2Bucket fits). */
|
|
19
|
+
export interface R2ObjectLike {
|
|
20
|
+
key: string;
|
|
21
|
+
size: number;
|
|
22
|
+
etag: string;
|
|
23
|
+
uploaded: Date;
|
|
24
|
+
version?: string;
|
|
25
|
+
checksums?: {
|
|
26
|
+
md5?: ArrayBuffer;
|
|
27
|
+
sha256?: ArrayBuffer;
|
|
28
|
+
};
|
|
29
|
+
customMetadata?: Record<string, string>;
|
|
30
|
+
httpMetadata?: {
|
|
31
|
+
contentType?: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface R2ObjectBodyLike extends R2ObjectLike {
|
|
35
|
+
body: ReadableStream<Uint8Array>;
|
|
36
|
+
}
|
|
37
|
+
export interface R2MultipartUploadLike {
|
|
38
|
+
readonly key: string;
|
|
39
|
+
readonly uploadId: string;
|
|
40
|
+
uploadPart(partNumber: number, value: ReadableStream<Uint8Array> | ArrayBuffer | Uint8Array): Promise<{
|
|
41
|
+
partNumber: number;
|
|
42
|
+
etag: string;
|
|
43
|
+
}>;
|
|
44
|
+
complete(parts: {
|
|
45
|
+
partNumber: number;
|
|
46
|
+
etag: string;
|
|
47
|
+
}[]): Promise<R2ObjectLike>;
|
|
48
|
+
abort(): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export interface R2BucketLike {
|
|
51
|
+
head(key: string): Promise<R2ObjectLike | null>;
|
|
52
|
+
get(key: string, opts?: {
|
|
53
|
+
range?: {
|
|
54
|
+
offset: number;
|
|
55
|
+
length: number;
|
|
56
|
+
};
|
|
57
|
+
onlyIf?: {
|
|
58
|
+
etagMatches?: string;
|
|
59
|
+
};
|
|
60
|
+
}): Promise<R2ObjectLike | R2ObjectBodyLike | null>;
|
|
61
|
+
put(key: string, value: ReadableStream<Uint8Array> | ArrayBuffer | Uint8Array, opts?: {
|
|
62
|
+
httpMetadata?: {
|
|
63
|
+
contentType?: string;
|
|
64
|
+
};
|
|
65
|
+
customMetadata?: Record<string, string>;
|
|
66
|
+
md5?: ArrayBuffer | string;
|
|
67
|
+
}): Promise<R2ObjectLike | null>;
|
|
68
|
+
createMultipartUpload(key: string, opts?: {
|
|
69
|
+
httpMetadata?: {
|
|
70
|
+
contentType?: string;
|
|
71
|
+
};
|
|
72
|
+
customMetadata?: Record<string, string>;
|
|
73
|
+
}): Promise<R2MultipartUploadLike>;
|
|
74
|
+
resumeMultipartUpload(key: string, uploadId: string): R2MultipartUploadLike;
|
|
75
|
+
}
|
|
76
|
+
export interface R2ModuleOptions {
|
|
77
|
+
/** Names this bucket in the copy's identity (saved steps); default the bucket (S3 API) or "" (a binding). */
|
|
78
|
+
id?: string;
|
|
79
|
+
/** The part size the product's uploads use for an object of `size` (lets a copy check composite ETags). */
|
|
80
|
+
sourcePartSize?: (size: number) => number;
|
|
81
|
+
/** Destination part size for an object of `size` (default: the upload engine's partSizeFor). */
|
|
82
|
+
partSize?: (size: number) => number;
|
|
83
|
+
/** Per-request timeout for the S3 API (default 60 s; parts 120 s + 1 s per MiB). */
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
/** S3 API from a config: every request (body included) is aborted after this long at most (default 30 min). */
|
|
86
|
+
requestMaxMs?: number;
|
|
87
|
+
/**
|
|
88
|
+
* S3 API only: largest request body (bytes), parts and single PUTs included. Default 96 MiB wherever it runs (a
|
|
89
|
+
* Worker's outgoing request body is cut at about 100 MiB). A binding has no such limit.
|
|
90
|
+
*/
|
|
91
|
+
maxRequestBytes?: number;
|
|
92
|
+
}
|
|
93
|
+
export type R2Module = CopySource & CopyDestination & {
|
|
94
|
+
readonly via: "binding" | "s3api";
|
|
95
|
+
};
|
|
96
|
+
export declare function r2(target: R2BucketLike | R2Config | R2Client, o?: R2ModuleOptions): R2Module;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type Query } from "../r2/encoding";
|
|
2
|
+
import type { CopyDestination, CopySource, UploadInfo } from "../../copy/types";
|
|
3
|
+
/** The largest request body a Worker can send, with room for aws-chunked framing (~1 KiB per part). */
|
|
4
|
+
export declare const WORKER_MAX_REQUEST: number;
|
|
5
|
+
/**
|
|
6
|
+
* The largest payload whose aws-chunked body (with its trailing CRC) is at most `wire` bytes on the wire, in whole
|
|
7
|
+
* 64 KiB: a part's request, framing included, never exceeds the cap.
|
|
8
|
+
*/
|
|
9
|
+
export declare function payloadFor(wire: number): number;
|
|
10
|
+
/** The largest part / single PUT payload s3() sends by default: its framed body is at most 96 MiB. */
|
|
11
|
+
export declare const WORKER_MAX_PART: number;
|
|
12
|
+
/**
|
|
13
|
+
* S3's storage classes as of 2026-11 (AWS PutObject). Not an allowlist: AWS adds classes (FSx-backed ones) and
|
|
14
|
+
* S3-compatible stores have their own, so `s3()` only checks a class's form. A product that wants its setting checked
|
|
15
|
+
* against a list checks it against its own (as the backup Worker does with DEEP_ARCHIVE / GLACIER_IR).
|
|
16
|
+
*/
|
|
17
|
+
export declare const S3_STORAGE_CLASSES: readonly ["STANDARD", "REDUCED_REDUNDANCY", "STANDARD_IA", "ONEZONE_IA", "INTELLIGENT_TIERING", "GLACIER", "DEEP_ARCHIVE", "OUTPOSTS", "GLACIER_IR", "SNOW", "EXPRESS_ONEZONE", "FSX_OPENZFS", "FSX_ONTAP"];
|
|
18
|
+
/** S3's archive classes: an existing copy in one counts as copied for another (see acceptStorageClasses). */
|
|
19
|
+
export declare const ARCHIVE_CLASSES: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* Running inside a Cloudflare Worker: workerd's documented navigator.userAgent, or (a Worker with the
|
|
22
|
+
* `no_global_navigator` flag has no navigator) the globals only the Workers runtime has.
|
|
23
|
+
*/
|
|
24
|
+
export declare const inWorker: () => boolean;
|
|
25
|
+
export interface S3Credentials {
|
|
26
|
+
accessKeyId: string;
|
|
27
|
+
secretAccessKey: string;
|
|
28
|
+
sessionToken?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface S3Lock {
|
|
31
|
+
mode: "COMPLIANCE" | "GOVERNANCE";
|
|
32
|
+
/** Retain for this many days from the write… */
|
|
33
|
+
days?: number;
|
|
34
|
+
/** …or until this date. */
|
|
35
|
+
until?: Date | string;
|
|
36
|
+
legalHold?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface S3Options {
|
|
39
|
+
bucket: string;
|
|
40
|
+
region: string;
|
|
41
|
+
/** An S3-compatible endpoint (path-style `${endpoint}/${bucket}/${key}`). Default: AWS virtual-hosted. */
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
/** Default STANDARD. S3's name, e.g. GLACIER_IR where an account's plan refuses DEEP_ARCHIVE (S3_STORAGE_CLASSES). */
|
|
44
|
+
storageClass?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Other classes an existing copy may be in and still count as copied. Default: for an archive class (DEEP_ARCHIVE,
|
|
47
|
+
* GLACIER, GLACIER_IR) the other archive classes (the same bytes and checksum, same durability; a lifecycle
|
|
48
|
+
* transition moves copies between them, and copying again would add a new archive version billed for 90-180 days),
|
|
49
|
+
* else none. Writing GLACIER_IR now and DEEP_ARCHIVE later must not copy everything again. Unfinished uploads are
|
|
50
|
+
* resumed only in `storageClass` itself. `[]` accepts `storageClass` only.
|
|
51
|
+
*/
|
|
52
|
+
acceptStorageClasses?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Largest request body on the wire (bytes, aws-chunked framing included): parts and single PUTs are never bigger.
|
|
55
|
+
* Default 96 MiB everywhere (a Cloudflare Worker's outgoing body is cut just above 100 MiB, and a saved plan may be
|
|
56
|
+
* replayed in a Worker), so the largest payload is 96 MiB − 64 KiB (WORKER_MAX_PART). At most S3's 5 GiB payload.
|
|
57
|
+
*/
|
|
58
|
+
maxRequestBytes?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Smallest part but the last (default 5 MiB, S3's). Lower only for an S3-compatible test endpoint that allows it;
|
|
61
|
+
* ignored without `endpoint` or for an AWS endpoint.
|
|
62
|
+
*/
|
|
63
|
+
minPartSize?: number;
|
|
64
|
+
lock?: S3Lock;
|
|
65
|
+
credentials: S3Credentials | (() => S3Credentials | Promise<S3Credentials>);
|
|
66
|
+
fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
67
|
+
/** Control requests (default 60 s). */
|
|
68
|
+
timeoutMs?: number;
|
|
69
|
+
/** A part's request (default 120 s + 1 s per MiB). */
|
|
70
|
+
partTimeoutMs?: (size: number) => number;
|
|
71
|
+
/** Part size for an object of `size` (default 64 MiB, grown to stay under `maxParts`). */
|
|
72
|
+
partSize?: (size: number) => number;
|
|
73
|
+
/** Object ETags are MD5s (default true; false with SSE-KMS / SSE-C). */
|
|
74
|
+
md5Etags?: boolean;
|
|
75
|
+
/** Follow a wrong-region answer once (default true). */
|
|
76
|
+
followRegion?: boolean;
|
|
77
|
+
/** Clock (ms). */
|
|
78
|
+
now?: () => number;
|
|
79
|
+
}
|
|
80
|
+
export type S3Module = CopySource & CopyDestination & {
|
|
81
|
+
readonly bucket: string;
|
|
82
|
+
/** The region requests are signed for now (after a followed redirect, the bucket's). */
|
|
83
|
+
region(): string;
|
|
84
|
+
/** S3's clock minus ours, as learned (ms). */
|
|
85
|
+
skew(): number;
|
|
86
|
+
/** Requests sent, per operation (for races and tests). */
|
|
87
|
+
readonly stats: Record<string, number>;
|
|
88
|
+
abort(key: string, uploadId: string): Promise<void>;
|
|
89
|
+
listUploads(prefix: string): Promise<UploadInfo[]>;
|
|
90
|
+
};
|
|
91
|
+
export declare function s3(o: S3Options): S3Module;
|
|
92
|
+
/** The query string S3 requests carry (exported for the fake's tests). */
|
|
93
|
+
export declare const s3Query: (query: Query) => string;
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An in-process fake of R2 over real HTTP, with injectable faults, for tests of anything that talks to storage:
|
|
3
|
+
* a product's server (through the SDK's R2 client: path-style S3 API with SigV4 checked against the configured
|
|
4
|
+
* credentials) and its clients (presigned PUT/GET URLs, either real SigV4 ones or the fake's own `presign()` tokens).
|
|
5
|
+
*
|
|
6
|
+
* Moved from UploadFilm's app/test/helpers/fake-cloud.ts (whose FakeCloud now extends it with UploadFilm's platform
|
|
7
|
+
* routes). R2 behaviours (measured on a real test bucket):
|
|
8
|
+
* - presigned PUT URLs are bound to their signed headers and expiry: a PUT that omits or changes a signed header
|
|
9
|
+
* (content-md5, content-type, content-length, if-none-match) → 403 SignatureDoesNotMatch; after expiry → 403
|
|
10
|
+
* ExpiredRequest "Request has expired", checked when the request starts only (a slow body that outlives the URL is
|
|
11
|
+
* still stored); a presigned URL dated over 15 min ahead → 403 RequestTimeTooSkewed
|
|
12
|
+
* - every PUT needs a fixed Content-Length: Transfer-Encoding: chunked → 411 MissingContentLength
|
|
13
|
+
* - part ETag = md5 hex of the part body; single-PUT ETag = md5 hex of the body (strong, on PUT responses)
|
|
14
|
+
* - multipart ETag = md5(concat(binary part md5s)) + "-" + N
|
|
15
|
+
* - PUT with If-None-Match: * onto an existing key → 412 PreconditionFailed (also CompleteMultipartUpload)
|
|
16
|
+
* - Content-MD5 mismatch → 400 BadDigest; so is a wrong x-amz-checksum-crc32 / -crc32c / -sha1 / -sha256. A right one
|
|
17
|
+
* is kept and HEAD/GET with `x-amz-checksum-mode: ENABLED` answer it
|
|
18
|
+
* - part numbers outside 1..10,000 → 400 InvalidArgument
|
|
19
|
+
* - part PUT / complete for an unknown (aborted, completed, expired) uploadId → 404 NoSuchUpload
|
|
20
|
+
* - complete: stale part ETag, unequal non-final part sizes or a last part bigger than the others → 400 InvalidPart; a
|
|
21
|
+
* non-final part under 5 MiB → 400 EntityTooSmall; duplicate part numbers → 400 InvalidPartOrder
|
|
22
|
+
* - aborting an upload already aborted → 204 again; DeleteObjects needs no Content-MD5 (a wrong one → BadDigest)
|
|
23
|
+
* - GET honours one Range (206 + Content-Range; suffix and open ranges clamp; past the end → 416 InvalidRange; several
|
|
24
|
+
* ranges → 400), If-Match (stale → 412) and If-None-Match (current → 304); `response-content-disposition` /
|
|
25
|
+
* `-content-type` / `-cache-control` on a signed GET are echoed as headers
|
|
26
|
+
* - HEAD answers carry no body and, when there is nothing to describe (404, other errors), no Content-Length
|
|
27
|
+
* - HEAD/GET of a text-like object (text/*, json, xml, …) over 1 KiB by a client that accepts gzip answers a WEAK
|
|
28
|
+
* ETag W/"…" and no Content-Length (R2 serves those compressed: the GET body is gzip, Content-Encoding: gzip);
|
|
29
|
+
* `accept-encoding: identity` gets the strong one. Ranged GETs are served identity
|
|
30
|
+
* - multipart uploads can expire with time (`uploadMaxAgeMs`, off by default): then NoSuchUpload, like a lifecycle rule
|
|
31
|
+
*
|
|
32
|
+
* Faults: `fake.fault({ target, action, ... })` (FaultRule) and `fake.outage(true|false)`.
|
|
33
|
+
*
|
|
34
|
+
* Its SigV4 verifier is written here on purpose, independently of the SDK's signer (aws4fetch): a second
|
|
35
|
+
* implementation that the SDK's signatures must satisfy, the way R2's own verifier does.
|
|
36
|
+
*
|
|
37
|
+
* A leaf module (only node: imports): UploadFilm's app test loader loads it by path through plain Node, so it stays
|
|
38
|
+
* free of relative imports and of TypeScript-only runtime syntax (no parameter properties, enums or namespaces).
|
|
39
|
+
*/
|
|
40
|
+
import http from "node:http";
|
|
41
|
+
import type { Socket } from "node:net";
|
|
42
|
+
export declare const md5hex: (b: Buffer) => string;
|
|
43
|
+
/** The ETag R2 gives a multipart object made of these part ETags. */
|
|
44
|
+
export declare function multipartEtag(partEtags: string[]): string;
|
|
45
|
+
/** Content types R2 compresses on the fly, whose HEAD/GET ETag is therefore weak (measured: text/plain, application/json weak; video/mp4 strong). */
|
|
46
|
+
export declare const isTextLike: (ct?: string) => boolean;
|
|
47
|
+
export declare const MIN_PART: number;
|
|
48
|
+
/**
|
|
49
|
+
* Storage targets (one request each):
|
|
50
|
+
* partPut (PUT of one multipart part), objectPut (PUT of a whole object), storage (= partPut or objectPut)
|
|
51
|
+
* s3:create, s3:complete, s3:abort, s3:head, s3:get, s3:listParts, s3:list, s3:listUploads, s3:delete,
|
|
52
|
+
* s3:deleteObjects, s3:copy, s3:* (any S3 API call that isn't a part/object PUT)
|
|
53
|
+
* storage:get (a token-presigned GET under `tokenMount`)
|
|
54
|
+
* Subclasses add their own (UploadFilm's FakeCloud: platform routes and sign ops).
|
|
55
|
+
*/
|
|
56
|
+
export type StorageTarget = "partPut" | "objectPut" | "storage" | `s3:${string}`;
|
|
57
|
+
/**
|
|
58
|
+
* drop connection destroyed before the request is applied (nothing happened server-side)
|
|
59
|
+
* reset like drop, but after part of the body was received
|
|
60
|
+
* dropResponse request applied (object stored / part stored / complete done …), response lost
|
|
61
|
+
* holdResponse request applied, response held for `ms` (forever if no ms) — the client has to time out
|
|
62
|
+
* delay wait `ms`, then handle normally
|
|
63
|
+
* status answer `status` (default 503) without applying
|
|
64
|
+
* stall stop reading the request body (no more upload progress) and never answer (or carry on after `ms`)
|
|
65
|
+
* noSuchUpload forget the multipart upload first (aborted by lifecycle / reconcile), then handle normally
|
|
66
|
+
* expire (PUT) this presigned URL has expired by the time the PUT arrives → 403 AccessDenied
|
|
67
|
+
* corruptInTransit (PUT) one byte of the body flips on the wire, BEFORE the Content-MD5 check (→ 400 BadDigest if sent)
|
|
68
|
+
* storeCorrupted (PUT) the body passes the MD5 check but storage stores (and reports the ETag of) one flipped byte
|
|
69
|
+
* noEtag (PUT) stored, answered 200 without an ETag header (a proxy stripping it)
|
|
70
|
+
* gate applied, then the response waits until the test calls `fault.release()`
|
|
71
|
+
* trickle read the body slowly but continuously (64 KiB every `ms`, default 50): a slow uplink, NOT stalled
|
|
72
|
+
* truncate (complete) storage assembles the object one byte short (a storage bug: size check territory)
|
|
73
|
+
* wrongEtag (complete/head) the reported ETag is not the stored object's (a lying / buggy storage answer)
|
|
74
|
+
* error200 (complete/copy) answer 200 with an <Error> body (InternalError, or `code`), not applied
|
|
75
|
+
* On GETs (s3:get, storage:get), `reset` sends the headers and half the body, then kills the connection; `stall`
|
|
76
|
+
* sends the headers and half the body, then stops (carries on after `ms` if given).
|
|
77
|
+
* Platform-level (subclasses): appliedError, duplicate.
|
|
78
|
+
*/
|
|
79
|
+
export type FaultAction = "drop" | "reset" | "dropResponse" | "holdResponse" | "delay" | "status" | "stall" | "noSuchUpload" | "appliedError" | "duplicate" | "expire" | "corruptInTransit" | "storeCorrupted" | "wrongEtag" | "truncate" | "noEtag" | "trickle" | "gate" | "error200";
|
|
80
|
+
export interface FaultInfo<T extends string = string> {
|
|
81
|
+
target: T;
|
|
82
|
+
key?: string;
|
|
83
|
+
partNumber?: number;
|
|
84
|
+
uploadId?: string;
|
|
85
|
+
/** The scope (UploadFilm: the project) when the target knows one. */
|
|
86
|
+
projectId?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface FaultRule<T extends string = string> {
|
|
89
|
+
target: T | T[];
|
|
90
|
+
action: FaultAction;
|
|
91
|
+
status?: number;
|
|
92
|
+
/** S3 error code (storage) or result code (op-level) to send with `status`. */
|
|
93
|
+
code?: string;
|
|
94
|
+
ms?: number;
|
|
95
|
+
/** How many times to fire (default: forever). */
|
|
96
|
+
times?: number;
|
|
97
|
+
/** Let the first N matching requests through untouched. */
|
|
98
|
+
after?: number;
|
|
99
|
+
/** Extra predicate (key, part number, …). */
|
|
100
|
+
match?: (i: FaultInfo<T>) => boolean;
|
|
101
|
+
}
|
|
102
|
+
export interface Fault<T extends string = string> extends FaultRule<T> {
|
|
103
|
+
id: number;
|
|
104
|
+
hits: number;
|
|
105
|
+
seen: number;
|
|
106
|
+
remove(): void;
|
|
107
|
+
/** For action "gate": let every held (and future) matching response through. */
|
|
108
|
+
release(): void;
|
|
109
|
+
}
|
|
110
|
+
export interface StoredObject {
|
|
111
|
+
body: Buffer;
|
|
112
|
+
/** Strong ETag as R2 stores it (md5 hex, or composite md5-N). */
|
|
113
|
+
etag: string;
|
|
114
|
+
size: number;
|
|
115
|
+
contentType?: string;
|
|
116
|
+
/** x-amz-meta-* (S3 API writes). */
|
|
117
|
+
meta?: Record<string, string>;
|
|
118
|
+
lastModified?: number;
|
|
119
|
+
/** x-amz-checksum-* sent with the PUT and verified (algorithm → base64), answered with x-amz-checksum-mode. */
|
|
120
|
+
checksums?: Record<string, string>;
|
|
121
|
+
}
|
|
122
|
+
export interface Upload {
|
|
123
|
+
key: string;
|
|
124
|
+
contentType?: string;
|
|
125
|
+
parts: Map<number, {
|
|
126
|
+
body: Buffer;
|
|
127
|
+
etag: string;
|
|
128
|
+
size: number;
|
|
129
|
+
checksums?: Record<string, string>;
|
|
130
|
+
}>;
|
|
131
|
+
/** When it was created (`now()` ms): `uploadMaxAgeMs` expires it. */
|
|
132
|
+
created?: number;
|
|
133
|
+
}
|
|
134
|
+
export interface CloudEvent {
|
|
135
|
+
t: number;
|
|
136
|
+
kind: string;
|
|
137
|
+
target?: string;
|
|
138
|
+
key?: string;
|
|
139
|
+
n?: number;
|
|
140
|
+
fault?: string;
|
|
141
|
+
status?: number;
|
|
142
|
+
detail?: string;
|
|
143
|
+
}
|
|
144
|
+
/** One storage PUT as the server saw it. */
|
|
145
|
+
export interface PutRecord {
|
|
146
|
+
t: number;
|
|
147
|
+
target: string;
|
|
148
|
+
key: string;
|
|
149
|
+
n?: number;
|
|
150
|
+
uploadId?: string;
|
|
151
|
+
/** Final HTTP status sent, or "closed" if the client went away first, "dropped" if we killed it. */
|
|
152
|
+
outcome: number | "closed" | "dropped" | "pending";
|
|
153
|
+
/** When the answer was sent. */
|
|
154
|
+
doneAt?: number;
|
|
155
|
+
/** The request carried Content-MD5 (bytes checked by storage). */
|
|
156
|
+
md5: boolean;
|
|
157
|
+
/** When the client closed the connection before an answer (stall detector / timeout / abort). */
|
|
158
|
+
clientClosedAt?: number;
|
|
159
|
+
bytes: number;
|
|
160
|
+
}
|
|
161
|
+
interface Presigned {
|
|
162
|
+
/** A presigned GET, not a PUT. */
|
|
163
|
+
get?: boolean;
|
|
164
|
+
key: string;
|
|
165
|
+
partNumber?: number;
|
|
166
|
+
uploadId?: string;
|
|
167
|
+
headers: Record<string, string>;
|
|
168
|
+
expiresAt: number;
|
|
169
|
+
}
|
|
170
|
+
/** Credentials the S3 API checks SigV4 against (the product's R2_* in tests). */
|
|
171
|
+
export interface FakeS3Config {
|
|
172
|
+
bucket: string;
|
|
173
|
+
accessKeyId: string;
|
|
174
|
+
secretAccessKey: string;
|
|
175
|
+
/** Default "auto". */
|
|
176
|
+
region?: string;
|
|
177
|
+
}
|
|
178
|
+
export interface FakeR2Options {
|
|
179
|
+
/** Serve the S3 API (path-style /<bucket>/<key>) with SigV4 checked. Without it only token URLs work. */
|
|
180
|
+
s3?: FakeS3Config;
|
|
181
|
+
}
|
|
182
|
+
type SigCheck = {
|
|
183
|
+
status: number;
|
|
184
|
+
code: string;
|
|
185
|
+
message: string;
|
|
186
|
+
} | null;
|
|
187
|
+
/** One S3 API answer: an error code (+ message), or status/headers/body. `noLength`: send no Content-Length. */
|
|
188
|
+
export interface S3Answer {
|
|
189
|
+
status: number;
|
|
190
|
+
error?: string;
|
|
191
|
+
message?: string;
|
|
192
|
+
body?: Buffer;
|
|
193
|
+
headers?: Record<string, string | number>;
|
|
194
|
+
noLength?: boolean;
|
|
195
|
+
}
|
|
196
|
+
export declare class FakeR2 {
|
|
197
|
+
objects: Map<string, StoredObject>;
|
|
198
|
+
uploads: Map<string, Upload>;
|
|
199
|
+
events: CloudEvent[];
|
|
200
|
+
/** Every storage PUT (see PutRecord). */
|
|
201
|
+
puts: PutRecord[];
|
|
202
|
+
/** Counts: requests, faults, rejectedSignature, and one `<target>s` per PUT target (partPuts, objectPuts, …). */
|
|
203
|
+
counters: Record<string, number>;
|
|
204
|
+
/** Every request, whatever it is: connection destroyed. */
|
|
205
|
+
offline: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Attempts refused by an outage, per unit: `${key}#${n}` for a part PUT, `${key}#put` for an object PUT, the path
|
|
208
|
+
* for anything else. Lets tests drive outages by attempt count instead of by time.
|
|
209
|
+
*/
|
|
210
|
+
refused: Map<string, number>;
|
|
211
|
+
/** App-time scale (real ms = app ms × scale): scales presign expiry. */
|
|
212
|
+
scale: number;
|
|
213
|
+
/** HEAD/GET answer weak ETags for text-like objects over 1 KiB, as R2 does (unless accept-encoding: identity). */
|
|
214
|
+
weakEtags: boolean;
|
|
215
|
+
/** Check signed headers / expiry on presigned PUTs (tokens and SigV4). */
|
|
216
|
+
enforceSignatures: boolean;
|
|
217
|
+
/** Keep part bodies (needed to assemble objects and check sha256). Off = only sizes/ETags (huge files). */
|
|
218
|
+
keepBodies: boolean;
|
|
219
|
+
/** Where presigned URLs point (default: this server). A chaos lab points them at a fault proxy. */
|
|
220
|
+
publicBase: string;
|
|
221
|
+
/** Token presigned URLs are mounted here: `${base}${tokenMount}${encodeURIComponent(key)}?X-Uf-Signature=…`. */
|
|
222
|
+
tokenMount: string;
|
|
223
|
+
/** Presigned token lifetime (real ms, before `scale`). */
|
|
224
|
+
presignTtlMs: number;
|
|
225
|
+
/** Clock (ms) for SigV4 dates and expiry. */
|
|
226
|
+
now: () => number;
|
|
227
|
+
/** GET of a text-like object over 1 KiB by a client that accepts gzip is sent gzip-encoded, as R2 does. Off = identity. */
|
|
228
|
+
gzipText: boolean;
|
|
229
|
+
/** Accept PUTs without a fixed Content-Length (Transfer-Encoding: chunked). R2 refuses them (411); on = the old leniency. */
|
|
230
|
+
allowChunkedPuts: boolean;
|
|
231
|
+
/** Check presigned expiry (and clock skew) again once the body is in. R2 checks at the start only; on = the old RL-D6 behaviour. */
|
|
232
|
+
expiryAfterBody: boolean;
|
|
233
|
+
/** Lifecycle: a multipart upload older than this many ms (on `now()`) is gone (NoSuchUpload). 0 = never (default). */
|
|
234
|
+
uploadMaxAgeMs: number;
|
|
235
|
+
/** Uploads aborted through the S3 API (id → key): aborting one again answers 204, as R2 does. */
|
|
236
|
+
protected aborted: Map<string, string>;
|
|
237
|
+
readonly s3?: FakeS3Config;
|
|
238
|
+
protected server?: http.Server;
|
|
239
|
+
protected sockets: Set<Socket>;
|
|
240
|
+
protected faults: Fault<string>[];
|
|
241
|
+
protected gates: Map<Fault<string>, Promise<void>>;
|
|
242
|
+
protected nextFaultId: number;
|
|
243
|
+
protected presigned: Map<string, Presigned>;
|
|
244
|
+
base: string;
|
|
245
|
+
port: number;
|
|
246
|
+
constructor(o?: FakeR2Options);
|
|
247
|
+
start(port?: number, host?: string): Promise<this>;
|
|
248
|
+
close(): Promise<void>;
|
|
249
|
+
/** The endpoint a product's R2 client points at (S3 API mode). */
|
|
250
|
+
get endpoint(): string;
|
|
251
|
+
fault<T extends string = StorageTarget>(rule: FaultRule<T>): Fault<T>;
|
|
252
|
+
clearFaults(): void;
|
|
253
|
+
/** Network gone (cable pulled): open connections die, new ones fail. `false` = back. */
|
|
254
|
+
outage(on: boolean): void;
|
|
255
|
+
/** Attempts of part `n` of `key` refused by the outage so far. */
|
|
256
|
+
refusedAttempts(key: string, n: number): number;
|
|
257
|
+
/** Simulate R2's lifecycle rule / a reconcile job aborting a multipart upload. */
|
|
258
|
+
abortUpload(uploadId: string): void;
|
|
259
|
+
/**
|
|
260
|
+
* The multipart upload `id` if it still exists: unknown ids, and (with `uploadMaxAgeMs`) uploads older than that,
|
|
261
|
+
* are gone (the lifecycle rule removes them on first sight). Subclasses should look uploads up through this.
|
|
262
|
+
*/
|
|
263
|
+
liveUpload(id: string | undefined): Upload | undefined;
|
|
264
|
+
/** Does rule target `t` cover request target `target`? Subclasses add aliases. */
|
|
265
|
+
protected targetMatches(t: string, target: string): boolean;
|
|
266
|
+
protected pick(info: FaultInfo<string>): Fault<string> | null;
|
|
267
|
+
protected log(e: Omit<CloudEvent, "t">): void;
|
|
268
|
+
object(key: string): StoredObject | undefined;
|
|
269
|
+
sha256(key: string): string | null;
|
|
270
|
+
/** What a server's headInfo() returns: size and the HEAD ETag with quotes stripped (weak → `W/<md5>`). */
|
|
271
|
+
headInfo(key: string): {
|
|
272
|
+
size: null;
|
|
273
|
+
etag: null;
|
|
274
|
+
} | {
|
|
275
|
+
size: number;
|
|
276
|
+
etag: string;
|
|
277
|
+
};
|
|
278
|
+
/** Successful PUTs of part `n` under `uploadId` (to check what a restarted client resends). */
|
|
279
|
+
partPutsOf(uploadId: string, n?: number): PutRecord[];
|
|
280
|
+
/** Last-modified for S3 API listings (only in S3 API mode: token-mode objects keep their original shape). */
|
|
281
|
+
protected stamp(): {
|
|
282
|
+
lastModified?: number;
|
|
283
|
+
};
|
|
284
|
+
/** Put an object in place directly (test setup). */
|
|
285
|
+
seed(key: string, body: Buffer | string, contentType?: string, meta?: Record<string, string>): void;
|
|
286
|
+
/** A presigned PUT URL for `key` (part with `partNumber` + `uploadId`) whose signed headers are `headers`. */
|
|
287
|
+
presign(key: string, headers: Record<string, string>, q?: {
|
|
288
|
+
partNumber?: number;
|
|
289
|
+
uploadId?: string;
|
|
290
|
+
}): {
|
|
291
|
+
url: string;
|
|
292
|
+
expiresAt: string;
|
|
293
|
+
};
|
|
294
|
+
/** A presigned GET URL (5 min by default). */
|
|
295
|
+
presignGet(key: string, ttlMs?: number): string;
|
|
296
|
+
/** Change when a token URL expires (real ms). */
|
|
297
|
+
protected expireToken(url: string, at: number): void;
|
|
298
|
+
protected handle(req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
|
|
299
|
+
/** Requests that are neither storage nor S3 API: 404 here, a subclass's platform routes. */
|
|
300
|
+
protected route(req: http.IncomingMessage, res: http.ServerResponse, _url: URL): Promise<void>;
|
|
301
|
+
protected bump(k: string): void;
|
|
302
|
+
/** Outage: count what was attempted (attempt-driven tests), then the connection dies. */
|
|
303
|
+
protected refuse(req: http.IncomingMessage, url: URL): Promise<void>;
|
|
304
|
+
protected json(res: http.ServerResponse, status: number, body: unknown): void;
|
|
305
|
+
protected s3err(res: http.ServerResponse, status: number, code: string, message?: string): undefined;
|
|
306
|
+
protected xml(res: http.ServerResponse, status: number, body: string, headers?: Record<string, string | number>): void;
|
|
307
|
+
protected body(req: http.IncomingMessage): Promise<Buffer<ArrayBufferLike>>;
|
|
308
|
+
/** Run the pre-apply part of a fault. Returns "handled" (answered/killed, stop) or "apply". */
|
|
309
|
+
protected pre(f: Fault<string> | null, req: http.IncomingMessage, res: http.ServerResponse, storage: boolean): Promise<"handled" | "apply">;
|
|
310
|
+
/** After the request was applied: lose or hold the response if the fault says so. True = don't respond. */
|
|
311
|
+
protected post(f: Fault<string> | null, req: http.IncomingMessage): Promise<boolean>;
|
|
312
|
+
/**
|
|
313
|
+
* R2's check of a token-presigned PUT: the URL's token must exist, be unexpired, and every signed header must be sent
|
|
314
|
+
* unchanged. `afterBody`: the second check, once the body is in (expiry is not checked again unless `expiryAfterBody`).
|
|
315
|
+
*/
|
|
316
|
+
protected checkSignature(req: http.IncomingMessage, url: URL, key: string, bodyLength: number | null, afterBody?: boolean): SigCheck;
|
|
317
|
+
/** Which PUT target a key/part is (subclasses split targets, e.g. UploadFilm's manifestPut). */
|
|
318
|
+
protected putTarget(key: string, partNumber: string | null): string;
|
|
319
|
+
/** A token-presigned GET or PUT under `tokenMount`. */
|
|
320
|
+
protected storage(req: http.IncomingMessage, res: http.ServerResponse, url: URL): Promise<undefined>;
|
|
321
|
+
/**
|
|
322
|
+
* One storage PUT (part or object), however it was signed: signature first (headers only), faults, body, the
|
|
323
|
+
* signature again with the body's length, Content-MD5, store, answer.
|
|
324
|
+
*/
|
|
325
|
+
protected storePut(req: http.IncomingMessage, res: http.ServerResponse, o: {
|
|
326
|
+
key: string;
|
|
327
|
+
pn: string | null;
|
|
328
|
+
uploadId?: string;
|
|
329
|
+
target: string;
|
|
330
|
+
check: (bodyLength: number | null, body?: Buffer) => SigCheck;
|
|
331
|
+
expire: () => void;
|
|
332
|
+
/** An S3 API PUT (If-Match and x-amz-meta-* honoured); token PUTs keep the platform fake's original rules. */
|
|
333
|
+
s3?: boolean;
|
|
334
|
+
}): Promise<undefined>;
|
|
335
|
+
createUpload(key: string, contentType?: string): string;
|
|
336
|
+
/**
|
|
337
|
+
* CompleteMultipartUpload as R2 does it. → the stored object, or the S3 error code. `truncate`: the storage bug
|
|
338
|
+
* fault (one byte short). The upload is consumed on success.
|
|
339
|
+
*/
|
|
340
|
+
completeUpload(key: string, uploadId: string, parts: {
|
|
341
|
+
n: number;
|
|
342
|
+
etag: string;
|
|
343
|
+
}[], o?: {
|
|
344
|
+
truncate?: boolean;
|
|
345
|
+
ifNoneMatch?: boolean;
|
|
346
|
+
}): {
|
|
347
|
+
ok: true;
|
|
348
|
+
object: StoredObject;
|
|
349
|
+
} | {
|
|
350
|
+
ok: false;
|
|
351
|
+
code: string;
|
|
352
|
+
status: number;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* SigV4 as R2 checks it, header-signed or presigned. `bodyLength` null = before the body was read. Expiry and clock
|
|
356
|
+
* skew are checked on the first call only (R2 checks them when the request starts) unless `expiryAfterBody`.
|
|
357
|
+
*/
|
|
358
|
+
protected checkSigV4(req: http.IncomingMessage, url: URL, bodyLength: number | null, body?: Buffer): SigCheck;
|
|
359
|
+
/** Key from a path-style S3 path (/bucket/a/b%20c → "a/b c"), "" for the bucket itself. */
|
|
360
|
+
protected s3Key(url: URL): string;
|
|
361
|
+
protected etagHeader(o: StoredObject, req: http.IncomingMessage): {
|
|
362
|
+
weak: boolean;
|
|
363
|
+
etag: string;
|
|
364
|
+
};
|
|
365
|
+
protected s3api(req: http.IncomingMessage, res: http.ServerResponse, url: URL): Promise<undefined>;
|
|
366
|
+
/** A GET fault that acts on the response body (reset / stall half-way), not before the request is applied. */
|
|
367
|
+
protected midBodyFault(f: Fault<string> | null): boolean;
|
|
368
|
+
/** Write a HEAD/GET answer; `reset` / `stall` faults cut or stop the body half-way. */
|
|
369
|
+
protected sendRead(req: http.IncomingMessage, res: http.ServerResponse, a: S3Answer, f: Fault<string> | null): Promise<undefined>;
|
|
370
|
+
/**
|
|
371
|
+
* HEAD/GET of a stored object as R2 answers it: If-Match (412), If-None-Match (304), one Range (206 / 416 / 400 for
|
|
372
|
+
* several), the weak ETag and gzip body for text-like objects, x-amz-checksum-mode, response-* overrides.
|
|
373
|
+
*/
|
|
374
|
+
protected readAnswer(o: StoredObject, req: http.IncomingMessage, url: URL, head: boolean, f: Fault<string> | null): S3Answer;
|
|
375
|
+
/** Apply one S3 API call. */
|
|
376
|
+
protected s3apply(action: string, key: string, req: http.IncomingMessage, url: URL, body: Buffer, f: Fault<string> | null): Promise<S3Answer>;
|
|
377
|
+
}
|
|
378
|
+
/** A started FakeR2 serving the S3 API for these credentials (default bucket "test-bucket"). */
|
|
379
|
+
export declare function createFakeR2(o?: Partial<FakeS3Config> & {
|
|
380
|
+
port?: number;
|
|
381
|
+
}): Promise<FakeR2 & {
|
|
382
|
+
config: {
|
|
383
|
+
endpoint: string;
|
|
384
|
+
bucket: string;
|
|
385
|
+
accessKeyId: string;
|
|
386
|
+
secretAccessKey: string;
|
|
387
|
+
region: string | undefined;
|
|
388
|
+
};
|
|
389
|
+
}>;
|
|
390
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@uploadfilm/sdk/server/testing`: a fake R2 for products' tests (Node). `createFakeR2()` serves the S3 API with SigV4
|
|
3
|
+
* checked (point the SDK's R2 client at `fake.config`), presigned URLs included; `fake.fault({ target, action })`
|
|
4
|
+
* injects drops, resets, stalls, lost responses, corruption, expiry, truncation and more. RFC §2.4.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SDK_ENTRY: "server/testing";
|
|
7
|
+
export { createFakeR2, FakeR2, isTextLike, md5hex, MIN_PART, multipartEtag } from "./fake-r2";
|
|
8
|
+
export { keyValueStoreContract } from "./kv-contract";
|
|
9
|
+
export type { KvCase, KvHarness } from "./kv-contract";
|
|
10
|
+
export type { CloudEvent, Fault, FaultAction, FaultInfo, FaultRule, FakeR2Options, FakeS3Config, PutRecord, StorageTarget, StoredObject, Upload, } from "./fake-r2";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KeyValueStore } from "@uploadfilm/sdk/server";
|
|
2
|
+
export interface KvHarness {
|
|
3
|
+
make(): Promise<{
|
|
4
|
+
store: KeyValueStore;
|
|
5
|
+
advance(ms: number): Promise<void>;
|
|
6
|
+
}>;
|
|
7
|
+
/** Milliseconds to use as a short TTL (Redis: real time; default 200). */
|
|
8
|
+
shortTtlMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface KvCase {
|
|
11
|
+
name: string;
|
|
12
|
+
run(h: KvHarness): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function keyValueStoreContract(): KvCase[];
|