@edgestore/server 0.1.5-alpha.9 → 0.1.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 (84) hide show
  1. package/dist/adapters/express/index.d.ts +18 -0
  2. package/dist/adapters/express/index.d.ts.map +1 -0
  3. package/dist/adapters/express/index.js +117 -0
  4. package/dist/adapters/express/index.mjs +113 -0
  5. package/dist/adapters/next/app/index.d.ts +1 -3
  6. package/dist/adapters/next/app/index.d.ts.map +1 -1
  7. package/dist/adapters/next/app/index.js +20 -16
  8. package/dist/adapters/next/app/index.mjs +9 -5
  9. package/dist/adapters/next/pages/index.d.ts +1 -3
  10. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  11. package/dist/adapters/next/pages/index.js +18 -16
  12. package/dist/adapters/next/pages/index.mjs +7 -5
  13. package/dist/adapters/shared.d.ts +7 -43
  14. package/dist/adapters/shared.d.ts.map +1 -1
  15. package/dist/core/client/index.d.ts +4 -10
  16. package/dist/core/client/index.d.ts.map +1 -1
  17. package/dist/core/index.d.ts +0 -5
  18. package/dist/core/index.d.ts.map +1 -1
  19. package/dist/core/index.js +3 -13
  20. package/dist/core/index.mjs +5 -14
  21. package/dist/core/sdk/index.d.ts +1 -2
  22. package/dist/core/sdk/index.d.ts.map +1 -1
  23. package/dist/{index-537039e4.mjs → index-28efdacf.mjs} +3 -39
  24. package/dist/{index-874abae5.js → index-4491caf0.js} +3 -41
  25. package/dist/{index-b8745c2f.js → index-beed799d.js} +3 -34
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +5 -215
  29. package/dist/index.mjs +1 -218
  30. package/dist/libs/errors/EdgeStoreCredentialsError.d.ts.map +1 -1
  31. package/dist/{logger-7ea2248c.mjs → logger-09f43a75.mjs} +14 -3
  32. package/dist/{logger-b530a3e1.js → logger-dcb682ae.js} +14 -3
  33. package/dist/providers/aws/index.d.ts +1 -1
  34. package/dist/providers/aws/index.d.ts.map +1 -1
  35. package/dist/providers/azure/index.d.ts +1 -1
  36. package/dist/providers/azure/index.d.ts.map +1 -1
  37. package/dist/providers/edgestore/index.d.ts +1 -1
  38. package/dist/providers/edgestore/index.d.ts.map +1 -1
  39. package/dist/providers/edgestore/index.js +4 -4
  40. package/dist/providers/edgestore/index.mjs +2 -2
  41. package/dist/{shared-6b717151.mjs → shared-039276af.mjs} +1 -1
  42. package/dist/{shared-4c2a6210.js → shared-7c700083.js} +20 -20
  43. package/dist/{shared-e84dbdde.js → shared-83f288f6.js} +1 -1
  44. package/package.json +9 -12
  45. package/src/adapters/express/index.ts +165 -0
  46. package/src/adapters/next/app/index.ts +12 -7
  47. package/src/adapters/next/pages/index.ts +10 -7
  48. package/src/adapters/shared.ts +14 -17
  49. package/src/core/client/index.ts +9 -12
  50. package/src/core/index.ts +0 -15
  51. package/src/core/sdk/index.ts +6 -3
  52. package/src/index.ts +1 -1
  53. package/src/libs/errors/EdgeStoreCredentialsError.ts +1 -2
  54. package/src/providers/aws/index.ts +1 -1
  55. package/src/providers/azure/index.ts +1 -1
  56. package/src/providers/edgestore/index.ts +5 -2
  57. package/dist/adapters/index.d.ts +0 -2
  58. package/dist/adapters/index.d.ts.map +0 -1
  59. package/dist/adapters/index.js +0 -2
  60. package/dist/adapters/index.mjs +0 -1
  61. package/dist/core/internals/bucketBuilder.d.ts +0 -269
  62. package/dist/core/internals/bucketBuilder.d.ts.map +0 -1
  63. package/dist/core/internals/createPathParamProxy.d.ts +0 -21
  64. package/dist/core/internals/createPathParamProxy.d.ts.map +0 -1
  65. package/dist/libs/errors/EdgeStoreApiClientError.d.ts +0 -8
  66. package/dist/libs/errors/EdgeStoreApiClientError.d.ts.map +0 -1
  67. package/dist/libs/errors/EdgeStoreError.d.ts +0 -48
  68. package/dist/libs/errors/EdgeStoreError.d.ts.map +0 -1
  69. package/dist/providers/index.d.ts +0 -2
  70. package/dist/providers/index.d.ts.map +0 -1
  71. package/dist/providers/index.js +0 -2
  72. package/dist/providers/index.mjs +0 -1
  73. package/dist/providers/types.d.ts +0 -114
  74. package/dist/providers/types.d.ts.map +0 -1
  75. package/dist/types.d.ts +0 -94
  76. package/dist/types.d.ts.map +0 -1
  77. package/src/adapters/index.ts +0 -6
  78. package/src/core/internals/bucketBuilder.ts +0 -555
  79. package/src/core/internals/createPathParamProxy.ts +0 -40
  80. package/src/libs/errors/EdgeStoreApiClientError.ts +0 -14
  81. package/src/libs/errors/EdgeStoreError.ts +0 -92
  82. package/src/providers/index.ts +0 -1
  83. package/src/providers/types.ts +0 -140
  84. package/src/types.ts +0 -148
