@dimah-s3/server 1.7.1 → 2.0.0-beta.1
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 +72 -16
- package/dist/adapters/express.d.ts +7 -7
- package/dist/adapters/express.d.ts.map +1 -1
- package/dist/adapters/express.js +94 -94
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/fastify.d.ts +11 -5
- package/dist/adapters/fastify.d.ts.map +1 -1
- package/dist/adapters/fastify.js +94 -94
- package/dist/adapters/fastify.js.map +1 -1
- package/dist/adapters/node.d.ts +20 -3
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +92 -92
- package/dist/adapters/node.js.map +1 -1
- package/dist/api/context.d.ts +8 -4
- package/dist/api/context.d.ts.map +1 -1
- package/dist/api/{routes/index.d.ts → core-endpoints.d.ts} +43 -68
- package/dist/api/core-endpoints.d.ts.map +1 -0
- package/dist/api/create-s3-endpoint.d.ts +70 -48
- package/dist/api/create-s3-endpoint.d.ts.map +1 -1
- package/dist/api/create-s3-middleware.d.ts +19 -16
- package/dist/api/create-s3-middleware.d.ts.map +1 -1
- package/dist/api/router-context.d.ts +23 -0
- package/dist/api/router-context.d.ts.map +1 -0
- package/dist/api/router.d.ts +15 -5
- package/dist/api/router.d.ts.map +1 -1
- package/dist/config/feature-toggle.d.ts +16 -0
- package/dist/config/feature-toggle.d.ts.map +1 -0
- package/dist/config/resolve-config.d.ts +9 -0
- package/dist/config/resolve-config.d.ts.map +1 -0
- package/dist/config/resolve-routes.d.ts +37 -0
- package/dist/config/resolve-routes.d.ts.map +1 -0
- package/dist/dimah-s3.d.ts +22 -32
- package/dist/dimah-s3.d.ts.map +1 -1
- package/dist/helpers/authorize-download.d.ts +25 -0
- package/dist/helpers/authorize-download.d.ts.map +1 -0
- package/dist/helpers/aws-errors.d.ts +16 -0
- package/dist/helpers/aws-errors.d.ts.map +1 -0
- package/dist/helpers/best-effort.d.ts +22 -3
- package/dist/helpers/best-effort.d.ts.map +1 -1
- package/dist/helpers/checksum-config.d.ts +13 -0
- package/dist/helpers/checksum-config.d.ts.map +1 -0
- package/dist/helpers/constraints.d.ts +17 -12
- package/dist/helpers/constraints.d.ts.map +1 -1
- package/dist/helpers/error-boundary.d.ts +28 -0
- package/dist/helpers/error-boundary.d.ts.map +1 -0
- package/dist/helpers/finalize-confirmed.d.ts +42 -13
- package/dist/helpers/finalize-confirmed.d.ts.map +1 -1
- package/dist/helpers/head-object.d.ts +6 -9
- package/dist/helpers/head-object.d.ts.map +1 -1
- package/dist/helpers/hooks.d.ts +29 -15
- package/dist/helpers/hooks.d.ts.map +1 -1
- package/dist/helpers/inline-types.d.ts +24 -7
- package/dist/helpers/inline-types.d.ts.map +1 -1
- package/dist/helpers/list-parts.d.ts +4 -6
- package/dist/helpers/list-parts.d.ts.map +1 -1
- package/dist/helpers/metadata-encoding.d.ts +15 -0
- package/dist/helpers/metadata-encoding.d.ts.map +1 -0
- package/dist/helpers/object-meta.d.ts +39 -0
- package/dist/helpers/object-meta.d.ts.map +1 -0
- package/dist/helpers/object-s3.d.ts +5 -2
- package/dist/helpers/object-s3.d.ts.map +1 -1
- package/dist/helpers/open-target.d.ts +89 -0
- package/dist/helpers/open-target.d.ts.map +1 -0
- package/dist/helpers/part-layout.d.ts +19 -0
- package/dist/helpers/part-layout.d.ts.map +1 -0
- package/dist/helpers/presign.d.ts +54 -0
- package/dist/helpers/presign.d.ts.map +1 -0
- package/dist/helpers/request.d.ts +6 -11
- package/dist/helpers/request.d.ts.map +1 -1
- package/dist/helpers/resolve-target.d.ts +28 -20
- package/dist/helpers/resolve-target.d.ts.map +1 -1
- package/dist/helpers/sniff-object.d.ts +22 -0
- package/dist/helpers/sniff-object.d.ts.map +1 -0
- package/dist/helpers/ticket.d.ts +75 -0
- package/dist/helpers/ticket.d.ts.map +1 -0
- package/dist/index.d.ts +4 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2647 -1579
- package/dist/index.js.map +1 -1
- package/dist/operations/catalog.d.ts +16 -0
- package/dist/operations/catalog.d.ts.map +1 -0
- package/dist/operations/confirm.d.ts +19 -0
- package/dist/operations/confirm.d.ts.map +1 -0
- package/dist/operations/delete-many.d.ts +18 -0
- package/dist/operations/delete-many.d.ts.map +1 -0
- package/dist/operations/delete.d.ts +14 -0
- package/dist/operations/delete.d.ts.map +1 -0
- package/dist/operations/download.d.ts +20 -0
- package/dist/operations/download.d.ts.map +1 -0
- package/dist/operations/file.d.ts +38 -0
- package/dist/operations/file.d.ts.map +1 -0
- package/dist/operations/multipart/abort.d.ts +20 -0
- package/dist/operations/multipart/abort.d.ts.map +1 -0
- package/dist/operations/multipart/complete.d.ts +21 -0
- package/dist/operations/multipart/complete.d.ts.map +1 -0
- package/dist/operations/multipart/init.d.ts +19 -0
- package/dist/operations/multipart/init.d.ts.map +1 -0
- package/dist/operations/multipart/list-parts.d.ts +11 -0
- package/dist/operations/multipart/list-parts.d.ts.map +1 -0
- package/dist/operations/multipart/open-multipart.d.ts +25 -0
- package/dist/operations/multipart/open-multipart.d.ts.map +1 -0
- package/dist/operations/multipart/sign-part.d.ts +20 -0
- package/dist/operations/multipart/sign-part.d.ts.map +1 -0
- package/dist/operations/put.d.ts +18 -0
- package/dist/operations/put.d.ts.map +1 -0
- package/dist/operations/run-operation.d.ts +18 -0
- package/dist/operations/run-operation.d.ts.map +1 -0
- package/dist/operations/s3-api.d.ts +12 -0
- package/dist/operations/s3-api.d.ts.map +1 -0
- package/dist/operations/upload.d.ts +19 -0
- package/dist/operations/upload.d.ts.map +1 -0
- package/dist/plugin/apply-plugins.d.ts +9 -11
- package/dist/plugin/apply-plugins.d.ts.map +1 -1
- package/dist/plugin/chain-hooks.d.ts +12 -9
- package/dist/plugin/chain-hooks.d.ts.map +1 -1
- package/dist/plugin/define-plugin.d.ts +11 -4
- package/dist/plugin/define-plugin.d.ts.map +1 -1
- package/dist/plugin/index.d.ts +1 -2
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +52 -56
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugins.d.ts +10 -8
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +325 -1627
- package/dist/plugins.js.map +1 -1
- package/dist/route.d.ts +0 -1
- package/dist/route.d.ts.map +1 -1
- package/dist/types/config.d.ts +171 -172
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/hook-contexts.d.ts +139 -147
- package/dist/types/hook-contexts.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/locals.d.ts +37 -0
- package/dist/types/locals.d.ts.map +1 -0
- package/dist/types/resolved.d.ts +118 -0
- package/dist/types/resolved.d.ts.map +1 -0
- package/package.json +8 -12
- package/dist/api/bind-endpoints.d.ts +0 -12
- package/dist/api/bind-endpoints.d.ts.map +0 -1
- package/dist/api/index.d.ts +0 -6
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -1353
- package/dist/api/index.js.map +0 -1
- package/dist/api/routes/catalog.d.ts +0 -9
- package/dist/api/routes/catalog.d.ts.map +0 -1
- package/dist/api/routes/confirm.d.ts +0 -13
- package/dist/api/routes/confirm.d.ts.map +0 -1
- package/dist/api/routes/delete-batch.d.ts +0 -14
- package/dist/api/routes/delete-batch.d.ts.map +0 -1
- package/dist/api/routes/delete.d.ts +0 -26
- package/dist/api/routes/delete.d.ts.map +0 -1
- package/dist/api/routes/download.d.ts +0 -21
- package/dist/api/routes/download.d.ts.map +0 -1
- package/dist/api/routes/file.d.ts +0 -20
- package/dist/api/routes/file.d.ts.map +0 -1
- package/dist/api/routes/index.d.ts.map +0 -1
- package/dist/api/routes/multipart/abort.d.ts +0 -16
- package/dist/api/routes/multipart/abort.d.ts.map +0 -1
- package/dist/api/routes/multipart/complete.d.ts +0 -22
- package/dist/api/routes/multipart/complete.d.ts.map +0 -1
- package/dist/api/routes/multipart/init.d.ts +0 -22
- package/dist/api/routes/multipart/init.d.ts.map +0 -1
- package/dist/api/routes/multipart/list-parts.d.ts +0 -17
- package/dist/api/routes/multipart/list-parts.d.ts.map +0 -1
- package/dist/api/routes/multipart/part.d.ts +0 -20
- package/dist/api/routes/multipart/part.d.ts.map +0 -1
- package/dist/api/routes/upload.d.ts +0 -22
- package/dist/api/routes/upload.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -23
- package/dist/errors.d.ts.map +0 -1
- package/dist/helpers/expires.d.ts +0 -21
- package/dist/helpers/expires.d.ts.map +0 -1
- package/dist/helpers/features.d.ts +0 -17
- package/dist/helpers/features.d.ts.map +0 -1
- package/dist/helpers/index.d.ts +0 -19
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/is-aws-not-found.d.ts +0 -5
- package/dist/helpers/is-aws-not-found.d.ts.map +0 -1
- package/dist/helpers/previous-key.d.ts +0 -5
- package/dist/helpers/previous-key.d.ts.map +0 -1
- package/dist/helpers/resolve-route.d.ts +0 -33
- package/dist/helpers/resolve-route.d.ts.map +0 -1
- package/dist/plugin/hook-registry.d.ts +0 -21
- package/dist/plugin/hook-registry.d.ts.map +0 -1
- package/dist/put.d.ts +0 -15
- package/dist/put.d.ts.map +0 -1
package/dist/dimah-s3.d.ts
CHANGED
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
import { S3_ERROR_CODES, type ConfirmedObjectResponse } from "@dimah-s3/core";
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export type MultipartAliasApi = {
|
|
7
|
-
init: CoreEndpoints["multipartInit"];
|
|
8
|
-
signPart: CoreEndpoints["multipartPart"];
|
|
9
|
-
listParts: CoreEndpoints["multipartListParts"];
|
|
10
|
-
complete: CoreEndpoints["multipartComplete"];
|
|
11
|
-
abort: CoreEndpoints["multipartAbort"];
|
|
12
|
-
};
|
|
13
|
-
export type DimahS3Api<P extends readonly DimahS3Plugin[] = []> = CoreEndpoints & {
|
|
14
|
-
multipart: MultipartAliasApi;
|
|
15
|
-
deleteMany: CoreEndpoints["deleteBatch"];
|
|
16
|
-
} & PluginEndpointMap<P>;
|
|
17
|
-
export type DimahS3<P extends readonly DimahS3Plugin[] = [], C extends Record<string, unknown> = PluginContextMap<P>, R extends Record<string, DimahS3RouteConfig> = Record<string, DimahS3RouteConfig>> = {
|
|
2
|
+
import { type DimahS3Plugin, type PluginContextMap } from "./plugin/index.js";
|
|
3
|
+
import type { DimahS3Api, DimahS3Config, DimahS3RouteConfig, PutInput, S3ServerCallOptions } from "./types/config.js";
|
|
4
|
+
/** A dimah-s3 server instance, returned by {@link dimahS3}. */
|
|
5
|
+
export type DimahS3<P extends readonly DimahS3Plugin[] = [], C = PluginContextMap<P>, R extends Record<string, DimahS3RouteConfig> = Record<string, DimahS3RouteConfig>> = {
|
|
18
6
|
/** Framework-agnostic HTTP handler (`Request` → `Response`). */
|
|
19
7
|
handler: (request: Request) => Promise<Response>;
|
|
20
8
|
/**
|
|
21
|
-
*
|
|
9
|
+
* The browser client's API, run in process. Pass `request` or `headers`
|
|
10
|
+
* for the hooks, and trusted `locals` to seed the guards.
|
|
22
11
|
*
|
|
23
12
|
* ```ts
|
|
24
|
-
* await s3.api.download({
|
|
25
|
-
* await s3.api.multipart.init({ body: { route, fileName, fileSize } });
|
|
13
|
+
* await s3.api.download({ route: "invoices", key }, { headers: await headers() });
|
|
26
14
|
* ```
|
|
27
15
|
*/
|
|
28
|
-
api: DimahS3Api
|
|
16
|
+
api: DimahS3Api;
|
|
17
|
+
/** Uploads from the server through the route's upload policy. */
|
|
18
|
+
put: (input: PutInput, options?: S3ServerCallOptions) => Promise<ConfirmedObjectResponse>;
|
|
29
19
|
/** Plugin contexts keyed by plugin id. */
|
|
30
20
|
context: C;
|
|
31
|
-
/**
|
|
21
|
+
/** Looks up a registered plugin by id. */
|
|
32
22
|
getPlugin: {
|
|
33
23
|
<Id extends P[number]["id"]>(id: Id): Extract<P[number], {
|
|
34
24
|
id: Id;
|
|
@@ -36,25 +26,25 @@ export type DimahS3<P extends readonly DimahS3Plugin[] = [], C extends Record<st
|
|
|
36
26
|
(id: string): DimahS3Plugin | undefined;
|
|
37
27
|
};
|
|
38
28
|
$ERROR_CODES: typeof S3_ERROR_CODES;
|
|
29
|
+
/** Type-only helpers: `typeof s3.$Infer.routes`. */
|
|
39
30
|
$Infer: {
|
|
40
|
-
api: DimahS3Api
|
|
31
|
+
api: DimahS3Api;
|
|
41
32
|
context: C;
|
|
42
33
|
routes: keyof R & string;
|
|
43
34
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Server-side upload through the same route policy as presign + confirm.
|
|
46
|
-
*/
|
|
47
|
-
put: (input: PutObjectInput) => Promise<ConfirmedObjectResponse>;
|
|
48
35
|
} & C;
|
|
49
36
|
/**
|
|
50
|
-
*
|
|
37
|
+
* Creates a dimah-s3 server instance.
|
|
38
|
+
*
|
|
39
|
+
* The config is checked here, so a mistake throws at startup. The ticket
|
|
40
|
+
* secret is the exception: without a `secret` option, `DIMAH_S3_SECRET` is
|
|
41
|
+
* read on the first upload.
|
|
51
42
|
*
|
|
52
|
-
* Plugin contexts are
|
|
53
|
-
*
|
|
43
|
+
* Plugin contexts are on `s3.context[id]` and on the instance itself
|
|
44
|
+
* (`s3.db` when the `db` plugin is registered).
|
|
54
45
|
*
|
|
55
46
|
* @example
|
|
56
47
|
* ```ts
|
|
57
|
-
* export const awsS3 = new S3Client({ ... });
|
|
58
48
|
* export const s3 = dimahS3({
|
|
59
49
|
* client: awsS3,
|
|
60
50
|
* bucket: "my-bucket",
|
|
@@ -64,9 +54,9 @@ export type DimahS3<P extends readonly DimahS3Plugin[] = [], C extends Record<st
|
|
|
64
54
|
* },
|
|
65
55
|
* });
|
|
66
56
|
*
|
|
67
|
-
* export const { GET, POST,
|
|
57
|
+
* export const { GET, POST, PATCH, DELETE } = toNextJsHandler(s3);
|
|
68
58
|
*
|
|
69
|
-
* await s3.api.download({
|
|
59
|
+
* await s3.api.download({ route: "invoices", key }, { headers: await headers() });
|
|
70
60
|
* ```
|
|
71
61
|
*/
|
|
72
62
|
export declare function dimahS3<const P extends readonly DimahS3Plugin[] = [], const R extends Record<string, DimahS3RouteConfig> = Record<string, DimahS3RouteConfig>>(config: DimahS3Config & {
|
package/dist/dimah-s3.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dimah-s3.d.ts","sourceRoot":"","sources":["../src/dimah-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"dimah-s3.d.ts","sourceRoot":"","sources":["../src/dimah-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAM9E,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACtB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,QAAQ,EACR,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAExB,+DAA+D;AAC/D,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,SAAS,aAAa,EAAE,GAAG,EAAE,EACvC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,EACvB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,MAAM,CACnD,MAAM,EACN,kBAAkB,CACnB,IACC;IACF,gEAAgE;IAChE,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjD;;;;;;;OAOG;IACH,GAAG,EAAE,UAAU,CAAC;IAChB,iEAAiE;IACjE,GAAG,EAAE,CACH,KAAK,EAAE,QAAQ,EACf,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,0CAA0C;IAC1C,OAAO,EAAE,CAAC,CAAC;IACX,0CAA0C;IAC1C,SAAS,EAAE;QACT,CAAC,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EACzB,EAAE,EAAE,EAAE,GACL,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE;YAAE,EAAE,EAAE,EAAE,CAAA;SAAE,CAAC,GAAG,SAAS,CAAC;QAC9C,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;KACzC,CAAC;IACF,YAAY,EAAE,OAAO,cAAc,CAAC;IACpC,oDAAoD;IACpD,MAAM,EAAE;QACN,GAAG,EAAE,UAAU,CAAC;QAChB,OAAO,EAAE,CAAC,CAAC;QACX,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;KAC1B,CAAC;CACH,GAAG,CAAC,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,CACrB,KAAK,CAAC,CAAC,SAAS,SAAS,aAAa,EAAE,GAAG,EAAE,EAC7C,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAAG,MAAM,CACzD,MAAM,EACN,kBAAkB,CACnB,EAED,MAAM,EAAE,aAAa,GAAG;IAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IAAC,MAAM,EAAE,CAAC,CAAA;CAAE,GACjD,OAAO,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAqBpC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ContentDispositionType } from "@dimah-s3/core";
|
|
2
|
+
import type { DownloadGuardContext, DownloadResolveInfo, ObjectContext } from "../types/hook-contexts.js";
|
|
3
|
+
import type { OpenedRoute, ResolvedConfig } from "../types/resolved.js";
|
|
4
|
+
/** What the client asked for: the download query or the `/file` query. */
|
|
5
|
+
export type DownloadRequest = {
|
|
6
|
+
mode: "presign" | "proxy";
|
|
7
|
+
name?: string;
|
|
8
|
+
disposition?: ContentDispositionType;
|
|
9
|
+
/** Presign mode only. */
|
|
10
|
+
expiresIn?: number;
|
|
11
|
+
};
|
|
12
|
+
export type AuthorizedDownload = {
|
|
13
|
+
/** The values that will be used, as `download.guard` saw them. */
|
|
14
|
+
context: DownloadGuardContext;
|
|
15
|
+
/** What `download.resolve` returned. */
|
|
16
|
+
resolved?: DownloadResolveInfo;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The download steps that presign and `/file` share, after the route
|
|
20
|
+
* guard: `download.resolve` can replace the name, the disposition and the
|
|
21
|
+
* TTL, and `download.guard` then runs with the values that will be used.
|
|
22
|
+
* In proxy mode the contexts have no `expiresIn`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function authorizeDownload(config: Pick<ResolvedConfig, "maxExpiresIn">, route: OpenedRoute<"download">, context: ObjectContext, request: DownloadRequest): Promise<AuthorizedDownload>;
|
|
25
|
+
//# sourceMappingURL=authorize-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorize-download.d.ts","sourceRoot":"","sources":["../../src/helpers/authorize-download.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAG7D,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEpE,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,sBAAsB,CAAC;IACrC,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kEAAkE;IAClE,OAAO,EAAE,oBAAoB,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,mBAAmB,CAAC;CAChC,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,EAC5C,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,EAC9B,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,kBAAkB,CAAC,CA+B7B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** The HTTP status S3 answered a failed call with, when there was one. */
|
|
2
|
+
export declare function awsStatus(error: unknown): number | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* The object, or the multipart upload, does not exist. A missing bucket is
|
|
5
|
+
* a 404 too, but it is a config error, so it does not count.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isAwsNotFound(error: unknown): boolean;
|
|
8
|
+
/** An `If-Match` or `If-Unmodified-Since` condition failed. */
|
|
9
|
+
export declare function isAwsPreconditionFailed(error: unknown): boolean;
|
|
10
|
+
/** The provider does not implement the request, such as a conditional delete. */
|
|
11
|
+
export declare function isAwsNotImplemented(error: unknown): boolean;
|
|
12
|
+
/** The requested byte range is outside the object. */
|
|
13
|
+
export declare function isAwsRangeNotSatisfiable(error: unknown): boolean;
|
|
14
|
+
/** Runs an S3 call and turns a not-found error into `OBJECT_NOT_FOUND`. */
|
|
15
|
+
export declare function sendOrObjectNotFound<T>(send: () => Promise<T>): Promise<T>;
|
|
16
|
+
//# sourceMappingURL=aws-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-errors.d.ts","sourceRoot":"","sources":["../../src/helpers/aws-errors.ts"],"names":[],"mappings":"AAqCA,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGrD;AAED,+DAA+D;AAC/D,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE/D;AAED,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED,sDAAsD;AACtD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEhE;AAED,2EAA2E;AAC3E,wBAAsB,oBAAoB,CAAC,CAAC,EAC1C,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CASZ"}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { type S3Client } from "@aws-sdk/client-s3";
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
4
|
-
|
|
2
|
+
/** The object to delete, and the ETag it must still have. */
|
|
3
|
+
export type ConditionalDeleteInput = {
|
|
4
|
+
bucket: string;
|
|
5
|
+
key: string;
|
|
6
|
+
/** ETag from the HeadObject that identified the object. */
|
|
7
|
+
eTag?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* DeleteObject that keeps a newer object at the same key. With an `eTag`,
|
|
11
|
+
* the delete is conditional (`If-Match`): when the key now holds another
|
|
12
|
+
* object (`412`), nothing is deleted and it returns `false`. A provider
|
|
13
|
+
* without conditional DeleteObject (`501`) gets a plain delete. Any other
|
|
14
|
+
* failure is thrown.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deleteObjectIfMatch(client: S3Client, input: ConditionalDeleteInput): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* {@link deleteObjectIfMatch} after a failed check, ignoring every failure:
|
|
19
|
+
* the caller is already returning an error, and an object left behind is
|
|
20
|
+
* caught by purge or a bucket lifecycle rule.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deleteObjectBestEffort(client: S3Client, bucket: string, key: string, eTag?: string): Promise<void>;
|
|
23
|
+
/** Best-effort AbortMultipartUpload, when init fails after CreateMultipartUpload. */
|
|
5
24
|
export declare function abortMultipartBestEffort(client: S3Client, bucket: string, key: string, uploadId: string): Promise<void>;
|
|
6
25
|
//# sourceMappingURL=best-effort.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/helpers/best-effort.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"best-effort.d.ts","sourceRoot":"","sources":["../../src/helpers/best-effort.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAG5B,6DAA6D;AAC7D,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,QAAQ,EAChB,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAMf;AAED,qFAAqF;AACrF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
/**
|
|
3
|
+
* Checks once per client that the AWS SDK does not add flexible checksums
|
|
4
|
+
* to presigned requests. With `requestChecksumCalculation: "WHEN_SUPPORTED"`
|
|
5
|
+
* (the SDK default since 3.729) a presigned URL signs a checksum of an empty
|
|
6
|
+
* body, and every upload to it fails at S3.
|
|
7
|
+
*
|
|
8
|
+
* The first failing call throws a {@link ConfigError}, which the error
|
|
9
|
+
* boundary logs. Later calls with the same client fail with
|
|
10
|
+
* `INTERNAL_ERROR` without logging again. An SDK without the option passes.
|
|
11
|
+
*/
|
|
12
|
+
export declare function assertChecksumConfig(client: S3Client): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=checksum-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum-config.d.ts","sourceRoot":"","sources":["../../src/helpers/checksum-config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQnD;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAa1E"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UploadFile } from "../types/hook-contexts.js";
|
|
2
|
+
import type { ResolvedUpload } from "../types/resolved.js";
|
|
2
3
|
/** File limits from `upload` (`fileTypes` / `maxFileSize`). */
|
|
3
|
-
export type FileConstraints = Pick<
|
|
4
|
-
/**
|
|
4
|
+
export type FileConstraints = Pick<ResolvedUpload, "fileTypes" | "maxFileSize">;
|
|
5
|
+
/** Fails with `FILE_TOO_LARGE` when `size` is over `maxFileSize`, if one is set. */
|
|
5
6
|
export declare function assertWithinMaxFileSize(maxFileSize: number | undefined, size: number): void;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
contentLength: number;
|
|
7
|
+
/**
|
|
8
|
+
* Checks a file against the route limits: `FILE_TYPE_NOT_ALLOWED` when it
|
|
9
|
+
* matches none of `fileTypes`, `FILE_EMPTY` when it has no bytes, and
|
|
10
|
+
* `FILE_TOO_LARGE` when it is over `maxFileSize`. Runs on the declared file
|
|
11
|
+
* at presign, and again on the HeadObject values at confirm.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertFileConstraints(constraints: FileConstraints, file: Pick<UploadFile, "size" | "type"> & {
|
|
14
|
+
name?: string;
|
|
15
15
|
}): void;
|
|
16
|
+
/**
|
|
17
|
+
* Fails with `FILE_TOO_LARGE` above 5 GiB, the most S3 takes in one POST or
|
|
18
|
+
* PutObject. Larger files need multipart.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertSingleUploadSize(size: number): void;
|
|
16
21
|
//# sourceMappingURL=constraints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../src/helpers/constraints.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constraints.d.ts","sourceRoot":"","sources":["../../src/helpers/constraints.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,+DAA+D;AAC/D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,aAAa,CAAC,CAAC;AAEhF,oFAAoF;AACpF,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,EAAE,MAAM,GACX,IAAI,CAIN;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,IAAI,CAWN;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAOzD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { APIError } from "@dimah-s3/core";
|
|
2
|
+
import type { S3Operation } from "../types/hook-contexts.js";
|
|
3
|
+
import type { ResolvedConfig } from "../types/resolved.js";
|
|
4
|
+
/**
|
|
5
|
+
* A server misconfiguration found while handling a call, such as a guard
|
|
6
|
+
* that returned a boolean. The error boundary logs it and returns
|
|
7
|
+
* `500 INTERNAL_ERROR`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ConfigError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export type ErrorBoundaryEnv = Pick<ResolvedConfig, "logger" | "onError">;
|
|
13
|
+
/**
|
|
14
|
+
* Maps anything a call throws to the {@link APIError} the client receives.
|
|
15
|
+
*
|
|
16
|
+
* - An `APIError` passes through. A raw better-call error gets a code:
|
|
17
|
+
* `UNSUPPORTED_MEDIA_TYPE`, `VALIDATION_ERROR` for a bad request, or the
|
|
18
|
+
* code and message it carries.
|
|
19
|
+
* - A socket error from S3 becomes `S3_NETWORK_ERROR`.
|
|
20
|
+
* - Anything else becomes `INTERNAL_ERROR`.
|
|
21
|
+
*
|
|
22
|
+
* Failures that are not an `APIError` are logged and passed to `onError`,
|
|
23
|
+
* unless the client already went away. Only a real better-call error passes
|
|
24
|
+
* through: another library's error that is merely named `APIError` is an
|
|
25
|
+
* unexpected failure like any other.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toAPIError(error: unknown, env: ErrorBoundaryEnv, request: Request, operation?: S3Operation): APIError;
|
|
28
|
+
//# sourceMappingURL=error-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../src/helpers/error-boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAW,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAqBvD;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAE1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,OAAO,EAChB,SAAS,CAAC,EAAE,WAAW,GACtB,QAAQ,CAaV"}
|
|
@@ -1,19 +1,48 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
1
|
+
import type { HeadObjectCommandOutput } from "@aws-sdk/client-s3";
|
|
2
|
+
import { type ConfirmedObjectResponse, type S3ObjectAcl } from "@dimah-s3/core";
|
|
3
|
+
import type { ObjectContext, UploadFile, UploadKind } from "../types/hook-contexts.js";
|
|
4
|
+
import type { OpenedRoute } from "../types/resolved.js";
|
|
4
5
|
export type FinalizeConfirmedInput = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
route: OpenedRoute<"upload">;
|
|
7
|
+
/** Context of the call, with the uploaded key and bucket. */
|
|
8
|
+
context: ObjectContext;
|
|
9
|
+
kind: UploadKind;
|
|
10
|
+
/** Upload token of this upload. The object must carry it as its marker. */
|
|
11
|
+
uploadToken: string;
|
|
12
|
+
/** Multipart only. */
|
|
9
13
|
uploadId?: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
14
|
+
/** File declared at presign, multipart init or `s3.put`. */
|
|
15
|
+
file: UploadFile;
|
|
16
|
+
/** Effective ACL written at presign, multipart init or `s3.put`. */
|
|
17
|
+
acl: S3ObjectAcl;
|
|
18
|
+
/** HeadObject of the uploaded key. */
|
|
19
|
+
head: HeadObjectCommandOutput;
|
|
12
20
|
};
|
|
13
21
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
22
|
+
* Finishes an upload once its object is in S3: confirm, multipart complete
|
|
23
|
+
* and `s3.put`.
|
|
24
|
+
*
|
|
25
|
+
* 1. The object must carry this upload's marker. Otherwise the key holds
|
|
26
|
+
* another upload's object, so the call fails with `OBJECT_NOT_FOUND` and
|
|
27
|
+
* nothing is deleted.
|
|
28
|
+
* 2. The HeadObject size must equal the declared size
|
|
29
|
+
* (`UPLOAD_SIZE_MISMATCH`), and the stored name, type and size must pass
|
|
30
|
+
* the route limits.
|
|
31
|
+
* 3. With `verifyContent`, the first bytes must match the type (for an
|
|
32
|
+
* untyped object, the type its name gives on download).
|
|
33
|
+
* 4. `upload.confirmGuard` runs with the verified `object`, except for
|
|
34
|
+
* `s3.put`.
|
|
35
|
+
* 5. `upload.onConfirmed` runs: plugins first, then the user hook.
|
|
36
|
+
*
|
|
37
|
+
* A rejection (a `4xx` `APIError`) in steps 2 to 4, or from a plugin
|
|
38
|
+
* `onConfirmed`, deletes the object and returns the error. That delete is
|
|
39
|
+
* conditional on the HeadObject ETag where the provider supports `If-Match`,
|
|
40
|
+
* so a newer upload at the same key is kept. Any other failure, such as an
|
|
41
|
+
* S3 network error or a hook whose database is down, keeps the object, so
|
|
42
|
+
* the confirm can be retried. A throw from the user `onConfirmed` keeps the
|
|
43
|
+
* object and returns `500 INTERNAL_ERROR`, even for an `APIError`, so a
|
|
44
|
+
* retried confirm replays the hooks with the same `uploadToken`. After every
|
|
45
|
+
* hook succeeds, `upload.object().previousKey` is deleted.
|
|
17
46
|
*/
|
|
18
|
-
export declare function
|
|
47
|
+
export declare function finalizeConfirmed(input: FinalizeConfirmedInput): Promise<ConfirmedObjectResponse>;
|
|
19
48
|
//# sourceMappingURL=finalize-confirmed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finalize-confirmed.d.ts","sourceRoot":"","sources":["../../src/helpers/finalize-confirmed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,
|
|
1
|
+
{"version":3,"file":"finalize-confirmed.d.ts","sourceRoot":"","sources":["../../src/helpers/finalize-confirmed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAIL,KAAK,uBAAuB,EAC5B,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,UAAU,EAGX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,6DAA6D;IAC7D,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,IAAI,EAAE,UAAU,CAAC;IACjB,oEAAoE;IACpE,GAAG,EAAE,WAAW,CAAC;IACjB,sCAAsC;IACtC,IAAI,EAAE,uBAAuB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CA4DlC"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { type HeadObjectCommandOutput, type S3Client } from "@aws-sdk/client-s3";
|
|
2
|
-
/** HeadObject as a yes/no. Errors other than not-found still throw. */
|
|
3
|
-
export declare function objectExists(client: S3Client, bucket: string, key: string): Promise<boolean>;
|
|
4
|
-
/** HeadObject, mapping AWS not-found to `OBJECT_NOT_FOUND`. */
|
|
5
|
-
export declare function headObjectOrNotFound(client: S3Client, bucket: string, key: string): Promise<HeadObjectCommandOutput>;
|
|
6
2
|
/**
|
|
7
|
-
* HeadObject
|
|
8
|
-
* `
|
|
3
|
+
* HeadObject of a stored object. A missing object fails with
|
|
4
|
+
* `OBJECT_NOT_FOUND`. `abortSignal` cancels the call, for example when the
|
|
5
|
+
* client disconnects.
|
|
9
6
|
*/
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export declare function headObjectOrNotFound(client: S3Client, bucket: string, key: string, options?: {
|
|
8
|
+
abortSignal?: AbortSignal;
|
|
9
|
+
}): Promise<HeadObjectCommandOutput>;
|
|
13
10
|
//# sourceMappingURL=head-object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"head-object.d.ts","sourceRoot":"","sources":["../../src/helpers/head-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"head-object.d.ts","sourceRoot":"","sources":["../../src/helpers/head-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAG5B;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAO,GAC1C,OAAO,CAAC,uBAAuB,CAAC,CAIlC"}
|
package/dist/helpers/hooks.d.ts
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GuardContext } from "../types/hook-contexts.js";
|
|
2
|
+
import type { DimahS3Locals, Guard, LifecycleHook } from "../types/locals.js";
|
|
3
|
+
import type { HookList } from "../types/resolved.js";
|
|
2
4
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* `useFormatDimahError` does not replace them with a generic mapped string.
|
|
5
|
+
* A new null-prototype `locals` object for one call, seeded with trusted
|
|
6
|
+
* in-process values.
|
|
6
7
|
*/
|
|
7
|
-
export declare function
|
|
8
|
-
request: Request;
|
|
9
|
-
}>(hook: ((context: T) => Promise<void> | void) | undefined, context: T): Promise<void>;
|
|
8
|
+
export declare function createLocals(seed?: Partial<DimahS3Locals>): DimahS3Locals;
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Runs guards in order. Each `{ locals }` result is copied into
|
|
11
|
+
* `context.locals`, so later hooks in the call see it. A throw rejects the
|
|
12
|
+
* call. Any other return value is a {@link ConfigError} and never allows.
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function runGuards<C extends GuardContext>(guards: HookList<Guard<C>>, context: C): Promise<void>;
|
|
15
|
+
export type RunLifecycleOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* Runs when a plugin hook throws, before the error is rethrown. Use it to
|
|
18
|
+
* undo the operation, for example to delete an object whose bookkeeping
|
|
19
|
+
* failed.
|
|
20
|
+
*/
|
|
21
|
+
onPluginError?: (error: unknown) => Promise<void> | void;
|
|
22
|
+
};
|
|
15
23
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
24
|
+
* Runs lifecycle hooks in order: plugins first, then the user hook. The
|
|
25
|
+
* first throw stops the rest and is rethrown. A user hook failure leaves the
|
|
26
|
+
* operation's effects in place.
|
|
18
27
|
*/
|
|
19
|
-
export declare function
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
export declare function runLifecycle<C>(hooks: HookList<LifecycleHook<C>>, context: C, options?: RunLifecycleOptions): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Exactly `{ locals: object }`: a plain object whose only key is `locals`,
|
|
31
|
+
* holding an object that is not an array.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isGuardResult(value: unknown): value is {
|
|
34
|
+
locals: Partial<DimahS3Locals>;
|
|
35
|
+
};
|
|
22
36
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/helpers/hooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/helpers/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAIzE;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC1B,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,IAAI,CAAC,CAYf;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1D,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAClC,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,EACjC,OAAO,EAAE,CAAC,EACV,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CASf;AAQD;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI;IAAE,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CAAE,CAU7C"}
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import { type ContentDispositionType
|
|
1
|
+
import { type ContentDispositionType } from "@dimah-s3/core";
|
|
2
|
+
import type { ResolvedDownload } from "../types/resolved.js";
|
|
3
|
+
/** How a stored object is sent: the presigned GET or the `/file` response. */
|
|
4
|
+
export type ObjectDisposition = {
|
|
5
|
+
disposition: ContentDispositionType;
|
|
6
|
+
/** `Content-Disposition` value, with the file name when there is one. */
|
|
7
|
+
header: string;
|
|
8
|
+
/**
|
|
9
|
+
* Set when the object opens inline but has no usable stored type: the
|
|
10
|
+
* type matched from the file name. Send it as `Content-Type`.
|
|
11
|
+
*/
|
|
12
|
+
contentType?: string;
|
|
13
|
+
};
|
|
2
14
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
15
|
+
* The disposition for a stored object, after S3 reports its type. `inline`
|
|
16
|
+
* is kept only when the type is on the route's effective `inlineTypes`;
|
|
17
|
+
* anything else is sent as `attachment`. Without a requested `name`, the
|
|
18
|
+
* file name comes from the stored `Content-Disposition`, else the key.
|
|
5
19
|
*/
|
|
6
|
-
export declare function
|
|
20
|
+
export declare function resolveObjectDisposition(inlineTypes: ResolvedDownload["inlineTypes"], input: {
|
|
7
21
|
key: string;
|
|
8
|
-
|
|
9
|
-
|
|
22
|
+
name?: string;
|
|
23
|
+
requested: ContentDispositionType;
|
|
24
|
+
/** Stored `Content-Type`, as S3 reports it. */
|
|
10
25
|
contentType?: string;
|
|
11
|
-
|
|
26
|
+
/** Stored `Content-Disposition`, as S3 reports it. */
|
|
27
|
+
contentDisposition?: string;
|
|
28
|
+
}): ObjectDisposition;
|
|
12
29
|
//# sourceMappingURL=inline-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-types.d.ts","sourceRoot":"","sources":["../../src/helpers/inline-types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"inline-types.d.ts","sourceRoot":"","sources":["../../src/helpers/inline-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,sBAAsB,EAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,WAAW,EAAE,sBAAsB,CAAC;IACpC,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,EAC5C,KAAK,EAAE;IACL,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,sBAAsB,CAAC;IAClC,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,GACA,iBAAiB,CAenB"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { type Part, type S3Client } from "@aws-sdk/client-s3";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Every uploaded part of a multipart upload, reading ListParts page by page
|
|
4
|
+
* until S3 reports no more. A missing upload fails with `OBJECT_NOT_FOUND`.
|
|
5
|
+
*/
|
|
3
6
|
export declare function listAllParts(client: S3Client, input: {
|
|
4
7
|
bucket: string;
|
|
5
8
|
key: string;
|
|
6
9
|
uploadId: string;
|
|
7
10
|
}): Promise<Part[]>;
|
|
8
|
-
/** Sum `Size` on listed parts. Pass `excludePartNumber` when replacing a part. */
|
|
9
|
-
export declare function listedPartsByteSize(parts: readonly {
|
|
10
|
-
PartNumber?: number;
|
|
11
|
-
Size?: number;
|
|
12
|
-
}[], excludePartNumber?: number): number;
|
|
13
11
|
//# sourceMappingURL=list-parts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-parts.d.ts","sourceRoot":"","sources":["../../src/helpers/list-parts.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"list-parts.d.ts","sourceRoot":"","sources":["../../src/helpers/list-parts.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EACT,KAAK,QAAQ,EACd,MAAM,oBAAoB,CAAC;AAM5B;;;GAGG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,QAAQ,EAChB,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,IAAI,EAAE,CAAC,CA4BjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes a metadata value safe to send as an `x-amz-meta-*` header. Printable
|
|
3
|
+
* ASCII without surrounding spaces is kept as is. Anything else becomes one
|
|
4
|
+
* RFC 2047 encoded word (`=?UTF-8?B?…?=`), the form S3 itself returns for
|
|
5
|
+
* non-ASCII metadata.
|
|
6
|
+
*/
|
|
7
|
+
export declare function encodeMetadataValue(value: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Reverses {@link encodeMetadataValue}, and decodes any RFC 2047 value S3
|
|
10
|
+
* returns: one or more `B` or `Q` encoded words in UTF-8 or US-ASCII,
|
|
11
|
+
* separated by whitespace. A value that is not a well-formed encoded word
|
|
12
|
+
* is returned unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export declare function decodeMetadataValue(value: string): string;
|
|
15
|
+
//# sourceMappingURL=metadata-encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-encoding.d.ts","sourceRoot":"","sources":["../../src/helpers/metadata-encoding.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBzD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** S3 user-metadata key for the upload marker. Its value is the upload token. */
|
|
2
|
+
export declare const UPLOAD_MARKER_META = "dimah-upload";
|
|
3
|
+
/** S3 user-metadata key for `upload.object().previousKey`. */
|
|
4
|
+
export declare const PREVIOUS_KEY_META = "dimah-previous-key";
|
|
5
|
+
/** S3 limit on user metadata: UTF-8 bytes of every key and value, summed. */
|
|
6
|
+
export declare const MAX_METADATA_BYTES = 2048;
|
|
7
|
+
export type ObjectMetadataInput = {
|
|
8
|
+
/** User metadata from `upload.object()` or `s3.put`. */
|
|
9
|
+
metadata?: Record<string, string>;
|
|
10
|
+
uploadToken: string;
|
|
11
|
+
/** Key to delete after a successful confirm. */
|
|
12
|
+
previousKey?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* S3 user metadata for a new object: the user metadata plus the upload
|
|
16
|
+
* marker and the previous key. Keys are lowercased, as S3 stores them, and
|
|
17
|
+
* values are RFC 2047-encoded where needed.
|
|
18
|
+
*
|
|
19
|
+
* Throws a {@link ConfigError} when a key is invalid, repeats, or uses an
|
|
20
|
+
* internal name, or when the total exceeds {@link MAX_METADATA_BYTES}.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildObjectMetadata(input: ObjectMetadataInput): Record<string, string>;
|
|
23
|
+
/** User metadata as HeadObject returns it, split from the internal keys. */
|
|
24
|
+
export type StoredObjectMetadata = {
|
|
25
|
+
/** Decoded user metadata, without internal keys. */
|
|
26
|
+
metadata: Record<string, string>;
|
|
27
|
+
uploadToken?: string;
|
|
28
|
+
previousKey?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Splits and decodes HeadObject `Metadata`. */
|
|
31
|
+
export declare function readObjectMetadata(raw: Record<string, string> | undefined): StoredObjectMetadata;
|
|
32
|
+
/**
|
|
33
|
+
* The upload token an object was written with: its upload marker, read
|
|
34
|
+
* from HeadObject `Metadata`. `undefined` for an object dimah-s3 did not
|
|
35
|
+
* write. A plugin that cleans up an upload deletes the object only while
|
|
36
|
+
* this still equals the token of the upload it tracks.
|
|
37
|
+
*/
|
|
38
|
+
export declare function readUploadMarker(metadata: Record<string, string> | undefined): string | undefined;
|
|
39
|
+
//# sourceMappingURL=object-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-meta.d.ts","sourceRoot":"","sources":["../../src/helpers/object-meta.ts"],"names":[],"mappings":"AAMA,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAEjD,8DAA8D;AAC9D,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAUvC,MAAM,MAAM,mBAAmB,GAAG;IAChC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,mBAAmB,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA8BxB;AAED,4EAA4E;AAC5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,gDAAgD;AAChD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACtC,oBAAoB,CAYtB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAC3C,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { StorageClass } from "@aws-sdk/client-s3";
|
|
2
|
-
import type { ObjectS3Headers } from "../types/
|
|
3
|
-
/**
|
|
2
|
+
import type { ObjectS3Headers } from "../types/hook-contexts.js";
|
|
3
|
+
/**
|
|
4
|
+
* URL-encoded `key=value&…` for the S3 `Tagging` / `x-amz-tagging` field.
|
|
5
|
+
* Tags come from `upload.object`, so an invalid tag is a {@link ConfigError}.
|
|
6
|
+
*/
|
|
4
7
|
export declare function encodeObjectTagging(tagging: Record<string, string>): string;
|
|
5
8
|
/**
|
|
6
9
|
* Drop blank `storageClass` / `cacheControl` / empty `tagging`, and reject
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-s3.d.ts","sourceRoot":"","sources":["../../src/helpers/object-s3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"object-s3.d.ts","sourceRoot":"","sources":["../../src/helpers/object-s3.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA+B7D;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAa3E;AAOD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,eAAe,GAAG,SAAS,GAChC,eAAe,CAajB;AAED,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe;;;;EASxD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,eAAe,GACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB"}
|