@edgestore/server 0.0.0-alpha.12

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 (83) hide show
  1. package/README.md +86 -0
  2. package/adapters/next/app/index.d.ts +1 -0
  3. package/adapters/next/app/index.js +1 -0
  4. package/adapters/next/index.d.ts +1 -0
  5. package/adapters/next/index.js +1 -0
  6. package/adapters/next/pages/index.d.ts +1 -0
  7. package/adapters/next/pages/index.js +1 -0
  8. package/core/index.d.ts +1 -0
  9. package/core/index.js +1 -0
  10. package/dist/adapters/imageTypes.d.ts +2 -0
  11. package/dist/adapters/imageTypes.d.ts.map +1 -0
  12. package/dist/adapters/next/app/index.d.ts +14 -0
  13. package/dist/adapters/next/app/index.d.ts.map +1 -0
  14. package/dist/adapters/next/app/index.js +95 -0
  15. package/dist/adapters/next/app/index.mjs +91 -0
  16. package/dist/adapters/next/pages/index.d.ts +15 -0
  17. package/dist/adapters/next/pages/index.d.ts.map +1 -0
  18. package/dist/adapters/next/pages/index.js +69 -0
  19. package/dist/adapters/next/pages/index.mjs +65 -0
  20. package/dist/adapters/shared.d.ts +79 -0
  21. package/dist/adapters/shared.d.ts.map +1 -0
  22. package/dist/core/client/index.d.ts +81 -0
  23. package/dist/core/client/index.d.ts.map +1 -0
  24. package/dist/core/index.d.ts +6 -0
  25. package/dist/core/index.d.ts.map +1 -0
  26. package/dist/core/index.js +96 -0
  27. package/dist/core/index.mjs +91 -0
  28. package/dist/core/internals/bucketBuilder.d.ts +199 -0
  29. package/dist/core/internals/bucketBuilder.d.ts.map +1 -0
  30. package/dist/core/internals/createPathParamProxy.d.ts +21 -0
  31. package/dist/core/internals/createPathParamProxy.d.ts.map +1 -0
  32. package/dist/core/sdk/index.d.ts +200 -0
  33. package/dist/core/sdk/index.d.ts.map +1 -0
  34. package/dist/index-3999aae6.js +187 -0
  35. package/dist/index-3cc4d530.js +183 -0
  36. package/dist/index-ca41982b.mjs +183 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +213 -0
  40. package/dist/index.mjs +209 -0
  41. package/dist/libs/errors/EdgeStoreCredentialsError.d.ts +5 -0
  42. package/dist/libs/errors/EdgeStoreCredentialsError.d.ts.map +1 -0
  43. package/dist/libs/errors/EdgeStoreError.d.ts +16 -0
  44. package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -0
  45. package/dist/providers/aws/index.d.ts +9 -0
  46. package/dist/providers/aws/index.d.ts.map +1 -0
  47. package/dist/providers/aws/index.js +81 -0
  48. package/dist/providers/aws/index.mjs +77 -0
  49. package/dist/providers/edgestore/index.d.ts +8 -0
  50. package/dist/providers/edgestore/index.d.ts.map +1 -0
  51. package/dist/providers/edgestore/index.js +121 -0
  52. package/dist/providers/edgestore/index.mjs +117 -0
  53. package/dist/providers/index.d.ts +3 -0
  54. package/dist/providers/index.d.ts.map +1 -0
  55. package/dist/providers/types.d.ts +91 -0
  56. package/dist/providers/types.d.ts.map +1 -0
  57. package/dist/shared-43667670.mjs +232 -0
  58. package/dist/shared-6bef8919.js +227 -0
  59. package/dist/shared-f7607e44.js +239 -0
  60. package/dist/types.d.ts +88 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/package.json +96 -0
  63. package/providers/aws/index.d.ts +1 -0
  64. package/providers/aws/index.js +1 -0
  65. package/providers/edgestore/index.d.ts +1 -0
  66. package/providers/edgestore/index.js +1 -0
  67. package/src/adapters/imageTypes.ts +10 -0
  68. package/src/adapters/next/app/index.ts +111 -0
  69. package/src/adapters/next/pages/index.ts +84 -0
  70. package/src/adapters/shared.ts +306 -0
  71. package/src/core/client/index.ts +202 -0
  72. package/src/core/index.ts +10 -0
  73. package/src/core/internals/bucketBuilder.ts +462 -0
  74. package/src/core/internals/createPathParamProxy.ts +40 -0
  75. package/src/core/sdk/index.ts +381 -0
  76. package/src/index.ts +1 -0
  77. package/src/libs/errors/EdgeStoreCredentialsError.ts +12 -0
  78. package/src/libs/errors/EdgeStoreError.ts +25 -0
  79. package/src/providers/aws/index.ts +109 -0
  80. package/src/providers/edgestore/index.ts +140 -0
  81. package/src/providers/index.ts +2 -0
  82. package/src/providers/types.ts +107 -0
  83. package/src/types.ts +139 -0
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
4
+ This can happen if you are trying to use the vanilla client in your frontend.
5
+ The vanilla client should only be used in the backend.`;
6
+ class EdgeStoreCredentialsError extends Error {
7
+ constructor(message = DEFAULT_MESSAGE){
8
+ super(message);
9
+ this.name = 'EdgeStoreCredentialsError';
10
+ }
11
+ }
12
+
13
+ const API_ENDPOINT = process.env.EDGE_STORE_API_ENDPOINT ?? 'https://api.edge-store.com';
14
+ async function makeRequest(params) {
15
+ const { body, accessKey, secretKey, path } = params;
16
+ const res = await fetch(`${API_ENDPOINT}${path}`, {
17
+ method: 'POST',
18
+ body: JSON.stringify(body),
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`
22
+ }
23
+ });
24
+ if (!res.ok) {
25
+ throw new Error(`Failed to make request to ${path}`);
26
+ }
27
+ return await res.json();
28
+ }
29
+ const edgeStoreRawSdk = {
30
+ async getToken (params) {
31
+ const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket])=>{
32
+ acc[bucketName] = {
33
+ path: bucket._def.path.map((p)=>{
34
+ const paramEntries = Object.entries(p);
35
+ if (paramEntries[0] === undefined) {
36
+ throw new Error('Missing path param');
37
+ }
38
+ const [key, value] = paramEntries[0];
39
+ return {
40
+ key,
41
+ value: value()
42
+ };
43
+ }),
44
+ accessControl: bucket._def.accessControl
45
+ };
46
+ return acc;
47
+ }, {});
48
+ const { token } = await makeRequest({
49
+ body: {
50
+ ctx: params.ctx,
51
+ buckets: reqBuckets
52
+ },
53
+ accessKey: params.accessKey,
54
+ secretKey: params.secretKey,
55
+ path: '/get-token'
56
+ });
57
+ return token;
58
+ },
59
+ async getFile ({ accessKey, secretKey, url }) {
60
+ return await makeRequest({
61
+ path: '/get-file',
62
+ accessKey,
63
+ secretKey,
64
+ body: {
65
+ url
66
+ }
67
+ });
68
+ },
69
+ async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart }) {
70
+ const res = await makeRequest({
71
+ path: '/request-upload',
72
+ accessKey,
73
+ secretKey,
74
+ body: {
75
+ multipart,
76
+ bucketName,
77
+ bucketType,
78
+ isPublic: fileInfo.isPublic,
79
+ path: fileInfo.path,
80
+ extension: fileInfo.extension,
81
+ size: fileInfo.size,
82
+ metadata: fileInfo.metadata,
83
+ replaceTargetUrl: fileInfo.replaceTargetUrl
84
+ }
85
+ });
86
+ return {
87
+ multipart: res.multipart,
88
+ signedUrl: res.signedUrl,
89
+ accessUrl: res.url
90
+ };
91
+ },
92
+ async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
93
+ const res = await makeRequest({
94
+ path: '/request-upload-parts',
95
+ accessKey,
96
+ secretKey,
97
+ body: {
98
+ multipart,
99
+ key
100
+ }
101
+ });
102
+ return {
103
+ multipart: res.multipart
104
+ };
105
+ },
106
+ async deleteFile ({ accessKey, secretKey, url }) {
107
+ return await makeRequest({
108
+ path: '/delete-file',
109
+ accessKey,
110
+ secretKey,
111
+ body: {
112
+ url
113
+ }
114
+ });
115
+ },
116
+ async listFiles ({ accessKey, secretKey, bucketName, filter, pagination }) {
117
+ return await makeRequest({
118
+ path: '/list-files',
119
+ accessKey,
120
+ secretKey,
121
+ body: {
122
+ bucketName,
123
+ filter,
124
+ pagination
125
+ }
126
+ });
127
+ }
128
+ };
129
+ function initEdgeStoreSdk(params) {
130
+ const { accessKey = process.env.EDGE_STORE_ACCESS_KEY, secretKey = process.env.EDGE_STORE_SECRET_KEY } = params ?? {};
131
+ if (!accessKey || !secretKey) {
132
+ throw new EdgeStoreCredentialsError();
133
+ }
134
+ return {
135
+ async getToken (params) {
136
+ return await edgeStoreRawSdk.getToken({
137
+ accessKey,
138
+ secretKey,
139
+ ctx: params.ctx,
140
+ router: params.router
141
+ });
142
+ },
143
+ async getFile ({ url }) {
144
+ return await edgeStoreRawSdk.getFile({
145
+ accessKey,
146
+ secretKey,
147
+ url
148
+ });
149
+ },
150
+ async requestUpload ({ bucketName, bucketType, fileInfo, multipart }) {
151
+ return await edgeStoreRawSdk.requestUpload({
152
+ accessKey,
153
+ secretKey,
154
+ bucketName,
155
+ bucketType,
156
+ fileInfo,
157
+ multipart
158
+ });
159
+ },
160
+ async requestUploadParts ({ key, multipart }) {
161
+ return await edgeStoreRawSdk.requestUploadParts({
162
+ accessKey,
163
+ secretKey,
164
+ key,
165
+ multipart
166
+ });
167
+ },
168
+ async deleteFile ({ url }) {
169
+ return await edgeStoreRawSdk.deleteFile({
170
+ accessKey,
171
+ secretKey,
172
+ url
173
+ });
174
+ },
175
+ async listFiles (params) {
176
+ return await edgeStoreRawSdk.listFiles({
177
+ accessKey,
178
+ secretKey,
179
+ ...params
180
+ });
181
+ }
182
+ };
183
+ }
184
+
185
+ exports.EdgeStoreCredentialsError = EdgeStoreCredentialsError;
186
+ exports.edgeStoreRawSdk = edgeStoreRawSdk;
187
+ exports.initEdgeStoreSdk = initEdgeStoreSdk;
@@ -0,0 +1,183 @@
1
+ const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
2
+ This can happen if you are trying to use the vanilla client in your frontend.
3
+ The vanilla client should only be used in the backend.`;
4
+ class EdgeStoreCredentialsError extends Error {
5
+ constructor(message = DEFAULT_MESSAGE) {
6
+ super(message);
7
+ this.name = 'EdgeStoreCredentialsError';
8
+ }
9
+ }
10
+
11
+ const API_ENDPOINT = process.env.EDGE_STORE_API_ENDPOINT ?? 'https://api.edge-store.com';
12
+ async function makeRequest(params) {
13
+ const { body, accessKey, secretKey, path } = params;
14
+ const res = await fetch(`${API_ENDPOINT}${path}`, {
15
+ method: 'POST',
16
+ body: JSON.stringify(body),
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`,
20
+ },
21
+ });
22
+ if (!res.ok) {
23
+ throw new Error(`Failed to make request to ${path}`);
24
+ }
25
+ return (await res.json());
26
+ }
27
+ const edgeStoreRawSdk = {
28
+ async getToken(params) {
29
+ const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket]) => {
30
+ acc[bucketName] = {
31
+ path: bucket._def.path.map((p) => {
32
+ const paramEntries = Object.entries(p);
33
+ if (paramEntries[0] === undefined) {
34
+ throw new Error('Missing path param');
35
+ }
36
+ const [key, value] = paramEntries[0];
37
+ return {
38
+ key,
39
+ value: value(),
40
+ };
41
+ }),
42
+ accessControl: bucket._def.accessControl,
43
+ };
44
+ return acc;
45
+ }, {});
46
+ const { token } = await makeRequest({
47
+ body: {
48
+ ctx: params.ctx,
49
+ buckets: reqBuckets,
50
+ },
51
+ accessKey: params.accessKey,
52
+ secretKey: params.secretKey,
53
+ path: '/get-token',
54
+ });
55
+ return token;
56
+ },
57
+ async getFile({ accessKey, secretKey, url, }) {
58
+ return await makeRequest({
59
+ path: '/get-file',
60
+ accessKey,
61
+ secretKey,
62
+ body: {
63
+ url,
64
+ },
65
+ });
66
+ },
67
+ async requestUpload({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart, }) {
68
+ const res = await makeRequest({
69
+ path: '/request-upload',
70
+ accessKey,
71
+ secretKey,
72
+ body: {
73
+ multipart,
74
+ bucketName,
75
+ bucketType,
76
+ isPublic: fileInfo.isPublic,
77
+ path: fileInfo.path,
78
+ extension: fileInfo.extension,
79
+ size: fileInfo.size,
80
+ metadata: fileInfo.metadata,
81
+ replaceTargetUrl: fileInfo.replaceTargetUrl,
82
+ },
83
+ });
84
+ return {
85
+ multipart: res.multipart,
86
+ signedUrl: res.signedUrl,
87
+ accessUrl: res.url,
88
+ };
89
+ },
90
+ async requestUploadParts({ accessKey, secretKey, key, multipart, }) {
91
+ const res = await makeRequest({
92
+ path: '/request-upload-parts',
93
+ accessKey,
94
+ secretKey,
95
+ body: {
96
+ multipart,
97
+ key,
98
+ },
99
+ });
100
+ return {
101
+ multipart: res.multipart,
102
+ };
103
+ },
104
+ async deleteFile({ accessKey, secretKey, url, }) {
105
+ return await makeRequest({
106
+ path: '/delete-file',
107
+ accessKey,
108
+ secretKey,
109
+ body: {
110
+ url,
111
+ },
112
+ });
113
+ },
114
+ async listFiles({ accessKey, secretKey, bucketName, filter, pagination, }) {
115
+ return await makeRequest({
116
+ path: '/list-files',
117
+ accessKey,
118
+ secretKey,
119
+ body: {
120
+ bucketName,
121
+ filter,
122
+ pagination,
123
+ },
124
+ });
125
+ },
126
+ };
127
+ function initEdgeStoreSdk(params) {
128
+ const { accessKey = process.env.EDGE_STORE_ACCESS_KEY, secretKey = process.env.EDGE_STORE_SECRET_KEY, } = params ?? {};
129
+ if (!accessKey || !secretKey) {
130
+ throw new EdgeStoreCredentialsError();
131
+ }
132
+ return {
133
+ async getToken(params) {
134
+ return await edgeStoreRawSdk.getToken({
135
+ accessKey,
136
+ secretKey,
137
+ ctx: params.ctx,
138
+ router: params.router,
139
+ });
140
+ },
141
+ async getFile({ url }) {
142
+ return await edgeStoreRawSdk.getFile({
143
+ accessKey,
144
+ secretKey,
145
+ url,
146
+ });
147
+ },
148
+ async requestUpload({ bucketName, bucketType, fileInfo, multipart, }) {
149
+ return await edgeStoreRawSdk.requestUpload({
150
+ accessKey,
151
+ secretKey,
152
+ bucketName,
153
+ bucketType,
154
+ fileInfo,
155
+ multipart,
156
+ });
157
+ },
158
+ async requestUploadParts({ key, multipart, }) {
159
+ return await edgeStoreRawSdk.requestUploadParts({
160
+ accessKey,
161
+ secretKey,
162
+ key,
163
+ multipart,
164
+ });
165
+ },
166
+ async deleteFile({ url }) {
167
+ return await edgeStoreRawSdk.deleteFile({
168
+ accessKey,
169
+ secretKey,
170
+ url,
171
+ });
172
+ },
173
+ async listFiles(params) {
174
+ return await edgeStoreRawSdk.listFiles({
175
+ accessKey,
176
+ secretKey,
177
+ ...params,
178
+ });
179
+ },
180
+ };
181
+ }
182
+
183
+ export { EdgeStoreCredentialsError as E, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
@@ -0,0 +1,183 @@
1
+ const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
2
+ This can happen if you are trying to use the vanilla client in your frontend.
3
+ The vanilla client should only be used in the backend.`;
4
+ class EdgeStoreCredentialsError extends Error {
5
+ constructor(message = DEFAULT_MESSAGE){
6
+ super(message);
7
+ this.name = 'EdgeStoreCredentialsError';
8
+ }
9
+ }
10
+
11
+ const API_ENDPOINT = process.env.EDGE_STORE_API_ENDPOINT ?? 'https://api.edge-store.com';
12
+ async function makeRequest(params) {
13
+ const { body, accessKey, secretKey, path } = params;
14
+ const res = await fetch(`${API_ENDPOINT}${path}`, {
15
+ method: 'POST',
16
+ body: JSON.stringify(body),
17
+ headers: {
18
+ 'Content-Type': 'application/json',
19
+ Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`
20
+ }
21
+ });
22
+ if (!res.ok) {
23
+ throw new Error(`Failed to make request to ${path}`);
24
+ }
25
+ return await res.json();
26
+ }
27
+ const edgeStoreRawSdk = {
28
+ async getToken (params) {
29
+ const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket])=>{
30
+ acc[bucketName] = {
31
+ path: bucket._def.path.map((p)=>{
32
+ const paramEntries = Object.entries(p);
33
+ if (paramEntries[0] === undefined) {
34
+ throw new Error('Missing path param');
35
+ }
36
+ const [key, value] = paramEntries[0];
37
+ return {
38
+ key,
39
+ value: value()
40
+ };
41
+ }),
42
+ accessControl: bucket._def.accessControl
43
+ };
44
+ return acc;
45
+ }, {});
46
+ const { token } = await makeRequest({
47
+ body: {
48
+ ctx: params.ctx,
49
+ buckets: reqBuckets
50
+ },
51
+ accessKey: params.accessKey,
52
+ secretKey: params.secretKey,
53
+ path: '/get-token'
54
+ });
55
+ return token;
56
+ },
57
+ async getFile ({ accessKey, secretKey, url }) {
58
+ return await makeRequest({
59
+ path: '/get-file',
60
+ accessKey,
61
+ secretKey,
62
+ body: {
63
+ url
64
+ }
65
+ });
66
+ },
67
+ async requestUpload ({ accessKey, secretKey, bucketName, bucketType, fileInfo, multipart }) {
68
+ const res = await makeRequest({
69
+ path: '/request-upload',
70
+ accessKey,
71
+ secretKey,
72
+ body: {
73
+ multipart,
74
+ bucketName,
75
+ bucketType,
76
+ isPublic: fileInfo.isPublic,
77
+ path: fileInfo.path,
78
+ extension: fileInfo.extension,
79
+ size: fileInfo.size,
80
+ metadata: fileInfo.metadata,
81
+ replaceTargetUrl: fileInfo.replaceTargetUrl
82
+ }
83
+ });
84
+ return {
85
+ multipart: res.multipart,
86
+ signedUrl: res.signedUrl,
87
+ accessUrl: res.url
88
+ };
89
+ },
90
+ async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
91
+ const res = await makeRequest({
92
+ path: '/request-upload-parts',
93
+ accessKey,
94
+ secretKey,
95
+ body: {
96
+ multipart,
97
+ key
98
+ }
99
+ });
100
+ return {
101
+ multipart: res.multipart
102
+ };
103
+ },
104
+ async deleteFile ({ accessKey, secretKey, url }) {
105
+ return await makeRequest({
106
+ path: '/delete-file',
107
+ accessKey,
108
+ secretKey,
109
+ body: {
110
+ url
111
+ }
112
+ });
113
+ },
114
+ async listFiles ({ accessKey, secretKey, bucketName, filter, pagination }) {
115
+ return await makeRequest({
116
+ path: '/list-files',
117
+ accessKey,
118
+ secretKey,
119
+ body: {
120
+ bucketName,
121
+ filter,
122
+ pagination
123
+ }
124
+ });
125
+ }
126
+ };
127
+ function initEdgeStoreSdk(params) {
128
+ const { accessKey = process.env.EDGE_STORE_ACCESS_KEY, secretKey = process.env.EDGE_STORE_SECRET_KEY } = params ?? {};
129
+ if (!accessKey || !secretKey) {
130
+ throw new EdgeStoreCredentialsError();
131
+ }
132
+ return {
133
+ async getToken (params) {
134
+ return await edgeStoreRawSdk.getToken({
135
+ accessKey,
136
+ secretKey,
137
+ ctx: params.ctx,
138
+ router: params.router
139
+ });
140
+ },
141
+ async getFile ({ url }) {
142
+ return await edgeStoreRawSdk.getFile({
143
+ accessKey,
144
+ secretKey,
145
+ url
146
+ });
147
+ },
148
+ async requestUpload ({ bucketName, bucketType, fileInfo, multipart }) {
149
+ return await edgeStoreRawSdk.requestUpload({
150
+ accessKey,
151
+ secretKey,
152
+ bucketName,
153
+ bucketType,
154
+ fileInfo,
155
+ multipart
156
+ });
157
+ },
158
+ async requestUploadParts ({ key, multipart }) {
159
+ return await edgeStoreRawSdk.requestUploadParts({
160
+ accessKey,
161
+ secretKey,
162
+ key,
163
+ multipart
164
+ });
165
+ },
166
+ async deleteFile ({ url }) {
167
+ return await edgeStoreRawSdk.deleteFile({
168
+ accessKey,
169
+ secretKey,
170
+ url
171
+ });
172
+ },
173
+ async listFiles (params) {
174
+ return await edgeStoreRawSdk.listFiles({
175
+ accessKey,
176
+ secretKey,
177
+ ...params
178
+ });
179
+ }
180
+ };
181
+ }
182
+
183
+ export { EdgeStoreCredentialsError as E, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
@@ -0,0 +1,2 @@
1
+ export { initEdgeStore } from './core/internals/bucketBuilder';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC"}