@edgestore/server 0.1.5-alpha.4 → 0.1.5-alpha.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/adapters/express/index.d.ts +1 -0
- package/adapters/express/index.js +1 -0
- 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 +75 -7
- 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 +32 -6
- package/dist/core/index.mjs +33 -8
- 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/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 +2 -2
- package/src/adapters/next/app/index.ts +51 -19
- package/src/adapters/next/pages/index.ts +42 -14
- package/src/adapters/shared.ts +61 -29
- package/src/core/client/index.ts +103 -12
- 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/edgestore/index.ts +9 -2
package/dist/core/index.mjs
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { b as buildPath, p as parsePath } from '../shared-
|
|
2
|
-
import { i as initEdgeStoreSdk } from '../index-
|
|
3
|
-
export { e as edgeStoreRawSdk, i as initEdgeStoreSdk } from '../index-
|
|
1
|
+
import { b as buildPath, p as parsePath } from '../shared-b14a84ee.mjs';
|
|
2
|
+
import { i as initEdgeStoreSdk } from '../index-7cb3a3f3.mjs';
|
|
3
|
+
export { e as edgeStoreRawSdk, i as initEdgeStoreSdk } from '../index-7cb3a3f3.mjs';
|
|
4
|
+
import { _ } from '@swc/helpers/_/_define_property';
|
|
4
5
|
import '@panva/hkdf';
|
|
5
6
|
import 'cookie';
|
|
6
7
|
import 'jose';
|
|
7
8
|
import 'uuid';
|
|
8
|
-
import '@swc/helpers/_/_define_property';
|
|
9
9
|
|
|
10
|
+
// type guard for `content`
|
|
11
|
+
function isTextContent(content) {
|
|
12
|
+
return typeof content === 'string';
|
|
13
|
+
}
|
|
14
|
+
function isBlobContent(content) {
|
|
15
|
+
return typeof content !== 'string' && 'blob' in content;
|
|
16
|
+
}
|
|
10
17
|
function initEdgeStoreClient(config) {
|
|
11
18
|
const sdk = initEdgeStoreSdk({
|
|
12
19
|
accessKey: config.accessKey,
|
|
@@ -24,8 +31,8 @@ function initEdgeStoreClient(config) {
|
|
|
24
31
|
const content = params.content;
|
|
25
32
|
const ctx = 'ctx' in params ? params.ctx : {};
|
|
26
33
|
const input = 'input' in params ? params.input : {};
|
|
27
|
-
const { blob, extension } = (()=>{
|
|
28
|
-
if (
|
|
34
|
+
const { blob, extension } = await (async ()=>{
|
|
35
|
+
if (isTextContent(content)) {
|
|
29
36
|
return {
|
|
30
37
|
blob: new Blob([
|
|
31
38
|
content
|
|
@@ -34,11 +41,16 @@ function initEdgeStoreClient(config) {
|
|
|
34
41
|
}),
|
|
35
42
|
extension: 'txt'
|
|
36
43
|
};
|
|
37
|
-
} else {
|
|
44
|
+
} else if (isBlobContent(content)) {
|
|
38
45
|
return {
|
|
39
46
|
blob: content.blob,
|
|
40
47
|
extension: content.extension
|
|
41
48
|
};
|
|
49
|
+
} else {
|
|
50
|
+
return {
|
|
51
|
+
blob: await getBlobFromUrl(content.url),
|
|
52
|
+
extension: content.extension
|
|
53
|
+
};
|
|
42
54
|
}
|
|
43
55
|
})();
|
|
44
56
|
const path = buildPath({
|
|
@@ -155,5 +167,18 @@ function initEdgeStoreClient(config) {
|
|
|
155
167
|
}
|
|
156
168
|
return url;
|
|
157
169
|
}
|
|
170
|
+
async function getBlobFromUrl(url) {
|
|
171
|
+
const res = await fetch(url);
|
|
172
|
+
return await res.blob();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
class EdgeStoreApiClientError extends Error {
|
|
176
|
+
constructor(opts){
|
|
177
|
+
super(opts.response.message);
|
|
178
|
+
_(this, "data", void 0);
|
|
179
|
+
this.name = 'EdgeStoreApiClientError';
|
|
180
|
+
this.data = opts.response;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
158
183
|
|
|
159
|
-
export { initEdgeStoreClient };
|
|
184
|
+
export { EdgeStoreApiClientError, initEdgeStoreClient };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/sdk/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,IAAI,CAAC;
|
|
1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|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */ const EDGE_STORE_ERROR_CODES = {
|
|
4
|
+
BAD_REQUEST: 400,
|
|
5
|
+
FILE_TOO_LARGE: 400,
|
|
6
|
+
MIME_TYPE_NOT_ALLOWED: 400,
|
|
7
|
+
UNAUTHORIZED: 401,
|
|
8
|
+
UPLOAD_NOT_ALLOWED: 403,
|
|
9
|
+
DELETE_NOT_ALLOWED: 403,
|
|
10
|
+
CREATE_CONTEXT_ERROR: 500,
|
|
11
|
+
SERVER_ERROR: 500
|
|
12
|
+
};
|
|
13
|
+
class EdgeStoreError extends Error {
|
|
14
|
+
formattedMessage() {
|
|
15
|
+
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}` : ''}`;
|
|
16
|
+
}
|
|
17
|
+
formattedJson() {
|
|
18
|
+
return {
|
|
19
|
+
message: this.code === 'SERVER_ERROR' ? 'Internal server error' : this.message,
|
|
20
|
+
code: this.code,
|
|
21
|
+
details: this.details
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
constructor(opts){
|
|
25
|
+
super(opts.message);
|
|
26
|
+
_(this, "cause", void 0);
|
|
27
|
+
_(this, "code", void 0);
|
|
28
|
+
_(this, "level", void 0);
|
|
29
|
+
_(this, "details", void 0);
|
|
30
|
+
this.name = 'EdgeStoreError';
|
|
31
|
+
this.code = opts.code;
|
|
32
|
+
this.cause = opts.cause;
|
|
33
|
+
this.level = EDGE_STORE_ERROR_CODES[opts.code] >= 500 ? 'error' : 'warn';
|
|
34
|
+
this.details = 'details' in opts ? opts.details : undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
2
37
|
|
|
3
38
|
const DEFAULT_MESSAGE = `Missing EDGE_STORE_ACCESS_KEY or EDGE_STORE_SECRET_KEY.
|
|
4
39
|
This can happen if you are trying to use the vanilla client in your frontend.
|
|
@@ -33,7 +68,10 @@ const edgeStoreRawSdk = {
|
|
|
33
68
|
path: bucket._def.path.map((p)=>{
|
|
34
69
|
const paramEntries = Object.entries(p);
|
|
35
70
|
if (paramEntries[0] === undefined) {
|
|
36
|
-
throw new
|
|
71
|
+
throw new EdgeStoreError({
|
|
72
|
+
message: `Empty path param found in: ${JSON.stringify(bucket._def.path)}`,
|
|
73
|
+
code: 'SERVER_ERROR'
|
|
74
|
+
});
|
|
37
75
|
}
|
|
38
76
|
const [key, value] = paramEntries[0];
|
|
39
77
|
return {
|
|
@@ -225,6 +263,4 @@ function initEdgeStoreSdk(params) {
|
|
|
225
263
|
};
|
|
226
264
|
}
|
|
227
265
|
|
|
228
|
-
|
|
229
|
-
exports.edgeStoreRawSdk = edgeStoreRawSdk;
|
|
230
|
-
exports.initEdgeStoreSdk = initEdgeStoreSdk;
|
|
266
|
+
export { EdgeStoreError as E, EDGE_STORE_ERROR_CODES as a, EdgeStoreCredentialsError as b, edgeStoreRawSdk as e, initEdgeStoreSdk as i };
|
|
@@ -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 };
|
|
@@ -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({
|