@edgestore/server 0.1.3-alpha.3 → 0.1.4

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.
@@ -31,6 +31,13 @@ export type AWSProviderOptions = {
31
31
  * Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
32
32
  */
33
33
  baseUrl?: string;
34
+ /**
35
+ * Secret to use for encrypting JWT tokens.
36
+ * Can be generated with `openssl rand -base64 32`.
37
+ *
38
+ * Can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
39
+ */
40
+ jwtSecret?: string;
34
41
  };
35
42
  export declare function AWSProvider(options?: AWSProviderOptions): Provider;
36
43
  //# sourceMappingURL=index.d.ts.map
@@ -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;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,QAAQ,CAkGlE"}
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"}
@@ -41,22 +41,23 @@ function AWSProvider(options) {
41
41
  uploadedAt: LastModified
42
42
  };
43
43
  },
44
- async requestUpload ({ bucketName, fileInfo }) {
45
- const pathPrefix = `${bucketName}${fileInfo.isPublic ? '/_public' : ''}`;
44
+ async requestUpload ({ bucketName: esBucketName, fileInfo }) {
45
+ const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
46
46
  const nameId = uuid.v4();
47
47
  const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
48
48
  const fileName = `${nameId}${extension}`;
49
49
  const filePath = fileInfo.path.reduce((acc, item)=>{
50
50
  return `${acc}/${item.value}`;
51
51
  }, '');
52
+ const accessPath = `${pathPrefix}${filePath}/${fileName}`;
52
53
  const command = new clientS3.PutObjectCommand({
53
54
  Bucket: bucketName,
54
- Key: `${pathPrefix}/${filePath}/${fileName}`
55
+ Key: accessPath
55
56
  });
56
57
  const signedUrl = await s3RequestPresigner.getSignedUrl(s3Client, command, {
57
58
  expiresIn: 60 * 60
58
59
  });
59
- const url = `${baseUrl}/${fileInfo.path}`;
60
+ const url = `${baseUrl}/${accessPath}`;
60
61
  return {
61
62
  uploadUrl: signedUrl,
62
63
  accessUrl: url
@@ -37,22 +37,23 @@ function AWSProvider(options) {
37
37
  uploadedAt: LastModified
38
38
  };
39
39
  },
40
- async requestUpload ({ bucketName, fileInfo }) {
41
- const pathPrefix = `${bucketName}${fileInfo.isPublic ? '/_public' : ''}`;
40
+ async requestUpload ({ bucketName: esBucketName, fileInfo }) {
41
+ const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
42
42
  const nameId = v4();
43
43
  const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
44
44
  const fileName = `${nameId}${extension}`;
45
45
  const filePath = fileInfo.path.reduce((acc, item)=>{
46
46
  return `${acc}/${item.value}`;
47
47
  }, '');
48
+ const accessPath = `${pathPrefix}${filePath}/${fileName}`;
48
49
  const command = new PutObjectCommand({
49
50
  Bucket: bucketName,
50
- Key: `${pathPrefix}/${filePath}/${fileName}`
51
+ Key: accessPath
51
52
  });
52
53
  const signedUrl = await getSignedUrl(s3Client, command, {
53
54
  expiresIn: 60 * 60
54
55
  });
55
- const url = `${baseUrl}/${fileInfo.path}`;
56
+ const url = `${baseUrl}/${accessPath}`;
56
57
  return {
57
58
  uploadUrl: signedUrl,
58
59
  accessUrl: url
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgestore/server",
3
- "version": "0.1.3-alpha.3",
3
+ "version": "0.1.4",
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",
@@ -84,17 +84,30 @@
84
84
  },
85
85
  "license": "MIT",
86
86
  "dependencies": {
87
- "@aws-sdk/client-s3": "^3.294.0",
88
- "@aws-sdk/s3-request-presigner": "^3.294.0",
89
87
  "@panva/hkdf": "^1.0.4",
90
88
  "cookie": "^0.5.0",
91
89
  "jose": "^4.13.1",
92
90
  "uuid": "^9.0.0"
93
91
  },
94
92
  "peerDependencies": {
93
+ "@aws-sdk/client-s3": ">=3.0.0",
94
+ "@aws-sdk/s3-request-presigner": ">=3.0.0",
95
95
  "zod": ">=3.0.0"
96
96
  },
97
+ "peerDependenciesMeta": {
98
+ "zod": {
99
+ "optional": true
100
+ },
101
+ "@aws-sdk/client-s3": {
102
+ "optional": true
103
+ },
104
+ "@aws-sdk/s3-request-presigner": {
105
+ "optional": true
106
+ }
107
+ },
97
108
  "devDependencies": {
109
+ "@aws-sdk/client-s3": "^3.420.0",
110
+ "@aws-sdk/s3-request-presigner": "^3.420.0",
98
111
  "@types/cookie": "^0.5.1",
99
112
  "@types/node": "^18.11.18",
100
113
  "@types/uuid": "^9.0.1",
@@ -104,5 +117,5 @@
104
117
  "typescript": "^5.1.6",
105
118
  "zod": "^3.21.4"
106
119
  },
107
- "gitHead": "f251931cec589c801432683521c8aa30428fa107"
120
+ "gitHead": "8caf5d5b576aea4d057d20b48eb61adc5bb0aa3d"
108
121
  }
@@ -40,6 +40,13 @@ export type AWSProviderOptions = {
40
40
  * Can also be set via the `EDGE_STORE_BASE_URL` environment variable.
41
41
  */
42
42
  baseUrl?: string;
43
+ /**
44
+ * Secret to use for encrypting JWT tokens.
45
+ * Can be generated with `openssl rand -base64 32`.
46
+ *
47
+ * Can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
48
+ */
49
+ jwtSecret?: string;
43
50
  };
44
51
 
45
52
  export function AWSProvider(options?: AWSProviderOptions): Provider {
@@ -92,8 +99,10 @@ export function AWSProvider(options?: AWSProviderOptions): Provider {
92
99
  uploadedAt: LastModified,
93
100
  };
94
101
  },
95
- async requestUpload({ bucketName, fileInfo }) {
96
- const pathPrefix = `${bucketName}${fileInfo.isPublic ? '/_public' : ''}`;
102
+ async requestUpload({ bucketName: esBucketName, fileInfo }) {
103
+ const pathPrefix = `${esBucketName}${
104
+ fileInfo.isPublic ? '/_public' : ''
105
+ }`;
97
106
  const nameId = uuidv4();
98
107
  const extension = fileInfo.extension
99
108
  ? `.${fileInfo.extension.replace('.', '')}`
@@ -102,17 +111,18 @@ export function AWSProvider(options?: AWSProviderOptions): Provider {
102
111
  const filePath = fileInfo.path.reduce((acc, item) => {
103
112
  return `${acc}/${item.value}`;
104
113
  }, '');
114
+ const accessPath = `${pathPrefix}${filePath}/${fileName}`;
105
115
 
106
116
  const command = new PutObjectCommand({
107
117
  Bucket: bucketName,
108
- Key: `${pathPrefix}/${filePath}/${fileName}`,
118
+ Key: accessPath,
109
119
  });
110
120
 
111
121
  const signedUrl = await getSignedUrl(s3Client, command, {
112
122
  expiresIn: 60 * 60, // 1 hour
113
123
  });
114
124
 
115
- const url = `${baseUrl}/${fileInfo.path}`;
125
+ const url = `${baseUrl}/${accessPath}`;
116
126
  return {
117
127
  uploadUrl: signedUrl,
118
128
  accessUrl: url,