@dimah-s3/core 1.7.1 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +32 -13
  2. package/dist/create-s3-client.d.ts +3 -0
  3. package/dist/create-s3-client.d.ts.map +1 -1
  4. package/dist/error-codes.d.ts +297 -29
  5. package/dist/error-codes.d.ts.map +1 -1
  6. package/dist/error.d.ts +46 -14
  7. package/dist/error.d.ts.map +1 -1
  8. package/dist/helpers/base64url.d.ts +18 -0
  9. package/dist/helpers/base64url.d.ts.map +1 -0
  10. package/dist/helpers/build-content-disposition.d.ts +4 -4
  11. package/dist/helpers/build-content-disposition.d.ts.map +1 -1
  12. package/dist/helpers/checksum.d.ts +8 -2
  13. package/dist/helpers/checksum.d.ts.map +1 -1
  14. package/dist/helpers/content-type.d.ts +17 -0
  15. package/dist/helpers/content-type.d.ts.map +1 -0
  16. package/dist/helpers/fit-file-name.d.ts +15 -0
  17. package/dist/helpers/fit-file-name.d.ts.map +1 -0
  18. package/dist/helpers/index.d.ts +7 -9
  19. package/dist/helpers/index.d.ts.map +1 -1
  20. package/dist/helpers/magic-bytes.d.ts +9 -2
  21. package/dist/helpers/magic-bytes.d.ts.map +1 -1
  22. package/dist/helpers/normalize-object-key.d.ts +8 -3
  23. package/dist/helpers/normalize-object-key.d.ts.map +1 -1
  24. package/dist/helpers/parse-file-name.d.ts +5 -0
  25. package/dist/helpers/parse-file-name.d.ts.map +1 -1
  26. package/dist/helpers/resolve-inline-disposition.d.ts +16 -6
  27. package/dist/helpers/resolve-inline-disposition.d.ts.map +1 -1
  28. package/dist/helpers/validate-file.d.ts +13 -16
  29. package/dist/helpers/validate-file.d.ts.map +1 -1
  30. package/dist/index.d.ts +2 -2
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +711 -478
  33. package/dist/index.js.map +1 -1
  34. package/dist/limits.d.ts +30 -0
  35. package/dist/limits.d.ts.map +1 -0
  36. package/dist/plugin/create-s3-fetch.d.ts +5 -3
  37. package/dist/plugin/create-s3-fetch.d.ts.map +1 -1
  38. package/dist/plugin/types.d.ts +13 -4
  39. package/dist/plugin/types.d.ts.map +1 -1
  40. package/dist/routes.d.ts +10 -4
  41. package/dist/routes.d.ts.map +1 -1
  42. package/dist/schema/catalog.d.ts +30 -39
  43. package/dist/schema/catalog.d.ts.map +1 -1
  44. package/dist/schema/delete.d.ts +1 -2
  45. package/dist/schema/delete.d.ts.map +1 -1
  46. package/dist/schema/download.d.ts +16 -3
  47. package/dist/schema/download.d.ts.map +1 -1
  48. package/dist/schema/index.d.ts +5 -9
  49. package/dist/schema/index.d.ts.map +1 -1
  50. package/dist/schema/index.js +221 -0
  51. package/dist/schema/index.js.map +1 -0
  52. package/dist/schema/multipart.d.ts +6 -29
  53. package/dist/schema/multipart.d.ts.map +1 -1
  54. package/dist/schema/shared.d.ts +25 -17
  55. package/dist/schema/shared.d.ts.map +1 -1
  56. package/dist/schema/upload.d.ts +10 -7
  57. package/dist/schema/upload.d.ts.map +1 -1
  58. package/dist/types/index.d.ts +2 -2
  59. package/dist/types/index.d.ts.map +1 -1
  60. package/dist/types/requests.d.ts +25 -31
  61. package/dist/types/requests.d.ts.map +1 -1
  62. package/dist/types/responses.d.ts +96 -83
  63. package/dist/types/responses.d.ts.map +1 -1
  64. package/package.json +9 -4
  65. package/dist/helpers/format-file-size.d.ts +0 -18
  66. package/dist/helpers/format-file-size.d.ts.map +0 -1
  67. package/dist/helpers/sanitize-file-name.d.ts +0 -3
  68. package/dist/helpers/sanitize-file-name.d.ts.map +0 -1
  69. package/dist/helpers/truncate-file-name.d.ts +0 -5
  70. package/dist/helpers/truncate-file-name.d.ts.map +0 -1
  71. package/dist/schema/error.d.ts +0 -14
  72. package/dist/schema/error.d.ts.map +0 -1
  73. package/dist/schema/file.d.ts +0 -12
  74. package/dist/schema/file.d.ts.map +0 -1
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Bidi embedding, override and isolate controls (U+202A to U+202E, U+2066
3
+ * to U+2069). They can make `x{U+202E}fdp.exe` read as `xexe.pdf`. Other
4
+ * format characters, such as the joiner in emoji, are kept.
5
+ */
6
+ export declare const BIDI_CONTROL: RegExp;
7
+ /**
8
+ * Fit a file name to the wire rule for `name`: lone surrogates replaced,
9
+ * control and bidi characters removed, trimmed, and at most
10
+ * {@link S3_MAX_FILE_FIELD_BYTES} UTF-8 bytes. A longer name is cut on a
11
+ * character boundary and keeps a short extension. A name that is already
12
+ * valid comes back unchanged; an empty result is `"file"`.
13
+ */
14
+ export declare function fitFileName(name: string): string;
15
+ //# sourceMappingURL=fit-file-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fit-file-name.d.ts","sourceRoot":"","sources":["../../src/helpers/fit-file-name.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAkC,CAAC;AA6C5D;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkBhD"}
@@ -1,17 +1,15 @@
1
1
  export { matchesFileTypes, validateFile } from "./validate-file";
