@vendure/core 3.7.4-master-202610050222 → 3.7.4

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 (40) hide show
  1. package/dist/config/catalog/default-stock-location-strategy.d.ts +57 -2
  2. package/dist/config/catalog/default-stock-location-strategy.js +101 -5
  3. package/dist/config/catalog/default-stock-location-strategy.js.map +1 -1
  4. package/dist/config/catalog/multi-channel-stock-location-strategy.d.ts +0 -5
  5. package/dist/config/catalog/multi-channel-stock-location-strategy.js +13 -27
  6. package/dist/config/catalog/multi-channel-stock-location-strategy.js.map +1 -1
  7. package/dist/config/order/default-order-process.js +13 -1
  8. package/dist/config/order/default-order-process.js.map +1 -1
  9. package/dist/config/order/stock-allocation-strategy.d.ts +4 -0
  10. package/dist/entity/order-line/order-line.entity.d.ts +3 -29
  11. package/dist/entity/order-line/order-line.entity.js +20 -66
  12. package/dist/entity/order-line/order-line.entity.js.map +1 -1
  13. package/dist/event-bus/events/stock-shortfall-event.d.ts +40 -0
  14. package/dist/event-bus/events/stock-shortfall-event.js +29 -0
  15. package/dist/event-bus/events/stock-shortfall-event.js.map +1 -0
  16. package/dist/event-bus/index.d.ts +1 -0
  17. package/dist/event-bus/index.js +1 -0
  18. package/dist/event-bus/index.js.map +1 -1
  19. package/dist/migration-utils/index.d.ts +0 -1
  20. package/dist/migration-utils/index.js +1 -3
  21. package/dist/migration-utils/index.js.map +1 -1
  22. package/dist/service/helpers/order-modifier/order-modifier.d.ts +15 -2
  23. package/dist/service/helpers/order-modifier/order-modifier.js +37 -12
  24. package/dist/service/helpers/order-modifier/order-modifier.js.map +1 -1
  25. package/dist/service/helpers/utils/stock-lock-order.d.ts +11 -0
  26. package/dist/service/helpers/utils/stock-lock-order.js +22 -0
  27. package/dist/service/helpers/utils/stock-lock-order.js.map +1 -0
  28. package/dist/service/services/product-variant.service.d.ts +9 -2
  29. package/dist/service/services/product-variant.service.js +18 -2
  30. package/dist/service/services/product-variant.service.js.map +1 -1
  31. package/dist/service/services/stock-level.service.d.ts +124 -2
  32. package/dist/service/services/stock-level.service.js +181 -12
  33. package/dist/service/services/stock-level.service.js.map +1 -1
  34. package/dist/service/services/stock-movement.service.d.ts +9 -0
  35. package/dist/service/services/stock-movement.service.js +143 -50
  36. package/dist/service/services/stock-movement.service.js.map +1 -1
  37. package/package.json +2 -2
  38. package/dist/migration-utils/v3_8_orderline_promotion_rescale.d.ts +0 -57
  39. package/dist/migration-utils/v3_8_orderline_promotion_rescale.js +0 -232
  40. package/dist/migration-utils/v3_8_orderline_promotion_rescale.js.map +0 -1
@@ -14,14 +14,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.StockLevelService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
+ const generated_types_1 = require("@vendure/common/lib/generated-types");
18
+ const unique_1 = require("@vendure/common/lib/unique");
17
19
  const dataloader_1 = __importDefault(require("dataloader"));
18
20
  const typeorm_1 = require("typeorm");
19
21
  const request_context_cache_service_1 = require("../../cache/request-context-cache.service");
20
22
  const instrument_decorator_1 = require("../../common/instrument-decorator");
21
23
  const config_service_1 = require("../../config/config.service");
24
+ const vendure_logger_1 = require("../../config/logger/vendure-logger");
22
25
  const transactional_connection_1 = require("../../connection/transactional-connection");
26
+ const product_variant_entity_1 = require("../../entity/product-variant/product-variant.entity");
23
27
  const stock_level_entity_1 = require("../../entity/stock-level/stock-level.entity");
28
+ const stock_lock_order_1 = require("../helpers/utils/stock-lock-order");
29
+ const global_settings_service_1 = require("./global-settings.service");
24
30
  const stock_location_service_1 = require("./stock-location.service");
31
+ const loggerCtx = 'StockLevelService';
25
32
  /**
26
33
  * @description
27
34
  * The StockLevelService is responsible for managing the stock levels of ProductVariants.
@@ -32,11 +39,14 @@ const stock_location_service_1 = require("./stock-location.service");
32
39
  * @since 2.0.0
33
40
  */
