@webiny/api-file-manager 6.6.0-alpha.1 → 6.6.0-alpha.10

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 (70) hide show
  1. package/delivery/AssetDeliveryRoute.d.ts +1 -0
  2. package/delivery/AssetDeliveryRoute.js +13 -2
  3. package/delivery/AssetDeliveryRoute.js.map +1 -1
  4. package/domain/file/errors.d.ts +10 -0
  5. package/domain/file/errors.js +9 -1
  6. package/domain/file/errors.js.map +1 -1
  7. package/domain/file/file.model.js +2 -1
  8. package/domain/file/file.model.js.map +1 -1
  9. package/domain/file/validateFileKey.d.ts +10 -0
  10. package/domain/file/validateFileKey.js +15 -0
  11. package/domain/file/validateFileKey.js.map +1 -0
  12. package/domain/settings/validation.d.ts +1 -1
  13. package/domain/settings/validation.js +3 -10
  14. package/domain/settings/validation.js.map +1 -1
  15. package/exports/api/file-manager/file.d.ts +2 -1
  16. package/exports/api/file-manager/file.js +2 -1
  17. package/features/FileManagerFeature.js +2 -0
  18. package/features/FileManagerFeature.js.map +1 -1
  19. package/features/file/CreateFile/CreateFileUseCase.js +6 -0
  20. package/features/file/CreateFile/CreateFileUseCase.js.map +1 -1
  21. package/features/file/CreateFile/abstractions.d.ts +2 -0
  22. package/features/file/CreateFile/abstractions.js.map +1 -1
  23. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js +8 -0
  24. package/features/file/CreateFilesInBatch/CreateFilesInBatchUseCase.js.map +1 -1
  25. package/features/file/CreateFilesInBatch/abstractions.d.ts +2 -0
  26. package/features/file/CreateFilesInBatch/abstractions.js.map +1 -1
  27. package/features/file/FileUrlGenerator/FileUrlGenerator.d.ts +4 -6
  28. package/features/file/FileUrlGenerator/FileUrlGenerator.js +7 -13
  29. package/features/file/FileUrlGenerator/FileUrlGenerator.js.map +1 -1
  30. package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.d.ts +13 -0
  31. package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js +29 -0
  32. package/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js.map +1 -0
  33. package/features/file/FileUrlGenerator/abstractions.d.ts +13 -2
  34. package/features/file/FileUrlGenerator/abstractions.js +2 -1
  35. package/features/file/FileUrlGenerator/abstractions.js.map +1 -1
  36. package/features/file/FileUrlGenerator/feature.js +2 -0
  37. package/features/file/FileUrlGenerator/feature.js.map +1 -1
  38. package/features/file/FileUrlGenerator/index.d.ts +1 -0
  39. package/features/file/FileUrlGenerator/index.js +1 -1
  40. package/features/file/ListImagesByTagTool/ListImagesByTagTool.d.ts +10 -5
  41. package/features/file/ListImagesByTagTool/ListImagesByTagTool.js +21 -12
  42. package/features/file/ListImagesByTagTool/ListImagesByTagTool.js.map +1 -1
  43. package/features/file/ListTags/ListTagsRepository.js +21 -2
  44. package/features/file/ListTags/ListTagsRepository.js.map +1 -1
  45. package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.d.ts +11 -0
  46. package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js +20 -0
  47. package/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js.map +1 -0
  48. package/features/settings/DefaultSrcPrefix/abstractions.d.ts +20 -0
  49. package/features/settings/DefaultSrcPrefix/abstractions.js +5 -0
  50. package/features/settings/DefaultSrcPrefix/abstractions.js.map +1 -0
  51. package/features/settings/DefaultSrcPrefix/feature.d.ts +4 -0
  52. package/features/settings/DefaultSrcPrefix/feature.js +11 -0
  53. package/features/settings/DefaultSrcPrefix/feature.js.map +1 -0
  54. package/features/settings/DefaultSrcPrefix/index.d.ts +1 -0
  55. package/features/settings/DefaultSrcPrefix/index.js +1 -0
  56. package/features/settings/GetSettings/GetSettingsUseCase.d.ts +7 -1
  57. package/features/settings/GetSettings/GetSettingsUseCase.js +15 -8
  58. package/features/settings/GetSettings/GetSettingsUseCase.js.map +1 -1
  59. package/features/settings/SettingsInstaller/SettingsInstaller.d.ts +1 -5
  60. package/features/settings/SettingsInstaller/SettingsInstaller.js +3 -16
  61. package/features/settings/SettingsInstaller/SettingsInstaller.js.map +1 -1
  62. package/features/settings/UpdateSettings/UpdateSettingsUseCase.d.ts +9 -1
  63. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js +16 -4
  64. package/features/settings/UpdateSettings/UpdateSettingsUseCase.js.map +1 -1
  65. package/features/upload/utils/FileNormalizer.js +8 -1
  66. package/features/upload/utils/FileNormalizer.js.map +1 -1
  67. package/graphql/FmGraphQLSchema.d.ts +2 -3
  68. package/graphql/FmGraphQLSchema.js +22 -5
  69. package/graphql/FmGraphQLSchema.js.map +1 -1
  70. package/package.json +19 -19
