evrythng.js SDK v5.0.0 Released
The evrythng.js
SDK, backbone of most of our AMPLIFY experiences, has received a major update to version 5.0.0!
This release comes after an interval since v4.7.2 where the SDK saw a lot of use, but sadly no updates or new features. Until now! From now on, we're in a much better position to continue releasing updates with new features, APIs, and bug fixes that aim to benefit the vast majority of use-cases we see.
Check out the full release on the GItHub releases page.
Breaking Changes
Firstly, there are some minor syntactical breaking changes for those already building apps/scripts with this SDK - but most of these are easy fixed with the 'find and replace' feature of all good IDEs. By breaking these changes with the 5
major version, we've taken the opportunity to fix and align some of the small inconsistencies that proved confusing or contradictory in previous versions.
If you are intending to upgrade to the new version for all the new features (and those coming in future releases to!) be sure to read the prepared evrythng.js v5.0.0 Migration Guide that will walk you through all the changes.
## New APIs and Features
To balance out the breaking changes, we've also added plenty of new APIs - some that were missing before, and some completely new to speed up common tasks and take the pain out of some of the more complicated types of requests. You can see a full list on GItHub releases page, but here are some of the biggest benefits you can expect to get from this new version.
Thng/product redirections
It's now possible to easily manage a Thng or product's redirection programmatically:
const thngId = 'U6PXpNWaMmPEY6aRaHDePhHh'
const payload = {
defaultRedirectUrl: 'https://example.com?thng={shortId}'
};
operator.thng(thngId).redirection()
.create(payload)
.then(console.log);
### Redirector
Both the account and application-level Redirector rules can be easily updated programmatically:
const payload = {
rules: [
// Run when a Thng's name is 'test'
{ match: 'thng.name=test' },
],
};
operator.redirector().update(payload)
.then(console.log);
Resource aliasing
Sometimes when building an app, integration, or library, it can get confusing if your terminology differs from the one we use for EVRYTHNG resources. One common example is the many and various use for Collections. It is now possible to alias most resource types so that your code makes more sense for you and your dependents. Note that the data model and underlying resource types remain the same as before.
// Alias collections as pallets for the Operator scope
evrythng.alias({ collection: 'pallet' }, 'Operator');
// Create a 'pallet'!
operator.pallet().create({ name: 'Example Pallet' })
.then(console.log);
Upsert unique resources
In many situation, especially when implementing serialised products, it is important to be able to create a resource using a unique identifier (such as a serial number), and then perform updates on that same identifier without needing to check if it already exists, or what its id
may be.
const payload = {
name: 'Test Thng',
identifiers: {
serial: '28fa34487f87bgd9'
}
};
const updateKey = { serial: payload.identifiers.serial };
// First call will create the described Thng, from then on
// repeated calls will update the same Thng with the new payload
// as long as 'serial' remains the same.
operator.thng().upsert(payload, payload.identifiers)
.then(console.log);
## Get Started
If you haven't already, get started using evrythng.js
to develop quickly and easily for the EVRYTHNG API by visiting the evrythng.js SDK Reference page.