@vendure/asset-server-plugin 2.0.0-next.8 → 2.0.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/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
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,kEAAgD;AAChD,qEAAmD;AACnD,8CAA4B"}
@@ -1,3 +1,4 @@
1
1
  import { Request } from 'express';
2
- import { AssetServerOptions } from './types';
2
+ import { AssetServerOptions, ImageTransformFormat } from './types';
3
3
  export declare function getAssetUrlPrefixFn(options: AssetServerOptions): ((request: Request, identifier: string) => string) | ((...args: any[]) => string);
4
+ export declare function getValidFormat(format?: unknown): ImageTransformFormat | undefined;
package/lib/src/common.js CHANGED
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAssetUrlPrefixFn = void 0;
3
+ exports.getValidFormat = exports.getAssetUrlPrefixFn = void 0;
4
4
  const constants_1 = require("@vendure/core/dist/common/constants");
5
5
  function getAssetUrlPrefixFn(options) {
6
6
  const { assetUrlPrefix, route } = options;
7
7
  if (assetUrlPrefix == null) {
8
- return (request, identifier) => `${request.protocol}://${request.get('host')}/${route}/`;
8
+ return (request, identifier) => {
9
+ var _a, _b;
10
+ const protocol = (_a = request.headers['x-forwarded-proto']) !== null && _a !== void 0 ? _a : request.protocol;
11
+ return `${Array.isArray(protocol) ? protocol[0] : protocol}://${(_b = request.get('host')) !== null && _b !== void 0 ? _b : 'could-not-determine-host'}/${route}/`;
12
+ };
9
13
  }
10
14
  if (typeof assetUrlPrefix === 'string') {
11
15
  return (...args) => assetUrlPrefix;
@@ -19,4 +23,20 @@ function getAssetUrlPrefixFn(options) {
19
23
  throw new Error(`The assetUrlPrefix option was of an unexpected type: ${JSON.stringify(assetUrlPrefix)}`);
20
24
  }
21
25
  exports.getAssetUrlPrefixFn = getAssetUrlPrefixFn;
26
+ function getValidFormat(format) {
27
+ if (typeof format !== 'string') {
28
+ return undefined;
29
+ }
30
+ switch (format) {
31
+ case 'jpg':
32
+ case 'jpeg':
33
+ case 'png':
34
+ case 'webp':
35
+ case 'avif':
36
+ return format;
37
+ default:
38
+ return undefined;
39
+ }
40
+ }
41
+ exports.getValidFormat = getValidFormat;
22
42
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":";;;AAAA,mEAA0E;AAK1E,SAAgB,mBAAmB,CAAC,OAA2B;IAC3D,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1C,IAAI,cAAc,IAAI,IAAI,EAAE;QACxB,OAAO,CAAC,OAAgB,EAAE,UAAkB,EAAE,EAAE,CAC5C,GAAG,OAAO,CAAC,QAAQ,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,CAAC;KAChE;IACD,IAAI,OAAO,cAAc,KAAK,QAAQ,EAA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,MAAM,GAAG,GAAI,OAAe,CAAC,+BAAmB,CAAC,CAAC;YAClD,OAAO,cAAc,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC3C,CAAC,CAAC;KACL;IACD,MAAM,IAAI,KAAK,CAAC,wDAAwD,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;AAC9G,CAAC;AApBD,kDAoBC;AAED,SAAgB,cAAc,CAAC,MAAgB;IAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC5B,OAAO,SAAS,CAAC;KACpB;IACD,QAAQ,MAAM,EAAE;QACZ,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,KAAK,CAAC;QACX,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACP,OAAO,MAAM,CAAC;QAClB;YACI,OAAO,SAAS,CAAC;KACxB;AACL,CAAC;AAdD,wCAcC"}
@@ -1 +1,2 @@
1
1
  export declare const loggerCtx = "AssetServerPlugin";
2
+ export declare const DEFAULT_CACHE_HEADER = "public, max-age=15552000";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loggerCtx = void 0;
3
+ exports.DEFAULT_CACHE_HEADER = exports.loggerCtx = void 0;
4
4
  exports.loggerCtx = 'AssetServerPlugin';
5
+ exports.DEFAULT_CACHE_HEADER = 'public, max-age=15552000';
5
6
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,mBAAmB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,mBAAmB,CAAC;AAChC,QAAA,oBAAoB,GAAG,0BAA0B,CAAC"}
@@ -12,7 +12,7 @@ import { DefaultAssetNamingStrategy, RequestContext } from '@vendure/core';
12
12
  * With this strategy, even with 200,000 total assets stored, each directory would
13
13
  * only contain less than 800 files.
14
14
  *
15
- * @docsCategory AssetServerPlugin
15
+ * @docsCategory core plugins/AssetServerPlugin
16
16
  */
17
17
  export declare class HashedAssetNamingStrategy extends DefaultAssetNamingStrategy {
18
18
  generateSourceFileName(ctx: RequestContext, originalFileName: string, conflictFileName?: string): string;
@@ -20,7 +20,7 @@ const path_1 = __importDefault(require("path"));
20
20
  * With this strategy, even with 200,000 total assets stored, each directory would
21
21
  * only contain less than 800 files.
22
22
  *
23
- * @docsCategory AssetServerPlugin
23
+ * @docsCategory core plugins/AssetServerPlugin
24
24
  */
25
25
  class HashedAssetNamingStrategy extends core_1.DefaultAssetNamingStrategy {
26
26
  generateSourceFileName(ctx, originalFileName, conflictFileName) {
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { AssetStorageStrategy } from '@vendure/core';
3
5
  import { Request } from 'express';
4
6
  import { ReadStream } from 'fs';
@@ -7,7 +9,7 @@ import { Stream } from 'stream';
7
9
  * @description
8
10
  * A persistence strategy which saves files to the local file system.
9
11
  *
10
- * @docsCategory AssetServerPlugin
12
+ * @docsCategory core plugins/AssetServerPlugin
11
13
  */
12
14
  export declare class LocalAssetStorageStrategy implements AssetStorageStrategy {
13
15
  private readonly uploadPath;
@@ -10,7 +10,7 @@ const path_1 = __importDefault(require("path"));
10
10
  * @description
11
11
  * A persistence strategy which saves files to the local file system.
12
12
  *
13
- * @docsCategory AssetServerPlugin
13
+ * @docsCategory core plugins/AssetServerPlugin
14
14
  */
15
15
  class LocalAssetStorageStrategy {
16
16
  constructor(uploadPath, toAbsoluteUrlFn) {
@@ -59,6 +59,22 @@ import { AssetServerOptions } from './types';
59
59
  *
60
60
  * `http://localhost:3000/assets/landscape.jpg?w=150&h=150&mode=crop&fpx=0.2&fpy=0.7`
61
61
  *
62
+ * ### Format
63
+ *
64
+ * Since v1.7.0, the image format can be specified by adding the `format` query parameter:
65
+ *
66
+ * `http://localhost:3000/assets/some-asset.jpg?format=webp`
67
+ *
68
+ * This means that, no matter the format of your original asset files, you can use more modern formats in your storefront if the browser
69
+ * supports them. Supported values for `format` are:
70
+ *
71
+ * * `jpeg` or `jpg`
72
+ * * `png`
73
+ * * `webp`
74
+ * * `avif`
75
+ *
76
+ * The `format` parameter can also be combined with presets (see below).
77
+ *
62
78
  * ### Transform presets
63
79
  *
64
80
  * Presets can be defined which allow a single preset name to be used instead of specifying the width, height and mode. Presets are
@@ -97,7 +113,7 @@ import { AssetServerOptions } from './types';
97
113
  * By default, the AssetServerPlugin will cache every transformed image, so that the transformation only needs to be performed a single time for
98
114
  * a given configuration. Caching can be disabled per-request by setting the `?cache=false` query parameter.
99
115
  *
100
- * @docsCategory AssetServerPlugin
116
+ * @docsCategory core plugins/AssetServerPlugin
101
117
  */
102
118
  export declare class AssetServerPlugin implements NestModule, OnApplicationBootstrap {
103
119
  private processContext;
@@ -105,6 +121,7 @@ export declare class AssetServerPlugin implements NestModule, OnApplicationBoots
105
121
  private readonly cacheDir;
106
122
  private presets;
107
123
  private static options;
124
+ private cacheHeader;
108
125
  /**
109
126
  * @description
110
127
  * Set the plugin options.
package/lib/src/plugin.js CHANGED
@@ -20,6 +20,7 @@ const express_1 = __importDefault(require("express"));
20
20
  const file_type_1 = require("file-type");
21
21
  const fs_extra_1 = __importDefault(require("fs-extra"));
22
22
  const path_1 = __importDefault(require("path"));
23
+ const common_1 = require("./common");
23
24
  const constants_1 = require("./constants");
24
25
  const default_asset_storage_strategy_factory_1 = require("./default-asset-storage-strategy-factory");
25
26
  const hashed_asset_naming_strategy_1 = require("./hashed-asset-naming-strategy");
@@ -82,6 +83,22 @@ const transform_image_1 = require("./transform-image");
82
83
  *
83
84
  * `http://localhost:3000/assets/landscape.jpg?w=150&h=150&mode=crop&fpx=0.2&fpy=0.7`
84
85
  *
86
+ * ### Format
87
+ *
88
+ * Since v1.7.0, the image format can be specified by adding the `format` query parameter:
89
+ *
90
+ * `http://localhost:3000/assets/some-asset.jpg?format=webp`
91
+ *
92
+ * This means that, no matter the format of your original asset files, you can use more modern formats in your storefront if the browser
93
+ * supports them. Supported values for `format` are:
94
+ *
95
+ * * `jpeg` or `jpg`
96
+ * * `png`
97
+ * * `webp`
98
+ * * `avif`
99
+ *
100
+ * The `format` parameter can also be combined with presets (see below).
101
+ *
85
102
  * ### Transform presets
86
103
  *
87
104
  * Presets can be defined which allow a single preset name to be used instead of specifying the width, height and mode. Presets are
@@ -120,20 +137,9 @@ const transform_image_1 = require("./transform-image");
120
137
  * By default, the AssetServerPlugin will cache every transformed image, so that the transformation only needs to be performed a single time for
121
138
  * a given configuration. Caching can be disabled per-request by setting the `?cache=false` query parameter.
122
139
  *
123
- * @docsCategory AssetServerPlugin
140
+ * @docsCategory core plugins/AssetServerPlugin
124
141
  */
125
142
  let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
126
- constructor(processContext) {
127
- this.processContext = processContext;
128
- this.cacheDir = 'cache';
129
- this.presets = [
130
- { name: 'tiny', width: 50, height: 50, mode: 'crop' },
131
- { name: 'thumb', width: 150, height: 150, mode: 'crop' },
132
- { name: 'small', width: 300, height: 300, mode: 'resize' },
133
- { name: 'medium', width: 500, height: 500, mode: 'resize' },
134
- { name: 'large', width: 800, height: 800, mode: 'resize' },
135
- ];
136
- }
137
143
  /**
138
144
  * @description
139
145
  * Set the plugin options.
@@ -144,17 +150,30 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
144
150
  }
145
151
  /** @internal */
146
152
  static async configure(config) {
153
+ var _a;
147
154
  const storageStrategyFactory = this.options.storageStrategyFactory || default_asset_storage_strategy_factory_1.defaultAssetStorageStrategyFactory;
148
155
  this.assetStorage = await storageStrategyFactory(this.options);
149
- config.assetOptions.assetPreviewStrategy = new sharp_asset_preview_strategy_1.SharpAssetPreviewStrategy({
150
- maxWidth: this.options.previewMaxWidth || 1600,
151
- maxHeight: this.options.previewMaxHeight || 1600,
152
- });
156
+ config.assetOptions.assetPreviewStrategy =
157
+ (_a = this.options.previewStrategy) !== null && _a !== void 0 ? _a : new sharp_asset_preview_strategy_1.SharpAssetPreviewStrategy({
158
+ maxWidth: this.options.previewMaxWidth,
159
+ maxHeight: this.options.previewMaxHeight,
160
+ });
153
161
  config.assetOptions.assetStorageStrategy = this.assetStorage;
154
162
  config.assetOptions.assetNamingStrategy =
155
163
  this.options.namingStrategy || new hashed_asset_naming_strategy_1.HashedAssetNamingStrategy();
156
164
  return config;
157
165
  }
166
+ constructor(processContext) {
167
+ this.processContext = processContext;
168
+ this.cacheDir = 'cache';
169
+ this.presets = [
170
+ { name: 'tiny', width: 50, height: 50, mode: 'crop' },
171
+ { name: 'thumb', width: 150, height: 150, mode: 'crop' },
172
+ { name: 'small', width: 300, height: 300, mode: 'resize' },
173
+ { name: 'medium', width: 500, height: 500, mode: 'resize' },
174
+ { name: 'large', width: 800, height: 800, mode: 'resize' },
175
+ ];
176
+ }
158
177
  /** @internal */
159
178
  onApplicationBootstrap() {
160
179
  if (this.processContext.isWorker) {
@@ -171,6 +190,21 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
171
190
  }
172
191
  }
173
192
  }
193
+ // Configure Cache-Control header
194
+ const { cacheHeader } = AssetServerPlugin_1.options;
195
+ if (!cacheHeader) {
196
+ this.cacheHeader = constants_1.DEFAULT_CACHE_HEADER;
197
+ }
198
+ else {
199
+ if (typeof cacheHeader === 'string') {
200
+ this.cacheHeader = cacheHeader;
201
+ }
202
+ else {
203
+ this.cacheHeader = [cacheHeader.restriction, `max-age: ${cacheHeader.maxAge}`]
204
+ .filter(value => !!value)
205
+ .join(', ');
206
+ }
207
+ }
174
208
  const cachePath = path_1.default.join(AssetServerPlugin_1.options.assetUploadDir, this.cacheDir);
175
209
  fs_extra_1.default.ensureDirSync(cachePath);
176
210
  }
@@ -204,7 +238,8 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
204
238
  mimeType = ((_a = (await (0, file_type_1.fromBuffer)(file))) === null || _a === void 0 ? void 0 : _a.mime) || 'application/octet-stream';
205
239
  }
206
240
  res.contentType(mimeType);
207
- res.setHeader('content-security-policy', `default-src 'self'`);
241
+ res.setHeader('content-security-policy', "default-src 'self'");
242
+ res.setHeader('Cache-Control', this.cacheHeader);
208
243
  res.send(file);
209
244
  }
210
245
  catch (e) {
@@ -221,6 +256,7 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
221
256
  */
222
257
  generateTransformedImage() {
223
258
  return async (err, req, res, next) => {
259
+ var _a;
224
260
  if (err && (err.status === 404 || err.statusCode === 404)) {
225
261
  if (req.query) {
226
262
  const decodedReqPath = decodeURIComponent(req.path);
@@ -229,20 +265,24 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
229
265
  try {
230
266
  file = await AssetServerPlugin_1.assetStorage.readFileToBuffer(decodedReqPath);
231
267
  }
232
- catch (err) {
268
+ catch (_err) {
233
269
  res.status(404).send('Resource not found');
234
270
  return;
235
271
  }
236
272
  const image = await (0, transform_image_1.transformImage)(file, req.query, this.presets || []);
237
273
  try {
238
274
  const imageBuffer = await image.toBuffer();
275
+ const cachedFileName = this.getFileNameFromRequest(req);
239
276
  if (!req.query.cache || req.query.cache === 'true') {
240
- const cachedFileName = this.getFileNameFromRequest(req);
241
277
  await AssetServerPlugin_1.assetStorage.writeFileFromBuffer(cachedFileName, imageBuffer);
242
278
  core_1.Logger.debug(`Saved cached asset: ${cachedFileName}`, constants_1.loggerCtx);
243
279
  }
244
- res.set('Content-Type', `image/${(await image.metadata()).format}`);
245
- res.setHeader('content-security-policy', `default-src 'self'`);
280
+ let mimeType = this.getMimeType(cachedFileName);
281
+ if (!mimeType) {
282
+ mimeType = ((_a = (await (0, file_type_1.fromBuffer)(imageBuffer))) === null || _a === void 0 ? void 0 : _a.mime) || 'image/jpeg';
283
+ }
284
+ res.set('Content-Type', mimeType);
285
+ res.setHeader('content-security-policy', "default-src 'self'");
246
286
  res.send(imageBuffer);
247
287
  return;
248
288
  }
@@ -257,22 +297,28 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
257
297
  };
258
298
  }
259
299
  getFileNameFromRequest(req) {
260
- const { w, h, mode, preset, fpx, fpy } = req.query;
300
+ const { w, h, mode, preset, fpx, fpy, format } = req.query;
301
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
261
302
  const focalPoint = fpx && fpy ? `_fpx${fpx}_fpy${fpy}` : '';
303
+ const imageFormat = (0, common_1.getValidFormat)(format);
262
304
  let imageParamHash = null;
263
305
  if (w || h) {
264
306
  const width = w || '';
265
307
  const height = h || '';
266
- imageParamHash = this.md5(`_transform_w${width}_h${height}_m${mode}${focalPoint}`);
308
+ imageParamHash = this.md5(`_transform_w${width}_h${height}_m${mode}${focalPoint}${imageFormat}`);
267
309
  }
268
310
  else if (preset) {
269
311
  if (this.presets && !!this.presets.find(p => p.name === preset)) {
270
- imageParamHash = this.md5(`_transform_pre_${preset}${focalPoint}`);
312
+ imageParamHash = this.md5(`_transform_pre_${preset}${focalPoint}${imageFormat}`);
271
313
  }
272
314
  }
315
+ else if (imageFormat) {
316
+ imageParamHash = this.md5(`_transform_${imageFormat}`);
317
+ }
318
+ /* eslint-enable @typescript-eslint/restrict-template-expressions */
273
319
  const decodedReqPath = decodeURIComponent(req.path);
274
320
  if (imageParamHash) {
275
- return path_1.default.join(this.cacheDir, this.addSuffix(decodedReqPath, imageParamHash));
321
+ return path_1.default.join(this.cacheDir, this.addSuffix(decodedReqPath, imageParamHash, imageFormat));
276
322
  }
277
323
  else {
278
324
  return decodedReqPath;
@@ -281,11 +327,12 @@ let AssetServerPlugin = AssetServerPlugin_1 = class AssetServerPlugin {
281
327
  md5(input) {
282
328
  return (0, crypto_1.createHash)('md5').update(input).digest('hex');
283
329
  }
284
- addSuffix(fileName, suffix) {
285
- const ext = path_1.default.extname(fileName);
286
- const baseName = path_1.default.basename(fileName, ext);
330
+ addSuffix(fileName, suffix, ext) {
331
+ const originalExt = path_1.default.extname(fileName);
332
+ const effectiveExt = ext ? `.${ext}` : originalExt;
333
+ const baseName = path_1.default.basename(fileName, originalExt);
287
334
  const dirName = path_1.default.dirname(fileName);
288
- return path_1.default.join(dirName, `${baseName}${suffix}${ext}`);
335
+ return path_1.default.join(dirName, `${baseName}${suffix}${effectiveExt}`);
289
336
  }
290
337
  /**
291
338
  * Attempt to get the mime type from the file name.
@@ -313,6 +360,7 @@ AssetServerPlugin = AssetServerPlugin_1 = __decorate([
313
360
  (0, core_1.VendurePlugin)({
314
361
  imports: [core_1.PluginCommonModule],
315
362
  configuration: config => AssetServerPlugin_1.configure(config),
363
+ compatibility: '^2.0.0',
316
364
  }),
317
365
  __metadata("design:paramtypes", [core_1.ProcessContext])
318
366
  ], AssetServerPlugin);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,wCAQuB;AACvB,mCAAoC;AACpC,sDAAmE;AACnE,yCAAuC;AACvC,wDAA0B;AAC1B,gDAAwB;AAExB,2CAAwC;AACxC,qGAA8F;AAC9F,iFAA2E;AAC3E,iFAA2E;AAC3E,uDAAmD;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgGG;AAKH,IAAa,iBAAiB,yBAA9B,MAAa,iBAAiB;IAoC1B,YAAoB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;QAlCjC,aAAQ,GAAG,OAAO,CAAC;QAC5B,YAAO,GAA2B;YACtC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACrD,EAAE,IAAI,EAAE,OAAO,EAA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C;IAED;;OAEG;IACK,WAAW,CAAC,QAAgB;QAChC,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,QAAQ,GAAG,EAAE;YACT,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;SAC3B;IACL,CAAC;CACJ,CAAA;AAjOY,iBAAiB;IAL7B,IAAA,oBAAa,EAAC;QACX,OAAO,EAAE,CAAC,yBAAkB,CAAC;QAC7B,aAAa,EAAE,MAAM,CAAC,EAAE,CAAC,mBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC;QAC5D,aAAa,EAAE,QAAQ;KAC1B,CAAC;qCAwCsC,qBAAc;GAvCzC,iBAAiB,CAiO7B;AAjOY,8CAAiB"}
@@ -1,31 +1,26 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@aws-sdk/types';
2
4
  import { AssetStorageStrategy } from '@vendure/core';
3
5
  import { Request } from 'express';
4
- import { Stream } from 'stream';
6
+ import { Readable } from 'node:stream';
5
7
  import { AssetServerOptions } from './types';
6
- export declare type S3Credentials = {
7
- accessKeyId: string;
8
- secretAccessKey: string;
9
- };
10
- export declare type S3CredentialsProfile = {
11
- profile: string;
12
- };
13
8
  /**
14
9
  * @description
15
10
  * Configuration for connecting to AWS S3.
16
11
  *
17
- * @docsCategory asset-server-plugin
12
+ * @docsCategory core plugins/AssetServerPlugin
18
13
  * @docsPage S3AssetStorageStrategy
19
14
  */
20
15
  export interface S3Config {
21
16
  /**
22
17
  * @description
23
- * The credentials used to access your s3 account. You can supply either the access key ID & secret,
24
- * or you can make use of a
18
+ * The credentials used to access your s3 account. You can supply either the access key ID & secret, or you can make use of a
25
19
  * [shared credentials file](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.html)
26
- * and supply the profile name (e.g. `'default'`).
20
+ * To use a shared credentials file, import the `fromIni()` function from the "@aws-sdk/credential-provider-ini" or "@aws-sdk/credential-providers" package and supply
21
+ * the profile name (e.g. `{ profile: 'default' }`) as its argument.
27
22
  */
28
- credentials?: S3Credentials | S3CredentialsProfile;
23
+ credentials: AwsCredentialIdentity | AwsCredentialIdentityProvider;
29
24
  /**
30
25
  * @description
31
26
  * The S3 bucket in which to store the assets. If it does not exist, it will be created on startup.
@@ -51,16 +46,17 @@ export interface S3Config {
51
46
  * Returns a configured instance of the {@link S3AssetStorageStrategy} which can then be passed to the {@link AssetServerOptions}
52
47
  * `storageStrategyFactory` property.
53
48
  *
54
- * Before using this strategy, make sure you have the `aws-sdk` package installed:
49
+ * Before using this strategy, make sure you have the `@aws-sdk/client-s3` and `@aws-sdk/lib-storage` package installed:
55
50
  *
56
51
  * ```sh
57
- * npm install aws-sdk
52
+ * npm install @aws-sdk/client-s3 @aws-sdk/lib-storage
58
53
  * ```
59
54
  *
60
55
  * @example
61
56
  * ```TypeScript
62
57
  * import { AssetServerPlugin, configureS3AssetStorage } from '\@vendure/asset-server-plugin';
63
58
  * import { DefaultAssetNamingStrategy } from '\@vendure/core';
59
+ * import { fromEnv } from '\@aws-sdk/credential-providers';
64
60
  *
65
61
  * // ...
66
62
  *
@@ -68,14 +64,10 @@ export interface S3Config {
68
64
  * AssetServerPlugin.init({
69
65
  * route: 'assets',
70
66
  * assetUploadDir: path.join(__dirname, 'assets'),
71
- * port: 5002,
72
67
  * namingStrategy: new DefaultAssetNamingStrategy(),
73
68
  * storageStrategyFactory: configureS3AssetStorage({
74
69
  * bucket: 'my-s3-bucket',
75
- * credentials: {
76
- * accessKeyId: process.env.AWS_ACCESS_KEY_ID,
77
- * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
78
- * },
70
+ * credentials: fromEnv(), // or any other credential provider
79
71
  * }),
80
72
  * }),
81
73
  * ```
@@ -95,7 +87,6 @@ export interface S3Config {
95
87
  * AssetServerPlugin.init({
96
88
  * route: 'assets',
97
89
  * assetUploadDir: path.join(__dirname, 'assets'),
98
- * port: 5002,
99
90
  * namingStrategy: new DefaultAssetNamingStrategy(),
100
91
  * storageStrategyFactory: configureS3AssetStorage({
101
92
  * bucket: 'my-minio-bucket',
@@ -105,13 +96,13 @@ export interface S3Config {
105
96
  * },
106
97
  * nativeS3Configuration: {
107
98
  * endpoint: process.env.MINIO_ENDPOINT ?? 'http://localhost:9000',
108
- * s3ForcePathStyle: true,
99
+ * forcePathStyle: true,
109
100
  * signatureVersion: 'v4',
110
101
  * },
111
102
  * }),
112
103
  * }),
113
104
  * ```
114
- * @docsCategory asset-server-plugin
105
+ * @docsCategory core plugins/AssetServerPlugin
115
106
  * @docsPage S3AssetStorageStrategy
116
107
  */
117
108
  export declare function configureS3AssetStorage(s3Config: S3Config): (options: AssetServerOptions) => S3AssetStorageStrategy;
@@ -119,12 +110,12 @@ export declare function configureS3AssetStorage(s3Config: S3Config): (options: A
119
110
  * @description
120
111
  * An {@link AssetStorageStrategy} which uses [Amazon S3](https://aws.amazon.com/s3/) object storage service.
121
112
  * To us this strategy you must first have access to an AWS account.
122
- * See their [getting started guide](https://aws.amazon.com/s3/getting-started/?nc=sn&loc=5) for how to get set up.
113
+ * See their [getting started guide](https://aws.amazon.com/s3/getting-started/) for how to get set up.
123
114
  *
124
- * Before using this strategy, make sure you have the `aws-sdk` package installed:
115
+ * Before using this strategy, make sure you have the `@aws-sdk/client-s3` and `@aws-sdk/lib-storage` package installed:
125
116
  *
126
117
  * ```sh
127
- * npm install aws-sdk
118
+ * npm install @aws-sdk/client-s3 @aws-sdk/lib-storage
128
119
  * ```
129
120
  *
130
121
  * **Note:** Rather than instantiating this manually, use the {@link configureS3AssetStorage} function.
@@ -141,18 +132,21 @@ export declare class S3AssetStorageStrategy implements AssetStorageStrategy {
141
132
  private s3Config;
142
133
  readonly toAbsoluteUrl: (request: Request, identifier: string) => string;
143
134
  private AWS;
144
- private s3;
135
+ private libStorage;
136
+ private s3Client;
145
137
  constructor(s3Config: S3Config, toAbsoluteUrl: (request: Request, identifier: string) => string);
146
138
  init(): Promise<void>;
147
139
  destroy?: (() => void | Promise<void>) | undefined;
148
140
  writeFileFromBuffer(fileName: string, data: Buffer): Promise<string>;
149
- writeFileFromStream(fileName: string, data: Stream): Promise<string>;
141
+ writeFileFromStream(fileName: string, data: Readable): Promise<string>;
150
142
  readFileToBuffer(identifier: string): Promise<Buffer>;
151
- readFileToStream(identifier: string): Promise<Stream>;
143
+ readFileToStream(identifier: string): Promise<Readable>;
144
+ private readFile;
145
+ private writeFile;
152
146
  deleteFile(identifier: string): Promise<void>;
153
147
  fileExists(fileName: string): Promise<boolean>;
154
148
  private getObjectParams;
155
- private getS3Credentials;
156
149
  private ensureBucket;
150
+ private getCredentials;
157
151
  private isCredentialsProfile;
158
152
  }