34
41
  let StockLevelService = class StockLevelService {
35
- constructor(connection, stockLocationService, configService, requestCache) {
42
+ constructor(connection, stockLocationService, configService, requestCache, globalSettingsService) {
36
43
  this.connection = connection;
37
44
  this.stockLocationService = stockLocationService;
38
45
  this.configService = configService;
39
46
  this.requestCache = requestCache;
47
+ this.globalSettingsService = globalSettingsService;
48
+ this.hasWarnedAboutMissingRowLockSupport = false;
49
+ this.hasWarnedAboutMissingTransaction = false;
40
50
  }
41
51
  /**
42
52
  * @description
@@ -66,10 +76,21 @@ let StockLevelService = class StockLevelService {
66
76
  * @description
67
77
  * Returns the available stock (on hand and allocated) for the given {@link ProductVariant}. This is determined
68
78
  * by the configured {@link StockLocationStrategy}.
79
+ *
80
+ * Pass `{ lockStockLevels: true }` when the caller is about to allocate stock based on the
81
+ * returned figures. This takes a write lock on the underlying StockLevel rows which is held
82
+ * until the surrounding transaction commits, so that the check and the allocation cannot be
83
+ * interleaved with another checkout for the same ProductVariant.
84
+ *
85
+ * @since 3.7.4 - Added the `options` parameter
69
86
  */
70
- async getAvailableStock(ctx, productVariantId) {
87
+ async getAvailableStock(ctx, productVariantId, options) {
71
88
  const { stockLocationStrategy } = this.configService.catalogOptions;
72
- const stockLevels = await this.getStockLevelLoader(ctx).load(productVariantId);
89
+ // The locked read bypasses the batching loader: the lock must be taken on this
90
+ // transaction's own query, and its rows must not be shared with other callers.
91
+ const stockLevels = (options === null || options === void 0 ? void 0 : options.lockStockLevels)
92
+ ? await this.getLockedStockLevelsForVariant(ctx, productVariantId)
93
+ : await this.getStockLevelLoader(ctx).load(productVariantId);
73
94
  return stockLocationStrategy.getAvailableStock(ctx, productVariantId, stockLevels);
74
95
  }
75
96
  /**
@@ -140,6 +161,9 @@ let StockLevelService = class StockLevelService {
140
161
  /**
141
162
  * @description
142
163
  * Updates the `stockOnHand` for the given {@link ProductVariant} and {@link StockLocation}.
164
+ * When creating a new StockLevel the initial value is the adjustment delta itself, which may be
165
+ * negative (e.g. a backorder against a variant with a negative `outOfStockThreshold`), so the
166
+ * row stays consistent with the `StockAdjustment` ledger.
143
167
  */
144
168
  async updateStockOnHandForLocation(ctx, productVariantId, stockLocationId, change) {
145
169
  const stockLevel = await this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).findOne({
@@ -148,7 +172,10 @@ let StockLevelService = class StockLevelService {
148
172
  stockLocationId,
149
173
  },
150
174
  });
151
- if (!stockLevel) {
175
+ if (stockLevel) {
176
+ await this.incrementStockLevel(ctx, stockLevel.id, 'stockOnHand', change);
177
+ }
178
+ else {
152
179
  await this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).save(new stock_level_entity_1.StockLevel({
153
180
  productVariantId,
154
181
  stockLocationId,
@@ -156,15 +183,12 @@ let StockLevelService = class StockLevelService {
156
183
  stockAllocated: 0,
157
184
  }));
158
185
  }
159
- if (stockLevel) {
160
- await this.connection
161
- .getRepository(ctx, stock_level_entity_1.StockLevel)
162
- .update(stockLevel.id, { stockOnHand: stockLevel.stockOnHand + change });
163
- }
164
186
  }
165
187
  /**
166
188
  * @description
167
189
  * Updates the `stockAllocated` for the given {@link ProductVariant} and {@link StockLocation}.
190
+ * `stockAllocated` is clamped at 0 so a release can never produce a negative value. A clamp
191
+ * which fires is logged, since it means more was released than was ever allocated.
168
192
  */
169
193
  async updateStockAllocatedForLocation(ctx, productVariantId, stockLocationId, change) {
170
194
  const stockLevel = await this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).findOne({
@@ -174,9 +198,153 @@ let StockLevelService = class StockLevelService {
174
198
  },
175
199
  });
176
200
  if (stockLevel) {
177
- await this.connection
201
+ await this.incrementStockLevel(ctx, stockLevel.id, 'stockAllocated', change);
202
+ if (change < 0) {
203
+ await this.clampStockAllocatedAtZero(ctx, stockLevel.id, productVariantId, stockLocationId, change);
204
+ }
205
+ }
206
+ }
207
+ /**
208
+ * A second atomic statement rather than a clamp computed in JavaScript, for the same reason as
209
+ * `incrementStockLevel`: only the database knows the value the decrement actually produced.
210
+ */
211
+ async clampStockAllocatedAtZero(ctx, stockLevelId, productVariantId, stockLocationId, change) {
212
+ const result = await this.connection
213
+ .getRepository(ctx, stock_level_entity_1.StockLevel)
214
+ .update({ id: stockLevelId, stockAllocated: (0, typeorm_1.LessThan)(0) }, { stockAllocated: 0 });
215
+ if (result.affected) {
216
+ vendure_logger_1.Logger.warn(`stockAllocated for ProductVariant ${String(productVariantId)} at StockLocation ` +
217
+ `${String(stockLocationId)} went negative after a change of ${change}; clamped to 0`, loggerCtx);
218
+ }
219
+ }
220
+ /**
221
+ * Applies the change with a single atomic SQL statement (`SET column = column + change`),
222
+ * via TypeORM's `Repository.increment()`. The invariant: the stored value must never be
223
+ * computed from a value read earlier in JavaScript, because two overlapping requests would
224
+ * then both start from the same figure and one of the two changes would be lost. A negative
225
+ * change decrements.
226
+ */
227
+ async incrementStockLevel(ctx, stockLevelId, property, change) {
228
+ await this.connection
229
+ .getRepository(ctx, stock_level_entity_1.StockLevel)
230
+ .increment({ id: stockLevelId }, property, change);
231
+ }
232
+ /**
233
+ * @description
234
+ * Takes the write lock of {@link StockLevelService.getLockedStockLevelsForVariant} for each of
235
+ * the given ProductVariants, in a fixed order: duplicates are dropped, the variants are visited
236
+ * in ascending id order and each variant's rows in id order. A transaction which changes the
237
+ * stock of more than one variant should call this once, before its first stock read or write.
238
+ * Two such transactions then take their locks in the same order, so they cannot deadlock, and
239
+ * later stock writes in the transaction meet rows it already holds.
240
+ *
241
+ * Variants which do not track inventory are skipped by default: nothing is checked or counted
242
+ * for them, so locking them would only serialize their checkouts. Pass
243
+ * `{ includeUntrackedVariants: true }` when the transaction derives what it writes from the
244
+ * current `stockOnHand` rather than from a saleable stock check.
245
+ *
246
+ * Degrades like `getLockedStockLevelsForVariant` without a transaction or row lock support.
247
+ *
248
+ * @since 3.7.4
249
+ */
250
+ async lockStockLevelsForVariants(ctx, productVariantIds, options) {
251
+ const ids = (0, unique_1.unique)(productVariantIds);
252
+ if (!ids.length) {
253
+ return;
254
+ }
255
+ const idsToLock = (options === null || options === void 0 ? void 0 : options.includeUntrackedVariants) ? ids : await this.filterToTrackedIds(ctx, ids);
256
+ for (const productVariantId of [...idsToLock].sort(stock_lock_order_1.compareIdsForLockOrder)) {
257
+ await this.getLockedStockLevelsForVariant(ctx, productVariantId);
258
+ }
259
+ }
260
+ async filterToTrackedIds(ctx, ids) {
261
+ const { trackInventory } = await this.globalSettingsService.getSettings(ctx);
262
+ const variants = await this.connection.getRepository(ctx, product_variant_entity_1.ProductVariant).find({
263
+ where: { id: (0, typeorm_1.In)(ids) },
264
+ select: { id: true, trackInventory: true },
265
+ loadEagerRelations: false,
266
+ });
267
+ return variants
268
+ .filter(v => v.trackInventory === generated_types_1.GlobalFlag.TRUE ||
269
+ (v.trackInventory === generated_types_1.GlobalFlag.INHERIT && trackInventory))
270
+ .map(v => v.id);
271
+ }
272
+ /**
273
+ * @description
274
+ * Returns every {@link StockLevel} of the given {@link ProductVariant}, whatever its
275
+ * {@link StockLocation} or Channel, with a write lock (`SELECT ... FOR UPDATE`) held until
276
+ * the surrounding transaction commits. Use it when the returned figures decide how much
277
+ * stock to allocate and the allocation happens in the same transaction: a second
278
+ * transaction for the same variant waits here until the first commits, then reads the
279
+ * updated `stockAllocated`.
280
+ *
281
+ * The rows are read by the locking statement itself. On MySQL and MariaDB a plain SELECT
282
+ * under REPEATABLE READ keeps returning the transaction's opening snapshot, while a locking
283
+ * read sees the latest committed row.
284
+ *
285
+ * Rows are locked in id order. When locking several variants in one transaction, visit them
286
+ * in a fixed order too, so two transactions cannot take the same locks in opposite order.
287
+ *
288
+ * Without an open transaction, or on a driver without row locks (SQLite, SQL.js), this falls
289
+ * back to an unlocked read and logs a warning once per process.
290
+ *
291
+ * @since 3.7.4
292
+ */
293
+ async getLockedStockLevelsForVariant(ctx, productVariantId) {
294
+ try {
295
+ return await this.connection
178
296
  .getRepository(ctx, stock_level_entity_1.StockLevel)
179
- .update(stockLevel.id, { stockAllocated: stockLevel.stockAllocated + change });
297
+ .createQueryBuilder('stockLevel')
298
+ .setLock('pessimistic_write')
299
+ .where('stockLevel.productVariantId = :productVariantId', { productVariantId })
300
+ .orderBy('stockLevel.id', 'ASC')
301
+ .getMany();
302
+ }
303
+ catch (e) {
304
+ // Only the two lock-support errors below are recoverable. Everything else must
305
+ // propagate, in particular MariaDB 11.6+ ER_CHECKREAD ("Record has changed since last
306
+ // read"), which `innodb_snapshot_isolation` raises when this locking read meets a row
307
+ // that changed after the transaction's snapshot. MariaDB has already aborted the
308
+ // transaction at that point, so failing here is the only outcome which is safe for the
309
+ // stock figures: swallowing it and falling back to an unlocked read would hand the
310
+ // caller a stale figure and allow the over-allocation this lock exists to prevent. It is
311
+ // not safe for payments: if a payment was already captured in this transaction, the
312
+ // abort rolls back the order while the charge stands.
313
+ if (!(e instanceof typeorm_1.LockNotSupportedOnGivenDriverError) &&
314
+ !(e instanceof typeorm_1.PessimisticLockTransactionRequiredError)) {
315
+ throw e;
316
+ }
317
+ if (e instanceof typeorm_1.PessimisticLockTransactionRequiredError) {
318
+ // The driver supports row locks but no transaction is open, so the lock cannot be
319
+ // taken. The caller may act on the unlocked figure, so say so rather than degrading
320
+ // in silence, but only once: a caller which does this does it on every request.
321
+ if (!this.hasWarnedAboutMissingTransaction) {
322
+ this.hasWarnedAboutMissingTransaction = true;
323
+ vendure_logger_1.Logger.warn('Could not lock the StockLevel rows for ProductVariant ' +
324
+ `${String(productVariantId)} because no transaction is in progress. ` +
325
+ 'Wrap the call with the @Transaction() resolver decorator, or start a ' +
326
+ 'transaction via TransactionalConnection.withTransaction(). Further ' +
327
+ 'occurrences are not logged.', loggerCtx);
328
+ }
329
+ }
330
+ else if (!this.hasWarnedAboutMissingRowLockSupport) {
331
+ // A driver without row locks is a property of the deployment, so this branch is
332
+ // taken for the whole life of the server. Warn once rather than on every checkout.
333
+ this.hasWarnedAboutMissingRowLockSupport = true;
334
+ vendure_logger_1.Logger.warn('The configured database driver does not support row locking, so the saleable ' +
335
+ 'stock check cannot be held across the allocation which follows it. ' +
336
+ 'Concurrent checkouts of the same ProductVariant can still allocate more ' +
337
+ 'units than are in stock. This is expected on SQLite and SQL.js. Use ' +
338
+ 'PostgreSQL, MySQL or MariaDB in production.', loggerCtx);
339
+ }
340
+ // SQLite and SQL.js have no row locks. Fall back to an unlocked read: on SQLite writes
341
+ // are serialized by the engine itself, and without a transaction there is nothing for
342
+ // the lock to be held for.
343
+ return this.connection.getRepository(ctx, stock_level_entity_1.StockLevel).find({
344
+ where: {
345
+ productVariantId,
346
+ },
347
+ });
180
348
  }
181
349
  }
182
350
  };
@@ -187,6 +355,7 @@ exports.StockLevelService = StockLevelService = __decorate([
187
355
  __metadata("design:paramtypes", [transactional_connection_1.TransactionalConnection,
188
356
  stock_location_service_1.StockLocationService,
189
357
  config_service_1.ConfigService,
190
- request_context_cache_service_1.RequestContextCacheService])
358
+ request_context_cache_service_1.RequestContextCacheService,
359
+ global_settings_service_1.GlobalSettingsService])
191
360
  ], StockLevelService);
