@edgestore/server 0.7.0 → 1.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/adapters/astro/index.d.ts +1 -1
  2. package/adapters/astro/index.js +1 -1
  3. package/adapters/express/index.d.ts +1 -1
  4. package/adapters/express/index.js +1 -1
  5. package/adapters/fastify/index.d.ts +1 -1
  6. package/adapters/fastify/index.js +1 -1
  7. package/adapters/hono/index.d.ts +1 -1
  8. package/adapters/hono/index.js +1 -1
  9. package/adapters/next/app/index.d.ts +1 -1
  10. package/adapters/next/app/index.js +1 -1
  11. package/adapters/next/pages/index.d.ts +1 -1
  12. package/adapters/next/pages/index.js +1 -1
  13. package/adapters/remix/index.d.ts +1 -1
  14. package/adapters/remix/index.js +1 -1
  15. package/adapters/start/index.d.ts +1 -1
  16. package/adapters/start/index.js +1 -1
  17. package/core/index.d.ts +1 -1
  18. package/core/index.js +1 -1
  19. package/dist/adapters/astro/index.d.ts +2 -2
  20. package/dist/adapters/astro/index.d.ts.map +1 -1
  21. package/dist/adapters/astro/index.js +35 -43
  22. package/dist/adapters/express/index.d.ts +2 -2
  23. package/dist/adapters/express/index.d.ts.map +1 -1
  24. package/dist/adapters/express/index.js +34 -41
  25. package/dist/adapters/fastify/index.d.ts +3 -3
  26. package/dist/adapters/fastify/index.d.ts.map +1 -1
  27. package/dist/adapters/fastify/index.js +33 -42
  28. package/dist/adapters/hono/index.d.ts +6 -72
  29. package/dist/adapters/hono/index.d.ts.map +1 -1
  30. package/dist/adapters/hono/index.js +38 -41
  31. package/dist/adapters/imageTypes.js +1 -3
  32. package/dist/adapters/next/app/index.d.ts +2 -2
  33. package/dist/adapters/next/app/index.d.ts.map +1 -1
  34. package/dist/adapters/next/app/index.js +34 -42
  35. package/dist/adapters/next/pages/index.d.ts +2 -2
  36. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  37. package/dist/adapters/next/pages/index.js +35 -42
  38. package/dist/adapters/remix/index.d.ts +2 -2
  39. package/dist/adapters/remix/index.d.ts.map +1 -1
  40. package/dist/adapters/remix/index.js +35 -42
  41. package/dist/adapters/shared.d.ts +8 -0
  42. package/dist/adapters/shared.d.ts.map +1 -1
  43. package/dist/adapters/shared.js +79 -56
  44. package/dist/adapters/start/index.d.ts +2 -2
  45. package/dist/adapters/start/index.d.ts.map +1 -1
  46. package/dist/adapters/start/index.js +35 -43
  47. package/dist/core/client/index.d.ts +112 -69
  48. package/dist/core/client/index.d.ts.map +1 -1
  49. package/dist/core/client/index.js +59 -13
  50. package/dist/core/index.d.ts +2 -2
  51. package/dist/core/index.js +2 -10
  52. package/dist/core/sdk/index.d.ts +44 -2
  53. package/dist/core/sdk/index.d.ts.map +1 -1
  54. package/dist/core/sdk/index.js +43 -16
  55. package/dist/index.js +1 -10
  56. package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -3
  57. package/dist/libs/logger.js +5 -9
  58. package/dist/libs/utils.js +1 -3
  59. package/dist/providers/aws/index.d.ts +1 -1
  60. package/dist/providers/aws/index.d.ts.map +1 -1
  61. package/dist/providers/aws/index.js +14 -17
  62. package/dist/providers/azure/index.d.ts.map +1 -1
  63. package/dist/providers/azure/index.js +38 -15
  64. package/dist/providers/edgestore/index.d.ts.map +1 -1
  65. package/dist/providers/edgestore/index.js +36 -18
  66. package/dist/test-utils/edgestoreSmoke.d.ts +32 -0
  67. package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -0
  68. package/dist/version.d.ts +3 -0
  69. package/dist/version.d.ts.map +1 -0
  70. package/dist/version.js +4 -0
  71. package/package.json +59 -49
  72. package/providers/aws/index.d.ts +1 -1
  73. package/providers/aws/index.js +1 -1
  74. package/providers/azure/index.d.ts +1 -1
  75. package/providers/azure/index.js +1 -1
  76. package/providers/edgestore/index.d.ts +1 -1
  77. package/providers/edgestore/index.js +1 -1
  78. package/src/adapters/astro/index.ts +11 -21
  79. package/src/adapters/express/index.ts +10 -16
  80. package/src/adapters/fastify/index.ts +13 -19
  81. package/src/adapters/hono/index.ts +19 -23
  82. package/src/adapters/next/app/index.ts +12 -22
  83. package/src/adapters/next/pages/index.ts +11 -16
  84. package/src/adapters/remix/index.ts +11 -12
  85. package/src/adapters/shared.ts +61 -17
  86. package/src/adapters/start/index.ts +11 -12
  87. package/src/core/client/index.ts +199 -75
  88. package/src/core/sdk/index.ts +76 -8
  89. package/src/providers/aws/index.ts +4 -5
  90. package/src/providers/azure/index.ts +40 -11
  91. package/src/providers/edgestore/index.ts +29 -0
  92. package/src/test-utils/edgestoreSmoke.ts +141 -0
  93. package/src/version.ts +2 -0
  94. package/dist/adapters/astro/index.mjs +0 -178
  95. package/dist/adapters/express/index.mjs +0 -113
  96. package/dist/adapters/fastify/index.mjs +0 -142
  97. package/dist/adapters/hono/index.mjs +0 -132
  98. package/dist/adapters/imageTypes.mjs +0 -12
  99. package/dist/adapters/next/app/index.mjs +0 -169
  100. package/dist/adapters/next/pages/index.mjs +0 -117
  101. package/dist/adapters/remix/index.mjs +0 -153
  102. package/dist/adapters/shared.mjs +0 -443
  103. package/dist/adapters/start/index.mjs +0 -187
  104. package/dist/core/client/index.mjs +0 -173
  105. package/dist/core/index.mjs +0 -2
  106. package/dist/core/sdk/index.mjs +0 -223
  107. package/dist/index.mjs +0 -1
  108. package/dist/libs/errors/EdgeStoreCredentialsError.mjs +0 -10
  109. package/dist/libs/logger.mjs +0 -53
  110. package/dist/libs/utils.mjs +0 -10
  111. package/dist/providers/aws/index.mjs +0 -103
  112. package/dist/providers/azure/index.mjs +0 -59
  113. package/dist/providers/edgestore/index.mjs +0 -144
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edgestoreSmoke.d.ts","sourceRoot":"","sources":["../../src/test-utils/edgestoreSmoke.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,wBAAgB,mBAAmB,WAElC;AAED,wBAAgB,kBAAkB,WAEjC;AAED,wBAAgB,uBAAuB,WAKtC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,uBAAuB,SAStC;AAMD,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,MAAM,EAAE,MAAM,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC5C,WAAW,EAAE,MAAM,CAAC;CACrB;aAE4B,OAAO;GAkCnC;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAuBF,wBAAsB,uBAAuB,CAAC,MAAM,EAAE;IACpD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9D,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC3D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IACpD,MAAM,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CACxC,4BA4BA"}
@@ -0,0 +1,3 @@
1
+ export declare const EDGE_STORE_PACKAGE_NAME = "@edgestore/server";
2
+ export declare const EDGE_STORE_PACKAGE_VERSION = "1.0.0-next.0";
3
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,eAAO,MAAM,0BAA0B,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ const EDGE_STORE_PACKAGE_NAME = '@edgestore/server';
2
+ const EDGE_STORE_PACKAGE_VERSION = '1.0.0-next.0';
3
+
4
+ export { EDGE_STORE_PACKAGE_NAME, EDGE_STORE_PACKAGE_VERSION };
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@edgestore/server",
3
- "version": "0.7.0",
3
+ "version": "1.0.0-next.0",
4
4
  "description": "Upload files with ease from React/Next.js",
