@edgestore/server 0.1.5-alpha.4 → 0.1.5-alpha.5

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 (45) hide show
  1. package/dist/adapters/next/app/index.d.ts +5 -3
  2. package/dist/adapters/next/app/index.d.ts.map +1 -1
  3. package/dist/adapters/next/app/index.js +38 -15
  4. package/dist/adapters/next/app/index.mjs +37 -14
  5. package/dist/adapters/next/pages/index.d.ts +5 -3
  6. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  7. package/dist/adapters/next/pages/index.js +32 -12
  8. package/dist/adapters/next/pages/index.mjs +31 -11
  9. package/dist/adapters/shared.d.ts.map +1 -1
  10. package/dist/core/client/index.d.ts +56 -2
  11. package/dist/core/client/index.d.ts.map +1 -1
  12. package/dist/core/index.d.ts +2 -0
  13. package/dist/core/index.d.ts.map +1 -1
  14. package/dist/core/index.js +13 -3
  15. package/dist/core/index.mjs +14 -5
  16. package/dist/core/sdk/index.d.ts.map +1 -1
  17. package/dist/{index-50ab9e08.js → index-7cb3a3f3.mjs} +41 -5
  18. package/dist/{index-f33a00fb.js → index-9eb6248c.js} +37 -2
  19. package/dist/{index-30a3741e.mjs → index-e25c8209.js} +48 -2
  20. package/dist/libs/errors/EdgeStoreApiClientError.d.ts +8 -0
  21. package/dist/libs/errors/EdgeStoreApiClientError.d.ts.map +1 -0
  22. package/dist/libs/errors/EdgeStoreError.d.ts +36 -4
  23. package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -1
  24. package/dist/libs/logger.d.ts +13 -0
  25. package/dist/libs/logger.d.ts.map +1 -0
  26. package/dist/logger-0f08f252.mjs +40 -0
  27. package/dist/logger-623f2833.js +42 -0
  28. package/dist/logger-8f098618.js +33 -0
  29. package/dist/providers/edgestore/index.d.ts.map +1 -1
  30. package/dist/providers/edgestore/index.js +10 -3
  31. package/dist/providers/edgestore/index.mjs +10 -3
  32. package/dist/{shared-5d1e7f43.js → shared-53cb59dd.js} +72 -51
  33. package/dist/{shared-30b7a2ab.mjs → shared-b14a84ee.mjs} +65 -42
  34. package/dist/{shared-88655ba7.js → shared-f8ddbf7c.js} +62 -36
  35. package/package.json +2 -2
  36. package/src/adapters/next/app/index.ts +52 -19
  37. package/src/adapters/next/pages/index.ts +43 -14
  38. package/src/adapters/shared.ts +61 -29
  39. package/src/core/client/index.ts +57 -2
  40. package/src/core/index.ts +6 -0
  41. package/src/core/sdk/index.ts +7 -1
  42. package/src/libs/errors/EdgeStoreApiClientError.ts +14 -0
  43. package/src/libs/errors/EdgeStoreError.ts +76 -7
  44. package/src/libs/logger.ts +44 -0
  45. package/src/providers/edgestore/index.ts +9 -2
@@ -1,3 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ const EDGE_STORE_ERROR_CODES = {
3
+ BAD_REQUEST: 400,
4
+ FILE_TOO_LARGE: 400,
5
+ MIME_TYPE_NOT_ALLOWED: 400,
6
+ UNAUTHORIZED: 401,
7
+ UPLOAD_NOT_ALLOWED: 403,
8
+ DELETE_NOT_ALLOWED: 403,
9
+ CREATE_CONTEXT_ERROR: 500,
10
+ SERVER_ERROR: 500,
11
+ };
12
+ class EdgeStoreError extends Error {
13
+ constructor(opts) {
14
+ super(opts.message);
15
+ this.name = 'EdgeStoreError';
16
+ this.code = opts.code;
17
+ this.cause = opts.cause;
18
+ this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
19
+ this.details = 'details' in opts ? opts.details : undefined;
20
+ }
21
+ formattedMessage() {
22
+ return `EdgeStore${this.level === 'error' ? 'Error' : 'Info'}: ${this.message}${this.details ? `\n Details: ${JSON.stringify(this.details)}` : ''}${this.cause ? `\n Caused by: ${this.cause.message}` : ''}`;
23
+ }
24
+ formattedJson() {
25
+ return {
26
+ message: this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
27
+ code: this.code,
28
+ details: this.details,
29
+ };
30
+ }
31
+ }
32
+
1
33
  const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