package/dist/index.mjs CHANGED
@@ -1,218 +1 @@
1
- import { z } from 'zod';
2
-
3
- /**
4
- * Creates a Proxy that prints the path to the property when called.
5
- *
6
- * Example:
7
- *
8
- * ```ts
9
- * const pathParamProxy = createPathParamProxy();
10
- * console.log(pathParamProxy.ctx.user.id());
11
- * // Logs: "ctx.user.id"
12
- * console.log(pathParamProxy.input.type());
13
- * // Logs: "input.type"
14
- * ```
15
- */ function createPathParamProxy() {
16
- const getPath = (target, _prop)=>{
17
- const proxyFunction = ()=>target;
18
- return new Proxy(proxyFunction, {
19
- get: (_target, propChild)=>{
20
- return getPath(`${target}.${String(propChild)}`);
21
- }
22
- });
23
- };
24
- return new Proxy(()=>'', {
25
- get: (_target, prop)=>{
26
- return getPath(String(prop));
27
- }
28
- });
29
- }
30
-
31
- const createNewBuilder = (initDef, newDef)=>{
32
- const mergedDef = {
33
- ...initDef,
34
- ...newDef
35
- };
36
- return createBuilder({
37
- type: mergedDef.type
38
- }, mergedDef);
39
- };
40
- function createBuilder(opts, initDef) {
41
- const _def = {
42
- type: opts.type,
43
- input: z.never(),
44
- path: [],
45
- metadata: ()=>({}),
46
- ...initDef
47
- };
48
- return {
49
- $config: {
50
- ctx: undefined
51
- },
52
- // @ts-expect-error - I think it would be too much work to make this type correct.
53
- _def,
54
- input (input) {
55
- return createNewBuilder(_def, {
56
- input
57
- });
58
- },
59
- path (pathResolver) {
60
- // TODO: Should throw a runtime error in the followin cases:
61
- // 1. in case of multiple keys in one object
62
- // 2. in case of duplicate keys
63
- const pathParamProxy = createPathParamProxy();
64
- const params = pathResolver(pathParamProxy);
65
- return createNewBuilder(_def, {
66
- path: params
67
- });
68
- },
69
- metadata (metadata) {
70
- return createNewBuilder(_def, {
71
- metadata
72
- });
73
- },
74
- accessControl (accessControl) {
75
- return createNewBuilder(_def, {
76
- accessControl: accessControl
77
- });
78
- },
79
- beforeUpload (beforeUpload) {
80
- return createNewBuilder(_def, {
81
- beforeUpload
82
- });
83
- },
84
- beforeDelete (beforeDelete) {
85
- return createNewBuilder(_def, {
86
- beforeDelete
87
- });
88
- }
89
- };
90
- }
91
- class EdgeStoreBuilder {
92
- context() {
93
- return new EdgeStoreBuilder();
94
- }
95
- create() {
96
- return createEdgeStoreInner()();
97
- }
98
- }
99
- function createRouterFactory() {
100
- return function createRouterInner(buckets) {
101
- return {
102
- $config: {
103
- ctx: undefined
104
- },
105
- buckets
106
- };
107
- };
108
- }
109
- function initBucket(type, config) {
110
- return createBuilder({
111
- type
112
- }, {
113
- bucketConfig: config
114
- });
115
- }
116
- function createEdgeStoreInner() {
117
- return function initEdgeStoreInner() {
118
- return {
119
- /**
120
- * Builder object for creating an image bucket
121
- */ imageBucket (config) {
122
- return initBucket('IMAGE', config);
123
- },
124
- /**
125
- * Builder object for creating a file bucket
126
- */ fileBucket (config) {
127
- return initBucket('FILE', config);
128
- },
129
- /**
130
- * Create a router
131
- */ router: createRouterFactory()
132
- };
133
- };
134
- }
135
- /**
136
- * Initialize EdgeStore - be done exactly once per backend
137
- */ const initEdgeStore = new EdgeStoreBuilder(); // ↓↓↓ TYPE TESTS ↓↓↓
138
- // type Context = {
139
- // userId: string;
140
- // userRole: 'admin' | 'visitor';
141
- // };
142
- // const es = initEdgeStore.context<Context>().create();
143
- // const imagesBucket = es.imageBucket()
144
- // .input(
145
- // z.object({
146
- // type: z.enum(['profile', 'post']),
147
- // extension: z.string().optional(),
148
- // }),
149
- // )
150
- // .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])
151
- // .metadata(({ ctx, input }) => ({
152
- // extension: input.extension,
153
- // role: ctx.userRole,
154
- // }))
155
- // .beforeUpload(() => {
156
- // return true;
157
- // });
158
- // const a = es.imageBucket()
159
- // .input(z.object({ type: z.string(), someMeta: z.string().optional() }))
160
- // .path(({ ctx, input }) => [{ author: ctx.userId }, { type: input.type }])
161
- // .metadata(({ ctx, input }) => ({
162
- // role: ctx.userRole,
163
- // someMeta: input.someMeta,
164
- // }))
165
- // .accessControl({
166
- // OR: [
167
- // {
168
- // userId: { path: 'author' }, // this will check if the userId is the same as the author in the path parameter
169
- // },
170
- // {
171
- // userRole: 'admin', // this is the same as { userRole: { eq: "admin" } }
172
- // },
173
- // ],
174
- // })
175
- // .beforeUpload(({ ctx, input }) => {
176
- // return true;
177
- // })
178
- // .beforeDelete(({ ctx, file }) => {
179
- // return true;
180
- // });
181
- // const b = es.imageBucket().path(({ ctx }) => [{ author: ctx.userId }]);
182
- // const router = es.router({
183
- // original: imagesBucket,
184
- // imageBucket: a,
185
- // imageBucket2: b,
186
- // });
187
- // export { router };
188
- // type ListFilesResponse<TBucket extends AnyRouter['buckets'][string]> = {
189
- // data: {
190
- // // url: string;
191
- // // size: number;
192
- // // uploadedAt: Date;
193
- // // metadata: InferMetadataObject<TBucket>;
194
- // path: InferBucketPathKeys<TBucket> extends string ? {
195
- // [key: string]: string;
196
- // } :{
197
- // [TKey in InferBucketPathKeys<TBucket>]: string;
198
- // };
199
- // }[];
200
- // pagination: {
201
- // currentPage: number;
202
- // totalPages: number;
203
- // totalCount: number;
204
- // };
205
- // };
206
- // type TPathKeys = 'author' | 'type';
207
- // type TPathKeys2 = InferBucketPathKeys<AnyBuilder>;
208
- // type ObjectWithKeys<TKeys extends string> = {
209
- // [TKey in TKeys]: string;
210
- // };
211
- // type Test1 = ObjectWithKeys<TPathKeys>;
212
- // type Test2 = ObjectWithKeys<TPathKeys2>;
213
- // type PathKeys = InferBucketPathKeys<typeof router.buckets.imageBucket>;
214
- // type MetadataKeys = InferMetadataObject<typeof router.buckets.imageBucket>;
215
- // type MyEdgeStoreRouter = typeof router;
216
- // type MyAccessControl = AccessControlSchema<Context, AnyDef>;
217
-
218
- export { initEdgeStore };
1
+ export { initEdgeStore } from '@edgestore/shared';
@@ -1 +1 @@
1
- {"version":3,"file":"EdgeStoreCredentialsError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreCredentialsError.ts"],"names":[],"mappings":"AAIA,cAAM,yBAA0B,SAAQ,KAAK;gBAC/B,OAAO,SAAkB;CAItC;AAED,eAAe,yBAAyB,CAAC"}
1
+ {"version":3,"file":"EdgeStoreCredentialsError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreCredentialsError.ts"],"names":[],"mappings":"AAGA,cAAM,yBAA0B,SAAQ,KAAK;gBAC/B,OAAO,SAAkB;CAItC;AAED,eAAe,yBAAyB,CAAC"}
@@ -1,5 +1,16 @@
1
- import { _ } from '@swc/helpers/_/_define_property';
2
-
1
+ /* eslint-disable no-console */ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
3
14
  const logLevel = [
4
15
  'debug',
5
16
  'info',
@@ -32,7 +43,7 @@ class Logger {
32
43
  }
33
44
  }
