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

@chec/commercerays-plugin

Package Overview
Dependencies
Maintainers
6
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chec/commercerays-plugin - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

87

nextjs/index.js

@@ -185,3 +185,49 @@ var Commerce = require('@chec/commerce.js');

function createGetStaticProps(schema) {
var addMissingValues = (function (context, schema, defaults) {
var missingAttributes = {}; // Function that generates a loop. This exists because it's a recursive loop
var createLoop = function createLoop(prefix) {
if (prefix === void 0) {
prefix = '';
}
return function (object) {
var key = "" + prefix + object.key; // Deal with sub-schema
if (Object.hasOwnProperty.call(object, 'schema')) {
// Reduce the sub-schema (with this reducer), using the current accumulator as a base
return object.schema.forEach(createLoop(key + "."));
} // Check if the value exists in context
var value = get__default['default'](context, key); // Skip if the value exists and it's not an image
if (object.type !== 'image' && value !== undefined) {
return;
} // Skip images if they have an ID (ie. has come from chec assets API)
if (object.type === 'image' && value && Array.isArray(value) && (!value.length || value[0].id)) {
return;
} // Grab a value from defaults to use in-place
set__default['default'](missingAttributes, key, get__default['default'](defaults, key));
};
};
schema.schema.forEach(createLoop()); // Apply the new values to our context and return that
return defaultsDeep__default['default'](missingAttributes, context);
});
function createGetStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function () {

@@ -202,6 +248,10 @@ try {

return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain).then(function (context) {
return context && resolveResourcesInContext(new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain) // Convert IDs from the API into actual resources using Commerce.js
.then(function (context) {
return context && resolveResourcesInContext(new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
}), schema, context);
}, commerceConfig)), schema, context);
}) // Add in any values that are defined in schema but missing from the loaded context, falling back to the defaults
.then(function (context) {
return addMissingValues(context, schema, defaults);
})).then(_temp);

@@ -216,5 +266,5 @@ };

if (!preview) {
var commerce = new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
var commerce = new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
});
}, commerceConfig));
return Promise.resolve(commerce.merchants.about()).then(function (_commerce$merchants$a) {

@@ -233,3 +283,11 @@ merchant = _commerce$merchants$a;

var augmentStaticProps = function augmentStaticProps(schema) {
var augmentStaticProps = function augmentStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function (staticProps) {

@@ -241,6 +299,6 @@ if (staticProps === void 0) {

try {
var getStaticProps = createGetStaticProps(schema);
return Promise.resolve(getStaticProps()).then(function (defaults) {
return _extends({}, staticProps, defaults, {
props: _extends({}, staticProps.props || {}, defaults.props)
var getStaticProps = createGetStaticProps(schema, defaults, commerceConfig);
return Promise.resolve(getStaticProps()).then(function (parentProps) {
return _extends({}, staticProps, parentProps, {
props: _extends({}, staticProps.props || {}, parentProps.props)
});

@@ -359,5 +417,5 @@ });

// Create a Commerce.js instance
var sdk = new Commerce__default['default'](providedKey, false, {
var sdk = new Commerce__default['default'](providedKey, false, _extends({
url: apiUrl || 'https://api.chec.io'
});
}, commerceConfig));
setCommerce(sdk);

@@ -423,3 +481,4 @@ setPublicKey(providedKey);

}, /*#__PURE__*/React__default['default'].createElement(Component, _extends({}, props, {
merchant: merchant
merchant: merchant,
preview: preview
}))));

@@ -426,0 +485,0 @@ };

61

nextjs/index.modern.js

@@ -136,3 +136,35 @@ import Commerce from '@chec/commerce.js';

function createGetStaticProps(schema) {
var addMissingValues = ((context, schema, defaults) => {
const missingAttributes = {}; // Function that generates a loop. This exists because it's a recursive loop
const createLoop = (prefix = '') => object => {
const key = `${prefix}${object.key}`; // Deal with sub-schema
if (Object.hasOwnProperty.call(object, 'schema')) {
// Reduce the sub-schema (with this reducer), using the current accumulator as a base
return object.schema.forEach(createLoop(`${key}.`));
} // Check if the value exists in context
const value = get(context, key); // Skip if the value exists and it's not an image
if (object.type !== 'image' && value !== undefined) {
return;
} // Skip images if they have an ID (ie. has come from chec assets API)
if (object.type === 'image' && value && Array.isArray(value) && (!value.length || value[0].id)) {
return;
} // Grab a value from defaults to use in-place
set(missingAttributes, key, get(defaults, key));
};
schema.schema.forEach(createLoop()); // Apply the new values to our context and return that
return defaultsDeep(missingAttributes, context);
});
function createGetStaticProps(schema, defaults = {}, commerceConfig = {}) {
return async () => {

@@ -144,11 +176,13 @@ const preview = process.env.COMMERCEJS_RAYS_MODE === 'preview';

if (!preview) {
const commerce = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
const commerce = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
});
}, commerceConfig));
merchant = await commerce.merchants.about();
}
const rayContext = preview ? null : await getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain).then(context => context && resolveResourcesInContext(new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
const rayContext = preview ? null : await getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain) // Convert IDs from the API into actual resources using Commerce.js
.then(context => context && resolveResourcesInContext(new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
}), schema, context));
}, commerceConfig)), schema, context)) // Add in any values that are defined in schema but missing from the loaded context, falling back to the defaults
.then(context => addMissingValues(context, schema, defaults));
return {

@@ -166,7 +200,7 @@ props: {

const augmentStaticProps = schema => async (staticProps = {}) => {
const getStaticProps = createGetStaticProps(schema);
const defaults = await getStaticProps();
return _extends({}, staticProps, defaults, {
props: _extends({}, staticProps.props || {}, defaults.props)
const augmentStaticProps = (schema, defaults = {}, commerceConfig = {}) => async (staticProps = {}) => {
const getStaticProps = createGetStaticProps(schema, defaults, commerceConfig);
const parentProps = await getStaticProps();
return _extends({}, staticProps, parentProps, {
props: _extends({}, staticProps.props || {}, parentProps.props)
});

@@ -250,5 +284,5 @@ };

// Create a Commerce.js instance
const sdk = new Commerce(providedKey, false, {
const sdk = new Commerce(providedKey, false, _extends({
url: apiUrl || 'https://api.chec.io'
});
}, commerceConfig));
setCommerce(sdk);

@@ -303,3 +337,4 @@ setPublicKey(providedKey);

}, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
merchant: merchant
merchant: merchant,
preview: preview
}))));

