Skip to content

Commit f125a82

Browse files
committed
fix: types
1 parent e109ef1 commit f125a82

File tree

1 file changed

+35
-25
lines changed
  • packages/product-json-to-csv/src

1 file changed

+35
-25
lines changed

packages/product-json-to-csv/src/main.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk
2424
import { createUserAgentMiddleware } from '@commercetools/sdk-middleware-user-agent'
2525
import highland from 'highland'
2626
import fetch from 'node-fetch'
27-
import Promise from 'bluebird'
27+
import PromiseBlueBird from 'bluebird'
2828
import JSONStream from 'JSONStream'
2929
import { memoize, map, get, pick, chunk, flatten } from 'lodash'
3030
import ProductMapping from './map-product-data'
@@ -163,14 +163,14 @@ export default class ProductJsonToCsv {
163163
// **CategoryOrderHints
164164
// **Variant prices
165165

166-
return Promise.all([
166+
return PromiseBlueBird.all([
167167
this._resolveProductType(product.productType),
168168
this._resolveTaxCategory(product.taxCategory),
169169
this._resolveState(product.state),
170170
this._resolveCategories(product.categories),
171171
this._resolveCategoryOrderHints(product.categoryOrderHints),
172172
this._resolveVariantReferences(product.masterVariant),
173-
Promise.map(
173+
PromiseBlueBird.map(
174174
product.variants,
175175
(variant: Variant) => this._resolveVariantReferences(variant),
176176
{ concurrency: 3 }
@@ -226,7 +226,7 @@ export default class ProductJsonToCsv {
226226
...(await acc),
227227
...(await this._getChannelsById(currentIds)),
228228
}),
229-
Promise.resolve({})
229+
PromiseBlueBird.resolve({})
230230
)
231231
} else {
232232
channelsById = await this._getChannelsById(channelIds)
@@ -240,7 +240,7 @@ export default class ProductJsonToCsv {
240240
...(await acc),
241241
...(await this._getCustomerGroupsById(currentIds)),
242242
}),
243-
Promise.resolve({})
243+
PromiseBlueBird.resolve({})
244244
)
245245
} else {
246246
customerGroupsById = await this._getCustomerGroupsById(customerGroupIds)
@@ -324,29 +324,35 @@ export default class ProductJsonToCsv {
324324
325325
const productTypeService = this._createService('productTypes')
326326
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+
)
330332
}
331333
332334
_resolveTaxCategory(taxCategoryReference: TypeReference): Object {
333335
if (!taxCategoryReference) return {}
334336
335337
const taxCategoryService = this._createService('taxCategories')
336338
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+
)
340344
}
341345
342346
_resolveState(stateReference: TypeReference): Object {
343347
if (!stateReference) return {}
344348
345349
const stateService = this._createService('states')
346350
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+
)
350356
}
351357
352358
_resolveCategories(
@@ -359,8 +365,9 @@ export default class ProductJsonToCsv {
359365
return this._getCategories(categoryIds).then(
360366
(categories: Array<Category>): { categories: Array<Category> } => {
361367
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)
364371
).then((categoriesWithParents: Array<Category>): Object => ({
365372
categories: categoriesWithParents,
366373
}))
@@ -395,13 +402,16 @@ export default class ProductJsonToCsv {
395402
396403
_resolveAncestors(category: Category): Promise<Category> {
397404
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+
)
405415
}
406416
return getParent(category)
407417
}
@@ -415,7 +425,7 @@ export default class ProductJsonToCsv {
415425
cachedCategories.push(this.categoriesCache[id])
416426
else notCachedIds.push(id)
417427
})
418-
if (!notCachedIds.length) return Promise.resolve(cachedCategories)
428+
if (!notCachedIds.length) return PromiseBlueBird.resolve(cachedCategories)
419429
420430
const predicate = `id in ("${notCachedIds.join('", "')}")`
421431
const categoriesService = this._createService('categories')
@@ -454,6 +464,6 @@ ProductJsonToCsv.prototype.fetchReferences = memoize(function _fetchReferences(
454464
}
455465
return this.client.process(
456466
request,
457-
(res: SuccessResult): Promise<SuccessResult> => Promise.resolve(res)
467+
(res: SuccessResult): Promise<SuccessResult> => PromiseBlueBird.resolve(res)
458468
)
459469
})

0 commit comments

Comments
 (0)