@pinelab/vendure-plugin-qls-fulfillment 3.0.0 → 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.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# 3.1.0 (2026-08-12)
|
|
2
|
+
|
|
3
|
+
- Trigger `saveAdditionalVariantData` from incoming stock webhooks using the webhook payload directly.
|
|
4
|
+
- Avoid fetching the QLS product entity during this flow.
|
|
5
|
+
- Add webhook coverage for additional variant data.
|
|
6
|
+
|
|
1
7
|
# 3.0.0 (2026-07-29)
|
|
2
8
|
|
|
3
9
|
- Migrated to React Dashboard.
|
|
@@ -40,7 +40,7 @@ let QlsWebhooksController = class QlsWebhooksController {
|
|
|
40
40
|
return core_1.Logger.error(`Incoming webhook with invalid channel token for channel '${channelToken}' to '${request.url}'`, constants_1.loggerCtx, JSON.stringify(body));
|
|
41
41
|
}
|
|
42
42
|
if (isStockWebhook(body)) {
|
|
43
|
-
await this.qlsProductService.
|
|
43
|
+
await this.qlsProductService.handleStockWebhook(ctx, body);
|
|
44
44
|
}
|
|
45
45
|
else if (isOrderWebhook(body)) {
|
|
46
46
|
await this.qlsOrderService.handleOrderStatusUpdate(ctx, body);
|
|
@@ -163,7 +163,7 @@ export interface FulfillmentOrder {
|
|
|
163
163
|
product: unknown;
|
|
164
164
|
}>;
|
|
165
165
|
}
|
|
166
|
-
export type IncomingStockWebhook =
|
|
166
|
+
export type IncomingStockWebhook = FulfillmentProductDetail;
|
|
167
167
|
export type IncomingOrderWebhook = Pick<FulfillmentOrder, 'customer_reference' | 'status' | 'cancelled' | 'amount_delivered' | 'amount_total'>;
|
|
168
168
|
/**
|
|
169
169
|
* This is the full data returend by the QLS API when fetching a fulfillment product by ID
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OnApplicationBootstrap, OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { EventBus, ID, Job, JobQueueService, ListQueryBuilder, ProductPriceApplicator, ProductVariant, ProductVariantService, RequestContext, StockLevelService, StockLocationService, TransactionalConnection } from '@vendure/core';
|
|
3
|
-
import { FulfillmentProduct } from '../lib/client-types';
|
|
3
|
+
import { FulfillmentProduct, IncomingStockWebhook } from '../lib/client-types';
|
|
4
4
|
import { QlsClient } from '../lib/qls-client';
|
|
5
5
|
import { QlsPluginOptions, QlsProductJobData } from '../types';
|
|
6
6
|
import { ModuleRef } from '@nestjs/core';
|
|
@@ -66,10 +66,13 @@ export declare class QlsProductService implements OnModuleInit, OnApplicationBoo
|
|
|
66
66
|
*/
|
|
67
67
|
addAdditionalEANsToQls(ctx: RequestContext, variantId: ID, additionalEANs: string[]): Promise<string[]>;
|
|
68
68
|
/**
|
|
69
|
-
* Update the stock level for a variant based on
|
|
70
|
-
* Returns true if the stock changed
|
|
69
|
+
* Update the stock level for a variant based on its SKU.
|
|
71
70
|
*/
|
|
72
71
|
updateStockBySku(ctx: RequestContext, sku: string, availableStock: number): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Handles an incoming stock webhook and saves any additional variant data.
|
|
74
|
+
*/
|
|
75
|
+
handleStockWebhook(ctx: RequestContext, qlsProduct: IncomingStockWebhook): Promise<boolean>;
|
|
73
76
|
/**
|
|
74
77
|
* Determines if a product needs to be created or updated in QLS based on the given variant and existing QLS product.
|
|
75
78
|
*/
|
|
@@ -217,18 +217,6 @@ let QlsProductService = class QlsProductService {
|
|
|
217
217
|
else if (result.status === 'updated') {
|
|
218
218
|
updatedInQls.push(variant);
|
|
219
219
|
}
|
|
220
|
-
if (result.qlsProductId &&
|
|
221
|
-
this.options.productSync.saveAdditionalVariantData) {
|
|
222
|
-
try {
|
|
223
|
-
const qlsProduct = await client.getFulfillmentProductById(result.qlsProductId);
|
|
224
|
-
if (qlsProduct) {
|
|
225
|
-
await this.options.productSync.saveAdditionalVariantData(ctx, new core_1.Injector(this.moduleRef), qlsProduct, variant);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (e) {
|
|
229
|
-
core_1.Logger.error(`Error in saveAdditionalData for variant '${variant.sku}': ${(0, catch_unknown_1.asError)(e).message}`, constants_1.loggerCtx);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
220
|
}
|
|
233
221
|
catch (e) {
|
|
234
222
|
const error = (0, catch_unknown_1.asError)(e);
|
|
@@ -312,8 +300,7 @@ let QlsProductService = class QlsProductService {
|
|
|
312
300
|
return eansToAdd;
|
|
313
301
|
}
|
|
314
302
|
/**
|
|
315
|
-
* Update the stock level for a variant based on
|
|
316
|
-
* Returns true if the stock changed
|
|
303
|
+
* Update the stock level for a variant based on its SKU.
|
|
317
304
|
*/
|
|
318
305
|
async updateStockBySku(ctx, sku, availableStock) {
|
|
319
306
|
const result = await this.variantService.findAll(ctx, {
|
|
@@ -329,6 +316,33 @@ let QlsProductService = class QlsProductService {
|
|
|
329
316
|
}
|
|
330
317
|
return await this.updateStock(ctx, variant.id, availableStock);
|
|
331
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* Handles an incoming stock webhook and saves any additional variant data.
|
|
321
|
+
*/
|
|
322
|
+
async handleStockWebhook(ctx, qlsProduct) {
|
|
323
|
+
const result = await this.variantService.findAll(ctx, {
|
|
324
|
+
filter: { sku: { eq: qlsProduct.sku } },
|
|
325
|
+
});
|
|
326
|
+
if (!result.items.length) {
|
|
327
|
+
core_1.Logger.info(`Variant with sku '${qlsProduct.sku}' not found, not handling stock webhook`, constants_1.loggerCtx);
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
const variant = result.items[0];
|
|
331
|
+
if (result.items.length > 1) {
|
|
332
|
+
core_1.Logger.error(`Multiple variants found for sku '${qlsProduct.sku}', using '${variant.id}'`, constants_1.loggerCtx);
|
|
333
|
+
}
|
|
334
|
+
await this.updateStockBySku(ctx, qlsProduct.sku, qlsProduct.amount_available);
|
|
335
|
+
if (!this.options.productSync.saveAdditionalVariantData) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
await this.options.productSync.saveAdditionalVariantData(ctx, new core_1.Injector(this.moduleRef), qlsProduct, variant);
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
core_1.Logger.error(`Error in saveAdditionalData for variant '${variant.sku}': ${(0, catch_unknown_1.asError)(e).message}`, constants_1.loggerCtx);
|
|
343
|
+
}
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
332
346
|
/**
|
|
333
347
|
* Determines if a product needs to be created or updated in QLS based on the given variant and existing QLS product.
|
|
334
348
|
*/
|