New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dotdev/dotheadless-node

Package Overview
Dependencies
Maintainers
13
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotdev/dotheadless-node - npm Package Compare versions

Comparing version 4.1.2 to 5.0.0

209

dist/gatsby/index.js

@@ -11,7 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.buildShopConfig = exports.buildShopConfigGatsby = exports.buildReactifySearchConfig = exports.buildSearchConfig = exports.buildSanityConfig = exports.buildShopifyIncrementalConfig = exports.buildShopifyConfig = exports.buildManifestConfig = exports.proxyUrl = exports.proxyMiddleware = exports.writeDocument = exports.writeCollections = exports.writeProducts = exports.writeRedirects = exports.writeRedirectsNative = exports.writeRobots = exports.hasHandle = exports.hasSlug = exports.nestedHandles = exports.traverseParents = exports.wrapper = exports.isDevelopment = void 0;
exports.getSearchConfig = exports.getShopConfig = exports.getSanityConfig = exports.getManifestConfig = exports.createCollectionPages = exports.createProductPages = exports.createPages = exports.createRedirects = exports.createRobots = exports.wrapper = void 0;
const fs = require("fs");
const jsonfile = require("jsonfile");
const http_proxy_middleware_1 = require("http-proxy-middleware");
exports.isDevelopment = (process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || "development") === "development";
const isDevelopment = (process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || "development") === "development";
/* Build path based on nested handles */
const nestedHandles = node => traverseParents(node).join("/") || node.shopify.handle;
/* Loop through the parents of a node and return an array of handles */
const traverseParents = node => {
let handles = [];
if (node.parent)
handles.push(...traverseParents(node.parent));
handles.push(node.shopify.handle);
return handles;
};
/* Wrap the gql queries to handle the errors */
const wrapper = promise => promise.then(result => {

@@ -24,17 +33,4 @@ if (result.errors) {

exports.wrapper = wrapper;
const traverseParents = node => {
let handles = [];
if (node.parent)
handles.push(...(0, exports.traverseParents)(node.parent));
handles.push(node.shopify.handle);
return handles;
};
exports.traverseParents = traverseParents;
const nestedHandles = node => (0, exports.traverseParents)(node).join("/") || node.shopify.handle;
exports.nestedHandles = nestedHandles;
const hasSlug = node => node && node.slug && node.slug.current;
exports.hasSlug = hasSlug;
const hasHandle = node => node && node.handle && node.handle.current;
exports.hasHandle = hasHandle;
const writeRobots = (data) => __awaiter(this, void 0, void 0, function* () {
/* Write the robots.txt file from data in Sanity */
const createRobots = ({ data }) => __awaiter(this, void 0, void 0, function* () {
if (data.length > -1) {

@@ -49,6 +45,6 @@ try {

});
exports.writeRobots = writeRobots;
const writeRedirectsNative = (config, data, createRedirect) => __awaiter(this, void 0, void 0, function* () {
exports.createRobots = createRobots;
/* Merge default redirects with custom redirects in Sanity */
const createRedirects = ({ defaultRedirects, data, createRedirect }) => __awaiter(this, void 0, void 0, function* () {
if (data.length) {
const defaultRedirects = config.settings.defaultRedirects;
const sanityRedirects = data

@@ -62,63 +58,55 @@ .filter(({ node }) => node.source && node.destination && node.type)

const finalRedirects = [...defaultRedirects, ...sanityRedirects].filter((v, i, a) => a.findIndex(t => t.source === v.source) === i);
finalRedirects.map(item => createRedirect({ fromPath: item.source, toPath: item.destination, statusCode: item.type }));
}
});
exports.writeRedirectsNative = writeRedirectsNative;
const writeRedirects = (config, firebase, file, data, createRedirect, gatsbyFile = false) => __awaiter(this, void 0, void 0, function* () {
if (firebase && data.length) {
const defaultRedirects = config.settings.defaultRedirects;
const sanityRedirects = data
.filter(({ node }) => node.source && node.destination && node.type)
.map(({ node }) => ({
source: node.source,
destination: node.destination,
type: parseInt(node.type),
finalRedirects.map(item => createRedirect({
fromPath: item.source,
toPath: item.destination,
statusCode: item.type,
}));
const finalRedirects = [...defaultRedirects, ...sanityRedirects].filter((v, i, a) => a.findIndex(t => t.source === v.source) === i);
finalRedirects.map(item => createRedirect({ fromPath: item.source, toPath: item.destination, statusCode: item.type }));
const newConfig = Array.isArray(firebase.hosting)
? Object.assign(Object.assign({}, firebase.hosting.filter(site => site.public.includes("app/public"))[0]), { redirects: finalRedirects }) : Object.assign(Object.assign({}, firebase.hosting), { redirects: finalRedirects });
yield jsonfile.writeFileSync(file, Object.assign(Object.assign({}, firebase), { hosting: Array.isArray(firebase.hosting) ? [...firebase.hosting.filter(site => !site.public.includes("app/public")), newConfig] : newConfig }), { spaces: 2 });
if (gatsbyFile)
yield jsonfile.writeFileSync(gatsbyFile, {
hosting: Object.assign({}, newConfig),
}, { spaces: 2 });
}
});
exports.writeRedirects = writeRedirects;
const writeProducts = (config, data, template, createPage, options = {}) => {
if (config.queries.products.hidden)
data = data.filter(({ node }) => node && node.handle && (!node.tags || (node.tags && !node.tags.find(tag => tag === config.queries.products.hidden))));
exports.createRedirects = createRedirects;
/* Create pages from Sanity data */
const createPages = ({ route, data, component, createPage, options = {} }) => data.forEach(({ node }) => {
createPage(Object.assign({ path: `${route}/${node.handle.current}`, component, context: {
id: node._id,
} }, options), true);
});
exports.createPages = createPages;
/* Create product pages from Sanity data and filter deleted and hidden */
const createProductPages = ({ route, data, component, createPage, settings, options = {} }) => {
data = data.filter(({ node }) => node && !node.deleted);
if (exports.isDevelopment && config.queries.products.devPageLimit > 0)
data = data.slice(0, config.queries.products.devPageLimit);
if (settings.hiddenTag) {
data = data.filter(({ node }) => node && node.shopify.handle && (!node.tags || (node.tags && !node.tags.find(tag => tag === settings.hiddenTag))));
}
if (isDevelopment && settings.devPageLimit > 0) {
data = data.slice(0, settings.devPageLimit);
}
data.forEach(({ node }) => {
var _a, _b, _c, _d, _e;
createPage(Object.assign({ path: `${(_a = config.settings) === null || _a === void 0 ? void 0 : _a.routes.PRODUCT}/${node.handle}`, component: template, context: {
handle: node.handle,
parentQuery: `${(_c = (_b = config === null || config === void 0 ? void 0 : config.queries) === null || _b === void 0 ? void 0 : _b.products) === null || _c === void 0 ? void 0 : _c.parentTagPrefix}:${node.handle}`,
siblingQuery: `${(_e = (_d = config === null || config === void 0 ? void 0 : config.queries) === null || _d === void 0 ? void 0 : _d.products) === null || _e === void 0 ? void 0 : _e.siblingTagPrefix}:${node.handle}`,
groupQuery1: node.tags.find(tag => { var _a, _b; return tag === null || tag === void 0 ? void 0 : tag.includes((_b = (_a = config === null || config === void 0 ? void 0 : config.queries) === null || _a === void 0 ? void 0 : _a.products) === null || _b === void 0 ? void 0 : _b.groupTagPrefix1); }) || "",
groupQuery2: node.tags.find(tag => { var _a, _b; return tag === null || tag === void 0 ? void 0 : tag.includes((_b = (_a = config === null || config === void 0 ? void 0 : config.queries) === null || _a === void 0 ? void 0 : _a.products) === null || _b === void 0 ? void 0 : _b.groupTagPrefix2); }) || "",
createPage(Object.assign({ path: `${route}/${node.shopify.handle}`, component, context: {
handle: node.shopify.handle,
parentQuery: `${settings.parentTagPrefix}:${node.shopify.handle}`,
siblingQuery: `${settings.siblingTagPrefix}:${node.shopify.handle}`,
groupQuery1: node.tags.find(tag => tag.includes(settings.groupTagPrefix1)) || "",
groupQuery2: node.tags.find(tag => tag.includes(settings.groupTagPrefix2)) || "",
} }, options), true);
});
};
exports.writeProducts = writeProducts;
const writeCollections = (config, data, template, createPage, createRedirect = undefined, options = {}) => {
if (config.queries.collections.hidden)
data = data.filter(({ node }) => { var _a; return node && ((_a = node === null || node === void 0 ? void 0 : node.shopify) === null || _a === void 0 ? void 0 : _a.handle) && (!node.tags || (node.tags && !node.tags.find(tag => tag === config.queries.collections.hidden))); });
exports.createProductPages = createProductPages;
/* Create collections pages from Sanity data, filter deleted and hidden, resolved nested collections and setup redirect */
const createCollectionPages = ({ route, data, component, createPage, createRedirect = undefined, settings, options = {} }) => {
data = data.filter(({ node }) => node && !node.deleted);
if (exports.isDevelopment && config.queries.collections.devPageLimit > 0)
data = data.slice(0, config.queries.collections.devPageLimit);
if (settings.hiddenTag) {
data = data.filter(({ node }) => node && node.shopify.handle && (!node.tags || (node.tags && !node.tags.find(tag => tag === settings.hiddenTag))));
}
if (isDevelopment && settings.devPageLimit > 0) {
data = data.slice(0, settings.devPageLimit);
}
data.forEach(({ node }) => {
var _a, _b;
const nestedHandle = (0, exports.nestedHandles)(node);
const nestedPath = `${(_a = config.settings) === null || _a === void 0 ? void 0 : _a.routes.COLLECTION}/${nestedHandle}`;
createPage(Object.assign({ path: nestedPath, component: template, context: {
const nestedHandle = nestedHandles(node);
const nestedPath = `${route}/${nestedHandle}`;
createPage(Object.assign({ path: nestedPath, component, context: {
handle: node.shopify.handle,
} }, options), true);
// create client redirect for nested collections (resolves preview issue)
if (createRedirect !== undefined && nestedHandle.split("/").length > 1) {
createRedirect({
fromPath: `${(_b = config.settings) === null || _b === void 0 ? void 0 : _b.routes.COLLECTION}/${nestedHandle.split("/").pop()}`,
fromPath: `${route}/${nestedHandle.split("/").pop()}`,
toPath: nestedPath,

@@ -131,31 +119,15 @@ isPermanent: false,

};
exports.writeCollections = writeCollections;
const writeDocument = (url, data, template, createPage, options = {}) => data.forEach(({ node }) => {
var _a, _b;
createPage(Object.assign({ path: `${url}/${((_a = node === null || node === void 0 ? void 0 : node.handle) === null || _a === void 0 ? void 0 : _a.current) || ((_b = node === null || node === void 0 ? void 0 : node.slug) === null || _b === void 0 ? void 0 : _b.current)}`, component: template, context: {
id: node._id,
} }, options), true);
});
exports.writeDocument = writeDocument;
const proxyMiddleware = (config, from, to) => (0, http_proxy_middleware_1.createProxyMiddleware)({
target: "http://localhost:5001",
pathRewrite: {
[`${from}`]: `/${config.services.firebase.projectId}/${config.services.firebase.region}/${to}`,
},
});
exports.proxyMiddleware = proxyMiddleware;
const proxyUrl = (config, to) => `http://localhost:5001/${config.services.firebase.projectId}/${config.services.firebase.region}/${to}`;
exports.proxyUrl = proxyUrl;
const buildManifestConfig = config => ({
start_url: `/`,
name: config.app.title,
short_name: config.app.title,
description: config.app.description,
background_color: config.app.themeBackground,
theme_color: config.app.themeColor,
display: config.app.themeDisplay,
icon: config.app.themeIcon,
exports.createCollectionPages = createCollectionPages;
const getManifestConfig = config => ({
start_url: "/",
name: config.store.title,
short_name: config.store.title,
description: config.store.description,
background_color: config.theme.background,
theme_color: config.theme.color,
display: config.theme.display,
icon: config.theme.icon,
icons: [
{
src: config.app.themeIcon,
src: config.theme.icon,
sizes: "196x196",

@@ -167,32 +139,9 @@ type: "image/png",

});
exports.buildManifestConfig = buildManifestConfig;
const buildShopifyConfig = config => ({
shopName: config.services.shopify.defaultShopName,
accessToken: config.stores[config.services.shopify.defaultShopName].accessToken,
apiVersion: config.services.shopify.apiVersion,
paginationSize: parseInt(config.services.shopify.paginationSize, 10),
verbose: true,
});
exports.buildShopifyConfig = buildShopifyConfig;
const buildShopifyIncrementalConfig = config => ({
myshopifyDomain: `${config.services.shopify.defaultShopName}.myshopify.com`,
adminAccessToken: config.stores[config.services.shopify.defaultShopName].adminAccessToken,
storefrontAccessToken: config.stores[config.services.shopify.defaultShopName].accessToken,
storefrontShopDomain: `${config.services.shopify.defaultShopName}.myshopify.com`,
shopifyPlus: config.stores[config.services.shopify.defaultShopName].shopifyPlus,
apiVersion: config.services.shopify.apiVersion,
includePages: false,
includeBlogs: false,
});
exports.buildShopifyIncrementalConfig = buildShopifyIncrementalConfig;
const buildSanityConfig = config => (Object.assign({ projectId: config.services.sanity.projectId, dataset: config.stores[config.services.shopify.defaultShopName].sanityDataset }, (exports.isDevelopment && { token: config.services.sanity.token, overlayDrafts: true, watchMode: !process.env.GATSBY_ACTIVE_ENV })));
exports.buildSanityConfig = buildSanityConfig;
const buildSearchConfig = config => ({
url: `${config.services.reactify.searchConfig}?shop=${config.services.shopify.defaultShopName}.myshopify.com`,
name: `Search`,
payloadKey: `body`,
});
exports.buildSearchConfig = buildSearchConfig;
const buildReactifySearchConfig = config => ({
url: `${config.services.reactify.searchConfig}`,
exports.getManifestConfig = getManifestConfig;
const getSanityConfig = store => (Object.assign({ projectId: store.sanityProjectId, dataset: store.sanityDataset, token: store.sanityToken }, (isDevelopment && { overlayDrafts: true, watchMode: !process.env.GATSBY_ACTIVE_ENV })));
exports.getSanityConfig = getSanityConfig;
const getShopConfig = store => (Object.assign({ url: `${store.url}/api/get-shop` }, shopConfigSchema));
exports.getShopConfig = getShopConfig;
const getSearchConfig = store => ({
url: `${store.searchConfig}`,
rootKey: "SearchSettings",

@@ -305,3 +254,3 @@ schemas: {

});
exports.buildReactifySearchConfig = buildReactifySearchConfig;
exports.getSearchConfig = getSearchConfig;
const shopConfigSchema = {

@@ -351,8 +300,2 @@ rootKey: "Shop",

};
const buildShopConfigGatsby = config => (Object.assign({ url: `${config.services.shopify.defaultURL}/api/get-shop?shop=${config.services.shopify.defaultShopName}` }, shopConfigSchema));
exports.buildShopConfigGatsby = buildShopConfigGatsby;
const buildShopConfig = (config, liveMode = false) => (Object.assign({ url: exports.isDevelopment && !liveMode
? `http://localhost:5001/${config.services.firebase.projectId}/${config.services.firebase.region}/getShop?shop=${config.services.shopify.defaultShopName}`
: `https://${config.services.firebase.region}-${config.services.firebase.projectId}.cloudfunctions.net/getShop?shop=${config.services.shopify.defaultShopName}` }, shopConfigSchema));
exports.buildShopConfig = buildShopConfig;
//# sourceMappingURL=index.js.map
{
"name": "@dotdev/dotheadless-node",
"description": "Node package for DotHeadless",
"version": "4.1.2",
"version": "5.0.0",
"author": "DotDev <info@dotdev.com.au>",

@@ -14,6 +14,2 @@ "main": "dist/index.js",

},
"dependencies": {
"http-proxy-middleware": "^2.0.3",
"jsonfile": "^6.1.0"
},
"devDependencies": {

@@ -20,0 +16,0 @@ "@types/node": "^16.11.25",

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