@arcteryx/js-cms
Advanced tools
Comparing version 2.3.2 to 2.3.3-alpha.0
@@ -21,7 +21,9 @@ 'use strict'; | ||
} | ||
returnObject[key] = item.relationships[key].data.map(related => { | ||
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); | ||
// 5) get the real entity object from the "included" array | ||
included.filter((include) => related?.id === include.id)[0], | ||
included | ||
); | ||
}); | ||
@@ -49,13 +51,17 @@ } | ||
} | ||
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[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[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) { | ||
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ""; | ||
function queryOptionsForSimplePages(market, country, path = "") { | ||
return jsUrl.toQueryParams({ | ||
@@ -65,19 +71,26 @@ "filter[field_path]": path, | ||
"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[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" | ||
"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" | ||
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names", | ||
}); | ||
} | ||
function queryOptionsForReusableString(stringsArray) { | ||
const filterObj = {}; | ||
filterObj["filter[title][operator]"] = "IN"; | ||
@@ -99,13 +112,16 @@ for (let i = 0; i < stringsArray.length; i++) { | ||
async function getDrupalData(fetchUrl, fetchOptions) { | ||
return await fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => { | ||
var _json$data; | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return (_json$data = json.data) === null || _json$data === void 0 ? void 0 : _json$data.map(label => flattenCMSJson(label, json.included)); | ||
}).catch(e => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
return await fetch(fetchUrl, fetchOptions) | ||
.then((resp) => resp.json()) | ||
.then((json) => { | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return json.data?.map((label) => flattenCMSJson(label, json.included)); | ||
}) | ||
.catch((e) => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
} | ||
function GetDrupalData(fetchUrl) { | ||
@@ -189,3 +205,3 @@ return getDrupalData(fetchUrl); | ||
const data = await GetDrupalData(drupalUrl); | ||
return data !== null && data !== void 0 && data.length ? data[0].title : null; | ||
return data?.length ? data[0].title : null; | ||
} | ||
@@ -205,12 +221,14 @@ | ||
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 await fetch(requestUrl).then(resp => resp.json()).then(json => { | ||
var _json$data$; | ||
return json === null || json === void 0 ? void 0 : (_json$data$ = json.data[0]) === null || _json$data$ === void 0 ? void 0 : _json$data$.id; | ||
}).catch(err => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
return await fetch(requestUrl) | ||
.then((resp) => resp.json()) | ||
.then((json) => json?.data[0]?.id) | ||
.catch((err) => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
}; | ||
@@ -227,2 +245,3 @@ | ||
let str = ""; | ||
const paths = path.split("/").map((p, i) => { | ||
@@ -250,2 +269,3 @@ // ARC.COM GENDER SPECIFIC OVERRIDES | ||
} | ||
return paths; | ||
@@ -267,2 +287,3 @@ }; | ||
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`; | ||
if (previewDraft) { | ||
@@ -276,2 +297,3 @@ let catIntroId = await getCategoryIntroId(cmsUrl, market, country, language, path); | ||
} | ||
return cmsApi; | ||
@@ -296,3 +318,6 @@ }; | ||
// Request Url with country filter | ||
const requestUrls = catIntroPaths.map(catPath => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft))); | ||
const requestUrls = catIntroPaths.map( | ||
(catPath) => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)) | ||
); | ||
return requestUrls; | ||
@@ -314,12 +339,18 @@ }; | ||
const getCategoryIntro = async (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => { | ||
const fetchOptions = previewDraft ? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}` | ||
} | ||
} : {}; | ||
const fetchOptions = previewDraft | ||
? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}`, | ||
}, | ||
} | ||
: {}; | ||
const requestUrls = await generateRequestUrls(cmsUrl, market, country, language, path, previewDraft); | ||
try { | ||
const catIntros = await 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); | ||
const catIntros = await Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then( | ||
(json) => json | ||
); | ||
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro?.length); | ||
@@ -334,4 +365,4 @@ /* | ||
// 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]; | ||
if (!path.includes("mens") && catIntrosNoEmpties?.length === 3) { | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 2]; | ||
} | ||
@@ -341,3 +372,3 @@ // Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item | ||
// e.g. ["womens"] return "womens" | ||
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1]; | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 1]; | ||
} catch (e) { | ||
@@ -360,3 +391,2 @@ console.error(e); | ||
const getCmsMessageByFieldName = async (cmsUrl, market, country, language, messageFieldName) => { | ||
var _data$0$field_content, _data$; | ||
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`; | ||
@@ -366,5 +396,8 @@ if (messageFieldName) { | ||
} | ||
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`; | ||
const data = await getDrupalData(messageUrl); | ||
return (_data$0$field_content = data === null || data === void 0 ? void 0 : (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.field_content.processed) !== null && _data$0$field_content !== void 0 ? _data$0$field_content : null; | ||
return data?.[0]?.field_content.processed ?? null; | ||
}; | ||
@@ -371,0 +404,0 @@ |
@@ -17,7 +17,9 @@ import { toQueryParams } from '@arcteryx/js-url'; | ||
} | ||
returnObject[key] = item.relationships[key].data.map(related => { | ||
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); | ||
// 5) get the real entity object from the "included" array | ||
included.filter((include) => related?.id === include.id)[0], | ||
included | ||
); | ||
}); | ||
@@ -45,13 +47,17 @@ } | ||
} | ||
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[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[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) { | ||
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ""; | ||
function queryOptionsForSimplePages(market, country, path = "") { | ||
return toQueryParams({ | ||
@@ -61,19 +67,26 @@ "filter[field_path]": path, | ||
"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[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" | ||
"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" | ||
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names", | ||
}); | ||
} | ||
function queryOptionsForReusableString(stringsArray) { | ||
const filterObj = {}; | ||
filterObj["filter[title][operator]"] = "IN"; | ||
@@ -95,13 +108,16 @@ for (let i = 0; i < stringsArray.length; i++) { | ||
async function getDrupalData(fetchUrl, fetchOptions) { | ||
return await fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => { | ||
var _json$data; | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return (_json$data = json.data) === null || _json$data === void 0 ? void 0 : _json$data.map(label => flattenCMSJson(label, json.included)); | ||
}).catch(e => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
return await fetch(fetchUrl, fetchOptions) | ||
.then((resp) => resp.json()) | ||
.then((json) => { | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return json.data?.map((label) => flattenCMSJson(label, json.included)); | ||
}) | ||
.catch((e) => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
} | ||
function GetDrupalData(fetchUrl) { | ||
@@ -185,3 +201,3 @@ return getDrupalData(fetchUrl); | ||
const data = await GetDrupalData(drupalUrl); | ||
return data !== null && data !== void 0 && data.length ? data[0].title : null; | ||
return data?.length ? data[0].title : null; | ||
} | ||
@@ -201,12 +217,14 @@ | ||
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 await fetch(requestUrl).then(resp => resp.json()).then(json => { | ||
var _json$data$; | ||
return json === null || json === void 0 ? void 0 : (_json$data$ = json.data[0]) === null || _json$data$ === void 0 ? void 0 : _json$data$.id; | ||
}).catch(err => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
return await fetch(requestUrl) | ||
.then((resp) => resp.json()) | ||
.then((json) => json?.data[0]?.id) | ||
.catch((err) => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
}; | ||
@@ -223,2 +241,3 @@ | ||
let str = ""; | ||
const paths = path.split("/").map((p, i) => { | ||
@@ -246,2 +265,3 @@ // ARC.COM GENDER SPECIFIC OVERRIDES | ||
} | ||
return paths; | ||
@@ -263,2 +283,3 @@ }; | ||
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`; | ||
if (previewDraft) { | ||
@@ -272,2 +293,3 @@ let catIntroId = await getCategoryIntroId(cmsUrl, market, country, language, path); | ||
} | ||
return cmsApi; | ||
@@ -292,3 +314,6 @@ }; | ||
// Request Url with country filter | ||
const requestUrls = catIntroPaths.map(catPath => cmsApi + toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft))); | ||
const requestUrls = catIntroPaths.map( | ||
(catPath) => cmsApi + toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)) | ||
); | ||
return requestUrls; | ||
@@ -310,12 +335,18 @@ }; | ||
const getCategoryIntro = async (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => { | ||
const fetchOptions = previewDraft ? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}` | ||
} | ||
} : {}; | ||
const fetchOptions = previewDraft | ||
? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}`, | ||
}, | ||
} | ||
: {}; | ||
const requestUrls = await generateRequestUrls(cmsUrl, market, country, language, path, previewDraft); | ||
try { | ||
const catIntros = await 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); | ||
const catIntros = await Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then( | ||
(json) => json | ||
); | ||
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro?.length); | ||
@@ -330,4 +361,4 @@ /* | ||
// 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]; | ||
if (!path.includes("mens") && catIntrosNoEmpties?.length === 3) { | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 2]; | ||
} | ||
@@ -337,3 +368,3 @@ // Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item | ||
// e.g. ["womens"] return "womens" | ||
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1]; | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 1]; | ||
} catch (e) { | ||
@@ -356,3 +387,2 @@ console.error(e); | ||
const getCmsMessageByFieldName = async (cmsUrl, market, country, language, messageFieldName) => { | ||
var _data$0$field_content, _data$; | ||
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`; | ||
@@ -362,5 +392,8 @@ if (messageFieldName) { | ||
} | ||
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`; | ||
const data = await getDrupalData(messageUrl); | ||
return (_data$0$field_content = data === null || data === void 0 ? void 0 : (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.field_content.processed) !== null && _data$0$field_content !== void 0 ? _data$0$field_content : null; | ||
return data?.[0]?.field_content.processed ?? null; | ||
}; | ||
@@ -367,0 +400,0 @@ |
@@ -26,7 +26,9 @@ (function (global, factory) { | ||
} | ||
returnObject[key] = item.relationships[key].data.map(related => { | ||
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); | ||
// 5) get the real entity object from the "included" array | ||
included.filter((include) => related?.id === include.id)[0], | ||
included | ||
); | ||
}); | ||
@@ -54,13 +56,17 @@ } | ||
} | ||
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[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[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) { | ||
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ""; | ||
function queryOptionsForSimplePages(market, country, path = "") { | ||
return jsUrl.toQueryParams({ | ||
@@ -70,19 +76,26 @@ "filter[field_path]": path, | ||
"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[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" | ||
"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" | ||
"fields[node--basic_block]": "title,field_basic_content,field_css_class_names", | ||
}); | ||
} | ||
function queryOptionsForReusableString(stringsArray) { | ||
const filterObj = {}; | ||
filterObj["filter[title][operator]"] = "IN"; | ||
@@ -104,13 +117,16 @@ for (let i = 0; i < stringsArray.length; i++) { | ||
async function getDrupalData(fetchUrl, fetchOptions) { | ||
return await fetch(fetchUrl, fetchOptions).then(resp => resp.json()).then(json => { | ||
var _json$data; | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return (_json$data = json.data) === null || _json$data === void 0 ? void 0 : _json$data.map(label => flattenCMSJson(label, json.included)); | ||
}).catch(e => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
return await fetch(fetchUrl, fetchOptions) | ||
.then((resp) => resp.json()) | ||
.then((json) => { | ||
if (!Array.isArray(json.data)) { | ||
json.data = new Array(json.data); | ||
} | ||
return json.data?.map((label) => flattenCMSJson(label, json.included)); | ||
}) | ||
.catch((e) => { | ||
console.error(e.message); | ||
return null; | ||
}); | ||
} | ||
function GetDrupalData(fetchUrl) { | ||
@@ -194,3 +210,3 @@ return getDrupalData(fetchUrl); | ||
const data = await GetDrupalData(drupalUrl); | ||
return data !== null && data !== void 0 && data.length ? data[0].title : null; | ||
return data?.length ? data[0].title : null; | ||
} | ||
@@ -210,12 +226,14 @@ | ||
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 await fetch(requestUrl).then(resp => resp.json()).then(json => { | ||
var _json$data$; | ||
return json === null || json === void 0 ? void 0 : (_json$data$ = json.data[0]) === null || _json$data$ === void 0 ? void 0 : _json$data$.id; | ||
}).catch(err => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
return await fetch(requestUrl) | ||
.then((resp) => resp.json()) | ||
.then((json) => json?.data[0]?.id) | ||
.catch((err) => { | ||
console.error(`Fetch error for ${requestUrl}`, err); | ||
return null; | ||
}); | ||
}; | ||
@@ -232,2 +250,3 @@ | ||
let str = ""; | ||
const paths = path.split("/").map((p, i) => { | ||
@@ -255,2 +274,3 @@ // ARC.COM GENDER SPECIFIC OVERRIDES | ||
} | ||
return paths; | ||
@@ -272,2 +292,3 @@ }; | ||
let cmsApi = `${cmsUrl}/${language}/jsonapi/node/category_intro/?`; | ||
if (previewDraft) { | ||
@@ -281,2 +302,3 @@ let catIntroId = await getCategoryIntroId(cmsUrl, market, country, language, path); | ||
} | ||
return cmsApi; | ||
@@ -301,3 +323,6 @@ }; | ||
// Request Url with country filter | ||
const requestUrls = catIntroPaths.map(catPath => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft))); | ||
const requestUrls = catIntroPaths.map( | ||
(catPath) => cmsApi + jsUrl.toQueryParams(queryOptionsForCategoryIntros(market, country, catPath, previewDraft)) | ||
); | ||
return requestUrls; | ||
@@ -319,12 +344,18 @@ }; | ||
const getCategoryIntro = async (cmsUrl, basicAuthToken, market, country, language, path, previewDraft) => { | ||
const fetchOptions = previewDraft ? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}` | ||
} | ||
} : {}; | ||
const fetchOptions = previewDraft | ||
? { | ||
headers: { | ||
"content-length": "0", | ||
authorization: `Basic ${basicAuthToken}`, | ||
}, | ||
} | ||
: {}; | ||
const requestUrls = await generateRequestUrls(cmsUrl, market, country, language, path, previewDraft); | ||
try { | ||
const catIntros = await 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); | ||
const catIntros = await Promise.all(requestUrls.map((url) => getDrupalData(url, fetchOptions))).then( | ||
(json) => json | ||
); | ||
const catIntrosNoEmpties = catIntros.filter((catIntro) => catIntro?.length); | ||
@@ -339,4 +370,4 @@ /* | ||
// 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]; | ||
if (!path.includes("mens") && catIntrosNoEmpties?.length === 3) { | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 2]; | ||
} | ||
@@ -346,3 +377,3 @@ // Else CDP is gendered OR a unisex Cat Intro doesn't exist then return the last item | ||
// e.g. ["womens"] return "womens" | ||
return catIntrosNoEmpties[(catIntrosNoEmpties === null || catIntrosNoEmpties === void 0 ? void 0 : catIntrosNoEmpties.length) - 1]; | ||
return catIntrosNoEmpties[catIntrosNoEmpties?.length - 1]; | ||
} catch (e) { | ||
@@ -365,3 +396,2 @@ console.error(e); | ||
const getCmsMessageByFieldName = async (cmsUrl, market, country, language, messageFieldName) => { | ||
var _data$0$field_content, _data$; | ||
let queryStrings = `filter[field_market]=${market}&filter[field_allowed_countries]=${country}&fields[node--message]=field_content`; | ||
@@ -371,5 +401,8 @@ if (messageFieldName) { | ||
} | ||
const messageUrl = `${cmsUrl}/${language}/jsonapi/node/message?${queryStrings}`; | ||
const data = await getDrupalData(messageUrl); | ||
return (_data$0$field_content = data === null || data === void 0 ? void 0 : (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.field_content.processed) !== null && _data$0$field_content !== void 0 ? _data$0$field_content : null; | ||
return data?.[0]?.field_content.processed ?? null; | ||
}; | ||
@@ -376,0 +409,0 @@ |
{ | ||
"name": "@arcteryx/js-cms", | ||
"version": "2.3.2", | ||
"version": "2.3.3-alpha.0", | ||
"source": "src/index.js", | ||
@@ -22,3 +22,3 @@ "main": "dist/cjs/index.js", | ||
"license": "ISC", | ||
"gitHead": "3a0f67f67df223ad4621261da557021d44fce1ee", | ||
"gitHead": "4f15ba8d5658656d9258fed37b749d2bfe63a9a2", | ||
"files": [ | ||
@@ -25,0 +25,0 @@ "dist", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1435
6
154383
2