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

@arcteryx/js-cms

Package Overview
Dependencies
Maintainers
3
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcteryx/js-cms - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

378

dist/cjs/index.js

@@ -51,81 +51,77 @@ 'use strict';

function flattenCMSJson(item, included) {
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
returnObject[key] = item.relationships[key].data.map((related) => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter((include) => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
return returnObject;
returnObject[key] = item.relationships[key].data.map(related => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter(include => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
}
return returnObject;
}
}
/* eslint-enable*/
const queryOptionsForCategoryIntros = (market, country, path, previewDraft) => {
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
}
else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
}
else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] =
"title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include =
"field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] =
"field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
} else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
} else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] = "title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include = "field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] = "field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
};
function queryOptionsForSimplePages(market, country, path = "") {
return jsUrl.toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text",
});
function queryOptionsForSimplePages(market, country) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
return jsUrl.toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text"
});
}
function queryOptionsForBasicBlock(title) {
return jsUrl.toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names",
});
return jsUrl.toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names"
});
}
function queryOptionsForReusableString(stringsArray) {
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return jsUrl.toQueryParams(filterObj);
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return jsUrl.toQueryParams(filterObj);
}

@@ -140,20 +136,17 @@ /*

function getDrupalData(fetchUrl, fetchOptions) {
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions)
.then((resp) => resp.json())
.then((json) => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map((label) => flattenCMSJson(label, json.included));
})
.catch((e) => {
console.error(e.message);
return null;
});
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map(label => flattenCMSJson(label, json.included));
}).catch(e => {
console.error(e.message);
return null;
});
});
}
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
return getDrupalData(fetchUrl);
}

@@ -171,6 +164,6 @@ /*

function getSimplePage(cmsUrl, market, country, language, path) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
}

@@ -186,6 +179,6 @@ /*

function getBasicBlock(cmsUrl, title, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
}

@@ -201,6 +194,6 @@ /*

function getReusableData(cmsUrl, stringsArray, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
}

@@ -219,10 +212,10 @@ /*

function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
return titleKey;
}
return titleKey;
}

@@ -238,7 +231,7 @@ /*

function getCsPhoneNumber(cmsUrl, market, country) {
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
}

@@ -256,13 +249,13 @@ /*

const getCategoryIntroId = (cmsUrl, market, country, language, path) => __awaiter(void 0, void 0, void 0, function* () {
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl)
.then((resp) => resp.json())
.then((json) => { var _a; return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id; })
.catch((err) => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl).then(resp => resp.json()).then(json => {
var _a;
return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id;
}).catch(err => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
});

@@ -277,27 +270,25 @@ /*

const getCategoryIntroPaths = (market, path) => {
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
}
else if (i !== 0) {
str += `/${p}`;
}
}
else if (market == "urban" || market == "leaf") {
str += p;
}
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
} else if (i !== 0) {
str += `/${p}`;
}
} else if (market == "urban" || market == "leaf") {
str += p;
}
return paths;
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
}
return paths;
};

@@ -316,12 +307,12 @@ /*

const getCmsApiForCategoryIntro = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
return cmsApi;
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
}
return cmsApi;
});

@@ -340,7 +331,7 @@ /*

const generateRequestUrls = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map((catPath) => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map(catPath => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
});

@@ -360,34 +351,31 @@ /*

const getCategoryIntro = (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const fetchOptions = previewDraft
? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`,
},
}
: {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then((json) => json);
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens CDPs returns 2 Cat Intros
Unisex CDPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the CDP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
const fetchOptions = previewDraft ? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`
}
catch (e) {
console.error(e);
return null;
} : {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map(url => getDrupalData(url, fetchOptions))).then(json => json);
const catIntrosNoEmpties = catIntros.filter(catIntro => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens PLPs returns 2 Cat Intros
Unisex PLPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the PLP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else PLP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
} catch (e) {
console.error(e);
return null;
}
});

@@ -405,10 +393,10 @@ /**

const getCmsMessageByFieldName = (cmsUrl, market, country, language, messageFieldName) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
});

@@ -415,0 +403,0 @@

@@ -47,81 +47,77 @@ import { toQueryParams } from '@arcteryx/js-url';

function flattenCMSJson(item, included) {
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
returnObject[key] = item.relationships[key].data.map((related) => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter((include) => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
return returnObject;
returnObject[key] = item.relationships[key].data.map(related => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter(include => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
}
return returnObject;
}
}
/* eslint-enable*/
const queryOptionsForCategoryIntros = (market, country, path, previewDraft) => {
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
}
else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
}
else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] =
"title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include =
"field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] =
"field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
} else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
} else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] = "title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include = "field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] = "field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
};
function queryOptionsForSimplePages(market, country, path = "") {
return toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text",
});
function queryOptionsForSimplePages(market, country) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
return toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text"
});
}
function queryOptionsForBasicBlock(title) {
return toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names",
});
return toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names"
});
}
function queryOptionsForReusableString(stringsArray) {
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return toQueryParams(filterObj);
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return toQueryParams(filterObj);
}