192
361
  //# sourceMappingURL=stock-level.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"stock-level.service.js","sourceRoot":"","sources":["../../../src/service/services/stock-level.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAE5C,4DAAoC;AACpC,qCAA6B;AAG7B,6FAAuF;AACvF,4EAA+D;AAE/D,gEAA4D;AAC5D,wFAAoF;AAEpF,oFAAyE;AAEzE,qEAAgE;AAEhE;;;;;;;;GAQG;AAGI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC1B,YACY,UAAmC,EACnC,oBAA0C,EAC1C,aAA4B,EAC5B,YAAwC;QAHxC,eAAU,GAAV,UAAU,CAAyB;QACnC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAA4B;IACjD,CAAC;IAEJ;;;OAGG;IACH,KAAK,CAAC,aAAa,CAAC,GAAmB,EAAE,gBAAoB,EAAE,eAAmB;QAC9E,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,C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I,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,+BAAU,CAAC,CAAC,IAAI,CACrD,IAAI,+BAAU,CAAC;gBACX,gBAAgB;gBAChB,eAAe;gBACf,WAAW,EAAE,MAAM;gBACnB,cAAc,EAAE,CAAC;aACpB,CAAC,CACL,CAAC;QACN,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,UAAU;iBAChB,aAAa,CAAC,GAAG,EAAE,+BAAU,CAAC;iBAC9B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,GAAG,MAAM,EAAE,CAAC,CAAC;QACjF,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,+BAA+B,CACjC,GAAmB,EACnB,gBAAoB,EACpB,eAAmB,EACnB,MAAc;QAEd,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,+BAAU,CAAC,CAAC,OAAO,CAAC;YAC5E,KAAK,EAAE;gBACH,gBAAgB;gBAChB,eAAe;aAClB;SACJ,CAAC,CAAC;QACH,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,UAAU;iBAChB,aAAa,CAAC,GAAG,EAAE,+BAAU,CAAC;iBAC9B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,UAAU,CAAC,cAAc,GAAG,MAAM,EAAE,CAAC,CAAC;QACvF,CAAC;IACL,CAAC;CACJ,CAAA;AAtLY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,mBAAU,GAAE;IACZ,IAAA,iCAAU,GAAE;qCAGe,kDAAuB;QACb,6CAAoB;QAC3B,8BAAa;QACd,0DAA0B;GAL3C,iBAAiB,CAsL7B"}
