@webiny/api-file-manager 0.0.0-mt-2 → 0.0.0-unstable.13771d80a8

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.
Files changed (156) hide show
  1. package/createFileManager/checkBasePermissions.d.ts +5 -0
  2. package/createFileManager/checkBasePermissions.js +24 -0
  3. package/createFileManager/checkBasePermissions.js.map +1 -0
  4. package/createFileManager/files.crud.d.ts +3 -0
  5. package/createFileManager/files.crud.js +336 -0
  6. package/createFileManager/files.crud.js.map +1 -0
  7. package/createFileManager/filevalidation.disabled.d.ts +0 -0
  8. package/createFileManager/filevalidation.disabled.js +55 -0
  9. package/createFileManager/filevalidation.disabled.js.map +1 -0
  10. package/createFileManager/index.d.ts +13 -0
  11. package/createFileManager/index.js +20 -0
  12. package/createFileManager/index.js.map +1 -0
  13. package/createFileManager/settings.crud.d.ts +3 -0
  14. package/createFileManager/settings.crud.js +91 -0
  15. package/createFileManager/settings.crud.js.map +1 -0
  16. package/createFileManager/system.crud.d.ts +3 -0
  17. package/createFileManager/system.crud.js +86 -0
  18. package/createFileManager/system.crud.js.map +1 -0
  19. package/graphql/index.d.ts +3 -0
  20. package/graphql/index.js +277 -0
  21. package/graphql/index.js.map +1 -0
  22. package/handlers/download/byAlias.d.ts +6 -0
  23. package/handlers/download/byAlias.js +89 -0
  24. package/handlers/download/byAlias.js.map +1 -0
  25. package/handlers/download/byExactKey.d.ts +2 -0
  26. package/handlers/download/byExactKey.js +57 -0
  27. package/handlers/download/byExactKey.js.map +1 -0
  28. package/handlers/download/extractFileInformation.d.ts +9 -0
  29. package/handlers/download/extractFileInformation.js +20 -0
  30. package/handlers/download/extractFileInformation.js.map +1 -0
  31. package/handlers/download/getS3Object.d.ts +10 -0
  32. package/handlers/download/getS3Object.js +57 -0
  33. package/handlers/download/getS3Object.js.map +1 -0
  34. package/handlers/download/index.d.ts +2 -3
  35. package/handlers/download/index.js +20 -118
  36. package/handlers/download/index.js.map +1 -0
  37. package/handlers/manage/index.d.ts +5 -3
  38. package/handlers/manage/index.js +43 -58
  39. package/handlers/manage/index.js.map +1 -0
  40. package/handlers/transform/index.d.ts +2 -3
  41. package/handlers/transform/index.js +66 -78
  42. package/handlers/transform/index.js.map +1 -0
  43. package/handlers/transform/legacyUtils.d.ts +17 -0
  44. package/handlers/transform/legacyUtils.js +42 -0
  45. package/handlers/transform/legacyUtils.js.map +1 -0
  46. package/handlers/transform/loaders/imageLoader.d.ts +26 -9
  47. package/handlers/transform/loaders/imageLoader.js +13 -25
  48. package/handlers/transform/loaders/imageLoader.js.map +1 -0
  49. package/handlers/transform/loaders/index.d.ts +4 -9
  50. package/handlers/transform/loaders/index.js +1 -4
  51. package/handlers/transform/loaders/index.js.map +1 -0
  52. package/handlers/transform/loaders/sanitizeImageTransformations.d.ts +7 -3
  53. package/handlers/transform/loaders/sanitizeImageTransformations.js +24 -30
  54. package/handlers/transform/loaders/sanitizeImageTransformations.js.map +1 -0
  55. package/handlers/transform/managers/imageManager.d.ts +12 -6
  56. package/handlers/transform/managers/imageManager.js +37 -28
  57. package/handlers/transform/managers/imageManager.js.map +1 -0
  58. package/handlers/transform/managers/index.d.ts +2 -6
  59. package/handlers/transform/managers/index.js +1 -4
  60. package/handlers/transform/managers/index.js.map +1 -0
  61. package/handlers/transform/optimizeImage.d.ts +2 -1
  62. package/handlers/transform/optimizeImage.js +4 -7
  63. package/handlers/transform/optimizeImage.js.map +1 -0
  64. package/handlers/transform/transformImage.d.ts +5 -4
  65. package/handlers/transform/transformImage.js +4 -9
  66. package/handlers/transform/transformImage.js.map +1 -0
  67. package/handlers/transform/utils.d.ts +2 -2
  68. package/handlers/transform/utils.js +8 -18
  69. package/handlers/transform/utils.js.map +1 -0
  70. package/handlers/types.d.ts +8 -0
  71. package/handlers/types.js +5 -0
  72. package/handlers/types.js.map +1 -0
  73. package/handlers/utils/getEnvironment.js +0 -2
  74. package/handlers/utils/getEnvironment.js.map +1 -0
  75. package/handlers/utils/getObjectParams.d.ts +3 -4
  76. package/handlers/utils/getObjectParams.js +1 -7
  77. package/handlers/utils/getObjectParams.js.map +1 -0
  78. package/handlers/utils/index.d.ts +0 -1
  79. package/handlers/utils/index.js +1 -12
  80. package/handlers/utils/index.js.map +1 -0
  81. package/index.d.ts +6 -0
  82. package/index.js +68 -0
  83. package/index.js.map +1 -0
  84. package/package.json +29 -30
  85. package/plugins/FilePhysicalStoragePlugin.d.ts +21 -0
  86. package/plugins/FilePhysicalStoragePlugin.js +31 -0
  87. package/plugins/FilePhysicalStoragePlugin.js.map +1 -0
  88. package/plugins/FileStorageTransformPlugin.d.ts +34 -0
  89. package/plugins/FileStorageTransformPlugin.js +40 -0
  90. package/plugins/FileStorageTransformPlugin.js.map +1 -0
  91. package/plugins/crud/files/validation.js +1 -1
  92. package/plugins/crud/files/validation.js.map +1 -0
  93. package/plugins/crud/files.crud.d.ts +1 -1
  94. package/plugins/crud/files.crud.js +48 -44
  95. package/plugins/crud/files.crud.js.map +1 -0
  96. package/plugins/crud/settings.crud.d.ts +1 -1
  97. package/plugins/crud/settings.crud.js +10 -9
  98. package/plugins/crud/settings.crud.js.map +1 -0
  99. package/plugins/crud/system.crud.d.ts +1 -1
  100. package/plugins/crud/system.crud.js +18 -10
  101. package/plugins/crud/system.crud.js.map +1 -0
  102. package/plugins/crud/utils/checkBasePermissions.js +1 -1
  103. package/plugins/crud/utils/checkBasePermissions.js.map +1 -0
  104. package/plugins/crud/utils/createFileModel.d.ts +3 -0
  105. package/plugins/crud/utils/createFileModel.js +13 -0
  106. package/plugins/crud/utils/createFileModel.js.map +1 -0
  107. package/plugins/crud/utils/lifecycleEvents.d.ts +2 -2
  108. package/plugins/crud/utils/lifecycleEvents.js +6 -1
  109. package/plugins/crud/utils/lifecycleEvents.js.map +1 -0
  110. package/plugins/definitions/FilePhysicalStoragePlugin.d.ts +10 -11
  111. package/plugins/definitions/FilePhysicalStoragePlugin.js +1 -1
  112. package/plugins/definitions/FilePhysicalStoragePlugin.js.map +1 -0
  113. package/plugins/definitions/FilePlugin.d.ts +6 -3
  114. package/plugins/definitions/FilePlugin.js +9 -3
  115. package/plugins/definitions/FilePlugin.js.map +1 -0
  116. package/plugins/definitions/FileStorageTransformPlugin.d.ts +9 -9
  117. package/plugins/definitions/FileStorageTransformPlugin.js +1 -1
  118. package/plugins/definitions/FileStorageTransformPlugin.js.map +1 -0
  119. package/plugins/definitions/FilesStorageOperationsProviderPlugin.d.ts +4 -4
  120. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js +1 -1
  121. package/plugins/definitions/FilesStorageOperationsProviderPlugin.js.map +1 -0
  122. package/plugins/definitions/InstallationPlugin.d.ts +9 -9
  123. package/plugins/definitions/InstallationPlugin.js +5 -3
  124. package/plugins/definitions/InstallationPlugin.js.map +1 -0
  125. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.d.ts +4 -4
  126. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js +1 -1
  127. package/plugins/definitions/SettingsStorageOperationsProviderPlugin.js.map +1 -0
  128. package/plugins/definitions/SystemStorageOperationsProviderPlugin.d.ts +4 -4
  129. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js +1 -1
  130. package/plugins/definitions/SystemStorageOperationsProviderPlugin.js.map +1 -0
  131. package/plugins/graphql.js +20 -4
  132. package/plugins/graphql.js.map +1 -0
  133. package/plugins/index.d.ts +2 -2
  134. package/plugins/index.js +22 -19
  135. package/plugins/index.js.map +1 -0
  136. package/plugins/storage/FileStorage.d.ts +23 -24
  137. package/plugins/storage/FileStorage.js +28 -20
  138. package/plugins/storage/FileStorage.js.map +1 -0
  139. package/plugins/storage/index.d.ts +1 -1
  140. package/plugins/storage/index.js +6 -2
  141. package/plugins/storage/index.js.map +1 -0
  142. package/storage/FileStorage.d.ts +30 -0
  143. package/storage/FileStorage.js +86 -0
  144. package/storage/FileStorage.js.map +1 -0
  145. package/types/file.d.ts +33 -0
  146. package/types/file.js +5 -0
  147. package/types/file.js.map +1 -0
  148. package/types/file.lifecycle.d.ts +40 -0
  149. package/types/file.lifecycle.js +5 -0
  150. package/types/file.lifecycle.js.map +1 -0
  151. package/types.d.ts +49 -50
  152. package/types.js +22 -0
  153. package/types.js.map +1 -0
  154. package/utils.js.map +1 -0
  155. package/handlers/utils/createHandler.d.ts +0 -24
  156. package/handlers/utils/createHandler.js +0 -68