5
5
  "homepage": "https://edgestore.dev",
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
8
+ "type": "module",
9
+ "engines": {
10
+ "node": ">=24"
11
+ },
8
12
  "repository": {
9
13
  "type": "git",
10
14
  "url": "https://github.com/edgestorejs/edgestore.git",
@@ -15,7 +19,6 @@
15
19
  },
16
20
  "author": "Ravi <me@ravi.com>",
17
21
  "main": "dist/index.js",
18
- "module": "dist/index.mjs",
19
22
  "types": "dist/index.d.ts",
20
23
  "keywords": [
21
24
  "react",
@@ -31,68 +34,68 @@
31
34
  "exports": {
32
35
  "./package.json": "./package.json",
33
36
  ".": {
34
- "import": "./dist/index.mjs",
35
- "require": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js",
36
39
  "default": "./dist/index.js"
37
40
  },
38
41
  "./adapters/astro": {
39
- "import": "./dist/adapters/astro/index.mjs",
40
- "require": "./dist/adapters/astro/index.js",
42
+ "types": "./dist/adapters/astro/index.d.ts",
43
+ "import": "./dist/adapters/astro/index.js",
41
44
  "default": "./dist/adapters/astro/index.js"
42
45
  },
43
46
  "./adapters/express": {
44
- "import": "./dist/adapters/express/index.mjs",
45
- "require": "./dist/adapters/express/index.js",
47
+ "types": "./dist/adapters/express/index.d.ts",
48
+ "import": "./dist/adapters/express/index.js",
46
49
  "default": "./dist/adapters/express/index.js"
47
50
  },
48
51
  "./adapters/fastify": {
49
- "import": "./dist/adapters/fastify/index.mjs",
50
- "require": "./dist/adapters/fastify/index.js",
52
+ "types": "./dist/adapters/fastify/index.d.ts",
53
+ "import": "./dist/adapters/fastify/index.js",
51
54
  "default": "./dist/adapters/fastify/index.js"
52
55
  },
53
56
  "./adapters/hono": {
54
- "import": "./dist/adapters/hono/index.mjs",
55
- "require": "./dist/adapters/hono/index.js",
57
+ "types": "./dist/adapters/hono/index.d.ts",
58
+ "import": "./dist/adapters/hono/index.js",
56
59
  "default": "./dist/adapters/hono/index.js"
57
60
  },
58
61
  "./adapters/next/app": {
59
- "import": "./dist/adapters/next/app/index.mjs",
60
- "require": "./dist/adapters/next/app/index.js",
62
+ "types": "./dist/adapters/next/app/index.d.ts",
63
+ "import": "./dist/adapters/next/app/index.js",
61
64
  "default": "./dist/adapters/next/app/index.js"
62
65
  },
63
66
  "./adapters/next/pages": {
64
- "import": "./dist/adapters/next/pages/index.mjs",
65
- "require": "./dist/adapters/next/pages/index.js",
67
+ "types": "./dist/adapters/next/pages/index.d.ts",
68
+ "import": "./dist/adapters/next/pages/index.js",
66
69
  "default": "./dist/adapters/next/pages/index.js"
67
70
  },
68
71
  "./adapters/remix": {
69
- "import": "./dist/adapters/remix/index.mjs",
70
- "require": "./dist/adapters/remix/index.js",
72
+ "types": "./dist/adapters/remix/index.d.ts",
73
+ "import": "./dist/adapters/remix/index.js",
71
74
  "default": "./dist/adapters/remix/index.js"
72
75
  },
73
76
  "./adapters/start": {
74
- "import": "./dist/adapters/start/index.mjs",
75
- "require": "./dist/adapters/start/index.js",
77
+ "types": "./dist/adapters/start/index.d.ts",
78
+ "import": "./dist/adapters/start/index.js",
76
79
  "default": "./dist/adapters/start/index.js"
77
80
  },
78
81
  "./core": {
79
- "import": "./dist/core/index.mjs",
80
- "require": "./dist/core/index.js",
82
+ "types": "./dist/core/index.d.ts",
83
+ "import": "./dist/core/index.js",
81
84
  "default": "./dist/core/index.js"
82
85
  },
83
86
  "./providers/aws": {
84
- "import": "./dist/providers/aws/index.mjs",
85
- "require": "./dist/providers/aws/index.js",
87
+ "types": "./dist/providers/aws/index.d.ts",
88
+ "import": "./dist/providers/aws/index.js",
86
89
  "default": "./dist/providers/aws/index.js"
87
90
  },
88
91
  "./providers/azure": {
89
- "import": "./dist/providers/azure/index.mjs",
90
- "require": "./dist/providers/azure/index.js",
92
+ "types": "./dist/providers/azure/index.d.ts",
93
+ "import": "./dist/providers/azure/index.js",
91
94
  "default": "./dist/providers/azure/index.js"
92
95
  },
93
96
  "./providers/edgestore": {
94
- "import": "./dist/providers/edgestore/index.mjs",
95
- "require": "./dist/providers/edgestore/index.js",
97
+ "types": "./dist/providers/edgestore/index.d.ts",
98
+ "import": "./dist/providers/edgestore/index.js",
96
99
  "default": "./dist/providers/edgestore/index.js"
97
100
  }
98
101
  },
@@ -109,11 +112,10 @@
109
112
  "!**/__tests__"
110
113
  ],
