@edgestore/server 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.
Files changed (47) hide show
  1. package/adapters/express/index.d.ts +1 -0
  2. package/adapters/express/index.js +1 -0
  3. package/dist/adapters/next/app/index.d.ts +5 -3
  4. package/dist/adapters/next/app/index.d.ts.map +1 -1
  5. package/dist/adapters/next/app/index.js +38 -15
  6. package/dist/adapters/next/app/index.mjs +37 -14
  7. package/dist/adapters/next/pages/index.d.ts +5 -3
  8. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  9. package/dist/adapters/next/pages/index.js +32 -12
  10. package/dist/adapters/next/pages/index.mjs +31 -11
  11. package/dist/adapters/shared.d.ts.map +1 -1
  12. package/dist/core/client/index.d.ts +75 -7
  13. package/dist/core/client/index.d.ts.map +1 -1
  14. package/dist/core/index.d.ts +2 -0
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/core/index.js +32 -6
  17. package/dist/core/index.mjs +33 -8
  18. package/dist/core/sdk/index.d.ts.map +1 -1
  19. package/dist/{index-50ab9e08.js → index-7cb3a3f3.mjs} +41 -5
  20. package/dist/{index-f33a00fb.js → index-9eb6248c.js} +37 -2
  21. package/dist/{index-30a3741e.mjs → index-e25c8209.js} +48 -2
  22. package/dist/libs/errors/EdgeStoreApiClientError.d.ts +8 -0
  23. package/dist/libs/errors/EdgeStoreApiClientError.d.ts.map +1 -0
  24. package/dist/libs/errors/EdgeStoreError.d.ts +36 -4
  25. package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -1
  26. package/dist/libs/logger.d.ts +13 -0
  27. package/dist/libs/logger.d.ts.map +1 -0
  28. package/dist/logger-0f08f252.mjs +40 -0
  29. package/dist/logger-623f2833.js +42 -0
  30. package/dist/logger-8f098618.js +33 -0
  31. package/dist/providers/edgestore/index.d.ts.map +1 -1
  32. package/dist/providers/edgestore/index.js +10 -3
  33. package/dist/providers/edgestore/index.mjs +10 -3
  34. package/dist/{shared-5d1e7f43.js → shared-53cb59dd.js} +72 -51
  35. package/dist/{shared-30b7a2ab.mjs → shared-b14a84ee.mjs} +65 -42
  36. package/dist/{shared-88655ba7.js → shared-f8ddbf7c.js} +62 -36
  37. package/package.json +2 -2
  38. package/src/adapters/next/app/index.ts +51 -19
  39. package/src/adapters/next/pages/index.ts +42 -14
  40. package/src/adapters/shared.ts +61 -29
  41. package/src/core/client/index.ts +103 -12
  42. package/src/core/index.ts +6 -0
  43. package/src/core/sdk/index.ts +7 -1
  44. package/src/libs/errors/EdgeStoreApiClientError.ts +14 -0
  45. package/src/libs/errors/EdgeStoreError.ts +76 -7
  46. package/src/libs/logger.ts +44 -0
  47. package/src/providers/edgestore/index.ts +9 -2
@@ -4,22 +4,7 @@ var hkdf = require('@panva/hkdf');
4
4
  var cookie = require('cookie');
5
5
  var jose = require('jose');
6
6
  var uuid = require('uuid');
7
- var _define_property = require('@swc/helpers/_/_define_property');
8
-
9
- const EDGE_STORE_ERROR_CODES = {
10
- BAD_REQUEST: 400,
11
- UNAUTHORIZED: 401
12
- };
13
- class EdgeStoreError extends Error {
14
- constructor(opts){
15
- super(opts.message);
16
- _define_property._(this, "cause", void 0);
17
- _define_property._(this, "code", void 0);
18
- this.name = 'EdgeStoreError';
19
- this.code = opts.code;
20
- this.cause = opts.cause;
21
- }
22
- }
7
+ var index = require('./index-e25c8209.js');
23
8
 
