@edgestore/server 0.1.5-alpha.2 → 0.1.5-alpha.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.
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/providers/azure/index.d.ts +20 -0
- package/dist/providers/azure/index.d.ts.map +1 -0
- package/dist/providers/azure/index.js +61 -0
- package/dist/providers/azure/index.mjs +57 -0
- package/package.json +12 -2
- package/providers/azure/index.d.ts +1 -0
- package/providers/azure/index.js +1 -0
- package/src/adapters/shared.ts +1 -0
- package/src/providers/azure/index.ts +89 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/adapters/shared.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAMnD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE;IACvC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,GAAG,EAAE,IAAI,CAAC;CACX;;;;GA4BA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE;IAChD,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC,IAA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|
+
* Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
|
|
6
|
+
*/
|
|
7
|
+
storageAccountName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* SAS token for Azure Blob Storage
|
|
10
|
+
* Can also be set via the `ES_AZURE_SAS_TOKEN` environment variable.
|
|
11
|
+
*/
|
|
12
|
+
sasToken?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Azure Blob Storage container name
|
|
15
|
+
* Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
|
|
16
|
+
*/
|
|
17
|
+
containerName?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function AzureProvider(options?: AzureProviderOptions): Provider;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var storageBlob = require('@azure/storage-blob');
|
|
6
|
+
var uuid = require('uuid');
|
|
7
|
+
|
|
8
|
+
function AzureProvider(options) {
|
|
9
|
+
const { storageAccountName = process.env.ES_AZURE_ACCOUNT_NAME, sasToken = process.env.ES_AZURE_SAS_TOKEN, containerName = process.env.ES_AZURE_CONTAINER_NAME } = options ?? {};
|
|
10
|
+
const baseUrl = `https://${storageAccountName}.blob.core.windows.net`;
|
|
11
|
+
const blobServiceClient = new storageBlob.BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
12
|
+
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
13
|
+
return {
|
|
14
|
+
async init () {
|
|
15
|
+
return {};
|
|
16
|
+
},
|
|
17
|
+
getBaseUrl () {
|
|
18
|
+
return baseUrl;
|
|
19
|
+
},
|
|
20
|
+
async getFile ({ url }) {
|
|
21
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
22
|
+
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
23
|
+
return {
|
|
24
|
+
url: url,
|
|
25
|
+
metadata: {},
|
|
26
|
+
path: {},
|
|
27
|
+
size: contentLength ?? 0,
|
|
28
|
+
uploadedAt: lastModified ?? new Date()
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
async requestUpload ({ fileInfo }) {
|
|
32
|
+
const nameId = uuid.v4();
|
|
33
|
+
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
34
|
+
const fileName = fileInfo.fileName ?? `${nameId}${extension}`;
|
|
35
|
+
const blobClient = containerClient.getBlobClient(fileName);
|
|
36
|
+
const url = blobClient.url;
|
|
37
|
+
return {
|
|
38
|
+
uploadUrl: url,
|
|
39
|
+
accessUrl: url
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
async requestUploadParts () {
|
|
43
|
+
throw new Error('Not implemented');
|
|
44
|
+
},
|
|
45
|
+
async completeMultipartUpload () {
|
|
46
|
+
throw new Error('Not implemented');
|
|
47
|
+
},
|
|
48
|
+
async confirmUpload () {
|
|
49
|
+
throw new Error('Not implemented');
|
|
50
|
+
},
|
|
51
|
+
async deleteFile ({ url }) {
|
|
52
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
53
|
+
await blobClient.delete();
|
|
54
|
+
return {
|
|
55
|
+
success: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.AzureProvider = AzureProvider;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
+
import { v4 } from 'uuid';
|
|
3
|
+
|
|
4
|
+
function AzureProvider(options) {
|
|
5
|
+
const { storageAccountName = process.env.ES_AZURE_ACCOUNT_NAME, sasToken = process.env.ES_AZURE_SAS_TOKEN, containerName = process.env.ES_AZURE_CONTAINER_NAME } = options ?? {};
|
|
6
|
+
const baseUrl = `https://${storageAccountName}.blob.core.windows.net`;
|
|
7
|
+
const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
8
|
+
const containerClient = blobServiceClient.getContainerClient(containerName ?? '');
|
|
9
|
+
return {
|
|
10
|
+
async init () {
|
|
11
|
+
return {};
|
|
12
|
+
},
|
|
13
|
+
getBaseUrl () {
|
|
14
|
+
return baseUrl;
|
|
15
|
+
},
|
|
16
|
+
async getFile ({ url }) {
|
|
17
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
18
|
+
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
19
|
+
return {
|
|
20
|
+
url: url,
|
|
21
|
+
metadata: {},
|
|
22
|
+
path: {},
|
|
23
|
+
size: contentLength ?? 0,
|
|
24
|
+
uploadedAt: lastModified ?? new Date()
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
async requestUpload ({ fileInfo }) {
|
|
28
|
+
const nameId = v4();
|
|
29
|
+
const extension = fileInfo.extension ? `.${fileInfo.extension.replace('.', '')}` : '';
|
|
30
|
+
const fileName = fileInfo.fileName ?? `${nameId}${extension}`;
|
|
31
|
+
const blobClient = containerClient.getBlobClient(fileName);
|
|
32
|
+
const url = blobClient.url;
|
|
33
|
+
return {
|
|
34
|
+
uploadUrl: url,
|
|
35
|
+
accessUrl: url
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
async requestUploadParts () {
|
|
39
|
+
throw new Error('Not implemented');
|
|
40
|
+
},
|
|
41
|
+
async completeMultipartUpload () {
|
|
42
|
+
throw new Error('Not implemented');
|
|
43
|
+
},
|
|
44
|
+
async confirmUpload () {
|
|
45
|
+
throw new Error('Not implemented');
|
|
46
|
+
},
|
|
47
|
+
async deleteFile ({ url }) {
|
|
48
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
49
|
+
await blobClient.delete();
|
|
50
|
+
return {
|
|
51
|
+
success: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { AzureProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgestore/server",
|
|
3
|
-
"version": "0.1.5-alpha.
|
|
3
|
+
"version": "0.1.5-alpha.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",
|
|
@@ -57,6 +57,11 @@
|
|
|
57
57
|
"require": "./dist/providers/aws/index.js",
|
|
58
58
|
"default": "./dist/providers/aws/index.js"
|
|
59
59
|
},
|
|
60
|
+
"./providers/azure": {
|
|
61
|
+
"import": "./dist/providers/azure/index.mjs",
|
|
62
|
+
"require": "./dist/providers/azure/index.js",
|
|
63
|
+
"default": "./dist/providers/azure/index.js"
|
|
64
|
+
},
|
|
60
65
|
"./providers/edgestore": {
|
|
61
66
|
"import": "./dist/providers/edgestore/index.mjs",
|
|
62
67
|
"require": "./dist/providers/edgestore/index.js",
|
|
@@ -92,6 +97,7 @@
|
|
|
92
97
|
"peerDependencies": {
|
|
93
98
|
"@aws-sdk/client-s3": ">=3.0.0",
|
|
94
99
|
"@aws-sdk/s3-request-presigner": ">=3.0.0",
|
|
100
|
+
"@azure/storage-blob": "^12.17.0",
|
|
95
101
|
"zod": ">=3.0.0"
|
|
96
102
|
},
|
|
97
103
|
"peerDependenciesMeta": {
|
|
@@ -103,11 +109,15 @@
|
|
|
103
109
|
},
|
|
104
110
|
"@aws-sdk/s3-request-presigner": {
|
|
105
111
|
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"@azure/storage-blob": {
|
|
114
|
+
"optional": true
|
|
106
115
|
}
|
|
107
116
|
},
|
|
108
117
|
"devDependencies": {
|
|
109
118
|
"@aws-sdk/client-s3": "^3.420.0",
|
|
110
119
|
"@aws-sdk/s3-request-presigner": "^3.420.0",
|
|
120
|
+
"@azure/storage-blob": "^12.17.0",
|
|
111
121
|
"@types/cookie": "^0.5.1",
|
|
112
122
|
"@types/node": "^18.11.18",
|
|
113
123
|
"@types/uuid": "^9.0.1",
|
|
@@ -117,5 +127,5 @@
|
|
|
117
127
|
"typescript": "^5.1.6",
|
|
118
128
|
"zod": "^3.21.4"
|
|
119
129
|
},
|
|
120
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "ae79c8b36dd3969ae3c0c3d5b8294961faf9e497"
|
|
121
131
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/providers/azure';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/providers/azure');
|
package/src/adapters/shared.ts
CHANGED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { type Provider } from '../types';
|
|
4
|
+
|
|
5
|
+
export type AzureProviderOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* The storage account name for Azure Blob Storage
|
|
8
|
+
* Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
|
|
9
|
+
*/
|
|
10
|
+
storageAccountName?: string;
|
|
11
|
+
/**
|
|
12
|
+
* SAS token for Azure Blob Storage
|
|
13
|
+
* Can also be set via the `ES_AZURE_SAS_TOKEN` environment variable.
|
|
14
|
+
*/
|
|
15
|
+
sasToken?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Azure Blob Storage container name
|
|
18
|
+
* Can also be set via the `ES_AZURE_CONTAINER_NAME` environment variable.
|
|
19
|
+
*/
|
|
20
|
+
containerName?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function AzureProvider(options?: AzureProviderOptions): Provider {
|
|
24
|
+
const {
|
|
25
|
+
storageAccountName = process.env.ES_AZURE_ACCOUNT_NAME,
|
|
26
|
+
sasToken = process.env.ES_AZURE_SAS_TOKEN,
|
|
27
|
+
containerName = process.env.ES_AZURE_CONTAINER_NAME,
|
|
28
|
+
} = options ?? {};
|
|
29
|
+
|
|
30
|
+
const baseUrl = `https://${storageAccountName}.blob.core.windows.net`;
|
|
31
|
+
const blobServiceClient = new BlobServiceClient(`${baseUrl}?${sasToken}`);
|
|
32
|
+
const containerClient = blobServiceClient.getContainerClient(
|
|
33
|
+
containerName ?? '',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
async init() {
|
|
38
|
+
return {};
|
|
39
|
+
},
|
|
40
|
+
getBaseUrl() {
|
|
41
|
+
return baseUrl;
|
|
42
|
+
},
|
|
43
|
+
async getFile({ url }) {
|
|
44
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
45
|
+
|
|
46
|
+
const { contentLength, lastModified } = await blobClient.getProperties();
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
url: url,
|
|
50
|
+
metadata: {},
|
|
51
|
+
path: {},
|
|
52
|
+
size: contentLength ?? 0,
|
|
53
|
+
uploadedAt: lastModified ?? new Date(),
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async requestUpload({ fileInfo }) {
|
|
57
|
+
const nameId = uuidv4();
|
|
58
|
+
const extension = fileInfo.extension
|
|
59
|
+
? `.${fileInfo.extension.replace('.', '')}`
|
|
60
|
+
: '';
|
|
61
|
+
const fileName = fileInfo.fileName ?? `${nameId}${extension}`;
|
|
62
|
+
|
|
63
|
+
const blobClient = containerClient.getBlobClient(fileName);
|
|
64
|
+
|
|
65
|
+
const url = blobClient.url;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
uploadUrl: url,
|
|
69
|
+
accessUrl: url,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
async requestUploadParts() {
|
|
73
|
+
throw new Error('Not implemented');
|
|
74
|
+
},
|
|
75
|
+
async completeMultipartUpload() {
|
|
76
|
+
throw new Error('Not implemented');
|
|
77
|
+
},
|
|
78
|
+
async confirmUpload() {
|
|
79
|
+
throw new Error('Not implemented');
|
|
80
|
+
},
|
|
81
|
+
async deleteFile({ url }) {
|
|
82
|
+
const blobClient = containerClient.getBlobClient(url);
|
|
83
|
+
await blobClient.delete();
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|