@edgestore/server 1.0.0-next.5 → 1.0.0-rc.6
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/agent-docs/README.md +1 -1
- package/agent-docs/astro.md +1 -1
- package/agent-docs/backend-client.md +5 -8
- package/agent-docs/express.md +1 -1
- package/agent-docs/fastify.md +1 -1
- package/agent-docs/hono.md +1 -1
- package/agent-docs/next.md +1 -1
- package/agent-docs/provider-azure-blob.md +150 -57
- package/agent-docs/provider-custom.md +17 -3
- package/agent-docs/provider-s3.md +4 -3
- package/agent-docs/remix.md +1 -1
- package/agent-docs/tanstack-start.md +1 -1
- package/dist/adapters/shared.d.ts +12 -102
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +63 -108
- package/dist/core/client/index.d.ts +0 -4
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/provider.d.ts +0 -1
- package/dist/core/provider.d.ts.map +1 -1
- package/dist/core/provider.js +1 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/providers/azure-blob/blocks.d.ts +48 -0
- package/dist/providers/azure-blob/blocks.d.ts.map +1 -0
- package/dist/providers/azure-blob/blocks.js +126 -0
- package/dist/providers/azure-blob/index.d.ts +76 -51
- package/dist/providers/azure-blob/index.d.ts.map +1 -1
- package/dist/providers/azure-blob/index.js +189 -107
- package/dist/providers/edgestore/index.d.ts +6 -22
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +19 -18
- package/dist/providers/s3/backendUpload.d.ts +2 -5
- package/dist/providers/s3/backendUpload.d.ts.map +1 -1
- package/dist/providers/s3/backendUpload.js +19 -57
- package/dist/providers/s3/index.d.ts +3 -12
- package/dist/providers/s3/index.d.ts.map +1 -1
- package/dist/providers/s3/index.js +23 -44
- package/dist/providers/s3/multipart.d.ts +3 -5
- package/dist/providers/s3/multipart.d.ts.map +1 -1
- package/dist/providers/s3/multipart.js +26 -62
- package/dist/providers/s3/options.d.ts +10 -32
- package/dist/providers/s3/options.d.ts.map +1 -1
- package/dist/providers/storage/multipartSession.d.ts +51 -0
- package/dist/providers/storage/multipartSession.d.ts.map +1 -0
- package/dist/providers/storage/multipartSession.js +83 -0
- package/dist/providers/storage/objectKeys.d.ts +41 -0
- package/dist/providers/storage/objectKeys.d.ts.map +1 -0
- package/dist/providers/{s3/keys.js → storage/objectKeys.js} +31 -4
- package/dist/providers/storage/transfer.d.ts +18 -0
- package/dist/providers/storage/transfer.d.ts.map +1 -0
- package/dist/providers/storage/transfer.js +69 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +4 -11
- package/src/adapters/shared.ts +81 -127
- package/src/core/client/index.ts +0 -4
- package/src/core/provider.ts +0 -8
- package/src/index.ts +3 -8
- package/src/providers/azure-blob/blocks.ts +201 -0
- package/src/providers/azure-blob/index.ts +289 -171
- package/src/providers/edgestore/index.ts +19 -22
- package/src/providers/s3/backendUpload.ts +20 -55
- package/src/providers/s3/index.ts +31 -58
- package/src/providers/s3/multipart.ts +36 -94
- package/src/providers/s3/options.ts +10 -33
- package/src/providers/storage/multipartSession.ts +145 -0
- package/src/providers/storage/objectKeys.ts +106 -0
- package/src/providers/storage/transfer.ts +105 -0
- package/src/version.ts +1 -1
- package/core/index.d.ts +0 -1
- package/core/index.js +0 -1
- package/dist/core/index.d.ts +0 -4
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/providers/s3/keys.d.ts +0 -10
- package/dist/providers/s3/keys.d.ts.map +0 -1
- package/src/core/index.ts +0 -9
- package/src/providers/s3/keys.ts +0 -59
|
@@ -1,91 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { MaybePromise, RequestUploadParams, RequestUploadRes } from '@edgestore/shared';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* storageAccountName: 'devstoreaccount1',
|
|
11
|
-
* storageAccountKey: 'some-account-key',
|
|
12
|
-
* containerName: 'some-container-name',
|
|
13
|
-
* customBaseUrl: 'http://localhost:10000/devstoreaccount1',
|
|
14
|
-
* })
|
|
15
|
-
*/
|
|
3
|
+
import { type ObjectPathFn, type ObjectPathFnArgs } from '../storage/objectKeys.js';
|
|
4
|
+
/** Blob settings shared by browser and backend uploads. */
|
|
5
|
+
export type AzureBlobObjectOptions = {
|
|
6
|
+
cacheControl?: string;
|
|
7
|
+
contentDisposition?: string;
|
|
8
|
+
metadata?: Record<string, string>;
|
|
9
|
+
};
|
|
16
10
|
export type AzureBlobProviderOptions = {
|
|
17
11
|
/**
|
|
18
|
-
*
|
|
19
|
-
* Can also be set via the `ES_AZURE_ACCOUNT_NAME` environment variable.
|
|
12
|
+
* Storage account name. Can also be set via `ES_AZURE_ACCOUNT_NAME`.
|
|
20
13
|
*/
|
|
21
14
|
storageAccountName?: string;
|
|
22
15
|
/**
|
|
23
|
-
* Account key used
|
|
24
|
-
*
|
|
25
|
-
* Can also be set via the `ES_AZURE_ACCOUNT_KEY` environment variable.
|
|
16
|
+
* Account key used for server-side operations and for signing short-lived,
|
|
17
|
+
* blob-scoped URLs. Can also be set via `ES_AZURE_ACCOUNT_KEY`.
|
|
26
18
|
*/
|
|
27
19
|
storageAccountKey?: string;
|
|
20
|
+
/** Container name. Can also be set via `ES_AZURE_CONTAINER_NAME`. */
|
|
21
|
+
containerName?: string;
|
|
28
22
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
23
|
+
* Blob service endpoint, for example Azurite at
|
|
24
|
+
* `http://127.0.0.1:10000/devstoreaccount1`. Defaults to
|
|
25
|
+
* `https://<account>.blob.core.windows.net`. Can also be set via
|
|
26
|
+
* `ES_AZURE_ENDPOINT`.
|
|
31
27
|
*/
|
|
32
|
-
|
|
28
|
+
endpoint?: string;
|
|
33
29
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
30
|
+
* Base URL for file URLs, such as a CDN in front of the container. Defaults
|
|
31
|
+
* to `<endpoint>/<container>`. Can also be set via `EDGE_STORE_BASE_URL`.
|
|
32
|
+
* Signed URLs always use the endpoint.
|
|
37
33
|
*/
|
|
38
|
-
|
|
34
|
+
baseUrl?: string;
|
|
39
35
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
36
|
+
* Secret used to sign multipart upload sessions. Defaults to
|
|
37
|
+
* `EDGE_STORE_JWT_SECRET` or `EDGE_STORE_SECRET_KEY`.
|
|
42
38
|
*/
|
|
43
|
-
|
|
39
|
+
jwtSecret?: string;
|
|
44
40
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
41
|
+
* Customizes the blob path beneath the logical EdgeStore bucket prefix.
|
|
42
|
+
* The logical bucket prefix is always preserved.
|
|
47
43
|
*/
|
|
44
|
+
path?: ObjectPathFn;
|
|
45
|
+
/** Blob settings shared by browser and backend uploads. */
|
|
46
|
+
objectOptions?: AzureBlobObjectOptions | ((args: ObjectPathFnArgs) => MaybePromise<AzureBlobObjectOptions>);
|
|
47
|
+
/** Upload URL lifetime in seconds. Default: 3600. */
|
|
48
|
+
uploadUrlExpiresIn?: number;
|
|
49
|
+
/** Signed read URL lifetime in seconds. Default: 3600. */
|
|
48
50
|
signedUrlExpiresIn?: number;
|
|
51
|
+
/** Automatic multipart upload configuration. */
|
|
52
|
+
multipart?: {
|
|
53
|
+
/** Size above which uploads use blocks. Default: 100 MiB. */
|
|
54
|
+
thresholdBytes?: number;
|
|
55
|
+
/** Preferred block size. Default: 16 MiB; maximum 4000 MiB. */
|
|
56
|
+
partSizeBytes?: number;
|
|
57
|
+
/**
|
|
58
|
+
* How long a browser multipart session can request URLs and complete, in
|
|
59
|
+
* seconds. Default: 86400 (24 hours).
|
|
60
|
+
*/
|
|
61
|
+
sessionExpiresIn?: number;
|
|
62
|
+
};
|
|
49
63
|
};
|
|
50
64
|
export declare function azureBlob(options?: AzureBlobProviderOptions): {
|
|
51
65
|
readonly name: "azure-blob";
|
|
52
|
-
readonly baseUrl: string;
|
|
53
66
|
readonly reference: {
|
|
54
|
-
readonly schema: z.ZodObject<{
|
|
67
|
+
readonly schema: z.ZodUnion<readonly [z.ZodObject<{
|
|
68
|
+
key: z.ZodString;
|
|
69
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
55
70
|
url: z.ZodString;
|
|
56
|
-
},
|
|
57
|
-
url: string;
|
|
58
|
-
}, {
|
|
59
|
-
url: string;
|
|
60
|
-
}>;
|
|
71
|
+
}, z.core.$strip>]>;
|
|
61
72
|
readonly fromUrl: (url: string) => {
|
|
62
73
|
url: string;
|
|
63
74
|
};
|
|
64
75
|
};
|
|
65
|
-
readonly init: () => Promise<{}>;
|
|
76
|
+
readonly init: <TCtx extends import("@edgestore/shared").AnyContext>({ router }: import("@edgestore/shared").InitParams<TCtx>) => Promise<{}>;
|
|
66
77
|
readonly uploads: {
|
|
67
78
|
readonly supportedOptions: {
|
|
68
79
|
readonly temporary: false;
|
|
69
80
|
readonly replaceTargetUrl: false;
|
|
70
81
|
};
|
|
71
|
-
readonly request: (params: RequestUploadParams) => Promise<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
readonly request: (params: RequestUploadParams) => Promise<RequestUploadRes>;
|
|
83
|
+
readonly multipart: import("@edgestore/shared").ProviderMultipartUploads;
|
|
84
|
+
readonly upload: (params: import("@edgestore/shared").BackendUploadParams) => Promise<{
|
|
85
|
+
file: {
|
|
86
|
+
key: string;
|
|
87
|
+
url: string;
|
|
88
|
+
sizeBytes: number;
|
|
89
|
+
uploadedAt: Date;
|
|
90
|
+
updatedAt: Date;
|
|
75
91
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
signedReadUrl: {
|
|
93
|
+
url: string;
|
|
94
|
+
signedUrl: string;
|
|
95
|
+
expiresAt: Date;
|
|
96
|
+
expiresIn: number;
|
|
97
|
+
} | undefined;
|
|
80
98
|
}>;
|
|
81
99
|
};
|
|
82
100
|
readonly files: {
|
|
83
101
|
readonly get: ({ bucketName, file }: {
|
|
84
102
|
bucketName: string;
|
|
85
103
|
file: {
|
|
104
|
+
key: string;
|
|
105
|
+
} | {
|
|
86
106
|
url: string;
|
|
87
107
|
};
|
|
88
108
|
}) => Promise<{
|
|
109
|
+
key: string;
|
|
89
110
|
url: string;
|
|
90
111
|
sizeBytes: number;
|
|
91
112
|
uploadedAt: Date;
|
|
@@ -93,9 +114,11 @@ export declare function azureBlob(options?: AzureBlobProviderOptions): {
|
|
|
93
114
|
}>;
|
|
94
115
|
readonly getSignedUrls: ({ bucketName, files, expiresIn }: {
|
|
95
116
|
bucketName: string;
|
|
96
|
-
files: {
|
|
117
|
+
files: ({
|
|
118
|
+
key: string;
|
|
119
|
+
} | {
|
|
97
120
|
url: string;
|
|
98
|
-
}[];
|
|
121
|
+
})[];
|
|
99
122
|
expiresIn?: number;
|
|
100
123
|
includeThumbnails?: boolean;
|
|
101
124
|
}) => Promise<{
|
|
@@ -106,9 +129,11 @@ export declare function azureBlob(options?: AzureBlobProviderOptions): {
|
|
|
106
129
|
}[]>;
|
|
107
130
|
readonly delete: ({ bucketName, files }: {
|
|
108
131
|
bucketName: string;
|
|
109
|
-
files: {
|
|
132
|
+
files: ({
|
|
133
|
+
key: string;
|
|
134
|
+
} | {
|
|
110
135
|
url: string;
|
|
111
|
-
}[];
|
|
136
|
+
})[];
|
|
112
137
|
}) => Promise<{
|
|
113
138
|
results: ({
|
|
114
139
|
success: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure-blob/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/azure-blob/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,YAAY,EAC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AUF,wBAAgB,SAAS,CAAC,OAAO,GAAE,wBAA6B;;;;;;;;;;;;;;;;;;2DA4JnC,OAAO,CAAC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwGrD"}
|
|
@@ -1,90 +1,130 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateBlobSASQueryParameters, SASProtocol, BlobSASPermissions, StorageSharedKeyCredential, BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
+
import { planMultipartUpload } from '@edgestore/sdk';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { defineProvider } from '../../core/provider.js';
|
|
4
5
|
import { getEnv } from '../../libs/env.js';
|
|
6
|
+
import { createMultipartSessions } from '../storage/multipartSession.js';
|
|
7
|
+
import { createObjectKeys } from '../storage/objectKeys.js';
|
|
8
|
+
import { runConcurrently, assertSignedUrlAccessControl, signedUrlLifetime } from '../storage/transfer.js';
|
|
9
|
+
import { createBlockUploads, uploadBlob } from './blocks.js';
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
const MiB = 1024 ** 2;
|
|
12
|
+
/** Largest single Put Blob request. */ const MAX_SINGLE_UPLOAD_BYTES = 5000 * MiB;
|
|
13
|
+
/** Largest Put Block request. */ const MAX_BLOCK_BYTES = 4000 * MiB;
|
|
14
|
+
const expiration = (value)=>signedUrlLifetime('Azure Blob', value);
|
|
15
|
+
function azureBlob(options = {}) {
|
|
16
|
+
const { storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'), storageAccountKey = getEnv('ES_AZURE_ACCOUNT_KEY'), containerName = getEnv('ES_AZURE_CONTAINER_NAME') } = options;
|
|
17
|
+
const endpoint = (options.endpoint ?? getEnv('ES_AZURE_ENDPOINT') ?? `https://${storageAccountName}.blob.core.windows.net`).replace(/\/+$/, '');
|
|
18
|
+
const baseUrl = options.baseUrl ?? getEnv('EDGE_STORE_BASE_URL') ?? `${endpoint}/${containerName}`;
|
|
19
|
+
const keys = createObjectKeys('Azure Blob', baseUrl);
|
|
20
|
+
const uploadExpiresIn = expiration(options.uploadUrlExpiresIn ?? 3600);
|
|
21
|
+
const readExpiresIn = expiration(options.signedUrlExpiresIn ?? 3600);
|
|
22
|
+
function plan(sizeBytes) {
|
|
23
|
+
if (!Number.isSafeInteger(sizeBytes) || sizeBytes < 0) throw new RangeError('Azure Blob upload size must be a nonnegative safe integer.');
|
|
24
|
+
const result = planMultipartUpload({
|
|
25
|
+
sizeBytes,
|
|
26
|
+
thresholdBytes: options.multipart?.thresholdBytes,
|
|
27
|
+
preferredPartSizeBytes: options.multipart?.partSizeBytes,
|
|
28
|
+
forceMultipart: sizeBytes > MAX_SINGLE_UPLOAD_BYTES
|
|
29
|
+
});
|
|
30
|
+
if (result && result.partSizeBytes > MAX_BLOCK_BYTES) throw new RangeError('Azure blocks cannot exceed 4000 MiB.');
|
|
31
|
+
return result;
|
|
10
32
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
// Validate multipart settings even before the first large upload.
|
|
34
|
+
plan(0);
|
|
35
|
+
// Credentials are resolved on first use, so defining a router needs none.
|
|
36
|
+
let resolved;
|
|
37
|
+
function storage() {
|
|
38
|
+
if (!storageAccountName || !storageAccountKey || !containerName) {
|
|
39
|
+
throw new Error('Azure Blob requires storageAccountName, storageAccountKey, and containerName (or ES_AZURE_ACCOUNT_NAME, ES_AZURE_ACCOUNT_KEY, and ES_AZURE_CONTAINER_NAME).');
|
|
40
|
+
}
|
|
41
|
+
if (!resolved) {
|
|
42
|
+
const credential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);
|
|
43
|
+
resolved = {
|
|
44
|
+
containerName,
|
|
45
|
+
credential,
|
|
46
|
+
container: new BlobServiceClient(endpoint, credential).getContainerClient(containerName)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return resolved;
|
|
16
50
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
permissions: BlobSASPermissions.parse(params.permissions),
|
|
28
|
-
protocol: baseUrl.startsWith('https:') ? SASProtocol.Https : SASProtocol.HttpsAndHttp,
|
|
51
|
+
const blob = (key)=>storage().container.getBlockBlobClient(key);
|
|
52
|
+
function sas(key, permissions, expiresIn) {
|
|
53
|
+
const expiresAt = new Date(Date.now() + expiresIn * 1000);
|
|
54
|
+
const { containerName: container, credential } = storage();
|
|
55
|
+
const query = generateBlobSASQueryParameters({
|
|
56
|
+
containerName: container,
|
|
57
|
+
blobName: key,
|
|
58
|
+
permissions: BlobSASPermissions.parse(permissions),
|
|
59
|
+
protocol: endpoint.startsWith('https:') ? SASProtocol.Https : SASProtocol.HttpsAndHttp,
|
|
60
|
+
// Tolerate clock skew between this server and Azure.
|
|
29
61
|
startsOn: new Date(Date.now() - 5 * 60 * 1000),
|
|
30
62
|
expiresOn: expiresAt
|
|
31
|
-
},
|
|
32
|
-
const blobClient = containerClient.getBlobClient(params.blobName);
|
|
63
|
+
}, credential).toString();
|
|
33
64
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
expiresAt,
|
|
37
|
-
expiresIn: params.expiresIn
|
|
65
|
+
query,
|
|
66
|
+
expiresAt
|
|
38
67
|
};
|
|
39
68
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
throw new Error();
|
|
50
|
-
}
|
|
51
|
-
return decodeURIComponent(blobUrl.pathname.slice(containerPath.length + 1));
|
|
52
|
-
} catch {
|
|
53
|
-
throw new Error('File URL does not belong to this Azure Blob provider.');
|
|
54
|
-
}
|
|
69
|
+
function signedRead(key, expiresIn = readExpiresIn) {
|
|
70
|
+
const ttl = expiration(expiresIn);
|
|
71
|
+
const { query, expiresAt } = sas(key, 'r', ttl);
|
|
72
|
+
return {
|
|
73
|
+
url: keys.toUrl(key),
|
|
74
|
+
signedUrl: `${blob(key).url}?${query}`,
|
|
75
|
+
expiresAt,
|
|
76
|
+
expiresIn: ttl
|
|
77
|
+
};
|
|
55
78
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new Error(`File does not belong to EdgeStore bucket "${edgestoreBucketName}".`);
|
|
60
|
-
}
|
|
61
|
-
return blobName;
|
|
79
|
+
function readForUpload(key, params) {
|
|
80
|
+
if (params.fileInfo.isPublic || !params.autoSignedUrls) return undefined;
|
|
81
|
+
return signedRead(key, params.autoSignedUrls.expiresIn);
|
|
62
82
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
const blocks = createBlockUploads({
|
|
84
|
+
blob,
|
|
85
|
+
sessions: createMultipartSessions({
|
|
86
|
+
providerName: 'Azure Blob',
|
|
87
|
+
audience: `edgestore:azure-blob:${endpoint}:${containerName}`,
|
|
88
|
+
secret: options.jwtSecret,
|
|
89
|
+
expiresIn: options.multipart?.sessionExpiresIn ?? 86400
|
|
90
|
+
}),
|
|
91
|
+
signPartUrl: (key, id)=>`${blob(key).url}?comp=block&blockid=${encodeURIComponent(id)}&${sas(key, 'w', uploadExpiresIn).query}`
|
|
92
|
+
});
|
|
93
|
+
async function prepare({ bucketName, fileInfo }) {
|
|
94
|
+
const { key, pathArgs } = await keys.forUpload(bucketName, fileInfo, options.path);
|
|
95
|
+
const objectOptions = typeof options.objectOptions === 'function' ? await options.objectOptions(pathArgs) : options.objectOptions;
|
|
96
|
+
const commit = {
|
|
97
|
+
blobHTTPHeaders: {
|
|
98
|
+
blobContentType: fileInfo.type || 'application/octet-stream',
|
|
99
|
+
blobCacheControl: objectOptions?.cacheControl,
|
|
100
|
+
blobContentDisposition: objectOptions?.contentDisposition
|
|
101
|
+
},
|
|
102
|
+
metadata: objectOptions?.metadata
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
key,
|
|
106
|
+
commit,
|
|
107
|
+
plan: plan(fileInfo.size)
|
|
108
|
+
};
|
|
75
109
|
}
|
|
76
110
|
return defineProvider({
|
|
77
111
|
name: 'azure-blob',
|
|
78
|
-
baseUrl,
|
|
79
112
|
reference: {
|
|
80
|
-
schema: z.
|
|
81
|
-
|
|
82
|
-
|
|
113
|
+
schema: z.union([
|
|
114
|
+
z.object({
|
|
115
|
+
key: z.string().min(1)
|
|
116
|
+
}),
|
|
117
|
+
z.object({
|
|
118
|
+
url: z.string().url()
|
|
119
|
+
})
|
|
120
|
+
]),
|
|
83
121
|
fromUrl: (url)=>({
|
|
84
122
|
url
|
|
85
123
|
})
|
|
86
124
|
},
|
|
87
|
-
async init () {
|
|
125
|
+
async init ({ router }) {
|
|
126
|
+
storage();
|
|
127
|
+
assertSignedUrlAccessControl('Azure Blob', router);
|
|
88
128
|
return {};
|
|
89
129
|
},
|
|
90
130
|
uploads: {
|
|
@@ -93,62 +133,86 @@ function azureBlob(options) {
|
|
|
93
133
|
replaceTargetUrl: false
|
|
94
134
|
},
|
|
95
135
|
async request (params) {
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
136
|
+
const { key, commit, plan } = await prepare(params);
|
|
137
|
+
const signedReadUrl = readForUpload(key, params);
|
|
138
|
+
const access = {
|
|
139
|
+
key,
|
|
140
|
+
url: keys.toUrl(key),
|
|
141
|
+
...signedReadUrl ? {
|
|
142
|
+
signedReadUrl
|
|
143
|
+
} : {}
|
|
144
|
+
};
|
|
145
|
+
if (plan) {
|
|
146
|
+
return {
|
|
147
|
+
...access,
|
|
148
|
+
multipart: await blocks.request({
|
|
149
|
+
key,
|
|
150
|
+
size: params.fileInfo.size,
|
|
151
|
+
plan,
|
|
152
|
+
commit
|
|
153
|
+
})
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...access,
|
|
158
|
+
uploadUrl: `${blob(key).url}?${sas(key, 'cw', uploadExpiresIn).query}`,
|
|
159
|
+
uploadHeaders: blobUploadHeaders(commit)
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
multipart: blocks.operations,
|
|
163
|
+
async upload (params) {
|
|
164
|
+
const { key, commit, plan } = await prepare({
|
|
165
|
+
...params,
|
|
166
|
+
fileInfo: {
|
|
167
|
+
...params.fileInfo,
|
|
168
|
+
size: params.source.size,
|
|
169
|
+
type: params.source.type || params.fileInfo.type
|
|
170
|
+
}
|
|
101
171
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
172
|
+
// Sign before sending bytes: nothing fallible runs after the commit.
|
|
173
|
+
const signedReadUrl = readForUpload(key, params);
|
|
174
|
+
await uploadBlob({
|
|
175
|
+
client: blob(key),
|
|
176
|
+
commit,
|
|
177
|
+
plan,
|
|
178
|
+
source: params.source,
|
|
179
|
+
signal: params.signal,
|
|
180
|
+
onProgress: params.onProgress
|
|
106
181
|
});
|
|
182
|
+
const uploadedAt = new Date();
|
|
107
183
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
184
|
+
file: {
|
|
185
|
+
key,
|
|
186
|
+
url: keys.toUrl(key),
|
|
187
|
+
sizeBytes: params.source.size,
|
|
188
|
+
uploadedAt,
|
|
189
|
+
updatedAt: uploadedAt
|
|
111
190
|
},
|
|
112
|
-
|
|
113
|
-
accessSignedUrl: readAccess?.signedUrl,
|
|
114
|
-
accessSignedUrlExpiresAt: readAccess?.expiresAt,
|
|
115
|
-
accessSignedUrlExpiresIn: readAccess?.expiresIn
|
|
191
|
+
signedReadUrl
|
|
116
192
|
};
|
|
117
193
|
}
|
|
118
194
|
},
|
|
119
195
|
files: {
|
|
120
196
|
async get ({ bucketName, file }) {
|
|
121
|
-
const
|
|
122
|
-
const { contentLength, lastModified } = await
|
|
123
|
-
|
|
197
|
+
const key = keys.fromReference(bucketName, file);
|
|
198
|
+
const { contentLength, lastModified } = await blob(key).getProperties();
|
|
199
|
+
if (contentLength === undefined || !lastModified) throw new Error('File not found');
|
|
124
200
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
201
|
+
key,
|
|
202
|
+
url: keys.toUrl(key),
|
|
203
|
+
sizeBytes: contentLength,
|
|
204
|
+
uploadedAt: lastModified,
|
|
205
|
+
updatedAt: lastModified
|
|
129
206
|
};
|
|
130
207
|
},
|
|
131
208
|
async getSignedUrls ({ bucketName, files, expiresIn }) {
|
|
132
|
-
return files.map((file)=>
|
|
133
|
-
const access = createSignedBlobUrl({
|
|
134
|
-
blobName: getBucketBlobName(bucketName, file.url),
|
|
135
|
-
permissions: 'r',
|
|
136
|
-
expiresIn: expiresIn ?? signedUrlExpiresIn
|
|
137
|
-
});
|
|
138
|
-
return {
|
|
139
|
-
url: access.url,
|
|
140
|
-
signedUrl: access.signedUrl,
|
|
141
|
-
expiresAt: access.expiresAt,
|
|
142
|
-
expiresIn: access.expiresIn
|
|
143
|
-
};
|
|
144
|
-
});
|
|
209
|
+
return files.map((file)=>signedRead(keys.fromReference(bucketName, file), expiresIn));
|
|
145
210
|
},
|
|
146
211
|
async delete ({ bucketName, files }) {
|
|
147
|
-
const
|
|
148
|
-
const results = await
|
|
212
|
+
const blobKeys = files.map((file)=>keys.fromReference(bucketName, file));
|
|
213
|
+
const results = await runConcurrently(blobKeys, undefined, async (key)=>{
|
|
149
214
|
try {
|
|
150
|
-
|
|
151
|
-
await blobClient.delete();
|
|
215
|
+
await blob(key).deleteIfExists();
|
|
152
216
|
return {
|
|
153
217
|
success: true
|
|
154
218
|
};
|
|
@@ -161,7 +225,7 @@ function azureBlob(options) {
|
|
|
161
225
|
}
|
|
162
226
|
};
|
|
163
227
|
}
|
|
164
|
-
})
|
|
228
|
+
});
|
|
165
229
|
return {
|
|
166
230
|
results
|
|
167
231
|
};
|
|
@@ -169,5 +233,23 @@ function azureBlob(options) {
|
|
|
169
233
|
}
|
|
170
234
|
});
|
|
171
235
|
}
|
|
236
|
+
/** Headers a browser Put Blob request must send to apply the blob settings. */ function blobUploadHeaders({ blobHTTPHeaders, metadata }) {
|
|
237
|
+
const headers = {
|
|
238
|
+
'x-ms-blob-type': 'BlockBlob'
|
|
239
|
+
};
|
|
240
|
+
const fields = {
|
|
241
|
+
blobContentType: 'x-ms-blob-content-type',
|
|
242
|
+
blobCacheControl: 'x-ms-blob-cache-control',
|
|
243
|
+
blobContentDisposition: 'x-ms-blob-content-disposition'
|
|
244
|
+
};
|
|
245
|
+
for (const [field, header] of Object.entries(fields)){
|
|
246
|
+
const value = blobHTTPHeaders[field];
|
|
247
|
+
if (value !== undefined) headers[header] = value;
|
|
248
|
+
}
|
|
249
|
+
for (const [name, value] of Object.entries(metadata ?? {})){
|
|
250
|
+
headers[`x-ms-meta-${name}`] = value;
|
|
251
|
+
}
|
|
252
|
+
return headers;
|
|
253
|
+
}
|
|
172
254
|
|
|
173
255
|
export { azureBlob };
|
|
@@ -33,27 +33,14 @@ type EdgeStoreBearerProviderOptions = {
|
|
|
33
33
|
export type EdgeStoreProviderOptions = EdgeStoreProviderCommonOptions & (EdgeStoreProjectProviderOptions | EdgeStoreBearerProviderOptions);
|
|
34
34
|
export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
35
35
|
readonly name: "edgestore";
|
|
36
|
-
readonly baseUrl: string;
|
|
37
36
|
readonly reference: {
|
|
38
|
-
readonly schema: z.
|
|
37
|
+
readonly schema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
39
38
|
id: z.ZodString;
|
|
40
|
-
},
|
|
41
|
-
id: string;
|
|
42
|
-
}, {
|
|
43
|
-
id: string;
|
|
44
|
-
}>, z.ZodObject<{
|
|
39
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
45
40
|
key: z.ZodString;
|
|
46
|
-
},
|
|
47
|
-
key: string;
|
|
48
|
-
}, {
|
|
49
|
-
key: string;
|
|
50
|
-
}>, z.ZodObject<{
|
|
41
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
51
42
|
url: z.ZodString;
|
|
52
|
-
},
|
|
53
|
-
url: string;
|
|
54
|
-
}, {
|
|
55
|
-
url: string;
|
|
56
|
-
}>]>, {
|
|
43
|
+
}, z.core.$strip>]>, z.ZodTransform<{
|
|
57
44
|
id: string;
|
|
58
45
|
} | {
|
|
59
46
|
key: string;
|
|
@@ -65,22 +52,19 @@ export declare function edgestore(options?: EdgeStoreProviderOptions): {
|
|
|
65
52
|
key: string;
|
|
66
53
|
} | {
|
|
67
54
|
url: string;
|
|
68
|
-
}
|
|
55
|
+
}>>;
|
|
69
56
|
readonly fromUrl: (url: string) => {
|
|
70
57
|
url: string;
|
|
71
58
|
};
|
|
72
59
|
};
|
|
73
60
|
readonly init: <TCtx extends import("@edgestore/shared").AnyContext>({ ctx, router }: import("@edgestore/shared").InitParams<TCtx>) => Promise<{
|
|
74
|
-
baseUrl?: undefined;
|
|
75
61
|
clientInit?: undefined;
|
|
76
62
|
} | {
|
|
77
|
-
baseUrl: string;
|
|
78
63
|
clientInit: {
|
|
79
|
-
|
|
64
|
+
urls: string[];
|
|
80
65
|
headers: {
|
|
81
66
|
'x-edgestore-token': string;
|
|
82
67
|
};
|
|
83
|
-
urls?: string[] | undefined;
|
|
84
68
|
};
|
|
85
69
|
}>;
|
|
86
70
|
readonly uploads: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACtB,MAAM,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