commercetools / nodejs Goto Github PK
View Code? Open in Web Editor NEWEverything related to the Node.js ecosystem for the commercetools platform.
Home Page: https://commercetools.github.io/nodejs/
License: MIT License
Everything related to the Node.js ecosystem for the commercetools platform.
Home Page: https://commercetools.github.io/nodejs/
License: MIT License
Looks like the URL structure changed, e.g:
https://commercetools.github.io/nodejs/docs/sdk/api/#sdk-middleware-user-agent
to:
https://commercetools.github.io/nodejs/sdk/api/sdkMiddlewareUserAgent.html
Also title's still include the 'commercetools' prefix.
When an empty string is provided as the orderHint
of a category an invalid sync-action
is generated.
I created the following tests which should succeed but fail currently (first one fails, second one is to ensure we don't change existing behaviour and currently succeeds):
// nodejs/packages/sync-actions/test/category-sync.spec.js
describe('changeOrderHint', () => {
describe('when setting to an empty string', () => {
it('should build a `changeOrderHint` action', () => {
const before = { orderHint: 'foo' }
const now = { orderHint: '' }
const actual = categorySync.buildActions(now, before)
const expected = [
{
action: 'changeOrderHint',
value: '',
},
]
expect(actual).toEqual(expected)
})
})
describe('when not provided', () => {
it('should not build an update action', () => {
const before = { orderHint: 'foo' }
const now = {}
const actual = categorySync.buildActions(now, before)
const expected = []
expect(actual).toEqual(expected)
})
})
})
The following sync-actions should be generated in the first case:
[
{
action: 'changeOrderHint',
value: '',
},
]
The following sync action is generated in the first case:
[
{
action: 'changeOrderHint',
},
]
This is an invalid sync action as value
is a required field. Providing an empty string as the value is valid and supported by the API.
In the MC, when trying to let users set an empty orderHint
for a category they get an API error instead of having the changes saved successfully.
I tried to push a failing test so you could work on that, but I don't have sufficient permissions to this repository :( You can add the snippet I provided above to the Actions
section of the tests.
We would like to add a support for ShoppingList endpoint on Impex and therefore we should add it also here to api-request-builder.
Not supported currently.
Add an endpoint specification to the list of default services here.
Currently we use Greenkeeper but it does only update the dependencies in the root package.json. The check-updates
npm script solves this but does not seem to be triggered automatically anywhere. We can trigger it after CI tests so every time before a PR is merged the dependencies need to be updated. Another option is using Travis new cron jobs in combination with Renovate
Currently it's not possible to enable price selection when querying via the product projection endpoint
Should support price selection
Only staged
query params is supported
The headers object is missing from the response.
Should include the headers in the response
the response header is striped out.
exec
(request shape)process
(request shape, must be a GET request, fn must be a function)Title says it all
http://dev.commercetools.com/http-api-projects-products-search.html#search-productprojections
Add in query-search
feature
fuzzyLevel
markMatchingVariants
Title says it all ๐
It would be nice to have a project endpoint also in the list of default endpoints here https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js
It should be enough to add this configuration to the list mentioned above:
project: {
type: 'project',
endpoint: '/',
features: [
features.query
]
}
Have a package that retrieves the API credentials from a system like the one we have in the old utils repository. Trying to simplify the behaviour of getting the credentials I came up with three steps. The package will return a promise since it could need to read from the FS.
CT_<project key>
containing <client id>:<client secret>
.CT_PROJECT_KEY
, CT_CLIENT_ID
, CT_CLIENT_SECRET
.ct-credentials.env
from the current or etc
directory.This is needed to move on with #27 and good to have for future packages. Avoiding logic duplication like over multiple packages like in csv-parser-price.
Thoughts?
The user agent is set in few commercetools Node.js modules but not in all. To maintain consistency and also to traceback on logs, we need this user agent to be set in all projects.
Have all the tools set the user agent following this pattern, like it is done in sphere-order-export.
We would like to measure the usage of each module in Kibana.
I'm trying to use the node sdk to upload a product image to commercetools. I'm currently using code that looks like:
// let's upload to the product's images endpoint
let imgType = mime.lookup(tmpFile);
let img = fs.readFileSync(tmpFile);
const pimgUri = requestBuilder.products.byId(existingProduct.id).build({ projectKey: projectKey });
const addImageRequest = {uri: pimgUri + '/images', method: "POST", headers: {'Content-Type': imgType}, body:img};
/// This won't work with current ct sdk
client.execute(addImageRequest).catch((e) => {
console.log(e);
process.exit(45);
});
I noticed that under the hood, the node sdk uses node-fetch, which would support sending a stream or buffer object as the request body. However, the sdk seems to drop that support in favor of ensuring every body is sent as JSON.
I'd expect to be able to upload an image to the product's images endpoint using the node sdk.
The sdk middleware seems to be JSON.stringify()'ing my Buffer/Stream object and sending that to commercetools, resulting in a 'This jpg encoding is not supported' error from commercetools.
While writing an importer for a potential customer, I needed to import their product images as well. I am currently unable to do so using the node sdk. I am able to use a call to curl, or a custom Request object to accomplish this in the meantime.
I'm not entirely sure, but https://github.com/commercetools/nodejs/blob/master/packages/sdk-middleware-http/src/http.js#L25 looks like it would cause this issue
The amount of flow type warnings are building up making it very hard to see new warnings and making me sad when running the linting task. :(
packages/api-request-builder/src/build-query-string.js:26:49
โ 26:49 Missing return type annotation. flowtype/require-return-type
โ 26:49 Missing "e" parameter type annotation. flowtype/require-parameter-type
โ 45:49 Missing return type annotation. flowtype/require-return-type
โ 45:49 Missing "s" parameter type annotation. flowtype/require-parameter-type
โ 58:19 Missing return type annotation. flowtype/require-return-type
โ 58:19 Missing "f" parameter type annotation. flowtype/require-parameter-type
โ 59:20 Missing "f" parameter type annotation. flowtype/require-parameter-type
โ 59:20 Missing return type annotation. flowtype/require-return-type
โ 60:27 Missing return type annotation. flowtype/require-return-type
โ 60:27 Missing "f" parameter type annotation. flowtype/require-parameter-type
โ 61:28 Missing return type annotation. flowtype/require-return-type
โ 61:28 Missing "f" parameter type annotation. flowtype/require-parameter-type
packages/api-request-builder/src/create-request-builder.js:13:42
โ 13:42 Missing return type annotation. flowtype/require-return-type
โ 13:43 Missing "acc" parameter type annotation. flowtype/require-parameter-type
โ 13:48 Missing "key" parameter type annotation. flowtype/require-parameter-type
packages/api-request-builder/src/create-service.js:53:23
โ 53:23 Missing return type annotation. flowtype/require-return-type
โ 53:24 Missing "acc" parameter type annotation. flowtype/require-parameter-type
โ 53:29 Missing "feature" parameter type annotation. flowtype/require-parameter-type
packages/sdk-client/src/client.js:34:27
โ 34:27 Missing "resolve" parameter type annotation. flowtype/require-parameter-type
โ 34:36 Missing "reject" parameter type annotation. flowtype/require-parameter-type
โ 68:27 Missing "resolve" parameter type annotation. flowtype/require-parameter-type
โ 68:36 Missing "reject" parameter type annotation. flowtype/require-parameter-type
โ 125:24 Missing return type annotation. flowtype/require-return-type
โ 125:24 Missing "func" parameter type annotation. flowtype/require-parameter-type
โ 130:23 Missing return type annotation. flowtype/require-return-type
โ 130:24 Missing "a" parameter type annotation. flowtype/require-parameter-type
โ 130:27 Missing "b" parameter type annotation. flowtype/require-parameter-type
โ 130:33 Missing return type annotation. flowtype/require-return-type
โ 130:34 Missing "args" parameter type annotation. flowtype/require-parameter-type
packages/sdk-middleware-auth/src/build-requests.js:44:3
โ 44:3 Unexpected todo comment. no-warning-comments
โ 48:3 Unexpected todo comment. no-warning-comments
โ 52:3 Unexpected todo comment. no-warning-comments
packages/sdk-middleware-auth/src/client-credentials-flow.js:29:10
โ 29:10 Missing return type annotation. flowtype/require-return-type
โ 29:10 Missing "next" parameter type annotation. flowtype/require-parameter-type
โ 92:35 Missing "task" parameter type annotation. flowtype/require-parameter-type
โ 113:13 Missing "error" parameter type annotation. flowtype/require-parameter-type
packages/sdk-middleware-http/src/http.js:21:10
โ 21:10 Missing return type annotation. flowtype/require-return-type
โ 21:10 Missing "next" parameter type annotation. flowtype/require-parameter-type
โ 97:23 Missing "{ statusCode, message, ...rest }" parameter type annotation. flowtype/require-parameter-type
packages/sdk-middleware-logger/src/logger.js:9:10
โ 9:10 Missing return type annotation. flowtype/require-return-type
โ 9:10 Missing "next" parameter type annotation. flowtype/require-parameter-type
โ 11:5 Unexpected console statement. no-console
โ 12:5 Unexpected console statement. no-console
packages/sdk-middleware-logger/test/logger.spec.js:21:28
โ 21:28 Unexpected console statement. no-console
โ 26:5 Unexpected console statement. no-console
โ 31:5 Unexpected console statement. no-console
โ 51:14 Unexpected console statement. no-console
โ 52:14 Unexpected console statement. no-console
โ 56:14 Unexpected console statement. no-console
packages/sdk-middleware-queue/src/queue.js:35:10
โ 35:10 Missing return type annotation. flowtype/require-return-type
โ 35:10 Missing "next" parameter type annotation. flowtype/require-parameter-type
packages/sdk-middleware-user-agent/src/user-agent.js:18:10
โ 18:10 Missing return type annotation. flowtype/require-return-type
โ 18:10 Missing "next" parameter type annotation. flowtype/require-parameter-type
packages/sync-actions/src/categories.js:16:1
โ 16:1 Missing return type annotation. flowtype/require-return-type
โ 16:36 Missing "mapActionGroup" parameter type annotation. flowtype/require-parameter-type
โ 17:10 Missing return type annotation. flowtype/require-return-type
โ 17:33 Missing "diff" parameter type annotation. flowtype/require-parameter-type
โ 17:39 Missing "newObj" parameter type annotation. flowtype/require-parameter-type
โ 17:47 Missing "oldObj" parameter type annotation. flowtype/require-parameter-type
โ 20:44 Missing return type annotation. flowtype/require-return-type
โ 23:50 Missing return type annotation. flowtype/require-return-type
โ 26:44 Missing return type annotation. flowtype/require-return-type
โ 29:46 Missing return type annotation. flowtype/require-return-type
packages/sync-actions/src/customers.js:16:1
โ 16:1 Missing return type annotation. flowtype/require-return-type
โ 16:36 Missing "mapActionGroup" parameter type annotation. flowtype/require-parameter-type
โ 17:10 Missing return type annotation. flowtype/require-return-type
โ 17:33 Missing "diff" parameter type annotation. flowtype/require-parameter-type
โ 17:39 Missing "newObj" parameter type annotation. flowtype/require-parameter-type
โ 17:47 Missing "oldObj" parameter type annotation. flowtype/require-parameter-type
โ 20:44 Missing return type annotation. flowtype/require-return-type
โ 23:50 Missing return type annotation. flowtype/require-return-type
โ 26:49 Missing return type annotation. flowtype/require-return-type
packages/sync-actions/src/inventories.js:16:1
โ 16:1 Missing return type annotation. flowtype/require-return-type
โ 16:37 Missing "mapActionGroup" parameter type annotation. flowtype/require-parameter-type
โ 17:10 Missing return type annotation. flowtype/require-return-type
โ 17:33 Missing "diff" parameter type annotation. flowtype/require-parameter-type
โ 17:39 Missing "newObj" parameter type annotation. flowtype/require-parameter-type
โ 17:47 Missing "oldObj" parameter type annotation. flowtype/require-parameter-type
โ 20:44 Missing return type annotation. flowtype/require-return-type
โ 23:50 Missing return type annotation. flowtype/require-return-type
packages/sync-actions/src/orders.js:17:1
โ 17:1 Missing return type annotation. flowtype/require-return-type
โ 17:33 Missing "mapActionGroup" parameter type annotation. flowtype/require-parameter-type
โ 18:10 Missing return type annotation. flowtype/require-return-type
โ 18:33 Missing "diff" parameter type annotation. flowtype/require-parameter-type
โ 18:39 Missing "newObj" parameter type annotation. flowtype/require-parameter-type
โ 18:47 Missing "oldObj" parameter type annotation. flowtype/require-parameter-type
โ 21:44 Missing return type annotation. flowtype/require-return-type
โ 24:50 Missing return type annotation. flowtype/require-return-type
packages/sync-actions/src/products.js:23:1
โ 23:1 Missing return type annotation. flowtype/require-return-type
โ 23:35 Missing "mapActionGroup" parameter type annotation. flowtype/require-parameter-type
โ 24:10 Missing return type annotation. flowtype/require-return-type
โ 24:33 Missing "diff" parameter type annotation. flowtype/require-parameter-type
โ 24:39 Missing "newObj" parameter type annotation. flowtype/require-parameter-type
โ 24:47 Missing "oldObj" parameter type annotation. flowtype/require-parameter-type
โ 24:55 Missing "options" parameter type annotation. flowtype/require-parameter-type
โ 28:44 Missing return type annotation. flowtype/require-return-type
โ 31:44 Missing return type annotation. flowtype/require-return-type
โ 34:50 Missing return type annotation. flowtype/require-return-type
โ 37:48 Missing return type annotation. flowtype/require-return-type
โ 40:50 Missing return type annotation. flowtype/require-return-type
โ 44:46 Missing return type annotation. flowtype/require-return-type
โ 47:46 Missing return type annotation. flowtype/require-return-type
โ 50:50 Missing return type annotation. flowtype/require-return-type
To prevent this from happening in the future let's run ESLint on CI with --max-warnings 0
so it fails.
The product category order hint of a update action is not supported by the sync-action module
Fix this failing integration test
Docs on https://commercetools.github.io/nodejs/sdk/api/sdkMiddlewareAuth.html are out of date? Host has no default value anymore.
#56 (comment)
@emmenko
Currently to do a delete, you have to manually add the version to the uri.
I find the user experience of this very bad, especially when compared to the old SDK
Should expose a method like service.delete(versionNumber).build()
Example of current behaviour can be found here
Currently get requests return only 20 per page. If you want more (or less), you have to manually add &limit=number
to the uri
Should expose a method like service.limit(number).build()
Something like this has to be done:
const uri = `${service.build()}?limit=100`
At the moment, if you try to add/change a inventory quantity with number "0" the API returns a bad request error
export function buildBaseAttributesActions ({
actions,
diff,
oldObj,
newObj,
}) {
return actions
.map((item) => {
const key = item.key // e.g.: name, description, ...
const actionKey = item.actionKey || item.key
const delta = diff[key]
const before = oldObj[key]
const now = newObj[key]
if (!delta) return undefined
if (!now && !before) return undefined
if (now && !before) // no value previously set
return { action: item.action, [actionKey]: now }
if (!now && !{}.hasOwnProperty.call(newObj, key)) // no new value
return undefined
if (!now && {}.hasOwnProperty.call(newObj, key)) // value unset
return { action: item.action }
})
.filter(action => action)
}
It should assemble the correct request body
Its assembling the request body without a required field (quantity).
This is happening because 0 is falsy, and on the buildBaseAttributesActions function it relies only on the value in order to define what to return
Maybe adding a variable to check the existence of the value (hasNow
and hasBefore
), so 0 wouldn't return false in this case.
In the sphere-node-sdk, it was possible to pass in the token to the client object and it will skip generating another token for the request.
This feature is currently missing in the sdk-middleware-auth middleware.
// sphere-node-sdk
client = new SphereClient
config:
project_key: projectKey
access_token: token['access_token'] // not possible with new SDK
It should accept the token parameter and if present, use it to authenticate subsequent request.
Does not accept valid token.
Using the auth middleware does not work in Node.js because of this piece of code:
export function getBasicAuth (
username: string,
password: string,
windowObject: Object = window,
): string {
const basicAuth = `${username}:${password}`
if (
windowObject &&
windowObject.btoa &&
typeof windowObject.btoa === 'function'
)
return windowObject.btoa(basicAuth)
return new Buffer(basicAuth).toString('base64')
}
So windowObject
falls back to window
which will be undefined.
I propose to follow this approach which Abi found online:
https://nolanlawson.com/2017/01/09/how-to-write-a-javascript-package-for-both-node-and-the-browser/
Funny enough the author created a package for this which we can use: base64-encode-string
.
Move the csv-parser-orders
module to this repository.
Doing this will also require changes to the code of the module and some additional steps:
package.json
fields and development dependenciesLet's remove the commercetools-
before each package directory, it's pretty annoying to type in the CLI and makes my editor sidebar unnecessarily wide. :)
Any objections?
After reading this it got me thinking on how to enforce the git commit message. It seems that only with GitHub Enterprise you can define server side hooks but what we can do is: only allow rebasing PRs that pass the CI and adding a commit message check at the CI. Shouldn't be to difficult to do and prevents any possibility of human error.
Thoughts? @hisabimbola @emmenko
There are 4 new query parameters used by the projections endpoint (and search).
http://dev.commercetools.com/http-api-projects-productProjections.html#get-productprojection-by-id
http://dev.commercetools.com/http-api-projects-products-search.html#search-productprojections
They should be put into a new separate feature (e.g. query-price-selection
)
priceCurrency
priceCountry
(requires priceCurrency
)priceCustomerGroup
(requires priceCurrency
)priceChannel
(requires priceCurrency
)A new module to generate discount codes
Instead of passing it every time as option of .build()
, pass it once to createRequestBuilder
.
It's a BREAKING CHANGE
Let's discuss if we want to use exact versions or semver ranges for the development dependencies.
I would vote for using semver ranges to decrease the amount of Greenkeeper PRs. And feel confident in doing this because we have the dependency lockfile.
A duplicate of this issue
Instead of implementing it there, it will be implemented here.
Fixes commercetools/sphere-node-sdk#207
For description see this task: commercetools/sphere-node-product-csv-sync#163
And this fix in the old SDK: commercetools/sphere-node-sdk#226
Currently the price-parser outputs the sku field wrongly, this is is not understood by the price-importer module. Changing the field of the sku from variant-sku
to sku
should fix the issue
Correct output data should look like this
{
"prices": [
{
"sku": "123",
"prices": [
{
"variant-sku": "123",
"value": {
"centAmount": 2000
},
"custom": {
"type": {
"id": "d1fefedefb1-ee4b-411c-81fe-cd1ab777115d"
},
"fields": {
"measureUnit": "ST",
"basePriceMeasureUnit": ""
}
}
}
]
}
]
}
Current outputed data looks like this
{
"prices": [
{
"variant-sku": "123",
"prices": [
{
"variant-sku": "123",
"value": {
"centAmount": 2000
},
"custom": {
"type": {
"id": "d1fdefb1-ee4b-411c-81fe-cd1ab777115d"
},
"fields": {
"measureUnit": "ST",
"basePriceMeasureUnit": ""
}
}
}
]
}
]
}
For some weird reasons, the csv-parser-price module does not output the correct json data. The currencyCode is missing from the data returned from the module, hence making the data invalid
centAmount
should be added to the data returned from the module
Expected data format
{
"prices": [{
"sku": "123",
"prices": [{
"variant-sku": "123",
"value": {
"centAmount": 5000
"currencyCode": "EUR"
}
}]
}]
}
Current data format
{
"prices": [{
"sku": "123",
"prices": [{
"variant-sku": "123",
"value": {
"centAmount": 5000
}
}]
}]
}
List the packages with their link to the NPM page, version and dependency status in the readme.
http://dev.commercetools.com/http-api-projects-products-suggestions.html
Given the unique query parameters, it might make sense to have them in their own feature
type.
A new module to import new or update existing discount codes to the API
Read batches
Decide if to update or create
Create codes
Update codes
Write documentation
Add integration tests
Provide an automatically build docker container so it can be easily used on any OS.
*talk to @emmenko for more info
Passing https://api.sphere.io/
vs. https://api.sphere.io
makes a difference.
Both should work the same.
My guess is it ends up with a double slash when appending things to the host URL.
I used the URLs that are given at the dev.commercetools.com documentation which failed. Confirmed this for sdk-middleware-http
.
Merge slashes if needed.
Based on the documentation the markMatchingVariants
parameter will add a flag to all variants which match search criteria.
On the API it is by default set to true
but in the new SDK we can only set it to true
because false
value is not sent to the API so there is no chance to turn this feature off.
We should have a possibility to set this feature off or it should be turned off by default.
We have two options:
markMatchingVariants=false
markMatchingVariants(false)
Unlike the old repo, status will always be printed to stdout. This can "disturb" the standard output
Logging should be separated from the output content
This, which is missing in this repo will be a good place to start
Move the csv-parser-price
module to this repository.
Doing this will also require changes to the code of the module and some additional steps:
types
endpoint to the SDK, PRjest-codemods
, replacing it
for test
and then manually grouping all same-function tests in describe blocks and rewriting .then().catch()
chains.package.json
fields and development dependenciesWe started this discussion some time ago. This is the problem that PRs from external contributors don't have access to encrypted variables in travis, for security reasons.
I think for now we can simply disable e.g. integration tests when travis builds such PRs.
@commercetools/node-js wdyt?
A new module to export discount codes from the API
As part of updating discount codes in #143, add sync actions to update discount codes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.