@edgestore/server 0.1.5-alpha.3 → 0.1.5-alpha.5
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/next/app/index.d.ts +5 -3
- package/dist/adapters/next/app/index.d.ts.map +1 -1
- package/dist/adapters/next/app/index.js +38 -15
- package/dist/adapters/next/app/index.mjs +37 -14
- package/dist/adapters/next/pages/index.d.ts +5 -3
- package/dist/adapters/next/pages/index.d.ts.map +1 -1
- package/dist/adapters/next/pages/index.js +32 -12
- package/dist/adapters/next/pages/index.mjs +31 -11
- package/dist/adapters/shared.d.ts.map +1 -1
- package/dist/core/client/index.d.ts +56 -2
- package/dist/core/client/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +13 -3
- package/dist/core/index.mjs +14 -5
- package/dist/core/sdk/index.d.ts.map +1 -1
- package/dist/{index-50ab9e08.js → index-7cb3a3f3.mjs} +41 -5
- package/dist/{index-f33a00fb.js → index-9eb6248c.js} +37 -2
- package/dist/{index-30a3741e.mjs → index-e25c8209.js} +48 -2
- package/dist/libs/errors/EdgeStoreApiClientError.d.ts +8 -0
- package/dist/libs/errors/EdgeStoreApiClientError.d.ts.map +1 -0
- package/dist/libs/errors/EdgeStoreError.d.ts +36 -4
- package/dist/libs/errors/EdgeStoreError.d.ts.map +1 -1
- package/dist/libs/logger.d.ts +13 -0
- package/dist/libs/logger.d.ts.map +1 -0
- package/dist/logger-0f08f252.mjs +40 -0
- package/dist/logger-623f2833.js +42 -0
- package/dist/logger-8f098618.js +33 -0
- 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/dist/providers/edgestore/index.d.ts.map +1 -1
- package/dist/providers/edgestore/index.js +10 -3
- package/dist/providers/edgestore/index.mjs +10 -3
- package/dist/{shared-5d1e7f43.js → shared-53cb59dd.js} +72 -51
- package/dist/{shared-30b7a2ab.mjs → shared-b14a84ee.mjs} +65 -42
- package/dist/{shared-88655ba7.js → shared-f8ddbf7c.js} +62 -36
- package/package.json +12 -2
- package/providers/azure/index.d.ts +1 -0
- package/providers/azure/index.js +1 -0
- package/src/adapters/next/app/index.ts +52 -19
- package/src/adapters/next/pages/index.ts +43 -14
- package/src/adapters/shared.ts +62 -29
- package/src/core/client/index.ts +57 -2
- package/src/core/index.ts +6 -0
- package/src/core/sdk/index.ts +7 -1
- package/src/libs/errors/EdgeStoreApiClientError.ts +14 -0
- package/src/libs/errors/EdgeStoreError.ts +76 -7
- package/src/libs/logger.ts +44 -0
- package/src/providers/azure/index.ts +89 -0
- package/src/providers/edgestore/index.ts +9 -2
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
const EDGE_STORE_ERROR_CODES = {
|
|
3
|
+
BAD_REQUEST: 400,
|
|
4
|
+
FILE_TOO_LARGE: 400,
|
|
5
|
+
MIME_TYPE_NOT_ALLOWED: 400,
|
|
6
|
+
UNAUTHORIZED: 401,
|
|
7
|
+
UPLOAD_NOT_ALLOWED: 403,
|
|
8
|
+
DELETE_NOT_ALLOWED: 403,
|
|
9
|
+
CREATE_CONTEXT_ERROR: 500,
|
|
10
|
+
SERVER_ERROR: 500,
|
|
11
|
+
};
|
|
12
|
+
class EdgeStoreError extends Error {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(opts.message);
|
|
15
|
+
this.name = 'EdgeStoreError';
|
|
16
|
+
this.code = opts.code;
|
|
17
|
+
this.cause = opts.cause;
|
|
18
|
+
this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
|
|
19
|
+
this.details = 'details' in opts ? opts.details : undefined;
|
|
20
|
+
}
|
|
21
|
+
formattedMessage() {
|
|
22
|
+
return `EdgeStore${this.level === 'error' ? 'Error' : 'Info'}: ${this.message}${this.details ? `\n Details: ${JSON.stringify(this.details)}` : ''}${this.cause ? `\n Caused by: ${this.cause.message}` : ''}`;
|
|
23
|
+
}
|
|
24
|
+
formattedJson() {
|
|
25
|
+
return {
|
|
26
|
+
message: this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
|
|
27
|
+
code: this.code,
|
|
28
|
+
details: this.details,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
1
33
|
const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
|
|
2
34
|
This can happen if you are trying to use the vanilla client in your frontend.
|
|
3
35
|
The vanilla client should only be used in the backend.`;
|
|
@@ -31,7 +63,10 @@ const edgeStoreRawSdk = {
|
|
|
31
63
|
path: bucket._def.path.map((p) => {
|
|
32
64
|
const paramEntries = Object.entries(p);
|
|
33
65
|
if (paramEntries[0] === undefined) {
|
|
34
|
-
throw new
|
|
66
|
+
throw new EdgeStoreError({
|
|
67
|
+
message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
|
|
68
|
+
code: 'SERVER_ERROR',
|
|
69
|
+
});
|
|
35
70
|
}
|
|
36
71
|
const [key, value] = paramEntries[0];
|
|
37
72
|
return {
|
|
@@ -223,4 +258,4 @@ function initEdgeStoreSdk(params) {
|
|
|
223
258
|
};
|
|
224
259
|
}
|
|
225
260
|
|
|
226
|
-
export {
|
|
261
|
+
export { EdgeStoreError as E, EDGE_STORE_ERROR_CODES as a, EdgeStoreCredentialsError as b, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
|
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _define_property = require('@swc/helpers/_/_define_property');
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ const EDGE_STORE_ERROR_CODES = {
|
|
6
|
+
BAD_REQUEST: 400,
|
|
7
|
+
FILE_TOO_LARGE: 400,
|
|
8
|
+
MIME_TYPE_NOT_ALLOWED: 400,
|
|
9
|
+
UNAUTHORIZED: 401,
|
|
10
|
+
UPLOAD_NOT_ALLOWED: 403,
|
|
11
|
+
DELETE_NOT_ALLOWED: 403,
|
|
12
|
+
CREATE_CONTEXT_ERROR: 500,
|
|
13
|
+
SERVER_ERROR: 500
|
|
14
|
+
};
|
|
15
|
+
class EdgeStoreError extends Error {
|
|
16
|
+
formattedMessage() {
|
|
17
|
+
return `EdgeStore${this.level === 'error' ? 'Error' : 'Info'}: ${this.message}${this.details ? `\n Details: ${JSON.stringify(this.details)}` : ''}${this.cause ? `\n Caused by: ${this.cause.message}` : ''}`;
|
|
18
|
+
}
|
|
19
|
+
formattedJson() {
|
|
20
|
+
return {
|
|
21
|
+
message: this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
|
|
22
|
+
code: this.code,
|
|
23
|
+
details: this.details
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
constructor(opts){
|
|
27
|
+
super(opts.message);
|
|
28
|
+
_define_property._(this, "cause", void 0);
|
|
29
|
+
_define_property._(this, "code", void 0);
|
|
30
|
+
_define_property._(this, "level", void 0);
|
|
31
|
+
_define_property._(this, "details", void 0);
|
|
32
|
+
this.name = 'EdgeStoreError';
|
|
33
|
+
this.code = opts.code;
|
|
34
|
+
this.cause = opts.cause;
|
|
35
|
+
this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
|
|
36
|
+
this.details = 'details' in opts ? opts.details : undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
1
40
|
const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
|
|
2
41
|
This can happen if you are trying to use the vanilla client in your frontend.
|
|
3
42
|
The vanilla client should only be used in the backend.`;
|
|
@@ -31,7 +70,10 @@ const edgeStoreRawSdk = {
|
|
|
31
70
|
path: bucket._def.path.map((p)=>{
|
|
32
71
|
const paramEntries = Object.entries(p);
|
|
33
72
|
if (paramEntries[0] === undefined) {
|
|
34
|
-
throw new
|
|
73
|
+
throw new EdgeStoreError({
|
|
74
|
+
message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
|
|
75
|
+
code: 'SERVER_ERROR'
|
|
76
|
+
});
|
|
35
77
|
}
|
|
36
78
|
const [key, value] = paramEntries[0];
|
|
37
79
|
return {
|
|
@@ -223,4 +265,8 @@ function initEdgeStoreSdk(params) {
|
|
|
223
265
|
};
|
|
224
266
|
}
|
|
225
267
|
|
|
226
|
-
|
|
268
|
+
exports.EDGE_STORE_ERROR_CODES = EDGE_STORE_ERROR_CODES;
|
|
269
|
+
exports.EdgeStoreCredentialsError = EdgeStoreCredentialsError;
|
|
270
|
+
exports.EdgeStoreError = EdgeStoreError;
|
|
271
|
+
exports.edgeStoreRawSdk = edgeStoreRawSdk;
|
|
272
|
+
exports.initEdgeStoreSdk = initEdgeStoreSdk;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EdgeStoreJsonResponse } from './EdgeStoreError';
|
|
2
|
+
export declare class EdgeStoreApiClientError extends Error {
|
|
3
|
+
readonly data: EdgeStoreJsonResponse;
|
|
4
|
+
constructor(opts: {
|
|
5
|
+
response: EdgeStoreJsonResponse;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=EdgeStoreApiClientError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeStoreApiClientError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreApiClientError.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,SAAgB,IAAI,EAAE,qBAAqB,CAAC;gBAEhC,IAAI,EAAE;QAAE,QAAQ,EAAE,qBAAqB,CAAA;KAAE;CAMtD"}
|
|
@@ -1,16 +1,48 @@
|
|
|
1
|
+
import { type Simplify } from '../../types';
|
|
1
2
|
export declare const EDGE_STORE_ERROR_CODES: {
|
|
2
3
|
readonly BAD_REQUEST: 400;
|
|
4
|
+
readonly FILE_TOO_LARGE: 400;
|
|
5
|
+
readonly MIME_TYPE_NOT_ALLOWED: 400;
|
|
3
6
|
readonly UNAUTHORIZED: 401;
|
|
7
|
+
readonly UPLOAD_NOT_ALLOWED: 403;
|
|
8
|
+
readonly DELETE_NOT_ALLOWED: 403;
|
|
9
|
+
readonly CREATE_CONTEXT_ERROR: 500;
|
|
10
|
+
readonly SERVER_ERROR: 500;
|
|
4
11
|
};
|
|
5
12
|
export type EdgeStoreErrorCodeKey = keyof typeof EDGE_STORE_ERROR_CODES;
|
|
6
|
-
|
|
13
|
+
export type EdgeStoreErrorDetails<TCode extends EdgeStoreErrorCodeKey> = TCode extends 'FILE_TOO_LARGE' ? {
|
|
14
|
+
maxFileSize: number;
|
|
15
|
+
fileSize: number;
|
|
16
|
+
} : TCode extends 'MIME_TYPE_NOT_ALLOWED' ? {
|
|
17
|
+
allowedMimeTypes: string[];
|
|
18
|
+
mimeType: string;
|
|
19
|
+
} : never;
|
|
20
|
+
export type EdgeStoreJsonResponse = Simplify<{
|
|
21
|
+
message: string;
|
|
22
|
+
code: 'FILE_TOO_LARGE';
|
|
23
|
+
details: EdgeStoreErrorDetails<'FILE_TOO_LARGE'>;
|
|
24
|
+
} | {
|
|
25
|
+
message: string;
|
|
26
|
+
code: 'MIME_TYPE_NOT_ALLOWED';
|
|
27
|
+
details: EdgeStoreErrorDetails<'MIME_TYPE_NOT_ALLOWED'>;
|
|
28
|
+
} | {
|
|
29
|
+
message: string;
|
|
30
|
+
code: Exclude<EdgeStoreErrorCodeKey, 'FILE_TOO_LARGE' | 'MIME_TYPE_NOT_ALLOWED'>;
|
|
31
|
+
}>;
|
|
32
|
+
declare class EdgeStoreError<TCode extends EdgeStoreErrorCodeKey> extends Error {
|
|
7
33
|
readonly cause?: Error;
|
|
8
|
-
readonly code:
|
|
34
|
+
readonly code: TCode;
|
|
35
|
+
readonly level: 'error' | 'warn';
|
|
36
|
+
readonly details: EdgeStoreErrorDetails<TCode>;
|
|
9
37
|
constructor(opts: {
|
|
10
38
|
message: string;
|
|
11
|
-
code:
|
|
39
|
+
code: TCode;
|
|
12
40
|
cause?: Error;
|
|
13
|
-
}
|
|
41
|
+
} & (EdgeStoreErrorDetails<TCode> extends undefined ? object : {
|
|
42
|
+
details: EdgeStoreErrorDetails<TCode>;
|
|
43
|
+
}));
|
|
44
|
+
formattedMessage(): string;
|
|
45
|
+
formattedJson(): EdgeStoreJsonResponse;
|
|
14
46
|
}
|
|
15
47
|
export default EdgeStoreError;
|
|
16
48
|
//# sourceMappingURL=EdgeStoreError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB
|
|
1
|
+
{"version":3,"file":"EdgeStoreError.d.ts","sourceRoot":"","sources":["../../../src/libs/errors/EdgeStoreError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C,eAAO,MAAM,sBAAsB;;;;;;;;;CASzB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,MAAM,OAAO,sBAAsB,CAAC;AAExE,MAAM,MAAM,qBAAqB,CAAC,KAAK,SAAS,qBAAqB,IACnE,KAAK,SAAS,gBAAgB,GAC1B;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,SAAS,uBAAuB,GACrC;IACE,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD,KAAK,CAAC;AAEZ,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CACxC;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;CAClD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,qBAAqB,CAAC,uBAAuB,CAAC,CAAC;CACzD,GACD;IACE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CACX,qBAAqB,EACrB,gBAAgB,GAAG,uBAAuB,CAC3C,CAAC;CACH,CACJ,CAAC;AAEF,cAAM,cAAc,CAAC,KAAK,SAAS,qBAAqB,CAAE,SAAQ,KAAK;IACrE,SAAgB,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9B,SAAgB,IAAI,EAAE,KAAK,CAAC;IAC5B,SAAgB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxC,SAAgB,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBAGpD,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,GAAG,CAAC,qBAAqB,CAAC,KAAK,CAAC,SAAS,SAAS,GAC/C,MAAM,GACN;QACE,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;KACvC,CAAC;IAWR,gBAAgB,IAAI,MAAM;IAQ1B,aAAa,IAAI,qBAAqB;CAQvC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const logLevel: readonly ["debug", "info", "warn", "error", "none"];
|
|
2
|
+
export type LogLevel = typeof logLevel[number];
|
|
3
|
+
declare class Logger {
|
|
4
|
+
private logLevel;
|
|
5
|
+
constructor(logLevel?: LogLevel);
|
|
6
|
+
private shouldLog;
|
|
7
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
8
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
9
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
10
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
}
|
|
12
|
+
export default Logger;
|
|
13
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/libs/logger.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,QAAQ,qDAAsD,CAAC;AAErE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE/C,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAW;gBAEf,QAAQ,CAAC,EAAE,QAAQ;IAK/B,OAAO,CAAC,SAAS;IAIjB,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMpD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMnD,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;IAMnD,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI;CAKrD;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { _ } from '@swc/helpers/_/_define_property';
|
|
2
|
+
|
|
3
|
+
const logLevel = [
|
|
4
|
+
'debug',
|
|
5
|
+
'info',
|
|
6
|
+
'warn',
|
|
7
|
+
'error',
|
|
8
|
+
'none'
|
|
9
|
+
];
|
|
10
|
+
class Logger {
|
|
11
|
+
shouldLog(level) {
|
|
12
|
+
return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
|
|
13
|
+
}
|
|
14
|
+
debug(message, ...optionalParams) {
|
|
15
|
+
if (this.shouldLog('debug')) {
|
|
16
|
+
console.debug(message, ...optionalParams);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
info(message, ...optionalParams) {
|
|
20
|
+
if (this.shouldLog('info')) {
|
|
21
|
+
console.info(message, ...optionalParams);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
warn(message, ...optionalParams) {
|
|
25
|
+
if (this.shouldLog('warn')) {
|
|
26
|
+
console.warn(message, ...optionalParams);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
error(message, ...optionalParams) {
|
|
30
|
+
if (this.shouldLog('error')) {
|
|
31
|
+
console.error(message, ...optionalParams);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
constructor(logLevel){
|
|
35
|
+
_(this, "logLevel", void 0);
|
|
36
|
+
this.logLevel = logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { Logger as L };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _define_property = require('@swc/helpers/_/_define_property');
|
|
4
|
+
|
|
5
|
+
const logLevel = [
|
|
6
|
+
'debug',
|
|
7
|
+
'info',
|
|
8
|
+
'warn',
|
|
9
|
+
'error',
|
|
10
|
+
'none'
|
|
11
|
+
];
|
|
12
|
+
class Logger {
|
|
13
|
+
shouldLog(level) {
|
|
14
|
+
return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
|
|
15
|
+
}
|
|
16
|
+
debug(message, ...optionalParams) {
|
|
17
|
+
if (this.shouldLog('debug')) {
|
|
18
|
+
console.debug(message, ...optionalParams);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
info(message, ...optionalParams) {
|
|
22
|
+
if (this.shouldLog('info')) {
|
|
23
|
+
console.info(message, ...optionalParams);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
warn(message, ...optionalParams) {
|
|
27
|
+
if (this.shouldLog('warn')) {
|
|
28
|
+
console.warn(message, ...optionalParams);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
error(message, ...optionalParams) {
|
|
32
|
+
if (this.shouldLog('error')) {
|
|
33
|
+
console.error(message, ...optionalParams);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
constructor(logLevel){
|
|
37
|
+
_define_property._(this, "logLevel", void 0);
|
|
38
|
+
this.logLevel = logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.Logger = Logger;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
const logLevel = ['debug', 'info', 'warn', 'error', 'none'];
|
|
3
|
+
class Logger {
|
|
4
|
+
constructor(logLevel) {
|
|
5
|
+
this.logLevel =
|
|
6
|
+
logLevel ?? process.env.NODE_ENV === 'production' ? 'error' : 'info';
|
|
7
|
+
}
|
|
8
|
+
shouldLog(level) {
|
|
9
|
+
return logLevel.indexOf(level) >= logLevel.indexOf(this.logLevel);
|
|
10
|
+
}
|
|
11
|
+
debug(message, ...optionalParams) {
|
|
12
|
+
if (this.shouldLog('debug')) {
|
|
13
|
+
console.debug(message, ...optionalParams);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
info(message, ...optionalParams) {
|
|
17
|
+
if (this.shouldLog('info')) {
|
|
18
|
+
console.info(message, ...optionalParams);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
warn(message, ...optionalParams) {
|
|
22
|
+
if (this.shouldLog('warn')) {
|
|
23
|
+
console.warn(message, ...optionalParams);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
error(message, ...optionalParams) {
|
|
27
|
+
if (this.shouldLog('error')) {
|
|
28
|
+
console.error(message, ...optionalParams);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { Logger as L };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Provider } from '../types';
|
|
2
|
+
export type AzureProviderOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* The storage account name for Azure Blob Storage
|
|
5
|
+
* 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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/edgestore/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,QAAQ,EAAyB,MAAM,UAAU,CAAC;AAIhE,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,QAAQ,CAgJV"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('../../index-
|
|
5
|
+
var index = require('../../index-e25c8209.js');
|
|
6
|
+
require('@swc/helpers/_/_define_property');
|
|
6
7
|
|
|
7
8
|
const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
|
|
8
9
|
function EdgeStoreProvider(options) {
|
|
@@ -81,7 +82,10 @@ function EdgeStoreProvider(options) {
|
|
|
81
82
|
thumbnailUrl: res.thumbnailUrl
|
|
82
83
|
};
|
|
83
84
|
} else {
|
|
84
|
-
throw new
|
|
85
|
+
throw new index.EdgeStoreError({
|
|
86
|
+
message: 'Could not get upload url',
|
|
87
|
+
code: 'SERVER_ERROR'
|
|
88
|
+
});
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
const res = await edgeStoreSdk.requestUpload({
|
|
@@ -96,7 +100,10 @@ function EdgeStoreProvider(options) {
|
|
|
96
100
|
thumbnailUrl: res.thumbnailUrl
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
|
-
throw new
|
|
103
|
+
throw new index.EdgeStoreError({
|
|
104
|
+
message: 'Could not get upload url',
|
|
105
|
+
code: 'SERVER_ERROR'
|
|
106
|
+
});
|
|
100
107
|
},
|
|
101
108
|
requestUploadParts: async ({ multipart, path })=>{
|
|
102
109
|
const res = await edgeStoreSdk.requestUploadParts({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b as EdgeStoreCredentialsError, i as initEdgeStoreSdk, E as EdgeStoreError } from '../../index-7cb3a3f3.mjs';
|
|
2
|
+
import '@swc/helpers/_/_define_property';
|
|
2
3
|
|
|
3
4
|
const DEFAULT_BASE_URL = 'https://files.edgestore.dev';
|
|
4
5
|
function EdgeStoreProvider(options) {
|
|
@@ -77,7 +78,10 @@ function EdgeStoreProvider(options) {
|
|
|
77
78
|
thumbnailUrl: res.thumbnailUrl
|
|
78
79
|
};
|
|
79
80
|
} else {
|
|
80
|
-
throw new
|
|
81
|
+
throw new EdgeStoreError({
|
|
82
|
+
message: 'Could not get upload url',
|
|
83
|
+
code: 'SERVER_ERROR'
|
|
84
|
+
});
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
const res = await edgeStoreSdk.requestUpload({
|
|
@@ -92,7 +96,10 @@ function EdgeStoreProvider(options) {
|
|
|
92
96
|
thumbnailUrl: res.thumbnailUrl
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
|
-
throw new
|
|
99
|
+
throw new EdgeStoreError({
|
|
100
|
+
message: 'Could not get upload url',
|
|
101
|
+
code: 'SERVER_ERROR'
|
|
102
|
+
});
|
|
96
103
|
},
|
|
97
104
|
requestUploadParts: async ({ multipart, path })=>{
|
|
98
105
|
const res = await edgeStoreSdk.requestUploadParts({
|