111
114
  "dependencies": {
112
- "@edgestore/shared": "0.7.0",
113
- "@panva/hkdf": "^1.0.4",
114
- "cookie": "^0.7.0",
115
- "jose": "^4.13.1",
116
- "uuid": "^9.0.0"
115
+ "@edgestore/shared": "1.0.0-next.0",
116
+ "@panva/hkdf": "^1.2.1",
117
+ "cookie": "^2.0.1",
118
+ "jose": "^6.2.3"
117
119
  },
118
120
  "peerDependencies": {
119
121
  "@aws-sdk/client-s3": ">=3.0.0",
@@ -136,28 +138,36 @@
136
138
  }
137
139
  },
138
140
  "devDependencies": {
139
- "@aws-sdk/client-s3": "^3.420.0",
140
- "@aws-sdk/s3-request-presigner": "^3.420.0",
141
- "@azure/storage-blob": "^12.17.0",
142
- "@types/cookie": "^0.5.1",
143
- "@types/express": "^4.17.21",
141
+ "@aws-sdk/client-s3": "3.1091.0",
142
+ "@aws-sdk/s3-request-presigner": "3.1091.0",
143
+ "@azure/storage-blob": "12.33.0",
144
+ "@types/express": "5.0.6",
144
145
  "@types/node": "25.0.3",
145
- "@types/uuid": "^9.0.1",
146
- "astro": "^5.7.12",
147
- "express": "^4.18.2",
148
- "fastify": "^5.3.2",
149
- "hono": "^4.7.9",
150
- "next": "16.1.1",
151
- "react": "19.2.3",
152
- "react-dom": "19.2.3",
153
- "typescript": "5.9.3",
154
- "zod": "3.25.42"
146
+ "astro": "7.1.3",
147
+ "dotenv": "17.4.2",
148
+ "express": "5.2.1",
149
+ "fastify": "5.10.0",
150
+ "hono": "4.12.31",
151
+ "next": "16.2.10",
152
+ "react": "19.2.7",
153
+ "react-dom": "19.2.7",
154
+ "tsx": "4.23.1",
155
+ "typescript": "6.0.3",
156
+ "zod": "3.25.76"
155
157
  },