@@ -306,0 +341,0 @@ };

@@ -175,3 +175,49 @@ import Commerce from '@chec/commerce.js';

function createGetStaticProps(schema) {
var addMissingValues = (function (context, schema, defaults) {
var missingAttributes = {}; // Function that generates a loop. This exists because it's a recursive loop
var createLoop = function createLoop(prefix) {
if (prefix === void 0) {
prefix = '';
}
return function (object) {
var key = "" + prefix + object.key; // Deal with sub-schema
if (Object.hasOwnProperty.call(object, 'schema')) {
// Reduce the sub-schema (with this reducer), using the current accumulator as a base
return object.schema.forEach(createLoop(key + "."));
} // Check if the value exists in context
var value = get(context, key); // Skip if the value exists and it's not an image
if (object.type !== 'image' && value !== undefined) {
return;
} // Skip images if they have an ID (ie. has come from chec assets API)
if (object.type === 'image' && value && Array.isArray(value) && (!value.length || value[0].id)) {
return;
} // Grab a value from defaults to use in-place
set(missingAttributes, key, get(defaults, key));
};
};
schema.schema.forEach(createLoop()); // Apply the new values to our context and return that
return defaultsDeep(missingAttributes, context);
});
function createGetStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function () {

@@ -192,6 +238,10 @@ try {

return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain).then(function (context) {
return context && resolveResourcesInContext(new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain) // Convert IDs from the API into actual resources using Commerce.js
.then(function (context) {
return context && resolveResourcesInContext(new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
}), schema, context);
}, commerceConfig)), schema, context);
}) // Add in any values that are defined in schema but missing from the loaded context, falling back to the defaults
.then(function (context) {
return addMissingValues(context, schema, defaults);
})).then(_temp);

@@ -206,5 +256,5 @@ };