@@ -136,20 +132,17 @@ /*

function getDrupalData(fetchUrl, fetchOptions) {
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions)
.then((resp) => resp.json())
.then((json) => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map((label) => flattenCMSJson(label, json.included));
})
.catch((e) => {
console.error(e.message);
return null;
});
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map(label => flattenCMSJson(label, json.included));
}).catch(e => {
console.error(e.message);
return null;
});
});
}
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
return getDrupalData(fetchUrl);
}

@@ -167,6 +160,6 @@ /*

function getSimplePage(cmsUrl, market, country, language, path) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
}

@@ -182,6 +175,6 @@ /*

function getBasicBlock(cmsUrl, title, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
}

@@ -197,6 +190,6 @@ /*

function getReusableData(cmsUrl, stringsArray, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
}

@@ -215,10 +208,10 @@ /*

function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
return titleKey;
}
return titleKey;
}

@@ -234,7 +227,7 @@ /*

function getCsPhoneNumber(cmsUrl, market, country) {
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
}

@@ -252,13 +245,13 @@ /*

const getCategoryIntroId = (cmsUrl, market, country, language, path) => __awaiter(void 0, void 0, void 0, function* () {
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl)
.then((resp) => resp.json())
.then((json) => { var _a; return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id; })
.catch((err) => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl).then(resp => resp.json()).then(json => {
var _a;
return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id;
}).catch(err => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
});

@@ -273,27 +266,25 @@ /*

const getCategoryIntroPaths = (market, path) => {
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
}
else if (i !== 0) {
str += `/${p}`;
}
}
else if (market == "urban" || market == "leaf") {
str += p;
}
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
} else if (i !== 0) {
str += `/${p}`;
}
} else if (market == "urban" || market == "leaf") {
str += p;
}
return paths;
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
}
return paths;
};

@@ -312,12 +303,12 @@ /*

const getCmsApiForCategoryIntro = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
return cmsApi;
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
}
return cmsApi;
});

@@ -336,7 +327,7 @@ /*

const generateRequestUrls = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map((catPath) => cmsApi + toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map(catPath => cmsApi + toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
});

@@ -356,34 +347,31 @@ /*

const getCategoryIntro = (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const fetchOptions = previewDraft
? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`,
},
}
: {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then((json) => json);
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens CDPs returns 2 Cat Intros
Unisex CDPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the CDP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
const fetchOptions = previewDraft ? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`
}
catch (e) {
console.error(e);
return null;
} : {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map(url => getDrupalData(url, fetchOptions))).then(json => json);
const catIntrosNoEmpties = catIntros.filter(catIntro => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens PLPs returns 2 Cat Intros
Unisex PLPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the PLP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else PLP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
} catch (e) {
console.error(e);
return null;
}
});

@@ -401,10 +389,10 @@ /**

const getCmsMessageByFieldName = (cmsUrl, market, country, language, messageFieldName) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
});

@@ -411,0 +399,0 @@

@@ -56,81 +56,77 @@ (function (global, factory) {

function flattenCMSJson(item, included) {
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
returnObject[key] = item.relationships[key].data.map((related) => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter((include) => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
// 2) Extracts it's "attributes" values into the return object
if (typeof item !== "undefined") {
const returnObject = item.attributes;
// 3) Checks for a "relationships" attribute, if it does, add a memeber to the return object named the same as the relationship key
if (item.relationships) {
for (const key in item.relationships) {
// 4) iterate over the items in the related field's data array (or if not an array, skip straight to processing the object)
if (item.relationships[key].data instanceof Array === false) {
// Sometimes the relationships[key] is just an object, sometimes it's an array. Let's always treat them as arrays.
item.relationships[key].data = [item.relationships[key].data];
}
return returnObject;
returnObject[key] = item.relationships[key].data.map(related => {
// 6) call getAttributes on the real entity object, put the results into the new member on the return object (from 3)
return flattenCMSJson(
// 5) get the real entity object from the "included" array
included.filter(include => (related === null || related === void 0 ? void 0 : related.id) === include.id)[0], included);
});
}
}
return returnObject;
}
}
/* eslint-enable*/
const queryOptionsForCategoryIntros = (market, country, path, previewDraft) => {
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
}
else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
}
else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] =
"title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include =
"field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] =
"field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
const options = {};
if (previewDraft) {
options.resourceVersion = "rel:working-copy";
} else {
options["filter[field_market]"] = market.toUpperCase();
options["filter[field_cat_intro_category_handle]"] = path;
}
if (country !== null) {
options["filter[field_allowed_countries]"] = country.toUpperCase();
} else {
options["filter[country-filter][condition][path]"] = "field_allowed_countries";
options["filter[country-filter][condition][operator]"] = "IS NULL";
}
options["fields[node--category_intro]"] = "title,field_cat_intro_category_handle,field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_breadcrumb_max_width,field_cat_intro_meta_description,field_cta,field_cat_intro_body_copy,field_cat_intro_product_callouts,field_background_image_position,field_text_colour";
options.include = "field_cat_intro_background_image,field_simple_page_title,field_breadcrumb_override,field_cta,field_cat_intro_meta_description,field_cat_intro_product_callouts.field_callout_flag_product,field_cat_intro_product_callouts.field_callout_outfit_product";
options["fields[paragraph--cta]"] = "field_link,field_style";
options["fields[paragraph--product_callout_flag]"] = "field_callout_flag_colour,field_callout_flag_type,field_callout_flag_x_percentage,field_callout_flag_y_percentage,field_callout_flag_product,field_callout_arrow_direction";
options["fields[node--reusable_string]"] = "field_reusable_string_text";
options["fields[file--file]"] = "uri";
options["fields[node--product]"] = "field_product_product_name,field_product_product_url";
return options;
};
function queryOptionsForSimplePages(market, country, path = "") {
return jsUrl.toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text",
});
function queryOptionsForSimplePages(market, country) {
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
return jsUrl.toQueryParams({
"filter[field_path]": path,
"filter[field_market]": market.toUpperCase(),
"filter[field_allowed_countries]": country.toUpperCase(),
"fields[node--simple_page]": "title,field_meta_page_title,field_meta_page_description,field_simple_page_sections,field_simple_page_breadcrumbs,field_simple_page_title,field_share_image",
include: "field_simple_page_sections,field_simple_page_title,field_simple_page_sections.field_simple_blocks,field_simple_page_sections.field_simple_blocks.field_background_image,field_simple_page_sections.field_simple_blocks.field_cta,field_share_image",
"fields[paragraph--simple_page_section]": "field_simple_page_section_header,field_simple_page_section_layout,field_simple_blocks",
"fields[node--simple_block]": "title,field_background_image_x_focal,field_background_image_y_focal,field_content_align_x,field_content_align_y,field_header_text,field_header_svg,field_sub_header_text,field_video_link,field_video_background,field_background_image,field_cta,field_raw",
"fields[file--file]": "uri",
"fields[paragraph--cta]": "field_link,field_style",
"fields[node--reusable_string]": "field_reusable_string_text"
});
}
function queryOptionsForBasicBlock(title) {
return jsUrl.toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names",
});
return jsUrl.toQueryParams({
"filter[title]": title,
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names"
});
}
function queryOptionsForReusableString(stringsArray) {
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return jsUrl.toQueryParams(filterObj);
const filterObj = {};
filterObj["filter[title][operator]"] = "IN";
for (let i = 0; i < stringsArray.length; i++) {
filterObj[`filter[title][value][${i}]`] = stringsArray[i];
}
filterObj["fields[node--reusable_string]"] = "title,field_reusable_string_text";
return jsUrl.toQueryParams(filterObj);
}