156
158
  "gitHead": "a223c4cb8df50e6b64f9db5dc2daf93848748da9",
157
159
  "scripts": {
158
160
  "build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
159
161
  "dev": "pnpm build --watch",
160
162
  "codegen:entrypoints": "tsx entrypoints.script.ts",
161
- "lint": "eslint --cache --ext \".js,.ts,.tsx\" --ignore-path ../../.gitignore --report-unused-disable-directives src"
163
+ "test": "vitest run --config vitest.config.ts",
164
+ "test:smoke": "vitest run --config vitest.smoke.config.ts",
165
+ "test:smoke:dev": "TEST_ENV=dev vitest run --config vitest.smoke.config.ts",
166
+ "test:smoke:prod": "TEST_ENV=prod vitest run --config vitest.smoke.config.ts",
167
+ "test:smoke:adapter": "vitest run --config vitest.smoke.config.ts src/adapters/edgestore.smoke.test.ts",
168
+ "test:smoke:client": "vitest run --config vitest.smoke.config.ts src/core/client/edgestore.smoke.test.ts",
169
+ "test:smoke:errors": "vitest run --config vitest.smoke.config.ts src/core/sdk/edgestore.errors.smoke.test.ts",
170
+ "typecheck": "tsc --noEmit -p tsconfig.json",
171
+ "lint": "eslint --cache --report-unused-disable-directives src"
162
172
  }
