@edgestore/server 0.4.0 → 0.5.0
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/adapters/astro/index.d.ts +1 -0
- package/adapters/astro/index.js +1 -0
- package/adapters/hono/index.d.ts +1 -0
- package/adapters/hono/index.js +1 -0
- package/adapters/remix/index.d.ts +1 -0
- package/adapters/remix/index.js +1 -0
- package/dist/adapters/astro/index.d.ts +14 -0
- package/dist/adapters/astro/index.d.ts.map +1 -0
- package/dist/adapters/astro/index.js +183 -0
- package/dist/adapters/astro/index.mjs +179 -0
- package/dist/adapters/express/index.js +3 -3
- package/dist/adapters/express/index.mjs +3 -3
- package/dist/adapters/fastify/index.js +3 -3
- package/dist/adapters/fastify/index.mjs +3 -3
- package/dist/adapters/hono/index.d.ts +82 -0
- package/dist/adapters/hono/index.d.ts.map +1 -0
- package/dist/adapters/hono/index.js +137 -0
- package/dist/adapters/hono/index.mjs +133 -0
- package/dist/adapters/next/app/index.js +3 -3
- package/dist/adapters/next/app/index.mjs +3 -3
- package/dist/adapters/next/pages/index.js +3 -3
- package/dist/adapters/next/pages/index.mjs +3 -3
- package/dist/adapters/remix/index.d.ts +18 -0
- package/dist/adapters/remix/index.d.ts.map +1 -0
- package/dist/adapters/remix/index.js +158 -0
- package/dist/adapters/remix/index.mjs +154 -0
- package/dist/adapters/shared.d.ts +2 -0
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/adapters/start/index.js +3 -3
- package/dist/adapters/start/index.mjs +3 -3
- package/dist/core/index.js +3 -3
- package/dist/core/index.mjs +4 -4
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/{index-a7cc3cd3.mjs → index-2848cb40.mjs} +3 -2
- package/dist/{index-474a21c4.js → index-421c502f.js} +3 -2
- package/dist/{index-b689bf59.js → index-7b259533.js} +5 -4
- package/dist/libs/logger.d.ts +1 -1
- package/dist/libs/logger.d.ts.map +1 -1
- package/dist/providers/aws/index.d.ts.map +1 -1
- package/dist/providers/aws/index.js +7 -2
- package/dist/providers/aws/index.mjs +7 -2
- package/dist/providers/azure/index.d.ts.map +1 -1
- package/dist/providers/azure/index.js +6 -1
- package/dist/providers/azure/index.mjs +6 -1
- package/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +13 -6
- package/dist/providers/edgestore/index.mjs +10 -3
- package/dist/{shared-d27101a7.js → shared-25dbfab4.js} +17 -4
- package/dist/{shared-c9442cbb.mjs → shared-4b199b96.mjs} +16 -4
- package/dist/{shared-6f6fd0bd.js → shared-685c8a0c.js} +17 -3
- package/dist/{utils-5819d5e1.js → utils-0aab6e3b.js} +3 -1
- package/dist/{utils-f6f56d38.mjs → utils-7349adab.mjs} +3 -1
- package/dist/{utils-461a2e3b.js → utils-b3d35894.js} +3 -2
- package/package.json +20 -3
- package/src/adapters/astro/index.ts +222 -0
- package/src/adapters/hono/index.ts +195 -0
- package/src/adapters/remix/index.ts +201 -0
- package/src/adapters/shared.ts +20 -3
- package/src/core/client/index.ts +2 -2
- package/src/core/sdk/index.ts +4 -3
- package/src/libs/logger.ts +4 -3
- package/src/providers/aws/index.ts +8 -7
- package/src/providers/azure/index.ts +5 -4
- package/src/providers/edgestore/index.ts +8 -3
- package/adapters/index.d.ts +0 -1
- package/adapters/index.js +0 -1
- package/providers/index.d.ts +0 -1
- package/providers/index.js +0 -1
package/src/adapters/shared.ts
CHANGED
|
@@ -434,7 +434,7 @@ export async function deleteFile<TCtx>(params: {
|
|
|
434
434
|
|
|
435
435
|
async function encryptJWT(ctx: any) {
|
|
436
436
|
const secret =
|
|
437
|
-
|
|
437
|
+
getEnv('EDGE_STORE_JWT_SECRET') ?? getEnv('EDGE_STORE_SECRET_KEY');
|
|
438
438
|
if (!secret) {
|
|
439
439
|
throw new EdgeStoreError({
|
|
440
440
|
message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
|
|
@@ -452,7 +452,7 @@ async function encryptJWT(ctx: any) {
|
|
|
452
452
|
|
|
453
453
|
async function decryptJWT(token: string) {
|
|
454
454
|
const secret =
|
|
455
|
-
|
|
455
|
+
getEnv('EDGE_STORE_JWT_SECRET') ?? getEnv('EDGE_STORE_SECRET_KEY');
|
|
456
456
|
if (!secret) {
|
|
457
457
|
throw new EdgeStoreError({
|
|
458
458
|
message: 'EDGE_STORE_JWT_SECRET or EDGE_STORE_SECRET_KEY is not defined',
|
|
@@ -539,7 +539,7 @@ async function getContext(token: string) {
|
|
|
539
539
|
* so that we can delete or confirm the upload.
|
|
540
540
|
*/
|
|
541
541
|
function unproxyUrl(url: string) {
|
|
542
|
-
if (
|
|
542
|
+
if (isDev() && url.startsWith('http://')) {
|
|
543
543
|
// get the url param from the query string
|
|
544
544
|
const urlParam = new URL(url).searchParams.get('url');
|
|
545
545
|
if (urlParam) {
|
|
@@ -548,3 +548,20 @@ function unproxyUrl(url: string) {
|
|
|
548
548
|
}
|
|
549
549
|
return url;
|
|
550
550
|
}
|
|
551
|
+
|
|
552
|
+
export function getEnv(key: string): string | undefined {
|
|
553
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
554
|
+
// @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
555
|
+
return process.env[key] ?? import.meta.env?.[key];
|
|
556
|
+
}
|
|
557
|
+
// @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
558
|
+
return import.meta.env?.[key];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export function isDev(): boolean {
|
|
562
|
+
return (
|
|
563
|
+
process?.env?.NODE_ENV === 'development' ||
|
|
564
|
+
// @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
565
|
+
import.meta.env?.DEV
|
|
566
|
+
);
|
|
567
|
+
}
|
package/src/core/client/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '@edgestore/shared';
|
|
11
11
|
import { type z, type ZodNever } from 'zod';
|
|
12
12
|
import { type Comparison } from '..';
|
|
13
|
-
import { buildPath, parsePath } from '../../adapters/shared';
|
|
13
|
+
import { buildPath, isDev, parsePath } from '../../adapters/shared';
|
|
14
14
|
import { initEdgeStoreSdk } from '../sdk';
|
|
15
15
|
|
|
16
16
|
export type GetFileRes<TBucket extends AnyBuilder> = {
|
|
@@ -408,7 +408,7 @@ export function initEdgeStoreClient<TRouter extends AnyRouter>(config: {
|
|
|
408
408
|
* we need to proxy the file through the server.
|
|
409
409
|
*/
|
|
410
410
|
function getUrl(url: string, baseUrl?: string) {
|
|
411
|
-
if (
|
|
411
|
+
if (isDev() && !url.includes('/_public/')) {
|
|
412
412
|
if (!baseUrl) {
|
|
413
413
|
throw new Error(
|
|
414
414
|
'Missing baseUrl. You need to pass the baseUrl to `initEdgeStoreClient` to get protected files in development.',
|
package/src/core/sdk/index.ts
CHANGED
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
type AnyMetadata,
|
|
5
5
|
type AnyRouter,
|
|
6
6
|
} from '@edgestore/shared';
|
|
7
|
+
import { getEnv } from '../../adapters/shared';
|
|
7
8
|
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError';
|
|
8
9
|
|
|
9
10
|
const API_ENDPOINT =
|
|
10
|
-
|
|
11
|
+
getEnv('EDGE_STORE_API_ENDPOINT') ?? 'https://api.edgestore.dev';
|
|
11
12
|
|
|
12
13
|
type FileInfoForUpload = {
|
|
13
14
|
size: number;
|
|
@@ -359,8 +360,8 @@ export function initEdgeStoreSdk(params: {
|
|
|
359
360
|
secretKey?: string;
|
|
360
361
|
}) {
|
|
361
362
|
const {
|
|
362
|
-
accessKey =
|
|
363
|
-
secretKey =
|
|
363
|
+
accessKey = getEnv('EDGE_STORE_ACCESS_KEY'),
|
|
364
|
+
secretKey = getEnv('EDGE_STORE_SECRET_KEY'),
|
|
364
365
|
} = params ?? {};
|
|
365
366
|
|
|
366
367
|
if (!accessKey || !secretKey) {
|
package/src/libs/logger.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
|
+
import { isDev } from '../adapters/shared';
|
|
4
|
+
|
|
3
5
|
const logLevel = ['debug', 'info', 'warn', 'error', 'none'] as const;
|
|
4
6
|
|
|
5
|
-
export type LogLevel = typeof logLevel[number];
|
|
7
|
+
export type LogLevel = (typeof logLevel)[number];
|
|
6
8
|
|
|
7
9
|
class Logger {
|
|
8
10
|
private logLevel: LogLevel;
|
|
9
11
|
|
|
10
12
|
constructor(logLevel?: LogLevel) {
|
|
11
|
-
this.logLevel =
|
|
12
|
-
logLevel ?? (process.env.NODE_ENV === 'production' ? 'error' : 'info');
|
|
13
|
+
this.logLevel = logLevel ?? (isDev() ? 'info' : 'error');
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
private shouldLog(level: LogLevel): boolean {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
8
8
|
import { type Provider } from '@edgestore/shared';
|
|
9
9
|
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
+
import { getEnv } from '../../adapters/shared';
|
|
10
11
|
|
|
11
12
|
export type AWSProviderOptions = {
|
|
12
13
|
/**
|
|
@@ -62,17 +63,17 @@ export type AWSProviderOptions = {
|
|
|
62
63
|
|
|
63
64
|
export function AWSProvider(options?: AWSProviderOptions): Provider {
|
|
64
65
|
const {
|
|
65
|
-
accessKeyId =
|
|
66
|
-
secretAccessKey =
|
|
67
|
-
region =
|
|
68
|
-
bucketName =
|
|
69
|
-
endpoint =
|
|
70
|
-
forcePathStyle =
|
|
66
|
+
accessKeyId = getEnv('ES_AWS_ACCESS_KEY_ID'),
|
|
67
|
+
secretAccessKey = getEnv('ES_AWS_SECRET_ACCESS_KEY'),
|
|
68
|
+
region = getEnv('ES_AWS_REGION'),
|
|
69
|
+
bucketName = getEnv('ES_AWS_BUCKET_NAME'),
|
|
70
|
+
endpoint = getEnv('ES_AWS_ENDPOINT'),
|
|
71
|
+
forcePathStyle = getEnv('ES_AWS_FORCE_PATH_STYLE') === 'true',
|
|
71
72
|
} = options ?? {};
|
|
72
73
|
|
|
73
74
|
const baseUrl =
|
|
74
75
|
options?.baseUrl ??
|
|
75
|
-
|
|
76
|
+
getEnv('EDGE_STORE_BASE_URL') ??
|
|
76
77
|
(endpoint
|
|
77
78
|
? `${endpoint}/${bucketName}`
|
|
78
79
|
: `https://${bucketName}.s3.${region}.amazonaws.com`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
2
|
import { type Provider } from '@edgestore/shared';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { getEnv } from '../../adapters/shared';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Options for the Azure provider. Compatible with Azure Blob Storage and Azurite.
|
|
@@ -41,10 +42,10 @@ export type AzureProviderOptions = {
|
|
|
41
42
|
|
|
42
43
|
export function AzureProvider(options?: AzureProviderOptions): Provider {
|
|
43
44
|
const {
|
|
44
|
-
storageAccountName =
|
|
45
|
-
sasToken =
|
|
46
|
-
containerName =
|
|
47
|
-
customBaseUrl =
|
|
45
|
+
storageAccountName = getEnv('ES_AZURE_ACCOUNT_NAME'),
|
|
46
|
+
sasToken = getEnv('ES_AZURE_SAS_TOKEN'),
|
|
47
|
+
containerName = getEnv('ES_AZURE_CONTAINER_NAME'),
|
|
48
|
+
customBaseUrl = getEnv('ES_AZURE_BASE_URL'),
|
|
48
49
|
} = options ?? {};
|
|
49
50
|
|
|
50
51
|
const baseUrl =
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type Provider,
|
|
4
4
|
type RequestUploadRes,
|
|
5
5
|
} from '@edgestore/shared';
|
|
6
|
+
import { getEnv } from '../../adapters/shared';
|
|
6
7
|
import { initEdgeStoreSdk } from '../../core/sdk';
|
|
7
8
|
import EdgeStoreCredentialsError from '../../libs/errors/EdgeStoreCredentialsError';
|
|
8
9
|
|
|
@@ -29,11 +30,15 @@ export function EdgeStoreProvider(
|
|
|
29
30
|
options?: EdgeStoreProviderOptions,
|
|
30
31
|
): Provider {
|
|
31
32
|
const {
|
|
32
|
-
accessKey =
|
|
33
|
-
|
|
33
|
+
accessKey = getEnv('EDGE_STORE_ACCESS_KEY') ??
|
|
34
|
+
// @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
35
|
+
import.meta.env?.EDGE_STORE_ACCESS_KEY,
|
|
36
|
+
secretKey = getEnv('EDGE_STORE_SECRET_KEY') ??
|
|
37
|
+
// @ts-expect-error - In Vite/Astro, the env variables are available on `import.meta`.
|
|
38
|
+
import.meta.env?.EDGE_STORE_SECRET_KEY,
|
|
34
39
|
} = options ?? {};
|
|
35
40
|
|
|
36
|
-
const baseUrl =
|
|
41
|
+
const baseUrl = getEnv('EDGE_STORE_BASE_URL') ?? DEFAULT_BASE_URL;
|
|
37
42
|
|
|
38
43
|
if (!accessKey || !secretKey) {
|
|
39
44
|
throw new EdgeStoreCredentialsError();
|
package/adapters/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/adapters';
|
package/adapters/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../dist/adapters');
|
package/providers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../dist/providers';
|
package/providers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../dist/providers');
|