@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.
Files changed (218) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +509 -2
  3. package/dist/ai/embed.d.ts +58 -0
  4. package/dist/ai/fake.d.ts +41 -0
  5. package/dist/ai/http.d.ts +17 -0
  6. package/dist/ai/index.d.ts +27 -0
  7. package/dist/ai/languages.d.ts +2 -0
  8. package/dist/ai/ollama.d.ts +23 -0
  9. package/dist/ai/openaiCompatible.d.ts +54 -0
  10. package/dist/ai/passages.d.ts +28 -0
  11. package/dist/ai/transcribe.d.ts +84 -0
  12. package/dist/ai/types.d.ts +141 -0
  13. package/dist/ai/usage.d.ts +66 -0
  14. package/dist/ai/whisperJson.d.ts +15 -0
  15. package/dist/ai/workersAi.d.ts +56 -0
  16. package/dist/ai.js +1 -0
  17. package/dist/ai.mjs +1 -0
  18. package/dist/cards/files.d.ts +91 -0
  19. package/dist/cards/index.d.ts +15 -0
  20. package/dist/cards/layouts.d.ts +121 -0
  21. package/dist/cards/probe.d.ts +69 -0
  22. package/dist/cards/proxies.d.ts +70 -0
  23. package/dist/cards/select.d.ts +68 -0
  24. package/dist/cards/volumes.d.ts +170 -0
  25. package/dist/cards/xml.d.ts +80 -0
  26. package/dist/cards.js +1 -0
  27. package/dist/cards.mjs +1 -0
  28. package/dist/copy/checksums.d.ts +66 -0
  29. package/dist/copy/engine.d.ts +24 -0
  30. package/dist/copy/errors.d.ts +109 -0
  31. package/dist/copy/index.d.ts +15 -0
  32. package/dist/copy/steps.d.ts +28 -0
  33. package/dist/copy/sweep.d.ts +24 -0
  34. package/dist/copy/types.d.ts +336 -0
  35. package/dist/embed/player.js +2 -0
  36. package/dist/host/adapters.d.ts +107 -0
  37. package/dist/host/detect.d.ts +68 -0
  38. package/dist/host/encoders.d.ts +34 -0
  39. package/dist/host/environment.d.ts +53 -0
  40. package/dist/host/index.d.ts +20 -0
  41. package/dist/host/linux.d.ts +94 -0
  42. package/dist/host/mac.d.ts +47 -0
  43. package/dist/host/network.d.ts +54 -0
  44. package/dist/host/node.d.ts +13 -0
  45. package/dist/host/policy.d.ts +101 -0
  46. package/dist/host/tuner.d.ts +48 -0
  47. package/dist/host/types.d.ts +118 -0
  48. package/dist/host-node.js +1 -0
  49. package/dist/host-node.mjs +1 -0
  50. package/dist/host.js +1 -0
  51. package/dist/host.mjs +1 -0
  52. package/dist/images/index.d.ts +11 -0
  53. package/dist/images/settings.d.ts +43 -0
  54. package/dist/images/types.d.ts +83 -0
  55. package/dist/images/url.d.ts +65 -0
  56. package/dist/index.d.ts +16 -0
  57. package/dist/index.js +1 -0
  58. package/dist/index.mjs +1 -0
  59. package/dist/player/adapters/hlsjs.d.ts +28 -0
  60. package/dist/player/bandwidthMemory.d.ts +28 -0
  61. package/dist/player/captions/index.d.ts +55 -0
  62. package/dist/player/embed/code.d.ts +195 -0
  63. package/dist/player/embed/constants.d.ts +4 -0
  64. package/dist/player/embed/controller.d.ts +62 -0
  65. package/dist/player/embed/element.d.ts +32 -0
  66. package/dist/player/embed/frame.d.ts +65 -0
  67. package/dist/player/embed/global.d.ts +14 -0
  68. package/dist/player/embed/index.d.ts +15 -0
  69. package/dist/player/embed/loader.d.ts +1 -0
  70. package/dist/player/embed/oembed.d.ts +74 -0
  71. package/dist/player/embed/protocol.d.ts +64 -0
  72. package/dist/player/engine.d.ts +215 -0
  73. package/dist/player/index.d.ts +18 -0
  74. package/dist/player/start.d.ts +62 -0
  75. package/dist/player/store.d.ts +10 -0
  76. package/dist/player/storyboard/index.d.ts +161 -0
  77. package/dist/player/stream.d.ts +206 -0
  78. package/dist/player/tracks.d.ts +41 -0
  79. package/dist/player.js +1 -0
  80. package/dist/player.mjs +1 -0
  81. package/dist/proxies/args.d.ts +19 -0
  82. package/dist/proxies/budget.d.ts +57 -0
  83. package/dist/proxies/camera.d.ts +104 -0
  84. package/dist/proxies/formats.d.ts +36 -0
  85. package/dist/proxies/index.d.ts +18 -0
  86. package/dist/proxies/jobs.d.ts +98 -0
  87. package/dist/proxies/node.d.ts +32 -0
  88. package/dist/proxies/plan.d.ts +89 -0
  89. package/dist/proxies/probe.d.ts +39 -0
  90. package/dist/proxies/render.d.ts +104 -0
  91. package/dist/proxies/safety.d.ts +45 -0
  92. package/dist/proxies/types.d.ts +83 -0
  93. package/dist/proxies/upload.d.ts +14 -0
  94. package/dist/react/BigPlay.d.ts +26 -0
  95. package/dist/react/Player.d.ts +58 -0
  96. package/dist/react/embed/index.d.ts +45 -0
  97. package/dist/react/examples/CustomControls.d.ts +8 -0
  98. package/dist/react/images/Image.d.ts +16 -0
  99. package/dist/react/images/index.d.ts +4 -0
  100. package/dist/react/images/useImage.d.ts +47 -0
  101. package/dist/react/index.d.ts +17 -0
  102. package/dist/react/storyboard/index.d.ts +58 -0
  103. package/dist/react/theme.d.ts +37 -0
  104. package/dist/react/useAdapterErrors.d.ts +8 -0
  105. package/dist/react/usePlaybackStart.d.ts +18 -0
  106. package/dist/react/usePlayer.d.ts +28 -0
  107. package/dist/react/useReducedMotion.d.ts +2 -0
  108. package/dist/react/useTimedTrack.d.ts +22 -0
  109. package/dist/react.js +1 -0
  110. package/dist/react.mjs +1 -0
  111. package/dist/server/auth/apiKeys.d.ts +30 -0
  112. package/dist/server/auth/cache.d.ts +21 -0
  113. package/dist/server/auth/deviceTokens.d.ts +38 -0
  114. package/dist/server/auth/envelope.d.ts +15 -0
  115. package/dist/server/auth/grants.d.ts +76 -0
  116. package/dist/server/auth/index.d.ts +19 -0
  117. package/dist/server/auth/jwt.d.ts +65 -0
  118. package/dist/server/auth/keyring.d.ts +31 -0
  119. package/dist/server/auth/kv.d.ts +12 -0
  120. package/dist/server/auth/repository.d.ts +45 -0
  121. package/dist/server/auth/revocations.d.ts +21 -0
  122. package/dist/server/auth/scope.d.ts +4 -0
  123. package/dist/server/auth/serviceAuth.d.ts +24 -0
  124. package/dist/server/auth/signedUrls.d.ts +28 -0
  125. package/dist/server/embed/index.d.ts +36 -0
  126. package/dist/server/embed/lifecycle.d.ts +53 -0
  127. package/dist/server/embed/playerScript.d.ts +4 -0
  128. package/dist/server/images/index.d.ts +15 -0
  129. package/dist/server/images/job.d.ts +80 -0
  130. package/dist/server/images/layout.d.ts +24 -0
  131. package/dist/server/images/params.d.ts +90 -0
  132. package/dist/server/images/route.d.ts +101 -0
  133. package/dist/server/images/sign.d.ts +55 -0
  134. package/dist/server/index.d.ts +42 -0
  135. package/dist/server/media/client.d.ts +66 -0
  136. package/dist/server/media/frameCheck.d.ts +62 -0
  137. package/dist/server/media/index.d.ts +10 -0
  138. package/dist/server/media/protocol.d.ts +318 -0
  139. package/dist/server/media/storyboard.d.ts +144 -0
  140. package/dist/server/media/transcript.d.ts +143 -0
  141. package/dist/server/pipeline/index.d.ts +12 -0
  142. package/dist/server/pipeline/match.d.ts +10 -0
  143. package/dist/server/pipeline/pipeline.d.ts +182 -0
  144. package/dist/server/pipeline/queues.d.ts +108 -0
  145. package/dist/server/pipeline/sources.d.ts +54 -0
  146. package/dist/server/r2/client.d.ts +150 -0
  147. package/dist/server/r2/crc32.d.ts +24 -0
  148. package/dist/server/r2/encoding.d.ts +35 -0
  149. package/dist/server/r2/errors.d.ts +9 -0
  150. package/dist/server/r2/integrity.d.ts +25 -0
  151. package/dist/server/r2/parts.d.ts +46 -0
  152. package/dist/server/r2/sign.d.ts +47 -0
  153. package/dist/server/redis/index.d.ts +39 -0
  154. package/dist/server/state/memory.d.ts +18 -0
  155. package/dist/server/state/r2.d.ts +73 -0
  156. package/dist/server/state/types.d.ts +57 -0
  157. package/dist/server/storage/chunked.d.ts +21 -0
  158. package/dist/server/storage/index.d.ts +12 -0
  159. package/dist/server/storage/r2.d.ts +96 -0
  160. package/dist/server/storage/s3.d.ts +93 -0
  161. package/dist/server/testing/fake-r2.d.ts +390 -0
  162. package/dist/server/testing/index.d.ts +10 -0
  163. package/dist/server/testing/kv-contract.d.ts +14 -0
  164. package/dist/server/transfer/handler.d.ts +167 -0
  165. package/dist/server/transfer/keys.d.ts +45 -0
  166. package/dist/server/transfer/protocol.d.ts +141 -0
  167. package/dist/server/zip/client.d.ts +32 -0
  168. package/dist/server/zip/generations.d.ts +83 -0
  169. package/dist/server/zip/index.d.ts +12 -0
  170. package/dist/server/zip/planner.d.ts +94 -0
  171. package/dist/server/zip/sign.d.ts +22 -0
  172. package/dist/server-media.js +1 -0
  173. package/dist/server-media.mjs +1 -0
  174. package/dist/server-redis.js +1 -0
  175. package/dist/server-redis.mjs +1 -0
  176. package/dist/server-testing.js +1 -0
  177. package/dist/server-testing.mjs +1 -0
  178. package/dist/server.js +1 -0
  179. package/dist/server.mjs +1 -0
  180. package/dist/storage/browserFile.d.ts +19 -0
  181. package/dist/storage/index.d.ts +12 -0
  182. package/dist/storage/local.d.ts +9 -0
  183. package/dist/storage/presigned.d.ts +22 -0
  184. package/dist/sync/ffmpeg.d.ts +44 -0
  185. package/dist/sync/index.d.ts +17 -0
  186. package/dist/sync/match.d.ts +28 -0
  187. package/dist/sync/probe.d.ts +30 -0
  188. package/dist/sync/timecode.d.ts +50 -0
  189. package/dist/sync/transcript.d.ts +35 -0
  190. package/dist/sync/types.d.ts +172 -0
  191. package/dist/sync/waveform.d.ts +89 -0
  192. package/dist/sync.js +1 -0
  193. package/dist/sync.mjs +1 -0
  194. package/dist/transfer/claims.d.ts +41 -0
  195. package/dist/transfer/client.d.ts +256 -0
  196. package/dist/transfer/download.d.ts +192 -0
  197. package/dist/transfer/engine.d.ts +382 -0
  198. package/dist/transfer/errors.d.ts +50 -0
  199. package/dist/transfer/index.d.ts +39 -0
  200. package/dist/transfer/integrity.d.ts +93 -0
  201. package/dist/transfer/limits.d.ts +34 -0
  202. package/dist/transfer/node.d.ts +63 -0
  203. package/dist/transfer/pool.d.ts +83 -0
  204. package/dist/transfer/protocol.d.ts +167 -0
  205. package/dist/transfer/signer.d.ts +29 -0
  206. package/dist/transfer/storage.d.ts +110 -0
  207. package/dist/transfer/timing.d.ts +132 -0
  208. package/dist/transfer/transports/electronNet.d.ts +62 -0
  209. package/dist/transfer/transports/fetch.d.ts +15 -0
  210. package/dist/transfer/transports/retryAfter.d.ts +12 -0
  211. package/dist/transfer/transports/undici.d.ts +72 -0
  212. package/dist/transfer/tuner.d.ts +56 -0
  213. package/dist/zip/index.d.ts +13 -0
  214. package/dist/zip/layout.d.ts +129 -0
  215. package/dist/zip/names.d.ts +34 -0
  216. package/dist/zip/plan.d.ts +115 -0
  217. package/dist/zip/sw.d.ts +7 -0
  218. package/package.json +265 -4
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Errors of the copy engine and its storage modules, with one classification every module maps into, so the engine
3
+ * decides "retry", "start the upload again" or "stop and alert" the same way for R2, S3, a presigned route or a file.
4
+ *
5
+ * Checked by `name` and `code`, never `instanceof`: the root entry and `@uploadfilm/sdk/server` are separate bundles,
6
+ * so a CopyError thrown by an `s3()` module and one made by the engine may come from two copies of this class.
7
+ */
8
+ /** What the error means for the copy. */
9
+ export type CopyErrorCode =
10
+ /** The source is no longer the version being copied (a new ETag): the copy of the old one is abandoned. */
11
+ "SourceChanged"
12
+ /** The source object does not exist. */
13
+ | "SourceGone"
14
+ /** The source can't be reached (R2 down, a broken read): retried, then alert "source". */
15
+ | "SourceUnavailable"
16
+ /** The source returned fewer or more bytes than asked for. */
17
+ | "ShortRead"
18
+ /** The multipart upload no longer exists (aborted by a lifecycle rule, completed elsewhere). */
19
+ | "NoSuchUpload"
20
+ /** Storage throttles (503 SlowDown, 429). */
21
+ | "Throttled"
22
+ /** Storage failed (500 InternalError, 502, 503 ServiceUnavailable). */
23
+ | "StorageError"
24
+ /** No answer in time (request timeout, a hung connection). */
25
+ | "Timeout"
26
+ /** The connection broke (reset, refused, DNS). */
27
+ | "Network"
28
+ /** A part reached storage damaged (BadDigest) or storage echoed another checksum: that part is resent. */
29
+ | "PartChecksumMismatch"
30
+ /** The stored object's checksum is not the one of the bytes sent (combined CRC / composite ETag). */
31
+ | "StoredChecksumMismatch"
32
+ /** The copy holds other bytes than the source's known checksum says. */
33
+ | "SourceChecksumMismatch"
34
+ /**
35
+ * Storage refused a request's signature (S3 SignatureDoesNotMatch). Real S3 answers it in bursts to correctly
36
+ * signed requests from a Worker (348 times in one backfill, every one fine on a retry with a fresh signature), so
37
+ * it is retried; only after `RetryPolicy.attempts` fresh signatures in a row does the copy call it Credentials.
38
+ */
39
+ | "SignatureMismatch"
40
+ /** The credentials are wrong, rotated, expired or lack a permission. */
41
+ | "Credentials"
42
+ /** The bucket is in another region than configured and the redirect couldn't be followed. */
43
+ | "WrongRegion"
44
+ /** Storage refuses our clock even when signed with its own time. */
45
+ | "ClockSkew"
46
+ /** Object Lock (or a WORM policy) refused the write. */
47
+ | "Locked"
48
+ /** The bucket does not exist, or the request is malformed: retrying can't help. */
49
+ | "Refused"
50
+ /** The copy is bigger than the destination accepts. */
51
+ | "TooLarge"
52
+ /** The copy was cancelled (signal). */
53
+ | "Aborted"
54
+ /** Retries or the time budget for one step are spent. */
55
+ | "RetriesExhausted";
56
+ /** Why a copy stopped and someone must look: the pipeline's `alert` names one of these. */
57
+ export type AlertKind = "source" | "storage" | "credentials" | "region" | "clock" | "checksum" | "lock" | "refused" | "budget";
58
+ export interface CopyErrorInit {
59
+ status?: number;
60
+ /** The storage's own error code (S3 `<Code>`), kept for logs. */
61
+ storageCode?: string;
62
+ /** Retrying (now or later) can help. */
63
+ retryable?: boolean;
64
+ /** Retrying can never help without someone changing something (keys, region, lock): no retries at all. */
65
+ fatal?: boolean;
66
+ alert?: AlertKind;
67
+ /** Wait at least this long before retrying (Retry-After). */
68
+ retryAfterMs?: number;
69
+ /** The region the bucket says it is in. */
70
+ region?: string;
71
+ cause?: unknown;
72
+ /** Extra facts for the alert (key, part number, checksums). */
73
+ detail?: Record<string, unknown>;
74
+ /**
75
+ * Not a failure: the module corrected something (learned storage's clock, followed a region, picked up new
76
+ * credentials) after a streamed body was already spent. The engine sends the same request again at once, without
77
+ * counting a try or waiting, once per call.
78
+ */
79
+ resend?: boolean;
80
+ }
81
+ export declare class CopyError extends Error {
82
+ readonly code: CopyErrorCode;
83
+ readonly status?: number;
84
+ readonly storageCode?: string;
85
+ readonly retryable: boolean;
86
+ readonly fatal: boolean;
87
+ readonly alert?: AlertKind;
88
+ readonly retryAfterMs?: number;
89
+ readonly region?: string;
90
+ readonly detail?: Record<string, unknown>;
91
+ readonly resend?: boolean;
92
+ constructor(code: CopyErrorCode, message: string, init?: CopyErrorInit);
93
+ }
94
+ /** A CopyError from either bundle (name + code), never a lookalike from elsewhere. */
95
+ export declare function isCopyError(e: unknown): e is CopyError;
96
+ /** `[copy:<code>:<alert>:<r|f>]`: a CopyError's classification in a message, which survives serialization. */
97
+ export declare const copyTag: (e: CopyError, retryable?: boolean) => string;
98
+ /** Inngest's NonRetriableError is recognised by name, inside a step too: a fatal error stops its retries. */
99
+ export declare function nonRetriable(e: CopyError): Error;
100
+ /**
101
+ * Any thrown value → a CopyError. Module errors already are; a fetch that rejected is a network error (or a timeout
102
+ * when its signal fired); anything else is a storage error worth a retry.
103
+ */
104
+ export declare function toCopyError(e: unknown, what?: string): CopyError;
105
+ /**
106
+ * The classification of an S3/R2 answer (status + `<Code>`), shared by the r2/s3/presigned modules. Redirects,
107
+ * clock skew and credential refreshes are handled by the module before it gets here.
108
+ */
109
+ export declare function classifyStorage(status: number, code: string, message: string, what: string, extra?: CopyErrorInit): CopyError;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `copy({ from, to })`: the one transfer engine for upload, download and replication (RFC §2). Storage modules are
3
+ * in ../storage (local, browserFile, presigned) and, server-only, ../server/storage (r2, s3).
4
+ */
5
+ export { copy } from "./engine";
6
+ export { sweepUploads } from "./sweep";
7
+ export type { SweepOptions, SweepResult } from "./sweep";
8
+ export { directSteps, memoSteps } from "./steps";
9
+ export type { MemoStore } from "./steps";
10
+ export { CopyError, isCopyError, toCopyError, classifyStorage, nonRetriable } from "./errors";
11
+ export type { AlertKind, CopyErrorCode, CopyErrorInit } from "./errors";
12
+ export { nodeCopyHasher, tap, collect, streamOf, combineCrcs, compositeEtag as compositeEtagOfMd5s, crcB64, crcHexFromB64, bare as bareEtagOf, } from "./checksums";
13
+ export type { CopyHasher, Digest, Tapped } from "./checksums";
14
+ export { META } from "./types";
15
+ export type { CopyOptions, CopyExpect, CopyResult, CopyState, CopyEvent, CopySource, CopyDestination, DestCapabilities, DestInfo, SourceInfo, ReadRange, PartBody, PartAnswer, WriteOptions, UploadInfo, Completed, StepRunner, RetryPolicy, } from "./types";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Step runners. A copy is a sequence of named steps (check, create, part-N, complete); each step's result is what a
3
+ * rerun needs to skip it. Inngest's `step` is one runner (results memoized by Inngest per run, a Worker restart
4
+ * resumes at the next step). In-process, `memoSteps` keeps the same results in a KeyValueStore, so a process killed
5
+ * mid-copy resumes at the next part on its next run with the same run id and never re-sends finished parts.
6
+ *
7
+ * Results are kept under an epoch: `copy:<runId>:e<epoch>:<stepId>`. A finished run bumps the epoch (one write), so
8
+ * the next copy with the same run id starts from nothing even if deleting the old results failed half-way: old
9
+ * results can never be mixed into a new copy (a fresh check with an old part or PUT result).
10
+ */
11
+ import type { StepRunner } from "./types";
12
+ /** No memo: every step runs (a rerun starts over, apart from what the destination itself lets it resume). */
13
+ export declare const directSteps: StepRunner;
14
+ export interface MemoStore {
15
+ get(k: string): Promise<string | null>;
16
+ set(k: string, v: string, o?: {
17
+ ttlMs?: number;
18
+ }): Promise<unknown>;
19
+ del(k: string): Promise<void>;
20
+ }
21
+ export interface MemoSteps extends StepRunner {
22
+ /** The run is over: bump the epoch (throws if the store can't be written), then drop the results (best effort). */
23
+ finish(): Promise<void>;
24
+ }
25
+ /** Steps memoized under `copy:<runId>:e<epoch>:<stepId>` (JSON). `ttlMs` default 7 days. */
26
+ export declare function memoSteps(store: MemoStore, runId: string, o?: {
27
+ ttlMs?: number;
28
+ }): MemoSteps;
@@ -0,0 +1,24 @@
1
+ import type { CopyDestination, UploadInfo } from "./types";
2
+ export interface SweepOptions {
3
+ to: CopyDestination;
4
+ prefix?: string;
5
+ olderThanMs?: number;
6
+ now?: () => number;
7
+ /**
8
+ * Abort uploads whose start time storage doesn't report (R2's ListMultipartUploads through the SDK client) too.
9
+ * Default false: an undated upload may be someone's upload in progress (a client sending to the same bucket).
10
+ */
11
+ includeUndated?: boolean;
12
+ /** Keep an upload anyway (e.g. one a copy in progress has saved). */
13
+ keep?: (u: UploadInfo) => boolean;
14
+ }
15
+ export interface SweepResult {
16
+ found: number;
17
+ aborted: UploadInfo[];
18
+ kept: UploadInfo[];
19
+ failed: {
20
+ upload: UploadInfo;
21
+ error: string;
22
+ }[];
23
+ }
24
+ export declare function sweepUploads(o: SweepOptions): Promise<SweepResult>;
@@ -0,0 +1,336 @@
1
+ /**
2
+ * The two ends of a copy (storage modules) and the copy's options and result. Upload (local → presigned/R2),
3
+ * download (presigned/R2 → local) and replication (R2 → S3) are the same engine with other modules (RFC §2).
4
+ *
5
+ * A module speaks in bare, lowercase ETags and hex checksums; it maps its storage's errors to CopyErrors
6
+ * (errors.ts `classifyStorage`) so the engine retries, restarts or alerts the same way whatever the storage is.
7
+ */
8
+ import type { CopyHasher } from "./checksums";
9
+ import type { AlertKind, CopyError } from "./errors";
10
+ /** One version of a source object. */
11
+ export interface SourceInfo {
12
+ key: string;
13
+ size: number;
14
+ /** Bare, lowercase. A local file's is a stamp of device/inode/size/mtime (`stamp:` prefix), not a content hash. */
15
+ etag: string;
16
+ versionId?: string;
17
+ /** When this version was written (ms since epoch). */
18
+ lastModified?: number;
19
+ contentType?: string;
20
+ /** Whole-object checksums storage knows for this version (hex). */
21
+ checksums?: {
22
+ crc32?: string;
23
+ md5?: string;
24
+ sha256?: string;
25
+ };
26
+ /**
27
+ * The part size this object was uploaded with, when known: a copy cut the same way can check its composite ETag
28
+ * (md5 of the part MD5s) against the source's.
29
+ */
30
+ partSize?: number;
31
+ /**
32
+ * Bytes read from this source ARE the truth (a local file, read under a stamp check before and after each part):
33
+ * a copy whose stored checksum matches what was read is verified.
34
+ */
35
+ authoritative?: boolean;
36
+ }
37
+ export interface ReadRange {
38
+ offset: number;
39
+ length: number;
40
+ /** Only while the object still has this ETag; otherwise the module throws CopyError "SourceChanged". */
41
+ ifEtag: string;
42
+ versionId?: string;
43
+ signal?: AbortSignal;
44
+ }
45
+ export interface CopySource {
46
+ /** "r2", "s3", "local", "presigned", "browserFile", "memory". */
47
+ readonly kind: string;
48
+ /** Which storage exactly (bucket, endpoint, path, version): part of the copy's identity for saved steps. */
49
+ readonly id?: string;
50
+ /** null: no such object. Throws (SourceUnavailable…) when the source can't be reached. */
51
+ head(key: string): Promise<SourceInfo | null>;
52
+ /** Exactly `length` bytes from `offset`, streamed. Throws SourceChanged / SourceGone / SourceUnavailable. */
53
+ read(key: string, range: ReadRange): Promise<ReadableStream<Uint8Array>>;
54
+ }
55
+ /** What a destination holds at a key. */
56
+ export interface DestInfo {
57
+ size: number;
58
+ etag: string;
59
+ /** User metadata (x-amz-meta-* / customMetadata), keys lowercase. */
60
+ meta: Record<string, string>;
61
+ /** Full-object CRC-32 (hex) when storage keeps one. */
62
+ crc32?: string;
63
+ checksumType?: string;
64
+ versionId?: string;
65
+ storageClass?: string;
66
+ /** When this version was written (ms). */
67
+ lastModified?: number;
68
+ /** Object Lock on this version: mode and retain-until (ms), legal hold. */
69
+ lockMode?: string;
70
+ lockUntil?: number;
71
+ legalHold?: boolean;
72
+ }
73
+ export interface DestCapabilities {
74
+ minPart: number;
75
+ maxPart: number;
76
+ maxParts: number;
77
+ /** Largest single PUT. */
78
+ maxPut: number;
79
+ /** Part answers carry the CRC-32 storage computed from what arrived. */
80
+ partCrc32: boolean;
81
+ /** Part ETags are the MD5 of the part (R2; S3 without SSE-KMS/SSE-C), and the object ETag md5(part MD5s)-N. */
82
+ md5Etags: boolean;
83
+ /** complete() answers the full-object CRC-32 storage combined. */
84
+ fullObjectCrc32: boolean;
85
+ /** HEAD answers the metadata written (default true; the presigned transfer protocol carries none). */
86
+ metadata?: boolean;
87
+ /** The destination buffers each part (Content-MD5 first): parts are capped by memory, not only by storage. */
88
+ buffersParts?: boolean;
89
+ /** The part size this destination prefers for an object of `size` (e.g. the upload engine's partSizeFor). */
90
+ preferredPartSize?(size: number): number;
91
+ }
92
+ /** A part (or whole object) on its way: exactly `size` bytes. */
93
+ export interface PartBody {
94
+ size: number;
95
+ /** Where the bytes sit in the object (a file destination writes there). */
96
+ offset: number;
97
+ stream: ReadableStream<Uint8Array>;
98
+ hasher: CopyHasher;
99
+ signal?: AbortSignal;
100
+ }
101
+ export interface PartAnswer {
102
+ n: number;
103
+ /** Bare, lowercase. */
104
+ etag: string;
105
+ size: number;
106
+ /** Hex, when storage computed one. */
107
+ crc32?: string;
108
+ }
109
+ export interface WriteOptions {
110
+ contentType?: string;
111
+ /** The whole object's size (a presigned route may need it to enforce plans). */
112
+ size?: number;
113
+ /** User metadata to store with the object (lowercase keys). */
114
+ meta: Record<string, string>;
115
+ /** publish(): the CRC-32 (hex) the staged object must still have. */
116
+ crc32?: string;
117
+ }
118
+ export interface UploadInfo {
119
+ key: string;
120
+ uploadId: string;
121
+ /** ms since epoch. */
122
+ initiated?: number;
123
+ storageClass?: string;
124
+ checksumAlgorithm?: string;
125
+ checksumType?: string;
126
+ }
127
+ export interface Completed {
128
+ etag?: string;
129
+ /** Full-object CRC-32 (hex) when storage combined one. */
130
+ crc32?: string;
131
+ checksumType?: string;
132
+ versionId?: string;
133
+ size?: number;
134
+ /**
135
+ * A staging destination (a local file) answers a token instead of publishing: the engine publishes it with
136
+ * `publish()` only once the copy is proven (or reported unverified), and `discard()`s it otherwise, so a failed copy
137
+ * never replaces what was there.
138
+ */
139
+ staged?: string;
140
+ }
141
+ export interface CopyDestination {
142
+ readonly kind: string;
143
+ /** Which storage exactly, with the write settings (bucket, storage class, lock): part of the copy's identity. */
144
+ readonly id?: string;
145
+ readonly caps: DestCapabilities;
146
+ head(key: string): Promise<DestInfo | null>;
147
+ create(key: string, o: WriteOptions): Promise<string>;
148
+ uploadPart(key: string, uploadId: string, n: number, body: PartBody): Promise<PartAnswer>;
149
+ /** The parts storage holds (every page). Throws NoSuchUpload. */
150
+ listParts(key: string, uploadId: string): Promise<PartAnswer[]>;
151
+ complete(key: string, uploadId: string, parts: PartAnswer[]): Promise<Completed>;
152
+ /** One PUT of a whole (small) object. */
153
+ put(key: string, body: PartBody, o: WriteOptions): Promise<Completed>;
154
+ /** Abort an unfinished upload (sweeps). Absent: unfinished uploads are left to a lifecycle rule. */
155
+ abort?(key: string, uploadId: string): Promise<void>;
156
+ /** Unfinished uploads whose key starts with `prefix`. */
157
+ listUploads?(prefix: string): Promise<UploadInfo[]>;
158
+ /** May a copy resume this unfinished upload (made with the same storage class, checksums, lock)? Default yes. */
159
+ reusable?(u: UploadInfo): boolean;
160
+ /** Is an existing object made the way this destination writes (class, checksum type, lock)? Default yes. */
161
+ conforms?(have: DestInfo): boolean;
162
+ /** Publish a staged write (see Completed.staged). */
163
+ publish?(key: string, staged: string, o: WriteOptions): Promise<void>;
164
+ /** Drop a staged write. */
165
+ discard?(key: string, staged: string): Promise<void>;
166
+ }
167
+ /** Runs one named, retryable step. Inngest's `step` fits; in-process the engine memoizes in a KeyValueStore. */
168
+ export interface StepRunner {
169
+ run<T>(id: string, fn: () => Promise<T>): Promise<T>;
170
+ }
171
+ export interface RetryPolicy {
172
+ /** Tries per call before the step fails (default 6), for errors other than unavailability (those use the budget). */
173
+ attempts?: number;
174
+ /** First backoff (default 500 ms), doubled each try, with jitter. */
175
+ baseMs?: number;
176
+ /** Longest single wait (default 30 s). */
177
+ maxMs?: number;
178
+ /**
179
+ * Longest one call keeps retrying a source that can't be reached / a throttling or failing storage (default 2 min).
180
+ * Past it the step fails with alert "source" / "storage" (retryable: the queue runs it again later).
181
+ */
182
+ budgetMs?: number;
183
+ }
184
+ export interface CopyEvent {
185
+ type: "check" | "skip" | "create" | "resume" | "part" | "partRetry" | "partReused" | "complete" | "restart" | "replaced" | "recopy" | "salvage" | "verified" | "unverified" | "alert" | "retry";
186
+ key: string;
187
+ toKey: string;
188
+ n?: number;
189
+ attempt?: number;
190
+ code?: string;
191
+ alert?: AlertKind;
192
+ detail?: Record<string, unknown>;
193
+ }
194
+ /** Metadata keys a copy writes (the backup worker's names: identical outputs, RFC §6.4). */
195
+ export declare const META: {
196
+ readonly sourceEtag: "source-etag";
197
+ readonly expectedCrc32: "expected-crc32";
198
+ readonly verify: "verify";
199
+ readonly attempt: "attempt";
200
+ };
201
+ export interface CopyOptions {
202
+ from: CopySource;
203
+ to: CopyDestination;
204
+ /** The source key. */
205
+ key: string;
206
+ /** The destination key (default: `key`). */
207
+ toKey?: string;
208
+ /** Default: the source's, else application/octet-stream. */
209
+ contentType?: string;
210
+ /** Extra metadata stored with the copy (e.g. project-id). Lowercase keys; `source-etag` etc. are set by the engine. */
211
+ meta?: Record<string, string>;
212
+ /**
213
+ * What the caller knows about the source (e.g. the CRC-32 a client verified). Trusted only for the version whose
214
+ * ETag is `etag` (when given): a replaced source has other bytes.
215
+ */
216
+ expect?: CopyExpect | ((source: SourceInfo) => Promise<CopyExpect | undefined | null>);
217
+ /** The ETag (version) the caller means to copy: a source with another one is "replaced". */
218
+ etag?: string;
219
+ /**
220
+ * A source that is not (or no longer) the version `etag` names: "copy" the version there now (default), or "skip"
221
+ * it (state `sourceReplaced`; the new version is expected to come with its own event, e.g. an R2 notification).
222
+ * A copy stopped mid-way leaves its upload to `abandon`.
223
+ */
224
+ replaced?: "copy" | "skip";
225
+ /**
226
+ * A source replaced mid-copy whose old version is already whole in the copy's unfinished upload (every part there,
227
+ * e.g. the last part stored but its answer lost): complete that upload as the old version's copy instead of
228
+ * abandoning it (default false). Where the source keeps no old versions (R2), it may be the only copy of those
229
+ * bytes. Proven like any copy: against the old version's known checksum. Needs a destination that lists parts.
230
+ */
231
+ salvage?: boolean;
232
+ /** Part size (bytes). Default: the source's own part size when known, else the destination's preference. */
233
+ partSize?: number;
234
+ /** Most parts a copy may be cut into (e.g. ≤ 900 when every part is an Inngest step). */
235
+ maxParts?: number;
236
+ /** A source body that sends no byte for this long is a failed read, retried (default 120 s). */
237
+ idleMs?: number;
238
+ /** Parts in flight (default 4). */
239
+ concurrency?: number;
240
+ /** Parts per step (default 1). Inngest: keep total steps well under 1,000. */
241
+ partsPerStep?: number;
242
+ /** Steps (Inngest's `step`); default: in-process, memoized in `state` so a rerun with the same `runId` resumes. */
243
+ steps?: StepRunner;
244
+ /** Where in-process steps are memoized (KeyValueStore-shaped). Default: nothing kept (a rerun starts over). */
245
+ state?: {
246
+ get(k: string): Promise<string | null>;
247
+ set(k: string, v: string, o?: {
248
+ ttlMs?: number;
249
+ }): Promise<unknown>;
250
+ del(k: string): Promise<void>;
251
+ };
252
+ /** Identifies this copy's saved steps (default: from + key + to + toKey). */
253
+ runId?: string;
254
+ retry?: RetryPolicy;
255
+ /**
256
+ * What may prove a copy (default all): "crc32" (an expected or stored full-object CRC-32), "etag" (the source's
257
+ * MD5 / composite ETag), "read" (an authoritative source). The backup worker's rule is `["crc32"]`: only the
258
+ * manifest's CRC proves an original; anything else is `unverified`.
259
+ */
260
+ proofs?: ("crc32" | "etag" | "read")[];
261
+ /** An existing copy of this version counts only if this agrees (e.g. its storage class is DEEP_ARCHIVE). */
262
+ accept?: (have: DestInfo) => boolean;
263
+ /**
264
+ * A source replaced mid-copy leaves an unfinished upload: "abort" it (default) or "leave" it for the bucket's
265
+ * lifecycle rule (a writer key without abort permission; the backup worker never aborts).
266
+ */
267
+ abandon?: "abort" | "leave";
268
+ /** Recopy even though an earlier recopy of this version mismatched the expected CRC (send by hand once fixed). */
269
+ force?: boolean;
270
+ hasher?: CopyHasher;
271
+ onEvent?: (e: CopyEvent) => void;
272
+ signal?: AbortSignal;
273
+ /** Clock and sleep (tests compress time). */
274
+ now?: () => number;
275
+ sleep?: (ms: number) => Promise<void>;
276
+ /** Jitter source in [0, 1) (tests: deterministic). */
277
+ random?: () => number;
278
+ }
279
+ /**
280
+ * What the caller knows about the source (e.g. the CRC-32 a client verified), trusted only for the version whose ETag
281
+ * is `etag` (when given). As a function it is asked inside the copy's check step, for the version found there, so a
282
+ * read that fails (a manifest read breaking) retries the check instead of copying without the checksum.
283
+ */
284
+ export interface CopyExpect {
285
+ etag?: string;
286
+ size?: number;
287
+ crc32?: string;
288
+ }
289
+ export type CopyState = "verified" | "unverified" | "alreadyCopied" | "sourceGone" | "sourceReplaced";
290
+ export interface CopyResult {
291
+ state: CopyState;
292
+ key: string;
293
+ toKey: string;
294
+ /** The source version copied (bare ETag). */
295
+ sourceEtag?: string;
296
+ size?: number;
297
+ /** Full-object CRC-32 of what was stored (hex). */
298
+ crc32?: string;
299
+ etag?: string;
300
+ versionId?: string;
301
+ /** alreadyCopied: whether the existing copy matched a known source checksum. Not verified = not proven. */
302
+ verified?: boolean;
303
+ /** unverified / alreadyCopied without proof / sourceReplaced: why. */
304
+ reason?: string;
305
+ /** How it was checked: "crc32" (expected CRC), "etag" (composite/MD5 ETag), "read" (authoritative source). */
306
+ checkedBy?: "crc32" | "etag" | "read";
307
+ parts?: number;
308
+ /** Parts already in storage that were reused (resume). */
309
+ reused?: number;
310
+ /** Times the upload was started again (NoSuchUpload, a foreign upload). */
311
+ restarts?: number;
312
+ /** The source was replaced during the copy; this result is for the new version. */
313
+ replaced?: boolean;
314
+ /** A full recopy happened after a stored-checksum mismatch. */
315
+ recopied?: boolean;
316
+ /**
317
+ * This run's first copy did not match (its CRC, what it was expected to be, why); the result is the recopy's. A
318
+ * caller may still treat the run as a failure: the bytes moved first were not the ones the source is known to be.
319
+ */
320
+ mismatch?: {
321
+ crc32?: string;
322
+ expected?: string;
323
+ reason: string;
324
+ };
325
+ /** The copy continued an unfinished upload (multipart) it found at the destination. */
326
+ resumed?: boolean;
327
+ /** `salvage`: the source was replaced mid-copy, and this is its old version's copy, completed from the upload. */
328
+ salvaged?: boolean;
329
+ /**
330
+ * The part size this copy's upload was cut with (bytes; the whole size for a single PUT). Recorded with the upload
331
+ * in its create step: a run resumed later (another deploy, other defaults) keeps cutting the same way.
332
+ */
333
+ partSize?: number;
334
+ }
335
+ /** A copy that could not finish: retry later (retryable) or someone must act (alert). */
336
+ export type CopyFailure = CopyError;
@@ -0,0 +1,2 @@
1
+ /*! @uploadfilm/sdk embed control API v1 | src 2e752049dda6c73e */
2
+ !function(){"use strict";var t="uploadfilm",e=function(){function e(t){this.ready=!1,this.state={currentTime:0,duration:0,paused:!0,muted:!0},this._queue=[],this._handlers={},this._doc=null,this._stale=null,this._readyDoc=null,this._init(t,"undefined"!=typeof window?window:"undefined"!=typeof self?self:globalThis)}return e.prototype._init=function(e,n){if(!e||!e.contentWindow)throw new Error("UploadFilm.Player needs an <iframe> of an UploadFilm embed");this.ready=!1,this.state={currentTime:0,duration:0,paused:!0,muted:!0},this._queue=[],this._handlers={},this._doc=null,this._stale=null,this._readyDoc=null;var i=this;if(this.iframe=e,this._root=n,this._onMessage=function(n){if(n.source===e.contentWindow){var o=n.data;if(o&&o.source===t&&"string"==typeof o.event&&(!o.doc||o.doc!==i._stale))if(i._doc=o.doc||null,i.state={currentTime:o.currentTime,duration:o.duration,paused:o.paused,muted:o.muted},!1!==o.playable){if(!i.ready){i.ready=!0;var s=i._queue;i._queue=[];for(var r=0;r<s.length;r++)i._send(s[r])}i._readyDoc===i._doc&&i._doc||(i._readyDoc=i._doc,i._emit("ready")),"ready"!==o.event&&"state"!==o.event&&i._emit(o.event)}else i.ready=!1}},n.addEventListener("message",this._onMessage),this._send({action:"state"}),this._onLoad=function(){i.ready=!1,i._send({action:"state"})},e.addEventListener("load",this._onLoad),"function"==typeof MutationObserver){var o=new MutationObserver(function(){i._stale=i._doc,i.ready=!1});o.observe(e,{attributes:!0,attributeFilter:["src"]}),this._observer=o}},e.prototype._send=function(e){e.source=t,this.iframe.contentWindow&&this.iframe.contentWindow.postMessage(e,"*")},e.prototype._command=function(t){return this.ready?this._send(t):this._queue.push(t),this},e.prototype._emit=function(t){for(var e=this._handlers[t]||[],n=0;n<e.length;n++)try{e[n].call(this,this.state)}catch(t){setTimeout(function(){throw t})}},e.prototype.play=function(){return this._command({action:"play"})},e.prototype.pause=function(){return this._command({action:"pause"})},e.prototype.mute=function(){return this._command({action:"mute"})},e.prototype.unmute=function(){return this._command({action:"unmute"})},e.prototype.seek=function(t){return this._command({action:"seek",time:Math.max(0,Number(t)||0)})},e.prototype.on=function(t,e){return(this._handlers[t]=this._handlers[t]||[]).push(e),this},e.prototype.off=function(t,e){return this._handlers[t]=(this._handlers[t]||[]).filter(function(t){return t!==e}),this},e.prototype.destroy=function(){this._root.removeEventListener("message",this._onMessage),this.iframe.removeEventListener("load",this._onLoad),this._observer&&this._observer.disconnect(),this._handlers={},this._queue=[]},e}(),n="undefined"!=typeof window?window:globalThis;function i(t){if(!(this instanceof i))return new i(t);this._init(t,n)}i.prototype=e.prototype,n.UploadFilm=n.UploadFilm||{},n.UploadFilm.Player=i}();
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Plugging decisions into the transfer engine and a media runner. Structural types only: nothing here imports the
3
+ * engine or the runner, so either side can adopt the tuner without a dependency cycle.
4
+ */
5
+ import { type TuneDecision } from "./policy";
6
+ import type { PowerMonitorLike } from "./detect";
7
+ import type { HwApi } from "./types";
8
+ import type { Tuner } from "./tuner";
9
+ /** `EngineCoreOptions.connections` from a decision. */
10
+ export declare const engineConnections: (d: TuneDecision) => {
11
+ min: number;
12
+ max: number;
13
+ start: number;
14
+ };
15
+ /** A lane as the engine takes it (LaneSpec). */
16
+ export interface LaneLike {
17
+ name: string;
18
+ first?: boolean;
19
+ minShare?: number;
20
+ yieldable?: boolean;
21
+ maxActive?: number;
22
+ }
23
+ /**
24
+ * The lanes with the primary lane's share raised to the decision's (never below ⅔). A product whose lanes have no
25
+ * primary gets them back unchanged.
26
+ */
27
+ export declare function withOriginalsShare<L extends LaneLike>(lanes: readonly L[], d: TuneDecision): L[];
28
+ /**
29
+ * Part size for a multipart created now: the engine's own floor for the object (16 MiB, or more so it fits in 9,500
30
+ * parts) or the decision's rounded up to a power-of-two MiB, whichever is bigger. Only for new multiparts: a saved one keeps the part size it started
31
+ * with (its parts are already in storage).
32
+ */
33
+ export declare function partSizeFor(size: number, d: TuneDecision): number;
34
+ /**
35
+ * Connections for parts of `partSize` bytes so that in-flight parts stay within `d.inflightBytes`: an object too big
36
+ * for 9,500 × d.partSize, or a resumed multipart that started with bigger parts. The budget wins over `min`; but never
37
+ * 0: one part at a time even when a single part is over budget, so an upload always moves (a stalled one would be a
38
+ * share that never updates).
39
+ */
40
+ export declare function connectionsForPart(d: TuneDecision, partSize: number): number;
41
+ /**
42
+ * What an engine needs to take live decisions: the SDK transfer engine's core (`createEngineCore`, or
43
+ * `createTransferEngine(...).core`) has all of it. Every member is optional, so an engine with fewer knobs still binds.
44
+ */
45
+ export interface TunableEngine {
46
+ setConnectionLimits?(l: {
47
+ min: number;
48
+ max: number;
49
+ start?: number;
50
+ }): void;
51
+ /** Part size for multiparts created from now on (null: the engine's own rule). */
52
+ setPartSizeHook?(fn: ((size: number) => number) | null): void;
53
+ /** Cap on buffered bytes in flight (null: none). */
54
+ setInflightBytes?(n: number | null): void;
55
+ /** Called with the engine's measured rate for passive throughput. */
56
+ readonly rate?: number;
57
+ readonly connections?: number;
58
+ }
59
+ /**
60
+ * Feed a tuner's decisions to an engine: connection bounds and the in-flight byte cap on every decision, and a part-size
61
+ * hook that reads the decision current when a multipart is created (multiparts already created keep their parts). The
62
+ * engine's rate goes back to the tuner every `sampleMs`. → unbind: decisions stop, and the engine's part-size rule and
63
+ * byte cap go back to its defaults (its connection bounds stay where the last decision left them).
64
+ */
65
+ export declare function bindEngine(tuner: Tuner, engine: TunableEngine, o?: {
66
+ sampleMs?: number;
67
+ }): () => void;
68
+ export interface RunnerSettings {
69
+ /** Clips (jobs) at once; 0 = start no new ones now. */
70
+ concurrency: number;
71
+ /** ffmpeg -threads per job. */
72
+ threads: number;
73
+ /** setpriority for the ffmpeg child. */
74
+ nice: number;
75
+ encoder: string | null;
76
+ api: HwApi | null;
77
+ }
78
+ export declare const runnerSettings: (d: TuneDecision) => RunnerSettings;
79
+ export interface VideoEncodeArgs {
80
+ /** Before -i (device setup, decode threads). */
81
+ input: string[];
82
+ /** Appended to the video filter chain ("format=nv12,hwupload" for VAAPI/QSV), "" when none. */
83
+ filterSuffix: string;
84
+ /** The encoder and its rate control. */
85
+ output: string[];
86
+ }
87
+ /**
88
+ * ffmpeg arguments to encode with the decision's encoder at a target bitrate. Decode stays on the CPU (the caller adds
89
+ * -hwaccel itself when its format allows: UploadFilm's proxy policy decodes 10-bit 4:2:2 in software).
90
+ */
91
+ export declare function videoEncodeArgs(e: {
92
+ encoder: string | null;
93
+ api: HwApi | null;
94
+ threads: number;
95
+ }, o: {
96
+ bitrateK: number;
97
+ maxrateK?: number;
98
+ bufsizeK?: number;
99
+ renderDevice?: string;
100
+ }): VideoEncodeArgs | null;
101
+ /** Electron powerMonitor with events. */
102
+ export interface PowerMonitorEvents extends PowerMonitorLike {
103
+ on(event: string, fn: () => void): unknown;
104
+ removeListener(event: string, fn: () => void): unknown;
105
+ }
106
+ /** Re-evaluate as soon as power or thermal state changes (instead of at the next interval). → stop. */
107
+ export declare function watchPowerMonitor(pm: PowerMonitorEvents, tuner: Tuner): () => void;