@@ -24,7 +24,7 @@ import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk
24
24
import { createUserAgentMiddleware } from '@commercetools/sdk-middleware-user-agent'
25
25
import highland from 'highland'
26
26
import fetch from 'node-fetch'
27
- import Promise from 'bluebird'
27
+ import PromiseBlueBird from 'bluebird'
28
28
import JSONStream from 'JSONStream'
29
29
import { memoize , map , get , pick , chunk , flatten } from 'lodash'
30
30
import ProductMapping from './map-product-data'
@@ -163,14 +163,14 @@ export default class ProductJsonToCsv {
163
163
// **CategoryOrderHints
164
164
// **Variant prices
165
165
166
- return Promise . all ( [
166
+ return PromiseBlueBird . all ( [
167
167
this . _resolveProductType ( product . productType ) ,
168
168
this . _resolveTaxCategory ( product . taxCategory ) ,
169
169
this . _resolveState ( product . state ) ,
170
170
this . _resolveCategories ( product . categories ) ,
171
171
this . _resolveCategoryOrderHints ( product . categoryOrderHints ) ,
172
172
this . _resolveVariantReferences ( product . masterVariant ) ,
173
- Promise . map (
173
+ PromiseBlueBird . map (
174
174
product . variants ,
175
175
( variant : Variant ) => this . _resolveVariantReferences ( variant ) ,
176
176
{ concurrency : 3 }
@@ -226,7 +226,7 @@ export default class ProductJsonToCsv {
226
226
...( await acc ) ,
227
227
...( await this . _getChannelsById ( currentIds ) ) ,
228
228
} ) ,
229
- Promise . resolve ( { } )
229
+ PromiseBlueBird . resolve ( { } )
230
230
)
231
231
} else {
232
232
channelsById = await this . _getChannelsById ( channelIds )
@@ -240,7 +240,7 @@ export default class ProductJsonToCsv {
240
240
...( await acc ) ,
241
241
...( await this . _getCustomerGroupsById ( currentIds ) ) ,
242
242
} ) ,
243
- Promise . resolve ( { } )
243
+ PromiseBlueBird . resolve ( { } )
244
244
)
245
245
} else {
246
246
customerGroupsById = await this . _getCustomerGroupsById ( customerGroupIds )
@@ -324,29 +324,35 @@ export default class ProductJsonToCsv {
324
324
325
325
const productTypeService = this._createService('productTypes')
326
326
const uri = productTypeService.byId(productTypeReference.id).build()
327
- return this.fetchReferences(uri).then(([{ body }]: SuccessResult): {
328
- productType: ProductType,
329
- } => ({ productType: body }))
327
+ return this.fetchReferences(uri).then(
328
+ ([{ body }]: SuccessResult): {
329
+ productType: ProductType,
330
+ } => ({ productType: body })
331
+ )
330
332
}
331
333
332
334
_resolveTaxCategory(taxCategoryReference: TypeReference): Object {
333
335
if (!taxCategoryReference) return {}
334
336
335
337
const taxCategoryService = this._createService('taxCategories')
336
338
const uri = taxCategoryService.byId(taxCategoryReference.id).build()
337
- return this.fetchReferences(uri).then(([{ body }]: SuccessResult): {
338
- taxCategory: TaxCategory,
339
- } => ({ taxCategory: body }))
339
+ return this.fetchReferences(uri).then(
340
+ ([{ body }]: SuccessResult): {
341
+ taxCategory: TaxCategory,
342
+ } => ({ taxCategory: body })
343
+ )
340
344
}
341
345
342
346
_resolveState(stateReference: TypeReference): Object {
343
347
if (!stateReference) return {}
344
348
345
349
const stateService = this._createService('states')
346
350
const uri = stateService.byId(stateReference.id).build()
347
- return this.fetchReferences(uri).then(([{ body }]: SuccessResult): {
348
- state: State,
349
- } => ({ state: body }))
351
+ return this.fetchReferences(uri).then(
352
+ ([{ body }]: SuccessResult): {
353
+ state: State,
354
+ } => ({ state: body })
355
+ )
350
356
}
351
357
352
358
_resolveCategories(
@@ -359,8 +365,9 @@ export default class ProductJsonToCsv {
359
365
return this._getCategories(categoryIds).then(
360
366
(categories: Array<Category>): { categories: Array<Category> } => {
361
367
if (this.parserConfig.categoryBy !== 'namedPath') return { categories }
362
- return Promise.map(categories, (cat: Category): Array<Category> =>
363
- this._resolveAncestors(cat)
368
+ return PromiseBlueBird.map(
369
+ categories,
370
+ (cat: Category): Promise<Category> => this._resolveAncestors(cat)
364
371
).then((categoriesWithParents: Array<Category>): Object => ({
365
372
categories: categoriesWithParents,
366
373
}))
@@ -395,13 +402,16 @@ export default class ProductJsonToCsv {
395
402
396
403
_resolveAncestors(category: Category): Promise<Category> {
397
404
const getParent = (cat: Category): Promise<Category> => {
398
- if (!cat.parent) return Promise.resolve(cat)
399
-
400
- return this._getCategories([cat.parent.id])
401
- .then((resolvedCategory: Object): Promise<Category> =>
402
- getParent(resolvedCategory[0])
403
- )
404
- .then((parent: Object): Promise<Category> => ({ ...cat, parent }))
405
+ if (!cat.parent) return PromiseBlueBird.resolve(cat)
406
+
407
+ return (
408
+ this._getCategories([cat.parent.id])
409
+ .then((resolvedCategory: Object): Promise<Category> =>
410
+ getParent(resolvedCategory[0])
411
+ )
412
+ // $FlowFixMe: incompatible returns
413
+ .then((parent: Object): Promise<Category> => ({ ...cat, parent }))
414
+ )
405
415
}
406
416
return getParent(category)
407
417
}
@@ -415,7 +425,7 @@ export default class ProductJsonToCsv {
415
425
cachedCategories.push(this.categoriesCache[id])
416
426
else notCachedIds.push(id)
417
427
})
418
- if (!notCachedIds.length) return Promise .resolve(cachedCategories)
428
+ if (!notCachedIds.length) return PromiseBlueBird .resolve(cachedCategories)
419
429
420
430
const predicate = ` id in ( "${notCachedIds.join('" , "')}" ) `
421
431
const categoriesService = this._createService('categories')
@@ -454,6 +464,6 @@ ProductJsonToCsv.prototype.fetchReferences = memoize(function _fetchReferences(
454
464
}
455
465
return this . client . process (
456
466
request ,
457
- ( res : SuccessResult ) : Promise < SuccessResult > => Promise . resolve ( res )
467
+ ( res : SuccessResult ) : Promise < SuccessResult > => PromiseBlueBird . resolve ( res )
458
468
)
459
469
} )
0 commit comments