@edgestore/react 0.1.5-alpha.4 → 0.1.5-alpha.6
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/dist/contextProvider.d.ts +1 -1
- package/dist/createNextProxy.d.ts.map +1 -1
- package/dist/index.js +20 -8
- package/dist/index.mjs +20 -8
- package/dist/libs/errors/EdgeStoreError.d.ts +2 -2
- package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/createNextProxy.ts +22 -8
- package/src/libs/errors/EdgeStoreError.ts +2 -2
|
@@ -31,7 +31,7 @@ export declare function createEdgeStoreProvider<TRouter extends AnyRouter>(opts?
|
|
|
31
31
|
* @example - If your app is hosted at `https://example.com/my-app`, you can set the `basePath` to `/my-app/api/edgestore`.
|
|
32
32
|
*/
|
|
33
33
|
basePath?: string | undefined;
|
|
34
|
-
}) => JSX.Element;
|
|
34
|
+
}) => React.JSX.Element;
|
|
35
35
|
useEdgeStore: () => EdgeStoreContextValue<TRouter>;
|
|
36
36
|
};
|
|
37
37
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"createNextProxy.d.ts","sourceRoot":"","sources":["../src/createNextProxy.ts"],"names":[],"mappings":";AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,IAAI;KAC3B,CAAC,IAAI,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;CAE7B,GAAG,EAAE,CAAC;AAEP,MAAM,MAAM,eAAe,CAAC,OAAO,SAA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AAQ,EAAE,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACrD,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACnD,SAAS,EAAE,QAAQ,CACjB,MAAM,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CACnD,EAAE,CAAC;SACL,CACN,CAAC;QACF,aAAa,EAAE,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1D,MAAM,EAAE,CAAC,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KACpD;CACF,CAAC;AAEF,KAAK,uBAAuB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAE1D,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,EACzD,OAAO,EACP,iBAAiB,EACjB,oBAAwB,GACzB,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,4BA6CA"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
+
var core = require('@edgestore/server/core');
|
|
6
7
|
|
|
7
8
|
function _interopNamespace(e) {
|
|
8
9
|
if (e && e.__esModule) return e;
|
|
@@ -24,7 +25,7 @@ function _interopNamespace(e) {
|
|
|
24
25
|
|
|
25
26
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
26
27
|
|
|
27
|
-
class
|
|
28
|
+
class EdgeStoreClientError extends Error {
|
|
28
29
|
constructor(message){
|
|
29
30
|
super(message);
|
|
30
31
|
this.name = 'EdgeStoreError';
|
|
@@ -57,7 +58,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
57
58
|
apiPath
|
|
58
59
|
});
|
|
59
60
|
if (!success) {
|
|
60
|
-
throw new
|
|
61
|
+
throw new EdgeStoreClientError('Failed to confirm upload');
|
|
61
62
|
}
|
|
62
63
|
},
|
|
63
64
|
delete: async (params)=>{
|
|
@@ -66,7 +67,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
66
67
|
apiPath
|
|
67
68
|
});
|
|
68
69
|
if (!success) {
|
|
69
|
-
throw new
|
|
70
|
+
throw new EdgeStoreClientError('Failed to delete file');
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
};
|
|
@@ -95,6 +96,11 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
95
96
|
'Content-Type': 'application/json'
|
|
96
97
|
}
|
|
97
98
|
});
|
|
99
|
+
if (!res.ok) {
|
|
100
|
+
throw new core.EdgeStoreApiClientError({
|
|
101
|
+
response: await res.json()
|
|
102
|
+
});
|
|
103
|
+
}
|
|
98
104
|
const json = await res.json();
|
|
99
105
|
if ('multipart' in json) {
|
|
100
106
|
await multipartUpload({
|
|
@@ -109,7 +115,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
109
115
|
// Upload the file to the signed URL and get the progress
|
|
110
116
|
await uploadFileInner(file, json.uploadUrl, onProgressChange);
|
|
111
117
|
} else {
|
|
112
|
-
throw new
|
|
118
|
+
throw new EdgeStoreClientError('An error occurred');
|
|
113
119
|
}
|
|
114
120
|
return {
|
|
115
121
|
url: getUrl(json.accessUrl, apiPath),
|
|
@@ -191,7 +197,7 @@ async function multipartUpload(params) {
|
|
|
191
197
|
onProgressChange?.(totalProgress);
|
|
192
198
|
});
|
|
193
199
|
if (!eTag) {
|
|
194
|
-
throw new
|
|
200
|
+
throw new EdgeStoreClientError('Could not get ETag from multipart response');
|
|
195
201
|
}
|
|
196
202
|
return {
|
|
197
203
|
partNumber: part.partNumber,
|
|
@@ -222,7 +228,9 @@ async function multipartUpload(params) {
|
|
|
222
228
|
}
|
|
223
229
|
});
|
|
224
230
|
if (!res.ok) {
|
|
225
|
-
throw new
|
|
231
|
+
throw new core.EdgeStoreApiClientError({
|
|
232
|
+
response: await res.json()
|
|
233
|
+
});
|
|
226
234
|
}
|
|
227
235
|
}
|
|
228
236
|
async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
@@ -237,7 +245,9 @@ async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
|
237
245
|
}
|
|
238
246
|
});
|
|
239
247
|
if (!res.ok) {
|
|
240
|
-
throw new
|
|
248
|
+
throw new core.EdgeStoreApiClientError({
|
|
249
|
+
response: await res.json()
|
|
250
|
+
});
|
|
241
251
|
}
|
|
242
252
|
return res.json();
|
|
243
253
|
}
|
|
@@ -253,7 +263,9 @@ async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
|
253
263
|
}
|
|
254
264
|
});
|
|
255
265
|
if (!res.ok) {
|
|
256
|
-
throw new
|
|
266
|
+
throw new core.EdgeStoreApiClientError({
|
|
267
|
+
response: await res.json()
|
|
268
|
+
});
|
|
257
269
|
}
|
|
258
270
|
return res.json();
|
|
259
271
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { EdgeStoreApiClientError } from '@edgestore/server/core';
|
|
2
3
|
|
|
3
|
-
class
|
|
4
|
+
class EdgeStoreClientError extends Error {
|
|
4
5
|
constructor(message){
|
|
5
6
|
super(message);
|
|
6
7
|
this.name = 'EdgeStoreError';
|
|
@@ -33,7 +34,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
33
34
|
apiPath
|
|
34
35
|
});
|
|
35
36
|
if (!success) {
|
|
36
|
-
throw new
|
|
37
|
+
throw new EdgeStoreClientError('Failed to confirm upload');
|
|
37
38
|
}
|
|
38
39
|
},
|
|
39
40
|
delete: async (params)=>{
|
|
@@ -42,7 +43,7 @@ function createNextProxy({ apiPath, uploadingCountRef, maxConcurrentUploads = 5
|
|
|
42
43
|
apiPath
|
|
43
44
|
});
|
|
44
45
|
if (!success) {
|
|
45
|
-
throw new
|
|
46
|
+
throw new EdgeStoreClientError('Failed to delete file');
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
};
|
|
@@ -71,6 +72,11 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
71
72
|
'Content-Type': 'application/json'
|
|
72
73
|
}
|
|
73
74
|
});
|
|
75
|
+
if (!res.ok) {
|
|
76
|
+
throw new EdgeStoreApiClientError({
|
|
77
|
+
response: await res.json()
|
|
78
|
+
});
|
|
79
|
+
}
|
|
74
80
|
const json = await res.json();
|
|
75
81
|
if ('multipart' in json) {
|
|
76
82
|
await multipartUpload({
|
|
@@ -85,7 +91,7 @@ async function uploadFile({ file, input, onProgressChange, options }, { apiPath,
|
|
|
85
91
|
// Upload the file to the signed URL and get the progress
|
|
86
92
|
await uploadFileInner(file, json.uploadUrl, onProgressChange);
|
|
87
93
|
} else {
|
|
88
|
-
throw new
|
|
94
|
+
throw new EdgeStoreClientError('An error occurred');
|
|
89
95
|
}
|
|
90
96
|
return {
|
|
91
97
|
url: getUrl(json.accessUrl, apiPath),
|
|
@@ -167,7 +173,7 @@ async function multipartUpload(params) {
|
|
|
167
173
|
onProgressChange?.(totalProgress);
|
|
168
174
|
});
|
|
169
175
|
if (!eTag) {
|
|
170
|
-
throw new
|
|
176
|
+
throw new EdgeStoreClientError('Could not get ETag from multipart response');
|
|
171
177
|
}
|
|
172
178
|
return {
|
|
173
179
|
partNumber: part.partNumber,
|
|
@@ -198,7 +204,9 @@ async function multipartUpload(params) {
|
|
|
198
204
|
}
|
|
199
205
|
});
|
|
200
206
|
if (!res.ok) {
|
|
201
|
-
throw new
|
|
207
|
+
throw new EdgeStoreApiClientError({
|
|
208
|
+
response: await res.json()
|
|
209
|
+
});
|
|
202
210
|
}
|
|
203
211
|
}
|
|
204
212
|
async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
@@ -213,7 +221,9 @@ async function confirmUpload({ url }, { apiPath, bucketName }) {
|
|
|
213
221
|
}
|
|
214
222
|
});
|
|
215
223
|
if (!res.ok) {
|
|
216
|
-
throw new
|
|
224
|
+
throw new EdgeStoreApiClientError({
|
|
225
|
+
response: await res.json()
|
|
226
|
+
});
|
|
217
227
|
}
|
|
218
228
|
return res.json();
|
|
219
229
|
}
|
|
@@ -229,7 +239,9 @@ async function deleteFile({ url }, { apiPath, bucketName }) {
|
|
|
229
239
|
}
|
|
230
240
|
});
|
|
231
241
|
if (!res.ok) {
|
|
232
|
-
throw new
|
|
242
|
+
throw new EdgeStoreApiClientError({
|
|
243
|
+
response: await res.json()
|
|
244
|
+
});
|
|
233
245
|
}
|
|
234
246
|
return res.json();
|
|
235
247
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,cAAM,
|
|
1
|
+
{"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,cAAM,oBAAqB,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,eAAe,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/react",
|
|
3
|
-
"version": "0.1.5-alpha.
|
|
3
|
+
"version": "0.1.5-alpha.6",
|
|
4
4
|
"description": "Upload files with ease from React/Next.js",
|
|
5
5
|
"homepage": "https://edgestore.dev",
|
|
6
6
|
"repository": "https://github.com/edgestorejs/edgestore.git",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"uuid": "^9.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@edgestore/server": "0.1.5-alpha.
|
|
63
|
+
"@edgestore/server": "0.1.5-alpha.6",
|
|
64
64
|
"next": "*",
|
|
65
65
|
"react": ">=16.8.0",
|
|
66
66
|
"react-dom": ">=16.8.0",
|
|
67
67
|
"zod": ">=3.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@edgestore/server": "0.1.5-alpha.
|
|
70
|
+
"@edgestore/server": "0.1.5-alpha.6",
|
|
71
71
|
"@types/cookie": "^0.5.1",
|
|
72
72
|
"@types/node": "^18.11.18",
|
|
73
73
|
"@types/uuid": "^9.0.1",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"typescript": "^5.1.6",
|
|
78
78
|
"zod": "^3.21.4"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "c39746e4fcf5a5d9568794bbe0236f8d21812e7d"
|
|
81
81
|
}
|
package/src/createNextProxy.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type RequestUploadRes } from '@edgestore/server/adapters';
|
|
2
2
|
import {
|
|
3
|
+
EdgeStoreApiClientError,
|
|
3
4
|
type AnyRouter,
|
|
4
5
|
type InferBucketPathObject,
|
|
5
6
|
type InferMetadataObject,
|
|
6
7
|
type UploadOptions,
|
|
7
8
|
} from '@edgestore/server/core';
|
|
8
9
|
import { type z } from 'zod';
|
|
9
|
-
import
|
|
10
|
+
import EdgeStoreClientError from './libs/errors/EdgeStoreError';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @internal
|
|
@@ -100,7 +101,7 @@ export function createNextProxy<TRouter extends AnyRouter>({
|
|
|
100
101
|
apiPath,
|
|
101
102
|
});
|
|
102
103
|
if (!success) {
|
|
103
|
-
throw new
|
|
104
|
+
throw new EdgeStoreClientError('Failed to confirm upload');
|
|
104
105
|
}
|
|
105
106
|
},
|
|
106
107
|
delete: async (params: { url: string }) => {
|
|
@@ -109,7 +110,7 @@ export function createNextProxy<TRouter extends AnyRouter>({
|
|
|
109
110
|
apiPath,
|
|
110
111
|
});
|
|
111
112
|
if (!success) {
|
|
112
|
-
throw new
|
|
113
|
+
throw new EdgeStoreClientError('Failed to delete file');
|
|
113
114
|
}
|
|
114
115
|
},
|
|
115
116
|
};
|
|
@@ -158,6 +159,11 @@ async function uploadFile(
|
|
|
158
159
|
'Content-Type': 'application/json',
|
|
159
160
|
},
|
|
160
161
|
});
|
|
162
|
+
if (!res.ok) {
|
|
163
|
+
throw new EdgeStoreApiClientError({
|
|
164
|
+
response: await res.json(),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
161
167
|
const json = (await res.json()) as RequestUploadRes;
|
|
162
168
|
if ('multipart' in json) {
|
|
163
169
|
await multipartUpload({
|
|
@@ -172,7 +178,7 @@ async function uploadFile(
|
|
|
172
178
|
// Upload the file to the signed URL and get the progress
|
|
173
179
|
await uploadFileInner(file, json.uploadUrl, onProgressChange);
|
|
174
180
|
} else {
|
|
175
|
-
throw new
|
|
181
|
+
throw new EdgeStoreClientError('An error occurred');
|
|
176
182
|
}
|
|
177
183
|
return {
|
|
178
184
|
url: getUrl(json.accessUrl, apiPath),
|
|
@@ -283,7 +289,9 @@ async function multipartUpload(params: {
|
|
|
283
289
|
onProgressChange?.(totalProgress);
|
|
284
290
|
});
|
|
285
291
|
if (!eTag) {
|
|
286
|
-
throw new
|
|
292
|
+
throw new EdgeStoreClientError(
|
|
293
|
+
'Could not get ETag from multipart response',
|
|
294
|
+
);
|
|
287
295
|
}
|
|
288
296
|
return {
|
|
289
297
|
partNumber: part.partNumber,
|
|
@@ -319,7 +327,9 @@ async function multipartUpload(params: {
|
|
|
319
327
|
},
|
|
320
328
|
});
|
|
321
329
|
if (!res.ok) {
|
|
322
|
-
throw new
|
|
330
|
+
throw new EdgeStoreApiClientError({
|
|
331
|
+
response: await res.json(),
|
|
332
|
+
});
|
|
323
333
|
}
|
|
324
334
|
}
|
|
325
335
|
|
|
@@ -348,7 +358,9 @@ async function confirmUpload(
|
|
|
348
358
|
},
|
|
349
359
|
});
|
|
350
360
|
if (!res.ok) {
|
|
351
|
-
throw new
|
|
361
|
+
throw new EdgeStoreApiClientError({
|
|
362
|
+
response: await res.json(),
|
|
363
|
+
});
|
|
352
364
|
}
|
|
353
365
|
return res.json();
|
|
354
366
|
}
|
|
@@ -378,7 +390,9 @@ async function deleteFile(
|
|
|
378
390
|
},
|
|
379
391
|
});
|
|
380
392
|
if (!res.ok) {
|
|
381
|
-
throw new
|
|
393
|
+
throw new EdgeStoreApiClientError({
|
|
394
|
+
response: await res.json(),
|
|
395
|
+
});
|
|
382
396
|
}
|
|
383
397
|
return res.json();
|
|
384
398
|
}
|