@@ -145,20 +141,17 @@ /*

function getDrupalData(fetchUrl, fetchOptions) {
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions)
.then((resp) => resp.json())
.then((json) => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map((label) => flattenCMSJson(label, json.included));
})
.catch((e) => {
console.error(e.message);
return null;
});
return __awaiter(this, void 0, void 0, function* () {
return yield fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => {
var _a;
if (!Array.isArray(json.data)) {
json.data = new Array(json.data);
}
return (_a = json.data) === null || _a === void 0 ? void 0 : _a.map(label => flattenCMSJson(label, json.included));
}).catch(e => {
console.error(e.message);
return null;
});
});
}
function GetDrupalData(fetchUrl) {
return getDrupalData(fetchUrl);
return getDrupalData(fetchUrl);
}

@@ -176,6 +169,6 @@ /*

function getSimplePage(cmsUrl, market, country, language, path) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/simple_page/?`;
return yield GetDrupalData(cmsApi + queryOptionsForSimplePages(market, country, path));
});
}

@@ -191,6 +184,6 @@ /*

function getBasicBlock(cmsUrl, title, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/basic_block/?`;
return yield GetDrupalData(cmsApi + queryOptionsForBasicBlock(title));
});
}

@@ -206,6 +199,6 @@ /*

function getReusableData(cmsUrl, stringsArray, language) {
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
return __awaiter(this, void 0, void 0, function* () {
const cmsApi = `${cmsUrl}/${language}/jsonapi/node/reusable_string/?`;
return yield GetDrupalData(cmsApi + queryOptionsForReusableString(stringsArray));
});
}

@@ -224,10 +217,10 @@ /*

function getReusableText(titleKey, resuableStrings) {
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
if (typeof resuableStrings !== "undefined") {
for (let i = 0; i < resuableStrings.length; i++) {
if (resuableStrings[i].title === titleKey) {
return resuableStrings[i].field_reusable_string_text;
}
}
return titleKey;
}
return titleKey;
}

@@ -243,7 +236,7 @@ /*

function getCsPhoneNumber(cmsUrl, market, country) {
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
return __awaiter(this, void 0, void 0, function* () {
const drupalUrl = `https://${cmsUrl}/jsonapi/node/cs_phone_number/?filter%5Bfield_market%5D=${market}&filter%5Bfield_allowed_countries%5D=${country}&fields%5Bnode--cs_phone_number%5D=title`;
const data = yield GetDrupalData(drupalUrl);
return (data === null || data === void 0 ? void 0 : data.length) ? data[0].title : null;
});
}

@@ -261,13 +254,13 @@ /*

const getCategoryIntroId = (cmsUrl, market, country, language, path) => __awaiter(void 0, void 0, void 0, function* () {
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl)
.then((resp) => resp.json())
.then((json) => { var _a; return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id; })
.catch((err) => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
let requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&fields%5Bnode--category_intro%5D=id`;
if (country !== null) {
requestUrl = `${cmsUrl}/${language}/jsonapi/node/category_intro/?filter%5Bfield_market%5D=${market}&filter%5Bfield_cat_intro_category_handle%5D=${path}&filter%5Bfield_allowed_countries%5D=${country.toUpperCase()}&fields%5Bnode--category_intro%5D=id`;
}
return yield fetch(requestUrl).then(resp => resp.json()).then(json => {
var _a;
return (_a = json === null || json === void 0 ? void 0 : json.data[0]) === null || _a === void 0 ? void 0 : _a.id;
}).catch(err => {
console.error(`Fetch error for ${requestUrl}`, err);
return null;
});
});

@@ -282,27 +275,25 @@ /*

const getCategoryIntroPaths = (market, path) => {
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
}
else if (i !== 0) {
str += `/${p}`;
}
}
else if (market == "urban" || market == "leaf") {
str += p;
}
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
let str = "";
const paths = path.split("/").map((p, i) => {
// ARC.COM GENDER SPECIFIC OVERRIDES
if (market === "outdoor" || market === "sale") {
if (!path.split("/").includes("womens") && !path.split("/").includes("mens") && i === 0) {
str += `${p}`;
}
if (p == "mens" || p == "womens") {
str += `${p}`;
} else if (i !== 0) {
str += `/${p}`;
}
} else if (market == "urban" || market == "leaf") {
str += p;
}
return paths;
return str;
});
// Use mens as a fallback
if (paths[0] !== "mens" && paths[0] !== "womens") {
paths.splice(1, 0, `mens/${path}`);
paths.unshift("mens");
}
return paths;
};

@@ -321,12 +312,12 @@ /*

const getCmsApiForCategoryIntro = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`;
if (previewDraft) {
let catIntroId = yield getCategoryIntroId(cmsUrl, market, country, language, path);
// If No catIntroId found with country filter, then try to find with no country set in CMS
if (catIntroId === null || !catIntroId) {
catIntroId = yield getCategoryIntroId(cmsUrl, market, null, language, path);
}
return cmsApi;
cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/${catIntroId}?`;
}
return cmsApi;
});

@@ -345,7 +336,7 @@ /*

const generateRequestUrls = (cmsUrl, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map((catPath) => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
const catIntroPaths = getCategoryIntroPaths(market, path);
const cmsApi = yield getCmsApiForCategoryIntro(cmsUrl, market, country, language, path, previewDraft);
// Request Url with country filter
const requestUrls = catIntroPaths.map(catPath => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)));
return requestUrls;
});

@@ -365,34 +356,31 @@ /*

const getCategoryIntro = (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => __awaiter(void 0, void 0, void 0, function* () {
const fetchOptions = previewDraft
? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`,
},
}
: {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then((json) => json);
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens CDPs returns 2 Cat Intros
Unisex CDPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the CDP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
const fetchOptions = previewDraft ? {
headers: {
"content-length": "0",
authorization: `Basic ${basicAuthToken}`
}
catch (e) {
console.error(e);
return null;
} : {};
const requestUrls = yield generateRequestUrls(cmsUrl, market, country, language, path, previewDraft);
try {
const catIntros = yield Promise.all(requestUrls.map(url => getDrupalData(url, fetchOptions))).then(json => json);
const catIntrosNoEmpties = catIntros.filter(catIntro => catIntro === null || catIntro === void 0 ? void 0 : catIntro.length);
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens PLPs returns 2 Cat Intros
Unisex PLPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the PLP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"
// Note: The order of the array never changes
if (!path.includes("mens") && (catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) === 3) {
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 2];
}
// Else PLP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"
// e.g. ["womens"] return "womens"
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1];
} catch (e) {
console.error(e);
return null;
}
});

@@ -410,10 +398,10 @@ /**

const getCmsMessageByFieldName = (cmsUrl, market, country, language, messageFieldName) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
var _a, _b;
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`;
if (messageFieldName) {
queryStrings += `&filter[field_name]=${messageFieldName}`;
}
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`;
const data = yield getDrupalData(messageUrl);
return (_b = (_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.field_content.processed) !== null && _b !== void 0 ? _b : null;
});

@@ -420,0 +408,0 @@

{
"name": "@arcteryx/js-cms",
"version": "2.4.0",
"version": "2.4.1",
"source": "src/index.js",

@@ -23,3 +23,3 @@ "main": "dist/cjs/index.js",

"license": "ISC",
"gitHead": "7b3b8a274968f39c5cf564cab85ae4508e484682",
"gitHead": "f4c380387540e23386d20e16c81b9cee0bd3b177",
"files": [

@@ -26,0 +26,0 @@ "dist",

@@ -341,8 +341,8 @@ import { toQueryParams } from "@arcteryx/js-url";

/*
The Drupal fetch returns an array of Cat Intros
Womens and mens CDPs returns 2 Cat Intros
Unisex CDPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
/*
The Drupal fetch returns an array of Cat Intros
Womens and mens PLPs returns 2 Cat Intros
Unisex PLPs return 2 or 3 Cat Intros depending if a unisex Cat Intro exists
*/
// If the CDP is unisex AND a unisex Cat Intro exists then return the second item
// If the PLP is unisex AND a unisex Cat Intro exists then return the second item
// e.g. ["mens", "rebird", "mens/rebird"] return "rebird"

@@ -353,3 +353,3 @@ // Note: The order of the array never changes

}
// Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// Else PLP is gendered OR a unisex Cat Intro doesn't exist then return the last item
// e.g. ["mens", "mens/accessories"] return "mens/accessories"

@@ -356,0 +356,0 @@ // e.g. ["womens"] return "womens"

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