@webiny/api-file-manager 5.23.1 → 5.25.0-beta.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/handlers/download/index.d.ts +5 -1
- package/handlers/download/index.js +25 -19
- package/handlers/download/index.js.map +1 -0
- package/handlers/manage/index.d.ts +2 -1
- package/handlers/manage/index.js +17 -16
- package/handlers/manage/index.js.map +1 -0
- package/handlers/transform/index.d.ts +2 -1
- package/handlers/transform/index.js +7 -4
- package/handlers/transform/index.js.map +1 -0
- package/handlers/transform/loaders/imageLoader.d.ts +25 -9
- package/handlers/transform/loaders/imageLoader.js +2 -3
- package/handlers/transform/loaders/imageLoader.js.map +1 -0
- package/handlers/transform/loaders/index.d.ts +4 -9
- package/handlers/transform/loaders/index.js.map +1 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
- package/handlers/transform/loaders/sanitizeImageTransformations.js +27 -20
- package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
- package/handlers/transform/managers/imageManager.d.ts +12 -6
- package/handlers/transform/managers/imageManager.js +22 -17
- package/handlers/transform/managers/imageManager.js.map +1 -0
- package/handlers/transform/managers/index.d.ts +2 -6
- package/handlers/transform/managers/index.js.map +1 -0
- package/handlers/transform/optimizeImage.d.ts +2 -1
- package/handlers/transform/optimizeImage.js +3 -0
- package/handlers/transform/optimizeImage.js.map +1 -0
- package/handlers/transform/transformImage.d.ts +5 -4
- package/handlers/transform/transformImage.js +3 -3
- package/handlers/transform/transformImage.js.map +1 -0
- package/handlers/transform/utils.d.ts +2 -2
- package/handlers/transform/utils.js.map +1 -0
- package/handlers/types.d.ts +33 -0
- package/handlers/types.js +5 -0
- package/handlers/types.js.map +1 -0
- package/handlers/utils/createHandler.d.ts +16 -16
- package/handlers/utils/createHandler.js +43 -42
- package/handlers/utils/createHandler.js.map +1 -0
- package/handlers/utils/getEnvironment.js.map +1 -0
- package/handlers/utils/getObjectParams.d.ts +3 -4
- package/handlers/utils/getObjectParams.js +0 -2
- package/handlers/utils/getObjectParams.js.map +1 -0
- package/handlers/utils/index.d.ts +1 -1
- package/handlers/utils/index.js +17 -7
- package/handlers/utils/index.js.map +1 -0
- package/package.json +20 -20
- package/plugins/crud/files/validation.js.map +1 -0
- package/plugins/crud/files.crud.js +4 -7
- package/plugins/crud/files.crud.js.map +1 -0
- package/plugins/crud/settings.crud.js +1 -0
- package/plugins/crud/settings.crud.js.map +1 -0
- package/plugins/crud/system.crud.js.map +1 -0
- package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
- package/plugins/crud/utils/createFileModel.d.ts +3 -0
- package/plugins/crud/utils/createFileModel.js +13 -0
- package/plugins/crud/utils/createFileModel.js.map +1 -0
- package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
- package/plugins/crud/utils/lifecycleEvents.js +5 -0
- package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
- package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
- package/plugins/definitions/FilePlugin.d.ts +6 -3
- package/plugins/definitions/FilePlugin.js +8 -2
- package/plugins/definitions/FilePlugin.js.map +1 -0
- package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
- package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +3 -3
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/definitions/InstallationPlugin.d.ts +9 -9
- package/plugins/definitions/InstallationPlugin.js +4 -2
- package/plugins/definitions/InstallationPlugin.js.map +1 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +3 -3
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +3 -3
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
- package/plugins/graphql.js +9 -1
- package/plugins/graphql.js.map +1 -0
- package/plugins/index.js.map +1 -0
- package/plugins/storage/FileStorage.d.ts +23 -24
- package/plugins/storage/FileStorage.js +23 -13
- package/plugins/storage/FileStorage.js.map +1 -0
- package/plugins/storage/index.js +4 -0
- package/plugins/storage/index.js.map +1 -0
- package/types.d.ts +10 -9
- package/types.js.map +1 -0
- package/utils.js.map +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface HandlerEventArgs {
|
|
2
|
+
httpMethod: "POST" | "OPTIONS";
|
|
3
|
+
}
|
|
4
|
+
interface S3Record {
|
|
5
|
+
s3: {
|
|
6
|
+
object: {
|
|
7
|
+
key?: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export interface ManageHandlerEventArgs extends HandlerEventArgs {
|
|
12
|
+
Records: S3Record[];
|
|
13
|
+
}
|
|
14
|
+
export interface DownloadHandlerEventArgs extends HandlerEventArgs {
|
|
15
|
+
pathParameters: {
|
|
16
|
+
path: string;
|
|
17
|
+
};
|
|
18
|
+
queryStringParameters?: {
|
|
19
|
+
width?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface TransformHandlerEventArgs extends HandlerEventArgs {
|
|
23
|
+
body: {
|
|
24
|
+
key: string;
|
|
25
|
+
transformations: {
|
|
26
|
+
width: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface HandlerHeaders {
|
|
31
|
+
[key: string]: string | boolean | undefined;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { HandlerEventArgs, HandlerHeaders } from "../types";
|
|
2
|
+
import { Body } from "aws-sdk/clients/s3";
|
|
3
|
+
interface EventHandlerResponse {
|
|
4
|
+
data: Body | null;
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
headers: HandlerHeaders;
|
|
7
|
+
}
|
|
8
|
+
export interface EventHandlerCallable<T> {
|
|
9
|
+
(event: T): Promise<EventHandlerResponse>;
|
|
10
|
+
}
|
|
11
|
+
export declare const createHandler: <T extends HandlerEventArgs>(eventHandler: EventHandlerCallable<T>) => (event: T) => Promise<{
|
|
12
|
+
isBase64Encoded: boolean;
|
|
3
13
|
statusCode: number;
|
|
4
14
|
headers: {
|
|
5
|
-
|
|
6
|
-
"Access-Control-Allow-Origin": string;
|
|
7
|
-
"Access-Control-Allow-Credentials": boolean;
|
|
15
|
+
[x: string]: string | boolean | undefined;
|
|
8
16
|
};
|
|
9
|
-
|
|
10
|
-
} | {
|
|
11
|
-
isBase64Encoded: boolean;
|
|
12
|
-
statusCode: any;
|
|
13
|
-
headers: any;
|
|
14
|
-
body: any;
|
|
17
|
+
body: string;
|
|
15
18
|
} | {
|
|
16
19
|
statusCode: number;
|
|
17
|
-
headers:
|
|
18
|
-
"Access-Control-Allow-Origin": string;
|
|
19
|
-
"Access-Control-Allow-Credentials": boolean;
|
|
20
|
-
};
|
|
20
|
+
headers: HandlerHeaders;
|
|
21
21
|
body: string;
|
|
22
22
|
isBase64Encoded?: undefined;
|
|
23
23
|
}>;
|
|
24
|
-
export
|
|
24
|
+
export {};
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.createHandler = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -15,7 +15,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* We need to respond with adequate CORS headers.
|
|
18
|
-
* @type {{"Access-Control-Allow-Origin": string, "Access-Control-Allow-Credentials": boolean}}
|
|
19
18
|
*/
|
|
20
19
|
const baseHeaders = {
|
|
21
20
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -23,46 +22,48 @@ const baseHeaders = {
|
|
|
23
22
|
};
|
|
24
23
|
const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const createHandler = eventHandler => {
|
|
26
|
+
return async event => {
|
|
27
|
+
if (event.httpMethod === "OPTIONS") {
|
|
28
|
+
return {
|
|
29
|
+
body: "",
|
|
30
|
+
statusCode: 204,
|
|
31
|
+
headers: _objectSpread(_objectSpread({}, baseHeaders), {}, {
|
|
32
|
+
"Cache-Control": "public, max-age=" + DEFAULT_CACHE_MAX_AGE
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
37
|
+
try {
|
|
38
|
+
const {
|
|
39
|
+
data,
|
|
40
|
+
statusCode,
|
|
41
|
+
headers = {}
|
|
42
|
+
} = await eventHandler(event);
|
|
43
|
+
const isBuffer = Buffer.isBuffer(data);
|
|
44
|
+
const body = isBuffer ? data.toString("base64") : JSON.stringify({
|
|
45
|
+
error: false,
|
|
46
|
+
data,
|
|
47
|
+
message: null
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
isBase64Encoded: isBuffer,
|
|
51
|
+
statusCode: statusCode || 200,
|
|
52
|
+
headers: _objectSpread(_objectSpread({}, baseHeaders), headers),
|
|
53
|
+
body
|
|
54
|
+
};
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return {
|
|
57
|
+
statusCode: 500,
|
|
58
|
+
headers: baseHeaders,
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
error: true,
|
|
61
|
+
data: null,
|
|
62
|
+
message: e.message
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
66
67
|
};
|
|
67
68
|
|
|
68
|
-
exports.
|
|
69
|
+
exports.createHandler = createHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["createHandler.ts"],"names":["baseHeaders","DEFAULT_CACHE_MAX_AGE","createHandler","eventHandler","event","httpMethod","body","statusCode","headers","data","isBuffer","Buffer","toString","JSON","stringify","error","message","isBase64Encoded","e"],"mappings":";;;;;;;;;;;;;;;AAGA;AACA;AACA;AACA,MAAMA,WAA2B,GAAG;AAChC,iCAA+B,GADC;AAEhC,sCAAoC;AAFJ,CAApC;AAIA,MAAMC,qBAAqB,GAAG,QAA9B,C,CAAwC;;AAWjC,MAAMC,aAAa,GACtBC,YADyB,IAExB;AACD,SAAO,MAAOC,KAAP,IAAoB;AACvB,QAAIA,KAAK,CAACC,UAAN,KAAqB,SAAzB,EAAoC;AAChC,aAAO;AACHC,QAAAA,IAAI,EAAE,EADH;AAEHC,QAAAA,UAAU,EAAE,GAFT;AAGHC,QAAAA,OAAO,kCACAR,WADA;AAEH,2BAAiB,qBAAqBC;AAFnC;AAHJ,OAAP;AAQH;;AAED,QAAI;AACA,YAAM;AAAEQ,QAAAA,IAAF;AAAQF,QAAAA,UAAR;AAAoBC,QAAAA,OAAO,GAAG;AAA9B,UAAqC,MAAML,YAAY,CAACC,KAAD,CAA7D;AACA,YAAMM,QAAQ,GAAGC,MAAM,CAACD,QAAP,CAAgBD,IAAhB,CAAjB;AACA,YAAMH,IAAI,GAAGI,QAAQ,GACdD,IAAD,CAAiBG,QAAjB,CAA0B,QAA1B,CADe,GAEfC,IAAI,CAACC,SAAL,CAAe;AACXC,QAAAA,KAAK,EAAE,KADI;AAEXN,QAAAA,IAFW;AAGXO,QAAAA,OAAO,EAAE;AAHE,OAAf,CAFN;AAQA,aAAO;AACHC,QAAAA,eAAe,EAAEP,QADd;AAEHH,QAAAA,UAAU,EAAEA,UAAU,IAAI,GAFvB;AAGHC,QAAAA,OAAO,kCAAOR,WAAP,GAAuBQ,OAAvB,CAHJ;AAIHF,QAAAA;AAJG,OAAP;AAMH,KAjBD,CAiBE,OAAOY,CAAP,EAAU;AACR,aAAO;AACHX,QAAAA,UAAU,EAAE,GADT;AAEHC,QAAAA,OAAO,EAAER,WAFN;AAGHM,QAAAA,IAAI,EAAEO,IAAI,CAACC,SAAL,CAAe;AACjBC,UAAAA,KAAK,EAAE,IADU;AAEjBN,UAAAA,IAAI,EAAE,IAFW;AAGjBO,UAAAA,OAAO,EAAEE,CAAC,CAACF;AAHM,SAAf;AAHH,OAAP;AASH;AACJ,GAxCD;AAyCH,CA5CM","sourcesContent":["import { HandlerEventArgs, HandlerHeaders } from \"~/handlers/types\";\nimport { Body } from \"aws-sdk/clients/s3\";\n\n/**\n * We need to respond with adequate CORS headers.\n */\nconst baseHeaders: HandlerHeaders = {\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Credentials\": true\n};\nconst DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year\n\ninterface EventHandlerResponse {\n data: Body | null;\n statusCode?: number;\n headers: HandlerHeaders;\n}\nexport interface EventHandlerCallable<T> {\n (event: T): Promise<EventHandlerResponse>;\n}\n\nexport const createHandler = <T extends HandlerEventArgs>(\n eventHandler: EventHandlerCallable<T>\n) => {\n return async (event: T) => {\n if (event.httpMethod === \"OPTIONS\") {\n return {\n body: \"\",\n statusCode: 204,\n headers: {\n ...baseHeaders,\n \"Cache-Control\": \"public, max-age=\" + DEFAULT_CACHE_MAX_AGE\n }\n };\n }\n\n try {\n const { data, statusCode, headers = {} } = await eventHandler(event);\n const isBuffer = Buffer.isBuffer(data);\n const body = isBuffer\n ? (data as Buffer).toString(\"base64\")\n : JSON.stringify({\n error: false,\n data,\n message: null\n });\n\n return {\n isBase64Encoded: isBuffer,\n statusCode: statusCode || 200,\n headers: { ...baseHeaders, ...headers },\n body\n };\n } catch (e) {\n return {\n statusCode: 500,\n headers: baseHeaders,\n body: JSON.stringify({\n error: true,\n data: null,\n message: e.message\n })\n };\n }\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getEnvironment.ts"],"names":["bucket","process","env","S3_BUCKET","region","AWS_REGION"],"mappings":";;;;;;;eAAe,OAAO;AAClBA,EAAAA,MAAM,EAAEC,OAAO,CAACC,GAAR,CAAYC,SADF;AAElBC,EAAAA,MAAM,EAAEH,OAAO,CAACC,GAAR,CAAYG;AAFF,CAAP,C","sourcesContent":["export default () => ({\n bucket: process.env.S3_BUCKET as string,\n region: process.env.AWS_REGION as string\n});\n"]}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export interface ObjectParamsResponse {
|
|
2
2
|
Bucket: string;
|
|
3
3
|
Key: string;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
|
+
declare const _default: (filename: string) => ObjectParamsResponse;
|
|
5
6
|
/**
|
|
6
7
|
* Returns website's Bucket and file's Key values.
|
|
7
|
-
* @param filename
|
|
8
|
-
* @returns {{Bucket: string, Key: string}}
|
|
9
8
|
*/
|
|
10
9
|
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["getObjectParams.ts"],"names":["filename","bucket","Bucket","Key"],"mappings":";;;;;;;;;AAAA;;AAMA;AACA;AACA;eACgBA,QAAD,IAA4C;AACvD,QAAM;AAAEC,IAAAA,MAAM,EAAEC;AAAV,MAAqB,8BAA3B;AAEA,SAAO;AACHA,IAAAA,MADG;AAEHC,IAAAA,GAAG,EAAG,GAAEH,QAAS;AAFd,GAAP;AAIH,C","sourcesContent":["import getEnvironment from \"./getEnvironment\";\n\nexport interface ObjectParamsResponse {\n Bucket: string;\n Key: string;\n}\n/**\n * Returns website's Bucket and file's Key values.\n */\nexport default (filename: string): ObjectParamsResponse => {\n const { bucket: Bucket } = getEnvironment();\n\n return {\n Bucket,\n Key: `${filename}`\n };\n};\n"]}
|
package/handlers/utils/index.js
CHANGED
|
@@ -5,12 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
});
|
|
8
|
+
var _exportNames = {
|
|
9
|
+
getEnvironment: true,
|
|
10
|
+
getObjectParams: true
|
|
11
|
+
};
|
|
14
12
|
Object.defineProperty(exports, "getEnvironment", {
|
|
15
13
|
enumerable: true,
|
|
16
14
|
get: function () {
|
|
@@ -26,6 +24,18 @@ Object.defineProperty(exports, "getObjectParams", {
|
|
|
26
24
|
|
|
27
25
|
var _getEnvironment = _interopRequireDefault(require("./getEnvironment"));
|
|
28
26
|
|
|
29
|
-
var _createHandler =
|
|
27
|
+
var _createHandler = require("./createHandler");
|
|
28
|
+
|
|
29
|
+
Object.keys(_createHandler).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
32
|
+
if (key in exports && exports[key] === _createHandler[key]) return;
|
|
33
|
+
Object.defineProperty(exports, key, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return _createHandler[key];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
var _getObjectParams = _interopRequireDefault(require("./getObjectParams"));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA","sourcesContent":["export { default as getEnvironment } from \"./getEnvironment\";\nexport * from \"./createHandler\";\nexport { default as getObjectParams } from \"./getObjectParams\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fm:base"
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/runtime": "7.
|
|
21
|
+
"@babel/runtime": "7.17.2",
|
|
22
22
|
"@commodo/fields": "1.1.2-beta.20",
|
|
23
|
-
"@webiny/api-i18n-content": "5.
|
|
24
|
-
"@webiny/api-security": "5.
|
|
25
|
-
"@webiny/api-tenancy": "5.
|
|
26
|
-
"@webiny/api-upgrade": "5.
|
|
27
|
-
"@webiny/error": "5.
|
|
28
|
-
"@webiny/handler": "5.
|
|
29
|
-
"@webiny/handler-args": "5.
|
|
30
|
-
"@webiny/handler-client": "5.
|
|
31
|
-
"@webiny/handler-graphql": "5.
|
|
32
|
-
"@webiny/plugins": "5.
|
|
33
|
-
"@webiny/project-utils": "5.
|
|
34
|
-
"@webiny/validation": "5.
|
|
35
|
-
"aws-sdk": "2.
|
|
23
|
+
"@webiny/api-i18n-content": "5.25.0-beta.0",
|
|
24
|
+
"@webiny/api-security": "5.25.0-beta.0",
|
|
25
|
+
"@webiny/api-tenancy": "5.25.0-beta.0",
|
|
26
|
+
"@webiny/api-upgrade": "5.25.0-beta.0",
|
|
27
|
+
"@webiny/error": "5.25.0-beta.0",
|
|
28
|
+
"@webiny/handler": "5.25.0-beta.0",
|
|
29
|
+
"@webiny/handler-args": "5.25.0-beta.0",
|
|
30
|
+
"@webiny/handler-client": "5.25.0-beta.0",
|
|
31
|
+
"@webiny/handler-graphql": "5.25.0-beta.0",
|
|
32
|
+
"@webiny/plugins": "5.25.0-beta.0",
|
|
33
|
+
"@webiny/project-utils": "5.25.0-beta.0",
|
|
34
|
+
"@webiny/validation": "5.25.0-beta.0",
|
|
35
|
+
"aws-sdk": "2.1086.0",
|
|
36
36
|
"commodo-fields-object": "1.0.6",
|
|
37
37
|
"mdbid": "1.0.0",
|
|
38
38
|
"object-hash": "1.3.1",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
46
46
|
"@babel/preset-env": "^7.16.4",
|
|
47
47
|
"@babel/preset-typescript": "^7.16.0",
|
|
48
|
-
"@webiny/api-i18n": "^5.
|
|
49
|
-
"@webiny/api-i18n-ddb": "^5.
|
|
50
|
-
"@webiny/cli": "^5.
|
|
48
|
+
"@webiny/api-i18n": "^5.25.0-beta.0",
|
|
49
|
+
"@webiny/api-i18n-ddb": "^5.25.0-beta.0",
|
|
50
|
+
"@webiny/cli": "^5.25.0-beta.0",
|
|
51
51
|
"jest": "^26.6.3",
|
|
52
52
|
"rimraf": "^3.0.2",
|
|
53
53
|
"ttypescript": "^1.5.12",
|
|
54
|
-
"typescript": "
|
|
54
|
+
"typescript": "4.5.5"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
]
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "2d3e7833575e88fde77d84e5490e746933a5ec28"
|
|
76
76
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["validation.ts"],"names":["FilePlugin","beforeCreate","data","FileModel","fileData","populate","validate","beforeUpdate","updatedFileData","beforeBatchCreate","input","fileInstance"],"mappings":";;;;;;;;;AAAA;;AACA;;eAEe,MAAoB,CAC/B,IAAIA,sBAAJ,CAAe;AACXC,EAAAA,YAAY,EAAE,OAAO;AAAEC,IAAAA;AAAF,GAAP,KAAoB;AAC9B,UAAMC,SAAS,GAAG,+BAAlB;AACA,UAAMC,QAAQ,GAAG,IAAID,SAAJ,GAAgBE,QAAhB,CAAyBH,IAAzB,CAAjB;AACA,UAAME,QAAQ,CAACE,QAAT,EAAN;AACH,GALU;AAMXC,EAAAA,YAAY,EAAE,OAAO;AAAEL,IAAAA;AAAF,GAAP,KAAoB;AAC9B,UAAMC,SAAS,GAAG,8BAAgB,KAAhB,CAAlB;AACA,UAAMK,eAAe,GAAG,IAAIL,SAAJ,GAAgBE,QAAhB,CAAyBH,IAAzB,CAAxB;AACA,UAAMM,eAAe,CAACF,QAAhB,EAAN;AACH,GAVU;AAWXG,EAAAA,iBAAiB,EAAE,OAAO;AAAEP,IAAAA;AAAF,GAAP,KAAoB;AACnC,UAAMC,SAAS,GAAG,+BAAlB;;AACA,SAAK,MAAMO,KAAX,IAAoBR,IAApB,EAA0B;AACtB,YAAMS,YAAY,GAAG,IAAIR,SAAJ,GAAgBE,QAAhB,CAAyBK,KAAzB,CAArB;AACA,YAAMC,YAAY,CAACL,QAAb,EAAN;AACH;AACJ;AAjBU,CAAf,CAD+B,C","sourcesContent":["import { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport createFileModel from \"~/plugins/crud/utils/createFileModel\";\n\nexport default (): FilePlugin[] => [\n new FilePlugin({\n beforeCreate: async ({ data }) => {\n const FileModel = createFileModel();\n const fileData = new FileModel().populate(data);\n await fileData.validate();\n },\n beforeUpdate: async ({ data }) => {\n const FileModel = createFileModel(false);\n const updatedFileData = new FileModel().populate(data);\n await updatedFileData.validate();\n },\n beforeBatchCreate: async ({ data }) => {\n const FileModel = createFileModel();\n for (const input of data) {\n const fileInstance = new FileModel().populate(input);\n await fileInstance.validate();\n }\n }\n })\n];\n"]}
|
|
@@ -15,8 +15,6 @@ var _handlerGraphql = require("@webiny/handler-graphql");
|
|
|
15
15
|
|
|
16
16
|
var _apiSecurity = require("@webiny/api-security");
|
|
17
17
|
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
18
|
var _checkBasePermissions = _interopRequireDefault(require("./utils/checkBasePermissions"));
|
|
21
19
|
|
|
22
20
|
var _handler = require("@webiny/handler");
|
|
@@ -25,6 +23,8 @@ var _FilePlugin = require("../definitions/FilePlugin");
|
|
|
25
23
|
|
|
26
24
|
var _FilesStorageOperationsProviderPlugin = require("../definitions/FilesStorageOperationsProviderPlugin");
|
|
27
25
|
|
|
26
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
27
|
+
|
|
28
28
|
var _lifecycleEvents = require("./utils/lifecycleEvents");
|
|
29
29
|
|
|
30
30
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -317,7 +317,7 @@ const filesContextCrudPlugin = new _handler.ContextPlugin(async context => {
|
|
|
317
317
|
|
|
318
318
|
const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
|
|
319
319
|
private: false,
|
|
320
|
-
locale: context
|
|
320
|
+
locale: getLocaleCode(context),
|
|
321
321
|
tenant: context.tenancy.getCurrentTenant().id
|
|
322
322
|
});
|
|
323
323
|
/**
|
|
@@ -392,12 +392,9 @@ const filesContextCrudPlugin = new _handler.ContextPlugin(async context => {
|
|
|
392
392
|
limit
|
|
393
393
|
}) {
|
|
394
394
|
await (0, _checkBasePermissions.default)(context);
|
|
395
|
-
const {
|
|
396
|
-
i18nContent
|
|
397
|
-
} = context;
|
|
398
395
|
const where = {
|
|
399
396
|
tenant: context.tenancy.getCurrentTenant().id,
|
|
400
|
-
locale:
|
|
397
|
+
locale: getLocaleCode(context)
|
|
401
398
|
};
|
|
402
399
|
const params = {
|
|
403
400
|
where,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["files.crud.ts"],"names":["BATCH_CREATE_MAX_FILES","checkOwnership","file","permission","context","own","identity","security","getIdentity","createdBy","id","NotAuthorizedError","getLocaleCode","i18nContent","WebinyError","locale","code","filesContextCrudPlugin","ContextPlugin","pluginType","FilesStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","storageOperations","provide","fileManager","filePlugins","FilePlugin","files","getFile","rwd","get","where","tenant","tenancy","getCurrentTenant","NotFoundError","createFile","input","tags","Array","isArray","meta","private","createdOn","Date","toISOString","displayName","webinyVersion","WEBINY_VERSION","data","result","create","ex","message","updateFile","original","update","deleteFile","delete","createFilesInBatch","inputs","length","map","results","createBatch","listFiles","params","limit","search","types","ids","after","initialWhere","sort","initialSort","type_in","tag_in","tag","toLowerCase","id_in","list","listTags","name"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AACA;;AAUA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,sBAAsB,GAAG,EAA/B;AAEA;AACA;AACA;;AACA,MAAMC,cAAc,GAAG,CAACC,IAAD,EAAaC,UAAb,EAAyCC,OAAzC,KAAyE;AAC5F,MAAI,CAAAD,UAAU,SAAV,IAAAA,UAAU,WAAV,YAAAA,UAAU,CAAEE,GAAZ,MAAoB,IAAxB,EAA8B;AAC1B,UAAMC,QAAQ,GAAGF,OAAO,CAACG,QAAR,CAAiBC,WAAjB,EAAjB;;AACA,QAAIN,IAAI,CAACO,SAAL,CAAeC,EAAf,KAAsBJ,QAAQ,CAACI,EAAnC,EAAuC;AACnC,YAAM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ACiC,OAAR,CAAgBC,gBAAhB,GAAmC5B,EADiB;AAE5DK,QAAAA,MAAM,EAAEH,aAAa,CAACR,OAAD;AAFuC,OAAhE;AAKA,YAAMkE,MAAM,GAAG;AACXnC,QAAAA,KADW;AAEXoC,QAAAA,KAAK,EAAEA,KAAK,IAAI,MAFL;AAGXI,QAAAA;AAHW,OAAf;;AAMA,UAAI;AACA,cAAM,CAACjC,IAAD,IAAS,MAAMhB,iBAAiB,CAACgB,IAAlB,CAAuB4B,MAAvB,CAArB;;AACA,YAAI3B,KAAK,CAACC,OAAN,CAAcF,IAAd,MAAwB,KAA5B,EAAmC;AAC/B,iBAAO,EAAP;AACH;AACD;AAChB;AACA;;;AACgB,eAAOA,IAAI,CAACmC,IAAL,EAAP;AACH,OATD,CASE,OAAOrB,EAAP,EAAW;AACT,cAAM,IAAI1C,cAAJ,CACF0C,EAAE,CAACC,OAAH,IAAc,4BADZ,EAEFD,EAAE,CAACxC,IAAH,IAAW,uBAFT,kCAIMwC,EAAE,CAACH,IAAH,IAAW,EAJjB;AAKEiB,UAAAA;AALF,WAAN;AAQH;AACJ;;AA3WuB,GAA5B;AA6WH,CApY8B,CAA/B;AAsYArD,sBAAsB,CAACqE,IAAvB,GAA8B,sBAA9B;eAEerE,sB","sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\nimport {\n CreatedBy,\n File,\n FileManagerContext,\n FileManagerFilesStorageOperationsListParamsWhere,\n FileManagerFilesStorageOperationsTagsParamsWhere,\n FilePermission,\n FilesListOpts\n} from \"~/types\";\nimport checkBasePermissions from \"./utils/checkBasePermissions\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { FilePlugin } from \"~/plugins/definitions/FilePlugin\";\nimport { FilesStorageOperationsProviderPlugin } from \"~/plugins/definitions/FilesStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { runLifecycleEvent } from \"~/plugins/crud/utils/lifecycleEvents\";\n\nconst BATCH_CREATE_MAX_FILES = 20;\n\n/**\n * If permission is limited to \"own\" files only, check that current identity owns the file.\n */\nconst checkOwnership = (file: File, permission: FilePermission, context: FileManagerContext) => {\n if (permission?.own === true) {\n const identity = context.security.getIdentity();\n if (file.createdBy.id !== identity.id) {\n throw new NotAuthorizedError();\n }\n }\n};\n\nconst getLocaleCode = (context: FileManagerContext): string => {\n if (!context.i18nContent) {\n throw new WebinyError(\n \"Missing i18nContent on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT\"\n );\n } else if (!context.i18nContent.locale) {\n throw new WebinyError(\n \"Missing i18nContent.locale on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE\"\n );\n } else if (!context.i18nContent.locale.code) {\n throw new WebinyError(\n \"Missing i18nContent.locale.code on the FileManagerContext.\",\n \"MISSING_I18N_CONTENT_LOCALE_CODE\"\n );\n }\n return context.i18nContent.locale.code;\n};\n\nconst filesContextCrudPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = FilesStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<FilesStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const filePlugins = context.plugins.byType<FilePlugin>(FilePlugin.type);\n\n context.fileManager.files = {\n async getFile(id: string) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n return file;\n },\n async createFile(input) {\n await checkBasePermissions(context, { rwd: \"w\" });\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n\n const id = mdbid();\n\n const file: File = {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n id,\n meta: {\n private: false,\n ...(input.meta || {})\n },\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeCreate\", {\n context,\n plugins: filePlugins,\n data: file\n });\n const result = await storageOperations.create({\n file\n });\n await runLifecycleEvent(\"afterCreate\", {\n context,\n plugins: filePlugins,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a file.\",\n ex.code || \"CREATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n file\n }\n );\n }\n },\n async updateFile(id, input) {\n const permission = await checkBasePermissions(context, { rwd: \"w\" });\n\n const original = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n\n if (!original) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(original, permission, context);\n\n const file: File = {\n ...original,\n ...input,\n tags: Array.isArray(input.tags)\n ? input.tags\n : Array.isArray(original.tags)\n ? original.tags\n : [],\n id: original.id,\n webinyVersion: context.WEBINY_VERSION\n };\n\n try {\n await runLifecycleEvent(\"beforeUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file\n });\n const result = await storageOperations.update({\n original,\n file\n });\n await runLifecycleEvent(\"afterUpdate\", {\n context,\n plugins: filePlugins,\n original,\n data: file,\n file: result\n });\n return result;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update a file.\",\n ex.code || \"UPDATE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n original,\n file\n }\n );\n }\n },\n async deleteFile(id) {\n const permission = await checkBasePermissions(context, { rwd: \"d\" });\n\n const file = await storageOperations.get({\n where: {\n id,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n }\n });\n if (!file) {\n throw new NotFoundError(`File with id \"${id}\" does not exists.`);\n }\n\n checkOwnership(file, permission, context);\n\n try {\n await runLifecycleEvent(\"beforeDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n await storageOperations.delete({\n file\n });\n await runLifecycleEvent(\"afterDelete\", {\n context,\n plugins: filePlugins,\n file\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete a file.\",\n ex.code || \"DELETE_FILE_ERROR\",\n {\n ...(ex.data || {}),\n id,\n file\n }\n );\n }\n\n return true;\n },\n async createFilesInBatch(inputs) {\n if (!Array.isArray(inputs)) {\n throw new WebinyError(`\"data\" must be an array.`, \"CREATE_FILES_NON_ARRAY\");\n }\n\n if (inputs.length === 0) {\n throw new WebinyError(\n `\"data\" argument must contain at least one file.`,\n \"CREATE_FILES_MIN_FILES\"\n );\n }\n\n if (inputs.length > BATCH_CREATE_MAX_FILES) {\n throw new WebinyError(\n `\"data\" argument must not contain more than ${BATCH_CREATE_MAX_FILES} files.`,\n \"CREATE_FILES_MAX_FILES\"\n );\n }\n\n await checkBasePermissions(context, { rwd: \"w\" });\n\n const identity = context.security.getIdentity();\n const tenant = context.tenancy.getCurrentTenant();\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n const files: File[] = inputs.map(input => {\n return {\n ...input,\n tags: Array.isArray(input.tags) ? input.tags : [],\n meta: {\n private: false,\n ...(input.meta || {})\n },\n id: mdbid(),\n tenant: tenant.id,\n createdOn: new Date().toISOString(),\n createdBy,\n locale: getLocaleCode(context),\n webinyVersion: context.WEBINY_VERSION\n };\n });\n\n try {\n await runLifecycleEvent(\"beforeBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files\n });\n const results = await storageOperations.createBatch({\n files\n });\n await runLifecycleEvent(\"afterBatchCreate\", {\n context,\n plugins: filePlugins,\n data: files,\n files: results\n });\n return results;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create a batch of files.\",\n ex.code || \"CREATE_FILES_ERROR\",\n {\n ...(ex.data || {}),\n files\n }\n );\n }\n },\n async listFiles(params: FilesListOpts = {}) {\n const permission = await checkBasePermissions(context, { rwd: \"r\" });\n\n const {\n limit = 40,\n search = \"\",\n types = [],\n tags = [],\n ids = [],\n after = null,\n where: initialWhere,\n sort: initialSort\n } = params;\n\n const where: FileManagerFilesStorageOperationsListParamsWhere = {\n ...initialWhere,\n private: false,\n locale: getLocaleCode(context),\n tenant: context.tenancy.getCurrentTenant().id\n };\n /**\n * Always override the createdBy received from the user, if any.\n */\n if (permission.own === true) {\n const identity = context.security.getIdentity();\n where.createdBy = identity.id;\n }\n /**\n * We need to map the old GraphQL definition to the new one.\n * That GQL definition is marked as deprecated.\n */\n /**\n * To have standardized where objects across the applications, we transform the types into type_in.\n */\n if (Array.isArray(types) && types.length > 0 && !where.type_in) {\n where.type_in = types;\n }\n /**\n * We are assigning search to tag and name search.\n * This should be treated as OR condition in the storage operations.\n */\n if (search && !where.search) {\n where.search = search;\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(tags) && tags.length > 0 && !where.tag_in) {\n where.tag_in = tags.map(tag => tag.toLowerCase());\n }\n /**\n * Same as on types/type_in.\n */\n if (Array.isArray(ids) && ids.length > 0 && !where.id_in) {\n where.id_in = ids;\n }\n\n const sort =\n Array.isArray(initialSort) && initialSort.length > 0 ? initialSort : [\"id_DESC\"];\n try {\n return await storageOperations.list({\n where,\n after,\n limit,\n sort\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list files by given parameters.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n where,\n after,\n limit,\n sort\n }\n );\n }\n },\n async listTags({ after, limit }) {\n await checkBasePermissions(context);\n\n const where: FileManagerFilesStorageOperationsTagsParamsWhere = {\n tenant: context.tenancy.getCurrentTenant().id,\n locale: getLocaleCode(context)\n };\n\n const params = {\n where,\n limit: limit || 100000,\n after\n };\n\n try {\n const [tags] = await storageOperations.tags(params);\n if (Array.isArray(tags) === false) {\n return [];\n }\n /**\n * just to keep it standardized, sort by the tag ASC\n */\n return tags.sort();\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not search for tags.\",\n ex.code || \"FILE_TAG_SEARCH_ERROR\",\n {\n ...(ex.data || {}),\n params\n }\n );\n }\n }\n };\n});\n\nfilesContextCrudPlugin.name = \"FileManagerFilesCrud\";\n\nexport default filesContextCrudPlugin;\n"]}
|
|
@@ -23,6 +23,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
23
23
|
|
|
24
24
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
25
|
|
|
26
|
+
// TODO @ts-refactor verify that this is not used and remove it
|
|
26
27
|
const SETTINGS_KEY = "file-manager";
|
|
27
28
|
exports.SETTINGS_KEY = SETTINGS_KEY;
|
|
28
29
|
const CreateDataModel = (0, _fields.withFields)({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["settings.crud.ts"],"names":["SETTINGS_KEY","CreateDataModel","uploadMinFileSize","value","validation","create","uploadMaxFileSize","srcPrefix","endsWith","UpdateDataModel","settingsCrudContextPlugin","ContextPlugin","context","pluginType","SettingsStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","settings","getSettings","get","createSettings","data","populate","validate","settingsData","toJSON","updateSettings","updatedValue","existingSettings","updatedSettings","onlyDirty","update","original","deleteSettings","delete","name"],"mappings":";;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA;AACO,MAAMA,YAAY,GAAG,cAArB;;AAEP,MAAMC,eAAe,GAAG,wBAAW;AAC/BC,EAAAA,iBAAiB,EAAE,oBAAO;AAAEC,IAAAA,KAAK,EAAE,CAAT;AAAYC,IAAAA,UAAU,EAAEA,uBAAWC,MAAX,CAAkB,OAAlB;AAAxB,GAAP,CADY;AAE/BC,EAAAA,iBAAiB,EAAE,oBAAO;AAAEH,IAAAA,KAAK,EAAE;AAAT,GAAP,CAFY;AAG/BI,EAAAA,SAAS,EAAE,mBAAOJ,KAAD,IAAoB;AACjC;AACA,QAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC3B,aAAOA,KAAK,CAACK,QAAN,CAAe,GAAf,IAAsBL,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;AACH;;AACD,WAAOA,KAAP;AACH,GANU,EAMR,oBAAO;AAAEA,IAAAA,KAAK,EAAE;AAAT,GAAP,CANQ;AAHoB,CAAX,GAAxB;AAYA,MAAMM,eAAe,GAAG,wBAAW;AAC/BP,EAAAA,iBAAiB,EAAE,oBAAO;AACtBE,IAAAA,UAAU,EAAEA,uBAAWC,MAAX,CAAkB,OAAlB;AADU,GAAP,CADY;AAI/BC,EAAAA,iBAAiB,EAAE,qBAJY;AAK/BC,EAAAA,SAAS,EAAE,mBAAOJ,KAAD,IAAoB;AACjC;AACA,QAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC3B,aAAOA,KAAK,CAACK,QAAN,CAAe,GAAf,IAAsBL,KAAtB,GAA8BA,KAAK,GAAG,GAA7C;AACH;;AACD,WAAOA,KAAP;AACH,GANU,EAMR,qBANQ;AALoB,CAAX,GAAxB;AAcA,MAAMO,yBAAyB,GAAG,IAAIC,sBAAJ,CAAsC,MAAMC,OAAN,IAAiB;AACrF,QAAMC,UA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MAAb,CAAoB;AAC5EK,QAAAA,SAAS,EAAE;AADiE,OAApB,CAA5D;AAIA,aAAOhB,iBAAiB,CAACiB,MAAlB,CAAyB;AAC5BC,QAAAA,QAAQ,EAAEJ,gBADkB;AAE5BP,QAAAA,IAAI,kCACGO,gBADH,GAEGC,eAFH;AAFwB,OAAzB,CAAP;AAOH,KA/B0B;;AAgC3B,UAAMI,cAAN,GAAuB;AACnB,YAAMnB,iBAAiB,CAACoB,MAAlB,EAAN;AAEA,aAAO,IAAP;AACH;;AApC0B,GAA/B;AAsCH,CA3DiC,CAAlC;AA6DA/B,yBAAyB,CAACgC,IAA1B,GAAiC,wBAAjC;eAEehC,yB","sourcesContent":["/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport { FileManagerContext, FileManagerSettings } from \"~/types\";\nimport { SettingsStorageOperationsProviderPlugin } from \"~/plugins/definitions/SettingsStorageOperationsProviderPlugin\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/handler\";\n\n// TODO @ts-refactor verify that this is not used and remove it\nexport const SETTINGS_KEY = \"file-manager\";\n\nconst CreateDataModel = withFields({\n uploadMinFileSize: number({ value: 0, validation: validation.create(\"gte:0\") }),\n uploadMaxFileSize: number({ value: 26214401 }),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string({ value: \"/files/\" }))\n})();\n\nconst UpdateDataModel = withFields({\n uploadMinFileSize: number({\n validation: validation.create(\"gte:0\")\n }),\n uploadMaxFileSize: number(),\n srcPrefix: onSet((value?: string) => {\n // Make sure srcPrefix always ends with forward slash.\n if (typeof value === \"string\") {\n return value.endsWith(\"/\") ? value : value + \"/\";\n }\n return value;\n })(string())\n})();\n\nconst settingsCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SettingsStorageOperationsProviderPlugin.type;\n\n const providerPlugin = context.plugins\n .byType<SettingsStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n context.fileManager.settings = {\n async getSettings() {\n return storageOperations.get();\n },\n async createSettings(data) {\n const settings = new CreateDataModel().populate(data);\n await settings.validate();\n\n const settingsData: FileManagerSettings = await settings.toJSON();\n\n return storageOperations.create({\n data: settingsData\n });\n },\n async updateSettings(data) {\n const updatedValue = new UpdateDataModel().populate(data);\n await updatedValue.validate();\n\n const existingSettings = (await storageOperations.get()) as FileManagerSettings;\n\n const updatedSettings: Partial<FileManagerSettings> = await updatedValue.toJSON({\n onlyDirty: true\n });\n\n return storageOperations.update({\n original: existingSettings,\n data: {\n ...existingSettings,\n ...updatedSettings\n }\n });\n },\n async deleteSettings() {\n await storageOperations.delete();\n\n return true;\n }\n };\n});\n\nsettingsCrudContextPlugin.name = \"FileMangerSettingsCrud\";\n\nexport default settingsCrudContextPlugin;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["system.crud.ts"],"names":["systemCrudContextPlugin","ContextPlugin","context","pluginType","SystemStorageOperationsProviderPlugin","type","providerPlugin","plugins","byType","find","WebinyError","storageOperations","provide","fileManager","getTenantId","tenancy","getCurrentTenant","id","system","getVersion","get","version","setVersion","data","tenant","update","original","ex","create","install","srcPrefix","identity","security","getIdentity","NotAuthorizedError","installationPlugins","InstallationPlugin","settings","createSettings","WEBINY_VERSION","upgrade","upgradePlugins","filter","pl","app","plugin","deployedVersion","installedAppVersion","upgradeToVersion","apply","name"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,M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HE,CAAN;AAQA,YAAMW,WAAW,CAACwB,QAAZ,CAAqBC,cAArB,CAAoCf,IAApC,CAAN;AAEA,YAAMV,WAAW,CAACK,MAAZ,CAAmBI,UAAnB,CAA8BpB,OAAO,CAACqC,cAAtC,CAAN;AAEA,YAAM,6BACFJ,mBADE,EAEF,cAFE,EAGF;AACIjC,QAAAA;AADJ,OAHE,CAAN;AAQA,aAAO,IAAP;AACH,KA7FwB;;AA8FzB,UAAMsC,OAAN,CAAcnB,OAAd,EAAuB;AACnB,YAAMU,QAAQ,GAAG7B,OAAO,CAAC8B,QAAR,CAAiBC,WAAjB,EAAjB;;AACA,UAAI,CAACF,QAAL,EAAe;AACX,cAAM,IAAIG,+BAAJ,EAAN;AACH;;AAED,YAAMO,cAAc,GAAGvC,OAAO,CAACK,OAAR,CAClBC,MADkB,CACI,aADJ,EAElBkC,MAFkB,CAEXC,EAAE,IAAIA,EAAE,CAACC,GAAH,KAAW,cAFN,CAAvB;AAIA,YAAMC,MAAM,GAAG,qCAAoB;AAC/BC,QAAAA,eAAe,EAAE5C,OAAO,CAACqC,cADM;AAE/BQ,QAAAA,mBAAmB,EAAE,MAAM,KAAK5B,UAAL,EAFI;AAG/BsB,QAAAA,cAH+B;AAI/BO,QAAAA,gBAAgB,EAAE3B;AAJa,OAApB,CAAf;AAOA,YAAMwB,MAAM,CAACI,KAAP,CAAa/C,OAAb,CAAN,CAjBmB,CAmBnB;;AACA,YAAMA,OAAO,CAACW,WAAR,CAAoBK,MAApB,CAA2BI,UAA3B,CAAsCD,OAAtC,CAAN;AAEA,aAAO,IAAP;AACH;;AArHwB,GAA7B;AAuHH,CA/I+B,CAAhC;AAiJArB,uBAAuB,CAACkD,IAAxB,GAA+B,uBAA/B;eAEelD,uB","sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport { getApplicablePlugin } from \"@webiny/api-upgrade\";\nimport { FileManagerContext, FileManagerSettings, FileManagerSystem } from \"~/types\";\nimport { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/handler\";\nimport { executeCallbacks } from \"~/utils\";\nimport { InstallationPlugin } from \"~/plugins/definitions/InstallationPlugin\";\nimport { SystemStorageOperationsProviderPlugin } from \"~/plugins/definitions/SystemStorageOperationsProviderPlugin\";\n\nconst systemCrudContextPlugin = new ContextPlugin<FileManagerContext>(async context => {\n const pluginType = SystemStorageOperationsProviderPlugin.type;\n const providerPlugin = context.plugins\n .byType<SystemStorageOperationsProviderPlugin>(pluginType)\n .find(() => true);\n\n if (!providerPlugin) {\n throw new WebinyError(`Missing \"${pluginType}\" plugin.`, \"PLUGIN_NOT_FOUND\", {\n type: pluginType\n });\n }\n\n const storageOperations = await providerPlugin.provide({\n context\n });\n\n if (!context.fileManager) {\n context.fileManager = {} as any;\n }\n\n const getTenantId = (): string => {\n return context.tenancy.getCurrentTenant().id;\n };\n\n context.fileManager.system = {\n async getVersion() {\n const system = await storageOperations.get();\n\n return system ? system.version : null;\n },\n async setVersion(version: string) {\n const system = await storageOperations.get();\n\n if (system) {\n const data: FileManagerSystem = {\n ...system,\n tenant: system.tenant || getTenantId(),\n version\n };\n try {\n await storageOperations.update({\n original: system,\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\n \"Could not update the system data.\",\n \"SYSTEM_UPDATE_ERROR\",\n {\n data\n }\n );\n }\n }\n\n const data: FileManagerSystem = {\n version,\n tenant: getTenantId()\n };\n try {\n await storageOperations.create({\n data\n });\n return;\n } catch (ex) {\n throw new WebinyError(\"Could not create the system data.\", \"SYSTEM_CREATE_ERROR\", {\n data\n });\n }\n },\n async install({ srcPrefix }) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n const { fileManager } = context;\n const version = await fileManager.system.getVersion();\n\n if (version) {\n throw new WebinyError(\n \"File Manager is already installed.\",\n \"FILES_INSTALL_ABORTED\"\n );\n }\n\n const data: Partial<FileManagerSettings> = {};\n\n if (srcPrefix) {\n data.srcPrefix = srcPrefix;\n }\n\n const installationPlugins = context.plugins.byType<InstallationPlugin>(\n InstallationPlugin.type\n );\n\n await executeCallbacks<InstallationPlugin[\"beforeInstall\"]>(\n installationPlugins,\n \"beforeInstall\",\n {\n context\n }\n );\n\n await fileManager.settings.createSettings(data);\n\n await fileManager.system.setVersion(context.WEBINY_VERSION);\n\n await executeCallbacks<InstallationPlugin[\"afterInstall\"]>(\n installationPlugins,\n \"afterInstall\",\n {\n context\n }\n );\n\n return true;\n },\n async upgrade(version) {\n const identity = context.security.getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const upgradePlugins = context.plugins\n .byType<UpgradePlugin>(\"api-upgrade\")\n .filter(pl => pl.app === \"file-manager\");\n\n const plugin = getApplicablePlugin({\n deployedVersion: context.WEBINY_VERSION,\n installedAppVersion: await this.getVersion(),\n upgradePlugins,\n upgradeToVersion: version\n });\n\n await plugin.apply(context);\n\n // Store new app version\n await context.fileManager.system.setVersion(version);\n\n return true;\n }\n };\n});\n\nsystemCrudContextPlugin.name = \"FileManagerSystemCrud\";\n\nexport default systemCrudContextPlugin;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["checkBasePermissions.ts"],"names":["context","check","i18nContent","checkI18NContentPermission","filePermission","security","getPermission","NotAuthorizedError","rwd","hasRwd","filesFilePermission","includes"],"mappings":";;;;;;;AACA;;eAEe,OACXA,OADW,EAEXC,KAAuB,GAAG,EAFf,KAGe;AAC1B,QAAMD,OAAO,CAACE,WAAR,CAAoBC,0BAApB,EAAN;AACA,QAAMC,cAAc,GAAG,MAAMJ,OAAO,CAACK,QAAR,CAAiBC,aAAjB,CAA+C,SAA/C,CAA7B;;AACA,MAAI,CAACF,cAAL,EAAqB;AACjB,UAAM,IAAIG,+BAAJ,EAAN;AACH;;AACD,MAAIN,KAAK,CAACO,GAAN,IAAa,CAACC,MAAM,CAACL,cAAD,EAAiBH,KAAK,CAACO,GAAvB,CAAxB,EAAqD;AACjD,UAAM,IAAID,+BAAJ,EAAN;AACH;;AAED,SAAOH,cAAP;AACH,C;;;;AAED,MAAMK,MAAM,GAAG,CAACC,mBAAD,EAAsCF,GAAtC,KAA+D;AAC1E,MAAI,OAAOE,mBAAmB,CAACF,GAA3B,KAAmC,QAAvC,EAAiD;AAC7C,WAAO,IAAP;AACH;;AAED,SAAOE,mBAAmB,CAACF,GAApB,CAAwBG,QAAxB,CAAiCH,GAAjC,CAAP;AACH,CAND","sourcesContent":["import { FileManagerContext, FilePermission } from \"~/types\";\nimport { NotAuthorizedError } from \"@webiny/api-security\";\n\nexport default async (\n context: FileManagerContext,\n check: { rwd?: string } = {}\n): Promise<FilePermission> => {\n await context.i18nContent.checkI18NContentPermission();\n const filePermission = await context.security.getPermission<FilePermission>(\"fm.file\");\n if (!filePermission) {\n throw new NotAuthorizedError();\n }\n if (check.rwd && !hasRwd(filePermission, check.rwd)) {\n throw new NotAuthorizedError();\n }\n\n return filePermission;\n};\n\nconst hasRwd = (filesFilePermission: FilePermission, rwd: string): boolean => {\n if (typeof filesFilePermission.rwd !== \"string\") {\n return true;\n }\n\n return filesFilePermission.rwd.includes(rwd);\n};\n"]}
|
|
@@ -11,6 +11,19 @@ var _commodoFieldsObject = require("commodo-fields-object");
|
|
|
11
11
|
|
|
12
12
|
var _validation = require("@webiny/validation");
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Package @commodo/fields does not have types
|
|
16
|
+
*/
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Package commodo-fields-object does not have types
|
|
21
|
+
*/
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* TODO @ts-refactor change for JOI or some other validation library
|
|
26
|
+
*/
|
|
14
27
|
var _default = (create = true) => {
|
|
15
28
|
return (0, _fields.withFields)({
|
|
16
29
|
key: (0, _fields.string)({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["createFileModel.ts"],"names":["create","key","validation","name","size","type","meta","value","private","tags","Array","isArray","map","item","toLowerCase","list","length","Error","i","tag"],"mappings":";;;;;;;AAIA;;AAKA;;AACA;;AAVA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAIA;AACA;AACA;eACe,CAACA,MAAM,GAAG,IAAV,KAAmB;AAC9B,SAAO,wBAAW;AACdC,IAAAA,GAAG,EAAE,oBAAO;AACRC,MAAAA,UAAU,EAAEA,uBAAWF,MAAX,CAAmB,GAAEA,MAAM,GAAG,WAAH,GAAiB,EAAG,gBAA/C;AADJ,KAAP,CADS;AAIdG,IAAAA,IAAI,EAAE,oBAAO;AAAED,MAAAA,UAAU,EAAEA,uBAAWF,MAAX,CAAkB,gBAAlB;AAAd,KAAP,CAJQ;AAKdI,IAAAA,IAAI,EAAE,qBALQ;AAMdC,IAAAA,IAAI,EAAE,oBAAO;AAAEH,MAAAA,UAAU,EAAEA,uBAAWF,MAAX,CAAkB,eAAlB;AAAd,KAAP,CANQ;AAOdM,IAAAA,IAAI,EAAE,iCAAO;AAAEC,MAAAA,KAAK,EAAE;AAAEC,QAAAA,OAAO,EAAE;AAAX;AAAT,KAAP,CAPQ;AAQdC,IAAAA,IAAI,EAAE,mBAAOF,KAAD,IAAqB;AAC7B,UAAI,CAACG,KAAK,CAACC,OAAN,CAAcJ,KAAd,CAAL,EAA2B;AACvB,eAAO,IAAP;AACH;;AAED,aAAOA,KAAK,CAACK,GAAN,CAAUC,IAAI,IAAIA,IAAI,CAACC,WAAL,EAAlB,CAAP;AACH,KANK,EAOF,oBAAO;AACHC,MAAAA,IAAI,EAAE,IADH;AAEHb,MAAAA,UAAU,EAAGO,IAAD,IAAoB;AAC5B,YAAI,CAACC,KAAK,CAACC,OAAN,CAAcF,IAAd,CAAL,EAA0B;AACtB;AACH;;AAED,YAAIA,IAAI,CAACO,MAAL,GAAc,EAAlB,EAAsB;AAClB,gBAAMC,KAAK,CAAC,mCAAD,CAAX;AACH;;AAED,aAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGT,IAAI,CAACO,MAAzB,EAAiCE,CAAC,EAAlC,EAAsC;AAClC,gBAAMC,GAAG,GAAGV,IAAI,CAACS,CAAD,CAAhB;;AACA,cAAI,OAAOC,GAAP,KAAe,QAAnB,EAA6B;AACzB,kBAAMF,KAAK,CAAC,4BAAD,CAAX;AACH;;AAED,cAAIE,GAAG,CAACH,MAAJ,GAAa,EAAjB,EAAqB;AACjB,kBAAMC,KAAK,CAAE,OAAME,GAAI,mCAAZ,CAAX;AACH;AACJ;AACJ;AArBE,KAAP,CAPE;AARQ,GAAX,GAAP;AAwCH,C","sourcesContent":["/**\n * Package @commodo/fields does not have types\n */\n// @ts-ignore\nimport { withFields, string, number, onSet } from \"@commodo/fields\";\n/**\n * Package commodo-fields-object does not have types\n */\n// @ts-ignore\nimport { object } from \"commodo-fields-object\";\nimport { validation } from \"@webiny/validation\";\n\n/**\n * TODO @ts-refactor change for JOI or some other validation library\n */\nexport default (create = true) => {\n return withFields({\n key: string({\n validation: validation.create(`${create ? \"required,\" : \"\"}maxLength:1000`)\n }),\n name: string({ validation: validation.create(\"maxLength:1000\") }),\n size: number(),\n type: string({ validation: validation.create(\"maxLength:255\") }),\n meta: object({ value: { private: false } }),\n tags: onSet((value: string[]) => {\n if (!Array.isArray(value)) {\n return null;\n }\n\n return value.map(item => item.toLowerCase());\n })(\n string({\n list: true,\n validation: (tags: string[]) => {\n if (!Array.isArray(tags)) {\n return;\n }\n\n if (tags.length > 15) {\n throw Error(\"You cannot set more than 15 tags.\");\n }\n\n for (let i = 0; i < tags.length; i++) {\n const tag = tags[i];\n if (typeof tag !== \"string\") {\n throw Error(\"Tag must be typeof string.\");\n }\n\n if (tag.length > 50) {\n throw Error(`Tag ${tag} is more than 50 characters long.`);\n }\n }\n }\n })\n )\n })();\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { FilePlugin } from "../../definitions/FilePlugin";
|
|
1
|
+
import { FilePlugin, FilePluginParams } from "../../definitions/FilePlugin";
|
|
2
2
|
import { FileManagerContext } from "../../../types";
|
|
3
|
-
export declare const runLifecycleEvent: (hook:
|
|
3
|
+
export declare const runLifecycleEvent: (hook: keyof FilePluginParams, params: {
|
|
4
4
|
context: FileManagerContext;
|
|
5
5
|
plugins: FilePlugin[];
|
|
6
6
|
} & Record<string, any>) => Promise<void>;
|
|
@@ -11,6 +11,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
|
|
|
11
11
|
|
|
12
12
|
const _excluded = ["plugins"];
|
|
13
13
|
|
|
14
|
+
// TODO @ts-refactor introduce pubsub methods
|
|
14
15
|
const runLifecycleEvent = async (hook, params) => {
|
|
15
16
|
const {
|
|
16
17
|
plugins
|
|
@@ -25,6 +26,10 @@ const runLifecycleEvent = async (hook, params) => {
|
|
|
25
26
|
if (!plugin[hook]) {
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.
|
|
31
|
+
*/
|
|
32
|
+
|
|
28
33
|
|
|
29
34
|
await plugin[hook](rest);
|
|
30
35
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["lifecycleEvents.ts"],"names":["runLifecycleEvent","hook","params","plugins","rest","length","plugin"],"mappings":";;;;;;;;;;;;;AAAA;AAIO,MAAMA,iBAAiB,GAAG,OAC7BC,IAD6B,EAE7BC,MAF6B,KAGb;AAChB,QAAM;AAAEC,IAAAA;AAAF,MAAuBD,MAA7B;AAAA,QAAoBE,IAApB,0CAA6BF,MAA7B;;AACA,MAAIC,OAAO,CAACE,MAAR,KAAmB,CAAvB,EAA0B;AACtB;AACH;;AACD,OAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;AAC1B,QAAI,CAACG,MAAM,CAACL,IAAD,CAAX,EAAmB;AACf;AACH;AACD;AACR;AACA;;;AACQ,UAAMK,MAAM,CAACL,IAAD,CAAN,CAAaG,IAAb,CAAN;AACH;AACJ,CAjBM","sourcesContent":["// TODO @ts-refactor introduce pubsub methods\nimport { FilePlugin, FilePluginParams } from \"~/plugins/definitions/FilePlugin\";\nimport { FileManagerContext } from \"~/types\";\n\nexport const runLifecycleEvent = async (\n hook: keyof FilePluginParams,\n params: { context: FileManagerContext; plugins: FilePlugin[] } & Record<string, any>\n): Promise<void> => {\n const { plugins, ...rest } = params;\n if (plugins.length === 0) {\n return;\n }\n for (const plugin of plugins) {\n if (!plugin[hook]) {\n continue;\n }\n /**\n * Keep any because we do not know which hook needs to be executed. This will be removed, so it does not matter.\n */\n await plugin[hook](rest as any);\n }\n};\n"]}
|