@@ -0,0 +1,13 @@
1
+ import { FileUrlPrefixProvider as Abstraction } from "./abstractions.js";
2
+ import { GetSettingsUseCase } from "../../../features/settings/GetSettings/abstractions.js";
3
+ declare class SettingsFileUrlPrefixProviderImpl implements Abstraction.Interface {
4
+ private readonly getSettings;
5
+ private prefix;
6
+ constructor(getSettings: GetSettingsUseCase.Interface);
7
+ getPrefix(): Promise<string>;
8
+ private loadPrefix;
9
+ }
10
+ export declare const SettingsFileUrlPrefixProvider: typeof SettingsFileUrlPrefixProviderImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IFileUrlPrefixProvider>;
12
+ };
13
+ export {};
@@ -0,0 +1,29 @@
1
+ import { FileUrlPrefixProvider } from "./abstractions.js";
2
+ import { GetSettingsUseCase } from "../../settings/GetSettings/abstractions.js";
3
+ class SettingsFileUrlPrefixProviderImpl {
4
+ constructor(getSettings){
5
+ this.getSettings = getSettings;
6
+ this.prefix = null;
7
+ }
8
+ getPrefix() {
9
+ if (!this.prefix) this.prefix = this.loadPrefix().catch((error)=>{
10
+ this.prefix = null;
11
+ throw error;
12
+ });
13
+ return this.prefix;
14
+ }
15
+ async loadPrefix() {
16
+ const result = await this.getSettings.execute();
17
+ if (result.isFail()) throw result.error;
18
+ return result.value?.srcPrefix ?? "";
19
+ }
20
+ }
21
+ const SettingsFileUrlPrefixProvider = FileUrlPrefixProvider.createImplementation({
22
+ implementation: SettingsFileUrlPrefixProviderImpl,
23
+ dependencies: [
24
+ GetSettingsUseCase
25
+ ]
26
+ });
27
+ export { SettingsFileUrlPrefixProvider };
28
+
29
+ //# sourceMappingURL=SettingsFileUrlPrefixProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.js","sources":["../../../../src/features/file/FileUrlGenerator/SettingsFileUrlPrefixProvider.ts"],"sourcesContent":["import { FileUrlPrefixProvider as Abstraction } from \"./abstractions.js\";\nimport { GetSettingsUseCase } from \"~/features/settings/GetSettings/abstractions.js\";\n\nclass SettingsFileUrlPrefixProviderImpl implements Abstraction.Interface {\n private prefix: Promise<string> | null = null;\n\n public constructor(private readonly getSettings: GetSettingsUseCase.Interface) {}\n\n // Read once per instance, when the first URL is needed. A failed read is forgotten, so the next\n // call tries again.\n public getPrefix(): Promise<string> {\n if (!this.prefix) {\n this.prefix = this.loadPrefix().catch(error => {\n this.prefix = null;\n throw error;\n });\n }\n return this.prefix;\n }\n\n private async loadPrefix(): Promise<string> {\n const result = await this.getSettings.execute();\n if (result.isFail()) {\n throw result.error;\n }\n return result.value?.srcPrefix ?? \"\";\n }\n}\n\nexport const SettingsFileUrlPrefixProvider = Abstraction.createImplementation({\n implementation: SettingsFileUrlPrefixProviderImpl,\n dependencies: [GetSettingsUseCase]\n});\n"],"names":["SettingsFileUrlPrefixProviderImpl","getSettings","error","result","SettingsFileUrlPrefixProvider","Abstraction","GetSettingsUseCase"],"mappings":";;AAGA,MAAMA;IAGF,YAAoCC,WAAyC,CAAE;aAA3CA,WAAW,GAAXA;aAF5B,MAAM,GAA2B;IAEuC;IAIzE,YAA6B;QAChC,IAAI,CAAC,IAAI,CAAC,MAAM,EACZ,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,GAAG,KAAK,CAACC,CAAAA;YAClC,IAAI,CAAC,MAAM,GAAG;YACd,MAAMA;QACV;QAEJ,OAAO,IAAI,CAAC,MAAM;IACtB;IAEA,MAAc,aAA8B;QACxC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO;QAC7C,IAAIA,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAEtB,OAAOA,OAAO,KAAK,EAAE,aAAa;IACtC;AACJ;AAEO,MAAMC,gCAAgCC,sBAAAA,oBAAgC,CAAC;IAC1E,gBAAgBL;IAChB,cAAc;QAACM;KAAmB;AACtC"}
@@ -1,9 +1,20 @@
1
1
  import type { File } from "../../../domain/file/types.js";
2
2
  export interface IFileUrlGenerator {
3
- generateUrl(file: File): string;
4
- init?(): Promise<void>;
3
+ generateUrl(file: File): Promise<string>;
5
4
  }
6
5
  export declare const FileUrlGenerator: import("@webiny/di").Abstraction<IFileUrlGenerator>;
7
6
  export declare namespace FileUrlGenerator {
8
7
  type Interface = IFileUrlGenerator;
9
8
  }
9
+ export interface IFileUrlPrefixProvider {
10
+ getPrefix(): Promise<string>;
11
+ }
12
+ /**
13
+ * Provides the prefix the default FileUrlGenerator puts in front of a file's key. The default
14
+ * implementation reads `srcPrefix` from the File Manager settings. Replace it to load the prefix
15
+ * from somewhere else, without touching how URLs are put together.
16
+ */
17
+ export declare const FileUrlPrefixProvider: import("@webiny/di").Abstraction<IFileUrlPrefixProvider>;
18
+ export declare namespace FileUrlPrefixProvider {
19
+ type Interface = IFileUrlPrefixProvider;
20
+ }
@@ -1,5 +1,6 @@
1
1
  import { createAbstraction } from "@webiny/feature/api";
2
2
  const FileUrlGenerator = createAbstraction("FileManager/FileUrlGenerator");
3
- export { FileUrlGenerator };
3
+ const FileUrlPrefixProvider = createAbstraction("FileManager/FileUrlPrefixProvider");
4
+ export { FileUrlGenerator, FileUrlPrefixProvider };
4
5
 
5
6
  //# sourceMappingURL=abstractions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/FileUrlGenerator/abstractions.js","sources":["../../../../src/features/file/FileUrlGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { File } from \"~/domain/file/types.js\";\n\nexport interface IFileUrlGenerator {\n generateUrl(file: File): string;\n init?(): Promise<void>;\n}\n\n/* Generate URLs for uploaded files. */\nexport const FileUrlGenerator = createAbstraction<IFileUrlGenerator>(\n \"FileManager/FileUrlGenerator\"\n);\n\nexport namespace FileUrlGenerator {\n export type Interface = IFileUrlGenerator;\n}\n"],"names":["FileUrlGenerator","createAbstraction"],"mappings":";AASO,MAAMA,mBAAmBC,kBAC5B"}
1
+ {"version":3,"file":"features/file/FileUrlGenerator/abstractions.js","sources":["../../../../src/features/file/FileUrlGenerator/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { File } from \"~/domain/file/types.js\";\n\nexport interface IFileUrlGenerator {\n generateUrl(file: File): Promise<string>;\n}\n\n/* Generate URLs for uploaded files. */\nexport const FileUrlGenerator = createAbstraction<IFileUrlGenerator>(\n \"FileManager/FileUrlGenerator\"\n);\n\nexport namespace FileUrlGenerator {\n export type Interface = IFileUrlGenerator;\n}\n\nexport interface IFileUrlPrefixProvider {\n getPrefix(): Promise<string>;\n}\n\n/**\n * Provides the prefix the default FileUrlGenerator puts in front of a file's key. The default\n * implementation reads `srcPrefix` from the File Manager settings. Replace it to load the prefix\n * from somewhere else, without touching how URLs are put together.\n */\nexport const FileUrlPrefixProvider = createAbstraction<IFileUrlPrefixProvider>(\n \"FileManager/FileUrlPrefixProvider\"\n);\n\nexport namespace FileUrlPrefixProvider {\n export type Interface = IFileUrlPrefixProvider;\n}\n"],"names":["FileUrlGenerator","createAbstraction","FileUrlPrefixProvider"],"mappings":";AAQO,MAAMA,mBAAmBC,kBAC5B;AAgBG,MAAMC,wBAAwBD,kBACjC"}
@@ -1,9 +1,11 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { FileUrlGenerator } from "./FileUrlGenerator.js";
3
+ import { SettingsFileUrlPrefixProvider } from "./SettingsFileUrlPrefixProvider.js";
3
4
  const FileUrlGeneratorFeature = createFeature({
4
5
  name: "FileManager/FileUrlGenerator",
5
6
  register (container) {
6
7
  container.register(FileUrlGenerator).inSingletonScope();
8
+ container.register(SettingsFileUrlPrefixProvider).inSingletonScope();
7
9
  }
8
10
  });
9
11
  export { FileUrlGeneratorFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/FileUrlGenerator/feature.js","sources":["../../../../src/features/file/FileUrlGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FileUrlGenerator } from \"./FileUrlGenerator.js\";\n\nexport const FileUrlGeneratorFeature = createFeature({\n name: \"FileManager/FileUrlGenerator\",\n register(container) {\n container.register(FileUrlGenerator).inSingletonScope();\n }\n});\n"],"names":["FileUrlGeneratorFeature","createFeature","container","FileUrlGenerator"],"mappings":";;AAGO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,kBAAkB,gBAAgB;IACzD;AACJ"}