24
9
  const IMAGE_MIME_TYPES = [
25
10
  'image/jpeg',
@@ -63,7 +48,7 @@ async function init(params) {
63
48
  async function requestUpload(params) {
64
49
  const { provider, router, ctxToken, body: { bucketName, input, fileInfo } } = params;
65
50
  if (!ctxToken) {
66
- throw new EdgeStoreError({
51
+ throw new index.EdgeStoreError({
67
52
  message: 'Missing edgestore-ctx cookie',
68
53
  code: 'UNAUTHORIZED'
69
54
  });
@@ -71,7 +56,10 @@ async function requestUpload(params) {
71
56
  const ctx = await getContext(ctxToken);
72
57
  const bucket = router.buckets[bucketName];
73
58
  if (!bucket) {
74
- throw new Error(`Bucket ${bucketName} not found`);
59
+ throw new index.EdgeStoreError({
60
+ message: `Bucket ${bucketName} not found`,
61
+ code: 'BAD_REQUEST'
62
+ });
75
63
  }
76
64
  if (bucket._def.beforeUpload) {
77
65
  const canUpload = await bucket._def.beforeUpload?.({
@@ -87,22 +75,33 @@ async function requestUpload(params) {
87
75
  }
88
76
  });
89
77
  if (!canUpload) {
90
- throw new Error('Upload not allowed');
78
+ throw new index.EdgeStoreError({
79
+ message: 'Upload not allowed for the current context',
80
+ code: 'UPLOAD_NOT_ALLOWED'
81
+ });
91
82
  }
92
83
  }
93
84
  if (bucket._def.type === 'IMAGE') {
94
85
  if (!IMAGE_MIME_TYPES.includes(fileInfo.type)) {
95
- throw new EdgeStoreError({
96
- code: 'BAD_REQUEST',
97
- message: 'Only images are allowed in this bucket'
86
+ throw new index.EdgeStoreError({
87
+ code: 'MIME_TYPE_NOT_ALLOWED',
88
+ message: 'Only images are allowed in this bucket',
89
+ details: {
90
+ allowedMimeTypes: IMAGE_MIME_TYPES,
91
+ mimeType: fileInfo.type
92
+ }
98
93
  });
99
94
  }
100
95
  }
101
96
  if (bucket._def.bucketConfig?.maxSize) {
102
97
  if (fileInfo.size > bucket._def.bucketConfig.maxSize) {
103
- throw new EdgeStoreError({
104
- code: 'BAD_REQUEST',
105
- message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`
98
+ throw new index.EdgeStoreError({
99
+ code: 'FILE_TOO_LARGE',
100
+ message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`,
101
+ details: {
102
+ maxFileSize: bucket._def.bucketConfig.maxSize,
103
+ fileSize: fileInfo.size
104
+ }
106
105
  });
107
106
  }
108
107
  }
@@ -122,9 +121,13 @@ async function requestUpload(params) {
122
121
  }
123
122
  }
124
123
  if (!accepted) {
125
- throw new EdgeStoreError({
126
- code: 'BAD_REQUEST',
127
- message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`
124
+ throw new index.EdgeStoreError({
125
+ code: 'MIME_TYPE_NOT_ALLOWED',
126
+ message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`,
127
+ details: {
128
+ allowedMimeTypes: accept,
129
+ mimeType: fileInfo.type
130
+ }
128
131
  });
129
132
  }
130
133
  }
@@ -162,18 +165,14 @@ async function requestUpload(params) {
162
165
  };
163
166
  }
164
167
  async function requestUploadParts(params) {
165
- const { provider, router, ctxToken, body: { multipart, path } } = params;
168
+ const { provider, ctxToken, body: { multipart, path } } = params;
166
169
  if (!ctxToken) {
167
- throw new EdgeStoreError({
170
+ throw new index.EdgeStoreError({
168
171
  message: 'Missing edgestore-ctx cookie',
169
172
  code: 'UNAUTHORIZED'
170
173
  });
171
174
  }
172
175
  await getContext(ctxToken); // just to check if the token is valid
173
- const bucket = router.buckets[multipart.uploadId];
174
- if (!bucket) {
175
- throw new Error(`Bucket ${multipart.uploadId} not found`);
176
- }
177
176
  return await provider.requestUploadParts({
178
177
  multipart,
179
178
  path
@@ -182,7 +181,7 @@ async function requestUploadParts(params) {
182
181
  async function completeMultipartUpload(params) {
183
182
  const { provider, router, ctxToken, body: { bucketName, uploadId, key, parts } } = params;
184
183
  if (!ctxToken) {
185
- throw new EdgeStoreError({
184
+ throw new index.EdgeStoreError({
186
185
  message: 'Missing edgestore-ctx cookie',
187
186
  code: 'UNAUTHORIZED'
188
187
  });
@@ -190,7 +189,10 @@ async function completeMultipartUpload(params) {
190
189
  await getContext(ctxToken); // just to check if the token is valid
191
190
  const bucket = router.buckets[bucketName];
192
191
  if (!bucket) {
193
- throw new Error(`Bucket ${bucketName} not found`);
192
+ throw new index.EdgeStoreError({
193
+ message: `Bucket ${bucketName} not found`,
194
+ code: 'BAD_REQUEST'
195
+ });
194
196
  }
195
197
  return await provider.completeMultipartUpload({
196
198
  uploadId,
@@ -201,7 +203,7 @@ async function completeMultipartUpload(params) {
201
203
  async function confirmUpload(params) {
202
204
  const { provider, router, ctxToken, body: { bucketName, url } } = params;
203
205
  if (!ctxToken) {
204
- throw new EdgeStoreError({
206
+ throw new index.EdgeStoreError({
205
207
  message: 'Missing edgestore-ctx cookie',
206
208
  code: 'UNAUTHORIZED'
207
209
  });
@@ -209,7 +211,10 @@ async function confirmUpload(params) {
209
211
  await getContext(ctxToken); // just to check if the token is valid
210
212
  const bucket = router.buckets[bucketName];
211
213
  if (!bucket) {
212
- throw new Error(`Bucket ${bucketName} not found`);
214
+ throw new index.EdgeStoreError({
215
+ message: `Bucket ${bucketName} not found`,
216
+ code: 'BAD_REQUEST'
217
+ });
213
218
  }
214
219
  return await provider.confirmUpload({
215
220
  bucket,
@@ -219,7 +224,7 @@ async function confirmUpload(params) {
219
224
  async function deleteFile(params) {
220
225
  const { provider, router, ctxToken, body: { bucketName, url } } = params;
221
226
  if (!ctxToken) {
222
- throw new EdgeStoreError({
227
+ throw new index.EdgeStoreError({
223
228
  message: 'Missing edgestore-ctx cookie',
224
229
  code: 'UNAUTHORIZED'
225
230
  });
@@ -227,10 +232,16 @@ async function deleteFile(params) {
227
232
  const ctx = await getContext(ctxToken);
228
233
  const bucket = router.buckets[bucketName];
229
234
  if (!bucket) {
230
- throw new Error(`Bucket ${bucketName} not found`);
235
+ throw new index.EdgeStoreError({
236
+ message: `Bucket ${bucketName} not found`,
237
+ code: 'BAD_REQUEST'
238
+ });
231
239
  }
232
240
  if (!bucket._def.beforeDelete) {
233
- throw new Error('You need to define beforeDelete if you want to delete files directly from the frontend.');
241
+ throw new index.EdgeStoreError({
242
+ message: 'You need to define beforeDelete if you want to delete files directly from the frontend.',
243
+ code: 'SERVER_ERROR'
244
+ });
234
245
  }
235
246
  const fileInfo = await provider.getFile({
236
247
  url
@@ -240,7 +251,10 @@ async function deleteFile(params) {
240
251
  fileInfo
241
252
  });
242
253
  if (!canDelete) {
243
- throw new Error('Delete not allowed');
254
+ throw new index.EdgeStoreError({
255
+ message: 'Delete not allowed for the current context',
256
+ code: 'DELETE_NOT_ALLOWED'
257
+ });
244
258
  }
245
259
  return await provider.deleteFile({
246
260
  bucket,
@@ -250,7 +264,10 @@ async function deleteFile(params) {
250
264
  async function encryptJWT(ctx) {
251
265
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
252
266
  if (!secret) {
253
- throw new Error('EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined');
267
+ throw new index.EdgeStoreError({
268
+ message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
269
+ code: 'SERVER_ERROR'
270
+ });
254
271
  }
255
272
  const encryptionSecret = await getDerivedEncryptionKey(secret);
256
273
  return await new jose.EncryptJWT(ctx).setProtectedHeader({
@@ -261,7 +278,10 @@ async function encryptJWT(ctx) {
261
278
  async function decryptJWT(token) {
262
279
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
263
280
  if (!secret) {
264
- throw new Error('EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not set');
281
+ throw new index.EdgeStoreError({
282
+ message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
283
+ code: 'SERVER_ERROR'
284
+ });
265
285
  }
266
286
  const encryptionSecret = await getDerivedEncryptionKey(secret);
267
287
  const { payload } = await jose.jwtDecrypt(token, encryptionSecret, {
@@ -278,13 +298,19 @@ function buildPath(params) {
278
298
  const path = pathParams.map((param)=>{
279
299
  const paramEntries = Object.entries(param);
280
300
  if (paramEntries[0] === undefined) {
281
- throw new Error('Missing path param');
301
+ throw new index.EdgeStoreError({
302
+ message: `Empty path param found in: ${JSON.stringify(pathParams)}`,
303
+ code: 'SERVER_ERROR'
304
+ });
282
305
  }
283
306
  const [key, value] = paramEntries[0];
284
307
  // this is a string like: "ctx.xxx" or "input.yyy.zzz"
285
308
  const currParamVal = value().split('.').reduce((acc2, key)=>{
286
309
  if (acc2[key] === undefined) {
287
- throw new Error(`Missing key ${key} in ${JSON.stringify(acc2)}`);
310
+ throw new index.EdgeStoreError({
311
+ message: `Missing key ${key} in ${JSON.stringify(acc2)}`,
312
+ code: 'BAD_REQUEST'
313
+ });
288
314
  }
289
315
  return acc2[key];
290
316
  }, params.pathAttrs);
@@ -307,9 +333,6 @@ function parsePath(path) {
307
333
  };
308
334
  }
309
335
  async function getContext(token) {
310
- if (!token) {
311
- throw new Error('No token');
312
- }
313
336
  return await decryptJWT(token);
314
337
  }
315
338
  /**
@@ -329,8 +352,6 @@ async function getContext(token) {
329
352
  return url;
330
353
  }
331
354
 
332
- exports.EDGE_STORE_ERROR_CODES = EDGE_STORE_ERROR_CODES;
333
- exports.EdgeStoreError = EdgeStoreError;
334
355
  exports.buildPath = buildPath;
335
356
  exports.completeMultipartUpload = completeMultipartUpload;
336
357
  exports.confirmUpload = confirmUpload;
@@ -2,22 +2,7 @@ import { hkdf } from '@panva/hkdf';
2
2
  import { serialize } from 'cookie';
3
3
  import { EncryptJWT, jwtDecrypt } from 'jose';
4
4
  import { v4 } from 'uuid';
5
- import { _ } from '@swc/helpers/_/_define_property';
6
-
7
- const EDGE_STORE_ERROR_CODES = {
8
- BAD_REQUEST: 400,
9
- UNAUTHORIZED: 401
10
- };
11
- class EdgeStoreError extends Error {
12
- constructor(opts){
13
- super(opts.message);
14
- _(this, "cause", void 0);
15
- _(this, "code", void 0);
16
- this.name = 'EdgeStoreError';
17
- this.code = opts.code;
18
- this.cause = opts.cause;
19
- }
20
- }
5
+ import { E as EdgeStoreError } from './index-7cb3a3f3.mjs';
21
6
 
22
7
  const IMAGE_MIME_TYPES = [
23
8
  'image/jpeg',
@@ -69,7 +54,10 @@ async function requestUpload(params) {
69
54
  const ctx = await getContext(ctxToken);
70
55
  const bucket = router.buckets[bucketName];
71
56
  if (!bucket) {
72
- throw new Error(`Bucket ${bucketName} not found`);
57
+ throw new EdgeStoreError({
58
+ message: `Bucket ${bucketName} not found`,
59
+ code: 'BAD_REQUEST'
60
+ });
73
61
  }
74
62
  if (bucket._def.beforeUpload) {
75
63
  const canUpload = await bucket._def.beforeUpload?.({
@@ -85,22 +73,33 @@ async function requestUpload(params) {
85
73
  }
86
74
  });
87
75
  if (!canUpload) {
88
- throw new Error('Upload not allowed');
76
+ throw new EdgeStoreError({
77
+ message: 'Upload not allowed for the current context',
78
+ code: 'UPLOAD_NOT_ALLOWED'
79
+ });
89
80
  }
90
81
  }
91
82
  if (bucket._def.type === 'IMAGE') {
92
83
  if (!IMAGE_MIME_TYPES.includes(fileInfo.type)) {
93
84
  throw new EdgeStoreError({
94
- code: 'BAD_REQUEST',
95
- message: 'Only images are allowed in this bucket'
85
+ code: 'MIME_TYPE_NOT_ALLOWED',
86
+ message: 'Only images are allowed in this bucket',
87
+ details: {
88
+ allowedMimeTypes: IMAGE_MIME_TYPES,
89
+ mimeType: fileInfo.type
90
+ }
96
91
  });
97
92
  }
98
93
  }
99
94
  if (bucket._def.bucketConfig?.maxSize) {
100
95
  if (fileInfo.size > bucket._def.bucketConfig.maxSize) {
101
96
  throw new EdgeStoreError({
102
- code: 'BAD_REQUEST',
103
- message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`
97
+ code: 'FILE_TOO_LARGE',
98
+ message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`,
99
+ details: {
100
+ maxFileSize: bucket._def.bucketConfig.maxSize,
101
+ fileSize: fileInfo.size
102
+ }
104
103
  });
105
104
  }
106
105
  }
@@ -121,8 +120,12 @@ async function requestUpload(params) {
121
120
  }
122
121
  if (!accepted) {
123
122
  throw new EdgeStoreError({
124
- code: 'BAD_REQUEST',
125
- message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`
123
+ code: 'MIME_TYPE_NOT_ALLOWED',
124
+ message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`,
125
+ details: {
126
+ allowedMimeTypes: accept,
127
+ mimeType: fileInfo.type
128
+ }
126
129
  });
127
130
  }
128
131
  }
@@ -160,7 +163,7 @@ async function requestUpload(params) {
160
163
  };
161
164
  }
162
165
  async function requestUploadParts(params) {
163
- const { provider, router, ctxToken, body: { multipart, path } } = params;
166
+ const { provider, ctxToken, body: { multipart, path } } = params;
164
167
  if (!ctxToken) {
165
168
  throw new EdgeStoreError({
166
169
  message: 'Missing edgestore-ctx cookie',
@@ -168,10 +171,6 @@ async function requestUploadParts(params) {
168
171
  });
169
172
  }
170
173
  await getContext(ctxToken); // just to check if the token is valid
171
- const bucket = router.buckets[multipart.uploadId];
172
- if (!bucket) {
173
- throw new Error(`Bucket ${multipart.uploadId} not found`);
174
- }
175
174
  return await provider.requestUploadParts({
176
175
  multipart,
177
176
  path
@@ -188,7 +187,10 @@ async function completeMultipartUpload(params) {
188
187
  await getContext(ctxToken); // just to check if the token is valid
189
188
  const bucket = router.buckets[bucketName];
190
189
  if (!bucket) {
191
- throw new Error(`Bucket ${bucketName} not found`);
190
+ throw new EdgeStoreError({
191
+ message: `Bucket ${bucketName} not found`,
192
+ code: 'BAD_REQUEST'
193
+ });
192
194
  }
193
195
  return await provider.completeMultipartUpload({
194
196
  uploadId,
@@ -207,7 +209,10 @@ async function confirmUpload(params) {
207
209
  await getContext(ctxToken); // just to check if the token is valid
208
210
  const bucket = router.buckets[bucketName];
209
211
  if (!bucket) {
210
- throw new Error(`Bucket ${bucketName} not found`);
212
+ throw new EdgeStoreError({
213
+ message: `Bucket ${bucketName} not found`,
214
+ code: 'BAD_REQUEST'
215
+ });
211
216
  }
212
217
  return await provider.confirmUpload({
213
218
  bucket,
@@ -225,10 +230,16 @@ async function deleteFile(params) {
225
230
  const ctx = await getContext(ctxToken);
226
231
  const bucket = router.buckets[bucketName];
227
232
  if (!bucket) {
228
- throw new Error(`Bucket ${bucketName} not found`);
233
+ throw new EdgeStoreError({
234
+ message: `Bucket ${bucketName} not found`,
235
+ code: 'BAD_REQUEST'
236
+ });
229
237
  }
230
238
  if (!bucket._def.beforeDelete) {
231
- throw new Error('You need to define beforeDelete if you want to delete files directly from the frontend.');
239
+ throw new EdgeStoreError({
240
+ message: 'You need to define beforeDelete if you want to delete files directly from the frontend.',
241
+ code: 'SERVER_ERROR'
242
+ });
232
243
  }
233
244
  const fileInfo = await provider.getFile({
234
245
  url
@@ -238,7 +249,10 @@ async function deleteFile(params) {
238
249
  fileInfo
239
250
  });
240
251
  if (!canDelete) {
241
- throw new Error('Delete not allowed');
252
+ throw new EdgeStoreError({
253
+ message: 'Delete not allowed for the current context',
254
+ code: 'DELETE_NOT_ALLOWED'
255
+ });
242
256
  }
243
257
  return await provider.deleteFile({
244
258
  bucket,
@@ -248,7 +262,10 @@ async function deleteFile(params) {
248
262
  async function encryptJWT(ctx) {
249
263
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
250
264
  if (!secret) {
251
- throw new Error('EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined');
265
+ throw new EdgeStoreError({
266
+ message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
267
+ code: 'SERVER_ERROR'
268
+ });
252
269
  }
253
270
  const encryptionSecret = await getDerivedEncryptionKey(secret);
254
271
  return await new EncryptJWT(ctx).setProtectedHeader({
@@ -259,7 +276,10 @@ async function encryptJWT(ctx) {
259
276
  async function decryptJWT(token) {
260
277
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
261
278
  if (!secret) {
262
- throw new Error('EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not set');
279
+ throw new EdgeStoreError({
280
+ message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
281
+ code: 'SERVER_ERROR'
282
+ });
263
283
  }
264
284
  const encryptionSecret = await getDerivedEncryptionKey(secret);
265
285
  const { payload } = await jwtDecrypt(token, encryptionSecret, {
@@ -276,13 +296,19 @@ function buildPath(params) {
276
296
  const path = pathParams.map((param)=>{
277
297
  const paramEntries = Object.entries(param);
278
298
  if (paramEntries[0] === undefined) {
279
- throw new Error('Missing path param');
299
+ throw new EdgeStoreError({
300
+ message: `Empty path param found in: ${JSON.stringify(pathParams)}`,
301
+ code: 'SERVER_ERROR'
302
+ });
280
303
  }
281
304
  const [key, value] = paramEntries[0];
282
305
  // this is a string like: "ctx.xxx" or "input.yyy.zzz"
283
306
  const currParamVal = value().split('.').reduce((acc2, key)=>{
284
307
  if (acc2[key] === undefined) {
285
- throw new Error(`Missing key ${key} in ${JSON.stringify(acc2)}`);
308
+ throw new EdgeStoreError({
309
+ message: `Missing key ${key} in ${JSON.stringify(acc2)}`,
310
+ code: 'BAD_REQUEST'
311
+ });
286
312
  }
287
313
  return acc2[key];
288
314
  }, params.pathAttrs);
@@ -305,9 +331,6 @@ function parsePath(path) {
305
331
  };
306
332
  }
307
333
  async function getContext(token) {
308
- if (!token) {
309
- throw new Error('No token');
310
- }
311
334
  return await decryptJWT(token);
312
335
  }
313
336
  /**
@@ -327,4 +350,4 @@ async function getContext(token) {
327
350
  return url;
328
351
  }
329
352
 
330
- export { EdgeStoreError as E, requestUploadParts as a, buildPath as b, completeMultipartUpload as c, confirmUpload as d, deleteFile as e, EDGE_STORE_ERROR_CODES as f, init as i, parsePath as p, requestUpload as r };
353
+ export { requestUploadParts as a, buildPath as b, completeMultipartUpload as c, confirmUpload as d, deleteFile as e, init as i, parsePath as p, requestUpload as r };