163
173
  }
@@ -1 +1 @@
1
- export * from '../../dist/providers/aws';
1
+ export * from '../../dist/providers/aws/index.js';
@@ -1 +1 @@
1
- module.exports = require('../../dist/providers/aws');
1
+ export * from '../../dist/providers/aws/index.js';
@@ -1 +1 @@
1
- export * from '../../dist/providers/azure';
1
+ export * from '../../dist/providers/azure/index.js';
@@ -1 +1 @@
1
- module.exports = require('../../dist/providers/azure');
1
+ export * from '../../dist/providers/azure/index.js';
@@ -1 +1 @@
1
- export * from '../../dist/providers/edgestore';
1
+ export * from '../../dist/providers/edgestore/index.js';
@@ -1 +1 @@
1
- module.exports = require('../../dist/providers/edgestore');
1
+ export * from '../../dist/providers/edgestore/index.js';
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -89,7 +90,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
89
90
  cause: err instanceof Error ? err : undefined,
90
91
  });
91
92
  }
92
- const { newCookies, token, baseUrl, providerName } = await init({
93
+ const { newCookies, ...body } = await init({
93
94
  ctx,
94
95
  provider,
95
96
  router: config.router,
@@ -108,14 +109,7 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
108
109
  headers.append('Set-Cookie', newCookies);
109
110
  }
110
111
 
111
- return new Response(
112
- JSON.stringify({
113
- token,
114
- baseUrl,
115
- providerName,
116
- }),
117
- { headers },
118
- );
112
+ return new Response(JSON.stringify(body), { headers });
119
113
  } else if (matchPath(url.pathname, 'request-upload')) {
120
114
  const body = (await request.json()) as RequestUploadBody;
121
115
  const result = await requestUpload({
@@ -178,22 +172,18 @@ export function createEdgeStoreAstroHandler<TCtx>(config: Config<TCtx>) {
178
172
  const url = new URL(request.url).searchParams.get('url');
179
173
 
180
174
  if (typeof url === 'string') {
181
- const cookieHeader = request.headers.get('cookie') ?? '';
182
-
183
- const proxyRes = await fetch(url, {
184
- headers: {
185
- cookie: cookieHeader,
186
- },
175
+ const proxyRes = await fetchProxyFile({
176
+ cookieHeader: request.headers.get('cookie') ?? undefined,
177
+ url,
187
178
  });
188
179
 
189
- const data = await proxyRes.arrayBuffer();
190
180
  const headers = new Headers();
191
- headers.set(
192
- 'Content-Type',
193
- proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
194
- );
181
+ headers.set('Content-Type', proxyRes.contentType);
195
182
 
196
- return new Response(data, { headers });
183
+ return new Response(proxyRes.body, {
184
+ headers,
185
+ status: proxyRes.status,
186
+ });
197
187
  } else {
198
188
  return new Response(null, { status: 400 });
199
189
  }
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -76,18 +77,14 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
76
77
  cause: err instanceof Error ? err : undefined,
77
78
  });
78
79
  }
79
- const { newCookies, token, baseUrl, providerName } = await init({
80
+ const { newCookies, ...body } = await init({
80
81
  ctx,
81
82
  provider,
82
83
  router: config.router,
83
84
  cookieConfig,
84
85
  });
85
86
  res.setHeader('Set-Cookie', newCookies);
86
- res.json({
87
- token,
88
- baseUrl,
89
- providerName,
90
- });
87
+ res.json(body);
91
88
  } else if (matchPath(pathname, '/request-upload')) {
92
89
  res.json(
93
90
  await requestUpload({
@@ -135,19 +132,16 @@ export function createEdgeStoreExpressHandler<TCtx>(config: Config<TCtx>) {
135
132
  } else if (matchPath(pathname, '/proxy-file')) {
136
133
  const { url } = req.query;
137
134
  if (typeof url === 'string') {
138
- const proxyRes = await fetch(url, {
139
- headers: {
140
- cookie: req.headers.cookie ?? '',
141
- },
135
+ const proxyRes = await fetchProxyFile({
136
+ cookieHeader: req.headers.cookie,
137
+ url,
142
138
  });
143
139
 
144
- const data = await proxyRes.arrayBuffer();
145
- res.setHeader(
146
- 'Content-Type',
147
- proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
140
+ res.setHeader('Content-Type', proxyRes.contentType);
141
+ res.status(proxyRes.status);
142
+ res.end(
143
+ proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
148
144
  );
149
-
150
- res.end(Buffer.from(data));
151
145
  } else {
152
146
  res.status(400).end();
153
147
  }
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -80,7 +81,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
80
81
 
81
82
  const resolvedCookieConfig = getCookieConfig(cookieConfig);
82
83
 
83
- return async (req: FastifyRequest, reply: FastifyReply) => {
84
+ return async (req: FastifyRequest, reply: FastifyReply): Promise<void> => {
84
85
  try {
85
86
  // Get the URL from the request - simplified approach
86
87
  const pathname = req.url;
@@ -101,7 +102,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
101
102
  cause: err instanceof Error ? err : undefined,
102
103
  });
103
104
  }
104
- const { newCookies, token, baseUrl, providerName } = await init({
105
+ const { newCookies, ...body } = await init({
105
106
  ctx,
106
107
  provider,
107
108
  router: config.router,
@@ -120,11 +121,7 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
120
121
  void reply.header('Set-Cookie', newCookies);
121
122
  }
122
123
 
123
- return reply.send({
124
- token,
125
- baseUrl,
126
- providerName,
127
- });
124
+ return reply.send(body);
128
125
  } else if (matchPath(pathname, '/request-upload')) {
129
126
  return reply.send(
130
127
  await requestUpload({
@@ -175,21 +172,18 @@ export function createEdgeStoreFastifyHandler<TCtx>(config: Config<TCtx>) {
175
172
  : undefined;
176
173
 
177
174
  if (typeof url === 'string') {
178
- const cookieHeader = req.headers.cookie ?? '';
179
-
180
- const proxyRes = await fetch(url, {
181
- headers: {
182
- cookie: cookieHeader,
183
- },
175
+ const proxyRes = await fetchProxyFile({
176
+ cookieHeader: req.headers.cookie,
177
+ url,
184
178
  });
185
179
 
186
- const data = await proxyRes.arrayBuffer();
187
- void reply.header(
188
- 'Content-Type',
189
- proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
190
- );
180
+ void reply.header('Content-Type', proxyRes.contentType);
191
181
 
192
- return reply.send(Buffer.from(data));
182
+ return reply
183
+ .status(proxyRes.status)
184
+ .send(
185
+ proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
186
+ );
193
187
  } else {
194
188
  return reply.status(400).send();
195
189
  }
@@ -6,7 +6,7 @@ import {
6
6
  type MaybePromise,
7
7
  type Provider,
8
8
  } from '@edgestore/shared';
9
- import { type Context } from 'hono';
9
+ import { type Context as HonoContext } from 'hono';
10
10
  import Logger, { type LogLevel } from '../../libs/logger';
11
11
  import { matchPath } from '../../libs/utils';
12
12
  import { EdgeStoreProvider } from '../../providers/edgestore';
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -27,7 +28,7 @@ import {
27
28
  } from '../shared';
28
29
 
29
30
  export type CreateContextOptions = {
30
- c: Context;
31
+ c: HonoContext;
31
32
  };
32
33
 
33
34
  export type Config<TCtx> = {
@@ -49,7 +50,7 @@ declare const globalThis: {
49
50
  };
50
51
 
51
52
  // Helper to get a cookie value from Hono Context
52
- function getCookie(c: Context, name: string): string | undefined {
53
+ function getCookie(c: HonoContext, name: string): string | undefined {
53
54
  const cookies = c.req.header('cookie');
54
55
  if (!cookies) return undefined;
55
56
 
@@ -65,7 +66,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
65
66
 
66
67
  const resolvedCookieConfig = getCookieConfig(cookieConfig);
67
68
 
68
- return async (c: Context) => {
69
+ return async (c: HonoContext): Promise<Response> => {
69
70
  try {
70
71
  const pathname = new URL(c.req.url).pathname;
71
72
 
@@ -85,7 +86,7 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
85
86
  cause: err instanceof Error ? err : undefined,
86
87
  });
87
88
  }
88
- const { newCookies, token, baseUrl, providerName } = await init({
89
+ const { newCookies, ...body } = await init({
89
90
  ctx,
90
91
  provider,
91
92
  router: config.router,
@@ -95,17 +96,13 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
95
96
  // Set cookies
96
97
  if (Array.isArray(newCookies)) {
97
98
  for (const cookie of newCookies) {
98
- c.header('Set-Cookie', cookie);
99
+ c.header('Set-Cookie', cookie, { append: true });
99
100
  }
100
101
  } else if (newCookies) {
101
102
  c.header('Set-Cookie', newCookies);
102
103
  }
103
104
 
104
- return c.json({
105
- token,
106
- baseUrl,
107
- providerName,
108
- });
105
+ return c.json(body);
109
106
  } else if (matchPath(pathname, '/request-upload')) {
110
107
  const body = await c.req.json<RequestUploadBody>();
111
108
  return c.json(
@@ -159,21 +156,20 @@ export function createEdgeStoreHonoHandler<TCtx>(config: Config<TCtx>) {
159
156
  const url = c.req.query('url');
160
157
 
161
158
  if (typeof url === 'string') {
162
- const cookieHeader = c.req.header('cookie') ?? '';
163
-
164
- const proxyRes = await fetch(url, {
165
- headers: {
166
- cookie: cookieHeader,
167
- },
159
+ const proxyRes = await fetchProxyFile({
160
+ cookieHeader: c.req.header('cookie'),
161
+ url,
168
162
  });
169
163
 
170
- const data = await proxyRes.arrayBuffer();
171
- c.header(
172
- 'Content-Type',
173
- proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
164
+ return new Response(
165
+ proxyRes.body === null ? null : Buffer.from(proxyRes.body),
166
+ {
167
+ status: proxyRes.status,
168
+ headers: {
169
+ 'Content-Type': proxyRes.contentType,
170
+ },
171
+ },
174
172
  );
175
-
176
- return c.body(Buffer.from(data));
177
173
  } else {
178
174
  return c.body(null, 400);
179
175
  }
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -85,25 +86,18 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
85
86
  cause: err instanceof Error ? err : undefined,
86
87
  });
87
88
  }
88
- const { newCookies, token, baseUrl, providerName } = await init({
89
+ const { newCookies, ...body } = await init({
89
90
  ctx,
90
91
  provider,
91
92
  router: config.router,
92
93
  cookieConfig,
93
94
  });
94
- const res = new Response(
95
- JSON.stringify({
96
- token,
97
- baseUrl,
98
- providerName,
99
- }),
100
- {
101
- status: 200,
102
- headers: {
103
- 'Content-Type': 'application/json',
104
- },
95
+ const res = new Response(JSON.stringify(body), {
96
+ status: 200,
97
+ headers: {
98
+ 'Content-Type': 'application/json',
105
99
  },
106
- );
100
+ });
107
101
  for (const cookie of newCookies) {
108
102
  res.headers.append('Set-Cookie', cookie);
109
103
  }
@@ -173,19 +167,15 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
173
167
  } else if (matchPath(pathname, '/proxy-file')) {
174
168
  const url = req.nextUrl.searchParams.get('url');
175
169
  if (typeof url === 'string') {
176
- const proxyRes = await fetch(url, {
177
- headers: {
178
- cookie: req.cookies.toString() ?? '',
179
- },
170
+ const proxyRes = await fetchProxyFile({
171
+ cookieHeader: req.cookies.toString(),
172
+ url,
180
173
  });
181
174
 
182
- const data = await proxyRes.arrayBuffer();
183
- return new Response(data, {
175
+ return new Response(proxyRes.body, {
184
176
  status: proxyRes.status,
185
177
  headers: {
186
- 'Content-Type':
187
- proxyRes.headers.get('Content-Type') ??
188
- 'application/octet-stream',
178
+ 'Content-Type': proxyRes.contentType,
189
179
  },
190
180
  });
191
181
  } else {
@@ -14,6 +14,7 @@ import {
14
14
  completeMultipartUpload,
15
15
  confirmUpload,
16
16
  deleteFile,
17
+ fetchProxyFile,
17
18
  getCookieConfig,
18
19
  init,
19
20
  requestUpload,
@@ -82,18 +83,14 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
82
83
  cause: err instanceof Error ? err : undefined,
83
84
  });
84
85
  }
85
- const { newCookies, token, baseUrl, providerName } = await init({
86
+ const { newCookies, ...body } = await init({
86
87
  ctx,
87
88
  provider,
88
89
  router: config.router,
89
90
  cookieConfig,
90
91
  });
91
92
  res.setHeader('Set-Cookie', newCookies);
92
- res.json({
93
- token,
94
- baseUrl,
95
- providerName,
96
- });
93
+ res.json(body);
97
94
  } else if (matchPath(pathname, '/request-upload')) {
98
95
  res.json(
99
96
  await requestUpload({
@@ -141,19 +138,17 @@ export function createEdgeStoreNextHandler<TCtx>(config: Config<TCtx>) {
141
138
  } else if (matchPath(pathname, '/proxy-file')) {
142
139
  const { url } = req.query;
143
140
  if (typeof url === 'string') {
144
- const proxyRes = await fetch(url, {
145
- headers: {
146
- cookie: req.headers.cookie ?? '',
147
- },
141
+ const proxyRes = await fetchProxyFile({
142
+ cookieHeader: req.headers.cookie,
143
+ url,
148
144
  });
149
145
 
150
- const data = await proxyRes.arrayBuffer();
151
- res.setHeader(
152
- 'Content-Type',
153
- proxyRes.headers.get('Content-Type') ?? 'application/octet-stream',
154
- );
146
+ res.setHeader('Content-Type', proxyRes.contentType);
155
147
 
156
- res.end(Buffer.from(data));
148
+ res.status(proxyRes.status);
149
+ res.end(
150
+ proxyRes.body === null ? undefined : Buffer.from(proxyRes.body),
151
+ );
157
152
  } else {
158
153
  res.status(400).end();
159
154
  }