
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@gradientedge/commercetools-utils
Advanced tools
Provide utility classes and functions for interacting with the commercetools API
An easy-to-use toolkit for working with the commercetools HTTP API: https://docs.commercetools.com/api/
Please note: this API is being built out bit by bit. If you're looking to use a method that doesn't appear to exist, please either raise an issue or feel free to make the change yourself and raise a PR 👍
See full documentation here: API documentation.
We think it's easier to use and less verbose. On the flip side, the official commercetools SDK is more flexible and certainly more complete and up to date.
Simply install the @gradientedge/commercetools-utils
package using your package manager, e.g.:
npm install --save @gradientedge/commercetools-utils
For clarity, we use the term grant to describe the object that holds the access token, refresh token, scope and expiry details.
import { Region, CommercetoolsAuth, CommercetoolsGrant } from '@gradientedge/commercetools-utils'
async function example() {
const auth = new CommercetoolsAuth({
projectKey: 'your-project-key',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
region: Region.EUROPE_GCP,
clientScopes: ['create_anonymous_token']
})
let grant: CommercetoolsGrant
try {
const grant = await auth.getClientGrant()
console.log('Grant:', grant)
} catch (error) {
// 'error' will likely be an instance of CommercetoolsError.
// See the API for full details.
console.error(error)
throw error
}
}
example()
import { Region, CommercetoolsAuth, CommercetoolsGrant } from '@gradientedge/commercetools-utils'
async function example() {
const auth = new CommercetoolsAuth({
projectKey: 'your-project-key',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
region: Region.EUROPE_GCP,
clientScopes: ['create_anonymous_token']
})
let grant: CommercetoolsGrant
try {
const grant = await auth.login({
username: 'myUsername',
password: 'myPassword'
})
console.log('Grant:', grant)
} catch (error) {
console.error(error)
throw error
}
}
example()
Note that the getClientGrant
method here could be swapped out for say, login
, in order to login a customer.
There is no need to call getClientGrant
before calling login
. Ensuring that there's an active client grant
will be taken care of by the CommercetoolsAuth
class.
import { Region, CommercetoolsAuth, CommercetoolsGrant } from '@gradientedge/commercetools-utils'
async function example() {
const auth = new CommercetoolsAuth({
projectKey: 'your-project-key',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
region: Region.EUROPE_GCP,
clientScopes: ['create_anonymous_token']
})
let grant: CommercetoolsGrant
try {
const grant = await auth.getAnonymousGrant()
console.log('Grant:', grant)
} catch (error) {
console.error(error)
throw error
}
}
example()
The code below demonstrates how we can call the refreshCustomerGrant
method with the refreshToken
of an
existing grant. Realistically, that grant would probably have come from something like a JWT that was passed
to your back-end server by your UI.
import { Region, CommercetoolsAuth, CommercetoolsGrant } from '@gradientedge/commercetools-utils'
async function example() {
const auth = new CommercetoolsAuth({
projectKey: 'your-project-key',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
region: Region.EUROPE_GCP,
clientScopes: ['create_anonymous_token']
})
let grant: CommercetoolsGrant
try {
const grant = await auth.login({
username: 'myUsername',
password: 'myPassword'
})
console.log('Grant:', grant)
} catch (error) {
console.error(error)
throw error
}
// The 'grant' would have been
const refreshToken = grant.refreshToken
try {
const grant = await auth.refreshCustomerGrant(refreshToken)
console.log('Refreshed grant:', grant)
} catch (error) {
console.error(error)
throw error
}
}
example()
FAQs
Provide utility classes and functions for interacting with the commercetools API
The npm package @gradientedge/commercetools-utils receives a total of 394 weekly downloads. As such, @gradientedge/commercetools-utils popularity was classified as not popular.
We found that @gradientedge/commercetools-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.