🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

gatsby-source-shopify

Package Overview
Dependencies
Maintainers
1
Versions
601
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-source-shopify - npm Package Compare versions

Comparing version

to
0.1.4

92

gatsby-node.js

@@ -16,25 +16,7 @@ 'use strict';

var _graphqlClient = require('graphql-client');
var _graphqlClient2 = _interopRequireDefault(_graphqlClient);
var _fp = require('lodash/fp');
var _lib = require('./lib');
var _nodes = require('./nodes');
var _queries = require('./queries');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const createClient = (name, token) => (0, _graphqlClient2.default)({
url: `https://${name}.myshopify.com/api/graphql`,
headers: {
'X-Shopify-Storefront-Access-Token': token
}
});
const createCollections = (() => {
var _ref = (0, _asyncToGenerator3.default)(function* (client, createNode) {
/**
* Query storefront for Collection objects and create CollectionNodes.
*/
let createCollections = (() => {
var _ref2 = (0, _asyncToGenerator3.default)(function* (client, createNode) {
const collections = yield (0, _lib.queryAll)(client, ['shop', 'collections'], _queries.collectionsQuery);

@@ -45,9 +27,17 @@

return function createCollections(_x, _x2) {
return _ref.apply(this, arguments);
return function createCollections(_x3, _x4) {
return _ref2.apply(this, arguments);
};
})();
const createProducts = (() => {
var _ref2 = (0, _asyncToGenerator3.default)(function* (client, createNode) {
/**
* Query storefront for Product objects and their associated ProductVariants
* and create ProductNodes and ProductVariantNodes.
*
* ProductNodes and ProductVariantNodes have parent-child links.
*/
let createProductsAndProductVariants = (() => {
var _ref3 = (0, _asyncToGenerator3.default)(function* (client, createNode) {
const products = yield (0, _lib.queryAll)(client, ['shop', 'products'], _queries.productsQuery);

@@ -65,9 +55,14 @@

return function createProducts(_x3, _x4) {
return _ref2.apply(this, arguments);
return function createProductsAndProductVariants(_x5, _x6) {
return _ref3.apply(this, arguments);
};
})();
const createShopPolicies = (() => {
var _ref3 = (0, _asyncToGenerator3.default)(function* (client, createNode) {
/**
* Query storefront for ShopPolicy objects and create ShopPolicyNodes.
*/
let createShopPolicies = (() => {
var _ref4 = (0, _asyncToGenerator3.default)(function* (client, createNode) {
const policies = yield (0, _lib.queryOnce)(client, _queries.policiesQuery);

@@ -80,19 +75,40 @@

return function createShopPolicies(_x5, _x6) {
return _ref3.apply(this, arguments);
return function createShopPolicies(_x7, _x8) {
return _ref4.apply(this, arguments);
};
})();
var _graphqlClient = require('graphql-client');
var _graphqlClient2 = _interopRequireDefault(_graphqlClient);
var _fp = require('lodash/fp');
var _lib = require('./lib');
var _nodes = require('./nodes');
var _queries = require('./queries');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const sourceNodes = exports.sourceNodes = (() => {
var _ref4 = (0, _asyncToGenerator3.default)(function* ({ boundActionCreators: { createNode } }, { name, token }) {
const client = createClient(name, token);
var _ref = (0, _asyncToGenerator3.default)(function* ({ boundActionCreators: { createNode } }, { name, token }) {
const client = (0, _graphqlClient2.default)({
url: `https://${name}.myshopify.com/api/graphql`,
headers: {
'X-Shopify-Storefront-Access-Token': token
}
});
// Call the create function, each with their own fetching. Individual
// fetching is required as some nodes require multiple paginated requests.
yield createCollections(client, createNode);
yield createProducts(client, createNode);
yield createProductsAndProductVariants(client, createNode);
yield createShopPolicies(client, createNode);
});
return function sourceNodes(_x7, _x8) {
return _ref4.apply(this, arguments);
return function sourceNodes(_x, _x2) {
return _ref.apply(this, arguments);
};
})();

@@ -42,3 +42,3 @@ 'use strict';

exports.GraphQLError = GraphQLError; /**
* Request a query from a client. Throws an error is any are returned.
* Request a query from a client. Throws an error if any are returned.
*/

@@ -45,0 +45,0 @@

@@ -12,2 +12,4 @@ 'use strict';

var _fp = require('lodash/fp');
var _gatsbyNodeHelpers = require('gatsby-node-helpers');

@@ -19,16 +21,36 @@

// General node prefix
const TYPE_PREFIX = 'Shopify';
// Node types
const COLLECTION = 'Collection';
const PRODUCT = 'Product';
const PRODUCT_VARIANT = 'ProductVariant';
const SHOP_POLICY = 'ShopPolicy';
// Create Gatsby node helpers.
const { createNodeFactory, generateNodeId } = (0, _gatsbyNodeHelpers2.default)({
typePrefix: 'Shopify'
typePrefix: TYPE_PREFIX
});
const CollectionNode = exports.CollectionNode = createNodeFactory('Collection', node => {
/**
* CollectionNode
*
* Represents a grouping of products that a shop owner can create to organize
* them or make their shops easier to browse.
*/
const CollectionNode = exports.CollectionNode = createNodeFactory(COLLECTION, (0, _fp.tap)(node => {
if (node.products) {
node.children = node.products.edges.map(edge => generateNodeId('Product', edge.node.id));
node.children = node.products.edges.map(edge => generateNodeId(PRODUCT, edge.node.id));
delete node.products;
}
}));
return node;
});
const ProductNode = exports.ProductNode = createNodeFactory('Product', node => {
/**
* ProductNode
*
* Represents an individual item for sale in a Shopify store.
*/
const ProductNode = exports.ProductNode = createNodeFactory(PRODUCT, (0, _fp.tap)(node => {
if (node.variants) {

@@ -41,16 +63,22 @@ const variants = node.variants.edges.map(edge => edge.node);

node.children = variants.map(variant => generateNodeId('ProductVariant', variant.id));
node.children = variants.map(variant => generateNodeId(PRODUCT_VARIANT, variant.id));
delete node.variants;
}
}));
return node;
});
/**
* ProductVariantNode
*
* Represents a different version of a product, such as differing sizes or
* differing colors.
*/
const ProductVariantNode = exports.ProductVariantNode = createNodeFactory(PRODUCT_VARIANT, (0, _fp.tap)(node => node.price = (0, _parseFloat2.default)(node.price)));
const ProductVariantNode = exports.ProductVariantNode = createNodeFactory('ProductVariant', node => {
node.price = (0, _parseFloat2.default)(node.price);
return node;
});
const ShopPolicyNode = exports.ShopPolicyNode = createNodeFactory('ShopPolicy');
/**
* ShopPolicyNode
*
* Policy that a merchant has configured for their store, such as their refund
* or privacy policy.
*/
const ShopPolicyNode = exports.ShopPolicyNode = createNodeFactory(SHOP_POLICY);
{
"name": "gatsby-source-shopify",
"version": "0.1.3",
"version": "0.1.4",
"description": "Gatsby source plugin for building websites using Shopfiy as a data source",

@@ -35,3 +35,2 @@ "scripts": {

"gatsby": "^1.9.36",
"gatsby-node-helpers": "^0.1.1",
"graphql": "^0.11.3",

@@ -45,2 +44,3 @@ "graphql-tools": "^1.2.2",

"es6-error": "^4.0.2",
"gatsby-node-helpers": "^0.1.1",
"graphql-client": "^2.0.0",

@@ -47,0 +47,0 @@ "json-stringify-safe": "^5.0.1",