@webiny/api-file-manager 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +17 -0
- package/handlers/download/index.d.ts +3 -0
- package/handlers/download/index.js +125 -0
- package/handlers/manage/index.d.ts +3 -0
- package/handlers/manage/index.js +70 -0
- package/handlers/transform/index.d.ts +3 -0
- package/handlers/transform/index.js +96 -0
- package/handlers/transform/loaders/imageLoader.d.ts +13 -0
- package/handlers/transform/loaders/imageLoader.js +106 -0
- package/handlers/transform/loaders/index.d.ts +13 -0
- package/handlers/transform/loaders/index.js +13 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -0
- package/handlers/transform/loaders/sanitizeImageTransformations.js +51 -0
- package/handlers/transform/managers/imageManager.d.ts +9 -0
- package/handlers/transform/managers/imageManager.js +55 -0
- package/handlers/transform/managers/index.d.ts +9 -0
- package/handlers/transform/managers/index.js +13 -0
- package/handlers/transform/optimizeImage.d.ts +2 -0
- package/handlers/transform/optimizeImage.js +45 -0
- package/handlers/transform/transformImage.d.ts +9 -0
- package/handlers/transform/transformImage.js +30 -0
- package/handlers/transform/utils.d.ts +12 -0
- package/handlers/transform/utils.js +46 -0
- package/handlers/utils/createHandler.d.ts +24 -0
- package/handlers/utils/createHandler.js +68 -0
- package/handlers/utils/getEnvironment.d.ts +5 -0
- package/handlers/utils/getEnvironment.js +13 -0
- package/handlers/utils/getObjectParams.d.ts +10 -0
- package/handlers/utils/getObjectParams.js +27 -0
- package/handlers/utils/index.d.ts +3 -0
- package/handlers/utils/index.js +31 -0
- package/package.json +75 -0
- package/plugins/crud/files/validation.d.ts +3 -0
- package/plugins/crud/files/validation.js +41 -0
- package/plugins/crud/files.crud.d.ts +4 -0
- package/plugins/crud/files.crud.js +427 -0
- package/plugins/crud/settings.crud.d.ts +5 -0
- package/plugins/crud/settings.crud.js +115 -0
- package/plugins/crud/system.crud.d.ts +4 -0
- package/plugins/crud/system.crud.js +145 -0
- package/plugins/crud/utils/checkBasePermissions.d.ts +5 -0
- package/plugins/crud/utils/checkBasePermissions.js +33 -0
- package/plugins/crud/utils/createFileModel.d.ts +2 -0
- package/plugins/crud/utils/createFileModel.js +64 -0
- package/plugins/crud/utils/lifecycleEvents.d.ts +6 -0
- package/plugins/crud/utils/lifecycleEvents.js +33 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +22 -0
- package/plugins/definitions/FilePhysicalStoragePlugin.js +42 -0
- package/plugins/definitions/FilePlugin.d.ts +133 -0
- package/plugins/definitions/FilePlugin.js +64 -0
- package/plugins/definitions/FileStorageTransformPlugin.d.ts +34 -0
- package/plugins/definitions/FileStorageTransformPlugin.js +51 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +17 -0
- package/plugins/definitions/InstallationPlugin.d.ts +19 -0
- package/plugins/definitions/InstallationPlugin.js +40 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +17 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +9 -0
- package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +17 -0
- package/plugins/graphql.d.ts +4 -0
- package/plugins/graphql.js +274 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +24 -0
- package/plugins/storage/FileStorage.d.ts +31 -0
- package/plugins/storage/FileStorage.js +95 -0
- package/plugins/storage/index.d.ts +4 -0
- package/plugins/storage/index.js +22 -0
- package/types.d.ts +357 -0
- package/types.js +5 -0
- package/utils.d.ts +4 -0
- package/utils.js +16 -0
package/types.d.ts
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
import { BaseI18NContentContext } from "@webiny/api-i18n-content/types";
|
|
2
|
+
import { FileStorage } from "./plugins/storage/FileStorage";
|
|
3
|
+
import { TenancyContext } from "@webiny/api-tenancy/types";
|
|
4
|
+
import { SecurityContext, SecurityPermission } from "@webiny/api-security/types";
|
|
5
|
+
import { ContextInterface } from "@webiny/handler/types";
|
|
6
|
+
export interface FileManagerContext extends ContextInterface, SecurityContext, TenancyContext, BaseI18NContentContext {
|
|
7
|
+
fileManager: {
|
|
8
|
+
files: FilesCRUD;
|
|
9
|
+
settings: SettingsCRUD;
|
|
10
|
+
storage: FileStorage;
|
|
11
|
+
system: SystemCRUD;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface FilePermission extends SecurityPermission {
|
|
15
|
+
name: "fm.file";
|
|
16
|
+
rwd?: string;
|
|
17
|
+
own?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface File {
|
|
20
|
+
id: string;
|
|
21
|
+
key: string;
|
|
22
|
+
size: number;
|
|
23
|
+
type: string;
|
|
24
|
+
name: string;
|
|
25
|
+
meta: Record<string, any>;
|
|
26
|
+
tags: string[];
|
|
27
|
+
createdOn: string;
|
|
28
|
+
createdBy: CreatedBy;
|
|
29
|
+
/**
|
|
30
|
+
* Added with new storage operations refactoring.
|
|
31
|
+
*/
|
|
32
|
+
tenant: string;
|
|
33
|
+
locale: string;
|
|
34
|
+
webinyVersion: string;
|
|
35
|
+
/**
|
|
36
|
+
* User can add new fields to the File object so we must allow it in the types.
|
|
37
|
+
*/
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}
|
|
40
|
+
export interface CreatedBy {
|
|
41
|
+
id: string;
|
|
42
|
+
displayName: string;
|
|
43
|
+
type: string;
|
|
44
|
+
}
|
|
45
|
+
export interface FileInput {
|
|
46
|
+
key: string;
|
|
47
|
+
name: string;
|
|
48
|
+
size: number;
|
|
49
|
+
type: string;
|
|
50
|
+
meta: Record<string, any>;
|
|
51
|
+
tags: [string];
|
|
52
|
+
}
|
|
53
|
+
export interface FileListWhereParams {
|
|
54
|
+
search?: string;
|
|
55
|
+
type?: string;
|
|
56
|
+
type_in?: string[];
|
|
57
|
+
tag?: string;
|
|
58
|
+
tag_in?: string[];
|
|
59
|
+
tag_and_in?: string[];
|
|
60
|
+
id_in?: string[];
|
|
61
|
+
id?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface FilesListOpts {
|
|
64
|
+
search?: string;
|
|
65
|
+
types?: string[];
|
|
66
|
+
tags?: string[];
|
|
67
|
+
ids?: string[];
|
|
68
|
+
limit?: number;
|
|
69
|
+
after?: string;
|
|
70
|
+
where?: FileListWhereParams;
|
|
71
|
+
sort?: string[];
|
|
72
|
+
}
|
|
73
|
+
export interface FileListMeta {
|
|
74
|
+
cursor: string;
|
|
75
|
+
totalCount: number;
|
|
76
|
+
}
|
|
77
|
+
interface FilesCrudListTagsWhere {
|
|
78
|
+
tag?: string;
|
|
79
|
+
tag_contains?: string;
|
|
80
|
+
tag_in?: string[];
|
|
81
|
+
}
|
|
82
|
+
interface FilesCrudListTagsParams {
|
|
83
|
+
where?: FilesCrudListTagsWhere;
|
|
84
|
+
limit?: number;
|
|
85
|
+
after?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface FilesCRUD {
|
|
88
|
+
getFile(id: string): Promise<File>;
|
|
89
|
+
listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
|
|
90
|
+
listTags(params: FilesCrudListTagsParams): Promise<string[]>;
|
|
91
|
+
createFile(data: FileInput): Promise<File>;
|
|
92
|
+
updateFile(id: string, data: Partial<FileInput>): Promise<File>;
|
|
93
|
+
deleteFile(id: string): Promise<boolean>;
|
|
94
|
+
createFilesInBatch(data: FileInput[]): Promise<File[]>;
|
|
95
|
+
}
|
|
96
|
+
export interface SystemCRUD {
|
|
97
|
+
getVersion(): Promise<string>;
|
|
98
|
+
setVersion(version: string): Promise<void>;
|
|
99
|
+
install(args: {
|
|
100
|
+
srcPrefix: string;
|
|
101
|
+
}): Promise<boolean>;
|
|
102
|
+
upgrade(version: string, data?: Record<string, any>): Promise<boolean>;
|
|
103
|
+
}
|
|
104
|
+
export interface FileManagerSettings {
|
|
105
|
+
key: string;
|
|
106
|
+
uploadMinFileSize: number;
|
|
107
|
+
uploadMaxFileSize: number;
|
|
108
|
+
srcPrefix: string;
|
|
109
|
+
}
|
|
110
|
+
export interface FileManagerSystem {
|
|
111
|
+
version: string;
|
|
112
|
+
}
|
|
113
|
+
export declare type SettingsCRUD = {
|
|
114
|
+
getSettings(): Promise<FileManagerSettings>;
|
|
115
|
+
createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
|
|
116
|
+
updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
|
|
117
|
+
deleteSettings(): Promise<boolean>;
|
|
118
|
+
};
|
|
119
|
+
/********
|
|
120
|
+
* Storage operations
|
|
121
|
+
*******/
|
|
122
|
+
/**
|
|
123
|
+
* @category StorageOperations
|
|
124
|
+
* @category SystemStorageOperations
|
|
125
|
+
* @category SystemStorageOperationsParams
|
|
126
|
+
*/
|
|
127
|
+
export interface FileManagerSystemStorageOperationsUpdateParams {
|
|
128
|
+
/**
|
|
129
|
+
* The system data to be updated.
|
|
130
|
+
*/
|
|
131
|
+
original: FileManagerSystem;
|
|
132
|
+
/**
|
|
133
|
+
* The system data with the updated fields.
|
|
134
|
+
*/
|
|
135
|
+
data: FileManagerSystem;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @category StorageOperations
|
|
139
|
+
* @category SystemStorageOperations
|
|
140
|
+
* @category SystemStorageOperationsParams
|
|
141
|
+
*/
|
|
142
|
+
export interface FileManagerSystemStorageOperationsCreateParams {
|
|
143
|
+
/**
|
|
144
|
+
* The system fields.
|
|
145
|
+
*/
|
|
146
|
+
data: FileManagerSystem;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @category StorageOperations
|
|
150
|
+
* @category SystemStorageOperations
|
|
151
|
+
*/
|
|
152
|
+
export interface FileManagerSystemStorageOperations {
|
|
153
|
+
/**
|
|
154
|
+
* Get the FileManager system data.
|
|
155
|
+
*/
|
|
156
|
+
get: () => Promise<FileManagerSystem | null>;
|
|
157
|
+
/**
|
|
158
|
+
* Update the FileManager system data..
|
|
159
|
+
*/
|
|
160
|
+
update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;
|
|
161
|
+
/**
|
|
162
|
+
* Create the FileManagerSystemData
|
|
163
|
+
*/
|
|
164
|
+
create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* @category StorageOperations
|
|
168
|
+
* @category SettingsStorageOperations
|
|
169
|
+
* @category SettingsStorageOperationsParams
|
|
170
|
+
*/
|
|
171
|
+
export interface FileManagerSettingsStorageOperationsUpdateParams {
|
|
172
|
+
/**
|
|
173
|
+
* Original settings to be updated.
|
|
174
|
+
*/
|
|
175
|
+
original: FileManagerSettings;
|
|
176
|
+
/**
|
|
177
|
+
* The settings with the updated fields.
|
|
178
|
+
*/
|
|
179
|
+
data: FileManagerSettings;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @category StorageOperations
|
|
183
|
+
* @category SettingsStorageOperations
|
|
184
|
+
* @category SettingsStorageOperationsParams
|
|
185
|
+
*/
|
|
186
|
+
export interface FileManagerSettingsStorageOperationsCreateParams {
|
|
187
|
+
/**
|
|
188
|
+
* The settings fields.
|
|
189
|
+
*/
|
|
190
|
+
data: FileManagerSettings;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @category StorageOperations
|
|
194
|
+
* @category SettingsStorageOperations
|
|
195
|
+
*/
|
|
196
|
+
export interface FileManagerSettingsStorageOperations {
|
|
197
|
+
/**
|
|
198
|
+
* Get the FileManager system data.
|
|
199
|
+
*/
|
|
200
|
+
get: () => Promise<FileManagerSettings | null>;
|
|
201
|
+
/**
|
|
202
|
+
* Create the FileManagerSettingsData
|
|
203
|
+
*/
|
|
204
|
+
create: (params: FileManagerSettingsStorageOperationsCreateParams) => Promise<FileManagerSettings>;
|
|
205
|
+
/**
|
|
206
|
+
* Update the FileManager system data..
|
|
207
|
+
*/
|
|
208
|
+
update: (params: FileManagerSettingsStorageOperationsUpdateParams) => Promise<FileManagerSettings>;
|
|
209
|
+
/**
|
|
210
|
+
* Delete the existing settings.
|
|
211
|
+
*/
|
|
212
|
+
delete: () => Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @category StorageOperations
|
|
216
|
+
* @category FilesStorageOperations
|
|
217
|
+
* @category FilesStorageOperationsParams
|
|
218
|
+
*/
|
|
219
|
+
export interface FileManagerFilesStorageOperationsGetParams {
|
|
220
|
+
where: {
|
|
221
|
+
id: string;
|
|
222
|
+
tenant: string;
|
|
223
|
+
locale: string;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* @category StorageOperations
|
|
228
|
+
* @category FilesStorageOperations
|
|
229
|
+
* @category FilesStorageOperationsParams
|
|
230
|
+
*/
|
|
231
|
+
export interface FileManagerFilesStorageOperationsCreateParams {
|
|
232
|
+
file: File;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* @category StorageOperations
|
|
236
|
+
* @category FilesStorageOperations
|
|
237
|
+
* @category FilesStorageOperationsParams
|
|
238
|
+
*/
|
|
239
|
+
export interface FileManagerFilesStorageOperationsUpdateParams {
|
|
240
|
+
original: File;
|
|
241
|
+
file: File;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @category StorageOperations
|
|
245
|
+
* @category FilesStorageOperations
|
|
246
|
+
* @category FilesStorageOperationsParams
|
|
247
|
+
*/
|
|
248
|
+
export interface FileManagerFilesStorageOperationsDeleteParams {
|
|
249
|
+
file: File;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @category StorageOperations
|
|
253
|
+
* @category FilesStorageOperations
|
|
254
|
+
* @category FilesStorageOperationsParams
|
|
255
|
+
*/
|
|
256
|
+
export interface FileManagerFilesStorageOperationsCreateBatchParams {
|
|
257
|
+
files: File[];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @category StorageOperations
|
|
261
|
+
* @category FilesStorageOperations
|
|
262
|
+
* @category FilesStorageOperationsParams
|
|
263
|
+
*/
|
|
264
|
+
export interface FileManagerFilesStorageOperationsListParamsWhere {
|
|
265
|
+
id?: string;
|
|
266
|
+
id_in?: string[];
|
|
267
|
+
name?: string;
|
|
268
|
+
name_contains?: string;
|
|
269
|
+
tag?: string;
|
|
270
|
+
tag_contains?: string;
|
|
271
|
+
tag_in?: string[];
|
|
272
|
+
createdBy?: string;
|
|
273
|
+
locale: string;
|
|
274
|
+
tenant: string;
|
|
275
|
+
private?: boolean;
|
|
276
|
+
type?: string;
|
|
277
|
+
type_in?: string[];
|
|
278
|
+
search?: string;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @category StorageOperations
|
|
282
|
+
* @category FilesStorageOperations
|
|
283
|
+
* @category FilesStorageOperationsParams
|
|
284
|
+
*/
|
|
285
|
+
export interface FileManagerFilesStorageOperationsListParams {
|
|
286
|
+
where: FileManagerFilesStorageOperationsListParamsWhere;
|
|
287
|
+
sort: string[];
|
|
288
|
+
limit: number;
|
|
289
|
+
after: string | null;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* @category StorageOperations
|
|
293
|
+
* @category FilesStorageOperations
|
|
294
|
+
* @category FilesStorageOperationsParams
|
|
295
|
+
*/
|
|
296
|
+
interface FileManagerFilesStorageOperationsListResponseMeta {
|
|
297
|
+
hasMoreItems: boolean;
|
|
298
|
+
totalCount: number;
|
|
299
|
+
cursor: string;
|
|
300
|
+
}
|
|
301
|
+
export declare type FileManagerFilesStorageOperationsListResponse = [
|
|
302
|
+
File[],
|
|
303
|
+
FileManagerFilesStorageOperationsListResponseMeta
|
|
304
|
+
];
|
|
305
|
+
export declare type FileManagerFilesStorageOperationsTagsResponse = [
|
|
306
|
+
string[],
|
|
307
|
+
FileManagerFilesStorageOperationsListResponseMeta
|
|
308
|
+
];
|
|
309
|
+
export interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {
|
|
310
|
+
locale: string;
|
|
311
|
+
tenant: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* @category StorageOperations
|
|
315
|
+
* @category FilesStorageOperations
|
|
316
|
+
* @category FilesStorageOperationsParams
|
|
317
|
+
*/
|
|
318
|
+
export interface FileManagerFilesStorageOperationsTagsParams {
|
|
319
|
+
where: FileManagerFilesStorageOperationsTagsParamsWhere;
|
|
320
|
+
limit: number;
|
|
321
|
+
after?: string;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @category StorageOperations
|
|
325
|
+
* @category FilesStorageOperations
|
|
326
|
+
*/
|
|
327
|
+
export interface FileManagerFilesStorageOperations {
|
|
328
|
+
/**
|
|
329
|
+
* Get a single file with given ID from the storage.
|
|
330
|
+
*/
|
|
331
|
+
get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;
|
|
332
|
+
/**
|
|
333
|
+
* Insert the file data into the database.
|
|
334
|
+
*/
|
|
335
|
+
create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File | null>;
|
|
336
|
+
/**
|
|
337
|
+
* Update the file data in the database.
|
|
338
|
+
*/
|
|
339
|
+
update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File | null>;
|
|
340
|
+
/**
|
|
341
|
+
* Delete the file from the database.
|
|
342
|
+
*/
|
|
343
|
+
delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;
|
|
344
|
+
/**
|
|
345
|
+
* Store multiple files at once to the database.
|
|
346
|
+
*/
|
|
347
|
+
createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;
|
|
348
|
+
/**
|
|
349
|
+
* Get a list of files filtered by given parameters.
|
|
350
|
+
*/
|
|
351
|
+
list: (params: FileManagerFilesStorageOperationsListParams) => Promise<FileManagerFilesStorageOperationsListResponse>;
|
|
352
|
+
/**
|
|
353
|
+
* Get a list of all file tags filtered by given parameters.
|
|
354
|
+
*/
|
|
355
|
+
tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse>;
|
|
356
|
+
}
|
|
357
|
+
export {};
|
package/types.js
ADDED
package/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/types";
|
|
2
|
+
declare type CallbackFallback = (args: any) => void | Promise<void>;
|
|
3
|
+
export declare const executeCallbacks: <TCallbackFunction extends CallbackFallback = CallbackFallback>(plugins: Plugin[], hook: string, args: Parameters<TCallbackFunction>[0]) => Promise<void>;
|
|
4
|
+
export {};
|
package/utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.executeCallbacks = void 0;
|
|
7
|
+
|
|
8
|
+
const executeCallbacks = async (plugins, hook, args) => {
|
|
9
|
+
for (const plugin of plugins) {
|
|
10
|
+
if (typeof plugin[hook] === "function") {
|
|
11
|
+
await plugin[hook](args);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.executeCallbacks = executeCallbacks;
|