@dimah-s3/server 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/express.js +16 -16
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/fastify.js +16 -16
- package/dist/adapters/fastify.js.map +1 -1
- package/dist/adapters/node.js +16 -16
- package/dist/adapters/node.js.map +1 -1
- package/dist/api/create-s3-endpoint.d.ts +1 -1
- package/dist/api/index.js +18 -18
- package/dist/api/index.js.map +1 -1
- package/dist/errors.d.ts +17 -17
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/dist/plugins.js +18 -18
- package/dist/plugins.js.map +1 -1
- package/package.json +6 -6
package/dist/plugins.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S3_API_ROUTES, isAPIError,
|
|
1
|
+
import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, S3_MAX_EXPIRES_IN, buildContentDisposition, S3_MAX_POST_OBJECT_BYTES, resolveStoredFileName, S3_DEFAULT_EXPIRES_IN, matchesFileTypes, ROUTE_NAME_PATTERN, normalizeObjectKey, sanitizeFileName } from '@dimah-s3/core';
|
|
2
2
|
import { DeleteObjectCommand, GetObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, PutObjectCommand, ListPartsCommand, AbortMultipartUploadCommand, CompleteMultipartUploadCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
3
3
|
import { createMiddleware, createEndpoint } from 'better-call';
|
|
4
4
|
import * as z from 'zod';
|
|
@@ -25,13 +25,13 @@ async function abortMultipartBestEffort(client, bucket, key, uploadId) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
var errors = {
|
|
28
|
-
notFound: () =>
|
|
29
|
-
unauthorized: () =>
|
|
30
|
-
forbidden: () =>
|
|
31
|
-
conflict: () =>
|
|
32
|
-
internalError: () =>
|
|
33
|
-
objectNotFound: () =>
|
|
34
|
-
featureDisabled: (feature) =>
|
|
28
|
+
notFound: () => APIError.from("NOT_FOUND", S3_ERROR_CODES.NOT_FOUND),
|
|
29
|
+
unauthorized: () => APIError.from("UNAUTHORIZED", S3_ERROR_CODES.UNAUTHORIZED),
|
|
30
|
+
forbidden: () => APIError.from("FORBIDDEN", S3_ERROR_CODES.FORBIDDEN),
|
|
31
|
+
conflict: () => APIError.from("CONFLICT", S3_ERROR_CODES.CONFLICT),
|
|
32
|
+
internalError: () => APIError.from("INTERNAL_SERVER_ERROR", S3_ERROR_CODES.INTERNAL_ERROR),
|
|
33
|
+
objectNotFound: () => APIError.from("NOT_FOUND", S3_ERROR_CODES.OBJECT_NOT_FOUND),
|
|
34
|
+
featureDisabled: (feature) => APIError.from("NOT_FOUND", {
|
|
35
35
|
code: S3_ERROR_CODES.FEATURE_DISABLED.code,
|
|
36
36
|
message: S3_ERROR_CODES.FEATURE_DISABLED.message.replaceAll(
|
|
37
37
|
"{feature}",
|
|
@@ -39,13 +39,13 @@ var errors = {
|
|
|
39
39
|
),
|
|
40
40
|
params: { feature }
|
|
41
41
|
}),
|
|
42
|
-
invalidKey: () =>
|
|
43
|
-
unknownRoute: (route) =>
|
|
42
|
+
invalidKey: () => APIError.from("BAD_REQUEST", S3_ERROR_CODES.INVALID_KEY),
|
|
43
|
+
unknownRoute: (route) => APIError.from("NOT_FOUND", {
|
|
44
44
|
code: S3_ERROR_CODES.UNKNOWN_ROUTE.code,
|
|
45
45
|
message: S3_ERROR_CODES.UNKNOWN_ROUTE.message,
|
|
46
46
|
params: { route }
|
|
47
47
|
}),
|
|
48
|
-
fileTypeNotAllowed: (fileName, contentType) =>
|
|
48
|
+
fileTypeNotAllowed: (fileName, contentType) => APIError.from("BAD_REQUEST", {
|
|
49
49
|
code: S3_ERROR_CODES.FILE_TYPE_NOT_ALLOWED.code,
|
|
50
50
|
message: S3_ERROR_CODES.FILE_TYPE_NOT_ALLOWED.message,
|
|
51
51
|
params: {
|
|
@@ -53,7 +53,7 @@ var errors = {
|
|
|
53
53
|
...contentType ? { contentType } : {}
|
|
54
54
|
}
|
|
55
55
|
}),
|
|
56
|
-
s3NetworkError: (code) =>
|
|
56
|
+
s3NetworkError: (code) => APIError.from("BAD_GATEWAY", {
|
|
57
57
|
code: S3_ERROR_CODES.S3_NETWORK_ERROR.code,
|
|
58
58
|
message: S3_ERROR_CODES.S3_NETWORK_ERROR.message.replaceAll(
|
|
59
59
|
"{code}",
|
|
@@ -61,7 +61,7 @@ var errors = {
|
|
|
61
61
|
),
|
|
62
62
|
params: { code }
|
|
63
63
|
}),
|
|
64
|
-
multipartPartMissing: (partNumber) =>
|
|
64
|
+
multipartPartMissing: (partNumber) => APIError.from("BAD_REQUEST", {
|
|
65
65
|
code: S3_ERROR_CODES.MULTIPART_PART_MISSING.code,
|
|
66
66
|
message: S3_ERROR_CODES.MULTIPART_PART_MISSING.message.replaceAll(
|
|
67
67
|
"{partNumber}",
|
|
@@ -69,15 +69,15 @@ var errors = {
|
|
|
69
69
|
),
|
|
70
70
|
params: { partNumber }
|
|
71
71
|
}),
|
|
72
|
-
payloadTooLarge: (message = S3_ERROR_CODES.PAYLOAD_TOO_LARGE.message) =>
|
|
72
|
+
payloadTooLarge: (message = S3_ERROR_CODES.PAYLOAD_TOO_LARGE.message) => APIError.from("PAYLOAD_TOO_LARGE", {
|
|
73
73
|
...S3_ERROR_CODES.PAYLOAD_TOO_LARGE,
|
|
74
74
|
message
|
|
75
75
|
}),
|
|
76
|
-
quotaExceeded: (message = S3_ERROR_CODES.QUOTA_EXCEEDED.message) =>
|
|
76
|
+
quotaExceeded: (message = S3_ERROR_CODES.QUOTA_EXCEEDED.message) => APIError.from("PAYLOAD_TOO_LARGE", {
|
|
77
77
|
...S3_ERROR_CODES.QUOTA_EXCEEDED,
|
|
78
78
|
message
|
|
79
79
|
}),
|
|
80
|
-
validationError: (message) =>
|
|
80
|
+
validationError: (message) => APIError.from("BAD_REQUEST", {
|
|
81
81
|
code: S3_ERROR_CODES.VALIDATION_ERROR.code,
|
|
82
82
|
message
|
|
83
83
|
})
|
|
@@ -122,7 +122,7 @@ function resolveLogger(logger) {
|
|
|
122
122
|
function mapGuardError(err) {
|
|
123
123
|
if (isAPIError(err)) throw err;
|
|
124
124
|
if (err instanceof Error && err.message.trim()) {
|
|
125
|
-
throw new
|
|
125
|
+
throw new APIError("FORBIDDEN", {
|
|
126
126
|
message: err.message,
|
|
127
127
|
cause: err
|
|
128
128
|
});
|
|
@@ -696,7 +696,7 @@ var deleteBatch = createS3Endpoint(
|
|
|
696
696
|
results.push({
|
|
697
697
|
key,
|
|
698
698
|
success: false,
|
|
699
|
-
error:
|
|
699
|
+
error: isAPIError(err) ? { code: err.code ?? "INTERNAL_ERROR", message: err.message } : { code: "INTERNAL_ERROR", message: "Internal server error" }
|
|
700
700
|
});
|
|
701
701
|
}
|
|
702
702
|
}
|