@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
|
@@ -1,227 +1,219 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ContentDispositionType, S3ObjectAcl } from "@dimah-s3/core";
|
|
2
|
+
import type { DimahS3Locals } from "./locals";
|
|
3
|
+
/** The call a hook runs in. Plugin endpoints use `"plugin"`. */
|
|
4
|
+
export type S3Operation = "upload" | "confirm" | "download" | "file" | "delete" | "deleteMany" | "catalog" | "put" | "multipart.init" | "multipart.signPart" | "multipart.listParts" | "multipart.complete" | "multipart.abort" | "plugin";
|
|
5
|
+
/**
|
|
6
|
+
* How the bytes reach S3: a presigned POST or PUT, a multipart upload, or
|
|
7
|
+
* `s3.put` on the server.
|
|
8
|
+
*/
|
|
9
|
+
export type UploadKind = "post" | "put" | "multipart" | "server";
|
|
10
|
+
/** Context for the instance `guard`. Every other context extends it. */
|
|
3
11
|
export type GuardContext = {
|
|
4
|
-
/** The incoming
|
|
12
|
+
/** The incoming request, or a synthetic one for in-process calls. */
|
|
5
13
|
request: Request;
|
|
14
|
+
operation: S3Operation;
|
|
15
|
+
/** Values from earlier guards in this call. See {@link DimahS3Locals}. */
|
|
16
|
+
locals: DimahS3Locals;
|
|
6
17
|
};
|
|
7
|
-
/** Context for a route
|
|
18
|
+
/** Context for a route `guard`. It runs before every operation on the route. */
|
|
8
19
|
export type RouteGuardContext = GuardContext & {
|
|
9
20
|
/** Named file route. */
|
|
10
21
|
route: string;
|
|
11
22
|
};
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
* upload / multipart init, or supplied on confirm / download / delete /
|
|
15
|
-
* multipart session ops.
|
|
16
|
-
*/
|
|
17
|
-
export type StoredObjectContext = RouteGuardContext & {
|
|
23
|
+
/** Shared context once the object key is known. */
|
|
24
|
+
export type ObjectContext = RouteGuardContext & {
|
|
18
25
|
/** S3 object key. */
|
|
19
26
|
key: string;
|
|
20
|
-
/** Target bucket. */
|
|
21
27
|
bucket: string;
|
|
22
28
|
};
|
|
23
|
-
/**
|
|
24
|
-
export type
|
|
29
|
+
/** File the client declared. S3 has not verified it yet. */
|
|
30
|
+
export type UploadFile = {
|
|
25
31
|
name: string;
|
|
26
|
-
size
|
|
32
|
+
size: number;
|
|
27
33
|
type?: string;
|
|
28
34
|
};
|
|
29
35
|
/**
|
|
30
|
-
* Input to `upload.object`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
36
|
+
* Input to `upload.object`. `clientMetadata` is what the client sent; it is
|
|
37
|
+
* written to S3 only when `object` copies it into
|
|
38
|
+
* {@link UploadObjectInfo.metadata}.
|
|
33
39
|
*/
|
|
34
|
-
export type UploadObjectContext = {
|
|
35
|
-
|
|
36
|
-
route: string;
|
|
37
|
-
file: ObjectFile;
|
|
40
|
+
export type UploadObjectContext = RouteGuardContext & {
|
|
41
|
+
file: UploadFile;
|
|
38
42
|
bucket: string;
|
|
39
43
|
/**
|
|
40
|
-
* Namespace this route writes under. `false
|
|
41
|
-
*
|
|
42
|
-
* `folder` / `key`.
|
|
44
|
+
* Namespace this route writes under. With `false`, the default key is
|
|
45
|
+
* `{uuid}/{name}` and follow-up keys are not namespace-checked.
|
|
43
46
|
*/
|
|
44
47
|
keyPrefix: string | false;
|
|
45
48
|
clientMetadata?: Record<string, string>;
|
|
46
49
|
};
|
|
47
|
-
/** Server-owned
|
|
50
|
+
/** Server-owned object identity from `upload.object`. */
|
|
48
51
|
export type UploadObjectInfo = {
|
|
49
52
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* `false` (`{folder}/{uuid}/{name}`). Ignored when {@link key} is set.
|
|
53
|
+
* Key path segment under the route `keyPrefix`:
|
|
54
|
+
* `{keyPrefix}/{keyFolder}/{uuid}/{name}`. Ignored when {@link key} is set.
|
|
53
55
|
*/
|
|
54
|
-
|
|
56
|
+
keyFolder?: string;
|
|
55
57
|
/**
|
|
56
|
-
* Object key, nested under
|
|
57
|
-
*
|
|
58
|
-
* If omitted, `{keyPrefix}/{folder}/{uuid}/{name}` is used
|
|
59
|
-
* (`{uuid}/{name}` when `keyPrefix` is `false` and `folder` is omitted).
|
|
58
|
+
* Object key, nested under the route `keyPrefix` unless it is already
|
|
59
|
+
* inside it or `keyPrefix` is `false`.
|
|
60
60
|
*/
|
|
61
61
|
key?: string;
|
|
62
|
-
/** S3 user metadata (`x-amz-meta-*`). */
|
|
63
|
-
metadata?: Record<string, string>;
|
|
64
|
-
/** Override the route ACL for this object. */
|
|
65
|
-
acl?: S3ObjectAcl;
|
|
66
62
|
/**
|
|
67
|
-
* S3
|
|
68
|
-
*
|
|
63
|
+
* S3 user metadata (`x-amz-meta-*`). Non-ASCII values are RFC 2047-encoded.
|
|
64
|
+
* Keys and values, including internal keys, are limited to 2048 UTF-8
|
|
65
|
+
* bytes in total.
|
|
69
66
|
*/
|
|
67
|
+
metadata?: Record<string, string>;
|
|
68
|
+
/** Overrides the route ACL for this object. */
|
|
69
|
+
acl?: S3ObjectAcl;
|
|
70
|
+
/** S3 storage class (`STANDARD_IA`, `INTELLIGENT_TIERING`, …). Signed. */
|
|
70
71
|
storageClass?: string;
|
|
71
|
-
/**
|
|
72
|
-
* `Cache-Control` written on the object. Signed into the upload so the
|
|
73
|
-
* client cannot set an arbitrary value.
|
|
74
|
-
*/
|
|
72
|
+
/** `Cache-Control` written on the object. Signed. */
|
|
75
73
|
cacheControl?: string;
|
|
76
74
|
/**
|
|
77
|
-
* S3 object tags (
|
|
78
|
-
*
|
|
75
|
+
* S3 object tags (at most 10), printable ASCII only. Signed, and visible
|
|
76
|
+
* to the client on presigned uploads, so keep secrets out.
|
|
79
77
|
*/
|
|
80
78
|
tagging?: Record<string, string>;
|
|
81
79
|
/**
|
|
82
|
-
*
|
|
83
|
-
* `keyPrefix
|
|
80
|
+
* Key to delete after a successful confirm. It must stay under the route
|
|
81
|
+
* `keyPrefix`. Use it with a new key to replace an avatar.
|
|
84
82
|
*/
|
|
85
83
|
previousKey?: string;
|
|
86
84
|
};
|
|
87
|
-
/** S3 headers
|
|
85
|
+
/** S3 headers from `upload.object` that are signed into the upload. */
|
|
88
86
|
export type ObjectS3Headers = Pick<UploadObjectInfo, "storageClass" | "cacheControl" | "tagging">;
|
|
89
87
|
/**
|
|
90
|
-
* Context for `upload.guard`.
|
|
91
|
-
*
|
|
92
|
-
* so `key` is already assigned (plugins like `db()` check ownership here).
|
|
93
|
-
* Client-declared values are not verified by S3.
|
|
88
|
+
* Context for `upload.guard`. It runs on presign, multipart init and
|
|
89
|
+
* `s3.put`, after `upload.object`, so `key` is already assigned.
|
|
94
90
|
*/
|
|
95
|
-
export type UploadGuardContext =
|
|
96
|
-
|
|
97
|
-
file:
|
|
98
|
-
|
|
91
|
+
export type UploadGuardContext = ObjectContext & ObjectS3Headers & {
|
|
92
|
+
kind: UploadKind;
|
|
93
|
+
file: UploadFile;
|
|
94
|
+
acl: S3ObjectAcl;
|
|
95
|
+
/** S3 metadata from `upload.object`. */
|
|
99
96
|
metadata?: Record<string, string>;
|
|
100
|
-
/** Client extras
|
|
97
|
+
/** Client extras. They are never written to S3 automatically. */
|
|
101
98
|
clientMetadata?: Record<string, string>;
|
|
102
|
-
/** Resolved ACL. */
|
|
103
|
-
acl?: S3ObjectAcl;
|
|
104
|
-
/** Route `upload.replace`. */
|
|
105
|
-
replace?: "overwrite";
|
|
106
|
-
};
|
|
107
|
-
/** Context for `upload.onPresigned` (single-shot only). */
|
|
108
|
-
export type UploadOnPresignedContext = UploadGuardContext & {
|
|
109
|
-
/** Presigned upload URL. */
|
|
110
|
-
url: string;
|
|
111
|
-
/** Validity in seconds. */
|
|
112
|
-
expiresIn: number;
|
|
113
99
|
};
|
|
114
100
|
/**
|
|
115
|
-
* Context for `upload.
|
|
116
|
-
*
|
|
101
|
+
* Context for `upload.onStart`. It runs once the upload can begin: after
|
|
102
|
+
* presign, after `CreateMultipartUpload`, or before `PutObject` for
|
|
103
|
+
* `s3.put`. A throw cancels the upload.
|
|
117
104
|
*/
|
|
118
|
-
export type
|
|
119
|
-
/**
|
|
105
|
+
export type UploadOnStartContext = UploadGuardContext & {
|
|
106
|
+
/** Stable id of this upload. Dedupe `onConfirmed` replays on it. */
|
|
107
|
+
uploadToken: string;
|
|
108
|
+
/** Multipart only. */
|
|
120
109
|
uploadId?: string;
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
contentType?: string;
|
|
134
|
-
/** Size from HeadObject — trust this, not the presign `fileSize`. */
|
|
135
|
-
contentLength: number;
|
|
136
|
-
/** ETag from HeadObject. */
|
|
110
|
+
/** Presigned URL. POST and PUT only. */
|
|
111
|
+
url?: string;
|
|
112
|
+
/** When the presigned URL expires. POST and PUT only. */
|
|
113
|
+
urlExpiresAt?: Date;
|
|
114
|
+
/** Confirm deadline: the ticket expiry, or 15 minutes for `s3.put`. */
|
|
115
|
+
expiresAt: Date;
|
|
116
|
+
};
|
|
117
|
+
/** Object as HeadObject reports it. Trust these values, not the declared file. */
|
|
118
|
+
export type VerifiedObject = {
|
|
119
|
+
name?: string;
|
|
120
|
+
size: number;
|
|
121
|
+
type?: string;
|
|
137
122
|
eTag?: string;
|
|
138
|
-
/** Object metadata. */
|
|
139
|
-
metadata?: Record<string, string>;
|
|
140
|
-
/** ACL from the upload policy (`upload.acl` / `object`). */
|
|
141
|
-
acl?: S3ObjectAcl;
|
|
142
|
-
/** Stored filename. */
|
|
143
|
-
fileName?: string;
|
|
144
|
-
/** S3 version ID. */
|
|
145
123
|
versionId?: string;
|
|
146
|
-
/** Last modified timestamp. */
|
|
147
124
|
lastModified?: string;
|
|
148
|
-
/**
|
|
125
|
+
/** User metadata, decoded, without internal keys. */
|
|
126
|
+
metadata: Record<string, string>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Context for `upload.confirmGuard`. It runs on confirm and multipart
|
|
130
|
+
* complete, after HeadObject and the size, type and content checks, so
|
|
131
|
+
* `object` holds the values S3 verified. A rejection deletes the object.
|
|
132
|
+
*/
|
|
133
|
+
export type UploadConfirmGuardContext = ObjectContext & {
|
|
134
|
+
kind: Exclude<UploadKind, "server">;
|
|
135
|
+
uploadToken: string;
|
|
136
|
+
/** Multipart only. */
|
|
149
137
|
uploadId?: string;
|
|
138
|
+
/** File declared at presign or init. Check `object` instead. */
|
|
139
|
+
file: UploadFile;
|
|
140
|
+
/** ACL from the upload policy. */
|
|
141
|
+
acl: S3ObjectAcl;
|
|
142
|
+
/** The object as HeadObject reports it. */
|
|
143
|
+
object: VerifiedObject;
|
|
150
144
|
};
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Context for `upload.onConfirmed`: the confirm guard context, and also for
|
|
147
|
+
* `s3.put` (`kind: "server"`). It runs at least once per upload; a retried
|
|
148
|
+
* confirm runs it again, so dedupe on `uploadToken`.
|
|
149
|
+
*/
|
|
150
|
+
export type UploadOnConfirmedContext = Omit<UploadConfirmGuardContext, "kind"> & {
|
|
151
|
+
kind: UploadKind;
|
|
157
152
|
/**
|
|
158
|
-
*
|
|
159
|
-
* `
|
|
160
|
-
* `download.guard` sees the TTL that will be signed
|
|
161
|
-
* (`0` when download `mode` is `"proxy"`).
|
|
153
|
+
* `upload.object().previousKey`, which is deleted once every
|
|
154
|
+
* `onConfirmed` hook succeeds. Retire your own record of it here.
|
|
162
155
|
*/
|
|
156
|
+
previousKey?: string;
|
|
157
|
+
};
|
|
158
|
+
/** Context for `download.resolve`. */
|
|
159
|
+
export type DownloadResolveContext = ObjectContext & {
|
|
160
|
+
mode: "presign" | "proxy";
|
|
161
|
+
/** Download file name the client asked for. */
|
|
162
|
+
name?: string;
|
|
163
|
+
/** Requested disposition, or the route default. */
|
|
164
|
+
disposition: ContentDispositionType;
|
|
165
|
+
/** TTL the client asked for. Presign mode only. */
|
|
163
166
|
expiresIn?: number;
|
|
164
167
|
};
|
|
165
|
-
/** Per-request
|
|
168
|
+
/** Per-request download options from `download.resolve`. */
|
|
166
169
|
export type DownloadResolveInfo = {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
name?: string;
|
|
171
|
+
disposition?: ContentDispositionType;
|
|
172
|
+
/** Signed TTL in seconds, capped by the instance `maxExpiresIn`. Presign mode only. */
|
|
173
|
+
expiresIn?: number;
|
|
174
|
+
/** `Cache-Control` on `/file` responses. Proxy mode only. @default "private, no-cache" */
|
|
175
|
+
cacheControl?: string;
|
|
176
|
+
};
|
|
177
|
+
/** Context for `download.guard`, with the values that will be used. */
|
|
178
|
+
export type DownloadGuardContext = ObjectContext & {
|
|
179
|
+
mode: "presign" | "proxy";
|
|
180
|
+
name?: string;
|
|
181
|
+
disposition: ContentDispositionType;
|
|
182
|
+
/** Signed TTL. `undefined` in proxy mode. */
|
|
172
183
|
expiresIn?: number;
|
|
173
|
-
fileName?: string;
|
|
174
184
|
};
|
|
175
185
|
/** Context for `download.onPresigned`. */
|
|
176
186
|
export type DownloadOnPresignedContext = DownloadGuardContext & {
|
|
177
|
-
/** Presigned GET URL. */
|
|
187
|
+
/** Presigned GET URL, or the `/file` URL in proxy mode. */
|
|
178
188
|
url: string;
|
|
179
|
-
/** Validity in seconds. */
|
|
180
|
-
expiresIn: number;
|
|
181
189
|
};
|
|
182
190
|
/** Context for `delete.guard`. */
|
|
183
|
-
export type DeleteGuardContext =
|
|
191
|
+
export type DeleteGuardContext = ObjectContext;
|
|
184
192
|
/**
|
|
185
|
-
* Context for `delete.onDeleted`. Delete is idempotent
|
|
186
|
-
* when the object
|
|
193
|
+
* Context for `delete.onDeleted`. Delete is idempotent, so this also runs
|
|
194
|
+
* when the object did not exist.
|
|
187
195
|
*/
|
|
188
|
-
export type DeleteOnDeletedContext =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
/** Shared base for multipart operations that already have an upload id. */
|
|
193
|
-
export type MultipartUploadContext = StoredObjectContext & {
|
|
194
|
-
/** Multipart upload ID. */
|
|
195
|
-
uploadId: string;
|
|
196
|
-
};
|
|
197
|
-
/** Context for `upload.multipart.onInit`. */
|
|
198
|
-
export type MultipartOnInitContext = UploadGuardContext & {
|
|
199
|
-
/** Multipart upload ID. */
|
|
196
|
+
export type DeleteOnDeletedContext = ObjectContext;
|
|
197
|
+
/** Shared context for multipart calls that carry a ticket. */
|
|
198
|
+
export type MultipartUploadContext = ObjectContext & {
|
|
200
199
|
uploadId: string;
|
|
200
|
+
uploadToken: string;
|
|
201
|
+
/** File declared at init. */
|
|
202
|
+
file: UploadFile;
|
|
201
203
|
};
|
|
202
204
|
/**
|
|
203
|
-
* Context for `upload.multipart.guard`.
|
|
204
|
-
*
|
|
205
|
-
* Complete also runs `upload.confirmGuard`.
|
|
205
|
+
* Context for `upload.multipart.guard`. It runs on part signing, list,
|
|
206
|
+
* abort and complete. Init uses `upload.guard`.
|
|
206
207
|
*/
|
|
207
208
|
export type MultipartGuardContext = (MultipartUploadContext & {
|
|
208
209
|
action: "part";
|
|
209
210
|
/** 1-based part number. */
|
|
210
211
|
partNumber: number;
|
|
211
|
-
/** Byte size
|
|
212
|
-
|
|
213
|
-
}) | (MultipartUploadContext & {
|
|
214
|
-
action: "list";
|
|
212
|
+
/** Byte size signed into the part URL. */
|
|
213
|
+
size: number;
|
|
215
214
|
}) | (MultipartUploadContext & {
|
|
216
|
-
action: "abort";
|
|
217
|
-
}) | (MultipartUploadContext & {
|
|
218
|
-
action: "complete";
|
|
215
|
+
action: "list" | "abort" | "complete";
|
|
219
216
|
});
|
|
220
217
|
/** Context for `upload.multipart.onAbort`. */
|
|
221
218
|
export type MultipartOnAbortContext = MultipartUploadContext;
|
|
222
|
-
/** Context for `upload.multipart.onList`. */
|
|
223
|
-
export type MultipartOnListContext = MultipartUploadContext & {
|
|
224
|
-
/** Parts already uploaded to S3. */
|
|
225
|
-
parts: MultipartPartInfo[];
|
|
226
|
-
};
|
|
227
219
|
//# sourceMappingURL=hook-contexts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook-contexts.d.ts","sourceRoot":"","sources":["../../src/types/hook-contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"hook-contexts.d.ts","sourceRoot":"","sources":["../../src/types/hook-contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,gEAAgE;AAChE,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,SAAS,GACT,UAAU,GACV,MAAM,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C,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,sBAAsB,CAAC;IACpC,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,0BAA0B,GAAG,oBAAoB,GAAG;IAC9D,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,kCAAkC;AAClC,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAEnD,8DAA8D;AAC9D,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAC7B,CAAC,sBAAsB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,GACF,CAAC,sBAAsB,GAAG;IAAE,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;CAAE,CAAC,CAAC;AAEzE,8CAA8C;AAC9C,MAAM,MAAM,uBAAuB,GAAG,sBAAsB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DeleteGuardContext, DeleteOnDeletedContext, DownloadGuardContext, DownloadOnPresignedContext,
|
|
2
|
-
export type { DeleteConfig, DimahS3Config, DimahS3Logger, DimahS3RouteConfig,
|
|
3
|
-
export {
|
|
1
|
+
export type { DeleteGuardContext, DeleteOnDeletedContext, DownloadGuardContext, DownloadOnPresignedContext, DownloadResolveContext, DownloadResolveInfo, GuardContext, MultipartGuardContext, MultipartOnAbortContext, MultipartUploadContext, ObjectContext, ObjectS3Headers, RouteGuardContext, S3Operation, UploadConfirmGuardContext, UploadFile, UploadGuardContext, UploadKind, UploadObjectContext, UploadObjectInfo, UploadOnConfirmedContext, UploadOnStartContext, VerifiedObject, } from "./hook-contexts";
|
|
2
|
+
export type { DeleteConfig, DimahS3Api, DimahS3Config, DimahS3Logger, DimahS3RouteConfig, DownloadConfig, FeatureToggle, MultipartConfig, PutInput, S3ServerCallOptions, TicketSubject, UploadConfig, } from "./config";
|
|
3
|
+
export type { DimahS3Locals, DimahS3RoutePluginOptions, Guard, GuardResult, LifecycleHook, } from "./locals";
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,yBAAyB,EACzB,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,UAAU,EACV,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,aAAa,EACb,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,aAAa,EACb,yBAAyB,EACzB,KAAK,EACL,WAAW,EACX,aAAa,GACd,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values that guards hand to later hooks in the same call. Augment it to
|
|
3
|
+
* type them:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* declare module "@dimah-s3/server" {
|
|
7
|
+
* interface DimahS3Locals {
|
|
8
|
+
* userId: string;
|
|
9
|
+
* }
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Each call gets its own null-prototype object. HTTP requests never set it.
|
|
14
|
+
*/
|
|
15
|
+
export interface DimahS3Locals {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Per-route plugin options under {@link DimahS3RouteConfig.plugins}, keyed
|
|
19
|
+
* by plugin id. Plugins augment it (`db?: false | DbRouteOptions`). `false`
|
|
20
|
+
* turns the plugin off for the route.
|
|
21
|
+
*/
|
|
22
|
+
export interface DimahS3RoutePluginOptions {
|
|
23
|
+
[pluginId: string]: false | object | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a guard returns. Return nothing to allow, `{ locals }` to allow and
|
|
27
|
+
* pass values to later hooks, and throw to reject. Any other value is a
|
|
28
|
+
* config error: it is logged, the call returns `500`, and it never allows.
|
|
29
|
+
*/
|
|
30
|
+
export type GuardResult = void | undefined | {
|
|
31
|
+
locals: Partial<DimahS3Locals>;
|
|
32
|
+
};
|
|
33
|
+
/** Authorization hook. See {@link GuardResult}. */
|
|
34
|
+
export type Guard<C> = (context: C) => GuardResult | Promise<GuardResult>;
|
|
35
|
+
/** Lifecycle `on*` hook. It runs after plugin hooks for the same slot. */
|
|
36
|
+
export type LifecycleHook<C> = (context: C) => void | Promise<void>;
|
|
37
|
+
//# sourceMappingURL=locals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locals.d.ts","sourceRoot":"","sources":["../../src/types/locals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,aAAa;CAAG;AAEjC;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;CAChD;AAED;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;CAAE,CAAC;AAEhF,mDAAmD;AACnD,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1E,0EAA0E;AAC1E,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
import type { ContentDispositionType, S3ObjectAcl, UploadPresignMethod } from "@dimah-s3/core";
|
|
3
|
+
import type { DimahS3Config, DimahS3Logger, DownloadConfig, TicketSubject, UploadConfig } from "./config";
|
|
4
|
+
import type { DeleteGuardContext, DeleteOnDeletedContext, DownloadGuardContext, DownloadOnPresignedContext, GuardContext, MultipartGuardContext, MultipartOnAbortContext, RouteGuardContext, UploadConfirmGuardContext, UploadGuardContext, UploadOnConfirmedContext, UploadOnStartContext } from "./hook-contexts";
|
|
5
|
+
import type { DimahS3RoutePluginOptions, Guard, LifecycleHook } from "./locals";
|
|
6
|
+
/**
|
|
7
|
+
* A route feature a call can hit. `multipart` is nested under upload, and
|
|
8
|
+
* `proxy` is a download in `mode: "proxy"`, the only one `/file` serves.
|
|
9
|
+
*/
|
|
10
|
+
export type RouteFeature = "upload" | "download" | "delete" | "multipart" | "proxy";
|
|
11
|
+
/** One hook and its owner. `plugin` is the plugin id; the user hook has none. */
|
|
12
|
+
export type HookEntry<H> = {
|
|
13
|
+
plugin?: string;
|
|
14
|
+
hook: H;
|
|
15
|
+
};
|
|
16
|
+
/** Hooks for one slot, in run order: plugins in plugin order, then the user hook. */
|
|
17
|
+
export type HookList<H> = readonly HookEntry<H>[];
|
|
18
|
+
export type DisabledFeature = {
|
|
19
|
+
enabled: false;
|
|
20
|
+
};
|
|
21
|
+
export type ResolvedMultipart = {
|
|
22
|
+
enabled: true;
|
|
23
|
+
/** Preferred part size. The part layout may raise it. */
|
|
24
|
+
partSize?: number;
|
|
25
|
+
ticketExpiresIn: number;
|
|
26
|
+
guard: HookList<Guard<MultipartGuardContext>>;
|
|
27
|
+
onAbort: HookList<LifecycleHook<MultipartOnAbortContext>>;
|
|
28
|
+
};
|
|
29
|
+
export type ResolvedUpload = {
|
|
30
|
+
enabled: true;
|
|
31
|
+
fileTypes?: readonly string[];
|
|
32
|
+
maxFileSize?: number;
|
|
33
|
+
object?: UploadConfig["object"];
|
|
34
|
+
acl: S3ObjectAcl;
|
|
35
|
+
method: UploadPresignMethod;
|
|
36
|
+
/** URL TTL, already capped by the instance `maxExpiresIn`. */
|
|
37
|
+
expiresIn: number;
|
|
38
|
+
confirmWindow: number;
|
|
39
|
+
/** Effective value: `true` whenever `verifyContent` is on. */
|
|
40
|
+
checksum: boolean;
|
|
41
|
+
verifyContent: boolean;
|
|
42
|
+
multipart: ResolvedMultipart | DisabledFeature;
|
|
43
|
+
guard: HookList<Guard<UploadGuardContext>>;
|
|
44
|
+
onStart: HookList<LifecycleHook<UploadOnStartContext>>;
|
|
45
|
+
confirmGuard: HookList<Guard<UploadConfirmGuardContext>>;
|
|
46
|
+
onConfirmed: HookList<LifecycleHook<UploadOnConfirmedContext>>;
|
|
47
|
+
};
|
|
48
|
+
export type ResolvedDownload = {
|
|
49
|
+
enabled: true;
|
|
50
|
+
/** Already capped by the instance `maxExpiresIn`. */
|
|
51
|
+
maxExpiresIn: number;
|
|
52
|
+
disposition: ContentDispositionType;
|
|
53
|
+
/**
|
|
54
|
+
* Effective allow-list: the config value, else `DEFAULT_INLINE_TYPES`
|
|
55
|
+
* (without `application/pdf` in proxy mode). `false` never inlines.
|
|
56
|
+
*/
|
|
57
|
+
inlineTypes: readonly string[] | false;
|
|
58
|
+
mode: "presign" | "proxy";
|
|
59
|
+
resolve?: DownloadConfig["resolve"];
|
|
60
|
+
guard: HookList<Guard<DownloadGuardContext>>;
|
|
61
|
+
onPresigned: HookList<LifecycleHook<DownloadOnPresignedContext>>;
|
|
62
|
+
};
|
|
63
|
+
export type ResolvedDelete = {
|
|
64
|
+
enabled: true;
|
|
65
|
+
guard: HookList<Guard<DeleteGuardContext>>;
|
|
66
|
+
onDeleted: HookList<LifecycleHook<DeleteOnDeletedContext>>;
|
|
67
|
+
};
|
|
68
|
+
export type ResolvedRoute = {
|
|
69
|
+
name: string;
|
|
70
|
+
client: S3Client;
|
|
71
|
+
bucket: string;
|
|
72
|
+
/** `false` means keys are not namespace-checked. */
|
|
73
|
+
keyPrefix: string | false;
|
|
74
|
+
/** The route `plugins` field as configured. */
|
|
75
|
+
plugins: DimahS3RoutePluginOptions;
|
|
76
|
+
guard: HookList<Guard<RouteGuardContext>>;
|
|
77
|
+
upload: ResolvedUpload | (DisabledFeature & {
|
|
78
|
+
multipart: DisabledFeature;
|
|
79
|
+
});
|
|
80
|
+
download: ResolvedDownload | DisabledFeature;
|
|
81
|
+
delete: ResolvedDelete | DisabledFeature;
|
|
82
|
+
};
|
|
83
|
+
/** A {@link ResolvedRoute} after the feature `F` was checked to be on. */
|
|
84
|
+
export type OpenedRoute<F extends RouteFeature> = ResolvedRoute & (F extends "multipart" ? {
|
|
85
|
+
upload: ResolvedUpload & {
|
|
86
|
+
multipart: ResolvedMultipart;
|
|
87
|
+
};
|
|
88
|
+
} : F extends "upload" ? {
|
|
89
|
+
upload: ResolvedUpload;
|
|
90
|
+
} : F extends "download" ? {
|
|
91
|
+
download: ResolvedDownload;
|
|
92
|
+
} : F extends "proxy" ? {
|
|
93
|
+
download: ResolvedDownload & {
|
|
94
|
+
mode: "proxy";
|
|
95
|
+
};
|
|
96
|
+
} : {
|
|
97
|
+
delete: ResolvedDelete;
|
|
98
|
+
});
|
|
99
|
+
export type ResolvedConfig = {
|
|
100
|
+
/** Normalized, without a trailing slash. */
|
|
101
|
+
basePath: string;
|
|
102
|
+
baseURL?: string;
|
|
103
|
+
/**
|
|
104
|
+
* Secrets from the config, first one signs. `undefined` means the
|
|
105
|
+
* environment or development fallback is resolved on first use.
|
|
106
|
+
*/
|
|
107
|
+
secret?: readonly string[];
|
|
108
|
+
/** From the config, else the first plugin that provides one. */
|
|
109
|
+
ticketSubject?: TicketSubject;
|
|
110
|
+
maxExpiresIn: number;
|
|
111
|
+
maxRequestBodySize: number;
|
|
112
|
+
/** `false` in the config resolves to a logger with no methods. */
|
|
113
|
+
logger: DimahS3Logger;
|
|
114
|
+
onError?: DimahS3Config["onError"];
|
|
115
|
+
guard: HookList<Guard<GuardContext>>;
|
|
116
|
+
routes: Readonly<Record<string, ResolvedRoute>>;
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=resolved.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolved.d.ts","sourceRoot":"","sources":["../../src/types/resolved.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EACV,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,UAAU,CAAC;AAClB,OAA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,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACnC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IACrC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;CACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimah-s3/server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Presigned S3 server — dimahS3() with HTTP handler and direct api for upload, download, delete, and multipart",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"s3",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"sveltekit",
|
|
26
26
|
"typescript"
|
|
27
27
|
],
|
|
28
|
-
"homepage": "https://s3.dimah.dev/docs/server",
|
|
28
|
+
"homepage": "https://v2.s3.dimah.dev/docs/server",
|
|
29
29
|
"bugs": {
|
|
30
30
|
"url": "https://github.com/dimah-kz/dimah-s3/issues"
|
|
31
31
|
},
|
|
@@ -74,31 +74,27 @@
|
|
|
74
74
|
"./plugins": {
|
|
75
75
|
"types": "./dist/plugins.d.ts",
|
|
76
76
|
"default": "./dist/plugins.js"
|
|
77
|
-
},
|
|
78
|
-
"./api": {
|
|
79
|
-
"types": "./dist/api/index.d.ts",
|
|
80
|
-
"default": "./dist/api/index.js"
|
|
81
77
|
}
|
|
82
78
|
},
|
|
83
79
|
"files": [
|
|
84
80
|
"dist"
|
|
85
81
|
],
|
|
86
82
|
"dependencies": {
|
|
87
|
-
"@aws-sdk/s3-presigned-post": "^3.
|
|
88
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
89
|
-
"@dimah-s3/core": "
|
|
83
|
+
"@aws-sdk/s3-presigned-post": "^3.1161.0",
|
|
84
|
+
"@aws-sdk/s3-request-presigner": "^3.1161.0",
|
|
85
|
+
"@dimah-s3/core": "2.0.0-beta.1",
|
|
90
86
|
"better-call": "1.4.4",
|
|
91
87
|
"zod": "^4.6.7"
|
|
92
88
|
},
|
|
93
89
|
"devDependencies": {
|
|
94
|
-
"@aws-sdk/client-s3": "^3.
|
|
90
|
+
"@aws-sdk/client-s3": "^3.1161.0",
|
|
95
91
|
"@types/node": "^26.6.6",
|
|
96
92
|
"@workspace/eslint-config": "0.0.1",
|
|
97
93
|
"@workspace/tsup-config": "0.0.0",
|
|
98
94
|
"@workspace/typescript-config": "0.0.1",
|
|
99
95
|
"@workspace/vitest-config": "0.0.7",
|
|
100
|
-
"eslint": "^10.
|
|
101
|
-
"tsc-alias": "^1.9.
|
|
96
|
+
"eslint": "^10.14.0",
|
|
97
|
+
"tsc-alias": "^1.9.10",
|
|
102
98
|
"tsup": "^9.0.0",
|
|
103
99
|
"typescript": "7.0.2",
|
|
104
100
|
"vitest": "^5.0.5"
|