1
+ {"version":3,"file":"stock-level.service.js","sourceRoot":"","sources":["../../../src/service/services/stock-level.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,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AC;oBACzC,IAAI,CAAC,gCAAgC,GAAG,IAAI,CAAC;oBAC7C,uBAAM,CAAC,IAAI,CACP,wDAAwD;wBACpD,GAAG,MAAM,CAAC,gBAAgB,CAAC,0CAA0C;wBACrE,uEAAuE;wBACvE,qEAAqE;wBACrE,6BAA6B,EACjC,SAAS,CACZ,CAAC;gBACN,CAAC;YACL,CAAC;iBAAM,IAAI,CAAC,IAAI,CAAC,mCAAmC,EAAE,CAAC;gBACnD,gFAAgF;gBAChF,mFAAmF;gBACnF,IAAI,CAAC,mCAAmC,GAAG,IAAI,CAAC;gBAChD,uBAAM,CAAC,IAAI,CACP,+EAA+E;oBAC3E,qEAAqE;oBACrE,0EAA0E;oBAC1E,sEAAsE;oBACtE,6CAA6C,EACjD,SAAS,CACZ,CAAC;YACN,CAAC;YACD,uFAAuF;YACvF,sFAAsF;YACtF,2BAA2B;YAC3B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,+BAAU,CAAC,CAAC,IAAI,CAAC;gBACvD,KAAK,EAAE;oBACH,gBAAgB;iBACnB;aACJ,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ,CAAA;AAjYY,8CAAiB;4BAAjB,iBAAiB;IAF7B,IAAA,mBAAU,GAAE;IACZ,IAAA,iCAAU,GAAE;qCAMe,kDAAuB;QACb,6CAAoB;QAC3B,8BAAa;QACd,0DAA0B;QACjB,+CAAqB;GAT/C,iBAAiB,CAiY7B"}
@@ -42,6 +42,15 @@ export declare class StockMovementService {
42
42
  * @description
43
43
  * Adjusts the stock level of the ProductVariant, creating a new {@link StockAdjustment} entity
44
44
  * in the process.
45
+ *
46
+ * The `stockOnHand` of the input is absolute, but the write which applies it is a relative
47
+ * `stockOnHand + delta`, so the current value is read under a write lock held until the
48
+ * surrounding transaction commits. Two concurrent adjustments of the same ProductVariant
49
+ * therefore serialize, and the stored value is the one the later of the two asked for.
50
+ *
51
+ * When adjusting more than one ProductVariant in a transaction, call
52
+ * {@link StockLevelService.lockStockLevelsForVariants} for the whole set first, with
53
+ * `{ includeUntrackedVariants: true }`, so the locks are taken in the shared order.
45
54
  */
46
55
  adjustProductVariantStock(ctx: RequestContext, productVariantId: ID, stockOnHandNumberOrInput: number | StockLevelInput[]): Promise<StockAdjustment[]>;
47
56
  /**
@@ -15,6 +15,7 @@ const generated_types_1 = require("@vendure/common/lib/generated-types");
15
15
  const typeorm_1 = require("typeorm");
16
16
  const instrument_decorator_1 = require("../../common/instrument-decorator");
17
17
  const utils_1 = require("../../common/utils");
18
+ const vendure_logger_1 = require("../../config/logger/vendure-logger");
18
19
  const transactional_connection_1 = require("../../connection/transactional-connection");
19
20
  const order_line_entity_1 = require("../../entity/order-line/order-line.entity");
20
21
  const product_variant_entity_1 = require("../../entity/product-variant/product-variant.entity");
@@ -26,10 +27,12 @@ const stock_adjustment_entity_1 = require("../../entity/stock-movement/stock-adj
26
27
  const stock_movement_entity_1 = require("../../entity/stock-movement/stock-movement.entity");
27
28
  const event_bus_1 = require("../../event-bus/event-bus");
28
29
  const stock_movement_event_1 = require("../../event-bus/events/stock-movement-event");
30
+ const stock_shortfall_event_1 = require("../../event-bus/events/stock-shortfall-event");
29
31
  const list_query_builder_1 = require("../helpers/list-query-builder/list-query-builder");
30
32
  const global_settings_service_1 = require("./global-settings.service");
31
33
  const stock_level_service_1 = require("./stock-level.service");
32
34
  const stock_location_service_1 = require("./stock-location.service");
35
+ const loggerCtx = 'StockMovementService';
33
36
  /**
34
37
  * @description
35
38
  * Contains methods relating to {@link StockMovement} entities.
@@ -66,37 +69,72 @@ let StockMovementService = class StockMovementService {
66
69
  * @description
67
70
  * Adjusts the stock level of the ProductVariant, creating a new {@link StockAdjustment} entity
68
71
  * in the process.
72
+ *
73
+ * The `stockOnHand` of the input is absolute, but the write which applies it is a relative
74
+ * `stockOnHand + delta`, so the current value is read under a write lock held until the
75
+ * surrounding transaction commits. Two concurrent adjustments of the same ProductVariant
76
+ * therefore serialize, and the stored value is the one the later of the two asked for.
77
+ *
78
+ * When adjusting more than one ProductVariant in a transaction, call
79
+ * {@link StockLevelService.lockStockLevelsForVariants} for the whole set first, with
80
+ * `{ includeUntrackedVariants: true }`, so the locks are taken in the shared order.
69
81
  */
70
82
  async adjustProductVariantStock(ctx, productVariantId, stockOnHandNumberOrInput) {
71
- let stockOnHandInputs;
72
- if (typeof stockOnHandNumberOrInput === 'number') {
73
- const defaultStockLocation = await this.stockLocationService.defaultStockLocation(ctx);
74
- stockOnHandInputs = [
75
- { stockLocationId: defaultStockLocation.id, stockOnHand: stockOnHandNumberOrInput },
76
- ];
77
- }
78
- else {
79
- stockOnHandInputs = stockOnHandNumberOrInput;
80
- }
81
- const adjustments = [];
82
- for (const input of stockOnHandInputs) {
83
- const stockLevel = await this.stockLevelService.getStockLevel(ctx, productVariantId, input.stockLocationId);
84
- const oldStockLevel = stockLevel.stockOnHand;
85
- const newStockLevel = input.stockOnHand;
86
- if (oldStockLevel === newStockLevel) {
87
- continue;
83
+ // Run inside a transaction for the same reason as `createAllocationsForOrderLines`: the
84
+ // locked read below needs one, and a caller from a non-transactional context (the
85
+ // FastImporterService, a job-queue processor, a stand-alone script) would otherwise fall
86
+ // back to an unlocked read. It also makes the StockAdjustment ledger row and the StockLevel
87
+ // write atomic. Nested transactions join the existing one, so the `@Transaction()`-wrapped
88
+ // API paths are unaffected.
89
+ return this.connection.withTransaction(ctx, async (txCtx) => {
90
+ let stockOnHandInputs;
91
+ if (typeof stockOnHandNumberOrInput === 'number') {
92
+ const defaultStockLocation = await this.stockLocationService.defaultStockLocation(txCtx);
93
+ stockOnHandInputs = [
94
+ { stockLocationId: defaultStockLocation.id, stockOnHand: stockOnHandNumberOrInput },
95
+ ];
88
96
  }
89
- const delta = newStockLevel - oldStockLevel;
90
- const adjustment = await this.connection.getRepository(ctx, stock_adjustment_entity_1.StockAdjustment).save(new stock_adjustment_entity_1.StockAdjustment({
91
- quantity: delta,
92
- stockLocation: { id: input.stockLocationId },
93
- productVariant: { id: productVariantId },
94
- }));
95
- await this.stockLevelService.updateStockOnHandForLocation(ctx, productVariantId, input.stockLocationId, delta);
96
- await this.eventBus.publish(new stock_movement_event_1.StockMovementEvent(ctx, [adjustment]));
97
- adjustments.push(adjustment);
98
- }
99
- return adjustments;
97
+ else {
98
+ stockOnHandInputs = stockOnHandNumberOrInput;
99
+ }
100
+ // One locked read for every location of this variant, before the first delta is
101
+ // computed. It must be the locking read rather than a plain one: on MySQL and MariaDB a
102
+ // plain SELECT under REPEATABLE READ returns the transaction's opening snapshot, which
103
+ // for a transaction that waited on the lock is the value from before the other
104
+ // adjustment committed.
105
+ const lockedStockLevels = await this.stockLevelService.getLockedStockLevelsForVariant(txCtx, productVariantId);
106
+ // Keyed by stock location, so that two inputs for the same location in one call each
107
+ // apply their delta to the value the previous one produced, rather than both to the
108
+ // value read above.
109
+ const stockOnHandByLocation = new Map(lockedStockLevels.map(level => [String(level.stockLocationId), level.stockOnHand]));
110
+ const adjustments = [];
111
+ for (const input of stockOnHandInputs) {
112
+ const locationKey = String(input.stockLocationId);
113
+ if (!stockOnHandByLocation.has(locationKey)) {
114
+ // No row for this location yet, so there is nothing to lock and nothing stale.
115
+ // `getStockLevel` creates it with a `stockOnHand` of 0.
116
+ const created = await this.stockLevelService.getStockLevel(txCtx, productVariantId, input.stockLocationId);
117
+ stockOnHandByLocation.set(locationKey, created.stockOnHand);
118
+ }
119
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120
+ const oldStockLevel = stockOnHandByLocation.get(locationKey);
121
+ const newStockLevel = input.stockOnHand;
122
+ if (oldStockLevel === newStockLevel) {
123
+ continue;
124
+ }
125
+ const delta = newStockLevel - oldStockLevel;
126
+ stockOnHandByLocation.set(locationKey, newStockLevel);
127
+ const adjustment = await this.connection.getRepository(txCtx, stock_adjustment_entity_1.StockAdjustment).save(new stock_adjustment_entity_1.StockAdjustment({
128
+ quantity: delta,
129
+ stockLocation: { id: input.stockLocationId },
130
+ productVariant: { id: productVariantId },
131
+ }));
132
+ await this.stockLevelService.updateStockOnHandForLocation(txCtx, productVariantId, input.stockLocationId, delta);
133
+ await this.eventBus.publish(new stock_movement_event_1.StockMovementEvent(txCtx, [adjustment]));
134
+ adjustments.push(adjustment);
135
+ }
136
+ return adjustments;
137
+ });
100
138
  }
101
139
  /**
102
140
  * @description
@@ -118,30 +156,82 @@ let StockMovementService = class StockMovementService {
118
156
  * increased, indicating that this quantity of stock is allocated and cannot be sold.
119
157
  */
120
158
  async createAllocationsForOrderLines(ctx, lines) {
121
- const allocations = [];
122
- const globalTrackInventory = (await this.globalSettingsService.getSettings(ctx)).trackInventory;
123
- for (const { orderLineId, quantity } of lines) {
124
- const orderLine = await this.connection.getEntityOrThrow(ctx, order_line_entity_1.OrderLine, orderLineId);
125
- const productVariant = await this.connection.getEntityOrThrow(ctx, product_variant_entity_1.ProductVariant, orderLine.productVariantId, { includeSoftDeleted: true });
126
- const allocationLocations = await this.stockLocationService.getAllocationLocations(ctx, orderLine, quantity);
127
- for (const allocationLocation of allocationLocations) {
128
- const allocation = new allocation_entity_1.Allocation({
129
- productVariant: new product_variant_entity_1.ProductVariant({ id: orderLine.productVariantId }),
130
- stockLocation: allocationLocation.location,
131
- quantity: allocationLocation.quantity,
132
- orderLine,
133
- });
134
- allocations.push(allocation);
135
- if (this.trackInventoryForVariant(productVariant, globalTrackInventory)) {
136
- await this.stockLevelService.updateStockAllocatedForLocation(ctx, orderLine.productVariantId, allocationLocation.location.id, allocationLocation.quantity);
159
+ // Run inside a transaction so that the per-variant pessimistic locks taken during
160
+ // allocation (see MultiChannelStockLocationStrategy.forAllocation) are valid and held until
161
+ // commit. Without this, a caller from a non-transactional context (a job-queue processor or
162
+ // a stand-alone script calling e.g. `orderService.transitionToState`) would trigger
163
+ // TypeORM's `PessimisticLockTransactionRequiredError` on every driver. Nested transactions
164
+ // join the existing one, so the core API paths (already `@Transaction`-wrapped) are unaffected.
165
+ return this.connection.withTransaction(ctx, async (txCtx) => {
166
+ const allocations = [];
167
+ // A single batch can contain lines from more than one Order: `Fulfillment.orders` is a
168
+ // many-to-many relation and `default-fulfillment-process` re-allocates a cancelled
169
+ // fulfillment's lines in one call. Shortfalls are therefore grouped by the Order the
170
+ // shortfalling line belongs to, so each StockShortfallEvent references the right Order.
171
+ const shortfallsByOrder = new Map();
172
+ const globalTrackInventory = (await this.globalSettingsService.getSettings(txCtx)).trackInventory;
173
+ const orderLinesToAllocate = await Promise.all(lines.map(async ({ orderLineId, quantity }) => ({
174
+ orderLine: await this.connection.getEntityOrThrow(txCtx, order_line_entity_1.OrderLine, orderLineId, {
175
+ relations: ['order'],
176
+ }),
177
+ quantity,
178
+ })));
179
+ await this.stockLevelService.lockStockLevelsForVariants(txCtx, orderLinesToAllocate.map(({ orderLine }) => orderLine.productVariantId));
180
+ for (const { orderLine, quantity } of orderLinesToAllocate) {
181
+ const productVariant = await this.connection.getEntityOrThrow(txCtx, product_variant_entity_1.ProductVariant, orderLine.productVariantId, { includeSoftDeleted: true });
182
+ const allocationLocations = await this.stockLocationService.getAllocationLocations(txCtx, orderLine, quantity);
183
+ const trackInventory = this.trackInventoryForVariant(productVariant, globalTrackInventory);
184
+ const allocatedForLine = allocationLocations.reduce((sum, l) => sum + l.quantity, 0);
185
+ // A variant which does not track inventory has no stock to fall short of, even
186
+ // when it has no StockLevel in the Channel's locations and so gets no allocation.
187
+ if (trackInventory && allocatedForLine < quantity) {
188
+ const shortfall = {
189
+ productVariantId: orderLine.productVariantId,
190
+ orderLineId: orderLine.id,
191
+ requested: quantity,
192
+ allocated: allocatedForLine,
193
+ };
194
+ const group = shortfallsByOrder.get(orderLine.order.id);
195
+ if (group) {
196
+ group.shortfalls.push(shortfall);
197
+ }
198
+ else {
199
+ shortfallsByOrder.set(orderLine.order.id, {
200
+ order: orderLine.order,
201
+ shortfalls: [shortfall],
202
+ });
203
+ }
204
+ }
205
+ for (const allocationLocation of allocationLocations) {
206
+ const allocation = new allocation_entity_1.Allocation({
207
+ productVariant: new product_variant_entity_1.ProductVariant({ id: orderLine.productVariantId }),
208
+ stockLocation: allocationLocation.location,
209
+ quantity: allocationLocation.quantity,
210
+ orderLine,
211
+ });
212
+ allocations.push(allocation);
213
+ if (trackInventory) {
214
+ await this.stockLevelService.updateStockAllocatedForLocation(txCtx, orderLine.productVariantId, allocationLocation.location.id, allocationLocation.quantity);
215
+ }
137
216
  }
138
217
  }
139
- }
140
- const savedAllocations = await this.connection.getRepository(ctx, allocation_entity_1.Allocation).save(allocations);
141
- if (savedAllocations.length) {
142
- await this.eventBus.publish(new stock_movement_event_1.StockMovementEvent(ctx, savedAllocations));
143
- }
144
- return savedAllocations;
218
+ const savedAllocations = await this.connection.getRepository(txCtx, allocation_entity_1.Allocation).save(allocations);
219
+ if (savedAllocations.length) {
220
+ await this.eventBus.publish(new stock_movement_event_1.StockMovementEvent(txCtx, savedAllocations));
221
+ }
222
+ for (const { order, shortfalls } of shortfallsByOrder.values()) {
223
+ // Surface the shortfall in the logs: allocation is capped rather than failed (the
224
+ // payment may already be captured), so without this a paid-but-under-allocated Order
225
+ // looks normal in the admin UI. The StockShortfallEvent lets a plugin react further.
226
+ for (const shortfall of shortfalls) {
227
+ vendure_logger_1.Logger.warn(`Stock shortfall on Order ${order.code}: ProductVariant ` +
228
+ `${shortfall.productVariantId} requested ${shortfall.requested}, ` +
229
+ `allocated ${shortfall.allocated}`, loggerCtx);
230
+ }
231
+ await this.eventBus.publish(new stock_shortfall_event_1.StockShortfallEvent(txCtx, order, shortfalls));
232
+ }
233
+ return savedAllocations;
234
+ });
145
235
  }
146
236
  /**
147
237
  * @description
@@ -156,6 +246,7 @@ let StockMovementService = class StockMovementService {
156
246
  const orderLines = await this.connection
157
247
  .getRepository(ctx, order_line_entity_1.OrderLine)
158
248
  .find({ where: { id: (0, typeorm_1.In)(lines.map(line => line.orderLineId)) } });
249
+ await this.stockLevelService.lockStockLevelsForVariants(ctx, orderLines.map(line => line.productVariantId));
159
250
  for (const lineRow of lines) {
160
251
  const orderLine = orderLines.find(line => (0, utils_1.idsAreEqual)(line.id, lineRow.orderLineId));
161
252
  if (!orderLine) {
@@ -196,6 +287,7 @@ let StockMovementService = class StockMovementService {
196
287
  },
197
288
  relations: ['productVariant'],
198
289
  });
290
+ await this.stockLevelService.lockStockLevelsForVariants(ctx, orderLines.map(line => line.productVariantId));
199
291
  const cancellations = [];
200
292
  const globalTrackInventory = (await this.globalSettingsService.getSettings(ctx)).trackInventory;
201
293
  for (const orderLine of orderLines) {
@@ -235,6 +327,7 @@ let StockMovementService = class StockMovementService {
235
327
  where: { id: (0, typeorm_1.In)(lineInputs.map(l => l.orderLineId)) },
236
328
  relations: ['productVariant'],
237
329
  });
330
+ await this.stockLevelService.lockStockLevelsForVariants(ctx, orderLines.map(line => line.productVariantId));
238
331
  const globalTrackInventory = (await this.globalSettingsService.getSettings(ctx)).trackInventory;
239
332
  const variantsMap = new Map();
240
333
  for (const orderLine of orderLines) {
@@ -1 +1 @@
1
- {"version":3,"file":"stock-movement.service.js","sourceRoot":"","sources":["../../../src/service/services/stock-movement.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yEAK6C;AAE7C,qCAA6B;AAG7B,4EAA+D;AAC/D,8CAAiD;AAGjD,wFAAoF;AAEpF,iFAAsE;AACtE,gGAAqF;AAErF,qFAA2E;AAC3E,yFAA+E;AAC/E,+EAAqE;AACrE,yEAA+D;AAC/D,iGAAsF;AACtF,6FAAkF;AAClF,yDAAqD;AACrD,sFAAiF;AACjF,yFAAoF;AAEpF,uEAAkE;AAClE,+DAA0D;AAC1D,qEAAgE;AAEhE;;;;;GAKG;AAGI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAK7B,YACY,UAAmC,EACnC,gBAAkC,EAClC,qBAA4C,EAC5C,iBAAoC,EACpC,QAAkB,EAClB,oBAA0C;QAL1C,eAAU,GAAV,UAAU,CAAyB;QACnC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,0BAAqB,GAArB,qBAAqB,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AM,EAAE,CAAC;YACvB,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,yCAAkB,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO,aAAa,CAAC;IACzB,CAAC;IAEO,wBAAwB,CAAC,OAAuB,EAAE,oBAA6B;QACnF,OAAO,CACH,OAAO,CAAC,cAAc,KAAK,4BAAU,CAAC,IAAI;YAC1C,CAAC,OAAO,CAAC,cAAc,KAAK,4BAAU,CAAC,OAAO,IAAI,oBAAoB,CAAC,CAC1E,CAAC;IACN,CAAC;CACJ,CAAA;AAtUY,oDAAoB;+BAApB,oBAAoB;IAFhC,IAAA,mBAAU,GAAE;IACZ,IAAA,iCAAU,GAAE;qCAOe,kDAAuB;QACjB,qCAAgB;QACX,+CAAqB;QACzB,uCAAiB;QAC1B,oBAAQ;QACI,6CAAoB;GAX7C,oBAAoB,CAsUhC"}
1
+ {"version":3,"file":"stock-movement.service.js","sourceRoot":"","sources":["../../../src/service/services/stock-movement.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,yEAK6C;AAE7C,qCAA6B;AAG7B,4EAA+D;AAC/D,8CAAiD;AACjD,uEAA4D;AAG5D,wFAAoF;AAEpF,iFAAsE;AACtE,gGAAqF;AAErF,qFAA2E;AAC3E,yFAA+E;AAC/E,+EAAqE;AACrE,yEAA+D;AAC/D,iGAAsF;AACtF,6FAAkF;AAClF,yDAAqD;AACrD,sFAAiF;AACjF,wFAAmG;AACnG,yFAAoF;AAEpF,uEAAkE;AAClE,+DAA0D;AAC1D,qEAAgE;AAEhE,MAAM,SAAS,GAAG,sBAAsB,CAAC;AAEzC;;;;;GAKG;AAGI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAK7B,YACY,UAAmC,EACnC,gBAAkC,EAClC,qBAA4C,EAC5C,iBAAoC,EACpC,QAAkB,EAClB,oBAA0C;QAL1C,eAAU,GAAV,UAAU,CAAyB;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