@webiny/api-file-manager 6.5.2-beta.0 → 6.5.2-beta.2

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 (52) hide show
  1. package/domain/file/errors.d.ts +12 -0
  2. package/domain/file/errors.js +10 -2
  3. package/domain/file/errors.js.map +1 -1
  4. package/domain/settings/errors.d.ts +4 -0
  5. package/domain/settings/errors.js +8 -1
  6. package/domain/settings/errors.js.map +1 -1
  7. package/domain/settings/validation.d.ts +9 -1
  8. package/domain/settings/validation.js +33 -11
  9. package/domain/settings/validation.js.map +1 -1
  10. package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +9 -1
  11. package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +14 -9
  12. package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -1
  13. package/features/file/CreateFile/CreateFileRepository.js +8 -2
  14. package/features/file/CreateFile/CreateFileRepository.js.map +1 -1
  15. package/features/file/CreateFile/CreateFileUseCase.js +15 -8
  16. package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
  17. package/features/file/CreateFile/abstractions.d.ts +3 -1
  18. package/features/file/CreateFile/abstractions.js.map +1 -1
  19. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.d.ts +3 -1
  20. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +13 -2
  21. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
  22. package/features/file/CreateFilesInBatch/abstractions.d.ts +2 -1
  23. package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
  24. package/features/file/ListTags/ListTagsUseCase.d.ts +3 -1
  25. package/features/file/ListTags/ListTagsUseCase.js +10 -2
  26. package/features/file/ListTags/ListTagsUseCase.js.map +1 -1
  27. package/features/file/UpdateFile/UpdateFileUseCase.js +7 -6
  28. package/features/file/UpdateFile/UpdateFileUseCase.js.map +1 -1
  29. package/features/file/shared/isValidFileKey.d.ts +8 -0
  30. package/features/file/shared/isValidFileKey.js +10 -0
  31. package/features/file/shared/isValidFileKey.js.map +1 -0
  32. package/features/settings/SettingsInstaller/SettingsInstaller.d.ts +3 -1
  33. package/features/settings/SettingsInstaller/SettingsInstaller.js +8 -5
  34. package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
  35. package/features/settings/UpdateSettings/UpdateSettingsUseCase.d.ts +3 -1
  36. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +14 -4
  37. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
  38. package/features/settings/UpdateSettings/abstractions.d.ts +2 -0
  39. package/features/settings/UpdateSettings/abstractions.js.map +1 -1
  40. package/features/upload/CreateMultiPartUpload/abstractions.d.ts +4 -0
  41. package/features/upload/CreateMultiPartUpload/abstractions.js.map +1 -1
  42. package/features/upload/GetUploadPayload/abstractions.d.ts +8 -1
  43. package/features/upload/GetUploadPayload/abstractions.js.map +1 -1
  44. package/features/upload/WriteFileMetadata/MetadataWriter.js +5 -1
  45. package/features/upload/WriteFileMetadata/MetadataWriter.js.map +1 -1
  46. package/features/upload/utils/FileNormalizer.js +27 -0
  47. package/features/upload/utils/FileNormalizer.js.map +1 -1
  48. package/graphql/FmGraphQLSchema.js +9 -2
  49. package/graphql/FmGraphQLSchema.js.map +1 -1
  50. package/graphql/FmUploadGraphQLSchema.js +8 -3
  51. package/graphql/FmUploadGraphQLSchema.js.map +1 -1
  52. package/package.json +18 -18
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/CreateFilesInBatch/abstractions.js","sources":["../../../../src/features/file/CreateFilesInBatch/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFilesInBatchInput {\n files: FileInput[];\n meta?: Record<string, any>;\n}\n\n/**\n * CreateFilesInBatch repository interface\n */\nexport interface ICreateFilesInBatchRepository {\n createBatch(files: FileInput[]): Promise<Result<File[], RepositoryError>>;\n}\n\nexport interface ICreateFilesInBatchRepositoryErrors {\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError =\n ICreateFilesInBatchRepositoryErrors[keyof ICreateFilesInBatchRepositoryErrors];\n\n/** Persist multiple files created in batch. */\nexport const CreateFilesInBatchRepository = createAbstraction<ICreateFilesInBatchRepository>(\n \"CreateFilesInBatchRepository\"\n);\n\nexport namespace CreateFilesInBatchRepository {\n export type Interface = ICreateFilesInBatchRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFilesInBatch use case interface\n */\nexport interface ICreateFilesInBatchUseCase {\n execute(input: CreateFilesInBatchInput): Promise<Result<File[], UseCaseError>>;\n}\n\nexport interface ICreateFilesInBatchUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n}\n\ntype UseCaseError = ICreateFilesInBatchUseCaseErrors[keyof ICreateFilesInBatchUseCaseErrors];\n\n/** Upload and create multiple files in batch. */\nexport const CreateFilesInBatchUseCase = createAbstraction<ICreateFilesInBatchUseCase>(\n \"CreateFilesInBatchUseCase\"\n);\n\nexport namespace CreateFilesInBatchUseCase {\n export type Interface = ICreateFilesInBatchUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFilesInBatchRepository","createAbstraction","CreateFilesInBatchUseCase"],"mappings":";AA6BO,MAAMA,+BAA+BC,kBACxC;AAwBG,MAAMC,4BAA4BD,kBACrC"}
1
+ {"version":3,"file":"features/file/CreateFilesInBatch/abstractions.js","sources":["../../../../src/features/file/CreateFilesInBatch/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { File, FileInput } from \"~/domain/file/types.js\";\nimport {\n type FilePersistenceError,\n type InvalidFileSizeError,\n type InvalidFileKeyError,\n FileNotAuthorizedError\n} from \"~/domain/file/errors.js\";\n\nexport interface CreateFilesInBatchInput {\n files: FileInput[];\n meta?: Record<string, any>;\n}\n\n/**\n * CreateFilesInBatch repository interface\n */\nexport interface ICreateFilesInBatchRepository {\n createBatch(files: FileInput[]): Promise<Result<File[], RepositoryError>>;\n}\n\nexport interface ICreateFilesInBatchRepositoryErrors {\n persistence: FilePersistenceError;\n}\n\ntype RepositoryError =\n ICreateFilesInBatchRepositoryErrors[keyof ICreateFilesInBatchRepositoryErrors];\n\n/** Persist multiple files created in batch. */\nexport const CreateFilesInBatchRepository = createAbstraction<ICreateFilesInBatchRepository>(\n \"CreateFilesInBatchRepository\"\n);\n\nexport namespace CreateFilesInBatchRepository {\n export type Interface = ICreateFilesInBatchRepository;\n export type Error = RepositoryError;\n}\n\n/**\n * CreateFilesInBatch use case interface\n */\nexport interface ICreateFilesInBatchUseCase {\n execute(input: CreateFilesInBatchInput): Promise<Result<File[], UseCaseError>>;\n}\n\nexport interface ICreateFilesInBatchUseCaseErrors {\n notAuthorized: FileNotAuthorizedError;\n persistence: FilePersistenceError;\n invalidSize: InvalidFileSizeError;\n invalidKey: InvalidFileKeyError;\n}\n\ntype UseCaseError = ICreateFilesInBatchUseCaseErrors[keyof ICreateFilesInBatchUseCaseErrors];\n\n/** Upload and create multiple files in batch. */\nexport const CreateFilesInBatchUseCase = createAbstraction<ICreateFilesInBatchUseCase>(\n \"CreateFilesInBatchUseCase\"\n);\n\nexport namespace CreateFilesInBatchUseCase {\n export type Interface = ICreateFilesInBatchUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["CreateFilesInBatchRepository","createAbstraction","CreateFilesInBatchUseCase"],"mappings":";AA8BO,MAAMA,+BAA+BC,kBACxC;AAyBG,MAAMC,4BAA4BD,kBACrC"}
@@ -1,10 +1,12 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { ListTagsUseCase as UseCaseAbstraction, ListTagsInput, TagItem, ListTagsRepository } from "./abstractions.js";
3
3
  import { FmPermissions } from "../../../features/shared/abstractions.js";
4
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
5
  declare class ListTagsUseCaseImpl implements UseCaseAbstraction.Interface {
5
6
  private permissions;
7
+ private identityContext;
6
8
  private repository;
7
- constructor(permissions: FmPermissions.Interface, repository: ListTagsRepository.Interface);
9
+ constructor(permissions: FmPermissions.Interface, identityContext: IdentityContext.Interface, repository: ListTagsRepository.Interface);
8
10
  execute(input: ListTagsInput): Promise<Result<TagItem[], UseCaseAbstraction.Error>>;
9
11
  }
10
12
  export declare const ListTagsUseCase: typeof ListTagsUseCaseImpl & {
@@ -2,16 +2,23 @@ import { Result } from "@webiny/feature/api";
2
2
  import { ListTagsRepository, ListTagsUseCase } from "./abstractions.js";
3
3
  import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
4
4
  import { FmPermissions } from "../../shared/abstractions.js";
5
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
5
6
  class ListTagsUseCaseImpl {
6
- constructor(permissions, repository){
7
+ constructor(permissions, identityContext, repository){
7
8
  this.permissions = permissions;
9
+ this.identityContext = identityContext;
8
10
  this.repository = repository;
9
11
  }
10
12
  async execute(input) {
11
- const hasPermission = await this.permissions.canAccess("file");
13
+ const hasPermission = await this.permissions.canRead("file");
12
14
  if (!hasPermission) return Result.fail(new FileNotAuthorizedError());
15
+ const where = {
16
+ ...input.where || {}
17
+ };
18
+ if (await this.permissions.onlyOwnRecords("file")) where.createdBy = this.identityContext.getIdentity().id;
13
19
  const enrichedInput = {
14
20
  ...input,
21
+ where,
15
22
  limit: input.limit || 1000000
16
23
  };
17
24
  const result = await this.repository.execute(enrichedInput);
@@ -23,6 +30,7 @@ const ListTagsUseCase_ListTagsUseCase = ListTagsUseCase.createImplementation({
23
30
  implementation: ListTagsUseCaseImpl,
24
31
  dependencies: [
25
32
  FmPermissions,
33
+ IdentityContext,
26
34
  ListTagsRepository
27
35
  ]
28
36
  });
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/ListTags/ListTagsUseCase.js","sources":["../../../../src/features/file/ListTags/ListTagsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListTagsUseCase as UseCaseAbstraction,\n ListTagsInput,\n TagItem,\n ListTagsRepository\n} from \"./abstractions.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\n\nclass ListTagsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private repository: ListTagsRepository.Interface\n ) {}\n\n async execute(input: ListTagsInput): Promise<Result<TagItem[], UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canAccess(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const enrichedInput: ListTagsInput = {\n ...input,\n limit: input.limit || 1000000\n };\n\n const result = await this.repository.execute(enrichedInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const ListTagsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListTagsUseCaseImpl,\n dependencies: [FmPermissions, ListTagsRepository]\n});\n"],"names":["ListTagsUseCaseImpl","permissions","repository","input","hasPermission","Result","FileNotAuthorizedError","enrichedInput","result","ListTagsUseCase","UseCaseAbstraction","FmPermissions","ListTagsRepository"],"mappings":";;;;AAUA,MAAMA;IACF,YACYC,WAAoC,EACpCC,UAAwC,CAClD;aAFUD,WAAW,GAAXA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAoB,EAAwD;QACtF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;QACvD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,gBAA+B;YACjC,GAAGJ,KAAK;YACR,OAAOA,MAAM,KAAK,IAAI;QAC1B;QAEA,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD;QAE7C,IAAIC,OAAO,MAAM,IACb,OAAOH,OAAO,IAAI,CAACG,OAAO,KAAK;QAGnC,OAAOH,OAAO,EAAE,CAACG,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMC,kCAAkBC,gBAAAA,oBAAuC,CAAC;IACnE,gBAAgBV;IAChB,cAAc;QAACW;QAAeC;KAAmB;AACrD"}
1
+ {"version":3,"file":"features/file/ListTags/ListTagsUseCase.js","sources":["../../../../src/features/file/ListTags/ListTagsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n ListTagsUseCase as UseCaseAbstraction,\n ListTagsInput,\n TagItem,\n ListTagsRepository\n} from \"./abstractions.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\nclass ListTagsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private identityContext: IdentityContext.Interface,\n private repository: ListTagsRepository.Interface\n ) {}\n\n async execute(input: ListTagsInput): Promise<Result<TagItem[], UseCaseAbstraction.Error>> {\n // Security: tags expose file data, so they need the same read access as listFiles.\n const hasPermission = await this.permissions.canRead(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const where: ListTagsInput[\"where\"] = {\n ...(input.where || {})\n };\n\n if (await this.permissions.onlyOwnRecords(\"file\")) {\n where.createdBy = this.identityContext.getIdentity().id;\n }\n\n const enrichedInput: ListTagsInput = {\n ...input,\n where,\n limit: input.limit || 1000000\n };\n\n const result = await this.repository.execute(enrichedInput);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(result.value);\n }\n}\n\nexport const ListTagsUseCase = UseCaseAbstraction.createImplementation({\n implementation: ListTagsUseCaseImpl,\n dependencies: [FmPermissions, IdentityContext, ListTagsRepository]\n});\n"],"names":["ListTagsUseCaseImpl","permissions","identityContext","repository","input","hasPermission","Result","FileNotAuthorizedError","where","enrichedInput","result","ListTagsUseCase","UseCaseAbstraction","FmPermissions","IdentityContext","ListTagsRepository"],"mappings":";;;;;AAWA,MAAMA;IACF,YACYC,WAAoC,EACpCC,eAA0C,EAC1CC,UAAwC,CAClD;aAHUF,WAAW,GAAXA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAoB,EAAwD;QAEtF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,QAAgC;YAClC,GAAIJ,MAAM,KAAK,IAAI,CAAC,CAAC;QACzB;QAEA,IAAI,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SACtCI,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,GAAG,EAAE;QAG3D,MAAMC,gBAA+B;YACjC,GAAGL,KAAK;YACRI;YACA,OAAOJ,MAAM,KAAK,IAAI;QAC1B;QAEA,MAAMM,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD;QAE7C,IAAIC,OAAO,MAAM,IACb,OAAOJ,OAAO,IAAI,CAACI,OAAO,KAAK;QAGnC,OAAOJ,OAAO,EAAE,CAACI,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMC,kCAAkBC,gBAAAA,oBAAuC,CAAC;IACnE,gBAAgBZ;IAChB,cAAc;QAACa;QAAeC;QAAiBC;KAAmB;AACtE"}
@@ -24,6 +24,7 @@ class UpdateFileUseCaseImpl {
24
24
  const canEditFile = await this.permissions.canEdit("file", original);
25
25
  if (!canEditFile) return Result.fail(new FileNotAuthorizedError());
26
26
  const currentIdentity = this.identityContext.getIdentity();
27
+ const systemInput = !this.identityContext.isAuthorizationEnabled() || await this.identityContext.hasFullAccess() ? input : {};
27
28
  const file = {
28
29
  ...original,
29
30
  ...input,
@@ -34,12 +35,12 @@ class UpdateFileUseCaseImpl {
34
35
  tags: void 0 !== input.tags ? input.tags : original.tags,
35
36
  description: void 0 !== input.description ? input.description : original.description,
36
37
  location: void 0 !== input.location ? input.location : original.location,
37
- createdOn: input.createdOn ?? original.createdOn,
38
- modifiedOn: input.modifiedOn ?? void 0,
39
- savedOn: input.savedOn ?? original.savedOn,
40
- createdBy: input.createdBy ? Identity.from(input.createdBy) : original.createdBy,
41
- modifiedBy: input.modifiedBy ? Identity.from(input.modifiedBy) : Identity.from(currentIdentity),
42
- savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)
38
+ createdOn: systemInput.createdOn ?? original.createdOn,
39
+ modifiedOn: systemInput.modifiedOn ?? void 0,
40
+ savedOn: systemInput.savedOn ?? original.savedOn,
41
+ createdBy: systemInput.createdBy ? Identity.from(systemInput.createdBy) : original.createdBy,
42
+ modifiedBy: systemInput.modifiedBy ? Identity.from(systemInput.modifiedBy) : Identity.from(currentIdentity),
43
+ savedBy: systemInput.savedBy ? Identity.from(systemInput.savedBy) : Identity.from(currentIdentity)
43
44
  };
44
45
  await this.eventPublisher.publish(new FileBeforeUpdateEvent({
45
46
  original,
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/UpdateFile/UpdateFileUseCase.js","sources":["../../../../src/features/file/UpdateFile/UpdateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateFileUseCase as UseCaseAbstraction,\n UpdateFileInput,\n UpdateFileRepository\n} from \"./abstractions.js\";\nimport { GetFileUseCase } from \"../GetFile/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FileBeforeUpdateEvent, FileAfterUpdateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass UpdateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private getFile: GetFileUseCase.Interface,\n private repository: UpdateFileRepository.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(input: UpdateFileInput): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canEdit(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Get the original file (includes ownership check).\n const getResult = await this.getFile.execute(input.id);\n\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n\n const original = getResult.value;\n\n // Check ownership-aware edit permission.\n const canEditFile = await this.permissions.canEdit(\"file\", original);\n if (!canEditFile) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const currentIdentity = this.identityContext.getIdentity();\n\n const file: File = {\n ...original,\n ...input,\n // Preserve immutable fields.\n id: original.id,\n key: original.key,\n size: original.size,\n type: original.type,\n // Update mutable fields.\n tags: input.tags !== undefined ? input.tags : original.tags,\n description: input.description !== undefined ? input.description : original.description,\n location: input.location !== undefined ? input.location : original.location,\n // System fields.\n createdOn: input.createdOn ?? original.createdOn,\n modifiedOn: input.modifiedOn ?? undefined,\n savedOn: input.savedOn ?? original.savedOn,\n createdBy: input.createdBy ? Identity.from(input.createdBy) : original.createdBy,\n modifiedBy: input.modifiedBy\n ? Identity.from(input.modifiedBy)\n : Identity.from(currentIdentity),\n savedBy: input.savedBy ? Identity.from(input.savedBy) : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeUpdateEvent({ original, file, input }));\n\n const result = await this.repository.update(file);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterUpdateEvent({ original, file, input }));\n\n return Result.ok(file);\n }\n}\n\nexport const UpdateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions,\n GetFileUseCase,\n UpdateFileRepository,\n EventPublisher\n ]\n});\n"],"names":["UpdateFileUseCaseImpl","identityContext","permissions","getFile","repository","eventPublisher","input","hasPermission","Result","FileNotAuthorizedError","getResult","original","canEditFile","currentIdentity","file","undefined","Identity","FileBeforeUpdateEvent","result","FileAfterUpdateEvent","UpdateFileUseCase","UseCaseAbstraction","IdentityContext","FmPermissions","GetFileUseCase","UpdateFileRepository","EventPublisher"],"mappings":";;;;;;;;;AAeA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,WAAoC,EACpCC,OAAiC,EACjCC,UAA0C,EAC1CC,cAAwC,CAClD;aALUJ,eAAe,GAAfA;aACAC,WAAW,GAAXA;aACAC,OAAO,GAAPA;aACAC,UAAU,GAAVA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAmD;QACnF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAACJ,MAAM,EAAE;QAErD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAGtC,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,cAAc,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQD;QAC3D,IAAI,CAACC,aACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMI,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW;QAExD,MAAMC,OAAa;YACf,GAAGH,QAAQ;YACX,GAAGL,KAAK;YAER,IAAIK,SAAS,EAAE;YACf,KAAKA,SAAS,GAAG;YACjB,MAAMA,SAAS,IAAI;YACnB,MAAMA,SAAS,IAAI;YAEnB,MAAML,AAAeS,WAAfT,MAAM,IAAI,GAAiBA,MAAM,IAAI,GAAGK,SAAS,IAAI;YAC3D,aAAaL,AAAsBS,WAAtBT,MAAM,WAAW,GAAiBA,MAAM,WAAW,GAAGK,SAAS,WAAW;YACvF,UAAUL,AAAmBS,WAAnBT,MAAM,QAAQ,GAAiBA,MAAM,QAAQ,GAAGK,SAAS,QAAQ;YAE3E,WAAWL,MAAM,SAAS,IAAIK,SAAS,SAAS;YAChD,YAAYL,MAAM,UAAU,IAAIS;YAChC,SAAST,MAAM,OAAO,IAAIK,SAAS,OAAO;YAC1C,WAAWL,MAAM,SAAS,GAAGU,SAAS,IAAI,CAACV,MAAM,SAAS,IAAIK,SAAS,SAAS;YAChF,YAAYL,MAAM,UAAU,GACtBU,SAAS,IAAI,CAACV,MAAM,UAAU,IAC9BU,SAAS,IAAI,CAACH;YACpB,SAASP,MAAM,OAAO,GAAGU,SAAS,IAAI,CAACV,MAAM,OAAO,IAAIU,SAAS,IAAI,CAACH;QAC1E;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAII,sBAAsB;YAAEN;YAAUG;YAAMR;QAAM;QAEpF,MAAMY,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOV,OAAO,IAAI,CAACU,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAER;YAAUG;YAAMR;QAAM;QAEnF,OAAOE,OAAO,EAAE,CAACM;IACrB;AACJ;AAEO,MAAMM,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/file/UpdateFile/UpdateFileUseCase.js","sources":["../../../../src/features/file/UpdateFile/UpdateFileUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateFileUseCase as UseCaseAbstraction,\n UpdateFileInput,\n UpdateFileRepository\n} from \"./abstractions.js\";\nimport { GetFileUseCase } from \"../GetFile/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\nimport { FileBeforeUpdateEvent, FileAfterUpdateEvent } from \"./events.js\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { Identity } from \"~/domain/identity/Identity.js\";\n\nclass UpdateFileUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private permissions: FmPermissions.Interface,\n private getFile: GetFileUseCase.Interface,\n private repository: UpdateFileRepository.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(input: UpdateFileInput): Promise<Result<File, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canEdit(\"file\");\n if (!hasPermission) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n // Get the original file (includes ownership check).\n const getResult = await this.getFile.execute(input.id);\n\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n\n const original = getResult.value;\n\n // Check ownership-aware edit permission.\n const canEditFile = await this.permissions.canEdit(\"file\", original);\n if (!canEditFile) {\n return Result.fail(new FileNotAuthorizedError());\n }\n\n const currentIdentity = this.identityContext.getIdentity();\n\n // Attribution and dates come from the server. Only full access, or code running without\n // authorization (imports, migrations), may set them.\n const systemInput: Partial<typeof input> =\n !this.identityContext.isAuthorizationEnabled() ||\n (await this.identityContext.hasFullAccess())\n ? input\n : {};\n\n const file: File = {\n ...original,\n ...input,\n // Preserve immutable fields.\n id: original.id,\n key: original.key,\n size: original.size,\n type: original.type,\n // Update mutable fields.\n tags: input.tags !== undefined ? input.tags : original.tags,\n description: input.description !== undefined ? input.description : original.description,\n location: input.location !== undefined ? input.location : original.location,\n // System fields.\n createdOn: systemInput.createdOn ?? original.createdOn,\n modifiedOn: systemInput.modifiedOn ?? undefined,\n savedOn: systemInput.savedOn ?? original.savedOn,\n createdBy: systemInput.createdBy\n ? Identity.from(systemInput.createdBy)\n : original.createdBy,\n modifiedBy: systemInput.modifiedBy\n ? Identity.from(systemInput.modifiedBy)\n : Identity.from(currentIdentity),\n savedBy: systemInput.savedBy\n ? Identity.from(systemInput.savedBy)\n : Identity.from(currentIdentity)\n };\n\n await this.eventPublisher.publish(new FileBeforeUpdateEvent({ original, file, input }));\n\n const result = await this.repository.update(file);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(new FileAfterUpdateEvent({ original, file, input }));\n\n return Result.ok(file);\n }\n}\n\nexport const UpdateFileUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateFileUseCaseImpl,\n dependencies: [\n IdentityContext,\n FmPermissions,\n GetFileUseCase,\n UpdateFileRepository,\n EventPublisher\n ]\n});\n"],"names":["UpdateFileUseCaseImpl","identityContext","permissions","getFile","repository","eventPublisher","input","hasPermission","Result","FileNotAuthorizedError","getResult","original","canEditFile","currentIdentity","systemInput","file","undefined","Identity","FileBeforeUpdateEvent","result","FileAfterUpdateEvent","UpdateFileUseCase","UseCaseAbstraction","IdentityContext","FmPermissions","GetFileUseCase","UpdateFileRepository","EventPublisher"],"mappings":";;;;;;;;;AAeA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,WAAoC,EACpCC,OAAiC,EACjCC,UAA0C,EAC1CC,cAAwC,CAClD;aALUJ,eAAe,GAAfA;aACAC,WAAW,GAAXA;aACAC,OAAO,GAAPA;aACAC,UAAU,GAAVA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAmD;QACnF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;QACrD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAACJ,MAAM,EAAE;QAErD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAGtC,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,cAAc,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQD;QAC3D,IAAI,CAACC,aACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMI,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW;QAIxD,MAAMC,cACF,CAAC,IAAI,CAAC,eAAe,CAAC,sBAAsB,MAC3C,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,KACnCR,QACA,CAAC;QAEX,MAAMS,OAAa;YACf,GAAGJ,QAAQ;YACX,GAAGL,KAAK;YAER,IAAIK,SAAS,EAAE;YACf,KAAKA,SAAS,GAAG;YACjB,MAAMA,SAAS,IAAI;YACnB,MAAMA,SAAS,IAAI;YAEnB,MAAML,AAAeU,WAAfV,MAAM,IAAI,GAAiBA,MAAM,IAAI,GAAGK,SAAS,IAAI;YAC3D,aAAaL,AAAsBU,WAAtBV,MAAM,WAAW,GAAiBA,MAAM,WAAW,GAAGK,SAAS,WAAW;YACvF,UAAUL,AAAmBU,WAAnBV,MAAM,QAAQ,GAAiBA,MAAM,QAAQ,GAAGK,SAAS,QAAQ;YAE3E,WAAWG,YAAY,SAAS,IAAIH,SAAS,SAAS;YACtD,YAAYG,YAAY,UAAU,IAAIE;YACtC,SAASF,YAAY,OAAO,IAAIH,SAAS,OAAO;YAChD,WAAWG,YAAY,SAAS,GAC1BG,SAAS,IAAI,CAACH,YAAY,SAAS,IACnCH,SAAS,SAAS;YACxB,YAAYG,YAAY,UAAU,GAC5BG,SAAS,IAAI,CAACH,YAAY,UAAU,IACpCG,SAAS,IAAI,CAACJ;YACpB,SAASC,YAAY,OAAO,GACtBG,SAAS,IAAI,CAACH,YAAY,OAAO,IACjCG,SAAS,IAAI,CAACJ;QACxB;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIK,sBAAsB;YAAEP;YAAUI;YAAMT;QAAM;QAEpF,MAAMa,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QAE5C,IAAII,OAAO,MAAM,IACb,OAAOX,OAAO,IAAI,CAACW,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIC,qBAAqB;YAAET;YAAUI;YAAMT;QAAM;QAEnF,OAAOE,OAAO,EAAE,CAACO;IACrB;AACJ;AAEO,MAAMM,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgBtB;IAChB,cAAc;QACVuB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Security: a file record must point only at the object uploaded for that file id.
3
+ *
4
+ * Keys come from `FileKey` as `[keyPrefix/]<id>/<name>`, so the id is either the first
5
+ * segment (no prefix) or the segment right before the file name (with a prefix).
6
+ * Anything that could escape the tenant folder, or point at another file's object, is refused.
7
+ */
8
+ export declare const isValidFileKey: (id: string, key: string) => boolean;
@@ -0,0 +1,10 @@
1
+ const isValidFileKey = (id, key)=>{
2
+ if (!id || !key || key.includes("\\") || key.startsWith("/")) return false;
3
+ const segments = key.split("/");
4
+ if (segments.length < 2) return false;
5
+ if (segments.some((segment)=>!segment.trim() || "." === segment.trim() || ".." === segment.trim())) return false;
6
+ return segments[0] === id || segments[segments.length - 2] === id;
7
+ };
8
+ export { isValidFileKey };
9
+
10
+ //# sourceMappingURL=isValidFileKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/file/shared/isValidFileKey.js","sources":["../../../../src/features/file/shared/isValidFileKey.ts"],"sourcesContent":["/**\n * Security: a file record must point only at the object uploaded for that file id.\n *\n * Keys come from `FileKey` as `[keyPrefix/]<id>/<name>`, so the id is either the first\n * segment (no prefix) or the segment right before the file name (with a prefix).\n * Anything that could escape the tenant folder, or point at another file's object, is refused.\n */\nexport const isValidFileKey = (id: string, key: string): boolean => {\n if (!id || !key || key.includes(\"\\\\\") || key.startsWith(\"/\")) {\n return false;\n }\n\n const segments = key.split(\"/\");\n if (segments.length < 2) {\n return false;\n }\n\n if (\n segments.some(\n segment => !segment.trim() || segment.trim() === \".\" || segment.trim() === \"..\"\n )\n ) {\n return false;\n }\n\n return segments[0] === id || segments[segments.length - 2] === id;\n};\n"],"names":["isValidFileKey","id","key","segments","segment"],"mappings":"AAOO,MAAMA,iBAAiB,CAACC,IAAYC;IACvC,IAAI,CAACD,MAAM,CAACC,OAAOA,IAAI,QAAQ,CAAC,SAASA,IAAI,UAAU,CAAC,MACpD,OAAO;IAGX,MAAMC,WAAWD,IAAI,KAAK,CAAC;IAC3B,IAAIC,SAAS,MAAM,GAAG,GAClB,OAAO;IAGX,IACIA,SAAS,IAAI,CACTC,CAAAA,UAAW,CAACA,QAAQ,IAAI,MAAMA,AAAmB,QAAnBA,QAAQ,IAAI,MAAcA,AAAmB,SAAnBA,QAAQ,IAAI,KAGxE,OAAO;IAGX,OAAOD,QAAQ,CAAC,EAAE,KAAKF,MAAME,QAAQ,CAACA,SAAS,MAAM,GAAG,EAAE,KAAKF;AACnE"}
@@ -1,13 +1,15 @@
1
1
  import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/index.js";
2
2
  import { UpdateSettingsUseCase } from "../../../features/settings/UpdateSettings/abstractions.js";
3
3
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
5
  declare class SettingsInstallerImpl implements AppInstaller.Interface {
6
+ private identityContext;
5
7
  private updateSettings;
6
8
  private keyValueStore;
7
9
  readonly alwaysRun = true;
8
10
  readonly appName = "FileManager";
9
11
  readonly dependsOn: never[];
10
- constructor(updateSettings: UpdateSettingsUseCase.Interface, keyValueStore: KeyValueStore.Interface);
12
+ constructor(identityContext: IdentityContext.Interface, updateSettings: UpdateSettingsUseCase.Interface, keyValueStore: KeyValueStore.Interface);
11
13
  install(): Promise<void>;
12
14
  uninstall(): Promise<void>;
13
15
  }
@@ -4,8 +4,10 @@ import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/in
4
4
  import { FILE_MANAGER_GENERAL_SETTINGS } from "../../../domain/settings/constants.js";
5
5
  import { UpdateSettingsUseCase } from "../UpdateSettings/abstractions.js";
6
6
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
7
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
7
8
  class SettingsInstallerImpl {
8
- constructor(updateSettings, keyValueStore){
9
+ constructor(identityContext, updateSettings, keyValueStore){
10
+ this.identityContext = identityContext;
9
11
  this.updateSettings = updateSettings;
10
12
  this.keyValueStore = keyValueStore;
11
13
  this.alwaysRun = true;
@@ -14,10 +16,10 @@ class SettingsInstallerImpl {
14
16
  }
15
17
  async install() {
16
18
  const manifest = await ServiceDiscovery.load();
17
- const domain = manifest?.api?.cloudfront.domain;
18
- await this.updateSettings.execute({
19
- srcPrefix: `${domain}/files`
20
- });
19
+ const domain = manifest?.api?.cloudfront?.domain;
20
+ await this.identityContext.withoutAuthorization(()=>this.updateSettings.execute({
21
+ srcPrefix: domain ? `${domain}/files` : ""
22
+ }));
21
23
  }
22
24
  async uninstall() {
23
25
  await this.keyValueStore.delete(FILE_MANAGER_GENERAL_SETTINGS);
@@ -27,6 +29,7 @@ const SettingsInstaller = createImplementation({
27
29
  abstraction: AppInstaller,
28
30
  implementation: SettingsInstallerImpl,
29
31
  dependencies: [
32
+ IdentityContext,
30
33
  UpdateSettingsUseCase,
31
34
  KeyValueStore
32
35
  ]
@@ -1 +1 @@
1
- {"version":3,"file":"features/settings/SettingsInstaller/SettingsInstaller.js","sources":["../../../../src/features/settings/SettingsInstaller/SettingsInstaller.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { AppInstaller } from \"@webiny/api-core/features/tenancy/InstallTenant/index.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { UpdateSettingsUseCase } from \"~/features/settings/UpdateSettings/abstractions.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nclass SettingsInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"FileManager\";\n readonly dependsOn = [];\n\n constructor(\n private updateSettings: UpdateSettingsUseCase.Interface,\n private keyValueStore: KeyValueStore.Interface\n ) {}\n\n async install(): Promise<void> {\n // TODO: move this to api-core with a proper abstraction\n const manifest = await ServiceDiscovery.load();\n\n // If no records in the database, `manifest` object is empty POJO.\n // That's why the heavy `?.` usage.\n const domain = manifest?.api?.cloudfront.domain;\n\n await this.updateSettings.execute({\n srcPrefix: `${domain}/files`\n });\n }\n\n async uninstall(): Promise<void> {\n await this.keyValueStore.delete(FILE_MANAGER_GENERAL_SETTINGS);\n }\n}\n\nexport const SettingsInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: SettingsInstallerImpl,\n dependencies: [UpdateSettingsUseCase, KeyValueStore]\n});\n"],"names":["SettingsInstallerImpl","updateSettings","keyValueStore","manifest","ServiceDiscovery","domain","FILE_MANAGER_GENERAL_SETTINGS","SettingsInstaller","createImplementation","AppInstaller","UpdateSettingsUseCase","KeyValueStore"],"mappings":";;;;;;AAOA,MAAMA;IAKF,YACYC,cAA+C,EAC/CC,aAAsC,CAChD;aAFUD,cAAc,GAAdA;aACAC,aAAa,GAAbA;aANH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;IAKpB;IAEH,MAAM,UAAyB;QAE3B,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAI5C,MAAMC,SAASF,UAAU,KAAK,WAAW;QAEzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAC9B,WAAW,GAAGE,OAAO,MAAM,CAAC;QAChC;IACJ;IAEA,MAAM,YAA2B;QAC7B,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACC;IACpC;AACJ;AAEO,MAAMC,oBAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBT;IAChB,cAAc;QAACU;QAAuBC;KAAc;AACxD"}
1
+ {"version":3,"file":"features/settings/SettingsInstaller/SettingsInstaller.js","sources":["../../../../src/features/settings/SettingsInstaller/SettingsInstaller.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { AppInstaller } from \"@webiny/api-core/features/tenancy/InstallTenant/index.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { UpdateSettingsUseCase } from \"~/features/settings/UpdateSettings/abstractions.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\n\nclass SettingsInstallerImpl implements AppInstaller.Interface {\n readonly alwaysRun = true;\n readonly appName = \"FileManager\";\n readonly dependsOn = [];\n\n constructor(\n private identityContext: IdentityContext.Interface,\n private updateSettings: UpdateSettingsUseCase.Interface,\n private keyValueStore: KeyValueStore.Interface\n ) {}\n\n async install(): Promise<void> {\n // TODO: move this to api-core with a proper abstraction\n const manifest = await ServiceDiscovery.load();\n\n // If no records in the database, `manifest` object is empty POJO.\n // That's why the heavy `?.` usage.\n const domain = manifest?.api?.cloudfront?.domain;\n\n // The installer can run as the caller (e.g. Tenant Manager creating a tenant),\n // and the value comes from the API's own URL, not from caller input.\n await this.identityContext.withoutAuthorization(() => {\n return this.updateSettings.execute({\n // An empty value makes validation fall back to an empty prefix.\n srcPrefix: domain ? `${domain}/files` : \"\"\n });\n });\n }\n\n async uninstall(): Promise<void> {\n await this.keyValueStore.delete(FILE_MANAGER_GENERAL_SETTINGS);\n }\n}\n\nexport const SettingsInstaller = createImplementation({\n abstraction: AppInstaller,\n implementation: SettingsInstallerImpl,\n dependencies: [IdentityContext, UpdateSettingsUseCase, KeyValueStore]\n});\n"],"names":["SettingsInstallerImpl","identityContext","updateSettings","keyValueStore","manifest","ServiceDiscovery","domain","FILE_MANAGER_GENERAL_SETTINGS","SettingsInstaller","createImplementation","AppInstaller","IdentityContext","UpdateSettingsUseCase","KeyValueStore"],"mappings":";;;;;;;AAQA,MAAMA;IAKF,YACYC,eAA0C,EAC1CC,cAA+C,EAC/CC,aAAsC,CAChD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,aAAa,GAAbA;aAPH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;IAMpB;IAEH,MAAM,UAAyB;QAE3B,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAI5C,MAAMC,SAASF,UAAU,KAAK,YAAY;QAI1C,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACrC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;gBAE/B,WAAWE,SAAS,GAAGA,OAAO,MAAM,CAAC,GAAG;YAC5C;IAER;IAEA,MAAM,YAA2B;QAC7B,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACC;IACpC;AACJ;AAEO,MAAMC,oBAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBV;IAChB,cAAc;QAACW;QAAiBC;QAAuBC;KAAc;AACzE"}
@@ -5,11 +5,13 @@ import { GetSettingsUseCase } from "../GetSettings/abstractions.js";
5
5
  import type { FileManagerSettings } from "../../../domain/settings/types.js";
6
6
  import type { UpdateSettingsInput } from "../../../domain/settings/types.js";
7
7
  import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
8
+ import { FmPermissions } from "../../../features/shared/abstractions.js";
8
9
  declare class UpdateSettingsUseCaseImpl implements UseCaseAbstraction.Interface {
10
+ private permissions;
9
11
  private keyValueStore;
10
12
  private getSettings;
11
13
  private eventPublisher;
12
- constructor(keyValueStore: KeyValueStore.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface);
14
+ constructor(permissions: FmPermissions.Interface, keyValueStore: KeyValueStore.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface);
13
15
  execute(input: UpdateSettingsInput): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>>;
14
16
  }
15
17
  export declare const UpdateSettingsUseCase: typeof UpdateSettingsUseCaseImpl & {
@@ -2,25 +2,29 @@ import { Result } from "@webiny/feature/api";
2
2
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
3
  import { UpdateSettingsUseCase } from "./abstractions.js";
4
4
  import { GetSettingsUseCase } from "../GetSettings/abstractions.js";
5
- import { SettingsUpdateError, SettingsValidationError } from "../../../domain/settings/errors.js";
5
+ import { SettingsNotAuthorizedError, SettingsUpdateError, SettingsValidationError } from "../../../domain/settings/errors.js";
6
6
  import { FILE_MANAGER_GENERAL_SETTINGS } from "../../../domain/settings/constants.js";
7
7
  import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
8
8
  import { SettingsAfterUpdateEvent, SettingsBeforeUpdateEvent } from "./events.js";
9
- import { updateSettingsValidation } from "../../../domain/settings/validation.js";
9
+ import { mergedSettingsValidation, updateSettingsValidation } from "../../../domain/settings/validation.js";
10
10
  import { createZodError } from "@webiny/utils";
11
+ import { FmPermissions } from "../../shared/abstractions.js";
11
12
  class UpdateSettingsUseCaseImpl {
12
- constructor(keyValueStore, getSettings, eventPublisher){
13
+ constructor(permissions, keyValueStore, getSettings, eventPublisher){
14
+ this.permissions = permissions;
13
15
  this.keyValueStore = keyValueStore;
14
16
  this.getSettings = getSettings;
15
17
  this.eventPublisher = eventPublisher;
16
18
  }
17
19
  async execute(input) {
20
+ const hasPermission = await this.permissions.canAccess("settings");
21
+ if (!hasPermission) return Result.fail(new SettingsNotAuthorizedError());
18
22
  const validationResult = await updateSettingsValidation.safeParseAsync(input);
19
23
  if (!validationResult.success) {
20
24
  const zodError = createZodError(validationResult.error);
21
25
  return Result.fail(new SettingsValidationError(zodError.data.invalidFields));
22
26
  }
23
- const validatedInput = validationResult.data;
27
+ const validatedInput = Object.fromEntries(Object.entries(validationResult.data).filter(([, value])=>void 0 !== value));
24
28
  const existingResult = await this.getSettings.execute();
25
29
  if (existingResult.isFail()) return existingResult;
26
30
  const existing = existingResult.value;
@@ -28,6 +32,11 @@ class UpdateSettingsUseCaseImpl {
28
32
  ...existing,
29
33
  ...validatedInput
30
34
  };
35
+ const mergedValidationResult = mergedSettingsValidation.safeParse(updatedSettings);
36
+ if (!mergedValidationResult.success) {
37
+ const zodError = createZodError(mergedValidationResult.error);
38
+ return Result.fail(new SettingsValidationError(zodError.data.invalidFields));
39
+ }
31
40
  await this.eventPublisher.publish(new SettingsBeforeUpdateEvent({
32
41
  original: existing,
33
42
  settings: updatedSettings,
@@ -46,6 +55,7 @@ class UpdateSettingsUseCaseImpl {
46
55
  const UpdateSettingsUseCase_UpdateSettingsUseCase = UpdateSettingsUseCase.createImplementation({
47
56
  implementation: UpdateSettingsUseCaseImpl,
48
57
  dependencies: [
58
+ FmPermissions,
49
59
  KeyValueStore,
50
60
  GetSettingsUseCase,
51
61
  EventPublisher
@@ -1 +1 @@
1
- {"version":3,"file":"features/settings/UpdateSettings/UpdateSettingsUseCase.js","sources":["../../../../src/features/settings/UpdateSettings/UpdateSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { UpdateSettingsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../GetSettings/abstractions.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport type { UpdateSettingsInput } from \"~/domain/settings/types.js\";\nimport { SettingsUpdateError } from \"~/domain/settings/errors.js\";\nimport { SettingsValidationError } from \"~/domain/settings/errors.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { SettingsBeforeUpdateEvent, SettingsAfterUpdateEvent } from \"./events.js\";\nimport { updateSettingsValidation } from \"~/domain/settings/validation.js\";\nimport { createZodError } from \"@webiny/utils\";\n\nclass UpdateSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(\n input: UpdateSettingsInput\n ): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>> {\n // Validate input\n const validationResult = await updateSettingsValidation.safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(new SettingsValidationError(zodError.data!.invalidFields));\n }\n\n const validatedInput = validationResult.data;\n\n // Get existing settings to merge with new data\n const existingResult = await this.getSettings.execute();\n if (existingResult.isFail()) {\n return existingResult;\n }\n const existing = existingResult.value;\n\n // Prepare merged settings\n const updatedSettings: FileManagerSettings = {\n ...existing,\n ...validatedInput\n };\n\n // Publish BeforeUpdate event\n await this.eventPublisher.publish(\n new SettingsBeforeUpdateEvent({\n original: existing,\n settings: updatedSettings,\n input: validatedInput\n })\n );\n\n const result = await this.keyValueStore.set(FILE_MANAGER_GENERAL_SETTINGS, updatedSettings);\n\n if (result.isFail()) {\n return Result.fail(new SettingsUpdateError(result.error));\n }\n\n // Publish AfterUpdate event\n await this.eventPublisher.publish(\n new SettingsAfterUpdateEvent({\n original: existing,\n settings: updatedSettings,\n input: validatedInput\n })\n );\n\n return Result.ok(updatedSettings);\n }\n}\n\nexport const UpdateSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateSettingsUseCaseImpl,\n dependencies: [KeyValueStore, GetSettingsUseCase, EventPublisher]\n});\n"],"names":["UpdateSettingsUseCaseImpl","keyValueStore","getSettings","eventPublisher","input","validationResult","updateSettingsValidation","zodError","createZodError","Result","SettingsValidationError","validatedInput","existingResult","existing","updatedSettings","SettingsBeforeUpdateEvent","result","FILE_MANAGER_GENERAL_SETTINGS","SettingsUpdateError","SettingsAfterUpdateEvent","UpdateSettingsUseCase","UseCaseAbstraction","KeyValueStore","GetSettingsUseCase","EventPublisher"],"mappings":";;;;;;;;;;AAcA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAAyC,EACzCC,cAAwC,CAClD;aAHUF,aAAa,GAAbA;aACAC,WAAW,GAAXA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QACFC,KAA0B,EACoC;QAE9D,MAAMC,mBAAmB,MAAMC,yBAAyB,cAAc,CAACF;QACvE,IAAI,CAACC,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOI,OAAO,IAAI,CAAC,IAAIC,wBAAwBH,SAAS,IAAI,CAAE,aAAa;QAC/E;QAEA,MAAMI,iBAAiBN,iBAAiB,IAAI;QAG5C,MAAMO,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QACrD,IAAIA,eAAe,MAAM,IACrB,OAAOA;QAEX,MAAMC,WAAWD,eAAe,KAAK;QAGrC,MAAME,kBAAuC;YACzC,GAAGD,QAAQ;YACX,GAAGF,cAAc;QACrB;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,0BAA0B;YAC1B,UAAUF;YACV,UAAUC;YACV,OAAOH;QACX;QAGJ,MAAMK,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACC,+BAA+BH;QAE3E,IAAIE,OAAO,MAAM,IACb,OAAOP,OAAO,IAAI,CAAC,IAAIS,oBAAoBF,OAAO,KAAK;QAI3D,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,yBAAyB;YACzB,UAAUN;YACV,UAAUC;YACV,OAAOH;QACX;QAGJ,OAAOF,OAAO,EAAE,CAACK;IACrB;AACJ;AAEO,MAAMM,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBrB;IAChB,cAAc;QAACsB;QAAeC;QAAoBC;KAAe;AACrE"}
1
+ {"version":3,"file":"features/settings/UpdateSettings/UpdateSettingsUseCase.js","sources":["../../../../src/features/settings/UpdateSettings/UpdateSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { UpdateSettingsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"../GetSettings/abstractions.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport type { UpdateSettingsInput } from \"~/domain/settings/types.js\";\nimport { SettingsUpdateError } from \"~/domain/settings/errors.js\";\nimport { SettingsValidationError } from \"~/domain/settings/errors.js\";\nimport { SettingsNotAuthorizedError } from \"~/domain/settings/errors.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { SettingsBeforeUpdateEvent, SettingsAfterUpdateEvent } from \"./events.js\";\nimport {\n mergedSettingsValidation,\n updateSettingsValidation\n} from \"~/domain/settings/validation.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { FmPermissions } from \"~/features/shared/abstractions.js\";\n\nclass UpdateSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private permissions: FmPermissions.Interface,\n private keyValueStore: KeyValueStore.Interface,\n private getSettings: GetSettingsUseCase.Interface,\n private eventPublisher: EventPublisher.Interface\n ) {}\n\n async execute(\n input: UpdateSettingsInput\n ): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>> {\n const hasPermission = await this.permissions.canAccess(\"settings\");\n if (!hasPermission) {\n return Result.fail(new SettingsNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await updateSettingsValidation.safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(new SettingsValidationError(zodError.data!.invalidFields));\n }\n\n // Drop keys passed as `undefined`, so they don't overwrite stored values.\n const validatedInput = Object.fromEntries(\n Object.entries(validationResult.data).filter(([, value]) => value !== undefined)\n ) as UpdateSettingsInput;\n\n // Get existing settings to merge with new data\n const existingResult = await this.getSettings.execute();\n if (existingResult.isFail()) {\n return existingResult;\n }\n const existing = existingResult.value;\n\n // Prepare merged settings\n const updatedSettings: FileManagerSettings = {\n ...existing,\n ...validatedInput\n };\n\n const mergedValidationResult = mergedSettingsValidation.safeParse(updatedSettings);\n if (!mergedValidationResult.success) {\n const zodError = createZodError(mergedValidationResult.error);\n return Result.fail(new SettingsValidationError(zodError.data!.invalidFields));\n }\n\n // Publish BeforeUpdate event\n await this.eventPublisher.publish(\n new SettingsBeforeUpdateEvent({\n original: existing,\n settings: updatedSettings,\n input: validatedInput\n })\n );\n\n const result = await this.keyValueStore.set(FILE_MANAGER_GENERAL_SETTINGS, updatedSettings);\n\n if (result.isFail()) {\n return Result.fail(new SettingsUpdateError(result.error));\n }\n\n // Publish AfterUpdate event\n await this.eventPublisher.publish(\n new SettingsAfterUpdateEvent({\n original: existing,\n settings: updatedSettings,\n input: validatedInput\n })\n );\n\n return Result.ok(updatedSettings);\n }\n}\n\nexport const UpdateSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateSettingsUseCaseImpl,\n dependencies: [FmPermissions, KeyValueStore, GetSettingsUseCase, EventPublisher]\n});\n"],"names":["UpdateSettingsUseCaseImpl","permissions","keyValueStore","getSettings","eventPublisher","input","hasPermission","Result","SettingsNotAuthorizedError","validationResult","updateSettingsValidation","zodError","createZodError","SettingsValidationError","validatedInput","Object","value","undefined","existingResult","existing","updatedSettings","mergedValidationResult","mergedSettingsValidation","SettingsBeforeUpdateEvent","result","FILE_MANAGER_GENERAL_SETTINGS","SettingsUpdateError","SettingsAfterUpdateEvent","UpdateSettingsUseCase","UseCaseAbstraction","FmPermissions","KeyValueStore","GetSettingsUseCase","EventPublisher"],"mappings":";;;;;;;;;;;AAmBA,MAAMA;IACF,YACYC,WAAoC,EACpCC,aAAsC,EACtCC,WAAyC,EACzCC,cAAwC,CAClD;aAJUH,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,WAAW,GAAXA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QACFC,KAA0B,EACoC;QAC9D,MAAMC,gBAAgB,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;QACvD,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,mBAAmB,MAAMC,yBAAyB,cAAc,CAACL;QACvE,IAAI,CAACI,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOF,OAAO,IAAI,CAAC,IAAIM,wBAAwBF,SAAS,IAAI,CAAE,aAAa;QAC/E;QAGA,MAAMG,iBAAiBC,OAAO,WAAW,CACrCA,OAAO,OAAO,CAACN,iBAAiB,IAAI,EAAE,MAAM,CAAC,CAAC,GAAGO,MAAM,GAAKA,AAAUC,WAAVD;QAIhE,MAAME,iBAAiB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QACrD,IAAIA,eAAe,MAAM,IACrB,OAAOA;QAEX,MAAMC,WAAWD,eAAe,KAAK;QAGrC,MAAME,kBAAuC;YACzC,GAAGD,QAAQ;YACX,GAAGL,cAAc;QACrB;QAEA,MAAMO,yBAAyBC,yBAAyB,SAAS,CAACF;QAClE,IAAI,CAACC,uBAAuB,OAAO,EAAE;YACjC,MAAMV,WAAWC,eAAeS,uBAAuB,KAAK;YAC5D,OAAOd,OAAO,IAAI,CAAC,IAAIM,wBAAwBF,SAAS,IAAI,CAAE,aAAa;QAC/E;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIY,0BAA0B;YAC1B,UAAUJ;YACV,UAAUC;YACV,OAAON;QACX;QAGJ,MAAMU,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACC,+BAA+BL;QAE3E,IAAII,OAAO,MAAM,IACb,OAAOjB,OAAO,IAAI,CAAC,IAAImB,oBAAoBF,OAAO,KAAK;QAI3D,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,yBAAyB;YACzB,UAAUR;YACV,UAAUC;YACV,OAAON;QACX;QAGJ,OAAOP,OAAO,EAAE,CAACa;IACrB;AACJ;AAEO,MAAMQ,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgB7B;IAChB,cAAc;QAAC8B;QAAeC;QAAeC;QAAoBC;KAAe;AACpF"}
@@ -3,6 +3,7 @@ import type { FileManagerSettings } from "../../../domain/settings/types.js";
3
3
  import type { UpdateSettingsInput } from "../../../domain/settings/types.js";
4
4
  import type { SettingsUpdateError } from "../../../domain/settings/errors.js";
5
5
  import type { SettingsValidationError } from "../../../domain/settings/errors.js";
6
+ import type { SettingsNotAuthorizedError } from "../../../domain/settings/errors.js";
6
7
  /**
7
8
  * UpdateSettings use case interface
8
9
  */
@@ -10,6 +11,7 @@ export interface IUpdateSettingsUseCase {
10
11
  execute(input: UpdateSettingsInput): Promise<Result<FileManagerSettings, UseCaseError>>;
11
12
  }
12
13
  export interface IUpdateSettingsUseCaseErrors {
14
+ notAuthorized: SettingsNotAuthorizedError;
13
15
  updateError: SettingsUpdateError;
14
16
  validationError: SettingsValidationError;
15
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/settings/UpdateSettings/abstractions.js","sources":["../../../../src/features/settings/UpdateSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport type { UpdateSettingsInput } from \"~/domain/settings/types.js\";\nimport type { SettingsUpdateError } from \"~/domain/settings/errors.js\";\nimport type { SettingsValidationError } from \"~/domain/settings/errors.js\";\n\n/**\n * UpdateSettings use case interface\n */\nexport interface IUpdateSettingsUseCase {\n execute(input: UpdateSettingsInput): Promise<Result<FileManagerSettings, UseCaseError>>;\n}\n\nexport interface IUpdateSettingsUseCaseErrors {\n updateError: SettingsUpdateError;\n validationError: SettingsValidationError;\n}\n\ntype UseCaseError = IUpdateSettingsUseCaseErrors[keyof IUpdateSettingsUseCaseErrors];\n\n/** Update file manager settings. */\nexport const UpdateSettingsUseCase =\n createAbstraction<IUpdateSettingsUseCase>(\"UpdateSettingsUseCase\");\n\nexport namespace UpdateSettingsUseCase {\n export type Interface = IUpdateSettingsUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["UpdateSettingsUseCase","createAbstraction"],"mappings":";AAsBO,MAAMA,wBACTC,kBAA0C"}
1
+ {"version":3,"file":"features/settings/UpdateSettings/abstractions.js","sources":["../../../../src/features/settings/UpdateSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport type { UpdateSettingsInput } from \"~/domain/settings/types.js\";\nimport type { SettingsUpdateError } from \"~/domain/settings/errors.js\";\nimport type { SettingsValidationError } from \"~/domain/settings/errors.js\";\nimport type { SettingsNotAuthorizedError } from \"~/domain/settings/errors.js\";\n\n/**\n * UpdateSettings use case interface\n */\nexport interface IUpdateSettingsUseCase {\n execute(input: UpdateSettingsInput): Promise<Result<FileManagerSettings, UseCaseError>>;\n}\n\nexport interface IUpdateSettingsUseCaseErrors {\n notAuthorized: SettingsNotAuthorizedError;\n updateError: SettingsUpdateError;\n validationError: SettingsValidationError;\n}\n\ntype UseCaseError = IUpdateSettingsUseCaseErrors[keyof IUpdateSettingsUseCaseErrors];\n\n/** Update file manager settings. */\nexport const UpdateSettingsUseCase =\n createAbstraction<IUpdateSettingsUseCase>(\"UpdateSettingsUseCase\");\n\nexport namespace UpdateSettingsUseCase {\n export type Interface = IUpdateSettingsUseCase;\n export type Error = UseCaseError;\n}\n"],"names":["UpdateSettingsUseCase","createAbstraction"],"mappings":";AAwBO,MAAMA,wBACTC,kBAA0C"}
@@ -3,6 +3,10 @@ import type { CreateMultiPartUploadResult } from "../../../features/upload/types
3
3
  export interface ICreateMultiPartUploadParams {
4
4
  file: FileData;
5
5
  numberOfParts: number;
6
+ /**
7
+ * The file id, when it was provided by the client (not generated on the server).
8
+ */
9
+ clientId?: string;
6
10
  }
7
11
  export interface ICreateMultiPartUploadUseCase {
8
12
  execute(params: ICreateMultiPartUploadParams): Promise<CreateMultiPartUploadResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/upload/CreateMultiPartUpload/abstractions.js","sources":["../../../../src/features/upload/CreateMultiPartUpload/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileData } from \"~/features/upload/types.js\";\nimport type { CreateMultiPartUploadResult } from \"~/features/upload/types.js\";\n\nexport interface ICreateMultiPartUploadParams {\n file: FileData;\n numberOfParts: number;\n}\n\nexport interface ICreateMultiPartUploadUseCase {\n execute(params: ICreateMultiPartUploadParams): Promise<CreateMultiPartUploadResult>;\n}\n\nexport const CreateMultiPartUploadUseCase = createAbstraction<ICreateMultiPartUploadUseCase>(\n \"CreateMultiPartUploadUseCase\"\n);\n\nexport namespace CreateMultiPartUploadUseCase {\n export type Interface = ICreateMultiPartUploadUseCase;\n export type Params = ICreateMultiPartUploadParams;\n}\n"],"names":["CreateMultiPartUploadUseCase","createAbstraction"],"mappings":";AAaO,MAAMA,+BAA+BC,kBACxC"}
1
+ {"version":3,"file":"features/upload/CreateMultiPartUpload/abstractions.js","sources":["../../../../src/features/upload/CreateMultiPartUpload/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileData } from \"~/features/upload/types.js\";\nimport type { CreateMultiPartUploadResult } from \"~/features/upload/types.js\";\n\nexport interface ICreateMultiPartUploadParams {\n file: FileData;\n numberOfParts: number;\n /**\n * The file id, when it was provided by the client (not generated on the server).\n */\n clientId?: string;\n}\n\nexport interface ICreateMultiPartUploadUseCase {\n execute(params: ICreateMultiPartUploadParams): Promise<CreateMultiPartUploadResult>;\n}\n\nexport const CreateMultiPartUploadUseCase = createAbstraction<ICreateMultiPartUploadUseCase>(\n \"CreateMultiPartUploadUseCase\"\n);\n\nexport namespace CreateMultiPartUploadUseCase {\n export type Interface = ICreateMultiPartUploadUseCase;\n export type Params = ICreateMultiPartUploadParams;\n}\n"],"names":["CreateMultiPartUploadUseCase","createAbstraction"],"mappings":";AAiBO,MAAMA,+BAA+BC,kBACxC"}
@@ -1,10 +1,17 @@
1
1
  import type { FileData } from "../../../features/upload/types.js";
2
2
  import type { UploadPayloadResponse } from "../../../features/upload/types.js";
3
3
  import type { FileManagerSettings } from "../../../domain/settings/types.js";
4
+ export interface IGetUploadPayloadOptions {
5
+ /**
6
+ * The file id, when it was provided by the client (not generated on the server).
7
+ */
8
+ clientId?: string;
9
+ }
4
10
  export interface IGetUploadPayloadUseCase {
5
- execute(file: FileData, settings: FileManagerSettings): Promise<UploadPayloadResponse>;
11
+ execute(file: FileData, settings: FileManagerSettings, options?: IGetUploadPayloadOptions): Promise<UploadPayloadResponse>;
6
12
  }
7
13
  export declare const GetUploadPayloadUseCase: import("@webiny/di").Abstraction<IGetUploadPayloadUseCase>;
8
14
  export declare namespace GetUploadPayloadUseCase {
9
15
  type Interface = IGetUploadPayloadUseCase;
16
+ type Options = IGetUploadPayloadOptions;
10
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/upload/GetUploadPayload/abstractions.js","sources":["../../../../src/features/upload/GetUploadPayload/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileData } from \"~/features/upload/types.js\";\nimport type { UploadPayloadResponse } from \"~/features/upload/types.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\n\nexport interface IGetUploadPayloadUseCase {\n execute(file: FileData, settings: FileManagerSettings): Promise<UploadPayloadResponse>;\n}\n\nexport const GetUploadPayloadUseCase =\n createAbstraction<IGetUploadPayloadUseCase>(\"GetUploadPayloadUseCase\");\n\nexport namespace GetUploadPayloadUseCase {\n export type Interface = IGetUploadPayloadUseCase;\n}\n"],"names":["GetUploadPayloadUseCase","createAbstraction"],"mappings":";AASO,MAAMA,0BACTC,kBAA4C"}
1
+ {"version":3,"file":"features/upload/GetUploadPayload/abstractions.js","sources":["../../../../src/features/upload/GetUploadPayload/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileData } from \"~/features/upload/types.js\";\nimport type { UploadPayloadResponse } from \"~/features/upload/types.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\n\nexport interface IGetUploadPayloadOptions {\n /**\n * The file id, when it was provided by the client (not generated on the server).\n */\n clientId?: string;\n}\n\nexport interface IGetUploadPayloadUseCase {\n execute(\n file: FileData,\n settings: FileManagerSettings,\n options?: IGetUploadPayloadOptions\n ): Promise<UploadPayloadResponse>;\n}\n\nexport const GetUploadPayloadUseCase =\n createAbstraction<IGetUploadPayloadUseCase>(\"GetUploadPayloadUseCase\");\n\nexport namespace GetUploadPayloadUseCase {\n export type Interface = IGetUploadPayloadUseCase;\n export type Options = IGetUploadPayloadOptions;\n}\n"],"names":["GetUploadPayloadUseCase","createAbstraction"],"mappings":";AAoBO,MAAMA,0BACTC,kBAA4C"}
@@ -1,6 +1,7 @@
1
1
  import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
2
2
  import { GlobalKeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
3
3
  import { MetadataWriter } from "./abstractions.js";
4
+ import { FileNotAuthorizedError } from "../../../domain/file/errors.js";
4
5
  class MetadataWriterImpl {
5
6
  constructor(tenantContext, keyValueStore){
6
7
  this.tenantContext = tenantContext;
@@ -8,8 +9,11 @@ class MetadataWriterImpl {
8
9
  }
9
10
  async write(files) {
10
11
  const writers = files.map(async (file)=>{
12
+ const key = `FileManager/File/${file.id}/Metadata`;
11
13
  const metadata = this.getMetadata(file);
12
- await this.keyValueStore.set(`FileManager/File/${file.id}/Metadata`, metadata);
14
+ const existing = await this.keyValueStore.get(key);
15
+ if (existing.isOk() && existing.value?.tenant && existing.value.tenant !== metadata.tenant) throw new FileNotAuthorizedError();
16
+ await this.keyValueStore.set(key, metadata);
13
17
  });
14
18
  await Promise.all(writers);
15
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/upload/WriteFileMetadata/MetadataWriter.js","sources":["../../../../src/features/upload/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { MetadataWriter as MetadataWriterAbstraction } from \"./abstractions.js\";\n\nclass MetadataWriterImpl implements MetadataWriterAbstraction.Interface {\n private readonly tenantContext: TenantContext.Interface;\n private readonly keyValueStore: GlobalKeyValueStore.Interface;\n\n public constructor(\n tenantContext: TenantContext.Interface,\n keyValueStore: GlobalKeyValueStore.Interface\n ) {\n this.tenantContext = tenantContext;\n this.keyValueStore = keyValueStore;\n }\n\n public async write(files: MetadataWriterAbstraction.File[]) {\n const writers = files.map(async file => {\n const metadata = this.getMetadata(file);\n await this.keyValueStore.set(`FileManager/File/${file.id}/Metadata`, metadata);\n });\n\n await Promise.all(writers);\n }\n\n private getMetadata(file: MetadataWriterAbstraction.File) {\n const tenant = this.tenantContext.getTenant();\n return {\n id: file.id,\n bucketKey: `tenants/${tenant.id}/files/${file.key}`,\n tenant: tenant.id,\n size: file.size,\n contentType: file.type\n };\n }\n}\n\nexport const MetadataWriter = MetadataWriterAbstraction.createImplementation({\n implementation: MetadataWriterImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["MetadataWriterImpl","tenantContext","keyValueStore","files","writers","file","metadata","Promise","tenant","MetadataWriter","MetadataWriterAbstraction","TenantContext","GlobalKeyValueStore"],"mappings":";;;AAIA,MAAMA;IAIF,YACIC,aAAsC,EACtCC,aAA4C,CAC9C;QACE,IAAI,CAAC,aAAa,GAAGD;QACrB,IAAI,CAAC,aAAa,GAAGC;IACzB;IAEA,MAAa,MAAMC,KAAuC,EAAE;QACxD,MAAMC,UAAUD,MAAM,GAAG,CAAC,OAAME;YAC5B,MAAMC,WAAW,IAAI,CAAC,WAAW,CAACD;YAClC,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAEA,KAAK,EAAE,CAAC,SAAS,CAAC,EAAEC;QACzE;QAEA,MAAMC,QAAQ,GAAG,CAACH;IACtB;IAEQ,YAAYC,IAAoC,EAAE;QACtD,MAAMG,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO;YACH,IAAIH,KAAK,EAAE;YACX,WAAW,CAAC,QAAQ,EAAEG,OAAO,EAAE,CAAC,OAAO,EAAEH,KAAK,GAAG,EAAE;YACnD,QAAQG,OAAO,EAAE;YACjB,MAAMH,KAAK,IAAI;YACf,aAAaA,KAAK,IAAI;QAC1B;IACJ;AACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAA8C,CAAC;IACzE,gBAAgBV;IAChB,cAAc;QAACW;QAAeC;KAAoB;AACtD"}
1
+ {"version":3,"file":"features/upload/WriteFileMetadata/MetadataWriter.js","sources":["../../../../src/features/upload/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { MetadataWriter as MetadataWriterAbstraction } from \"./abstractions.js\";\nimport { FileNotAuthorizedError } from \"~/domain/file/errors.js\";\n\nclass MetadataWriterImpl implements MetadataWriterAbstraction.Interface {\n private readonly tenantContext: TenantContext.Interface;\n private readonly keyValueStore: GlobalKeyValueStore.Interface;\n\n public constructor(\n tenantContext: TenantContext.Interface,\n keyValueStore: GlobalKeyValueStore.Interface\n ) {\n this.tenantContext = tenantContext;\n this.keyValueStore = keyValueStore;\n }\n\n public async write(files: MetadataWriterAbstraction.File[]) {\n const writers = files.map(async file => {\n const key = `FileManager/File/${file.id}/Metadata`;\n const metadata = this.getMetadata(file);\n\n // Security: metadata is global and keyed only by file id. Never overwrite\n // metadata that belongs to a file in another tenant.\n const existing = await this.keyValueStore.get<{ tenant?: string }>(key);\n if (\n existing.isOk() &&\n existing.value?.tenant &&\n existing.value.tenant !== metadata.tenant\n ) {\n throw new FileNotAuthorizedError();\n }\n\n await this.keyValueStore.set(key, metadata);\n });\n\n await Promise.all(writers);\n }\n\n private getMetadata(file: MetadataWriterAbstraction.File) {\n const tenant = this.tenantContext.getTenant();\n return {\n id: file.id,\n bucketKey: `tenants/${tenant.id}/files/${file.key}`,\n tenant: tenant.id,\n size: file.size,\n contentType: file.type\n };\n }\n}\n\nexport const MetadataWriter = MetadataWriterAbstraction.createImplementation({\n implementation: MetadataWriterImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["MetadataWriterImpl","tenantContext","keyValueStore","files","writers","file","key","metadata","existing","FileNotAuthorizedError","Promise","tenant","MetadataWriter","MetadataWriterAbstraction","TenantContext","GlobalKeyValueStore"],"mappings":";;;;AAKA,MAAMA;IAIF,YACIC,aAAsC,EACtCC,aAA4C,CAC9C;QACE,IAAI,CAAC,aAAa,GAAGD;QACrB,IAAI,CAAC,aAAa,GAAGC;IACzB;IAEA,MAAa,MAAMC,KAAuC,EAAE;QACxD,MAAMC,UAAUD,MAAM,GAAG,CAAC,OAAME;YAC5B,MAAMC,MAAM,CAAC,iBAAiB,EAAED,KAAK,EAAE,CAAC,SAAS,CAAC;YAClD,MAAME,WAAW,IAAI,CAAC,WAAW,CAACF;YAIlC,MAAMG,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAAsBF;YACnE,IACIE,SAAS,IAAI,MACbA,SAAS,KAAK,EAAE,UAChBA,SAAS,KAAK,CAAC,MAAM,KAAKD,SAAS,MAAM,EAEzC,MAAM,IAAIE;YAGd,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACH,KAAKC;QACtC;QAEA,MAAMG,QAAQ,GAAG,CAACN;IACtB;IAEQ,YAAYC,IAAoC,EAAE;QACtD,MAAMM,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO;YACH,IAAIN,KAAK,EAAE;YACX,WAAW,CAAC,QAAQ,EAAEM,OAAO,EAAE,CAAC,OAAO,EAAEN,KAAK,GAAG,EAAE;YACnD,QAAQM,OAAO,EAAE;YACjB,MAAMN,KAAK,IAAI;YACf,aAAaA,KAAK,IAAI;QAC1B;IACJ;AACJ;AAEO,MAAMO,gCAAiBC,eAAAA,oBAA8C,CAAC;IACzE,gBAAgBb;IAChB,cAAc;QAACc;QAAeC;KAAoB;AACtD"}
@@ -1,4 +1,5 @@
1
1
  import { mdbid } from "@webiny/utils";
2
+ import { BaseError } from "@webiny/feature/api";
2
3
  import { FileKey } from "./FileKey.js";
3
4
  import { mimeTypes as external_mimeTypes_js_mimeTypes } from "./mimeTypes.js";
4
5
  const extensionToMime = new Map();
@@ -7,13 +8,39 @@ function resolveTypeFromName(name) {
7
8
  const ext = name.slice(name.lastIndexOf(".") + 1).toLowerCase();
8
9
  return extensionToMime.get(ext) || "application/octet-stream";
9
10
  }
11
+ class InvalidKeyPrefixError extends BaseError {
12
+ constructor(keyPrefix){
13
+ super({
14
+ message: `Invalid file key prefix "${keyPrefix}".`,
15
+ data: {
16
+ keyPrefix
17
+ }
18
+ }), this.code = "INVALID_KEY_PREFIX";
19
+ }
20
+ }
21
+ class InvalidFileIdError extends BaseError {
22
+ constructor(id){
23
+ super({
24
+ message: `Invalid file id "${id}". It may contain only letters, numbers and dashes, and must start and end with a letter or a number.`,
25
+ data: {
26
+ id
27
+ }
28
+ }), this.code = "INVALID_FILE_ID";
29
+ }
30
+ }
31
+ const FILE_ID_PATTERN = /^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/;
10
32
  class FileNormalizer {
11
33
  constructor(modifier){
12
34
  this.modifier = modifier;
13
35
  }
14
36
  async normalizeFile(payload) {
37
+ const keyPrefix = (payload.keyPrefix ?? "").trim();
38
+ const segments = keyPrefix.split("/").map((segment)=>segment.trim());
39
+ if (keyPrefix.startsWith("/") || keyPrefix.includes("\\") || segments.some((segment)=>".." === segment || "." === segment)) throw new InvalidKeyPrefixError(keyPrefix);
40
+ if (payload.id && !FILE_ID_PATTERN.test(payload.id)) throw new InvalidFileIdError(payload.id);
15
41
  const data = {
16
42
  ...payload,
43
+ keyPrefix: keyPrefix || void 0,
17
44
  id: payload.id || mdbid(),
18
45
  type: payload.type || resolveTypeFromName(payload.name)
19
46
  };
@@ -1 +1 @@
1
- {"version":3,"file":"features/upload/utils/FileNormalizer.js","sources":["../../../../src/features/upload/utils/FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport type { FileData, PresignedPostPayloadData } from \"~/features/upload/types.js\";\nimport { FileKey } from \"./FileKey.js\";\nimport { mimeTypes } from \"./mimeTypes.js\";\nimport type { FileModifier } from \"./FileUploadModifier.js\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\n}\n\nconst extensionToMime = new Map<string, string>();\nfor (const [mime, extensions] of Object.entries(mimeTypes)) {\n for (const ext of extensions) {\n if (!extensionToMime.has(ext)) {\n extensionToMime.set(ext, mime);\n }\n }\n}\n\nfunction resolveTypeFromName(name: string): string {\n const ext = name.slice(name.lastIndexOf(\".\") + 1).toLowerCase();\n return extensionToMime.get(ext) || \"application/octet-stream\";\n}\n\n/*\n * FileNormalizer normalizes file data, before it's signed for upload.\n * It generates a unique file id, and makes sure that the file key includes the unique id.\n */\nexport class FileNormalizer {\n private readonly modifier: FileModifier | undefined;\n\n constructor(modifier?: FileModifier) {\n this.modifier = modifier;\n }\n\n async normalizeFile(payload: PresignedPostPayloadData): Promise<FileData> {\n const data = {\n ...payload,\n id: payload.id || mdbid(),\n type: payload.type || resolveTypeFromName(payload.name)\n };\n\n const key = new FileKey(data);\n const defaultKey = key.toString();\n\n const file: FileToSign = {\n name: data.name,\n type: data.type,\n key: defaultKey,\n size: data.size\n };\n\n if (this.modifier) {\n Object.assign(file, await this.modifier(file));\n }\n\n if (defaultKey !== file.key) {\n key.setKey(file.key);\n }\n\n return {\n id: data.id,\n key: key.toString(),\n name: file.name,\n size: file.size,\n type: file.type\n };\n }\n}\n"],"names":["extensionToMime","Map","mime","extensions","Object","mimeTypes","ext","resolveTypeFromName","name","FileNormalizer","modifier","payload","data","mdbid","key","FileKey","defaultKey","file"],"mappings":";;;AAaA,MAAMA,kBAAkB,IAAIC;AAC5B,KAAK,MAAM,CAACC,MAAMC,WAAW,IAAIC,OAAO,OAAO,CAACC,iCAC5C,KAAK,MAAMC,OAAOH,WACd,IAAI,CAACH,gBAAgB,GAAG,CAACM,MACrBN,gBAAgB,GAAG,CAACM,KAAKJ;AAKrC,SAASK,oBAAoBC,IAAY;IACrC,MAAMF,MAAME,KAAK,KAAK,CAACA,KAAK,WAAW,CAAC,OAAO,GAAG,WAAW;IAC7D,OAAOR,gBAAgB,GAAG,CAACM,QAAQ;AACvC;AAMO,MAAMG;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,cAAcC,OAAiC,EAAqB;QACtE,MAAMC,OAAO;YACT,GAAGD,OAAO;YACV,IAAIA,QAAQ,EAAE,IAAIE;YAClB,MAAMF,QAAQ,IAAI,IAAIJ,oBAAoBI,QAAQ,IAAI;QAC1D;QAEA,MAAMG,MAAM,IAAIC,QAAQH;QACxB,MAAMI,aAAaF,IAAI,QAAQ;QAE/B,MAAMG,OAAmB;YACrB,MAAML,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,KAAKI;YACL,MAAMJ,KAAK,IAAI;QACnB;QAEA,IAAI,IAAI,CAAC,QAAQ,EACbR,OAAO,MAAM,CAACa,MAAM,MAAM,IAAI,CAAC,QAAQ,CAACA;QAG5C,IAAID,eAAeC,KAAK,GAAG,EACvBH,IAAI,MAAM,CAACG,KAAK,GAAG;QAGvB,OAAO;YACH,IAAIL,KAAK,EAAE;YACX,KAAKE,IAAI,QAAQ;YACjB,MAAMG,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;QACnB;IACJ;AACJ"}
1
+ {"version":3,"file":"features/upload/utils/FileNormalizer.js","sources":["../../../../src/features/upload/utils/FileNormalizer.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { BaseError } from \"@webiny/feature/api\";\nimport type { FileData, PresignedPostPayloadData } from \"~/features/upload/types.js\";\nimport { FileKey } from \"./FileKey.js\";\nimport { mimeTypes } from \"./mimeTypes.js\";\nimport type { FileModifier } from \"./FileUploadModifier.js\";\n\nexport interface FileToSign {\n name: string;\n key: string;\n type: string;\n size: number;\n}\n\nconst extensionToMime = new Map<string, string>();\nfor (const [mime, extensions] of Object.entries(mimeTypes)) {\n for (const ext of extensions) {\n if (!extensionToMime.has(ext)) {\n extensionToMime.set(ext, mime);\n }\n }\n}\n\nfunction resolveTypeFromName(name: string): string {\n const ext = name.slice(name.lastIndexOf(\".\") + 1).toLowerCase();\n return extensionToMime.get(ext) || \"application/octet-stream\";\n}\n\nclass InvalidKeyPrefixError extends BaseError<{ keyPrefix: string }> {\n override readonly code = \"INVALID_KEY_PREFIX\" as const;\n\n constructor(keyPrefix: string) {\n super({ message: `Invalid file key prefix \"${keyPrefix}\".`, data: { keyPrefix } });\n }\n}\n\nclass InvalidFileIdError extends BaseError<{ id: string }> {\n override readonly code = \"INVALID_FILE_ID\" as const;\n\n constructor(id: string) {\n super({\n message: `Invalid file id \"${id}\". It may contain only letters, numbers and dashes, and must start and end with a letter or a number.`,\n data: { id }\n });\n }\n}\n\n// Security: a client id becomes a storage path segment; allow only CMS-style ids.\nconst FILE_ID_PATTERN = /^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/;\n\n/*\n * FileNormalizer normalizes file data, before it's signed for upload.\n * It generates a unique file id, and makes sure that the file key includes the unique id.\n */\nexport class FileNormalizer {\n private readonly modifier: FileModifier | undefined;\n\n constructor(modifier?: FileModifier) {\n this.modifier = modifier;\n }\n\n async normalizeFile(payload: PresignedPostPayloadData): Promise<FileData> {\n const keyPrefix = (payload.keyPrefix ?? \"\").trim();\n const segments = keyPrefix.split(\"/\").map(segment => segment.trim());\n if (\n keyPrefix.startsWith(\"/\") ||\n keyPrefix.includes(\"\\\\\") ||\n segments.some(segment => segment === \"..\" || segment === \".\")\n ) {\n throw new InvalidKeyPrefixError(keyPrefix);\n }\n\n if (payload.id && !FILE_ID_PATTERN.test(payload.id)) {\n throw new InvalidFileIdError(payload.id);\n }\n\n const data = {\n ...payload,\n keyPrefix: keyPrefix || undefined,\n id: payload.id || mdbid(),\n type: payload.type || resolveTypeFromName(payload.name)\n };\n\n const key = new FileKey(data);\n const defaultKey = key.toString();\n\n const file: FileToSign = {\n name: data.name,\n type: data.type,\n key: defaultKey,\n size: data.size\n };\n\n if (this.modifier) {\n Object.assign(file, await this.modifier(file));\n }\n\n if (defaultKey !== file.key) {\n key.setKey(file.key);\n }\n\n return {\n id: data.id,\n key: key.toString(),\n name: file.name,\n size: file.size,\n type: file.type\n };\n }\n}\n"],"names":["extensionToMime","Map","mime","extensions","Object","mimeTypes","ext","resolveTypeFromName","name","InvalidKeyPrefixError","BaseError","keyPrefix","InvalidFileIdError","id","FILE_ID_PATTERN","FileNormalizer","modifier","payload","segments","segment","data","undefined","mdbid","key","FileKey","defaultKey","file"],"mappings":";;;;AAcA,MAAMA,kBAAkB,IAAIC;AAC5B,KAAK,MAAM,CAACC,MAAMC,WAAW,IAAIC,OAAO,OAAO,CAACC,iCAC5C,KAAK,MAAMC,OAAOH,WACd,IAAI,CAACH,gBAAgB,GAAG,CAACM,MACrBN,gBAAgB,GAAG,CAACM,KAAKJ;AAKrC,SAASK,oBAAoBC,IAAY;IACrC,MAAMF,MAAME,KAAK,KAAK,CAACA,KAAK,WAAW,CAAC,OAAO,GAAG,WAAW;IAC7D,OAAOR,gBAAgB,GAAG,CAACM,QAAQ;AACvC;AAEA,MAAMG,8BAA8BC;IAGhC,YAAYC,SAAiB,CAAE;QAC3B,KAAK,CAAC;YAAE,SAAS,CAAC,yBAAyB,EAAEA,UAAU,EAAE,CAAC;YAAE,MAAM;gBAAEA;YAAU;QAAE,SAHlE,IAAI,GAAG;IAIzB;AACJ;AAEA,MAAMC,2BAA2BF;IAG7B,YAAYG,EAAU,CAAE;QACpB,KAAK,CAAC;YACF,SAAS,CAAC,iBAAiB,EAAEA,GAAG,qGAAqG,CAAC;YACtI,MAAM;gBAAEA;YAAG;QACf,SANc,IAAI,GAAG;IAOzB;AACJ;AAGA,MAAMC,kBAAkB;AAMjB,MAAMC;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,cAAcC,OAAiC,EAAqB;QACtE,MAAMN,YAAaM,AAAAA,CAAAA,QAAQ,SAAS,IAAI,EAAC,EAAG,IAAI;QAChD,MAAMC,WAAWP,UAAU,KAAK,CAAC,KAAK,GAAG,CAACQ,CAAAA,UAAWA,QAAQ,IAAI;QACjE,IACIR,UAAU,UAAU,CAAC,QACrBA,UAAU,QAAQ,CAAC,SACnBO,SAAS,IAAI,CAACC,CAAAA,UAAWA,AAAY,SAAZA,WAAoBA,AAAY,QAAZA,UAE7C,MAAM,IAAIV,sBAAsBE;QAGpC,IAAIM,QAAQ,EAAE,IAAI,CAACH,gBAAgB,IAAI,CAACG,QAAQ,EAAE,GAC9C,MAAM,IAAIL,mBAAmBK,QAAQ,EAAE;QAG3C,MAAMG,OAAO;YACT,GAAGH,OAAO;YACV,WAAWN,aAAaU;YACxB,IAAIJ,QAAQ,EAAE,IAAIK;YAClB,MAAML,QAAQ,IAAI,IAAIV,oBAAoBU,QAAQ,IAAI;QAC1D;QAEA,MAAMM,MAAM,IAAIC,QAAQJ;QACxB,MAAMK,aAAaF,IAAI,QAAQ;QAE/B,MAAMG,OAAmB;YACrB,MAAMN,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,KAAKK;YACL,MAAML,KAAK,IAAI;QACnB;QAEA,IAAI,IAAI,CAAC,QAAQ,EACbhB,OAAO,MAAM,CAACsB,MAAM,MAAM,IAAI,CAAC,QAAQ,CAACA;QAG5C,IAAID,eAAeC,KAAK,GAAG,EACvBH,IAAI,MAAM,CAACG,KAAK,GAAG;QAGvB,OAAO;YACH,IAAIN,KAAK,EAAE;YACX,KAAKG,IAAI,QAAQ;YACjB,MAAMG,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;QACnB;IACJ;AACJ"}
@@ -1,5 +1,6 @@
1
1
  import { GraphQLSchemaFactory } from "@webiny/handler-graphql/graphql/abstractions.js";
2
2
  import { ErrorResponse, ListResponse, NotFoundResponse, Response } from "@webiny/handler-graphql";
3
+ import NotAuthorizedResponse from "@webiny/api-core/graphql/security/NotAuthorizedResponse.js";
3
4
  import { renderFields } from "@webiny/api-headless-cms/utils/renderFields.js";
4
5
  import { renderInputFields } from "@webiny/api-headless-cms/utils/renderInputFields.js";
5
6
  import { renderListFilterFields } from "@webiny/api-headless-cms/utils/renderListFilterFields.js";
@@ -297,9 +298,11 @@ class FmGraphQLSchemaImpl {
297
298
  builder.addResolver({
298
299
  path: "FmQuery.getSettings",
299
300
  dependencies: [
301
+ IdentityContext,
300
302
  GetSettingsUseCase
301
303
  ],
302
- resolver: (getSettings)=>async ()=>{
304
+ resolver: (identityContext, getSettings)=>async ()=>{
305
+ if (identityContext.getIdentity().isAnonymous()) return new NotAuthorizedResponse();
303
306
  const result = await getSettings.execute();
304
307
  if (result.isFail()) return new ErrorResponse(result.error);
305
308
  return new Response(result.value);
@@ -328,9 +331,13 @@ class FmGraphQLSchemaImpl {
328
331
  builder.addResolver({
329
332
  path: "FmQuery.getFileModel",
330
333
  dependencies: [
334
+ IdentityContext,
331
335
  FileModel
332
336
  ],
333
- resolver: (fileModel)=>()=>new Response(fileModel)
337
+ resolver: (identityContext, fileModel)=>()=>{
338
+ if (identityContext.getIdentity().isAnonymous()) return new NotAuthorizedResponse();
339
+ return new Response(fileModel);
340
+ }
334
341
  });
335
342
  builder.addResolver({
336
343
  path: "FmQuery.getFile",