package/types/file.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.ts"],"sourcesContent":["export interface File {\n id: string;\n key: string;\n size: number;\n type: string;\n name: string;\n meta: Record<string, any>;\n tags: string[];\n aliases: string[];\n createdOn: string;\n createdBy: CreatedBy;\n /**\n * Added with new storage operations refactoring.\n */\n tenant: string;\n locale: string;\n webinyVersion: string;\n /**\n * User can add new fields to the File object so we must allow it in the types.\n */\n [key: string]: any;\n}\n\nexport interface FileAlias {\n tenant: string;\n locale: string;\n fileId: string;\n alias: string;\n}\n\nexport interface CreatedBy {\n id: string;\n displayName: string | null;\n type: string;\n}\n"],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { Topic } from "@webiny/pubsub/types";
2
+ import { File } from "./file";
3
+ export interface OnFileBeforeCreateTopicParams<TFile extends File = File> {
4
+ file: TFile;
5
+ }
6
+ export interface OnFileAfterCreateTopicParams<TFile extends File = File> {
7
+ file: TFile;
8
+ }
9
+ export interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {
10
+ files: TFile[];
11
+ }
12
+ export interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {
13
+ files: TFile[];
14
+ }
15
+ export interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {
16
+ original: TFile;
17
+ file: TFile;
18
+ input: Record<string, any>;
19
+ }
20
+ export interface OnFileAfterUpdateTopicParams<TFile extends File = File> {
21
+ original: TFile;
22
+ file: TFile;
23
+ input: Record<string, any>;
24
+ }
25
+ export interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {
26
+ file: TFile;
27
+ }
28
+ export interface OnFileAfterDeleteTopicParams<TFile extends File = File> {
29
+ file: TFile;
30
+ }
31
+ export interface FileLifecycleEvents {
32
+ onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;
33
+ onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;
34
+ onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;
35
+ onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;
36
+ onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;
37
+ onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;
38
+ onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;
39
+ onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;
40
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["file.lifecycle.ts"],"sourcesContent":["import { Topic } from \"@webiny/pubsub/types\";\nimport { File } from \"./file\";\n\nexport interface OnFileBeforeCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterCreateTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileBeforeBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n}\n\nexport interface OnFileAfterBatchCreateTopicParams<TFile extends File = File> {\n files: TFile[];\n}\n\nexport interface OnFileBeforeUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileAfterUpdateTopicParams<TFile extends File = File> {\n original: TFile;\n file: TFile;\n input: Record<string, any>;\n}\n\nexport interface OnFileBeforeDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface OnFileAfterDeleteTopicParams<TFile extends File = File> {\n file: TFile;\n}\n\nexport interface FileLifecycleEvents {\n onFileBeforeCreate: Topic<OnFileBeforeCreateTopicParams>;\n onFileAfterCreate: Topic<OnFileAfterCreateTopicParams>;\n onFileBeforeBatchCreate: Topic<OnFileBeforeBatchCreateTopicParams>;\n onFileAfterBatchCreate: Topic<OnFileAfterBatchCreateTopicParams>;\n onFileBeforeUpdate: Topic<OnFileBeforeUpdateTopicParams>;\n onFileAfterUpdate: Topic<OnFileAfterUpdateTopicParams>;\n onFileBeforeDelete: Topic<OnFileBeforeDeleteTopicParams>;\n onFileAfterDelete: Topic<OnFileAfterDeleteTopicParams>;\n}\n"],"mappings":""}
package/types.d.ts CHANGED
@@ -1,54 +1,33 @@
1
- import { BaseI18NContentContext } from "@webiny/api-i18n-content/types";
2
- import { FileStorage } from "./plugins/storage/FileStorage";
1
+ import { I18NContext } from "@webiny/api-i18n/types";
2
+ import { FileStorage } from "./storage/FileStorage";
3
3
  import { TenancyContext } from "@webiny/api-tenancy/types";
4
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
- };
5
+ import { Context } from "@webiny/api/types";
6
+ import { FileLifecycleEvents } from "./types/file.lifecycle";
7
+ import { File } from "./types/file";
8
+ import { Topic } from "@webiny/pubsub/types";
9
+ export * from "./types/file.lifecycle";
10
+ export * from "./types/file";
11
+ export interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {
12
+ storage: FileStorage;
13
+ }
14
+ export interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {
15
+ fileManager: FileManagerContextObject;
13
16
  }
14
17
  export interface FilePermission extends SecurityPermission {
15
18
  name: "fm.file";
16
19
  rwd?: string;
17
20
  own?: boolean;
18
21
  }
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
22
  export interface FileInput {
23
+ id: string;
46
24
  key: string;
47
25
  name: string;
48
26
  size: number;
49
27
  type: string;
50
28
  meta: Record<string, any>;
51
- tags: [string];
29
+ tags: string[];
30
+ aliases: string[];
52
31
  }
53
32
  export interface FileListWhereParams {
54
33
  search?: string;
@@ -71,20 +50,23 @@ export interface FilesListOpts {
71
50
  sort?: string[];
72
51
  }
73
52
  export interface FileListMeta {
74
- cursor: string;
53
+ cursor: string | null;
75
54
  totalCount: number;
55
+ hasMoreItems: boolean;
76
56
  }
77
57
  interface FilesCrudListTagsWhere {
78
58
  tag?: string;
79
59
  tag_contains?: string;
80
60
  tag_in?: string[];
61
+ tag_not_startsWith?: string;
62
+ tag_startsWith?: string;
81
63
  }
82
64
  interface FilesCrudListTagsParams {
83
65
  where?: FilesCrudListTagsWhere;
84
66
  limit?: number;
85
67
  after?: string;
86
68
  }
87
- export interface FilesCRUD {
69
+ export interface FilesCRUD extends FileLifecycleEvents {
88
70
  getFile(id: string): Promise<File>;
89
71
  listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;
90
72
  listTags(params: FilesCrudListTagsParams): Promise<string[]>;
@@ -94,14 +76,16 @@ export interface FilesCRUD {
94
76
  createFilesInBatch(data: FileInput[]): Promise<File[]>;
95
77
  }
96
78
  export interface SystemCRUD {
97
- getVersion(): Promise<string>;
79
+ onSystemBeforeInstall: Topic;
80
+ onSystemAfterInstall: Topic;
81
+ getVersion(): Promise<string | null>;
98
82
  setVersion(version: string): Promise<void>;
99
83
  install(args: {
100
84
  srcPrefix: string;
101
85
  }): Promise<boolean>;
102
- upgrade(version: string, data?: Record<string, any>): Promise<boolean>;
103
86
  }
104
87
  export interface FileManagerSettings {
88
+ tenant: string;
105
89
  key: string;
106
90
  uploadMinFileSize: number;
107
91
  uploadMaxFileSize: number;
@@ -109,9 +93,10 @@ export interface FileManagerSettings {
109
93
  }
110
94
  export interface FileManagerSystem {
111
95
  version: string;
96
+ tenant: string;
112
97
  }
113
98
  export declare type SettingsCRUD = {
114
- getSettings(): Promise<FileManagerSettings>;
99
+ getSettings(): Promise<FileManagerSettings | null>;
115
100
  createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
116
101
  updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;
117
102
  deleteSettings(): Promise<boolean>;
@@ -145,6 +130,9 @@ export interface FileManagerSystemStorageOperationsCreateParams {
145
130
  */
146
131
  data: FileManagerSystem;
147
132
  }
133
+ export interface FileManagerSystemStorageOperationsGetParams {
134
+ tenant: string;
135
+ }
148
136
  /**
149
137
  * @category StorageOperations
150
138
  * @category SystemStorageOperations
@@ -153,7 +141,7 @@ export interface FileManagerSystemStorageOperations {
153
141
  /**
154
142
  * Get the FileManager system data.
155
143
  */
156
- get: () => Promise<FileManagerSystem | null>;
144
+ get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;
157
145
  /**
158
146
  * Update the FileManager system data..
159
147
  */
@@ -189,6 +177,12 @@ export interface FileManagerSettingsStorageOperationsCreateParams {
189
177
  */
190
178
  data: FileManagerSettings;
191
179
  }
180
+ export interface FileManagerStorageOperationsGetSettingsParams {
181
+ tenant: string;
182
+ }
183
+ export interface FileManagerStorageOperationsDeleteSettings {
184
+ tenant: string;
185
+ }
192
186
  /**
193
187
  * @category StorageOperations
194
188
  * @category SettingsStorageOperations
@@ -197,7 +191,7 @@ export interface FileManagerSettingsStorageOperations {
197
191
  /**
198
192
  * Get the FileManager system data.
199
193
  */
200
- get: () => Promise<FileManagerSettings | null>;
194
+ get: (params: FileManagerStorageOperationsGetSettingsParams) => Promise<FileManagerSettings | null>;
201
195
  /**
202
196
  * Create the FileManagerSettingsData
203
197
  */
@@ -209,7 +203,7 @@ export interface FileManagerSettingsStorageOperations {
209
203
  /**
210
204
  * Delete the existing settings.
211
205
  */
212
- delete: () => Promise<void>;
206
+ delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;
213
207
  }
214
208
  /**
215
209
  * @category StorageOperations
@@ -293,10 +287,10 @@ export interface FileManagerFilesStorageOperationsListParams {
293
287
  * @category FilesStorageOperations
294
288
  * @category FilesStorageOperationsParams
295
289
  */
296
- interface FileManagerFilesStorageOperationsListResponseMeta {
290
+ export interface FileManagerFilesStorageOperationsListResponseMeta {
297
291
  hasMoreItems: boolean;
298
292
  totalCount: number;
299
- cursor: string;
293
+ cursor: string | null;
300
294
  }
301
295
  export declare type FileManagerFilesStorageOperationsListResponse = [
302
296
  File[],
@@ -332,11 +326,11 @@ export interface FileManagerFilesStorageOperations {
332
326
  /**
333
327
  * Insert the file data into the database.
334
328
  */
335
- create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File | null>;
329
+ create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;
336
330
  /**
337
331
  * Update the file data in the database.
338
332
  */
339
- update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File | null>;
333
+ update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;
340
334
  /**
341
335
  * Delete the file from the database.
342
336
  */
@@ -354,4 +348,9 @@ export interface FileManagerFilesStorageOperations {
354
348
  */
355
349
  tags: (params: FileManagerFilesStorageOperationsTagsParams) => Promise<FileManagerFilesStorageOperationsTagsResponse>;
356
350
  }
357
- export {};
351
+ export interface FileManagerStorageOperations<TContext = FileManagerContext> {
352
+ beforeInit?: (context: TContext) => Promise<void>;
353
+ files: FileManagerFilesStorageOperations;
354
+ settings: FileManagerSettingsStorageOperations;
355
+ system: FileManagerSystemStorageOperations;
356
+ }
package/types.js CHANGED
@@ -2,4 +2,26 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
+ });
6
+ var _file = require("./types/file.lifecycle");
7
+ Object.keys(_file).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _file[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _file[key];
14
+ }
15
+ });
16
+ });
17
+ var _file2 = require("./types/file");
18
+ Object.keys(_file2).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _file2[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _file2[key];
25
+ }
26
+ });
5
27
  });
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { I18NContext } from \"@webiny/api-i18n/types\";\nimport { FileStorage } from \"./storage/FileStorage\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { SecurityContext, SecurityPermission } from \"@webiny/api-security/types\";\nimport { Context } from \"@webiny/api/types\";\nimport { FileLifecycleEvents } from \"./types/file.lifecycle\";\nimport { File } from \"./types/file\";\nimport { Topic } from \"@webiny/pubsub/types\";\nexport * from \"./types/file.lifecycle\";\nexport * from \"./types/file\";\n\nexport interface FileManagerContextObject extends FilesCRUD, SettingsCRUD, SystemCRUD {\n storage: FileStorage;\n}\n\nexport interface FileManagerContext extends Context, SecurityContext, TenancyContext, I18NContext {\n fileManager: FileManagerContextObject;\n}\n\nexport interface FilePermission extends SecurityPermission {\n name: \"fm.file\";\n rwd?: string;\n own?: boolean;\n}\n\nexport interface FileInput {\n id: string;\n key: string;\n name: string;\n size: number;\n type: string;\n meta: Record<string, any>;\n tags: string[];\n aliases: string[];\n}\n\nexport interface FileListWhereParams {\n search?: string;\n type?: string;\n type_in?: string[];\n tag?: string;\n tag_in?: string[];\n tag_and_in?: string[];\n id_in?: string[];\n id?: string;\n}\nexport interface FilesListOpts {\n search?: string;\n types?: string[];\n tags?: string[];\n ids?: string[];\n limit?: number;\n after?: string;\n where?: FileListWhereParams;\n sort?: string[];\n}\n\nexport interface FileListMeta {\n cursor: string | null;\n totalCount: number;\n hasMoreItems: boolean;\n}\n\ninterface FilesCrudListTagsWhere {\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n tag_not_startsWith?: string;\n tag_startsWith?: string;\n}\ninterface FilesCrudListTagsParams {\n where?: FilesCrudListTagsWhere;\n limit?: number;\n after?: string;\n}\n\nexport interface FilesCRUD extends FileLifecycleEvents {\n getFile(id: string): Promise<File>;\n listFiles(opts?: FilesListOpts): Promise<[File[], FileListMeta]>;\n listTags(params: FilesCrudListTagsParams): Promise<string[]>;\n createFile(data: FileInput): Promise<File>;\n updateFile(id: string, data: Partial<FileInput>): Promise<File>;\n deleteFile(id: string): Promise<boolean>;\n createFilesInBatch(data: FileInput[]): Promise<File[]>;\n}\n\nexport interface SystemCRUD {\n onSystemBeforeInstall: Topic;\n onSystemAfterInstall: Topic;\n getVersion(): Promise<string | null>;\n setVersion(version: string): Promise<void>;\n install(args: { srcPrefix: string }): Promise<boolean>;\n}\n\nexport interface FileManagerSettings {\n tenant: string;\n key: string;\n uploadMinFileSize: number;\n uploadMaxFileSize: number;\n srcPrefix: string;\n}\n\nexport interface FileManagerSystem {\n version: string;\n tenant: string;\n}\n\nexport type SettingsCRUD = {\n getSettings(): Promise<FileManagerSettings | null>;\n createSettings(data?: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n updateSettings(data: Partial<FileManagerSettings>): Promise<FileManagerSettings>;\n deleteSettings(): Promise<boolean>;\n};\n/********\n * Storage operations\n *******/\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsUpdateParams {\n /**\n * The system data to be updated.\n */\n original: FileManagerSystem;\n /**\n * The system data with the updated fields.\n */\n data: FileManagerSystem;\n}\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n * @category SystemStorageOperationsParams\n */\nexport interface FileManagerSystemStorageOperationsCreateParams {\n /**\n * The system fields.\n */\n data: FileManagerSystem;\n}\n\nexport interface FileManagerSystemStorageOperationsGetParams {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SystemStorageOperations\n */\nexport interface FileManagerSystemStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (params: FileManagerSystemStorageOperationsGetParams) => Promise<FileManagerSystem | null>;\n /**\n * Update the FileManager system data..\n */\n update: (params: FileManagerSystemStorageOperationsUpdateParams) => Promise<FileManagerSystem>;\n /**\n * Create the FileManagerSystemData\n */\n create: (params: FileManagerSystemStorageOperationsCreateParams) => Promise<FileManagerSystem>;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsUpdateParams {\n /**\n * Original settings to be updated.\n */\n original: FileManagerSettings;\n /**\n * The settings with the updated fields.\n */\n data: FileManagerSettings;\n}\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n * @category SettingsStorageOperationsParams\n */\nexport interface FileManagerSettingsStorageOperationsCreateParams {\n /**\n * The settings fields.\n */\n data: FileManagerSettings;\n}\n\nexport interface FileManagerStorageOperationsGetSettingsParams {\n tenant: string;\n}\n\nexport interface FileManagerStorageOperationsDeleteSettings {\n tenant: string;\n}\n\n/**\n * @category StorageOperations\n * @category SettingsStorageOperations\n */\nexport interface FileManagerSettingsStorageOperations {\n /**\n * Get the FileManager system data.\n */\n get: (\n params: FileManagerStorageOperationsGetSettingsParams\n ) => Promise<FileManagerSettings | null>;\n /**\n * Create the FileManagerSettingsData\n */\n create: (\n params: FileManagerSettingsStorageOperationsCreateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Update the FileManager system data..\n */\n update: (\n params: FileManagerSettingsStorageOperationsUpdateParams\n ) => Promise<FileManagerSettings>;\n /**\n * Delete the existing settings.\n */\n delete: (params: FileManagerStorageOperationsDeleteSettings) => Promise<void>;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsUpdateParams {\n original: File;\n file: File;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsDeleteParams {\n file: File;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsCreateBatchParams {\n files: File[];\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParamsWhere {\n id?: string;\n id_in?: string[];\n name?: string;\n name_contains?: string;\n tag?: string;\n tag_contains?: string;\n tag_in?: string[];\n createdBy?: string;\n locale: string;\n tenant: string;\n private?: boolean;\n type?: string;\n type_in?: string[];\n search?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListParams {\n where: FileManagerFilesStorageOperationsListParamsWhere;\n sort: string[];\n limit: number;\n after: string | null;\n}\n\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsListResponseMeta {\n hasMoreItems: boolean;\n totalCount: number;\n cursor: string | null;\n}\nexport type FileManagerFilesStorageOperationsListResponse = [\n File[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport type FileManagerFilesStorageOperationsTagsResponse = [\n string[],\n FileManagerFilesStorageOperationsListResponseMeta\n];\n\nexport interface FileManagerFilesStorageOperationsTagsParamsWhere extends FilesCrudListTagsWhere {\n locale: string;\n tenant: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n * @category FilesStorageOperationsParams\n */\nexport interface FileManagerFilesStorageOperationsTagsParams {\n where: FileManagerFilesStorageOperationsTagsParamsWhere;\n limit: number;\n after?: string;\n}\n/**\n * @category StorageOperations\n * @category FilesStorageOperations\n */\nexport interface FileManagerFilesStorageOperations {\n /**\n * Get a single file with given ID from the storage.\n */\n get: (params: FileManagerFilesStorageOperationsGetParams) => Promise<File | null>;\n /**\n * Insert the file data into the database.\n */\n create: (params: FileManagerFilesStorageOperationsCreateParams) => Promise<File>;\n /**\n * Update the file data in the database.\n */\n update: (params: FileManagerFilesStorageOperationsUpdateParams) => Promise<File>;\n /**\n * Delete the file from the database.\n */\n delete: (params: FileManagerFilesStorageOperationsDeleteParams) => Promise<void>;\n /**\n * Store multiple files at once to the database.\n */\n createBatch: (params: FileManagerFilesStorageOperationsCreateBatchParams) => Promise<File[]>;\n /**\n * Get a list of files filtered by given parameters.\n */\n list: (\n params: FileManagerFilesStorageOperationsListParams\n ) => Promise<FileManagerFilesStorageOperationsListResponse>;\n /**\n * Get a list of all file tags filtered by given parameters.\n */\n tags: (\n params: FileManagerFilesStorageOperationsTagsParams\n ) => Promise<FileManagerFilesStorageOperationsTagsResponse>;\n}\n\nexport interface FileManagerStorageOperations<TContext = FileManagerContext> {\n beforeInit?: (context: TContext) => Promise<void>;\n files: FileManagerFilesStorageOperations;\n settings: FileManagerSettingsStorageOperations;\n system: FileManagerSystemStorageOperations;\n}\n"],"mappings":";;;;;AAQA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/utils.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["executeCallbacks","plugins","hook","args","plugin"],"sources":["utils.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/types\";\n\ntype CallbackFallback = (args: any) => void | Promise<void>;\n\nexport const executeCallbacks = async <\n TCallbackFunction extends CallbackFallback = CallbackFallback\n>(\n plugins: Plugin[],\n hook: string,\n args: Parameters<TCallbackFunction>[0]\n) => {\n for (const plugin of plugins) {\n if (typeof plugin[hook] === \"function\") {\n await plugin[hook](args);\n }\n }\n};\n"],"mappings":";;;;;;;AAIO,MAAMA,gBAAgB,GAAG,OAG5BC,OAH4B,EAI5BC,IAJ4B,EAK5BC,IAL4B,KAM3B;EACD,KAAK,MAAMC,MAAX,IAAqBH,OAArB,EAA8B;IAC1B,IAAI,OAAOG,MAAM,CAACF,IAAD,CAAb,KAAwB,UAA5B,EAAwC;MACpC,MAAME,MAAM,CAACF,IAAD,CAAN,CAAaC,IAAb,CAAN;IACH;EACJ;AACJ,CAZM"}
@@ -1,24 +0,0 @@
1
- declare const _default: (handler: any) => (event: any) => Promise<{
2
- body: string;
3
- statusCode: number;
4
- headers: {
5
- "Cache-Control": string;
6
- "Access-Control-Allow-Origin": string;
7
- "Access-Control-Allow-Credentials": boolean;
8
- };
9
- isBase64Encoded?: undefined;
10
- } | {
11
- isBase64Encoded: boolean;
12
- statusCode: any;
13
- headers: any;
14
- body: any;
15
- } | {
16
- statusCode: number;
17
- headers: {
18
- "Access-Control-Allow-Origin": string;
19
- "Access-Control-Allow-Credentials": boolean;
20
- };
21
- body: string;
22
- isBase64Encoded?: undefined;
23
- }>;
24
- export default _default;
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
13
-
14
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
15
-
16
- /**
17
- * We need to respond with adequate CORS headers.
18
- * @type {{"Access-Control-Allow-Origin": string, "Access-Control-Allow-Credentials": boolean}}
19
- */
20
- const baseHeaders = {
21
- "Access-Control-Allow-Origin": "*",
22
- "Access-Control-Allow-Credentials": true
23
- };
24
- const DEFAULT_CACHE_MAX_AGE = 30758400; // 1 year
25
-
26
- var _default = handler => 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
-
37
- try {
38
- const {
39
- data,
40
- statusCode,
41
- headers = {}
42
- } = await handler(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
- };
67
-
68
- exports.default = _default;