@uplift-io/uploadthing 1.0.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/dist/index.cjs +69 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Uplift contributors
|
|
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/dist/index.cjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
uploadthing: () => uploadthing
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_uplift = require("@uplift-io/uplift");
|
|
27
|
+
function uploadthing(options) {
|
|
28
|
+
return {
|
|
29
|
+
provider: "uploadthing",
|
|
30
|
+
async put(input) {
|
|
31
|
+
const result = await options.uploader(input.body, input);
|
|
32
|
+
const uploaded = normalizeUploadThingResult(Array.isArray(result) ? result[0] : result);
|
|
33
|
+
if (!uploaded) {
|
|
34
|
+
throw new import_uplift.UploadError("UPLOAD_FAILED", "UploadThing did not return an uploaded file.");
|
|
35
|
+
}
|
|
36
|
+
const url = uploaded.ufsUrl ?? uploaded.url ?? uploaded.appUrl;
|
|
37
|
+
if (!url) {
|
|
38
|
+
throw new import_uplift.UploadError("UPLOAD_FAILED", "UploadThing did not return a file URL.");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
url,
|
|
42
|
+
key: uploaded.key ?? input.key,
|
|
43
|
+
name: uploaded.name ?? input.file.name,
|
|
44
|
+
type: uploaded.type ?? input.file.type,
|
|
45
|
+
size: uploaded.size ?? input.file.size,
|
|
46
|
+
extension: input.file.extension,
|
|
47
|
+
provider: "uploadthing"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function normalizeUploadThingResult(result) {
|
|
53
|
+
if (!result) return void 0;
|
|
54
|
+
if (isWrappedUploadThingResponse(result)) {
|
|
55
|
+
if (result.error) {
|
|
56
|
+
throw new import_uplift.UploadError("UPLOAD_FAILED", result.error.message ?? "UploadThing rejected the upload.");
|
|
57
|
+
}
|
|
58
|
+
return result.data ?? void 0;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function isWrappedUploadThingResponse(result) {
|
|
63
|
+
return "data" in result;
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
uploadthing
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { UploadError, type StorageAdapter, type StoragePutInput, type UploadedFile } from \"@uplift-io/uplift\";\n\r\nexport type UploadThingFileResult = {\r\n url?: string | null;\r\n ufsUrl?: string | null;\r\n appUrl?: string | null;\r\n key?: string | null;\r\n name?: string | null;\r\n type?: string | null;\r\n size?: number | null;\r\n};\r\n\r\nexport type UploadThingUploadResponse =\r\n | UploadThingFileResult\r\n | {\r\n data: UploadThingFileResult | null;\r\n error: { message?: string; code?: string; data?: unknown } | null;\r\n };\r\n\r\nexport type UploadThingUploader = (\r\n file: File | File[],\r\n input: StoragePutInput\r\n) => Promise<UploadThingUploadResponse | UploadThingUploadResponse[]>;\r\n\r\nexport type UploadThingOptions = {\r\n uploader: UploadThingUploader;\r\n};\r\n\r\nexport function uploadthing(options: UploadThingOptions): StorageAdapter {\r\n return {\r\n provider: \"uploadthing\",\r\n async put(input) {\r\n const result = await options.uploader(input.body, input);\r\n const uploaded = normalizeUploadThingResult(Array.isArray(result) ? result[0] : result);\r\n if (!uploaded) {\r\n throw new UploadError(\"UPLOAD_FAILED\", \"UploadThing did not return an uploaded file.\");\r\n }\r\n\r\n const url = uploaded.ufsUrl ?? uploaded.url ?? uploaded.appUrl;\r\n if (!url) {\r\n throw new UploadError(\"UPLOAD_FAILED\", \"UploadThing did not return a file URL.\");\r\n }\r\n\r\n return {\r\n url,\r\n key: uploaded.key ?? input.key,\r\n name: uploaded.name ?? input.file.name,\r\n type: uploaded.type ?? input.file.type,\r\n size: uploaded.size ?? input.file.size,\r\n extension: input.file.extension,\r\n provider: \"uploadthing\"\r\n } satisfies UploadedFile;\r\n }\r\n };\r\n}\r\n\r\nfunction normalizeUploadThingResult(result: UploadThingUploadResponse | undefined): UploadThingFileResult | undefined {\r\n if (!result) return undefined;\r\n if (isWrappedUploadThingResponse(result)) {\r\n if (result.error) {\r\n throw new UploadError(\"UPLOAD_FAILED\", result.error.message ?? \"UploadThing rejected the upload.\");\r\n }\r\n return result.data ?? undefined;\r\n }\r\n return result;\r\n}\r\n\r\nfunction isWrappedUploadThingResponse(result: UploadThingUploadResponse): result is Extract<\r\n UploadThingUploadResponse,\r\n { data: UploadThingFileResult | null }\r\n> {\r\n return \"data\" in result;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0F;AA4BnF,SAAS,YAAY,SAA6C;AACvE,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,IAAI,OAAO;AACf,YAAM,SAAS,MAAM,QAAQ,SAAS,MAAM,MAAM,KAAK;AACvD,YAAM,WAAW,2BAA2B,MAAM,QAAQ,MAAM,IAAI,OAAO,CAAC,IAAI,MAAM;AACtF,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,0BAAY,iBAAiB,8CAA8C;AAAA,MACvF;AAEA,YAAM,MAAM,SAAS,UAAU,SAAS,OAAO,SAAS;AACxD,UAAI,CAAC,KAAK;AACR,cAAM,IAAI,0BAAY,iBAAiB,wCAAwC;AAAA,MACjF;AAEA,aAAO;AAAA,QACL;AAAA,QACA,KAAK,SAAS,OAAO,MAAM;AAAA,QAC3B,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,WAAW,MAAM,KAAK;AAAA,QACtB,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,2BAA2B,QAAkF;AACpH,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,6BAA6B,MAAM,GAAG;AACxC,QAAI,OAAO,OAAO;AAChB,YAAM,IAAI,0BAAY,iBAAiB,OAAO,MAAM,WAAW,kCAAkC;AAAA,IACnG;AACA,WAAO,OAAO,QAAQ;AAAA,EACxB;AACA,SAAO;AACT;AAEA,SAAS,6BAA6B,QAGpC;AACA,SAAO,UAAU;AACnB;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StoragePutInput, StorageAdapter } from '@uplift-io/uplift';
|
|
2
|
+
|
|
3
|
+
type UploadThingFileResult = {
|
|
4
|
+
url?: string | null;
|
|
5
|
+
ufsUrl?: string | null;
|
|
6
|
+
appUrl?: string | null;
|
|
7
|
+
key?: string | null;
|
|
8
|
+
name?: string | null;
|
|
9
|
+
type?: string | null;
|
|
10
|
+
size?: number | null;
|
|
11
|
+
};
|
|
12
|
+
type UploadThingUploadResponse = UploadThingFileResult | {
|
|
13
|
+
data: UploadThingFileResult | null;
|
|
14
|
+
error: {
|
|
15
|
+
message?: string;
|
|
16
|
+
code?: string;
|
|
17
|
+
data?: unknown;
|
|
18
|
+
} | null;
|
|
19
|
+
};
|
|
20
|
+
type UploadThingUploader = (file: File | File[], input: StoragePutInput) => Promise<UploadThingUploadResponse | UploadThingUploadResponse[]>;
|
|
21
|
+
type UploadThingOptions = {
|
|
22
|
+
uploader: UploadThingUploader;
|
|
23
|
+
};
|
|
24
|
+
declare function uploadthing(options: UploadThingOptions): StorageAdapter;
|
|
25
|
+
|
|
26
|
+
export { type UploadThingFileResult, type UploadThingOptions, type UploadThingUploadResponse, type UploadThingUploader, uploadthing };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StoragePutInput, StorageAdapter } from '@uplift-io/uplift';
|
|
2
|
+
|
|
3
|
+
type UploadThingFileResult = {
|
|
4
|
+
url?: string | null;
|
|
5
|
+
ufsUrl?: string | null;
|
|
6
|
+
appUrl?: string | null;
|
|
7
|
+
key?: string | null;
|
|
8
|
+
name?: string | null;
|
|
9
|
+
type?: string | null;
|
|
10
|
+
size?: number | null;
|
|
11
|
+
};
|
|
12
|
+
type UploadThingUploadResponse = UploadThingFileResult | {
|
|
13
|
+
data: UploadThingFileResult | null;
|
|
14
|
+
error: {
|
|
15
|
+
message?: string;
|
|
16
|
+
code?: string;
|
|
17
|
+
data?: unknown;
|
|
18
|
+
} | null;
|
|
19
|
+
};
|
|
20
|
+
type UploadThingUploader = (file: File | File[], input: StoragePutInput) => Promise<UploadThingUploadResponse | UploadThingUploadResponse[]>;
|
|
21
|
+
type UploadThingOptions = {
|
|
22
|
+
uploader: UploadThingUploader;
|
|
23
|
+
};
|
|
24
|
+
declare function uploadthing(options: UploadThingOptions): StorageAdapter;
|
|
25
|
+
|
|
26
|
+
export { type UploadThingFileResult, type UploadThingOptions, type UploadThingUploadResponse, type UploadThingUploader, uploadthing };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { UploadError } from "@uplift-io/uplift";
|
|
3
|
+
function uploadthing(options) {
|
|
4
|
+
return {
|
|
5
|
+
provider: "uploadthing",
|
|
6
|
+
async put(input) {
|
|
7
|
+
const result = await options.uploader(input.body, input);
|
|
8
|
+
const uploaded = normalizeUploadThingResult(Array.isArray(result) ? result[0] : result);
|
|
9
|
+
if (!uploaded) {
|
|
10
|
+
throw new UploadError("UPLOAD_FAILED", "UploadThing did not return an uploaded file.");
|
|
11
|
+
}
|
|
12
|
+
const url = uploaded.ufsUrl ?? uploaded.url ?? uploaded.appUrl;
|
|
13
|
+
if (!url) {
|
|
14
|
+
throw new UploadError("UPLOAD_FAILED", "UploadThing did not return a file URL.");
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
url,
|
|
18
|
+
key: uploaded.key ?? input.key,
|
|
19
|
+
name: uploaded.name ?? input.file.name,
|
|
20
|
+
type: uploaded.type ?? input.file.type,
|
|
21
|
+
size: uploaded.size ?? input.file.size,
|
|
22
|
+
extension: input.file.extension,
|
|
23
|
+
provider: "uploadthing"
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function normalizeUploadThingResult(result) {
|
|
29
|
+
if (!result) return void 0;
|
|
30
|
+
if (isWrappedUploadThingResponse(result)) {
|
|
31
|
+
if (result.error) {
|
|
32
|
+
throw new UploadError("UPLOAD_FAILED", result.error.message ?? "UploadThing rejected the upload.");
|
|
33
|
+
}
|
|
34
|
+
return result.data ?? void 0;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
function isWrappedUploadThingResponse(result) {
|
|
39
|
+
return "data" in result;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
uploadthing
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { UploadError, type StorageAdapter, type StoragePutInput, type UploadedFile } from \"@uplift-io/uplift\";\n\r\nexport type UploadThingFileResult = {\r\n url?: string | null;\r\n ufsUrl?: string | null;\r\n appUrl?: string | null;\r\n key?: string | null;\r\n name?: string | null;\r\n type?: string | null;\r\n size?: number | null;\r\n};\r\n\r\nexport type UploadThingUploadResponse =\r\n | UploadThingFileResult\r\n | {\r\n data: UploadThingFileResult | null;\r\n error: { message?: string; code?: string; data?: unknown } | null;\r\n };\r\n\r\nexport type UploadThingUploader = (\r\n file: File | File[],\r\n input: StoragePutInput\r\n) => Promise<UploadThingUploadResponse | UploadThingUploadResponse[]>;\r\n\r\nexport type UploadThingOptions = {\r\n uploader: UploadThingUploader;\r\n};\r\n\r\nexport function uploadthing(options: UploadThingOptions): StorageAdapter {\r\n return {\r\n provider: \"uploadthing\",\r\n async put(input) {\r\n const result = await options.uploader(input.body, input);\r\n const uploaded = normalizeUploadThingResult(Array.isArray(result) ? result[0] : result);\r\n if (!uploaded) {\r\n throw new UploadError(\"UPLOAD_FAILED\", \"UploadThing did not return an uploaded file.\");\r\n }\r\n\r\n const url = uploaded.ufsUrl ?? uploaded.url ?? uploaded.appUrl;\r\n if (!url) {\r\n throw new UploadError(\"UPLOAD_FAILED\", \"UploadThing did not return a file URL.\");\r\n }\r\n\r\n return {\r\n url,\r\n key: uploaded.key ?? input.key,\r\n name: uploaded.name ?? input.file.name,\r\n type: uploaded.type ?? input.file.type,\r\n size: uploaded.size ?? input.file.size,\r\n extension: input.file.extension,\r\n provider: \"uploadthing\"\r\n } satisfies UploadedFile;\r\n }\r\n };\r\n}\r\n\r\nfunction normalizeUploadThingResult(result: UploadThingUploadResponse | undefined): UploadThingFileResult | undefined {\r\n if (!result) return undefined;\r\n if (isWrappedUploadThingResponse(result)) {\r\n if (result.error) {\r\n throw new UploadError(\"UPLOAD_FAILED\", result.error.message ?? \"UploadThing rejected the upload.\");\r\n }\r\n return result.data ?? undefined;\r\n }\r\n return result;\r\n}\r\n\r\nfunction isWrappedUploadThingResponse(result: UploadThingUploadResponse): result is Extract<\r\n UploadThingUploadResponse,\r\n { data: UploadThingFileResult | null }\r\n> {\r\n return \"data\" in result;\r\n}\r\n"],"mappings":";AAAA,SAAS,mBAAiF;AA4BnF,SAAS,YAAY,SAA6C;AACvE,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,IAAI,OAAO;AACf,YAAM,SAAS,MAAM,QAAQ,SAAS,MAAM,MAAM,KAAK;AACvD,YAAM,WAAW,2BAA2B,MAAM,QAAQ,MAAM,IAAI,OAAO,CAAC,IAAI,MAAM;AACtF,UAAI,CAAC,UAAU;AACb,cAAM,IAAI,YAAY,iBAAiB,8CAA8C;AAAA,MACvF;AAEA,YAAM,MAAM,SAAS,UAAU,SAAS,OAAO,SAAS;AACxD,UAAI,CAAC,KAAK;AACR,cAAM,IAAI,YAAY,iBAAiB,wCAAwC;AAAA,MACjF;AAEA,aAAO;AAAA,QACL;AAAA,QACA,KAAK,SAAS,OAAO,MAAM;AAAA,QAC3B,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,MAAM,SAAS,QAAQ,MAAM,KAAK;AAAA,QAClC,WAAW,MAAM,KAAK;AAAA,QACtB,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,2BAA2B,QAAkF;AACpH,MAAI,CAAC,OAAQ,QAAO;AACpB,MAAI,6BAA6B,MAAM,GAAG;AACxC,QAAI,OAAO,OAAO;AAChB,YAAM,IAAI,YAAY,iBAAiB,OAAO,MAAM,WAAW,kCAAkC;AAAA,IACnG;AACA,WAAO,OAAO,QAAQ;AAAA,EACxB;AACA,SAAO;AACT;AAEA,SAAS,6BAA6B,QAGpC;AACA,SAAO,UAAU;AACnB;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uplift-io/uploadthing",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@uplift-io/uplift": "1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://itzfeminisce.github.io/uplift/",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/Itzfeminisce/uplift.git",
|
|
26
|
+
"directory": "packages/uploadthing"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/Itzfeminisce/uplift/issues"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
34
|
+
}
|
|
35
|
+
}
|