@adtrackify/at-service-common 3.1.26 → 3.1.27
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/dist/cjs/services/cache/generic-cached-object.d.ts +5 -0
- package/dist/cjs/services/cache/generic-cached-object.js +3 -0
- package/dist/cjs/services/cache/generic-cached-object.js.map +1 -0
- package/dist/cjs/services/cache/product-cache-service.d.ts +6 -2
- package/dist/cjs/services/cache/product-cache-service.js +21 -5
- package/dist/cjs/services/cache/product-cache-service.js.map +1 -1
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js +1 -4
- package/dist/cjs/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/dist/esm/services/cache/generic-cached-object.d.ts +5 -0
- package/dist/esm/services/cache/generic-cached-object.js +2 -0
- package/dist/esm/services/cache/generic-cached-object.js.map +1 -0
- package/dist/esm/services/cache/product-cache-service.d.ts +6 -2
- package/dist/esm/services/cache/product-cache-service.js +16 -4
- package/dist/esm/services/cache/product-cache-service.js.map +1 -1
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.js +1 -4
- package/dist/esm/services/shopify/products/shopify-products-serviceV2.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-cached-object.js","sourceRoot":"","sources":["../../../../src/services/cache/generic-cached-object.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { InternalProduct } from '../shopify/types/product';
|
|
2
|
-
|
|
2
|
+
import { GenericCachedObject } from './generic-cached-object';
|
|
3
|
+
export interface ProductCache extends GenericCachedObject {
|
|
3
4
|
productCompressed: string;
|
|
4
|
-
|
|
5
|
+
fullSha256?: string;
|
|
6
|
+
noInventorySha256?: string;
|
|
5
7
|
}
|
|
8
|
+
export declare const getProductCacheKey: (pixelId: string, productId: string) => string;
|
|
6
9
|
export declare class ProductCacheService {
|
|
7
10
|
private genericCacheService;
|
|
8
11
|
constructor(cacheLambdaFunctionArn: string);
|
|
9
12
|
getCacheKey: (pixelId: string, productId: string) => string;
|
|
10
13
|
getProductFromCache: (pixelId: string, productId: string) => Promise<InternalProduct | undefined>;
|
|
14
|
+
getProductCache: (pixelId: string, productId: string) => Promise<ProductCache | undefined>;
|
|
11
15
|
putProductInCache: (pixelId: string, productId: string, product: InternalProduct, ttlInDays?: number) => Promise<void>;
|
|
12
16
|
deleteProductFromCache: (pixelId: string, productId: string) => Promise<void>;
|
|
13
17
|
}
|
|
@@ -1,32 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProductCacheService = void 0;
|
|
6
|
+
exports.ProductCacheService = exports.getProductCacheKey = void 0;
|
|
4
7
|
const luxon_1 = require("luxon");
|
|
5
8
|
const generic_cache_service_1 = require("../generic-cache-service");
|
|
6
9
|
const libs_1 = require("../../libs");
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const getProductCacheKey = (pixelId, productId) => {
|
|
12
|
+
return `internal:product:${pixelId}_${productId}`;
|
|
13
|
+
};
|
|
14
|
+
exports.getProductCacheKey = getProductCacheKey;
|
|
7
15
|
class ProductCacheService {
|
|
8
16
|
genericCacheService;
|
|
9
17
|
constructor(cacheLambdaFunctionArn) {
|
|
10
18
|
this.genericCacheService = new generic_cache_service_1.GenericCacheService(cacheLambdaFunctionArn);
|
|
11
19
|
}
|
|
12
20
|
getCacheKey = (pixelId, productId) => {
|
|
13
|
-
return
|
|
21
|
+
return (0, exports.getProductCacheKey)(pixelId, productId);
|
|
14
22
|
};
|
|
15
23
|
getProductFromCache = async (pixelId, productId) => {
|
|
16
|
-
const
|
|
17
|
-
const cachedData = await this.genericCacheService.getCachedData(cacheKey);
|
|
24
|
+
const cachedData = await this.getProductCache(pixelId, productId);
|
|
18
25
|
if (cachedData) {
|
|
19
26
|
const product = (0, libs_1.decompressJSON)(cachedData.productCompressed);
|
|
20
27
|
return product;
|
|
21
28
|
}
|
|
22
29
|
return undefined;
|
|
23
30
|
};
|
|
31
|
+
getProductCache = async (pixelId, productId) => {
|
|
32
|
+
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
33
|
+
const cachedData = await this.genericCacheService.getCachedData(cacheKey);
|
|
34
|
+
return cachedData;
|
|
35
|
+
};
|
|
24
36
|
putProductInCache = async (pixelId, productId, product, ttlInDays) => {
|
|
25
37
|
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
26
38
|
const ttl = ttlInDays || 7;
|
|
27
39
|
const expiresAt = luxon_1.DateTime.now().plus({ days: ttl }).toSeconds();
|
|
40
|
+
const cachedAtEpoch = luxon_1.DateTime.now().toSeconds();
|
|
41
|
+
const fullSha256 = crypto_1.default.createHash('sha256').update(JSON.stringify(product)).digest('hex');
|
|
42
|
+
const noInventoryProduct = { ...product, totalInventory: undefined, variants: product?.variants?.map(variant => ({ ...variant, inventoryQuantity: undefined, inventoryItem: undefined })) };
|
|
43
|
+
const noInventorySha256 = crypto_1.default.createHash('sha256').update(JSON.stringify(noInventoryProduct)).digest('hex');
|
|
28
44
|
const productCompressed = (0, libs_1.compressJSON)(product);
|
|
29
|
-
await this.genericCacheService.putCachedData(cacheKey, { productCompressed, expiresAt });
|
|
45
|
+
await this.genericCacheService.putCachedData(cacheKey, { productCompressed, expiresAt, cachedAtEpoch, fullSha256, noInventorySha256 });
|
|
30
46
|
};
|
|
31
47
|
deleteProductFromCache = async (pixelId, productId) => {
|
|
32
48
|
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-cache-service.js","sourceRoot":"","sources":["../../../../src/services/cache/product-cache-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-cache-service.js","sourceRoot":"","sources":["../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AI,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,MAAM,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC,CAAA;CACF;AApCD,kDAoCC"}
|
|
@@ -27,9 +27,6 @@ class ShopifyProductsServiceV2 {
|
|
|
27
27
|
helpers_1.Logger.debug('getShopifyProduct: Product found in ShopifyAPI, putting in cache', { pixelId, productId, product });
|
|
28
28
|
await this.productCacheService.putProductInCache(pixelId, productId, product);
|
|
29
29
|
}
|
|
30
|
-
if (!getShopifyProductResponse?.transformedProduct) {
|
|
31
|
-
helpers_1.Logger.error('getShopifyProduct: Product not found in ShopifyAPI or cache', { pixelId, shop, productId });
|
|
32
|
-
}
|
|
33
30
|
helpers_1.Logger.debug('getShopifyProduct: Returning product', { pixelId, shop, productId, product: getShopifyProductResponse?.transformedProduct });
|
|
34
31
|
return getShopifyProductResponse;
|
|
35
32
|
}
|
|
@@ -53,7 +50,7 @@ class ShopifyProductsServiceV2 {
|
|
|
53
50
|
return getShopifyProductResponse;
|
|
54
51
|
}
|
|
55
52
|
else {
|
|
56
|
-
helpers_1.Logger.error('getShopifyProductFromAPI: Product
|
|
53
|
+
helpers_1.Logger.error('getShopifyProductFromAPI: Product ShopifyAPI error', { pixelId, shop, productId, error: response?.errors });
|
|
57
54
|
return getShopifyProductResponse;
|
|
58
55
|
}
|
|
59
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shopify-products-serviceV2.js","sourceRoot":"","sources":["../../../../../src/services/shopify/products/shopify-products-serviceV2.ts"],"names":[],"mappings":";;;AAAA,8CAA0C;AAG1C,6EAAwE;AACxE,gFAA2E;AAC3E,wGAAmG;AAQnG,MAAa,wBAAwB;IAE3B,mBAAmB,CAAsB;IACjD,YAAY,sBAA8B;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,2CAAmB,CAAC,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IAEM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,IAAY,EAAE,WAAmB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAA6C,EAAE;QACzL,IAAI;YACF,IAAI,yBAAyB,GAAqC,EAAE,CAAC;YACrE,IAAI,QAAQ,EAAE;gBAEZ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBACvF,IAAI,OAAO,EAAE;oBACX,gBAAM,CAAC,KAAK,CAAC,2CAA2C,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;oBACjG,yBAAyB,CAAC,kBAAkB,GAAG,OAAO,CAAC;oBACvD,OAAO,yBAAyB,CAAC;iBAClC;aACF;YAED,yBAAyB,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;YAC7G,IAAI,yBAAyB,EAAE,kBAAkB,IAAI,WAAW,EAAE;gBAChE,MAAM,OAAO,GAAG,yBAAyB,CAAC,kBAAkB,CAAC;gBAC7D,gBAAM,CAAC,KAAK,CAAC,kEAAkE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBAClH,MAAM,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;aAC/E;
|
|
1
|
+
{"version":3,"file":"shopify-products-serviceV2.js","sourceRoot":"","sources":["../../../../../src/services/shopify/products/shopify-products-serviceV2.ts"],"names":[],"mappings":";;;AAAA,8CAA0C;AAG1C,6EAAwE;AACxE,gFAA2E;AAC3E,wGAAmG;AAQnG,MAAa,wBAAwB;IAE3B,mBAAmB,CAAsB;IACjD,YAAY,sBAA8B;QACxC,IAAI,CAAC,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E,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;YACtJ,OAAO,IAAI,CAAC;SACb;IACH,CAAC,CAAA;CACF;AA3DD,4DA2DC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generic-cached-object.js","sourceRoot":"","sources":["../../../../src/services/cache/generic-cached-object.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { InternalProduct } from '../shopify/types/product';
|
|
2
|
-
|
|
2
|
+
import { GenericCachedObject } from './generic-cached-object';
|
|
3
|
+
export interface ProductCache extends GenericCachedObject {
|
|
3
4
|
productCompressed: string;
|
|
4
|
-
|
|
5
|
+
fullSha256?: string;
|
|
6
|
+
noInventorySha256?: string;
|
|
5
7
|
}
|
|
8
|
+
export declare const getProductCacheKey: (pixelId: string, productId: string) => string;
|
|
6
9
|
export declare class ProductCacheService {
|
|
7
10
|
private genericCacheService;
|
|
8
11
|
constructor(cacheLambdaFunctionArn: string);
|
|
9
12
|
getCacheKey: (pixelId: string, productId: string) => string;
|
|
10
13
|
getProductFromCache: (pixelId: string, productId: string) => Promise<InternalProduct | undefined>;
|
|
14
|
+
getProductCache: (pixelId: string, productId: string) => Promise<ProductCache | undefined>;
|
|
11
15
|
putProductInCache: (pixelId: string, productId: string, product: InternalProduct, ttlInDays?: number) => Promise<void>;
|
|
12
16
|
deleteProductFromCache: (pixelId: string, productId: string) => Promise<void>;
|
|
13
17
|
}
|
|
@@ -1,29 +1,41 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
import { GenericCacheService } from '../generic-cache-service';
|
|
3
3
|
import { compressJSON, decompressJSON } from '../../libs';
|
|
4
|
+
import crypto from 'crypto';
|
|
5
|
+
export const getProductCacheKey = (pixelId, productId) => {
|
|
6
|
+
return `internal:product:${pixelId}_${productId}`;
|
|
7
|
+
};
|
|
4
8
|
export class ProductCacheService {
|
|
5
9
|
genericCacheService;
|
|
6
10
|
constructor(cacheLambdaFunctionArn) {
|
|
7
11
|
this.genericCacheService = new GenericCacheService(cacheLambdaFunctionArn);
|
|
8
12
|
}
|
|
9
13
|
getCacheKey = (pixelId, productId) => {
|
|
10
|
-
return
|
|
14
|
+
return getProductCacheKey(pixelId, productId);
|
|
11
15
|
};
|
|
12
16
|
getProductFromCache = async (pixelId, productId) => {
|
|
13
|
-
const
|
|
14
|
-
const cachedData = await this.genericCacheService.getCachedData(cacheKey);
|
|
17
|
+
const cachedData = await this.getProductCache(pixelId, productId);
|
|
15
18
|
if (cachedData) {
|
|
16
19
|
const product = decompressJSON(cachedData.productCompressed);
|
|
17
20
|
return product;
|
|
18
21
|
}
|
|
19
22
|
return undefined;
|
|
20
23
|
};
|
|
24
|
+
getProductCache = async (pixelId, productId) => {
|
|
25
|
+
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
26
|
+
const cachedData = await this.genericCacheService.getCachedData(cacheKey);
|
|
27
|
+
return cachedData;
|
|
28
|
+
};
|
|
21
29
|
putProductInCache = async (pixelId, productId, product, ttlInDays) => {
|
|
22
30
|
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
23
31
|
const ttl = ttlInDays || 7;
|
|
24
32
|
const expiresAt = DateTime.now().plus({ days: ttl }).toSeconds();
|
|
33
|
+
const cachedAtEpoch = DateTime.now().toSeconds();
|
|
34
|
+
const fullSha256 = crypto.createHash('sha256').update(JSON.stringify(product)).digest('hex');
|
|
35
|
+
const noInventoryProduct = { ...product, totalInventory: undefined, variants: product?.variants?.map(variant => ({ ...variant, inventoryQuantity: undefined, inventoryItem: undefined })) };
|
|
36
|
+
const noInventorySha256 = crypto.createHash('sha256').update(JSON.stringify(noInventoryProduct)).digest('hex');
|
|
25
37
|
const productCompressed = compressJSON(product);
|
|
26
|
-
await this.genericCacheService.putCachedData(cacheKey, { productCompressed, expiresAt });
|
|
38
|
+
await this.genericCacheService.putCachedData(cacheKey, { productCompressed, expiresAt, cachedAtEpoch, fullSha256, noInventorySha256 });
|
|
27
39
|
};
|
|
28
40
|
deleteProductFromCache = async (pixelId, productId) => {
|
|
29
41
|
const cacheKey = this.getCacheKey(pixelId, productId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-cache-service.js","sourceRoot":"","sources":["../../../../src/services/cache/product-cache-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"product-cache-service.js","sourceRoot":"","sources":["../../../../src/services/cache/product-cache-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAQ5B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;IACvE,OAAO,oBAAoB,OAAO,IAAI,SAAS,EAAE,CAAC;AACpD,CAAC,CAAA;AAED,MAAM,OAAO,mBAAmB;IACtB,mBAAmB,CAAsB;IACjD,YAAY,sBAA8B;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IACM,WAAW,GAAG,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;QAC1D,OAAO,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC,CAAA;IACM,mBAAmB,GAAG,KAAK,EAAE,OAAe,EAAE,SAAiB,EAAwC,EAAE;QAC9G,MAAM,UAA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AAC,EAAE,GAAG,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC;QAC7M,MAAM,iBAAiB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/G,MAAM,iBAAiB,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,iBAAiB,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACzI,CAAC,CAAA;IACM,sBAAsB,GAAG,KAAK,EAAE,OAAe,EAAE,SAAiB,EAAE,EAAE;QAC3E,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACtD,MAAM,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC5D,CAAC,CAAA;CACF"}
|
|
@@ -24,9 +24,6 @@ export class ShopifyProductsServiceV2 {
|
|
|
24
24
|
Logger.debug('getShopifyProduct: Product found in ShopifyAPI, putting in cache', { pixelId, productId, product });
|
|
25
25
|
await this.productCacheService.putProductInCache(pixelId, productId, product);
|
|
26
26
|
}
|
|
27
|
-
if (!getShopifyProductResponse?.transformedProduct) {
|
|
28
|
-
Logger.error('getShopifyProduct: Product not found in ShopifyAPI or cache', { pixelId, shop, productId });
|
|
29
|
-
}
|
|
30
27
|
Logger.debug('getShopifyProduct: Returning product', { pixelId, shop, productId, product: getShopifyProductResponse?.transformedProduct });
|
|
31
28
|
return getShopifyProductResponse;
|
|
32
29
|
}
|
|
@@ -50,7 +47,7 @@ export class ShopifyProductsServiceV2 {
|
|
|
50
47
|
return getShopifyProductResponse;
|
|
51
48
|
}
|
|
52
49
|
else {
|
|
53
|
-
Logger.error('getShopifyProductFromAPI: Product
|
|
50
|
+
Logger.error('getShopifyProductFromAPI: Product ShopifyAPI error', { pixelId, shop, productId, error: response?.errors });
|
|
54
51
|
return getShopifyProductResponse;
|
|
55
52
|
}
|
|
56
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shopify-products-serviceV2.js","sourceRoot":"","sources":["../../../../../src/services/shopify/products/shopify-products-serviceV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AAQnG,MAAM,OAAO,wBAAwB;IAE3B,mBAAmB,CAAsB;IACjD,YAAY,sBAA8B;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IAEM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,IAAY,EAAE,WAAmB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAA6C,EAAE;QACzL,IAAI;YACF,IAAI,yBAAyB,GAAqC,EAAE,CAAC;YACrE,IAAI,QAAQ,EAAE;gBAEZ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBACvF,IAAI,OAAO,EAAE;oBACX,MAAM,CAAC,KAAK,CAAC,2CAA2C,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;oBACjG,yBAAyB,CAAC,kBAAkB,GAAG,OAAO,CAAC;oBACvD,OAAO,yBAAyB,CAAC;iBAClC;aACF;YAED,yBAAyB,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;YAC7G,IAAI,yBAAyB,EAAE,kBAAkB,IAAI,WAAW,EAAE;gBAChE,MAAM,OAAO,GAAG,yBAAyB,CAAC,kBAAkB,CAAC;gBAC7D,MAAM,CAAC,KAAK,CAAC,kEAAkE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;gBAClH,MAAM,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;aAC/E;
|
|
1
|
+
{"version":3,"file":"shopify-products-serviceV2.js","sourceRoot":"","sources":["../../../../../src/services/shopify/products/shopify-products-serviceV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6DAA6D,CAAC;AAQnG,MAAM,OAAO,wBAAwB;IAE3B,mBAAmB,CAAsB;IACjD,YAAY,sBAA8B;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;IAC7E,CAAC;IAEM,iBAAiB,GAAG,KAAK,EAAE,OAAe,EAAE,IAAY,EAAE,WAAmB,EAAE,SAAiB,EAAE,QAAQ,GAAG,IAAI,EAAE,WAAW,GAAG,IAAI,EAA6C,EAAE;QACzL,IAAI;YACF,IAAI,yBAAyB,GAAqC,EAAE,CAAC;YACrE,IAAI,QAAQ,EAAE;gBAEZ,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;gBAC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