@vendure/asset-server-plugin 3.1.0-next.3 → 3.1.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.
Files changed (43) hide show
  1. package/lib/index.d.ts +6 -2
  2. package/lib/index.js +6 -2
  3. package/lib/index.js.map +1 -1
  4. package/lib/src/asset-server.d.ts +50 -0
  5. package/lib/src/asset-server.js +303 -0
  6. package/lib/src/asset-server.js.map +1 -0
  7. package/lib/src/{default-asset-storage-strategy-factory.d.ts → config/default-asset-storage-strategy-factory.d.ts} +1 -1
  8. package/lib/src/{default-asset-storage-strategy-factory.js → config/default-asset-storage-strategy-factory.js} +1 -1
  9. package/lib/src/config/default-asset-storage-strategy-factory.js.map +1 -0
  10. package/lib/src/config/hashed-asset-naming-strategy.js.map +1 -0
  11. package/lib/src/config/image-transform-strategy.d.ts +58 -0
  12. package/lib/src/config/image-transform-strategy.js +3 -0
  13. package/lib/src/config/image-transform-strategy.js.map +1 -0
  14. package/lib/src/config/local-asset-storage-strategy.js.map +1 -0
  15. package/lib/src/config/preset-only-strategy.d.ts +82 -0
  16. package/lib/src/config/preset-only-strategy.js +70 -0
  17. package/lib/src/config/preset-only-strategy.js.map +1 -0
  18. package/lib/src/{s3-asset-storage-strategy.d.ts → config/s3-asset-storage-strategy.d.ts} +1 -1
  19. package/lib/src/{s3-asset-storage-strategy.js → config/s3-asset-storage-strategy.js} +2 -2
  20. package/lib/src/config/s3-asset-storage-strategy.js.map +1 -0
  21. package/lib/src/{sharp-asset-preview-strategy.js → config/sharp-asset-preview-strategy.js} +2 -2
  22. package/lib/src/config/sharp-asset-preview-strategy.js.map +1 -0
  23. package/lib/src/constants.d.ts +1 -0
  24. package/lib/src/constants.js +2 -1
  25. package/lib/src/constants.js.map +1 -1
  26. package/lib/src/plugin.d.ts +39 -31
  27. package/lib/src/plugin.js +100 -206
  28. package/lib/src/plugin.js.map +1 -1
  29. package/lib/src/transform-image.d.ts +2 -2
  30. package/lib/src/transform-image.js +9 -24
  31. package/lib/src/transform-image.js.map +1 -1
  32. package/lib/src/types.d.ts +15 -0
  33. package/package.json +4 -4
  34. package/lib/src/default-asset-storage-strategy-factory.js.map +0 -1
  35. package/lib/src/hashed-asset-naming-strategy.js.map +0 -1
  36. package/lib/src/local-asset-storage-strategy.js.map +0 -1
  37. package/lib/src/s3-asset-storage-strategy.js.map +0 -1
  38. package/lib/src/sharp-asset-preview-strategy.js.map +0 -1
  39. /package/lib/src/{hashed-asset-naming-strategy.d.ts → config/hashed-asset-naming-strategy.d.ts} +0 -0
  40. /package/lib/src/{hashed-asset-naming-strategy.js → config/hashed-asset-naming-strategy.js} +0 -0
  41. /package/lib/src/{local-asset-storage-strategy.d.ts → config/local-asset-storage-strategy.d.ts} +0 -0
  42. /package/lib/src/{local-asset-storage-strategy.js → config/local-asset-storage-strategy.js} +0 -0
  43. /package/lib/src/{sharp-asset-preview-strategy.d.ts → config/sharp-asset-preview-strategy.d.ts} +0 -0
package/lib/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  export * from './src/plugin';
2
- export * from './src/s3-asset-storage-strategy';
3
- export * from './src/sharp-asset-preview-strategy';
2
+ export * from './src/asset-server';
3
+ export * from './src/config/s3-asset-storage-strategy';
4
+ export * from './src/config/sharp-asset-preview-strategy';
5
+ export * from './src/config/image-transform-strategy';
6
+ export * from './src/config/preset-only-strategy';
7
+ export * from './src/config/hashed-asset-naming-strategy';
4
8
  export * from './src/types';
