@edgestore/server 1.0.0-next.5 → 1.0.0-rc.7
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/README.md +2 -2
- package/agent-docs/README.md +1 -1
- package/agent-docs/astro.md +3 -3
- package/agent-docs/backend-client.md +5 -8
- package/agent-docs/express.md +3 -3
- package/agent-docs/fastify.md +3 -3
- package/agent-docs/hono.md +3 -3
- package/agent-docs/next.md +3 -3
- package/agent-docs/provider-azure-blob.md +150 -57
- package/agent-docs/provider-custom.md +29 -3
- package/agent-docs/provider-edgestore.md +2 -2
- package/agent-docs/provider-s3.md +124 -24
- package/agent-docs/remix.md +3 -3
- package/agent-docs/tanstack-start.md +3 -3
- package/dist/adapters/dispatcher.d.ts.map +1 -1
- package/dist/adapters/dispatcher.js +10 -1
- package/dist/adapters/shared.d.ts +25 -103
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/shared.js +157 -110
- 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/libs/env.d.ts.map +1 -1
- package/dist/libs/env.js +3 -0
- package/dist/libs/errors/EdgeStoreCredentialsError.js +1 -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 +41 -24
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +33 -20
- 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 +24 -45
- 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 +13 -35
- 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/test-utils/edgestoreSmoke.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +4 -11
- package/src/adapters/dispatcher.ts +14 -0
- package/src/adapters/shared.ts +179 -127
- package/src/core/client/index.ts +0 -4
- package/src/core/provider.ts +0 -8
- package/src/index.ts +3 -8
- package/src/libs/env.ts +9 -0
- package/src/libs/errors/EdgeStoreCredentialsError.ts +1 -1
- package/src/providers/azure-blob/blocks.ts +201 -0
- package/src/providers/azure-blob/index.ts +289 -171
- package/src/providers/edgestore/index.ts +30 -26
- package/src/providers/s3/backendUpload.ts +20 -55
- package/src/providers/s3/index.ts +32 -59
- package/src/providers/s3/multipart.ts +36 -94
- package/src/providers/s3/options.ts +13 -36
- 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/test-utils/edgestoreSmoke.ts +3 -5
- 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
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { type MultipartUploadPlan } from '@edgestore/sdk';
|
|
2
|
+
import { EdgeStoreError } from '@edgestore/shared';
|
|
3
|
+
import { jwtVerify, SignJWT } from 'jose';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { INITIAL_MULTIPART_PART_URLS } from '../../core/provider';
|
|
6
|
+
import { getEnv } from '../../libs/env';
|
|
7
|
+
|
|
8
|
+
const sessionSchema = z.object({
|
|
9
|
+
key: z.string(),
|
|
10
|
+
/** Storage upload ID (S3) or block ID prefix (Azure). */
|
|
11
|
+
id: z.string(),
|
|
12
|
+
size: z.number().int().nonnegative(),
|
|
13
|
+
partSize: z.number().int().positive(),
|
|
14
|
+
totalParts: z.number().int().min(1).max(10_000),
|
|
15
|
+
/** Provider-specific settings applied when the upload completes. */
|
|
16
|
+
data: z.record(z.string(), z.unknown()).optional(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type MultipartSession = z.infer<typeof sessionSchema>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Browser multipart sessions are HS256 JWTs. The token is the `uploadId` the
|
|
23
|
+
* browser sends back, and acts as a bearer capability for one object key.
|
|
24
|
+
*/
|
|
25
|
+
export function createMultipartSessions({
|
|
26
|
+
providerName,
|
|
27
|
+
audience,
|
|
28
|
+
secret,
|
|
29
|
+
expiresIn,
|
|
30
|
+
}: {
|
|
31
|
+
providerName: string;
|
|
32
|
+
audience: string;
|
|
33
|
+
secret: string | undefined;
|
|
34
|
+
expiresIn: number;
|
|
35
|
+
}) {
|
|
36
|
+
if (!Number.isSafeInteger(expiresIn) || expiresIn < 1) {
|
|
37
|
+
throw new RangeError(
|
|
38
|
+
`${providerName} multipart session lifetime must be a positive integer number of seconds.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function signingKey() {
|
|
43
|
+
const value =
|
|
44
|
+
secret ??
|
|
45
|
+
getEnv('EDGESTORE_JWT_SECRET') ??
|
|
46
|
+
getEnv('EDGESTORE_SECRET_KEY');
|
|
47
|
+
if (!value)
|
|
48
|
+
throw new Error(
|
|
49
|
+
`${providerName} multipart uploads require jwtSecret or EDGESTORE_JWT_SECRET.`,
|
|
50
|
+
);
|
|
51
|
+
return new TextEncoder().encode(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
/** Fails before storage resources are allocated when no secret is set. */
|
|
56
|
+
assertConfigured() {
|
|
57
|
+
signingKey();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
sign(session: MultipartSession) {
|
|
61
|
+
return new SignJWT(session)
|
|
62
|
+
.setProtectedHeader({ alg: 'HS256' })
|
|
63
|
+
.setAudience(audience)
|
|
64
|
+
.setIssuedAt()
|
|
65
|
+
.setExpirationTime(`${expiresIn}s`)
|
|
66
|
+
.sign(signingKey());
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
async read(token: string, key: string) {
|
|
70
|
+
try {
|
|
71
|
+
const { payload } = await jwtVerify(token, signingKey(), {
|
|
72
|
+
algorithms: ['HS256'],
|
|
73
|
+
audience,
|
|
74
|
+
});
|
|
75
|
+
const session = sessionSchema.parse(payload);
|
|
76
|
+
if (session.key !== key) throw new Error('Wrong object key');
|
|
77
|
+
return session;
|
|
78
|
+
} catch {
|
|
79
|
+
throw new EdgeStoreError({
|
|
80
|
+
code: 'BAD_REQUEST',
|
|
81
|
+
message: `Invalid or expired ${providerName} multipart upload session.`,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Builds a session from an upload plan. */
|
|
89
|
+
export function sessionFromPlan({
|
|
90
|
+
key,
|
|
91
|
+
id,
|
|
92
|
+
size,
|
|
93
|
+
plan,
|
|
94
|
+
data,
|
|
95
|
+
}: {
|
|
96
|
+
key: string;
|
|
97
|
+
id: string;
|
|
98
|
+
size: number;
|
|
99
|
+
plan: MultipartUploadPlan;
|
|
100
|
+
data?: Record<string, unknown>;
|
|
101
|
+
}): MultipartSession {
|
|
102
|
+
return {
|
|
103
|
+
key,
|
|
104
|
+
id,
|
|
105
|
+
size,
|
|
106
|
+
partSize: plan.partSizeBytes,
|
|
107
|
+
totalParts: plan.totalParts,
|
|
108
|
+
...(data ? { data } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Part numbers whose URLs are signed when the upload starts. */
|
|
113
|
+
export function initialPartNumbers(plan: MultipartUploadPlan) {
|
|
114
|
+
return plan.partNumbers.slice(0, INITIAL_MULTIPART_PART_URLS);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Rejects empty, duplicate, or out-of-range part lists. */
|
|
118
|
+
export function assertValidParts(
|
|
119
|
+
session: MultipartSession,
|
|
120
|
+
parts: number[],
|
|
121
|
+
{ complete = false } = {},
|
|
122
|
+
) {
|
|
123
|
+
if (
|
|
124
|
+
!parts.length ||
|
|
125
|
+
new Set(parts).size !== parts.length ||
|
|
126
|
+
parts.some(
|
|
127
|
+
(part) =>
|
|
128
|
+
!Number.isInteger(part) || part < 1 || part > session.totalParts,
|
|
129
|
+
) ||
|
|
130
|
+
(complete && parts.length !== session.totalParts)
|
|
131
|
+
) {
|
|
132
|
+
throw new EdgeStoreError({
|
|
133
|
+
code: 'BAD_REQUEST',
|
|
134
|
+
message: 'Invalid multipart part numbers.',
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Byte length of one part; the last part may be shorter. */
|
|
140
|
+
export function partLength(session: MultipartSession, partNumber: number) {
|
|
141
|
+
return Math.min(
|
|
142
|
+
session.partSize,
|
|
143
|
+
session.size - (partNumber - 1) * session.partSize,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { MaybePromise, RequestUploadParams } from '@edgestore/shared';
|
|
2
|
+
|
|
3
|
+
export type ObjectPathFnArgs = {
|
|
4
|
+
/** Logical EdgeStore router bucket name. */
|
|
5
|
+
edgestoreBucketName: string;
|
|
6
|
+
/** File info after EdgeStore path and metadata generation. */
|
|
7
|
+
fileInfo: RequestUploadParams['fileInfo'];
|
|
8
|
+
/** Default object path relative to the logical bucket prefix. */
|
|
9
|
+
defaultPath: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Returns an object path relative to the logical bucket prefix. */
|
|
13
|
+
export type ObjectPathFn = (args: ObjectPathFnArgs) => MaybePromise<string>;
|
|
14
|
+
|
|
15
|
+
export function createObjectKeys(providerName: string, baseUrl: string) {
|
|
16
|
+
const normalizedBaseUrl = baseUrl.replace(/\/+$/, '');
|
|
17
|
+
|
|
18
|
+
function objectKeyToUrl(objectKey: string) {
|
|
19
|
+
const encodedKey = objectKey
|
|
20
|
+
.split('/')
|
|
21
|
+
.map((segment) => encodeURIComponent(segment))
|
|
22
|
+
.join('/');
|
|
23
|
+
return `${normalizedBaseUrl}/${encodedKey}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function urlToObjectKey(url: string) {
|
|
27
|
+
try {
|
|
28
|
+
const fileUrl = new URL(url);
|
|
29
|
+
const providerUrl = new URL(`${normalizedBaseUrl}/`);
|
|
30
|
+
if (
|
|
31
|
+
fileUrl.origin !== providerUrl.origin ||
|
|
32
|
+
!fileUrl.pathname.startsWith(providerUrl.pathname)
|
|
33
|
+
) {
|
|
34
|
+
throw new Error();
|
|
35
|
+
}
|
|
36
|
+
return decodeURIComponent(
|
|
37
|
+
fileUrl.pathname.slice(providerUrl.pathname.length),
|
|
38
|
+
);
|
|
39
|
+
} catch {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`File URL does not belong to this ${providerName} provider.`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeRelativePath(value: string) {
|
|
47
|
+
const path = value.replace(/^\/+|\/+$/g, '');
|
|
48
|
+
if (
|
|
49
|
+
path.length === 0 ||
|
|
50
|
+
path.split('/').some((segment) => segment === '.' || segment === '..')
|
|
51
|
+
) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`${providerName} paths must stay within the EdgeStore bucket prefix.`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Keys from both URLs and key references must stay inside the logical bucket. */
|
|
60
|
+
function fromReference(
|
|
61
|
+
bucketName: string,
|
|
62
|
+
file: { url: string } | { key: string },
|
|
63
|
+
) {
|
|
64
|
+
const key = 'url' in file ? urlToObjectKey(file.url) : file.key;
|
|
65
|
+
if (
|
|
66
|
+
normalizeRelativePath(key) !== key ||
|
|
67
|
+
!key.startsWith(`${bucketName}/`)
|
|
68
|
+
) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`File does not belong to EdgeStore bucket "${bucketName}".`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return key;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resolves the object key for an upload. The logical bucket is always the
|
|
78
|
+
* first key segment, so router authorization for one bucket cannot reach
|
|
79
|
+
* objects from another.
|
|
80
|
+
*/
|
|
81
|
+
async function forUpload(
|
|
82
|
+
edgestoreBucketName: string,
|
|
83
|
+
fileInfo: RequestUploadParams['fileInfo'],
|
|
84
|
+
path?: ObjectPathFn,
|
|
85
|
+
) {
|
|
86
|
+
const extension = fileInfo.extension
|
|
87
|
+
? `.${fileInfo.extension.replace(/^\./, '')}`
|
|
88
|
+
: '';
|
|
89
|
+
const defaultPath = [
|
|
90
|
+
...(fileInfo.isPublic ? ['_public'] : []),
|
|
91
|
+
...fileInfo.path.map((part) => part.value),
|
|
92
|
+
fileInfo.fileName ?? `${crypto.randomUUID()}${extension}`,
|
|
93
|
+
].join('/');
|
|
94
|
+
const relativePath = normalizeRelativePath(
|
|
95
|
+
path
|
|
96
|
+
? await path({ edgestoreBucketName, fileInfo, defaultPath })
|
|
97
|
+
: defaultPath,
|
|
98
|
+
);
|
|
99
|
+
return {
|
|
100
|
+
key: `${edgestoreBucketName}/${relativePath}`,
|
|
101
|
+
pathArgs: { edgestoreBucketName, fileInfo, defaultPath },
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return { toUrl: objectKeyToUrl, fromReference, forUpload };
|
|
106
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DEFAULT_MULTIPART_CONCURRENCY } from '@edgestore/sdk';
|
|
2
|
+
import type {
|
|
3
|
+
AnyContext,
|
|
4
|
+
BackendUploadParams,
|
|
5
|
+
EdgeStoreRouter,
|
|
6
|
+
} from '@edgestore/shared';
|
|
7
|
+
|
|
8
|
+
/** Validates a signed URL lifetime against the storage service's maximum. */
|
|
9
|
+
export function signedUrlLifetime(
|
|
10
|
+
providerName: string,
|
|
11
|
+
value: number,
|
|
12
|
+
maxSeconds = 604800,
|
|
13
|
+
) {
|
|
14
|
+
if (!Number.isInteger(value) || value < 1 || value > maxSeconds) {
|
|
15
|
+
throw new RangeError(
|
|
16
|
+
`${providerName} signed URL expiration must be an integer between 1 and ${maxSeconds} seconds.`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Direct-storage providers authorize private reads with backend-issued signed
|
|
24
|
+
* URLs. Cookie-based rules would silently not be enforced, so reject them.
|
|
25
|
+
*/
|
|
26
|
+
export function assertSignedUrlAccessControl<TCtx extends AnyContext>(
|
|
27
|
+
providerName: string,
|
|
28
|
+
router: EdgeStoreRouter<TCtx>,
|
|
29
|
+
) {
|
|
30
|
+
for (const bucket of Object.values(router.buckets)) {
|
|
31
|
+
const { accessControl } = bucket._def;
|
|
32
|
+
if (accessControl !== undefined && accessControl !== 'private') {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`${providerName} supports accessControl("private") with backend signed URLs, not cookie-based access-control rules.`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reports cumulative backend upload progress. */
|
|
41
|
+
export function createProgress(
|
|
42
|
+
totalBytes: number,
|
|
43
|
+
onProgress: BackendUploadParams['onProgress'],
|
|
44
|
+
) {
|
|
45
|
+
let transferredBytes = 0;
|
|
46
|
+
const report = (bytes: number) => {
|
|
47
|
+
transferredBytes += bytes;
|
|
48
|
+
onProgress?.({
|
|
49
|
+
transferredBytes,
|
|
50
|
+
totalBytes,
|
|
51
|
+
percentage: totalBytes ? (transferredBytes / totalBytes) * 100 : 100,
|
|
52
|
+
phase: 'uploading',
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
report(0);
|
|
56
|
+
return report;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Runs tasks a few at a time to bound memory use. The first failure, or
|
|
61
|
+
* the caller's signal, stops the remaining parts before the error is thrown.
|
|
62
|
+
*/
|
|
63
|
+
export async function runConcurrently<TItem, TResult>(
|
|
64
|
+
items: TItem[],
|
|
65
|
+
signal: AbortSignal | undefined,
|
|
66
|
+
task: (item: TItem, signal: AbortSignal) => Promise<TResult>,
|
|
67
|
+
) {
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const partSignal = signal
|
|
70
|
+
? AbortSignal.any([signal, controller.signal])
|
|
71
|
+
: controller.signal;
|
|
72
|
+
const results = new Array<TResult>(items.length);
|
|
73
|
+
let next = 0;
|
|
74
|
+
const workers = Array.from(
|
|
75
|
+
{ length: Math.min(DEFAULT_MULTIPART_CONCURRENCY, items.length) },
|
|
76
|
+
async () => {
|
|
77
|
+
while (next < items.length) {
|
|
78
|
+
partSignal.throwIfAborted();
|
|
79
|
+
const index = next++;
|
|
80
|
+
results[index] = await task(items[index]!, partSignal);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
try {
|
|
85
|
+
await Promise.all(workers);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
controller.abort(error);
|
|
88
|
+
await Promise.allSettled(workers);
|
|
89
|
+
throw signal?.aborted ? signal.reason : error;
|
|
90
|
+
}
|
|
91
|
+
signal?.throwIfAborted();
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Reads one part of the source into memory. */
|
|
96
|
+
export async function readPart(
|
|
97
|
+
source: Blob,
|
|
98
|
+
partNumber: number,
|
|
99
|
+
partSizeBytes: number,
|
|
100
|
+
) {
|
|
101
|
+
const start = (partNumber - 1) * partSizeBytes;
|
|
102
|
+
return new Uint8Array(
|
|
103
|
+
await source.slice(start, start + partSizeBytes).arrayBuffer(),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { getEnv } from '../libs/env';
|
|
2
3
|
|
|
3
4
|
export const SMOKE_CONTENT = 'edgestore smoke test';
|
|
4
5
|
|
|
@@ -11,12 +12,9 @@ export function createSmokeFileName(prefix: string) {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export function requireSmokeCredentials() {
|
|
14
|
-
if (
|
|
15
|
-
!process.env.EDGE_STORE_ACCESS_KEY ||
|
|
16
|
-
!process.env.EDGE_STORE_SECRET_KEY
|
|
17
|
-
) {
|
|
15
|
+
if (!getEnv('EDGESTORE_ACCESS_KEY') || !getEnv('EDGESTORE_SECRET_KEY')) {
|
|
18
16
|
throw new Error(
|
|
19
|
-
'
|
|
17
|
+
'EDGESTORE_ACCESS_KEY and EDGESTORE_SECRET_KEY are required',
|
|
20
18
|
);
|
|
21
19
|
}
|
|
22
20
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const EDGE_STORE_PACKAGE_NAME = '@edgestore/server';
|
|
2
|
-
export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-
|
|
2
|
+
export const EDGE_STORE_PACKAGE_VERSION = '1.0.0-rc.7';
|
package/core/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/core/index.js';
|
package/core/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/core/index.js';
|
package/dist/core/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type * from './client/index.js';
|
|
2
|
-
export { EdgeStoreFileMutationError } from './client/index.js';
|
|
3
|
-
export { defineProvider, getProviderBaseUrl, referenceFromUrl, validateProviderCursor, validateProviderReference, } from './provider.js';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,UAAU,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
|
package/dist/core/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function createObjectKeys(baseUrl: string): {
|
|
2
|
-
toUrl: (objectKey: string) => string;
|
|
3
|
-
fromReference: (bucketName: string, file: {
|
|
4
|
-
url: string;
|
|
5
|
-
} | {
|
|
6
|
-
key: string;
|
|
7
|
-
}) => string;
|
|
8
|
-
normalizeRelativePath: (value: string) => string;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/providers/s3/keys.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM;uBAGX,MAAM;gCAuC3B,MAAM,QACZ;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE;mCAdH,MAAM;EA6B7C"}
|
package/src/core/index.ts
DELETED
package/src/providers/s3/keys.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
export function createObjectKeys(baseUrl: string) {
|
|
2
|
-
const normalizedBaseUrl = baseUrl.replace(/\/+$/, '');
|
|
3
|
-
|
|
4
|
-
function objectKeyToUrl(objectKey: string) {
|
|
5
|
-
const encodedKey = objectKey
|
|
6
|
-
.split('/')
|
|
7
|
-
.map((segment) => encodeURIComponent(segment))
|
|
8
|
-
.join('/');
|
|
9
|
-
return `${normalizedBaseUrl}/${encodedKey}`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function urlToObjectKey(url: string) {
|
|
13
|
-
try {
|
|
14
|
-
const fileUrl = new URL(url);
|
|
15
|
-
const providerUrl = new URL(`${normalizedBaseUrl}/`);
|
|
16
|
-
if (
|
|
17
|
-
fileUrl.origin !== providerUrl.origin ||
|
|
18
|
-
!fileUrl.pathname.startsWith(providerUrl.pathname)
|
|
19
|
-
) {
|
|
20
|
-
throw new Error();
|
|
21
|
-
}
|
|
22
|
-
return decodeURIComponent(
|
|
23
|
-
fileUrl.pathname.slice(providerUrl.pathname.length),
|
|
24
|
-
);
|
|
25
|
-
} catch {
|
|
26
|
-
throw new Error('File URL does not belong to this S3 provider.');
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizeRelativePath(value: string) {
|
|
31
|
-
const path = value.replace(/^\/+|\/+$/g, '');
|
|
32
|
-
if (
|
|
33
|
-
path.length === 0 ||
|
|
34
|
-
path.split('/').some((segment) => segment === '.' || segment === '..')
|
|
35
|
-
) {
|
|
36
|
-
throw new Error('S3 paths must stay within the EdgeStore bucket prefix.');
|
|
37
|
-
}
|
|
38
|
-
return path;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Keys from both URLs and key references must stay inside the logical bucket. */
|
|
42
|
-
function fromReference(
|
|
43
|
-
bucketName: string,
|
|
44
|
-
file: { url: string } | { key: string },
|
|
45
|
-
) {
|
|
46
|
-
const key = 'url' in file ? urlToObjectKey(file.url) : file.key;
|
|
47
|
-
if (
|
|
48
|
-
normalizeRelativePath(key) !== key ||
|
|
49
|
-
!key.startsWith(`${bucketName}/`)
|
|
50
|
-
) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`File does not belong to EdgeStore bucket "${bucketName}".`,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return key;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return { toUrl: objectKeyToUrl, fromReference, normalizeRelativePath };
|
|
59
|
-
}
|