34
45
  constructor(logLevel){
35
- _(this, "logLevel", void 0);
46
+ _define_property(this, "logLevel", void 0);
36
47
  this.logLevel = logLevel ?? (process.env.NODE_ENV === 'production' ? 'error' : 'info');
37
48
  }
38
49
  }
@@ -1,7 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var _define_property = require('@swc/helpers/_/_define_property');
4
-
3
+ /* eslint-disable no-console */ function _define_property(obj, key, value) {
4
+ if (key in obj) {
5
+ Object.defineProperty(obj, key, {
6
+ value: value,
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true
10
+ });
11
+ } else {
12
+ obj[key] = value;
13
+ }
14
+ return obj;
15
+ }
5
16
  const logLevel = [
6
17
  'debug',
7
18
  'info',
@@ -34,7 +45,7 @@ class Logger {
34
45
  }
35
46
  }
36
47
  constructor(logLevel){
37
- _define_property._(this, "logLevel", void 0);
48
+ _define_property(this, "logLevel", void 0);
38
49
  this.logLevel = logLevel ?? (process.env.NODE_ENV === 'production' ? 'error' : 'info');
39
50
  }
40
51
  }
@@ -1,4 +1,4 @@
1
- import { type Provider } from '../types';
1
+ import { type Provider } from '@edgestore/shared';
2
2
  export type AWSProviderOptions = {
3
3
  /**
4
4
  * Access key for AWS credentials.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAqGlE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAqGlE"}
@@ -1,4 +1,4 @@
1
- import { type Provider } from '../types';
1
+ import { type Provider } from '@edgestore/shared';
2
2
  export type AzureProviderOptions = {
3
3
  /**
4
4
  * The storage account name for Azure Blob Storage
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,CAkEtE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,CAkEtE"}
@@ -1,4 +1,4 @@
1
- import { type Provider } from '../types';
1
+ import { type Provider } from '@edgestore/shared';
2
2
  export type EdgeStoreProviderOptions = {
3
3
  /**
4
4
  * Access key for your EdgeStore project.
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,EAEd,MAAM,mBAAmB,CAAC;AAM3B,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,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('../../index-874abae5.js');
6
- require('@swc/helpers/_/_define_property');
5
+ var shared = require('@edgestore/shared');
6
+ var index = require('../../index-4491caf0.js');
7
7
 
8
8
  const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
9
9
  function EdgeStoreProvider(options) {
@@ -82,7 +82,7 @@ function EdgeStoreProvider(options) {
82
82
  thumbnailUrl: res.thumbnailUrl
83
83
  };
84
84
  } else {
85
- throw new index.EdgeStoreError({
85
+ throw new shared.EdgeStoreError({
86
86
  message: 'Could not get upload url',
87
87
  code: 'SERVER_ERROR'
88
88
  });
@@ -100,7 +100,7 @@ function EdgeStoreProvider(options) {
100
100
  thumbnailUrl: res.thumbnailUrl
101
101
  };
102
102
  }
103
- throw new index.EdgeStoreError({
103
+ throw new shared.EdgeStoreError({
104
104
  message: 'Could not get upload url',
105
105
  code: 'SERVER_ERROR'
106
106
  });
@@ -1,5 +1,5 @@
1
- import { b as EdgeStoreCredentialsError, i as initEdgeStoreSdk, E as EdgeStoreError } from '../../index-537039e4.mjs';
2
- import '@swc/helpers/_/_define_property';
1
+ import { EdgeStoreError } from '@edgestore/shared';
2
+ import { E as EdgeStoreCredentialsError, i as initEdgeStoreSdk } from '../../index-28efdacf.mjs';
3
3
 
4
4
  const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
5
5
  function EdgeStoreProvider(options) {
@@ -1,8 +1,8 @@
1
+ import { EdgeStoreError } from '@edgestore/shared';
1
2
  import { hkdf } from '@panva/hkdf';
2
3
  import { serialize } from 'cookie';
3
4
  import { EncryptJWT, jwtDecrypt } from 'jose';
4
5
  import { v4 } from 'uuid';
5
- import { E as EdgeStoreError } from './index-537039e4.mjs';
6
6
 
7
7
  const IMAGE_MIME_TYPES = [
8
8
  'image/jpeg',
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var shared = require('@edgestore/shared');
3
4
  var hkdf = require('@panva/hkdf');
4
5
  var cookie = require('cookie');
5
6
  var jose = require('jose');
6
7
  var uuid = require('uuid');
7
- var index = require('./index-874abae5.js');
8
8
 
9
9
  const IMAGE_MIME_TYPES = [
10
10
  'image/jpeg',
@@ -64,7 +64,7 @@ async function requestUpload(params) {
64
64
  fileInfo
65
65
  });
66
66
  if (!ctxToken) {
67
- throw new index.EdgeStoreError({
67
+ throw new shared.EdgeStoreError({
68
68
  message: 'Missing edgestore-ctx cookie',
69
69
  code: 'UNAUTHORIZED'
70
70
  });
@@ -75,7 +75,7 @@ async function requestUpload(params) {
75
75
  });
76
76
  const bucket = router.buckets[bucketName];
77
77
  if (!bucket) {
78
- throw new index.EdgeStoreError({
78
+ throw new shared.EdgeStoreError({
79
79
  message: `Bucket ${bucketName} not found`,
80
80
  code: 'BAD_REQUEST'
81
81
  });
@@ -98,7 +98,7 @@ async function requestUpload(params) {
98
98
  canUpload
99
99
  });
100
100
  if (!canUpload) {
101
- throw new index.EdgeStoreError({
101
+ throw new shared.EdgeStoreError({
102
102
  message: 'Upload not allowed for the current context',
103
103
  code: 'UPLOAD_NOT_ALLOWED'
104
104
  });
@@ -106,7 +106,7 @@ async function requestUpload(params) {
106
106
  }
107
107
  if (bucket._def.type === 'IMAGE') {
108
108
  if (!IMAGE_MIME_TYPES.includes(fileInfo.type)) {
109
- throw new index.EdgeStoreError({
109
+ throw new shared.EdgeStoreError({
110
110
  code: 'MIME_TYPE_NOT_ALLOWED',
111
111
  message: 'Only images are allowed in this bucket',
112
112
  details: {
@@ -118,7 +118,7 @@ async function requestUpload(params) {
118
118
  }
119
119
  if (bucket._def.bucketConfig?.maxSize) {
120
120
  if (fileInfo.size > bucket._def.bucketConfig.maxSize) {
121
- throw new index.EdgeStoreError({
121
+ throw new shared.EdgeStoreError({
122
122
  code: 'FILE_TOO_LARGE',
123
123
  message: `File size is too big. Max size is ${bucket._def.bucketConfig.maxSize}`,
124
124
  details: {
@@ -144,7 +144,7 @@ async function requestUpload(params) {
144
144
  }
145
145
  }
146
146
  if (!accepted) {
147
- throw new index.EdgeStoreError({
147
+ throw new shared.EdgeStoreError({
148
148
  code: 'MIME_TYPE_NOT_ALLOWED',
149
149
  message: `"${fileInfo.type}" is not allowed. Accepted types are ${JSON.stringify(accept)}`,
150
150
  details: {
@@ -202,7 +202,7 @@ async function requestUploadParts(params) {
202
202
  path
203
203
  });
204
204
  if (!ctxToken) {
205
- throw new index.EdgeStoreError({
205
+ throw new shared.EdgeStoreError({
206
206
  message: 'Missing edgestore-ctx cookie',
207
207
  code: 'UNAUTHORIZED'
208
208
  });
@@ -224,7 +224,7 @@ async function completeMultipartUpload(params) {
224
224
  key
225
225
  });
226
226
  if (!ctxToken) {
227
- throw new index.EdgeStoreError({
227
+ throw new shared.EdgeStoreError({
228
228
  message: 'Missing edgestore-ctx cookie',
229
229
  code: 'UNAUTHORIZED'
230
230
  });
@@ -232,7 +232,7 @@ async function completeMultipartUpload(params) {
232
232
  await getContext(ctxToken); // just to check if the token is valid
233
233
  const bucket = router.buckets[bucketName];
234
234
  if (!bucket) {
235
- throw new index.EdgeStoreError({
235
+ throw new shared.EdgeStoreError({
236
236
  message: `Bucket ${bucketName} not found`,
237
237
  code: 'BAD_REQUEST'
238
238
  });
@@ -253,7 +253,7 @@ async function confirmUpload(params) {
253
253
  url
254
254
  });
255
255
  if (!ctxToken) {
256
- throw new index.EdgeStoreError({
256
+ throw new shared.EdgeStoreError({
257
257
  message: 'Missing edgestore-ctx cookie',
258
258
  code: 'UNAUTHORIZED'
259
259
  });
@@ -261,7 +261,7 @@ async function confirmUpload(params) {
261
261
  await getContext(ctxToken); // just to check if the token is valid
262
262
  const bucket = router.buckets[bucketName];
263
263
  if (!bucket) {
264
- throw new index.EdgeStoreError({
264
+ throw new shared.EdgeStoreError({
265
265
  message: `Bucket ${bucketName} not found`,
266
266
  code: 'BAD_REQUEST'
267
267
  });
@@ -281,7 +281,7 @@ async function deleteFile(params) {
281
281
  url
282
282
  });
283
283
  if (!ctxToken) {
284
- throw new index.EdgeStoreError({
284
+ throw new shared.EdgeStoreError({
285
285
  message: 'Missing edgestore-ctx cookie',
286
286
  code: 'UNAUTHORIZED'
287
287
  });
@@ -289,13 +289,13 @@ async function deleteFile(params) {
289
289
  const ctx = await getContext(ctxToken);
290
290
  const bucket = router.buckets[bucketName];
291
291
  if (!bucket) {
292
- throw new index.EdgeStoreError({
292
+ throw new shared.EdgeStoreError({
293
293
  message: `Bucket ${bucketName} not found`,
294
294
  code: 'BAD_REQUEST'
295
295
  });
296
296
  }
297
297
  if (!bucket._def.beforeDelete) {
298
- throw new index.EdgeStoreError({
298
+ throw new shared.EdgeStoreError({
299
299
  message: 'You need to define beforeDelete if you want to delete files directly from the frontend.',
300
300
  code: 'SERVER_ERROR'
301
301
  });
@@ -308,7 +308,7 @@ async function deleteFile(params) {
308
308
  fileInfo
309
309
  });
310
310
  if (!canDelete) {
311
- throw new index.EdgeStoreError({
311
+ throw new shared.EdgeStoreError({
312
312
  message: 'Delete not allowed for the current context',
313
313
  code: 'DELETE_NOT_ALLOWED'
314
314
  });
@@ -323,7 +323,7 @@ async function deleteFile(params) {
323
323
  async function encryptJWT(ctx) {
324
324
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
325
325
  if (!secret) {
326
- throw new index.EdgeStoreError({
326
+ throw new shared.EdgeStoreError({
327
327
  message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
328
328
  code: 'SERVER_ERROR'
329
329
  });
@@ -337,7 +337,7 @@ async function encryptJWT(ctx) {
337
337
  async function decryptJWT(token) {
338
338
  const secret = process.env.EDGE_STORE_JWT_SECRET ?? process.env.EDGE_STORE_SECRET_KEY;
339
339
  if (!secret) {
340
- throw new index.EdgeStoreError({
340
+ throw new shared.EdgeStoreError({
341
341
  message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
342
342
  code: 'SERVER_ERROR'
343
343
  });
@@ -357,7 +357,7 @@ function buildPath(params) {
357
357
  const path = pathParams.map((param)=>{
358
358
  const paramEntries = Object.entries(param);
359
359
  if (paramEntries[0] === undefined) {
360
- throw new index.EdgeStoreError({
360
+ throw new shared.EdgeStoreError({
361
361
  message: `Empty path param found in: ${JSON.stringify(pathParams)}`,
362
362
  code: 'SERVER_ERROR'
363
363
  });
@@ -366,7 +366,7 @@ function buildPath(params) {
366
366
  // this is a string like: "ctx.xxx" or "input.yyy.zzz"
367
367
  const currParamVal = value().split('.').reduce((acc2, key)=>{
368
368
  if (acc2[key] === undefined) {
369
- throw new index.EdgeStoreError({
369
+ throw new shared.EdgeStoreError({
370
370
  message: `Missing key ${key} in ${JSON.stringify(acc2)}`,
371
371
  code: 'BAD_REQUEST'
372
372
  });
@@ -1,8 +1,8 @@
1
+ import { EdgeStoreError } from '@edgestore/shared';
1
2
  import { hkdf } from '@panva/hkdf';
2
3
  import { serialize } from 'cookie';
3
4
  import { EncryptJWT, jwtDecrypt } from 'jose';
4
5
  import { v4 } from 'uuid';
5
- import { E as EdgeStoreError } from './index-b8745c2f.js';
6
6
 
7
7
  const IMAGE_MIME_TYPES = [
8
8
  'image/jpeg',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgestore/server",
3
- "version": "0.1.5-alpha.9",
3
+ "version": "0.1.5",
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",
@@ -37,10 +37,10 @@
37
37
  "require": "./dist/core/index.js",
38
38
  "default": "./dist/core/index.js"
39
39
  },
40
- "./adapters": {
41
- "import": "./dist/adapters/index.mjs",
42
- "require": "./dist/adapters/index.js",
43
- "default": "./dist/adapters/index.js"
40
+ "./adapters/express": {
41
+ "import": "./dist/adapters/express/index.mjs",
42
+ "require": "./dist/adapters/express/index.js",
43
+ "default": "./dist/adapters/express/index.js"
44
44
  },
45
45
  "./adapters/next/pages": {
46
46
  "import": "./dist/adapters/next/pages/index.mjs",
@@ -66,11 +66,6 @@
66
66
  "import": "./dist/providers/edgestore/index.mjs",
67
67
  "require": "./dist/providers/edgestore/index.js",
68
68
  "default": "./dist/providers/edgestore/index.js"
69
- },
70
- "./providers": {
71
- "import": "./dist/providers/index.mjs",
72
- "require": "./dist/providers/index.js",
73
- "default": "./dist/providers/index.js"
74
69
  }
75
70
  },
76
71
  "files": [
@@ -98,6 +93,7 @@
98
93
  "@aws-sdk/client-s3": ">=3.0.0",
99
94
  "@aws-sdk/s3-request-presigner": ">=3.0.0",
100
95
  "@azure/storage-blob": "^12.17.0",
96
+ "@edgestore/shared": "0.1.5",
101
97
  "zod": ">=3.0.0"
102
98
  },
103
99
  "peerDependenciesMeta": {
@@ -118,6 +114,7 @@
118
114
  "@aws-sdk/client-s3": "^3.420.0",
119
115
  "@aws-sdk/s3-request-presigner": "^3.420.0",
120
116
  "@azure/storage-blob": "^12.17.0",
117
+ "@edgestore/shared": "0.1.5",
121
118
  "@types/cookie": "^0.5.1",
122
119
  "@types/node": "^18.11.18",
123
120
  "@types/uuid": "^9.0.1",
@@ -125,7 +122,7 @@
125
122
  "react": "^18.2.0",
126
123
  "react-dom": "^18.2.0",
127
124
  "typescript": "^5.1.6",
128
- "zod": "^3.21.4"
125
+ "zod": "3.21.4"
129
126
  },
130
- "gitHead": "a2739cac672d5fb29feb5c1c867a96faf5115756"
127
+ "gitHead": "44951b90386930abadb67009cc9a5d1826b5cecb"
131
128
  }