@webiny/api-file-manager-s3 6.4.5 → 6.6.0-alpha.0
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 +34 -0
- package/FileManagerS3Feature.js.map +1 -0
- package/assetDelivery/assetDeliveryConfig.d.ts +1 -1
- package/assetDelivery/assetDeliveryConfig.js +0 -2
- package/assetDelivery/assetDeliveryConfig.js.map +1 -1
- package/assetDelivery/s3/SharpTransform.js +13 -6
- package/assetDelivery/s3/SharpTransform.js.map +1 -1
- 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/features/DeleteFileFromBucket/DeleteS3FolderTask.d.ts +1 -1
- package/features/ExtractMetadata/ExtractMetadataTask.d.ts +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 +2 -2
- package/features/FlushCache/InvalidateCacheTask.js +2 -2
- 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 +9 -0
- package/graphql/S3GraphQLSchema.js +229 -0
- package/graphql/S3GraphQLSchema.js.map +1 -0
- package/index.d.ts +2 -2
- package/index.js +1 -29
- package/package.json +20 -18
- 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
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
execute(builder: GraphQLSchemaBuilder.Interface): CoreGraphQLSchemaFactory.Return;
|
|
5
|
+
}
|
|
6
|
+
export declare const S3GraphQLSchema: typeof S3GraphQLSchemaImpl & {
|
|
7
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core.js").ICoreGraphQLSchemaFactory>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import p_map from "p-map";
|
|
2
|
+
import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
3
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
5
|
+
import { S3 } from "@webiny/aws-sdk/client-s3/index.js";
|
|
6
|
+
import { ErrorResponse, Response } from "@webiny/api-graphql/responses.js";
|
|
7
|
+
import { GetSettingsUseCase } from "@webiny/api-file-manager/features/settings/GetSettings/abstractions.js";
|
|
8
|
+
import { getPresignedPostPayload } from "../utils/getPresignedPostPayload.js";
|
|
9
|
+
import { createFileNormalizerFromContext } from "../utils/createFileNormalizerFromContext.js";
|
|
10
|
+
import { checkPermissions } from "./checkPermissions.js";
|
|
11
|
+
import { CreateMultiPartUploadUseCase } from "../multiPartUpload/CreateMultiPartUploadUseCase.js";
|
|
12
|
+
import { CompleteMultiPartUploadUseCase } from "../multiPartUpload/CompleteMultiPartUploadUseCase.js";
|
|
13
|
+
const TYPE_DEFS = `
|
|
14
|
+
type UploadFileResponseDataFile {
|
|
15
|
+
id: ID!
|
|
16
|
+
name: String!
|
|
17
|
+
type: String!
|
|
18
|
+
size: Long!
|
|
19
|
+
key: String!
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
input PreSignedPostPayloadInput {
|
|
23
|
+
id: ID
|
|
24
|
+
name: String!
|
|
25
|
+
type: String!
|
|
26
|
+
size: Long!
|
|
27
|
+
key: String
|
|
28
|
+
keyPrefix: String
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type GetPreSignedPostPayloadResponseDataFile {
|
|
32
|
+
id: ID!
|
|
33
|
+
name: String!
|
|
34
|
+
type: String!
|
|
35
|
+
size: Long!
|
|
36
|
+
key: String!
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type GetPreSignedPostPayloadResponseData {
|
|
40
|
+
# Contains data that is necessary for initiating a file upload.
|
|
41
|
+
data: JSON!
|
|
42
|
+
file: UploadFileResponseDataFile!
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type GetPreSignedPostPayloadResponse {
|
|
46
|
+
error: FmError
|
|
47
|
+
data: GetPreSignedPostPayloadResponseData
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type MultiPartUploadFilePart {
|
|
51
|
+
partNumber: Int!
|
|
52
|
+
url: String!
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type CreateMultiPartUploadResponseData {
|
|
56
|
+
file: GetPreSignedPostPayloadResponseDataFile!
|
|
57
|
+
uploadId: String!
|
|
58
|
+
parts: [MultiPartUploadFilePart!]!
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type CompleteMultiPartUploadResponse {
|
|
62
|
+
data: Boolean
|
|
63
|
+
error: FmError
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type GetPreSignedPostPayloadsResponse {
|
|
67
|
+
error: FmError
|
|
68
|
+
data: [GetPreSignedPostPayloadResponseData!]!
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
extend type FmQuery {
|
|
72
|
+
getPreSignedPostPayload(data: PreSignedPostPayloadInput!): GetPreSignedPostPayloadResponse
|
|
73
|
+
getPreSignedPostPayloads(
|
|
74
|
+
data: [PreSignedPostPayloadInput]!
|
|
75
|
+
): GetPreSignedPostPayloadsResponse
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type CreateMultiPartUploadResponse {
|
|
79
|
+
data: CreateMultiPartUploadResponseData
|
|
80
|
+
error: FmError
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
input MultiPartUploadFilePartInput {
|
|
84
|
+
partNumber: Int!
|
|
85
|
+
etag: String!
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
extend type FmMutation {
|
|
89
|
+
createMultiPartUpload(
|
|
90
|
+
data: PreSignedPostPayloadInput!
|
|
91
|
+
numberOfParts: Number!
|
|
92
|
+
): CreateMultiPartUploadResponse
|
|
93
|
+
|
|
94
|
+
completeMultiPartUpload(
|
|
95
|
+
fileKey: String!
|
|
96
|
+
uploadId: String!
|
|
97
|
+
): CompleteMultiPartUploadResponse
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
class S3GraphQLSchemaImpl {
|
|
101
|
+
async execute(builder) {
|
|
102
|
+
builder.addTypeDefs(TYPE_DEFS);
|
|
103
|
+
builder.addResolver({
|
|
104
|
+
path: "FmQuery.getPreSignedPostPayload",
|
|
105
|
+
dependencies: [
|
|
106
|
+
IdentityContext,
|
|
107
|
+
GetSettingsUseCase,
|
|
108
|
+
TenantContext
|
|
109
|
+
],
|
|
110
|
+
resolver (identityContext, getSettings, tenantContext) {
|
|
111
|
+
return async ({ args, context })=>{
|
|
112
|
+
try {
|
|
113
|
+
await checkPermissions(identityContext, {
|
|
114
|
+
rwd: "w"
|
|
115
|
+
});
|
|
116
|
+
const settingsResult = await getSettings.execute();
|
|
117
|
+
const settings = settingsResult.value;
|
|
118
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
119
|
+
const presignedPayload = await getPresignedPostPayload(await normalizer.normalizeFile(args.data), settings, tenantContext);
|
|
120
|
+
return new Response(presignedPayload);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return new ErrorResponse({
|
|
123
|
+
message: e.message,
|
|
124
|
+
code: e.code,
|
|
125
|
+
data: e.data
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
builder.addResolver({
|
|
132
|
+
path: "FmQuery.getPreSignedPostPayloads",
|
|
133
|
+
dependencies: [
|
|
134
|
+
IdentityContext,
|
|
135
|
+
GetSettingsUseCase,
|
|
136
|
+
TenantContext
|
|
137
|
+
],
|
|
138
|
+
resolver (identityContext, getSettings, tenantContext) {
|
|
139
|
+
return async ({ args, context })=>{
|
|
140
|
+
await checkPermissions(identityContext, {
|
|
141
|
+
rwd: "w"
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
const settingsResult = await getSettings.execute();
|
|
145
|
+
const settings = settingsResult.value;
|
|
146
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
147
|
+
const presignedPayloads = await p_map(args.data, async (data)=>getPresignedPostPayload(await normalizer.normalizeFile(data), settings, tenantContext));
|
|
148
|
+
return new Response(presignedPayloads);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
return new ErrorResponse({
|
|
151
|
+
message: e.message,
|
|
152
|
+
code: e.code,
|
|
153
|
+
data: e.data
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
builder.addResolver({
|
|
160
|
+
path: "FmMutation.createMultiPartUpload",
|
|
161
|
+
dependencies: [
|
|
162
|
+
IdentityContext
|
|
163
|
+
],
|
|
164
|
+
resolver (identityContext) {
|
|
165
|
+
return async ({ args, context })=>{
|
|
166
|
+
await checkPermissions(identityContext, {
|
|
167
|
+
rwd: "w"
|
|
168
|
+
});
|
|
169
|
+
const s3Client = new S3({
|
|
170
|
+
region: process.env.AWS_REGION
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
const useCase = new CreateMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
174
|
+
const normalizer = createFileNormalizerFromContext(context);
|
|
175
|
+
const multiPartUpload = await useCase.execute({
|
|
176
|
+
file: await normalizer.normalizeFile(args.data),
|
|
177
|
+
numberOfParts: args.numberOfParts
|
|
178
|
+
});
|
|
179
|
+
return new Response(multiPartUpload);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
return new ErrorResponse({
|
|
182
|
+
message: e.message,
|
|
183
|
+
code: e.code,
|
|
184
|
+
data: e.data
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
builder.addResolver({
|
|
191
|
+
path: "FmMutation.completeMultiPartUpload",
|
|
192
|
+
dependencies: [
|
|
193
|
+
IdentityContext
|
|
194
|
+
],
|
|
195
|
+
resolver (identityContext) {
|
|
196
|
+
return async ({ args })=>{
|
|
197
|
+
await checkPermissions(identityContext, {
|
|
198
|
+
rwd: "w"
|
|
199
|
+
});
|
|
200
|
+
const s3Client = new S3({
|
|
201
|
+
region: process.env.AWS_REGION
|
|
202
|
+
});
|
|
203
|
+
try {
|
|
204
|
+
const useCase = new CompleteMultiPartUploadUseCase(String(process.env.S3_BUCKET), s3Client);
|
|
205
|
+
await useCase.execute({
|
|
206
|
+
fileKey: args.fileKey,
|
|
207
|
+
uploadId: args.uploadId
|
|
208
|
+
});
|
|
209
|
+
return new Response(true);
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return new ErrorResponse({
|
|
212
|
+
message: e.message,
|
|
213
|
+
code: e.code,
|
|
214
|
+
data: e.data
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
return builder;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const S3GraphQLSchema = CoreGraphQLSchemaFactory.createImplementation({
|
|
224
|
+
implementation: S3GraphQLSchemaImpl,
|
|
225
|
+
dependencies: []
|
|
226
|
+
});
|
|
227
|
+
export { S3GraphQLSchema };
|
|
228
|
+
|
|
229
|
+
//# 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 { 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 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 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 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","CompleteMultiPartUploadUseCase","S3GraphQLSchema","CoreGraphQLSchemaFactory"],"mappings":";;;;;;;;;;;;AAeA,MAAMA,YAA0B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFjC,CAAC;AAED,MAAMC;IACF,MAAa,QAAQC,OAAuC,EAAmC;QAC3FA,QAAQ,WAAW,CAACF;QAEpBE,QAAQ,WAAW,CAAqC;YACpD,MAAM;YACN,cAAc;gBAACC;gBAAiBC;gBAAoBC;aAAc;YAClE,UACIC,eAA0C,EAC1CC,WAAyC,EACzCC,aAAsC;gBAEtC,OAAO,OAAO,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MAAMA,EAAE,IAAI;wBAChB;oBACJ;gBACJ;YACJ;QACJ;QAEA,OAAOjB;IACX;AACJ;AAEO,MAAM8B,kBAAkBC,yBAAyB,oBAAoB,CAAC;IACzE,gBAAgBhC;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": "6.
|
|
3
|
+
"version": "6.6.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -14,31 +14,33 @@
|
|
|
14
14
|
"author": "Webiny Ltd",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@webiny/api": "6.
|
|
18
|
-
"@webiny/api-core": "6.
|
|
19
|
-
"@webiny/api-file-manager": "6.
|
|
20
|
-
"@webiny/api-
|
|
21
|
-
"@webiny/
|
|
22
|
-
"@webiny/
|
|
23
|
-
"@webiny/
|
|
24
|
-
"@webiny/
|
|
25
|
-
"@webiny/handler-aws": "6.
|
|
26
|
-
"@webiny/handler-
|
|
27
|
-
"@webiny/
|
|
28
|
-
"@webiny/
|
|
29
|
-
"@webiny/
|
|
30
|
-
"
|
|
17
|
+
"@webiny/api": "6.6.0-alpha.0",
|
|
18
|
+
"@webiny/api-core": "6.6.0-alpha.0",
|
|
19
|
+
"@webiny/api-file-manager": "6.6.0-alpha.0",
|
|
20
|
+
"@webiny/api-graphql": "6.6.0-alpha.0",
|
|
21
|
+
"@webiny/api-websockets": "6.6.0-alpha.0",
|
|
22
|
+
"@webiny/aws-sdk": "6.6.0-alpha.0",
|
|
23
|
+
"@webiny/background-tasks": "6.6.0-alpha.0",
|
|
24
|
+
"@webiny/di": "1.0.2",
|
|
25
|
+
"@webiny/event-handler-aws": "6.6.0-alpha.0",
|
|
26
|
+
"@webiny/event-handler-core": "6.6.0-alpha.0",
|
|
27
|
+
"@webiny/feature": "6.6.0-alpha.0",
|
|
28
|
+
"@webiny/handler": "6.6.0-alpha.0",
|
|
29
|
+
"@webiny/plugins": "6.6.0-alpha.0",
|
|
30
|
+
"@webiny/utils": "6.6.0-alpha.0",
|
|
31
|
+
"@webiny/validation": "6.6.0-alpha.0",
|
|
32
|
+
"exifreader": "4.41.3",
|
|
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
38
|
"sharp": "0.35.3"
|
|
37
39
|
},
|
|
38
40
|
"devDependencies": {
|
|
39
|
-
"@webiny/build-tools": "6.
|
|
41
|
+
"@webiny/build-tools": "6.6.0-alpha.0",
|
|
40
42
|
"rimraf": "6.1.3",
|
|
41
|
-
"typescript": "
|
|
43
|
+
"typescript": "7.0.2",
|
|
42
44
|
"vitest": "4.1.10"
|
|
43
45
|
},
|
|
44
46
|
"publishConfig": {
|
|
@@ -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>;
|