2
- export type { ValidateFileError, ValidateFileErrorCode } from "./validate-file";
3
2
  export { buildObjectKey } from "./build-object-key";
4
3
  export { parseFileName, fileNameFromKey, resolveStoredFileName, } from "./parse-file-name";
5
- export { formatFileSize } from "./format-file-size";
6
- export type { FileSizeUnit, FormatFileSizeOptions } from "./format-file-size";
4
+ export { describeFileType, effectiveContentType } from "./content-type";
7
5
  export { buildContentDisposition } from "./build-content-disposition";
8
6
  export type { ContentDispositionType } from "./build-content-disposition";
9
- export { resolveInlineDisposition } from "./resolve-inline-disposition";
7
+ export { DEFAULT_INLINE_TYPES, resolveInlineDisposition, } from "./resolve-inline-disposition";
10
8
  export type { ResolveInlineDispositionInput, ResolveInlineDispositionResult, } from "./resolve-inline-disposition";
11
- export { sanitizeFileName } from "./sanitize-file-name";
12
- export { truncateFileName } from "./truncate-file-name";
13
- export { normalizeObjectKey, S3_MAX_OBJECT_KEY_LENGTH, } from "./normalize-object-key";
14
- export { sha256Base64, sha256File } from "./checksum";
15
- export { matchesMagicBytes, sniffContentType } from "./magic-bytes";
9
+ export { fitFileName } from "./fit-file-name";
10
+ export { normalizeObjectKey, objectKeyByteLength, S3_MAX_OBJECT_KEY_BYTES, } from "./normalize-object-key";
11
+ export { sha256Base64, sha256Blob } from "./checksum";
12
+ export { base64UrlDecode, base64UrlEncode } from "./base64url";
13
+ export { isSniffableType, matchesMagicBytes, SNIFF_BYTE_LENGTH, sniffContentType, } from "./magic-bytes";
16
14
  export { buildPublicObjectUrl } from "./public-object-url";
17
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACjE,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,YAAY,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,eAAe,EACf,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,YAAY,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,11 +1,18 @@
1
+ /** Bytes to read from the start of an object before sniffing it. */
2
+ export declare const SNIFF_BYTE_LENGTH = 4096;
1
3
  /**
2
4
  * Sniff a MIME type from the start of a file. Returns `undefined` when
3
5
  * the prefix is unknown — this is not a substitute for `fileTypes`.
4
6
  */
5
7
  export declare function sniffContentType(bytes: Uint8Array): string | undefined;
6
8
  /**
7
- * Whether `bytes` match `expected` (exact MIME or `image/*`).
8
- * Unknown prefixes return `false`.
9
+ * Whether {@link matchesMagicBytes} can verify a declared `type`. Types with
10
+ * no known signature (such as `text/plain`) return `false`.
11
+ */
12
+ export declare function isSniffableType(type: string): boolean;
13
+ /**
14
+ * Whether `bytes` match `expected` (exact MIME or `type/*`). Common aliases
15
+ * count, so `audio/x-wav` matches a WAV file. Unknown prefixes return `false`.
9
16
  */
10
17
  export declare function matchesMagicBytes(bytes: Uint8Array, expected: string): boolean;
11
18
  //# sourceMappingURL=magic-bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"magic-bytes.d.ts","sourceRoot":"","sources":["../../src/helpers/magic-bytes.ts"],"names":[],"mappings":"AAyBA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAUtE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAOT"}