package/lib/index.js CHANGED
@@ -15,7 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./src/plugin"), exports);
18
- __exportStar(require("./src/s3-asset-storage-strategy"), exports);
19
- __exportStar(require("./src/sharp-asset-preview-strategy"), exports);
18
+ __exportStar(require("./src/asset-server"), exports);
19
+ __exportStar(require("./src/config/s3-asset-storage-strategy"), exports);
20
+ __exportStar(require("./src/config/sharp-asset-preview-strategy"), exports);
21
+ __exportStar(require("./src/config/image-transform-strategy"), exports);
22
+ __exportStar(require("./src/config/preset-only-strategy"), exports);
23
+ __exportStar(require("./src/config/hashed-asset-naming-strategy"), exports);
20
24
  __exportStar(require("./src/types"), exports);
21
25
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kEAAgD;AAChD,qEAAmD;AACnD,8CAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,qDAAmC;AACnC,yEAAuD;AACvD,4EAA0D;AAC1D,wEAAsD;AACtD,oEAAkD;AAClD,4EAA0D;AAC1D,8CAA4B"}
@@ -0,0 +1,50 @@
1
+ import { ConfigService, ProcessContext } from '@vendure/core';
2
+ import { ImageTransformStrategy } from './config/image-transform-strategy';
3
+ import { AssetServerOptions, ImageTransformPreset } from './types';
4
+ /**
5
+ * This houses the actual Express server that handles incoming requests, performs image transformations,
6
+ * caches the results, and serves the transformed images.
7
+ */
8
+ export declare class AssetServer {
9
+ private options;
10
+ private configService;
11
+ private processContext;
12
+ private readonly assetStorageStrategy;
13
+ private readonly cacheDir;
14
+ private cacheHeader;
15
+ private presets;
16
+ private imageTransformStrategies;
17
+ constructor(options: AssetServerOptions, configService: ConfigService, processContext: ProcessContext);
18
+ /** @internal */
19
+ onApplicationBootstrap(): void;
20
+ /**
21
+ * Creates the image server instance
22
+ */
23
+ createAssetServer(serverConfig: {
24
+ presets: ImageTransformPreset[];
25
+ imageTransformStrategies: ImageTransformStrategy[];
26
+ }): import("express-serve-static-core").Router;
27
+ /**
28
+ * Reads the file requested and send the response to the browser.
29
+ */
30
+ private sendAsset;
31
+ /**
32
+ * If an exception was thrown by the first handler, then it may be because a transformed image
33
+ * is being requested which does not yet exist. In this case, this handler will generate the
34
+ * transformed image, save it to cache, and serve the result as a response.
35
+ */
36
+ private generateTransformedImage;
37
+ private getImageTransformParameters;
38
+ private getInitialImageTransformParameters;
39
+ private getFileNameFromParameters;
40
+ /**
41
+ * Sanitize the file path to prevent directory traversal attacks.
42
+ */
43
+ private sanitizeFilePath;
44
+ private md5;
45
+ private addSuffix;
46
+ /**
47
+ * Attempt to get the mime type from the file name.
48
+ */
49
+ private getMimeType;
50
+ }
@@ -0,0 +1,303 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __importDefault = (this && this.__importDefault) || function (mod) {
15
+ return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AssetServer = void 0;
19
+ const common_1 = require("@nestjs/common");
20
+ const core_1 = require("@vendure/core");
21
+ const crypto_1 = require("crypto");
22
+ const express_1 = __importDefault(require("express"));
23
+ const fs_extra_1 = __importDefault(require("fs-extra"));
24
+ const path_1 = __importDefault(require("path"));
25
+ const common_2 = require("./common");
26
+ const s3_asset_storage_strategy_1 = require("./config/s3-asset-storage-strategy");
27
+ const constants_1 = require("./constants");
28
+ const transform_image_1 = require("./transform-image");
29
+ async function getFileType(buffer) {
30
+ const { fileTypeFromBuffer } = await import('file-type');
31
+ return fileTypeFromBuffer(buffer);
32
+ }
33
+ /**
34
+ * This houses the actual Express server that handles incoming requests, performs image transformations,
35
+ * caches the results, and serves the transformed images.
36
+ */
37
+ let AssetServer = class AssetServer {
38
+ constructor(options, configService, processContext) {
39
+ this.options = options;
40
+ this.configService = configService;
41
+ this.processContext = processContext;
42
+ this.cacheDir = 'cache';
43
+ this.assetStorageStrategy = this.configService.assetOptions.assetStorageStrategy;
44
+ }
45
+ /** @internal */
46
+ onApplicationBootstrap() {
47
+ if (this.processContext.isWorker) {
48
+ return;
49
+ }
50
+ // Configure Cache-Control header
51
+ const { cacheHeader } = this.options;
52
+ if (!cacheHeader) {
53
+ this.cacheHeader = constants_1.DEFAULT_CACHE_HEADER;
54
+ }
55
+ else {
56
+ if (typeof cacheHeader === 'string') {
57
+ this.cacheHeader = cacheHeader;
58
+ }
59
+ else {
60
+ this.cacheHeader = [cacheHeader.restriction, `max-age: ${cacheHeader.maxAge}`]
61
+ .filter(value => !!value)
62
+ .join(', ');
63
+ }
64
+ }
65
+ const cachePath = path_1.default.join(this.options.assetUploadDir, this.cacheDir);
66
+ fs_extra_1.default.ensureDirSync(cachePath);
67
+ }
68
+ /**
69
+ * Creates the image server instance
70
+ */
71
+ createAssetServer(serverConfig) {
72
+ this.presets = serverConfig.presets;
73
+ this.imageTransformStrategies = serverConfig.imageTransformStrategies;
74
+ const assetServer = express_1.default.Router();
75
+ assetServer.use(this.sendAsset(), this.generateTransformedImage());
76
+ return assetServer;
77
+ }
78
+ /**
79
+ * Reads the file requested and send the response to the browser.
80
+ */
81
+ sendAsset() {
82
+ return async (req, res, next) => {
83
+ var _a;
84
+ let params;
85
+ try {
86
+ params = await this.getImageTransformParameters(req);
87
+ }
88
+ catch (e) {
89
+ core_1.Logger.error(e.message, constants_1.loggerCtx);
90
+ res.status(400).send('Invalid parameters');
91
+ return;
92
+ }
93
+ const key = this.getFileNameFromParameters(req.path, params);
94
+ try {
95
+ const file = await this.assetStorageStrategy.readFileToBuffer(key);
96
+ let mimeType = this.getMimeType(key);
97
+ if (!mimeType) {
98
+ mimeType = ((_a = (await getFileType(file))) === null || _a === void 0 ? void 0 : _a.mime) || 'application/octet-stream';
99
+ }
100
+ res.contentType(mimeType);
101
+ res.setHeader('content-security-policy', "default-src 'self'");
102
+ res.setHeader('Cache-Control', this.cacheHeader);
103
+ res.send(file);
104
+ }
105
+ catch (e) {
106
+ const err = new Error('File not found');
107
+ err.status = 404;
108
+ return next(err);
109
+ }
110
+ };
111
+ }
112
+ /**
113
+ * If an exception was thrown by the first handler, then it may be because a transformed image
114
+ * is being requested which does not yet exist. In this case, this handler will generate the
115
+ * transformed image, save it to cache, and serve the result as a response.
116
+ */
117
+ generateTransformedImage() {
118
+ return async (err, req, res, next) => {
119
+ var _a;
120
+ if (err && (err.status === 404 || err.statusCode === 404)) {
121
+ if (req.query) {
122
+ const decodedReqPath = this.sanitizeFilePath(req.path);
123
+ core_1.Logger.debug(`Pre-cached Asset not found: ${decodedReqPath}`, constants_1.loggerCtx);
124
+ let file;
125
+ try {
126
+ file = await this.assetStorageStrategy.readFileToBuffer(decodedReqPath);
127
+ }
128
+ catch (_err) {
129
+ res.status(404).send('Resource not found');
130
+ return;
131
+ }
132
+ try {
133
+ const parameters = await this.getImageTransformParameters(req);
134
+ const image = await (0, transform_image_1.transformImage)(file, parameters);
135
+ const imageBuffer = await image.toBuffer();
136
+ const cachedFileName = this.getFileNameFromParameters(req.path, parameters);
137
+ if (!req.query.cache || req.query.cache === 'true') {
138
+ await this.assetStorageStrategy.writeFileFromBuffer(cachedFileName, imageBuffer);
139
+ core_1.Logger.debug(`Saved cached asset: ${cachedFileName}`, constants_1.loggerCtx);
140
+ }
141
+ let mimeType = this.getMimeType(cachedFileName);
142
+ if (!mimeType) {
143
+ mimeType = ((_a = (await getFileType(imageBuffer))) === null || _a === void 0 ? void 0 : _a.mime) || 'image/jpeg';
144
+ }
145
+ res.set('Content-Type', mimeType);
146
+ res.setHeader('content-security-policy', "default-src 'self'");
147
+ res.send(imageBuffer);
148
+ return;
149
+ }
150
+ catch (e) {
151
+ core_1.Logger.error(e.message, constants_1.loggerCtx, e.stack);
152
+ res.status(500).send('An error occurred when generating the image');
153
+ return;
154
+ }
155
+ }
156
+ }
157
+ next();
158
+ };
159
+ }
160
+ async getImageTransformParameters(req) {
161
+ let parameters = this.getInitialImageTransformParameters(req.query);
162
+ for (const strategy of this.imageTransformStrategies) {
163
+ try {
164
+ parameters = await strategy.getImageTransformParameters({
165
+ req,
166
+ input: Object.assign({}, parameters),
167
+ availablePresets: this.presets,
168
+ });
169
+ }
170
+ catch (e) {
171
+ core_1.Logger.error(`Error applying ImageTransformStrategy: ` + e.message, constants_1.loggerCtx);
172
+ throw e;
173
+ }
174
+ }
175
+ let targetWidth = parameters.width;
176
+ let targetHeight = parameters.height;
177
+ let targetMode = parameters.mode;
178
+ if (parameters.preset) {
179
+ const matchingPreset = this.presets.find(p => p.name === parameters.preset);
180
+ if (matchingPreset) {
181
+ targetWidth = matchingPreset.width;
182
+ targetHeight = matchingPreset.height;
183
+ targetMode = matchingPreset.mode;
184
+ }
185
+ }
186
+ return Object.assign(Object.assign({}, parameters), { width: targetWidth, height: targetHeight, mode: targetMode });
187
+ }
188
+ getInitialImageTransformParameters(queryParams) {
189
+ const width = Math.round(+queryParams.w) || undefined;
190
+ const height = Math.round(+queryParams.h) || undefined;
191
+ const quality = queryParams.q != null ? Math.round(Math.max(Math.min(+queryParams.q, 100), 1)) : undefined;
192
+ const mode = queryParams.mode === 'resize' ? 'resize' : 'crop';
193
+ const fpx = +queryParams.fpx || undefined;
194
+ const fpy = +queryParams.fpy || undefined;
195
+ const format = (0, common_2.getValidFormat)(queryParams.format);
196
+ return {
197
+ width,
198
+ height,
199
+ quality,
200
+ format,
201
+ mode,
202
+ fpx,
203
+ fpy,
204
+ preset: queryParams.preset,
205
+ };
206
+ }
207
+ getFileNameFromParameters(filePath, params) {
208
+ const { width: w, height: h, mode, preset, fpx, fpy, format, quality: q } = params;
209
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
210
+ const focalPoint = fpx && fpy ? `_fpx${fpx}_fpy${fpy}` : '';
211
+ const quality = q ? `_q${q}` : '';
212
+ const imageFormat = (0, common_2.getValidFormat)(format);
213
+ let imageParamsString = '';
214
+ if (w || h) {
215
+ const width = w || '';
216
+ const height = h || '';
217
+ imageParamsString = `_transform_w${width}_h${height}_m${mode}`;
218
+ }
219
+ else if (preset) {
220
+ if (this.presets && !!this.presets.find(p => p.name === preset)) {
221
+ imageParamsString = `_transform_pre_${preset}`;
222
+ }
223
+ }
224
+ if (focalPoint) {
225
+ imageParamsString += focalPoint;
226
+ }
227
+ if (imageFormat) {
228
+ imageParamsString += imageFormat;
229
+ }
230
+ if (quality) {
231
+ imageParamsString += quality;
232
+ }
233
+ const decodedReqPath = this.sanitizeFilePath(filePath);
234
+ if (imageParamsString !== '') {
235
+ const imageParamHash = this.md5(imageParamsString);
236
+ return path_1.default.join(this.cacheDir, this.addSuffix(decodedReqPath, imageParamHash, imageFormat));
237
+ }
238
+ else {
239
+ return decodedReqPath;
240
+ }
241
+ }
242
+ /**
243
+ * Sanitize the file path to prevent directory traversal attacks.
244
+ */
245
+ sanitizeFilePath(filePath) {
246
+ let decodedPath;
247
+ try {
248
+ decodedPath = decodeURIComponent(filePath);
249
+ }
250
+ catch (e) {
251
+ core_1.Logger.error(e.message + ': ' + filePath, constants_1.loggerCtx);
252
+ return '';
253
+ }
254
+ if (!(this.assetStorageStrategy instanceof s3_asset_storage_strategy_1.S3AssetStorageStrategy)) {
255
+ // For S3 storage, we don't need to sanitize the path because
256
+ // directory traversal attacks are not possible, and modifying the
257
+ // path in this way can s3 files to be not found.
258
+ return path_1.default.normalize(decodedPath).replace(/(\.\.[\/\\])+/, '');
259
+ }
260
+ else {
261
+ return decodedPath;
262
+ }
263
+ }
264
+ md5(input) {
265
+ return (0, crypto_1.createHash)('md5').update(input).digest('hex');
266
+ }
267
+ addSuffix(fileName, suffix, ext) {
268
+ const originalExt = path_1.default.extname(fileName);
269
+ const effectiveExt = ext ? `.${ext}` : originalExt;
270
+ const baseName = path_1.default.basename(fileName, originalExt);
271
+ const dirName = path_1.default.dirname(fileName);
272
+ return path_1.default.join(dirName, `${baseName}${suffix}${effectiveExt}`);
273
+ }
274
+ /**
275
+ * Attempt to get the mime type from the file name.
276
+ */
277
+ getMimeType(fileName) {
278
+ const ext = path_1.default.extname(fileName);
279
+ switch (ext) {
280
+ case '.jpg':
281
+ case '.jpeg':
282
+ return 'image/jpeg';
283
+ case '.png':
284
+ return 'image/png';
285
+ case '.gif':
286
+ return 'image/gif';
287
+ case '.svg':
288
+ return 'image/svg+xml';
289
+ case '.tiff':
290
+ return 'image/tiff';
291
+ case '.webp':
292
+ return 'image/webp';
293
+ }
294
+ }
295
+ };
296
+ exports.AssetServer = AssetServer;
297
+ exports.AssetServer = AssetServer = __decorate([
298
+ (0, common_1.Injectable)(),
299
+ __param(0, (0, common_1.Inject)(constants_1.ASSET_SERVER_PLUGIN_INIT_OPTIONS)),
300
+ __metadata("design:paramtypes", [Object, core_1.ConfigService,
301
+ core_1.ProcessContext])
302
+ ], AssetServer);
303
+ //# sourceMappingURL=asset-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-server.js","sourceRoot":"","sources":["../../src/asset-server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,wCAA4F;AAC5F,mCAAoC;AACpC,sDAAmE;AACnE,wDAA0B;AAC1B,gDAAwB;AAExB,qCAA0C;AAE1C,kFAA4E;AAC5E,2CAAgG;AAChG,uDAAmD;AAGnD,KAAK,UAAU,WAAW,CAAC,MAAc;IACrC,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IACzD,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACtC,CAA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AAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,QAAQ,GAAG,EAAE,CAAC;YACV,KAAK,MAAM,CAAC;YACZ,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;YACxB,KAAK,MAAM;gBACP,OAAO,WAAW,CAAC;YACvB,KAAK,MAAM;gBACP,OAAO,WAAW,CAAC;YACvB,KAAK,MAAM;gBACP,OAAO,eAAe,CAAC;YAC3B,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;YACxB,KAAK,OAAO;gBACR,OAAO,YAAY,CAAC;QAC5B,CAAC;IACL,CAAC;CACJ,CAAA;AAvRY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IASJ,WAAA,IAAA,eAAM,EAAC,4CAAgC,CAAC,CAAA;6CAClB,oBAAa;QACZ,qBAAc;GAVjC,WAAW,CAuRvB"}
@@ -1,5 +1,5 @@
1
+ import { AssetServerOptions } from '../types';
1
2
  import { LocalAssetStorageStrategy } from './local-asset-storage-strategy';
2
- import { AssetServerOptions } from './types';
3
3
  /**
4
4
  * By default the AssetServerPlugin will configure and use the LocalStorageStrategy to persist Assets.
5
5
  */
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultAssetStorageStrategyFactory = void 0;
4
- const common_1 = require("./common");
4
+ const common_1 = require("../common");
5
5
  const local_asset_storage_strategy_1 = require("./local-asset-storage-strategy");
6
6
  /**
7
7
  * By default the AssetServerPlugin will configure and use the LocalStorageStrategy to persist Assets.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-asset-storage-strategy-factory.js","sourceRoot":"","sources":["../../../src/config/default-asset-storage-strategy-factory.ts"],"names":[],"mappings":";;;AAEA,sCAAgD;AAGhD,iFAA2E;AAE3E;;GAEG;AACH,SAAgB,kCAAkC,CAAC,OAA2B;IAC1E,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,OAAO,CAA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AC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC;IAEO,YAAY,CAAC,QAAgB;QACjC,OAAO,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;CACJ;AAjBD,8DAiBC"}
@@ -0,0 +1,58 @@
1
+ import { InjectableStrategy } from '@vendure/core';
2
+ import { Request } from 'express';
3
+ import { ImageTransformFormat, ImageTransformMode, ImageTransformPreset } from '../types';
4
+ /**
5
+ * @description
6
+ * Parameters which are used to transform the image.
7
+ *
8
+ * @docsCategory core plugins/AssetServerPlugin
9
+ * @since 3.1.0
10
+ * @docsPage ImageTransformStrategy
11
+ */
12
+ export interface ImageTransformParameters {
13
+ width: number | undefined;
14
+ height: number | undefined;
15
+ mode: ImageTransformMode | undefined;
16
+ quality: number | undefined;
17
+ format: ImageTransformFormat | undefined;
18
+ fpx: number | undefined;
19
+ fpy: number | undefined;
20
+ preset: string | undefined;
21
+ }
22
+ /**
23
+ * @description
24
+ * The arguments passed to the `getImageTransformParameters` method of an ImageTransformStrategy.
25
+ *
26
+ * @docsCategory core plugins/AssetServerPlugin
27
+ * @since 3.1.0
28
+ * @docsPage ImageTransformStrategy
29
+ */
30
+ export interface GetImageTransformParametersArgs {
31
+ req: Request;
32
+ availablePresets: ImageTransformPreset[];
33
+ input: ImageTransformParameters;
34
+ }
35
+ /**
36
+ * @description
37
+ * An injectable strategy which is used to determine the parameters for transforming an image.
38
+ * This can be used to implement custom image transformation logic, for example to
39
+ * limit transform parameters to a known set of presets.
40
+ *
41
+ * This is set via the `imageTransformStrategy` option in the AssetServerOptions. Multiple
42
+ * strategies can be defined and will be executed in the order in which they are defined.
43
+ *
44
+ * If a strategy throws an error, the image transformation will be aborted and the error
45
+ * will be logged, with an HTTP 400 response sent to the client.
46
+ *
47
+ * @docsCategory core plugins/AssetServerPlugin
48
+ * @docsPage ImageTransformStrategy
49
+ * @docsWeight 0
50
+ * @since 3.1.0
51
+ */
52
+ export interface ImageTransformStrategy extends InjectableStrategy {
53
+ /**
54
+ * @description
55
+ * Given the input parameters, return the parameters which should be used to transform the image.
56
+ */
57
+ getImageTransformParameters(args: GetImageTransformParametersArgs): Promise<ImageTransformParameters> | ImageTransformParameters;
58
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=image-transform-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-transform-strategy.js","sourceRoot":"","sources":["../../../src/config/image-transform-strategy.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-asset-storage-strategy.js","sourceRoot":"","sources":["../../../src/config/local-asset-storage-strategy.ts"],"names":[],"mappings":";;;;;;AAIA,wDAA0B;AAC1B,gDAAwB;AAGxB;;;;;GAKG;AACH,MAAa,yBAAyB;IAGlC,YACqB,UAAkB,EAClB,eAAiE;QADjE,eAAU,GAAV,UAAU,CAAQ;QAClB,oBAAe,GAAf,eAAe,CAAkD;QAElF,kBAAE,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,IAAI,eAAe,EAAE,CAAC;YAClB,IAAI,CAAC,aAAa,GAAG,eAAe,CAAC;QACzC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,QAAgB,EAAE,IAAgB;QACxD,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QACtD,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,kBAAE,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC7D,OAAO,IAAI,OAAO,CA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oB,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxF,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,UAAU,CAAC,UAAkB;QACzB,OAAO,kBAAE,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;IAC5D,CAAC;IAEO,oBAAoB,CAAC,QAAgB;QACzC,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAClE,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QACpE,OAAO,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;IAEO,oBAAoB,CAAC,UAAkB;QAC3C,OAAO,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAClD,CAAC;CACJ;AA9DD,8DA8DC"}
@@ -0,0 +1,82 @@
1
+ import { ImageTransformFormat } from '../types';
2
+ import { GetImageTransformParametersArgs, ImageTransformParameters, ImageTransformStrategy } from './image-transform-strategy';
3
+ /**
4
+ * @description
5
+ * Configuration options for the {@link PresetOnlyStrategy}.
6
+ *
7
+ * @docsCategory core plugins/AssetServerPlugin
8
+ * @docsPage PresetOnlyStrategy
9
+ */
10
+ export interface PresetOnlyStrategyOptions {
11
+ /**
12
+ * @description
13
+ * The name of the default preset to use if no preset is specified in the URL.
14
+ */
15
+ defaultPreset: string;
16
+ /**
17
+ * @description
18
+ * The permitted quality of the transformed images. If set to 'any', then any quality is permitted.
19
+ * If set to an array of numbers (0-100), then only those quality values are permitted.
20
+ *
21
+ * @default [0, 50, 75, 85, 95]
22
+ */
23
+ permittedQuality?: number[];
24
+ /**
25
+ * @description
26
+ * The permitted formats of the transformed images. If set to 'any', then any format is permitted.
27
+ * If set to an array of strings e.g. `['jpg', 'webp']`, then only those formats are permitted.
28
+ *
29
+ * @default ['jpg', 'webp', 'avif']
30
+ */
31
+ permittedFormats?: ImageTransformFormat[];
32
+ /**
33
+ * @description
34
+ * Whether to allow the focal point to be specified in the URL.
35
+ *
36
+ * @default false
37
+ */
38
+ allowFocalPoint?: boolean;
39
+ }
40
+ /**
41
+ * @description
42
+ * An {@link ImageTransformStrategy} which only allows transformations to be made using
43
+ * presets which are defined in the available presets.
44
+ *
45
+ * With this strategy enabled, requests to the asset server must include a `preset` parameter (or use the default preset)
46
+ *
47
+ * This is valid: `http://localhost:3000/assets/some-asset.jpg?preset=medium`
48
+ *
49
+ * This is invalid: `http://localhost:3000/assets/some-asset.jpg?w=200&h=200`, and the dimensions will be ignored.
50
+ *
51
+ * The strategy can be configured to allow only certain quality values and formats, and to
52
+ * optionally allow the focal point to be specified in the URL.
53
+ *
54
+ * If a preset is not found in the available presets, an error will be thrown.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { AssetServerPlugin, PresetOnlyStrategy } from '\@vendure/core';
59
+ *
60
+ * // ...
61
+ *
62
+ * AssetServerPlugin.init({
63
+ * //...
64
+ * imageTransformStrategy: new PresetOnlyStrategy({
65
+ * defaultPreset: 'thumbnail',
66
+ * permittedQuality: [0, 50, 75, 85, 95],
67
+ * permittedFormats: ['jpg', 'webp', 'avif'],
68
+ * allowFocalPoint: true,
69
+ * }),
70
+ * });
71
+ * ```
72
+ *
73
+ * @docsCategory core plugins/AssetServerPlugin
74
+ * @docsPage PresetOnlyStrategy
75
+ * @docsWeight 0
76
+ * @since 3.1.0
77
+ */
78
+ export declare class PresetOnlyStrategy implements ImageTransformStrategy {
79
+ private options;
80
+ constructor(options: PresetOnlyStrategyOptions);
81
+ getImageTransformParameters({ input, availablePresets, }: GetImageTransformParametersArgs): Promise<ImageTransformParameters> | ImageTransformParameters;
82
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PresetOnlyStrategy = void 0;
4
+ /**
5
+ * @description
6
+ * An {@link ImageTransformStrategy} which only allows transformations to be made using
7
+ * presets which are defined in the available presets.
8
+ *
9
+ * With this strategy enabled, requests to the asset server must include a `preset` parameter (or use the default preset)
10
+ *
11
+ * This is valid: `http://localhost:3000/assets/some-asset.jpg?preset=medium`
12
+ *
13
+ * This is invalid: `http://localhost:3000/assets/some-asset.jpg?w=200&h=200`, and the dimensions will be ignored.
14
+ *
15
+ * The strategy can be configured to allow only certain quality values and formats, and to
16
+ * optionally allow the focal point to be specified in the URL.
17
+ *
18
+ * If a preset is not found in the available presets, an error will be thrown.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { AssetServerPlugin, PresetOnlyStrategy } from '\@vendure/core';
23
+ *
24
+ * // ...
25
+ *
26
+ * AssetServerPlugin.init({
27
+ * //...
28
+ * imageTransformStrategy: new PresetOnlyStrategy({
29
+ * defaultPreset: 'thumbnail',
30
+ * permittedQuality: [0, 50, 75, 85, 95],
31
+ * permittedFormats: ['jpg', 'webp', 'avif'],
32
+ * allowFocalPoint: true,
33
+ * }),
34
+ * });
35
+ * ```
36
+ *
37
+ * @docsCategory core plugins/AssetServerPlugin
38
+ * @docsPage PresetOnlyStrategy
39
+ * @docsWeight 0
40
+ * @since 3.1.0
41
+ */
42
+ class PresetOnlyStrategy {
43
+ constructor(options) {
44
+ this.options = options;
45
+ }
46
+ getImageTransformParameters({ input, availablePresets, }) {
47
+ var _a, _b, _c;
48
+ const presetName = (_a = input.preset) !== null && _a !== void 0 ? _a : this.options.defaultPreset;
49
+ const matchingPreset = availablePresets.find(p => p.name === presetName);
50
+ if (!matchingPreset) {
51
+ throw new Error(`Preset "${presetName}" not found`);
52
+ }
53
+ const permittedQuality = (_b = this.options.permittedQuality) !== null && _b !== void 0 ? _b : [0, 50, 75, 85, 95];
54
+ const permittedFormats = (_c = this.options.permittedFormats) !== null && _c !== void 0 ? _c : ['jpg', 'webp', 'avif'];
55
+ const quality = input.quality && permittedQuality.includes(input.quality) ? input.quality : undefined;
56
+ const format = input.format && permittedFormats.includes(input.format) ? input.format : undefined;
57
+ return {
58
+ width: matchingPreset.width,
59
+ height: matchingPreset.height,
60
+ mode: matchingPreset.mode,
61
+ quality,
62
+ format,
63
+ fpx: this.options.allowFocalPoint ? input.fpx : undefined,
64
+ fpy: this.options.allowFocalPoint ? input.fpy : undefined,
65
+ preset: input.preset,
66
+ };
67
+ }
68
+ }
69
+ exports.PresetOnlyStrategy = PresetOnlyStrategy;
70
+ //# sourceMappingURL=preset-only-strategy.js.map