@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/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { S3_API_ROUTES, isAPIError, DimahS3Error, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, isDimahS3Error, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, resolveStoredFileName, S3_MAX_EXPIRES_IN, buildContentDisposition, S3_MAX_POST_OBJECT_BYTES, normalizeS3ApiBasePath, S3_API_BASE_PATH, matchesFileTypes, S3_DEFAULT_EXPIRES_IN, normalizeObjectKey, sanitizeFileName, ROUTE_NAME_PATTERN } from '@dimah-s3/core';
2
- export { DimahS3Error, S3_ERROR_CODES, isAPIError, isDimahS3Error, isS3ErrorCode } from '@dimah-s3/core';
1
+ import { S3_API_ROUTES, isAPIError, APIError, S3_ERROR_CODES, confirmBodySchema, deleteQuerySchema, deleteBatchBodySchema, downloadQuerySchema, fileQuerySchema, multipartAbortBodySchema, multipartCompleteBodySchema, multipartInitBodySchema, multipartListPartsQuerySchema, multipartSignPartBodySchema, uploadBodySchema, resolveStoredFileName, S3_MAX_EXPIRES_IN, buildContentDisposition, S3_MAX_POST_OBJECT_BYTES, normalizeS3ApiBasePath, S3_API_BASE_PATH, matchesFileTypes, S3_DEFAULT_EXPIRES_IN, normalizeObjectKey, sanitizeFileName, ROUTE_NAME_PATTERN } from '@dimah-s3/core';
2
+ export { APIError, S3_ERROR_CODES, isAPIError, isS3ErrorCode } from '@dimah-s3/core';
3
3
  import { PutObjectCommand, DeleteObjectCommand, GetObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, ListPartsCommand, AbortMultipartUploadCommand, CompleteMultipartUploadCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
4
4
  import { createMiddleware, createEndpoint, createRouter, toResponse } from 'better-call';
5
5
  import * as z from 'zod';
@@ -31,13 +31,13 @@ async function abortMultipartBestEffort(client, bucket, key, uploadId) {
31
31
  }
32
32
  }
