Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@commercelayer/sdk

Package Overview
Dependencies
Maintainers
3
Versions
373
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercelayer/sdk - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

package.json
{
"name": "@commercelayer/sdk",
"version": "2.0.0",
"version": "2.0.1",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "types": "lib/index.d.ts",

@@ -171,3 +171,3 @@ # Commerce Layer JS SDK

// Fetches the SKUs, setting the page number to 3 and the page size to 5
const skus = await Sku.perPage(5).page(3).all()
const skus = await cl.skus.list({ pageNumber: 3, pageSize: 5 })

@@ -200,5 +200,4 @@ // Gets the total number of SKUs in the collection

```
const sku = await Sku.find('xYZkjABcde') // fetches the SKU by ID
const attributes = {
const sku = {
id: 'xYZkjABcde',
description: 'Updated description.',

@@ -208,3 +207,3 @@ imageUrl: 'https://img.yourdomain.com/skus/new-image.png'

sku.update(attributes) // updates the SKU on the server
cl.skus.update(sku) // updates the SKU on the server
```

@@ -219,5 +218,3 @@

```
const sku = await Sku.find('xYZkjABcde') // fetches the SKU by ID
sku.destroy() // persisted deletion
cl.skus.delete('xYZkjABcde') // persisted deletion
```

@@ -229,9 +226,13 @@

If needed, Commerce Layer JS SDK lets you set the configuration at a request level. To do that, just use the `withCredentials()` method and authenticate the API call with the desired credentials:
If needed, Commerce Layer JS SDK lets you change the client configuration set it at a request level. To do that, just use the `config()` method or pass the `options` parameter and authenticate the API call with the desired credentials:
```
const skus = await Sku.withCredentials({
accessToken: 'your-access-token',
endpoint: 'https://yourdomain.commercelayer.io'
}).all()
// Permanently change configuration at client level
cl.config({ organization: 'you-organization-slug', accessToken: 'your-access-token' })
const skus = await cl.skus.list()
or
// Use configuration at request level
cl.skus.list({}, { organization: 'you-organization-slug', accessToken: 'your-access-token' })
```

@@ -241,35 +242,39 @@

Commerce Layer API returns specific errors (with extra information) on each attribute of a single resource. You can inspect them to properly handle validation errors (if any). To do that, use the `errors()` method:
Commerce Layer API returns specific errors (with extra information) on each attribute of a single resource. You can inspect them to properly handle validation errors (if any). To do that, use the `errors` attribute of the catched error:
```
// logs 2 error messages to console:
// 'shipping_category - must exist'
// 'name - can't be blank'
// logs error messages to console:
const attributes = { code: 'TSHIRTMM000000FFFFFFXL' }
const attributes = { code: 'TSHIRTMM000000FFFFFFXL', name: '' }
const newSku = await Sku.create(attributes, (sku) => {
const errors = sku.errors()
if (!errors.empty()) {
errors.toArray().map((e) => {
console.error(e.code + ' on ' + e.field + ': ' + e.message)
})
}
})
const newSku = await cl.skus.create(attributes).catch(error => console.log(error.errors))
// logs 1 error message to console
// 'pieces_per_pack - must be greater than 0'
const sku = await Sku.findBy({ code: 'TSHIRTMM000000FFFFFFXL' })
const attributes = { piecesPerPack: 0 }
sku.update(attributes, (sku) => {
const errors = sku.errors()
if (!errors.empty()) {
errors.toArray().map((e) => {
console.error(e.code + ' on ' + e.field + ': ' + e.message)
})
/*
[
{
title: "can't be blank",
detail: "name - can't be blank",
code: 'VALIDATION_ERROR',
source: { pointer: '/data/attributes/name' },
status: '422',
meta: { error: 'blank' }
},
{
title: 'has already been taken',
detail: 'code - has already been taken',
code: 'VALIDATION_ERROR',
source: { pointer: '/data/attributes/code' },
status: '422',
meta: { error: 'taken', value: 'TSHIRTMM000000FFFFFFXL' }
},
{
title: "can't be blank",
detail: "shipping_category - can't be blank",
code: 'VALIDATION_ERROR',
source: { pointer: '/data/relationships/shipping_category' },
status: '422',
meta: { error: 'blank' }
}
})
]
*/

@@ -276,0 +281,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc