@useupup/server 3.3.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 +322 -0
- package/dist/config-3b434689.d.cts +297 -0
- package/dist/config-3b434689.d.ts +297 -0
- package/dist/express.cjs +2360 -0
- package/dist/express.cjs.map +1 -0
- package/dist/express.d.cts +19 -0
- package/dist/express.d.ts +19 -0
- package/dist/express.js +2358 -0
- package/dist/express.js.map +1 -0
- package/dist/fastify.cjs +2365 -0
- package/dist/fastify.cjs.map +1 -0
- package/dist/fastify.d.cts +32 -0
- package/dist/fastify.d.ts +32 -0
- package/dist/fastify.js +2363 -0
- package/dist/fastify.js.map +1 -0
- package/dist/handler-030ee446.d.cts +6 -0
- package/dist/handler-9f2df17e.d.ts +6 -0
- package/dist/hono.cjs +2314 -0
- package/dist/hono.cjs.map +1 -0
- package/dist/hono.d.cts +7 -0
- package/dist/hono.d.ts +7 -0
- package/dist/hono.js +2312 -0
- package/dist/hono.js.map +1 -0
- package/dist/index.cjs +2349 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +2342 -0
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +2359 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.cts +27 -0
- package/dist/next.d.ts +27 -0
- package/dist/next.js +2355 -0
- package/dist/next.js.map +1 -0
- package/dist/node-http-bridge.cjs +59 -0
- package/dist/node-http-bridge.cjs.map +1 -0
- package/dist/node-http-bridge.d.cts +29 -0
- package/dist/node-http-bridge.d.ts +29 -0
- package/dist/node-http-bridge.js +32 -0
- package/dist/node-http-bridge.js.map +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE Node-request -> Web-`Request` and Web-`Response` -> Node-response bridge
|
|
3
|
+
* for @useupup/server's Node adapters (F-651). express.ts, fastify.ts, and
|
|
4
|
+
* @useupup/next's pages-handler.ts each hand-rolled this conversion and drifted:
|
|
5
|
+
* two copied ALL response headers (incl. content-length) and sent a `.text()`
|
|
6
|
+
* string; one correctly skipped content-length and sent a lossless Buffer. This
|
|
7
|
+
* module pins the correct behavior for every future Node adapter to import
|
|
8
|
+
* rather than re-derive.
|
|
9
|
+
*
|
|
10
|
+
* hono.ts / next.ts (App Router) are web-native (they receive/return a Web
|
|
11
|
+
* Request/Response directly) and do not need this bridge.
|
|
12
|
+
*/
|
|
13
|
+
declare function nodeHeadersToWeb(h: Record<string, string | string[] | undefined>): Headers;
|
|
14
|
+
declare function toWebRequest(input: {
|
|
15
|
+
url: string;
|
|
16
|
+
method: string;
|
|
17
|
+
headers: Record<string, string | string[] | undefined>;
|
|
18
|
+
body?: RequestInit['body'];
|
|
19
|
+
}): Request;
|
|
20
|
+
/** Minimal Node-response sink. Express's res, Fastify's reply (via a thin
|
|
21
|
+
* method-name adapter), and Next's NextApiResponse all satisfy this shape. */
|
|
22
|
+
interface NodeResponseSink {
|
|
23
|
+
status(code: number): void;
|
|
24
|
+
setHeader(name: string, value: string): void;
|
|
25
|
+
send(body: Buffer): void;
|
|
26
|
+
}
|
|
27
|
+
declare function writeWebResponse(sink: NodeResponseSink, webRes: Response): Promise<void>;
|
|
28
|
+
|
|
29
|
+
export { type NodeResponseSink, nodeHeadersToWeb, toWebRequest, writeWebResponse };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/node-http-bridge.ts
|
|
2
|
+
function nodeHeadersToWeb(h) {
|
|
3
|
+
const headers = new Headers();
|
|
4
|
+
for (const [k, v] of Object.entries(h)) {
|
|
5
|
+
if (v === void 0) continue;
|
|
6
|
+
if (Array.isArray(v)) for (const one of v) headers.append(k, one);
|
|
7
|
+
else headers.set(k, v);
|
|
8
|
+
}
|
|
9
|
+
return headers;
|
|
10
|
+
}
|
|
11
|
+
function toWebRequest(input) {
|
|
12
|
+
const hasBody = input.method !== "GET" && input.method !== "HEAD";
|
|
13
|
+
return new Request(input.url, {
|
|
14
|
+
method: input.method,
|
|
15
|
+
headers: nodeHeadersToWeb(input.headers),
|
|
16
|
+
...hasBody && input.body != null ? { body: input.body } : {}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async function writeWebResponse(sink, webRes) {
|
|
20
|
+
sink.status(webRes.status);
|
|
21
|
+
webRes.headers.forEach((value, key) => {
|
|
22
|
+
if (key.toLowerCase() === "content-length") return;
|
|
23
|
+
sink.setHeader(key, value);
|
|
24
|
+
});
|
|
25
|
+
sink.send(Buffer.from(await webRes.arrayBuffer()));
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
nodeHeadersToWeb,
|
|
29
|
+
toWebRequest,
|
|
30
|
+
writeWebResponse
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=node-http-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node-http-bridge.ts"],"sourcesContent":["/**\r\n * The ONE Node-request -> Web-`Request` and Web-`Response` -> Node-response bridge\r\n * for @useupup/server's Node adapters (F-651). express.ts, fastify.ts, and\r\n * @useupup/next's pages-handler.ts each hand-rolled this conversion and drifted:\r\n * two copied ALL response headers (incl. content-length) and sent a `.text()`\r\n * string; one correctly skipped content-length and sent a lossless Buffer. This\r\n * module pins the correct behavior for every future Node adapter to import\r\n * rather than re-derive.\r\n *\r\n * hono.ts / next.ts (App Router) are web-native (they receive/return a Web\r\n * Request/Response directly) and do not need this bridge.\r\n */\r\n\r\nexport function nodeHeadersToWeb(\r\n h: Record<string, string | string[] | undefined>,\r\n): Headers {\r\n const headers = new Headers()\r\n for (const [k, v] of Object.entries(h)) {\r\n if (v === undefined) continue\r\n if (Array.isArray(v)) for (const one of v) headers.append(k, one)\r\n else headers.set(k, v)\r\n }\r\n return headers\r\n}\r\n\r\nexport function toWebRequest(input: {\r\n url: string\r\n method: string\r\n headers: Record<string, string | string[] | undefined>\r\n // RequestInit['body'] (not the bare BodyInit alias): this tsconfig's\r\n // lib:[\"ES2020\"] + @types/node resolve the composite RequestInit interface\r\n // globally (used elsewhere in this package, e.g. normalize-origin.ts) but\r\n // not every constituent type alias as its own global name.\r\n body?: RequestInit['body']\r\n}): Request {\r\n const hasBody = input.method !== 'GET' && input.method !== 'HEAD'\r\n return new Request(input.url, {\r\n method: input.method,\r\n headers: nodeHeadersToWeb(input.headers),\r\n ...(hasBody && input.body != null ? { body: input.body } : {}),\r\n })\r\n}\r\n\r\n/** Minimal Node-response sink. Express's res, Fastify's reply (via a thin\r\n * method-name adapter), and Next's NextApiResponse all satisfy this shape. */\r\nexport interface NodeResponseSink {\r\n status(code: number): void\r\n setHeader(name: string, value: string): void\r\n send(body: Buffer): void\r\n}\r\n\r\nexport async function writeWebResponse(\r\n sink: NodeResponseSink,\r\n webRes: Response,\r\n): Promise<void> {\r\n sink.status(webRes.status)\r\n webRes.headers.forEach((value, key) => {\r\n // Node recomputes content-length from the payload; copying it risks a mismatch.\r\n if (key.toLowerCase() === 'content-length') return\r\n sink.setHeader(key, value)\r\n })\r\n sink.send(Buffer.from(await webRes.arrayBuffer()))\r\n}\r\n"],"mappings":";AAaO,SAAS,iBACZ,GACO;AACP,QAAM,UAAU,IAAI,QAAQ;AAC5B,aAAW,CAAC,GAAG,CAAC,KAAK,OAAO,QAAQ,CAAC,GAAG;AACpC,QAAI,MAAM,OAAW;AACrB,QAAI,MAAM,QAAQ,CAAC,EAAG,YAAW,OAAO,EAAG,SAAQ,OAAO,GAAG,GAAG;AAAA,QAC3D,SAAQ,IAAI,GAAG,CAAC;AAAA,EACzB;AACA,SAAO;AACX;AAEO,SAAS,aAAa,OASjB;AACR,QAAM,UAAU,MAAM,WAAW,SAAS,MAAM,WAAW;AAC3D,SAAO,IAAI,QAAQ,MAAM,KAAK;AAAA,IAC1B,QAAQ,MAAM;AAAA,IACd,SAAS,iBAAiB,MAAM,OAAO;AAAA,IACvC,GAAI,WAAW,MAAM,QAAQ,OAAO,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;AAAA,EAChE,CAAC;AACL;AAUA,eAAsB,iBAClB,MACA,QACa;AACb,OAAK,OAAO,OAAO,MAAM;AACzB,SAAO,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AAEnC,QAAI,IAAI,YAAY,MAAM,iBAAkB;AAC5C,SAAK,UAAU,KAAK,KAAK;AAAA,EAC7B,CAAC;AACD,OAAK,KAAK,OAAO,KAAK,MAAM,OAAO,YAAY,CAAC,CAAC;AACrD;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@useupup/server",
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"description": "Server-mode endpoints for the upup uploader — S3-compatible presign + proxy uploads, cloud-drive token exchange, and an HMAC-signed upload-token trust model. Framework-agnostic with Next.js/Express/Fastify/Hono adapters.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"file-upload",
|
|
7
|
+
"uploader",
|
|
8
|
+
"server",
|
|
9
|
+
"s3",
|
|
10
|
+
"s3-compatible",
|
|
11
|
+
"presigned-url",
|
|
12
|
+
"multipart",
|
|
13
|
+
"hmac",
|
|
14
|
+
"express",
|
|
15
|
+
"fastify",
|
|
16
|
+
"hono",
|
|
17
|
+
"google-drive",
|
|
18
|
+
"one-drive",
|
|
19
|
+
"drag-and-drop",
|
|
20
|
+
"dropzone",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://useupup.com",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/DevinoSolutions/upup/issues"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/DevinoSolutions/upup.git",
|
|
30
|
+
"directory": "packages/server"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"exports": {
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/index.js",
|
|
45
|
+
"require": "./dist/index.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./next": {
|
|
48
|
+
"types": "./dist/next.d.ts",
|
|
49
|
+
"import": "./dist/next.js",
|
|
50
|
+
"require": "./dist/next.cjs"
|
|
51
|
+
},
|
|
52
|
+
"./express": {
|
|
53
|
+
"types": "./dist/express.d.ts",
|
|
54
|
+
"import": "./dist/express.js",
|
|
55
|
+
"require": "./dist/express.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./hono": {
|
|
58
|
+
"types": "./dist/hono.d.ts",
|
|
59
|
+
"import": "./dist/hono.js",
|
|
60
|
+
"require": "./dist/hono.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./fastify": {
|
|
63
|
+
"types": "./dist/fastify.d.ts",
|
|
64
|
+
"import": "./dist/fastify.js",
|
|
65
|
+
"require": "./dist/fastify.cjs"
|
|
66
|
+
},
|
|
67
|
+
"./node-bridge": {
|
|
68
|
+
"types": "./dist/node-http-bridge.d.ts",
|
|
69
|
+
"import": "./dist/node-http-bridge.js",
|
|
70
|
+
"require": "./dist/node-http-bridge.cjs"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"main": "./dist/index.cjs",
|
|
74
|
+
"module": "./dist/index.js",
|
|
75
|
+
"types": "./dist/index.d.ts",
|
|
76
|
+
"files": [
|
|
77
|
+
"dist"
|
|
78
|
+
],
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"@aws-sdk/client-s3": "^3.689.0",
|
|
81
|
+
"@aws-sdk/s3-request-presigner": "^3.689.0",
|
|
82
|
+
"@useupup/core": "3.3.0"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@types/node": "^20.10.0",
|
|
86
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
87
|
+
"eslint": "^10.6.0",
|
|
88
|
+
"tsup": "^8.4.0",
|
|
89
|
+
"typescript": "^5.3.2",
|
|
90
|
+
"vitest": "^4.1.2",
|
|
91
|
+
"@useupup/eslint-config": "0.1.0"
|
|
92
|
+
},
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "tsup",
|
|
95
|
+
"dev": "tsup --watch",
|
|
96
|
+
"lint": "eslint . --max-warnings 0",
|
|
97
|
+
"test": "vitest run",
|
|
98
|
+
"test:coverage": "vitest run --coverage",
|
|
99
|
+
"test:watch": "vitest",
|
|
100
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit"
|
|
101
|
+
}
|
|
102
|
+
}
|