2
34
  This can happen if you are trying to use the vanilla client in your frontend.
3
35
  The vanilla client should only be used in the backend.`;
@@ -31,7 +63,10 @@ const edgeStoreRawSdk = {
31
63
  path: bucket._def.path.map((p) => {
32
64
  const paramEntries = Object.entries(p);
33
65
  if (paramEntries[0] === undefined) {
34
- throw new Error('Missing path param');
66
+ throw new EdgeStoreError({
67
+ message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
68
+ code: 'SERVER_ERROR',
69
+ });
35
70
  }
36
71
  const [key, value] = paramEntries[0];
37
72
  return {
@@ -223,4 +258,4 @@ function initEdgeStoreSdk(params) {
223
258
  };
224
259
  }
225
260
 
226
- export { EdgeStoreCredentialsError as E, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
261
+ export { EdgeStoreError as E, EDGE_STORE_ERROR_CODES as a, EdgeStoreCredentialsError as b, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
@@ -1,3 +1,42 @@
1
+ 'use strict';
2
+
3
+ var _define_property = require('@swc/helpers/_/_define_property');
4
+
5
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ const EDGE_STORE_ERROR_CODES = {
6
+ BAD_REQUEST: 400,
7
+ FILE_TOO_LARGE: 400,
8
+ MIME_TYPE_NOT_ALLOWED: 400,
9
+ UNAUTHORIZED: 401,
10
+ UPLOAD_NOT_ALLOWED: 403,
11
+ DELETE_NOT_ALLOWED: 403,
12
+ CREATE_CONTEXT_ERROR: 500,
13
+ SERVER_ERROR: 500
14
+ };
15
+ class EdgeStoreError extends Error {
16
+ formattedMessage() {
17
+ return `EdgeStore${this.level === 'error' ? 'Error' : 'Info'}: ${this.message}${this.details ? `\n Details: ${JSON.stringify(this.details)}` : ''}${this.cause ? `\n Caused by: ${this.cause.message}` : ''}`;
18
+ }
19
+ formattedJson() {
20
+ return {
21
+ message: this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
22
+ code: this.code,
23
+ details: this.details
24
+ };
25
+ }
26
+ constructor(opts){
27
+ super(opts.message);
28
+ _define_property._(this, "cause", void 0);
29
+ _define_property._(this, "code", void 0);
30
+ _define_property._(this, "level", void 0);
31
+ _define_property._(this, "details", void 0);
32
+ this.name = 'EdgeStoreError';
33
+ this.code = opts.code;
34
+ this.cause = opts.cause;
35
+ this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
36
+ this.details = 'details' in opts ? opts.details : undefined;
37
+ }
38
+ }
39
+
1
40
  const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
2
41
  This can happen if you are trying to use the vanilla client in your frontend.
3
42
  The vanilla client should only be used in the backend.`;