1
+ {"version":3,"file":"magic-bytes.d.ts","sourceRoot":"","sources":["../../src/helpers/magic-bytes.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAyOtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAEtE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAUT"}
@@ -1,8 +1,13 @@
1
- /** S3 object key maximum (1024 bytes). */
2
- export declare const S3_MAX_OBJECT_KEY_LENGTH = 1024;
1
+ /** S3 object key maximum, in UTF-8 bytes. */
2
+ export declare const S3_MAX_OBJECT_KEY_BYTES = 1024;
3
+ /** Length of an object key in UTF-8 bytes, the unit S3 limits keys in. */
4
+ export declare function objectKeyByteLength(key: string): number;
3
5
  /**
4
6
  * Strip leading/trailing slashes and reject `.` / `..` / empty segments,
5
- * NUL, backslashes, and oversized keys. Returns `null` when the key is unsafe.
7
+ * control characters, backslashes, lone surrogates, whitespace around the
8
+ * key, and keys over {@link S3_MAX_OBJECT_KEY_BYTES}. Returns `null` when
9
+ * the key is unsafe. A key is never trimmed: `a.pdf ` and `a.pdf` are two
10
+ * objects, so a key that differs from its trimmed form is refused.
6
11
  */
7
12
  export declare function normalizeObjectKey(key: string): string | null;
8
13
  //# sourceMappingURL=normalize-object-key.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-object-key.d.ts","sourceRoot":"","sources":["../../src/helpers/normalize-object-key.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU7D"}
1
+ {"version":3,"file":"normalize-object-key.d.ts","sourceRoot":"","sources":["../../src/helpers/normalize-object-key.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAI5C,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAKD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAa7D"}
@@ -1,3 +1,8 @@
1
+ /**
2
+ * The file name of a `Content-Disposition` value (RFC 6266), whoever wrote
3
+ * it: the UTF-8 `filename*` first, then a quoted `filename` with its
4
+ * escapes undone, then a bare token. `undefined` when it names none.
5
+ */
1
6
  export declare function parseFileName(contentDisposition: string | null | undefined): string | undefined;
2
7
  /** Last path segment of an object key (`uploads/uuid/a.png` → `a.png`). */
3
8
  export declare function fileNameFromKey(key: string): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-file-name.d.ts","sourceRoot":"","sources":["../../src/helpers/parse-file-name.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC5C,MAAM,GAAG,SAAS,CAcpB;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7C,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAEpB"}
1
+ {"version":3,"file":"parse-file-name.d.ts","sourceRoot":"","sources":["../../src/helpers/parse-file-name.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC5C,MAAM,GAAG,SAAS,CAepB;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7C,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAEpB"}
@@ -1,17 +1,26 @@
1
1
  import type { ContentDispositionType } from "./build-content-disposition";
2
+ /**
3
+ * Types that open in the browser by default: raster images, PDF, audio,
4
+ * video, and plain text. Never HTML, SVG, or other active content.
5
+ */
6
+ export declare const DEFAULT_INLINE_TYPES: readonly string[];
2
7
  /** Input for {@link resolveInlineDisposition}. */
3
8
  export type ResolveInlineDispositionInput = {
4
9
  /** Stored type, such as HeadObject `ContentType`. */
5
10
  contentType?: string;
6
- /** Used for the type when `contentType` is missing or `application/octet-stream`. */
11
+ /**
12
+ * Used for the type when `contentType` is missing, empty,
13
+ * `application/octet-stream` or `binary/octet-stream`.
14
+ */
7
15
  fileName?: string;
8
16
  /**
9
17
  * MIME types, or `type/*` wildcards, that may open in the browser.
10
18
  * File extensions are not accepted: the name does not decide what renders.
11
- * A wildcard never matches HTML, XML (including `image/svg+xml`), or
12
- * JavaScript; list those types exactly to allow them.
19
+ * A wildcard never matches HTML, XML (including `image/svg+xml` and
20
+ * `text/xsl`), or JavaScript; list those types exactly to allow them.
21
+ * Omitted: {@link DEFAULT_INLINE_TYPES}. `false`: never inline.
13
22
  */
14
- allow: readonly string[];
23
+ allow?: readonly string[] | false;
15
24
  /** Client request or route default. */
16
25
  requested?: ContentDispositionType;
17
26
  };
@@ -28,8 +37,9 @@ export type ResolveInlineDispositionResult = {
28
37
  /**
29
38
  * Whether an object may open in the browser. `inline` is kept only when the
30
39
  * object's type is on `allow`; anything else is signed as `attachment`.
31
- * `download.inlineTypes` on a route runs this on presign and `/file`, and a
32
- * client can call it with the same list to choose Preview or Download.
40
+ * The server runs this on presign and `/file` with the route's inline list,
41
+ * and a client can call it with the catalog `inlineTypes` to choose Preview
42
+ * or Download.
33
43
  */
34
44
  export declare function resolveInlineDisposition(input: ResolveInlineDispositionInput): ResolveInlineDispositionResult;
35
45
  //# sourceMappingURL=resolve-inline-disposition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-inline-disposition.d.ts","sourceRoot":"","sources":["../../src/helpers/resolve-inline-disposition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AA4E1E,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,uCAAuC;IACvC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,sBAAsB,CAAC;IACpC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,6BAA6B,GACnC,8BAA8B,CAWhC"}
1
+ {"version":3,"file":"resolve-inline-disposition.d.ts","sourceRoot":"","sources":["../../src/helpers/resolve-inline-disposition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAG1E;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAWjD,CAAC;AA2BF,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC;IAClC,uCAAuC;IACvC,SAAS,CAAC,EAAE,sBAAsB,CAAC;CACpC,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,sBAAsB,CAAC;IACpC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,6BAA6B,GACnC,8BAA8B,CAahC"}
@@ -1,24 +1,21 @@
1
- /** Machine-readable codes for client-side file validation failures. */
2
- export type ValidateFileErrorCode = "FILE_TYPE_NOT_ALLOWED" | "FILE_EMPTY" | "FILE_TOO_LARGE";
3
- /** Result of {@link validateFile} when the file fails a check. */
4
- export type ValidateFileError = {
5
- code: ValidateFileErrorCode;
6
- /** English fallback message (localize via Fuma when a translator is available). */
7
- message: string;
8
- /** Interpolation params for i18n (e.g. `{ type }`, `{ size }`). */
9
- params?: Record<string, string | number>;
10
- };
1
+ import { type APIError } from "../error";
11
2
  /**
12
3
  * Whether `fileName` / `contentType` match HTML `accept` / route `fileTypes`
13
- * tokens (`image/*`, `application/pdf`, `.png`).
4
+ * tokens (`image/*`, `application/pdf`, `.png`). Like a browser, it
5
+ * ignores case and type parameters (`image/PNG; x=1` is `image/png`), and
6
+ * a bare `*`, or the any-type wildcard, accepts any file.
14
7
  */
15
8
  export declare function matchesFileTypes(fileName: string, contentType: string | undefined, fileTypes: readonly string[]): boolean;
16
9
  /**
17
- * Client-side accept / size / empty checks before starting an upload.
18
- * Returns `null` when the file is valid.
10
+ * Client-side accept / empty / size checks before starting an upload.
11
+ * Returns `null` when the file is valid, otherwise a catalog error:
12
+ * `FILE_TYPE_NOT_ALLOWED`, `FILE_EMPTY`, or `FILE_TOO_LARGE`.
13
+ * The name is not checked: `fitFileName` fits it to the wire rule.
19
14
  */
20
- export declare function validateFile(file: File, options: {
21
- accept?: string[];
15
+ export declare function validateFile(file: Blob & {
16
+ name: string;
17
+ }, options: {
18
+ accept?: readonly string[];
22
19
  maxFileSize?: number;
23
- }): ValidateFileError | null;
20
+ }): APIError | null;
24
21
  //# sourceMappingURL=validate-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate-file.d.ts","sourceRoot":"","sources":["../../src/helpers/validate-file.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,MAAM,qBAAqB,GAC/B,uBAAuB,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAE5D,kEAAkE;AAClE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,OAAO,CAYT;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,iBAAiB,GAAG,IAAI,CAiC1B"}
1
+ {"version":3,"file":"validate-file.d.ts","sourceRoot":"","sources":["../../src/helpers/validate-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGlD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,OAAO,CAWT;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAC7B,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D,QAAQ,GAAG,IAAI,CAejB"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type * from "./types";
2
2
  export * from "./helpers";
3
- export * from "./schema";
4
- export { APIError, defineErrorCodes, isAPIError, isS3ErrorCode, S3_ERROR_CODES, type S3ErrorCode, } from "./error";
3
+ export * from "./limits";
4
+ export { APIError, defineErrorCodes, formatErrorMessage, isAPIError, isS3ErrorCode, s3Error, S3_ERROR_CODES, type APIErrorBody, type APIErrorStatus, type S3ClientErrorCode, type S3ErrorCode, type S3ErrorEntry, type S3ErrorOptions, type S3ErrorParams, type S3ErrorParamsMap, type S3ErrorShape, type S3ServerErrorCode, } from "./error";
5
5
  export { S3_API_BASE_PATH, normalizeS3ApiBasePath, S3_API_ROUTES, } from "./routes";
6
6
  export { createS3Client, type CreateS3ClientOptions, type CreateS3ClientResult, } from "./create-s3-client";
7
7
  export { createS3Fetch, defineClientPlugin, pluginPath, RESERVED_CLIENT_KEYS, } from "./plugin";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,cAAc,EACd,KAAK,WAAW,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,OAAO,GACR,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,OAAO,EACP,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,UAAU,EACV,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,OAAO,GACR,MAAM,UAAU,CAAC"}