@edgestore/server 1.0.0-next.0 → 1.0.0-next.1

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 (115) hide show
  1. package/README.md +10 -4
  2. package/dist/adapters/astro/index.d.ts +7 -12
  3. package/dist/adapters/astro/index.d.ts.map +1 -1
  4. package/dist/adapters/astro/index.js +14 -161
  5. package/dist/adapters/dispatcher.d.ts +30 -0
  6. package/dist/adapters/dispatcher.d.ts.map +1 -0
  7. package/dist/adapters/dispatcher.js +172 -0
  8. package/dist/adapters/express/index.d.ts +7 -12
  9. package/dist/adapters/express/index.d.ts.map +1 -1
  10. package/dist/adapters/express/index.js +24 -94
  11. package/dist/adapters/fastify/index.d.ts +7 -12
  12. package/dist/adapters/fastify/index.d.ts.map +1 -1
  13. package/dist/adapters/fastify/index.js +23 -121
  14. package/dist/adapters/hono/index.d.ts +7 -12
  15. package/dist/adapters/hono/index.d.ts.map +1 -1
  16. package/dist/adapters/hono/index.js +14 -121
  17. package/dist/adapters/next/app/index.d.ts +7 -12
  18. package/dist/adapters/next/app/index.d.ts.map +1 -1
  19. package/dist/adapters/next/app/index.js +21 -148
  20. package/dist/adapters/next/pages/index.d.ts +7 -12
  21. package/dist/adapters/next/pages/index.d.ts.map +1 -1
  22. package/dist/adapters/next/pages/index.js +34 -95
  23. package/dist/adapters/remix/index.d.ts +7 -12
  24. package/dist/adapters/remix/index.d.ts.map +1 -1
  25. package/dist/adapters/remix/index.js +14 -136
  26. package/dist/adapters/shared.d.ts +140 -55
  27. package/dist/adapters/shared.d.ts.map +1 -1
  28. package/dist/adapters/shared.js +188 -179
  29. package/dist/adapters/start/index.d.ts +7 -12
  30. package/dist/adapters/start/index.d.ts.map +1 -1
  31. package/dist/adapters/start/index.js +14 -169
  32. package/dist/core/client/bucketClient.d.ts +7 -0
  33. package/dist/core/client/bucketClient.d.ts.map +1 -0
  34. package/dist/core/client/bucketClient.js +312 -0
  35. package/dist/core/client/index.d.ts +119 -140
  36. package/dist/core/client/index.d.ts.map +1 -1
  37. package/dist/core/client/index.js +13 -218
  38. package/dist/core/index.d.ts +20 -1
  39. package/dist/core/index.d.ts.map +1 -1
  40. package/dist/core/index.js +14 -2
  41. package/dist/core/provider.d.ts +15 -0
  42. package/dist/core/provider.d.ts.map +1 -0
  43. package/dist/core/provider.js +25 -0
  44. package/dist/core/routerRules.d.ts +21 -0
  45. package/dist/core/routerRules.d.ts.map +1 -0
  46. package/dist/core/routerRules.js +54 -0
  47. package/dist/core/validateFile.d.ts +9 -0
  48. package/dist/core/validateFile.d.ts.map +1 -0
  49. package/dist/core/validateFile.js +43 -0
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +3 -0
  53. package/dist/libs/env.d.ts +3 -0
  54. package/dist/libs/env.d.ts.map +1 -0
  55. package/dist/libs/env.js +14 -0
  56. package/dist/libs/logger.d.ts +2 -1
  57. package/dist/libs/logger.d.ts.map +1 -1
  58. package/dist/libs/logger.js +1 -1
  59. package/dist/providers/azure-blob/index.d.ts +119 -0
  60. package/dist/providers/azure-blob/index.d.ts.map +1 -0
  61. package/dist/providers/azure-blob/index.js +166 -0
  62. package/dist/providers/edgestore/index.d.ts +171 -3
  63. package/dist/providers/edgestore/index.d.ts.map +1 -1
  64. package/dist/providers/edgestore/index.js +304 -136
  65. package/dist/providers/{aws → s3}/index.d.ts +68 -11
  66. package/dist/providers/s3/index.d.ts.map +1 -0
  67. package/dist/providers/s3/index.js +146 -0
  68. package/dist/test-utils/edgestoreSmoke.d.ts +0 -2
  69. package/dist/test-utils/edgestoreSmoke.d.ts.map +1 -1
  70. package/dist/version.d.ts +1 -1
  71. package/package.json +13 -12
  72. package/providers/azure-blob/index.d.ts +1 -0
  73. package/providers/azure-blob/index.js +1 -0
  74. package/providers/s3/index.d.ts +1 -0
  75. package/providers/s3/index.js +1 -0
  76. package/src/adapters/astro/index.ts +27 -211
  77. package/src/adapters/dispatcher.ts +261 -0
  78. package/src/adapters/express/index.ts +43 -149
  79. package/src/adapters/fastify/index.ts +43 -191
  80. package/src/adapters/hono/index.ts +28 -183
  81. package/src/adapters/next/app/index.ts +37 -201
  82. package/src/adapters/next/pages/index.ts +55 -156
  83. package/src/adapters/remix/index.ts +27 -190
  84. package/src/adapters/shared.ts +237 -261
  85. package/src/adapters/start/index.ts +28 -200
  86. package/src/core/client/bucketClient.ts +480 -0
  87. package/src/core/client/index.ts +300 -427
  88. package/src/core/index.ts +42 -1
  89. package/src/core/provider.ts +80 -0
  90. package/src/core/routerRules.ts +75 -0
  91. package/src/core/validateFile.ts +50 -0
  92. package/src/index.ts +10 -0
  93. package/src/libs/env.ts +16 -0
  94. package/src/libs/logger.ts +4 -2
  95. package/src/providers/azure-blob/index.ts +265 -0
  96. package/src/providers/edgestore/index.ts +426 -154
  97. package/src/providers/s3/index.ts +289 -0
  98. package/src/test-utils/edgestoreSmoke.ts +0 -11
  99. package/src/version.ts +1 -1
  100. package/dist/core/sdk/index.d.ts +0 -282
  101. package/dist/core/sdk/index.d.ts.map +0 -1
  102. package/dist/core/sdk/index.js +0 -253
  103. package/dist/providers/aws/index.d.ts.map +0 -1
  104. package/dist/providers/aws/index.js +0 -102
  105. package/dist/providers/azure/index.d.ts +0 -39
  106. package/dist/providers/azure/index.d.ts.map +0 -1
  107. package/dist/providers/azure/index.js +0 -84
  108. package/dist/version.js +0 -4
  109. package/providers/aws/index.d.ts +0 -1
  110. package/providers/aws/index.js +0 -1
  111. package/providers/azure/index.d.ts +0 -1
  112. package/providers/azure/index.js +0 -1
  113. package/src/core/sdk/index.ts +0 -542
  114. package/src/providers/aws/index.ts +0 -239
  115. package/src/providers/azure/index.ts +0 -141
