@pinelab/vendure-plugin-qls-fulfillment 1.0.0-beta.4 → 1.0.0-beta.5

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.
@@ -7,6 +7,7 @@ type SyncProductsJobResult = {
7
7
  updatedInQls: number;
8
8
  createdInQls: number;
9
9
  updatedStock: number;
10
+ failed: number;
10
11
  };
11
12
  export declare class QlsProductService implements OnModuleInit, OnApplicationBootstrap {
12
13
  private connection;
@@ -110,6 +110,7 @@ let QlsProductService = class QlsProductService {
110
110
  // Create or update products in QLS
111
111
  let createdQlsProductsCount = 0;
112
112
  let updatedQlsProductsCount = 0;
113
+ let failedCount = 0;
113
114
  for (const variant of allVariants) {
114
115
  try {
115
116
  const existingQlsProduct = allQlsProducts.find((p) => p.sku == variant.sku);
@@ -124,7 +125,9 @@ let QlsProductService = class QlsProductService {
124
125
  catch (e) {
125
126
  const error = (0, catch_unknown_1.asError)(e);
126
127
  core_1.Logger.error(`Error creating or updating variant '${variant.sku}' in QLS: ${error.message}`, constants_1.loggerCtx, error.stack);
128
+ failedCount += 1;
127
129
  }
130
+ await new Promise((resolve) => setTimeout(resolve, 700)); // Avoid rate limit of 500/5 minutes (700ms delay = 85/minute)
128
131
  }
129
132
  core_1.Logger.info(`Created ${createdQlsProductsCount} products in QLS`, constants_1.loggerCtx);
130
133
  core_1.Logger.info(`Updated ${updatedQlsProductsCount} products in QLS`, constants_1.loggerCtx);
@@ -132,6 +135,7 @@ let QlsProductService = class QlsProductService {
132
135
  updatedInQls: updatedQlsProductsCount,
133
136
  createdInQls: createdQlsProductsCount,
134
137
  updatedStock: updateStockCount,
138
+ failed: failedCount,
135
139
  };
136
140
  }
137
141
  catch (e) {
@@ -151,29 +155,44 @@ let QlsProductService = class QlsProductService {
151
155
  updatedInQls: 0,
152
156
  createdInQls: 0,
153
157
  updatedStock: 0,
158
+ failed: 0,
154
159
  };
155
160
  }
156
161
  let updatedInQls = 0;
157
162
  let createdInQls = 0;
163
+ let failedCount = 0;
158
164
  for (const variantId of productVariantIds) {
159
- const variant = await this.variantService.findOne(ctx, variantId);
160
- if (!variant) {
161
- core_1.Logger.error(`Variant with id ${variantId} not found. Not creating or updating product in QLS.`, constants_1.loggerCtx);
162
- continue;
163
- }
164
- const existingQlsProduct = await client.getFulfillmentProductBySku(variant.sku);
165
- const result = await this.createOrUpdateProductInQls(ctx, client, variant, existingQlsProduct ?? null);
166
- if (result === 'created') {
167
- createdInQls += 1;
165
+ try {
166
+ const variant = await this.variantService.findOne(ctx, variantId, [
167
+ 'featuredAsset',
168
+ 'taxCategory',
169
+ 'channels',
170
+ 'product.featuredAsset',
171
+ ]);
172
+ if (!variant) {
173
+ core_1.Logger.error(`Variant with id ${variantId} not found. Not creating or updating product in QLS.`, constants_1.loggerCtx);
174
+ continue;
175
+ }
176
+ const existingQlsProduct = await client.getFulfillmentProductBySku(variant.sku);
177
+ const result = await this.createOrUpdateProductInQls(ctx, client, variant, existingQlsProduct ?? null);
178
+ if (result === 'created') {
179
+ createdInQls += 1;
180
+ }
181
+ else if (result === 'updated') {
182
+ updatedInQls += 1;
183
+ }
168
184
  }
169
- else if (result === 'updated') {
170
- updatedInQls += 1;
185
+ catch (e) {
186
+ const error = (0, catch_unknown_1.asError)(e);
187
+ core_1.Logger.error(`Error syncing variant ${variantId} to QLS: ${error.message}`, constants_1.loggerCtx, error.stack);
188
+ failedCount += 1;
171
189
  }
172
190
  }
173
191
  return {
174
192
  updatedInQls,
175
193
  createdInQls,
176
194
  updatedStock: 0,
195
+ failed: failedCount,
177
196
  };
178
197
  }
179
198
  /**
@@ -273,8 +292,14 @@ let QlsProductService = class QlsProductService {
273
292
  const take = 100;
274
293
  let hasMore = true;
275
294
  while (hasMore) {
276
- const relations = ['featuredAsset', 'taxCategory', 'channels', 'product.featuredAsset'];
277
- const [items, totalItems] = await this.listQueryBuilder.build(core_1.ProductVariant, {
295
+ const relations = [
296
+ 'featuredAsset',
297
+ 'taxCategory',
298
+ 'channels',
299
+ 'product.featuredAsset',
300
+ ];
301
+ const [items, totalItems] = await this.listQueryBuilder
302
+ .build(core_1.ProductVariant, {
278
303
  skip,
279
304
  take,
280
305
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinelab/vendure-plugin-qls-fulfillment",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Vendure plugin to fulfill orders via QLS.",
5
5
  "keywords": [
6
6
  "fulfillment",