@webiny/api-file-manager 6.4.0-beta.2 → 6.4.0-beta.3
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/delivery/index.d.ts +3 -12
- package/delivery/index.js +2 -6
- package/delivery/setupAssetDelivery.d.ts +1 -2
- package/delivery/setupAssetDelivery.js +6 -20
- package/delivery/setupAssetDelivery.js.map +1 -1
- package/features/assetDelivery/FilesAssetRequestResolver.d.ts +9 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/FilesAssetRequestResolver.js +7 -2
- package/features/assetDelivery/FilesAssetRequestResolver.js.map +1 -0
- package/features/assetDelivery/NullAssetOutputStrategy.d.ts +8 -0
- package/features/assetDelivery/NullAssetOutputStrategy.js +14 -0
- package/features/assetDelivery/NullAssetOutputStrategy.js.map +1 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/NullAssetReply.js +1 -1
- package/{delivery/AssetDelivery → features/assetDelivery}/NullAssetReply.js.map +1 -1
- package/features/assetDelivery/NullAssetResolver.d.ts +8 -0
- package/features/assetDelivery/NullAssetResolver.js +13 -0
- package/features/assetDelivery/NullAssetResolver.js.map +1 -0
- package/features/assetDelivery/abstractions.d.ts +54 -0
- package/features/assetDelivery/abstractions.js +11 -0
- package/features/assetDelivery/abstractions.js.map +1 -0
- package/features/assetDelivery/feature.d.ts +4 -0
- package/features/assetDelivery/feature.js +29 -0
- package/features/assetDelivery/feature.js.map +1 -0
- package/features/assetDelivery/privateFiles/NotAuthorizedAssetReply.d.ts +4 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/NotAuthorizedAssetReply.js +1 -1
- package/features/assetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +1 -0
- package/features/assetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +5 -0
- package/features/assetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +1 -0
- package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +11 -0
- package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +26 -0
- package/features/assetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +1 -0
- package/features/assetDelivery/privateFiles/PrivateCache.d.ts +8 -0
- package/features/assetDelivery/privateFiles/PrivateCache.js.map +1 -0
- package/features/assetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +11 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/PrivateFileAssetRequestResolver.js +7 -2
- package/features/assetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +1 -0
- package/features/assetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +19 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/PrivateFilesAssetProcessor.js +17 -8
- package/features/assetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +1 -0
- package/features/assetDelivery/privateFiles/PublicCache.d.ts +8 -0
- package/features/assetDelivery/privateFiles/PublicCache.js.map +1 -0
- package/features/assetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +9 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/RedirectToPrivateUrlOutputStrategy.js +1 -1
- package/features/assetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +1 -0
- package/features/assetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +9 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/RedirectToPublicUrlOutputStrategy.js +1 -1
- package/features/assetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +1 -0
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +9 -0
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js +13 -0
- package/features/assetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +1 -0
- package/features/assetDelivery/transformation/TransformationAssetProcessor.d.ts +11 -0
- package/{delivery/AssetDelivery → features/assetDelivery}/transformation/TransformationAssetProcessor.js +8 -1
- package/features/assetDelivery/transformation/TransformationAssetProcessor.js.map +1 -0
- package/index.d.ts +1 -1
- package/index.js +7 -1
- package/index.js.map +1 -1
- package/package.json +16 -17
- package/delivery/AssetDelivery/AssetDeliveryConfig.d.ts +0 -65
- package/delivery/AssetDelivery/AssetDeliveryConfig.js +0 -81
- package/delivery/AssetDelivery/AssetDeliveryConfig.js.map +0 -1
- package/delivery/AssetDelivery/FilesAssetRequestResolver.d.ts +0 -6
- package/delivery/AssetDelivery/FilesAssetRequestResolver.js.map +0 -1
- package/delivery/AssetDelivery/NullAssetOutputStrategy.d.ts +0 -4
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js +0 -9
- package/delivery/AssetDelivery/NullAssetOutputStrategy.js.map +0 -1
- package/delivery/AssetDelivery/NullAssetResolver.d.ts +0 -5
- package/delivery/AssetDelivery/NullAssetResolver.js +0 -8
- package/delivery/AssetDelivery/NullAssetResolver.js.map +0 -1
- package/delivery/AssetDelivery/NullRequestResolver.d.ts +0 -4
- package/delivery/AssetDelivery/NullRequestResolver.js +0 -8
- package/delivery/AssetDelivery/NullRequestResolver.js.map +0 -1
- package/delivery/AssetDelivery/SetCacheControlHeaders.d.ts +0 -8
- package/delivery/AssetDelivery/SetCacheControlHeaders.js +0 -15
- package/delivery/AssetDelivery/SetCacheControlHeaders.js.map +0 -1
- package/delivery/AssetDelivery/SetResponseHeaders.d.ts +0 -18
- package/delivery/AssetDelivery/SetResponseHeaders.js +0 -19
- package/delivery/AssetDelivery/SetResponseHeaders.js.map +0 -1
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.d.ts +0 -4
- package/delivery/AssetDelivery/abstractions/AssetContentsReader.js +0 -0
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.d.ts +0 -4
- package/delivery/AssetDelivery/abstractions/AssetOutputStrategy.js +0 -0
- package/delivery/AssetDelivery/abstractions/AssetProcessor.d.ts +0 -4
- package/delivery/AssetDelivery/abstractions/AssetProcessor.js +0 -0
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.d.ts +0 -5
- package/delivery/AssetDelivery/abstractions/AssetRequestResolver.js +0 -0
- package/delivery/AssetDelivery/abstractions/AssetResolver.d.ts +0 -4
- package/delivery/AssetDelivery/abstractions/AssetResolver.js +0 -0
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.d.ts +0 -4
- package/delivery/AssetDelivery/abstractions/AssetTransformationStrategy.js +0 -0
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.d.ts +0 -4
- package/delivery/AssetDelivery/privateFiles/AssetAuthorizer.js +0 -0
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.d.ts +0 -4
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.d.ts +0 -4
- package/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.d.ts +0 -8
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js +0 -18
- package/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/PrivateCache.d.ts +0 -6
- package/delivery/AssetDelivery/privateFiles/PrivateCache.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.d.ts +0 -8
- package/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.d.ts +0 -13
- package/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/PublicCache.d.ts +0 -6
- package/delivery/AssetDelivery/privateFiles/PublicCache.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.d.ts +0 -7
- package/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js.map +0 -1
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.d.ts +0 -7
- package/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js.map +0 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.d.ts +0 -4
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js +0 -8
- package/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js.map +0 -1
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.d.ts +0 -4
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js +0 -8
- package/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js.map +0 -1
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.d.ts +0 -6
- package/delivery/AssetDelivery/transformation/TransformationAssetProcessor.js.map +0 -1
- /package/{delivery/AssetDelivery → features/assetDelivery}/NullAssetReply.d.ts +0 -0
- /package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/NotAuthorizedOutputStrategy.js +0 -0
- /package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/PrivateCache.js +0 -0
- /package/{delivery/AssetDelivery → features/assetDelivery}/privateFiles/PublicCache.js +0 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts"],"sourcesContent":["import { ResponseHeaders } from \"@webiny/handler\";\nimport { AssetReply } from \"~/delivery/index.js\";\n\nexport class NotAuthorizedAssetReply extends AssetReply {\n constructor() {\n super({\n code: 403,\n headers: ResponseHeaders.create({\n \"cache-control\": \"no-store\",\n \"content-type\": \"application/json; charset=utf-8\"\n }),\n body: () => ({ error: \"Not authorized!\", code: \"NOT_AUTHORIZED\" })\n });\n }\n}\n"],"names":["NotAuthorizedAssetReply","AssetReply","ResponseHeaders"],"mappings":";;AAGO,MAAMA,gCAAgCC;IACzC,aAAc;QACV,KAAK,CAAC;YACF,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,iBAAiB;gBACjB,gBAAgB;YACpB;YACA,MAAM,IAAO;oBAAE,OAAO;oBAAmB,MAAM;gBAAiB;QACpE;IACJ;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/NotAuthorizedOutputStrategy.ts"],"sourcesContent":["import type { AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\nimport { NotAuthorizedAssetReply } from \"./NotAuthorizedAssetReply.js\";\n\nexport class NotAuthorizedOutputStrategy implements AssetOutputStrategy {\n async output(): Promise<AssetReply> {\n return new NotAuthorizedAssetReply();\n }\n}\n"],"names":["NotAuthorizedOutputStrategy","NotAuthorizedAssetReply"],"mappings":";AAGO,MAAMA;IACT,MAAM,SAA8B;QAChC,OAAO,IAAIC;IACf;AACJ"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { File } from "../../../domain/file/types.js";
|
|
2
|
-
import type { AssetAuthorizer } from "./AssetAuthorizer.js";
|
|
3
|
-
import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
|
|
4
|
-
export declare class PrivateAuthenticatedAuthorizer implements AssetAuthorizer {
|
|
5
|
-
private context;
|
|
6
|
-
constructor(context: ApiCoreContext);
|
|
7
|
-
authorize(file: File): Promise<void>;
|
|
8
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import error from "@webiny/error";
|
|
2
|
-
class PrivateAuthenticatedAuthorizer {
|
|
3
|
-
constructor(context){
|
|
4
|
-
this.context = context;
|
|
5
|
-
}
|
|
6
|
-
async authorize(file) {
|
|
7
|
-
if (file.accessControl && "private-authenticated" === file.accessControl.type) {
|
|
8
|
-
const identity = this.context.security.getIdentity();
|
|
9
|
-
if (!identity) throw new error({
|
|
10
|
-
code: "NOT_AUTHORIZED",
|
|
11
|
-
message: "You're not authorized to access this asset!"
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export { PrivateAuthenticatedAuthorizer };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=PrivateAuthenticatedAuthorizer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateAuthenticatedAuthorizer.ts"],"sourcesContent":["import Error from \"@webiny/error\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\nexport class PrivateAuthenticatedAuthorizer implements AssetAuthorizer {\n private context: ApiCoreContext;\n\n constructor(context: ApiCoreContext) {\n this.context = context;\n }\n\n async authorize(file: File) {\n if (file.accessControl && file.accessControl.type === \"private-authenticated\") {\n // Make sure there's a valid identity!\n const identity = this.context.security.getIdentity();\n\n if (!identity) {\n throw new Error({\n code: \"NOT_AUTHORIZED\",\n message: \"You're not authorized to access this asset!\"\n });\n }\n }\n }\n}\n"],"names":["PrivateAuthenticatedAuthorizer","context","file","identity","Error"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,OAAuB,CAAE;QACjC,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,MAAM,UAAUC,IAAU,EAAE;QACxB,IAAIA,KAAK,aAAa,IAAIA,AAA4B,4BAA5BA,KAAK,aAAa,CAAC,IAAI,EAA8B;YAE3E,MAAMC,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW;YAElD,IAAI,CAACA,UACD,MAAM,IAAIC,MAAM;gBACZ,MAAM;gBACN,SAAS;YACb;QAER;IACJ;AACJ"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetOutputStrategy, AssetReply } from "../../../delivery/index.js";
|
|
2
|
-
export declare class PrivateCache implements AssetOutputStrategy {
|
|
3
|
-
private strategy;
|
|
4
|
-
constructor(strategy: AssetOutputStrategy);
|
|
5
|
-
output(asset: Asset): Promise<AssetReply>;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateCache.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PrivateCache implements AssetOutputStrategy {\n private strategy: AssetOutputStrategy;\n\n constructor(strategy: AssetOutputStrategy) {\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n headers.set(\"cache-control\", (value = \"\") => {\n const cacheControl = parse(value);\n cacheControl[\"private\"] = true;\n cacheControl[\"public\"] = false;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"names":["PrivateCache","strategy","asset","reply","headers","value","cacheControl","parse","stringify"],"mappings":";AAGO,MAAMA;IAGT,YAAYC,QAA6B,CAAE;QACvC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACD;QAEzCC,MAAM,UAAU,CAACC,CAAAA;YACbA,QAAQ,GAAG,CAAC,iBAAiB,CAACC,QAAQ,EAAE;gBACpC,MAAMC,eAAeC,MAAMF;gBAC3BC,YAAY,CAAC,UAAU,GAAG;gBAC1BA,YAAY,CAAC,SAAS,GAAG;gBACzB,OAAOE,UAAUF;YACrB;YACA,OAAOF;QACX;QAEA,OAAOD;IACX;AACJ"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AssetRequestResolver } from "../../../delivery/index.js";
|
|
2
|
-
import { AssetRequest } from "../../../delivery/index.js";
|
|
3
|
-
import type { Request } from "@webiny/handler/types.js";
|
|
4
|
-
export declare class PrivateFileAssetRequestResolver implements AssetRequestResolver {
|
|
5
|
-
private readonly resolver;
|
|
6
|
-
constructor(resolver: AssetRequestResolver);
|
|
7
|
-
resolve(request: Request): Promise<AssetRequest | undefined>;
|
|
8
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFileAssetRequestResolver.ts"],"sourcesContent":["import type { AssetRequestResolver } from \"~/delivery/index.js\";\nimport { AssetRequest } from \"~/delivery/index.js\";\nimport type { Request } from \"@webiny/handler/types.js\";\n\nexport class PrivateFileAssetRequestResolver implements AssetRequestResolver {\n private readonly resolver: AssetRequestResolver;\n\n constructor(resolver: AssetRequestResolver) {\n this.resolver = resolver;\n }\n\n async resolve(request: Request): Promise<AssetRequest | undefined> {\n // Example: /private/65722cb5c7824a0008d05963/image-48.jpg?width=300\n if (!request.url.startsWith(\"/private/\")) {\n return this.resolver.resolve(request);\n }\n\n const params = (request.params ?? {}) as Record<string, any>;\n const query = (request.query ?? {}) as Record<string, any>;\n\n // Example: { '*': '/private/65722cb5c7824a0008d05963/image-48.jpg' },\n const path = params[\"*\"];\n\n return new AssetRequest({\n key: decodeURI(path).replace(\"/private/\", \"\"),\n context: {\n url: request.url,\n private: true\n },\n options: {\n ...query,\n width: query.width ? parseInt(query.width) : undefined\n }\n });\n }\n}\n"],"names":["PrivateFileAssetRequestResolver","resolver","request","params","query","path","AssetRequest","decodeURI","parseInt","undefined"],"mappings":";AAIO,MAAMA;IAGT,YAAYC,QAA8B,CAAE;QACxC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAgB,EAAqC;QAE/D,IAAI,CAACA,QAAQ,GAAG,CAAC,UAAU,CAAC,cACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAACA;QAGjC,MAAMC,SAAUD,QAAQ,MAAM,IAAI,CAAC;QACnC,MAAME,QAASF,QAAQ,KAAK,IAAI,CAAC;QAGjC,MAAMG,OAAOF,MAAM,CAAC,IAAI;QAExB,OAAO,IAAIG,aAAa;YACpB,KAAKC,UAAUF,MAAM,OAAO,CAAC,aAAa;YAC1C,SAAS;gBACL,KAAKH,QAAQ,GAAG;gBAChB,SAAS;YACb;YACA,SAAS;gBACL,GAAGE,KAAK;gBACR,OAAOA,MAAM,KAAK,GAAGI,SAASJ,MAAM,KAAK,IAAIK;YACjD;QACJ;IACJ;AACJ"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
|
|
2
|
-
import type { Asset, AssetProcessor, AssetRequest } from "../../../delivery/index.js";
|
|
3
|
-
import type { AssetAuthorizer } from "./AssetAuthorizer.js";
|
|
4
|
-
export declare class PrivateFilesAssetProcessor implements AssetProcessor {
|
|
5
|
-
private readonly context;
|
|
6
|
-
private assetProcessor;
|
|
7
|
-
private assetAuthorizer;
|
|
8
|
-
constructor(context: ApiCoreContext, assetAuthorizer: AssetAuthorizer, assetProcessor: AssetProcessor);
|
|
9
|
-
process(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
10
|
-
private isPrivate;
|
|
11
|
-
private requestedViaPrivateEndpoint;
|
|
12
|
-
private requestedViaPublicEndpoint;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PrivateFilesAssetProcessor.ts"],"sourcesContent":["import type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { File } from \"~/domain/file/types.js\";\nimport type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\nimport type { AssetAuthorizer } from \"./AssetAuthorizer.js\";\nimport { NotAuthorizedOutputStrategy } from \"./NotAuthorizedOutputStrategy.js\";\nimport { RedirectToPublicUrlOutputStrategy } from \"./RedirectToPublicUrlOutputStrategy.js\";\nimport { RedirectToPrivateUrlOutputStrategy } from \"./RedirectToPrivateUrlOutputStrategy.js\";\nimport { PrivateCache } from \"./PrivateCache.js\";\nimport { PublicCache } from \"./PublicCache.js\";\nimport { GetFileUseCase } from \"~/features/file/GetFile/index.js\";\n\ninterface MaybePrivate {\n private?: boolean;\n}\n\nexport class PrivateFilesAssetProcessor implements AssetProcessor {\n private readonly context: ApiCoreContext;\n private assetProcessor: AssetProcessor;\n private assetAuthorizer: AssetAuthorizer;\n\n constructor(\n context: ApiCoreContext,\n assetAuthorizer: AssetAuthorizer,\n assetProcessor: AssetProcessor\n ) {\n this.assetAuthorizer = assetAuthorizer;\n this.context = context;\n this.assetProcessor = assetProcessor;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const id = asset.getId();\n const { security } = this.context;\n const getFile = this.context.container.resolve(GetFileUseCase);\n\n // Get file from File Manager by `id`.\n const file = await security.withoutAuthorization(async () => {\n const fileResult = await getFile.execute(id);\n if (fileResult.isFail()) {\n throw fileResult.error;\n }\n return fileResult.value;\n });\n\n const isPrivateFile = this.isPrivate(file);\n\n if (!isPrivateFile && this.requestedViaPrivateEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPublicUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n if (isPrivateFile && this.requestedViaPublicEndpoint(assetRequest)) {\n asset.setOutputStrategy(new RedirectToPrivateUrlOutputStrategy(assetRequest));\n return asset;\n }\n\n try {\n await this.assetAuthorizer.authorize(file);\n } catch {\n asset.setOutputStrategy(new NotAuthorizedOutputStrategy());\n\n return asset;\n }\n\n const processedAsset = await this.assetProcessor.process(assetRequest, asset);\n\n processedAsset.setOutputStrategy(strategy => {\n if (!strategy) {\n throw Error(`No asset output strategy is configured!`);\n }\n return isPrivateFile ? new PrivateCache(strategy) : new PublicCache(strategy);\n });\n\n return processedAsset;\n }\n\n private isPrivate(file: File) {\n return file.accessControl && file.accessControl.type.startsWith(\"private-\");\n }\n\n private requestedViaPrivateEndpoint(assetRequest: AssetRequest) {\n return assetRequest.getContext<MaybePrivate>().private;\n }\n\n private requestedViaPublicEndpoint(assetRequest: AssetRequest) {\n return !this.requestedViaPrivateEndpoint(assetRequest);\n }\n}\n"],"names":["PrivateFilesAssetProcessor","context","assetAuthorizer","assetProcessor","assetRequest","asset","id","security","getFile","GetFileUseCase","file","fileResult","isPrivateFile","RedirectToPublicUrlOutputStrategy","RedirectToPrivateUrlOutputStrategy","NotAuthorizedOutputStrategy","processedAsset","strategy","Error","PrivateCache","PublicCache"],"mappings":";;;;;;AAeO,MAAMA;IAKT,YACIC,OAAuB,EACvBC,eAAgC,EAChCC,cAA8B,CAChC;QACE,IAAI,CAAC,eAAe,GAAGD;QACvB,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,cAAc,GAAGE;IAC1B;IAEA,MAAM,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QACpE,MAAMC,KAAKD,MAAM,KAAK;QACtB,MAAM,EAAEE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO;QACjC,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QAG/C,MAAMC,OAAO,MAAMH,SAAS,oBAAoB,CAAC;YAC7C,MAAMI,aAAa,MAAMH,QAAQ,OAAO,CAACF;YACzC,IAAIK,WAAW,MAAM,IACjB,MAAMA,WAAW,KAAK;YAE1B,OAAOA,WAAW,KAAK;QAC3B;QAEA,MAAMC,gBAAgB,IAAI,CAAC,SAAS,CAACF;QAErC,IAAI,CAACE,iBAAiB,IAAI,CAAC,2BAA2B,CAACR,eAAe;YAClEC,MAAM,iBAAiB,CAAC,IAAIQ,kCAAkCT;YAC9D,OAAOC;QACX;QAEA,IAAIO,iBAAiB,IAAI,CAAC,0BAA0B,CAACR,eAAe;YAChEC,MAAM,iBAAiB,CAAC,IAAIS,mCAAmCV;YAC/D,OAAOC;QACX;QAEA,IAAI;YACA,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAACK;QACzC,EAAE,OAAM;YACJL,MAAM,iBAAiB,CAAC,IAAIU;YAE5B,OAAOV;QACX;QAEA,MAAMW,iBAAiB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACZ,cAAcC;QAEvEW,eAAe,iBAAiB,CAACC,CAAAA;YAC7B,IAAI,CAACA,UACD,MAAMC,MAAM;YAEhB,OAAON,gBAAgB,IAAIO,aAAaF,YAAY,IAAIG,YAAYH;QACxE;QAEA,OAAOD;IACX;IAEQ,UAAUN,IAAU,EAAE;QAC1B,OAAOA,KAAK,aAAa,IAAIA,KAAK,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC;IACpE;IAEQ,4BAA4BN,YAA0B,EAAE;QAC5D,OAAOA,aAAa,UAAU,GAAiB,OAAO;IAC1D;IAEQ,2BAA2BA,YAA0B,EAAE;QAC3D,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAACA;IAC7C;AACJ"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetOutputStrategy, AssetReply } from "../../../delivery/index.js";
|
|
2
|
-
export declare class PublicCache implements AssetOutputStrategy {
|
|
3
|
-
private strategy;
|
|
4
|
-
constructor(strategy: AssetOutputStrategy);
|
|
5
|
-
output(asset: Asset): Promise<AssetReply>;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/PublicCache.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/PublicCache.ts"],"sourcesContent":["import { parse, stringify } from \"cache-control-parser\";\nimport type { Asset, AssetOutputStrategy, AssetReply } from \"~/delivery/index.js\";\n\nexport class PublicCache implements AssetOutputStrategy {\n private strategy: AssetOutputStrategy;\n\n constructor(strategy: AssetOutputStrategy) {\n this.strategy = strategy;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const reply = await this.strategy.output(asset);\n\n reply.setHeaders(headers => {\n headers.set(\"cache-control\", (value = \"\") => {\n const cacheControl = parse(value);\n cacheControl[\"private\"] = false;\n cacheControl[\"public\"] = true;\n return stringify(cacheControl);\n });\n return headers;\n });\n\n return reply;\n }\n}\n"],"names":["PublicCache","strategy","asset","reply","headers","value","cacheControl","parse","stringify"],"mappings":";AAGO,MAAMA;IAGT,YAAYC,QAA6B,CAAE;QACvC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,QAAQ,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAACD;QAEzCC,MAAM,UAAU,CAACC,CAAAA;YACbA,QAAQ,GAAG,CAAC,iBAAiB,CAACC,QAAQ,EAAE;gBACpC,MAAMC,eAAeC,MAAMF;gBAC3BC,YAAY,CAAC,UAAU,GAAG;gBAC1BA,YAAY,CAAC,SAAS,GAAG;gBACzB,OAAOE,UAAUF;YACrB;YACA,OAAOF;QACX;QAEA,OAAOD;IACX;AACJ"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetOutputStrategy, AssetRequest } from "../../../delivery/index.js";
|
|
2
|
-
import { AssetReply } from "../../../delivery/index.js";
|
|
3
|
-
export declare class RedirectToPrivateUrlOutputStrategy implements AssetOutputStrategy {
|
|
4
|
-
private assetRequest;
|
|
5
|
-
constructor(assetRequest: AssetRequest);
|
|
6
|
-
output(asset: Asset): Promise<AssetReply>;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/RedirectToPrivateUrlOutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetRequest } from \"~/delivery/index.js\";\nimport { AssetReply } from \"~/delivery/index.js\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class RedirectToPrivateUrlOutputStrategy implements AssetOutputStrategy {\n private assetRequest: AssetRequest;\n\n constructor(assetRequest: AssetRequest) {\n this.assetRequest = assetRequest;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const requestUrl = this.assetRequest.getContext().url;\n\n return new AssetReply({\n code: 301,\n headers: ResponseHeaders.create({\n location: requestUrl.replace(\"/files/\", \"/private/\"),\n \"content-type\": asset.getContentType(),\n \"cache-control\": `public, max-age=${86400 * 30}`\n })\n });\n }\n}\n"],"names":["RedirectToPrivateUrlOutputStrategy","assetRequest","asset","requestUrl","AssetReply","ResponseHeaders"],"mappings":";;AAIO,MAAMA;IAGT,YAAYC,YAA0B,CAAE;QACpC,IAAI,CAAC,YAAY,GAAGA;IACxB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,aAAa,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,GAAG;QAErD,OAAO,IAAIC,WAAW;YAClB,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,UAAUF,WAAW,OAAO,CAAC,WAAW;gBACxC,gBAAgBD,MAAM,cAAc;gBACpC,iBAAiB;YACrB;QACJ;IACJ;AACJ"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetOutputStrategy, AssetRequest } from "../../../delivery/index.js";
|
|
2
|
-
import { AssetReply } from "../../../delivery/index.js";
|
|
3
|
-
export declare class RedirectToPublicUrlOutputStrategy implements AssetOutputStrategy {
|
|
4
|
-
private assetRequest;
|
|
5
|
-
constructor(assetRequest: AssetRequest);
|
|
6
|
-
output(asset: Asset): Promise<AssetReply>;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.js","sources":["../../../../src/delivery/AssetDelivery/privateFiles/RedirectToPublicUrlOutputStrategy.ts"],"sourcesContent":["import type { Asset, AssetOutputStrategy, AssetRequest } from \"~/delivery/index.js\";\nimport { AssetReply } from \"~/delivery/index.js\";\nimport { ResponseHeaders } from \"@webiny/handler\";\n\nexport class RedirectToPublicUrlOutputStrategy implements AssetOutputStrategy {\n private assetRequest: AssetRequest;\n\n constructor(assetRequest: AssetRequest) {\n this.assetRequest = assetRequest;\n }\n\n async output(asset: Asset): Promise<AssetReply> {\n const requestUrl = this.assetRequest.getContext().url;\n\n return new AssetReply({\n code: 301,\n headers: ResponseHeaders.create({\n location: requestUrl.replace(\"/private/\", \"/files/\"),\n \"content-type\": asset.getContentType(),\n \"cache-control\": `public, max-age=${86400 * 30}`\n })\n });\n }\n}\n"],"names":["RedirectToPublicUrlOutputStrategy","assetRequest","asset","requestUrl","AssetReply","ResponseHeaders"],"mappings":";;AAIO,MAAMA;IAGT,YAAYC,YAA0B,CAAE;QACpC,IAAI,CAAC,YAAY,GAAGA;IACxB;IAEA,MAAM,OAAOC,KAAY,EAAuB;QAC5C,MAAMC,aAAa,IAAI,CAAC,YAAY,CAAC,UAAU,GAAG,GAAG;QAErD,OAAO,IAAIC,WAAW;YAClB,MAAM;YACN,SAASC,gBAAgB,MAAM,CAAC;gBAC5B,UAAUF,WAAW,OAAO,CAAC,aAAa;gBAC1C,gBAAgBD,MAAM,cAAc;gBACpC,iBAAiB;YACrB;QACJ;IACJ;AACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/transformation/PassthroughAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/transformation/PassthroughAssetProcessor.ts"],"sourcesContent":["import type { Asset, AssetProcessor, AssetRequest } from \"~/delivery/index.js\";\n\nexport class PassthroughAssetProcessor implements AssetProcessor {\n process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n return Promise.resolve(asset);\n }\n}\n"],"names":["PassthroughAssetProcessor","assetRequest","asset","Promise"],"mappings":"AAEO,MAAMA;IACT,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QAC9D,OAAOC,QAAQ,OAAO,CAACD;IAC3B;AACJ"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetTransformationStrategy, AssetRequest } from "../../../delivery/index.js";
|
|
2
|
-
export declare class PassthroughAssetTransformationStrategy implements AssetTransformationStrategy {
|
|
3
|
-
transform(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
4
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.js","sources":["../../../../src/delivery/AssetDelivery/transformation/PassthroughAssetTransformationStrategy.ts"],"sourcesContent":["import type { Asset, AssetTransformationStrategy, AssetRequest } from \"~/delivery/index.js\";\n\nexport class PassthroughAssetTransformationStrategy implements AssetTransformationStrategy {\n transform(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n return Promise.resolve(asset);\n }\n}\n"],"names":["PassthroughAssetTransformationStrategy","assetRequest","asset","Promise"],"mappings":"AAEO,MAAMA;IACT,UAAUC,YAA0B,EAAEC,KAAY,EAAkB;QAChE,OAAOC,QAAQ,OAAO,CAACD;IAC3B;AACJ"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Asset, AssetProcessor, AssetRequest, AssetTransformationStrategy } from "../../../delivery/index.js";
|
|
2
|
-
export declare class TransformationAssetProcessor implements AssetProcessor {
|
|
3
|
-
private strategy;
|
|
4
|
-
constructor(strategy: AssetTransformationStrategy);
|
|
5
|
-
process(assetRequest: AssetRequest, asset: Asset): Promise<Asset>;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delivery/AssetDelivery/transformation/TransformationAssetProcessor.js","sources":["../../../../src/delivery/AssetDelivery/transformation/TransformationAssetProcessor.ts"],"sourcesContent":["import type {\n Asset,\n AssetProcessor,\n AssetRequest,\n AssetTransformationStrategy\n} from \"~/delivery/index.js\";\n\nexport class TransformationAssetProcessor implements AssetProcessor {\n private strategy: AssetTransformationStrategy;\n\n constructor(strategy: AssetTransformationStrategy) {\n this.strategy = strategy;\n }\n\n async process(assetRequest: AssetRequest, asset: Asset): Promise<Asset> {\n const { original } = assetRequest.getOptions();\n\n // If the `original` image was requested, we skip all transformations.\n if (original) {\n console.log(\"Skip transformations; original asset was requested.\");\n return asset;\n }\n\n return this.strategy.transform(assetRequest, asset);\n }\n}\n"],"names":["TransformationAssetProcessor","strategy","assetRequest","asset","original","console"],"mappings":"AAOO,MAAMA;IAGT,YAAYC,QAAqC,CAAE;QAC/C,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,YAA0B,EAAEC,KAAY,EAAkB;QACpE,MAAM,EAAEC,QAAQ,EAAE,GAAGF,aAAa,UAAU;QAG5C,IAAIE,UAAU;YACVC,QAAQ,GAAG,CAAC;YACZ,OAAOF;QACX;QAEA,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAACD,cAAcC;IACjD;AACJ"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|