33
33
  var errors = {
34
- notFound: () => DimahS3Error.from("NOT_FOUND", S3_ERROR_CODES.NOT_FOUND),
35
- unauthorized: () => DimahS3Error.from("UNAUTHORIZED", S3_ERROR_CODES.UNAUTHORIZED),
36
- forbidden: () => DimahS3Error.from("FORBIDDEN", S3_ERROR_CODES.FORBIDDEN),
37
- conflict: () => DimahS3Error.from("CONFLICT", S3_ERROR_CODES.CONFLICT),
38
- internalError: () => DimahS3Error.from("INTERNAL_SERVER_ERROR", S3_ERROR_CODES.INTERNAL_ERROR),
39
- objectNotFound: () => DimahS3Error.from("NOT_FOUND", S3_ERROR_CODES.OBJECT_NOT_FOUND),
40
- featureDisabled: (feature) => DimahS3Error.from("NOT_FOUND", {
34
+ notFound: () => APIError.from("NOT_FOUND", S3_ERROR_CODES.NOT_FOUND),
35
+ unauthorized: () => APIError.from("UNAUTHORIZED", S3_ERROR_CODES.UNAUTHORIZED),
36
+ forbidden: () => APIError.from("FORBIDDEN", S3_ERROR_CODES.FORBIDDEN),
37
+ conflict: () => APIError.from("CONFLICT", S3_ERROR_CODES.CONFLICT),
38
+ internalError: () => APIError.from("INTERNAL_SERVER_ERROR", S3_ERROR_CODES.INTERNAL_ERROR),
39
+ objectNotFound: () => APIError.from("NOT_FOUND", S3_ERROR_CODES.OBJECT_NOT_FOUND),
40
+ featureDisabled: (feature) => APIError.from("NOT_FOUND", {
41
41
  code: S3_ERROR_CODES.FEATURE_DISABLED.code,
42
42
  message: S3_ERROR_CODES.FEATURE_DISABLED.message.replaceAll(
43
43
  "{feature}",
@@ -45,13 +45,13 @@ var errors = {
45
45
  ),
46
46
  params: { feature }
47
47
  }),
48
- invalidKey: () => DimahS3Error.from("BAD_REQUEST", S3_ERROR_CODES.INVALID_KEY),
49
- unknownRoute: (route2) => DimahS3Error.from("NOT_FOUND", {
48
+ invalidKey: () => APIError.from("BAD_REQUEST", S3_ERROR_CODES.INVALID_KEY),
49
+ unknownRoute: (route2) => APIError.from("NOT_FOUND", {
50
50
  code: S3_ERROR_CODES.UNKNOWN_ROUTE.code,
51
51
  message: S3_ERROR_CODES.UNKNOWN_ROUTE.message,
52
52
  params: { route: route2 }
53
53
  }),
54
- fileTypeNotAllowed: (fileName, contentType) => DimahS3Error.from("BAD_REQUEST", {
54
+ fileTypeNotAllowed: (fileName, contentType) => APIError.from("BAD_REQUEST", {
55
55
  code: S3_ERROR_CODES.FILE_TYPE_NOT_ALLOWED.code,
56
56
  message: S3_ERROR_CODES.FILE_TYPE_NOT_ALLOWED.message,
57
57
  params: {
@@ -59,7 +59,7 @@ var errors = {
59
59
  ...contentType ? { contentType } : {}
60
60
  }
61
61
  }),
62
- s3NetworkError: (code) => DimahS3Error.from("BAD_GATEWAY", {
62
+ s3NetworkError: (code) => APIError.from("BAD_GATEWAY", {
63
63
  code: S3_ERROR_CODES.S3_NETWORK_ERROR.code,
64
64
  message: S3_ERROR_CODES.S3_NETWORK_ERROR.message.replaceAll(
65
65
  "{code}",
@@ -67,7 +67,7 @@ var errors = {
67
67
  ),
68
68
  params: { code }
69
69
  }),
70
- multipartPartMissing: (partNumber) => DimahS3Error.from("BAD_REQUEST", {
70
+ multipartPartMissing: (partNumber) => APIError.from("BAD_REQUEST", {
71
71
  code: S3_ERROR_CODES.MULTIPART_PART_MISSING.code,
72
72
  message: S3_ERROR_CODES.MULTIPART_PART_MISSING.message.replaceAll(
73
73
  "{partNumber}",
@@ -75,15 +75,15 @@ var errors = {
75
75
  ),
76
76
  params: { partNumber }
77
77
  }),
78
- payloadTooLarge: (message = S3_ERROR_CODES.PAYLOAD_TOO_LARGE.message) => DimahS3Error.from("PAYLOAD_TOO_LARGE", {
78
+ payloadTooLarge: (message = S3_ERROR_CODES.PAYLOAD_TOO_LARGE.message) => APIError.from("PAYLOAD_TOO_LARGE", {
79
79
  ...S3_ERROR_CODES.PAYLOAD_TOO_LARGE,
80
80
  message
81
81
  }),
82
- quotaExceeded: (message = S3_ERROR_CODES.QUOTA_EXCEEDED.message) => DimahS3Error.from("PAYLOAD_TOO_LARGE", {
82
+ quotaExceeded: (message = S3_ERROR_CODES.QUOTA_EXCEEDED.message) => APIError.from("PAYLOAD_TOO_LARGE", {
83
83
  ...S3_ERROR_CODES.QUOTA_EXCEEDED,
84
84
  message
85
85
  }),
86
- validationError: (message) => DimahS3Error.from("BAD_REQUEST", {
86
+ validationError: (message) => APIError.from("BAD_REQUEST", {
87
87
  code: S3_ERROR_CODES.VALIDATION_ERROR.code,
88
88
  message
89
89
  })
@@ -128,7 +128,7 @@ function resolveLogger(logger) {
128
128
  function mapGuardError(err) {
129
129
  if (isAPIError(err)) throw err;
130
130
  if (err instanceof Error && err.message.trim()) {
131
- throw new DimahS3Error("FORBIDDEN", {
131
+ throw new APIError("FORBIDDEN", {
132
132
  message: err.message,
133
133
  cause: err
134
134
  });
@@ -756,7 +756,7 @@ var deleteBatch = createS3Endpoint(
756
756
  results.push({
757
757
  key,
758
758
  success: false,
759
- error: isDimahS3Error(err) ? { code: err.code ?? "INTERNAL_ERROR", message: err.message } : { code: "INTERNAL_ERROR", message: "Internal server error" }
759
+ error: isAPIError(err) ? { code: err.code ?? "INTERNAL_ERROR", message: err.message } : { code: "INTERNAL_ERROR", message: "Internal server error" }
760
760
  });
761
761
  }
762
762
  }