@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,253 +0,0 @@
1
- import { EdgeStoreError } from '@edgestore/shared';
2
- import { getEnv } from '../../adapters/shared.js';
3
- import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError.js';
4
- import { EDGE_STORE_PACKAGE_VERSION, EDGE_STORE_PACKAGE_NAME } from '../../version.js';
5
-
6
- const API_ENDPOINT = getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
7
- async function makeRequest(params) {
8
- const { body, accessKey, secretKey, path } = params;
9
- const res = await fetch(`${API_ENDPOINT}${path}`, {
10
- method: 'POST',
11
- body: JSON.stringify(body),
12
- headers: {
13
- 'Content-Type': 'application/json',
14
- Authorization: `Basic ${Buffer.from(`${accessKey}:${secretKey}`).toString('base64')}`,
15
- 'x-edgestore-package-name': EDGE_STORE_PACKAGE_NAME,
16
- 'x-edgestore-package-version': EDGE_STORE_PACKAGE_VERSION
17
- }
18
- });
19
- if (!res.ok) {
20
- throw new Error(`Failed to make request to ${path}: ${await res.text()}`);
21
- }
22
- return await res.json();
23
- }
24
- const edgeStoreRawSdk = {
25
- async getToken (params) {
26
- const reqBuckets = Object.entries(params.router.buckets).reduce((acc, [bucketName, bucket])=>{
27
- acc[bucketName] = {
28
- path: bucket._def.path.map((p)=>{
29
- const paramEntries = Object.entries(p);
30
- if (paramEntries[0] === undefined) {
31
- throw new EdgeStoreError({
32
- message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
33
- code: 'SERVER_ERROR'
34
- });
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, autoSignedUrls }) {
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
- mimeType: fileInfo.type,
81
- metadata: fileInfo.metadata,
82
- fileName: fileInfo.fileName,
83
- replaceTargetUrl: fileInfo.replaceTargetUrl,
84
- isTemporary: fileInfo.temporary,
85
- autoSignedUrls
86
- }
87
- });
88
- return {
89
- multipart: res.multipart,
90
- signedUrl: res.signedUrl,
91
- accessUrl: res.url,
92
- path: res.path,
93
- thumbnailUrl: res.thumbnailUrl,
94
- accessSignedUrl: res.accessSignedUrl,
95
- accessSignedThumbnailUrl: res.accessSignedThumbnailUrl,
96
- accessSignedUrlExpiresAt: res.accessSignedUrlExpiresAt,
97
- accessSignedUrlExpiresIn: res.accessSignedUrlExpiresIn
98
- };
99
- },
100
- async getSignedUrls ({ accessKey, secretKey, bucketName, urls, expiresIn, includeThumbnails }) {
101
- const res = await makeRequest({
102
- path: '/get-signed-urls',
103
- accessKey,
104
- secretKey,
105
- body: {
106
- bucketName,
107
- urls,
108
- expiresIn,
109
- includeThumbnails
110
- }
111
- });
112
- return res.signedUrls;
113
- },
114
- async requestUploadParts ({ accessKey, secretKey, key, multipart }) {
115
- const res = await makeRequest({
116
- path: '/request-upload-parts',
117
- accessKey,
118
- secretKey,
119
- body: {
120
- multipart,
121
- key
122
- }
123
- });
124
- return {
125
- multipart: res.multipart
126
- };
127
- },
128
- async completeMultipartUpload ({ accessKey, secretKey, uploadId, key, parts }) {
129
- return await makeRequest({
130
- path: '/complete-multipart-upload',
131
- accessKey,
132
- secretKey,
133
- body: {
134
- uploadId,
135
- key,
136
- parts
137
- }
138
- });
139
- },
140
- async confirmUpload ({ accessKey, secretKey, url }) {
141
- return await makeRequest({
142
- path: '/confirm-upload',
143
- accessKey,
144
- secretKey,
145
- body: {
146
- url
147
- }
148
- });
149
- },
150
- async deleteFile ({ accessKey, secretKey, url }) {
151
- return await makeRequest({
152
- path: '/delete-file',
153
- accessKey,
154
- secretKey,
155
- body: {
156
- url
157
- }
158
- });
159
- },
160
- async listFiles ({ accessKey, secretKey, bucketName, filter, pagination }) {
161
- return await makeRequest({
162
- path: '/list-files',
163
- accessKey,
164
- secretKey,
165
- body: {
166
- bucketName,
167
- filter,
168
- pagination
169
- }
170
- });
171
- }
172
- };
173
- function initEdgeStoreSdk(params) {
174
- const { accessKey = getEnv('EDGE_STORE_ACCESS_KEY'), secretKey = getEnv('EDGE_STORE_SECRET_KEY') } = params ?? {};
175
- if (!accessKey || !secretKey) {
176
- throw new EdgeStoreCredentialsError();
177
- }
178
- return {
179
- async getToken (params) {
180
- return await edgeStoreRawSdk.getToken({
181
- accessKey,
182
- secretKey,
183
- ctx: params.ctx,
184
- router: params.router
185
- });
186
- },
187
- async getFile ({ url }) {
188
- return await edgeStoreRawSdk.getFile({
189
- accessKey,
190
- secretKey,
191
- url
192
- });
193
- },
194
- async requestUpload ({ bucketName, bucketType, fileInfo, multipart, autoSignedUrls }) {
195
- return await edgeStoreRawSdk.requestUpload({
196
- accessKey,
197
- secretKey,
198
- bucketName,
199
- bucketType,
200
- fileInfo,
201
- multipart,
202
- autoSignedUrls
203
- });
204
- },
205
- async getSignedUrls (params) {
206
- return await edgeStoreRawSdk.getSignedUrls({
207
- accessKey,
208
- secretKey,
209
- ...params
210
- });
211
- },
212
- async requestUploadParts ({ key, multipart }) {
213
- return await edgeStoreRawSdk.requestUploadParts({
214
- accessKey,
215
- secretKey,
216
- key,
217
- multipart
218
- });
219
- },
220
- async completeMultipartUpload ({ uploadId, key, parts }) {
221
- return await edgeStoreRawSdk.completeMultipartUpload({
222
- accessKey,
223
- secretKey,
224
- uploadId,
225
- key,
226
- parts
227
- });
228
- },
229
- async confirmUpload ({ url }) {
230
- return await edgeStoreRawSdk.confirmUpload({
231
- accessKey,
232
- secretKey,
233
- url
234
- });
235
- },
236
- async deleteFile ({ url }) {
237
- return await edgeStoreRawSdk.deleteFile({
238
- accessKey,
239
- secretKey,
240
- url
241
- });
242
- },
243
- async listFiles (params) {
244
- return await edgeStoreRawSdk.listFiles({
245
- accessKey,
246
- secretKey,
247
- ...params
248
- });
249
- }
250
- };
251
- }
252
-
253
- export { edgeStoreRawSdk, initEdgeStoreSdk };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/aws/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,KAAK,QAAQ,IAAI,iBAAiB,EAClC,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAI3B,KAAK,wBAAwB,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAEhE,MAAM,MAAM,sBAAsB,GAAG;IAEnC,YAAY,EAAE,MAAM,CAAC;IAErB,QAAQ,EAAE,wBAAwB,CAAC;IAEnC,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,CAC/B,IAAI,EAAE,sBAAsB,KACzB,YAAY,CAAC,MAAM,CAAC,CAAC;AAE1B,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;IAC5C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,iBAAiB,CA0I3E"}
@@ -1,102 +0,0 @@
1
- import { S3Client, DeleteObjectCommand, PutObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
2
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
3
- import { getEnv } from '../../adapters/shared.js';
4
-
5
- function AWSProvider(options) {
6
- const { credentials: credentialsFromOptions, accessKeyId = getEnv('ES_AWS_ACCESS_KEY_ID'), secretAccessKey = getEnv('ES_AWS_SECRET_ACCESS_KEY'), region = getEnv('ES_AWS_REGION'), bucketName = getEnv('ES_AWS_BUCKET_NAME'), endpoint = getEnv('ES_AWS_ENDPOINT'), forcePathStyle = getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true', overwritePath } = options ?? {};
7
- const baseUrl = options?.baseUrl ?? getEnv('EDGE_STORE_BASE_URL') ?? (endpoint ? `${endpoint}/${bucketName}` : `https://${bucketName}.s3.${region}.amazonaws.com`);
8
- const credentials = credentialsFromOptions ?? (accessKeyId && secretAccessKey ? {
9
- accessKeyId,
10
- secretAccessKey
11
- } : undefined);
12
- const s3Client = new S3Client({
13
- region,
14
- credentials,
15
- endpoint,
16
- forcePathStyle
17
- });
18
- return {
19
- name: 'aws',
20
- async init () {
21
- return {};
22
- },
23
- getBaseUrl () {
24
- return baseUrl;
25
- },
26
- async getFile ({ url }) {
27
- const path = url.replace(`${baseUrl}/`, '');
28
- const { ContentLength, LastModified } = await s3Client.send(new HeadObjectCommand({
29
- Bucket: bucketName,
30
- Key: path
31
- }));
32
- if (!ContentLength || !LastModified) {
33
- throw new Error('File not found');
34
- }
35
- return {
36
- url,
37
- metadata: {},
38
- path: {},
39
- size: ContentLength,
40
- uploadedAt: LastModified
41
- };
42
- },
43
- async requestUpload (params) {
44
- const { bucketName: esBucketName, fileInfo } = params;
45
- if (!bucketName) {
46
- throw new Error('S3 bucketName is not configured in AWSProviderOptions.');
47
- }
48
- // Default S3 key (accessPath) construction logic
49
- const pathPrefix = `${esBucketName}${fileInfo.isPublic ? '/_public' : ''}`;
50
- const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
51
- const defaultResolvedFileName = fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`;
52
- const defaultFilePathFromMetadata = fileInfo.path.reduce((acc, item)=>{
53
- return `${acc}/${item.value}`;
54
- }, '');
55
- let accessPath = `${pathPrefix}${defaultFilePathFromMetadata}/${defaultResolvedFileName}`;
56
- if (overwritePath) {
57
- accessPath = await overwritePath({
58
- esBucketName,
59
- fileInfo,
60
- defaultAccessPath: accessPath
61
- });
62
- }
63
- accessPath = accessPath.replace(/^\/+/, '');
64
- const command = new PutObjectCommand({
65
- Bucket: bucketName,
66
- Key: accessPath
67
- });
68
- const signedUrl = await getSignedUrl(s3Client, command, {
69
- expiresIn: 60 * 60
70
- });
71
- const finalAccessUrl = `${baseUrl}/${accessPath}`;
72
- return {
73
- uploadUrl: signedUrl,
74
- accessUrl: finalAccessUrl
75
- };
76
- },
77
- async requestUploadParts () {
78
- throw new Error('Not implemented');
79
- },
80
- async completeMultipartUpload () {
81
- throw new Error('Not implemented');
82
- },
83
- async confirmUpload () {
84
- throw new Error('Not implemented');
85
- },
86
- async deleteFile ({ url }) {
87
- if (!bucketName) {
88
- throw new Error('S3 bucketName is not configured in AWSProviderOptions for deleteFile.');
89
- }
90
- const path = url.replace(`${baseUrl}/`, '');
91
- await s3Client.send(new DeleteObjectCommand({
92
- Bucket: bucketName,
93
- Key: path
94
- }));
95
- return {
96
- success: true
97
- };
98
- }
99
- };
100
- }
101
-
102
- export { AWSProvider };
@@ -1,39 +0,0 @@
1
- import { type Provider } from '@edgestore/shared';
2
- /**
3
- * Options for the Azure provider. Compatible with Azure Blob Storage and Azurite.
4
- * Use Azure Storage Explorer for local development with Azurite.
5
- * @see https://azure.microsoft.com/de-de/products/storage/storage-explorer
6
- * @category Providers
7
- * @example
8
- * AzureProvider({
9
- * storageAccountName: 'devstoreaccount1',
10
- * sasToken: 'some-generated-token-from-azure-storage-explorer',
11
- * containerName: 'some-container-name',
12
- * customBaseUrl: 'http://localhost:10000/devstoreaccount1',
13
- * })
14
- */
15
- export type AzureProviderOptions = {
16
- /**
17
- * The storage account name for Azure Blob Storage
18
- * Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
19
- */
20
- storageAccountName?: string;
21
- /**
22
- * SAS token for Azure Blob Storage
23
- * Can also be set via the `ES_AZURE_SAS_TOKEN` environment variable.
24
- */
25
- sasToken?: string;
26
- /**
27
- * Azure Blob Storage container name
28
- * Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
29
- */
30
- containerName?: string;
31
- /**
32
- * Optional base URL for the Azure Blob Storage.
33
- * Useful for local development with Azurite. For example: `http://localhost:10000/devstoreaccount1`
34
- * Can also be set via the `ES_AZURE_BASE_URL` environment variable.
35
- */
36
- customBaseUrl?: string;
37
- };
38
- export declare function AzureProvider(options?: AzureProviderOptions): Provider;
39
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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;;;;;;;;;;;;GAYG;AACH,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;IACvB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,QAAQ,CAmGtE"}
@@ -1,84 +0,0 @@
1
- import { BlobServiceClient } from '@azure/storage-blob';
2
- import { getEnv } from '../../adapters/shared.js';
3
-
4
- function AzureProvider(options) {
5
- const { storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'), sasToken = getEnv('ES_AZURE_SAS_TOKEN'), containerName = getEnv('ES_AZURE_CONTAINER_NAME'), customBaseUrl = getEnv('ES_AZURE_BASE_URL') } = options ?? {};
6
- const baseUrl = customBaseUrl ?? `https://${storageAccountName}.blob.core.windows.net`;
7
- const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
8
- const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
9
- function getBlobNameFromUrl(url) {
10
- try {
11
- const blobUrl = new URL(url);
12
- const containerUrl = new URL(containerClient.url);
13
- const containerPath = containerUrl.pathname.replace(/\/$/, '');
14
- if (blobUrl.origin !== containerUrl.origin) {
15
- return url;
16
- }
17
- if (!blobUrl.pathname.startsWith(`${containerPath}/`)) {
18
- return url;
19
- }
20
- return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
21
- } catch {
22
- return url;
23
- }
24
- }
25
- function getBlobName(params) {
26
- const { bucketName: esBucketName, fileInfo } = params;
27
- const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
28
- const fileName = fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`;
29
- return [
30
- esBucketName,
31
- ...fileInfo.isPublic ? [
32
- '_public'
33
- ] : [],
34
- ...fileInfo.path.map((item)=>item.value),
35
- fileName
36
- ].join('/');
37
- }
38
- return {
39
- name: 'azure',
40
- async init () {
41
- return {};
42
- },
43
- getBaseUrl () {
44
- return baseUrl;
45
- },
46
- async getFile ({ url }) {
47
- const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
48
- const { contentLength, lastModified } = await blobClient.getProperties();
49
- return {
50
- url: url,
51
- metadata: {},
52
- path: {},
53
- size: contentLength ?? 0,
54
- uploadedAt: lastModified ?? new Date()
55
- };
56
- },
57
- async requestUpload (params) {
58
- const blobClient = containerClient.getBlobClient(getBlobName(params));
59
- const url = blobClient.url;
60
- return {
61
- uploadUrl: url,
62
- accessUrl: url
63
- };
64
- },
65
- async requestUploadParts () {
66
- throw new Error('Not implemented');
67
- },
68
- async completeMultipartUpload () {
69
- throw new Error('Not implemented');
70
- },
71
- async confirmUpload () {
72
- throw new Error('Not implemented');
73
- },
74
- async deleteFile ({ url }) {
75
- const blobClient = containerClient.getBlobClient(getBlobNameFromUrl(url));
76
- await blobClient.delete();
77
- return {
78
- success: true
79
- };
80
- }
81
- };
82
- }
83
-
84
- export { AzureProvider };
package/dist/version.js DELETED
@@ -1,4 +0,0 @@
1
- const EDGE_STORE_PACKAGE_NAME = '@edgestore/server';
2
- const EDGE_STORE_PACKAGE_VERSION = '1.0.0-next.0';
3
-
4
- export { EDGE_STORE_PACKAGE_NAME, EDGE_STORE_PACKAGE_VERSION };
@@ -1 +0,0 @@
1
- export * from '../../dist/providers/aws/index.js';
@@ -1 +0,0 @@
1
- export * from '../../dist/providers/aws/index.js';
@@ -1 +0,0 @@
1
- export * from '../../dist/providers/azure/index.js';
@@ -1 +0,0 @@
1
- export * from '../../dist/providers/azure/index.js';