@dimah-s3/core 0.1.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/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/create-s3-client.d.ts +29 -0
- package/dist/create-s3-client.d.ts.map +1 -0
- package/dist/error.d.ts +31 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/helpers/build-content-disposition.d.ts +8 -0
- package/dist/helpers/build-content-disposition.d.ts.map +1 -0
- package/dist/helpers/build-object-key.d.ts +2 -0
- package/dist/helpers/build-object-key.d.ts.map +1 -0
- package/dist/helpers/format-file-size.d.ts +2 -0
- package/dist/helpers/format-file-size.d.ts.map +1 -0
- package/dist/helpers/get-file-extension.d.ts +2 -0
- package/dist/helpers/get-file-extension.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +10 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/parse-file-name.d.ts +2 -0
- package/dist/helpers/parse-file-name.d.ts.map +1 -0
- package/dist/helpers/sanitize-file-name.d.ts +3 -0
- package/dist/helpers/sanitize-file-name.d.ts.map +1 -0
- package/dist/helpers/truncate-file-name.d.ts +7 -0
- package/dist/helpers/truncate-file-name.d.ts.map +1 -0
- package/dist/helpers/validate-file.d.ts +19 -0
- package/dist/helpers/validate-file.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +340 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/plugin/create-fetcher.d.ts +10 -0
- package/dist/plugin/create-fetcher.d.ts.map +1 -0
- package/dist/plugin/define-client-plugin.d.ts +18 -0
- package/dist/plugin/define-client-plugin.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +5 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/plugin-endpoint-path.d.ts +9 -0
- package/dist/plugin/plugin-endpoint-path.d.ts.map +1 -0
- package/dist/plugin/types.d.ts +46 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/routes.d.ts +15 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/requests.d.ts +98 -0
- package/dist/types/requests.d.ts.map +1 -0
- package/dist/types/responses.d.ts +136 -0
- package/dist/types/responses.d.ts.map +1 -0
- package/dist/types/upload-presign-method.d.ts +3 -0
- package/dist/types/upload-presign-method.d.ts.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hamidreza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @dimah-s3/core
|
|
2
|
+
|
|
3
|
+
Shared protocol, typed API client, and pure helpers used by `@dimah-s3/server` and `@dimah-s3/react`.
|
|
4
|
+
|
|
5
|
+
Full documentation: [dimah-s3-docs.vercel.app](https://dimah-s3-docs.vercel.app/docs/quickstart)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @dimah-s3/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Minimal setup
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createS3Client, DimahS3Error } from "@dimah-s3/core";
|
|
17
|
+
|
|
18
|
+
export const api = createS3Client({
|
|
19
|
+
// optional: auth for core routes + client plugins
|
|
20
|
+
credentials: "include",
|
|
21
|
+
headers: () => ({ Authorization: `Bearer ${token}` }),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
await api.download(key);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
if (err instanceof DimahS3Error) console.error(err.status, err.message);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For React apps, prefer `createS3Client` from `@dimah-s3/react` (returns `api` + bound `S3Provider` / `useApi`).
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { S3Api } from "./types";
|
|
2
|
+
import { type ClientPluginMethodsMap, type S3ClientFetchOptions, type S3ClientPlugin } from "./plugin";
|
|
3
|
+
/** Options for {@link createS3Client}. */
|
|
4
|
+
export type CreateS3ClientOptions<P extends readonly S3ClientPlugin[] = readonly S3ClientPlugin[]> = {
|
|
5
|
+
/** API path prefix — must match server `basePath`. @default "/api/s3" */
|
|
6
|
+
basePath?: string;
|
|
7
|
+
/** Client plugins (e.g. `dbClient()` from `@dimah-s3/db/client`). */
|
|
8
|
+
plugins?: P;
|
|
9
|
+
} & S3ClientFetchOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Browser (or isomorphic) client for the dimah-s3 HTTP API.
|
|
12
|
+
*
|
|
13
|
+
* For React apps prefer `createS3Client` from `@dimah-s3/react` — same options,
|
|
14
|
+
* plus a bound `S3Provider` / typed `useApi`.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createS3Client } from "@dimah-s3/core";
|
|
18
|
+
* import { dbClient } from "@dimah-s3/db/client";
|
|
19
|
+
*
|
|
20
|
+
* export const api = createS3Client({
|
|
21
|
+
* basePath: "/api/s3",
|
|
22
|
+
* plugins: [dbClient()],
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* await api.db.listObjects();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createS3Client<const P extends readonly S3ClientPlugin[] = []>(options?: CreateS3ClientOptions<P>): S3Api & ClientPluginMethodsMap<P>;
|
|
29
|
+
//# sourceMappingURL=create-s3-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-s3-client.d.ts","sourceRoot":"","sources":["../src/create-s3-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAQV,KAAK,EAGN,MAAM,SAAS,CAAC;AAEjB,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACpB,MAAM,UAAU,CAAC;AAOlB,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,SAAS,cAAc,EAAE,GAAG,SAAS,cAAc,EAAE,IAC7D;IACF,yEAAyE;IACzE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,OAAO,CAAC,EAAE,CAAC,CAAC;CACb,GAAG,oBAAoB,CAAC;AAUzB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,GAAG,EAAE,EAC3E,OAAO,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,GACjC,KAAK,GAAG,sBAAsB,CAAC,CAAC,CAAC,CA0FnC"}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Stable API error codes returned in JSON `{ code, message, params? }`. */
|
|
2
|
+
export declare const S3_ERROR_CODES: {
|
|
3
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
4
|
+
readonly INVALID_JSON: "INVALID_JSON";
|
|
5
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
6
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
7
|
+
readonly OBJECT_NOT_FOUND: "OBJECT_NOT_FOUND";
|
|
8
|
+
readonly S3_NETWORK_ERROR: "S3_NETWORK_ERROR";
|
|
9
|
+
readonly FIELD_REQUIRED: "FIELD_REQUIRED";
|
|
10
|
+
readonly KEY_REQUIRED: "KEY_REQUIRED";
|
|
11
|
+
readonly UPLOAD_ID_REQUIRED: "UPLOAD_ID_REQUIRED";
|
|
12
|
+
readonly PART_NUMBER_INVALID: "PART_NUMBER_INVALID";
|
|
13
|
+
readonly PARTS_REQUIRED: "PARTS_REQUIRED";
|
|
14
|
+
readonly FILE_SIZE_REQUIRED_UPLOAD: "FILE_SIZE_REQUIRED_UPLOAD";
|
|
15
|
+
readonly FILE_SIZE_REQUIRED_MULTIPART: "FILE_SIZE_REQUIRED_MULTIPART";
|
|
16
|
+
};
|
|
17
|
+
export type S3ErrorCode = (typeof S3_ERROR_CODES)[keyof typeof S3_ERROR_CODES];
|
|
18
|
+
export type DimahS3ErrorParams = Record<string, string | number>;
|
|
19
|
+
export type DimahS3ErrorOptions = {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
code?: S3ErrorCode | string;
|
|
22
|
+
params?: DimahS3ErrorParams;
|
|
23
|
+
};
|
|
24
|
+
/** Typed API / procedure error with HTTP status and optional stable code. */
|
|
25
|
+
export declare class DimahS3Error extends Error {
|
|
26
|
+
readonly status: number;
|
|
27
|
+
readonly code?: S3ErrorCode | string;
|
|
28
|
+
readonly params?: DimahS3ErrorParams;
|
|
29
|
+
constructor(message: string, status?: number, options?: DimahS3ErrorOptions);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,eAAO,MAAM,cAAc;aACzB,SAAS,EAAE,WAAW;aACtB,YAAY,EAAE,cAAc;aAC5B,SAAS,EAAE,WAAW;aACtB,cAAc,EAAE,gBAAgB;aAChC,gBAAgB,EAAE,kBAAkB;aACpC,gBAAgB,EAAE,kBAAkB;aACpC,cAAc,EAAE,gBAAgB;aAChC,YAAY,EAAE,cAAc;aAC5B,kBAAkB,EAAE,oBAAoB;aACxC,mBAAmB,EAAE,qBAAqB;aAC1C,cAAc,EAAE,gBAAgB;aAChC,yBAAyB,EAAE,2BAA2B;aACtD,4BAA4B,EAAE,8BAA8B;CACpD,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAE/E,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B,CAAC;AAEF,6EAA6E;AAC7E,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAErC,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,SAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,EASvE;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a RFC 6266 `Content-Disposition` value for a file attachment.
|
|
3
|
+
*
|
|
4
|
+
* Includes both the ASCII-safe `filename` fallback and the RFC 5987
|
|
5
|
+
* `filename*` parameter for full Unicode support.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildContentDisposition(fileName: string): string;
|
|
8
|
+
//# sourceMappingURL=build-content-disposition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-content-disposition.d.ts","sourceRoot":"","sources":["../../src/helpers/build-content-disposition.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-object-key.d.ts","sourceRoot":"","sources":["../../src/helpers/build-object-key.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAKzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-file-size.d.ts","sourceRoot":"","sources":["../../src/helpers/format-file-size.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-file-extension.d.ts","sourceRoot":"","sources":["../../src/helpers/get-file-extension.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIzD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { validateFile } from "./validate-file";
|
|
2
|
+
export type { ValidateFileError, ValidateFileErrorCode } from "./validate-file";
|
|
3
|
+
export { buildObjectKey } from "./build-object-key";
|
|
4
|
+
export { getFileExtension } from "./get-file-extension";
|
|
5
|
+
export { parseFileName } from "./parse-file-name";
|
|
6
|
+
export { formatFileSize } from "./format-file-size";
|
|
7
|
+
export { buildContentDisposition } from "./build-content-disposition";
|
|
8
|
+
export { sanitizeFileName } from "./sanitize-file-name";
|
|
9
|
+
export { truncateFileName, truncateFilename } from "./truncate-file-name";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,YAAY,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize-file-name.d.ts","sourceRoot":"","sources":["../../src/helpers/sanitize-file-name.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncates a filename while preserving the extension when possible.
|
|
3
|
+
*/
|
|
4
|
+
export declare function truncateFileName(name: string, maxChars?: number): string;
|
|
5
|
+
/** @deprecated Use {@link truncateFileName}. */
|
|
6
|
+
export declare const truncateFilename: typeof truncateFileName;
|
|
7
|
+
//# sourceMappingURL=truncate-file-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate-file-name.d.ts","sourceRoot":"","sources":["../../src/helpers/truncate-file-name.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAK,GAAG,MAAM,CAYpE;AAED,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,yBAAmB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Client-side accept / size / empty checks before starting an upload.
|
|
13
|
+
* Returns `null` when the file is valid.
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateFile(file: File, options: {
|
|
16
|
+
accept?: string[];
|
|
17
|
+
maxFileSize?: number;
|
|
18
|
+
}): ValidateFileError | null;
|
|
19
|
+
//# sourceMappingURL=validate-file.d.ts.map
|
|
@@ -0,0 +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,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,CAuC1B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./helpers";
|
|
3
|
+
export { DimahS3Error, S3_ERROR_CODES, type S3ErrorCode, type DimahS3ErrorParams, type DimahS3ErrorOptions, } from "./error";
|
|
4
|
+
export { S3_API_BASE_PATH, normalizeS3ApiBasePath, S3_API_ROUTES, } from "./routes";
|
|
5
|
+
export { createS3Client, type CreateS3ClientOptions } from "./create-s3-client";
|
|
6
|
+
export { createFetcher, defineClientPlugin, pluginEndpointPath, RESERVED_CLIENT_KEYS, } from "./plugin";
|
|
7
|
+
export type { ClientPluginMethodsMap, ReservedClientKey, S3ClientFetcher, S3ClientFetchOptions, S3ClientPlugin, } from "./plugin";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,sBAAsB,EACtB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,cAAc,GACf,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// src/helpers/validate-file.ts
|
|
2
|
+
function validateFile(file, options) {
|
|
3
|
+
if (options.accept?.length) {
|
|
4
|
+
const allowed = options.accept.some((type) => {
|
|
5
|
+
if (type.startsWith(".")) {
|
|
6
|
+
return file.name.toLowerCase().endsWith(type.toLowerCase());
|
|
7
|
+
}
|
|
8
|
+
if (type.endsWith("/*")) {
|
|
9
|
+
return file.type.startsWith(type.replace("/*", "/"));
|
|
10
|
+
}
|
|
11
|
+
return file.type === type;
|
|
12
|
+
});
|
|
13
|
+
if (!allowed) {
|
|
14
|
+
const ext = file.name.includes(".") ? file.name.split(".").pop() : null;
|
|
15
|
+
const type = ext ? `.${ext}` : file.type || "unknown";
|
|
16
|
+
return {
|
|
17
|
+
code: "FILE_TYPE_NOT_ALLOWED",
|
|
18
|
+
message: `File type "${type}" is not allowed`,
|
|
19
|
+
params: { type }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (file.size === 0) {
|
|
24
|
+
return {
|
|
25
|
+
code: "FILE_EMPTY",
|
|
26
|
+
message: "File is empty"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (options.maxFileSize && file.size > options.maxFileSize) {
|
|
30
|
+
const maxMB = (options.maxFileSize / (1024 * 1024)).toFixed(1);
|
|
31
|
+
return {
|
|
32
|
+
code: "FILE_TOO_LARGE",
|
|
33
|
+
message: `File size exceeds ${maxMB} MB limit`,
|
|
34
|
+
params: { size: `${maxMB} MB` }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/helpers/build-object-key.ts
|
|
41
|
+
function buildObjectKey(...parts) {
|
|
42
|
+
return parts.map((p) => p.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/helpers/get-file-extension.ts
|
|
46
|
+
function getFileExtension(fileName) {
|
|
47
|
+
const dotIndex = fileName.lastIndexOf(".");
|
|
48
|
+
if (dotIndex < 1) return "";
|
|
49
|
+
return fileName.slice(dotIndex + 1).toLowerCase();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/helpers/parse-file-name.ts
|
|
53
|
+
function parseFileName(contentDisposition) {
|
|
54
|
+
if (!contentDisposition) return void 0;
|
|
55
|
+
const utf8Match = contentDisposition.match(/filename\*=UTF-8''([^;,\s]+)/i);
|
|
56
|
+
if (utf8Match) {
|
|
57
|
+
try {
|
|
58
|
+
return decodeURIComponent(utf8Match[1]);
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const asciiMatch = contentDisposition.match(/filename="([^"]*)"/i);
|
|
63
|
+
return asciiMatch?.[1];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/helpers/format-file-size.ts
|
|
67
|
+
function formatFileSize(bytes) {
|
|
68
|
+
if (bytes === 0) return "0 B";
|
|
69
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
70
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
71
|
+
const size = bytes / Math.pow(1024, i);
|
|
72
|
+
return `${size.toFixed(i === 0 ? 0 : 1)} ${units[i]}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/helpers/build-content-disposition.ts
|
|
76
|
+
function buildContentDisposition(fileName) {
|
|
77
|
+
const ascii = fileName.replace(/[^\x20-\x7E]/g, "_").replace(/["\\]/g, "_");
|
|
78
|
+
const encoded = encodeURIComponent(fileName);
|
|
79
|
+
return `attachment; filename="${ascii}"; filename*=UTF-8''${encoded}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/helpers/sanitize-file-name.ts
|
|
83
|
+
function sanitizeFileName(fileName) {
|
|
84
|
+
return fileName.replace(/["\\\r\n]/g, "_");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/helpers/truncate-file-name.ts
|
|
88
|
+
function truncateFileName(name, maxChars = 26) {
|
|
89
|
+
if (name.length <= maxChars) return name;
|
|
90
|
+
const dotIndex = name.lastIndexOf(".");
|
|
91
|
+
if (dotIndex <= 0) {
|
|
92
|
+
return name.slice(0, maxChars - 1) + "\u2026";
|
|
93
|
+
}
|
|
94
|
+
const ext = name.slice(dotIndex);
|
|
95
|
+
const available = maxChars - ext.length - 1;
|
|
96
|
+
if (available <= 0) {
|
|
97
|
+
return name.slice(0, maxChars - 1) + "\u2026";
|
|
98
|
+
}
|
|
99
|
+
return name.slice(0, available) + "\u2026 " + ext;
|
|
100
|
+
}
|
|
101
|
+
var truncateFilename = truncateFileName;
|
|
102
|
+
|
|
103
|
+
// src/error.ts
|
|
104
|
+
var S3_ERROR_CODES = {
|
|
105
|
+
NOT_FOUND: "NOT_FOUND",
|
|
106
|
+
INVALID_JSON: "INVALID_JSON",
|
|
107
|
+
FORBIDDEN: "FORBIDDEN",
|
|
108
|
+
INTERNAL_ERROR: "INTERNAL_ERROR",
|
|
109
|
+
OBJECT_NOT_FOUND: "OBJECT_NOT_FOUND",
|
|
110
|
+
S3_NETWORK_ERROR: "S3_NETWORK_ERROR",
|
|
111
|
+
FIELD_REQUIRED: "FIELD_REQUIRED",
|
|
112
|
+
KEY_REQUIRED: "KEY_REQUIRED",
|
|
113
|
+
UPLOAD_ID_REQUIRED: "UPLOAD_ID_REQUIRED",
|
|
114
|
+
PART_NUMBER_INVALID: "PART_NUMBER_INVALID",
|
|
115
|
+
PARTS_REQUIRED: "PARTS_REQUIRED",
|
|
116
|
+
FILE_SIZE_REQUIRED_UPLOAD: "FILE_SIZE_REQUIRED_UPLOAD",
|
|
117
|
+
FILE_SIZE_REQUIRED_MULTIPART: "FILE_SIZE_REQUIRED_MULTIPART"
|
|
118
|
+
};
|
|
119
|
+
var DimahS3Error = class extends Error {
|
|
120
|
+
status;
|
|
121
|
+
code;
|
|
122
|
+
params;
|
|
123
|
+
constructor(message, status = 400, options) {
|
|
124
|
+
super(
|
|
125
|
+
message,
|
|
126
|
+
options?.cause !== void 0 ? { cause: options.cause } : void 0
|
|
127
|
+
);
|
|
128
|
+
this.name = "DimahS3Error";
|
|
129
|
+
this.status = status;
|
|
130
|
+
this.code = options?.code;
|
|
131
|
+
this.params = options?.params;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/routes.ts
|
|
136
|
+
var S3_API_BASE_PATH = "/api/s3";
|
|
137
|
+
function normalizeS3ApiBasePath(basePath) {
|
|
138
|
+
return basePath.replace(/\/$/, "");
|
|
139
|
+
}
|
|
140
|
+
var S3_API_ROUTES = {
|
|
141
|
+
upload: "presign/upload",
|
|
142
|
+
uploadConfirm: "presign/upload/confirm",
|
|
143
|
+
download: "presign/download",
|
|
144
|
+
delete: "delete",
|
|
145
|
+
multipartInit: "presign/multipart/init",
|
|
146
|
+
multipartPart: "presign/multipart/part",
|
|
147
|
+
multipartComplete: "presign/multipart/complete",
|
|
148
|
+
multipartAbort: "presign/multipart/abort",
|
|
149
|
+
multipartListParts: "presign/multipart/parts"
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/plugin/create-fetcher.ts
|
|
153
|
+
function buildQuery(query) {
|
|
154
|
+
if (!query) return "";
|
|
155
|
+
const params = new URLSearchParams();
|
|
156
|
+
for (const [key, value] of Object.entries(query)) {
|
|
157
|
+
if (value === void 0) continue;
|
|
158
|
+
params.set(key, String(value));
|
|
159
|
+
}
|
|
160
|
+
const qs = params.toString();
|
|
161
|
+
return qs ? `?${qs}` : "";
|
|
162
|
+
}
|
|
163
|
+
async function resolveHeaders(headers) {
|
|
164
|
+
if (headers == null) return void 0;
|
|
165
|
+
if (typeof headers === "function") return headers();
|
|
166
|
+
return headers;
|
|
167
|
+
}
|
|
168
|
+
function mergeHeaders(...parts) {
|
|
169
|
+
const out = {};
|
|
170
|
+
for (const part of parts) {
|
|
171
|
+
if (!part) continue;
|
|
172
|
+
const h = new Headers(part);
|
|
173
|
+
h.forEach((value, key) => {
|
|
174
|
+
out[key] = value;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
function jsonBody(body) {
|
|
180
|
+
return {
|
|
181
|
+
headers: { "Content-Type": "application/json" },
|
|
182
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function createFetcher(base, options) {
|
|
186
|
+
const fetchImpl = options?.fetch ?? fetch;
|
|
187
|
+
const json = async (url, init) => {
|
|
188
|
+
const extraHeaders = await resolveHeaders(options?.headers);
|
|
189
|
+
const res = await fetchImpl(url, {
|
|
190
|
+
...init,
|
|
191
|
+
credentials: options?.credentials ?? init?.credentials,
|
|
192
|
+
headers: mergeHeaders(extraHeaders, init?.headers)
|
|
193
|
+
});
|
|
194
|
+
if (!res.ok) {
|
|
195
|
+
const body = await res.json().catch(() => ({}));
|
|
196
|
+
throw new DimahS3Error(body.message ?? res.statusText, res.status, {
|
|
197
|
+
code: body.code,
|
|
198
|
+
params: body.params
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return res.json();
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
get(path, query) {
|
|
205
|
+
return json(`${base}/${path}${buildQuery(query)}`);
|
|
206
|
+
},
|
|
207
|
+
post(path, body) {
|
|
208
|
+
return json(`${base}/${path}`, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
...jsonBody(body)
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
put(path, body) {
|
|
214
|
+
return json(`${base}/${path}`, {
|
|
215
|
+
method: "PUT",
|
|
216
|
+
...jsonBody(body)
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
patch(path, body) {
|
|
220
|
+
return json(`${base}/${path}`, {
|
|
221
|
+
method: "PATCH",
|
|
222
|
+
...jsonBody(body)
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
delete(path, query) {
|
|
226
|
+
return json(`${base}/${path}${buildQuery(query)}`, {
|
|
227
|
+
method: "DELETE"
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// src/plugin/define-client-plugin.ts
|
|
234
|
+
function defineClientPlugin(plugin) {
|
|
235
|
+
return plugin;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/plugin/plugin-endpoint-path.ts
|
|
239
|
+
function pluginEndpointPath(pluginId, path) {
|
|
240
|
+
return `plugins/${pluginId}/${path.replace(/^\/+/, "")}`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/plugin/types.ts
|
|
244
|
+
var RESERVED_CLIENT_KEYS = [
|
|
245
|
+
"upload",
|
|
246
|
+
"confirm",
|
|
247
|
+
"download",
|
|
248
|
+
"delete",
|
|
249
|
+
"multipart"
|
|
250
|
+
];
|
|
251
|
+
|
|
252
|
+
// src/create-s3-client.ts
|
|
253
|
+
function withoutHeaders(value) {
|
|
254
|
+
const { headers: _headers, ...rest } = value;
|
|
255
|
+
return rest;
|
|
256
|
+
}
|
|
257
|
+
function createS3Client(options) {
|
|
258
|
+
const { basePath, plugins, ...fetchOptions } = options ?? {};
|
|
259
|
+
const base = normalizeS3ApiBasePath(basePath ?? S3_API_BASE_PATH);
|
|
260
|
+
const fetcher = createFetcher(base, fetchOptions);
|
|
261
|
+
const api = {
|
|
262
|
+
upload(payload) {
|
|
263
|
+
return fetcher.post(
|
|
264
|
+
S3_API_ROUTES.upload,
|
|
265
|
+
withoutHeaders(payload)
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
confirm(payload) {
|
|
269
|
+
return fetcher.post(
|
|
270
|
+
S3_API_ROUTES.uploadConfirm,
|
|
271
|
+
withoutHeaders(payload)
|
|
272
|
+
);
|
|
273
|
+
},
|
|
274
|
+
download(key, options2) {
|
|
275
|
+
const { fileName, bucket } = options2 ?? {};
|
|
276
|
+
return fetcher.get(S3_API_ROUTES.download, {
|
|
277
|
+
key,
|
|
278
|
+
fileName: fileName ? sanitizeFileName(fileName) : void 0,
|
|
279
|
+
bucket
|
|
280
|
+
});
|
|
281
|
+
},
|
|
282
|
+
delete(key, options2) {
|
|
283
|
+
const { bucket } = options2 ?? {};
|
|
284
|
+
return fetcher.delete(S3_API_ROUTES.delete, {
|
|
285
|
+
key,
|
|
286
|
+
bucket
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
multipart: {
|
|
290
|
+
init(payload) {
|
|
291
|
+
return fetcher.post(
|
|
292
|
+
S3_API_ROUTES.multipartInit,
|
|
293
|
+
withoutHeaders(payload)
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
signPart(payload) {
|
|
297
|
+
return fetcher.post(
|
|
298
|
+
S3_API_ROUTES.multipartPart,
|
|
299
|
+
withoutHeaders(payload)
|
|
300
|
+
);
|
|
301
|
+
},
|
|
302
|
+
listParts(payload) {
|
|
303
|
+
const { key, uploadId, bucket } = withoutHeaders(payload);
|
|
304
|
+
return fetcher.get(
|
|
305
|
+
S3_API_ROUTES.multipartListParts,
|
|
306
|
+
{ key, uploadId, bucket }
|
|
307
|
+
);
|
|
308
|
+
},
|
|
309
|
+
complete(payload) {
|
|
310
|
+
return fetcher.post(
|
|
311
|
+
S3_API_ROUTES.multipartComplete,
|
|
312
|
+
withoutHeaders(payload)
|
|
313
|
+
);
|
|
314
|
+
},
|
|
315
|
+
abort(payload) {
|
|
316
|
+
return fetcher.post(
|
|
317
|
+
S3_API_ROUTES.multipartAbort,
|
|
318
|
+
withoutHeaders(payload)
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
const pluginMethods = {};
|
|
324
|
+
for (const plugin of plugins ?? []) {
|
|
325
|
+
if (RESERVED_CLIENT_KEYS.includes(plugin.id)) {
|
|
326
|
+
throw new Error(
|
|
327
|
+
`Client plugin id "${plugin.id}" is reserved on the S3 client.`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
if (plugin.id in pluginMethods) {
|
|
331
|
+
throw new Error(`Duplicate client plugin id "${plugin.id}".`);
|
|
332
|
+
}
|
|
333
|
+
pluginMethods[plugin.id] = plugin.createMethods(fetcher);
|
|
334
|
+
}
|
|
335
|
+
return { ...api, ...pluginMethods };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export { DimahS3Error, RESERVED_CLIENT_KEYS, S3_API_BASE_PATH, S3_API_ROUTES, S3_ERROR_CODES, buildContentDisposition, buildObjectKey, createFetcher, createS3Client, defineClientPlugin, formatFileSize, getFileExtension, normalizeS3ApiBasePath, parseFileName, pluginEndpointPath, sanitizeFileName, truncateFileName, truncateFilename, validateFile };
|
|
339
|
+
//# sourceMappingURL=index.js.map
|
|
340
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/helpers/validate-file.ts","../src/helpers/build-object-key.ts","../src/helpers/get-file-extension.ts","../src/helpers/parse-file-name.ts","../src/helpers/format-file-size.ts","../src/helpers/build-content-disposition.ts","../src/helpers/sanitize-file-name.ts","../src/helpers/truncate-file-name.ts","../src/error.ts","../src/routes.ts","../src/plugin/create-fetcher.ts","../src/plugin/define-client-plugin.ts","../src/plugin/plugin-endpoint-path.ts","../src/plugin/types.ts","../src/create-s3-client.ts"],"names":["options"],"mappings":";AAiBO,SAAS,YAAA,CACd,MACA,OAAA,EAC0B;AAC1B,EAAA,IAAI,OAAA,CAAQ,QAAQ,MAAA,EAAQ;AAC1B,IAAA,MAAM,OAAA,GAAU,OAAA,CAAQ,MAAA,CAAO,IAAA,CAAK,CAAC,IAAA,KAAS;AAC5C,MAAA,IAAI,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EAAG;AACxB,QAAA,OAAO,KAAK,IAAA,CAAK,WAAA,GAAc,QAAA,CAAS,IAAA,CAAK,aAAa,CAAA;AAAA,MAC5D;AACA,MAAA,IAAI,IAAA,CAAK,QAAA,CAAS,IAAI,CAAA,EAAG;AACvB,QAAA,OAAO,KAAK,IAAA,CAAK,UAAA,CAAW,KAAK,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAC,CAAA;AAAA,MACrD;AACA,MAAA,OAAO,KAAK,IAAA,KAAS,IAAA;AAAA,IACvB,CAAC,CAAA;AACD,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,MAAM,GAAA,GAAM,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,GAAG,CAAA,GAAI,IAAA,CAAK,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,EAAI,GAAI,IAAA;AACnE,MAAA,MAAM,OAAO,GAAA,GAAM,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA,GAAK,KAAK,IAAA,IAAQ,SAAA;AAC5C,MAAA,OAAO;AAAA,QACL,IAAA,EAAM,uBAAA;AAAA,QACN,OAAA,EAAS,cAAc,IAAI,CAAA,gBAAA,CAA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;AAAA,UACb,aAAA,CAAc,kBAAA;AAAA,UACd,EAAE,GAAA,EAAK,QAAA,EAAU,MAAA;AAAO,SAC1B;AAAA,MACF,CAAA;AAAA,MAEA,SAAS,OAAA,EAAS;AAChB,QAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,UACb,aAAA,CAAc,iBAAA;AAAA,UACd,eAAe,OAAO;AAAA,SACxB;AAAA,MACF,CAAA;AAAA,MAEA,MAAM,OAAA,EAAS;AACb,QAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,UACb,aAAA,CAAc,cAAA;AAAA,UACd,eAAe,OAAO;AAAA,SACxB;AAAA,MACF;AAAA;AACF,GACF;AAEA,EAAA,MAAM,gBAAyC,EAAC;AAChD,EAAA,KAAA,MAAW,MAAA,IAAU,OAAA,IAAW,EAAC,EAAG;AAClC,IAAA,IAAK,oBAAA,CAA2C,QAAA,CAAS,MAAA,CAAO,EAAE,CAAA,EAAG;AACnE,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAA,kBAAA,EAAqB,OAAO,EAAE,CAAA,+BAAA;AAAA,OAChC;AAAA,IACF;AACA,IAAA,IAAI,MAAA,CAAO,MAAM,aAAA,EAAe;AAC9B,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,4BAAA,EAA+B,MAAA,CAAO,EAAE,CAAA,EAAA,CAAI,CAAA;AAAA,IAC9D;AACA,IAAA,aAAA,CAAc,MAAA,CAAO,EAAE,CAAA,GAAI,MAAA,CAAO,cAAc,OAAO,CAAA;AAAA,EACzD;AAEA,EAAA,OAAO,EAAE,GAAG,GAAA,EAAK,GAAG,aAAA,EAAc;AACpC","file":"index.js","sourcesContent":["/** Machine-readable codes for client-side file validation failures. */\nexport type ValidateFileErrorCode =\n \"FILE_TYPE_NOT_ALLOWED\" | \"FILE_EMPTY\" | \"FILE_TOO_LARGE\";\n\n/** Result of {@link validateFile} when the file fails a check. */\nexport type ValidateFileError = {\n code: ValidateFileErrorCode;\n /** English fallback message (localize via Fuma when a translator is available). */\n message: string;\n /** Interpolation params for i18n (e.g. `{ type }`, `{ size }`). */\n params?: Record<string, string | number>;\n};\n\n/**\n * Client-side accept / size / empty checks before starting an upload.\n * Returns `null` when the file is valid.\n */\nexport function validateFile(\n file: File,\n options: { accept?: string[]; maxFileSize?: number },\n): ValidateFileError | null {\n if (options.accept?.length) {\n const allowed = options.accept.some((type) => {\n if (type.startsWith(\".\")) {\n return file.name.toLowerCase().endsWith(type.toLowerCase());\n }\n if (type.endsWith(\"/*\")) {\n return file.type.startsWith(type.replace(\"/*\", \"/\"));\n }\n return file.type === type;\n });\n if (!allowed) {\n const ext = file.name.includes(\".\") ? file.name.split(\".\").pop() : null;\n const type = ext ? `.${ext}` : file.type || \"unknown\";\n return {\n code: \"FILE_TYPE_NOT_ALLOWED\",\n message: `File type \"${type}\" is not allowed`,\n params: { type },\n };\n }\n }\n\n if (file.size === 0) {\n return {\n code: \"FILE_EMPTY\",\n message: \"File is empty\",\n };\n }\n\n if (options.maxFileSize && file.size > options.maxFileSize) {\n const maxMB = (options.maxFileSize / (1024 * 1024)).toFixed(1);\n return {\n code: \"FILE_TOO_LARGE\",\n message: `File size exceeds ${maxMB} MB limit`,\n params: { size: `${maxMB} MB` },\n };\n }\n\n return null;\n}\n","export function buildObjectKey(...parts: string[]): string {\n return parts\n .map((p) => p.replace(/^\\/+|\\/+$/g, \"\"))\n .filter(Boolean)\n .join(\"/\");\n}\n","export function getFileExtension(fileName: string): string {\n const dotIndex = fileName.lastIndexOf(\".\");\n if (dotIndex < 1) return \"\";\n return fileName.slice(dotIndex + 1).toLowerCase();\n}\n","export function parseFileName(\n contentDisposition: string | null | undefined,\n): string | undefined {\n if (!contentDisposition) return undefined;\n\n const utf8Match = contentDisposition.match(/filename\\*=UTF-8''([^;,\\s]+)/i);\n if (utf8Match) {\n try {\n return decodeURIComponent(utf8Match[1]);\n } catch {\n /* ignore malformed encoding */\n }\n }\n\n const asciiMatch = contentDisposition.match(/filename=\"([^\"]*)\"/i);\n return asciiMatch?.[1];\n}\n","export function formatFileSize(bytes: number): string {\n if (bytes === 0) return \"0 B\";\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\n const i = Math.floor(Math.log(bytes) / Math.log(1024));\n const size = bytes / Math.pow(1024, i);\n return `${size.toFixed(i === 0 ? 0 : 1)} ${units[i]}`;\n}\n","/**\n * Builds a RFC 6266 `Content-Disposition` value for a file attachment.\n *\n * Includes both the ASCII-safe `filename` fallback and the RFC 5987\n * `filename*` parameter for full Unicode support.\n */\nexport function buildContentDisposition(fileName: string): string {\n const ascii = fileName.replace(/[^\\x20-\\x7E]/g, \"_\").replace(/[\"\\\\]/g, \"_\");\n const encoded = encodeURIComponent(fileName);\n return `attachment; filename=\"${ascii}\"; filename*=UTF-8''${encoded}`;\n}\n","/** Sanitizes a file name for safe use in URL query parameters. */\nexport function sanitizeFileName(fileName: string): string {\n return fileName.replace(/[\"\\\\\\r\\n]/g, \"_\");\n}\n","/**\n * Truncates a filename while preserving the extension when possible.\n */\nexport function truncateFileName(name: string, maxChars = 26): string {\n if (name.length <= maxChars) return name;\n const dotIndex = name.lastIndexOf(\".\");\n if (dotIndex <= 0) {\n return name.slice(0, maxChars - 1) + \"…\";\n }\n const ext = name.slice(dotIndex);\n const available = maxChars - ext.length - 1;\n if (available <= 0) {\n return name.slice(0, maxChars - 1) + \"…\";\n }\n return name.slice(0, available) + \"… \" + ext;\n}\n\n/** @deprecated Use {@link truncateFileName}. */\nexport const truncateFilename = truncateFileName;\n","/** Stable API error codes returned in JSON `{ code, message, params? }`. */\nexport const S3_ERROR_CODES = {\n NOT_FOUND: \"NOT_FOUND\",\n INVALID_JSON: \"INVALID_JSON\",\n FORBIDDEN: \"FORBIDDEN\",\n INTERNAL_ERROR: \"INTERNAL_ERROR\",\n OBJECT_NOT_FOUND: \"OBJECT_NOT_FOUND\",\n S3_NETWORK_ERROR: \"S3_NETWORK_ERROR\",\n FIELD_REQUIRED: \"FIELD_REQUIRED\",\n KEY_REQUIRED: \"KEY_REQUIRED\",\n UPLOAD_ID_REQUIRED: \"UPLOAD_ID_REQUIRED\",\n PART_NUMBER_INVALID: \"PART_NUMBER_INVALID\",\n PARTS_REQUIRED: \"PARTS_REQUIRED\",\n FILE_SIZE_REQUIRED_UPLOAD: \"FILE_SIZE_REQUIRED_UPLOAD\",\n FILE_SIZE_REQUIRED_MULTIPART: \"FILE_SIZE_REQUIRED_MULTIPART\",\n} as const;\n\nexport type S3ErrorCode = (typeof S3_ERROR_CODES)[keyof typeof S3_ERROR_CODES];\n\nexport type DimahS3ErrorParams = Record<string, string | number>;\n\nexport type DimahS3ErrorOptions = {\n cause?: unknown;\n code?: S3ErrorCode | string;\n params?: DimahS3ErrorParams;\n};\n\n/** Typed API / procedure error with HTTP status and optional stable code. */\nexport class DimahS3Error extends Error {\n readonly status: number;\n readonly code?: S3ErrorCode | string;\n readonly params?: DimahS3ErrorParams;\n\n constructor(message: string, status = 400, options?: DimahS3ErrorOptions) {\n super(\n message,\n options?.cause !== undefined ? { cause: options.cause } : undefined,\n );\n this.name = \"DimahS3Error\";\n this.status = status;\n this.code = options?.code;\n this.params = options?.params;\n }\n}\n","/** Default mount path for the catch-all route (`app/api/s3/[...s3]/route.ts`). */\nexport const S3_API_BASE_PATH = \"/api/s3\";\n\nexport function normalizeS3ApiBasePath(basePath: string): string {\n return basePath.replace(/\\/$/, \"\");\n}\n\nexport const S3_API_ROUTES = {\n upload: \"presign/upload\",\n uploadConfirm: \"presign/upload/confirm\",\n download: \"presign/download\",\n delete: \"delete\",\n multipartInit: \"presign/multipart/init\",\n multipartPart: \"presign/multipart/part\",\n multipartComplete: \"presign/multipart/complete\",\n multipartAbort: \"presign/multipart/abort\",\n multipartListParts: \"presign/multipart/parts\",\n} as const;\n","import { DimahS3Error } from \"../error\";\nimport type { S3ClientFetcher, S3ClientFetchOptions } from \"./types\";\n\nfunction buildQuery(\n query?: Record<string, string | number | boolean | undefined>,\n): string {\n if (!query) return \"\";\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue;\n params.set(key, String(value));\n }\n const qs = params.toString();\n return qs ? `?${qs}` : \"\";\n}\n\nasync function resolveHeaders(\n headers: S3ClientFetchOptions[\"headers\"],\n): Promise<HeadersInit | undefined> {\n if (headers == null) return undefined;\n if (typeof headers === \"function\") return headers();\n return headers;\n}\n\nfunction mergeHeaders(\n ...parts: (HeadersInit | undefined)[]\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const part of parts) {\n if (!part) continue;\n const h = new Headers(part);\n h.forEach((value, key) => {\n out[key] = value;\n });\n }\n return out;\n}\n\nfunction jsonBody(body: unknown): RequestInit {\n return {\n headers: { \"Content-Type\": \"application/json\" },\n body: body === undefined ? undefined : JSON.stringify(body),\n };\n}\n\n/**\n * Shared fetch + JSON error parsing for core routes and client plugins.\n * `base` is a normalized API prefix (e.g. `/api/s3`).\n *\n * Non-OK responses throw {@link DimahS3Error} with the HTTP status — same\n * class as server procedures, so client and server error shapes stay aligned.\n */\nexport function createFetcher(\n base: string,\n options?: S3ClientFetchOptions,\n): S3ClientFetcher {\n const fetchImpl = options?.fetch ?? fetch;\n\n const json = async <T>(url: string, init?: RequestInit): Promise<T> => {\n const extraHeaders = await resolveHeaders(options?.headers);\n const res = await fetchImpl(url, {\n ...init,\n credentials: options?.credentials ?? init?.credentials,\n headers: mergeHeaders(extraHeaders, init?.headers),\n });\n if (!res.ok) {\n const body = (await res.json().catch(() => ({}))) as {\n message?: string;\n code?: string;\n params?: Record<string, string | number>;\n };\n throw new DimahS3Error(body.message ?? res.statusText, res.status, {\n code: body.code,\n params: body.params,\n });\n }\n return res.json() as Promise<T>;\n };\n\n return {\n get<T>(\n path: string,\n query?: Record<string, string | number | boolean | undefined>,\n ) {\n return json<T>(`${base}/${path}${buildQuery(query)}`);\n },\n post<T>(path: string, body?: unknown) {\n return json<T>(`${base}/${path}`, {\n method: \"POST\",\n ...jsonBody(body),\n });\n },\n put<T>(path: string, body?: unknown) {\n return json<T>(`${base}/${path}`, {\n method: \"PUT\",\n ...jsonBody(body),\n });\n },\n patch<T>(path: string, body?: unknown) {\n return json<T>(`${base}/${path}`, {\n method: \"PATCH\",\n ...jsonBody(body),\n });\n },\n delete<T>(\n path: string,\n query?: Record<string, string | number | boolean | undefined>,\n ) {\n return json<T>(`${base}/${path}${buildQuery(query)}`, {\n method: \"DELETE\",\n });\n },\n };\n}\n","import type { S3ClientPlugin } from \"./types\";\n\n/**\n * Identity helper that preserves literal `id` and method types for\n * {@link createS3Client} inference (`api[id]`).\n *\n * ```ts\n * export function dbClient() {\n * return defineClientPlugin({\n * id: \"db\",\n * createMethods: (fetcher) => ({\n * listObjects: () => fetcher.get(pluginEndpointPath(\"db\", \"objects\")),\n * }),\n * });\n * }\n * ```\n */\nexport function defineClientPlugin<\n Id extends string,\n TMethods extends Record<string, unknown> = Record<string, unknown>,\n>(plugin: S3ClientPlugin<Id, TMethods>): S3ClientPlugin<Id, TMethods> {\n return plugin;\n}\n","/**\n * Build the relative path for a plugin HTTP endpoint under `basePath`.\n * Server mounts and client fetchers share this so URLs never diverge.\n *\n * @example\n * pluginEndpointPath(\"db\", \"objects\") // \"plugins/db/objects\"\n */\nexport function pluginEndpointPath(pluginId: string, path: string): string {\n return `plugins/${pluginId}/${path.replace(/^\\/+/, \"\")}`;\n}\n","/**\n * Optional fetch configuration for {@link createFetcher} / {@link createS3Client}.\n * Applied to core routes and every client plugin sharing the same fetcher.\n */\nexport type S3ClientFetchOptions = {\n /** Defaults to global `fetch` — override for SSR, tests, or logging. */\n fetch?: typeof fetch;\n /** e.g. `\"include\"` to send cookies cross-origin. */\n credentials?: RequestCredentials;\n /**\n * Static headers or a (possibly async) factory called per request —\n * useful for Authorization tokens.\n */\n headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);\n};\n\n/**\n * Shared HTTP helper used by core `S3Api` methods and client plugins.\n * Built once by {@link createFetcher} / {@link createS3Client}.\n */\nexport type S3ClientFetcher = {\n get<T>(\n path: string,\n query?: Record<string, string | number | boolean | undefined>,\n ): Promise<T>;\n post<T>(path: string, body?: unknown): Promise<T>;\n put<T>(path: string, body?: unknown): Promise<T>;\n patch<T>(path: string, body?: unknown): Promise<T>;\n delete<T>(\n path: string,\n query?: Record<string, string | number | boolean | undefined>,\n ): Promise<T>;\n};\n\n/**\n * Browser / isomorphic client plugin — mirrors server `DimahS3Plugin`\n * (literal `id` + methods flattened onto the `createS3Client` result).\n *\n * @typeParam Id — unique plugin id; becomes `api[id]`.\n * @typeParam TMethods — methods returned by {@link createMethods}.\n */\nexport type S3ClientPlugin<\n Id extends string = string,\n TMethods extends Record<string, unknown> = Record<string, unknown>,\n> = {\n id: Id;\n /** Build typed methods that call plugin endpoints via the shared fetcher. */\n createMethods: (fetcher: S3ClientFetcher) => TMethods;\n};\n\n/** Map client plugin ids → their method bags. */\nexport type ClientPluginMethodsMap<P extends readonly S3ClientPlugin[]> = {\n [K in P[number] as K[\"id\"]]: K extends S3ClientPlugin<string, infer M>\n ? M\n : never;\n};\n\n/** Keys reserved on the `createS3Client` result — client plugins may not use these as ids. */\nexport const RESERVED_CLIENT_KEYS = [\n \"upload\",\n \"confirm\",\n \"download\",\n \"delete\",\n \"multipart\",\n] as const;\n\nexport type ReservedClientKey = (typeof RESERVED_CLIENT_KEYS)[number];\n","import type {\n DeleteResponse,\n MultipartAbortResponse,\n MultipartCompleteResponse,\n MultipartInitResponse,\n MultipartListPartsResponse,\n MultipartPartResponse,\n PresignResponse,\n S3Api,\n UploadConfirmResponse,\n UploadPresignResponse,\n} from \"./types\";\nimport { sanitizeFileName } from \"./helpers/sanitize-file-name\";\nimport {\n createFetcher,\n RESERVED_CLIENT_KEYS,\n type ClientPluginMethodsMap,\n type S3ClientFetchOptions,\n type S3ClientPlugin,\n} from \"./plugin\";\nimport {\n normalizeS3ApiBasePath,\n S3_API_BASE_PATH,\n S3_API_ROUTES,\n} from \"./routes\";\n\n/** Options for {@link createS3Client}. */\nexport type CreateS3ClientOptions<\n P extends readonly S3ClientPlugin[] = readonly S3ClientPlugin[],\n> = {\n /** API path prefix — must match server `basePath`. @default \"/api/s3\" */\n basePath?: string;\n /** Client plugins (e.g. `dbClient()` from `@dimah-s3/db/client`). */\n plugins?: P;\n} & S3ClientFetchOptions;\n\n/** Strip server-only `headers` before sending over HTTP. */\nfunction withoutHeaders<T extends { headers?: HeadersInit }>(\n value: T,\n): Omit<T, \"headers\"> {\n const { headers: _headers, ...rest } = value;\n return rest;\n}\n\n/**\n * Browser (or isomorphic) client for the dimah-s3 HTTP API.\n *\n * For React apps prefer `createS3Client` from `@dimah-s3/react` — same options,\n * plus a bound `S3Provider` / typed `useApi`.\n *\n * ```ts\n * import { createS3Client } from \"@dimah-s3/core\";\n * import { dbClient } from \"@dimah-s3/db/client\";\n *\n * export const api = createS3Client({\n * basePath: \"/api/s3\",\n * plugins: [dbClient()],\n * });\n *\n * await api.db.listObjects();\n * ```\n */\nexport function createS3Client<const P extends readonly S3ClientPlugin[] = []>(\n options?: CreateS3ClientOptions<P>,\n): S3Api & ClientPluginMethodsMap<P> {\n const { basePath, plugins, ...fetchOptions } = options ?? {};\n const base = normalizeS3ApiBasePath(basePath ?? S3_API_BASE_PATH);\n const fetcher = createFetcher(base, fetchOptions);\n\n const api: S3Api = {\n upload(payload) {\n return fetcher.post<UploadPresignResponse>(\n S3_API_ROUTES.upload,\n withoutHeaders(payload),\n );\n },\n\n confirm(payload) {\n return fetcher.post<UploadConfirmResponse>(\n S3_API_ROUTES.uploadConfirm,\n withoutHeaders(payload),\n );\n },\n\n download(key, options?) {\n const { fileName, bucket } = options ?? {};\n return fetcher.get<PresignResponse>(S3_API_ROUTES.download, {\n key,\n fileName: fileName ? sanitizeFileName(fileName) : undefined,\n bucket,\n });\n },\n\n delete(key, options?) {\n const { bucket } = options ?? {};\n return fetcher.delete<DeleteResponse>(S3_API_ROUTES.delete, {\n key,\n bucket,\n });\n },\n\n multipart: {\n init(payload) {\n return fetcher.post<MultipartInitResponse>(\n S3_API_ROUTES.multipartInit,\n withoutHeaders(payload),\n );\n },\n\n signPart(payload) {\n return fetcher.post<MultipartPartResponse>(\n S3_API_ROUTES.multipartPart,\n withoutHeaders(payload),\n );\n },\n\n listParts(payload) {\n const { key, uploadId, bucket } = withoutHeaders(payload);\n return fetcher.get<MultipartListPartsResponse>(\n S3_API_ROUTES.multipartListParts,\n { key, uploadId, bucket },\n );\n },\n\n complete(payload) {\n return fetcher.post<MultipartCompleteResponse>(\n S3_API_ROUTES.multipartComplete,\n withoutHeaders(payload),\n );\n },\n\n abort(payload) {\n return fetcher.post<MultipartAbortResponse>(\n S3_API_ROUTES.multipartAbort,\n withoutHeaders(payload),\n );\n },\n },\n };\n\n const pluginMethods: Record<string, unknown> = {};\n for (const plugin of plugins ?? []) {\n if ((RESERVED_CLIENT_KEYS as readonly string[]).includes(plugin.id)) {\n throw new Error(\n `Client plugin id \"${plugin.id}\" is reserved on the S3 client.`,\n );\n }\n if (plugin.id in pluginMethods) {\n throw new Error(`Duplicate client plugin id \"${plugin.id}\".`);\n }\n pluginMethods[plugin.id] = plugin.createMethods(fetcher);\n }\n\n return { ...api, ...pluginMethods } as S3Api & ClientPluginMethodsMap<P>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { S3ClientFetcher, S3ClientFetchOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Shared fetch + JSON error parsing for core routes and client plugins.
|
|
4
|
+
* `base` is a normalized API prefix (e.g. `/api/s3`).
|
|
5
|
+
*
|
|
6
|
+
* Non-OK responses throw {@link DimahS3Error} with the HTTP status — same
|
|
7
|
+
* class as server procedures, so client and server error shapes stay aligned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createFetcher(base: string, options?: S3ClientFetchOptions): S3ClientFetcher;
|
|
10
|
+
//# sourceMappingURL=create-fetcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-fetcher.d.ts","sourceRoot":"","sources":["../../src/plugin/create-fetcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AA4CrE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,oBAAoB,GAC7B,eAAe,CA0DjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { S3ClientPlugin } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Identity helper that preserves literal `id` and method types for
|
|
4
|
+
* {@link createS3Client} inference (`api[id]`).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* export function dbClient() {
|
|
8
|
+
* return defineClientPlugin({
|
|
9
|
+
* id: "db",
|
|
10
|
+
* createMethods: (fetcher) => ({
|
|
11
|
+
* listObjects: () => fetcher.get(pluginEndpointPath("db", "objects")),
|
|
12
|
+
* }),
|
|
13
|
+
* });
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function defineClientPlugin<Id extends string, TMethods extends Record<string, unknown> = Record<string, unknown>>(plugin: S3ClientPlugin<Id, TMethods>): S3ClientPlugin<Id, TMethods>;
|
|
18
|
+
//# sourceMappingURL=define-client-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-client-plugin.d.ts","sourceRoot":"","sources":["../../src/plugin/define-client-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,SAAS,MAAM,EACjB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,MAAM,EAAE,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,CAEpE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createFetcher } from "./create-fetcher";
|
|
2
|
+
export { defineClientPlugin } from "./define-client-plugin";
|
|
3
|
+
export { pluginEndpointPath } from "./plugin-endpoint-path";
|
|
4
|
+
export { RESERVED_CLIENT_KEYS, type ClientPluginMethodsMap, type ReservedClientKey, type S3ClientFetcher, type S3ClientFetchOptions, type S3ClientPlugin, } from "./types";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,cAAc,GACpB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the relative path for a plugin HTTP endpoint under `basePath`.
|
|
3
|
+
* Server mounts and client fetchers share this so URLs never diverge.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* pluginEndpointPath("db", "objects") // "plugins/db/objects"
|
|
7
|
+
*/
|
|
8
|
+
export declare function pluginEndpointPath(pluginId: string, path: string): string;
|
|
9
|
+
//# sourceMappingURL=plugin-endpoint-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-endpoint-path.d.ts","sourceRoot":"","sources":["../../src/plugin/plugin-endpoint-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional fetch configuration for {@link createFetcher} / {@link createS3Client}.
|
|
3
|
+
* Applied to core routes and every client plugin sharing the same fetcher.
|
|
4
|
+
*/
|
|
5
|
+
export type S3ClientFetchOptions = {
|
|
6
|
+
/** Defaults to global `fetch` — override for SSR, tests, or logging. */
|
|
7
|
+
fetch?: typeof fetch;
|
|
8
|
+
/** e.g. `"include"` to send cookies cross-origin. */
|
|
9
|
+
credentials?: RequestCredentials;
|
|
10
|
+
/**
|
|
11
|
+
* Static headers or a (possibly async) factory called per request —
|
|
12
|
+
* useful for Authorization tokens.
|
|
13
|
+
*/
|
|
14
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Shared HTTP helper used by core `S3Api` methods and client plugins.
|
|
18
|
+
* Built once by {@link createFetcher} / {@link createS3Client}.
|
|
19
|
+
*/
|
|
20
|
+
export type S3ClientFetcher = {
|
|
21
|
+
get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
22
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
23
|
+
put<T>(path: string, body?: unknown): Promise<T>;
|
|
24
|
+
patch<T>(path: string, body?: unknown): Promise<T>;
|
|
25
|
+
delete<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Browser / isomorphic client plugin — mirrors server `DimahS3Plugin`
|
|
29
|
+
* (literal `id` + methods flattened onto the `createS3Client` result).
|
|
30
|
+
*
|
|
31
|
+
* @typeParam Id — unique plugin id; becomes `api[id]`.
|
|
32
|
+
* @typeParam TMethods — methods returned by {@link createMethods}.
|
|
33
|
+
*/
|
|
34
|
+
export type S3ClientPlugin<Id extends string = string, TMethods extends Record<string, unknown> = Record<string, unknown>> = {
|
|
35
|
+
id: Id;
|
|
36
|
+
/** Build typed methods that call plugin endpoints via the shared fetcher. */
|
|
37
|
+
createMethods: (fetcher: S3ClientFetcher) => TMethods;
|
|
38
|
+
};
|
|
39
|
+
/** Map client plugin ids → their method bags. */
|
|
40
|
+
export type ClientPluginMethodsMap<P extends readonly S3ClientPlugin[]> = {
|
|
41
|
+
[K in P[number] as K["id"]]: K extends S3ClientPlugin<string, infer M> ? M : never;
|
|
42
|
+
};
|
|
43
|
+
/** Keys reserved on the `createS3Client` result — client plugins may not use these as ids. */
|
|
44
|
+
export declare const RESERVED_CLIENT_KEYS: readonly ["upload", "confirm", "download", "delete", "multipart"];
|
|
45
|
+
export type ReservedClientKey = (typeof RESERVED_CLIENT_KEYS)[number];
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,wEAAwE;IACxE,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,qDAAqD;IACrD,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACpE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,CAAC,CAAC,EACH,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,GAC5D,OAAO,CAAC,CAAC,CAAC,CAAC;IACd,IAA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AoB,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Default mount path for the catch-all route (`app/api/s3/[...s3]/route.ts`). */
|
|
2
|
+
export declare const S3_API_BASE_PATH = "/api/s3";
|
|
3
|
+
export declare function normalizeS3ApiBasePath(basePath: string): string;
|
|
4
|
+
export declare const S3_API_ROUTES: {
|
|
5
|
+
readonly upload: "presign/upload";
|
|
6
|
+
readonly uploadConfirm: "presign/upload/confirm";
|
|
7
|
+
readonly download: "presign/download";
|
|
8
|
+
readonly delete: "delete";
|
|
9
|
+
readonly multipartInit: "presign/multipart/init";
|
|
10
|
+
readonly multipartPart: "presign/multipart/part";
|
|
11
|
+
readonly multipartComplete: "presign/multipart/complete";
|
|
12
|
+
readonly multipartAbort: "presign/multipart/abort";
|
|
13
|
+
readonly multipartListParts: "presign/multipart/parts";
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,YAAY,CAAC;AAE1C,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,eAAO,MAAM,aAAa;aACxB,MAAM,EAAE,gBAAgB;aACxB,aAAa,EAAE,wBAAwB;aACvC,QAAQ,EAAE,kBAAkB;aAC5B,MAAM,EAAE,QAAQ;aAChB,aAAa,EAAE,wBAAwB;aACvC,aAAa,EAAE,wBAAwB;aACvC,iBAAiB,EAAE,4BAA4B;aAC/C,cAAc,EAAE,yBAAyB;aACzC,kBAAkB,EAAE,yBAAyB;CACrC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { UploadPresignMethod } from "./upload-presign-method";
|
|
2
|
+
export type { S3ObjectAcl, S3ApiHeaders, UploadPayload, ConfirmPayload, DownloadOptions, DeleteOptions, MultipartInitPayload, MultipartSignPartPayload, MultipartListPartsPayload, MultipartCompletedPartRef, MultipartCompletePayload, MultipartAbortPayload, } from "./requests";
|
|
3
|
+
export type { DeleteResponse, MultipartCompleteResponse, MultipartAbortResponse, PresignResponse, UploadPresignResponse, MultipartInitResponse, MultipartPartResponse, MultipartPartInfo, MultipartListPartsResponse, UploadConfirmResponse, S3Api, } from "./responses";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,YAAY,EACV,WAAW,EACX,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,0BAA0B,EAC1B,qBAAqB,EACrB,KAAK,GACN,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { UploadPresignMethod } from "./upload-presign-method";
|
|
2
|
+
/** S3 object ACL. */
|
|
3
|
+
export type S3ObjectAcl = "private" | "public-read";
|
|
4
|
+
/**
|
|
5
|
+
* Server-side auth context for `dimahS3().api` calls (guards / db scope).
|
|
6
|
+
* Ignored by {@link createS3Client} — never sent over the wire.
|
|
7
|
+
*/
|
|
8
|
+
export type S3ApiHeaders = {
|
|
9
|
+
/** Forwarded into a synthetic `Request` for server-side `api` calls. */
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
};
|
|
12
|
+
/** Payload for {@link S3Api.upload}. */
|
|
13
|
+
export type UploadPayload = S3ApiHeaders & {
|
|
14
|
+
/** S3 object key. */
|
|
15
|
+
key: string;
|
|
16
|
+
/** Declared MIME type. */
|
|
17
|
+
contentType?: string;
|
|
18
|
+
/** Declared size in bytes. */
|
|
19
|
+
fileSize?: number;
|
|
20
|
+
/** Custom object metadata (`x-amz-meta-*`). */
|
|
21
|
+
metadata?: Record<string, string>;
|
|
22
|
+
/** Override default bucket. */
|
|
23
|
+
bucket?: string;
|
|
24
|
+
/** Requested ACL. */
|
|
25
|
+
acl?: S3ObjectAcl;
|
|
26
|
+
/** Original filename for `Content-Disposition`. */
|
|
27
|
+
fileName?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Payload for {@link S3Api.confirm}. */
|
|
30
|
+
export type ConfirmPayload = S3ApiHeaders & {
|
|
31
|
+
/** S3 object key. */
|
|
32
|
+
key: string;
|
|
33
|
+
/** Override default bucket. */
|
|
34
|
+
bucket?: string;
|
|
35
|
+
};
|
|
36
|
+
/** Options for {@link S3Api.download}. */
|
|
37
|
+
export type DownloadOptions = S3ApiHeaders & {
|
|
38
|
+
/** Download filename for `Content-Disposition`. */
|
|
39
|
+
fileName?: string;
|
|
40
|
+
/** Override default bucket. */
|
|
41
|
+
bucket?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Options for {@link S3Api.delete}. */
|
|
44
|
+
export type DeleteOptions = S3ApiHeaders & {
|
|
45
|
+
/** Override default bucket. */
|
|
46
|
+
bucket?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Payload for {@link S3Api.multipart.init}. Same fields as {@link UploadPayload}. */
|
|
49
|
+
export type MultipartInitPayload = UploadPayload;
|
|
50
|
+
/** Payload for {@link S3Api.multipart.signPart}. */
|
|
51
|
+
export type MultipartSignPartPayload = S3ApiHeaders & {
|
|
52
|
+
/** S3 object key. */
|
|
53
|
+
key: string;
|
|
54
|
+
/** Multipart upload ID. */
|
|
55
|
+
uploadId: string;
|
|
56
|
+
/** 1-based part number. */
|
|
57
|
+
partNumber: number;
|
|
58
|
+
/** Byte size locked into the presigned URL signature. */
|
|
59
|
+
partSize?: number;
|
|
60
|
+
/** Override default bucket. */
|
|
61
|
+
bucket?: string;
|
|
62
|
+
};
|
|
63
|
+
/** Payload for {@link S3Api.multipart.listParts}. */
|
|
64
|
+
export type MultipartListPartsPayload = S3ApiHeaders & {
|
|
65
|
+
/** S3 object key. */
|
|
66
|
+
key: string;
|
|
67
|
+
/** Multipart upload ID. */
|
|
68
|
+
uploadId: string;
|
|
69
|
+
/** Override default bucket. */
|
|
70
|
+
bucket?: string;
|
|
71
|
+
};
|
|
72
|
+
/** A completed multipart part reference for {@link S3Api.multipart.complete}. */
|
|
73
|
+
export type MultipartCompletedPartRef = {
|
|
74
|
+
/** 1-based part number. */
|
|
75
|
+
partNumber: number;
|
|
76
|
+
};
|
|
77
|
+
/** Payload for {@link S3Api.multipart.complete}. */
|
|
78
|
+
export type MultipartCompletePayload = S3ApiHeaders & {
|
|
79
|
+
/** S3 object key. */
|
|
80
|
+
key: string;
|
|
81
|
+
/** Multipart upload ID. */
|
|
82
|
+
uploadId: string;
|
|
83
|
+
/** Parts to assemble (order does not matter — S3 sorts by part number). */
|
|
84
|
+
parts: MultipartCompletedPartRef[];
|
|
85
|
+
/** Override default bucket. */
|
|
86
|
+
bucket?: string;
|
|
87
|
+
};
|
|
88
|
+
/** Payload for {@link S3Api.multipart.abort}. */
|
|
89
|
+
export type MultipartAbortPayload = S3ApiHeaders & {
|
|
90
|
+
/** S3 object key. */
|
|
91
|
+
key: string;
|
|
92
|
+
/** Multipart upload ID. */
|
|
93
|
+
uploadId: string;
|
|
94
|
+
/** Override default bucket. */
|
|
95
|
+
bucket?: string;
|
|
96
|
+
};
|
|
97
|
+
export type { UploadPresignMethod };
|
|
98
|
+
//# sourceMappingURL=requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../src/types/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AbortPayload, MultipartCompletePayload, MultipartInitPayload, MultipartListPartsPayload, MultipartSignPartPayload, S3ObjectAcl, UploadPayload, UploadPresignMethod } from "./requests";
|
|
2
|
+
/** Response from {@link S3Api.delete}. */
|
|
3
|
+
export type DeleteResponse = {
|
|
4
|
+
success: boolean;
|
|
5
|
+
bucket: string;
|
|
6
|
+
key: string;
|
|
7
|
+
};
|
|
8
|
+
/** Response from {@link S3Api.multipart.complete}. */
|
|
9
|
+
export type MultipartCompleteResponse = {
|
|
10
|
+
key: string;
|
|
11
|
+
bucket: string;
|
|
12
|
+
uploadId: string;
|
|
13
|
+
/** Verified size in bytes. */
|
|
14
|
+
contentLength: number;
|
|
15
|
+
contentType?: string;
|
|
16
|
+
eTag?: string;
|
|
17
|
+
metadata: Record<string, string>;
|
|
18
|
+
versionId?: string;
|
|
19
|
+
lastModified?: string;
|
|
20
|
+
/** Resolved ACL. Omitted when ACL lookup is disabled or unsupported. */
|
|
21
|
+
acl?: S3ObjectAcl;
|
|
22
|
+
/** Stored filename. */
|
|
23
|
+
fileName?: string;
|
|
24
|
+
};
|
|
25
|
+
/** Response from {@link S3Api.multipart.abort}. */
|
|
26
|
+
export type MultipartAbortResponse = {
|
|
27
|
+
aborted: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** Presigned GET URL for download. */
|
|
30
|
+
export type PresignResponse = {
|
|
31
|
+
/** S3 object key. */
|
|
32
|
+
key: string;
|
|
33
|
+
/** Target bucket. */
|
|
34
|
+
bucket: string;
|
|
35
|
+
/** Presigned URL. */
|
|
36
|
+
url: string;
|
|
37
|
+
/** Validity in seconds. */
|
|
38
|
+
expiresIn: number;
|
|
39
|
+
};
|
|
40
|
+
/** Presigned upload URL and method-specific fields. */
|
|
41
|
+
export type UploadPresignResponse = {
|
|
42
|
+
/** S3 object key. */
|
|
43
|
+
key: string;
|
|
44
|
+
/** Target bucket. */
|
|
45
|
+
bucket: string;
|
|
46
|
+
/** Presigned upload URL. */
|
|
47
|
+
url: string;
|
|
48
|
+
/** Validity in seconds. */
|
|
49
|
+
expiresIn: number;
|
|
50
|
+
/** HTTP method for the upload request. */
|
|
51
|
+
method: UploadPresignMethod;
|
|
52
|
+
/** Present when `method` is `"POST"`. Must be appended to FormData before the file. */
|
|
53
|
+
fields?: Record<string, string>;
|
|
54
|
+
/** Present when `method` is `"PUT"`. Must be set as request headers on the PUT request. */
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
};
|
|
57
|
+
/** Response from multipart upload initialization. */
|
|
58
|
+
export type MultipartInitResponse = {
|
|
59
|
+
/** S3 object key. */
|
|
60
|
+
key: string;
|
|
61
|
+
/** Target bucket. */
|
|
62
|
+
bucket: string;
|
|
63
|
+
/** S3 multipart upload ID. */
|
|
64
|
+
uploadId: string;
|
|
65
|
+
};
|
|
66
|
+
/** Presigned URL for a single multipart part. */
|
|
67
|
+
export type MultipartPartResponse = {
|
|
68
|
+
/** Presigned PUT URL for this part. */
|
|
69
|
+
presignedUrl: string;
|
|
70
|
+
/** 1-based part number. */
|
|
71
|
+
partNumber: number;
|
|
72
|
+
/** Multipart upload ID. */
|
|
73
|
+
uploadId: string;
|
|
74
|
+
/** Target bucket. */
|
|
75
|
+
bucket: string;
|
|
76
|
+
/** Validity in seconds. */
|
|
77
|
+
expiresIn: number;
|
|
78
|
+
/** Exact byte size locked into this part's presigned URL signature. */
|
|
79
|
+
partSize?: number;
|
|
80
|
+
};
|
|
81
|
+
/** A part already uploaded in a multipart session. */
|
|
82
|
+
export type MultipartPartInfo = {
|
|
83
|
+
/** 1-based part number. */
|
|
84
|
+
partNumber: number;
|
|
85
|
+
/** Part size in bytes. */
|
|
86
|
+
size: number;
|
|
87
|
+
/** Part ETag from S3. */
|
|
88
|
+
eTag: string;
|
|
89
|
+
};
|
|
90
|
+
/** Response from listing uploaded multipart parts. */
|
|
91
|
+
export type MultipartListPartsResponse = {
|
|
92
|
+
parts: MultipartPartInfo[];
|
|
93
|
+
};
|
|
94
|
+
/** Verified object metadata after upload confirmation. */
|
|
95
|
+
export type UploadConfirmResponse = {
|
|
96
|
+
/** S3 object key. */
|
|
97
|
+
key: string;
|
|
98
|
+
/** Target bucket. */
|
|
99
|
+
bucket: string;
|
|
100
|
+
/** MIME type from HeadObject. */
|
|
101
|
+
contentType?: string;
|
|
102
|
+
/** Verified size in bytes. */
|
|
103
|
+
contentLength: number;
|
|
104
|
+
/** ETag from HeadObject. */
|
|
105
|
+
eTag?: string;
|
|
106
|
+
/** Object metadata. */
|
|
107
|
+
metadata: Record<string, string>;
|
|
108
|
+
/** Object ACL. */
|
|
109
|
+
acl?: S3ObjectAcl;
|
|
110
|
+
/** Stored filename. */
|
|
111
|
+
fileName?: string;
|
|
112
|
+
/** S3 version ID. */
|
|
113
|
+
versionId?: string;
|
|
114
|
+
/** Last modified timestamp. */
|
|
115
|
+
lastModified?: string;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Presign API protocol shared by `@dimah-s3/react` hooks and `@dimah-s3/server`.
|
|
119
|
+
*
|
|
120
|
+
* Implement with `createS3Client()` from `@dimah-s3/core` / `@dimah-s3/react`,
|
|
121
|
+
* or any custom backend.
|
|
122
|
+
*/
|
|
123
|
+
export type S3Api = {
|
|
124
|
+
upload: (payload: UploadPayload) => Promise<UploadPresignResponse>;
|
|
125
|
+
confirm: (payload: ConfirmPayload) => Promise<UploadConfirmResponse>;
|
|
126
|
+
download: (key: string, options?: DownloadOptions) => Promise<PresignResponse>;
|
|
127
|
+
delete: (key: string, options?: DeleteOptions) => Promise<DeleteResponse>;
|
|
128
|
+
multipart: {
|
|
129
|
+
init: (payload: MultipartInitPayload) => Promise<MultipartInitResponse>;
|
|
130
|
+
signPart: (payload: MultipartSignPartPayload) => Promise<MultipartPartResponse>;
|
|
131
|
+
listParts: (payload: MultipartListPartsPayload) => Promise<MultipartListPartsResponse>;
|
|
132
|
+
complete: (payload: MultipartCompletePayload) => Promise<MultipartCompleteResponse>;
|
|
133
|
+
abort: (payload: MultipartAbortPayload) => Promise<MultipartAbortResponse>;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=responses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/types/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,EACzB,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,0CAA0C;AAC1C,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,sDAAsD;AACtD,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,sCAAsC;AACtC,MAAM,MAAM,eAAe,GAAG;IAC5B,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,MAAM,EAAE,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,qBAAqB,CAAC,CAAC;QACxE,QAAQ,EAAE,CACR,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,qBAAqB,CAAC,CAAC;QACpC,SAAS,EAAE,CACT,OAAO,EAAE,yBAAyB,KAC/B,OAAO,CAAC,0BAA0B,CAAC,CAAC;QACzC,QAAQ,EAAE,CACR,OAAO,EAAE,wBAAwB,KAC9B,OAAO,CAAC,yBAAyB,CAAC,CAAC;QACxC,KAAK,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;KAC5E,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-presign-method.d.ts","sourceRoot":"","sources":["../../src/types/upload-presign-method.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dimah-s3/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared types and pure helpers for @dimah-s3/react and @dimah-s3/server",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"s3",
|
|
7
|
+
"types",
|
|
8
|
+
"upload",
|
|
9
|
+
"file-upload"
|
|
10
|
+
],
|
|
11
|
+
"author": "Hamidrezakz",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/dimah-kz/dimah-s3.git",
|
|
16
|
+
"directory": "packages/core"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://github.com/dimah-kz/dimah-s3/tree/main/packages/core",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/dimah-kz/dimah-s3/issues"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"type": "module",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"eslint": "^10.8.0",
|
|
35
|
+
"tsup": "^8.5.1",
|
|
36
|
+
"typescript": "7.0.2",
|
|
37
|
+
"vitest": "^4.1.10",
|
|
38
|
+
"@workspace/eslint-config": "0.0.1",
|
|
39
|
+
"@workspace/typescript-config": "0.0.1"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup --config tsup.config.ts && tsc --emitDeclarationOnly",
|
|
46
|
+
"lint": "eslint",
|
|
47
|
+
"check-types": "tsc --noEmit",
|
|
48
|
+
"test": "vitest run"
|
|
49
|
+
}
|
|
50
|
+
}
|