@@ -1,239 +0,0 @@
1
- import {
2
- DeleteObjectCommand,
3
- HeadObjectCommand,
4
- PutObjectCommand,
5
- S3Client,
6
- type S3ClientConfig,
7
- } from '@aws-sdk/client-s3';
8
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
9
- import {
10
- type Provider as EdgeStoreProvider,
11
- type MaybePromise,
12
- type RequestUploadParams,
13
- } from '@edgestore/shared';
14
- import { getEnv } from '../../adapters/shared';
15
-
16
- // FileInfo type as received by the provider's requestUpload, part of RequestUploadParams
17
- type ProviderUploadedFileInfo = RequestUploadParams['fileInfo'];
18
-
19
- export type AWSOverwritePathFnArgs = {
20
- /* EdgeStore bucket name */
21
- esBucketName: string;
22
- /* File info after path generation and metadata by EdgeStore */
23
- fileInfo: ProviderUploadedFileInfo;
24
- /* The S3 key that would be generated by default by this provider */
25
- defaultAccessPath: string;
26
- };
27
-
28
- export type AWSOverwritePathFn = (
29
- args: AWSOverwritePathFnArgs,
30
- ) => MaybePromise<string>;
31
-
32
- export type AWSProviderOptions = {
33
- /**
34
- * AWS SDK credentials (or credentials provider) to use for S3 requests.
35
- *
36
- * If unset, the AWS SDK will use its default credential provider chain
37
- * (environment variables, shared config files, instance/task roles, etc).
38
- */
39
- credentials?: S3ClientConfig['credentials'];
40
- /**
41
- * Access key for AWS credentials.
42
- * Can also be set via the `ES_AWS_ACCESS_KEY_ID` environment variable.
43
- *
44
- * If unset, the SDK will attempt to use the default credentials provider chain.
45
- *
46
- * @deprecated Pass `credentials` instead.
47
- */
48
- accessKeyId?: string;
49
- /**
50
- * Secret access key for AWS credentials.
51
- * Can also be set via the `ES_AWS_SECRET_ACCESS_KEY` environment variable.
52
- *
53
- * If unset, the SDK will attempt to use the default credentials provider chain.
54
- *
55
- * @deprecated Pass `credentials` instead.
56
- */
57
- secretAccessKey?: string;
58
- /**
59
- * AWS region to use.
60
- * Can also be set via the `ES_AWS_REGION` environment variable.
61
- */
62
- region?: string;
63
- /**
64
- * Name of the S3 bucket to use.
65
- * Can also be set via the `ES_AWS_BUCKET_NAME` environment variable.
66
- */
67
- bucketName?: string;
68
- /**
69
- * Custom endpoint for S3-compatible storage providers (e.g., MinIO).
70
- * Can also be set via the `ES_AWS_ENDPOINT` environment variable.
71
- */
72
- endpoint?: string;
73
- /**
74
- * Force path style for S3-compatible storage providers.
75
- * Can also be set via the `ES_AWS_FORCE_PATH_STYLE` environment variable.
76
- * Defaults to false for AWS S3, but should be true for most S3-compatible providers.
77
- */
78
- forcePathStyle?: boolean;
79
- /**
80
- * Base URL to use for accessing files.
81
- * Only needed if you are using a custom domain or cloudfront.
82
- *
83
- * It can also be set via the `EDGE_STORE_BASE_URL` environment variable.
84
- */
85
- baseUrl?: string;
86
- /**
87
- * Secret to use for encrypting JWT tokens.
88
- * Can be generated with `openssl rand -base64 32`.
89
- *
90
- * It can also be set via the `EDGE_STORE_JWT_SECRET` environment variable.
91
- */
92
- jwtSecret?: string;
93
- /**
94
- * Optional function to overwrite the S3 key (object path) for uploads.
95
- * This function receives the EdgeStore bucket name, fileInfo and the default S3 key
96
- * and should return the desired S3 key string.
97
- */
98
- overwritePath?: AWSOverwritePathFn;
99
- };
100
-
101
- export function AWSProvider(options?: AWSProviderOptions): EdgeStoreProvider {
102
- const {
103
- credentials: credentialsFromOptions,
104
- accessKeyId = getEnv('ES_AWS_ACCESS_KEY_ID'),
105
- secretAccessKey = getEnv('ES_AWS_SECRET_ACCESS_KEY'),
106
- region = getEnv('ES_AWS_REGION'),
107
- bucketName = getEnv('ES_AWS_BUCKET_NAME'),
108
- endpoint = getEnv('ES_AWS_ENDPOINT'),
109
- forcePathStyle = getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true',
110
- overwritePath,
111
- } = options ?? {};
112
-
113
- const baseUrl =
114
- options?.baseUrl ??
115
- getEnv('EDGE_STORE_BASE_URL') ??
116
- (endpoint
117
- ? `${endpoint}/${bucketName}`
118
- : `https://${bucketName}.s3.${region}.amazonaws.com`);
119
-
120
- const credentials =
121
- credentialsFromOptions ??
122
- (accessKeyId && secretAccessKey
123
- ? {
124
- accessKeyId,
125
- secretAccessKey,
126
- }
127
- : undefined);
128
- const s3Client = new S3Client({
129
- region,
130
- credentials,
131
- endpoint,
132
- forcePathStyle,
133
- });
134
-
135
- return {
136
- name: 'aws',
137
- async init() {
138
- return {};
139
- },
140
- getBaseUrl() {
141
- return baseUrl;
142
- },
143
- async getFile({ url }) {
144
- const path = url.replace(`${baseUrl}/`, '');
145
- const { ContentLength, LastModified } = await s3Client.send(
146
- new HeadObjectCommand({
147
- Bucket: bucketName,
148
- Key: path,
149
- }),
150
- );
151
-
152
- if (!ContentLength || !LastModified) {
153
- throw new Error('File not found');
154
- }
155
-
156
- return {
157
- url,
158
- metadata: {},
159
- path: {},
160
- size: ContentLength,
161
- uploadedAt: LastModified,
162
- };
163
- },
164
- async requestUpload(params: RequestUploadParams) {
165
- const { bucketName: esBucketName, fileInfo } = params;
166
-
167
- if (!bucketName) {
168
- throw new Error(
169
- 'S3 bucketName is not configured in AWSProviderOptions.',
170
- );
171
- }
172
-
173
- // Default S3 key (accessPath) construction logic
174
- const pathPrefix = `${esBucketName}${
175
- fileInfo.isPublic ? '/_public' : ''
176
- }`;
177
- const extension = fileInfo.extension
178
- ? `.${fileInfo.extension.replace('.', '')}`
179
- : '';
180
- const defaultResolvedFileName =
181
- fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`;
182
- const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item) => {
183
- return `${acc}/${item.value}`;
184
- }, '');
185
-
186
- let accessPath = `${pathPrefix}${defaultFilePathFromMetadata}/${defaultResolvedFileName}`;
187
-
188
- if (overwritePath) {
189
- accessPath = await overwritePath({
190
- esBucketName,
191
- fileInfo,
192
- defaultAccessPath: accessPath,
193
- });
194
- }
195
- accessPath = accessPath.replace(/^\/+/, '');
196
-
197
- const command = new PutObjectCommand({
198
- Bucket: bucketName,
199
- Key: accessPath,
200
- });
201
-
202
- const signedUrl = await getSignedUrl(s3Client, command, {
203
- expiresIn: 60 * 60, // 1 hour
204
- });
205
-
206
- const finalAccessUrl = `${baseUrl}/${accessPath}`;
207
- return {
208
- uploadUrl: signedUrl,
209
- accessUrl: finalAccessUrl,
210
- };
211
- },
212
- async requestUploadParts() {
213
- throw new Error('Not implemented');
214
- },
215
- async completeMultipartUpload() {
216
- throw new Error('Not implemented');
217
- },
218
- async confirmUpload() {
219
- throw new Error('Not implemented');
220
- },
221
- async deleteFile({ url }) {
222
- if (!bucketName) {
223
- throw new Error(
224
- 'S3 bucketName is not configured in AWSProviderOptions for deleteFile.',
225
- );
226
- }
227
- const path = url.replace(`${baseUrl}/`, '');
228
- await s3Client.send(
229
- new DeleteObjectCommand({
230
- Bucket: bucketName,
231
- Key: path,
232
- }),
233
- );
234
- return {
235
- success: true,
236
- };
237
- },
238
- };
239
- }
@@ -1,141 +0,0 @@
1
- import { BlobServiceClient } from '@azure/storage-blob';
2
- import { type Provider } from '@edgestore/shared';
3
- import { getEnv } from '../../adapters/shared';
4
-
5
- /**
6
- * Options for the Azure provider. Compatible with Azure Blob Storage and Azurite.
7
- * Use Azure Storage Explorer for local development with Azurite.
8
- * @see https://azure.microsoft.com/de-de/products/storage/storage-explorer
9
- * @category Providers
10
- * @example
11
- * AzureProvider({
12
- * storageAccountName: 'devstoreaccount1',
13
- * sasToken: 'some-generated-token-from-azure-storage-explorer',
14
- * containerName: 'some-container-name',
15
- * customBaseUrl: 'http://localhost:10000/devstoreaccount1',
16
- * })
17
- */
18
- export type AzureProviderOptions = {
19
- /**
20
- * The storage account name for Azure Blob Storage
21
- * Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
22
- */
23
- storageAccountName?: string;
24
- /**
25
- * SAS token for Azure Blob Storage
26
- * Can also be set via the `ES_AZURE_SAS_TOKEN` environment variable.
27
- */
28
- sasToken?: string;
29
- /**
30
- * Azure Blob Storage container name
31
- * Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
32
- */
33
- containerName?: string;
34
- /**
35
- * Optional base URL for the Azure Blob Storage.
36
- * Useful for local development with Azurite. For example: `http://localhost:10000/devstoreaccount1`
37
- * Can also be set via the `ES_AZURE_BASE_URL` environment variable.
38
- */
39
- customBaseUrl?: string;
40
- };
41
-
42
- export function AzureProvider(options?: AzureProviderOptions): Provider {
43
- const {
44
- storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'),
45
- sasToken = getEnv('ES_AZURE_SAS_TOKEN'),
46
- containerName = getEnv('ES_AZURE_CONTAINER_NAME'),
47
- customBaseUrl = getEnv('ES_AZURE_BASE_URL'),
48
- } = options ?? {};
49
-
50
- const baseUrl =
51
- customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
52
- const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
53
- const containerClient = blobServiceClient.getContainerClient(
54
- containerName ?? '',
55
- );
56
- function getBlobNameFromUrl(url: string) {
57
- try {
58
- const blobUrl = new URL(url);
59
- const containerUrl = new URL(containerClient.url);
60
- const containerPath = containerUrl.pathname.replace(/\/$/, '');
61
-
62
- if (blobUrl.origin !== containerUrl.origin) {
63
- return url;
64
- }
65
-
66
- if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
67
- return url;
68
- }
69
-
70
- return decodeURIComponent(
71
- blobUrl.pathname.slice(containerPath.length + 1),
72
- );
73
- } catch {
74
- return url;
75
- }
76
- }
77
-
78
- function getBlobName(params: Parameters<Provider['requestUpload']>[0]) {
79
- const { bucketName: esBucketName, fileInfo } = params;
80
- const extension = fileInfo.extension
81
- ? `.${fileInfo.extension.replace('.', '')}`
82
- : '';
83
- const fileName = fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`;
84
-
85
- return [
86
- esBucketName,
87
- ...(fileInfo.isPublic ? ['_public'] : []),
88
- ...fileInfo.path.map((item) => item.value),
89
- fileName,
90
- ].join('/');
91
- }
92
-
93
- return {
94
- name: 'azure',
95
- async init() {
96
- return {};
97
- },
98
- getBaseUrl() {
99
- return baseUrl;
100
- },
101
- async getFile({ url }) {
102
- const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
103
-
104
- const { contentLength, lastModified } = await blobClient.getProperties();
105
-
106
- return {
107
- url: url,
108
- metadata: {},
109
- path: {},
110
- size: contentLength ?? 0,
111
- uploadedAt: lastModified ?? new Date(),
112
- };
113
- },
114
- async requestUpload(params) {
115
- const blobClient = containerClient.getBlobClient(getBlobName(params));
116
-
117
- const url = blobClient.url;
118
-
119
- return {
120
- uploadUrl: url,
121
- accessUrl: url,
122
- };
123
- },
124
- async requestUploadParts() {
125
- throw new Error('Not implemented');
126
- },
127
- async completeMultipartUpload() {
128
- throw new Error('Not implemented');
129
- },
130
- async confirmUpload() {
131
- throw new Error('Not implemented');
132
- },
133
- async deleteFile({ url }) {
134
- const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
135
- await blobClient.delete();
136
- return {
137
- success: true,
138
- };
139
- },
140
- };
141
- }