@@ -31,7 +70,10 @@ const edgeStoreRawSdk = {
31
70
  path: bucket._def.path.map((p)=>{
32
71
  const paramEntries = Object.entries(p);
33
72
  if (paramEntries[0] === undefined) {
34
- throw new Error('Missing path param');
73
+ throw new EdgeStoreError({
74
+ message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
75
+ code: 'SERVER_ERROR'
76
+ });
35
77
  }
36
78
  const [key, value] = paramEntries[0];
37
79
  return {
@@ -223,4 +265,8 @@ function initEdgeStoreSdk(params) {
223
265
  };
224
266
  }
225
267
 
226
- export { EdgeStoreCredentialsError as E, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
268
+ exports.EDGE_STORE_ERROR_CODES = EDGE_STORE_ERROR_CODES;
269
+ exports.EdgeStoreCredentialsError = EdgeStoreCredentialsError;
270
+ exports.EdgeStoreError = EdgeStoreError;
271
+ exports.edgeStoreRawSdk = edgeStoreRawSdk;
272
+ exports.initEdgeStoreSdk = initEdgeStoreSdk;
@@ -0,0 +1,8 @@
1
+ import { type EdgeStoreJsonResponse } from './EdgeStoreError';
2
+ export declare class EdgeStoreApiClientError extends Error {
3
+ readonly data: EdgeStoreJsonResponse;
4
+ constructor(opts: {
5
+ response: EdgeStoreJsonResponse;
6
+ });
7
+ }
8
+ //# sourceMappingURL=EdgeStoreApiClientError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdgeStoreApiClientError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreApiClientError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAgB,IAAI,EAAE,qBAAqB,CAAC;gBAEhC,IAAI,EAAE;QAAE,QAAQ,EAAE,qBAAqB,CAAA;KAAE;CAMtD"}
@@ -1,16 +1,48 @@
1
+ import { type Simplify } from '../../types';
1
2
  export declare const EDGE_STORE_ERROR_CODES: {
2
3
  readonly BAD_REQUEST: 400;
4
+ readonly FILE_TOO_LARGE: 400;
5
+ readonly MIME_TYPE_NOT_ALLOWED: 400;
3
6
  readonly UNAUTHORIZED: 401;
7
+ readonly UPLOAD_NOT_ALLOWED: 403;
8
+ readonly DELETE_NOT_ALLOWED: 403;
9
+ readonly CREATE_CONTEXT_ERROR: 500;
10
+ readonly SERVER_ERROR: 500;
4
11
  };
5
12
  export type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;
6
- declare class EdgeStoreError extends Error {
13
+ export type EdgeStoreErrorDetails<TCode extends EdgeStoreErrorCodeKey> = TCode extends 'FILE_TOO_LARGE' ? {
14
+ maxFileSize: number;
15
+ fileSize: number;
16
+ } : TCode extends 'MIME_TYPE_NOT_ALLOWED' ? {
17
+ allowedMimeTypes: string[];
18
+ mimeType: string;
19
+ } : never;
20
+ export type EdgeStoreJsonResponse = Simplify<{
21
+ message: string;
22
+ code: 'FILE_TOO_LARGE';
23
+ details: EdgeStoreErrorDetails<'FILE_TOO_LARGE'>;
24
+ } | {
25
+ message: string;
26
+ code: 'MIME_TYPE_NOT_ALLOWED';
27
+ details: EdgeStoreErrorDetails<'MIME_TYPE_NOT_ALLOWED'>;
28
+ } | {
29
+ message: string;
30
+ code: Exclude<EdgeStoreErrorCodeKey, 'FILE_TOO_LARGE' | 'MIME_TYPE_NOT_ALLOWED'>;
31
+ }>;
32
+ declare class EdgeStoreError<TCode extends EdgeStoreErrorCodeKey> extends Error {
7
33
  readonly cause?: Error;
8
- readonly code: EdgeStoreErrorCodeKey;
34
+ readonly code: TCode;
35
+ readonly level: 'error' | 'warn';
36
+ readonly details: EdgeStoreErrorDetails<TCode>;
9
37
  constructor(opts: {
10
38
  message: string;
11
- code: EdgeStoreErrorCodeKey;
39
+ code: TCode;
12
40
  cause?: Error;
13
- });
41
+ } & (EdgeStoreErrorDetails<TCode> extends undefined ? object : {
42
+ details: EdgeStoreErrorDetails<TCode>;
43
+ }));
44
+ formattedMessage(): string;
45
+ formattedJson(): EdgeStoreJsonResponse;
14
46
  }
15
47
  export default EdgeStoreError;
16
48
  //# sourceMappingURL=EdgeStoreError.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB;;;CAGzB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,sBAAsB,CAAC;AAExE,cAAM,cAAe,SAAQ,KAAK;IAChC,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9B,SAAgB,IAAI,EAAE,qBAAqB,CAAC;gBAEhC,IAAI,EAAE;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,qBAAqB,CAAC;QAC5B,KAAK,CAAC,EAAE,KAAK,CAAC;KACf;CAOF;AAED,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,eAAO,MAAM,sBAAsB;;;;;;;;;CASzB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,sBAAsB,CAAC;AAExE,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,qBAAqB,IACnE,KAAK,SAAS,gBAAgB,GAC1B;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,SAAS,uBAAuB,GACrC;IACE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CACxC;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;CAClD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,qBAAqB,CAAC,uBAAuB,CAAC,CAAC;CACzD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CACX,qBAAqB,EACrB,gBAAgB,GAAG,uBAAuB,CAC3C,CAAC;CACH,CACJ,CAAC;AAEF,cAAM,cAAc,CAAC,KAAK,SAAS,qBAAqB,CAAE,SAAQ,KAAK;IACrE,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9B,SAAgB,IAAI,EAAE,KAAK,CAAC;IAC5B,SAAgB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxC,SAAgB,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAGpD,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,GAAG,CAAC,qBAAqB,CAAC,KAAK,CAAC,SAAS,SAAS,GAC/C,MAAM,GACN;QACE,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;KACvC,CAAC;IAWR,gBAAgB,IAAI,MAAM;IAQ1B,aAAa,IAAI,qBAAqB;CAQvC;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,13 @@
1
+ declare const logLevel: readonly ["debug", "info", "warn", "error", "none"];
2
+ export type LogLevel = typeof logLevel[number];
3
+ declare class Logger {
4
+ private logLevel;
5
+ constructor(logLevel?: LogLevel);
6
+ private shouldLog;
7
+ debug(message?: any, ...optionalParams: any[]): void;
8
+ info(message?: any, ...optionalParams: any[]): void;
9
+ warn(message?: any, ...optionalParams: any[]): void;
10
+ error(message?: any, ...optionalParams: any[]): void;
11
+ }
12
+ export default Logger;
13
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/libs/logger.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,QAAQ,qDAAsD,CAAC;AAErE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE/C,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAW;gBAEf,QAAQ,CAAC,EAAE,QAAQ;IAK/B,OAAO,CAAC,SAAS;IAIjB,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMpD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMnD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMnD,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;CAKrD;AAED,eAAe,MAAM,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { _ } from '@swc/helpers/_/_define_property';
2
+
3
+ const logLevel = [
4
+ 'debug',
5
+ 'info',
6
+ 'warn',
7
+ 'error',
8
+ 'none'
9
+ ];
10
+ class Logger {
11
+ shouldLog(level) {
12
+ return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
13
+ }
14
+ debug(message, ...optionalParams) {
15
+ if (this.shouldLog('debug')) {
16
+ console.debug(message, ...optionalParams);
17
+ }
18
+ }
19
+ info(message, ...optionalParams) {
20
+ if (this.shouldLog('info')) {
21
+ console.info(message, ...optionalParams);
22
+ }
23
+ }
24
+ warn(message, ...optionalParams) {
25
+ if (this.shouldLog('warn')) {
26
+ console.warn(message, ...optionalParams);
27
+ }
28
+ }
29
+ error(message, ...optionalParams) {
30
+ if (this.shouldLog('error')) {
31
+ console.error(message, ...optionalParams);
32
+ }
33
+ }
34
+ constructor(logLevel){
35
+ _(this, "logLevel", void 0);
36
+ this.logLevel = logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
37
+ }
38
+ }
39
+
40
+ export { Logger as L };
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ var _define_property = require('@swc/helpers/_/_define_property');
4
+
5
+ const logLevel = [
6
+ 'debug',
7
+ 'info',
8
+ 'warn',
9
+ 'error',
10
+ 'none'
11
+ ];
12
+ class Logger {
13
+ shouldLog(level) {
14
+ return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
15
+ }
16
+ debug(message, ...optionalParams) {
17
+ if (this.shouldLog('debug')) {
18
+ console.debug(message, ...optionalParams);
19
+ }
20
+ }
21
+ info(message, ...optionalParams) {
22
+ if (this.shouldLog('info')) {
23
+ console.info(message, ...optionalParams);
24
+ }
25
+ }
26
+ warn(message, ...optionalParams) {
27
+ if (this.shouldLog('warn')) {
28
+ console.warn(message, ...optionalParams);
29
+ }
30
+ }
31
+ error(message, ...optionalParams) {
32
+ if (this.shouldLog('error')) {
33
+ console.error(message, ...optionalParams);
34
+ }
35
+ }
36
+ constructor(logLevel){
37
+ _define_property._(this, "logLevel", void 0);
38
+ this.logLevel = logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
39
+ }
40
+ }
41
+
42
+ exports.Logger = Logger;
@@ -0,0 +1,33 @@
1
+ /* eslint-disable no-console */
2
+ const logLevel = ['debug', 'info', 'warn', 'error', 'none'];
3
+ class Logger {
4
+ constructor(logLevel) {
5
+ this.logLevel =
6
+ logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
7
+ }
8
+ shouldLog(level) {
9
+ return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
10
+ }
11
+ debug(message, ...optionalParams) {
12
+ if (this.shouldLog('debug')) {
13
+ console.debug(message, ...optionalParams);
14
+ }
15
+ }
16
+ info(message, ...optionalParams) {
17
+ if (this.shouldLog('info')) {
18
+ console.info(message, ...optionalParams);
19
+ }
20
+ }
21
+ warn(message, ...optionalParams) {
22
+ if (this.shouldLog('warn')) {
23
+ console.warn(message, ...optionalParams);
24
+ }
25
+ }
26
+ error(message, ...optionalParams) {
27
+ if (this.shouldLog('error')) {
28
+ console.error(message, ...optionalParams);
29
+ }
30
+ }
31
+ }
32
+
33
+ export { Logger as L };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAyB,MAAM,UAAU,CAAC;AAIhE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,CA0IV"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,QAAQ,EAAyB,MAAM,UAAU,CAAC;AAIhE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,CAgJV"}
@@ -2,7 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../index-50ab9e08.js');
5
+ var index = require('../../index-e25c8209.js');
6
+ require('@swc/helpers/_/_define_property');
6
7
 
7
8
  const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
8
9
  function EdgeStoreProvider(options) {
@@ -81,7 +82,10 @@ function EdgeStoreProvider(options) {
81
82
  thumbnailUrl: res.thumbnailUrl
82
83
  };
83
84
  } else {
84
- throw new Error('Could not get upload url');
85
+ throw new index.EdgeStoreError({
86
+ message: 'Could not get upload url',
87
+ code: 'SERVER_ERROR'
88
+ });
85
89
  }
86
90
  }
87
91
  const res = await edgeStoreSdk.requestUpload({
@@ -96,7 +100,10 @@ function EdgeStoreProvider(options) {
96
100
  thumbnailUrl: res.thumbnailUrl
97
101
  };
98
102
  }
99
- throw new Error('Could not get upload url');
103
+ throw new index.EdgeStoreError({
104
+ message: 'Could not get upload url',
105
+ code: 'SERVER_ERROR'
106
+ });
100
107
  },
101
108
  requestUploadParts: async ({ multipart, path })=>{
102
109
  const res = await edgeStoreSdk.requestUploadParts({
@@ -1,4 +1,5 @@
1
- import { E as EdgeStoreCredentialsError, i as initEdgeStoreSdk } from '../../index-30a3741e.mjs';
1
+ import { b as EdgeStoreCredentialsError, i as initEdgeStoreSdk, E as EdgeStoreError } from '../../index-7cb3a3f3.mjs';
2
+ import '@swc/helpers/_/_define_property';
2
3
 
3
4
  const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
4
5
  function EdgeStoreProvider(options) {
@@ -77,7 +78,10 @@ function EdgeStoreProvider(options) {
77
78
  thumbnailUrl: res.thumbnailUrl
78
79
  };
79
80
  } else {
80
- throw new Error('Could not get upload url');
81
+ throw new EdgeStoreError({
82
+ message: 'Could not get upload url',
83
+ code: 'SERVER_ERROR'
84
+ });
81
85
  }
82
86
  }
83
87
  const res = await edgeStoreSdk.requestUpload({
@@ -92,7 +96,10 @@ function EdgeStoreProvider(options) {
92
96
  thumbnailUrl: res.thumbnailUrl
93
97
  };
94
98
  }
95
- throw new Error('Could not get upload url');
99
+ throw new EdgeStoreError({
100
+ message: 'Could not get upload url',
101
+ code: 'SERVER_ERROR'
102
+ });
96
103
  },
97
104
  requestUploadParts: async ({ multipart, path })=>{
98
105
  const res = await edgeStoreSdk.requestUploadParts({
@@ -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;