1
+ {"version":3,"file":"features/file/FileUrlGenerator/feature.js","sources":["../../../../src/features/file/FileUrlGenerator/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FileUrlGenerator } from \"./FileUrlGenerator.js\";\nimport { SettingsFileUrlPrefixProvider } from \"./SettingsFileUrlPrefixProvider.js\";\n\nexport const FileUrlGeneratorFeature = createFeature({\n name: \"FileManager/FileUrlGenerator\",\n register(container) {\n container.register(FileUrlGenerator).inSingletonScope();\n // A singleton, so the settings are read once per request however many URLs are generated.\n container.register(SettingsFileUrlPrefixProvider).inSingletonScope();\n }\n});\n"],"names":["FileUrlGeneratorFeature","createFeature","container","FileUrlGenerator","SettingsFileUrlPrefixProvider"],"mappings":";;;AAIO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,kBAAkB,gBAAgB;QAErDD,UAAU,QAAQ,CAACE,+BAA+B,gBAAgB;IACtE;AACJ"}
@@ -1 +1,2 @@
1
1
  export { FileUrlGenerator } from "./abstractions.js";
2
+ export { FileUrlPrefixProvider } from "./abstractions.js";
@@ -1 +1 @@
1
- export { FileUrlGenerator } from "./abstractions.js";
1
+ export { FileUrlGenerator, FileUrlPrefixProvider } from "./abstractions.js";
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { type IAiSdkTool } from "@webiny/api-core/features/ai/index.js";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
3
  import { ListFilesUseCase } from "../../../features/file/ListFiles/index.js";
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  tag: z.ZodString;
@@ -11,8 +11,12 @@ interface ImageItem {
11
11
  type: string;
12
12
  tags: string[];
13
13
  }
14
- declare class ListImagesByTagToolImpl implements IAiSdkTool<Input> {
14
+ declare class ListImagesByTagToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
15
15
  private listFiles;
16
+ constructor(listFiles: ListFilesUseCase.Interface);
17
+ execute(input: Input): Promise<ImageItem[]>;
18
+ }
19
+ declare class ListImagesByTagToolImpl implements AiSdkToolDefinition.Interface<Input> {
16
20
  readonly name = "listImagesByTag";
17
21
  readonly title = "List images by tag";
18
22
  readonly description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
@@ -23,10 +27,11 @@ declare class ListImagesByTagToolImpl implements IAiSdkTool<Input> {
23
27
  readOnlyHint: boolean;
24
28
  idempotentHint: boolean;
25
29
  };
26
- constructor(listFiles: ListFilesUseCase.Interface);
27
- execute(input: Input): Promise<ImageItem[]>;
30
+ readonly handler: typeof ListImagesByTagToolHandlerImpl & {
31
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
32
+ };
28
33
  }
29
34
  export declare const ListImagesByTagTool: typeof ListImagesByTagToolImpl & {
30
- __abstraction: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
35
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
31
36
  };
32
37
  export {};
@@ -1,20 +1,12 @@
1
1
  import { z } from "zod";
2
- import { AiSdkTool } from "@webiny/api-core/features/ai/index.js";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
3
  import { ListFilesUseCase } from "../ListFiles/index.js";
4
4
  const inputSchema = z.object({
5
5
  tag: z.string().describe("Tag to filter images by")
6
6
  });
7
- class ListImagesByTagToolImpl {
7
+ class ListImagesByTagToolHandlerImpl {
8
8
  constructor(listFiles){
9
9
  this.listFiles = listFiles;
10
- this.name = "listImagesByTag";
11
- this.title = "List images by tag";
12
- this.description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
13
- this.inputSchema = inputSchema;
14
- this.annotations = {
15
- readOnlyHint: true,
16
- idempotentHint: true
17
- };
18
10
  }
19
11
  async execute(input) {
20
12
  console.log("Call images tool", input);
@@ -36,12 +28,29 @@ class ListImagesByTagToolImpl {
36
28
  }));
37
29
  }
38
30
  }
39
- const ListImagesByTagTool = AiSdkTool.createImplementation({
40
- implementation: ListImagesByTagToolImpl,
31
+ const ListImagesByTagToolHandler = AiSdkToolHandler.createImplementation({
32
+ implementation: ListImagesByTagToolHandlerImpl,
41
33
  dependencies: [
42
34
  ListFilesUseCase
43
35
  ]
44
36
  });
37
+ class ListImagesByTagToolImpl {
38
+ constructor(){
39
+ this.name = "listImagesByTag";
40
+ this.title = "List images by tag";
41
+ this.description = "Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.";
42
+ this.inputSchema = inputSchema;
43
+ this.annotations = {
44
+ readOnlyHint: true,
45
+ idempotentHint: true
46
+ };
47
+ this.handler = ListImagesByTagToolHandler;
48
+ }
49
+ }
50
+ const ListImagesByTagTool = AiSdkToolDefinition.createImplementation({
51
+ implementation: ListImagesByTagToolImpl,
52
+ dependencies: []
53
+ });
45
54
  export { ListImagesByTagTool };
46
55
 
47
56
  //# sourceMappingURL=ListImagesByTagTool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/ListImagesByTagTool/ListImagesByTagTool.js","sources":["../../../../src/features/file/ListImagesByTagTool/ListImagesByTagTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkTool, type IAiSdkTool } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListFilesUseCase } from \"~/features/file/ListFiles/index.js\";\n\nconst inputSchema = z.object({\n tag: z.string().describe(\"Tag to filter images by\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface ImageItem {\n id: string;\n name: string;\n type: string;\n tags: string[];\n}\n\nclass ListImagesByTagToolImpl implements IAiSdkTool<Input> {\n readonly name = \"listImagesByTag\";\n readonly title = \"List images by tag\";\n readonly description =\n \"Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n\n constructor(private listFiles: ListFilesUseCase.Interface) {}\n\n async execute(input: Input): Promise<ImageItem[]> {\n console.log(\"Call images tool\", input);\n const result = await this.listFiles.execute({\n where: {\n type_startsWith: \"image/\",\n tags_in: [input.tag]\n },\n limit: 50\n });\n\n if (result.isFail()) {\n return [];\n }\n\n return result.value.items.map(file => ({\n id: file.id,\n name: file.name,\n type: file.type,\n tags: file.tags\n }));\n }\n}\n\nexport const ListImagesByTagTool = AiSdkTool.createImplementation({\n implementation: ListImagesByTagToolImpl,\n dependencies: [ListFilesUseCase]\n});\n"],"names":["inputSchema","z","ListImagesByTagToolImpl","listFiles","input","console","result","file","ListImagesByTagTool","AiSdkTool","ListFilesUseCase"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,KAAKA,EAAE,MAAM,GAAG,QAAQ,CAAC;AAC7B;AAWA,MAAMC;IAQF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;aAPX,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGH;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;IAEN;IAE5D,MAAM,QAAQI,KAAY,EAAwB;QAC9CC,QAAQ,GAAG,CAAC,oBAAoBD;QAChC,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YACxC,OAAO;gBACH,iBAAiB;gBACjB,SAAS;oBAACF,MAAM,GAAG;iBAAC;YACxB;YACA,OAAO;QACX;QAEA,IAAIE,OAAO,MAAM,IACb,OAAO,EAAE;QAGb,OAAOA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAACC,CAAAA,OAAS;gBACnC,IAAIA,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;YACnB;IACJ;AACJ;AAEO,MAAMC,sBAAsBC,UAAU,oBAAoB,CAAC;IAC9D,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC"}
1
+ {"version":3,"file":"features/file/ListImagesByTagTool/ListImagesByTagTool.js","sources":["../../../../src/features/file/ListImagesByTagTool/ListImagesByTagTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { ListFilesUseCase } from \"~/features/file/ListFiles/index.js\";\n\nconst inputSchema = z.object({\n tag: z.string().describe(\"Tag to filter images by\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface ImageItem {\n id: string;\n name: string;\n type: string;\n tags: string[];\n}\n\nclass ListImagesByTagToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private listFiles: ListFilesUseCase.Interface) {}\n\n async execute(input: Input): Promise<ImageItem[]> {\n console.log(\"Call images tool\", input);\n const result = await this.listFiles.execute({\n where: {\n type_startsWith: \"image/\",\n tags_in: [input.tag]\n },\n limit: 50\n });\n\n if (result.isFail()) {\n return [];\n }\n\n return result.value.items.map(file => ({\n id: file.id,\n name: file.name,\n type: file.type,\n tags: file.tags\n }));\n }\n}\n\nconst ListImagesByTagToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListImagesByTagToolHandlerImpl,\n dependencies: [ListFilesUseCase]\n});\n\nclass ListImagesByTagToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listImagesByTag\";\n readonly title = \"List images by tag\";\n readonly description =\n \"Lists images from the file manager filtered by a given tag. Returns name, type, and tags for each image.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListImagesByTagToolHandler;\n}\n\nexport const ListImagesByTagTool = AiSdkToolDefinition.createImplementation({\n implementation: ListImagesByTagToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListImagesByTagToolHandlerImpl","listFiles","input","console","result","file","ListImagesByTagToolHandler","AiSdkToolHandler","ListFilesUseCase","ListImagesByTagToolImpl","ListImagesByTagTool","AiSdkToolDefinition"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,KAAKA,EAAE,MAAM,GAAG,QAAQ,CAAC;AAC7B;AAWA,MAAMC;IACF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;IAAwC;IAE5D,MAAM,QAAQC,KAAY,EAAwB;QAC9CC,QAAQ,GAAG,CAAC,oBAAoBD;QAChC,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;YACxC,OAAO;gBACH,iBAAiB;gBACjB,SAAS;oBAACF,MAAM,GAAG;iBAAC;YACxB;YACA,OAAO;QACX;QAEA,IAAIE,OAAO,MAAM,IACb,OAAO,EAAE;QAGb,OAAOA,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAACC,CAAAA,OAAS;gBACnC,IAAIA,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;YACnB;IACJ;AACJ;AAEA,MAAMC,6BAA6BC,iBAAiB,oBAAoB,CAAC;IACrE,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC;AAEA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,sBAAsBC,oBAAoB,oBAAoB,CAAC;IACxE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -4,6 +4,10 @@ import { ListTagsRepository } from "./abstractions.js";
4
4
  import { FileModelProvider } from "../../../domain/file/abstractions.js";
5
5
  import { FilePersistenceError } from "../../../domain/file/errors.js";
6
6
  import { CmsWhereMapper } from "@webiny/api-headless-cms";
7
+ const TAG_PREFIX_FILTERS = [
8
+ "tags_startsWith",
9
+ "tags_not_startsWith"
10
+ ];
7
11
  class ListTagsRepositoryImpl {
8
12
  constructor(getUniqueFieldValues, fileModelProvider, cmsWhereMapper){
9
13
  this.getUniqueFieldValues = getUniqueFieldValues;
@@ -12,18 +16,33 @@ class ListTagsRepositoryImpl {
12
16
  }
13
17
  async execute(input) {
14
18
  const fileModel = await this.fileModelProvider.get();
19
+ const filesWhere = {};
20
+ const tagFilters = [];
21
+ for (const [key, value] of Object.entries(input.where || {})){
22
+ if (TAG_PREFIX_FILTERS.includes(key)) {
23
+ if (null != value && "" !== value) tagFilters.push({
24
+ key,
25
+ prefix: String(value).toLowerCase()
26
+ });
27
+ continue;
28
+ }
29
+ filesWhere[key] = value;
30
+ }
15
31
  const result = await this.getUniqueFieldValues.execute(fileModel, {
16
32
  fieldId: "tags",
17
33
  where: this.cmsWhereMapper.map({
18
34
  input: {
19
- ...input.where || {},
35
+ ...filesWhere,
20
36
  latest: true
21
37
  },
22
38
  fields: fileModel.fields
23
39
  })
24
40
  });
25
41
  if (result.isFail()) return Result.fail(new FilePersistenceError(result.error));
26
- const tags = result.value.map((uv)=>({
42
+ const tags = result.value.filter((uv)=>tagFilters.every(({ key, prefix })=>{
43
+ const starts = String(uv.value).toLowerCase().startsWith(prefix);
44
+ return "tags_startsWith" === key ? starts : !starts;
45
+ })).map((uv)=>({
27
46
  tag: uv.value,
28
47
  count: uv.count
29
48
  })).sort((a, b)=>a.tag < b.tag ? -1 : 1).sort((a, b)=>a.count > b.count ? -1 : 1);
@@ -1 +1 @@
1
- {"version":3,"file":"features/file/ListTags/ListTagsRepository.js","sources":["../../../../src/features/file/ListTags/ListTagsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetUniqueFieldValuesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetUniqueFieldValues\";\nimport {\n ListTagsInput,\n ListTagsRepository as RepositoryAbstraction,\n TagItem\n} from \"./abstractions.js\";\nimport { FileModelProvider } from \"~/domain/file/abstractions.js\";\nimport { FilePersistenceError } from \"~/domain/file/errors.js\";\nimport { CmsWhereMapper } from \"@webiny/api-headless-cms\";\n\nclass ListTagsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private getUniqueFieldValues: GetUniqueFieldValuesUseCase.Interface,\n private fileModelProvider: FileModelProvider.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface\n ) {}\n\n async execute(input: ListTagsInput): Promise<Result<TagItem[], RepositoryAbstraction.Error>> {\n const fileModel = await this.fileModelProvider.get();\n\n const result = await this.getUniqueFieldValues.execute(fileModel, {\n fieldId: \"tags\",\n // TODO fix with proper types\n // @ts-expect-error\n where: this.cmsWhereMapper.map({\n input: {\n ...(input.where || {}),\n latest: true\n },\n fields: fileModel.fields\n })\n });\n\n if (result.isFail()) {\n return Result.fail(new FilePersistenceError(result.error));\n }\n\n // Map to TagItem format\n const tags: TagItem[] = result.value\n .map(uv => ({\n tag: uv.value as string,\n count: uv.count\n }))\n // Sort by tag name alphabetically\n .sort((a, b) => (a.tag < b.tag ? -1 : 1))\n // Then sort by count descending (most used first)\n .sort((a, b) => (a.count > b.count ? -1 : 1));\n\n return Result.ok(tags);\n }\n}\n\nexport const ListTagsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListTagsRepositoryImpl,\n dependencies: [GetUniqueFieldValuesUseCase, FileModelProvider, CmsWhereMapper]\n});\n"],"names":["ListTagsRepositoryImpl","getUniqueFieldValues","fileModelProvider","cmsWhereMapper","input","fileModel","result","Result","FilePersistenceError","tags","uv","a","b","ListTagsRepository","RepositoryAbstraction","GetUniqueFieldValuesUseCase","FileModelProvider","CmsWhereMapper"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,oBAA2D,EAC3DC,iBAA8C,EAC9CC,cAAwC,CAClD;aAHUF,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,KAAoB,EAA2D;QACzF,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG;QAElD,MAAMC,SAAS,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACD,WAAW;YAC9D,SAAS;YAGT,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;gBAC3B,OAAO;oBACH,GAAID,MAAM,KAAK,IAAI,CAAC,CAAC;oBACrB,QAAQ;gBACZ;gBACA,QAAQC,UAAU,MAAM;YAC5B;QACJ;QAEA,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,qBAAqBF,OAAO,KAAK;QAI5D,MAAMG,OAAkBH,OAAO,KAAK,CAC/B,GAAG,CAACI,CAAAA,KAAO;gBACR,KAAKA,GAAG,KAAK;gBACb,OAAOA,GAAG,KAAK;YACnB,IAEC,IAAI,CAAC,CAACC,GAAGC,IAAOD,EAAE,GAAG,GAAGC,EAAE,GAAG,GAAG,KAAK,GAErC,IAAI,CAAC,CAACD,GAAGC,IAAOD,EAAE,KAAK,GAAGC,EAAE,KAAK,GAAG,KAAK;QAE9C,OAAOL,OAAO,EAAE,CAACE;IACrB;AACJ;AAEO,MAAMI,wCAAqBC,mBAAAA,oBAA0C,CAAC;IACzE,gBAAgBd;IAChB,cAAc;QAACe;QAA6BC;QAAmBC;KAAe;AAClF"}
1
+ {"version":3,"file":"features/file/ListTags/ListTagsRepository.js","sources":["../../../../src/features/file/ListTags/ListTagsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetUniqueFieldValuesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetUniqueFieldValues\";\nimport {\n ListTagsInput,\n ListTagsRepository as RepositoryAbstraction,\n TagItem\n} from \"./abstractions.js\";\nimport { FileModelProvider } from \"~/domain/file/abstractions.js\";\nimport { FilePersistenceError } from \"~/domain/file/errors.js\";\nimport { CmsWhereMapper } from \"@webiny/api-headless-cms\";\n\nconst TAG_PREFIX_FILTERS = [\"tags_startsWith\", \"tags_not_startsWith\"];\n\nclass ListTagsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private getUniqueFieldValues: GetUniqueFieldValuesUseCase.Interface,\n private fileModelProvider: FileModelProvider.Interface,\n private cmsWhereMapper: CmsWhereMapper.Interface\n ) {}\n\n async execute(input: ListTagsInput): Promise<Result<TagItem[], RepositoryAbstraction.Error>> {\n const fileModel = await this.fileModelProvider.get();\n\n /*\n * Prefix conditions on the tags themselves select tags, not files: \"tags not starting with\n * scope:\" lists every other tag, including those of files that also have a scoped tag.\n * Other conditions (e.g. createdBy) still select the files whose tags are listed. Without\n * them the storage lists the tags of all files, which it can answer from maintained counts.\n */\n const filesWhere: Record<string, any> = {};\n const tagFilters: { key: string; prefix: string }[] = [];\n for (const [key, value] of Object.entries(input.where || {})) {\n if (TAG_PREFIX_FILTERS.includes(key)) {\n if (value !== undefined && value !== null && value !== \"\") {\n tagFilters.push({ key, prefix: String(value).toLowerCase() });\n }\n continue;\n }\n filesWhere[key] = value;\n }\n\n const result = await this.getUniqueFieldValues.execute(fileModel, {\n fieldId: \"tags\",\n // TODO fix with proper types\n // @ts-expect-error\n where: this.cmsWhereMapper.map({\n input: {\n ...filesWhere,\n latest: true\n },\n fields: fileModel.fields\n })\n });\n\n if (result.isFail()) {\n return Result.fail(new FilePersistenceError(result.error));\n }\n\n // Map to TagItem format\n const tags: TagItem[] = result.value\n .filter(uv =>\n tagFilters.every(({ key, prefix }) => {\n // Case-insensitive, as the startsWith filter.\n const starts = String(uv.value).toLowerCase().startsWith(prefix);\n return key === \"tags_startsWith\" ? starts : !starts;\n })\n )\n .map(uv => ({\n tag: uv.value as string,\n count: uv.count\n }))\n // Sort by tag name alphabetically\n .sort((a, b) => (a.tag < b.tag ? -1 : 1))\n // Then sort by count descending (most used first)\n .sort((a, b) => (a.count > b.count ? -1 : 1));\n\n return Result.ok(tags);\n }\n}\n\nexport const ListTagsRepository = RepositoryAbstraction.createImplementation({\n implementation: ListTagsRepositoryImpl,\n dependencies: [GetUniqueFieldValuesUseCase, FileModelProvider, CmsWhereMapper]\n});\n"],"names":["TAG_PREFIX_FILTERS","ListTagsRepositoryImpl","getUniqueFieldValues","fileModelProvider","cmsWhereMapper","input","fileModel","filesWhere","tagFilters","key","value","Object","String","result","Result","FilePersistenceError","tags","uv","prefix","starts","a","b","ListTagsRepository","RepositoryAbstraction","GetUniqueFieldValuesUseCase","FileModelProvider","CmsWhereMapper"],"mappings":";;;;;;AAWA,MAAMA,qBAAqB;IAAC;IAAmB;CAAsB;AAErE,MAAMC;IACF,YACYC,oBAA2D,EAC3DC,iBAA8C,EAC9CC,cAAwC,CAClD;aAHUF,oBAAoB,GAApBA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,KAAoB,EAA2D;QACzF,MAAMC,YAAY,MAAM,IAAI,CAAC,iBAAiB,CAAC,GAAG;QAQlD,MAAMC,aAAkC,CAAC;QACzC,MAAMC,aAAgD,EAAE;QACxD,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAO,OAAO,CAACN,MAAM,KAAK,IAAI,CAAC,GAAI;YAC1D,IAAIL,mBAAmB,QAAQ,CAACS,MAAM;gBAClC,IAAIC,QAAAA,SAAyCA,AAAU,OAAVA,OACzCF,WAAW,IAAI,CAAC;oBAAEC;oBAAK,QAAQG,OAAOF,OAAO,WAAW;gBAAG;gBAE/D;YACJ;YACAH,UAAU,CAACE,IAAI,GAAGC;QACtB;QAEA,MAAMG,SAAS,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACP,WAAW;YAC9D,SAAS;YAGT,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;gBAC3B,OAAO;oBACH,GAAGC,UAAU;oBACb,QAAQ;gBACZ;gBACA,QAAQD,UAAU,MAAM;YAC5B;QACJ;QAEA,IAAIO,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,qBAAqBF,OAAO,KAAK;QAI5D,MAAMG,OAAkBH,OAAO,KAAK,CAC/B,MAAM,CAACI,CAAAA,KACJT,WAAW,KAAK,CAAC,CAAC,EAAEC,GAAG,EAAES,MAAM,EAAE;gBAE7B,MAAMC,SAASP,OAAOK,GAAG,KAAK,EAAE,WAAW,GAAG,UAAU,CAACC;gBACzD,OAAOT,AAAQ,sBAARA,MAA4BU,SAAS,CAACA;YACjD,IAEH,GAAG,CAACF,CAAAA,KAAO;gBACR,KAAKA,GAAG,KAAK;gBACb,OAAOA,GAAG,KAAK;YACnB,IAEC,IAAI,CAAC,CAACG,GAAGC,IAAOD,EAAE,GAAG,GAAGC,EAAE,GAAG,GAAG,KAAK,GAErC,IAAI,CAAC,CAACD,GAAGC,IAAOD,EAAE,KAAK,GAAGC,EAAE,KAAK,GAAG,KAAK;QAE9C,OAAOP,OAAO,EAAE,CAACE;IACrB;AACJ;AAEO,MAAMM,wCAAqBC,mBAAAA,oBAA0C,CAAC;IACzE,gBAAgBtB;IAChB,cAAc;QAACuB;QAA6BC;QAAmBC;KAAe;AAClF"}
@@ -0,0 +1,11 @@
1
+ import { PublicUrls } from "@webiny/api-core/features/publicUrls/index.js";
2
+ import { DefaultSrcPrefix } from "./abstractions.js";
3
+ declare class PublicUrlsDefaultSrcPrefixImpl implements DefaultSrcPrefix.Interface {
4
+ private publicUrls;
5
+ constructor(publicUrls: PublicUrls.Interface);
6
+ get(): Promise<string>;
7
+ }
8
+ export declare const PublicUrlsDefaultSrcPrefix: typeof PublicUrlsDefaultSrcPrefixImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IDefaultSrcPrefix>;
10
+ };
11
+ export {};
@@ -0,0 +1,20 @@
1
+ import { PublicUrls } from "@webiny/api-core/features/publicUrls/index.js";
2
+ import { DefaultSrcPrefix } from "./abstractions.js";
3
+ class PublicUrlsDefaultSrcPrefixImpl {
4
+ constructor(publicUrls){
5
+ this.publicUrls = publicUrls;
6
+ }
7
+ async get() {
8
+ const apiUrl = await this.publicUrls.getApiUrl();
9
+ return apiUrl.join("/files/");
10
+ }
11
+ }
12
+ const PublicUrlsDefaultSrcPrefix = DefaultSrcPrefix.createImplementation({
13
+ implementation: PublicUrlsDefaultSrcPrefixImpl,
14
+ dependencies: [
15
+ PublicUrls
16
+ ]
17
+ });
18
+ export { PublicUrlsDefaultSrcPrefix };
19
+
20
+ //# sourceMappingURL=PublicUrlsDefaultSrcPrefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.js","sources":["../../../../src/features/settings/DefaultSrcPrefix/PublicUrlsDefaultSrcPrefix.ts"],"sourcesContent":["import { PublicUrls } from \"@webiny/api-core/features/publicUrls/index.js\";\nimport { DefaultSrcPrefix } from \"./abstractions.js\";\n\nclass PublicUrlsDefaultSrcPrefixImpl implements DefaultSrcPrefix.Interface {\n constructor(private publicUrls: PublicUrls.Interface) {}\n\n async get(): Promise<string> {\n const apiUrl = await this.publicUrls.getApiUrl();\n return apiUrl.join(\"/files/\");\n }\n}\n\nexport const PublicUrlsDefaultSrcPrefix = DefaultSrcPrefix.createImplementation({\n implementation: PublicUrlsDefaultSrcPrefixImpl,\n dependencies: [PublicUrls]\n});\n"],"names":["PublicUrlsDefaultSrcPrefixImpl","publicUrls","apiUrl","PublicUrlsDefaultSrcPrefix","DefaultSrcPrefix","PublicUrls"],"mappings":";;AAGA,MAAMA;IACF,YAAoBC,UAAgC,CAAE;aAAlCA,UAAU,GAAVA;IAAmC;IAEvD,MAAM,MAAuB;QACzB,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS;QAC9C,OAAOA,OAAO,IAAI,CAAC;IACvB;AACJ;AAEO,MAAMC,6BAA6BC,iBAAiB,oBAAoB,CAAC;IAC5E,gBAAgBJ;IAChB,cAAc;QAACK;KAAW;AAC9B"}
@@ -0,0 +1,20 @@
1
+ export interface IDefaultSrcPrefix {
2
+ /**
3
+ * The file delivery URL used when no custom one is set: the API's public URL plus `/files/`.
4
+ * Empty when the API URL is unknown.
5
+ */
6
+ get(): Promise<string>;
7
+ }
8
+ /**
9
+ * The default `srcPrefix`. Computed on every read rather than stored, so file URLs follow the API
10
+ * when its public URL changes (a custom domain added, a container moved).
11
+ *
12
+ * Replace this to change the default itself: it is what settings fall back to, what the Admin
13
+ * settings form shows as the placeholder, and what a save compares against. Replace
14
+ * `FileUrlPrefixProvider` instead to change the prefix of generated file URLs regardless of the
15
+ * settings; the settings form will not know about it.
16
+ */
17
+ export declare const DefaultSrcPrefix: import("@webiny/di").Abstraction<IDefaultSrcPrefix>;
18
+ export declare namespace DefaultSrcPrefix {
19
+ type Interface = IDefaultSrcPrefix;
20
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const DefaultSrcPrefix = createAbstraction("FileManager/DefaultSrcPrefix");
3
+ export { DefaultSrcPrefix };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/settings/DefaultSrcPrefix/abstractions.js","sources":["../../../../src/features/settings/DefaultSrcPrefix/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IDefaultSrcPrefix {\n /**\n * The file delivery URL used when no custom one is set: the API's public URL plus `/files/`.\n * Empty when the API URL is unknown.\n */\n get(): Promise<string>;\n}\n\n/**\n * The default `srcPrefix`. Computed on every read rather than stored, so file URLs follow the API\n * when its public URL changes (a custom domain added, a container moved).\n *\n * Replace this to change the default itself: it is what settings fall back to, what the Admin\n * settings form shows as the placeholder, and what a save compares against. Replace\n * `FileUrlPrefixProvider` instead to change the prefix of generated file URLs regardless of the\n * settings; the settings form will not know about it.\n */\nexport const DefaultSrcPrefix = createAbstraction<IDefaultSrcPrefix>(\n \"FileManager/DefaultSrcPrefix\"\n);\n\nexport namespace DefaultSrcPrefix {\n export type Interface = IDefaultSrcPrefix;\n}\n"],"names":["DefaultSrcPrefix","createAbstraction"],"mappings":";AAmBO,MAAMA,mBAAmBC,kBAC5B"}
@@ -0,0 +1,4 @@
1
+ export declare const DefaultSrcPrefixFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { PublicUrlsDefaultSrcPrefix } from "./PublicUrlsDefaultSrcPrefix.js";
3
+ const DefaultSrcPrefixFeature = createFeature({
4
+ name: "FileManager/DefaultSrcPrefix",
5
+ register (container) {
6
+ container.register(PublicUrlsDefaultSrcPrefix);
7
+ }
8
+ });
9
+ export { DefaultSrcPrefixFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/settings/DefaultSrcPrefix/feature.js","sources":["../../../../src/features/settings/DefaultSrcPrefix/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { PublicUrlsDefaultSrcPrefix } from \"./PublicUrlsDefaultSrcPrefix.js\";\n\nexport const DefaultSrcPrefixFeature = createFeature({\n name: \"FileManager/DefaultSrcPrefix\",\n register(container) {\n container.register(PublicUrlsDefaultSrcPrefix);\n }\n});\n"],"names":["DefaultSrcPrefixFeature","createFeature","container","PublicUrlsDefaultSrcPrefix"],"mappings":";;AAGO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1 @@
1
+ export { DefaultSrcPrefix } from "./abstractions.js";
@@ -0,0 +1 @@
1
+ export { DefaultSrcPrefix } from "./abstractions.js";
@@ -2,9 +2,15 @@ import { Result } from "@webiny/feature/api";
2
2
  import { GetSettingsUseCase as UseCaseAbstraction } from "./abstractions.js";
3
3
  import type { FileManagerSettings } from "../../../domain/settings/types.js";
4
4
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
5
+ import { DefaultSrcPrefix } from "../../../features/settings/DefaultSrcPrefix/index.js";
6
+ /**
7
+ * Returns the settings in effect. The stored `srcPrefix` is only a custom one; when none is stored,
8
+ * the prefix is the current default (`DefaultSrcPrefix`), so file URLs follow the API's public URL.
9
+ */
5
10
  declare class GetSettingsUseCaseImpl implements UseCaseAbstraction.Interface {
6
11
  private keyValueStore;
7
- constructor(keyValueStore: KeyValueStore.Interface);
12
+ private defaultSrcPrefix;
13
+ constructor(keyValueStore: KeyValueStore.Interface, defaultSrcPrefix: DefaultSrcPrefix.Interface);
8
14
  execute(): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>>;
9
15
  }
10
16
  export declare const GetSettingsUseCase: typeof GetSettingsUseCaseImpl & {
@@ -2,25 +2,32 @@ import { Result } from "@webiny/feature/api";
2
2
  import { GetSettingsUseCase } from "./abstractions.js";
3
3
  import { FILE_MANAGER_GENERAL_SETTINGS } from "../../../domain/settings/constants.js";
4
4
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
5
+ import { DefaultSrcPrefix } from "../DefaultSrcPrefix/index.js";
6
+ const DEFAULT_SETTINGS = {
7
+ uploadMinFileSize: 0,
8
+ uploadMaxFileSize: 10737418240,
9
+ srcPrefix: ""
10
+ };
5
11
  class GetSettingsUseCaseImpl {
6
- constructor(keyValueStore){
12
+ constructor(keyValueStore, defaultSrcPrefix){
7
13
  this.keyValueStore = keyValueStore;
14
+ this.defaultSrcPrefix = defaultSrcPrefix;
8
15
  }
9
16
  async execute() {
10
17
  const result = await this.keyValueStore.get(FILE_MANAGER_GENERAL_SETTINGS);
11
- if (result.isFail()) return Result.ok({
12
- uploadMinFileSize: 0,
13
- uploadMaxFileSize: 10737418240,
14
- srcPrefix: ""
18
+ const stored = result.isFail() ? DEFAULT_SETTINGS : result.value;
19
+ const srcPrefix = stored.srcPrefix || await this.defaultSrcPrefix.get();
20
+ return Result.ok({
21
+ ...stored,
22
+ srcPrefix
15
23
  });
16
- const settings = result.value;
17
- return Result.ok(settings);
18
24
  }
19
25
  }
20
26
  const GetSettingsUseCase_GetSettingsUseCase = GetSettingsUseCase.createImplementation({
21
27
  implementation: GetSettingsUseCaseImpl,
22
28
  dependencies: [
23
- KeyValueStore
29
+ KeyValueStore,
30
+ DefaultSrcPrefix
24
31
  ]
25
32
  });
26
33
  export { GetSettingsUseCase_GetSettingsUseCase as GetSettingsUseCase };
@@ -1 +1 @@
1
- {"version":3,"file":"features/settings/GetSettings/GetSettingsUseCase.js","sources":["../../../../src/features/settings/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetSettingsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nclass GetSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(private keyValueStore: KeyValueStore.Interface) {}\n\n async execute(): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>> {\n const result = await this.keyValueStore.get<FileManagerSettings>(\n FILE_MANAGER_GENERAL_SETTINGS\n );\n\n if (result.isFail()) {\n // Return default values\n return Result.ok({\n uploadMinFileSize: 0,\n uploadMaxFileSize: 10737418240,\n srcPrefix: \"\"\n });\n }\n\n const settings = result.value;\n\n return Result.ok(settings);\n }\n}\n\nexport const GetSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetSettingsUseCaseImpl,\n dependencies: [KeyValueStore]\n});\n"],"names":["GetSettingsUseCaseImpl","keyValueStore","result","FILE_MANAGER_GENERAL_SETTINGS","Result","settings","GetSettingsUseCase","UseCaseAbstraction","KeyValueStore"],"mappings":";;;;AAMA,MAAMA;IACF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;IAAyC;IAE7D,MAAM,UAA0E;QAC5E,MAAMC,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvCC;QAGJ,IAAID,OAAO,MAAM,IAEb,OAAOE,OAAO,EAAE,CAAC;YACb,mBAAmB;YACnB,mBAAmB;YACnB,WAAW;QACf;QAGJ,MAAMC,WAAWH,OAAO,KAAK;QAE7B,OAAOE,OAAO,EAAE,CAACC;IACrB;AACJ;AAEO,MAAMC,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBP;IAChB,cAAc;QAACQ;KAAc;AACjC"}
1
+ {"version":3,"file":"features/settings/GetSettings/GetSettingsUseCase.js","sources":["../../../../src/features/settings/GetSettings/GetSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { GetSettingsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { FileManagerSettings } from \"~/domain/settings/types.js\";\nimport { FILE_MANAGER_GENERAL_SETTINGS } from \"~/domain/settings/constants.js\";\nimport { KeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\nimport { DefaultSrcPrefix } from \"~/features/settings/DefaultSrcPrefix/index.js\";\n\nconst DEFAULT_SETTINGS: FileManagerSettings = {\n uploadMinFileSize: 0,\n uploadMaxFileSize: 10737418240,\n srcPrefix: \"\"\n};\n\n/**\n * Returns the settings in effect. The stored `srcPrefix` is only a custom one; when none is stored,\n * the prefix is the current default (`DefaultSrcPrefix`), so file URLs follow the API's public URL.\n */\nclass GetSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private keyValueStore: KeyValueStore.Interface,\n private defaultSrcPrefix: DefaultSrcPrefix.Interface\n ) {}\n\n async execute(): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>> {\n const result = await this.keyValueStore.get<FileManagerSettings>(\n FILE_MANAGER_GENERAL_SETTINGS\n );\n\n const stored = result.isFail() ? DEFAULT_SETTINGS : result.value;\n const srcPrefix = stored.srcPrefix || (await this.defaultSrcPrefix.get());\n\n return Result.ok({ ...stored, srcPrefix });\n }\n}\n\nexport const GetSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetSettingsUseCaseImpl,\n dependencies: [KeyValueStore, DefaultSrcPrefix]\n});\n"],"names":["DEFAULT_SETTINGS","GetSettingsUseCaseImpl","keyValueStore","defaultSrcPrefix","result","FILE_MANAGER_GENERAL_SETTINGS","stored","srcPrefix","Result","GetSettingsUseCase","UseCaseAbstraction","KeyValueStore","DefaultSrcPrefix"],"mappings":";;;;;AAOA,MAAMA,mBAAwC;IAC1C,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;AACf;AAMA,MAAMC;IACF,YACYC,aAAsC,EACtCC,gBAA4C,CACtD;aAFUD,aAAa,GAAbA;aACAC,gBAAgB,GAAhBA;IACT;IAEH,MAAM,UAA0E;QAC5E,MAAMC,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CACvCC;QAGJ,MAAMC,SAASF,OAAO,MAAM,KAAKJ,mBAAmBI,OAAO,KAAK;QAChE,MAAMG,YAAYD,OAAO,SAAS,IAAK,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG;QAEtE,OAAOE,OAAO,EAAE,CAAC;YAAE,GAAGF,MAAM;YAAEC;QAAU;IAC5C;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAAuC,CAAC;IACtE,gBAAgBT;IAChB,cAAc;QAACU;QAAeC;KAAiB;AACnD"}
@@ -1,15 +1,11 @@
1
1
  import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/index.js";
2
- import { UpdateSettingsUseCase } from "../../../features/settings/UpdateSettings/abstractions.js";
3
2
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
4
- import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
5
3
  declare class SettingsInstallerImpl implements AppInstaller.Interface {
6
- private updateSettings;
7
4
  private keyValueStore;
8
- private buildParams;
9
5
  readonly alwaysRun = true;
10
6
  readonly appName = "FileManager";
11
7
  readonly dependsOn: never[];
12
- constructor(updateSettings: UpdateSettingsUseCase.Interface, keyValueStore: KeyValueStore.Interface, buildParams: BuildParams.Interface);
8
+ constructor(keyValueStore: KeyValueStore.Interface);
13
9
  install(): Promise<void>;
14
10
  uninstall(): Promise<void>;
15
11
  }
@@ -1,26 +1,15 @@
1
- import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
2
1
  import { createImplementation } from "@webiny/feature/api";
3
2
  import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/index.js";
4
3
  import { FILE_MANAGER_GENERAL_SETTINGS } from "../../../domain/settings/constants.js";
5
- import { UpdateSettingsUseCase } from "../UpdateSettings/abstractions.js";
6
4
  import { KeyValueStore } from "@webiny/api-core/features/keyValueStore/index.js";
7
- import { BuildParams } from "@webiny/api-core/features/buildParams/index.js";
8
5
  class SettingsInstallerImpl {
9
- constructor(updateSettings, keyValueStore, buildParams){
10
- this.updateSettings = updateSettings;
6
+ constructor(keyValueStore){
11
7
  this.keyValueStore = keyValueStore;
12
- this.buildParams = buildParams;
13
8
  this.alwaysRun = true;
14
9
  this.appName = "FileManager";
15
10
  this.dependsOn = [];
16
11
  }
17
- async install() {
18
- const manifest = await ServiceDiscovery.load();
19
- const domain = manifest?.api?.cloudfront?.domain ?? this.buildParams.get("WEBINY_API_URL") ?? "";
20
- await this.updateSettings.execute({
21
- srcPrefix: `${domain}/files`
22
- });
23
- }
12
+ async install() {}
24
13
  async uninstall() {
25
14
  await this.keyValueStore.delete(FILE_MANAGER_GENERAL_SETTINGS);
26
15
  }
@@ -29,9 +18,7 @@ const SettingsInstaller = createImplementation({
29
18
  abstraction: AppInstaller,
30
19
  implementation: SettingsInstallerImpl,
31
20
  dependencies: [
32
- UpdateSettingsUseCase,
33
- KeyValueStore,
34
- BuildParams
21
+ KeyValueStore
35
22
  ]
36
23
  });
37
24
  export { SettingsInstaller };
@@ -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\";\nimport { BuildParams } from \"@webiny/api-core/features/buildParams/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 private buildParams: BuildParams.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 //\n // The AWS hosting type serves files from a CloudFront domain (in the manifest). The self-hosted\n // (server) hosting type has no CloudFront — files are served by the api's own `/files/*` route — so\n // fall back to the configured API origin, read from the WEBINY_API_URL build param (baked by\n // Infra.ApiUrl), not a process.env read.\n const domain =\n manifest?.api?.cloudfront?.domain ??\n this.buildParams.get<string>(\"WEBINY_API_URL\") ??\n \"\";\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, BuildParams]\n});\n"],"names":["SettingsInstallerImpl","updateSettings","keyValueStore","buildParams","manifest","ServiceDiscovery","domain","FILE_MANAGER_GENERAL_SETTINGS","SettingsInstaller","createImplementation","AppInstaller","UpdateSettingsUseCase","KeyValueStore","BuildParams"],"mappings":";;;;;;;AAQA,MAAMA;IAKF,YACYC,cAA+C,EAC/CC,aAAsC,EACtCC,WAAkC,CAC5C;aAHUF,cAAc,GAAdA;aACAC,aAAa,GAAbA;aACAC,WAAW,GAAXA;aAPH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;IAMpB;IAEH,MAAM,UAAyB;QAE3B,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAS5C,MAAMC,SACFF,UAAU,KAAK,YAAY,UAC3B,IAAI,CAAC,WAAW,CAAC,GAAG,CAAS,qBAC7B;QAEJ,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,gBAAgBV;IAChB,cAAc;QAACW;QAAuBC;QAAeC;KAAY;AACrE"}
1
+ {"version":3,"file":"features/settings/SettingsInstaller/SettingsInstaller.js","sources":["../../../../src/features/settings/SettingsInstaller/SettingsInstaller.ts"],"sourcesContent":["import { 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 { 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(private keyValueStore: KeyValueStore.Interface) {}\n\n async install(): Promise<void> {\n /*\n * Nothing to write. Settings that were never saved read as the defaults, and the file\n * delivery URL defaults to the API's current public URL on every read (DefaultSrcPrefix),\n * so writing it here would only freeze today's URL into the tenant's settings.\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: [KeyValueStore]\n});\n"],"names":["SettingsInstallerImpl","keyValueStore","FILE_MANAGER_GENERAL_SETTINGS","SettingsInstaller","createImplementation","AppInstaller","KeyValueStore"],"mappings":";;;;AAKA,MAAMA;IAKF,YAAoBC,aAAsC,CAAE;aAAxCA,aAAa,GAAbA;aAJX,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG,EAAE;IAEsC;IAE7D,MAAM,UAAyB,CAM/B;IAEA,MAAM,YAA2B;QAC7B,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAACC;IACpC;AACJ;AAEO,MAAMC,oBAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBL;IAChB,cAAc;QAACM;KAAc;AACjC"}
@@ -5,11 +5,19 @@ 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 { DefaultSrcPrefix } from "../../../features/settings/DefaultSrcPrefix/index.js";
9
+ /**
10
+ * Stores only a custom `srcPrefix`. An empty value, or the current default (which is what the
11
+ * Admin settings form shows and sends back unchanged), is stored as "no custom prefix", so
12
+ * `GetSettings` keeps following the API's public URL. An update that omits `srcPrefix` keeps the
13
+ * stored one.
14
+ */
8
15
  declare class UpdateSettingsUseCaseImpl implements UseCaseAbstraction.Interface {
9
16
  private keyValueStore;
10
17
  private getSettings;
11
18
  private eventPublisher;
12
- constructor(keyValueStore: KeyValueStore.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface);
19
+ private defaultSrcPrefix;
20
+ constructor(keyValueStore: KeyValueStore.Interface, getSettings: GetSettingsUseCase.Interface, eventPublisher: EventPublisher.Interface, defaultSrcPrefix: DefaultSrcPrefix.Interface);
13
21
  execute(input: UpdateSettingsInput): Promise<Result<FileManagerSettings, UseCaseAbstraction.Error>>;
14
22
  }
15
23
  export declare const UpdateSettingsUseCase: typeof UpdateSettingsUseCaseImpl & {