if (!preview) {
var commerce = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
var commerce = new Commerce(process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
});
}, commerceConfig));
return Promise.resolve(commerce.merchants.about()).then(function (_commerce$merchants$a) {

@@ -223,3 +273,11 @@ merchant = _commerce$merchants$a;

var augmentStaticProps = function augmentStaticProps(schema) {
var augmentStaticProps = function augmentStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function (staticProps) {

@@ -231,6 +289,6 @@ if (staticProps === void 0) {

try {
var getStaticProps = createGetStaticProps(schema);
return Promise.resolve(getStaticProps()).then(function (defaults) {
return _extends({}, staticProps, defaults, {
props: _extends({}, staticProps.props || {}, defaults.props)
var getStaticProps = createGetStaticProps(schema, defaults, commerceConfig);
return Promise.resolve(getStaticProps()).then(function (parentProps) {
return _extends({}, staticProps, parentProps, {
props: _extends({}, staticProps.props || {}, parentProps.props)
});

@@ -349,5 +407,5 @@ });

// Create a Commerce.js instance
var sdk = new Commerce(providedKey, false, {
var sdk = new Commerce(providedKey, false, _extends({
url: apiUrl || 'https://api.chec.io'
});
}, commerceConfig));
setCommerce(sdk);

@@ -413,3 +471,4 @@ setPublicKey(providedKey);

}, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
merchant: merchant
merchant: merchant,
preview: preview
}))));

@@ -416,0 +475,0 @@ };

@@ -181,3 +181,49 @@ (function (global, factory) {

function createGetStaticProps(schema) {
var addMissingValues = (function (context, schema, defaults) {
var missingAttributes = {}; // Function that generates a loop. This exists because it's a recursive loop
var createLoop = function createLoop(prefix) {
if (prefix === void 0) {
prefix = '';
}
return function (object) {
var key = "" + prefix + object.key; // Deal with sub-schema
if (Object.hasOwnProperty.call(object, 'schema')) {
// Reduce the sub-schema (with this reducer), using the current accumulator as a base
return object.schema.forEach(createLoop(key + "."));
} // Check if the value exists in context
var value = get__default['default'](context, key); // Skip if the value exists and it's not an image
if (object.type !== 'image' && value !== undefined) {
return;
} // Skip images if they have an ID (ie. has come from chec assets API)
if (object.type === 'image' && value && Array.isArray(value) && (!value.length || value[0].id)) {
return;
} // Grab a value from defaults to use in-place
set__default['default'](missingAttributes, key, get__default['default'](defaults, key));
};
};
schema.schema.forEach(createLoop()); // Apply the new values to our context and return that
return defaultsDeep__default['default'](missingAttributes, context);
});
function createGetStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function () {

@@ -198,6 +244,10 @@ try {

return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain).then(function (context) {
return context && resolveResourcesInContext(new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
return preview ? _temp(null) : Promise.resolve(getSavedContext(process.env.COMMERCEJS_RAY_ID, process.env.CHEC_SECRET_KEY, domain) // Convert IDs from the API into actual resources using Commerce.js
.then(function (context) {
return context && resolveResourcesInContext(new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
}), schema, context);
}, commerceConfig)), schema, context);
}) // Add in any values that are defined in schema but missing from the loaded context, falling back to the defaults
.then(function (context) {
return addMissingValues(context, schema, defaults);
})).then(_temp);

@@ -212,5 +262,5 @@ };

if (!preview) {
var commerce = new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, {
var commerce = new Commerce__default['default'](process.env.NEXT_PUBLIC_CHEC_PUBLIC_KEY, false, _extends({
url: domain
});
}, commerceConfig));
return Promise.resolve(commerce.merchants.about()).then(function (_commerce$merchants$a) {

@@ -229,3 +279,11 @@ merchant = _commerce$merchants$a;

var augmentStaticProps = function augmentStaticProps(schema) {
var augmentStaticProps = function augmentStaticProps(schema, defaults, commerceConfig) {
if (defaults === void 0) {
defaults = {};
}
if (commerceConfig === void 0) {
commerceConfig = {};
}
return function (staticProps) {

@@ -237,6 +295,6 @@ if (staticProps === void 0) {

try {
var getStaticProps = createGetStaticProps(schema);
return Promise.resolve(getStaticProps()).then(function (defaults) {
return _extends({}, staticProps, defaults, {
props: _extends({}, staticProps.props || {}, defaults.props)
var getStaticProps = createGetStaticProps(schema, defaults, commerceConfig);
return Promise.resolve(getStaticProps()).then(function (parentProps) {
return _extends({}, staticProps, parentProps, {
props: _extends({}, staticProps.props || {}, parentProps.props)
});

@@ -355,5 +413,5 @@ });

// Create a Commerce.js instance
var sdk = new Commerce__default['default'](providedKey, false, {
var sdk = new Commerce__default['default'](providedKey, false, _extends({
url: apiUrl || 'https://api.chec.io'
});
}, commerceConfig));
setCommerce(sdk);

@@ -419,3 +477,4 @@ setPublicKey(providedKey);

}, /*#__PURE__*/React__default['default'].createElement(Component, _extends({}, props, {
merchant: merchant
merchant: merchant,
preview: preview
}))));

@@ -422,0 +481,0 @@ };

{
"name": "@chec/commercerays-plugin",
"version": "0.0.10",
"version": "0.0.11",
"description": "Integrate directly with an editor within the Chec Dashboard - allowing customisation of your project by the merchant",

@@ -5,0 +5,0 @@ "main": "dist/rays-plugin.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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