@rechargeapps/bundling-data
v2.3.0
Published
Library to serialize and deserialize bundle-related data to and from XDR.
Downloads
7
Keywords
Readme
Bundling Data
Bundling Data is a library to serialize and deserialize bundle-related data to and from XDR.
XDR is a standard to represent and encode data in binary (RFC 4506).
Public-facing services like the storefront API or the JS Widget deliver bundle representation data in their XDR encoding representation.
Some of the benefits of XDR are:
- Shorter payloads: If the bundle payload is a line item property, XDR yields a shorted string (%60 smaller) versus a raw JSON.
- Security: XDR forces data to follow a given structure, which helps reduce the attack surface at the application level.
- Obfuscation: Hide the bundle representation on public-facing services, where attackers could try to read the XHR Request and reverse engineer a bundle.
const data = require('@recharge-packages/bundling-data);
const bundle = {
variantId: "32237082935351",
version: 1,
items: [
{
collectionId: "164879106103",
productId: "4595439042615",
variantId: "32222566678583",
sku: "RG-THYME",
quantity: 6,
},
{
collectionId: "64879106103",
productId: "4595438813239",
variantId: "32222566219831",
sku: "RG-SPINACH",
quantity: 1,
},
],
};
const xdr = data.toLineItemProperty(bundle);
console.log('data: ', xdr)
// expected output: data: AAAAAAAAHVHH4IA3AAAAAgAAACZjj4A3AAAELfWDADcAAB1OZqQANwAAAAhSRy1USFlNRQAAAAYAAAAAAAAADxsYmDcAAAQt9X+ANwAAHU5mnQA3AAAAClJHLVNQSU5BQ0gAAAAAAAEAAAAAAAAAAQAAAAA=
data.toBundle(xdr) === bundle;
// expected output: true
Shareable SDK
esbuild sdk.js --bundle --platform=node --outfile=rebundle-sdk.js
Release
Bump the version in package.json
, create a commit, and then create a new semver tag on master. After the tag is published, GitLab will automatically release the new version.
git tag 0.0.1
git push --tags