@webiny/api-file-manager-s3 0.0.0-unstable.7be00a75a9 → 0.0.0-unstable.7c2def32a7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FileManagerS3Feature.d.ts +9 -0
- package/FileManagerS3Feature.js +27 -0
- package/FileManagerS3Feature.js.map +1 -0
- package/assetDelivery/abstractions.d.ts +2 -0
- package/assetDelivery/abstractions.js.map +1 -1
- package/assetDelivery/assetDeliveryConfig.d.ts +1 -1
- package/assetDelivery/assetDeliveryConfig.js +0 -2
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/feature.js +5 -6
- package/assetDelivery/feature.js.map +1 -1
- package/assetDelivery/s3/LazySharpTransform.d.ts +34 -0
- package/assetDelivery/s3/LazySharpTransform.js +34 -0
- package/assetDelivery/s3/LazySharpTransform.js.map +1 -0
- package/assetDelivery/s3/SharpTransform.d.ts +15 -7
- package/assetDelivery/s3/SharpTransform.js +112 -101
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- package/assetDelivery/s3/transformation/AssetKeyGenerator.js +2 -2
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.d.ts +21 -1
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js +43 -27
- package/assetDelivery/threatDetection/createThreatDetectionEventHandler.js.map +1 -1
- package/assetDelivery/threatDetection/processThreatScanResult.js +9 -7
- package/assetDelivery/threatDetection/processThreatScanResult.js.map +1 -1
- package/assetDelivery/types.d.ts +3 -0
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.d.ts +3 -1
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js +7 -2
- package/enterprise/ApplyThreatScanning/CreateFileWithThreatScanDecorator.js.map +1 -1
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +9 -4
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js +9 -2
- package/features/DeleteFileFromBucket/DeleteS3FolderTask.js.map +1 -1
- package/features/ExtractMetadata/ExtractMetadataTask.d.ts +11 -6
- package/features/ExtractMetadata/ExtractMetadataTask.js +23 -14
- package/features/ExtractMetadata/ExtractMetadataTask.js.map +1 -1
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js +1 -1
- package/features/FlushCache/FlushCacheOnFileDeleteHandler.js.map +1 -1
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js +1 -1
- package/features/FlushCache/FlushCacheOnFileUpdateHandler.js.map +1 -1
- package/features/FlushCache/InvalidateCacheTask.d.ts +11 -6
- package/features/FlushCache/InvalidateCacheTask.js +17 -8
- package/features/FlushCache/InvalidateCacheTask.js.map +1 -1
- package/features/WriteFileMetadata/MetadataWriter.js +3 -1
- package/features/WriteFileMetadata/MetadataWriter.js.map +1 -1
- package/graphql/S3GraphQLSchema.d.ts +10 -0
- package/graphql/S3GraphQLSchema.js +235 -0
- package/graphql/S3GraphQLSchema.js.map +1 -0
- package/index.d.ts +2 -2
- package/index.js +1 -29
- package/package.json +22 -20
- package/types.d.ts +1 -1
- package/types.js +1 -1
- package/utils/FileUploadModifier.d.ts +8 -2
- package/utils/FileUploadModifier.js +5 -3
- package/utils/FileUploadModifier.js.map +1 -1
- package/utils/createFileNormalizerFromContext.js +2 -2
- package/utils/createFileNormalizerFromContext.js.map +1 -1
- package/utils/uploadFileToS3.d.ts +1 -1
- package/graphql/schema.d.ts +0 -1
- package/graphql/schema.js +0 -201
- package/graphql/schema.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ServiceDiscovery } from "@webiny/api";
|
|
1
|
+
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
2
2
|
import { CloudFront } from "@webiny/aws-sdk/client-cloudfront/index.js";
|
|
3
|
-
import { TaskDefinition } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
3
|
+
import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
4
|
import { executeWithRetry } from "@webiny/utils";
|
|
5
5
|
class ReturnContinue extends Error {
|
|
6
6
|
}
|
|
7
|
-
class
|
|
7
|
+
class InvalidateCloudfrontCacheTaskHandlerImpl {
|
|
8
8
|
async run({ input, controller }) {
|
|
9
9
|
if (controller.runtime.isAborted()) return controller.response.aborted();
|
|
10
10
|
const manifest = await ServiceDiscovery.load();
|
|
@@ -51,7 +51,19 @@ class InvalidateCloudfrontCacheTask {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
constructor(){
|
|
54
|
-
this.
|
|
54
|
+
this.continueIfCode = [
|
|
55
|
+
"TooManyInvalidationsInProgress",
|
|
56
|
+
"Throttling"
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const InvalidateCloudfrontCacheTaskHandler = TaskHandler.createImplementation({
|
|
61
|
+
implementation: InvalidateCloudfrontCacheTaskHandlerImpl,
|
|
62
|
+
dependencies: []
|
|
63
|
+
});
|
|
64
|
+
class InvalidateCloudfrontCacheTask {
|
|
65
|
+
constructor(){
|
|
66
|
+
this.id = "invalidateAssetCache";
|
|
55
67
|
this.title = "Invalidate CloudFront Cache";
|
|
56
68
|
this.description = "A task to invalidate Cloudfront cache by given paths.";
|
|
57
69
|
this.maxIterations = 100;
|
|
@@ -60,10 +72,7 @@ class InvalidateCloudfrontCacheTask {
|
|
|
60
72
|
"onSuccess",
|
|
61
73
|
"onAbort"
|
|
62
74
|
];
|
|
63
|
-
this.
|
|
64
|
-
"TooManyInvalidationsInProgress",
|
|
65
|
-
"Throttling"
|
|
66
|
-
];
|
|
75
|
+
this.handler = InvalidateCloudfrontCacheTaskHandler;
|
|
67
76
|
}
|
|
68
77
|
}
|
|
69
78
|
const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/FlushCache/InvalidateCacheTask.js","sources":["../../../src/features/FlushCache/InvalidateCacheTask.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api\";\nimport { CloudFront } from \"@webiny/aws-sdk/client-cloudfront/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/FlushCache/InvalidateCacheTask.js","sources":["../../../src/features/FlushCache/InvalidateCacheTask.ts"],"sourcesContent":["import { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { CloudFront } from \"@webiny/aws-sdk/client-cloudfront/index.js\";\nimport {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nclass ReturnContinue extends Error {}\n\nexport interface InvalidateCacheInput {\n /**\n * Caller of the task (e.g., `fm-before-update`, `fm-after-delete`).\n */\n caller: string;\n /**\n * Cache paths to invalidate.\n */\n paths: string[];\n}\n\nclass InvalidateCloudfrontCacheTaskHandlerImpl implements TaskHandler.Interface<InvalidateCacheInput> {\n private continueIfCode = [\"TooManyInvalidationsInProgress\", \"Throttling\"];\n\n public async run({ input, controller }: TaskHandler.RunParams<InvalidateCacheInput>) {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n const manifest = await ServiceDiscovery.load();\n\n if (!manifest) {\n return controller.response.error({\n message: `Unable to invalidate cache due to a missing service manifest.`,\n code: \"MISSING_SERVICE_MANIFEST\",\n data: {\n manifest: \"api\"\n }\n });\n }\n\n const { distributionId } = manifest.api.cloudfront;\n\n const invalidateCache = () => {\n return this.invalidateCache(input.caller, distributionId as string, input.paths);\n };\n\n try {\n await executeWithRetry(invalidateCache, {\n minTimeout: 2000,\n // instead of forever: true\n retries: 10000,\n onFailedAttempt: ({ error }) => {\n if (this.continueIfCode.includes(error.name)) {\n throw new ReturnContinue();\n }\n\n if (error.message.includes(\"not authorized to perform\")) {\n throw error;\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n throw new ReturnContinue();\n }\n }\n });\n } catch (error) {\n if (error instanceof ReturnContinue) {\n return controller.response.continue(input);\n }\n\n return controller.response.error({\n message: error.message,\n code: \"EXECUTE_WITH_RETRY_FAILED\",\n data: input.paths\n });\n }\n\n return controller.response.done();\n }\n\n private async invalidateCache(\n caller: string,\n distributionId: string,\n paths: string[]\n ): Promise<void> {\n const cloudfront = new CloudFront();\n await cloudfront.createInvalidation({\n DistributionId: distributionId,\n InvalidationBatch: {\n CallerReference: `${new Date().getTime()}-${caller}`,\n Paths: {\n Quantity: paths.length,\n Items: paths\n }\n }\n });\n }\n}\n\nconst InvalidateCloudfrontCacheTaskHandler = TaskHandler.createImplementation({\n implementation: InvalidateCloudfrontCacheTaskHandlerImpl,\n dependencies: []\n});\n\nclass InvalidateCloudfrontCacheTask implements TaskDefinition.Interface {\n id = \"invalidateAssetCache\";\n title = \"Invalidate CloudFront Cache\";\n description = \"A task to invalidate Cloudfront cache by given paths.\";\n maxIterations = 100;\n isPrivate = true;\n selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = InvalidateCloudfrontCacheTaskHandler;\n}\n\nexport const InvalidateCloudfrontCacheTaskDefinition = TaskDefinition.createImplementation({\n implementation: InvalidateCloudfrontCacheTask,\n dependencies: []\n});\n"],"names":["ReturnContinue","Error","InvalidateCloudfrontCacheTaskHandlerImpl","input","controller","manifest","ServiceDiscovery","distributionId","invalidateCache","executeWithRetry","error","caller","paths","cloudfront","CloudFront","Date","InvalidateCloudfrontCacheTaskHandler","TaskHandler","InvalidateCloudfrontCacheTask","InvalidateCloudfrontCacheTaskDefinition","TaskDefinition"],"mappings":";;;;AAQA,MAAMA,uBAAuBC;AAAO;AAapC,MAAMC;IAGF,MAAa,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA+C,EAAE;QACjF,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;QAGtC,MAAMC,WAAW,MAAMC,iBAAiB,IAAI;QAE5C,IAAI,CAACD,UACD,OAAOD,WAAW,QAAQ,CA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c,EAAE;AACpB;AAEA,MAAMgB;;aACF,EAAE,GAAG;aACL,KAAK,GAAG;aACR,WAAW,GAAG;aACd,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExD,OAAO,GAAGF;;AACd;AAEO,MAAMG,0CAA0CC,eAAe,oBAAoB,CAAC;IACvF,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -6,7 +6,9 @@ class MetadataWriter {
|
|
|
6
6
|
async write(files) {
|
|
7
7
|
const writers = files.map(async (file)=>{
|
|
8
8
|
const metadata = this.getMetadata(file);
|
|
9
|
-
|
|
9
|
+
const key = `FileManager/File/${file.id}/Metadata`;
|
|
10
|
+
const result = await this.keyValueStore.set(key, metadata);
|
|
11
|
+
if (result.isFail()) console.error(`[FileManagerS3] Failed to write delivery metadata "${key}":`, result.error);
|
|
10
12
|
});
|
|
11
13
|
await Promise.all(writers);
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/WriteFileMetadata/MetadataWriter.js","sources":["../../../src/features/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport type { File } from \"@webiny/api-file-manager/domain/file/types.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nexport class MetadataWriter {\n constructor(\n private tenantContext: TenantContext.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface\n ) {}\n\n async write(files: File[]) {\n /**\n * We need to write each file with retry.\n */\n const writers = files.map(async file => {\n const metadata = this.getMetadata(file);\n
|
|
1
|
+
{"version":3,"file":"features/WriteFileMetadata/MetadataWriter.js","sources":["../../../src/features/WriteFileMetadata/MetadataWriter.ts"],"sourcesContent":["import { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport type { File } from \"@webiny/api-file-manager/domain/file/types.js\";\nimport { GlobalKeyValueStore } from \"@webiny/api-core/features/keyValueStore/index.js\";\n\nexport class MetadataWriter {\n constructor(\n private tenantContext: TenantContext.Interface,\n private keyValueStore: GlobalKeyValueStore.Interface\n ) {}\n\n async write(files: File[]) {\n /**\n * We need to write each file with retry.\n */\n const writers = files.map(async file => {\n const metadata = this.getMetadata(file);\n const key = `FileManager/File/${file.id}/Metadata`;\n // Check the result: the KV store returns a failed Result (it does not throw), so an\n // ignored failure here would silently break asset delivery (missing metadata → 404).\n const result = await this.keyValueStore.set(key, metadata);\n if (result.isFail()) {\n console.error(\n `[FileManagerS3] Failed to write delivery metadata \"${key}\":`,\n result.error\n );\n }\n });\n\n await Promise.all(writers);\n }\n\n private getMetadata(file: 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"],"names":["MetadataWriter","tenantContext","keyValueStore","files","writers","file","metadata","key","result","console","Promise","tenant"],"mappings":"AAIO,MAAMA;IACT,YACYC,aAAsC,EACtCC,aAA4C,CACtD;aAFUD,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,MAAMC,KAAa,EAAE;QAIvB,MAAMC,UAAUD,MAAM,GAAG,CAAC,OAAME;YAC5B,MAAMC,WAAW,IAAI,CAAC,WAAW,CAACD;YAClC,MAAME,MAAM,CAAC,iBAAiB,EAAEF,KAAK,EAAE,CAAC,SAAS,CAAC;YAGlD,MAAMG,SAAS,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,CAACD,KAAKD;YACjD,IAAIE,OAAO,MAAM,IACbC,QAAQ,KAAK,CACT,CAAC,mDAAmD,EAAEF,IAAI,EAAE,CAAC,EAC7DC,OAAO,KAAK;QAGxB;QAEA,MAAME,QAAQ,GAAG,CAACN;IACtB;IAEQ,YAAYC,IAAU,EAAE;QAC5B,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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
|
+
import { GraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js";
|
|
3
|
+
declare class S3GraphQLSchemaImpl implements CoreGraphQLSchemaFactory.Interface {
|
|
4
|
+
getSchemaKey: () => string;
|
|
5
|
+
execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return;
|
|
6
|
+
}
|
|
7
|
+
export declare const S3GraphQLSchema: typeof S3GraphQLSchemaImpl & {
|
|
8
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core.js").ICoreGraphQLSchemaFactory>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import p_map from "p-map";
|
|
2
|
+
import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
|
|
3
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
6
|
+
import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
7
|
+
import { ErrorResponse, Response } from "@webiny/api-graphql/responses.js";
|
|
8
|
+
import { GetSettingsUseCase } from "@webiny/api-file-manager/features/settings/GetSettings/abstractions.js";
|
|
9
|
+
import { getPresignedPostPayload } from "../utils/getPresignedPostPayload.js";
|
|
10
|
+
import { createFileNormalizerFromContext } from "../utils/createFileNormalizerFromContext.js";
|
|
11
|
+
import { checkPermissions } from "./checkPermissions.js";
|
|
12
|
+
import { CreateMultiPartUploadUseCase } from "../multiPartUpload/CreateMultiPartUploadUseCase.js";
|
|
13
|
+
import { CompleteMultiPartUploadUseCase } from "../multiPartUpload/CompleteMultiPartUploadUseCase.js";
|
|
14
|
+
const TYPE_DEFS = `
|
|
15
|
+
type UploadFileResponseDataFile {
|
|
16
|
+
id: ID!
|
|
17
|
+
name: String!
|
|
18
|
+
type: String!
|
|
19
|
+
size: Long!
|
|
20
|
+
key: String!
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
input PreSignedPostPayloadInput {
|
|
24
|
+
id: ID
|
|
25
|
+
name: String!
|
|
26
|
+
type: String!
|
|
27
|
+
size: Long!
|
|
28
|
+
key: String
|
|
29
|
+
keyPrefix: String
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type GetPreSignedPostPayloadResponseDataFile {
|
|
33
|
+
id: ID!
|
|
34
|
+
name: String!
|
|
35
|
+
type: String!
|
|
36
|
+
size: Long!
|
|
37
|
+
key: String!
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type GetPreSignedPostPayloadResponseData {
|
|
41
|
+
# Contains data that is necessary for initiating a file upload.
|
|
42
|
+
data: JSON!
|
|
43
|
+
file: UploadFileResponseDataFile!
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type GetPreSignedPostPayloadResponse {
|
|
47
|
+
error: FmError
|
|
48
|
+
data: GetPreSignedPostPayloadResponseData
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type MultiPartUploadFilePart {
|
|
52
|
+
partNumber: Int!
|
|
53
|
+
url: String!
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type CreateMultiPartUploadResponseData {
|
|
57
|
+
file: GetPreSignedPostPayloadResponseDataFile!
|
|
58
|
+
uploadId: String!
|
|
59
|
+
parts: [MultiPartUploadFilePart!]!
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type CompleteMultiPartUploadResponse {
|
|
63
|
+
data: Boolean
|
|
64
|
+
error: FmError
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type GetPreSignedPostPayloadsResponse {
|
|
68
|
+
error: FmError
|
|
69
|
+
data: [GetPreSignedPostPayloadResponseData!]!
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
extend type FmQuery {
|
|
73
|
+
getPreSignedPostPayload(data: PreSignedPostPayloadInput!): GetPreSignedPostPayloadResponse
|
|
74
|
+
getPreSignedPostPayloads(
|
|
75
|
+
data: [PreSignedPostPayloadInput]!
|
|
76
|
+
): GetPreSignedPostPayloadsResponse
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type CreateMultiPartUploadResponse {
|
|
80
|
+
data: CreateMultiPartUploadResponseData
|
|
81
|
+
error: FmError
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
input MultiPartUploadFilePartInput {
|
|
85
|
+
partNumber: Int!
|
|
86
|
+
etag: String!
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
extend type FmMutation {
|
|
90
|
+
createMultiPartUpload(
|
|
91
|
+
data: PreSignedPostPayloadInput!
|
|
92
|
+
numberOfParts: Number!
|
|
93
|
+
): CreateMultiPartUploadResponse
|
|
94
|
+
|
|
95
|
+
completeMultiPartUpload(
|
|
96
|
+
fileKey: String!
|
|
97
|
+
uploadId: String!
|
|
98
|
+
): CompleteMultiPartUploadResponse
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
class S3GraphQLSchemaImpl {
|
|
102
|
+
async execute(builder) {
|
|
103
|
+
builder.addTypeDefs(TYPE_DEFS);
|
|
104
|
+
builder.addResolver({
|
|
105
|
+
path: "FmQuery.getPreSignedPostPayload",
|
|
106
|
+
dependencies: [
|
|
107
|
+
IdentityContext,
|
|
108
|
+
GetSettingsUseCase,
|
|
109
|
+
TenantContext
|
|
110
|
+
],
|
|
111
|
+
resolver (identityContext, getSettings, tenantContext) {
|
|
112
|
+
return async ({ args, context })=>{
|
|
113
|
+
try {
|
|
114
|
+
await checkPermissions(identityContext, {
|
|
115
|
+
rwd: "w"
|
|
116
|
+
});
|
|
117
|
+
const settingsResult = await getSettings.execute();
|
|
118
|
+
if (settingsResult.isFail()) throw settingsResult.error;
|
|
119
|
+
const settings = settingsResult.value;
|
|
120
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
121
|
+
const presignedPayload = await getPresignedPostPayload(await normalizer.normalizeFile(args.data), settings, tenantContext);
|
|
122
|
+
return new Response(presignedPayload);
|
|
123
|
+
} catch (e) {
|
|
124
|
+
return new ErrorResponse({
|
|
125
|
+
message: e.message,
|
|
126
|
+
code: e.code,
|
|
127
|
+
data: e.data
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
builder.addResolver({
|
|
134
|
+
path: "FmQuery.getPreSignedPostPayloads",
|
|
135
|
+
dependencies: [
|
|
136
|
+
IdentityContext,
|
|
137
|
+
GetSettingsUseCase,
|
|
138
|
+
TenantContext
|
|
139
|
+
],
|
|
140
|
+
resolver (identityContext, getSettings, tenantContext) {
|
|
141
|
+
return async ({ args, context })=>{
|
|
142
|
+
await checkPermissions(identityContext, {
|
|
143
|
+
rwd: "w"
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
const settingsResult = await getSettings.execute();
|
|
147
|
+
if (settingsResult.isFail()) throw settingsResult.error;
|
|
148
|
+
const settings = settingsResult.value;
|
|
149
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
150
|
+
const presignedPayloads = await p_map(args.data, async (data)=>getPresignedPostPayload(await normalizer.normalizeFile(data), settings, tenantContext));
|
|
151
|
+
return new Response(presignedPayloads);
|
|
152
|
+
} catch (e) {
|
|
153
|
+
return new ErrorResponse({
|
|
154
|
+
message: e.message,
|
|
155
|
+
code: e.code,
|
|
156
|
+
data: e.data
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
builder.addResolver({
|
|
163
|
+
path: "FmMutation.createMultiPartUpload",
|
|
164
|
+
dependencies: [
|
|
165
|
+
IdentityContext
|
|
166
|
+
],
|
|
167
|
+
resolver (identityContext) {
|
|
168
|
+
return async ({ args, context })=>{
|
|
169
|
+
await checkPermissions(identityContext, {
|
|
170
|
+
rwd: "w"
|
|
171
|
+
});
|
|
172
|
+
const s3Client = new S3({
|
|
173
|
+
region: process.env.AWS_REGION
|
|
174
|
+
});
|
|
175
|
+
try {
|
|
176
|
+
const useCase = new CreateMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
177
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
178
|
+
const multiPartUpload = await useCase.execute({
|
|
179
|
+
file: await normalizer.normalizeFile(args.data),
|
|
180
|
+
numberOfParts: args.numberOfParts
|
|
181
|
+
});
|
|
182
|
+
return new Response(multiPartUpload);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
return new ErrorResponse({
|
|
185
|
+
message: e.message,
|
|
186
|
+
code: e.code,
|
|
187
|
+
data: e.data
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
builder.addResolver({
|
|
194
|
+
path: "FmMutation.completeMultiPartUpload",
|
|
195
|
+
dependencies: [
|
|
196
|
+
IdentityContext
|
|
197
|
+
],
|
|
198
|
+
resolver (identityContext) {
|
|
199
|
+
return async ({ args })=>{
|
|
200
|
+
await checkPermissions(identityContext, {
|
|
201
|
+
rwd: "w"
|
|
202
|
+
});
|
|
203
|
+
const s3Client = new S3({
|
|
204
|
+
region: process.env.AWS_REGION
|
|
205
|
+
});
|
|
206
|
+
try {
|
|
207
|
+
const useCase = new CompleteMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
208
|
+
await useCase.execute({
|
|
209
|
+
fileKey: args.fileKey,
|
|
210
|
+
uploadId: args.uploadId
|
|
211
|
+
});
|
|
212
|
+
return new Response(true);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
return new ErrorResponse({
|
|
215
|
+
message: e.message,
|
|
216
|
+
code: e.code,
|
|
217
|
+
data: e.data
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return builder;
|
|
224
|
+
}
|
|
225
|
+
constructor(){
|
|
226
|
+
this.getSchemaKey = staticSchemaKey("api-file-manager-s3/S3GraphQLSchemaImpl");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const S3GraphQLSchema = CoreGraphQLSchemaFactory.createImplementation({
|
|
230
|
+
implementation: S3GraphQLSchemaImpl,
|
|
231
|
+
dependencies: []
|
|
232
|
+
});
|
|
233
|
+
export { S3GraphQLSchema };
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=S3GraphQLSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql/S3GraphQLSchema.js","sources":["../../src/graphql/S3GraphQLSchema.ts"],"sourcesContent":["import pMap from \"p-map\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { GraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { S3 } from \"@webiny/aws-sdk/client-s3/index.js\";\nimport { ErrorResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { GetSettingsUseCase } from \"@webiny/api-file-manager/features/settings/GetSettings/abstractions.js\";\nimport { getPresignedPostPayload } from \"~/utils/getPresignedPostPayload.js\";\nimport { createFileNormalizerFromContext } from \"~/utils/createFileNormalizerFromContext.js\";\nimport { checkPermissions } from \"./checkPermissions.js\";\nimport type { PresignedPostPayloadData } from \"~/types.js\";\nimport { CreateMultiPartUploadUseCase } from \"~/multiPartUpload/CreateMultiPartUploadUseCase.js\";\nimport { CompleteMultiPartUploadUseCase } from \"~/multiPartUpload/CompleteMultiPartUploadUseCase.js\";\n\nconst TYPE_DEFS = /* GraphQL */ `\n type UploadFileResponseDataFile {\n id: ID!\n name: String!\n type: String!\n size: Long!\n key: String!\n }\n\n input PreSignedPostPayloadInput {\n id: ID\n name: String!\n type: String!\n size: Long!\n key: String\n keyPrefix: String\n }\n\n type GetPreSignedPostPayloadResponseDataFile {\n id: ID!\n name: String!\n type: String!\n size: Long!\n key: String!\n }\n\n type GetPreSignedPostPayloadResponseData {\n # Contains data that is necessary for initiating a file upload.\n data: JSON!\n file: UploadFileResponseDataFile!\n }\n\n type GetPreSignedPostPayloadResponse {\n error: FmError\n data: GetPreSignedPostPayloadResponseData\n }\n\n type MultiPartUploadFilePart {\n partNumber: Int!\n url: String!\n }\n\n type CreateMultiPartUploadResponseData {\n file: GetPreSignedPostPayloadResponseDataFile!\n uploadId: String!\n parts: [MultiPartUploadFilePart!]!\n }\n\n type CompleteMultiPartUploadResponse {\n data: Boolean\n error: FmError\n }\n\n type GetPreSignedPostPayloadsResponse {\n error: FmError\n data: [GetPreSignedPostPayloadResponseData!]!\n }\n\n extend type FmQuery {\n getPreSignedPostPayload(data: PreSignedPostPayloadInput!): GetPreSignedPostPayloadResponse\n getPreSignedPostPayloads(\n data: [PreSignedPostPayloadInput]!\n ): GetPreSignedPostPayloadsResponse\n }\n\n type CreateMultiPartUploadResponse {\n data: CreateMultiPartUploadResponseData\n error: FmError\n }\n\n input MultiPartUploadFilePartInput {\n partNumber: Int!\n etag: String!\n }\n\n extend type FmMutation {\n createMultiPartUpload(\n data: PreSignedPostPayloadInput!\n numberOfParts: Number!\n ): CreateMultiPartUploadResponse\n\n completeMultiPartUpload(\n fileKey: String!\n uploadId: String!\n ): CompleteMultiPartUploadResponse\n }\n`;\n\nclass S3GraphQLSchemaImpl implements CoreGraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-file-manager-s3/S3GraphQLSchemaImpl\");\n\n public async execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return {\n builder.addTypeDefs(TYPE_DEFS);\n\n builder.addResolver<{ data: PresignedPostPayloadData }>({\n path: \"FmQuery.getPreSignedPostPayload\",\n dependencies: [IdentityContext, GetSettingsUseCase, TenantContext],\n resolver(\n identityContext: IdentityContext.Interface,\n getSettings: GetSettingsUseCase.Interface,\n tenantContext: TenantContext.Interface\n ) {\n return async ({ args, context }) => {\n try {\n await checkPermissions(identityContext, { rwd: \"w\" });\n\n const settingsResult = await getSettings.execute();\n if (settingsResult.isFail()) {\n throw settingsResult.error;\n }\n const settings = settingsResult.value;\n\n const normalizer = createFileNormalizerFromContext(context);\n const presignedPayload = await getPresignedPostPayload(\n await normalizer.normalizeFile(args.data),\n settings,\n tenantContext\n );\n\n return new Response(presignedPayload);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n };\n }\n });\n\n builder.addResolver<{ data: PresignedPostPayloadData[] }>({\n path: \"FmQuery.getPreSignedPostPayloads\",\n dependencies: [IdentityContext, GetSettingsUseCase, TenantContext],\n resolver(\n identityContext: IdentityContext.Interface,\n getSettings: GetSettingsUseCase.Interface,\n tenantContext: TenantContext.Interface\n ) {\n return async ({ args, context }) => {\n await checkPermissions(identityContext, { rwd: \"w\" });\n\n try {\n const settingsResult = await getSettings.execute();\n if (settingsResult.isFail()) {\n throw settingsResult.error;\n }\n const settings = settingsResult.value;\n\n const normalizer = createFileNormalizerFromContext(context);\n\n const presignedPayloads = await pMap(args.data, async data => {\n return getPresignedPostPayload(\n await normalizer.normalizeFile(data),\n settings,\n tenantContext\n );\n });\n\n return new Response(presignedPayloads);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n };\n }\n });\n\n builder.addResolver<{ data: any; numberOfParts: number }>({\n path: \"FmMutation.createMultiPartUpload\",\n dependencies: [IdentityContext],\n resolver(identityContext: IdentityContext.Interface) {\n return async ({ args, context }) => {\n await checkPermissions(identityContext, { rwd: \"w\" });\n\n const s3Client = new S3({ region: process.env.AWS_REGION });\n\n try {\n const useCase = new CreateMultiPartUploadUseCase(\n String(process.env.S3_BUCKET),\n s3Client\n );\n\n const normalizer = createFileNormalizerFromContext(context);\n\n const multiPartUpload = await useCase.execute({\n file: await normalizer.normalizeFile(args.data),\n numberOfParts: args.numberOfParts\n });\n\n return new Response(multiPartUpload);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n };\n }\n });\n\n builder.addResolver<{ fileKey: string; uploadId: string }>({\n path: \"FmMutation.completeMultiPartUpload\",\n dependencies: [IdentityContext],\n resolver(identityContext: IdentityContext.Interface) {\n return async ({ args }) => {\n await checkPermissions(identityContext, { rwd: \"w\" });\n\n const s3Client = new S3({ region: process.env.AWS_REGION });\n\n try {\n const useCase = new CompleteMultiPartUploadUseCase(\n String(process.env.S3_BUCKET),\n s3Client\n );\n\n await useCase.execute({\n fileKey: args.fileKey,\n uploadId: args.uploadId\n });\n\n return new Response(true);\n } catch (e) {\n return new ErrorResponse({\n message: e.message,\n code: e.code,\n data: e.data\n });\n }\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const S3GraphQLSchema = CoreGraphQLSchemaFactory.createImplementation({\n implementation: S3GraphQLSchemaImpl,\n dependencies: []\n});\n"],"names":["TYPE_DEFS","S3GraphQLSchemaImpl","builder","IdentityContext","GetSettingsUseCase","TenantContext","identityContext","getSettings","tenantContext","args","context","checkPermissions","settingsResult","settings","normalizer","createFileNormalizerFromContext","presignedPayload","getPresignedPostPayload","Response","e","ErrorResponse","presignedPayloads","pMap","data","s3Client","S3","process","useCase","CreateMultiPartUploadUseCase","String","multiPartUpload","CompleteMultiPart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vD,MAAM;YACN,cAAc;gBAACC;aAAgB;YAC/B,UAASG,eAA0C;gBAC/C,OAAO,OAAO,EAAEG,IAAI,EAAE;oBAClB,MAAME,iBAAiBL,iBAAiB;wBAAE,KAAK;oBAAI;oBAEnD,MAAMkB,WAAW,IAAIC,GAAG;wBAAE,QAAQC,QAAQ,GAAG,CAAC,UAAU;oBAAC;oBAEzD,IAAI;wBACA,MAAMC,UAAU,IAAII,+BAChBF,OAAOH,QAAQ,GAAG,CAAC,SAAS,GAC5BF;wBAGJ,MAAMG,QAAQ,OAAO,CAAC;4BAClB,SAASlB,KAAK,OAAO;4BACrB,UAAUA,KAAK,QAAQ;wBAC3B;wBAEA,OAAO,IAAIS,SAAS;oBACxB,EAAE,OAAOC,GAAG;wBACR,OAAO,IAAIC,cAAc;4BACrB,SAASD,EAAE,OAAO;4BAClB,MAAMA,EAAE,IAAI;4BACZ,MAAMA,EAAE,IAAI;wBAChB;oBACJ;gBACJ;YACJ;QACJ;QAEA,OAAOjB;IACX;;aArJO,YAAY,GAAG8B,gBAAgB;;AAsJ1C;AAEO,MAAMC,kBAAkBC,yBAAyB,oBAAoB,CAAC;IACzE,gBAAgBjC;IAChB,cAAc,EAAE;AACpB"}
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
1
|
export { createFileUploadModifier } from "./utils/FileUploadModifier.js";
|
|
3
2
|
export { createAssetDelivery } from "./assetDelivery/createAssetDelivery.js";
|
|
4
|
-
export
|
|
3
|
+
export { FileManagerS3Feature } from "./FileManagerS3Feature.js";
|
|
4
|
+
export type { FileManagerS3FeatureConfig } from "./FileManagerS3Feature.js";
|
package/index.js
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
import { ContextPlugin } from "@webiny/api";
|
|
2
|
-
import { WcpContext } from "@webiny/api-core/features/wcp/WcpContext/index.js";
|
|
3
|
-
import { createS3GraphQLSchema } from "./graphql/schema.js";
|
|
4
|
-
import { DeleteFileFromBucketFeature } from "./features/DeleteFileFromBucket/feature.js";
|
|
5
|
-
import { WriteFileMetadataFeature } from "./features/WriteFileMetadata/feature.js";
|
|
6
|
-
import { ApplyThreatScanningFeature } from "./enterprise/ApplyThreatScanning/feature.js";
|
|
7
|
-
import { FlushCacheFeature } from "./features/FlushCache/feature.js";
|
|
8
|
-
import { ExtractMetadataFeature } from "./features/ExtractMetadata/feature.js";
|
|
9
|
-
import { GetFileContentsByIdFeature } from "./features/GetFileContentsById/feature.js";
|
|
10
|
-
import { GetFileContentsByKeyFeature } from "./features/GetFileContentsByKey/feature.js";
|
|
11
|
-
const contextPlugin = new ContextPlugin((context)=>{
|
|
12
|
-
const container = context.container;
|
|
13
|
-
FlushCacheFeature.register(container);
|
|
14
|
-
DeleteFileFromBucketFeature.register(container);
|
|
15
|
-
ExtractMetadataFeature.register(container);
|
|
16
|
-
WriteFileMetadataFeature.register(container);
|
|
17
|
-
GetFileContentsByIdFeature.register(container);
|
|
18
|
-
GetFileContentsByKeyFeature.register(container);
|
|
19
|
-
const wcp = container.resolve(WcpContext);
|
|
20
|
-
if (wcp.canUseFileManagerThreatDetection()) ApplyThreatScanningFeature.register(container);
|
|
21
|
-
});
|
|
22
|
-
contextPlugin.name = "fileManagerS3.context";
|
|
23
|
-
const createFileManagerS3 = ()=>[
|
|
24
|
-
contextPlugin,
|
|
25
|
-
createS3GraphQLSchema()
|
|
26
|
-
];
|
|
27
1
|
export { createFileUploadModifier } from "./utils/FileUploadModifier.js";
|
|
28
2
|
export { createAssetDelivery } from "./assetDelivery/createAssetDelivery.js";
|
|
29
|
-
export {
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
+
export { FileManagerS3Feature } from "./FileManagerS3Feature.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-file-manager-s3",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.7c2def32a7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -14,32 +14,34 @@
|
|
|
14
14
|
"author": "Webiny Ltd",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/api": "0.0.0-unstable.
|
|
18
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
19
|
-
"@webiny/api-file-manager": "0.0.0-unstable.
|
|
20
|
-
"@webiny/api-
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/handler-
|
|
26
|
-
"@webiny/
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/
|
|
29
|
-
"@webiny/
|
|
30
|
-
"
|
|
17
|
+
"@webiny/api": "0.0.0-unstable.7c2def32a7",
|
|
18
|
+
"@webiny/api-core": "0.0.0-unstable.7c2def32a7",
|
|
19
|
+
"@webiny/api-file-manager": "0.0.0-unstable.7c2def32a7",
|
|
20
|
+
"@webiny/api-graphql": "0.0.0-unstable.7c2def32a7",
|
|
21
|
+
"@webiny/api-websockets": "0.0.0-unstable.7c2def32a7",
|
|
22
|
+
"@webiny/aws-sdk": "0.0.0-unstable.7c2def32a7",
|
|
23
|
+
"@webiny/background-tasks": "0.0.0-unstable.7c2def32a7",
|
|
24
|
+
"@webiny/di": "2.0.0",
|
|
25
|
+
"@webiny/event-handler-aws": "0.0.0-unstable.7c2def32a7",
|
|
26
|
+
"@webiny/event-handler-core": "0.0.0-unstable.7c2def32a7",
|
|
27
|
+
"@webiny/feature": "0.0.0-unstable.7c2def32a7",
|
|
28
|
+
"@webiny/handler": "0.0.0-unstable.7c2def32a7",
|
|
29
|
+
"@webiny/plugins": "0.0.0-unstable.7c2def32a7",
|
|
30
|
+
"@webiny/utils": "0.0.0-unstable.7c2def32a7",
|
|
31
|
+
"@webiny/validation": "0.0.0-unstable.7c2def32a7",
|
|
32
|
+
"exifreader": "4.43.0",
|
|
31
33
|
"mime": "4.1.0",
|
|
32
34
|
"object-hash": "3.0.0",
|
|
33
|
-
"p-map": "7.0.
|
|
35
|
+
"p-map": "7.0.6",
|
|
34
36
|
"p-reduce": "3.0.0",
|
|
35
37
|
"sanitize-filename": "1.6.4",
|
|
36
|
-
"sharp": "0.
|
|
38
|
+
"sharp": "0.35.3"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
41
|
+
"@webiny/build-tools": "0.0.0-unstable.7c2def32a7",
|
|
40
42
|
"rimraf": "6.1.3",
|
|
41
|
-
"typescript": "
|
|
42
|
-
"vitest": "4.1.
|
|
43
|
+
"typescript": "7.0.2",
|
|
44
|
+
"vitest": "4.1.11"
|
|
43
45
|
},
|
|
44
46
|
"publishConfig": {
|
|
45
47
|
"access": "public"
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
-
import "@webiny/tasks/features/TaskController/augmentation.js";
|
|
2
|
+
import "@webiny/background-tasks/api/features/TaskController/augmentation.js";
|
|
3
3
|
export interface PresignedPostPayloadData {
|
|
4
4
|
name: string;
|
|
5
5
|
type: string;
|
package/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import "@webiny/tasks/features/TaskController/augmentation.js";
|
|
1
|
+
import "@webiny/background-tasks/api/features/TaskController/augmentation.js";
|
|
@@ -3,14 +3,14 @@ import type { FileToSign } from "../utils/FileNormalizer.js";
|
|
|
3
3
|
interface Setter<T> {
|
|
4
4
|
(param: T): T;
|
|
5
5
|
}
|
|
6
|
-
declare class
|
|
6
|
+
declare class FileUploadModifierBuilder {
|
|
7
7
|
private fileSetters;
|
|
8
8
|
setFile(setter: Setter<FileToSign>): void;
|
|
9
9
|
execute(file: FileToSign): Promise<FileToSign>;
|
|
10
10
|
}
|
|
11
11
|
interface FileUploadModifierCallbackParams {
|
|
12
12
|
modifier: {
|
|
13
|
-
setFile:
|
|
13
|
+
setFile: FileUploadModifierBuilder["setFile"];
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export declare class FileUploadModifierPlugin extends Plugin {
|
|
@@ -23,6 +23,12 @@ interface FileUploadModifierCallable {
|
|
|
23
23
|
(params: FileUploadModifierCallbackParams): void;
|
|
24
24
|
}
|
|
25
25
|
export declare const createFileUploadModifier: (cb: FileUploadModifierCallable) => FileUploadModifierPlugin;
|
|
26
|
+
/**
|
|
27
|
+
* DI multiple-abstraction for file-upload modifiers. Replaces the old
|
|
28
|
+
* `context.plugins.byType(FileUploadModifierPlugin.type)` lookup in createFileNormalizerFromContext.
|
|
29
|
+
* Extensions register modifiers via `container.registerInstance(FileUploadModifier, createFileUploadModifier(cb))`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const FileUploadModifier: import("@webiny/di").Abstraction<FileUploadModifierPlugin>;
|
|
26
32
|
export interface FileModifier {
|
|
27
33
|
(file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;
|
|
28
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import p_reduce from "p-reduce";
|
|
2
2
|
import { Plugin } from "@webiny/plugins";
|
|
3
|
-
|
|
3
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
4
|
+
class FileUploadModifierBuilder {
|
|
4
5
|
setFile(setter) {
|
|
5
6
|
this.fileSetters.push(setter);
|
|
6
7
|
}
|
|
@@ -27,13 +28,14 @@ class FileUploadModifierPlugin extends Plugin {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
const createFileUploadModifier = (cb)=>new FileUploadModifierPlugin(cb);
|
|
31
|
+
const FileUploadModifier = createAbstraction("FileUploadModifier");
|
|
30
32
|
const createModifierFromPlugins = (plugins = [])=>{
|
|
31
|
-
const modifier = new
|
|
33
|
+
const modifier = new FileUploadModifierBuilder();
|
|
32
34
|
plugins.forEach((pl)=>pl.execute({
|
|
33
35
|
modifier
|
|
34
36
|
}));
|
|
35
37
|
return (file)=>modifier.execute(file);
|
|
36
38
|
};
|
|
37
|
-
export { FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
|
|
39
|
+
export { FileUploadModifier, FileUploadModifierPlugin, createFileUploadModifier, createModifierFromPlugins };
|
|
38
40
|
|
|
39
41
|
//# sourceMappingURL=FileUploadModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/FileUploadModifier.js","sources":["../../src/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass
|
|
1
|
+
{"version":3,"file":"utils/FileUploadModifier.js","sources":["../../src/utils/FileUploadModifier.ts"],"sourcesContent":["import pReduce from \"p-reduce\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { FileToSign } from \"~/utils/FileNormalizer.js\";\n\ninterface Setter<T> {\n (param: T): T;\n}\n\nclass FileUploadModifierBuilder {\n private fileSetters: Setter<FileToSign>[] = [];\n\n setFile(setter: Setter<FileToSign>): void {\n this.fileSetters.push(setter);\n }\n\n execute(file: FileToSign) {\n return pReduce(\n this.fileSetters,\n async (file, setter) => {\n // We need to spread the original file, then add (potentially) partial changes.\n return { ...file, ...(await setter(file)) };\n },\n file\n );\n }\n}\n\ninterface FileUploadModifierCallbackParams {\n modifier: {\n setFile: FileUploadModifierBuilder[\"setFile\"];\n };\n}\n\nexport class FileUploadModifierPlugin extends Plugin {\n public static override type = \"fm.s3.uploadModifier\";\n private readonly cb: FileUploadModifierCallable;\n\n constructor(cb: FileUploadModifierCallable) {\n super();\n this.cb = cb;\n }\n\n execute(params: FileUploadModifierCallbackParams) {\n return this.cb(params);\n }\n}\n\ninterface FileUploadModifierCallable {\n (params: FileUploadModifierCallbackParams): void;\n}\n\nexport const createFileUploadModifier = (cb: FileUploadModifierCallable) => {\n return new FileUploadModifierPlugin(cb);\n};\n\n/**\n * DI multiple-abstraction for file-upload modifiers. Replaces the old\n * `context.plugins.byType(FileUploadModifierPlugin.type)` lookup in createFileNormalizerFromContext.\n * Extensions register modifiers via `container.registerInstance(FileUploadModifier, createFileUploadModifier(cb))`.\n */\nexport const FileUploadModifier = createAbstraction<FileUploadModifierPlugin>(\"FileUploadModifier\");\n\nexport interface FileModifier {\n (file: FileToSign): Promise<Partial<FileToSign>> | Partial<FileToSign>;\n}\n\nexport const createModifierFromPlugins = (\n plugins: FileUploadModifierPlugin[] = []\n): FileModifier => {\n const modifier = new FileUploadModifierBuilder();\n plugins.forEach(pl => pl.execute({ modifier }));\n\n return (file: FileToSign) => modifier.execute(file);\n};\n"],"names":["FileUploadModifierBuilder","setter","file","pReduce","FileUploadModifierPlugin","Plugin","cb","params","createFileUploadModifier","FileUploadModifier","createAbstraction","createModifierFromPlugins","plugins","modifier","pl"],"mappings":";;;AASA,MAAMA;IAGF,QAAQC,MAA0B,EAAQ;QACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAACA;IAC1B;IAEA,QAAQC,IAAgB,EAAE;QACtB,OAAOC,SACH,IAAI,CAAC,WAAW,EAChB,OAAOD,MAAMD,SAEF;gBAAE,GAAGC,IAAI;gBAAE,GAAI,MAAMD,OAAOC,KAAK;YAAE,IAE9CA;IAER;;aAfQ,WAAW,GAAyB,EAAE;;AAgBlD;AAQO,MAAME,iCAAiCC;;aACnB,IAAI,GAAG;;IAG9B,YAAYC,EAA8B,CAAE;QACxC,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,QAAQC,MAAwC,EAAE;QAC9C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAMO,MAAMC,2BAA2B,CAACF,KAC9B,IAAIF,yBAAyBE;AAQjC,MAAMG,qBAAqBC,kBAA4C;AAMvE,MAAMC,4BAA4B,CACrCC,UAAsC,EAAE;IAExC,MAAMC,WAAW,IAAIb;IACrBY,QAAQ,OAAO,CAACE,CAAAA,KAAMA,GAAG,OAAO,CAAC;YAAED;QAAS;IAE5C,OAAO,CAACX,OAAqBW,SAAS,OAAO,CAACX;AAClD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FileNormalizer } from "./FileNormalizer.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FileUploadModifier, createModifierFromPlugins } from "./FileUploadModifier.js";
|
|
3
3
|
const createFileNormalizerFromContext = (context)=>{
|
|
4
|
-
const modifierPlugins = context.
|
|
4
|
+
const modifierPlugins = context.container.resolveAll(FileUploadModifier);
|
|
5
5
|
return new FileNormalizer(createModifierFromPlugins(modifierPlugins));
|
|
6
6
|
};
|
|
7
7
|
export { createFileNormalizerFromContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils/createFileNormalizerFromContext.js","sources":["../../src/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer.js\";\nimport { createModifierFromPlugins,
|
|
1
|
+
{"version":3,"file":"utils/createFileNormalizerFromContext.js","sources":["../../src/utils/createFileNormalizerFromContext.ts"],"sourcesContent":["import type { Context } from \"@webiny/api/types.js\";\nimport { FileNormalizer } from \"~/utils/FileNormalizer.js\";\nimport { createModifierFromPlugins, FileUploadModifier } from \"~/utils/FileUploadModifier.js\";\n\nexport const createFileNormalizerFromContext = (context: Context) => {\n // Modifiers are registered as DI instances (FileUploadModifier) — was\n // context.plugins.byType(FileUploadModifierPlugin.type).\n const modifierPlugins = context.container.resolveAll(FileUploadModifier);\n\n return new FileNormalizer(createModifierFromPlugins(modifierPlugins));\n};\n"],"names":["createFileNormalizerFromContext","context","modifierPlugins","FileUploadModifier","FileNormalizer","createModifierFromPlugins"],"mappings":";;AAIO,MAAMA,kCAAkC,CAACC;IAG5C,MAAMC,kBAAkBD,QAAQ,SAAS,CAAC,UAAU,CAACE;IAErD,OAAO,IAAIC,eAAeC,0BAA0BH;AACxD"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PresignedPost } from "@webiny/aws-sdk/client-s3/index.js";
|
|
2
|
-
declare const _default: (buffer: Buffer, preSignedPostPayload: PresignedPost) => Promise<Response>;
|
|
3
2
|
export default _default;
|
|
3
|
+
declare function _default(buffer: Buffer, preSignedPostPayload: PresignedPost): Promise<Response>;
|
package/graphql/schema.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createS3GraphQLSchema: () => import("@webiny/handler-graphql").GraphQLSchemaPlugin<import("@webiny/api/types.js").Context>;
|